aboutsummaryrefslogtreecommitdiff
path: root/libc/src/math/generic/powf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/src/math/generic/powf.cpp')
-rw-r--r--libc/src/math/generic/powf.cpp44
1 files changed, 21 insertions, 23 deletions
diff --git a/libc/src/math/generic/powf.cpp b/libc/src/math/generic/powf.cpp
index 8470eb8..49f33b7 100644
--- a/libc/src/math/generic/powf.cpp
+++ b/libc/src/math/generic/powf.cpp
@@ -387,24 +387,24 @@ static constexpr DoubleDouble LOG2_R2_DD[] = {
};
LIBC_INLINE bool is_odd_integer(float x) {
- using FloatProp = typename fputil::FloatProperties<float>;
+ using FPBits = typename fputil::FPBits<float>;
uint32_t x_u = cpp::bit_cast<uint32_t>(x);
- int32_t x_e = static_cast<int32_t>((x_u & FloatProp::EXP_MASK) >>
- FloatProp::FRACTION_LEN);
- int32_t lsb = cpp::countr_zero(x_u | FloatProp::EXP_MASK);
+ int32_t x_e =
+ static_cast<int32_t>((x_u & FPBits::EXP_MASK) >> FPBits::FRACTION_LEN);
+ int32_t lsb = cpp::countr_zero(x_u | FPBits::EXP_MASK);
constexpr int32_t UNIT_EXPONENT =
- FloatProp::EXP_BIAS + static_cast<int32_t>(FloatProp::FRACTION_LEN);
+ FPBits::EXP_BIAS + static_cast<int32_t>(FPBits::FRACTION_LEN);
return (x_e + lsb == UNIT_EXPONENT);
}
LIBC_INLINE bool is_integer(float x) {
- using FloatProp = typename fputil::FloatProperties<float>;
+ using FPBits = typename fputil::FPBits<float>;
uint32_t x_u = cpp::bit_cast<uint32_t>(x);
- int32_t x_e = static_cast<int32_t>((x_u & FloatProp::EXP_MASK) >>
- FloatProp::FRACTION_LEN);
- int32_t lsb = cpp::countr_zero(x_u | FloatProp::EXP_MASK);
+ int32_t x_e =
+ static_cast<int32_t>((x_u & FPBits::EXP_MASK) >> FPBits::FRACTION_LEN);
+ int32_t lsb = cpp::countr_zero(x_u | FPBits::EXP_MASK);
constexpr int32_t UNIT_EXPONENT =
- FloatProp::EXP_BIAS + static_cast<int32_t>(FloatProp::FRACTION_LEN);
+ FPBits::EXP_BIAS + static_cast<int32_t>(FPBits::FRACTION_LEN);
return (x_e + lsb >= UNIT_EXPONENT);
}
@@ -424,7 +424,6 @@ LIBC_INLINE bool larger_exponent(double a, double b) {
double powf_double_double(int idx_x, double dx, double y6, double lo6_hi,
const DoubleDouble &exp2_hi_mid) {
using DoubleBits = typename fputil::FPBits<double>;
- using DoubleProp = typename fputil::FloatProperties<double>;
// Perform a second range reduction step:
// idx2 = round(2^14 * (dx + 2^-8)) = round ( dx * 2^14 + 2^6)
// dx2 = (1 + dx) * r2 - 1
@@ -500,7 +499,7 @@ double powf_double_double(int idx_x, double dx, double y6, double lo6_hi,
bool lo_sign = DoubleBits(r.lo).get_sign();
if (hi_sign == lo_sign) {
++r_bits;
- } else if ((r_bits & DoubleProp::FRACTION_MASK) > 0) {
+ } else if ((r_bits & DoubleBits::FRACTION_MASK) > 0) {
--r_bits;
}
}
@@ -512,8 +511,7 @@ double powf_double_double(int idx_x, double dx, double y6, double lo6_hi,
LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
using FloatBits = typename fputil::FPBits<float>;
- using FloatProp = typename fputil::FloatProperties<float>;
- using DoubleProp = typename fputil::FloatProperties<double>;
+ using DoubleBits = typename fputil::FPBits<double>;
FloatBits xbits(x), ybits(y);
uint32_t x_u = xbits.uintval();
@@ -584,7 +582,7 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
// x^y will be overflow / underflow in single precision. Set y to a
// large enough exponent but not too large, so that the computations
// won't be overflow in double precision.
- y = cpp::bit_cast<float>((y_u & FloatProp::SIGN_MASK) + 0x4f800000U);
+ y = cpp::bit_cast<float>((y_u & FloatBits::SIGN_MASK) + 0x4f800000U);
}
}
}
@@ -607,11 +605,11 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
return generic::exp10f(y);
}
- bool x_sign = x_u >= FloatProp::SIGN_MASK;
+ bool x_sign = x_u >= FloatBits::SIGN_MASK;
switch (x_abs) {
case 0x0000'0000: { // x = +-0.0f
- bool x_sign = (x_u >= FloatProp::SIGN_MASK);
+ bool x_sign = (x_u >= FloatBits::SIGN_MASK);
bool out_sign = x_sign && is_odd_integer(FloatBits(y_u).get_val());
if (y_u > 0x8000'0000U) {
// pow(0, negative number) = inf
@@ -623,9 +621,9 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
return out_sign ? -0.0f : 0.0f;
}
case 0x7f80'0000: { // x = +-Inf
- bool x_sign = (x_u >= FloatProp::SIGN_MASK);
+ bool x_sign = (x_u >= FloatBits::SIGN_MASK);
bool out_sign = x_sign && is_odd_integer(FloatBits(y_u).get_val());
- if (y_u >= FloatProp::SIGN_MASK) {
+ if (y_u >= FloatBits::SIGN_MASK) {
return out_sign ? -0.0f : 0.0f;
}
return FloatBits::inf(out_sign);
@@ -669,11 +667,11 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
x_u = FloatBits(x).uintval();
// Extract exponent field of x.
- ex += (x_u >> FloatProp::FRACTION_LEN);
+ ex += (x_u >> FloatBits::FRACTION_LEN);
double e_x = static_cast<double>(ex);
// Use the highest 7 fractional bits of m_x as the index for look up tables.
- uint32_t x_mant = x_u & FloatProp::FRACTION_MASK;
- int idx_x = static_cast<int>(x_mant >> (FloatProp::FRACTION_LEN - 7));
+ uint32_t x_mant = x_u & FloatBits::FRACTION_MASK;
+ int idx_x = static_cast<int>(x_mant >> (FloatBits::FRACTION_LEN - 7));
// Add the hidden bit to the mantissa.
// 1 <= m_x < 2
float m_x = cpp::bit_cast<float>(x_mant | 0x3f800000);
@@ -774,7 +772,7 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
int idx_y = hm_i & 0x3f;
// 2^hi
- int64_t exp_hi_i = (hm_i >> 6) << DoubleProp::FRACTION_LEN;
+ int64_t exp_hi_i = (hm_i >> 6) << DoubleBits::FRACTION_LEN;
// 2^mid
int64_t exp_mid_i = cpp::bit_cast<uint64_t>(EXP2_MID1[idx_y].hi);
// (-1)^sign * 2^hi * 2^mid