[libc-commits] [PATCH] D127550: [libc] add EXP_MAT_MASK to x87 long double

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


michaelrj created this revision.
michaelrj added reviewers: sivachandra, lntue.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
michaelrj requested review of this revision.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127550

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


Index: libc/src/__support/FPUtil/FloatProperties.h
===================================================================
--- libc/src/__support/FPUtil/FloatProperties.h
+++ libc/src/__support/FPUtil/FloatProperties.h
@@ -109,16 +109,27 @@
                 "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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127550.436075.patch
Type: text/x-patch
Size: 1482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20220610/ca9c713d/attachment-0001.bin>


More information about the libc-commits mailing list