[libc-commits] [libc] [libc] Address sincosf size bloat (PR #179004)
Prabhu Rajasekaran via libc-commits
libc-commits at lists.llvm.org
Fri Jan 30 21:15:00 PST 2026
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/179004
>From 8afde420c8a9ccc907782c30d7e1634e846ebd5a Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Fri, 30 Jan 2026 21:13:16 -0800
Subject: [PATCH] [libc] Address sincosf size bloat
The recent refactoring in #177523 marked SIN_K_PI_OVER_32 as inline
which bloated sinf and cosf functions in size. This was breaking our
baremetal builds which are severely size constrained. Removing static
storage added in the above change which caused the bloat.
---
libc/src/__support/math/sincosf.h | 2 +-
libc/src/__support/math/sincosf_float_eval.h | 6 +++---
libc/src/__support/math/sincosf_utils.h | 8 ++++----
3 files changed, 8 insertions(+), 8 deletions(-)
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..f5514bba0351f 100644
--- a/libc/src/__support/math/sincosf_utils.h
+++ b/libc/src/__support/math/sincosf_utils.h
@@ -60,7 +60,7 @@ 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,
+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.
@@ -88,7 +88,7 @@ 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,
+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;
@@ -107,14 +107,14 @@ 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,
+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);
More information about the libc-commits
mailing list