Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 22c8344

Browse files
authored
[libc] Address size bloat issues (#179398)
This refactoring addresses bloat by removing static function specifiers.
1 parent 792f7b0 commit 22c8344

6 files changed

Lines changed: 35 additions & 37 deletions

File tree

libc/src/__support/ctype_utils.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace internal {
3737
// EBCDIC. Technically we could use some smaller ranges, but that's even harder
3838
// to read.
3939

40-
LIBC_INLINE static constexpr bool islower(char ch) {
40+
LIBC_INLINE constexpr bool islower(char ch) {
4141
switch (ch) {
4242
case 'a':
4343
case 'b':
@@ -71,7 +71,7 @@ LIBC_INLINE static constexpr bool islower(char ch) {
7171
}
7272
}
7373

74-
LIBC_INLINE static constexpr bool isupper(char ch) {
74+
LIBC_INLINE constexpr bool isupper(char ch) {
7575
switch (ch) {
7676
case 'A':
7777
case 'B':
@@ -105,7 +105,7 @@ LIBC_INLINE static constexpr bool isupper(char ch) {
105105
}
106106
}
107107

108-
LIBC_INLINE static constexpr bool isdigit(char ch) {
108+
LIBC_INLINE constexpr bool isdigit(char ch) {
109109
switch (ch) {
110110
case '0':
111111
case '1':
@@ -123,7 +123,7 @@ LIBC_INLINE static constexpr bool isdigit(char ch) {
123123
}
124124
}
125125

126-
LIBC_INLINE static constexpr char tolower(char ch) {
126+
LIBC_INLINE constexpr char tolower(char ch) {
127127
switch (ch) {
128128
case 'A':
129129
return 'a';
@@ -182,7 +182,7 @@ LIBC_INLINE static constexpr char tolower(char ch) {
182182
}
183183
}
184184

185-
LIBC_INLINE static constexpr char toupper(char ch) {
185+
LIBC_INLINE constexpr char toupper(char ch) {
186186
switch (ch) {
187187
case 'a':
188188
return 'A';
@@ -241,7 +241,7 @@ LIBC_INLINE static constexpr char toupper(char ch) {
241241
}
242242
}
243243

244-
LIBC_INLINE static constexpr bool isalpha(char ch) {
244+
LIBC_INLINE constexpr bool isalpha(char ch) {
245245
switch (ch) {
246246
case 'a':
247247
case 'b':
@@ -301,7 +301,7 @@ LIBC_INLINE static constexpr bool isalpha(char ch) {
301301
}
302302
}
303303

304-
LIBC_INLINE static constexpr bool isalnum(char ch) {
304+
LIBC_INLINE constexpr bool isalnum(char ch) {
305305
switch (ch) {
306306
case 'a':
307307
case 'b':
@@ -371,7 +371,7 @@ LIBC_INLINE static constexpr bool isalnum(char ch) {
371371
}
372372
}
373373

374-
LIBC_INLINE static constexpr int b36_char_to_int(char ch) {
374+
LIBC_INLINE constexpr int b36_char_to_int(char ch) {
375375
switch (ch) {
376376
case '0':
377377
return 0;
@@ -476,7 +476,7 @@ LIBC_INLINE static constexpr int b36_char_to_int(char ch) {
476476
}
477477
}
478478

479-
LIBC_INLINE static constexpr char int_to_b36_char(int num) {
479+
LIBC_INLINE constexpr char int_to_b36_char(int num) {
480480
// Can't actually use LIBC_ASSERT here because it depends on integer_to_string
481481
// which depends on this.
482482

@@ -559,7 +559,7 @@ LIBC_INLINE static constexpr char int_to_b36_char(int num) {
559559
}
560560
}
561561

562-
LIBC_INLINE static constexpr bool isspace(char ch) {
562+
LIBC_INLINE constexpr bool isspace(char ch) {
563563
switch (ch) {
564564
case ' ':
565565
case '\t':
@@ -574,14 +574,12 @@ LIBC_INLINE static constexpr bool isspace(char ch) {
574574
}
575575

576576
// not yet encoding independent.
577-
LIBC_INLINE static constexpr bool isgraph(char ch) {
578-
return 0x20 < ch && ch < 0x7f;
579-
}
577+
LIBC_INLINE constexpr bool isgraph(char ch) { return 0x20 < ch && ch < 0x7f; }
580578

581579
// An overload which provides a way to compare input with specific character
582580
// values, when input can be of a regular or a wide character type.
583-
LIBC_INLINE static constexpr bool is_char_or_wchar(char ch, char c_value,
584-
[[maybe_unused]] wchar_t) {
581+
LIBC_INLINE constexpr bool is_char_or_wchar(char ch, char c_value,
582+
[[maybe_unused]] wchar_t) {
585583
return (ch == c_value);
586584
}
587585

libc/src/__support/math/atan2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace math {
7575
// and relative errors bounded by:
7676
// |(atan(u) - P(u)) / P(u)| < u^10 / 11 < 2^-73.
7777

78-
LIBC_INLINE static constexpr double atan2(double y, double x) {
78+
LIBC_INLINE constexpr double atan2(double y, double x) {
7979
using namespace atan_internal;
8080
using FPBits = fputil::FPBits<double>;
8181

libc/src/__support/math/common_constants.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ namespace common_constants_internal {
1919
// log(2) generated by Sollya with:
2020
// > a = 2^-43 * nearestint(2^43*log(2));
2121
// LSB = 2^-43 is chosen so that e_x * LOG_2_HI is exact for -1075 < e_x < 1024.
22-
static constexpr double LOG_2_HI = 0x1.62e42fefa38p-1; // LSB = 2^-43
22+
LIBC_INLINE_VAR constexpr double LOG_2_HI = 0x1.62e42fefa38p-1; // LSB = 2^-43
2323
// > b = round(log10(2) - a, D, RN);
24-
static constexpr double LOG_2_LO = 0x1.ef35793c7673p-45; // LSB = 2^-97
24+
LIBC_INLINE_VAR constexpr double LOG_2_LO = 0x1.ef35793c7673p-45; // LSB = 2^-97
2525

2626
// Minimax polynomial for (log(1 + x) - x)/x^2, generated by sollya with:
2727
// > P = fpminimax((log(1 + x) - x)/x^2, 5, [|D...|], [-2^-8, 2^-7]);
28-
constexpr double LOG_COEFFS[6] = {-0x1.fffffffffffffp-2, 0x1.5555555554a9bp-2,
29-
-0x1.0000000094567p-2, 0x1.99999dcc9823cp-3,
30-
-0x1.55550ac2e537ap-3, 0x1.21a02c4e624d7p-3};
28+
LIBC_INLINE_VAR constexpr double LOG_COEFFS[6] = {
29+
-0x1.fffffffffffffp-2, 0x1.5555555554a9bp-2, -0x1.0000000094567p-2,
30+
0x1.99999dcc9823cp-3, -0x1.55550ac2e537ap-3, 0x1.21a02c4e624d7p-3};
3131

3232
// Range reduction constants for logarithms.
3333
// r(0) = 1, r(127) = 0.5
@@ -36,7 +36,7 @@ constexpr double LOG_COEFFS[6] = {-0x1.fffffffffffffp-2, 0x1.5555555554a9bp-2,
3636
// precision, and -2^-8 <= v < 2^-7.
3737
// TODO(lntue): Add reference to how the constants are derived after the
3838
// resulting paper is ready.
39-
alignas(8) static constexpr float R[128] = {
39+
alignas(8) LIBC_INLINE_VAR constexpr float R[128] = {
4040
0x1p0, 0x1.fcp-1, 0x1.f8p-1, 0x1.f4p-1, 0x1.fp-1, 0x1.ecp-1, 0x1.e8p-1,
4141
0x1.e4p-1, 0x1.ep-1, 0x1.dep-1, 0x1.dap-1, 0x1.d6p-1, 0x1.d4p-1, 0x1.dp-1,
4242
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] = {
5757
0x1.0ap-1, 0x1.08p-1, 0x1.08p-1, 0x1.06p-1, 0x1.06p-1, 0x1.04p-1, 0x1.04p-1,
5858
0x1.02p-1, 0x1.0p-1};
5959

60-
static constexpr double RD[128] = {
60+
LIBC_INLINE_VAR constexpr double RD[128] = {
6161
0x1p0, 0x1.fcp-1, 0x1.f8p-1, 0x1.f4p-1, 0x1.fp-1, 0x1.ecp-1, 0x1.e8p-1,
6262
0x1.e4p-1, 0x1.ep-1, 0x1.dep-1, 0x1.dap-1, 0x1.d6p-1, 0x1.d4p-1, 0x1.dp-1,
6363
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] = {
8282
// available.
8383
// Generated by Sollya with the formula: CD[i] = RD[i]*(1 + i*2^-7) - 1
8484
// for RD[i] defined on the table above.
85-
static constexpr double CD[128] = {
85+
LIBC_INLINE_VAR constexpr double CD[128] = {
8686
0.0, -0x1p-14, -0x1p-12, -0x1.2p-11, -0x1p-10, -0x1.9p-10,
8787
-0x1.2p-9, -0x1.88p-9, -0x1p-8, -0x1.9p-11, -0x1.fp-10, -0x1.9cp-9,
8888
-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] = {
107107
-0x1p-14, -0x1p-8,
108108
};
109109

110-
static constexpr double LOG_R[128] = {
110+
LIBC_INLINE_VAR constexpr double LOG_R[128] = {
111111
0x0.0000000000000p0, 0x1.010157588de71p-7, 0x1.0205658935847p-6,
112112
0x1.8492528c8cabfp-6, 0x1.0415d89e74444p-5, 0x1.466aed42de3eap-5,
113113
0x1.894aa149fb343p-5, 0x1.ccb73cdddb2ccp-5, 0x1.08598b59e3a07p-4,
@@ -152,7 +152,7 @@ static constexpr double LOG_R[128] = {
152152
0x1.5707a26bb8c66p-1, 0x1.5af405c3649ep-1, 0x1.5af405c3649ep-1,
153153
0x1.5ee82aa24192p-1, 0x0.000000000000p0};
154154

155-
static constexpr double LOG2_R[128] = {
155+
LIBC_INLINE_VAR constexpr double LOG2_R[128] = {
156156
0x0.0000000000000p+0, 0x1.72c7ba20f7327p-7, 0x1.743ee861f3556p-6,
157157
0x1.184b8e4c56af8p-5, 0x1.77394c9d958d5p-5, 0x1.d6ebd1f1febfep-5,
158158
0x1.1bb32a600549dp-4, 0x1.4c560fe68af88p-4, 0x1.7d60496cfbb4cp-4,
@@ -205,7 +205,7 @@ static constexpr double LOG2_R[128] = {
205205
// print("{", -c, ",", -b, "},");
206206
// };
207207
// We replace LOG_R[0] with log10(1.0) == 0.0
208-
alignas(16) static constexpr NumberPair<double> LOG_R_DD[128] = {
208+
alignas(16) LIBC_INLINE_VAR constexpr NumberPair<double> LOG_R_DD[128] = {
209209
{0.0, 0.0},
210210
{-0x1.0c76b999d2be8p-46, 0x1.010157589p-7},
211211
{-0x1.3dc5b06e2f7d2p-45, 0x1.0205658938p-6},
@@ -341,7 +341,7 @@ alignas(16) static constexpr NumberPair<double> LOG_R_DD[128] = {
341341
// Output range:
342342
// [-0x1.3ffcp-15, 0x1.3e3dp-15]
343343
// We store S2[i] = 2^16 (r(i - 2^6) - 1).
344-
alignas(8) static constexpr int S2[193] = {
344+
alignas(8) LIBC_INLINE_VAR constexpr int S2[193] = {
345345
0x101, 0xfd, 0xf9, 0xf5, 0xf1, 0xed, 0xe9, 0xe5, 0xe1,
346346
0xdd, 0xd9, 0xd5, 0xd1, 0xcd, 0xc9, 0xc5, 0xc1, 0xbd,
347347
0xb9, 0xb4, 0xb0, 0xac, 0xa8, 0xa4, 0xa0, 0x9c, 0x98,
@@ -365,7 +365,7 @@ alignas(8) static constexpr int S2[193] = {
365365
-0x1cd, -0x1d1, -0x1d5, -0x1d9, -0x1dd, -0x1e0, -0x1e4, -0x1e8, -0x1ec,
366366
-0x1f0, -0x1f4, -0x1f8, -0x1fc};
367367

368-
static constexpr double R2[193] = {
368+
LIBC_INLINE_VAR constexpr double R2[193] = {
369369
0x1.0101p0, 0x1.00fdp0, 0x1.00f9p0, 0x1.00f5p0, 0x1.00f1p0,
370370
0x1.00edp0, 0x1.00e9p0, 0x1.00e5p0, 0x1.00e1p0, 0x1.00ddp0,
371371
0x1.00d9p0, 0x1.00d5p0, 0x1.00d1p0, 0x1.00cdp0, 0x1.00c9p0,
@@ -412,7 +412,7 @@ static constexpr double R2[193] = {
412412
// Output range:
413413
// [-0x1.01928p-22 , 0x1p-22]
414414
// We store S[i] = 2^21 (r(i - 80) - 1).
415-
alignas(8) static constexpr int S3[161] = {
415+
alignas(8) LIBC_INLINE_VAR constexpr int S3[161] = {
416416
0x50, 0x4f, 0x4e, 0x4d, 0x4c, 0x4b, 0x4a, 0x49, 0x48, 0x47, 0x46,
417417
0x45, 0x44, 0x43, 0x42, 0x41, 0x40, 0x3f, 0x3e, 0x3d, 0x3c, 0x3b,
418418
0x3a, 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30,
@@ -435,7 +435,7 @@ alignas(8) static constexpr int S3[161] = {
435435
// Output range:
436436
// [-0x1.0002143p-29 , 0x1p-29]
437437
// We store S[i] = 2^28 (r(i - 65) - 1).
438-
alignas(8) static constexpr int S4[130] = {
438+
alignas(8) LIBC_INLINE_VAR constexpr int S4[130] = {
439439
0x41, 0x40, 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37,
440440
0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, 0x2f, 0x2e, 0x2d, 0x2c,
441441
0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21,
@@ -456,7 +456,7 @@ alignas(8) static constexpr int S4[130] = {
456456
// Table is generated with Sollya as follow:
457457
// > display = hexadecimal;
458458
// > for i from -104 to 89 do { D(exp(i)); };
459-
static constexpr double EXP_M1[195] = {
459+
LIBC_INLINE_VAR constexpr double EXP_M1[195] = {
460460
0x1.f1e6b68529e33p-151, 0x1.525be4e4e601dp-149, 0x1.cbe0a45f75eb1p-148,
461461
0x1.3884e838aea68p-146, 0x1.a8c1f14e2af5dp-145, 0x1.20a717e64a9bdp-143,
462462
0x1.8851d84118908p-142, 0x1.0a9bdfb02d240p-140, 0x1.6a5bea046b42ep-139,
@@ -528,7 +528,7 @@ static constexpr double EXP_M1[195] = {
528528
// Table is generated with Sollya as follow:
529529
// > display = hexadecimal;
530530
// > for i from 0 to 127 do { D(exp(i / 128)); };
531-
static constexpr double EXP_M2[128] = {
531+
LIBC_INLINE_VAR constexpr double EXP_M2[128] = {
532532
0x1.0000000000000p0, 0x1.0202015600446p0, 0x1.04080ab55de39p0,
533533
0x1.06122436410ddp0, 0x1.08205601127edp0, 0x1.0a32a84e9c1f6p0,
534534
0x1.0c49236829e8cp0, 0x1.0e63cfa7ab09dp0, 0x1.1082b577d34edp0,

libc/src/__support/math/cos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace LIBC_NAMESPACE_DECL {
3030

3131
namespace math {
3232

33-
LIBC_INLINE static constexpr double cos(double x) {
33+
LIBC_INLINE constexpr double cos(double x) {
3434
using namespace range_reduction_double_internal;
3535
using DoubleDouble = fputil::DoubleDouble;
3636
using FPBits = typename fputil::FPBits<double>;

libc/src/__support/math/range_reduction_double_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ LIBC_INLINE static unsigned range_reduction_small(double x, DoubleDouble &u) {
9797
// and one of those conditions guarantees that ulp(0.25 * x_reduced) >= 2, and
9898
// will safely be discarded.
9999

100-
static constexpr double ONE_TWENTY_EIGHT_OVER_PI[64][4] = {
100+
LIBC_INLINE_VAR constexpr double ONE_TWENTY_EIGHT_OVER_PI[64][4] = {
101101
{0x1.0000000000014p5, 0x1.7cc1b727220a8p-49, 0x1.4fe13abe8fa9cp-101,
102102
-0x1.911f924eb5336p-153},
103103
{0x1.0000000145f3p5, 0x1.b727220a94fep-49, 0x1.3abe8fa9a6eep-101,
@@ -306,7 +306,7 @@ LIBC_INLINE static Float128 range_reduction_small_f128(double x) {
306306
return fputil::quick_mul(y, PI_OVER_128_F128);
307307
}
308308

309-
static constexpr Float128 SIN_K_PI_OVER_128_F128[65] = {
309+
LIBC_INLINE_VAR constexpr Float128 SIN_K_PI_OVER_128_F128[65] = {
310310
{Sign::POS, 0, 0},
311311
{Sign::POS, -133, 0xc90a'afbd'1b33'efc9'c539'edcb'fda0'cf2c_u128},
312312
{Sign::POS, -132, 0xc8fb'2f88'6ec0'9f37'6a17'954b'2b7c'5171_u128},

libc/src/__support/math/sin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace LIBC_NAMESPACE_DECL {
2929

3030
namespace math {
3131

32-
LIBC_INLINE static constexpr double sin(double x) {
32+
LIBC_INLINE constexpr double sin(double x) {
3333
using namespace math::range_reduction_double_internal;
3434
using FPBits = typename fputil::FPBits<double>;
3535
FPBits xbits(x);

0 commit comments

Comments
 (0)