-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc][NFC] Make QNAN_MASK
an implementation detail of FPBits
#75945
Merged
gchatelet
merged 3 commits into
llvm:main
from
gchatelet:make_qnan_mask_an_implementation_detail
Dec 19, 2023
Merged
[libc][NFC] Make QNAN_MASK
an implementation detail of FPBits
#75945
gchatelet
merged 3 commits into
llvm:main
from
gchatelet:make_qnan_mask_an_implementation_detail
Dec 19, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-libc Author: Guillaume Chatelet (gchatelet) ChangesFull diff: https://github.com/llvm/llvm-project/pull/75945.diff 4 Files Affected:
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index 7f5dd0fca58d4f..fd67c6e0ea5ff0 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;
- using FloatProperties<T>::QUIET_NAN_MASK;
+
+private:
+ using FloatProperties<T>::QNAN_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 different 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);
@@ -154,7 +157,7 @@ template <typename T> struct FPBits : private FloatProperties<T> {
}
LIBC_INLINE constexpr bool is_quiet_nan() const {
- return (bits & EXP_MANT_MASK) == (EXP_MASK | QUIET_NAN_MASK);
+ return (bits & EXP_MANT_MASK) == (EXP_MASK | QNAN_MASK);
}
LIBC_INLINE constexpr bool is_inf_or_nan() const {
@@ -196,7 +199,7 @@ template <typename T> struct FPBits : private FloatProperties<T> {
}
LIBC_INLINE static constexpr T build_quiet_nan(StorageType v) {
- return build_nan(QUIET_NAN_MASK | v);
+ return build_nan(QNAN_MASK | v);
}
// The function convert integer number and unbiased exponent to proper float
diff --git a/libc/src/__support/FPUtil/FloatProperties.h b/libc/src/__support/FPUtil/FloatProperties.h
index 896c29919e2f77..dd714fde017874 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 =
@@ -166,9 +156,18 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
EXP_MASK | SIG_MASK;
// 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;
+ // QNAN_MASK & bits(x) != 0
+ 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...
+
+ // If a number x is a NAN, then it is a signalling NAN if:
+ // SNAN_MASK & bits(x) != 0
+ 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...
};
//-----------------------------------------------------------------------------
diff --git a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
index 89c47063ebac4d..27435abdd16d4b 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;
- using FloatProperties<long double>::QUIET_NAN_MASK;
+
+private:
+ using FloatProperties<long double>::QNAN_MASK;
+
+public:
using FloatProperties<long double>::SIGN_MASK;
static constexpr int MAX_EXPONENT = 0x7FFF;
@@ -196,7 +200,7 @@ template <> struct FPBits<long double> : private FloatProperties<long double> {
}
LIBC_INLINE static constexpr long double build_quiet_nan(StorageType v) {
- return build_nan(QUIET_NAN_MASK | v);
+ return build_nan(QNAN_MASK | v);
}
LIBC_INLINE static constexpr long double min_normal() {
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);
|
gchatelet
changed the title
[libc][NFC] Make
[libc][NFC] Make Dec 19, 2023
QNAN_MASK
an implementation detailQNAN_MASK
an implementation detail of FPBits
legrosbuffle
approved these changes
Dec 19, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.