15 changes: 8 additions & 7 deletions libc/src/math/generic/asinhf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ LLVM_LIBC_FUNCTION(float, asinhf, (float x)) {
uint32_t x_abs = x_u & FPBits_t::FloatProp::EXP_MANT_MASK;

// |x| <= 2^-3
if (unlikely(x_abs <= 0x3e80'0000U)) {
if (LIBC_UNLIKELY(x_abs <= 0x3e80'0000U)) {
// |x| <= 2^-26
if (unlikely(x_abs <= 0x3280'0000U)) {
return unlikely(x_abs == 0) ? x : (x - 0x1.5555555555555p-3 * x * x * x);
if (LIBC_UNLIKELY(x_abs <= 0x3280'0000U)) {
return LIBC_UNLIKELY(x_abs == 0) ? x
: (x - 0x1.5555555555555p-3 * x * x * x);
}

double x_d = x;
Expand Down Expand Up @@ -55,8 +56,8 @@ LLVM_LIBC_FUNCTION(float, asinhf, (float x)) {
static_cast<float>(x_sign) * 0x1.0p-24f);
};

if (unlikely(x_abs >= 0x4bdd'65a5U)) {
if (unlikely(x_abs >= 0x7f80'0000U)) {
if (LIBC_UNLIKELY(x_abs >= 0x4bdd'65a5U)) {
if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
// x is +-inf or nan
return x;
}
Expand Down Expand Up @@ -84,11 +85,11 @@ LLVM_LIBC_FUNCTION(float, asinhf, (float x)) {
}
} else {
// Exceptional cases when x < 2^24.
if (unlikely(x_abs == 0x45abaf26)) {
if (LIBC_UNLIKELY(x_abs == 0x45abaf26)) {
// |x| = 0x1.575e4cp12f
return round_result_slightly_down(0x1.29becap3f);
}
if (unlikely(x_abs == 0x49d29048)) {
if (LIBC_UNLIKELY(x_abs == 0x49d29048)) {
// |x| = 0x1.a5209p20f
return round_result_slightly_down(0x1.e1b92p3f);
}
Expand Down
6 changes: 3 additions & 3 deletions libc/src/math/generic/atanf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ LLVM_LIBC_FUNCTION(float, atanf, (float x)) {
bool sign = xbits.get_sign();
xbits.set_sign(false);

if (unlikely(xbits.is_inf_or_nan())) {
if (LIBC_UNLIKELY(xbits.is_inf_or_nan())) {
if (xbits.is_inf())
return opt_barrier(sign ? -M_MATH_PI_2 : M_MATH_PI_2);
else
return x;
}
// |x| == 0.06905200332403183
if (unlikely(xbits.uintval() == 0x3d8d6b23U)) {
if (LIBC_UNLIKELY(xbits.uintval() == 0x3d8d6b23U)) {
if (fputil::get_round() == FE_TONEAREST) {
// 0.06894256919622421
FPBits br(0x3d8d31c3U);
Expand All @@ -36,7 +36,7 @@ LLVM_LIBC_FUNCTION(float, atanf, (float x)) {
}

// |x| == 1.8670953512191772
if (unlikely(xbits.uintval() == 0x3feefcfbU)) {
if (LIBC_UNLIKELY(xbits.uintval() == 0x3feefcfbU)) {
int rounding_mode = fputil::get_round();
if (sign) {
if (rounding_mode == FE_DOWNWARD) {
Expand Down
9 changes: 5 additions & 4 deletions libc/src/math/generic/atanhf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(float, atanhf, (float x)) {
uint32_t x_abs = xbits.uintval() & FPBits::FloatProp::EXP_MANT_MASK;

// |x| >= 1.0
if (unlikely(x_abs >= 0x3F80'0000U)) {
if (LIBC_UNLIKELY(x_abs >= 0x3F80'0000U)) {
if (xbits.is_nan()) {
return x;
}
Expand All @@ -36,10 +36,11 @@ LLVM_LIBC_FUNCTION(float, atanhf, (float x)) {
}

// |x| < ~0.10
if (unlikely(x_abs <= 0x3dcc'0000U)) {
if (LIBC_UNLIKELY(x_abs <= 0x3dcc'0000U)) {
// |x| <= 2^-26
if (unlikely(x_abs <= 0x3280'0000U)) {
return unlikely(x_abs == 0) ? x : (x + 0x1.5555555555555p-2 * x * x * x);
if (LIBC_UNLIKELY(x_abs <= 0x3280'0000U)) {
return LIBC_UNLIKELY(x_abs == 0) ? x
: (x + 0x1.5555555555555p-2 * x * x * x);
}

double xdbl = x;
Expand Down
6 changes: 3 additions & 3 deletions libc/src/math/generic/cosf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ LLVM_LIBC_FUNCTION(float, cosf, (float x)) {
// Sollya respectively.

// |x| < 0x1.0p-12f
if (unlikely(x_abs < 0x3980'0000U)) {
if (LIBC_UNLIKELY(x_abs < 0x3980'0000U)) {
// When |x| < 2^-12, the relative error of the approximation cos(x) ~ 1
// is:
// |cos(x) - 1| < |x^2 / 2| = 2^-25 < epsilon(1)/2.
Expand All @@ -107,11 +107,11 @@ LLVM_LIBC_FUNCTION(float, cosf, (float x)) {
#endif // LIBC_TARGET_HAS_FMA
}

if (auto r = COSF_EXCEPTS.lookup(x_abs); unlikely(r.has_value()))
if (auto r = COSF_EXCEPTS.lookup(x_abs); LIBC_UNLIKELY(r.has_value()))
return r.value();

// x is inf or nan.
if (unlikely(x_abs >= 0x7f80'0000U)) {
if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
if (x_abs == 0x7f80'0000U) {
errno = EDOM;
fputil::set_except(FE_INVALID);
Expand Down
6 changes: 3 additions & 3 deletions libc/src/math/generic/coshf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ LLVM_LIBC_FUNCTION(float, coshf, (float x)) {
uint32_t x_u = xbits.uintval();

// |x| <= 2^-26
if (unlikely(x_u <= 0x3280'0000U)) {
if (LIBC_UNLIKELY(x_u <= 0x3280'0000U)) {
return 1.0f + x;
}

// When |x| >= 90, or x is inf or nan
if (unlikely(x_u >= 0x42b4'0000U)) {
if (LIBC_UNLIKELY(x_u >= 0x42b4'0000U)) {
if (xbits.is_inf_or_nan())
return x + FPBits::inf().get_val();

int rounding = fputil::get_round();
if (unlikely(rounding == FE_DOWNWARD || rounding == FE_TOWARDZERO))
if (LIBC_UNLIKELY(rounding == FE_DOWNWARD || rounding == FE_TOWARDZERO))
return FPBits(FPBits::MAX_NORMAL).get_val();

errno = ERANGE;
Expand Down
12 changes: 6 additions & 6 deletions libc/src/math/generic/exp10f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ LLVM_LIBC_FUNCTION(float, exp10f, (float x)) {
uint32_t x_abs = x_u & 0x7fff'ffffU;

// When |x| >= log10(2^128), or x is nan
if (unlikely(x_abs >= 0x421a'209bU)) {
if (LIBC_UNLIKELY(x_abs >= 0x421a'209bU)) {
// When x < log10(2^-150) or nan
if (x_u > 0xc234'9e35U) {
// exp(-Inf) = 0
Expand Down Expand Up @@ -58,29 +58,29 @@ LLVM_LIBC_FUNCTION(float, exp10f, (float x)) {
}

// When |x| <= log10(2)*2^-6
if (unlikely(x_abs <= 0x3b9a'209bU)) {
if (unlikely(x_u == 0xb25e'5bd9U)) { // x = -0x1.bcb7b2p-27f
if (LIBC_UNLIKELY(x_abs <= 0x3b9a'209bU)) {
if (LIBC_UNLIKELY(x_u == 0xb25e'5bd9U)) { // x = -0x1.bcb7b2p-27f
if (fputil::get_round() == FE_TONEAREST)
return 0x1.fffffep-1f;
}
// |x| < 2^-25
// 10^x ~ 1 + log(10) * x
if (unlikely(x_abs <= 0x3280'0000U)) {
if (LIBC_UNLIKELY(x_abs <= 0x3280'0000U)) {
return fputil::multiply_add(x, 0x1.26bb1cp+1f, 1.0f);
}

return Exp10Base::powb_lo(x);
}

// Exceptional value.
if (unlikely(x_u == 0x3d14'd956U)) { // x = 0x1.29b2acp-5f
if (LIBC_UNLIKELY(x_u == 0x3d14'd956U)) { // x = 0x1.29b2acp-5f
if (fputil::get_round() == FE_UPWARD)
return 0x1.1657c4p+0f;
}

// Exact outputs when x = 1, 2, ..., 10.
// Quick check mask: 0x800f'ffffU = ~(bits of 1.0f | ... | bits of 10.0f)
if (unlikely((x_u & 0x800f'ffffU) == 0)) {
if (LIBC_UNLIKELY((x_u & 0x800f'ffffU) == 0)) {
switch (x_u) {
case 0x3f800000U: // x = 1.0f
return 10.0f;
Expand Down
10 changes: 5 additions & 5 deletions libc/src/math/generic/exp2f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ LLVM_LIBC_FUNCTION(float, exp2f, (float x)) {
uint32_t x_abs = x_u & 0x7fff'ffffU;

// |x| < 2^-25
if (unlikely(x_abs <= 0x3280'0000U)) {
if (LIBC_UNLIKELY(x_abs <= 0x3280'0000U)) {
return 1.0f + x;
}

// // When |x| >= 128, or x is nan
if (unlikely(x_abs >= 0x4300'0000U)) {
if (LIBC_UNLIKELY(x_abs >= 0x4300'0000U)) {

// x >= 128
if (!xbits.get_sign()) {
Expand Down Expand Up @@ -69,11 +69,11 @@ LLVM_LIBC_FUNCTION(float, exp2f, (float x)) {
}

// Check exceptional values.
if (unlikely(x_u & exval_mask) == exval_mask) {
if (unlikely(x_u == exval1)) { // x = 0x1.853a6ep-9f
if (LIBC_UNLIKELY(x_u & exval_mask) == exval_mask) {
if (LIBC_UNLIKELY(x_u == exval1)) { // x = 0x1.853a6ep-9f
if (fputil::get_round() == FE_TONEAREST)
return 0x1.00870ap+0f;
} else if (unlikely(x_u == exval2)) { // x = -0x1.e7526ep-6f
} else if (LIBC_UNLIKELY(x_u == exval2)) { // x = -0x1.e7526ep-6f
if (fputil::get_round() == FE_TONEAREST)
return 0x1.f58d62p-1f;
}
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/expf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ LLVM_LIBC_FUNCTION(float, expf, (float x)) {
uint32_t x_abs = x_u & 0x7fff'ffffU;

// Exceptional values
if (unlikely(x_u == 0xc236'bd8cU)) { // x = -0x1.6d7b18p+5f
if (LIBC_UNLIKELY(x_u == 0xc236'bd8cU)) { // x = -0x1.6d7b18p+5f
return 0x1.108a58p-66f - x * 0x1.0p-95f;
}

// When |x| >= 89, |x| < 2^-25, or x is nan
if (unlikely(x_abs >= 0x42b2'0000U || x_abs <= 0x3280'0000U)) {
if (LIBC_UNLIKELY(x_abs >= 0x42b2'0000U || x_abs <= 0x3280'0000U)) {
// |x| < 2^-25
if (xbits.get_unbiased_exponent() <= 101) {
return 1.0f + x;
Expand Down
8 changes: 4 additions & 4 deletions libc/src/math/generic/expm1f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ LLVM_LIBC_FUNCTION(float, expm1f, (float x)) {
uint32_t x_abs = x_u & 0x7fff'ffffU;

// Exceptional value
if (unlikely(x_u == 0x3e35'bec5U)) { // x = 0x1.6b7d8ap-3f
if (LIBC_UNLIKELY(x_u == 0x3e35'bec5U)) { // x = 0x1.6b7d8ap-3f
int round_mode = fputil::get_round();
if (round_mode == FE_TONEAREST || round_mode == FE_UPWARD)
return 0x1.8dbe64p-3f;
return 0x1.8dbe62p-3f;
}

#if !defined(LIBC_TARGET_HAS_FMA)
if (unlikely(x_u == 0xbdc1'c6cbU)) { // x = -0x1.838d96p-4f
if (LIBC_UNLIKELY(x_u == 0xbdc1'c6cbU)) { // x = -0x1.838d96p-4f
int round_mode = fputil::get_round();
if (round_mode == FE_TONEAREST || round_mode == FE_DOWNWARD)
return -0x1.71c884p-4f;
Expand All @@ -47,7 +47,7 @@ LLVM_LIBC_FUNCTION(float, expm1f, (float x)) {
#endif // LIBC_TARGET_HAS_FMA

// When |x| > 25*log(2), or nan
if (unlikely(x_abs >= 0x418a'a123U)) {
if (LIBC_UNLIKELY(x_abs >= 0x418a'a123U)) {
// x < log(2^-25)
if (xbits.get_sign()) {
// exp(-Inf) = 0
Expand Down Expand Up @@ -80,7 +80,7 @@ LLVM_LIBC_FUNCTION(float, expm1f, (float x)) {
// |x| < 2^-25
if (x_abs < 0x3300'0000U) {
// x = -0.0f
if (unlikely(xbits.uintval() == 0x8000'0000U))
if (LIBC_UNLIKELY(xbits.uintval() == 0x8000'0000U))
return x;
// When |x| < 2^-25, the relative error of the approximation e^x - 1 ~ x
// is:
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/log10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,8 @@ LLVM_LIBC_FUNCTION(double, log10, (double x)) {
FPBits_t xbits(x);
int x_e = -1023;

if (unlikely(xbits.uintval() < FPBits_t::MIN_NORMAL ||
xbits.uintval() > FPBits_t::MAX_NORMAL)) {
if (LIBC_UNLIKELY(xbits.uintval() < FPBits_t::MIN_NORMAL ||
xbits.uintval() > FPBits_t::MAX_NORMAL)) {
if (xbits.is_zero()) {
// return -Inf and raise FE_DIVBYZERO.
return -1.0 / 0.0;
Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/math_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ template <typename T> LIBC_INLINE T with_errno(T x, int err) {
}

template <typename T> LIBC_INLINE void force_eval(T x) {
volatile T y UNUSED = x;
volatile T y LIBC_UNUSED = x;
}

template <typename T> LIBC_INLINE T opt_barrier(T x) {
Expand Down
8 changes: 4 additions & 4 deletions libc/src/math/generic/sincosf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ LLVM_LIBC_FUNCTION(void, sincosf, (float x, float *sinp, float *cosp)) {
// Sollya respectively.

// |x| < 0x1.0p-12f
if (unlikely(x_abs < 0x3980'0000U)) {
if (unlikely(x_abs == 0U)) {
if (LIBC_UNLIKELY(x_abs < 0x3980'0000U)) {
if (LIBC_UNLIKELY(x_abs == 0U)) {
// For signed zeros.
*sinp = x;
*cosp = 1.0f;
Expand Down Expand Up @@ -141,7 +141,7 @@ LLVM_LIBC_FUNCTION(void, sincosf, (float x, float *sinp, float *cosp)) {
}

// x is inf or nan.
if (unlikely(x_abs >= 0x7f80'0000U)) {
if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
if (x_abs == 0x7f80'0000U) {
errno = EDOM;
fputil::set_except(FE_INVALID);
Expand All @@ -154,7 +154,7 @@ LLVM_LIBC_FUNCTION(void, sincosf, (float x, float *sinp, float *cosp)) {

// Check exceptional values.
for (int i = 0; i < N_EXCEPTS; ++i) {
if (unlikely(x_abs == EXCEPT_INPUTS[i])) {
if (LIBC_UNLIKELY(x_abs == EXCEPT_INPUTS[i])) {
uint32_t s = EXCEPT_OUTPUTS_SIN[i][0]; // FE_TOWARDZERO
uint32_t c = EXCEPT_OUTPUTS_COS[i][0]; // FE_TOWARDZERO
bool x_sign = x < 0;
Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/sincosf_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ LIBC_INLINE void sincosf_eval(double xd, uint32_t x_abs, double &sin_k,
int64_t k;
double y;

if (likely(x_abs < FAST_PASS_BOUND)) {
if (LIBC_LIKELY(x_abs < FAST_PASS_BOUND)) {
k = small_range_reduction(xd, y);
} else {
fputil::FPBits<float> x_bits(x_abs);
Expand Down
10 changes: 5 additions & 5 deletions libc/src/math/generic/sinf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ LLVM_LIBC_FUNCTION(float, sinf, (float x)) {
// Sollya respectively.

// |x| <= pi/16
if (unlikely(x_abs <= 0x3e49'0fdbU)) {
if (LIBC_UNLIKELY(x_abs <= 0x3e49'0fdbU)) {

// |x| < 0x1.d12ed2p-12f
if (unlikely(x_abs < 0x39e8'9769U)) {
if (unlikely(x_abs == 0U)) {
if (LIBC_UNLIKELY(x_abs < 0x39e8'9769U)) {
if (LIBC_UNLIKELY(x_abs == 0U)) {
// For signed zeros.
return x;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ LLVM_LIBC_FUNCTION(float, sinf, (float x)) {
return xd * result;
}

if (unlikely(x_abs == 0x4619'9998U)) { // x = 0x1.33333p13
if (LIBC_UNLIKELY(x_abs == 0x4619'9998U)) { // x = 0x1.33333p13
float r = -0x1.63f4bap-2f;
int rounding = fputil::get_round();
bool sign = xbits.get_sign();
Expand All @@ -132,7 +132,7 @@ LLVM_LIBC_FUNCTION(float, sinf, (float x)) {
return xbits.get_sign() ? -r : r;
}

if (unlikely(x_abs >= 0x7f80'0000U)) {
if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
if (x_abs == 0x7f80'0000U) {
errno = EDOM;
fputil::set_except(FE_INVALID);
Expand Down
14 changes: 7 additions & 7 deletions libc/src/math/generic/sinhf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ LLVM_LIBC_FUNCTION(float, sinhf, (float x)) {
uint32_t x_abs = xbits.uintval() & FPBits::FloatProp::EXP_MANT_MASK;

// |x| <= 2^-26
if (unlikely(x_abs <= 0x3280'0000U)) {
return unlikely(x_abs == 0) ? x : (x + 0.25 * x * x * x);
if (LIBC_UNLIKELY(x_abs <= 0x3280'0000U)) {
return LIBC_UNLIKELY(x_abs == 0) ? x : (x + 0.25 * x * x * x);
}

// When |x| >= 90, or x is inf or nan
if (unlikely(x_abs >= 0x42b4'0000U)) {
if (LIBC_UNLIKELY(x_abs >= 0x42b4'0000U)) {
if (xbits.is_nan())
return x + 1.0f; // sNaN to qNaN + signal

Expand All @@ -33,11 +33,11 @@ LLVM_LIBC_FUNCTION(float, sinhf, (float x)) {

int rounding = fputil::get_round();
if (sign) {
if (unlikely(rounding == FE_UPWARD || rounding == FE_TOWARDZERO))
if (LIBC_UNLIKELY(rounding == FE_UPWARD || rounding == FE_TOWARDZERO))
return FPBits(FPBits::MAX_NORMAL | FPBits::FloatProp::SIGN_MASK)
.get_val();
} else {
if (unlikely(rounding == FE_DOWNWARD || rounding == FE_TOWARDZERO))
if (LIBC_UNLIKELY(rounding == FE_DOWNWARD || rounding == FE_TOWARDZERO))
return FPBits(FPBits::MAX_NORMAL).get_val();
}

Expand All @@ -47,9 +47,9 @@ LLVM_LIBC_FUNCTION(float, sinhf, (float x)) {
}

// |x| <= 0.078125
if (unlikely(x_abs <= 0x3da0'0000U)) {
if (LIBC_UNLIKELY(x_abs <= 0x3da0'0000U)) {
// |x| = 0.0005589424981735646724700927734375
if (unlikely(x_abs == 0x3a12'85ffU)) {
if (LIBC_UNLIKELY(x_abs == 0x3a12'85ffU)) {
if (fputil::get_round() == FE_TONEAREST)
return x;
}
Expand Down
14 changes: 7 additions & 7 deletions libc/src/math/generic/tanf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ LLVM_LIBC_FUNCTION(float, tanf, (float x)) {
uint32_t x_abs = xbits.uintval() & 0x7fff'ffffU;

// |x| < pi/32
if (unlikely(x_abs <= 0x3dc9'0fdbU)) {
if (LIBC_UNLIKELY(x_abs <= 0x3dc9'0fdbU)) {
double xd = static_cast<double>(x);

// |x| < 0x1.0p-12f
if (unlikely(x_abs < 0x3980'0000U)) {
if (unlikely(x_abs == 0U)) {
if (LIBC_UNLIKELY(x_abs < 0x3980'0000U)) {
if (LIBC_UNLIKELY(x_abs == 0U)) {
// For signed zeros.
return x;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ LLVM_LIBC_FUNCTION(float, tanf, (float x)) {
}

// Check for exceptional values
if (unlikely(x_abs == 0x3f8a1f62U)) {
if (LIBC_UNLIKELY(x_abs == 0x3f8a1f62U)) {
// |x| = 0x1.143ec4p0
float sign = x_sign ? -1.0f : 1.0f;

Expand All @@ -106,9 +106,9 @@ LLVM_LIBC_FUNCTION(float, tanf, (float x)) {
}

// |x| > 0x1.ada6a8p+27f
if (unlikely(x_abs > 0x4d56'd354U)) {
if (LIBC_UNLIKELY(x_abs > 0x4d56'd354U)) {
// Inf or NaN
if (unlikely(x_abs >= 0x7f80'0000U)) {
if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
if (x_abs == 0x7f80'0000U) {
errno = EDOM;
fputil::set_except(FE_INVALID);
Expand All @@ -118,7 +118,7 @@ LLVM_LIBC_FUNCTION(float, tanf, (float x)) {
}
// Other large exceptional values
if (auto r = TANF_EXCEPTS.lookup_odd(x_abs, x_sign);
unlikely(r.has_value()))
LIBC_UNLIKELY(r.has_value()))
return r.value();
}

Expand Down
11 changes: 6 additions & 5 deletions libc/src/math/generic/tanhf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ LLVM_LIBC_FUNCTION(float, tanhf, (float x)) {
uint32_t x_abs = xbits.uintval() & FPBits::FloatProp::EXP_MANT_MASK;

// |x| <= 2^-26
if (unlikely(x_abs <= 0x3280'0000U)) {
return unlikely(x_abs == 0) ? x : (x - 0x1.5555555555555p-2 * x * x * x);
if (LIBC_UNLIKELY(x_abs <= 0x3280'0000U)) {
return LIBC_UNLIKELY(x_abs == 0) ? x
: (x - 0x1.5555555555555p-2 * x * x * x);
}

// When |x| >= 15, or x is inf or nan
if (unlikely(x_abs >= 0x4170'0000U)) {
if (LIBC_UNLIKELY(x_abs >= 0x4170'0000U)) {
if (xbits.is_nan())
return x + 1.0f; // sNaN to qNaN + signal

Expand All @@ -39,7 +40,7 @@ LLVM_LIBC_FUNCTION(float, tanhf, (float x)) {
}

// |x| <= 0.078125
if (unlikely(x_abs <= 0x3da0'0000U)) {
if (LIBC_UNLIKELY(x_abs <= 0x3da0'0000U)) {
double xdbl = x;
double x2 = xdbl * xdbl;
// Pure Taylor series.
Expand All @@ -49,7 +50,7 @@ LLVM_LIBC_FUNCTION(float, tanhf, (float x)) {
return fputil::multiply_add(xdbl, pe, xdbl);
}

if (unlikely(xbits.bits == 0x4058'e0a3U)) {
if (LIBC_UNLIKELY(xbits.bits == 0x4058'e0a3U)) {
if (fputil::get_round() == FE_DOWNWARD)
return FPBits(0x3f7f'6ad9U).get_val();
}
Expand Down
10 changes: 5 additions & 5 deletions libc/src/string/memory_utils/bcmp_implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ inline_bcmp_x86_avx2_gt16(CPtr p1, CPtr p2, size_t count) {
return x86::avx2::Bcmp<32>::head_tail(p1, p2, count);
if (count <= 128)
return x86::avx2::Bcmp<64>::head_tail(p1, p2, count);
if (unlikely(count >= 256)) {
if (LIBC_UNLIKELY(count >= 256)) {
if (auto value = x86::avx2::Bcmp<64>::block(p1, p2))
return value;
align_to_next_boundary<64, Arg::P1>(p1, p2, count);
Expand All @@ -78,7 +78,7 @@ inline_bcmp_x86_avx512bw_gt16(CPtr p1, CPtr p2, size_t count) {
return x86::avx2::Bcmp<32>::head_tail(p1, p2, count);
if (count <= 128)
return x86::avx512bw::Bcmp<64>::head_tail(p1, p2, count);
if (unlikely(count >= 256)) {
if (LIBC_UNLIKELY(count >= 256)) {
if (auto value = x86::avx512bw::Bcmp<64>::block(p1, p2))
return value;
align_to_next_boundary<64, Arg::P1>(p1, p2, count);
Expand Down Expand Up @@ -115,8 +115,8 @@ inline_bcmp_x86_avx512bw_gt16(CPtr p1, CPtr p2, size_t count) {
[[maybe_unused]] LIBC_INLINE BcmpReturnType inline_bcmp_aarch64(CPtr p1,
CPtr p2,
size_t count) {
if (likely(count <= 32)) {
if (unlikely(count >= 16)) {
if (LIBC_LIKELY(count <= 32)) {
if (LIBC_UNLIKELY(count >= 16)) {
return aarch64::Bcmp<16>::head_tail(p1, p2, count);
}
switch (count) {
Expand Down Expand Up @@ -151,7 +151,7 @@ inline_bcmp_x86_avx512bw_gt16(CPtr p1, CPtr p2, size_t count) {
return aarch64::Bcmp<32>::head_tail(p1, p2, count);

// Aligned loop if > 256, otherwise normal loop
if (unlikely(count > 256)) {
if (LIBC_UNLIKELY(count > 256)) {
if (auto value = aarch64::Bcmp<32>::block(p1, p2))
return value;
align_to_next_boundary<16, Arg::P1>(p1, p2, count);
Expand Down
10 changes: 5 additions & 5 deletions libc/src/string/memory_utils/memcmp_implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ inline_memcmp_embedded_tiny(CPtr p1, CPtr p2, size_t count) {
#if defined(LIBC_TARGET_IS_X86) || defined(LIBC_TARGET_IS_AARCH64)
[[maybe_unused]] LIBC_INLINE MemcmpReturnType
inline_memcmp_generic_gt16(CPtr p1, CPtr p2, size_t count) {
if (unlikely(count >= 384)) {
if (LIBC_UNLIKELY(count >= 384)) {
if (auto value = generic::Memcmp<16>::block(p1, p2))
return value;
align_to_next_boundary<16, Arg::P1>(p1, p2, count);
Expand All @@ -44,7 +44,7 @@ inline_memcmp_generic_gt16(CPtr p1, CPtr p2, size_t count) {
#if defined(LIBC_TARGET_IS_X86)
[[maybe_unused]] LIBC_INLINE MemcmpReturnType
inline_memcmp_x86_sse2_gt16(CPtr p1, CPtr p2, size_t count) {
if (unlikely(count >= 384)) {
if (LIBC_UNLIKELY(count >= 384)) {
if (auto value = x86::sse2::Memcmp<16>::block(p1, p2))
return value;
align_to_next_boundary<16, Arg::P1>(p1, p2, count);
Expand All @@ -60,7 +60,7 @@ inline_memcmp_x86_avx2_gt16(CPtr p1, CPtr p2, size_t count) {
return x86::avx2::Memcmp<32>::head_tail(p1, p2, count);
if (count <= 128)
return x86::avx2::Memcmp<64>::head_tail(p1, p2, count);
if (unlikely(count >= 384)) {
if (LIBC_UNLIKELY(count >= 384)) {
if (auto value = x86::avx2::Memcmp<32>::block(p1, p2))
return value;
align_to_next_boundary<32, Arg::P1>(p1, p2, count);
Expand All @@ -76,7 +76,7 @@ inline_memcmp_x86_avx512bw_gt16(CPtr p1, CPtr p2, size_t count) {
return x86::avx2::Memcmp<32>::head_tail(p1, p2, count);
if (count <= 128)
return x86::avx512bw::Memcmp<64>::head_tail(p1, p2, count);
if (unlikely(count >= 384)) {
if (LIBC_UNLIKELY(count >= 384)) {
if (auto value = x86::avx512bw::Memcmp<64>::block(p1, p2))
return value;
align_to_next_boundary<64, Arg::P1>(p1, p2, count);
Expand All @@ -89,7 +89,7 @@ inline_memcmp_x86_avx512bw_gt16(CPtr p1, CPtr p2, size_t count) {
#if defined(LIBC_TARGET_IS_AARCH64)
[[maybe_unused]] LIBC_INLINE MemcmpReturnType
inline_memcmp_aarch64_neon_gt16(CPtr p1, CPtr p2, size_t count) {
if (unlikely(count >= 128)) { // [128, ∞]
if (LIBC_UNLIKELY(count >= 128)) { // [128, ∞]
if (auto value = generic::Memcmp<16>::block(p1, p2))
return value;
align_to_next_boundary<16, Arg::P1>(p1, p2, count);
Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/memcpy_implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ inline_memcpy_x86_maybe_interpose_repmovsb(Ptr __restrict dst,
} else if constexpr (kRepMovsbThreshold == size_t(-1)) {
return inline_memcpy_x86(dst, src, count);
} else {
if (unlikely(count >= kRepMovsbThreshold))
if (LIBC_UNLIKELY(count >= kRepMovsbThreshold))
return x86::Memcpy::repmovsb(dst, src, count);
else
return inline_memcpy_x86(dst, src, count);
Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ LIBC_INLINE char *string_token(char *__restrict src,
const char *__restrict delimiter_string,
char **__restrict saveptr) {
// Return nullptr immediately if both src AND saveptr are nullptr
if (unlikely(src == nullptr && ((src = *saveptr) == nullptr)))
if (LIBC_UNLIKELY(src == nullptr && ((src = *saveptr) == nullptr)))
return nullptr;

cpp::bitset<256> delimiter_set;
Expand Down
5 changes: 3 additions & 2 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ libc_support_library(
libc_support_library(
name = "__support_common",
hdrs = [
"src/__support/macros/architectures.h",
"src/__support/common.h",
"src/__support/macros/cpu_features.h",
"src/__support/endian.h",
"src/__support/macros/architectures.h",
"src/__support/macros/attributes.h",
"src/__support/macros/cpu_features.h",
],
)

Expand Down