[libc-commits] [libc] [llvm] [libc] use constexpr for sinpif (PR #176580)

via libc-commits libc-commits at lists.llvm.org
Mon Jan 19 09:08:15 PST 2026


https://github.com/DannyDaoBoYang updated https://github.com/llvm/llvm-project/pull/176580

>From ebcb49a1161f656bc04b959047f7d9167001de29 Mon Sep 17 00:00:00 2001
From: DannyDaoBoYang <34634047+DannyDaoBoYang at users.noreply.github.com>
Date: Sat, 17 Jan 2026 12:38:22 -0500
Subject: [PATCH 1/8] [libc] use constexpr for sinpif

---
 libc/shared/math.h                            |   1 +
 libc/shared/math/sinpif.h                     |  22 ++++
 libc/src/__support/math/CMakeLists.txt        |  16 +++
 libc/src/__support/math/sinpif.h              | 120 ++++++++++++++++++
 libc/src/math/generic/CMakeLists.txt          |   9 +-
 libc/src/math/generic/sinpif.cpp              | 105 +--------------
 libc/test/shared/CMakeLists.txt               |   1 +
 libc/test/shared/shared_math_test.cpp         |   3 +-
 .../llvm-project-overlay/libc/BUILD.bazel     |   7 +-
 9 files changed, 171 insertions(+), 113 deletions(-)
 create mode 100644 libc/shared/math/sinpif.h
 create mode 100644 libc/src/__support/math/sinpif.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index b75e60c4f1973..21e037bed7a51 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -71,5 +71,6 @@
 #include "math/rsqrtf.h"
 #include "math/rsqrtf16.h"
 #include "math/sin.h"
+#include "math/sinpif.h"
 
 #endif // LLVM_LIBC_SHARED_MATH_H
diff --git a/libc/shared/math/sinpif.h b/libc/shared/math/sinpif.h
new file mode 100644
index 0000000000000..82fe1937f1c83
--- /dev/null
+++ b/libc/shared/math/sinpif.h
@@ -0,0 +1,22 @@
+//===-- Shared sin 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_SINPIF_H
+#define LLVM_LIBC_SHARED_MATH_SINPIF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/sinpif.h"
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::sinpif;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SINPIF_H
\ No newline at end of file
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 97852c8688182..15b4b39b3eaff 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1044,6 +1044,22 @@ add_header_library(
     libc.src.__support.FPUtil.multiply_add
 )
 
+add_header_library(
+  sinpif
+  HDRS
+    sinpif.h
+  DEPENDS
+    .exp10f_utils
+    libc.src.__support.FPUtil.FEnvImpl
+    libc.src.__support.FPUtil.FPBits
+    libc.src.__support.FPUtil.PolyEval
+    libc.src.__support.FPUtil.multiply_add
+    libc.src.__support.common
+    libc.src.__support.macros.config
+    libc.src.__support.macros.optimization
+    libc.src.__support.math.sincosf_utils
+)
+
 add_header_library(
   log
   HDRS
diff --git a/libc/src/__support/math/sinpif.h b/libc/src/__support/math/sinpif.h
new file mode 100644
index 0000000000000..c1e97ddd0c3c8
--- /dev/null
+++ b/libc/src/__support/math/sinpif.h
@@ -0,0 +1,120 @@
+//===-- Implementation header for sinpif -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINPIF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SINPIF_H
+
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+#include "src/__support/math/sincosf_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+LIBC_INLINE static constexpr float sinpif(float x) {
+  using FPBits = typename fputil::FPBits<float>;
+  FPBits xbits(x);
+
+  uint32_t x_u = xbits.uintval();
+  uint32_t x_abs = x_u & 0x7fff'ffffU;
+  double xd = static_cast<double>(x);
+
+  // Range reduction:
+  // For |x| > 1/32, we perform range reduction as follows:
+  // Find k and y such that:
+  //   x = (k + y) * 1/32
+  //   k is an integer
+  //   |y| < 0.5
+  //
+  // This is done by performing:
+  //   k = round(x * 32)
+  //   y = x * 32 - k
+  //
+  // Once k and y are computed, we then deduce the answer by the sine of sum
+  // formula:
+  //   sin(x * pi) = sin((k + y)*pi/32)
+  //          = sin(y*pi/32) * cos(k*pi/32) + cos(y*pi/32) * sin(k*pi/32)
+  // The values of sin(k*pi/32) and cos(k*pi/32) for k = 0..31 are precomputed
+  // and stored using a vector of 32 doubles. Sin(y*pi/32) and cos(y*pi/32) are
+  // computed using degree-7 and degree-6 minimax polynomials generated by
+  // Sollya respectively.
+
+  // |x| <= 1/16
+  if (LIBC_UNLIKELY(x_abs <= 0x3d80'0000U)) {
+
+    if (LIBC_UNLIKELY(x_abs < 0x33CD'01D7U)) {
+      if (LIBC_UNLIKELY(x_abs == 0U)) {
+        // For signed zeros.
+        return x;
+      }
+
+      // For very small values we can approximate sinpi(x) with x * pi
+      // An exhaustive test shows that this is accurate for |x| < 9.546391 ×
+      // 10-8
+      double xdpi = xd * 0x1.921fb54442d18p1;
+      return static_cast<float>(xdpi);
+    }
+
+    // |x| < 1/16.
+    double xsq = xd * xd;
+
+    // Degree-9 polynomial approximation:
+    //   sinpi(x) ~ x + a_3 x^3 + a_5 x^5 + a_7 x^7 + a_9 x^9
+    //          = x (1 + a_3 x^2 + ... + a_9 x^8)
+    //          = x * P(x^2)
+    // generated by Sollya with the following commands:
+    // > display = hexadecimal;
+    // > Q = fpminimax(sin(pi * x)/x, [|0, 2, 4, 6, 8|], [|D...|], [0, 1/16]);
+    double result = fputil::polyeval(
+        xsq, 0x1.921fb54442d18p1, -0x1.4abbce625bbf2p2, 0x1.466bc675e116ap1,
+        -0x1.32d2c0b62d41cp-1, 0x1.501ec4497cb7dp-4);
+    return static_cast<float>(xd * result);
+  }
+
+  // Numbers greater or equal to 2^23 are always integers or NaN
+  if (LIBC_UNLIKELY(x_abs >= 0x4B00'0000)) {
+
+    // check for NaN values
+    if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
+      if (xbits.is_signaling_nan()) {
+        fputil::raise_except_if_required(FE_INVALID);
+        return FPBits::quiet_nan().get_val();
+      }
+
+      if (x_abs == 0x7f80'0000U) {
+        fputil::set_errno_if_required(EDOM);
+        fputil::raise_except_if_required(FE_INVALID);
+      }
+
+      return x + FPBits::quiet_nan().get_val();
+    }
+
+    return FPBits::zero(xbits.sign()).get_val();
+  }
+
+  // Combine the results with the sine of sum formula:
+  //   sin(x * pi) = sin((k + y)*pi/32)
+  //          = sin(y*pi/32) * cos(k*pi/32) + cos(y*pi/32) * sin(k*pi/32)
+  //          = sin_y * cos_k + (1 + cosm1_y) * sin_k
+  //          = sin_y * cos_k + (cosm1_y * sin_k + sin_k)
+  double sin_k = 0, cos_k = 0, sin_y = 0, cosm1_y = 0;
+  sincospif_eval(xd, sin_k, cos_k, sin_y, cosm1_y);
+
+  if (LIBC_UNLIKELY(sin_y == 0 && sin_k == 0))
+    return FPBits::zero(xbits.sign()).get_val();
+
+  return static_cast<float>(fputil::multiply_add(
+      sin_y, cos_k, fputil::multiply_add(cosm1_y, sin_k, sin_k)));
+}
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINPIF_H
\ No newline at end of file
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 6fb260a7523d4..bbe9ea50fb209 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -433,14 +433,7 @@ add_entrypoint_object(
   HDRS
     ../sinpif.h
   DEPENDS
-    libc.src.__support.math.sincosf_utils
-    libc.src.__support.FPUtil.fenv_impl
-    libc.src.__support.FPUtil.fp_bits
-    libc.src.__support.FPUtil.fma
-    libc.src.__support.FPUtil.multiply_add
-    libc.src.__support.FPUtil.polyeval
-    libc.src.__support.common
-    libc.src.__support.macros.optimization
+    libc.src.__support.math.sinpif
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/sinpif.cpp b/libc/src/math/generic/sinpif.cpp
index f3383f19db60f..f7a6e1acb6534 100644
--- a/libc/src/math/generic/sinpif.cpp
+++ b/libc/src/math/generic/sinpif.cpp
@@ -7,111 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/sinpif.h"
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/PolyEval.h"
-#include "src/__support/FPUtil/multiply_add.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
-#include "src/__support/math/sincosf_utils.h"
-
+#include "src/__support/math/sinpif.h"
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, sinpif, (float x)) {
-  using FPBits = typename fputil::FPBits<float>;
-  FPBits xbits(x);
-
-  uint32_t x_u = xbits.uintval();
-  uint32_t x_abs = x_u & 0x7fff'ffffU;
-  double xd = static_cast<double>(x);
-
-  // Range reduction:
-  // For |x| > 1/32, we perform range reduction as follows:
-  // Find k and y such that:
-  //   x = (k + y) * 1/32
-  //   k is an integer
-  //   |y| < 0.5
-  //
-  // This is done by performing:
-  //   k = round(x * 32)
-  //   y = x * 32 - k
-  //
-  // Once k and y are computed, we then deduce the answer by the sine of sum
-  // formula:
-  //   sin(x * pi) = sin((k + y)*pi/32)
-  //          = sin(y*pi/32) * cos(k*pi/32) + cos(y*pi/32) * sin(k*pi/32)
-  // The values of sin(k*pi/32) and cos(k*pi/32) for k = 0..31 are precomputed
-  // and stored using a vector of 32 doubles. Sin(y*pi/32) and cos(y*pi/32) are
-  // computed using degree-7 and degree-6 minimax polynomials generated by
-  // Sollya respectively.
-
-  // |x| <= 1/16
-  if (LIBC_UNLIKELY(x_abs <= 0x3d80'0000U)) {
-
-    if (LIBC_UNLIKELY(x_abs < 0x33CD'01D7U)) {
-      if (LIBC_UNLIKELY(x_abs == 0U)) {
-        // For signed zeros.
-        return x;
-      }
-
-      // For very small values we can approximate sinpi(x) with x * pi
-      // An exhaustive test shows that this is accurate for |x| < 9.546391 ×
-      // 10-8
-      double xdpi = xd * 0x1.921fb54442d18p1;
-      return static_cast<float>(xdpi);
-    }
-
-    // |x| < 1/16.
-    double xsq = xd * xd;
-
-    // Degree-9 polynomial approximation:
-    //   sinpi(x) ~ x + a_3 x^3 + a_5 x^5 + a_7 x^7 + a_9 x^9
-    //          = x (1 + a_3 x^2 + ... + a_9 x^8)
-    //          = x * P(x^2)
-    // generated by Sollya with the following commands:
-    // > display = hexadecimal;
-    // > Q = fpminimax(sin(pi * x)/x, [|0, 2, 4, 6, 8|], [|D...|], [0, 1/16]);
-    double result = fputil::polyeval(
-        xsq, 0x1.921fb54442d18p1, -0x1.4abbce625bbf2p2, 0x1.466bc675e116ap1,
-        -0x1.32d2c0b62d41cp-1, 0x1.501ec4497cb7dp-4);
-    return static_cast<float>(xd * result);
-  }
-
-  // Numbers greater or equal to 2^23 are always integers or NaN
-  if (LIBC_UNLIKELY(x_abs >= 0x4B00'0000)) {
-
-    // check for NaN values
-    if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
-      if (xbits.is_signaling_nan()) {
-        fputil::raise_except_if_required(FE_INVALID);
-        return FPBits::quiet_nan().get_val();
-      }
-
-      if (x_abs == 0x7f80'0000U) {
-        fputil::set_errno_if_required(EDOM);
-        fputil::raise_except_if_required(FE_INVALID);
-      }
-
-      return x + FPBits::quiet_nan().get_val();
-    }
-
-    return FPBits::zero(xbits.sign()).get_val();
-  }
-
-  // Combine the results with the sine of sum formula:
-  //   sin(x * pi) = sin((k + y)*pi/32)
-  //          = sin(y*pi/32) * cos(k*pi/32) + cos(y*pi/32) * sin(k*pi/32)
-  //          = sin_y * cos_k + (1 + cosm1_y) * sin_k
-  //          = sin_y * cos_k + (cosm1_y * sin_k + sin_k)
-  double sin_k, cos_k, sin_y, cosm1_y;
-  sincospif_eval(xd, sin_k, cos_k, sin_y, cosm1_y);
-
-  if (LIBC_UNLIKELY(sin_y == 0 && sin_k == 0))
-    return FPBits::zero(xbits.sign()).get_val();
-
-  return static_cast<float>(fputil::multiply_add(
-      sin_y, cos_k, fputil::multiply_add(cosm1_y, sin_k, sin_k)));
+  return math::sinpif(x);
 }
-
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 3a9bf9f8d4cf4..7bfd26f9d6145 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -67,4 +67,5 @@ add_fp_unittest(
     libc.src.__support.math.rsqrtf
     libc.src.__support.math.rsqrtf16
     libc.src.__support.math.sin
+    libc.src.__support.math.sinpif
 )
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 84563d851a002..d04876318f002 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -69,7 +69,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::expf(0.0f));
   EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::exp2f(0.0f));
   EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::expm1f(0.0f));
-
+  
   EXPECT_FP_EQ_ALL_ROUNDING(0.75f,
                             LIBC_NAMESPACE::shared::frexpf(24.0f, &exponent));
   EXPECT_EQ(exponent, 5);
@@ -78,6 +78,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   ASSERT_FP_EQ(float(-1 * (8 << 5)), LIBC_NAMESPACE::shared::ldexpf(-8.0f, 5));
 
   EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::rsqrtf(1.0f));
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::sinpif(0.0f));
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index f1d390207e45e..1eb9b99e61a33 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3267,6 +3267,11 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_sinpif",
+    hdrs = ["src/__support/math/sinpif.h"],
+    deps = [":__support_sincosf_utils",],
+)
 ############################### complex targets ################################
 
 libc_function(
@@ -4886,7 +4891,7 @@ libc_math_function(
 libc_math_function(
     name = "sinpif",
     additional_deps = [
-        ":__support_sincosf_utils",
+        ":__support_math_sinpif",
     ],
 )
 

>From e9494a012db214bde405ae10a01a133468e5bb6b Mon Sep 17 00:00:00 2001
From: DannyDaoBoYang <34634047+DannyDaoBoYang at users.noreply.github.com>
Date: Sat, 17 Jan 2026 12:54:30 -0500
Subject: [PATCH 2/8] newline at end of line

---
 libc/src/__support/math/sinpif.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/__support/math/sinpif.h b/libc/src/__support/math/sinpif.h
index c1e97ddd0c3c8..14a5b3001fe22 100644
--- a/libc/src/__support/math/sinpif.h
+++ b/libc/src/__support/math/sinpif.h
@@ -117,4 +117,4 @@ LIBC_INLINE static constexpr float sinpif(float x) {
 }
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINPIF_H
\ No newline at end of file
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINPIF_H

>From 6facc7f903a5023743b6577a445c53a25cf50103 Mon Sep 17 00:00:00 2001
From: DannyDaoBoYang <daobo.yang41 at gmail.com>
Date: Sat, 17 Jan 2026 13:26:36 -0500
Subject: [PATCH 3/8] Apply suggestions from code review

Co-authored-by: Anonmiraj <ezzibrahimx at gmail.com>
---
 libc/shared/math/sinpif.h                         |  3 ++-
 libc/src/__support/math/CMakeLists.txt            |  2 +-
 libc/src/math/generic/sinpif.cpp                  |  1 +
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 11 ++++++++++-
 4 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/libc/shared/math/sinpif.h b/libc/shared/math/sinpif.h
index 82fe1937f1c83..fb4a4c06258e0 100644
--- a/libc/shared/math/sinpif.h
+++ b/libc/shared/math/sinpif.h
@@ -1,4 +1,4 @@
-//===-- Shared sin function -------------------------------------*- C++ -*-===//
+//===-- Shared sinpif 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.
@@ -11,6 +11,7 @@
 
 #include "shared/libc_common.h"
 #include "src/__support/math/sinpif.h"
+
 namespace LIBC_NAMESPACE_DECL {
 namespace shared {
 
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index d24fb29d14073..4e412fe287a30 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1091,7 +1091,7 @@ add_header_library(
   HDRS
     sinpif.h
   DEPENDS
-    .exp10f_utils
+
     libc.src.__support.FPUtil.FEnvImpl
     libc.src.__support.FPUtil.FPBits
     libc.src.__support.FPUtil.PolyEval
diff --git a/libc/src/math/generic/sinpif.cpp b/libc/src/math/generic/sinpif.cpp
index f7a6e1acb6534..062d340d4c107 100644
--- a/libc/src/math/generic/sinpif.cpp
+++ b/libc/src/math/generic/sinpif.cpp
@@ -8,6 +8,7 @@
 
 #include "src/math/sinpif.h"
 #include "src/__support/math/sinpif.h"
+
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, sinpif, (float x)) {
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index fb1aecc20fb6b..b41be3a4461f0 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3328,7 +3328,16 @@ libc_support_library(
 libc_support_library(
     name = "__support_math_sinpif",
     hdrs = ["src/__support/math/sinpif.h"],
-    deps = [":__support_sincosf_utils",],
+    deps = [
+    ":__support_common",
+    ":__support_fputil_fenv_impl",
+    ":__support_fputil_fp_bits",
+    ":__support_fputil_multiply_add",
+    ":__support_fputil_polyeval",
+    ":__support_macros_optimization",
+    ":__support_sincosf_utils",
+
+    ],
 )
 
 ############################### complex targets ################################

>From 04c40a2aa843d2402fb7a1b19a9383f45cf5046a Mon Sep 17 00:00:00 2001
From: DannyDaoBoYang <34634047+DannyDaoBoYang at users.noreply.github.com>
Date: Sat, 17 Jan 2026 13:28:02 -0500
Subject: [PATCH 4/8] buidifier format

---
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index b41be3a4461f0..11c70cb7b0210 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3329,14 +3329,13 @@ libc_support_library(
     name = "__support_math_sinpif",
     hdrs = ["src/__support/math/sinpif.h"],
     deps = [
-    ":__support_common",
-    ":__support_fputil_fenv_impl",
-    ":__support_fputil_fp_bits",
-    ":__support_fputil_multiply_add",
-    ":__support_fputil_polyeval",
-    ":__support_macros_optimization",
-    ":__support_sincosf_utils",
-
+        ":__support_common",
+        ":__support_fputil_fenv_impl",
+        ":__support_fputil_fp_bits",
+        ":__support_fputil_multiply_add",
+        ":__support_fputil_polyeval",
+        ":__support_macros_optimization",
+        ":__support_sincosf_utils",
     ],
 )
 

>From bfdc03d1a842b379646888ffdfdf47bb4aa930b7 Mon Sep 17 00:00:00 2001
From: DannyDaoBoYang <34634047+DannyDaoBoYang at users.noreply.github.com>
Date: Sat, 17 Jan 2026 13:50:49 -0500
Subject: [PATCH 5/8] clang-format

clang-format -i -Werror shared/math/sinpif.h libc/src/__support/math/sinpif.h libc/shared/math.h libc/src/math/generic/sinpif.cpp libc/test/shared/shared_math_test.cpp
---
 libc/src/__support/math/sinpif.h      | 2 +-
 libc/src/math/generic/sinpif.cpp      | 4 +---
 libc/test/shared/shared_math_test.cpp | 2 +-
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/libc/src/__support/math/sinpif.h b/libc/src/__support/math/sinpif.h
index 14a5b3001fe22..a44779c3befa9 100644
--- a/libc/src/__support/math/sinpif.h
+++ b/libc/src/__support/math/sinpif.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for sinpif -------------------------*- C++ -*-===//
+//===-- Implementation header for sinpif -----* C++*--===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/math/generic/sinpif.cpp b/libc/src/math/generic/sinpif.cpp
index 062d340d4c107..67e44a7df6bfd 100644
--- a/libc/src/math/generic/sinpif.cpp
+++ b/libc/src/math/generic/sinpif.cpp
@@ -11,7 +11,5 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(float, sinpif, (float x)) {
-  return math::sinpif(x);
-}
+LLVM_LIBC_FUNCTION(float, sinpif, (float x)) { return math::sinpif(x); }
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 554873637d882..0c1f8a81158d4 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -69,7 +69,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::exp2m1f(0.0f));
   EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::expf(0.0f));
   EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::exp2f(0.0f));
-  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::expm1f(0.0f));  
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::expm1f(0.0f));
   EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::hypotf(0.0f, 0.0f));
   EXPECT_FP_EQ_ALL_ROUNDING(0.75f,
                             LIBC_NAMESPACE::shared::frexpf(24.0f, &exponent));

>From 872865b4bf857de74efc008c01f73c3a2d6240d8 Mon Sep 17 00:00:00 2001
From: DannyDaoBoYang <34634047+DannyDaoBoYang at users.noreply.github.com>
Date: Sat, 17 Jan 2026 23:33:52 -0500
Subject: [PATCH 6/8] Buidifier

---
 utils/bazel/llvm-project-overlay/clang/BUILD.bazel | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
index 9d698d48f595d..b9f022207da65 100644
--- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -1807,8 +1807,8 @@ cc_library(
         "//llvm:AllTargetsAsmParsers",
         "//llvm:AllTargetsCodeGens",
         "//llvm:Core",
-        "//llvm:JITLink",
         "//llvm:ExecutionEngine",
+        "//llvm:JITLink",
         "//llvm:MC",
         "//llvm:Option",
         "//llvm:OrcDebugging",

>From a6af6796fbdf6121ff32de0b2fd261f34cf94cd7 Mon Sep 17 00:00:00 2001
From: DannyDaoBoYang <daobo.yang41 at gmail.com>
Date: Mon, 19 Jan 2026 12:07:10 -0500
Subject: [PATCH 7/8] Apply suggestions from code review

Co-authored-by: Muhammad Bassiouni <60100307+bassiounix at users.noreply.github.com>
---
 libc/shared/math/sinpif.h        | 2 +-
 libc/src/__support/math/sinpif.h | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/libc/shared/math/sinpif.h b/libc/shared/math/sinpif.h
index fb4a4c06258e0..c7dee419d9f1f 100644
--- a/libc/shared/math/sinpif.h
+++ b/libc/shared/math/sinpif.h
@@ -20,4 +20,4 @@ using math::sinpif;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LLVM_LIBC_SHARED_MATH_SINPIF_H
\ No newline at end of file
+#endif // LLVM_LIBC_SHARED_MATH_SINPIF_H
diff --git a/libc/src/__support/math/sinpif.h b/libc/src/__support/math/sinpif.h
index a44779c3befa9..64164ca9764c7 100644
--- a/libc/src/__support/math/sinpif.h
+++ b/libc/src/__support/math/sinpif.h
@@ -16,10 +16,11 @@
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
-#include "src/__support/math/sincosf_utils.h"
+#include "sincosf_utils.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
+
 LIBC_INLINE static constexpr float sinpif(float x) {
   using FPBits = typename fputil::FPBits<float>;
   FPBits xbits(x);
@@ -115,6 +116,8 @@ LIBC_INLINE static constexpr float sinpif(float x) {
   return static_cast<float>(fputil::multiply_add(
       sin_y, cos_k, fputil::multiply_add(cosm1_y, sin_k, sin_k)));
 }
+
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
+
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINPIF_H

>From 98319491c4037b223f790e57bfd876927530ef38 Mon Sep 17 00:00:00 2001
From: DannyDaoBoYang <daobo.yang41 at gmail.com>
Date: Mon, 19 Jan 2026 12:07:40 -0500
Subject: [PATCH 8/8] Update libc/src/__support/math/CMakeLists.txt

Co-authored-by: Muhammad Bassiouni <60100307+bassiounix at users.noreply.github.com>
---
 libc/src/__support/math/CMakeLists.txt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 4e412fe287a30..8237e3cfa8fef 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1091,7 +1091,6 @@ add_header_library(
   HDRS
     sinpif.h
   DEPENDS
-
     libc.src.__support.FPUtil.FEnvImpl
     libc.src.__support.FPUtil.FPBits
     libc.src.__support.FPUtil.PolyEval



More information about the libc-commits mailing list