[libc-commits] [PATCH] D113625: [libc] clean up FPUtil long doubles

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Nov 10 16:29:37 PST 2021


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

Add quietNaNMask consts to FloatProperties and make LongDoubleBitsX86
clear the extra bits that aren't set when initializing with an 80 bit
long double.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113625

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


Index: libc/src/__support/FPUtil/LongDoubleBitsX86.h
===================================================================
--- libc/src/__support/FPUtil/LongDoubleBitsX86.h
+++ libc/src/__support/FPUtil/LongDoubleBitsX86.h
@@ -89,7 +89,11 @@
 
   template <typename XType,
             cpp::EnableIfType<cpp::IsSame<long double, XType>::Value, int> = 0>
-  explicit FPBits(XType x) : val(x) {}
+  explicit FPBits(XType x) : val(x) {
+    // bits starts uninitialized, and setting it to a long double only
+    // overwrites the first 80 bits. This clears those upper bits.
+    bits = bits & ((UIntType(1) << 80) - 1);
+  }
 
   template <typename XType,
             cpp::EnableIfType<cpp::IsSame<XType, UIntType>::Value, int> = 0>
Index: libc/src/__support/FPUtil/FloatProperties.h
===================================================================
--- libc/src/__support/FPUtil/FloatProperties.h
+++ libc/src/__support/FPUtil/FloatProperties.h
@@ -80,6 +80,12 @@
       FloatProperties<double>::exponentMask;
   static constexpr uint32_t exponentBias =
       FloatProperties<double>::exponentBias;
+
+  // If a number x is a NAN, then it is a quiet NAN if:
+  //   QuietNaNMask & bits(x) != 0
+  // Else, it is a signalling NAN.
+  static constexpr BitsType quietNaNMask =
+      FloatProperties<double>::quietNaNMask;
 };
 #elif defined(SPECIAL_X86_LONG_DOUBLE)
 // Properties for numbers represented in 80 bits long double on non-Windows x86
@@ -99,6 +105,11 @@
   static constexpr BitsType exponentMask = ((BitsType(1) << exponentWidth) - 1)
                                            << (mantissaWidth + 1);
   static constexpr uint32_t exponentBias = 16383;
+
+  // If a number x is a NAN, then it is a quiet NAN if:
+  //   QuietNaNMask & bits(x) != 0
+  // Else, it is a signalling NAN.
+  static constexpr BitsType quietNaNMask = BitsType(1) << (mantissaWidth - 1);
 };
 #else
 // Properties for numbers represented in 128 bits long double on non x86
@@ -117,6 +128,11 @@
                                        << (exponentWidth + mantissaWidth);
   static constexpr BitsType exponentMask = ~(signMask | mantissaMask);
   static constexpr uint32_t exponentBias = 16383;
+
+  // If a number x is a NAN, then it is a quiet NAN if:
+  //   QuietNaNMask & bits(x) != 0
+  // Else, it is a signalling NAN.
+  static constexpr BitsType quietNaNMask = BitsType(1) << (mantissaWidth - 1);
 };
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113625.386352.patch
Type: text/x-patch
Size: 2408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20211111/44210ee3/attachment.bin>


More information about the libc-commits mailing list