[libc-commits] [libc] 747061f - [libc][NFC] Make `QNAN_MASK` an implementation detail of `FPBits` (#75945)

via libc-commits libc-commits at lists.llvm.org
Tue Dec 19 08:16:35 PST 2023


Author: Guillaume Chatelet
Date: 2023-12-19T17:16:31+01:00
New Revision: 747061f9ba7e2d6cdf730d3bd2cda1134f1175a1

URL: https://github.com/llvm/llvm-project/commit/747061f9ba7e2d6cdf730d3bd2cda1134f1175a1
DIFF: https://github.com/llvm/llvm-project/commit/747061f9ba7e2d6cdf730d3bd2cda1134f1175a1.diff

LOG: [libc][NFC] Make `QNAN_MASK` an implementation detail of `FPBits` (#75945)

Added: 
    

Modified: 
    libc/src/__support/FPUtil/FPBits.h
    libc/src/__support/FPUtil/FloatProperties.h
    libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
    libc/src/__support/str_to_float.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index 7f5dd0fca58d4f..bee93ca60dc1fb 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -39,7 +39,11 @@ template <typename T> struct FPBits : private FloatProperties<T> {
   using FloatProperties<T>::EXP_LEN;
   using FloatProperties<T>::FRACTION_MASK;
   using FloatProperties<T>::FRACTION_LEN;
+
+private:
   using FloatProperties<T>::QUIET_NAN_MASK;
+
+public:
   using FloatProperties<T>::SIGN_MASK;
 
   // Reinterpreting bits as an integer value and interpreting the bits of an
@@ -90,7 +94,6 @@ template <typename T> struct FPBits : private FloatProperties<T> {
                 "Data type and integral representation have 
diff erent sizes.");
 
   static constexpr int MAX_EXPONENT = (1 << EXP_LEN) - 1;
-
   static constexpr StorageType MIN_SUBNORMAL = StorageType(1);
   static constexpr StorageType MAX_SUBNORMAL = FRACTION_MASK;
   static constexpr StorageType MIN_NORMAL = (StorageType(1) << FRACTION_LEN);

diff  --git a/libc/src/__support/FPUtil/FloatProperties.h b/libc/src/__support/FPUtil/FloatProperties.h
index 896c29919e2f77..ecc6f8d2299945 100644
--- a/libc/src/__support/FPUtil/FloatProperties.h
+++ b/libc/src/__support/FPUtil/FloatProperties.h
@@ -143,16 +143,6 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
     return StorageType(1) << position;
   }
 
-  LIBC_INLINE_VAR static constexpr StorageType QNAN_MASK =
-      UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
-          ? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 2) // 0b1100...
-          : bit_at(SIG_LEN - 1);                      // 0b1000...
-
-  LIBC_INLINE_VAR static constexpr StorageType SNAN_MASK =
-      UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
-          ? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 3) // 0b1010...
-          : bit_at(SIG_LEN - 2);                      // 0b0100...
-
 public:
   // The number of bits after the decimal dot when the number is in normal form.
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN =
@@ -165,10 +155,20 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
   LIBC_INLINE_VAR static constexpr StorageType EXP_MANT_MASK =
       EXP_MASK | SIG_MASK;
 
+protected:
   // 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 StorageType QUIET_NAN_MASK = QNAN_MASK;
+  //   QUIET_NAN_MASK & bits(x) != 0
+  LIBC_INLINE_VAR static constexpr StorageType QUIET_NAN_MASK =
+      UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
+          ? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 2) // 0b1100...
+          : bit_at(SIG_LEN - 1);                      // 0b1000...
+
+  // If a number x is a NAN, then it is a signalling NAN if:
+  //   SIGNALING_NAN_MASK & bits(x) != 0
+  LIBC_INLINE_VAR static constexpr StorageType SIGNALING_NAN_MASK =
+      UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
+          ? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 3) // 0b1010...
+          : bit_at(SIG_LEN - 2);                      // 0b0100...
 };
 
 //-----------------------------------------------------------------------------

diff  --git a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
index 89c47063ebac4d..7ac94664baf605 100644
--- a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
+++ b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
@@ -35,7 +35,11 @@ template <> struct FPBits<long double> : private FloatProperties<long double> {
   using FloatProperties<long double>::EXP_LEN;
   using FloatProperties<long double>::FRACTION_MASK;
   using FloatProperties<long double>::FRACTION_LEN;
+
+private:
   using FloatProperties<long double>::QUIET_NAN_MASK;
+
+public:
   using FloatProperties<long double>::SIGN_MASK;
 
   static constexpr int MAX_EXPONENT = 0x7FFF;

diff  --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h
index 9984bcd7064d75..ec2b8b062b9b78 100644
--- a/libc/src/__support/str_to_float.h
+++ b/libc/src/__support/str_to_float.h
@@ -1167,7 +1167,6 @@ LIBC_INLINE StrToNumResult<T> strtofloatingpoint(const char *__restrict src) {
           index = left_paren;
         }
       }
-      nan_mantissa |= fputil::FloatProperties<T>::QUIET_NAN_MASK;
       if (result.get_sign()) {
         result = FPBits(result.build_quiet_nan(nan_mantissa));
         result.set_sign(true);


        


More information about the libc-commits mailing list