Skip to content

[libc][math] Refractor sinhf16 to Header only#177337

Merged
bassiounix merged 18 commits intollvm:mainfrom
an1k3sh:refractor-constexpr-sinhf16
Jan 27, 2026
Merged

[libc][math] Refractor sinhf16 to Header only#177337
bassiounix merged 18 commits intollvm:mainfrom
an1k3sh:refractor-constexpr-sinhf16

Conversation

@an1k3sh
Copy link
Copy Markdown
Contributor

@an1k3sh an1k3sh commented Jan 22, 2026

Part of #147386

Separate issue hasn't been created for the task

EDIT: Resolves #177645

@llvmbot llvmbot added libc bazel "Peripheral" support tier build system: utils/bazel labels Jan 22, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Jan 22, 2026

@llvm/pr-subscribers-libc

Author: Anikesh Parashar (an1k3sh)

Changes

Part of #147386

Separate issue hasn't been created for the task


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

9 Files Affected:

  • (modified) libc/shared/math.h (+1)
  • (added) libc/shared/math/sinhf16.h (+24)
  • (modified) libc/src/__support/math/CMakeLists.txt (+18)
  • (added) libc/src/__support/math/sinhf16.h (+161)
  • (modified) libc/src/math/generic/CMakeLists.txt (+3)
  • (modified) libc/src/math/generic/sinhf16.cpp (+2-139)
  • (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 (+17)
diff --git a/libc/shared/math.h b/libc/shared/math.h
index d58238703701d..612307e897043 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -79,5 +79,6 @@
 #include "math/rsqrtf.h"
 #include "math/rsqrtf16.h"
 #include "math/sin.h"
+#include "math/sinhf16.h"
 
 #endif // LLVM_LIBC_SHARED_MATH_H
diff --git a/libc/shared/math/sinhf16.h b/libc/shared/math/sinhf16.h
new file mode 100644
index 0000000000000..86f40c9e11377
--- /dev/null
+++ b/libc/shared/math/sinhf16.h
@@ -0,0 +1,24 @@
+//===-- Shared sinhf16 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_SINHF16_H
+#define LLVM_LIBC_SHARED_MATH_SINHF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/sinhf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace shared {
+using math::sinhf16;
+} // namespace shared
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SINHF16_H
\ No newline at end of file
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index bf1c4463b8066..21686729a9be1 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1174,6 +1174,24 @@ add_header_library(
     libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  sinhf16
+  HDRS
+    sinhf16.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.except_value_utils
+    libc.src.__support.FPUtil.rounding_mode
+    libc.src.__support.common
+    libc.src.__support.macros.config
+    libc.src.__support.macros.optimization
+    libc.src.__support.math.expxf16_utils
+    
+)
+
 add_header_library(
   dfmal
   HDRS
diff --git a/libc/src/__support/math/sinhf16.h b/libc/src/__support/math/sinhf16.h
new file mode 100644
index 0000000000000..3a0e293b85ea8
--- /dev/null
+++ b/libc/src/__support/math/sinhf16.h
@@ -0,0 +1,161 @@
+//===-- Half-precision sinh(x) function -----------------------------------===//
+//
+// 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_SINHF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SINHF16_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/expxf16_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+static constexpr fputil::ExceptValues<float16, 17> SINHF16_EXCEPTS_POS = {{
+    // x = 0x1.714p-5, sinhf16(x) = 0x1.714p-5 (RZ)
+    {0x29c5U, 0x29c5U, 1U, 0U, 1U},
+    // x = 0x1.25p-4, sinhf16(x) = 0x1.25p-4 (RZ)
+    {0x2c94U, 0x2c94U, 1U, 0U, 1U},
+    // x = 0x1.f5p-4, sinhf16(x) = 0x1.f64p-4 (RZ)
+    {0x2fd4U, 0x2fd9U, 1U, 0U, 0U},
+    // x = 0x1.b1cp-3, sinhf16(x) = 0x1.b4cp-3 (RZ)
+    {0x32c7U, 0x32d3U, 1U, 0U, 1U},
+    // x = 0x1.6e8p-2, sinhf16(x) = 0x1.764p-2 (RZ)
+    {0x35baU, 0x35d9U, 1U, 0U, 1U},
+    // x = 0x1.6b4p-1, sinhf16(x) = 0x1.8a4p-1 (RZ)
+    {0x39adU, 0x3a29U, 1U, 0U, 1U},
+    // x = 0x1.a58p-1, sinhf16(x) = 0x1.d68p-1 (RZ)
+    {0x3a96U, 0x3b5aU, 1U, 0U, 1U},
+    // x = 0x1.574p+0, sinhf16(x) = 0x1.c78p+0 (RZ)
+    {0x3d5dU, 0x3f1eU, 1U, 0U, 1U},
+    // x = 0x1.648p+1, sinhf16(x) = 0x1.024p+3 (RZ)
+    {0x4192U, 0x4809U, 1U, 0U, 0U},
+    // x = 0x1.cdcp+1, sinhf16(x) = 0x1.26cp+4 (RZ)
+    {0x4337U, 0x4c9bU, 1U, 0U, 0U},
+    // x = 0x1.d0cp+1, sinhf16(x) = 0x1.2d8p+4 (RZ)
+    {0x4343U, 0x4cb6U, 1U, 0U, 1U},
+    // x = 0x1.018p+2, sinhf16(x) = 0x1.bfp+4 (RZ)
+    {0x4406U, 0x4efcU, 1U, 0U, 0U},
+    // x = 0x1.2fcp+2, sinhf16(x) = 0x1.cc4p+5 (RZ)
+    {0x44bfU, 0x5331U, 1U, 0U, 1U},
+    // x = 0x1.4ecp+2, sinhf16(x) = 0x1.75cp+6 (RZ)
+    {0x453bU, 0x55d7U, 1U, 0U, 0U},
+    // x = 0x1.8a4p+2, sinhf16(x) = 0x1.d94p+7 (RZ)
+    {0x4629U, 0x5b65U, 1U, 0U, 1U},
+    // x = 0x1.5fp+3, sinhf16(x) = 0x1.c54p+14 (RZ)
+    {0x497cU, 0x7715U, 1U, 0U, 1U},
+    // x = 0x1.3c8p+1, sinhf16(x) = 0x1.78ap+2 (RZ)
+    {0x40f2U, 0x45e2U, 1U, 0U, 1U},
+}};
+
+static constexpr fputil::ExceptValues<float16, 13> SINHF16_EXCEPTS_NEG = {{
+    // x = -0x1.714p-5, sinhf16(x) = -0x1.714p-5 (RZ)
+    {0xa9c5U, 0xa9c5U, 0U, 1U, 1U},
+    // x = -0x1.25p-4, sinhf16(x) = -0x1.25p-4 (RZ)
+    {0xac94U, 0xac94U, 0U, 1U, 1U},
+    // x = -0x1.f5p-4, sinhf16(x) = -0x1.f64p-4 (RZ)
+    {0xafd4U, 0xafd9U, 0U, 1U, 0U},
+    // x = -0x1.6e8p-2, sinhf16(x) = -0x1.764p-2 (RZ)
+    {0xb5baU, 0xb5d9U, 0U, 1U, 1U},
+    // x = -0x1.a58p-1, sinhf16(x) = -0x1.d68p-1 (RZ)
+    {0xba96U, 0xbb5aU, 0U, 1U, 1U},
+    // x = -0x1.cdcp+1, sinhf16(x) = -0x1.26cp+4 (RZ)
+    {0xc337U, 0xcc9bU, 0U, 1U, 0U},
+    // x = -0x1.d0cp+1, sinhf16(x) = -0x1.2d8p+4 (RZ)
+    {0xc343U, 0xccb6U, 0U, 1U, 1U},
+    // x = -0x1.018p+2, sinhf16(x) = -0x1.bfp+4 (RZ)
+    {0xc406U, 0xcefcU, 0U, 1U, 0U},
+    // x = -0x1.2fcp+2, sinhf16(x) = -0x1.cc4p+5 (RZ)
+    {0xc4bfU, 0xd331U, 0U, 1U, 1U},
+    // x = -0x1.4ecp+2, sinhf16(x) = -0x1.75cp+6 (RZ)
+    {0xc53bU, 0xd5d7U, 0U, 1U, 0U},
+    // x = -0x1.8a4p+2, sinhf16(x) = -0x1.d94p+7 (RZ)
+    {0xc629U, 0xdb65U, 0U, 1U, 1U},
+    // x = -0x1.5fp+3, sinhf16(x) = -0x1.c54p+14 (RZ)
+    {0xc97cU, 0xf715U, 0U, 1U, 1U},
+    // x = -0x1.3c8p+1, sinhf16(x) = -0x1.78ap+2 (RZ)
+    {0xc0f2U, 0xc5e2U, 0U, 1U, 1U},
+}};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+static constexpr float16 sinhf16(float16 x) {
+  using namespace math::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| = 0, or -2^(-14) <= x <= -2^(-9), or |x| >= asinh(2^16), or x is
+  // NaN.
+  if (LIBC_UNLIKELY(x_abs == 0U || (x_u >= 0x8400U && x_u <= 0xa400U) ||
+                    x_abs >= 0x49e5U)) {
+    // sinh(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;
+    }
+
+    // sinh(+/-0) = sinh(+/-0)
+    if (x_abs == 0U)
+      return FPBits::zero(x_bits.sign()).get_val();
+
+    // When |x| >= asinh(2^16).
+    if (x_abs >= 0x49e5U) {
+      // sinh(+/-inf) = +/-inf
+      if (x_bits.is_inf())
+        return FPBits::inf(x_bits.sign()).get_val();
+
+      int rounding_mode = fputil::quick_get_round();
+      if (rounding_mode == FE_TONEAREST ||
+          (x_bits.is_pos() && rounding_mode == FE_UPWARD) ||
+          (x_bits.is_neg() && rounding_mode == FE_DOWNWARD)) {
+        fputil::set_errno_if_required(ERANGE);
+        fputil::raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
+        return FPBits::inf(x_bits.sign()).get_val();
+      }
+      return FPBits::max_normal(x_bits.sign()).get_val();
+    }
+
+    // When -2^(-14) <= x <= -2^(-9).
+    if (fputil::fenv_is_round_down())
+      return FPBits(static_cast<uint16_t>(x_u + 1)).get_val();
+    return FPBits(static_cast<uint16_t>(x_u)).get_val();
+  }
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  if (x_bits.is_pos()) {
+    if (auto r = SINHF16_EXCEPTS_POS.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
+      return r.value();
+  } else {
+    if (auto r = SINHF16_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=*/true>(x);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINHF16_H
\ No newline at end of file
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index b578d1805f2a8..2a439478b6e21 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4214,6 +4214,9 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.rounding_mode
     libc.src.__support.macros.optimization
     libc.src.__support.math.expxf16_utils
+    libc.src.__support.common
+    libc.src.__support.macros.config
+    libc.src.__support.math.sinhf16
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/sinhf16.cpp b/libc/src/math/generic/sinhf16.cpp
index f6b5c9bea16b0..1dd15016fc818 100644
--- a/libc/src/math/generic/sinhf16.cpp
+++ b/libc/src/math/generic/sinhf16.cpp
@@ -7,147 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/sinhf16.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/expxf16_utils.h"
+#include "src/__support/math/sinhf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-static constexpr fputil::ExceptValues<float16, 17> SINHF16_EXCEPTS_POS = {{
-    // x = 0x1.714p-5, sinhf16(x) = 0x1.714p-5 (RZ)
-    {0x29c5U, 0x29c5U, 1U, 0U, 1U},
-    // x = 0x1.25p-4, sinhf16(x) = 0x1.25p-4 (RZ)
-    {0x2c94U, 0x2c94U, 1U, 0U, 1U},
-    // x = 0x1.f5p-4, sinhf16(x) = 0x1.f64p-4 (RZ)
-    {0x2fd4U, 0x2fd9U, 1U, 0U, 0U},
-    // x = 0x1.b1cp-3, sinhf16(x) = 0x1.b4cp-3 (RZ)
-    {0x32c7U, 0x32d3U, 1U, 0U, 1U},
-    // x = 0x1.6e8p-2, sinhf16(x) = 0x1.764p-2 (RZ)
-    {0x35baU, 0x35d9U, 1U, 0U, 1U},
-    // x = 0x1.6b4p-1, sinhf16(x) = 0x1.8a4p-1 (RZ)
-    {0x39adU, 0x3a29U, 1U, 0U, 1U},
-    // x = 0x1.a58p-1, sinhf16(x) = 0x1.d68p-1 (RZ)
-    {0x3a96U, 0x3b5aU, 1U, 0U, 1U},
-    // x = 0x1.574p+0, sinhf16(x) = 0x1.c78p+0 (RZ)
-    {0x3d5dU, 0x3f1eU, 1U, 0U, 1U},
-    // x = 0x1.648p+1, sinhf16(x) = 0x1.024p+3 (RZ)
-    {0x4192U, 0x4809U, 1U, 0U, 0U},
-    // x = 0x1.cdcp+1, sinhf16(x) = 0x1.26cp+4 (RZ)
-    {0x4337U, 0x4c9bU, 1U, 0U, 0U},
-    // x = 0x1.d0cp+1, sinhf16(x) = 0x1.2d8p+4 (RZ)
-    {0x4343U, 0x4cb6U, 1U, 0U, 1U},
-    // x = 0x1.018p+2, sinhf16(x) = 0x1.bfp+4 (RZ)
-    {0x4406U, 0x4efcU, 1U, 0U, 0U},
-    // x = 0x1.2fcp+2, sinhf16(x) = 0x1.cc4p+5 (RZ)
-    {0x44bfU, 0x5331U, 1U, 0U, 1U},
-    // x = 0x1.4ecp+2, sinhf16(x) = 0x1.75cp+6 (RZ)
-    {0x453bU, 0x55d7U, 1U, 0U, 0U},
-    // x = 0x1.8a4p+2, sinhf16(x) = 0x1.d94p+7 (RZ)
-    {0x4629U, 0x5b65U, 1U, 0U, 1U},
-    // x = 0x1.5fp+3, sinhf16(x) = 0x1.c54p+14 (RZ)
-    {0x497cU, 0x7715U, 1U, 0U, 1U},
-    // x = 0x1.3c8p+1, sinhf16(x) = 0x1.78ap+2 (RZ)
-    {0x40f2U, 0x45e2U, 1U, 0U, 1U},
-}};
-
-static constexpr fputil::ExceptValues<float16, 13> SINHF16_EXCEPTS_NEG = {{
-    // x = -0x1.714p-5, sinhf16(x) = -0x1.714p-5 (RZ)
-    {0xa9c5U, 0xa9c5U, 0U, 1U, 1U},
-    // x = -0x1.25p-4, sinhf16(x) = -0x1.25p-4 (RZ)
-    {0xac94U, 0xac94U, 0U, 1U, 1U},
-    // x = -0x1.f5p-4, sinhf16(x) = -0x1.f64p-4 (RZ)
-    {0xafd4U, 0xafd9U, 0U, 1U, 0U},
-    // x = -0x1.6e8p-2, sinhf16(x) = -0x1.764p-2 (RZ)
-    {0xb5baU, 0xb5d9U, 0U, 1U, 1U},
-    // x = -0x1.a58p-1, sinhf16(x) = -0x1.d68p-1 (RZ)
-    {0xba96U, 0xbb5aU, 0U, 1U, 1U},
-    // x = -0x1.cdcp+1, sinhf16(x) = -0x1.26cp+4 (RZ)
-    {0xc337U, 0xcc9bU, 0U, 1U, 0U},
-    // x = -0x1.d0cp+1, sinhf16(x) = -0x1.2d8p+4 (RZ)
-    {0xc343U, 0xccb6U, 0U, 1U, 1U},
-    // x = -0x1.018p+2, sinhf16(x) = -0x1.bfp+4 (RZ)
-    {0xc406U, 0xcefcU, 0U, 1U, 0U},
-    // x = -0x1.2fcp+2, sinhf16(x) = -0x1.cc4p+5 (RZ)
-    {0xc4bfU, 0xd331U, 0U, 1U, 1U},
-    // x = -0x1.4ecp+2, sinhf16(x) = -0x1.75cp+6 (RZ)
-    {0xc53bU, 0xd5d7U, 0U, 1U, 0U},
-    // x = -0x1.8a4p+2, sinhf16(x) = -0x1.d94p+7 (RZ)
-    {0xc629U, 0xdb65U, 0U, 1U, 1U},
-    // x = -0x1.5fp+3, sinhf16(x) = -0x1.c54p+14 (RZ)
-    {0xc97cU, 0xf715U, 0U, 1U, 1U},
-    // x = -0x1.3c8p+1, sinhf16(x) = -0x1.78ap+2 (RZ)
-    {0xc0f2U, 0xc5e2U, 0U, 1U, 1U},
-}};
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-LLVM_LIBC_FUNCTION(float16, sinhf16, (float16 x)) {
-  using namespace math::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| = 0, or -2^(-14) <= x <= -2^(-9), or |x| >= asinh(2^16), or x is
-  // NaN.
-  if (LIBC_UNLIKELY(x_abs == 0U || (x_u >= 0x8400U && x_u <= 0xa400U) ||
-                    x_abs >= 0x49e5U)) {
-    // sinh(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;
-    }
-
-    // sinh(+/-0) = sinh(+/-0)
-    if (x_abs == 0U)
-      return FPBits::zero(x_bits.sign()).get_val();
-
-    // When |x| >= asinh(2^16).
-    if (x_abs >= 0x49e5U) {
-      // sinh(+/-inf) = +/-inf
-      if (x_bits.is_inf())
-        return FPBits::inf(x_bits.sign()).get_val();
-
-      int rounding_mode = fputil::quick_get_round();
-      if (rounding_mode == FE_TONEAREST ||
-          (x_bits.is_pos() && rounding_mode == FE_UPWARD) ||
-          (x_bits.is_neg() && rounding_mode == FE_DOWNWARD)) {
-        fputil::set_errno_if_required(ERANGE);
-        fputil::raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
-        return FPBits::inf(x_bits.sign()).get_val();
-      }
-      return FPBits::max_normal(x_bits.sign()).get_val();
-    }
-
-    // When -2^(-14) <= x <= -2^(-9).
-    if (fputil::fenv_is_round_down())
-      return FPBits(static_cast<uint16_t>(x_u + 1)).get_val();
-    return FPBits(static_cast<uint16_t>(x_u)).get_val();
-  }
-
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-  if (x_bits.is_pos()) {
-    if (auto r = SINHF16_EXCEPTS_POS.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
-      return r.value();
-  } else {
-    if (auto r = SINHF16_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=*/true>(x);
-}
+LLVM_LIBC_FUNCTION(float16, sinhf16, (float16 x)) { return math::sinhf16(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index cfc2eda1aaec9..3d66bf2a9d6c9 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -75,4 +75,5 @@ add_fp_unittest(
     libc.src.__support.math.rsqrtf
     libc.src.__support.math.rsqrtf16
     libc.src.__support.math.sin
+    libc.src.__support.math.sinhf16
 )
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 88e6ecc98a0a7..ea32ec05c389c 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -32,6 +32,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::exp2m1f16(0.0f16));
   EXPECT_FP_EQ(0x1p+0f16, LIBC_NAMESPACE::shared::expf16(0.0f16));
   EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::expm1f16(0.0f16));
+  EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::sinhf16(0.0f16));
 
   EXPECT_FP_EQ(float16(10.0), LIBC_NAMESPACE::shared::f16fma(2.0, 3.0, 4.0));
 
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 90b1da0e3376e..180073f5503eb 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3321,6 +3321,23 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_sinhf16",
+    hdrs = ["src/__support/math/sinhf16.h"],
+    deps = [
+        ":hdr_errno_macros",
+        ":hdr_fenv_macros",
+        ":__support_fputil_except_value_utils",
+        ":__support_fputil_fenv_impl",
+        ":__support_fputil_fp_bits",
+        ":__support_fputil_rounding_mode",
+        ":__support_common",
+        ":__support_macros_config",
+        ":__support_macros_optimization",
+        ":__support_math_expxf16_utils",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_sinhfcoshf_utils",
     hdrs = ["src/__support/math/sinhfcoshf_utils.h"],

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 22, 2026

🐧 Linux x64 Test Results

✅ The build succeeded and no tests ran. This is expected in some build configurations.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 25, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

@an1k3sh
Copy link
Copy Markdown
Contributor Author

an1k3sh commented Jan 26, 2026

@bassiounix could you review this PR?

@bassiounix
Copy link
Copy Markdown
Member

Also please format bazel file

an1k3sh and others added 5 commits January 27, 2026 02:58
Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
Copy link
Copy Markdown
Member

@bassiounix bassiounix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. will merge after passing tests.
Thank you for the refactor!

@bassiounix bassiounix merged commit 667703e into llvm:main Jan 27, 2026
29 checks passed
Abdelrhmansersawy pushed a commit to Abdelrhmansersawy/llvm-project that referenced this pull request Jan 27, 2026
stomfaig pushed a commit to stomfaig/llvm-project that referenced this pull request Jan 28, 2026
sshrestha-aa pushed a commit to sshrestha-aa/llvm-project that referenced this pull request Feb 4, 2026
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.

[libc][math] Refactor sinhf16 to Header Only.

3 participants