-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[libc][NFC] Remove remaining specializations in FloatProperties #75165
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
Merged
Conversation
This file contains hidden or 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
This patch sinks `EXPLICIT_BIT_MASK` into `get_explicit_mantissa` - the only function using it. Then it sinks the content of `FPCommonProperties` directly into `FPProperties`.
@llvm/pr-subscribers-libc Author: Guillaume Chatelet (gchatelet) ChangesThis patch sinks Full diff: https://github.com/llvm/llvm-project/pull/75165.diff 2 Files Affected:
diff --git a/libc/src/__support/FPUtil/FloatProperties.h b/libc/src/__support/FPUtil/FloatProperties.h
index ef6a3cd403db6..0144404d952c0 100644
--- a/libc/src/__support/FPUtil/FloatProperties.h
+++ b/libc/src/__support/FPUtil/FloatProperties.h
@@ -90,13 +90,12 @@ template <typename T, size_t count> static constexpr T mask_trailing_ones() {
return count == 0 ? 0 : ((~T(0)) >> (t_bits - count));
}
-// Derives more properties from 'FPBaseProperties' above.
-// This class serves as a halfway point between 'FPBaseProperties' and
-// 'FPProperties' below.
+} // namespace internal
+
template <FPType fp_type>
-struct FPCommonProperties : private FPBaseProperties<fp_type> {
+struct FPProperties : public internal::FPBaseProperties<fp_type> {
private:
- using UP = FPBaseProperties<fp_type>;
+ using UP = internal::FPBaseProperties<fp_type>;
using UP::EXP_BITS;
using UP::SIG_BITS;
using UP::TOTAL_BITS;
@@ -123,15 +122,15 @@ struct FPCommonProperties : private FPBaseProperties<fp_type> {
// Masks
LIBC_INLINE_VAR static constexpr UIntType SIG_MASK =
- mask_trailing_ones<UIntType, SIG_BITS>() << SIG_MASK_SHIFT;
+ internal::mask_trailing_ones<UIntType, SIG_BITS>() << SIG_MASK_SHIFT;
LIBC_INLINE_VAR static constexpr UIntType EXP_MASK =
- mask_trailing_ones<UIntType, EXP_BITS>() << EXP_MASK_SHIFT;
+ internal::mask_trailing_ones<UIntType, EXP_BITS>() << EXP_MASK_SHIFT;
// Trailing underscore on SIGN_MASK_ is temporary - it will be removed
// once we can replace the public part below with the private one.
LIBC_INLINE_VAR static constexpr UIntType SIGN_MASK_ =
- mask_trailing_ones<UIntType, SIGN_BITS>() << SIGN_MASK_SHIFT;
+ internal::mask_trailing_ones<UIntType, SIGN_BITS>() << SIGN_MASK_SHIFT;
LIBC_INLINE_VAR static constexpr UIntType FP_MASK =
- mask_trailing_ones<UIntType, TOTAL_BITS>();
+ internal::mask_trailing_ones<UIntType, TOTAL_BITS>();
static_assert((SIG_MASK & EXP_MASK & SIGN_MASK_) == 0, "masks disjoint");
static_assert((SIG_MASK | EXP_MASK | SIGN_MASK_) == FP_MASK, "masks cover");
@@ -140,19 +139,19 @@ struct FPCommonProperties : private FPBaseProperties<fp_type> {
}
LIBC_INLINE_VAR static constexpr UIntType QNAN_MASK =
- UP::ENCODING == FPEncoding::X86_ExtendedPrecision
+ UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
? bit_at(SIG_BITS - 1) | bit_at(SIG_BITS - 2) // 0b1100...
: bit_at(SIG_BITS - 1); // 0b1000...
LIBC_INLINE_VAR static constexpr UIntType SNAN_MASK =
- UP::ENCODING == FPEncoding::X86_ExtendedPrecision
+ UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
? bit_at(SIG_BITS - 1) | bit_at(SIG_BITS - 3) // 0b1010...
: bit_at(SIG_BITS - 2); // 0b0100...
// The number of bits after the decimal dot when the number if in normal form.
LIBC_INLINE_VAR static constexpr int FRACTION_BITS =
- UP::ENCODING == FPEncoding::X86_ExtendedPrecision ? SIG_BITS - 1
- : SIG_BITS;
+ UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision ? SIG_BITS - 1
+ : SIG_BITS;
public:
// Public facing API to keep the change local to this file.
@@ -163,7 +162,7 @@ struct FPCommonProperties : private FPBaseProperties<fp_type> {
LIBC_INLINE_VAR static constexpr uint32_t MANTISSA_PRECISION =
MANTISSA_WIDTH + 1;
LIBC_INLINE_VAR static constexpr BitsType MANTISSA_MASK =
- mask_trailing_ones<UIntType, MANTISSA_WIDTH>();
+ internal::mask_trailing_ones<UIntType, MANTISSA_WIDTH>();
LIBC_INLINE_VAR static constexpr uint32_t EXPONENT_WIDTH = EXP_BITS;
LIBC_INLINE_VAR static constexpr uint32_t EXPONENT_BIAS =
static_cast<uint32_t>(EXP_BIAS);
@@ -177,29 +176,6 @@ struct FPCommonProperties : private FPBaseProperties<fp_type> {
static constexpr BitsType QUIET_NAN_MASK = QNAN_MASK;
};
-} // namespace internal
-
-template <FPType fp_type>
-struct FPProperties : public internal::FPCommonProperties<fp_type> {};
-
-// ----------------
-// Work In Progress
-// ----------------
-// The 'FPProperties' template specializations below are being slowly replaced
-// with properties from 'FPCommonProperties' above. Once specializations are
-// empty, 'FPProperties' declaration can be fully replace with
-// 'FPCommonProperties' implementation.
-
-// Properties for numbers represented in 80 bits long double on non-Windows x86
-// platforms.
-template <>
-struct FPProperties<FPType::X86_Binary80>
- : public internal::FPCommonProperties<FPType::X86_Binary80> {
- // 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);
-};
-
//-----------------------------------------------------------------------------
template <typename FP> LIBC_INLINE static constexpr FPType get_fp_type() {
if constexpr (cpp::is_same_v<FP, float> && __FLT_MANT_DIG__ == 24)
diff --git a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
index bbc30ff7a376d..60953313a695c 100644
--- a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
+++ b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
@@ -68,7 +68,11 @@ template <> struct FPBits<long double> {
}
LIBC_INLINE constexpr UIntType get_explicit_mantissa() const {
- return bits & (FloatProp::MANTISSA_MASK | FloatProp::EXPLICIT_BIT_MASK);
+ // The x86 80 bit float represents the leading digit of the mantissa
+ // explicitly. This is the mask for that bit.
+ constexpr UIntType EXPLICIT_BIT_MASK =
+ (UIntType(1) << FloatProp::MANTISSA_WIDTH);
+ return bits & (FloatProp::MANTISSA_MASK | EXPLICIT_BIT_MASK);
}
LIBC_INLINE constexpr void set_biased_exponent(UIntType expVal) {
|
legrosbuffle
approved these changes
Dec 12, 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.
This patch sinks
EXPLICIT_BIT_MASK
intoget_explicit_mantissa
- the only function using it. Then it sinks the content ofFPCommonProperties
directly intoFPProperties
.