[libc-commits] [libc] [llvm] [libc][math][c23] Add sinhbf16 function (PR #224645)
via libc-commits
libc-commits at lists.llvm.org
Fri Sep 18 06:57:56 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-nvptx
@llvm/pr-subscribers-backend-amdgpu
Author: dil12321
<details>
<summary>Changes</summary>
Add sinhbf16 higher math function for bfloat16 type.
---
Patch is 24.42 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/224645.diff
30 Files Affected:
- (modified) libc/config/baremetal/aarch64/entrypoints.txt (+1)
- (modified) libc/config/baremetal/arm/entrypoints.txt (+1)
- (modified) libc/config/baremetal/riscv/entrypoints.txt (+1)
- (modified) libc/config/darwin/aarch64/entrypoints.txt (+1)
- (modified) libc/config/darwin/x86_64/entrypoints.txt (+1)
- (modified) libc/config/freebsd/x86_64/entrypoints.txt (+1)
- (modified) libc/config/gpu/amdgpu/entrypoints.txt (+1)
- (modified) libc/config/gpu/nvptx/entrypoints.txt (+1)
- (modified) libc/config/linux/aarch64/entrypoints.txt (+1)
- (modified) libc/config/linux/arm/entrypoints.txt (+1)
- (modified) libc/config/linux/riscv/entrypoints.txt (+1)
- (modified) libc/config/linux/x86_64/entrypoints.txt (+1)
- (modified) libc/config/windows/entrypoints.txt (+1)
- (modified) libc/docs/headers/math/index.rst (+1-1)
- (modified) libc/include/math.yaml (+6)
- (modified) libc/shared/math.h (+1)
- (added) libc/shared/math/sinhbf16.h (+23)
- (modified) libc/src/__support/math/CMakeLists.txt (+13)
- (added) libc/src/__support/math/sinhbf16.h (+97)
- (modified) libc/src/math/CMakeLists.txt (+1)
- (modified) libc/src/math/generic/CMakeLists.txt (+10)
- (added) libc/src/math/generic/sinhbf16.cpp (+18)
- (added) libc/src/math/sinhbf16.h (+21)
- (modified) libc/test/shared/CMakeLists.txt (+1)
- (modified) libc/test/shared/shared_math_test.cpp (+1)
- (modified) libc/test/src/math/CMakeLists.txt (+13)
- (added) libc/test/src/math/sinhbf16_test.cpp (+47)
- (modified) libc/test/src/math/smoke/CMakeLists.txt (+13)
- (added) libc/test/src/math/smoke/sinhbf16_test.cpp (+89)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+20)
``````````diff
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 114534ce61ae6..cdc0eb219fb8a 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 c8148815c34e3..24cd54e88376c 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 622d6156cff11..7d67b314707a3 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 d702b2c5a6549..75561bd049c8b 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 716ab572f8d3c..57b48280a12e4 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 8f6c178301c2f..33987b80a7150 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 5c5e5891da822..8fbdbd897342d 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 afae725484a89..0c65b328bdb8f 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 f87ba3437fb6c..f9ea212ab13d4 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 f4347331d0b31..8cb0d594bd82e 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 51587056fb02d..911003ed26322 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 8b77efa648c43..0cb7d7fa68b79 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 3a48b49e169b3..603717a159c00 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 2d5e188e804d4..60dc3fb152f59 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 006233e579f86..cdd0c6fbe1b3a 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 7b52cedf99c24..17e8b38d64a73 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 0000000000000..a4255838a5d91
--- /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 0871a5bf229b6..58339ad126401 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 0000000000000..6720bd4a265bd
--- /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 2c7568f0b6361..3fb9e8b2d0cc5 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 28b8e954530dd..e243130c997e3 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 0000000000000..eaab609360752
--- /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 0000000000000..91f30cb68f246
--- /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 74eda7cdaf065..927b99faa8e6f 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 7b785331f36c6..147772b30c6f7 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 8f1a543de0a5e..72dd7350ca286 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 0000000000000..f5115d48547f4
--- /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 a61b854a85fb2..6e45b79c26a4d 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
+ ...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/224645
More information about the libc-commits
mailing list