[libc-commits] [libc] [libc] Fix compilation of new trig functions (PR #111987)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Fri Oct 11 05:36:22 PDT 2024
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/111987
>From f2e0a33124726498185820beb7d2f3ea3de2b520 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 11 Oct 2024 07:22:15 -0500
Subject: [PATCH 1/3] [libc] Fix compilation of new trig functions
---
libc/src/math/generic/cos.cpp | 4 ++--
libc/src/math/generic/range_reduction_double_common.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/src/math/generic/cos.cpp b/libc/src/math/generic/cos.cpp
index 923ea96852d889..618a96520848a4 100644
--- a/libc/src/math/generic/cos.cpp
+++ b/libc/src/math/generic/cos.cpp
@@ -99,7 +99,7 @@ LLVM_LIBC_FUNCTION(double, cos, (double x)) {
// Fast look up version, but needs 256-entry table.
// -sin(k * pi/128) = sin((k + 128) * pi/128)
// cos(k * pi/128) = sin(k * pi/128 + pi/2) = sin((k + 64) * pi/128).
- DoubleDouble msin_k = SIN_K_PI_OVER_128[(k + 128) & 255];
+ DoubleDouble sin_k = SIN_K_PI_OVER_128[(k + 128) & 255];
DoubleDouble cos_k = SIN_K_PI_OVER_128[(k + 64) & 255];
#endif // LIBC_MATH_HAS_SMALL_TABLES
@@ -108,7 +108,7 @@ LLVM_LIBC_FUNCTION(double, cos, (double x)) {
// Then cos(x) = cos((k * pi/128 + y)
// = cos(y) * cos(k*pi/128) - sin(y) * sin(k*pi/128)
DoubleDouble cos_k_cos_y = fputil::quick_mult(cos_y, cos_k);
- DoubleDouble msin_k_sin_y = fputil::quick_mult(sin_y, msin_k);
+ DoubleDouble msin_k_sin_y = fputil::quick_mult(sin_y, sin_k);
DoubleDouble rr = fputil::exact_add<false>(cos_k_cos_y.hi, msin_k_sin_y.hi);
rr.lo += msin_k_sin_y.lo + cos_k_cos_y.lo;
diff --git a/libc/src/math/generic/range_reduction_double_common.h b/libc/src/math/generic/range_reduction_double_common.h
index e23bbff144bee8..f32bcda70d9b41 100644
--- a/libc/src/math/generic/range_reduction_double_common.h
+++ b/libc/src/math/generic/range_reduction_double_common.h
@@ -278,7 +278,7 @@ struct LargeRangeReduction {
DoubleDouble y_mid;
};
-static Float128 range_reduction_small_f128(double x) {
+[[maybe_unused]] static Float128 range_reduction_small_f128(double x) {
constexpr Float128 PI_OVER_128_F128 = {
Sign::POS, -133, 0xc90f'daa2'2168'c234'c4c6'628b'80dc'1cd1_u128};
constexpr double ONE_TWENTY_EIGHT_OVER_PI_D = 0x1.45f306dc9c883p5;
>From 5ddf84052d75196d84e2e9c3649f2915c3c53ae1 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 11 Oct 2024 07:34:06 -0500
Subject: [PATCH 2/3] comments
---
libc/src/math/generic/cos.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/src/math/generic/cos.cpp b/libc/src/math/generic/cos.cpp
index 618a96520848a4..568b1254c6f02b 100644
--- a/libc/src/math/generic/cos.cpp
+++ b/libc/src/math/generic/cos.cpp
@@ -93,13 +93,13 @@ LLVM_LIBC_FUNCTION(double, cos, (double x)) {
}
return ans;
};
- DoubleDouble sin_k = get_idx_dd(k + 128);
+ DoubleDouble msin_k = get_idx_dd(k + 128);
DoubleDouble cos_k = get_idx_dd(k + 64);
#else
// Fast look up version, but needs 256-entry table.
// -sin(k * pi/128) = sin((k + 128) * pi/128)
// cos(k * pi/128) = sin(k * pi/128 + pi/2) = sin((k + 64) * pi/128).
- DoubleDouble sin_k = SIN_K_PI_OVER_128[(k + 128) & 255];
+ DoubleDouble msin_k = SIN_K_PI_OVER_128[(k + 128) & 255];
DoubleDouble cos_k = SIN_K_PI_OVER_128[(k + 64) & 255];
#endif // LIBC_MATH_HAS_SMALL_TABLES
@@ -108,7 +108,7 @@ LLVM_LIBC_FUNCTION(double, cos, (double x)) {
// Then cos(x) = cos((k * pi/128 + y)
// = cos(y) * cos(k*pi/128) - sin(y) * sin(k*pi/128)
DoubleDouble cos_k_cos_y = fputil::quick_mult(cos_y, cos_k);
- DoubleDouble msin_k_sin_y = fputil::quick_mult(sin_y, sin_k);
+ DoubleDouble msin_k_sin_y = fputil::quick_mult(sin_y, msin_k);
DoubleDouble rr = fputil::exact_add<false>(cos_k_cos_y.hi, msin_k_sin_y.hi);
rr.lo += msin_k_sin_y.lo + cos_k_cos_y.lo;
>From 7ccd9437bc9c86c98f64f5bad3455e821e872979 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 11 Oct 2024 07:36:12 -0500
Subject: [PATCH 3/3] comments
---
libc/src/math/generic/range_reduction_double_common.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/src/math/generic/range_reduction_double_common.h b/libc/src/math/generic/range_reduction_double_common.h
index f32bcda70d9b41..bcab82f6c9c3a8 100644
--- a/libc/src/math/generic/range_reduction_double_common.h
+++ b/libc/src/math/generic/range_reduction_double_common.h
@@ -278,7 +278,8 @@ struct LargeRangeReduction {
DoubleDouble y_mid;
};
-[[maybe_unused]] static Float128 range_reduction_small_f128(double x) {
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+static Float128 range_reduction_small_f128(double x) {
constexpr Float128 PI_OVER_128_F128 = {
Sign::POS, -133, 0xc90f'daa2'2168'c234'c4c6'628b'80dc'1cd1_u128};
constexpr double ONE_TWENTY_EIGHT_OVER_PI_D = 0x1.45f306dc9c883p5;
@@ -300,7 +301,6 @@ struct LargeRangeReduction {
return fputil::quick_mul(y, PI_OVER_128_F128);
}
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
static constexpr Float128 SIN_K_PI_OVER_128_F128[65] = {
{Sign::POS, 0, 0},
{Sign::POS, -133, 0xc90a'afbd'1b33'efc9'c539'edcb'fda0'cf2c_u128},
More information about the libc-commits
mailing list