[libc-commits] [libc] adaa3e7 - [libc] Address sincosf size bloat (#179004)

via libc-commits libc-commits at lists.llvm.org
Sun Feb 1 10:37:33 PST 2026


Author: Prabhu Rajasekaran
Date: 2026-02-01T10:37:29-08:00
New Revision: adaa3e74e808c2a729a28e444a67258267c8106e

URL: https://github.com/llvm/llvm-project/commit/adaa3e74e808c2a729a28e444a67258267c8106e
DIFF: https://github.com/llvm/llvm-project/commit/adaa3e74e808c2a729a28e444a67258267c8106e.diff

LOG: [libc] Address sincosf size bloat (#179004)

The recent refactoring in #177523 marked some functions as static which
increased the size of sinf/cosf functions. Removing the static storage
for these functions to remove the bloat which is especially problematic
in size constrained baremetal target builds.

Added: 
    

Modified: 
    libc/src/__support/math/sincosf.h
    libc/src/__support/math/sincosf_float_eval.h
    libc/src/__support/math/sincosf_utils.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/math/sincosf.h b/libc/src/__support/math/sincosf.h
index 46a2948340b01..b6b6ffeb7e6b0 100644
--- a/libc/src/__support/math/sincosf.h
+++ b/libc/src/__support/math/sincosf.h
@@ -58,7 +58,7 @@ LIBC_INLINE_VAR constexpr uint32_t EXCEPT_OUTPUTS_COS[N_EXCEPTS][4] = {
 #endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 } // namespace sincosf_internal
 
-LIBC_INLINE static void sincosf(float x, float *sinp, float *cosp) {
+LIBC_INLINE void sincosf(float x, float *sinp, float *cosp) {
   using namespace sincosf_internal;
   using FPBits = typename fputil::FPBits<float>;
   FPBits xbits(x);

diff  --git a/libc/src/__support/math/sincosf_float_eval.h b/libc/src/__support/math/sincosf_float_eval.h
index 836e928bc8675..195ce373c0f07 100644
--- a/libc/src/__support/math/sincosf_float_eval.h
+++ b/libc/src/__support/math/sincosf_float_eval.h
@@ -41,7 +41,7 @@ namespace sincosf_float_eval {
 //   p_k <= 7.
 // We set the bound for p_k to be 6 so that we can have some more wiggle room
 // for computations.
-LIBC_INLINE static unsigned sincosf_range_reduction_small(float x, float &u) {
+LIBC_INLINE unsigned sincosf_range_reduction_small(float x, float &u) {
   // > display=hexadecimal;
   // > a = round(pi/8, 18, RN);
   // > b = round(pi/8 - a, 18, RN);
@@ -59,7 +59,7 @@ LIBC_INLINE static unsigned sincosf_range_reduction_small(float x, float &u) {
 }
 
 // TODO: Add non-FMA version of large range reduction.
-LIBC_INLINE static unsigned sincosf_range_reduction_large(float x, float &u) {
+LIBC_INLINE unsigned sincosf_range_reduction_large(float x, float &u) {
   // > for i from 0 to 13 do {
   //     if i < 2 then { pi_inv = 0.25 + 2^(8*(i - 2)) / pi; }
   //     else { pi_inv = 2^(8*(i-2)) / pi; };
@@ -133,7 +133,7 @@ LIBC_INLINE static unsigned sincosf_range_reduction_large(float x, float &u) {
   return static_cast<unsigned>(static_cast<int>(k));
 }
 
-template <bool IS_SIN> LIBC_INLINE static float sincosf_eval(float x) {
+template <bool IS_SIN> LIBC_INLINE float sincosf_eval(float x) {
   // sin(k * pi/8) for k = 0..15, generated by Sollya with:
   // > for k from 0 to 16 do {
   //     print(round(sin(k * pi/8), SG, RN));

diff  --git a/libc/src/__support/math/sincosf_utils.h b/libc/src/__support/math/sincosf_utils.h
index 265998fb0ec7a..b13a39999866d 100644
--- a/libc/src/__support/math/sincosf_utils.h
+++ b/libc/src/__support/math/sincosf_utils.h
@@ -60,9 +60,9 @@ LIBC_INLINE_VAR const double SIN_K_PI_OVER_32[64] = {
     -0x1.917a6bc29b42cp-4,
 };
 
-static LIBC_INLINE void sincosf_poly_eval(int64_t k, double y, double &sin_k,
-                                          double &cos_k, double &sin_y,
-                                          double &cosm1_y) {
+LIBC_INLINE void sincosf_poly_eval(int64_t k, double y, double &sin_k,
+                                   double &cos_k, double &sin_y,
+                                   double &cosm1_y) {
   // After range reduction, k = round(x * 32 / pi) and y = (x * 32 / pi) - k.
   // So k is an integer and -0.5 <= y <= 0.5.
   // Then sin(x) = sin((k + y)*pi/32)
@@ -88,9 +88,8 @@ static LIBC_INLINE void sincosf_poly_eval(int64_t k, double y, double &sin_k,
                                    0x1.03c1f070c2e27p-18, -0x1.55cc84bd942p-30);
 }
 
-LIBC_INLINE static void sincosf_eval(double xd, uint32_t x_abs, double &sin_k,
-                                     double &cos_k, double &sin_y,
-                                     double &cosm1_y) {
+LIBC_INLINE void sincosf_eval(double xd, uint32_t x_abs, double &sin_k,
+                              double &cos_k, double &sin_y, double &cosm1_y) {
   int64_t k;
   double y;
 
@@ -107,15 +106,15 @@ LIBC_INLINE static void sincosf_eval(double xd, uint32_t x_abs, double &sin_k,
 // Return k and y, where
 //   k = round(x * 32) and y = (x * 32) - k.
 //   => pi * x = (k + y) * pi / 32
-static LIBC_INLINE int64_t range_reduction_sincospi(double x, double &y) {
+LIBC_INLINE int64_t range_reduction_sincospi(double x, double &y) {
   double kd = fputil::nearest_integer(x * 32);
   y = fputil::multiply_add(x, 32.0, -kd);
 
   return static_cast<int64_t>(kd);
 }
 
-LIBC_INLINE static void sincospif_eval(double xd, double &sin_k, double &cos_k,
-                                       double &sin_y, double &cosm1_y) {
+LIBC_INLINE void sincospif_eval(double xd, double &sin_k, double &cos_k,
+                                double &sin_y, double &cosm1_y) {
   double y;
   int64_t k = range_reduction_sincospi(xd, y);
   sincosf_poly_eval(k, y, sin_k, cos_k, sin_y, cosm1_y);


        


More information about the libc-commits mailing list