[libc-commits] [libc] [llvm] [libc][math][c23] Add sinhbf16 function (PR #224645)
via libc-commits
libc-commits at lists.llvm.org
Sun Oct 25 03:02:54 PDT 2026
https://github.com/dil12321 updated https://github.com/llvm/llvm-project/pull/224645
>From 81a9a4f6fa5f9c15799ac4a0191098697b047749 Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Fri, 18 Sep 2026 23:50:55 +1000
Subject: [PATCH 01/17] feat: implementation and tests for sinhbf16
---
libc/config/baremetal/aarch64/entrypoints.txt | 1 +
libc/config/baremetal/arm/entrypoints.txt | 1 +
libc/config/baremetal/riscv/entrypoints.txt | 1 +
libc/config/darwin/aarch64/entrypoints.txt | 1 +
libc/config/darwin/x86_64/entrypoints.txt | 1 +
libc/config/freebsd/x86_64/entrypoints.txt | 1 +
libc/config/gpu/amdgpu/entrypoints.txt | 1 +
libc/config/gpu/nvptx/entrypoints.txt | 1 +
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/arm/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/config/windows/entrypoints.txt | 1 +
libc/docs/headers/math/index.rst | 2 +-
libc/include/math.yaml | 6 ++
libc/shared/math.h | 1 +
libc/shared/math/sinhbf16.h | 23 +++++
libc/src/__support/math/CMakeLists.txt | 13 +++
libc/src/__support/math/sinhbf16.h | 97 +++++++++++++++++++
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/generic/CMakeLists.txt | 10 ++
libc/src/math/generic/sinhbf16.cpp | 18 ++++
libc/src/math/sinhbf16.h | 21 ++++
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 1 +
libc/test/src/math/CMakeLists.txt | 13 +++
libc/test/src/math/sinhbf16_test.cpp | 47 +++++++++
libc/test/src/math/smoke/CMakeLists.txt | 13 +++
libc/test/src/math/smoke/sinhbf16_test.cpp | 89 +++++++++++++++++
.../llvm-project-overlay/libc/BUILD.bazel | 20 ++++
30 files changed, 388 insertions(+), 1 deletion(-)
create mode 100644 libc/shared/math/sinhbf16.h
create mode 100644 libc/src/__support/math/sinhbf16.h
create mode 100644 libc/src/math/generic/sinhbf16.cpp
create mode 100644 libc/src/math/sinhbf16.h
create mode 100644 libc/test/src/math/sinhbf16_test.cpp
create mode 100644 libc/test/src/math/smoke/sinhbf16_test.cpp
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 114534ce61ae6e..cdc0eb219fb8a5 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -875,6 +875,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index c8148815c34e34..24cd54e88376c0 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -886,6 +886,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 622d6156cff11d..7d67b314707a3f 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -878,6 +878,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index d702b2c5a65497..75561bd049c8b4 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -697,6 +697,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 716ab572f8d3cd..57b48280a12e44 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -333,6 +333,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 8f6c178301c2f2..33987b80a71508 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -630,6 +630,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 5c5e5891da8227..8fbdbd897342d5 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -746,6 +746,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index afae725484a891..0c65b328bdb8fb 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -762,6 +762,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index f87ba3437fb6c4..f9ea212ab13d46 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1064,6 +1064,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index f4347331d0b310..8cb0d594bd82ed 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -688,6 +688,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 51587056fb02d6..911003ed26322d 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1148,6 +1148,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 8b77efa648c43d..0cb7d7fa68b79e 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1159,6 +1159,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 3a48b49e169b3a..603717a159c001 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -423,6 +423,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 2d5e188e804d4c..60dc3fb152f59c 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -347,7 +347,7 @@ Higher Math Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| sincos | |check| | |check| | | | | | | |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| sinh | |check| | | | |check| | | | 7.12.5.5 | F.10.2.5 |
+| sinh | |check| | | | |check| | | |check| | 7.12.5.5 | F.10.2.5 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| sinpi | |check| | | | |check| | | | 7.12.4.13 | F.10.1.13 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/include/math.yaml b/libc/include/math.yaml
index 006233e579f86c..cdd0c6fbe1b3a2 100644
--- a/libc/include/math.yaml
+++ b/libc/include/math.yaml
@@ -2659,6 +2659,12 @@ functions:
return_type: float
arguments:
- type: float
+ - name: sinhbf16
+ standards:
+ - stdc
+ return_type: _Float16
+ arguments:
+ - type: _Float16
- name: sinhf16
standards:
- stdc
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 7b52cedf99c245..17e8b38d64a738 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -467,6 +467,7 @@
#include "math/sinf.h"
#include "math/sinf16.h"
#include "math/sinhf.h"
+#include "math/sinhbf16.h"
#include "math/sinhf16.h"
#include "math/sinpif.h"
#include "math/sinpif16.h"
diff --git a/libc/shared/math/sinhbf16.h b/libc/shared/math/sinhbf16.h
new file mode 100644
index 00000000000000..a4255838a5d917
--- /dev/null
+++ b/libc/shared/math/sinhbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared sinhbf16 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_SINHBF16_H
+#define LLVM_LIBC_SHARED_MATH_SINHBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/sinhbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::sinhbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SINHBF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 0871a5bf229b63..58339ad1264011 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -5370,6 +5370,19 @@ add_header_library(
libc.src.__support.macros.properties.types
)
+add_header_library(
+ sinhbf16
+ HDRS
+ sinhbf16.h
+ DEPENDS
+ .sinhfcoshf_utils
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.macros.config
+ libc.src.__support.macros.attributes
+ libc.src.__support.macros.optimization
+)
+
add_header_library(
sinhf
HDRS
diff --git a/libc/src/__support/math/sinhbf16.h b/libc/src/__support/math/sinhbf16.h
new file mode 100644
index 00000000000000..6720bd4a265bd2
--- /dev/null
+++ b/libc/src/__support/math/sinhbf16.h
@@ -0,0 +1,97 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the implementation of sinhbf16.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16_H
+
+#include "sinhfcoshf_utils.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE bfloat16 sinhbf16(bfloat16 x) {
+ using FPBits = fputil::FPBits<bfloat16>;
+ FPBits x_bits(x);
+ uint16_t x_u = x_bits.uintval();
+ uint16_t x_abs = x_u & 0x7fff;
+
+ // |x| <= 0.11328125
+ if (x_abs <= 0x3de8) {
+ if (x_abs == 0U)
+ return x;
+
+#ifndef LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
+ if (x_u & 0x8000) {
+ if (fputil::fenv_is_round_down())
+ return FPBits(static_cast<uint16_t>(x_u + 1)).get_val();
+ } else {
+ if (fputil::fenv_is_round_up())
+ return FPBits(static_cast<uint16_t>(x_u + 1)).get_val();
+ }
+#endif
+ return FPBits(static_cast<uint16_t>(x_u)).get_val();
+ }
+
+ // |x| >= 89.5
+ if (LIBC_UNLIKELY(x_abs >= 0x42b3)) {
+
+ // sinh(inf) = inf
+ if (x_bits.is_inf())
+ return x;
+
+ // 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;
+ }
+
+#ifndef LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
+ int rounding = fputil::quick_get_round();
+ if (x_bits.is_neg()) {
+ if (LIBC_UNLIKELY(rounding == FE_UPWARD || rounding == FE_TOWARDZERO))
+ return -FPBits::max_normal().get_val();
+ } else {
+ if (LIBC_UNLIKELY(rounding == FE_DOWNWARD || rounding == FE_TOWARDZERO))
+ return FPBits::max_normal().get_val();
+ }
+#endif // !LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
+
+ fputil::set_errno_if_required(ERANGE);
+ fputil::raise_except_if_required(FE_OVERFLOW);
+
+ uint16_t inf_bits = (x_u & 0x8000) | 0x7f80;
+ return fputil::FPBits<bfloat16>(inf_bits).get_val();
+ }
+
+ float xf = static_cast<float>(x);
+ float result = static_cast<float>(
+ math::sinhfcoshf_internal::exp_pm_eval</*is_sinh*/ true>(xf));
+
+ return fputil::cast<bfloat16>(result);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16_H
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 2c7568f0b63618..3fb9e8b2d0cc5f 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -580,6 +580,7 @@ add_math_entrypoint_object(sinpif)
add_math_entrypoint_object(sinpif16)
add_math_entrypoint_object(sinh)
+add_math_entrypoint_object(sinhbf16)
add_math_entrypoint_object(sinhf)
add_math_entrypoint_object(sinhf16)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 28b8e954530ddf..e243130c997e32 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3755,6 +3755,16 @@ add_entrypoint_object(
libc.src.__support.math.sinhf
)
+add_entrypoint_object(
+ sinhbf16
+ SRCS
+ sinhbf16.cpp
+ HDRS
+ ../sinhbf16.h
+ DEPENDS
+ libc.src.__support.math.sinhbf16
+)
+
add_entrypoint_object(
sinhf16
SRCS
diff --git a/libc/src/math/generic/sinhbf16.cpp b/libc/src/math/generic/sinhbf16.cpp
new file mode 100644
index 00000000000000..eaab609360752f
--- /dev/null
+++ b/libc/src/math/generic/sinhbf16.cpp
@@ -0,0 +1,18 @@
+//===-- Implementation for sinhbf16(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.
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/sinhbf16.h"
+#include "src/__support/math/sinhbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, sinhbf16, (bfloat16 x)) {
+ return math::sinhbf16(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/sinhbf16.h b/libc/src/math/sinhbf16.h
new file mode 100644
index 00000000000000..91f30cb68f2469
--- /dev/null
+++ b/libc/src/math/sinhbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sinhbf16 ----------------------*- 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_MATH_SINHBF16_H
+#define LLVM_LIBC_SRC_MATH_SINHBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 sinhbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SINHBF16_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 74eda7cdaf065e..927b99faa8e6ff 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -471,6 +471,7 @@ else()
libc.src.__support.math.sincos
libc.src.__support.math.sincosf
libc.src.__support.math.sinf
+ libc.src.__support.math.sinbf16
libc.src.__support.math.sinf16
libc.src.__support.math.sinhf
libc.src.__support.math.sinhf16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 7b785331f36c6a..147772b30c6f7b 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -811,6 +811,7 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
EXPECT_FP_EQ(bfloat16(1.0), LIBC_NAMESPACE::shared::expbf16(bfloat16(0.0)));
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::log_bf16(bfloat16(1.0)));
+ EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::sinhbf16(bfloat16(0.0)));
bfloat16 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
EXPECT_FP_EQ(neg_min_denormal,
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 8f1a543de0a5e7..72dd7350ca286d 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2612,6 +2612,19 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ sinhbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ sinhbf16_test.cpp
+ DEPENDS
+ libc.src.math.sinhbf16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
sinhf16_test
NEED_MPFR
diff --git a/libc/test/src/math/sinhbf16_test.cpp b/libc/test/src/math/sinhbf16_test.cpp
new file mode 100644
index 00000000000000..f5115d48547f46
--- /dev/null
+++ b/libc/test/src/math/sinhbf16_test.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains exhaustive tests for bfloat16 sinh.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/expbf16.h"
+#include "src/math/sinhbf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcSinhBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// range: [0, inf]
+static constexpr uint16_t POS_START = 0x0000U;
+static constexpr uint16_t POS_STOP = 0x7f80U;
+
+// range: [-0, -inf]
+static constexpr uint16_t NEG_START = 0x8000U;
+static constexpr uint16_t NEG_STOP = 0xff80U;
+
+TEST_F(LlvmLibcSinhBf16Test, PositiveRange) {
+ for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
+ bfloat16 x = FPBits(v).get_val();
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sinh, x,
+ LIBC_NAMESPACE::sinhbf16(x), 0.5);
+ }
+}
+
+TEST_F(LlvmLibcSinhBf16Test, NegativeRange) {
+ for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
+ bfloat16 x = FPBits(v).get_val();
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sinh, x,
+ LIBC_NAMESPACE::sinhbf16(x), 0.5);
+ }
+}
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index a61b854a85fb2b..6e45b79c26a4d2 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4763,6 +4763,19 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ sinhbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ sinhbf16_test.cpp
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.src.math.sinhbf16
+ libc.hdr.fenv_macros
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
sinhf16_test
SUITE
diff --git a/libc/test/src/math/smoke/sinhbf16_test.cpp b/libc/test/src/math/smoke/sinhbf16_test.cpp
new file mode 100644
index 00000000000000..69d6959ef8a7c3
--- /dev/null
+++ b/libc/test/src/math/smoke/sinhbf16_test.cpp
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains unit tests for bfloat16 sinh.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/sinhbf16.h"
+#include "test/UnitTest/FEnvSafeTest.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+class LlvmLibcSinhBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+ DECLARE_SPECIAL_CONSTANTS(bfloat16)
+public:
+ void test_special_numbers() {
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::sinhbf16(aNaN));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::sinhbf16(sNaN),
+ FE_INVALID);
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::sinhbf16(inf));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, LIBC_NAMESPACE::sinhbf16(neg_inf));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::sinhbf16(zero));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, LIBC_NAMESPACE::sinhbf16(neg_zero));
+ EXPECT_MATH_ERRNO(0);
+ }
+
+ // For small values, sinh(x) is x.
+ void test_small_values() {
+ bfloat16 x = FPBits(uint16_t(0x3de8)).get_val();
+ bfloat16 result = LIBC_NAMESPACE::sinhbf16(x);
+ EXPECT_FP_EQ(x, result);
+
+ x = FPBits(uint16_t(0xbde8)).get_val();
+ result = LIBC_NAMESPACE::sinhbf16(x);
+ EXPECT_FP_EQ(x, result);
+
+ x = FPBits(uint16_t(0x0001)).get_val();
+ result = LIBC_NAMESPACE::sinhbf16(x);
+ EXPECT_FP_EQ(x, result);
+
+ x = FPBits(uint16_t(0x8001)).get_val();
+ result = LIBC_NAMESPACE::sinhbf16(x);
+ EXPECT_FP_EQ(x, result);
+ }
+
+ void test_overflow() {
+ EXPECT_FP_EQ_WITH_EXCEPTION(
+ inf, LIBC_NAMESPACE::sinhbf16(FPBits(uint16_t(0x42b3)).get_val()),
+ FE_OVERFLOW);
+ EXPECT_MATH_ERRNO(ERANGE);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::sinhbf16(max_normal),
+ FE_OVERFLOW);
+ EXPECT_MATH_ERRNO(ERANGE);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(
+ neg_inf, LIBC_NAMESPACE::sinhbf16(FPBits(uint16_t(0xc2b3)).get_val()),
+ FE_OVERFLOW);
+ EXPECT_MATH_ERRNO(ERANGE);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(
+ neg_inf, LIBC_NAMESPACE::sinhbf16(neg_max_normal), FE_OVERFLOW);
+ EXPECT_MATH_ERRNO(ERANGE);
+ }
+};
+
+TEST_F(LlvmLibcSinhBf16Test, SpecialNumbers) { test_special_numbers(); }
+TEST_F(LlvmLibcSinhBf16Test, SmallValues) { test_small_values(); }
+TEST_F(LlvmLibcSinhBf16Test, Overflow) { test_overflow(); }
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index cdbf40b3e81a24..66832c972a978d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -10610,6 +10610,19 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_sinhbf16",
+ hdrs = ["src/__support/math/sinhbf16.h"],
+ deps = [
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_cast",
+ ":__support_fputil_fp_bits",
+ ":__support_macros_config",
+ ":__support_macros_optimization",
+ ":__support_sincosf_utils",
+ ],
+)
+
libc_support_library(
name = "__support_math_sinf16",
hdrs = ["src/__support/math/sinf16.h"],
@@ -14621,6 +14634,13 @@ libc_math_function(
additional_deps = [":__support_math_sinhf"],
)
+libc_math_function(
+ name = "sinhbf16",
+ additional_deps = [
+ ":__support_math_sinhbf16",
+ ],
+)
+
libc_math_function(
name = "sinhf16",
additional_deps = [
>From c0567c7fe905c459df5ea9cb1d2e44cf60561f3f Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Sun, 20 Sep 2026 23:02:49 +1000
Subject: [PATCH 02/17] new header template
---
libc/shared/math/sinhbf16.h | 7 ++++++-
libc/src/math/generic/sinhbf16.cpp | 9 +++++++--
libc/src/math/sinhbf16.h | 7 ++++++-
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/libc/shared/math/sinhbf16.h b/libc/shared/math/sinhbf16.h
index a4255838a5d917..0c31f307ba789e 100644
--- a/libc/shared/math/sinhbf16.h
+++ b/libc/shared/math/sinhbf16.h
@@ -1,10 +1,15 @@
-//===-- Shared sinhbf16 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
//
//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the shared sinhbf16(x) function.
+///
+//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SHARED_MATH_SINHBF16_H
#define LLVM_LIBC_SHARED_MATH_SINHBF16_H
diff --git a/libc/src/math/generic/sinhbf16.cpp b/libc/src/math/generic/sinhbf16.cpp
index eaab609360752f..2a09a0dc152821 100644
--- a/libc/src/math/generic/sinhbf16.cpp
+++ b/libc/src/math/generic/sinhbf16.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation for sinhbf16(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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation for sinhbf16(x) function.
+///
+//===----------------------------------------------------------------------===//
#include "src/math/sinhbf16.h"
#include "src/__support/math/sinhbf16.h"
diff --git a/libc/src/math/sinhbf16.h b/libc/src/math/sinhbf16.h
index 91f30cb68f2469..11c7f659984869 100644
--- a/libc/src/math/sinhbf16.h
+++ b/libc/src/math/sinhbf16.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for sinhbf16 ----------------------*- 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
//
//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for sinhbf16.
+///
+//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_MATH_SINHBF16_H
#define LLVM_LIBC_SRC_MATH_SINHBF16_H
>From 960a5713a0dd577fe0a4d77c4eb204b4cb562648 Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Sun, 20 Sep 2026 23:17:30 +1000
Subject: [PATCH 03/17] add test files to bazel
---
.../llvm-project-overlay/libc/test/src/math/BUILD.bazel | 7 +++++++
.../libc/test/src/math/smoke/BUILD.bazel | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
index 8e5706c085f39f..cf48d85df48479 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
@@ -773,6 +773,13 @@ math_mpfr_test(
],
)
+math_mpfr_test(
+ name = "sinhbf16",
+ deps = [
+ "//libc:__support_fputil_bfloat16",
+ ],
+)
+
math_mpfr_test(
name = "sinpif",
hdrs = ["sdcomp26094.h"],
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index e1d9305617303e..f9a75a5c3252d5 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -2099,6 +2099,13 @@ math_test(name = "sincos")
math_test(name = "sincosf")
+math_test(
+ name = "sinhbf16",
+ deps = [
+ "//libc:__support_fputil_bfloat16",
+ ],
+)
+
math_test(
name = "sinhf",
deps = [
>From 1fbfe996f271a76921c904db35d145542911dece Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Wed, 23 Sep 2026 23:29:26 +1000
Subject: [PATCH 04/17] make sinhbf16 constexpr, use float for intermediate
calculation
---
libc/src/__support/math/CMakeLists.txt | 13 +-
libc/src/__support/math/sinhbf16.h | 21 ++-
.../__support/math/sinhbf16coshbf16_utils.h | 170 ++++++++++++++++++
.../llvm-project-overlay/libc/BUILD.bazel | 14 ++
4 files changed, 213 insertions(+), 5 deletions(-)
create mode 100644 libc/src/__support/math/sinhbf16coshbf16_utils.h
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 58339ad1264011..ea74945e597c1a 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -4932,6 +4932,17 @@ add_header_library(
libc.src.__support.common
)
+add_header_library(
+ sinhbf16coshbf16_utils
+ HDRS
+ sinhbf16coshbf16_utils.h
+ DEPENDS
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.polyeval
+ libc.src.__support.FPUtil.nearest_integer
+ libc.src.__support.FPUtil.multiply_add
+)
+
add_header_library(
sinhfcoshf_utils
HDRS
@@ -5375,7 +5386,7 @@ add_header_library(
HDRS
sinhbf16.h
DEPENDS
- .sinhfcoshf_utils
+ .sinhbf16coshbf16_utils
libc.src.__support.FPUtil.bfloat16
libc.src.__support.FPUtil.cast
libc.src.__support.macros.config
diff --git a/libc/src/__support/math/sinhbf16.h b/libc/src/__support/math/sinhbf16.h
index 6720bd4a265bd2..300d3a4685423d 100644
--- a/libc/src/__support/math/sinhbf16.h
+++ b/libc/src/__support/math/sinhbf16.h
@@ -14,7 +14,7 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16_H
-#include "sinhfcoshf_utils.h"
+#include "sinhbf16coshbf16_utils.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/cast.h"
@@ -22,12 +22,11 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"
-
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE bfloat16 sinhbf16(bfloat16 x) {
+LIBC_INLINE constexpr bfloat16 sinhbf16(bfloat16 x) {
using FPBits = fputil::FPBits<bfloat16>;
FPBits x_bits(x);
uint16_t x_u = x_bits.uintval();
@@ -85,8 +84,22 @@ LIBC_INLINE bfloat16 sinhbf16(bfloat16 x) {
}
float xf = static_cast<float>(x);
+
+ // |x| >= 6.875
+ // return e^x / 2
+ if (x_abs >= 0x40dc) {
+ uint32_t x_abs_bits = fputil::FPBits<float>(xf).uintval() & 0x7fffffff;
+ float x_abs_f = fputil::FPBits<float>(x_abs_bits).get_val();
+ float abs_result = math::sinhbf16coshbf16_internal::exp_half(x_abs_f);
+ if (x_u & 0x8000) {
+ abs_result = -abs_result;
+ }
+ return fputil::cast<bfloat16>(abs_result);
+ }
+
+ // sinh(x) = (e^x - e^(-x)) / 2.
float result = static_cast<float>(
- math::sinhfcoshf_internal::exp_pm_eval</*is_sinh*/ true>(xf));
+ math::sinhbf16coshbf16_internal::eval_sinh_or_cosh</*is_sinh*/ true>(xf));
return fputil::cast<bfloat16>(result);
}
diff --git a/libc/src/__support/math/sinhbf16coshbf16_utils.h b/libc/src/__support/math/sinhbf16coshbf16_utils.h
new file mode 100644
index 00000000000000..4e51813d7e5c74
--- /dev/null
+++ b/libc/src/__support/math/sinhbf16coshbf16_utils.h
@@ -0,0 +1,170 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// General sinh/cosh functions for bfloat16.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16COSHBF16_UTILS_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16COSHBF16_UTILS_H
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+namespace sinhbf16coshbf16_internal {
+
+LIBC_INLINE_VAR constexpr float LOG2F_E = 0x1.715476p+0f;
+
+LIBC_INLINE_VAR constexpr float LOGF_2 = 0x1.62e43p-1f;
+
+LIBC_INLINE_VAR constexpr cpp::array<uint32_t, 32> EXP2_MID_5_BITS = {
+ 0x3f80'0000U, 0x3f82'cd87U, 0x3f85'aac3U, 0x3f88'980fU, 0x3f8b'95c2U,
+ 0x3f8e'a43aU, 0x3f91'c3d3U, 0x3f94'f4f0U, 0x3f98'37f0U, 0x3f9b'8d3aU,
+ 0x3f9e'f532U, 0x3fa2'7043U, 0x3fa5'fed7U, 0x3fa9'a15bU, 0x3fad'583fU,
+ 0x3fb1'23f6U, 0x3fb5'04f3U, 0x3fb8'fbafU, 0x3fbd'08a4U, 0x3fc1'2c4dU,
+ 0x3fc5'672aU, 0x3fc9'b9beU, 0x3fce'248cU, 0x3fd2'a81eU, 0x3fd7'44fdU,
+ 0x3fdb'fbb8U, 0x3fe0'ccdfU, 0x3fe5'b907U, 0x3fea'c0c7U, 0x3fef'e4baU,
+ 0x3ff5'257dU, 0x3ffa'83b3U,
+};
+
+// This function correctly calculates sinh(x) and cosh(x) by calculating exp(x)
+// and exp(-x) simultaneously.
+// To compute e^x, we perform the following range reduction:
+// find hi, mid, lo such that:
+// x = (hi + mid) * log(2) + lo, in which
+// hi is an integer,
+// 0 <= mid * 2^5 < 32 is an integer
+// -2^(-5) <= lo * log2(e) <= 2^-5.
+// In particular,
+// hi + mid = round(x * log2(e) * 2^5) * 2^(-5).
+// Then,
+// e^x = 2^(hi + mid) * e^lo = 2^hi * 2^mid * e^lo.
+// We store 2^mid in the lookup table EXP2_MID_5_BITS, and compute 2^hi * 2^mid
+// by adding hi to the exponent field of 2^mid.
+// e^lo is computed using a degree-3 minimax polynomial generated by Sollya:
+// e^lo ~ P(lo)
+// = 1 + lo + c2 * lo^2 + ... + c5 * lo^5
+// = (1 + c2*lo^2 + c4*lo^4) + lo * (1 + c3*lo^2 + c5*lo^4)
+// = P_even + lo * P_odd
+// To compute e^(-x), notice that:
+// e^(-x) = 2^(-(hi + mid)) * e^(-lo)
+// ~ 2^(-(hi + mid)) * P(-lo)
+// = 2^(-(hi + mid)) * (P_even - lo * P_odd)
+// So:
+// sinh(x) = (e^x - e^(-x)) / 2
+// ~ 0.5 * (2^(hi + mid) * (P_even + lo * P_odd) -
+// 2^(-(hi + mid)) * (P_even - lo * P_odd))
+// = 0.5 * (P_even * (2^(hi + mid) - 2^(-(hi + mid))) +
+// lo * P_odd * (2^(hi + mid) + 2^(-(hi + mid))))
+// And similarly:
+// cosh(x) = (e^x + e^(-x)) / 2
+// ~ 0.5 * (P_even * (2^(hi + mid) + 2^(-(hi + mid))) +
+// lo * P_odd * (2^(hi + mid) - 2^(-(hi + mid))))
+// 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 constexpr float eval_sinh_or_cosh(float xf) {
+ float kf = fputil::nearest_integer(xf * (LOG2F_E * 0x1.0p+5f));
+ int x_hi_mid_p = static_cast<int>(kf);
+ int x_hi_mid_m = -x_hi_mid_p;
+
+ unsigned x_hi_p = static_cast<unsigned>(x_hi_mid_p) >> 5;
+ unsigned x_hi_m = static_cast<unsigned>(x_hi_mid_m) >> 5;
+ unsigned x_mid_p = static_cast<unsigned>(x_hi_mid_p) & 0x1f;
+ unsigned x_mid_m = static_cast<unsigned>(x_hi_mid_m) & 0x1f;
+
+ uint32_t exp2_hi_mid_bits_p =
+ EXP2_MID_5_BITS[x_mid_p] +
+ static_cast<uint32_t>(x_hi_p << fputil::FPBits<float>::FRACTION_LEN);
+ uint32_t exp2_hi_mid_bits_m =
+ EXP2_MID_5_BITS[x_mid_m] +
+ static_cast<uint32_t>(x_hi_m << fputil::FPBits<float>::FRACTION_LEN);
+ // exp2_hi_mid_p = 2^(hi + mid)
+ float exp2_hi_mid_p = fputil::FPBits<float>(exp2_hi_mid_bits_p).get_val();
+ // exp2_hi_mid_m = 2^(-(hi + mid))
+ float exp2_hi_mid_m = fputil::FPBits<float>(exp2_hi_mid_bits_m).get_val();
+
+ // exp2_hi_mid_sum = 2^(hi + mid) + 2^(-(hi + mid))
+ float exp2_hi_mid_sum = exp2_hi_mid_p + exp2_hi_mid_m;
+ // exp2_hi_mid_diff = 2^(hi + mid) - 2^(-(hi + mid))
+ float exp2_hi_mid_diff = exp2_hi_mid_p - exp2_hi_mid_m;
+
+ // lo = x - (hi + mid) = round(x * log2(e) * 2^5) * log(2) * (-2^(-5)) + x
+ float lo = fputil::multiply_add(kf, LOGF_2 * -0x1.0p-5f, xf);
+ float lo_sq = lo * lo;
+
+ // Degree-3 minimax polynomial generated by Sollya with the following
+ // commands:
+ // > display = hexadecimal;
+ // > P = fpminimax(expm1(x)/x, 2, [|SG...|], [-2^-5, 2^-5]);
+ // > 1 + x * P;
+ constexpr cpp::array<float, 4> COEFFS = {0x1p+0f, 0x1p+0f, 0x1.0004p-1f,
+ 0x1.555778p-3f};
+ float half_p_odd =
+ fputil::polyeval(lo_sq, COEFFS[1] * 0.5f, COEFFS[3] * 0.5f);
+ float half_p_even =
+ fputil::polyeval(lo_sq, COEFFS[0] * 0.5f, COEFFS[2] * 0.5f);
+
+ // sinh(x) = lo * (0.5 * P_odd * (2^(hi + mid) + 2^(-(hi + mid)))) +
+ // (0.5 * P_even * (2^(hi + mid) - 2^(-(hi + mid))))
+ if constexpr (IsSinh)
+ return fputil::multiply_add(lo, half_p_odd * exp2_hi_mid_sum,
+ half_p_even * exp2_hi_mid_diff);
+ // cosh(x) = lo * (0.5 * P_odd * (2^(hi + mid) - 2^(-(hi + mid)))) +
+ // (0.5 * P_even * (2^(hi + mid) + 2^(-(hi + mid))))
+ return fputil::multiply_add(lo, half_p_odd * exp2_hi_mid_diff,
+ half_p_even * exp2_hi_mid_sum);
+}
+
+// Calculate e^x / 2
+LIBC_INLINE constexpr float exp_half(float xf) {
+ float kf = fputil::nearest_integer(xf * (LOG2F_E * 0x1.0p+5f));
+ int x_hi_mid_p = static_cast<int>(kf);
+
+ unsigned x_hi_p = (static_cast<unsigned>(x_hi_mid_p) >> 5) - 1;
+ unsigned x_mid_p = static_cast<unsigned>(x_hi_mid_p) & 0x1f;
+
+ uint32_t exp2_hi_mid_bits_p =
+ EXP2_MID_5_BITS[x_mid_p] +
+ static_cast<uint32_t>(x_hi_p << fputil::FPBits<float>::FRACTION_LEN);
+
+ // exp2_hi_mid_p = 2^(hi + mid - 1)
+ float exp2_hi_mid_p = fputil::FPBits<float>(exp2_hi_mid_bits_p).get_val();
+
+ // lo = x - (hi + mid) = round(x * log2(e) * 2^5) * log(2) * (-2^(-5)) + x
+ float lo = fputil::multiply_add(kf, LOGF_2 * -0x1.0p-5f, xf);
+ float lo_sq = lo * lo;
+
+ constexpr cpp::array<float, 4> COEFFS = {0x1p+0f, 0x1p+0f, 0x1.0004p-1f,
+ 0x1.555778p-3f};
+
+ float p_odd = fputil::polyeval(lo_sq, COEFFS[1], COEFFS[3]);
+ float p_even = fputil::polyeval(lo_sq, COEFFS[0], COEFFS[2]);
+
+ float exp_lo = p_even + lo * p_odd;
+
+ // exp(x) / 2 = 2^(hi + mid - 1) * exp(lo).
+ float result = exp2_hi_mid_p * exp_lo;
+ return result;
+}
+
+} // namespace sinhbf16coshbf16_internal
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16COSHBF16_UTILS_H
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 66832c972a978d..94aa7d1f077450 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -10620,6 +10620,7 @@ libc_support_library(
":__support_macros_config",
":__support_macros_optimization",
":__support_sincosf_utils",
+ ":__support_math_sinhbf16coshbf16_utils",
],
)
@@ -10669,6 +10670,19 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_sinhbf16coshbf16_utils",
+ hdrs = ["src/__support/math/sinhbf16coshbf16_utils.h"],
+ deps = [
+ ":__support_fputil_cast",
+ ":__support_fputil_fp_bits",
+ ":__support_fputil_multiply_add",
+ ":__support_fputil_nearest_integer",
+ ":__support_macros_attributes",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_sqrt",
hdrs = ["src/__support/math/sqrt.h"],
>From 1337d8ee2ac2c5030b8f7becb20bd6ec28a997f9 Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Thu, 24 Sep 2026 15:15:13 +1000
Subject: [PATCH 05/17] formatting, correct BUILD.bazel dependancies
---
libc/shared/math.h | 2 +-
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 17e8b38d64a738..20ce5316e8a2a6 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -466,8 +466,8 @@
#include "math/sincosf.h"
#include "math/sinf.h"
#include "math/sinf16.h"
-#include "math/sinhf.h"
#include "math/sinhbf16.h"
+#include "math/sinhf.h"
#include "math/sinhf16.h"
#include "math/sinpif.h"
#include "math/sinpif16.h"
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 94aa7d1f077450..f0b00fda97155d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -10678,6 +10678,7 @@ libc_support_library(
":__support_fputil_fp_bits",
":__support_fputil_multiply_add",
":__support_fputil_nearest_integer",
+ ":__support_fputil_polyeval",
":__support_macros_attributes",
":__support_macros_config",
],
>From 9744c666a9a282431b7aba0068a5494d23f88eb9 Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Sun, 27 Sep 2026 11:10:15 +1000
Subject: [PATCH 06/17] Use LIBC_CONSTEXPR, update dependancies
---
libc/src/__support/math/CMakeLists.txt | 1 +
libc/src/__support/math/sinhbf16.h | 2 +-
libc/src/__support/math/sinhbf16coshbf16_utils.h | 5 +++--
libc/test/src/math/sinhbf16_test.cpp | 1 -
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 2 +-
5 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index ea74945e597c1a..643416ad3747a4 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -4941,6 +4941,7 @@ add_header_library(
libc.src.__support.FPUtil.polyeval
libc.src.__support.FPUtil.nearest_integer
libc.src.__support.FPUtil.multiply_add
+ libc.src.__support.macros.attributes
)
add_header_library(
diff --git a/libc/src/__support/math/sinhbf16.h b/libc/src/__support/math/sinhbf16.h
index 300d3a4685423d..6216e353c0eb04 100644
--- a/libc/src/__support/math/sinhbf16.h
+++ b/libc/src/__support/math/sinhbf16.h
@@ -26,7 +26,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE constexpr bfloat16 sinhbf16(bfloat16 x) {
+LIBC_INLINE LIBC_CONSTEXPR bfloat16 sinhbf16(bfloat16 x) {
using FPBits = fputil::FPBits<bfloat16>;
FPBits x_bits(x);
uint16_t x_u = x_bits.uintval();
diff --git a/libc/src/__support/math/sinhbf16coshbf16_utils.h b/libc/src/__support/math/sinhbf16coshbf16_utils.h
index 4e51813d7e5c74..829bac859f31e1 100644
--- a/libc/src/__support/math/sinhbf16coshbf16_utils.h
+++ b/libc/src/__support/math/sinhbf16coshbf16_utils.h
@@ -18,6 +18,7 @@
#include "src/__support/FPUtil/PolyEval.h"
#include "src/__support/FPUtil/multiply_add.h"
#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
@@ -76,7 +77,7 @@ LIBC_INLINE_VAR 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 constexpr float eval_sinh_or_cosh(float xf) {
+template <bool IsSinh> LIBC_INLINE LIBC_CONSTEXPR float eval_sinh_or_cosh(float xf) {
float kf = fputil::nearest_integer(xf * (LOG2F_E * 0x1.0p+5f));
int x_hi_mid_p = static_cast<int>(kf);
int x_hi_mid_m = -x_hi_mid_p;
@@ -130,7 +131,7 @@ template <bool IsSinh> LIBC_INLINE constexpr float eval_sinh_or_cosh(float xf) {
}
// Calculate e^x / 2
-LIBC_INLINE constexpr float exp_half(float xf) {
+LIBC_INLINE LIBC_CONSTEXPR float exp_half(float xf) {
float kf = fputil::nearest_integer(xf * (LOG2F_E * 0x1.0p+5f));
int x_hi_mid_p = static_cast<int>(kf);
diff --git a/libc/test/src/math/sinhbf16_test.cpp b/libc/test/src/math/sinhbf16_test.cpp
index f5115d48547f46..2b34bfc1ea19d1 100644
--- a/libc/test/src/math/sinhbf16_test.cpp
+++ b/libc/test/src/math/sinhbf16_test.cpp
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "src/__support/FPUtil/bfloat16.h"
-#include "src/math/expbf16.h"
#include "src/math/sinhbf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index f0b00fda97155d..a2d3c9b12a3896 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -10617,9 +10617,9 @@ libc_support_library(
":__support_fputil_bfloat16",
":__support_fputil_cast",
":__support_fputil_fp_bits",
+ ":__support_macros_attributes",
":__support_macros_config",
":__support_macros_optimization",
- ":__support_sincosf_utils",
":__support_math_sinhbf16coshbf16_utils",
],
)
>From e9914efa99bdc8c076c72edeb7b8a4b75f1ac31b Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Mon, 28 Sep 2026 19:54:38 +1000
Subject: [PATCH 07/17] formatting
---
libc/src/__support/math/sinhbf16coshbf16_utils.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/math/sinhbf16coshbf16_utils.h b/libc/src/__support/math/sinhbf16coshbf16_utils.h
index 829bac859f31e1..f7ed1b6efb4d7f 100644
--- a/libc/src/__support/math/sinhbf16coshbf16_utils.h
+++ b/libc/src/__support/math/sinhbf16coshbf16_utils.h
@@ -77,7 +77,8 @@ LIBC_INLINE_VAR 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 LIBC_CONSTEXPR float eval_sinh_or_cosh(float xf) {
+template <bool IsSinh>
+LIBC_INLINE LIBC_CONSTEXPR float eval_sinh_or_cosh(float xf) {
float kf = fputil::nearest_integer(xf * (LOG2F_E * 0x1.0p+5f));
int x_hi_mid_p = static_cast<int>(kf);
int x_hi_mid_m = -x_hi_mid_p;
>From db9be25cb1fb6c5d1c94bfcc6b231860cd018fa3 Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Tue, 29 Sep 2026 21:01:41 +1000
Subject: [PATCH 08/17] remove LIBC_CONSTEXPR to fix libc-shared-tests gcc-11
---
libc/src/__support/math/sinhbf16.h | 2 +-
libc/src/__support/math/sinhbf16coshbf16_utils.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/src/__support/math/sinhbf16.h b/libc/src/__support/math/sinhbf16.h
index 6216e353c0eb04..e3258848e8fa6e 100644
--- a/libc/src/__support/math/sinhbf16.h
+++ b/libc/src/__support/math/sinhbf16.h
@@ -26,7 +26,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE LIBC_CONSTEXPR bfloat16 sinhbf16(bfloat16 x) {
+LIBC_INLINE bfloat16 sinhbf16(bfloat16 x) {
using FPBits = fputil::FPBits<bfloat16>;
FPBits x_bits(x);
uint16_t x_u = x_bits.uintval();
diff --git a/libc/src/__support/math/sinhbf16coshbf16_utils.h b/libc/src/__support/math/sinhbf16coshbf16_utils.h
index f7ed1b6efb4d7f..c3663a55df0e1f 100644
--- a/libc/src/__support/math/sinhbf16coshbf16_utils.h
+++ b/libc/src/__support/math/sinhbf16coshbf16_utils.h
@@ -78,7 +78,7 @@ LIBC_INLINE_VAR constexpr cpp::array<uint32_t, 32> EXP2_MID_5_BITS = {
// the polynomials approximating lower parts of e^x and e^(-x) is shared and
// only done once.
template <bool IsSinh>
-LIBC_INLINE LIBC_CONSTEXPR float eval_sinh_or_cosh(float xf) {
+LIBC_INLINE float eval_sinh_or_cosh(float xf) {
float kf = fputil::nearest_integer(xf * (LOG2F_E * 0x1.0p+5f));
int x_hi_mid_p = static_cast<int>(kf);
int x_hi_mid_m = -x_hi_mid_p;
@@ -132,7 +132,7 @@ LIBC_INLINE LIBC_CONSTEXPR float eval_sinh_or_cosh(float xf) {
}
// Calculate e^x / 2
-LIBC_INLINE LIBC_CONSTEXPR float exp_half(float xf) {
+LIBC_INLINE float exp_half(float xf) {
float kf = fputil::nearest_integer(xf * (LOG2F_E * 0x1.0p+5f));
int x_hi_mid_p = static_cast<int>(kf);
>From 85961dc8d8d53182597ad29fd2955533791b4022 Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Thu, 1 Oct 2026 21:53:27 +1000
Subject: [PATCH 09/17] formatting, dependancies
---
libc/include/math.yaml | 6 ------
libc/src/__support/math/sinhbf16coshbf16_utils.h | 3 +--
libc/test/shared/CMakeLists.txt | 2 +-
libc/test/src/math/smoke/CMakeLists.txt | 3 ++-
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 -
5 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/libc/include/math.yaml b/libc/include/math.yaml
index cdd0c6fbe1b3a2..006233e579f86c 100644
--- a/libc/include/math.yaml
+++ b/libc/include/math.yaml
@@ -2659,12 +2659,6 @@ functions:
return_type: float
arguments:
- type: float
- - name: sinhbf16
- standards:
- - stdc
- return_type: _Float16
- arguments:
- - type: _Float16
- name: sinhf16
standards:
- stdc
diff --git a/libc/src/__support/math/sinhbf16coshbf16_utils.h b/libc/src/__support/math/sinhbf16coshbf16_utils.h
index c3663a55df0e1f..b136ecaa376aac 100644
--- a/libc/src/__support/math/sinhbf16coshbf16_utils.h
+++ b/libc/src/__support/math/sinhbf16coshbf16_utils.h
@@ -77,8 +77,7 @@ LIBC_INLINE_VAR 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 float eval_sinh_or_cosh(float xf) {
+template <bool IsSinh> LIBC_INLINE float eval_sinh_or_cosh(float xf) {
float kf = fputil::nearest_integer(xf * (LOG2F_E * 0x1.0p+5f));
int x_hi_mid_p = static_cast<int>(kf);
int x_hi_mid_m = -x_hi_mid_p;
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 927b99faa8e6ff..17dd50e9ef9b4e 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -471,9 +471,9 @@ else()
libc.src.__support.math.sincos
libc.src.__support.math.sincosf
libc.src.__support.math.sinf
- libc.src.__support.math.sinbf16
libc.src.__support.math.sinf16
libc.src.__support.math.sinhf
+ libc.src.__support.math.sinhbf16
libc.src.__support.math.sinhf16
libc.src.__support.math.sqrtf128
libc.src.__support.math.sinpif
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 6e45b79c26a4d2..7e5c1214712042 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4771,9 +4771,10 @@ add_fp_unittest(
sinhbf16_test.cpp
DEPENDS
libc.hdr.errno_macros
- libc.src.math.sinhbf16
libc.hdr.fenv_macros
+ libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.bfloat16
+ libc.src.math.sinhbf16
)
add_fp_unittest(
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index a2d3c9b12a3896..17e82344e2a19d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -10674,7 +10674,6 @@ libc_support_library(
name = "__support_math_sinhbf16coshbf16_utils",
hdrs = ["src/__support/math/sinhbf16coshbf16_utils.h"],
deps = [
- ":__support_fputil_cast",
":__support_fputil_fp_bits",
":__support_fputil_multiply_add",
":__support_fputil_nearest_integer",
>From 01efc1666cf42a6a8288f04622d007901fb2b897 Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Thu, 1 Oct 2026 22:15:15 +1000
Subject: [PATCH 10/17] add FEnvImpl dependancy
---
libc/src/__support/math/CMakeLists.txt | 2 ++
libc/src/__support/math/sinhbf16.h | 1 +
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 +
3 files changed, 4 insertions(+)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 643416ad3747a4..b7af0fbee6b911 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -5388,6 +5388,8 @@ add_header_library(
sinhbf16.h
DEPENDS
.sinhbf16coshbf16_utils
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.bfloat16
libc.src.__support.FPUtil.cast
libc.src.__support.macros.config
diff --git a/libc/src/__support/math/sinhbf16.h b/libc/src/__support/math/sinhbf16.h
index e3258848e8fa6e..ffd57d66349312 100644
--- a/libc/src/__support/math/sinhbf16.h
+++ b/libc/src/__support/math/sinhbf16.h
@@ -15,6 +15,7 @@
#define LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16_H
#include "sinhbf16coshbf16_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/cast.h"
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 17e82344e2a19d..d85ce45f0543a7 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -10616,6 +10616,7 @@ libc_support_library(
deps = [
":__support_fputil_bfloat16",
":__support_fputil_cast",
+ ":__support_fputil_fenv_impl",
":__support_fputil_fp_bits",
":__support_macros_attributes",
":__support_macros_config",
>From c6a184aadff00d52dddeea490406ed5bb149a717 Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Sat, 24 Oct 2026 21:19:41 +1100
Subject: [PATCH 11/17] Use Estrin's scheme directly
---
libc/src/__support/math/sinhbf16coshbf16_utils.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/src/__support/math/sinhbf16coshbf16_utils.h b/libc/src/__support/math/sinhbf16coshbf16_utils.h
index b136ecaa376aac..769221b3ba9a87 100644
--- a/libc/src/__support/math/sinhbf16coshbf16_utils.h
+++ b/libc/src/__support/math/sinhbf16coshbf16_utils.h
@@ -152,10 +152,10 @@ LIBC_INLINE float exp_half(float xf) {
constexpr cpp::array<float, 4> COEFFS = {0x1p+0f, 0x1p+0f, 0x1.0004p-1f,
0x1.555778p-3f};
- float p_odd = fputil::polyeval(lo_sq, COEFFS[1], COEFFS[3]);
- float p_even = fputil::polyeval(lo_sq, COEFFS[0], COEFFS[2]);
+ float p_even = fputil::multiply_add(lo, COEFFS[1], COEFFS[0]);
+ float p_odd = fputil::multiply_add(lo, COEFFS[3], COEFFS[2]);
- float exp_lo = p_even + lo * p_odd;
+ float exp_lo = fputil::multiply_add(lo_sq, p_odd, p_even);
// exp(x) / 2 = 2^(hi + mid - 1) * exp(lo).
float result = exp2_hi_mid_p * exp_lo;
>From e7b3f30977fb2dd100eba5eee543c52ebc8ea7cb Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Sat, 24 Oct 2026 21:27:04 +1100
Subject: [PATCH 12/17] rename sinhbf16coshbf16_utils to sinhcoshbf16_utils
---
libc/src/__support/math/CMakeLists.txt | 6 +++---
libc/src/__support/math/sinhbf16.h | 6 +++---
...16coshbf16_utils.h => sinhcoshbf16_utils.h} | 10 +++++-----
libc/utils/MPFRWrapper/CMakeLists.txt | 18 ++++++++++++++----
.../llvm-project-overlay/libc/BUILD.bazel | 6 +++---
5 files changed, 28 insertions(+), 18 deletions(-)
rename libc/src/__support/math/{sinhbf16coshbf16_utils.h => sinhcoshbf16_utils.h} (96%)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index b7af0fbee6b911..b95e2d6a7e49ff 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -4933,9 +4933,9 @@ add_header_library(
)
add_header_library(
- sinhbf16coshbf16_utils
+ sinhcoshbf16_utils
HDRS
- sinhbf16coshbf16_utils.h
+ sinhcoshbf16_utils.h
DEPENDS
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.polyeval
@@ -5387,7 +5387,7 @@ add_header_library(
HDRS
sinhbf16.h
DEPENDS
- .sinhbf16coshbf16_utils
+ .sinhcoshbf16_utils
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.bfloat16
diff --git a/libc/src/__support/math/sinhbf16.h b/libc/src/__support/math/sinhbf16.h
index ffd57d66349312..4e9012052b618c 100644
--- a/libc/src/__support/math/sinhbf16.h
+++ b/libc/src/__support/math/sinhbf16.h
@@ -14,7 +14,7 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16_H
-#include "sinhbf16coshbf16_utils.h"
+#include "sinhcoshbf16_utils.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/bfloat16.h"
@@ -91,7 +91,7 @@ LIBC_INLINE bfloat16 sinhbf16(bfloat16 x) {
if (x_abs >= 0x40dc) {
uint32_t x_abs_bits = fputil::FPBits<float>(xf).uintval() & 0x7fffffff;
float x_abs_f = fputil::FPBits<float>(x_abs_bits).get_val();
- float abs_result = math::sinhbf16coshbf16_internal::exp_half(x_abs_f);
+ float abs_result = math::sinhcoshbf16_internal::exp_half(x_abs_f);
if (x_u & 0x8000) {
abs_result = -abs_result;
}
@@ -100,7 +100,7 @@ LIBC_INLINE bfloat16 sinhbf16(bfloat16 x) {
// sinh(x) = (e^x - e^(-x)) / 2.
float result = static_cast<float>(
- math::sinhbf16coshbf16_internal::eval_sinh_or_cosh</*is_sinh*/ true>(xf));
+ math::sinhcoshbf16_internal::eval_sinh_or_cosh</*is_sinh*/ true>(xf));
return fputil::cast<bfloat16>(result);
}
diff --git a/libc/src/__support/math/sinhbf16coshbf16_utils.h b/libc/src/__support/math/sinhcoshbf16_utils.h
similarity index 96%
rename from libc/src/__support/math/sinhbf16coshbf16_utils.h
rename to libc/src/__support/math/sinhcoshbf16_utils.h
index 769221b3ba9a87..351a9afc02ffb0 100644
--- a/libc/src/__support/math/sinhbf16coshbf16_utils.h
+++ b/libc/src/__support/math/sinhcoshbf16_utils.h
@@ -11,8 +11,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16COSHBF16_UTILS_H
-#define LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16COSHBF16_UTILS_H
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINHCOSHBF16_UTILS_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SINHCOSHBF16_UTILS_H
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/PolyEval.h"
@@ -25,7 +25,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-namespace sinhbf16coshbf16_internal {
+namespace sinhcoshbf16_internal {
LIBC_INLINE_VAR constexpr float LOG2F_E = 0x1.715476p+0f;
@@ -162,10 +162,10 @@ LIBC_INLINE float exp_half(float xf) {
return result;
}
-} // namespace sinhbf16coshbf16_internal
+} // namespace sinhcoshbf16_internal
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16COSHBF16_UTILS_H
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINHCOSHBF16_UTILS_H
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index 8efa6fc1f0b126..58e3d7b38c1de8 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -20,8 +20,12 @@ if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
libc.test.UnitTest.FPTestHelpers
)
if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
- target_link_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ target_include_directories(libcMPCommon PUBLIC
+ ${LLVM_LIBC_MPFR_INSTALL_PATH}/include
+ /opt/homebrew/opt/gmp/include)
+ target_link_directories(libcMPCommon PUBLIC
+ ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib
+ /opt/homebrew/opt/gmp/lib)
endif()
target_include_directories(libcMPCommon PUBLIC ${LIBC_SOURCE_DIR})
target_link_libraries(libcMPCommon PUBLIC mpfr gmp)
@@ -51,9 +55,15 @@ if(LIBC_TESTS_CAN_USE_MPFR)
libc.test.UnitTest.LibcTest
)
if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
- target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ target_include_directories(libcMPFRWrapper PUBLIC
+ ${LLVM_LIBC_MPFR_INSTALL_PATH}/include
+ /opt/homebrew/opt/gmp/include)
+
+ target_link_directories(libcMPFRWrapper PUBLIC
+ ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib
+ /opt/homebrew/opt/gmp/lib)
endif()
+
target_include_directories(libcMPFRWrapper PUBLIC ${LIBC_SOURCE_DIR})
target_link_libraries(libcMPFRWrapper PUBLIC libcMPCommon)
elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index d85ce45f0543a7..c7a1426db229cf 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -10621,7 +10621,7 @@ libc_support_library(
":__support_macros_attributes",
":__support_macros_config",
":__support_macros_optimization",
- ":__support_math_sinhbf16coshbf16_utils",
+ ":__support_math_sinhcoshbf16_utils",
],
)
@@ -10672,8 +10672,8 @@ libc_support_library(
)
libc_support_library(
- name = "__support_math_sinhbf16coshbf16_utils",
- hdrs = ["src/__support/math/sinhbf16coshbf16_utils.h"],
+ name = "__support_math_sinhcoshbf16_utils",
+ hdrs = ["src/__support/math/sinhcoshbf16_utils.h"],
deps = [
":__support_fputil_fp_bits",
":__support_fputil_multiply_add",
>From 1d04aee5423fcf9cd4ff7cf14018ee9a6034fb0e Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Sat, 24 Oct 2026 21:30:06 +1100
Subject: [PATCH 13/17] undo accidental commit
---
libc/utils/MPFRWrapper/CMakeLists.txt | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index 58e3d7b38c1de8..8efa6fc1f0b126 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -20,12 +20,8 @@ if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
libc.test.UnitTest.FPTestHelpers
)
if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPCommon PUBLIC
- ${LLVM_LIBC_MPFR_INSTALL_PATH}/include
- /opt/homebrew/opt/gmp/include)
- target_link_directories(libcMPCommon PUBLIC
- ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib
- /opt/homebrew/opt/gmp/lib)
+ target_include_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
endif()
target_include_directories(libcMPCommon PUBLIC ${LIBC_SOURCE_DIR})
target_link_libraries(libcMPCommon PUBLIC mpfr gmp)
@@ -55,15 +51,9 @@ if(LIBC_TESTS_CAN_USE_MPFR)
libc.test.UnitTest.LibcTest
)
if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPFRWrapper PUBLIC
- ${LLVM_LIBC_MPFR_INSTALL_PATH}/include
- /opt/homebrew/opt/gmp/include)
-
- target_link_directories(libcMPFRWrapper PUBLIC
- ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib
- /opt/homebrew/opt/gmp/lib)
+ target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
endif()
-
target_include_directories(libcMPFRWrapper PUBLIC ${LIBC_SOURCE_DIR})
target_link_libraries(libcMPFRWrapper PUBLIC libcMPCommon)
elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
>From 3bb1d9402859653f839e257b57dcb26ff2f3cf0e Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Sat, 24 Oct 2026 21:59:53 +1100
Subject: [PATCH 14/17] remove libc/docs/headers/math/index.rst
---
libc/docs/headers/math/index.rst | 637 -------------------------------
1 file changed, 637 deletions(-)
delete mode 100644 libc/docs/headers/math/index.rst
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
deleted file mode 100644
index 60dc3fb152f59c..00000000000000
--- a/libc/docs/headers/math/index.rst
+++ /dev/null
@@ -1,637 +0,0 @@
-.. _math:
-
-======
-math.h
-======
-
-.. raw:: html
-
- <style> .green {color:green} </style>
-
-.. role:: green
-
-.. toctree::
- :hidden:
-
- log.rst
-
-
-Source Locations
-================
-
-- The main source is located at: `libc/src/math <https://github.com/llvm/llvm-project/tree/main/libc/src/math>`_.
-- The tests are located at: `libc/test/src/math <https://github.com/llvm/llvm-project/tree/main/libc/test/src/math>`_.
-- The floating point utilities are located at: `libc/src/__support/FPUtil <https://github.com/llvm/llvm-project/tree/main/libc/src/__support/FPUtil>`_.
-
-Implementation Requirements / Goals
-===================================
-
-* The highest priority is to be as accurate as possible, according to the C and
- IEEE 754 standards. By default, we will aim to be correctly rounded for `all rounding modes <https://en.cppreference.com/w/c/numeric/fenv/FE_round>`_.
- The current rounding mode of the floating point environment is used to perform
- computations and produce the final results.
-
- - To test for correctness, we compare the outputs with other correctly rounded
- multiple-precision math libraries such as the `GNU MPFR library <https://www.mpfr.org/>`_
- or the `CORE-MATH library <https://core-math.gitlabpages.inria.fr/>`_.
-
-* Our next requirement is that the outputs are consistent across all platforms.
- Notice that the consistency requirement will be satisfied automatically if the
- implementation is correctly rounded.
-
-* Our last requirement for the implementations is to have good and predicable
- performance:
-
- - The average performance should be comparable to other ``libc``
- implementations.
- - The worst case performance should be within 10X-20X of the average.
- - Platform-specific implementations or instructions could be added whenever it
- makes sense and provides significant performance boost.
-
-* For other use cases that have strict requirements on the code size, memory
- footprint, or latency, such as embedded systems, we will aim to be as accurate
- as possible within the memory or latency budgets, and consistent across all
- platforms.
-
-
-Add a new math function to LLVM libc
-====================================
-
-* To add a new math function, follow the steps at: `libc/src/math/docs/add_math_function.md <https://github.com/llvm/llvm-project/tree/main/libc/src/math/docs/add_math_function.md>`_.
-
-Implementation Status
-=====================
-
-* To check math functions enabled for Linux:
-
- - `linux-x86_64 <https://github.com/llvm/llvm-project/tree/main/libc/config/linux/x86_64/entrypoints.txt>`_
-
- - `linux-aarch64 <https://github.com/llvm/llvm-project/tree/main/libc/config/linux/aarch64/entrypoints.txt>`_
-
- - `linux-aarch32 <https://github.com/llvm/llvm-project/tree/main/libc/config/linux/arm/entrypoints.txt>`_
-
- - `linux-riscv and linux-riscv32 <https://github.com/llvm/llvm-project/tree/main/libc/config/linux/riscv/entrypoints.txt>`_
-
-* To check math functions enabled for Windows:
-
- - `windows-x86_64 <https://github.com/llvm/llvm-project/tree/main/libc/config/windows/entrypoints.txt>`_
-
- - windows-aarch64 - to be added
-
-* To check math functions enabled for macOS:
-
- - `darwin-x86_64 <https://github.com/llvm/llvm-project/tree/main/libc/config/darwin/x86_64/entrypoints.txt>`_
-
- - `darwin-aarch64 <https://github.com/llvm/llvm-project/tree/main/libc/config/darwin/aarch64/entrypoints.txt>`_
-
-* To check math functions enabled for GPU:
-
- - `amdgpu-entrypoints <https://github.com/llvm/llvm-project/tree/main/libc/config/gpu/amdgpu/entrypoints.txt>`_
-
- - `nvptx-entrypoints <https://github.com/llvm/llvm-project/tree/main/libc/config/gpu/nvptx/entrypoints.txt>`_
-
-* To check math functions enabled for embedded system:
-
- - `baremetal-aarch64 <https://github.com/llvm/llvm-project/tree/main/libc/config/baremetal/aarch64/entrypoints.txt>`_
-
- - `baremetal-aarch32 <https://github.com/llvm/llvm-project/tree/main/libc/config/baremetal/arm/entrypoints.txt>`_
-
- - `baremetal-riscv32 <https://github.com/llvm/llvm-project/tree/main/libc/config/baremetal/riscv/entrypoints.txt>`_
-
-
-Basic Operations
-================
-
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| <Func> | <Func_f> (float) | <Func> (double) | <Func_l> (long double) | <Func_f16> (float16) | <Func_f128> (float128) | <Func_bf16> (bfloat16) | C23 Definition Section | C23 Error Handling Section |
-+==================+==================+=================+========================+======================+========================+========================+========================+============================+
-| ceil | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.1 | F.10.6.1 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| canonicalize | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.11.7 | F.10.8.7 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| copysign | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.11.1 | F.10.8.1 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| dadd | N/A | N/A | |check| | N/A | |check|\* | N/A | 7.12.14.1 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ddiv | N/A | N/A | |check| | N/A | |check|\* | N/A | 7.12.14.4 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| dfma | N/A | N/A | |check| | N/A | |check|\* | N/A | 7.12.14.5 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| dmul | N/A | N/A | |check| | N/A | |check|\* | N/A | 7.12.14.3 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| dsub | N/A | N/A | |check| | N/A | |check|\* | N/A | 7.12.14.2 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| f16add | |check|\* | |check|\* | |check|\* | N/A | |check| | N/A | 7.12.14.1 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| f16div | |check|\* | |check|\* | |check|\* | N/A | |check| | N/A | 7.12.14.4 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| f16fma | |check|\* | |check|\* | |check|\* | N/A | |check| | N/A | 7.12.14.5 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| f16mul | |check|\* | |check|\* | |check|\* | N/A | |check| | N/A | 7.12.14.3 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| f16sub | |check|\* | |check|\* | |check|\* | N/A | |check| | N/A | 7.12.14.2 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| bf16add | |check|\* | |check|\* | |check|\* | N/A | |check| | N/A | 7.12.14.1 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| bf16div | |check|\* | |check|\* | |check|\* | N/A | |check| | N/A | 7.12.14.4 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| bf16fma | |check|\* | |check|\* | |check|\* | N/A | |check| | N/A | 7.12.14.5 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| bf16mul | |check|\* | |check|\* | |check|\* | N/A | |check| | N/A | 7.12.14.3 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| bf16sub | |check|\* | |check|\* | |check|\* | N/A | |check| | N/A | 7.12.14.2 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fabs | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.7.3 | F.10.4.3 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fadd | N/A | |check| | |check| | N/A | |check| | N/A | 7.12.14.1 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fdim | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.1 | F.10.9.1 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fdiv | N/A | |check| | |check| | N/A | |check|\* | N/A | 7.12.14.4 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ffma | N/A | |check| | |check| | N/A | |check|\* | N/A | 7.12.14.5 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| floor | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.2 | F.10.6.2 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fmax | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.2 | F.10.9.2 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fmaximum | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.4 | F.10.9.4 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fmaximum_mag | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.6 | F.10.9.4 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fmaximum_mag_num | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.10 | F.10.9.5 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fmaximum_num | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.8 | F.10.9.5 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fmin | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.3 | F.10.9.3 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fminimum | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.5 | F.10.9.4 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fminimum_mag | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.7 | F.10.9.4 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fminimum_mag_num | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.11 | F.10.9.5 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fminimum_num | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.12.9 | F.10.9.5 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fmod | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.10.1 | F.10.7.1 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fmul | N/A | |check| | |check| | N/A | |check|\* | N/A | 7.12.14.3 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| frexp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.7 | F.10.3.7 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fromfp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.10 | F.10.6.10 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fromfpx | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.11 | F.10.6.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fsub | N/A | |check| | |check| | N/A | |check|\* | N/A | 7.12.14.2 | F.10.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| getpayload | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.1 | N/A |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ilogb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.8 | F.10.3.8 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| iscanonical | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.3.2 | N/A |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| issignaling | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.3.8 | N/A |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ldexp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.9 | F.10.3.9 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| llogb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.10 | F.10.3.10 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| llrint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| llround | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| logb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.17 | F.10.3.17 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| lrint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| lround | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| modf | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.18 | F.10.3.18 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| nan | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.11.2 | F.10.8.2 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| nearbyint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.3 | F.10.6.3 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| nextafter | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.11.3 | F.10.8.3 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| nextdown | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.11.6 | F.10.8.6 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| nexttoward | |check| | |check| | |check| | |check| | N/A | |check| | 7.12.11.4 | F.10.8.4 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| nextup | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.11.5 | F.10.8.5 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| remainder | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.10.2 | F.10.7.2 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| remquo | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.10.3 | F.10.7.3 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| rint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.4 | F.10.6.4 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| round | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.6 | F.10.6.6 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| roundeven | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.8 | F.10.6.8 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| scalbln | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| scalbn | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| setpayload | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.2 | N/A |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| setpayloadsig | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.3 | N/A |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| totalorder | |check| | |check| | |check| | |check| | |check| | |check| | F.10.12.1 | N/A |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| totalordermag | |check| | |check| | |check| | |check| | |check| | |check| | F.10.12.2 | N/A |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| trunc | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.9 | F.10.6.9 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ufromfp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.10 | F.10.6.10 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ufromfpx | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.11 | F.10.6.11 |
-+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-
-Higher Math Functions
-=====================
-
-
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+----------++------------+------------------------+----------------------------+
-| <Func> | <Func_f> (float) | <Func> (double) | <Func_l> (long double) | <Func_f16> (float16) | <Func_f128> (float128) | <Func_bf16> (bfloat16) | C23 Definition Section | C23 Error Handling Section |
-+===========+==================+=================+========================+======================+========================+========================+========================+============================+
-| acos | |check| | |check| | | |check| | | |check| | 7.12.4.1 | F.10.1.1 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| acosh | |check| | | | |check| | | | 7.12.5.1 | F.10.2.1 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| acospi | | | | |check| | | | 7.12.4.8 | F.10.1.8 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| asin | |check| | |check| | | |check| | | |check| | 7.12.4.2 | F.10.1.2 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| asinh | |check| | | | |check| | | | 7.12.5.2 | F.10.2.2 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| asinpi | |check| | |check| | | |check| | | | 7.12.4.9 | F.10.1.9 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| atan | |check| | 1 ULP | | |check| | | |check| | 7.12.4.3 | F.10.1.3 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| atan2 | |check| | 1 ULP | | |check| | 1 ULP | | 7.12.4.4 | F.10.1.4 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| atan2pi | | | | | | | 7.12.4.11 | F.10.1.11 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| atanh | |check| | | | |check| | | | 7.12.5.3 | F.10.2.3 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| atanpi | | | | |check| | | | 7.12.4.10 | F.10.1.10 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| cbrt | |check| | |check| | | |check| | | |check| | 7.12.7.1 | F.10.4.1 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| compoundn | | | | | | | 7.12.7.2 | F.10.4.2 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| cos | |check| | |check| | | |check| | | | 7.12.4.5 | F.10.1.5 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| cosh | |check| | | | |check| | | | 7.12.5.4 | F.10.2.4 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| cospi | |check| | | | |check| | | | 7.12.4.12 | F.10.1.12 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| dsqrt | N/A | N/A | |check| | N/A | |check|\* | | 7.12.14.6 | F.10.11 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| erf | |check| | | | | | | 7.12.8.1 | F.10.5.1 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| erfc | | | | | | | 7.12.8.2 | F.10.5.2 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| exp | |check| | |check| | | |check| | | |check| | 7.12.6.1 | F.10.3.1 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| exp10 | |check| | |check| | | |check| | | | 7.12.6.2 | F.10.3.2 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| exp10m1 | |check| | | | |check| | | | 7.12.6.3 | F.10.3.3 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| exp2 | |check| | |check| | | |check| | | | 7.12.6.4 | F.10.3.4 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| exp2m1 | |check| | | | |check| | | | 7.12.6.5 | F.10.3.5 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| expm1 | |check| | |check| | | |check| | | | 7.12.6.6 | F.10.3.6 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fma | |check| | |check| | | |check| | | |check| | 7.12.13.1 | F.10.10.1 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| f16sqrt | |check|\* | |check|\* | |check|\* | N/A | |check| | | 7.12.14.6 | F.10.11 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fsqrt | N/A | |check| | |check| | N/A | |check|\* | | 7.12.14.6 | F.10.11 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| hypot | |check| | |check| | | |check| | | |check| | 7.12.7.4 | F.10.4.4 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| lgamma | | | | |check| | | | 7.12.8.3 | F.10.5.3 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| log | |check| | |check| | | |check| | | |check| ? | 7.12.6.11 | F.10.3.11 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| log10 | |check| | |check| | | |check| | | | 7.12.6.12 | F.10.3.12 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| log10p1 | | | | |check| | | | 7.12.6.13 | F.10.3.13 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| log1p | |check| | |check| | | | | | 7.12.6.14 | F.10.3.14 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| log2 | |check| | |check| | | |check| | | | 7.12.6.15 | F.10.3.15 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| log2p1 | | | | |check| | | | 7.12.6.16 | F.10.3.16 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| logp1 | | | | | | | 7.12.6.14 | F.10.3.14 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| pow | |check| | 1 ULP | | | | | 7.12.7.5 | F.10.4.5 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| powi\* | | | | | | | | |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| pown | | | | | | | 7.12.7.6 | F.10.4.6 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| powr | | | | | | | 7.12.7.7 | F.10.4.7 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| rootn | | | | | | | 7.12.7.8 | F.10.4.8 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| rsqrt | |check| | | | |check| | | | 7.12.7.9 | F.10.4.9 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| sin | |check| | |check| | | |check| | | | 7.12.4.6 | F.10.1.6 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| sincos | |check| | |check| | | | | | | |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| sinh | |check| | | | |check| | | |check| | 7.12.5.5 | F.10.2.5 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| sinpi | |check| | | | |check| | | | 7.12.4.13 | F.10.1.13 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| sqrt | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.7.10 | F.10.4.10 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| tan | |check| | |check| | | |check| | | |check| | 7.12.4.7 | F.10.1.7 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| tanh | |check| | | | |check| | | | 7.12.5.6 | F.10.2.6 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| tanpi | |check| | | | |check| | | | 7.12.4.14 | F.10.1.14 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| tgamma | | | | | | | 7.12.8.4 | F.10.5.4 |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-
-
-Legends:
-
-* |check| : correctly rounded for all 4 rounding modes.
-* CR: correctly rounded for the default rounding mode (round-to-the-nearest,
- tie-to-even).
-* x ULPs: largest errors recorded.
-* N/A: Not defined in the standard or will not be added.
-* \*: LLVM libc extension.
-* ? Because of a conflict between float16 logb function and bfloat16 log function, the latter is implemented as `log_bf16`.
-
-..
- TODO(lntue): Add a new page to discuss about the algorithms used in the
- implementations and include the link here.
-
-GPU Conformance
-===============
-
-* Conformance tests are located at: `offload/unittests/Conformance <https://github.com/llvm/llvm-project/tree/main/offload/unittests/Conformance>`_.
-
-* The math functions for GPUs are compiled with the following optimization options: ``LIBC_MATH_SKIP_ACCURATE_PASS``, ``LIBC_MATH_INTERMEDIATE_COMP_IN_FLOAT``, ``LIBC_MATH_SMALL_TABLES``, ``LIBC_MATH_NO_ERRNO``, and ``LIBC_MATH_NO_EXCEPT``.
-
-* The conformance test results for higher math functions on GPUs are reported in the table below. The results show the maximum observed ULP distance when comparing a given GPU implementation against the corresponding correctly rounded implementation from LLVM libc, which is computed on the host CPU and serves as the reference. For comparison purposes, results for CUDA Math and HIP Math against the same reference are also included.
-
-+------------------------+-------------+---------------+-----------------------------------------------------------------------------------+
-| Function | Test Method | ULP Tolerance | Max ULP Distance |
-| | | +--------------------+--------------------+--------------------+--------------------+
-| | | | LLVM libc | LLVM libc | CUDA Math | HIP Math |
-| | | | (AMDGPU) | (CUDA) | (CUDA) | (AMDGPU) |
-+========================+=============+===============+====================+====================+====================+====================+
-| acos | Randomized | 4 | 6 (FAILED) | 6 (FAILED) | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| acosf | Exhaustive | 4 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| acosf16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| acoshf | Exhaustive | 4 | 1 | 1 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| acoshf16 | Exhaustive | 2 | 0 | 0 | | 0 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| acospif16 | Exhaustive | 2 | 0 | 0 | | |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| asin | Randomized | 4 | 6 (FAILED) | 6 (FAILED) | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| asinf | Exhaustive | 4 | 1 | 1 | 1 | 3 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| asinf16 | Exhaustive | 2 | 0 | 0 | | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| asinhf | Exhaustive | 4 | 1 | 1 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| asinhf16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| atanf | Exhaustive | 5 | 0 | 0 | 1 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| atanf16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| atan2f | Randomized | 6 | 1 | 1 | 2 | 3 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| atanhf | Exhaustive | 5 | 0 | 0 | 3 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| atanhf16 | Exhaustive | 2 | 0 | 0 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| cbrt | Randomized | 2 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| cbrtf | Exhaustive | 2 | 0 | 0 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| cos | Randomized | 4 | 1 | 1 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| cosf | Exhaustive | 4 | 1 | 1 | 2 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| cosf16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| coshf | Exhaustive | 4 | 0 | 0 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| coshf16 | Exhaustive | 2 | 1 | 0 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| cospif | Exhaustive | 4 | 0 | 0 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| cospif16 | Exhaustive | 2 | 0 | 0 | | |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| erff | Exhaustive | 16 | 0 | 0 | 1 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| exp | Randomized | 3 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| expf | Exhaustive | 3 | 0 | 0 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| expf16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| exp10 | Randomized | 3 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| exp10f | Exhaustive | 3 | 0 | 0 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| exp10f16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| exp2 | Randomized | 3 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| exp2f | Exhaustive | 3 | 1 | 1 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| exp2f16 | Exhaustive | 2 | 1 | 1 | | 0 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| expm1 | Randomized | 3 | 0 | 0 | 1 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| expm1f | Exhaustive | 3 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| expm1f16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| hypot | Randomized | 4 | 0 | 0 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| hypotf | Randomized | 4 | 0 | 0 | 1 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| hypotf16 | Exhaustive | 2 | 0 | 0 | | |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| log | Randomized | 3 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| logf | Exhaustive | 3 | 1 | 1 | 1 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| logf16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| log10 | Randomized | 3 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| log10f | Exhaustive | 3 | 1 | 1 | 2 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| log10f16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| log1p | Randomized | 2 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| log1pf | Exhaustive | 2 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| log2 | Randomized | 3 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| log2f | Exhaustive | 3 | 0 | 0 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| log2f16 | Exhaustive | 2 | 1 | 1 | | 0 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| powf (integer exp.) | Randomized | 16 | 0 | 0 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| powf (real exp.) | Randomized | 16 | 0 | 0 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sin | Randomized | 4 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sinf | Exhaustive | 4 | 1 | 1 | 1 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sinf16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sincos (cos part) | Randomized | 4 | 1 | 1 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sincos (sin part) | Randomized | 4 | 1 | 1 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sincosf (cos part) | Exhaustive | 4 | 1 | 1 | 2 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sincosf (sin part) | Exhaustive | 4 | 1 | 1 | 1 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sinhf | Exhaustive | 4 | 1 | 1 | 3 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sinhf16 | Exhaustive | 2 | 1 | 1 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sinpif | Exhaustive | 4 | 0 | 0 | 1 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| sinpif16 | Exhaustive | 2 | 0 | 0 | | |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| tan | Randomized | 5 | 2 | 2 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| tanf | Exhaustive | 5 | 0 | 0 | 3 | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| tanf16 | Exhaustive | 2 | 1 | 1 | | 2 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| tanhf | Exhaustive | 5 | 0 | 0 | 2 | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| tanhf16 | Exhaustive | 2 | 0 | 0 | | 1 |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| tanpif | Exhaustive | 6 | 0 | 0 | | |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-| tanpif16 | Exhaustive | 2 | 1 | 1 | | |
-+------------------------+-------------+---------------+--------------------+--------------------+--------------------+--------------------+
-
-Notes:
-
-* Exhaustive tests check every representable point in the input space. This method is used for half-precision functions and single-precision univariate functions.
-* Randomized tests check a large, deterministic subset of the input space, typically using 2\ :sup:`32` samples. This method is used for functions with larger input spaces, such as single-precision bivariate and double-precision functions.
-* ULP tolerances are based on The Khronos Group, `The OpenCL C Specification v3.0.19 <https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html>`_, Sec. 7.4, Khronos Registry [July 10, 2025].
-* The AMD GPU used for testing is AMD Radeon RX 6950 XT.
-* The NVIDIA GPU used for testing is NVIDIA RTX 4000 SFF Ada Generation.
-
-Performance
-===========
-
-* Simple performance testings are located at: `libc/test/src/math/performance_testing <https://github.com/llvm/llvm-project/tree/main/libc/test/src/math/performance_testing>`_.
-
-* We also use the *perf* tool from the `CORE-MATH <https://core-math.gitlabpages.inria.fr/>`_
- project: `link <https://gitlab.inria.fr/core-math/core-math/-/tree/master>`_.
- The performance results from the CORE-MATH's perf tool are reported in the
- table below, using the system library as reference (such as the `GNU C library <https://www.gnu.org/software/libc/>`_
- on Linux). Fmod performance results obtained with "performance_testing".
-
-+--------------+-------------------------------+-------------------------------+-------------------------------------+----------------------------------------------------------------------+
-| <Func> | Reciprocal throughput (clk) | Latency (clk) | Testing ranges | Testing configuration |
-| +-----------+-------------------+-----------+-------------------+ +-------------+-------------------------+--------------+---------------+
-| | LLVM libc | Reference (glibc) | LLVM libc | Reference (glibc) | | CPU | OS | Compiler | Special flags |
-+==============+===========+===================+===========+===================+=====================================+=============+=========================+==============+===============+
-| acosf | 24 | 29 | 62 | 77 | :math:`[-1, 1]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| acoshf | 18 | 26 | 73 | 74 | :math:`[1, 21]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| asinf | 23 | 27 | 62 | 62 | :math:`[-1, 1]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| asinhf | 21 | 39 | 77 | 91 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| atanf | 27 | 29 | 79 | 68 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| atanhf | 18 | 66 | 68 | 133 | :math:`[-1, 1]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| cosf | 13 | 32 | 53 | 59 | :math:`[0, 2\pi]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| coshf | 14 | 20 | 50 | 48 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| expf | 9 | 7 | 44 | 38 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| exp10f | 10 | 8 | 40 | 38 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| exp2f | 9 | 6 | 35 | 31 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| expm1f | 9 | 44 | 42 | 121 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| fmodf | 73 | 263 | - | - | [MIN_NORMAL, MAX_NORMAL] | i5 mobile | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | |
-| +-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| | 9 | 11 | - | - | [0, MAX_SUBNORMAL] | i5 mobile | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| fmod | 595 | 3297 | - | - | [MIN_NORMAL, MAX_NORMAL] | i5 mobile | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | |
-| +-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| | 14 | 13 | - | - | [0, MAX_SUBNORMAL] | i5 mobile | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| hypotf | 25 | 15 | 64 | 49 | :math:`[-10, 10] \times [-10, 10]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| logf | 12 | 10 | 56 | 46 | :math:`[e^{-1}, e]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| log10f | 9 | 17 | 35 | 48 | :math:`[e^{-1}, e]` | Ryzen 5900X | Ubuntu 22.04 LTS x86_64 | Clang 15.0.6 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| log1pf | 16 | 33 | 61 | 97 | :math:`[e^{-0.5} - 1, e^{0.5} - 1]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| log2f | 13 | 10 | 57 | 46 | :math:`[e^{-1}, e]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| sinf | 12 | 25 | 51 | 57 | :math:`[-\pi, \pi]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| sincosf | 19 | 30 | 57 | 68 | :math:`[-\pi, \pi]` | Ryzen 1700 | Ubuntu 20.04 LTS x86_64 | Clang 12.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| sinhf | 13 | 63 | 48 | 137 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| tanf | 16 | 50 | 61 | 107 | :math:`[-\pi, \pi]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-| tanhf | 13 | 55 | 57 | 123 | :math:`[-10, 10]` | Ryzen 1700 | Ubuntu 22.04 LTS x86_64 | Clang 14.0.0 | FMA |
-+--------------+-----------+-------------------+-----------+-------------------+-------------------------------------+-------------+-------------------------+--------------+---------------+
-
-Algorithms + Implementation Details
-===================================
-
-* :doc:`log`
-
-Fixed-point Arithmetics
-=======================
-
-* :doc:`../stdfix`
-
-References
-==========
-
-* `CRLIBM <https://hal-ens-lyon.archives-ouvertes.fr/ensl-01529804/file/crlibm.pdf>`_.
-* `RLIBM <https://people.cs.rutgers.edu/~sn349/rlibm/>`_.
-* `Sollya <https://www.sollya.org/>`_.
-* `The CORE-MATH Project <https://core-math.gitlabpages.inria.fr/>`_.
-* `The GNU C Library (glibc) <https://www.gnu.org/software/libc/>`_.
-* `The GNU MPFR Library <https://www.mpfr.org/>`_.
-* `C++23 Standard <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/n4950.pdf>`_.
-* `BFloat16 <https://en.wikipedia.org/wiki/Bfloat16_floating-point_format>`_.
>From 61333e3ef2e9ca0da9cdf804d922bb60131996cd Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Sat, 24 Oct 2026 22:31:10 +1100
Subject: [PATCH 15/17] change libc-math-unittests to libc-math-tests
---
libc/test/src/math/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index f2a3e6c9ce7af5..7b758c0032cfaa 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2615,7 +2615,7 @@ add_fp_unittest(
sinhbf16_test
NEED_MPFR
SUITE
- libc-math-unittests
+ libc-math-tests
SRCS
sinhbf16_test.cpp
DEPENDS
>From 32feb90b0bdbb378e02407c8f5086ae47b14268c Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Sat, 24 Oct 2026 22:47:52 +1100
Subject: [PATCH 16/17] use .abs and .is_neg, remove redundant static_cast
---
libc/src/__support/math/sinhbf16.h | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/libc/src/__support/math/sinhbf16.h b/libc/src/__support/math/sinhbf16.h
index 4e9012052b618c..fe4d454342722e 100644
--- a/libc/src/__support/math/sinhbf16.h
+++ b/libc/src/__support/math/sinhbf16.h
@@ -89,18 +89,17 @@ LIBC_INLINE bfloat16 sinhbf16(bfloat16 x) {
// |x| >= 6.875
// return e^x / 2
if (x_abs >= 0x40dc) {
- uint32_t x_abs_bits = fputil::FPBits<float>(xf).uintval() & 0x7fffffff;
- float x_abs_f = fputil::FPBits<float>(x_abs_bits).get_val();
- float abs_result = math::sinhcoshbf16_internal::exp_half(x_abs_f);
- if (x_u & 0x8000) {
+ float abs_result =
+ math::sinhcoshbf16_internal::exp_half(x_bits.abs().get_val());
+ if (x_bits.is_neg()) {
abs_result = -abs_result;
}
return fputil::cast<bfloat16>(abs_result);
}
// sinh(x) = (e^x - e^(-x)) / 2.
- float result = static_cast<float>(
- math::sinhcoshbf16_internal::eval_sinh_or_cosh</*is_sinh*/ true>(xf));
+ float result =
+ math::sinhcoshbf16_internal::eval_sinh_or_cosh</*is_sinh*/ true>(xf);
return fputil::cast<bfloat16>(result);
}
>From a8b3c3a50c383c2044feae9656ff7ba6125a973d Mon Sep 17 00:00:00 2001
From: Dylan Fernando <dylanf123 at gmail.com>
Date: Sun, 25 Oct 2026 21:02:29 +1100
Subject: [PATCH 17/17] Add errno, fenv, rounding_mode dependancies
---
libc/src/__support/math/CMakeLists.txt | 3 +++
libc/src/__support/math/sinhbf16.h | 5 ++++-
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 3 +++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 0efc829c9feaa7..1b8bfce1545b18 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -5752,10 +5752,13 @@ add_header_library(
sinhbf16.h
DEPENDS
.sinhcoshbf16_utils
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.bfloat16
libc.src.__support.FPUtil.cast
+ libc.src.__support.FPUtil.rounding_mode
libc.src.__support.macros.config
libc.src.__support.macros.attributes
libc.src.__support.macros.optimization
diff --git a/libc/src/__support/math/sinhbf16.h b/libc/src/__support/math/sinhbf16.h
index fe4d454342722e..3be857638bb8e3 100644
--- a/libc/src/__support/math/sinhbf16.h
+++ b/libc/src/__support/math/sinhbf16.h
@@ -14,14 +14,17 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_SINHBF16_H
-#include "sinhcoshbf16_utils.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/bfloat16.h"
#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/rounding_mode.h"
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"
+#include "src/__support/math/sinhcoshbf16_utils.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 487de172dc9bd2..654a4ab8c4a35f 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -11399,10 +11399,13 @@ libc_support_library(
":__support_fputil_cast",
":__support_fputil_fenv_impl",
":__support_fputil_fp_bits",
+ ":__support_fputil_rounding_mode",
":__support_macros_attributes",
":__support_macros_config",
":__support_macros_optimization",
":__support_math_sinhcoshbf16_utils",
+ ":hdr_errno_macros",
+ ":hdr_fenv_macros",
],
)
More information about the libc-commits
mailing list