[libc-commits] [libc] 75d2fcb - [libc] Add a naming rule for global constants.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Wed Jan 19 14:11:24 PST 2022
Author: Siva Chandra Reddy
Date: 2022-01-19T22:11:16Z
New Revision: 75d2fcb03fa5039d09ee18f4b0d5404c6267af45
URL: https://github.com/llvm/llvm-project/commit/75d2fcb03fa5039d09ee18f4b0d5404c6267af45
DIFF: https://github.com/llvm/llvm-project/commit/75d2fcb03fa5039d09ee18f4b0d5404c6267af45.diff
LOG: [libc] Add a naming rule for global constants.
Reviewed By: michaelrj
Differential Revision: https://reviews.llvm.org/D117645
Added:
Modified:
libc/.clang-tidy
libc/src/__support/FPUtil/aarch64/FEnvImpl.h
libc/src/math/generic/cosf.cpp
libc/src/math/generic/math_utils.cpp
libc/src/math/generic/math_utils.h
libc/src/math/generic/sincosf.cpp
libc/src/math/generic/sincosf_data.cpp
libc/src/math/generic/sincosf_utils.h
libc/src/math/generic/sinf.cpp
Removed:
################################################################################
diff --git a/libc/.clang-tidy b/libc/.clang-tidy
index a1dba68177bfe..741b63b18d6d5 100644
--- a/libc/.clang-tidy
+++ b/libc/.clang-tidy
@@ -18,6 +18,8 @@ CheckOptions:
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
index 305ecffeecd3a..99a0e3e4fef80 100644
--- a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
@@ -34,16 +34,16 @@ struct FEnv {
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 @@ struct FEnv {
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 ? DIVBYZERO : 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 @@ static inline int raise_except(int excepts) {
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 @@ static inline int raise_except(int excepts) {
divfunc(two, three);
uint32_t statusWord = FEnv::getStatusWord();
if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
- FEnv::Inexact))
+ FEnv::INEXACT))
return -1;
}
return 0;
@@ -188,13 +188,13 @@ static inline int get_round() {
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 @@ static inline int set_round(int mode) {
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
index 46e7466a233c1..40d83b108d4cb 100644
--- a/libc/src/math/generic/cosf.cpp
+++ b/libc/src/math/generic/cosf.cpp
@@ -25,9 +25,9 @@ LLVM_LIBC_FUNCTION(float, cosf, (float y)) {
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 @@ LLVM_LIBC_FUNCTION(float, cosf, (float y)) {
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 @@ LLVM_LIBC_FUNCTION(float, cosf, (float y)) {
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.cpp b/libc/src/math/generic/math_utils.cpp
index 309632953fe32..cc922f73fbb45 100644
--- 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<float>::overflow_value = 0x1p97f;
-constexpr float XFlowValues<float>::underflow_value = 0x1p-95f;
-constexpr float XFlowValues<float>::may_underflow_value = 0x1.4p-75f;
+constexpr float XFlowValues<float>::OVERFLOW_VALUE = 0x1p97f;
+constexpr float XFlowValues<float>::UNDERFLOW_VALUE = 0x1p-95f;
+constexpr float XFlowValues<float>::MAY_UNDERFLOW_VALUE = 0x1.4p-75f;
-constexpr double XFlowValues<double>::overflow_value = 0x1p769;
-constexpr double XFlowValues<double>::underflow_value = 0x1p-767;
-constexpr double XFlowValues<double>::may_underflow_value = 0x1.8p-538;
+constexpr double XFlowValues<double>::OVERFLOW_VALUE = 0x1p769;
+constexpr double XFlowValues<double>::UNDERFLOW_VALUE = 0x1p-767;
+constexpr double XFlowValues<double>::MAY_UNDERFLOW_VALUE = 0x1.8p-538;
} // namespace __llvm_libc
diff --git a/libc/src/math/generic/math_utils.h b/libc/src/math/generic/math_utils.h
index ed9a1910a90ee..7dbb78500616f 100644
--- a/libc/src/math/generic/math_utils.h
+++ b/libc/src/math/generic/math_utils.h
@@ -42,15 +42,15 @@ static inline uint32_t top12_bits(double x) { return as_uint64_bits(x) >> 52; }
template <typename T> struct XFlowValues;
template <> struct XFlowValues<float> {
- 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<double> {
- 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 <typename T> static inline T with_errno(T x, int err) {
@@ -86,16 +86,16 @@ T xflow(uint32_t sign, T y) {
}
template <typename T, EnableIfFloatOrDouble<T> = 0> T overflow(uint32_t sign) {
- return xflow(sign, XFlowValues<T>::overflow_value);
+ return xflow(sign, XFlowValues<T>::OVERFLOW_VALUE);
}
template <typename T, EnableIfFloatOrDouble<T> = 0> T underflow(uint32_t sign) {
- return xflow(sign, XFlowValues<T>::underflow_value);
+ return xflow(sign, XFlowValues<T>::UNDERFLOW_VALUE);
}
template <typename T, EnableIfFloatOrDouble<T> = 0>
T may_underflow(uint32_t sign) {
- return xflow(sign, XFlowValues<T>::may_underflow_value);
+ return xflow(sign, XFlowValues<T>::MAY_UNDERFLOW_VALUE);
}
template <typename T, EnableIfFloatOrDouble<T> = 0>
diff --git a/libc/src/math/generic/sincosf.cpp b/libc/src/math/generic/sincosf.cpp
index 44a39d6c95edf..fa05cd24bea42 100644
--- a/libc/src/math/generic/sincosf.cpp
+++ b/libc/src/math/generic/sincosf.cpp
@@ -25,9 +25,9 @@ LLVM_LIBC_FUNCTION(void, sincosf, (float y, float *sinp, float *cosp)) {
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 @@ LLVM_LIBC_FUNCTION(void, sincosf, (float y, float *sinp, float *cosp)) {
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 @@ LLVM_LIBC_FUNCTION(void, sincosf, (float y, float *sinp, float *cosp)) {
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
index 7e5641c054190..ac632652f1692 100644
--- a/libc/src/math/generic/sincosf_data.cpp
+++ b/libc/src/math/generic/sincosf_data.cpp
@@ -15,7 +15,7 @@ namespace __llvm_libc {
// 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 @@ constexpr sincos_t __SINCOSF_TABLE[2] = {
// 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
index 58e6a12c73811..5ddcc9c5b55bf 100644
--- 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 @@ typedef struct {
} 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 @@ static inline double reduce_fast(double x, const sincos_t *p, int *np) {
// 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 @@ static inline double reduce_large(uint32_t xi, int *np) {
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
index 50fb8c3522642..18e88cc9b72c3 100644
--- a/libc/src/math/generic/sinf.cpp
+++ b/libc/src/math/generic/sinf.cpp
@@ -25,9 +25,9 @@ LLVM_LIBC_FUNCTION(float, sinf, (float y)) {
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 @@ LLVM_LIBC_FUNCTION(float, sinf, (float y)) {
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 @@ LLVM_LIBC_FUNCTION(float, sinf, (float y)) {
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);
}
More information about the libc-commits
mailing list