Skip to content

Commit 747061f

Browse files
authored
[libc][NFC] Make QNAN_MASK an implementation detail of FPBits (#75945)
1 parent 571d151 commit 747061f

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

libc/src/__support/FPUtil/FPBits.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ template <typename T> struct FPBits : private FloatProperties<T> {
3939
using FloatProperties<T>::EXP_LEN;
4040
using FloatProperties<T>::FRACTION_MASK;
4141
using FloatProperties<T>::FRACTION_LEN;
42+
43+
private:
4244
using FloatProperties<T>::QUIET_NAN_MASK;
45+
46+
public:
4347
using FloatProperties<T>::SIGN_MASK;
4448

4549
// Reinterpreting bits as an integer value and interpreting the bits of an
@@ -90,7 +94,6 @@ template <typename T> struct FPBits : private FloatProperties<T> {
9094
"Data type and integral representation have different sizes.");
9195

9296
static constexpr int MAX_EXPONENT = (1 << EXP_LEN) - 1;
93-
9497
static constexpr StorageType MIN_SUBNORMAL = StorageType(1);
9598
static constexpr StorageType MAX_SUBNORMAL = FRACTION_MASK;
9699
static constexpr StorageType MIN_NORMAL = (StorageType(1) << FRACTION_LEN);

libc/src/__support/FPUtil/FloatProperties.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,6 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
143143
return StorageType(1) << position;
144144
}
145145

146-
LIBC_INLINE_VAR static constexpr StorageType QNAN_MASK =
147-
UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
148-
? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 2) // 0b1100...
149-
: bit_at(SIG_LEN - 1); // 0b1000...
150-
151-
LIBC_INLINE_VAR static constexpr StorageType SNAN_MASK =
152-
UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
153-
? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 3) // 0b1010...
154-
: bit_at(SIG_LEN - 2); // 0b0100...
155-
156146
public:
157147
// The number of bits after the decimal dot when the number is in normal form.
158148
LIBC_INLINE_VAR static constexpr int FRACTION_LEN =
@@ -165,10 +155,20 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
165155
LIBC_INLINE_VAR static constexpr StorageType EXP_MANT_MASK =
166156
EXP_MASK | SIG_MASK;
167157

158+
protected:
168159
// If a number x is a NAN, then it is a quiet NAN if:
169-
// QuietNaNMask & bits(x) != 0
170-
// Else, it is a signalling NAN.
171-
static constexpr StorageType QUIET_NAN_MASK = QNAN_MASK;
160+
// QUIET_NAN_MASK & bits(x) != 0
161+
LIBC_INLINE_VAR static constexpr StorageType QUIET_NAN_MASK =
162+
UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
163+
? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 2) // 0b1100...
164+
: bit_at(SIG_LEN - 1); // 0b1000...
165+
166+
// If a number x is a NAN, then it is a signalling NAN if:
167+
// SIGNALING_NAN_MASK & bits(x) != 0
168+
LIBC_INLINE_VAR static constexpr StorageType SIGNALING_NAN_MASK =
169+
UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
170+
? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 3) // 0b1010...
171+
: bit_at(SIG_LEN - 2); // 0b0100...
172172
};
173173

174174
//-----------------------------------------------------------------------------

libc/src/__support/FPUtil/x86_64/LongDoubleBits.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ template <> struct FPBits<long double> : private FloatProperties<long double> {
3535
using FloatProperties<long double>::EXP_LEN;
3636
using FloatProperties<long double>::FRACTION_MASK;
3737
using FloatProperties<long double>::FRACTION_LEN;
38+
39+
private:
3840
using FloatProperties<long double>::QUIET_NAN_MASK;
41+
42+
public:
3943
using FloatProperties<long double>::SIGN_MASK;
4044

4145
static constexpr int MAX_EXPONENT = 0x7FFF;

libc/src/__support/str_to_float.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,6 @@ LIBC_INLINE StrToNumResult<T> strtofloatingpoint(const char *__restrict src) {
11671167
index = left_paren;
11681168
}
11691169
}
1170-
nan_mantissa |= fputil::FloatProperties<T>::QUIET_NAN_MASK;
11711170
if (result.get_sign()) {
11721171
result = FPBits(result.build_quiet_nan(nan_mantissa));
11731172
result.set_sign(true);

0 commit comments

Comments
 (0)