[libc] [llvm] [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:34:59 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 {
----------------
nickdesaulniers wrote:

32b arm build bot failure here:
```
In file included from /llvm/ndesaulniers/llvm-project/libc/src/fenv/fegetround.cpp:10:
In file included from /llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/FEnvImpl.h:33:
In file included from /llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/arm/FEnvImpl.h:12:
/llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/FPBits.h:203:28: error: non-integral type '__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>::StorageType' (aka 'BigInt<128U, false>') is an invalid underlying type
  enum class Significand : StorageType {
                           ^
/llvm/ndesaulniers/llvm-project/libc/src/__support/FPUtil/FPBits.h:436:45: note: in instantiation of template class '__llvm_libc_18_0_0_git::fputil::FPRepBase<__llvm_libc_18_0_0_git::fputil::FPType::X86_Binary80>' requested here
struct FPRep<FPType::X86_Binary80> : public FPRepBase<FPType::X86_Binary80> {
                                            ^
```

https://github.com/llvm/llvm-project/pull/78192


More information about the llvm-commits mailing list