[libc] [llvm] [libc][NFC] Refactor FPBits and remove LongDoubleBits specialization (PR #78192)

Clement Courbet via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 02:47:50 PST 2024


================
@@ -132,11 +166,84 @@ 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 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,
+    NORMAL_MIN = 1,
+    NORMAL_ZERO = EXP_BIAS,
+    NORMAL_MAX = 2 * EXP_BIAS,
+    // The exponent value for infinity.
+    BITS_ALL_ONES = NORMAL_MAX + 1,
+  };
+
+  // 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].
----------------
legrosbuffle wrote:

All right, This comment makes it much clearer. 
I would add `// Significand values can be manipulated with the three provided operators `|`, `^` and `>>`, which guarantee that the underlying value remains within this range of values.`

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


More information about the llvm-commits mailing list