[libc-commits] [libc] [llvm] [libc][math] Implement acoshbf16 function (PR #236475)
via libc-commits
libc-commits at lists.llvm.org
Wed Nov 4 21:32:05 PST 2026
https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/236475
>From 3760f977f1985a1775f1dc2eed4401323021ce78 Mon Sep 17 00:00:00 2001
From: Youssef Wael <youssefwael.work at gmail.com>
Date: Wed, 28 Oct 2026 19:10:22 +0300
Subject: [PATCH 1/4] libc: Add acoshbf16
git rm libc/docs/headers/math/index.rst
git add libc/docs/headers/math/index.md
git rebase --continue# modified: libc/config/linux/x86_64/entrypoints.txt
---
libc/config/baremetal/aarch64/entrypoints.txt | 1 +
libc/config/baremetal/arm/entrypoints.txt | 1 +
libc/config/baremetal/hexagon/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.md | 2 +-
libc/shared/math.h | 1 +
libc/shared/math/acoshbf16.h | 28 ++++
libc/src/__support/math/CMakeLists.txt | 17 ++
libc/src/__support/math/acoshbf16.h | 148 ++++++++++++++++++
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/acoshbf16.h | 26 +++
libc/src/math/generic/CMakeLists.txt | 11 ++
libc/src/math/generic/acoshbf16.cpp | 23 +++
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/acoshbf16_test.cpp | 36 +++++
libc/test/src/math/smoke/CMakeLists.txt | 14 ++
libc/test/src/math/smoke/acoshbf16_test.cpp | 70 +++++++++
.../llvm-project-overlay/libc/BUILD.bazel | 25 +++
.../libc/test/src/math/BUILD.bazel | 7 +
.../libc/test/src/math/smoke/BUILD.bazel | 7 +
32 files changed, 444 insertions(+), 1 deletion(-)
create mode 100644 libc/shared/math/acoshbf16.h
create mode 100644 libc/src/__support/math/acoshbf16.h
create mode 100644 libc/src/math/acoshbf16.h
create mode 100644 libc/src/math/generic/acoshbf16.cpp
create mode 100644 libc/test/src/math/acoshbf16_test.cpp
create mode 100644 libc/test/src/math/smoke/acoshbf16_test.cpp
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index f8175da9fadb80..218be9ee5172c4 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -826,6 +826,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 ab84c92f5c03c9..50c136edf8dcff 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -837,6 +837,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 a7617ec243e278..7112ee3ee12a5b 100644
--- a/libc/config/baremetal/hexagon/entrypoints.txt
+++ b/libc/config/baremetal/hexagon/entrypoints.txt
@@ -827,6 +827,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 01a7251e35b447..c4e80b283b7624 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -829,6 +829,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 363cb74dc209e0..c9d56572b5ca6b 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -648,6 +648,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 e5b82f29b6686b..b12b336ce5ba13 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -284,6 +284,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 56f60acadd6693..c41488516396a7 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -581,6 +581,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.acosbf16
libc.src.math.asinbf16
libc.src.math.atanbf16
+ libc.src.math.acoshbf16
libc.src.math.bf16add
libc.src.math.bf16addf
libc.src.math.bf16addl
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 2b0874bbe1f089..235579b2b69842 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -707,6 +707,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 2adf832016d21a..67adf61527697b 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -723,6 +723,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 b45313f5068bd0..f3248a16a58f6a 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1063,6 +1063,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 71cb938ec9459f..bdfab3dfd05ba8 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -674,6 +674,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 3b42f020cf750e..873808ba40d971 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1143,6 +1143,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 0ec5d8f73a8a4d..afdc498a2ac6da 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1165,6 +1165,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 9bf43138e4eff1..9d1363f6734f50 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -381,6 +381,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.atanbf16
libc.src.math.acosbf16
libc.src.math.asinbf16
+ libc.src.math.acoshbf16
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 d138caa5eb34aa..8039b235499d53 100644
--- a/libc/docs/headers/math/index.md
+++ b/libc/docs/headers/math/index.md
@@ -167,7 +167,7 @@ log
| \<Func> | \<Func_f> (float) | \<Func> (double) | \<Func_f80> (f80) | \<Func> (double-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 |
+| acosh | {{ check }} | | | | {{ 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 |
diff --git a/libc/shared/math.h b/libc/shared/math.h
index bf490aa4738b41..d96274831760b0 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -15,6 +15,7 @@
#include "math/acosbf16.h"
#include "math/acosf.h"
#include "math/acosf16.h"
+#include "math/acoshbf16.h"
#include "math/acoshf.h"
#include "math/acoshf16.h"
#include "math/acospif.h"
diff --git a/libc/shared/math/acoshbf16.h b/libc/shared/math/acoshbf16.h
new file mode 100644
index 00000000000000..5fff69ba87304c
--- /dev/null
+++ b/libc/shared/math/acoshbf16.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 the acoshbf16 function.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ACOSHBF16_H
+#define LLVM_LIBC_SHARED_MATH_ACOSHBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/acoshbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::acoshbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ACOSHBF16_H
\ No newline at end of file
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index da3a3fcb3dd366..74bcdbe8f47e7e 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -95,6 +95,23 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ acoshbf16
+ HDRS
+ acoshbf16.h
+ DEPENDS
+ .acoshf_utils
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.macros.config
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.multiply_add
+ libc.src.__support.FPUtil.polyeval
+ libc.src.__support.FPUtil.sqrt
+ libc.src.__support.macros.optimization
+)
+
add_header_library(
acoshf16
HDRS
diff --git a/libc/src/__support/math/acoshbf16.h b/libc/src/__support/math/acoshbf16.h
new file mode 100644
index 00000000000000..26672ef2766349
--- /dev/null
+++ b/libc/src/__support/math/acoshbf16.h
@@ -0,0 +1,148 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 the acoshbf16 function.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ACOSHBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ACOSHBF16_H
+
+#include "acoshf_utils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE LIBC_CONSTEXPR bfloat16 acoshbf16(bfloat16 x) {
+ using namespace acoshf_internal;
+ using FPBits = fputil::FPBits<bfloat16>;
+
+ FPBits xbits(x);
+
+ // Handle NaNs before checking the domain. The sign of a NaN does not
+ // determine whether the input is a domain error.
+ if (LIBC_UNLIKELY(xbits.is_inf_or_nan())) {
+ if (xbits.is_signaling_nan()) {
+ fputil::raise_except_if_required(FE_INVALID);
+ return FPBits::quiet_nan().get_val();
+ }
+
+ // Negative infinity is outside the domain.
+ if (xbits.is_inf() && xbits.is_neg()) {
+ fputil::set_errno_if_required(EDOM);
+ fputil::raise_except_if_required(FE_INVALID);
+ return FPBits::quiet_nan().get_val();
+ }
+ // positive infinity and quiet NaNs are returned unchanged.
+ return x;
+ }
+
+ float xf = static_cast<float>(x);
+
+ // acosh(x) is defined for x >= 1. Its value at x = 1 is exactly zero.
+ if (LIBC_UNLIKELY(xf <= 1.0f)) {
+ if (xf == 1.0f)
+ return FPBits::zero().get_val();
+
+ fputil::set_errno_if_required(EDOM);
+ fputil::raise_except_if_required(FE_INVALID);
+ return FPBits::quiet_nan().get_val();
+ }
+
+ uint16_t x_u = xbits.uintval();
+
+ // For x close to 1, let delta = x - 1. Then
+ //
+ // acosh(1 + delta) = sqrt(2 * delta) * P(delta),
+ //
+ // where the Taylor expansion of P is
+ //
+ // P(delta) = 1 - delta / 12 + 3 * delta^2 / 160
+ // - 5 * delta^3 / 896 + O(delta^4).
+ //
+ // Factoring out sqrt(2 * delta) captures the behavior near x = 1
+ // and leaves a smooth function that can be approximated by a
+ // low-degree polynomial. This fast path uses the degree-2 Taylor
+ // polynomial
+ //
+ // P2(delta) = 1 - delta / 12 + 3 * delta^2 / 160.
+ //
+ // for delta in [0, 0.25), corresponding to 1 < x < 1.25.
+ //
+ // The following Sollya commands estimate the absolute error of this
+ // polynomial over the closed interval [0, 0.25], using the same
+ // single-precision rounded coefficients as the implementation:
+ //
+ // prec = 200;
+ // display = hexadecimal;
+ // c1 = round(-1/12, single, RN); // -0x1.555556p-4
+ // c2 = round(3/160, single, RN); // 0x1.333334p-6
+ // P2 = 1 + c1*x + c2*x^2;
+ // dirtyinfnorm(acosh(1 + x) - sqrt(2 * x) * P2, [0; 0.25]);
+ //
+ // Sollya estimated the maximum absolute approximation error over
+ // this interval (including single-precision float coefficient rounding) as:
+ //
+ // 0x1.dce3cfd50cfc0248598bad104690338afe96a2a1efe4359a3cp-15
+ // (approximately 5.68e-5, below 2^-14).
+ //
+ // The coefficients used below are rounded to float:
+ //
+ // round(1 / 12, SG, RN); // 0x1.555556p-4
+ // round(3 / 160, SG, RN); // 0x1.333334p-6
+ //
+ // Precision Context:
+ // Since bfloat16 machine epsilon is 2^-7 (~7.81e-3) and fp16 machine
+ // epsilon is 2^-10 (~9.77e-4), an error of ~5.68e-5 (< 2^-14) guarantees
+ // full precision. It does not include float-operation rounding
+ // or the final conversion to bfloat16, and it does not by itself
+ // establish correct rounding. Separately, exhaustive comparison of
+ // all 31 bfloat16 inputs in (1, 1.25) against a 100-digit acosh
+ // reference found no output mismatches for separate float
+ // multiply/add evaluation or fused multiply_add evaluation.
+ // This polynomial avoids the logarithm and provides a
+ // candidate fast path for BFloat16 inputs in (1, 1.25).
+ //
+ // The threshold 0x3FA0 is the BFloat16 encoding of 1.25.
+ if (x_u < 0x3FA0U) {
+ float delta = xf - 1.0f;
+ float sqrt_2_delta = fputil::sqrt<float>(2.0f * delta);
+
+ float p = fputil::polyeval(delta, 1.0f, -0x1.555556p-4f, 0x1.333334p-6f);
+
+ return fputil::cast<bfloat16>(sqrt_2_delta * p);
+ }
+
+ // Away from x = 1, evaluate
+ //
+ // acosh(x) = log(x + sqrt(x^2 - 1)).
+ //
+ // Use double precision for the intermediate calculations. In particular,
+ // this avoids overflow when squaring the largest finite BFloat16 inputs.
+ // Convert directly to BFloat16 to avoid an intermediate float rounding.
+ double xd = static_cast<double>(xf);
+ double sqrt_term = fputil::sqrt<double>(fputil::multiply_add(xd, xd, -1.0));
+ double result = log_eval(xd + sqrt_term);
+
+ return fputil::cast<bfloat16>(result);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ACOSHBF16_H
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 08728a02809359..1cf5ab1ebe4df9 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -47,6 +47,7 @@ add_math_entrypoint_object(acosf16)
add_math_entrypoint_object(acosh)
add_math_entrypoint_object(acoshf)
+add_math_entrypoint_object(acoshbf16)
add_math_entrypoint_object(acoshf16)
add_math_entrypoint_object(acospif)
diff --git a/libc/src/math/acoshbf16.h b/libc/src/math/acoshbf16.h
new file mode 100644
index 00000000000000..8cd6e35666a2d6
--- /dev/null
+++ b/libc/src/math/acoshbf16.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 the acoshbf16 function.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_MATH_ACOSHBF16_H
+#define LLVM_LIBC_SRC_MATH_ACOSHBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 acoshbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ACOSHBF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 30f40f993330c7..acbea085dd9e0e 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3953,6 +3953,17 @@ add_entrypoint_object(
libc.src.__support.math.acoshf
)
+add_entrypoint_object(
+ acoshbf16
+ SRCS
+ acoshbf16.cpp
+ HDRS
+ ../acoshbf16.h
+ DEPENDS
+ libc.src.__support.math.acoshbf16
+ libc.src.errno.errno
+)
+
add_entrypoint_object(
acoshf16
SRCS
diff --git a/libc/src/math/generic/acoshbf16.cpp b/libc/src/math/generic/acoshbf16.cpp
new file mode 100644
index 00000000000000..4647b88127f1e3
--- /dev/null
+++ b/libc/src/math/generic/acoshbf16.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 the acoshbf16 function.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/math/acoshbf16.h"
+#include "src/__support/math/acoshbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, acoshbf16, (bfloat16 x)) {
+ return math::acoshbf16(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 554f8d2bdcfac2..bb97f764bf3fe7 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -32,6 +32,7 @@ else()
libc.src.__support.math.acosf
libc.src.__support.math.acosf16
libc.src.__support.math.acoshf
+ libc.src.__support.math.acoshbf16
libc.src.__support.math.acoshf16
libc.src.__support.math.acospif
libc.src.__support.math.acospif16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 7ca4b7340dd6b2..2e5c8eecf1bab9 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -807,6 +807,7 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>;
EXPECT_FP_EQ(bfloat16(0x1.921fb6p0f),
LIBC_NAMESPACE::shared::acosbf16(bfloat16(0.0f)));
+ EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::acoshbf16(bfloat16(1.0)));
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::asinbf16(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));
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index fb025dee1d33e7..31648a09ef67ea 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2833,6 +2833,19 @@ add_fp_unittest(
libc.src.math.acoshf16
)
+add_fp_unittest(
+ acoshbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-tests
+ SRCS
+ acoshbf16_test.cpp
+ DEPENDS
+ libc.src.math.acoshbf16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
asinf_test
NEED_MPFR
diff --git a/libc/test/src/math/acoshbf16_test.cpp b/libc/test/src/math/acoshbf16_test.cpp
new file mode 100644
index 00000000000000..8f4befb02beaed
--- /dev/null
+++ b/libc/test/src/math/acoshbf16_test.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Tests every valid positive bfloat16 input against MPFR across all
+/// supported floating-point rounding modes.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/acoshbf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcAcoshBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// Domain: [1, +Inf]
+// The first 31 inputs above 1 exercise the polynomial fast path.
+static constexpr uint16_t START = 0x3f80U;
+static constexpr uint16_t STOP = 0x7f80U;
+
+TEST_F(LlvmLibcAcoshBf16Test, PositiveRange) {
+ for (uint16_t bits = START; bits <= STOP; bits++) {
+ bfloat16 x = FPBits(bits).get_val();
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, x,
+ LIBC_NAMESPACE::acoshbf16(x), 0.5);
+ }
+}
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 126e516f879dcd..4709280ad246e2 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -5146,6 +5146,20 @@ add_fp_unittest(
libc.src.__support.FPUtil.cast
)
+add_fp_unittest(
+ acoshbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ acoshbf16_test.cpp
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
+ libc.src.math.acoshbf16
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.cast
+)
+
add_fp_unittest(
asinf_test
SUITE
diff --git a/libc/test/src/math/smoke/acoshbf16_test.cpp b/libc/test/src/math/smoke/acoshbf16_test.cpp
new file mode 100644
index 00000000000000..94f63e8e767d1d
--- /dev/null
+++ b/libc/test/src/math/smoke/acoshbf16_test.cpp
@@ -0,0 +1,70 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Smoke tests for acoshbf16.
+///
+/// Verifies boundary values, special floating-point edge cases (NaN, sNaN,
+/// positive/negative infinity, zero), out-of-domain inputs (x < 1.0), and
+/// proper floating-point exception handling (FE_INVALID) along with errno
+/// reporting (EDOM).
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/math/acoshbf16.h"
+#include "test/UnitTest/FEnvSafeTest.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+class LlvmLibcAcoshBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+ DECLARE_SPECIAL_CONSTANTS(bfloat16)
+public:
+ void test_special_numbers() {
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acoshbf16(aNaN));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+ aNaN, LIBC_NAMESPACE::acoshbf16(sNaN), FE_INVALID);
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+ aNaN, LIBC_NAMESPACE::acoshbf16(zero), FE_INVALID);
+ EXPECT_MATH_ERRNO(EDOM);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+ aNaN, LIBC_NAMESPACE::acoshbf16(neg_zero), FE_INVALID);
+ EXPECT_MATH_ERRNO(EDOM);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::acoshbf16(inf));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+ aNaN, LIBC_NAMESPACE::acoshbf16(neg_inf), FE_INVALID);
+ EXPECT_MATH_ERRNO(EDOM);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::acoshbf16(bfloat16(1.0)));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+ aNaN, LIBC_NAMESPACE::acoshbf16(bfloat16(0.5)), FE_INVALID);
+ EXPECT_MATH_ERRNO(EDOM);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+ aNaN, LIBC_NAMESPACE::acoshbf16(bfloat16(-1.0)), FE_INVALID);
+ EXPECT_MATH_ERRNO(EDOM);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+ aNaN, LIBC_NAMESPACE::acoshbf16(bfloat16(-2.0)), FE_INVALID);
+ EXPECT_MATH_ERRNO(EDOM);
+ }
+};
+TEST_F(LlvmLibcAcoshBf16Test, 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 0ac142400687d6..c4b0a69985c7b0 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -6160,6 +6160,23 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_acoshbf16",
+ hdrs = ["src/__support/math/acoshbf16.h"],
+ deps = [
+ ":__support_math_acoshf_utils",
+ ":__support_fputil_fenv_impl",
+ ":__support_fputil_fp_bits",
+ ":__support_fputil_polyeval",
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_cast",
+ ":__support_fputil_multiply_add",
+ ":__support_fputil_sqrt",
+ ":__support_macros_config",
+ ":__support_macros_optimization",
+ ],
+)
+
libc_support_library(
name = "__support_math_acoshf16",
hdrs = ["src/__support/math/acoshf16.h"],
@@ -12980,6 +12997,14 @@ libc_math_function(
additional_deps = [":__support_math_acoshf"],
)
+libc_math_function(
+ name = "acoshbf16",
+ additional_deps = [
+ ":__support_math_acoshbf16",
+ ":errno",
+ ],
+)
+
libc_math_function(
name = "acoshf16",
additional_deps = [
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 9460f690487f3b..fcbf463838b48f 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
@@ -29,6 +29,13 @@ math_mpfr_test(name = "acospif")
math_mpfr_test(name = "asin")
+math_mpfr_test(
+ name = "acoshbf16",
+ deps = [
+ "//libc:__support_fputil_bfloat16",
+ ],
+)
+
math_mpfr_test(
name = "asinbf16",
deps = [
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 49f4bb29551a41..9a26cb0f867811 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
@@ -23,6 +23,13 @@ math_test(name = "acosf")
math_test(name = "acoshf")
+math_test(
+ name = "acoshbf16",
+ deps = [
+ "//libc:__support_fputil_bfloat16",
+ ],
+)
+
math_test(name = "acosf16")
math_test(name = "acoshf16")
>From 0a88c7ac0c2101ede80bd089e96d1ce97b34d98c Mon Sep 17 00:00:00 2001
From: Youssef Wael <youssefwael.work at gmail.com>
Date: Wed, 28 Oct 2026 21:17:00 +0300
Subject: [PATCH 2/4] Fix acoshbf16 formatting
---
libc/shared/math/acoshbf16.h | 2 +-
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/libc/shared/math/acoshbf16.h b/libc/shared/math/acoshbf16.h
index 5fff69ba87304c..e368ede0d58e9e 100644
--- a/libc/shared/math/acoshbf16.h
+++ b/libc/shared/math/acoshbf16.h
@@ -25,4 +25,4 @@ using math::acoshbf16;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SHARED_MATH_ACOSHBF16_H
\ No newline at end of file
+#endif // LLVM_LIBC_SHARED_MATH_ACOSHBF16_H
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c4b0a69985c7b0..e308866b7d39fa 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -6164,16 +6164,16 @@ libc_support_library(
name = "__support_math_acoshbf16",
hdrs = ["src/__support/math/acoshbf16.h"],
deps = [
- ":__support_math_acoshf_utils",
- ":__support_fputil_fenv_impl",
- ":__support_fputil_fp_bits",
- ":__support_fputil_polyeval",
":__support_fputil_bfloat16",
":__support_fputil_cast",
+ ":__support_fputil_fenv_impl",
+ ":__support_fputil_fp_bits",
":__support_fputil_multiply_add",
+ ":__support_fputil_polyeval",
":__support_fputil_sqrt",
":__support_macros_config",
":__support_macros_optimization",
+ ":__support_math_acoshf_utils",
],
)
>From 4bea7c919ce70fd85126ff1637aa765c5bf51a66 Mon Sep 17 00:00:00 2001
From: Youssef Wael <youssefwael.work at gmail.com>
Date: Mon, 2 Nov 2026 20:29:18 +0200
Subject: [PATCH 3/4] removing unnecessary includes and comments
---
libc/config/baremetal/aarch64/entrypoints.txt | 2 +-
libc/config/baremetal/arm/entrypoints.txt | 2 +-
libc/config/baremetal/hexagon/entrypoints.txt | 2 +-
libc/config/baremetal/riscv/entrypoints.txt | 2 +-
libc/config/darwin/aarch64/entrypoints.txt | 2 +-
libc/config/darwin/x86_64/entrypoints.txt | 2 +-
libc/config/freebsd/x86_64/entrypoints.txt | 2 +-
libc/config/gpu/amdgpu/entrypoints.txt | 2 +-
libc/config/gpu/nvptx/entrypoints.txt | 2 +-
libc/config/linux/aarch64/entrypoints.txt | 2 +-
libc/config/linux/arm/entrypoints.txt | 2 +-
libc/config/linux/riscv/entrypoints.txt | 2 +-
libc/config/linux/x86_64/entrypoints.txt | 2 +-
libc/config/windows/entrypoints.txt | 2 +-
libc/test/src/math/acoshbf16_test.cpp | 2 --
libc/test/src/math/smoke/CMakeLists.txt | 1 -
libc/test/src/math/smoke/acoshbf16_test.cpp | 1 -
17 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 218be9ee5172c4..4ff09b507d208b 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -825,8 +825,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 50c136edf8dcff..58aa64c3960e2e 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -836,8 +836,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 7112ee3ee12a5b..7ff79359ddcf13 100644
--- a/libc/config/baremetal/hexagon/entrypoints.txt
+++ b/libc/config/baremetal/hexagon/entrypoints.txt
@@ -826,8 +826,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 c4e80b283b7624..b6a35340a024f4 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -828,8 +828,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 c9d56572b5ca6b..e10512fc621a25 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -647,8 +647,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 b12b336ce5ba13..43e9acd9f94e94 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -283,8 +283,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 c41488516396a7..aad3d972752079 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -579,9 +579,9 @@ endif()
list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.acosbf16
+ libc.src.math.acoshbf16
libc.src.math.asinbf16
libc.src.math.atanbf16
- libc.src.math.acoshbf16
libc.src.math.bf16add
libc.src.math.bf16addf
libc.src.math.bf16addl
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 235579b2b69842..8439b7e695fa72 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -706,8 +706,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 67adf61527697b..8067928bfa638e 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -722,8 +722,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 f3248a16a58f6a..8cf2292531fabf 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1062,8 +1062,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 bdfab3dfd05ba8..7f9d5445a51745 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -673,8 +673,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 873808ba40d971..c4393bae1edc49 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1142,8 +1142,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 afdc498a2ac6da..adaf83cee4e006 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1164,8 +1164,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
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 9d1363f6734f50..9153e9482b5ea0 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -380,8 +380,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
# bfloat16 entrypoints
libc.src.math.atanbf16
libc.src.math.acosbf16
- libc.src.math.asinbf16
libc.src.math.acoshbf16
+ libc.src.math.asinbf16
libc.src.math.bf16add
libc.src.math.bf16addf
libc.src.math.bf16addl
diff --git a/libc/test/src/math/acoshbf16_test.cpp b/libc/test/src/math/acoshbf16_test.cpp
index 8f4befb02beaed..18e44d32d291c2 100644
--- a/libc/test/src/math/acoshbf16_test.cpp
+++ b/libc/test/src/math/acoshbf16_test.cpp
@@ -22,8 +22,6 @@ using LlvmLibcAcoshBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
-// Domain: [1, +Inf]
-// The first 31 inputs above 1 exercise the polynomial fast path.
static constexpr uint16_t START = 0x3f80U;
static constexpr uint16_t STOP = 0x7f80U;
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 4709280ad246e2..af534040cf7c21 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -5157,7 +5157,6 @@ add_fp_unittest(
libc.hdr.fenv_macros
libc.src.math.acoshbf16
libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.cast
)
add_fp_unittest(
diff --git a/libc/test/src/math/smoke/acoshbf16_test.cpp b/libc/test/src/math/smoke/acoshbf16_test.cpp
index 94f63e8e767d1d..93339f000e4030 100644
--- a/libc/test/src/math/smoke/acoshbf16_test.cpp
+++ b/libc/test/src/math/smoke/acoshbf16_test.cpp
@@ -19,7 +19,6 @@
#include "hdr/errno_macros.h"
#include "hdr/fenv_macros.h"
#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/FPUtil/cast.h"
#include "src/math/acoshbf16.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
>From 9a58058b4453e07a71cd4d33b4578d434d56115a Mon Sep 17 00:00:00 2001
From: Youssef Wael <youssefwael.work at gmail.com>
Date: Wed, 4 Nov 2026 03:38:21 +0200
Subject: [PATCH 4/4] fixing include format and added constexpr test
---
libc/src/__support/math/acoshbf16.h | 2 +-
libc/src/math/generic/CMakeLists.txt | 1 -
libc/test/shared/CMakeLists.txt | 1 +
.../test/shared/shared_math_constexpr_test.cpp | 2 ++
libc/test/src/math/CMakeLists.txt | 16 ++++++++--------
libc/test/src/math/smoke/CMakeLists.txt | 18 +++++++++---------
.../llvm-project-overlay/libc/BUILD.bazel | 5 +----
7 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/libc/src/__support/math/acoshbf16.h b/libc/src/__support/math/acoshbf16.h
index 26672ef2766349..aaf9b0c05f7868 100644
--- a/libc/src/__support/math/acoshbf16.h
+++ b/libc/src/__support/math/acoshbf16.h
@@ -14,7 +14,6 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ACOSHBF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_ACOSHBF16_H
-#include "acoshf_utils.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/PolyEval.h"
@@ -24,6 +23,7 @@
#include "src/__support/FPUtil/sqrt.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"
+#include "src/__support/math/acoshf_utils.h"
namespace LIBC_NAMESPACE_DECL {
namespace math {
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index acbea085dd9e0e..9812fdb2396676 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3961,7 +3961,6 @@ add_entrypoint_object(
../acoshbf16.h
DEPENDS
libc.src.__support.math.acoshbf16
- libc.src.errno.errno
)
add_entrypoint_object(
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index bb97f764bf3fe7..32afcfe88e5e7e 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -555,6 +555,7 @@ else()
DEPENDS
libc.src.__support.FPUtil.float128
libc.src.__support.FPUtil.float80
+ libc.src.__support.math.acoshbf16
libc.src.__support.math.asinbf16
libc.src.__support.math.bf16subl
libc.src.__support.math.canonicalize
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 113ec24d2dd0ed..cb72feec287e02 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -600,6 +600,8 @@ static_assert(0 == [] {
bfloat16 x = bfloat16(0.0);
return LIBC_NAMESPACE::shared::canonicalizebf16(&cx, &x);
}());
+static_assert(bfloat16(0.0) ==
+ LIBC_NAMESPACE::shared::acoshbf16(bfloat16(1.0)));
static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::asinbf16(bfloat16(0.0)));
static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::ceilbf16(bfloat16(0.0)));
static_assert(bfloat16(1.0) ==
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 31648a09ef67ea..2de2951121c069 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2823,27 +2823,27 @@ add_fp_unittest(
)
add_fp_unittest(
- acoshf16_test
+ acoshbf16_test
NEED_MPFR
SUITE
libc-math-tests
SRCS
- acoshf16_test.cpp
+ acoshbf16_test.cpp
DEPENDS
- libc.src.math.acoshf16
+ libc.src.math.acoshbf16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.bfloat16
)
add_fp_unittest(
- acoshbf16_test
+ acoshf16_test
NEED_MPFR
SUITE
libc-math-tests
SRCS
- acoshbf16_test.cpp
+ acoshf16_test.cpp
DEPENDS
- libc.src.math.acoshbf16
- libc.src.__support.FPUtil.fp_bits
- libc.src.__support.FPUtil.bfloat16
+ libc.src.math.acoshf16
)
add_fp_unittest(
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index af534040cf7c21..d25bb7ecf1c57b 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -5135,28 +5135,28 @@ add_fp_unittest(
)
add_fp_unittest(
- acoshf16_test
+ acoshbf16_test
SUITE
libc-math-smoke-tests
SRCS
- acoshf16_test.cpp
+ acoshbf16_test.cpp
DEPENDS
libc.hdr.errno_macros
- libc.src.math.acoshf16
- libc.src.__support.FPUtil.cast
+ libc.hdr.fenv_macros
+ libc.src.math.acoshbf16
+ libc.src.__support.FPUtil.bfloat16
)
add_fp_unittest(
- acoshbf16_test
+ acoshf16_test
SUITE
libc-math-smoke-tests
SRCS
- acoshbf16_test.cpp
+ acoshf16_test.cpp
DEPENDS
libc.hdr.errno_macros
- libc.hdr.fenv_macros
- libc.src.math.acoshbf16
- libc.src.__support.FPUtil.bfloat16
+ libc.src.math.acoshf16
+ libc.src.__support.FPUtil.cast
)
add_fp_unittest(
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index e308866b7d39fa..50deb89ecbf06d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -12999,10 +12999,7 @@ libc_math_function(
libc_math_function(
name = "acoshbf16",
- additional_deps = [
- ":__support_math_acoshbf16",
- ":errno",
- ],
+ additional_deps = [":__support_math_acoshbf16"],
)
libc_math_function(
More information about the libc-commits
mailing list