Skip to content

Commit f69c83f

Browse files
authored
[libc][NFC] Remove ExponentWidth traits (#75362)
Is it redundant with `FloatProperties::EXPONENT_WIDTH` and does bear its weight.
1 parent 7f4f75c commit f69c83f

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

libc/src/__support/FPUtil/FPBits.h

-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ template <typename T> struct MantissaWidth {
2424
static constexpr unsigned VALUE = FloatProperties<T>::MANTISSA_WIDTH;
2525
};
2626

27-
template <typename T> struct ExponentWidth {
28-
static constexpr unsigned VALUE = FloatProperties<T>::EXPONENT_WIDTH;
29-
};
30-
3127
// A generic class to represent single precision, double precision, and quad
3228
// precision IEEE 754 floating point formats.
3329
// On most platforms, the 'float' type corresponds to single precision floating

libc/src/__support/FPUtil/NormalFloat.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ template <typename T> struct NormalFloat {
9292
LIBC_INLINE operator T() const {
9393
int biased_exponent = exponent + FPBits<T>::EXPONENT_BIAS;
9494
// Max exponent is of the form 0xFF...E. That is why -2 and not -1.
95-
constexpr int MAX_EXPONENT_VALUE = (1 << ExponentWidth<T>::VALUE) - 2;
95+
constexpr int MAX_EXPONENT_VALUE = (1 << FPBits<T>::EXPONENT_WIDTH) - 2;
9696
if (biased_exponent > MAX_EXPONENT_VALUE) {
9797
return sign ? T(FPBits<T>::neg_inf()) : T(FPBits<T>::inf());
9898
}
@@ -208,18 +208,18 @@ NormalFloat<long double>::init_from_bits(FPBits<long double> bits) {
208208
}
209209

210210
template <> LIBC_INLINE NormalFloat<long double>::operator long double() const {
211-
int biased_exponent = exponent + FPBits<long double>::EXPONENT_BIAS;
211+
using LDBits = FPBits<long double>;
212+
int biased_exponent = exponent + LDBits::EXPONENT_BIAS;
212213
// Max exponent is of the form 0xFF...E. That is why -2 and not -1.
213-
constexpr int MAX_EXPONENT_VALUE =
214-
(1 << ExponentWidth<long double>::VALUE) - 2;
214+
constexpr int MAX_EXPONENT_VALUE = (1 << LDBits::EXPONENT_WIDTH) - 2;
215215
if (biased_exponent > MAX_EXPONENT_VALUE) {
216-
return sign ? FPBits<long double>::neg_inf() : FPBits<long double>::inf();
216+
return sign ? LDBits::neg_inf() : LDBits::inf();
217217
}
218218

219219
FPBits<long double> result(0.0l);
220220
result.set_sign(sign);
221221

222-
constexpr int SUBNORMAL_EXPONENT = -FPBits<long double>::EXPONENT_BIAS + 1;
222+
constexpr int SUBNORMAL_EXPONENT = -LDBits::EXPONENT_BIAS + 1;
223223
if (exponent < SUBNORMAL_EXPONENT) {
224224
unsigned shift = SUBNORMAL_EXPONENT - exponent;
225225
if (shift <= MantissaWidth<long double>::VALUE + 1) {

libc/src/stdio/printf_core/float_hex_converter.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
namespace LIBC_NAMESPACE {
2626
namespace printf_core {
2727

28-
using MantissaInt = fputil::FPBits<long double>::UIntType;
29-
3028
LIBC_INLINE int convert_float_hex_exp(Writer *writer,
3129
const FormatSection &to_conv) {
30+
using LDBits = fputil::FPBits<long double>;
31+
using MantissaInt = LDBits::UIntType;
3232
// All of the letters will be defined relative to variable a, which will be
3333
// the appropriate case based on the name of the conversion. This converts any
3434
// conversion name into the letter 'a' with the appropriate case.
@@ -40,18 +40,19 @@ LIBC_INLINE int convert_float_hex_exp(Writer *writer,
4040
bool is_inf_or_nan;
4141
uint32_t mantissa_width;
4242
if (to_conv.length_modifier == LengthModifier::L) {
43-
mantissa_width = fputil::MantissaWidth<long double>::VALUE;
44-
fputil::FPBits<long double>::UIntType float_raw = to_conv.conv_val_raw;
45-
fputil::FPBits<long double> float_bits(float_raw);
43+
mantissa_width = LDBits::MANTISSA_WIDTH;
44+
LDBits::UIntType float_raw = to_conv.conv_val_raw;
45+
LDBits float_bits(float_raw);
4646
is_negative = float_bits.get_sign();
4747
exponent = float_bits.get_explicit_exponent();
4848
mantissa = float_bits.get_explicit_mantissa();
4949
is_inf_or_nan = float_bits.is_inf_or_nan();
5050
} else {
51-
mantissa_width = fputil::MantissaWidth<double>::VALUE;
52-
fputil::FPBits<double>::UIntType float_raw =
53-
static_cast<fputil::FPBits<double>::UIntType>(to_conv.conv_val_raw);
54-
fputil::FPBits<double> float_bits(float_raw);
51+
using LBits = fputil::FPBits<double>;
52+
mantissa_width = LBits::MANTISSA_WIDTH;
53+
LBits::UIntType float_raw =
54+
static_cast<LBits::UIntType>(to_conv.conv_val_raw);
55+
LBits float_bits(float_raw);
5556
is_negative = float_bits.get_sign();
5657
exponent = float_bits.get_explicit_exponent();
5758
mantissa = float_bits.get_explicit_mantissa();
@@ -157,8 +158,7 @@ LIBC_INLINE int convert_float_hex_exp(Writer *writer,
157158
// 15 -> 5
158159
// 11 -> 4
159160
// 8 -> 3
160-
constexpr size_t EXP_LEN =
161-
(((fputil::ExponentWidth<long double>::VALUE * 5) + 15) / 16) + 1;
161+
constexpr size_t EXP_LEN = (((LDBits::EXPONENT_WIDTH * 5) + 15) / 16) + 1;
162162
char exp_buffer[EXP_LEN];
163163

164164
bool exp_is_negative = false;

0 commit comments

Comments
 (0)