[libc-commits] [libc] [llvm] [libc][math][c23] Add sinbf16 function (PR #185441)
via libc-commits
libc-commits at lists.llvm.org
Tue Nov 3 09:46:15 PST 2026
https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/185441
>From dc518b9208375986a9ebf05ab7ee213515704006 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 f8175da9fadb80..68008a62c7507c 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -892,6 +892,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index ab84c92f5c03c9..e8650342b93ce0 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -903,6 +903,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 01a7251e35b447..49d580e06e2da4 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -895,6 +895,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 363cb74dc209e0..d493d5f0300d1b 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -714,6 +714,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index e5b82f29b6686b..21756b467248a8 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -351,6 +351,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 2b0874bbe1f089..0943b93ac8e164 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -773,6 +773,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 2adf832016d21a..021d884f49b79f 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -789,6 +789,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 02f5aecaa862c0..8596c962c115a8 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1129,6 +1129,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 71cb938ec9459f..78487f44b69f1e 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -740,6 +740,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 23c2aaec20ead2..abc603dbdd1e01 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1209,6 +1209,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 88ee0729735ff9..46d59190ed6327 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1231,6 +1231,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 9bf43138e4eff1..91d628dc860c4c 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -450,6 +450,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
diff --git a/libc/shared/math.h b/libc/shared/math.h
index bf490aa4738b41..fb6ac02eb58314 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -477,6 +477,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 bf87c405cc0814..c946d96fd419a3 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -5811,6 +5811,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 08728a02809359..4699c8d10939da 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -588,6 +588,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 30f40f993330c7..dcc6725d9339b5 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -341,6 +341,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 554f8d2bdcfac2..7afae20d7335d0 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -490,6 +490,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 7ca4b7340dd6b2..b23bae04e9e5a3 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -843,6 +843,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 fb025dee1d33e7..b23080f6aff4e4 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 126e516f879dcd..f0fb1c4b05beda 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 8ea7140904b6f9..f254f8e78de89e 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -11919,6 +11919,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 = [
@@ -16195,6 +16211,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 7aa9c45a172a43301a707171a415bed89b89270e 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 56f60acadd6693..fe476b9d44caa5 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -646,6 +646,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
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 5c778d2f86d260f75b6f4be30f3ea58d5a198049 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 c946d96fd419a3..41d6757cff199b 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -5823,6 +5823,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 3027241de5aaf8002c39144e581b0decde3dfea4 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 5f0437ca9d89ef909c035afb70497cac32e907a3 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 9460f690487f3b..fbbfea3fe3ead9 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
@@ -1028,6 +1028,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 49f4bb29551a41..b6d996bd900330 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
@@ -2332,6 +2332,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 161717229712d22dc7d940e93d57ac43b61a494f 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 f254f8e78de89e..5f068009f0c15d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -11928,6 +11928,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 e3651686eb0b48b09c8ed4d2cf0477c49f95335b 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 5f068009f0c15d..f254f8e78de89e 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -11928,8 +11928,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 d82a5d1ca9641b3c43ba7f4afc1425676a4c2deb 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 f254f8e78de89e..5f068009f0c15d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -11928,6 +11928,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 bf868ba876850c9054a1dcda01c1b080c969afa1 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 a7617ec243e278..de3b86c8e65de5 100644
--- a/libc/config/baremetal/hexagon/entrypoints.txt
+++ b/libc/config/baremetal/hexagon/entrypoints.txt
@@ -892,6 +892,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.sqrtbf16
libc.src.math.tanbf16
libc.src.math.truncbf16
>From 5957bf5e214364950db4cc265c1ffe990d0a4306 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 d138caa5eb34aa..d676267e0852d8 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 }} | | | 7.12.5.5 | F.10.2.5 |
| sinpi | {{ check }} | | | | {{ check }} | | | 7.12.4.13 | F.10.1.13 |
>From 07ee79407693e8d961d23c06283336b407357466 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 b23080f6aff4e4..6f1c59eadf4a8d 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