Skip to content

Commit 1e47a15

Browse files
authored
[libc][NFC] Remove last use of BitsType in FloatProperties (#75174)
Also start to expose some of the internals to avoid duplication.
1 parent 0e9879e commit 1e47a15

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

libc/src/__support/FPUtil/FPBits.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ template <typename T> struct FPBits {
4444
// integer value as a floating point value is used in tests. So, a convenient
4545
// type is provided for such reinterpretations.
4646
using FloatProp = FloatProperties<T>;
47-
// TODO: Change UintType name to BitsType for consistency.
48-
using UIntType = typename FloatProp::BitsType;
47+
using UIntType = typename FloatProp::UIntType;
4948

5049
UIntType bits;
5150

libc/src/__support/FPUtil/FloatProperties.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
9090
using UP::EXP_BITS;
9191
using UP::SIG_BITS;
9292
using UP::TOTAL_BITS;
93+
94+
public:
9395
using UIntType = typename UP::UIntType;
9496

97+
private:
9598
LIBC_INLINE_VAR static constexpr int STORAGE_BITS =
9699
sizeof(UIntType) * CHAR_BIT;
97100
static_assert(STORAGE_BITS >= TOTAL_BITS);
@@ -116,14 +119,16 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
116119
mask_trailing_ones<UIntType, SIG_BITS>() << SIG_MASK_SHIFT;
117120
LIBC_INLINE_VAR static constexpr UIntType EXP_MASK =
118121
mask_trailing_ones<UIntType, EXP_BITS>() << EXP_MASK_SHIFT;
119-
// Trailing underscore on SIGN_MASK_ is temporary - it will be removed
120-
// once we can replace the public part below with the private one.
121-
LIBC_INLINE_VAR static constexpr UIntType SIGN_MASK_ =
122+
123+
public:
124+
LIBC_INLINE_VAR static constexpr UIntType SIGN_MASK =
122125
mask_trailing_ones<UIntType, SIGN_BITS>() << SIGN_MASK_SHIFT;
126+
127+
private:
123128
LIBC_INLINE_VAR static constexpr UIntType FP_MASK =
124129
mask_trailing_ones<UIntType, TOTAL_BITS>();
125-
static_assert((SIG_MASK & EXP_MASK & SIGN_MASK_) == 0, "masks disjoint");
126-
static_assert((SIG_MASK | EXP_MASK | SIGN_MASK_) == FP_MASK, "masks cover");
130+
static_assert((SIG_MASK & EXP_MASK & SIGN_MASK) == 0, "masks disjoint");
131+
static_assert((SIG_MASK | EXP_MASK | SIGN_MASK) == FP_MASK, "masks cover");
127132

128133
LIBC_INLINE static constexpr UIntType bit_at(int position) {
129134
return UIntType(1) << position;
@@ -145,25 +150,21 @@ struct FPProperties : public internal::FPBaseProperties<fp_type> {
145150
: SIG_BITS;
146151

147152
public:
148-
// Public facing API to keep the change local to this file.
149-
using BitsType = UIntType;
150-
151153
LIBC_INLINE_VAR static constexpr uint32_t BIT_WIDTH = TOTAL_BITS;
152154
LIBC_INLINE_VAR static constexpr uint32_t MANTISSA_WIDTH = FRACTION_BITS;
153155
LIBC_INLINE_VAR static constexpr uint32_t MANTISSA_PRECISION =
154156
MANTISSA_WIDTH + 1;
155-
LIBC_INLINE_VAR static constexpr BitsType MANTISSA_MASK =
157+
LIBC_INLINE_VAR static constexpr UIntType MANTISSA_MASK =
156158
mask_trailing_ones<UIntType, MANTISSA_WIDTH>();
157159
LIBC_INLINE_VAR static constexpr uint32_t EXPONENT_WIDTH = EXP_BITS;
158160
LIBC_INLINE_VAR static constexpr int32_t EXPONENT_BIAS = EXP_BIAS;
159-
LIBC_INLINE_VAR static constexpr BitsType SIGN_MASK = SIGN_MASK_;
160-
LIBC_INLINE_VAR static constexpr BitsType EXPONENT_MASK = EXP_MASK;
161-
LIBC_INLINE_VAR static constexpr BitsType EXP_MANT_MASK = EXP_MASK | SIG_MASK;
161+
LIBC_INLINE_VAR static constexpr UIntType EXPONENT_MASK = EXP_MASK;
162+
LIBC_INLINE_VAR static constexpr UIntType EXP_MANT_MASK = EXP_MASK | SIG_MASK;
162163

163164
// If a number x is a NAN, then it is a quiet NAN if:
164165
// QuietNaNMask & bits(x) != 0
165166
// Else, it is a signalling NAN.
166-
static constexpr BitsType QUIET_NAN_MASK = QNAN_MASK;
167+
static constexpr UIntType QUIET_NAN_MASK = QNAN_MASK;
167168
};
168169

169170
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)