[libc] add EXP_MAT_MASK to x87 long double
authorMichael Jones <michaelrj@google.com>
Fri, 10 Jun 2022 23:09:18 +0000 (16:09 -0700)
committerMichael Jones <michaelrj@google.com>
Fri, 10 Jun 2022 23:26:29 +0000 (16:26 -0700)
A previous patch added the constant EXP_MANT_MASK to the FloatProperties
for other types of long double. This patch adds it to the special 80-bit
x87 long double.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D127550

libc/src/__support/FPUtil/FloatProperties.h

index 6fc8b6a..cbef390 100644 (file)
@@ -109,16 +109,27 @@ template <> struct FloatProperties<long double> {
                 "Unexpected size of 'long double' type.");
 
   static constexpr uint32_t BIT_WIDTH = (sizeof(BitsType) * 8) - 48;
+  static constexpr BitsType FULL_WIDTH_MASK = ((BitsType(1) << BIT_WIDTH) - 1);
 
   static constexpr uint32_t MANTISSA_WIDTH = 63;
   static constexpr uint32_t EXPONENT_WIDTH = 15;
   static constexpr BitsType MANTISSA_MASK = (BitsType(1) << MANTISSA_WIDTH) - 1;
+
+  // The x86 80 bit float represents the leading digit of the mantissa
+  // explicitly. This is the mask for that bit.
+  static constexpr BitsType EXPLICIT_BIT_MASK = (BitsType(1) << MANTISSA_WIDTH);
+
   static constexpr BitsType SIGN_MASK =
       BitsType(1) << (EXPONENT_WIDTH + MANTISSA_WIDTH + 1);
   static constexpr BitsType EXPONENT_MASK =
       ((BitsType(1) << EXPONENT_WIDTH) - 1) << (MANTISSA_WIDTH + 1);
   static constexpr uint32_t EXPONENT_BIAS = 16383;
 
+  static constexpr BitsType EXP_MANT_MASK =
+      MANTISSA_MASK + EXPLICIT_BIT_MASK + EXPONENT_MASK;
+  static_assert(EXP_MANT_MASK == (~SIGN_MASK & FULL_WIDTH_MASK),
+                "Exponent and mantissa masks are not as expected.");
+
   // If a number x is a NAN, then it is a quiet NAN if:
   //   QuietNaNMask & bits(x) != 0
   // Else, it is a signalling NAN.