aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlntue <35648136+lntue@users.noreply.github.com>2023-12-08 09:54:21 -0500
committerGitHub <noreply@github.com>2023-12-08 09:54:21 -0500
commitb8f7c2ce89d6da34eb68fde76eec9bbdaed87619 (patch)
treec1ce1ff812447d17eb2ceea3856ed67ac66fc526
parent4a2a6397f11da7c15a73d19fb1e6c9dcd1ceb5af (diff)
downloadllvm-b8f7c2ce89d6da34eb68fde76eec9bbdaed87619.zip
llvm-b8f7c2ce89d6da34eb68fde76eec9bbdaed87619.tar.gz
llvm-b8f7c2ce89d6da34eb68fde76eec9bbdaed87619.tar.bz2
[libc][NFC] Clean up conversion warnings in math function implementations. (#74697)
-rw-r--r--libc/src/__support/FPUtil/Hypot.h2
-rw-r--r--libc/src/__support/FPUtil/dyadic_float.h6
-rw-r--r--libc/src/math/generic/explogxf.h3
-rw-r--r--libc/src/math/generic/log.cpp2
-rw-r--r--libc/src/math/generic/log10.cpp2
-rw-r--r--libc/src/math/generic/log1p.cpp5
-rw-r--r--libc/src/math/generic/log1pf.cpp4
-rw-r--r--libc/src/math/generic/log2.cpp2
8 files changed, 14 insertions, 12 deletions
diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index 8a6eb4b..fb04d8a 100644
--- a/libc/src/__support/FPUtil/Hypot.h
+++ b/libc/src/__support/FPUtil/Hypot.h
@@ -178,7 +178,7 @@ LIBC_INLINE T hypot(T x, T y) {
// But before that, remember to store the losing bits to sticky.
// The shift length is for a^2 and b^2, so it's double of the exponent
// difference between a and b.
- uint16_t shift_length = 2 * (a_exp - b_exp);
+ uint16_t shift_length = static_cast<uint16_t>(2 * (a_exp - b_exp));
sticky_bits =
((b_mant_sq & ((DUIntType(1) << shift_length) - DUIntType(1))) !=
DUIntType(0));
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index b792094..5f0d8f4 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -94,7 +94,7 @@ template <size_t Bits> struct DyadicFloat {
return 0.0;
// Assume that it is normalized, and output is also normal.
- constexpr size_t PRECISION = FloatProperties<T>::MANTISSA_WIDTH + 1;
+ constexpr uint32_t PRECISION = FloatProperties<T>::MANTISSA_PRECISION;
using output_bits_t = typename FPBits<T>::UIntType;
int exp_hi = exponent + static_cast<int>((Bits - 1) +
@@ -110,12 +110,12 @@ template <size_t Bits> struct DyadicFloat {
exp_hi = FloatProperties<T>::EXPONENT_BIAS;
}
- int exp_lo = exp_hi - PRECISION - 1;
+ int exp_lo = exp_hi - static_cast<int>(PRECISION) - 1;
MantissaType m_hi(mantissa >> shift);
T d_hi = FPBits<T>::create_value(sign, exp_hi,
- output_bits_t(m_hi) &
+ static_cast<output_bits_t>(m_hi) &
FloatProperties<T>::MANTISSA_MASK)
.get_val();
diff --git a/libc/src/math/generic/explogxf.h b/libc/src/math/generic/explogxf.h
index 512785b..156c24c 100644
--- a/libc/src/math/generic/explogxf.h
+++ b/libc/src/math/generic/explogxf.h
@@ -311,7 +311,8 @@ LIBC_INLINE static double log_eval(double x) {
// p1 is the leading 7 bits of mx, i.e.
// p1 * 2^(-7) <= m_x < (p1 + 1) * 2^(-7).
- int p1 = (bs.get_mantissa() >> (FPB::FloatProp::MANTISSA_WIDTH - 7));
+ int p1 = static_cast<int>(bs.get_mantissa() >>
+ (FPB::FloatProp::MANTISSA_WIDTH - 7));
// Set bs to (1 + (mx - p1*2^(-7))
bs.bits &= FPB::FloatProp::MANTISSA_MASK >> 7;
diff --git a/libc/src/math/generic/log.cpp b/libc/src/math/generic/log.cpp
index 46b64df..dfa41ad 100644
--- a/libc/src/math/generic/log.cpp
+++ b/libc/src/math/generic/log.cpp
@@ -769,7 +769,7 @@ LLVM_LIBC_FUNCTION(double, log, (double x)) {
// Range reduction for log(x_m):
// For each x_m, we would like to find r such that:
// -2^-8 <= r * x_m - 1 < 2^-7
- int shifted = x_u >> 45;
+ int shifted = static_cast<int>(x_u >> 45);
int index = shifted & 0x7F;
double r = RD[index];
diff --git a/libc/src/math/generic/log10.cpp b/libc/src/math/generic/log10.cpp
index 38789ac..2a801c6 100644
--- a/libc/src/math/generic/log10.cpp
+++ b/libc/src/math/generic/log10.cpp
@@ -770,7 +770,7 @@ LLVM_LIBC_FUNCTION(double, log10, (double x)) {
// Range reduction for log10(x_m):
// For each x_m, we would like to find r such that:
// -2^-8 <= r * x_m - 1 < 2^-7
- int shifted = x_u >> 45;
+ int shifted = static_cast<int>(x_u >> 45);
int index = shifted & 0x7F;
double r = RD[index];
diff --git a/libc/src/math/generic/log1p.cpp b/libc/src/math/generic/log1p.cpp
index c6ee8d8..02299e2 100644
--- a/libc/src/math/generic/log1p.cpp
+++ b/libc/src/math/generic/log1p.cpp
@@ -949,8 +949,9 @@ LLVM_LIBC_FUNCTION(double, log1p, (double x)) {
x_u = xhi_bits.uintval();
// Range reduction:
// Find k such that |x_hi - k * 2^-7| <= 2^-8.
- int idx = ((x_u & MANTISSA_MASK) + (1ULL << (MANTISSA_WIDTH - 8))) >>
- (MANTISSA_WIDTH - 7);
+ int idx = static_cast<int>(
+ ((x_u & MANTISSA_MASK) + (1ULL << (MANTISSA_WIDTH - 8))) >>
+ (MANTISSA_WIDTH - 7));
int x_e = xhi_bits.get_exponent() + (idx >> 7);
double e_x = static_cast<double>(x_e);
diff --git a/libc/src/math/generic/log1pf.cpp b/libc/src/math/generic/log1pf.cpp
index 5b4e7edc..023387d 100644
--- a/libc/src/math/generic/log1pf.cpp
+++ b/libc/src/math/generic/log1pf.cpp
@@ -56,8 +56,8 @@ LIBC_INLINE float log(double x) {
// Get the 8 highest bits, use 7 bits (excluding the implicit hidden bit) for
// lookup tables.
- int f_index =
- xbits.get_mantissa() >> 45; // fputil::MantissaWidth<double>::VALUE - 7
+ int f_index = static_cast<int>(
+ xbits.get_mantissa() >> 45); // fputil::MantissaWidth<double>::VALUE - 7
// Set bits to 1.m
xbits.set_unbiased_exponent(0x3FF);
diff --git a/libc/src/math/generic/log2.cpp b/libc/src/math/generic/log2.cpp
index d72b093..2ceddf8 100644
--- a/libc/src/math/generic/log2.cpp
+++ b/libc/src/math/generic/log2.cpp
@@ -890,7 +890,7 @@ LLVM_LIBC_FUNCTION(double, log2, (double x)) {
// Range reduction for log2(x_m):
// For each x_m, we would like to find r such that:
// -2^-8 <= r * x_m - 1 < 2^-7
- int shifted = x_u >> 45;
+ int shifted = static_cast<int>(x_u >> 45);
int index = shifted & 0x7F;
double r = RD[index];