[libc-commits] [libc] [llvm] [libc][math] Implement asinhbf16 (PR #235448)

via libc-commits libc-commits at lists.llvm.org
Sun Oct 25 06:47:26 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-nvptx

Author: Tejaswi2517

<details>
<summary>Changes</summary>

Implements asinhbf16 using the existing asinhf function. The input is converted to float, and the result is rounded once to bfloat16.

Testing:

MPFR-based unit tests covering every non-NaN bfloat16 input across all rounding modes.

Smoke tests for NaN, signaling NaN, positive and negative zero, and positive and negative infinity across all rounding modes.


---

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


32 Files Affected:

- (modified) libc/config/baremetal/aarch64/entrypoints.txt (+1) 
- (modified) libc/config/baremetal/arm/entrypoints.txt (+1) 
- (modified) libc/config/baremetal/hexagon/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.md (+1-1) 
- (modified) libc/shared/math.h (+1) 
- (added) libc/shared/math/asinhbf16.h (+23) 
- (modified) libc/src/__support/math/CMakeLists.txt (+11) 
- (added) libc/src/__support/math/asinhbf16.h (+29) 
- (modified) libc/src/math/CMakeLists.txt (+1) 
- (added) libc/src/math/asinhbf16.h (+21) 
- (modified) libc/src/math/generic/CMakeLists.txt (+10) 
- (added) libc/src/math/generic/asinhbf16.cpp (+18) 
- (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/asinhbf16_test.cpp (+40) 
- (modified) libc/test/src/math/smoke/CMakeLists.txt (+13) 
- (added) libc/test/src/math/smoke/asinhbf16_test.cpp (+41) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+16) 
- (modified) utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel (+7) 
- (modified) utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel (+7) 


``````````diff
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 0202bc7a2dc56b..b447703e93ffc3 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -810,6 +810,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index b7322502d570d4..ec46bb174bfa54 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -821,6 +821,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/baremetal/hexagon/entrypoints.txt b/libc/config/baremetal/hexagon/entrypoints.txt
index 61f869457b3282..ce301a724059e2 100644
--- a/libc/config/baremetal/hexagon/entrypoints.txt
+++ b/libc/config/baremetal/hexagon/entrypoints.txt
@@ -811,6 +811,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 7e68a3c374249d..a1caaa0b56b364 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -813,6 +813,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index c0ce5870c862ec..f5bf9c786b3d52 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -632,6 +632,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index e3fc845d2ed3af..946ce2b67ac621 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -267,6 +267,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 42d52b3ebc6c2c..4c50ad23801e33 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -564,6 +564,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   # bfloat16 entrypoints
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.atanbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index ffbcc4b1672403..379056c57e7561 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -685,6 +685,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index ff31536073543e..b3d99d5e94dccf 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -701,6 +701,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index b193733a02dc5f..88656c1102dc9a 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1042,6 +1042,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 8c7ebf61d5786d..7c4f1ae08095c9 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -647,6 +647,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 273b865173bcec..a1d5eda965119b 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1120,6 +1120,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 1769cfbfaa9b43..12b9a25a7ffac8 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1142,6 +1142,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index e0477cbf5a6f00..d0166303f31850 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -359,6 +359,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.atanbf16
   libc.src.math.acosbf16
   libc.src.math.asinbf16
+  libc.src.math.asinhbf16
   libc.src.math.bf16add
   libc.src.math.bf16addf
   libc.src.math.bf16addl
diff --git a/libc/docs/headers/math/index.md b/libc/docs/headers/math/index.md
index 30aba90c60a9bc..b0a22a49ec677e 100644
--- a/libc/docs/headers/math/index.md
+++ b/libc/docs/headers/math/index.md
@@ -170,7 +170,7 @@ log
 | 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                   |
+| asinh     | {{ check }}       |                  |                         | {{ 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                   |
diff --git a/libc/shared/math.h b/libc/shared/math.h
index eb72bebcb53bfa..6eb5c74bb6d137 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -23,6 +23,7 @@
 #include "math/asinbf16.h"
 #include "math/asinf.h"
 #include "math/asinf16.h"
+#include "math/asinhbf16.h"
 #include "math/asinhf.h"
 #include "math/asinhf16.h"
 #include "math/asinpi.h"
diff --git a/libc/shared/math/asinhbf16.h b/libc/shared/math/asinhbf16.h
new file mode 100644
index 00000000000000..70b6c2f503c728
--- /dev/null
+++ b/libc/shared/math/asinhbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared asinhbf16 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_ASINHBF16_H
+#define LLVM_LIBC_SHARED_MATH_ASINHBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/asinhbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::asinhbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ASINHBF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 400e5e2d6aeaa8..3f764044074dad 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -172,6 +172,17 @@ add_header_library(
     libc.src.__support.macros.properties.cpu_features
 )
 
+add_header_library(
+  asinhbf16
+  HDRS
+    asinhbf16.h
+  DEPENDS
+    .asinhf
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.cast
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   asinhf
   HDRS
diff --git a/libc/src/__support/math/asinhbf16.h b/libc/src/__support/math/asinhbf16.h
new file mode 100644
index 00000000000000..9d2df6030a847e
--- /dev/null
+++ b/libc/src/__support/math/asinhbf16.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for asinhbf16 --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ASINHBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ASINHBF16_H
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/math/asinhf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE bfloat16 asinhbf16(bfloat16 x) {
+  // Evaluate in float to use the established asinh implementation, then round
+  // once to the narrower bfloat16 result type.
+  return fputil::cast<bfloat16>(asinhf(static_cast<float>(x)));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ASINHBF16_H
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 4f1dd95a6993da..fd5ecddeba9c7d 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -58,6 +58,7 @@ add_math_entrypoint_object(asinf)
 add_math_entrypoint_object(asinf16)
 
 add_math_entrypoint_object(asinh)
+add_math_entrypoint_object(asinhbf16)
 add_math_entrypoint_object(asinhf)
 add_math_entrypoint_object(asinhf16)
 
diff --git a/libc/src/math/asinhbf16.h b/libc/src/math/asinhbf16.h
new file mode 100644
index 00000000000000..6cc0fa592d5a58
--- /dev/null
+++ b/libc/src/math/asinhbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for asinhbf16 --------------------*- 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_ASINHBF16_H
+#define LLVM_LIBC_SRC_MATH_ASINHBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 asinhbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ASINHBF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index b4b2465b384b10..4e5bb226b3e2d1 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3825,6 +3825,16 @@ add_entrypoint_object(
     libc.src.__support.math.acospif
 )
 
+add_entrypoint_object(
+  asinhbf16
+  SRCS
+    asinhbf16.cpp
+  HDRS
+    ../asinhbf16.h
+  DEPENDS
+    libc.src.__support.math.asinhbf16
+)
+
 add_entrypoint_object(
   asinhf
   SRCS
diff --git a/libc/src/math/generic/asinhbf16.cpp b/libc/src/math/generic/asinhbf16.cpp
new file mode 100644
index 00000000000000..abee848db114f8
--- /dev/null
+++ b/libc/src/math/generic/asinhbf16.cpp
@@ -0,0 +1,18 @@
+//===-- Implementation for asinhbf16(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/asinhbf16.h"
+#include "src/__support/math/asinhbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, asinhbf16, (bfloat16 x)) {
+  return math::asinhbf16(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index eff5bea2970fd1..455ca3bfa416b7 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -32,6 +32,7 @@ else()
       libc.src.__support.math.asinbf16
       libc.src.__support.math.asinf
       libc.src.__support.math.asinf16
+      libc.src.__support.math.asinhbf16
       libc.src.__support.math.asinhf
       libc.src.__support.math.asinhf16
       libc.src.__support.math.asinpi
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 68b562c48931aa..ec0ace9f6d371a 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -771,6 +771,7 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
   EXPECT_FP_EQ(bfloat16(0x1.921fb6p0f),
                LIBC_NAMESPACE::shared::acosbf16(bfloat16(0.0f)));
   EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::asinbf16(bfloat16(0.0)));
+  EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::asinhbf16(bfloat16(0.0)));
   EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::atanbf16(bfloat16(0.0)));
   EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16add(2.0, 3.0));
   EXPECT_FP_EQ(bfloat16(2.0f), LIBC_NAMESPACE::shared::bf16divf(4.0f, 2.0f));
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index d88afe6370e27b..1f7c25a8bbcc19 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2710,6 +2710,19 @@ add_fp_unittest(
     libc.src.stdlib.srand
 )
 
+add_fp_unittest(
+  asinhbf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-tests
+  SRCS
+    asinhbf16_test.cpp
+  DEPENDS
+    libc.src.math.asinhbf16
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.bfloat16
+)
+
 add_fp_unittest(
   asinhf_test
   NEED_MPFR
diff --git a/libc/test/src/math/asinhbf16_test.cpp b/libc/test/src/math/asinhbf16_test.cpp
new file mode 100644
index 00000000000000..3a11cf7f765f0d
--- /dev/null
+++ b/libc/test/src/math/asinhbf16_test.cpp
@@ -0,0 +1,40 @@
+//===-- Exhaustive test for asinhbf16 ------------------------------------===//
+//
+// 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/__support/FPUtil/bfloat16.h"
+#include "src/math/asinhbf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcAsinhBf16Test = 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: [-Inf, 0]
+static constexpr uint16_t NEG_START = 0x8000U;
+static constexpr uint16_t NEG_STOP = 0xff80U;
+
+TEST_F(LlvmLibcAsinhBf16Test, PositiveRange) {
+  for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
+    bfloat16 x = FPBits(v).get_val();
+    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, x,
+                                   LIBC_NAMESPACE::asinhbf16(x), 0.5);
+  }
+}
+
+TEST_F(LlvmLibcAsinhBf16Test, NegativeRange) {
+  for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
+    bfloat16 x = FPBits(v).get_val();
+    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, x,
+                                   LIBC_NAMESPACE::asinhbf16(x), 0.5);
+  }
+}
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index d68eb7786e3b58..d5f431c0968176 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4972,6 +4972,19 @@ add_fp_unittest(
     libc.src.math.asinf16
 )
 
+add_fp_unittest(
+  asinhbf16_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    asinhbf16_test.cpp
+  DEPENDS
+    libc.src.math.asinhbf16
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.__support.FPUtil.bfloat16
+)
+
 add_fp_unittest(
   acosbf16_test
   SUITE
diff --git a/libc/test/src/math/smoke/asinhbf16_test.cpp b/libc/test/src/math/smoke/asinhbf16_test.cpp
new file mode 100644
index 00000000000000..f00b394859866b
--- /dev/null
+++ b/libc/test/src/math/smoke/asinhbf16_test.cpp
@@ -0,0 +1,41 @@
+//===-- Unittests for asinhbf16 -------------------------------------------===//
+//
+// 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 "hdr/errno_macros.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/asinhbf16.h"
+#include "test/UnitTest/FEnvSafeTest.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+class LlvmLibcAsinhBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+  DECLARE_SPECIAL_CONSTANTS(bfloat16)
+public:
+  void test_special_numbers() {
+    EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinhbf16(aNaN));
+    EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+        aNaN, LIBC_NAMESPACE::asinhbf16(sNaN), FE_INVALID);
+    EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::asinhbf16(zero));
+    EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, LIBC_NAMESPACE::asinhbf16(neg_zero));
+    EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::asinhbf16(inf));
+    EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, LIBC_NAMESPACE::asinhbf16(neg_inf));
+    EXPECT_MATH_ERRNO(0);
+  }
+};
+
+TEST_F(LlvmLibcAsinhBf16Test, SpecialNumbers) { test_special_numbers(); }
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 0e74580b1f84ba..972d97cbb2e890 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overl...
[truncated]

``````````

</details>


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


More information about the libc-commits mailing list