[libc-commits] [libc] [libc] Address size bloat issues (PR #179398)

Prabhu Rajasekaran via libc-commits libc-commits at lists.llvm.org
Mon Feb 2 21:51:53 PST 2026


https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/179398

This refactoring addresses bloat by removing static function specifiers
and anonymous namespaces.


>From d85ebfe1fcc7dfa3ff3fca3e274835d0d2face5b Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Mon, 2 Feb 2026 21:47:15 -0800
Subject: [PATCH] [libc] Address size bloat issues

This refactoring addresses bloat by removing static function specifiers
and anonymous namespaces.
---
 libc/src/__support/ctype_utils.h              | 28 +++++++--------
 libc/src/__support/math/atan2.h               |  2 +-
 libc/src/__support/math/common_constants.h    | 34 +++++++++----------
 libc/src/__support/math/cos.h                 |  2 +-
 .../math/range_reduction_double_common.h      |  4 +--
 libc/src/__support/math/sin.h                 |  2 +-
 libc/src/math/generic/pow.cpp                 |  5 ---
 7 files changed, 35 insertions(+), 42 deletions(-)

diff --git a/libc/src/__support/ctype_utils.h b/libc/src/__support/ctype_utils.h
index d60562c02e81c..515eca18f9e4c 100644
--- a/libc/src/__support/ctype_utils.h
+++ b/libc/src/__support/ctype_utils.h
@@ -37,7 +37,7 @@ namespace internal {
 // EBCDIC. Technically we could use some smaller ranges, but that's even harder
 // to read.
 
-LIBC_INLINE static constexpr bool islower(char ch) {
+LIBC_INLINE constexpr bool islower(char ch) {
   switch (ch) {
   case 'a':
   case 'b':
@@ -71,7 +71,7 @@ LIBC_INLINE static constexpr bool islower(char ch) {
   }
 }
 
-LIBC_INLINE static constexpr bool isupper(char ch) {
+LIBC_INLINE constexpr bool isupper(char ch) {
   switch (ch) {
   case 'A':
   case 'B':
@@ -105,7 +105,7 @@ LIBC_INLINE static constexpr bool isupper(char ch) {
   }
 }
 
-LIBC_INLINE static constexpr bool isdigit(char ch) {
+LIBC_INLINE constexpr bool isdigit(char ch) {
   switch (ch) {
   case '0':
   case '1':
@@ -123,7 +123,7 @@ LIBC_INLINE static constexpr bool isdigit(char ch) {
   }
 }
 
-LIBC_INLINE static constexpr char tolower(char ch) {
+LIBC_INLINE constexpr char tolower(char ch) {
   switch (ch) {
   case 'A':
     return 'a';
@@ -182,7 +182,7 @@ LIBC_INLINE static constexpr char tolower(char ch) {
   }
 }
 
-LIBC_INLINE static constexpr char toupper(char ch) {
+LIBC_INLINE constexpr char toupper(char ch) {
   switch (ch) {
   case 'a':
     return 'A';
@@ -241,7 +241,7 @@ LIBC_INLINE static constexpr char toupper(char ch) {
   }
 }
 
-LIBC_INLINE static constexpr bool isalpha(char ch) {
+LIBC_INLINE constexpr bool isalpha(char ch) {
   switch (ch) {
   case 'a':
   case 'b':
@@ -301,7 +301,7 @@ LIBC_INLINE static constexpr bool isalpha(char ch) {
   }
 }
 
-LIBC_INLINE static constexpr bool isalnum(char ch) {
+LIBC_INLINE constexpr bool isalnum(char ch) {
   switch (ch) {
   case 'a':
   case 'b':
@@ -371,7 +371,7 @@ LIBC_INLINE static constexpr bool isalnum(char ch) {
   }
 }
 
-LIBC_INLINE static constexpr int b36_char_to_int(char ch) {
+LIBC_INLINE constexpr int b36_char_to_int(char ch) {
   switch (ch) {
   case '0':
     return 0;
@@ -476,7 +476,7 @@ LIBC_INLINE static constexpr int b36_char_to_int(char ch) {
   }
 }
 
-LIBC_INLINE static constexpr char int_to_b36_char(int num) {
+LIBC_INLINE constexpr char int_to_b36_char(int num) {
   // Can't actually use LIBC_ASSERT here because it depends on integer_to_string
   // which depends on this.
 
@@ -559,7 +559,7 @@ LIBC_INLINE static constexpr char int_to_b36_char(int num) {
   }
 }
 
-LIBC_INLINE static constexpr bool isspace(char ch) {
+LIBC_INLINE constexpr bool isspace(char ch) {
   switch (ch) {
   case ' ':
   case '\t':
@@ -574,14 +574,12 @@ LIBC_INLINE static constexpr bool isspace(char ch) {
 }
 
 // not yet encoding independent.
-LIBC_INLINE static constexpr bool isgraph(char ch) {
-  return 0x20 < ch && ch < 0x7f;
-}
+LIBC_INLINE constexpr bool isgraph(char ch) { return 0x20 < ch && ch < 0x7f; }
 
 // An overload which provides a way to compare input with specific character
 // values, when input can be of a regular or a wide character type.
-LIBC_INLINE static constexpr bool is_char_or_wchar(char ch, char c_value,
-                                                   [[maybe_unused]] wchar_t) {
+LIBC_INLINE constexpr bool is_char_or_wchar(char ch, char c_value,
+                                            [[maybe_unused]] wchar_t) {
   return (ch == c_value);
 }
 
diff --git a/libc/src/__support/math/atan2.h b/libc/src/__support/math/atan2.h
index 90ed926c8d75f..f59d92b6dc19c 100644
--- a/libc/src/__support/math/atan2.h
+++ b/libc/src/__support/math/atan2.h
@@ -75,7 +75,7 @@ namespace math {
 // and relative errors bounded by:
 //   |(atan(u) - P(u)) / P(u)| < u^10 / 11 < 2^-73.
 
-LIBC_INLINE static constexpr double atan2(double y, double x) {
+LIBC_INLINE constexpr double atan2(double y, double x) {
   using namespace atan_internal;
   using FPBits = fputil::FPBits<double>;
 
diff --git a/libc/src/__support/math/common_constants.h b/libc/src/__support/math/common_constants.h
index 53abbfeef3412..4548cd506bb99 100644
--- a/libc/src/__support/math/common_constants.h
+++ b/libc/src/__support/math/common_constants.h
@@ -19,15 +19,15 @@ namespace common_constants_internal {
 // log(2) generated by Sollya with:
 // > a = 2^-43 * nearestint(2^43*log(2));
 // LSB = 2^-43 is chosen so that e_x * LOG_2_HI is exact for -1075 < e_x < 1024.
-static constexpr double LOG_2_HI = 0x1.62e42fefa38p-1; // LSB = 2^-43
+LIBC_INLINE_VAR constexpr double LOG_2_HI = 0x1.62e42fefa38p-1; // LSB = 2^-43
 // > b = round(log10(2) - a, D, RN);
-static constexpr double LOG_2_LO = 0x1.ef35793c7673p-45; // LSB = 2^-97
+LIBC_INLINE_VAR constexpr double LOG_2_LO = 0x1.ef35793c7673p-45; // LSB = 2^-97
 
 // Minimax polynomial for (log(1 + x) - x)/x^2, generated by sollya with:
 // > P = fpminimax((log(1 + x) - x)/x^2, 5, [|D...|], [-2^-8, 2^-7]);
-constexpr double LOG_COEFFS[6] = {-0x1.fffffffffffffp-2, 0x1.5555555554a9bp-2,
-                                  -0x1.0000000094567p-2, 0x1.99999dcc9823cp-3,
-                                  -0x1.55550ac2e537ap-3, 0x1.21a02c4e624d7p-3};
+LIBC_INLINE_VAR constexpr double LOG_COEFFS[6] = {
+    -0x1.fffffffffffffp-2, 0x1.5555555554a9bp-2,  -0x1.0000000094567p-2,
+    0x1.99999dcc9823cp-3,  -0x1.55550ac2e537ap-3, 0x1.21a02c4e624d7p-3};
 
 // Range reduction constants for logarithms.
 // r(0) = 1, r(127) = 0.5
@@ -36,7 +36,7 @@ constexpr double LOG_COEFFS[6] = {-0x1.fffffffffffffp-2, 0x1.5555555554a9bp-2,
 // precision, and -2^-8 <= v < 2^-7.
 // TODO(lntue): Add reference to how the constants are derived after the
 // resulting paper is ready.
-alignas(8) static constexpr float R[128] = {
+alignas(8) LIBC_INLINE_VAR constexpr float R[128] = {
     0x1p0,     0x1.fcp-1, 0x1.f8p-1, 0x1.f4p-1, 0x1.fp-1,  0x1.ecp-1, 0x1.e8p-1,
     0x1.e4p-1, 0x1.ep-1,  0x1.dep-1, 0x1.dap-1, 0x1.d6p-1, 0x1.d4p-1, 0x1.dp-1,
     0x1.ccp-1, 0x1.cap-1, 0x1.c6p-1, 0x1.c4p-1, 0x1.cp-1,  0x1.bep-1, 0x1.bap-1,
@@ -57,7 +57,7 @@ alignas(8) static constexpr float R[128] = {
     0x1.0ap-1, 0x1.08p-1, 0x1.08p-1, 0x1.06p-1, 0x1.06p-1, 0x1.04p-1, 0x1.04p-1,
     0x1.02p-1, 0x1.0p-1};
 
-static constexpr double RD[128] = {
+LIBC_INLINE_VAR constexpr double RD[128] = {
     0x1p0,     0x1.fcp-1, 0x1.f8p-1, 0x1.f4p-1, 0x1.fp-1,  0x1.ecp-1, 0x1.e8p-1,
     0x1.e4p-1, 0x1.ep-1,  0x1.dep-1, 0x1.dap-1, 0x1.d6p-1, 0x1.d4p-1, 0x1.dp-1,
     0x1.ccp-1, 0x1.cap-1, 0x1.c6p-1, 0x1.c4p-1, 0x1.cp-1,  0x1.bep-1, 0x1.bap-1,
@@ -82,7 +82,7 @@ static constexpr double RD[128] = {
 // available.
 // Generated by Sollya with the formula: CD[i] = RD[i]*(1 + i*2^-7) - 1
 // for RD[i] defined on the table above.
-static constexpr double CD[128] = {
+LIBC_INLINE_VAR constexpr double CD[128] = {
     0.0,        -0x1p-14,   -0x1p-12,   -0x1.2p-11,  -0x1p-10,   -0x1.9p-10,
     -0x1.2p-9,  -0x1.88p-9, -0x1p-8,    -0x1.9p-11,  -0x1.fp-10, -0x1.9cp-9,
     -0x1p-12,   -0x1.cp-10, -0x1.bp-9,  -0x1.5p-11,  -0x1.4p-9,  0x1p-14,
@@ -107,7 +107,7 @@ static constexpr double CD[128] = {
     -0x1p-14,   -0x1p-8,
 };
 
-static constexpr double LOG_R[128] = {
+LIBC_INLINE_VAR constexpr double LOG_R[128] = {
     0x0.0000000000000p0,  0x1.010157588de71p-7, 0x1.0205658935847p-6,
     0x1.8492528c8cabfp-6, 0x1.0415d89e74444p-5, 0x1.466aed42de3eap-5,
     0x1.894aa149fb343p-5, 0x1.ccb73cdddb2ccp-5, 0x1.08598b59e3a07p-4,
@@ -152,7 +152,7 @@ static constexpr double LOG_R[128] = {
     0x1.5707a26bb8c66p-1, 0x1.5af405c3649ep-1,  0x1.5af405c3649ep-1,
     0x1.5ee82aa24192p-1,  0x0.000000000000p0};
 
-static constexpr double LOG2_R[128] = {
+LIBC_INLINE_VAR constexpr double LOG2_R[128] = {
     0x0.0000000000000p+0, 0x1.72c7ba20f7327p-7, 0x1.743ee861f3556p-6,
     0x1.184b8e4c56af8p-5, 0x1.77394c9d958d5p-5, 0x1.d6ebd1f1febfep-5,
     0x1.1bb32a600549dp-4, 0x1.4c560fe68af88p-4, 0x1.7d60496cfbb4cp-4,
@@ -205,7 +205,7 @@ static constexpr double LOG2_R[128] = {
 //     print("{", -c, ",", -b, "},");
 //   };
 // We replace LOG_R[0] with log10(1.0) == 0.0
-alignas(16) static constexpr NumberPair<double> LOG_R_DD[128] = {
+alignas(16) LIBC_INLINE_VAR constexpr NumberPair<double> LOG_R_DD[128] = {
     {0.0, 0.0},
     {-0x1.0c76b999d2be8p-46, 0x1.010157589p-7},
     {-0x1.3dc5b06e2f7d2p-45, 0x1.0205658938p-6},
@@ -341,7 +341,7 @@ alignas(16) static constexpr NumberPair<double> LOG_R_DD[128] = {
 // Output range:
 //   [-0x1.3ffcp-15, 0x1.3e3dp-15]
 // We store S2[i] = 2^16 (r(i - 2^6) - 1).
-alignas(8) static constexpr int S2[193] = {
+alignas(8) LIBC_INLINE_VAR constexpr int S2[193] = {
     0x101,  0xfd,   0xf9,   0xf5,   0xf1,   0xed,   0xe9,   0xe5,   0xe1,
     0xdd,   0xd9,   0xd5,   0xd1,   0xcd,   0xc9,   0xc5,   0xc1,   0xbd,
     0xb9,   0xb4,   0xb0,   0xac,   0xa8,   0xa4,   0xa0,   0x9c,   0x98,
@@ -365,7 +365,7 @@ alignas(8) static constexpr int S2[193] = {
     -0x1cd, -0x1d1, -0x1d5, -0x1d9, -0x1dd, -0x1e0, -0x1e4, -0x1e8, -0x1ec,
     -0x1f0, -0x1f4, -0x1f8, -0x1fc};
 
-static constexpr double R2[193] = {
+LIBC_INLINE_VAR constexpr double R2[193] = {
     0x1.0101p0,  0x1.00fdp0,  0x1.00f9p0,  0x1.00f5p0,  0x1.00f1p0,
     0x1.00edp0,  0x1.00e9p0,  0x1.00e5p0,  0x1.00e1p0,  0x1.00ddp0,
     0x1.00d9p0,  0x1.00d5p0,  0x1.00d1p0,  0x1.00cdp0,  0x1.00c9p0,
@@ -412,7 +412,7 @@ static constexpr double R2[193] = {
 // Output range:
 //   [-0x1.01928p-22 , 0x1p-22]
 // We store S[i] = 2^21 (r(i - 80) - 1).
-alignas(8) static constexpr int S3[161] = {
+alignas(8) LIBC_INLINE_VAR constexpr int S3[161] = {
     0x50,  0x4f,  0x4e,  0x4d,  0x4c,  0x4b,  0x4a,  0x49,  0x48,  0x47,  0x46,
     0x45,  0x44,  0x43,  0x42,  0x41,  0x40,  0x3f,  0x3e,  0x3d,  0x3c,  0x3b,
     0x3a,  0x39,  0x38,  0x37,  0x36,  0x35,  0x34,  0x33,  0x32,  0x31,  0x30,
@@ -435,7 +435,7 @@ alignas(8) static constexpr int S3[161] = {
 // Output range:
 //   [-0x1.0002143p-29 , 0x1p-29]
 // We store S[i] = 2^28 (r(i - 65) - 1).
-alignas(8) static constexpr int S4[130] = {
+alignas(8) LIBC_INLINE_VAR constexpr int S4[130] = {
     0x41,  0x40,  0x3f,  0x3e,  0x3d,  0x3c,  0x3b,  0x3a,  0x39,  0x38,  0x37,
     0x36,  0x35,  0x34,  0x33,  0x32,  0x31,  0x30,  0x2f,  0x2e,  0x2d,  0x2c,
     0x2b,  0x2a,  0x29,  0x28,  0x27,  0x26,  0x25,  0x24,  0x23,  0x22,  0x21,
@@ -456,7 +456,7 @@ alignas(8) static constexpr int S4[130] = {
 // Table is generated with Sollya as follow:
 // > display = hexadecimal;
 // > for i from -104 to 89 do { D(exp(i)); };
-static constexpr double EXP_M1[195] = {
+LIBC_INLINE_VAR constexpr double EXP_M1[195] = {
     0x1.f1e6b68529e33p-151, 0x1.525be4e4e601dp-149, 0x1.cbe0a45f75eb1p-148,
     0x1.3884e838aea68p-146, 0x1.a8c1f14e2af5dp-145, 0x1.20a717e64a9bdp-143,
     0x1.8851d84118908p-142, 0x1.0a9bdfb02d240p-140, 0x1.6a5bea046b42ep-139,
@@ -528,7 +528,7 @@ static constexpr double EXP_M1[195] = {
 // Table is generated with Sollya as follow:
 // > display = hexadecimal;
 // > for i from 0 to 127 do { D(exp(i / 128)); };
-static constexpr double EXP_M2[128] = {
+LIBC_INLINE_VAR constexpr double EXP_M2[128] = {
     0x1.0000000000000p0, 0x1.0202015600446p0, 0x1.04080ab55de39p0,
     0x1.06122436410ddp0, 0x1.08205601127edp0, 0x1.0a32a84e9c1f6p0,
     0x1.0c49236829e8cp0, 0x1.0e63cfa7ab09dp0, 0x1.1082b577d34edp0,
diff --git a/libc/src/__support/math/cos.h b/libc/src/__support/math/cos.h
index cd4abc2864324..1a7833978304a 100644
--- a/libc/src/__support/math/cos.h
+++ b/libc/src/__support/math/cos.h
@@ -30,7 +30,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE static constexpr double cos(double x) {
+LIBC_INLINE constexpr double cos(double x) {
   using namespace range_reduction_double_internal;
   using DoubleDouble = fputil::DoubleDouble;
   using FPBits = typename fputil::FPBits<double>;
diff --git a/libc/src/__support/math/range_reduction_double_common.h b/libc/src/__support/math/range_reduction_double_common.h
index a12c25da4fdd0..5dda3f9ec43ea 100644
--- a/libc/src/__support/math/range_reduction_double_common.h
+++ b/libc/src/__support/math/range_reduction_double_common.h
@@ -97,7 +97,7 @@ LIBC_INLINE static unsigned range_reduction_small(double x, DoubleDouble &u) {
 // and one of those conditions guarantees that ulp(0.25 * x_reduced) >= 2, and
 // will safely be discarded.
 
-static constexpr double ONE_TWENTY_EIGHT_OVER_PI[64][4] = {
+LIBC_INLINE_VAR constexpr double ONE_TWENTY_EIGHT_OVER_PI[64][4] = {
     {0x1.0000000000014p5, 0x1.7cc1b727220a8p-49, 0x1.4fe13abe8fa9cp-101,
      -0x1.911f924eb5336p-153},
     {0x1.0000000145f3p5, 0x1.b727220a94fep-49, 0x1.3abe8fa9a6eep-101,
@@ -306,7 +306,7 @@ LIBC_INLINE static Float128 range_reduction_small_f128(double x) {
   return fputil::quick_mul(y, PI_OVER_128_F128);
 }
 
-static constexpr Float128 SIN_K_PI_OVER_128_F128[65] = {
+LIBC_INLINE_VAR constexpr Float128 SIN_K_PI_OVER_128_F128[65] = {
     {Sign::POS, 0, 0},
     {Sign::POS, -133, 0xc90a'afbd'1b33'efc9'c539'edcb'fda0'cf2c_u128},
     {Sign::POS, -132, 0xc8fb'2f88'6ec0'9f37'6a17'954b'2b7c'5171_u128},
diff --git a/libc/src/__support/math/sin.h b/libc/src/__support/math/sin.h
index 3a67af08b2b80..124df61b1dc80 100644
--- a/libc/src/__support/math/sin.h
+++ b/libc/src/__support/math/sin.h
@@ -29,7 +29,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE static constexpr double sin(double x) {
+LIBC_INLINE constexpr double sin(double x) {
   using namespace math::range_reduction_double_internal;
   using FPBits = typename fputil::FPBits<double>;
   FPBits xbits(x);
diff --git a/libc/src/math/generic/pow.cpp b/libc/src/math/generic/pow.cpp
index c9f685b82fcb5..4d06ae7cf9bf7 100644
--- a/libc/src/math/generic/pow.cpp
+++ b/libc/src/math/generic/pow.cpp
@@ -26,9 +26,6 @@
 namespace LIBC_NAMESPACE_DECL {
 
 using fputil::DoubleDouble;
-
-namespace {
-
 using namespace common_constants_internal;
 
 // Constants for log2(x) range reduction, generated by Sollya with:
@@ -197,8 +194,6 @@ bool is_integer(double x) {
   return (x_e + lsb >= UNIT_EXPONENT);
 }
 
-} // namespace
-
 LLVM_LIBC_FUNCTION(double, pow, (double x, double y)) {
   using FPBits = fputil::FPBits<double>;
 



More information about the libc-commits mailing list