[llvm] [libc] [libc][NFC] Refactor FPBits and remove LongDoubleBits specialization (PR #78192)
Nick Desaulniers via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 16 10:27:02 PST 2024
================
@@ -132,11 +166,94 @@ struct FPRepBase : public internal::FPLayout<fp_type> {
static_assert((SIG_MASK & EXP_MASK & SIGN_MASK) == 0, "masks disjoint");
static_assert((SIG_MASK | EXP_MASK | SIGN_MASK) == FP_MASK, "masks cover");
-private:
+protected:
LIBC_INLINE static constexpr StorageType bit_at(int position) {
return StorageType(1) << position;
}
+ // An opaque type to store a floating point exponent.
+ // We define special values but it is valid to create arbitrary values as long
+ // as they are in the range [MIN, MAX].
+ enum class Exponent : int32_t {
+ MIN = 1 - EXP_BIAS,
+ ZERO = 0,
+ MAX = EXP_BIAS,
+ };
+
+ // An opaque type to store a floating point biased exponent.
+ // We define special values but it is valid to create arbitrary values as long
+ // as they are in the range [BITS_ALL_ZEROES, BITS_ALL_ONES].
+ // Values greater than BITS_ALL_ONES are truncated.
+ enum class BiasedExponent : uint32_t {
+ // The exponent value for denormal numbers.
+ BITS_ALL_ZEROES = 0,
+ // The exponent value for infinity.
+ BITS_ALL_ONES = 2 * EXP_BIAS + 1,
+ };
+
+ LIBC_INLINE static constexpr BiasedExponent biased(Exponent value) {
+ return static_cast<BiasedExponent>(static_cast<int32_t>(value) + EXP_BIAS);
+ }
+
+ // An opaque type to store a floating point significand.
+ // We define special values but it is valid to create arbitrary values as long
+ // as they are in the range [BITS_ALL_ZEROES, BITS_ALL_ONES].
+ // Note that the semantics of the Significand are implementation dependent.
+ // Values greater than BITS_ALL_ONES are truncated.
+ enum class Significand : StorageType {
+ ZERO = 0,
+ LSB = 1,
+ MSB = bit_at(SIG_LEN - 1),
+ // Aliases
+ BITS_ALL_ZEROES = ZERO,
+ BITS_ALL_ONES = SIG_MASK,
+ };
+
+ template <typename T>
+ LIBC_INLINE static constexpr auto storage_cast(T value) {
+ return static_cast<StorageType>(value);
----------------
nickdesaulniers wrote:
32b arm build bot failure here:
```
/llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/FPBits.h:214:12: error: no matching conversion for static_cast from '__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::BiasedExponent' to '__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::StorageType' (aka 'BigInt<128U, false>')
return static_cast<StorageType>(value);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/FPBits.h:231:13: note: in instantiation of function template specialization '__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::storage_cast<__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::BiasedExponent>' requested here
return (storage_cast(exp) << SIG_LEN) & EXP_MASK;
^
/llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/FPBits.h:472:23: note: in instantiation of member function '__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::encode' requested here
if (exp_bits() == encode(BiasedExponent::BITS_ALL_ONES))
^
/llvm/ndesaulniers/llvm-project/libc/src/__support/UInt.h:44:25: note: candidate constructor not viable: no known conversion from '__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::BiasedExponent' to 'const BigInt<128U, false>' for 1st argument
LIBC_INLINE constexpr BigInt(const BigInt<Bits, Signed> &other) = default;
^
/llvm/ndesaulniers/llvm-project/libc/src/__support/UInt.h:100:34: note: candidate constructor not viable: no known conversion from '__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::BiasedExponent' to 'const cpp::array<uint64_t, WORDCOUNT>' (aka 'const array<unsigned long long, WORDCOUNT>') for 1st argument
LIBC_INLINE constexpr explicit BigInt(
^
/llvm/ndesaulniers/llvm-project/libc/src/__support/UInt.h:47:25: note: candidate template ignored: could not match 'BigInt<OtherBits, OtherSigned>' against '__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::BiasedExponent'
LIBC_INLINE constexpr BigInt(const BigInt<OtherBits, OtherSigned> &other) {
^
/llvm/ndesaulniers/llvm-project/libc/src/__support/UInt.h:67:25: note: candidate template ignored: could not match 'uint64_t[N]' (aka 'unsigned long long[N]') against '__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::BiasedExponent'
LIBC_INLINE constexpr BigInt(const uint64_t (&nums)[N]) {
^
/llvm/ndesaulniers/llvm-project/libc/src/__support/UInt.h:81:25: note: candidate template ignored: substitution failure [with T = __llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::BiasedExponent]: implicit instantiation of undefined template '__llvm_libc_18_0_0_git::cpp::enable_if<false>'
LIBC_INLINE constexpr BigInt(T v) {
^
/llvm/ndesaulniers/llvm-project/libc/src/__support/UInt.h:42:25: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
LIBC_INLINE constexpr BigInt() = default;
^
```
https://github.com/llvm/llvm-project/pull/78192
More information about the llvm-commits
mailing list