[libc-commits] [libc] 02f4aff - [libc] add EXP_MAT_MASK to x87 long double

Michael Jones via libc-commits libc-commits at lists.llvm.org
Fri Jun 10 16:26:33 PDT 2022


Author: Michael Jones
Date: 2022-06-10T16:26:29-07:00
New Revision: 02f4affe2d85ec457c3638971fea3b32be357478

URL: https://github.com/llvm/llvm-project/commit/02f4affe2d85ec457c3638971fea3b32be357478
DIFF: https://github.com/llvm/llvm-project/commit/02f4affe2d85ec457c3638971fea3b32be357478.diff

LOG: [libc] add EXP_MAT_MASK to x87 long double

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

Added: 
    

Modified: 
    libc/src/__support/FPUtil/FloatProperties.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/FPUtil/FloatProperties.h b/libc/src/__support/FPUtil/FloatProperties.h
index 6fc8b6ac1bb06..cbef3908220cd 100644
--- a/libc/src/__support/FPUtil/FloatProperties.h
+++ b/libc/src/__support/FPUtil/FloatProperties.h
@@ -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.


        


More information about the libc-commits mailing list