Skip to content

Conversation

bassiounix
Copy link
Contributor

@bassiounix bassiounix commented Aug 14, 2025

@bassiounix bassiounix added bazel "Peripheral" support tier build system: utils/bazel libc labels Aug 14, 2025 — with Graphite App
@bassiounix bassiounix requested a review from lntue August 14, 2025 14:15
@bassiounix bassiounix marked this pull request as ready for review August 14, 2025 14:15
@llvmbot
Copy link
Member

llvmbot commented Aug 14, 2025

@llvm/pr-subscribers-libc

Author: Muhammad Bassiouni (bassiounix)

Changes

Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450


Patch is 31.45 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/153582.diff

18 Files Affected:

  • (modified) libc/shared/math.h (+1)
  • (added) libc/shared/math/coshf16.h (+28)
  • (modified) libc/src/__support/math/CMakeLists.txt (+28)
  • (added) libc/src/__support/math/coshf16.h (+124)
  • (renamed) libc/src/__support/math/expxf16_utils.h (+15-6)
  • (modified) libc/src/math/generic/CMakeLists.txt (+9-31)
  • (modified) libc/src/math/generic/coshf16.cpp (+2-97)
  • (modified) libc/src/math/generic/exp2f16.cpp (+2-1)
  • (modified) libc/src/math/generic/exp2m1f16.cpp (+2-1)
  • (modified) libc/src/math/generic/expm1f16.cpp (+2-1)
  • (modified) libc/src/math/generic/log10f16.cpp (+2-1)
  • (modified) libc/src/math/generic/log2f16.cpp (+2-1)
  • (modified) libc/src/math/generic/logf16.cpp (+2-1)
  • (modified) libc/src/math/generic/sinhf16.cpp (+2-1)
  • (modified) libc/src/math/generic/tanhf16.cpp (+2-1)
  • (modified) libc/test/shared/CMakeLists.txt (+1)
  • (modified) libc/test/shared/shared_math_test.cpp (+1)
  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+36-22)
diff --git a/libc/shared/math.h b/libc/shared/math.h
index c582877563f98..a89aa90ee1ef8 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -36,6 +36,7 @@
 #include "math/cosf.h"
 #include "math/cosf16.h"
 #include "math/coshf.h"
+#include "math/coshf16.h"
 #include "math/erff.h"
 #include "math/exp.h"
 #include "math/exp10.h"
diff --git a/libc/shared/math/coshf16.h b/libc/shared/math/coshf16.h
new file mode 100644
index 0000000000000..66e8d1431df65
--- /dev/null
+++ b/libc/shared/math/coshf16.h
@@ -0,0 +1,28 @@
+//===-- Shared coshf16 function ---------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_COSHF16_H
+#define LLVM_LIBC_SHARED_MATH_COSHF16_H
+
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/coshf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::coshf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_COSHF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e249af93b36c1..cddf336369973 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -419,6 +419,19 @@ add_header_library(
     libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  coshf16
+  HDRS
+    coshf16.h
+  DEPENDS
+    .expxf16_utils
+    libc.src.__support.FPUtil.except_value_utils
+    libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.rounding_mode
+    libc.src.__support.macros.optimization
+)
+
 add_header_library(
   erff
   HDRS
@@ -489,6 +502,21 @@ add_header_library(
     libc.include.llvm-libc-macros.float16_macros
 )
 
+add_header_library(
+  expxf16_utils
+  HDRS
+    expxf16_utils.h
+  DEPENDS
+    libc.hdr.stdint_proxy
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.cast
+    libc.src.__support.FPUtil.multiply_add
+    libc.src.__support.FPUtil.nearest_integer
+    libc.src.__support.macros.attributes
+    libc.src.__support.math.expf16_utils
+    libc.src.__support.math.exp10_float16_constants
+)
+
 add_header_library(
   frexpf128
   HDRS
diff --git a/libc/src/__support/math/coshf16.h b/libc/src/__support/math/coshf16.h
new file mode 100644
index 0000000000000..4c96a78fa5254
--- /dev/null
+++ b/libc/src/__support/math/coshf16.h
@@ -0,0 +1,124 @@
+//===-- Implementation header for coshf16 -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_COSHF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_COSHF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "expxf16_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/rounding_mode.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE static constexpr float16 coshf16(float16 x) {
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  constexpr fputil::ExceptValues<float16, 9> COSHF16_EXCEPTS_POS = {{
+      // x = 0x1.6ap-5, coshf16(x) = 0x1p+0 (RZ)
+      {0x29a8U, 0x3c00U, 1U, 0U, 1U},
+      // x = 0x1.8c4p+0, coshf16(x) = 0x1.3a8p+1 (RZ)
+      {0x3e31U, 0x40eaU, 1U, 0U, 0U},
+      // x = 0x1.994p+0, coshf16(x) = 0x1.498p+1 (RZ)
+      {0x3e65U, 0x4126U, 1U, 0U, 0U},
+      // x = 0x1.b6p+0, coshf16(x) = 0x1.6d8p+1 (RZ)
+      {0x3ed8U, 0x41b6U, 1U, 0U, 1U},
+      // x = 0x1.aap+1, coshf16(x) = 0x1.be8p+3 (RZ)
+      {0x42a8U, 0x4afaU, 1U, 0U, 1U},
+      // x = 0x1.cc4p+1, coshf16(x) = 0x1.23cp+4 (RZ)
+      {0x4331U, 0x4c8fU, 1U, 0U, 0U},
+      // x = 0x1.288p+2, coshf16(x) = 0x1.9b4p+5 (RZ)
+      {0x44a2U, 0x526dU, 1U, 0U, 0U},
+      // x = 0x1.958p+2, coshf16(x) = 0x1.1a4p+8 (RZ)
+      {0x4656U, 0x5c69U, 1U, 0U, 0U},
+      // x = 0x1.5fp+3, coshf16(x) = 0x1.c54p+14 (RZ)
+      {0x497cU, 0x7715U, 1U, 0U, 1U},
+  }};
+
+  constexpr fputil::ExceptValues<float16, 6> COSHF16_EXCEPTS_NEG = {{
+      // x = -0x1.6ap-5, coshf16(x) = 0x1p+0 (RZ)
+      {0xa9a8U, 0x3c00U, 1U, 0U, 1U},
+      // x = -0x1.b6p+0, coshf16(x) = 0x1.6d8p+1 (RZ)
+      {0xbed8U, 0x41b6U, 1U, 0U, 1U},
+      // x = -0x1.288p+2, coshf16(x) = 0x1.9b4p+5 (RZ)
+      {0xc4a2U, 0x526dU, 1U, 0U, 0U},
+      // x = -0x1.5fp+3, coshf16(x) = 0x1.c54p+14 (RZ)
+      {0xc97cU, 0x7715U, 1U, 0U, 1U},
+      // x = -0x1.8c4p+0, coshf16(x) = 0x1.3a8p+1 (RZ)
+      {0xbe31U, 0x40eaU, 1U, 0U, 0U},
+      // x = -0x1.994p+0, coshf16(x) = 0x1.498p+1 (RZ)
+      {0xbe65U, 0x4126U, 1U, 0U, 0U},
+  }};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+  using namespace expxf16_internal;
+  using FPBits = fputil::FPBits<float16>;
+  FPBits x_bits(x);
+
+  uint16_t x_u = x_bits.uintval();
+  uint16_t x_abs = x_u & 0x7fffU;
+
+  // When |x| >= acosh(2^16), or x is NaN.
+  if (LIBC_UNLIKELY(x_abs >= 0x49e5U)) {
+    // cosh(NaN) = NaN
+    if (x_bits.is_nan()) {
+      if (x_bits.is_signaling_nan()) {
+        fputil::raise_except_if_required(FE_INVALID);
+        return FPBits::quiet_nan().get_val();
+      }
+
+      return x;
+    }
+
+    // When |x| >= acosh(2^16).
+    if (x_abs >= 0x49e5U) {
+      // cosh(+/-inf) = +inf
+      if (x_bits.is_inf())
+        return FPBits::inf().get_val();
+
+      switch (fputil::quick_get_round()) {
+      case FE_TONEAREST:
+      case FE_UPWARD:
+        fputil::set_errno_if_required(ERANGE);
+        fputil::raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
+        return FPBits::inf().get_val();
+      default:
+        return FPBits::max_normal().get_val();
+      }
+    }
+  }
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  if (x_bits.is_pos()) {
+    if (auto r = COSHF16_EXCEPTS_POS.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
+      return r.value();
+  } else {
+    if (auto r = COSHF16_EXCEPTS_NEG.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
+      return r.value();
+  }
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+  return eval_sinh_or_cosh</*IsSinh=*/false>(x);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_COSHF16_H
diff --git a/libc/src/math/generic/expxf16.h b/libc/src/__support/math/expxf16_utils.h
similarity index 95%
rename from libc/src/math/generic/expxf16.h
rename to libc/src/__support/math/expxf16_utils.h
index 562a427fc6cdc..651ef12d8a59d 100644
--- a/libc/src/math/generic/expxf16.h
+++ b/libc/src/__support/math/expxf16_utils.h
@@ -21,7 +21,11 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LIBC_INLINE ExpRangeReduction exp2_range_reduction(float16 x) {
+namespace math {
+
+namespace expxf16_internal {
+
+LIBC_INLINE static constexpr ExpRangeReduction exp2_range_reduction(float16 x) {
   // For -25 < x < 16, to compute 2^x, we perform the following range reduction:
   // find hi, mid, lo, such that:
   //   x = hi + mid + lo, in which
@@ -117,7 +121,8 @@ static constexpr cpp::array<uint32_t, 32> EXP2_MID_5_BITS = {
 // The main point of these formulas is that the expensive part of calculating
 // the polynomials approximating lower parts of e^x and e^(-x) is shared and
 // only done once.
-template <bool IsSinh> LIBC_INLINE float16 eval_sinh_or_cosh(float16 x) {
+template <bool IsSinh>
+LIBC_INLINE static constexpr float16 eval_sinh_or_cosh(float16 x) {
   float xf = x;
   float kf = fputil::nearest_integer(xf * (LOG2F_E * 0x1.0p+5f));
   int x_hi_mid_p = static_cast<int>(kf);
@@ -174,7 +179,7 @@ template <bool IsSinh> LIBC_INLINE float16 eval_sinh_or_cosh(float16 x) {
 // Generated by Sollya with the following commands:
 //   > display = hexadecimal;
 //   > for i from 0 to 31 do print(round(log(1 + i * 2^-5), SG, RN));
-constexpr cpp::array<float, 32> LOGF_F = {
+static constexpr cpp::array<float, 32> LOGF_F = {
     0x0p+0f,        0x1.f829bp-6f,  0x1.f0a30cp-5f, 0x1.6f0d28p-4f,
     0x1.e27076p-4f, 0x1.29553p-3f,  0x1.5ff308p-3f, 0x1.9525aap-3f,
     0x1.c8ff7cp-3f, 0x1.fb9186p-3f, 0x1.1675cap-2f, 0x1.2e8e2cp-2f,
@@ -188,7 +193,7 @@ constexpr cpp::array<float, 32> LOGF_F = {
 // Generated by Sollya with the following commands:
 //   > display = hexadecimal;
 //   > for i from 0 to 31 do print(round(log2(1 + i * 2^-5), SG, RN));
-constexpr cpp::array<float, 32> LOG2F_F = {
+static constexpr cpp::array<float, 32> LOG2F_F = {
     0x0p+0f,        0x1.6bad38p-5f, 0x1.663f7p-4f,  0x1.08c588p-3f,
     0x1.5c01a4p-3f, 0x1.acf5e2p-3f, 0x1.fbc16cp-3f, 0x1.24407ap-2f,
     0x1.49a784p-2f, 0x1.6e221cp-2f, 0x1.91bba8p-2f, 0x1.b47ecp-2f,
@@ -202,7 +207,7 @@ constexpr cpp::array<float, 32> LOG2F_F = {
 // Generated by Sollya with the following commands:
 //   > display = hexadecimal;
 //   > for i from 0 to 31 do print(round(log10(1 + i * 2^-5), SG, RN));
-constexpr cpp::array<float, 32> LOG10F_F = {
+static constexpr cpp::array<float, 32> LOG10F_F = {
     0x0p+0f,        0x1.b5e908p-7f, 0x1.af5f92p-6f, 0x1.3ed11ap-5f,
     0x1.a30a9ep-5f, 0x1.02428cp-4f, 0x1.31b306p-4f, 0x1.5fe804p-4f,
     0x1.8cf184p-4f, 0x1.b8de4ep-4f, 0x1.e3bc1ap-4f, 0x1.06cbd6p-3f,
@@ -216,7 +221,7 @@ constexpr cpp::array<float, 32> LOG10F_F = {
 // Generated by Sollya with the following commands:
 //   > display = hexadecimal;
 //   > for i from 0 to 31 do print(round(1 / (1 + i * 2^-5), SG, RN));
-constexpr cpp::array<float, 32> ONE_OVER_F_F = {
+static constexpr cpp::array<float, 32> ONE_OVER_F_F = {
     0x1p+0f,        0x1.f07c2p-1f,  0x1.e1e1e2p-1f, 0x1.d41d42p-1f,
     0x1.c71c72p-1f, 0x1.bacf92p-1f, 0x1.af286cp-1f, 0x1.a41a42p-1f,
     0x1.99999ap-1f, 0x1.8f9c18p-1f, 0x1.861862p-1f, 0x1.7d05f4p-1f,
@@ -227,6 +232,10 @@ constexpr cpp::array<float, 32> ONE_OVER_F_F = {
     0x1.111112p-1f, 0x1.0c9714p-1f, 0x1.08421p-1f,  0x1.041042p-1f,
 };
 
+} // namespace expxf16_internal
+
+} // namespace math
+
 } // namespace LIBC_NAMESPACE_DECL
 
 #endif // LLVM_LIBC_SRC_MATH_GENERIC_EXPXF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 65e4839268443..91b8e3d530ef4 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1395,7 +1395,6 @@ add_entrypoint_object(
   HDRS
     ../exp2f16.h
   DEPENDS
-    .expxf16
     libc.hdr.errno_macros
     libc.hdr.fenv_macros
     libc.src.__support.FPUtil.cast
@@ -1404,6 +1403,7 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.rounding_mode
     libc.src.__support.macros.optimization
+    libc.src.__support.math.expxf16_utils
 )
 
 add_entrypoint_object(
@@ -1433,7 +1433,6 @@ add_entrypoint_object(
   HDRS
     ../exp2m1f16.h
   DEPENDS
-    .expxf16
     libc.hdr.errno_macros
     libc.hdr.fenv_macros
     libc.src.__support.common
@@ -1446,6 +1445,7 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.rounding_mode
     libc.src.__support.macros.optimization
     libc.src.__support.macros.properties.cpu_features
+    libc.src.__support.math.expxf16_utils
 )
 
 add_entrypoint_object(
@@ -1568,7 +1568,6 @@ add_entrypoint_object(
   HDRS
     ../expm1f16.h
   DEPENDS
-    .expxf16
     libc.hdr.errno_macros
     libc.hdr.fenv_macros
     libc.src.__support.FPUtil.cast
@@ -1579,6 +1578,7 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.polyeval
     libc.src.__support.FPUtil.rounding_mode
     libc.src.__support.macros.optimization
+    libc.src.__support.math.expxf16_utils
 )
 
 add_entrypoint_object(
@@ -1949,7 +1949,6 @@ add_entrypoint_object(
   HDRS
     ../log10f16.h
   DEPENDS
-    .expxf16
     libc.hdr.errno_macros
     libc.hdr.fenv_macros
     libc.src.__support.FPUtil.cast
@@ -1960,6 +1959,7 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.polyeval
     libc.src.__support.macros.optimization
     libc.src.__support.macros.properties.cpu_features
+    libc.src.__support.math.expxf16_utils
 )
 
 add_entrypoint_object(
@@ -2038,7 +2038,6 @@ add_entrypoint_object(
   HDRS
     ../log2f16.h
   DEPENDS
-    .expxf16
     libc.hdr.errno_macros
     libc.hdr.fenv_macros
     libc.src.__support.FPUtil.cast
@@ -2049,6 +2048,7 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.polyeval
     libc.src.__support.macros.optimization
     libc.src.__support.macros.properties.cpu_features
+    libc.src.__support.math.expxf16_utils
 )
 
 add_entrypoint_object(
@@ -2093,7 +2093,6 @@ add_entrypoint_object(
   HDRS
     ../logf16.h
   DEPENDS
-    .expxf16
     libc.hdr.errno_macros
     libc.hdr.fenv_macros
     libc.src.__support.FPUtil.cast
@@ -2104,6 +2103,7 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.polyeval
     libc.src.__support.macros.optimization
     libc.src.__support.macros.properties.cpu_features
+    libc.src.__support.math.expxf16_utils
 )
 
 add_entrypoint_object(
@@ -3918,14 +3918,7 @@ add_entrypoint_object(
   HDRS
     ../coshf16.h
   DEPENDS
-    .expxf16
-    libc.hdr.errno_macros
-    libc.hdr.fenv_macros
-    libc.src.__support.FPUtil.except_value_utils
-    libc.src.__support.FPUtil.fenv_impl
-    libc.src.__support.FPUtil.fp_bits
-    libc.src.__support.FPUtil.rounding_mode
-    libc.src.__support.macros.optimization
+    libc.src.__support.math.coshf16
 )
 
 add_entrypoint_object(
@@ -3948,7 +3941,6 @@ add_entrypoint_object(
   HDRS
     ../sinhf16.h
   DEPENDS
-    .expxf16
     libc.hdr.errno_macros
     libc.hdr.fenv_macros
     libc.src.__support.FPUtil.except_value_utils
@@ -3956,6 +3948,7 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.rounding_mode
     libc.src.__support.macros.optimization
+    libc.src.__support.math.expxf16_utils
 )
 
 add_entrypoint_object(
@@ -3980,7 +3973,6 @@ add_entrypoint_object(
   HDRS
     ../tanhf16.h
   DEPENDS
-    .expxf16
     libc.hdr.fenv_macros
     libc.src.__support.CPP.array
     libc.src.__support.FPUtil.cast
@@ -3992,6 +3984,7 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.polyeval
     libc.src.__support.FPUtil.rounding_mode
     libc.src.__support.macros.optimization
+    libc.src.__support.math.expxf16_utils
 )
 
 add_entrypoint_object(
@@ -4937,21 +4930,6 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.generic.mul
 )
 
-add_header_library(
-  expxf16
-  HDRS
-    expxf16.h
-  DEPENDS
-    libc.hdr.stdint_proxy
-    libc.src.__support.FPUtil.fp_bits
-    libc.src.__support.FPUtil.cast
-    libc.src.__support.FPUtil.multiply_add
-    libc.src.__support.FPUtil.nearest_integer
-    libc.src.__support.macros.attributes
-    libc.src.__support.math.expf16_utils
-    libc.src.__support.math.exp10_float16_constants
-)
-
 add_entrypoint_object(
   bf16add
   SRCS
diff --git a/libc/src/math/generic/coshf16.cpp b/libc/src/math/generic/coshf16.cpp
index 689d16a55260f..d86edd98f29e9 100644
--- a/libc/src/math/generic/coshf16.cpp
+++ b/libc/src/math/generic/coshf16.cpp
@@ -7,105 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/coshf16.h"
-#include "expxf16.h"
-#include "hdr/errno_macros.h"
-#include "hdr/fenv_macros.h"
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/except_value_utils.h"
-#include "src/__support/FPUtil/rounding_mode.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/optimization.h"
+#include "src/__support/math/coshf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-static constexpr fputil::ExceptValues<float16, 9> COSHF16_EXCEPTS_POS = {{
-    // x = 0x1.6ap-5, coshf16(x) = 0x1p+0 (RZ)
-    {0x29a8U, 0x3c00U, 1U, 0U, 1U},
-    // x = 0x1.8c4p+0, coshf16(x) = 0x1.3a8p+1 (RZ)
-    {0x3e31U, 0x40eaU, 1U, 0U, 0U},
-    // x = 0x1.994p+0, coshf16(x) = 0x1.498p+1 (RZ)
-    {0x3e65U, 0x4126U, 1U, 0U, 0U},
-    // x = 0x1.b6p+0, coshf16(x) = 0x1.6d8p+1 (RZ)
-    {0x3ed8U, 0x41b6U, 1U, 0U, 1U},
-    // x = 0x1.aap+1, coshf16(x) = 0x1.be8p+3 (RZ)
-    {0x42a8U, 0x4afaU, 1U, 0U, 1U},
-    // x = 0x1.cc4p+1, coshf16(x) = 0x1.23cp+4 (RZ)
-    {0x4331U, 0x4c8fU, 1U, 0U, 0U},
-    // x = 0x1.288p+2, coshf16(x) = 0x1.9b4p+5 (RZ)
-    {0x44a2U, 0x526dU, 1U, 0U, 0U},
-    // x = 0x1.958p+2, coshf16(x) = 0x1.1a4p+8 (RZ)
-    {0x4656U, 0x5c69U, 1U, 0U, 0U},
-    // x = 0x1.5fp+3, coshf16(x) = 0x1.c54p+14 (RZ)
-    {0x497cU, 0x7715U, 1U, 0U, 1U},
-}};
-
-static constexpr fputil::ExceptValues<float16, 6> COSHF16_EXCEPTS_NEG = {{
-    // x = -0x1.6ap-5, coshf16(x) = 0x1p+0 (RZ)
-    {0xa9a8U, 0x3c00U, 1U, 0U, 1U},
-    // x = -0x1.b6p+0, coshf16(x) = 0x1.6d8p+1 (RZ)
-    {0xbed8U, 0x41b6U, 1U, 0U, 1U},
-    // x = -0x1.288p+2, coshf16(x) = 0x1.9b4p+5 (RZ)
-    {0xc4a2U, 0x526dU, 1U, 0U, 0U},
-    // x = -0x1.5fp+3, coshf16(x) = 0x1.c54p+14 (RZ)
-    {0xc97cU, 0x7715U, 1U, 0U, 1U},
-    // x = -0x1.8c4p+0, coshf16(x) = 0x1.3a8p+1 (RZ)
-    {0xbe31U, 0x40eaU, 1U, 0U, 0U},
-    // x = -0x1.994p+0, coshf16(x) = 0x1.498p+1 (RZ)
-    {0xbe65U, 0x4126U, 1U, 0U, 0U},
-}};
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-LLVM_LIBC_FUNCTION(float16, coshf16, (float16 x)) {
-  using FPBits = fputil::FPBits<float16>;
-  FPBits x_bits(x);
-
-  uint16_t x_u = x_bits.uintval();
-  uint16_t x_abs = x_u & 0x7fffU;
-
-  // When |x| >= acosh(2^16), or x is NaN.
-  if (LIBC_UNLIKELY(x_abs >= 0x49e5U)) {
-    // cosh(NaN) = NaN
-    if (x_bits.is_nan()) {
-      if (x_bits.is_signaling_nan()) {
-        fputil::raise_except_if_required(FE_INVALID);
-        return FPBits::quiet_nan().get_val();
-      }
-
-      return x;
-    }
-
-    // When |x| >= acosh(2^16).
-    if (x_abs >= 0x49e5U) {
-      // cosh(+/-inf) = +inf
-      if (x_bits.is_inf())
-        return FPBits::inf().get_val();
-
-      switch (fputil::quick_get_round()) {
-      case FE_TONEAREST:
-      case FE_UPWARD:
-        fputil::set_errno_if_required(ERANGE);
-        fputil::raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
-        return FPBits::inf().get_val();
-      default:
-        return FPBits::max_normal().get_val();
-      }
-    }
-  }
-
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-  if (x_bits.is_pos()) {
-    if (auto r = COSHF16_EXCEPTS_POS.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
-      return r.value();
-  } else {
-    if (auto r = COSHF16_EXCEPTS_NEG.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
-      return r.value();
-  }
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-  return eval_sinh_or_cosh</*IsSinh=*/false>(x);
-}
+LLVM_LIBC_FUNCTION(float16, coshf16, (float16 x)) { return math::coshf16(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/exp2f16.cpp b/libc/src/math/generic/exp2f16.cpp
index 5c039c59df1af..5db0c3a9de08d 100644
--- a/libc/src/math/generic/exp2f16.cpp
+++ b/libc/src/math/generic/exp2f16.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/exp2f16.h"
-#include "expxf16.h"
 #include "hdr/errno_macros.h"
 #include "hdr/fenv_macros.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
@@ -18,6 +17,7 @@
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/optimization.h"
+#include "src/__support/math/expxf16_utils.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
@@ -34,6 +34,7 @@ static constexpr fputil::ExceptValues<float16, 3> EXP2F16_EXCEPTS = {{
 #endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 
 LLVM_LIBC_FUNCTION(float16, exp2f16, (float16 x)) {
+  using namespace math::expxf16_internal;
   using FPBits = fputil::FPBits<float16>;
   FPBits x_bits(x);
 
diff --git a/libc/src/math/generic/exp2m1f16.cpp b/libc/src/math/generic/exp2m1f16.cpp
index 61633cd2cfcfb..ce0cc60748f19 100644
--- a/libc/src/math/generic/exp2m1f16.cpp
+++ b/libc/src/math/generic/exp2m1f16.cpp
@@ -7,7 +...
[truncated]

Copy link
Contributor Author

bassiounix commented Aug 14, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

Base automatically changed from users/bassiounix/spr/08-13-_libc_math_refactor_coshf_implementation_to_header-only_in_src___support_math_folder to main August 14, 2025 14:19
@bassiounix bassiounix force-pushed the users/bassiounix/spr/08-14-_libc_math_refactor_coshf16_implementation_to_header-only_in_src___support_math_folder branch from cb03965 to abcf3bc Compare August 14, 2025 14:20
@bassiounix bassiounix force-pushed the users/bassiounix/spr/08-14-_libc_math_refactor_coshf16_implementation_to_header-only_in_src___support_math_folder branch from abcf3bc to 75ae446 Compare August 18, 2025 22:37
@bassiounix bassiounix force-pushed the users/bassiounix/spr/08-14-_libc_math_refactor_coshf16_implementation_to_header-only_in_src___support_math_folder branch from ef4490d to b320f74 Compare August 18, 2025 23:03
Copy link
Contributor Author

bassiounix commented Aug 18, 2025

Merge activity

  • Aug 18, 11:03 PM UTC: Graphite rebased this pull request as part of a merge.
  • Aug 18, 11:08 PM UTC: @bassiounix merged this pull request with Graphite.

@bassiounix bassiounix merged commit 2c79dc1 into main Aug 18, 2025
20 checks passed
@bassiounix bassiounix deleted the users/bassiounix/spr/08-14-_libc_math_refactor_coshf16_implementation_to_header-only_in_src___support_math_folder branch August 18, 2025 23:08
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 18, 2025

LLVM Buildbot has detected a new failure on builder libc-aarch64-ubuntu-dbg running on libc-aarch64-ubuntu while building libc,utils at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/104/builds/29347

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[ RUN      ] LlvmLibcTanfTest.SpecialNumbers
[       OK ] LlvmLibcTanfTest.SpecialNumbers (6 us)
[ RUN      ] LlvmLibcTanfTest.InFloatRange
[       OK ] LlvmLibcTanfTest.InFloatRange (698 ms)
[ RUN      ] LlvmLibcTanfTest.SpecificBitPatterns
[       OK ] LlvmLibcTanfTest.SpecificBitPatterns (2 ms)
[ RUN      ] LlvmLibcTanfTest.SDCOMP_26094
[       OK ] LlvmLibcTanfTest.SDCOMP_26094 (30 us)
Ran 4 tests.  PASS: 4  FAIL: 0
[158/1096] Building CXX object libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o
FAILED: libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -DLIBC_THREAD_MODE=LIBC_THREAD_MODE_PLATFORM -fpie -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -DLIBC_TEST=UNIT -std=gnu++17 -MD -MT libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o -MF libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o.d -o libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/test/shared/shared_math_test.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/test/shared/shared_math_test.cpp:9:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/shared/math.h:39:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/shared/math/coshf16.h:16:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/coshf16.h:16:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/expxf16_utils.h:28:48: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
LIBC_INLINE static constexpr ExpRangeReduction exp2_range_reduction(float16 x) {
                                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/expxf16_utils.h:44:14: note: non-constexpr function 'nearest_integer' cannot be used in a constant expression
  float kf = fputil::nearest_integer(xf * 0x1.0p+3f);
             ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/FPUtil/aarch64/nearest_integer.h:23:19: note: declared here
LIBC_INLINE float nearest_integer(float x) {
                  ^
1 error generated.
[159/1096] Building CXX object libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o
FAILED: libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -D__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC -D__LIBC_USE_BUILTIN_ROUND -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -DLIBC_THREAD_MODE=LIBC_THREAD_MODE_PLATFORM -fpie -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -DLIBC_TEST=UNIT -std=gnu++17 -MD -MT libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o -MF libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o.d -o libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/test/shared/shared_math_test.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/test/shared/shared_math_test.cpp:9:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/shared/math.h:39:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/shared/math/coshf16.h:16:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/coshf16.h:16:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/expxf16_utils.h:28:48: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
LIBC_INLINE static constexpr ExpRangeReduction exp2_range_reduction(float16 x) {
                                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/expxf16_utils.h:44:14: note: non-constexpr function 'nearest_integer' cannot be used in a constant expression
  float kf = fputil::nearest_integer(xf * 0x1.0p+3f);
             ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/FPUtil/aarch64/nearest_integer.h:23:19: note: declared here
LIBC_INLINE float nearest_integer(float x) {
                  ^
1 error generated.
[160/1096] Running unit test libc.test.src.math.bf16fmaf128_test.__unit__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcFmaTest.SubnormalRange
[       OK ] LlvmLibcFmaTest.SubnormalRange (385 ms)
[ RUN      ] LlvmLibcFmaTest.NormalRange
[       OK ] LlvmLibcFmaTest.NormalRange (429 ms)
Step 7 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[ RUN      ] LlvmLibcTanfTest.SpecialNumbers
[       OK ] LlvmLibcTanfTest.SpecialNumbers (6 us)
[ RUN      ] LlvmLibcTanfTest.InFloatRange
[       OK ] LlvmLibcTanfTest.InFloatRange (698 ms)
[ RUN      ] LlvmLibcTanfTest.SpecificBitPatterns
[       OK ] LlvmLibcTanfTest.SpecificBitPatterns (2 ms)
[ RUN      ] LlvmLibcTanfTest.SDCOMP_26094
[       OK ] LlvmLibcTanfTest.SDCOMP_26094 (30 us)
Ran 4 tests.  PASS: 4  FAIL: 0
[158/1096] Building CXX object libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o
FAILED: libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -DLIBC_THREAD_MODE=LIBC_THREAD_MODE_PLATFORM -fpie -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -DLIBC_TEST=UNIT -std=gnu++17 -MD -MT libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o -MF libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o.d -o libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/test/shared/shared_math_test.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/test/shared/shared_math_test.cpp:9:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/shared/math.h:39:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/shared/math/coshf16.h:16:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/coshf16.h:16:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/expxf16_utils.h:28:48: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
LIBC_INLINE static constexpr ExpRangeReduction exp2_range_reduction(float16 x) {
                                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/expxf16_utils.h:44:14: note: non-constexpr function 'nearest_integer' cannot be used in a constant expression
  float kf = fputil::nearest_integer(xf * 0x1.0p+3f);
             ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/FPUtil/aarch64/nearest_integer.h:23:19: note: declared here
LIBC_INLINE float nearest_integer(float x) {
                  ^
1 error generated.
[159/1096] Building CXX object libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o
FAILED: libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -D__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC -D__LIBC_USE_BUILTIN_ROUND -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -DLIBC_THREAD_MODE=LIBC_THREAD_MODE_PLATFORM -fpie -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -DLIBC_TEST=UNIT -std=gnu++17 -MD -MT libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o -MF libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o.d -o libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/test/shared/shared_math_test.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/test/shared/shared_math_test.cpp:9:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/shared/math.h:39:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/shared/math/coshf16.h:16:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/coshf16.h:16:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/expxf16_utils.h:28:48: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
LIBC_INLINE static constexpr ExpRangeReduction exp2_range_reduction(float16 x) {
                                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/math/expxf16_utils.h:44:14: note: non-constexpr function 'nearest_integer' cannot be used in a constant expression
  float kf = fputil::nearest_integer(xf * 0x1.0p+3f);
             ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/__support/FPUtil/aarch64/nearest_integer.h:23:19: note: declared here
LIBC_INLINE float nearest_integer(float x) {
                  ^
1 error generated.
[160/1096] Running unit test libc.test.src.math.bf16fmaf128_test.__unit__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcFmaTest.SubnormalRange
[       OK ] LlvmLibcFmaTest.SubnormalRange (385 ms)
[ RUN      ] LlvmLibcFmaTest.NormalRange
[       OK ] LlvmLibcFmaTest.NormalRange (429 ms)

@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 18, 2025

LLVM Buildbot has detected a new failure on builder libc-aarch64-ubuntu-fullbuild-dbg running on libc-aarch64-ubuntu while building libc,utils at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/71/builds/29336

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[       OK ] LlvmLibcStrtouint32Test.MessyBaseSixteenDecode (2 us)
[ RUN      ] LlvmLibcStrtouint32Test.AutomaticBaseSelection
[       OK ] LlvmLibcStrtouint32Test.AutomaticBaseSelection (4 us)
Ran 14 tests.  PASS: 14  FAIL: 0
[971/977] Running unit test libc.test.src.time.nanosleep_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcNanosleep.SmokeTest
[       OK ] LlvmLibcNanosleep.SmokeTest (27 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[972/977] Building CXX object libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o
FAILED: libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -D__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC -D__LIBC_USE_BUILTIN_ROUND -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -DLIBC_THREAD_MODE=LIBC_THREAD_MODE_PLATFORM -fpie -DLIBC_FULL_BUILD -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -DLIBC_TEST=UNIT -std=gnu++17 -MD -MT libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o -MF libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o.d -o libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__build__.dir/shared_math_test.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/test/shared/shared_math_test.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/test/shared/shared_math_test.cpp:9:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/shared/math.h:39:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/shared/math/coshf16.h:16:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/coshf16.h:16:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/expxf16_utils.h:28:48: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
LIBC_INLINE static constexpr ExpRangeReduction exp2_range_reduction(float16 x) {
                                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/expxf16_utils.h:44:14: note: non-constexpr function 'nearest_integer' cannot be used in a constant expression
  float kf = fputil::nearest_integer(xf * 0x1.0p+3f);
             ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/aarch64/nearest_integer.h:23:19: note: declared here
LIBC_INLINE float nearest_integer(float x) {
                  ^
1 error generated.
[973/977] Building CXX object libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o
FAILED: libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -DLIBC_THREAD_MODE=LIBC_THREAD_MODE_PLATFORM -fpie -DLIBC_FULL_BUILD -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wstrict-prototypes -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wthread-safety -DLIBC_TEST=UNIT -std=gnu++17 -MD -MT libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o -MF libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o.d -o libc/test/shared/CMakeFiles/libc.test.shared.shared_math_test.__unit__.__NO_ROUND_OPT.__build__.dir/shared_math_test.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/test/shared/shared_math_test.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/test/shared/shared_math_test.cpp:9:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/shared/math.h:39:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/shared/math/coshf16.h:16:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/coshf16.h:16:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/expxf16_utils.h:28:48: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
LIBC_INLINE static constexpr ExpRangeReduction exp2_range_reduction(float16 x) {
                                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/math/expxf16_utils.h:44:14: note: non-constexpr function 'nearest_integer' cannot be used in a constant expression
  float kf = fputil::nearest_integer(xf * 0x1.0p+3f);
             ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/aarch64/nearest_integer.h:23:19: note: declared here
LIBC_INLINE float nearest_integer(float x) {
                  ^
1 error generated.
ninja: build stopped: subcommand failed.
['ninja', 'libc-unit-tests'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 181, in step
    yield

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bazel "Peripheral" support tier build system: utils/bazel libc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants