[libc-commits] [libc] [llvm] [libc][math][c23] Add sinbf16 function (PR #185441)
via libc-commits
libc-commits at lists.llvm.org
Sat Nov 7 04:51:39 PST 2026
https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/185441
>From 35a389156b0e2d875876ccdfb044fd0b0300b2f3 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 17 Oct 2026 11:41:53 +0530
Subject: [PATCH 01/11] rebase
---
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/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/shared/math.h | 1 +
libc/shared/math/sinbf16.h | 23 +++++
libc/src/__support/math/CMakeLists.txt | 16 ++++
libc/src/__support/math/sinbf16.h | 92 +++++++++++++++++++
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/generic/CMakeLists.txt | 10 ++
libc/src/math/generic/sinbf16.cpp | 17 ++++
libc/src/math/sinbf16.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/sinbf16_test.cpp | 45 +++++++++
libc/test/src/math/smoke/CMakeLists.txt | 13 +++
libc/test/src/math/smoke/sinbf16_test.cpp | 40 ++++++++
.../llvm-project-overlay/libc/BUILD.bazel | 23 +++++
27 files changed, 329 insertions(+)
create mode 100644 libc/shared/math/sinbf16.h
create mode 100644 libc/src/__support/math/sinbf16.h
create mode 100644 libc/src/math/generic/sinbf16.cpp
create mode 100644 libc/src/math/sinbf16.h
create mode 100644 libc/test/src/math/sinbf16_test.cpp
create mode 100644 libc/test/src/math/smoke/sinbf16_test.cpp
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index bd46d678013fd0..8bb90fcc20ea13 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -899,6 +899,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 0cf179de3daa9c..a1c1606fb75406 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -910,6 +910,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 380ee84c219e9d..f6ecc79ccd5275 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -902,6 +902,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 78cffd1f6b4fee..d5dacf834d6d3e 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -721,6 +721,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index a5f5cacb0f8638..fb7bba25bf7a77 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -359,6 +359,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index ffa65e07f6e558..b28c80501c9ec4 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -783,6 +783,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 7d35aecf54e44a..2e9b333d58d60c 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -799,6 +799,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 2f22842dde7cec..8ba560989af6af 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1145,6 +1145,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 49162a88046b97..5e04635e298e77 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -751,6 +751,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 2087af04a93888..56813aaf66a91f 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1225,6 +1225,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index a5aea75c9b1c22..25b24740400b97 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1247,6 +1247,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index cebd511414bcb6..c0c46291515b81 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -460,6 +460,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.setpayloadf128
libc.src.math.setpayloadsigbf16
libc.src.math.setpayloadsigf128
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 348ef11f9f655a..f7616676b27c08 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -482,6 +482,7 @@
#include "math/setpayloadsigf16.h"
#include "math/setpayloadsigl.h"
#include "math/sin.h"
+#include "math/sinbf16.h"
#include "math/sincos.h"
#include "math/sincosf.h"
#include "math/sinf.h"
diff --git a/libc/shared/math/sinbf16.h b/libc/shared/math/sinbf16.h
new file mode 100644
index 00000000000000..f85a4795d51702
--- /dev/null
+++ b/libc/shared/math/sinbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared sinbf16 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_SINBF16_H
+#define LLVM_LIBC_SHARED_MATH_SINBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/sinbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::sinbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SINBF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 7af8fba1f85a58..62236629b60187 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -5880,6 +5880,22 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ sinbf16
+ HDRS
+ sinbf16.h
+ DEPENDS
+ .sincosf_utils
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.multiply_add
+ libc.src.__support.macros.optimization
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_header_library(
sinf_double_eval
HDRS
diff --git a/libc/src/__support/math/sinbf16.h b/libc/src/__support/math/sinbf16.h
new file mode 100644
index 00000000000000..de67d9ab575827
--- /dev/null
+++ b/libc/src/__support/math/sinbf16.h
@@ -0,0 +1,92 @@
+//===-- Implementation of sinbf16(x) function -----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SINBF16_H
+
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
+#include "sincosf_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"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE bfloat16 sinbf16(bfloat16 x) {
+ using namespace sincosf_utils_internal;
+
+ using FPBits = fputil::FPBits<bfloat16>;
+ FPBits xbits(x);
+
+ uint16_t x_u = xbits.uintval();
+ uint16_t x_abs = x_u & 0x7fff;
+ float xf = x;
+
+ if (x_abs < 0x7f80) {
+
+ int rounding = fputil::quick_get_round();
+ if (LIBC_UNLIKELY(x_abs <= 0x3e12)) {
+ // sin(+/-0) = +/-0
+ if (LIBC_UNLIKELY(x_abs == 0U))
+ return x;
+
+ // When x > 0, and rounding upward, sin(x) == x.
+ // When x < 0, and rounding downward, sin(x) == x.
+ if ((rounding == FE_UPWARD && xbits.is_pos()) ||
+ (rounding == FE_DOWNWARD && xbits.is_neg()))
+ return x;
+
+ // When x < 0, and rounding upward, sin(x) == (x - 1ULP)
+ if (rounding == FE_UPWARD && xbits.is_neg()) {
+ x_u--;
+ return FPBits(x_u).get_val();
+ }
+ }
+ double xd = static_cast<double>(xf);
+ uint32_t x_abs_d = fputil::FPBits<float>(xf).uintval() & 0x7fffffff;
+ double sin_k, cos_k, sin_y, cosm1_y;
+
+ sincosf_eval(xd, x_abs_d, sin_k, cos_k, sin_y, cosm1_y);
+ // using sin(a + b) = sin(a)*cos(b) + cos(a)*sin(b)
+ // sin(x) = sin_k*cos_y + cos_k*sin_y
+ // but cosm1_y = cos_y - 1 --> cos_y = cosm1_y + 1
+ // sin(x) = sin_k*cosm1_y + sin_k + cos_k * sin_y
+
+ if (LIBC_UNLIKELY(sin_y == 0 && sin_k == 0))
+ return FPBits::zero(xbits.sign()).get_val();
+ return fputil::cast<bfloat16>(fputil::multiply_add(
+ sin_y, cos_k, fputil::multiply_add(cosm1_y, sin_k, sin_k)));
+ }
+
+ // nan
+ if (xbits.is_nan()) {
+ if (xbits.is_signaling_nan()) {
+ fputil::raise_except_if_required(FE_INVALID);
+ return FPBits::quiet_nan().get_val();
+ }
+ return x;
+ }
+
+ // +/- inf
+ fputil::set_errno_if_required(EDOM);
+ fputil::raise_except_if_required(FE_INVALID);
+
+ return x + FPBits::quiet_nan().get_val();
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINBF16_H
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 6119fdb817f050..2a75aba26a2c7b 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -593,6 +593,7 @@ add_math_entrypoint_object(sincos)
add_math_entrypoint_object(sincosf)
add_math_entrypoint_object(sin)
+add_math_entrypoint_object(sinbf16)
add_math_entrypoint_object(sinf)
add_math_entrypoint_object(sinf16)
add_math_entrypoint_object(sinpif)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index e79e69f9bfc0b7..1d628e75ecd807 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -363,6 +363,16 @@ add_entrypoint_object(
libc.src.__support.math.sin_integer_eval
)
+add_entrypoint_object(
+ sinbf16
+ SRCS
+ sinbf16.cpp
+ HDRS
+ ../sinbf16.h
+ DEPENDS
+ libc.src.__support.math.sinbf16
+)
+
add_entrypoint_object(
sinf
SRCS
diff --git a/libc/src/math/generic/sinbf16.cpp b/libc/src/math/generic/sinbf16.cpp
new file mode 100644
index 00000000000000..44f30352ead0e1
--- /dev/null
+++ b/libc/src/math/generic/sinbf16.cpp
@@ -0,0 +1,17 @@
+//===-- Implementation for sinbf16 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/sinbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/math/sinbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, sinbf16, (bfloat16 x)) { return math::sinbf16(x); }
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/sinbf16.h b/libc/src/math/sinbf16.h
new file mode 100644
index 00000000000000..ae754400168cd8
--- /dev/null
+++ b/libc/src/math/sinbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sinbf16 -----------------------*- 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_SINBF16_H
+#define LLVM_LIBC_SRC_MATH_SINBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 sinbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SINBF16_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 18638523256cf3..e71040c591b56a 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -495,6 +495,7 @@ else()
libc.src.__support.math.setpayloadsigl
libc.src.__support.math.sqrtf16
libc.src.__support.math.sin
+ libc.src.__support.math.sinbf16
libc.src.__support.math.sincos
libc.src.__support.math.sincosf
libc.src.__support.math.sinf
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 9ddce72220c8dd..53cf9a94c39b29 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -856,6 +856,7 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
LIBC_NAMESPACE::shared::hypotbf16(bfloat16(4.0), bfloat16(3.0)));
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::logbbf16(bfloat16(1.0f)));
+ EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::sinbf16(bfloat16(0.0)));
bfloat16 setpayloadbf16_res = bfloat16(0.0);
EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadbf16(&setpayloadbf16_res,
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index e87122875cfec3..bb2b16e2517b36 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -83,6 +83,19 @@ add_fp_unittest(
libc.src.math.daddl
)
+add_fp_unittest(
+ sinbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ sinbf16_test.cpp
+ DEPENDS
+ libc.src.math.sinbf16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
sinf_test
NEED_MPFR
diff --git a/libc/test/src/math/sinbf16_test.cpp b/libc/test/src/math/sinbf16_test.cpp
new file mode 100644
index 00000000000000..5c3d9138e2b6ed
--- /dev/null
+++ b/libc/test/src/math/sinbf16_test.cpp
@@ -0,0 +1,45 @@
+//===-- Unittests for sinbf16 ---------------------------------------------===//
+//
+// 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/sinbf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcSinBf16Test = 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(LlvmLibcSinBf16Test, PositiveRange) {
+
+ for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
+ bfloat16 x = FPBits(v).get_val();
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x,
+ LIBC_NAMESPACE::sinbf16(x), 0.5);
+ }
+}
+
+TEST_F(LlvmLibcSinBf16Test, NegativeRange) {
+
+ for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
+ bfloat16 x = FPBits(v).get_val();
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x,
+ LIBC_NAMESPACE::sinbf16(x), 0.5);
+ }
+}
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 9bb2f0ccd5dce2..7f2b50feaacf78 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -47,6 +47,19 @@ add_fp_unittest(
libc.src.__support.FPUtil.cast
)
+add_fp_unittest(
+ sinbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ sinbf16_test.cpp
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.src.math.sinbf16
+ libc.hdr.fenv_macros
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
sinf_test
SUITE
diff --git a/libc/test/src/math/smoke/sinbf16_test.cpp b/libc/test/src/math/smoke/sinbf16_test.cpp
new file mode 100644
index 00000000000000..4f2cb201340e20
--- /dev/null
+++ b/libc/test/src/math/smoke/sinbf16_test.cpp
@@ -0,0 +1,40 @@
+//===-- Unittests for sinbf16 ---------------------------------------------===//
+//
+// 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/sinbf16.h"
+#include "test/UnitTest/FEnvSafeTest.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+class LlvmLibcSinBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+ DECLARE_SPECIAL_CONSTANTS(bfloat16)
+public:
+ void test_special_numbers() {
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::sinbf16(aNaN));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+ aNaN, LIBC_NAMESPACE::sinbf16(sNaN), FE_INVALID);
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::sinbf16(zero));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, LIBC_NAMESPACE::sinbf16(neg_zero));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::sinbf16(inf));
+ EXPECT_MATH_ERRNO(EDOM);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::sinbf16(neg_inf));
+ EXPECT_MATH_ERRNO(EDOM);
+ }
+};
+TEST_F(LlvmLibcSinBf16Test, 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 e41bc10b25dff6..e489ccfa6b3755 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -12119,6 +12119,22 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_sinbf16",
+ hdrs = ["src/__support/math/sinbf16.h"],
+ deps = [
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_cast",
+ ":__support_fputil_fenv_impl",
+ ":__support_fputil_fp_bits",
+ ":__support_fputil_multiply_add",
+ ":__support_macros_optimization",
+ ":__support_sincosf_utils",
+ ":hdr_errno_macros",
+ ":hdr_fenv_macros",
+ ],
+)
+
libc_support_library(
name = "__support_math_sinf",
hdrs = [
@@ -16494,6 +16510,13 @@ libc_math_function(
],
)
+libc_math_function(
+ name = "sinbf16",
+ additional_deps = [
+ ":__support_math_sinbf16",
+ ],
+)
+
libc_math_function(
name = "sinf",
additional_deps = [":__support_math_sinf"],
>From 6a983feec2f3f0bc82a746d7ed75d2e17c02d68b Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 27 Jun 2026 00:57:18 +0530
Subject: [PATCH 02/11] nits and add freebsd entrypoint
---
libc/config/freebsd/x86_64/entrypoints.txt | 1 +
libc/src/__support/math/sinbf16.h | 11 +++++------
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 7ee9f58c04f72e..28c3ca6411f7f6 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -653,6 +653,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
diff --git a/libc/src/__support/math/sinbf16.h b/libc/src/__support/math/sinbf16.h
index de67d9ab575827..cdbd29ce54e231 100644
--- a/libc/src/__support/math/sinbf16.h
+++ b/libc/src/__support/math/sinbf16.h
@@ -34,13 +34,12 @@ LIBC_INLINE bfloat16 sinbf16(bfloat16 x) {
float xf = x;
if (x_abs < 0x7f80) {
-
- int rounding = fputil::quick_get_round();
if (LIBC_UNLIKELY(x_abs <= 0x3e12)) {
// sin(+/-0) = +/-0
- if (LIBC_UNLIKELY(x_abs == 0U))
+ if (LIBC_UNLIKELY(x_abs == 0))
return x;
+ int rounding = fputil::quick_get_round();
// When x > 0, and rounding upward, sin(x) == x.
// When x < 0, and rounding downward, sin(x) == x.
if ((rounding == FE_UPWARD && xbits.is_pos()) ||
@@ -54,10 +53,10 @@ LIBC_INLINE bfloat16 sinbf16(bfloat16 x) {
}
}
double xd = static_cast<double>(xf);
- uint32_t x_abs_d = fputil::FPBits<float>(xf).uintval() & 0x7fffffff;
+ uint32_t x_abs_f = fputil::FPBits<float>(xf).uintval() & 0x7fffffff;
double sin_k, cos_k, sin_y, cosm1_y;
- sincosf_eval(xd, x_abs_d, sin_k, cos_k, sin_y, cosm1_y);
+ sincosf_eval(xd, x_abs_f, sin_k, cos_k, sin_y, cosm1_y);
// using sin(a + b) = sin(a)*cos(b) + cos(a)*sin(b)
// sin(x) = sin_k*cos_y + cos_k*sin_y
// but cosm1_y = cos_y - 1 --> cos_y = cosm1_y + 1
@@ -69,7 +68,7 @@ LIBC_INLINE bfloat16 sinbf16(bfloat16 x) {
sin_y, cos_k, fputil::multiply_add(cosm1_y, sin_k, sin_k)));
}
- // nan
+ // NaN
if (xbits.is_nan()) {
if (xbits.is_signaling_nan()) {
fputil::raise_except_if_required(FE_INVALID);
>From 83084d03c15c5db049169ae5022af7d781c8b76f Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 17 Oct 2026 12:10:58 +0530
Subject: [PATCH 03/11] nits
---
libc/shared/math/sinbf16.h | 1 +
libc/src/__support/math/CMakeLists.txt | 2 ++
libc/src/__support/math/sinbf16.h | 2 ++
libc/src/math/generic/sinbf16.cpp | 3 ++-
4 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/libc/shared/math/sinbf16.h b/libc/shared/math/sinbf16.h
index f85a4795d51702..4874866d1f12cc 100644
--- a/libc/shared/math/sinbf16.h
+++ b/libc/shared/math/sinbf16.h
@@ -10,6 +10,7 @@
#define LLVM_LIBC_SHARED_MATH_SINBF16_H
#include "shared/libc_common.h"
+#include "src/__support/macros/config.h"
#include "src/__support/math/sinbf16.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 62236629b60187..ee57d082456c33 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -5892,6 +5892,8 @@ add_header_library(
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.multiply_add
+ libc.src.__support.macros.attributes
+ libc.src.__support.macros.config
libc.src.__support.macros.optimization
libc.src.__support.FPUtil.bfloat16
)
diff --git a/libc/src/__support/math/sinbf16.h b/libc/src/__support/math/sinbf16.h
index cdbd29ce54e231..83993caf6e73ed 100644
--- a/libc/src/__support/math/sinbf16.h
+++ b/libc/src/__support/math/sinbf16.h
@@ -17,6 +17,8 @@
#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/cast.h"
#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/math/generic/sinbf16.cpp b/libc/src/math/generic/sinbf16.cpp
index 44f30352ead0e1..422299beec2ed0 100644
--- a/libc/src/math/generic/sinbf16.cpp
+++ b/libc/src/math/generic/sinbf16.cpp
@@ -7,7 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/sinbf16.h"
-#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
#include "src/__support/math/sinbf16.h"
namespace LIBC_NAMESPACE_DECL {
>From fe7a660d032fd6c56c477dbb112c82629e7e0ef0 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 17 Oct 2026 12:18:27 +0530
Subject: [PATCH 04/11] new header commments
---
libc/shared/math/sinbf16.h | 7 ++++++-
libc/src/__support/math/sinbf16.h | 7 ++++++-
libc/src/math/generic/sinbf16.cpp | 7 ++++++-
libc/src/math/sinbf16.h | 7 ++++++-
libc/test/src/math/sinbf16_test.cpp | 7 ++++++-
libc/test/src/math/smoke/sinbf16_test.cpp | 7 ++++++-
6 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/libc/shared/math/sinbf16.h b/libc/shared/math/sinbf16.h
index 4874866d1f12cc..71605acf635f95 100644
--- a/libc/shared/math/sinbf16.h
+++ b/libc/shared/math/sinbf16.h
@@ -1,10 +1,15 @@
-//===-- Shared sinbf16 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
+/// Shared header for the sinbf16 function.
+///
+//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SHARED_MATH_SINBF16_H
#define LLVM_LIBC_SHARED_MATH_SINBF16_H
diff --git a/libc/src/__support/math/sinbf16.h b/libc/src/__support/math/sinbf16.h
index 83993caf6e73ed..a01b642eff7145 100644
--- a/libc/src/__support/math/sinbf16.h
+++ b/libc/src/__support/math/sinbf16.h
@@ -1,10 +1,15 @@
-//===-- Implementation of sinbf16(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
//
//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of the sinbf16 function.
+///
+//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINBF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_SINBF16_H
diff --git a/libc/src/math/generic/sinbf16.cpp b/libc/src/math/generic/sinbf16.cpp
index 422299beec2ed0..b4846830947f1e 100644
--- a/libc/src/math/generic/sinbf16.cpp
+++ b/libc/src/math/generic/sinbf16.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation for sinbf16 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
//
//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Entrypoint definition for the sinbf16 function.
+///
+//===----------------------------------------------------------------------===//
#include "src/math/sinbf16.h"
#include "src/__support/common.h"
diff --git a/libc/src/math/sinbf16.h b/libc/src/math/sinbf16.h
index ae754400168cd8..9a8aebadac0791 100644
--- a/libc/src/math/sinbf16.h
+++ b/libc/src/math/sinbf16.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for sinbf16 -----------------------*- 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
+/// Public declaration of the sinbf16 entrypoint.
+///
+//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_MATH_SINBF16_H
#define LLVM_LIBC_SRC_MATH_SINBF16_H
diff --git a/libc/test/src/math/sinbf16_test.cpp b/libc/test/src/math/sinbf16_test.cpp
index 5c3d9138e2b6ed..5d5e09cf4d65af 100644
--- a/libc/test/src/math/sinbf16_test.cpp
+++ b/libc/test/src/math/sinbf16_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for sinbf16 ---------------------------------------------===//
+//===----------------------------------------------------------------------===//
//
// 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
+/// Unit tests for the sinbf16 function.
+///
+//===----------------------------------------------------------------------===//
#include "src/__support/FPUtil/bfloat16.h"
#include "src/math/sinbf16.h"
diff --git a/libc/test/src/math/smoke/sinbf16_test.cpp b/libc/test/src/math/smoke/sinbf16_test.cpp
index 4f2cb201340e20..7f7214a2ea72e1 100644
--- a/libc/test/src/math/smoke/sinbf16_test.cpp
+++ b/libc/test/src/math/smoke/sinbf16_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for sinbf16 ---------------------------------------------===//
+//===----------------------------------------------------------------------===//
//
// 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 the sinbf16 function.
+///
+//===----------------------------------------------------------------------===//
#include "hdr/errno_macros.h"
#include "src/__support/FPUtil/bfloat16.h"
>From ceba550fdebf29ccabdc9db212275764f65eeebf Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 17 Oct 2026 14:06:30 +0530
Subject: [PATCH 05/11] 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 4e641c872edd2d..8a15664f1ab33a 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
@@ -1041,6 +1041,13 @@ math_mpfr_test(
math_mpfr_test(name = "sin")
+math_mpfr_test(
+ name = "sinbf16",
+ deps = [
+ "//libc:__support_fputil_bfloat16",
+ ],
+)
+
math_mpfr_test(
name = "sinf",
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 c43d3f272cfe06..2d4aa158ef13f3 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
@@ -2379,6 +2379,13 @@ math_test(
math_test(name = "sin")
+math_test(
+ name = "sinbf16",
+ deps = [
+ "//libc:__support_fputil_bfloat16",
+ ],
+)
+
math_test(name = "sinf")
math_test(name = "sincos")
>From c7127978ed3e77c1707c30851e1d5157fae31c2d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 17 Oct 2026 14:26:12 +0530
Subject: [PATCH 06/11] bazel missing deps
---
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 2 ++
1 file changed, 2 insertions(+)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index e489ccfa6b3755..89c312fa4fe87b 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -12128,6 +12128,8 @@ libc_support_library(
":__support_fputil_fenv_impl",
":__support_fputil_fp_bits",
":__support_fputil_multiply_add",
+ ":__support_macros_attributes",
+ ":__support_macros_config",
":__support_macros_optimization",
":__support_sincosf_utils",
":hdr_errno_macros",
>From 8883ed187927bfcd78019190c1d0d5d5ca14c825 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 18 Oct 2026 12:24:40 +0530
Subject: [PATCH 07/11] apply suggestions
---
libc/src/__support/math/sinbf16.h | 5 ++++-
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 2 --
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/libc/src/__support/math/sinbf16.h b/libc/src/__support/math/sinbf16.h
index a01b642eff7145..fe9a678c00285c 100644
--- a/libc/src/__support/math/sinbf16.h
+++ b/libc/src/__support/math/sinbf16.h
@@ -16,7 +16,6 @@
#include "hdr/errno_macros.h"
#include "hdr/fenv_macros.h"
-#include "sincosf_utils.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/bfloat16.h"
@@ -25,6 +24,7 @@
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"
+#include "src/__support/math/sincosf_utils.h"
namespace LIBC_NAMESPACE_DECL {
@@ -41,11 +41,13 @@ LIBC_INLINE bfloat16 sinbf16(bfloat16 x) {
float xf = x;
if (x_abs < 0x7f80) {
+ // |x| <= 0x1.24p-3f (0x3e12)
if (LIBC_UNLIKELY(x_abs <= 0x3e12)) {
// sin(+/-0) = +/-0
if (LIBC_UNLIKELY(x_abs == 0))
return x;
+#ifndef LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
int rounding = fputil::quick_get_round();
// When x > 0, and rounding upward, sin(x) == x.
// When x < 0, and rounding downward, sin(x) == x.
@@ -58,6 +60,7 @@ LIBC_INLINE bfloat16 sinbf16(bfloat16 x) {
x_u--;
return FPBits(x_u).get_val();
}
+#endif // !LIBC_MATH_HAS_ASSUME_ROUND_NEAREST_ONLY
}
double xd = static_cast<double>(xf);
uint32_t x_abs_f = fputil::FPBits<float>(xf).uintval() & 0x7fffffff;
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 89c312fa4fe87b..e489ccfa6b3755 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -12128,8 +12128,6 @@ libc_support_library(
":__support_fputil_fenv_impl",
":__support_fputil_fp_bits",
":__support_fputil_multiply_add",
- ":__support_macros_attributes",
- ":__support_macros_config",
":__support_macros_optimization",
":__support_sincosf_utils",
":hdr_errno_macros",
>From c007063f780a58b88e7aed9ade062d7e60a10767 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 21 Oct 2026 19:32:17 +0530
Subject: [PATCH 08/11] nits
---
libc/src/__support/math/sinbf16.h | 1 +
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 2 ++
2 files changed, 3 insertions(+)
diff --git a/libc/src/__support/math/sinbf16.h b/libc/src/__support/math/sinbf16.h
index fe9a678c00285c..219fb2b7fadcc3 100644
--- a/libc/src/__support/math/sinbf16.h
+++ b/libc/src/__support/math/sinbf16.h
@@ -40,6 +40,7 @@ LIBC_INLINE bfloat16 sinbf16(bfloat16 x) {
uint16_t x_abs = x_u & 0x7fff;
float xf = x;
+ // |x| < inf (0x7f80)
if (x_abs < 0x7f80) {
// |x| <= 0x1.24p-3f (0x3e12)
if (LIBC_UNLIKELY(x_abs <= 0x3e12)) {
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index e489ccfa6b3755..89c312fa4fe87b 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -12128,6 +12128,8 @@ libc_support_library(
":__support_fputil_fenv_impl",
":__support_fputil_fp_bits",
":__support_fputil_multiply_add",
+ ":__support_macros_attributes",
+ ":__support_macros_config",
":__support_macros_optimization",
":__support_sincosf_utils",
":hdr_errno_macros",
>From 7a85d7500f024e3543c279c363153ea71b48963f Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 3 Nov 2026 23:03:29 +0530
Subject: [PATCH 09/11] add to hexagon entrypoint list
---
libc/config/baremetal/hexagon/entrypoints.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/config/baremetal/hexagon/entrypoints.txt b/libc/config/baremetal/hexagon/entrypoints.txt
index 44e287ec3b62e6..f10de569db06f6 100644
--- a/libc/config/baremetal/hexagon/entrypoints.txt
+++ b/libc/config/baremetal/hexagon/entrypoints.txt
@@ -899,6 +899,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
+ libc.src.math.sinbf16
libc.src.math.sinhbf16
libc.src.math.sqrtbf16
libc.src.math.tanbf16
>From 59a5299b467580c37b233ec05a04ea5758dd52a1 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 3 Nov 2026 23:06:20 +0530
Subject: [PATCH 10/11] add in index.md
---
libc/docs/headers/math/index.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/docs/headers/math/index.md b/libc/docs/headers/math/index.md
index e82e308351dce4..d6e0f647594537 100644
--- a/libc/docs/headers/math/index.md
+++ b/libc/docs/headers/math/index.md
@@ -209,7 +209,7 @@ log
| 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 |
+| sin | {{ check }} | {{ check }} | | | {{ check }} | | {{ check }} | 7.12.4.6 | F.10.1.6 |
| sincos | {{ check }} | {{ check }} | | | | | | | |
| sinh | {{ check }} | {{ check }} | | | {{ check }} | | {{ check }} | 7.12.5.5 | F.10.2.5 |
| sinpi | {{ check }} | | | | {{ check }} | | | 7.12.4.13 | F.10.1.13 |
>From 1d91fde162f3b5bb79b34c078c0e9f7c1efff303 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 3 Nov 2026 23:15:48 +0530
Subject: [PATCH 11/11] nit
---
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 bb2b16e2517b36..ba0ab3a0fd8846 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -87,7 +87,7 @@ add_fp_unittest(
sinbf16_test
NEED_MPFR
SUITE
- libc-math-unittests
+ libc-math-tests
SRCS
sinbf16_test.cpp
DEPENDS
More information about the libc-commits
mailing list