[libc-commits] [libc] [libc][math][c23] Refactor expf16 (PR #101373)
via libc-commits
libc-commits at lists.llvm.org
Wed Jul 31 10:41:48 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: OverMighty (overmighty)
<details>
<summary>Changes</summary>
Also updates and sorts CMake target dependencies, and corrects the smoke
test that expected expf16(sNaN) to return sNaN instead of aNaN, although
the test still passed, as FPMatcher only checks whether both sides are
NaN, not whether they're the same NaN value.
---
Full diff: https://github.com/llvm/llvm-project/pull/101373.diff
4 Files Affected:
- (modified) libc/src/math/generic/CMakeLists.txt (+2-1)
- (modified) libc/src/math/generic/expf16.cpp (+3-4)
- (modified) libc/test/src/math/performance_testing/expf16_perf.cpp (+1-1)
- (modified) libc/test/src/math/smoke/expf16_test.cpp (+1-1)
``````````diff
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index a4c1318f8a168..e707615e69b97 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1236,11 +1236,12 @@ add_entrypoint_object(
libc.hdr.errno_macros
libc.hdr.fenv_macros
libc.src.__support.CPP.array
+ libc.src.__support.FPUtil.except_value_utils
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
- libc.src.__support.FPUtil.polyeval
libc.src.__support.FPUtil.multiply_add
libc.src.__support.FPUtil.nearest_integer
+ libc.src.__support.FPUtil.polyeval
libc.src.__support.FPUtil.rounding_mode
libc.src.__support.macros.optimization
COMPILE_OPTIONS
diff --git a/libc/src/math/generic/expf16.cpp b/libc/src/math/generic/expf16.cpp
index b618edc36a046..b198c559dfedb 100644
--- a/libc/src/math/generic/expf16.cpp
+++ b/libc/src/math/generic/expf16.cpp
@@ -127,9 +127,8 @@ LLVM_LIBC_FUNCTION(float16, expf16, (float16 x)) {
// > display = hexadecimal;
// > P = fpminimax(expm1(x)/x, 2, [|SG...|], [-2^-5, 2^-5]);
// > 1 + x * P;
- float r =
- fputil::polyeval(xf, 0x1p+0f, 0x1p+0f, 0x1.0004p-1f, 0x1.555778p-3f);
- return static_cast<float16>(r);
+ return static_cast<float16>(
+ fputil::polyeval(xf, 0x1p+0f, 0x1p+0f, 0x1.0004p-1f, 0x1.555778p-3f));
}
}
@@ -150,7 +149,7 @@ LLVM_LIBC_FUNCTION(float16, expf16, (float16 x)) {
// respectively. exp(lo) is computed using a degree-3 minimax polynomial
// generated by Sollya.
- float xf = static_cast<float>(x);
+ float xf = x;
float kf = fputil::nearest_integer(xf * 0x1.0p+3f);
int x_hi_mid = static_cast<int>(kf);
int x_hi = x_hi_mid >> 3;
diff --git a/libc/test/src/math/performance_testing/expf16_perf.cpp b/libc/test/src/math/performance_testing/expf16_perf.cpp
index c1213689ff5e7..bc9d9f05559a3 100644
--- a/libc/test/src/math/performance_testing/expf16_perf.cpp
+++ b/libc/test/src/math/performance_testing/expf16_perf.cpp
@@ -1,4 +1,4 @@
-//===-- Performancel test for expf16 --------------------------------------===//
+//===-- Performance test for expf16 ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/math/smoke/expf16_test.cpp b/libc/test/src/math/smoke/expf16_test.cpp
index f05ecd0dc4d0e..969870fe247bc 100644
--- a/libc/test/src/math/smoke/expf16_test.cpp
+++ b/libc/test/src/math/smoke/expf16_test.cpp
@@ -21,7 +21,7 @@ TEST_F(LlvmLibcExpf16Test, SpecialNumbers) {
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::expf16(aNaN));
EXPECT_MATH_ERRNO(0);
- EXPECT_FP_EQ_WITH_EXCEPTION(sNaN, LIBC_NAMESPACE::expf16(sNaN), FE_INVALID);
+ EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::expf16(sNaN), FE_INVALID);
EXPECT_MATH_ERRNO(0);
EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::expf16(inf));
``````````
</details>
https://github.com/llvm/llvm-project/pull/101373
More information about the libc-commits
mailing list