diff --git a/libc/.clang-tidy b/libc/.clang-tidy --- a/libc/.clang-tidy +++ b/libc/.clang-tidy @@ -18,6 +18,8 @@ value: lower_case - key: readability-identifier-naming.FunctionIgnoredRegexp value: "^_[A-Za-z0-9_]+$" + - key: readability-identifier-naming.GlobalConstantCase + value: UPPER_CASE - key: readability-identifier-naming.ConstexprVariableCase value: UPPER_CASE - key: readability-identifier-naming.GetConfigPerFile diff --git a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h --- a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h +++ b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h @@ -34,16 +34,16 @@ sizeof(fenv_t) == sizeof(FPState), "Internal floating point state does not match the public fenv_t type."); - static constexpr uint32_t ToNearest = 0x0; - static constexpr uint32_t Upward = 0x1; - static constexpr uint32_t Downward = 0x2; - static constexpr uint32_t TowardZero = 0x3; + static constexpr uint32_t TONEAREST = 0x0; + static constexpr uint32_t UPWARD = 0x1; + static constexpr uint32_t DOWNWARD = 0x2; + static constexpr uint32_t TOWARDZERO = 0x3; - static constexpr uint32_t Invalid = 0x1; - static constexpr uint32_t DivByZero = 0x2; - static constexpr uint32_t Overflow = 0x4; - static constexpr uint32_t Underflow = 0x8; - static constexpr uint32_t Inexact = 0x10; + static constexpr uint32_t INVALID = 0x1; + static constexpr uint32_t DIVBYZERO = 0x2; + static constexpr uint32_t OVERFLOW = 0x4; + static constexpr uint32_t UNDERFLOW = 0x8; + static constexpr uint32_t INEXACT = 0x10; // Zero-th bit is the first bit. static constexpr uint32_t RoundingControlBitPosition = 22; @@ -51,19 +51,19 @@ static constexpr uint32_t ExceptionControlFlagsBitPosition = 8; static inline uint32_t getStatusValueForExcept(int excepts) { - return (excepts & FE_INVALID ? Invalid : 0) | - (excepts & FE_DIVBYZERO ? DivByZero : 0) | - (excepts & FE_OVERFLOW ? Overflow : 0) | - (excepts & FE_UNDERFLOW ? Underflow : 0) | - (excepts & FE_INEXACT ? Inexact : 0); + return (excepts & FE_INVALID ? INVALID : 0) | + (excepts & FE_DIVBYZERO ? DIVBYERO : 0) | + (excepts & FE_OVERFLOW ? OVERFLOW : 0) | + (excepts & FE_UNDERFLOW ? UNDERFLOW : 0) | + (excepts & FE_INEXACT ? INEXACT : 0); } static inline int exceptionStatusToMacro(uint32_t status) { - return (status & Invalid ? FE_INVALID : 0) | - (status & DivByZero ? FE_DIVBYZERO : 0) | - (status & Overflow ? FE_OVERFLOW : 0) | - (status & Underflow ? FE_UNDERFLOW : 0) | - (status & Inexact ? FE_INEXACT : 0); + return (status & INVALID ? FE_INVALID : 0) | + (status & DIVBYZERO ? FE_DIVBYZERO : 0) | + (status & OVERFLOW ? FE_OVERFLOW : 0) | + (status & UNDERFLOW ? FE_UNDERFLOW : 0) | + (status & INEXACT ? FE_INEXACT : 0); } static uint32_t getControlWord() { return __arm_rsr("fpcr"); } @@ -141,36 +141,36 @@ uint32_t toRaise = FEnv::getStatusValueForExcept(excepts); - if (toRaise & FEnv::Invalid) { + if (toRaise & FEnv::INVALID) { divfunc(zero, zero); uint32_t statusWord = FEnv::getStatusWord(); if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) & - FEnv::Invalid)) + FEnv::INVALID)) return -1; } - if (toRaise & FEnv::DivByZero) { + if (toRaise & FEnv::DIVBYZERO) { divfunc(one, zero); uint32_t statusWord = FEnv::getStatusWord(); if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) & - FEnv::DivByZero)) + FEnv::DIVBYZERO)) return -1; } - if (toRaise & FEnv::Overflow) { + if (toRaise & FEnv::OVERFLOW) { divfunc(largeValue, smallValue); uint32_t statusWord = FEnv::getStatusWord(); if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) & - FEnv::Overflow)) + FEnv::OVERFLOW)) return -1; } - if (toRaise & FEnv::Underflow) { + if (toRaise & FEnv::UNDERFLOW) { divfunc(smallValue, largeValue); uint32_t statusWord = FEnv::getStatusWord(); if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) & - FEnv::Underflow)) + FEnv::UNDERFLOW)) return -1; } - if (toRaise & FEnv::Inexact) { + if (toRaise & FEnv::INEXACT) { float two = 2.0f; float three = 3.0f; // 2.0 / 3.0 cannot be represented exactly in any radix 2 floating point @@ -178,7 +178,7 @@ divfunc(two, three); uint32_t statusWord = FEnv::getStatusWord(); if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) & - FEnv::Inexact)) + FEnv::INEXACT)) return -1; } return 0; @@ -188,13 +188,13 @@ uint32_t roundingMode = (FEnv::getControlWord() >> FEnv::RoundingControlBitPosition) & 0x3; switch (roundingMode) { - case FEnv::ToNearest: + case FEnv::TONEAREST: return FE_TONEAREST; - case FEnv::Downward: + case FEnv::DOWNWARD: return FE_DOWNWARD; - case FEnv::Upward: + case FEnv::UPWARD: return FE_UPWARD; - case FEnv::TowardZero: + case FEnv::TOWARDZERO: return FE_TOWARDZERO; default: return -1; // Error value. @@ -205,16 +205,16 @@ uint16_t bitValue; switch (mode) { case FE_TONEAREST: - bitValue = FEnv::ToNearest; + bitValue = FEnv::TONEAREST; break; case FE_DOWNWARD: - bitValue = FEnv::Downward; + bitValue = FEnv::DOWNWARD; break; case FE_UPWARD: - bitValue = FEnv::Upward; + bitValue = FEnv::UPWARD; break; case FE_TOWARDZERO: - bitValue = FEnv::TowardZero; + bitValue = FEnv::TOWARDZERO; break; default: return 1; // To indicate failure diff --git a/libc/src/math/generic/cosf.cpp b/libc/src/math/generic/cosf.cpp --- a/libc/src/math/generic/cosf.cpp +++ b/libc/src/math/generic/cosf.cpp @@ -25,9 +25,9 @@ double x = y; double s; int n; - const sincos_t *p = &__SINCOSF_TABLE[0]; + const sincos_t *p = &SINCOSF_TABLE[0]; - if (abstop12(y) < abstop12(pio4)) { + if (abstop12(y) < abstop12(PIO4)) { double x2 = x * x; if (unlikely(abstop12(y) < abstop12(as_float(0x39800000)))) @@ -41,7 +41,7 @@ s = p->sign[n & 3]; if (n & 2) - p = &__SINCOSF_TABLE[1]; + p = &SINCOSF_TABLE[1]; return sinf_poly(x * s, x * x, p, n ^ 1); } else if (abstop12(y) < abstop12(INFINITY)) { @@ -54,7 +54,7 @@ s = p->sign[(n + sign) & 3]; if ((n + sign) & 2) - p = &__SINCOSF_TABLE[1]; + p = &SINCOSF_TABLE[1]; return sinf_poly(x * s, x * x, p, n ^ 1); } diff --git a/libc/src/math/generic/math_utils.h b/libc/src/math/generic/math_utils.h --- a/libc/src/math/generic/math_utils.h +++ b/libc/src/math/generic/math_utils.h @@ -42,15 +42,15 @@ template struct XFlowValues; template <> struct XFlowValues { - static const float overflow_value; - static const float underflow_value; - static const float may_underflow_value; + static const float OVERFLOW_VALUE; + static const float UNDERFLOW_VALUE; + static const float MAY_UNDERFLOW_VALUE; }; template <> struct XFlowValues { - static const double overflow_value; - static const double underflow_value; - static const double may_underflow_value; + static const double OVERFLOW_VALUE; + static const double UNDERFLOW_VALUE; + static const double MAY_UNDERFLOW_VALUE; }; template static inline T with_errno(T x, int err) { @@ -86,16 +86,16 @@ } template = 0> T overflow(uint32_t sign) { - return xflow(sign, XFlowValues::overflow_value); + return xflow(sign, XFlowValues::OVERFLOW_VALUE); } template = 0> T underflow(uint32_t sign) { - return xflow(sign, XFlowValues::underflow_value); + return xflow(sign, XFlowValues::UNDERFLOW_VALUE); } template = 0> T may_underflow(uint32_t sign) { - return xflow(sign, XFlowValues::may_underflow_value); + return xflow(sign, XFlowValues::MAY_UNDERFLOW_VALUE); } template = 0> diff --git a/libc/src/math/generic/math_utils.cpp b/libc/src/math/generic/math_utils.cpp --- a/libc/src/math/generic/math_utils.cpp +++ b/libc/src/math/generic/math_utils.cpp @@ -10,12 +10,12 @@ namespace __llvm_libc { -constexpr float XFlowValues::overflow_value = 0x1p97f; -constexpr float XFlowValues::underflow_value = 0x1p-95f; -constexpr float XFlowValues::may_underflow_value = 0x1.4p-75f; +constexpr float XFlowValues::OVERFLOW_VALUE = 0x1p97f; +constexpr float XFlowValues::UNDERFLOW_VALUE = 0x1p-95f; +constexpr float XFlowValues::MAY_UNDERFLOW_VALUE = 0x1.4p-75f; -constexpr double XFlowValues::overflow_value = 0x1p769; -constexpr double XFlowValues::underflow_value = 0x1p-767; -constexpr double XFlowValues::may_underflow_value = 0x1.8p-538; +constexpr double XFlowValues::OVERFLOW_VALUE = 0x1p769; +constexpr double XFlowValues::UNDERFLOW_VALUE = 0x1p-767; +constexpr double XFlowValues::MAY_UNDERFLOW_VALUE = 0x1.8p-538; } // namespace __llvm_libc diff --git a/libc/src/math/generic/sincosf.cpp b/libc/src/math/generic/sincosf.cpp --- a/libc/src/math/generic/sincosf.cpp +++ b/libc/src/math/generic/sincosf.cpp @@ -25,9 +25,9 @@ double x = y; double s; int n; - const sincos_t *p = &__SINCOSF_TABLE[0]; + const sincos_t *p = &SINCOSF_TABLE[0]; - if (abstop12(y) < abstop12(pio4)) { + if (abstop12(y) < abstop12(PIO4)) { double x2 = x * x; if (unlikely(abstop12(y) < abstop12(as_float(0x39800000)))) { @@ -47,7 +47,7 @@ s = p->sign[n & 3]; if (n & 2) - p = &__SINCOSF_TABLE[1]; + p = &SINCOSF_TABLE[1]; sincosf_poly(x * s, x * x, p, n, sinp, cosp); } else if (likely(abstop12(y) < abstop12(INFINITY))) { @@ -60,7 +60,7 @@ s = p->sign[(n + sign) & 3]; if ((n + sign) & 2) - p = &__SINCOSF_TABLE[1]; + p = &SINCOSF_TABLE[1]; sincosf_poly(x * s, x * x, p, n, sinp, cosp); } else { diff --git a/libc/src/math/generic/sincosf_data.cpp b/libc/src/math/generic/sincosf_data.cpp --- a/libc/src/math/generic/sincosf_data.cpp +++ b/libc/src/math/generic/sincosf_data.cpp @@ -15,7 +15,7 @@ // The constants and polynomials for sine and cosine. The 2nd entry // computes -cos (x) rather than cos (x) to get negation for free. -constexpr sincos_t __SINCOSF_TABLE[2] = { +constexpr sincos_t SINCOSF_TABLE[2] = { {{1.0, -1.0, -1.0, 1.0}, 0x1.45f306dc9c883p+23, 0x1.921fb54442d18p+0, @@ -42,7 +42,7 @@ // Table with 4/PI to 192 bit precision. To avoid unaligned accesses // only 8 new bits are added per entry, making the table 4 times larger. -constexpr uint32_t __INV_PIO4[24] = { +constexpr uint32_t INV_PIO4[24] = { 0xa2, 0xa2f9, 0xa2f983, 0xa2f9836e, 0xf9836e4e, 0x836e4e44, 0x6e4e4415, 0x4e441529, 0x441529fc, 0x1529fc27, 0x29fc2757, 0xfc2757d1, 0x2757d1f5, 0x57d1f534, 0xd1f534dd, 0xf534ddc0, 0x34ddc0db, 0xddc0db62, diff --git a/libc/src/math/generic/sincosf_utils.h b/libc/src/math/generic/sincosf_utils.h --- a/libc/src/math/generic/sincosf_utils.h +++ b/libc/src/math/generic/sincosf_utils.h @@ -16,9 +16,9 @@ namespace __llvm_libc { // 2PI * 2^-64. -static constexpr double pi63 = 0x1.921fb54442d18p-62; +static constexpr double PI63 = 0x1.921fb54442d18p-62; // PI / 4. -static constexpr double pio4 = 0x1.921fb54442d18p-1; +static constexpr double PIO4 = 0x1.921fb54442d18p-1; // The constants and polynomials for sine and cosine. typedef struct { @@ -30,10 +30,10 @@ } sincos_t; // Polynomial data (the cosine polynomial is negated in the 2nd entry). -extern const sincos_t __SINCOSF_TABLE[2]; +extern const sincos_t SINCOSF_TABLE[2]; // Table with 4/PI to 192 bit precision. -extern const uint32_t __INV_PIO4[]; +extern const uint32_t INV_PIO4[]; // Top 12 bits of the float representation with the sign bit cleared. static inline uint32_t abstop12(float x) { @@ -117,7 +117,7 @@ // can have at most 29 leading zeros after the binary point, the double // precision result is accurate to 33 bits. static inline double reduce_large(uint32_t xi, int *np) { - const uint32_t *arr = &__INV_PIO4[(xi >> 26) & 15]; + const uint32_t *arr = &INV_PIO4[(xi >> 26) & 15]; int shift = (xi >> 23) & 7; uint64_t n, res0, res1, res2; @@ -134,7 +134,7 @@ res0 -= n << 62; double x = (int64_t)res0; *np = n; - return x * pi63; + return x * PI63; } } // namespace __llvm_libc diff --git a/libc/src/math/generic/sinf.cpp b/libc/src/math/generic/sinf.cpp --- a/libc/src/math/generic/sinf.cpp +++ b/libc/src/math/generic/sinf.cpp @@ -25,9 +25,9 @@ double x = y; double s; int n; - const sincos_t *p = &__SINCOSF_TABLE[0]; + const sincos_t *p = &SINCOSF_TABLE[0]; - if (abstop12(y) < abstop12(pio4)) { + if (abstop12(y) < abstop12(PIO4)) { s = x * x; if (unlikely(abstop12(y) < abstop12(as_float(0x39800000)))) { @@ -45,7 +45,7 @@ s = p->sign[n & 3]; if (n & 2) - p = &__SINCOSF_TABLE[1]; + p = &SINCOSF_TABLE[1]; return sinf_poly(x * s, x * x, p, n); } else if (abstop12(y) < abstop12(INFINITY)) { @@ -58,7 +58,7 @@ s = p->sign[(n + sign) & 3]; if ((n + sign) & 2) - p = &__SINCOSF_TABLE[1]; + p = &SINCOSF_TABLE[1]; return sinf_poly(x * s, x * x, p, n); }