Skip to content

[libc][math][c23] Refactor expf16 #101373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

overmighty
Copy link
Member

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.

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.
@overmighty overmighty requested a review from lntue July 31, 2024 17:41
@llvmbot llvmbot added the libc label Jul 31, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 31, 2024

@llvm/pr-subscribers-libc

Author: OverMighty (overmighty)

Changes

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 --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));

@overmighty overmighty merged commit b66aa3b into llvm:main Jul 31, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants