[libc-commits] [libc] [libc][math] Move CR/RN expf to float_eval_cr_rn namespace (PR #237614)

via libc-commits libc-commits at lists.llvm.org
Sat Oct 31 12:21:59 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Leandro Lacerda (leandrolcampos)

<details>
<summary>Changes</summary>

Rename `math::float_eval::cr_expf_rn` to `math::float_eval_cr_rn::expf` and restore namespace-based implementation selection with `using`, removing the forwarding wrapper.

Also register the missing `check.exp_exceptions` CMake target, which caused CMake to skip the tests:

```text
Skipping test libc.test.src.math.expf_test as it has missing deps:
libc.src.__support.math.check.exp_exceptions.
```

---
Full diff: https://github.com/llvm/llvm-project/pull/237614.diff


8 Files Affected:

- (modified) libc/src/__support/math/CMakeLists.txt (+2) 
- (added) libc/src/__support/math/check/CMakeLists.txt (+10) 
- (modified) libc/src/__support/math/expf.h (+5-5) 
- (modified) libc/src/__support/math/expf_float_eval.h (+8-4) 
- (modified) libc/src/__support/math/expf_float_utils.h (+4-4) 
- (modified) libc/test/src/math/exhaustive/expf_test.cpp (+4-3) 
- (modified) libc/test/src/math/expf_test.cpp (+1-1) 
- (modified) libc/test/src/math/smoke/expf_test.cpp (+1-1) 


``````````diff
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index da3a3fcb3dd366..bf87c405cc0814 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1,3 +1,5 @@
+add_subdirectory(check)
+
 add_header_library(
   acos
   HDRS
diff --git a/libc/src/__support/math/check/CMakeLists.txt b/libc/src/__support/math/check/CMakeLists.txt
new file mode 100644
index 00000000000000..31d901f900a8a5
--- /dev/null
+++ b/libc/src/__support/math/check/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_header_library(
+  exp_exceptions
+  HDRS
+    exp_exceptions.h
+  DEPENDS
+    libc.hdr.fenv_macros
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.common
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/math/expf.h b/libc/src/__support/math/expf.h
index d53d19cfc78475..c60450c1f6f558 100644
--- a/libc/src/__support/math/expf.h
+++ b/libc/src/__support/math/expf.h
@@ -27,33 +27,33 @@
     defined(LIBC_MATH_HAS_NO_EXCEPT) && defined(LIBC_MATH_HAS_NO_ERRNO)
 
 #include "src/__support/math/expf_float_eval.h"
-#define LIBC_MATH_EXPF_IMPL float_eval::cr_expf_rn
+#define LIBC_MATH_EXPF_IMPL float_eval_cr_rn
 
 #elif defined(LIBC_MATH_HAS_SKIP_ACCURATE_PASS) &&                             \
     (defined(LIBC_MATH_HAS_SMALL_TABLES) ||                                    \
      defined(LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT))
 
 #include "src/__support/math/expf_float_eval.h"
-#define LIBC_MATH_EXPF_IMPL float_eval::expf
+#define LIBC_MATH_EXPF_IMPL float_eval
 
 #elif !defined(LIBC_TARGET_CPU_HAS_FPU_DOUBLE) &&                              \
     defined(LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY) &&                        \
     defined(LIBC_MATH_HAS_NO_EXCEPT) && defined(LIBC_MATH_HAS_NO_ERRNO)
 
 #include "src/__support/math/expf_integer_eval.h"
-#define LIBC_MATH_EXPF_IMPL integer_eval::expf
+#define LIBC_MATH_EXPF_IMPL integer_eval
 
 #else
 
 #include "src/__support/math/expf_double_eval.h"
-#define LIBC_MATH_EXPF_IMPL double_eval::expf
+#define LIBC_MATH_EXPF_IMPL double_eval
 
 #endif
 
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE float expf(float x) { return LIBC_MATH_EXPF_IMPL(x); }
+using LIBC_MATH_EXPF_IMPL::expf;
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/math/expf_float_eval.h b/libc/src/__support/math/expf_float_eval.h
index a9f49751ac2495..5df8f80ff15540 100644
--- a/libc/src/__support/math/expf_float_eval.h
+++ b/libc/src/__support/math/expf_float_eval.h
@@ -123,10 +123,14 @@ LIBC_INLINE float expf(float x) {
   return exp2f_eval(u, k);
 }
 
+} // namespace float_eval
+
+namespace float_eval_cr_rn {
+
 // Designed for GPU performance. Correctly rounded only in round-to-nearest,
 // ties-to-even mode. Requires single-precision FMA. Does not support errno
 // or floating-point exception reporting.
-LIBC_INLINE float cr_expf_rn(float x) {
+LIBC_INLINE float expf(float x) {
   using FPBits = fputil::FPBits<float>;
   using FPBounds = math::check::exp_internal::Bounds<float>;
 
@@ -179,10 +183,10 @@ LIBC_INLINE float cr_expf_rn(float x) {
   u.lo += u_lo.lo;
 
   // Polynomial approximation: e^u
-  fputil::FloatFloat exp_u = cr_expf_rn_internal::exp_eval(u);
+  fputil::FloatFloat exp_u = expf_internal::exp_eval(u);
 
   // Reconstruction: 2^k * e^u
-  float res = cr_expf_rn_internal::scale_result(exp_u, k, produces_subnormal);
+  float res = expf_internal::scale_result(exp_u, k, produces_subnormal);
 
   // Special cases
   constexpr float INF = FPBits::inf().get_val();
@@ -194,7 +198,7 @@ LIBC_INLINE float cr_expf_rn(float x) {
   return res;
 }
 
-} // namespace float_eval
+} // namespace float_eval_cr_rn
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/src/__support/math/expf_float_utils.h b/libc/src/__support/math/expf_float_utils.h
index d65abda27af380..ac6371225a20ac 100644
--- a/libc/src/__support/math/expf_float_utils.h
+++ b/libc/src/__support/math/expf_float_utils.h
@@ -23,9 +23,9 @@
 
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
-namespace float_eval {
+namespace float_eval_cr_rn {
 
-namespace cr_expf_rn_internal {
+namespace expf_internal {
 
 using fputil::FloatFloat;
 
@@ -140,9 +140,9 @@ LIBC_INLINE float scale_result(const FloatFloat &exp_u, int k,
   return FPBits((res_u & res_mask) + exponent_adj).get_val();
 }
 
-} // namespace cr_expf_rn_internal
+} // namespace expf_internal
 
-} // namespace float_eval
+} // namespace float_eval_cr_rn
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/test/src/math/exhaustive/expf_test.cpp b/libc/test/src/math/exhaustive/expf_test.cpp
index c299eaedee9d84..c547358a39d088 100644
--- a/libc/test/src/math/exhaustive/expf_test.cpp
+++ b/libc/test/src/math/exhaustive/expf_test.cpp
@@ -58,13 +58,14 @@ TEST_F(LlvmLibcExpfFloatExhaustiveTest, NegativeRange) {
 // Float-eval implementation correctly rounded only in round-to-nearest,
 // ties-to-even mode: tested against the double-eval version in that mode
 // with a 0 ULP bound.
-static float cr_expf_rn(float x) {
-  return LIBC_NAMESPACE::math::float_eval::cr_expf_rn(x);
+static float expf_float_eval_cr_rn(float x) {
+  return LIBC_NAMESPACE::math::float_eval_cr_rn::expf(x);
 }
 
 using LlvmLibcExpfFloatCrRnExhaustiveTest =
     LlvmLibcUnaryOpAgainstBaselineExhaustiveMathTest<
-        float, LIBC_NAMESPACE::math::double_eval::expf, cr_expf_rn, 0>;
+        float, LIBC_NAMESPACE::math::double_eval::expf,
+        expf_float_eval_cr_rn, 0>;
 
 TEST_F(LlvmLibcExpfFloatCrRnExhaustiveTest, PositiveRange) {
   test_full_range(mpfr::RoundingMode::Nearest, POS_START, POS_STOP);
diff --git a/libc/test/src/math/expf_test.cpp b/libc/test/src/math/expf_test.cpp
index e9a2d1dd230929..56ee5fe9f3b834 100644
--- a/libc/test/src/math/expf_test.cpp
+++ b/libc/test/src/math/expf_test.cpp
@@ -182,7 +182,7 @@ LIST_EXPF_TESTS(FloatEval, LIBC_NAMESPACE::math::float_eval::expf,
                 /*ulp_tolerance=*/1.5, /*all_rounding=*/false,
                 /*check_exception_and_errno=*/true, /*check_errno=*/true)
 #ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
-LIST_EXPF_TESTS(FloatEvalCrRn, LIBC_NAMESPACE::math::float_eval::cr_expf_rn,
+LIST_EXPF_TESTS(FloatEvalCrRn, LIBC_NAMESPACE::math::float_eval_cr_rn::expf,
                 /*ulp_tolerance=*/TOLERANCE + 0.5, /*all_rounding=*/false,
                 /*check_exception_and_errno=*/false, /*check_errno=*/false)
 #endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT
diff --git a/libc/test/src/math/smoke/expf_test.cpp b/libc/test/src/math/smoke/expf_test.cpp
index 49361ed716d942..85a40eb4e81b13 100644
--- a/libc/test/src/math/smoke/expf_test.cpp
+++ b/libc/test/src/math/smoke/expf_test.cpp
@@ -122,7 +122,7 @@ LIST_EXPF_TESTS(FloatEval, LIBC_NAMESPACE::math::float_eval::expf,
                 /*check_snan_invalid=*/false,
                 /*check_exception_and_errno=*/true, /*check_errno=*/true)
 #ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
-LIST_EXPF_TESTS(FloatEvalCrRn, LIBC_NAMESPACE::math::float_eval::cr_expf_rn,
+LIST_EXPF_TESTS(FloatEvalCrRn, LIBC_NAMESPACE::math::float_eval_cr_rn::expf,
                 /*check_snan_invalid=*/false,
                 /*check_exception_and_errno=*/false, /*check_errno=*/false)
 #endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT

``````````

</details>


https://github.com/llvm/llvm-project/pull/237614


More information about the libc-commits mailing list