diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td --- a/libc/config/linux/api.td +++ b/libc/config/linux/api.td @@ -20,9 +20,9 @@ }]; } -def StructTm: TypeDecl<"struct tm"> { +def StructTm: TypeDecl<"struct Tm"> { let Decl = [{ - struct tm { + struct Tm { int tm_sec; // seconds after the minute int tm_min; // minutes after the hour int tm_hour; // hours since midnight diff --git a/libc/fuzzing/math/Compare.h b/libc/fuzzing/math/Compare.h --- a/libc/fuzzing/math/Compare.h +++ b/libc/fuzzing/math/Compare.h @@ -13,21 +13,21 @@ #include "src/__support/FPUtil/FPBits.h" template -__llvm_libc::cpp::EnableIfType<__llvm_libc::cpp::IsFloatingPointType::Value, +__llvm_libc::cpp::EnableIfType<__llvm_libc::cpp::IsFloatingPointType::VALUE, bool> ValuesEqual(T x1, T x2) { __llvm_libc::fputil::FPBits bits1(x1); __llvm_libc::fputil::FPBits bits2(x2); // If either is NaN, we want both to be NaN. - if (bits1.isNaN() || bits2.isNaN()) - return bits2.isNaN() && bits2.isNaN(); + if (bits1.is_nan() || bits2.is_nan()) + return bits2.is_nan() && bits2.is_nan(); // For all other values, we want the values to be bitwise equal. return bits1.uintval() == bits2.uintval(); } template -__llvm_libc::cpp::EnableIfType<__llvm_libc::cpp::IsIntegral::Value, bool> +__llvm_libc::cpp::EnableIfType<__llvm_libc::cpp::IsIntegral::VALUE, bool> ValuesEqual(T x1, T x2) { return x1 == x1; } diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -3,7 +3,7 @@ NamedType FILE = NamedType<"FILE">; PtrType FILEPtr = PtrType; RestrictedPtrType FILERestrictedPtr = RestrictedPtrType; - NamedType StructTmType = NamedType<"struct tm">; + NamedType StructTmType = NamedType<"struct Tm">; PtrType StructTmPtr = PtrType; PtrType TimeTTypePtr = PtrType; diff --git a/libc/src/__support/CPP/ArrayRef.h b/libc/src/__support/CPP/ArrayRef.h --- a/libc/src/__support/CPP/ArrayRef.h +++ b/libc/src/__support/CPP/ArrayRef.h @@ -109,7 +109,7 @@ template struct ArrayRef : public internal::ArrayRefBase { private: - static_assert(IsSameV>, + static_assert(IS_SAME_V>, "ArrayRef must have a non-const, non-volatile value_type"); using Impl = internal::ArrayRefBase; using Impl::Impl; @@ -123,7 +123,7 @@ struct MutableArrayRef : public internal::ArrayRefBase { private: static_assert( - IsSameV>, + IS_SAME_V>, "MutableArrayRef must have a non-const, non-volatile value_type"); using Impl = internal::ArrayRefBase; using Impl::Impl; diff --git a/libc/src/__support/CPP/Bitset.h b/libc/src/__support/CPP/Bitset.h --- a/libc/src/__support/CPP/Bitset.h +++ b/libc/src/__support/CPP/Bitset.h @@ -20,17 +20,18 @@ "Cannot create a __llvm_libc::cpp::Bitset of size 0."); constexpr void set(size_t Index) { - Data[Index / BitsPerUnit] |= (uintptr_t{1} << (Index % BitsPerUnit)); + Data[Index / BITS_PER_UNIT] |= (uintptr_t{1} << (Index % BITS_PER_UNIT)); } constexpr bool test(size_t Index) const { - return Data[Index / BitsPerUnit] & (uintptr_t{1} << (Index % BitsPerUnit)); + return Data[Index / BITS_PER_UNIT] & + (uintptr_t{1} << (Index % BITS_PER_UNIT)); } private: - static constexpr size_t BitsPerByte = 8; - static constexpr size_t BitsPerUnit = BitsPerByte * sizeof(uintptr_t); - uintptr_t Data[(NumberOfBits + BitsPerUnit - 1) / BitsPerUnit] = {0}; + static constexpr size_t BITS_PER_BYTE = 8; + static constexpr size_t BITS_PER_UNIT = BITS_PER_BYTE * sizeof(uintptr_t); + uintptr_t Data[(NumberOfBits + BITS_PER_UNIT - 1) / BITS_PER_UNIT] = {0}; }; } // namespace cpp diff --git a/libc/src/__support/CPP/TypeTraits.h b/libc/src/__support/CPP/TypeTraits.h --- a/libc/src/__support/CPP/TypeTraits.h +++ b/libc/src/__support/CPP/TypeTraits.h @@ -19,11 +19,11 @@ using EnableIfType = typename EnableIf::Type; struct TrueValue { - static constexpr bool Value = true; + static constexpr bool VALUE = true; }; struct FalseValue { - static constexpr bool Value = false; + static constexpr bool VALUE = false; }; template struct TypeIdentity { typedef T Type; }; @@ -31,7 +31,7 @@ template struct IsSame : public FalseValue {}; template struct IsSame : public TrueValue {}; template -static constexpr bool IsSameV = IsSame::Value; +static constexpr bool IS_SAME_V = IsSame::VALUE; template struct RemoveCV : public TypeIdentity {}; template struct RemoveCV : public TypeIdentity {}; @@ -43,32 +43,32 @@ template struct IsIntegral { using TypeNoCV = RemoveCVType; - static constexpr bool Value = - IsSameV || IsSameV || - IsSameV || IsSameV || - IsSameV || IsSameV || - IsSameV || IsSameV || - IsSameV || IsSameV || - IsSameV || IsSameV || - IsSameV<__uint128_t, TypeNoCV> || IsSameV<__int128_t, TypeNoCV>; + static constexpr bool VALUE = + IS_SAME_V || IS_SAME_V || + IS_SAME_V || IS_SAME_V || + IS_SAME_V || IS_SAME_V || + IS_SAME_V || IS_SAME_V || + IS_SAME_V || IS_SAME_V || + IS_SAME_V || IS_SAME_V || + IS_SAME_V<__uint128_t, TypeNoCV> || IS_SAME_V<__int128_t, TypeNoCV>; }; template struct IsPointerTypeNoCV : public FalseValue {}; template struct IsPointerTypeNoCV : public TrueValue {}; template struct IsPointerType { - static constexpr bool Value = IsPointerTypeNoCV>::Value; + static constexpr bool VALUE = IsPointerTypeNoCV>::VALUE; }; template struct IsFloatingPointType { using TypeNoCV = RemoveCVType; - static constexpr bool Value = IsSame::Value || - IsSame::Value || - IsSame::Value; + static constexpr bool VALUE = IsSame::VALUE || + IsSame::VALUE || + IsSame::VALUE; }; template struct IsArithmetic { - static constexpr bool Value = - IsIntegral::Value || IsFloatingPointType::Value; + static constexpr bool VALUE = + IsIntegral::VALUE || IsFloatingPointType::VALUE; }; } // namespace cpp diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h --- a/libc/src/__support/FPUtil/BasicOperations.h +++ b/libc/src/__support/FPUtil/BasicOperations.h @@ -17,61 +17,61 @@ namespace fputil { template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T abs(T x) { FPBits bits(x); - bits.setSign(0); + bits.set_sign(0); return T(bits); } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T fmin(T x, T y) { FPBits bitx(x), bity(y); - if (bitx.isNaN()) { + if (bitx.is_nan()) { return y; - } else if (bity.isNaN()) { + } else if (bity.is_nan()) { return x; - } else if (bitx.getSign() != bity.getSign()) { + } else if (bitx.get_sign() != bity.get_sign()) { // To make sure that fmin(+0, -0) == -0 == fmin(-0, +0), whenever x and // y has different signs and both are not NaNs, we return the number // with negative sign. - return (bitx.getSign() ? x : y); + return (bitx.get_sign() ? x : y); } else { return (x < y ? x : y); } } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T fmax(T x, T y) { FPBits bitx(x), bity(y); - if (bitx.isNaN()) { + if (bitx.is_nan()) { return y; - } else if (bity.isNaN()) { + } else if (bity.is_nan()) { return x; - } else if (bitx.getSign() != bity.getSign()) { + } else if (bitx.get_sign() != bity.get_sign()) { // To make sure that fmax(+0, -0) == +0 == fmax(-0, +0), whenever x and // y has different signs and both are not NaNs, we return the number // with positive sign. - return (bitx.getSign() ? y : x); + return (bitx.get_sign() ? y : x); } else { return (x > y ? x : y); } } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T fdim(T x, T y) { FPBits bitx(x), bity(y); - if (bitx.isNaN()) { + if (bitx.is_nan()) { return x; } - if (bity.isNaN()) { + if (bity.is_nan()) { return y; } diff --git a/libc/src/__support/FPUtil/DivisionAndRemainderOperations.h b/libc/src/__support/FPUtil/DivisionAndRemainderOperations.h --- a/libc/src/__support/FPUtil/DivisionAndRemainderOperations.h +++ b/libc/src/__support/FPUtil/DivisionAndRemainderOperations.h @@ -18,38 +18,38 @@ namespace __llvm_libc { namespace fputil { -static constexpr int quotientLSBBits = 3; +static constexpr int QUOTIENT_LSB_BITS = 3; // The implementation is a bit-by-bit algorithm which uses integer division // to evaluate the quotient and remainder. template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T remquo(T x, T y, int &q) { FPBits xbits(x), ybits(y); - if (xbits.isNaN()) + if (xbits.is_nan()) return x; - if (ybits.isNaN()) + if (ybits.is_nan()) return y; - if (xbits.isInf() || ybits.isZero()) - return FPBits::buildNaN(1); + if (xbits.is_inf() || ybits.is_zero()) + return FPBits::build_nan(1); - if (xbits.isZero()) { + if (xbits.is_zero()) { q = 0; return __llvm_libc::fputil::copysign(T(0.0), x); } - if (ybits.isInf()) { + if (ybits.is_inf()) { q = 0; return x; } - bool resultSign = (xbits.getSign() == ybits.getSign() ? false : true); + bool result_sign = (xbits.get_sign() == ybits.get_sign() ? false : true); // Once we know the sign of the result, we can just operate on the absolute // values. The correct sign can be applied to the result after the result // is evaluated. - xbits.setSign(0); - ybits.setSign(0); + xbits.set_sign(0); + ybits.set_sign(0); NormalFloat normalx(xbits), normaly(ybits); int exp = normalx.exponent - normaly.exponent; @@ -58,21 +58,21 @@ q = 0; while (exp >= 0) { - unsigned shiftCount = 0; + unsigned shift_count = 0; typename NormalFloat::UIntType n = mx; - for (shiftCount = 0; n < my; n <<= 1, ++shiftCount) + for (shift_count = 0; n < my; n <<= 1, ++shift_count) ; - if (static_cast(shiftCount) > exp) + if (static_cast(shift_count) > exp) break; - exp -= shiftCount; - if (0 <= exp && exp < quotientLSBBits) + exp -= shift_count; + if (0 <= exp && exp < QUOTIENT_LSB_BITS) q |= (1 << exp); mx = n - my; if (mx == 0) { - q = resultSign ? -q : q; + q = result_sign ? -q : q; return __llvm_libc::fputil::copysign(T(0.0), x); } } @@ -84,33 +84,33 @@ // However, if NormalFloat to native type conversion is updated in future, // then the conversion to native remainder value should be updated // appropriately and some directed tests added. - T nativeRemainder(remainder); + T native_remainder(remainder); T absy = T(ybits); int cmp = remainder.mul2(1).cmp(normaly); if (cmp > 0) { q = q + 1; if (x >= T(0.0)) - nativeRemainder = nativeRemainder - absy; + native_remainder = native_remainder - absy; else - nativeRemainder = absy - nativeRemainder; + native_remainder = absy - native_remainder; } else if (cmp == 0) { if (q & 1) { q += 1; if (x >= T(0.0)) - nativeRemainder = -nativeRemainder; + native_remainder = -native_remainder; } else { if (x < T(0.0)) - nativeRemainder = -nativeRemainder; + native_remainder = -native_remainder; } } else { if (x < T(0.0)) - nativeRemainder = -nativeRemainder; + native_remainder = -native_remainder; } - q = resultSign ? -q : q; - if (nativeRemainder == T(0.0)) + q = result_sign ? -q : q; + if (native_remainder == T(0.0)) return __llvm_libc::fputil::copysign(T(0.0), x); - return nativeRemainder; + return native_remainder; } } // namespace fputil diff --git a/libc/src/__support/FPUtil/DummyFEnvImpl.h b/libc/src/__support/FPUtil/DummyFEnvImpl.h --- a/libc/src/__support/FPUtil/DummyFEnvImpl.h +++ b/libc/src/__support/FPUtil/DummyFEnvImpl.h @@ -17,21 +17,21 @@ // All dummy functions silently succeed. -static inline int clearExcept(int) { return 0; } +static inline int clear_except(int) { return 0; } -static inline int testExcept(int) { return 0; } +static inline int test_except(int) { return 0; } -static inline int setExcept(int) { return 0; } +static inline int set_except(int) { return 0; } -static inline int raiseExcept(int) { return 0; } +static inline int raise_except(int) { return 0; } -static inline int getRound() { return FE_TONEAREST; } +static inline int get_round() { return FE_TONEAREST; } -static inline int setRound(int) { return 0; } +static inline int set_round(int) { return 0; } -static inline int getEnv(fenv_t *) { return 0; } +static inline int get_env(fenv_t *) { return 0; } -static inline int setEnv(const fenv_t *) { return 0; } +static inline int set_env(const fenv_t *) { return 0; } } // namespace fputil } // namespace __llvm_libc diff --git a/libc/src/__support/FPUtil/FMA.h b/libc/src/__support/FPUtil/FMA.h --- a/libc/src/__support/FPUtil/FMA.h +++ b/libc/src/__support/FPUtil/FMA.h @@ -25,7 +25,7 @@ // We have a generic implementation available only for single precision fma as // we restrict it to float values for now. template -static inline cpp::EnableIfType::Value, T> fma(T x, T y, +static inline cpp::EnableIfType::VALUE, T> fma(T x, T y, T z) { return generic::fma(x, y, z); } diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h --- a/libc/src/__support/FPUtil/FPBits.h +++ b/libc/src/__support/FPUtil/FPBits.h @@ -20,11 +20,11 @@ namespace fputil { template struct MantissaWidth { - static constexpr unsigned value = FloatProperties::mantissaWidth; + static constexpr unsigned VALUE = FloatProperties::MANTISSA_WIDTH; }; template struct ExponentWidth { - static constexpr unsigned value = FloatProperties::exponentWidth; + static constexpr unsigned VALUE = FloatProperties::EXPONENT_WIDTH; }; // A generic class to represent single precision, double precision, and quad @@ -36,7 +36,7 @@ // an x87 floating point format. This format is an IEEE 754 extension format. // It is handled as an explicit specialization of this class. template union FPBits { - static_assert(cpp::IsFloatingPointType::Value, + static_assert(cpp::IsFloatingPointType::VALUE, "FPBits instantiated with invalid type."); // Reinterpreting bits as an integer value and interpreting the bits of an @@ -48,58 +48,58 @@ UIntType bits; - void setMantissa(UIntType mantVal) { - mantVal &= (FloatProp::mantissaMask); - bits &= ~(FloatProp::mantissaMask); + void set_mantissa(UIntType mantVal) { + mantVal &= (FloatProp::MANTISSA_MASK); + bits &= ~(FloatProp::MANTISSA_MASK); bits |= mantVal; } - UIntType getMantissa() const { return bits & FloatProp::mantissaMask; } + UIntType get_mantissa() const { return bits & FloatProp::MANTISSA_MASK; } - void setUnbiasedExponent(UIntType expVal) { - expVal = (expVal << (FloatProp::mantissaWidth)) & FloatProp::exponentMask; - bits &= ~(FloatProp::exponentMask); + void set_unbiased_exponent(UIntType expVal) { + expVal = (expVal << (FloatProp::MANTISSA_WIDTH)) & FloatProp::EXPONENT_MASK; + bits &= ~(FloatProp::EXPONENT_MASK); bits |= expVal; } - uint16_t getUnbiasedExponent() const { - return uint16_t((bits & FloatProp::exponentMask) >> - (FloatProp::mantissaWidth)); + uint16_t get_unbiased_exponent() const { + return uint16_t((bits & FloatProp::EXPONENT_MASK) >> + (FloatProp::MANTISSA_WIDTH)); } - void setSign(bool signVal) { - bits &= ~(FloatProp::signMask); - UIntType sign = UIntType(signVal) << (FloatProp::bitWidth - 1); + void set_sign(bool signVal) { + bits &= ~(FloatProp::SIGN_MASK); + UIntType sign = UIntType(signVal) << (FloatProp::BIT_WIDTH - 1); bits |= sign; } - bool getSign() const { - return ((bits & FloatProp::signMask) >> (FloatProp::bitWidth - 1)); + bool get_sign() const { + return ((bits & FloatProp::SIGN_MASK) >> (FloatProp::BIT_WIDTH - 1)); } T val; static_assert(sizeof(T) == sizeof(UIntType), "Data type and integral representation have different sizes."); - static constexpr int exponentBias = (1 << (ExponentWidth::value - 1)) - 1; - static constexpr int maxExponent = (1 << ExponentWidth::value) - 1; + static constexpr int EXPONENT_BIAS = (1 << (ExponentWidth::VALUE - 1)) - 1; + static constexpr int MAX_EXPONENT = (1 << ExponentWidth::VALUE) - 1; - static constexpr UIntType minSubnormal = UIntType(1); - static constexpr UIntType maxSubnormal = - (UIntType(1) << MantissaWidth::value) - 1; - static constexpr UIntType minNormal = - (UIntType(1) << MantissaWidth::value); - static constexpr UIntType maxNormal = - ((UIntType(maxExponent) - 1) << MantissaWidth::value) | maxSubnormal; + static constexpr UIntType MIN_SUBNORMAL = UIntType(1); + static constexpr UIntType MAX_SUBNORMAL = + (UIntType(1) << MantissaWidth::VALUE) - 1; + static constexpr UIntType MIN_NORMAL = + (UIntType(1) << MantissaWidth::VALUE); + static constexpr UIntType MAX_NORMAL = + ((UIntType(MAX_EXPONENT) - 1) << MantissaWidth::VALUE) | MAX_SUBNORMAL; // We don't want accidental type promotions/conversions so we require exact // type match. template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> explicit FPBits(XType x) : val(x) {} template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> explicit FPBits(XType x) : bits(x) {} FPBits() : bits(0) {} @@ -108,43 +108,45 @@ UIntType uintval() const { return bits; } - int getExponent() const { return int(getUnbiasedExponent()) - exponentBias; } + int get_exponent() const { + return int(get_unbiased_exponent()) - EXPONENT_BIAS; + } - bool isZero() const { - return getMantissa() == 0 && getUnbiasedExponent() == 0; + bool is_zero() const { + return get_mantissa() == 0 && get_unbiased_exponent() == 0; } - bool isInf() const { - return getMantissa() == 0 && getUnbiasedExponent() == maxExponent; + bool is_inf() const { + return get_mantissa() == 0 && get_unbiased_exponent() == MAX_EXPONENT; } - bool isNaN() const { - return getUnbiasedExponent() == maxExponent && getMantissa() != 0; + bool is_nan() const { + return get_unbiased_exponent() == MAX_EXPONENT && get_mantissa() != 0; } - bool isInfOrNaN() const { return getUnbiasedExponent() == maxExponent; } + bool is_inf_or_nan() const { return get_unbiased_exponent() == MAX_EXPONENT; } static FPBits zero() { return FPBits(); } - static FPBits negZero() { + static FPBits neg_zero() { return FPBits(UIntType(1) << (sizeof(UIntType) * 8 - 1)); } static FPBits inf() { FPBits bits; - bits.setUnbiasedExponent(maxExponent); + bits.set_unbiased_exponent(MAX_EXPONENT); return bits; } - static FPBits negInf() { + static FPBits neg_inf() { FPBits bits = inf(); - bits.setSign(1); + bits.set_sign(1); return bits; } - static T buildNaN(UIntType v) { + static T build_nan(UIntType v) { FPBits bits = inf(); - bits.setMantissa(v); + bits.set_mantissa(v); return T(bits); } }; diff --git a/libc/src/__support/FPUtil/FloatProperties.h b/libc/src/__support/FPUtil/FloatProperties.h --- a/libc/src/__support/FPUtil/FloatProperties.h +++ b/libc/src/__support/FPUtil/FloatProperties.h @@ -22,20 +22,20 @@ static_assert(sizeof(BitsType) == sizeof(float), "Unexpected size of 'float' type."); - static constexpr uint32_t bitWidth = sizeof(BitsType) << 3; + static constexpr uint32_t BIT_WIDTH = sizeof(BitsType) << 3; - static constexpr uint32_t mantissaWidth = 23; - static constexpr uint32_t exponentWidth = 8; - static constexpr BitsType mantissaMask = (BitsType(1) << mantissaWidth) - 1; - static constexpr BitsType signMask = BitsType(1) - << (exponentWidth + mantissaWidth); - static constexpr BitsType exponentMask = ~(signMask | mantissaMask); - static constexpr uint32_t exponentBias = 127; + static constexpr uint32_t MANTISSA_WIDTH = 23; + static constexpr uint32_t EXPONENT_WIDTH = 8; + static constexpr BitsType MANTISSA_MASK = (BitsType(1) << MANTISSA_WIDTH) - 1; + static constexpr BitsType SIGN_MASK = BitsType(1) + << (EXPONENT_WIDTH + MANTISSA_WIDTH); + static constexpr BitsType EXPONENT_MASK = ~(SIGN_MASK | MANTISSA_MASK); + static constexpr uint32_t EXPONENT_BIAS = 127; // If a number x is a NAN, then it is a quiet NAN if: // QuietNaNMask & bits(x) != 0 // Else, it is a signalling NAN. - static constexpr BitsType quietNaNMask = 0x00400000U; + static constexpr BitsType QUIET_NAN_MASK = 0x00400000U; }; template <> struct FloatProperties { @@ -43,20 +43,20 @@ static_assert(sizeof(BitsType) == sizeof(double), "Unexpected size of 'double' type."); - static constexpr uint32_t bitWidth = sizeof(BitsType) << 3; + static constexpr uint32_t BIT_WIDTH = sizeof(BitsType) << 3; - static constexpr uint32_t mantissaWidth = 52; - static constexpr uint32_t exponentWidth = 11; - static constexpr BitsType mantissaMask = (BitsType(1) << mantissaWidth) - 1; - static constexpr BitsType signMask = BitsType(1) - << (exponentWidth + mantissaWidth); - static constexpr BitsType exponentMask = ~(signMask | mantissaMask); - static constexpr uint32_t exponentBias = 1023; + static constexpr uint32_t MANTISSA_WIDTH = 52; + static constexpr uint32_t EXPONENT_WIDTH = 11; + static constexpr BitsType MANTISSA_MASK = (BitsType(1) << MANTISSA_WIDTH) - 1; + static constexpr BitsType SIGN_MASK = BitsType(1) + << (EXPONENT_WIDTH + MANTISSA_WIDTH); + static constexpr BitsType EXPONENT_MASK = ~(SIGN_MASK | MANTISSA_MASK); + static constexpr uint32_t EXPONENT_BIAS = 1023; // If a number x is a NAN, then it is a quiet NAN if: // QuietNaNMask & bits(x) != 0 // Else, it is a signalling NAN. - static constexpr BitsType quietNaNMask = 0x0008000000000000ULL; + static constexpr BitsType QUIET_NAN_MASK = 0x0008000000000000ULL; }; #if defined(LONG_DOUBLE_IS_DOUBLE) @@ -67,25 +67,25 @@ static_assert(sizeof(BitsType) == sizeof(double), "Unexpected size of 'double' type."); - static constexpr uint32_t bitWidth = FloatProperties::bitWidth; + static constexpr uint32_t BIT_WIDTH = FloatProperties::BIT_WIDTH; - static constexpr uint32_t mantissaWidth = - FloatProperties::mantissaWidth; - static constexpr uint32_t exponentWidth = - FloatProperties::exponentWidth; - static constexpr BitsType mantissaMask = - FloatProperties::mantissaMask; - static constexpr BitsType signMask = FloatProperties::signMask; - static constexpr BitsType exponentMask = - FloatProperties::exponentMask; - static constexpr uint32_t exponentBias = - FloatProperties::exponentBias; + static constexpr uint32_t MANTISSA_WIDTH = + FloatProperties::MANTISSA_WIDTH; + static constexpr uint32_t EXPONENT_WIDTH = + FloatProperties::EXPONENT_WIDTH; + static constexpr BitsType MANTISSA_MASK = + FloatProperties::MANTISSA_MASK; + static constexpr BitsType SIGN_MASK = FloatProperties::SIGN_MASK; + static constexpr BitsType EXPONENT_MASK = + FloatProperties::EXPONENT_MASK; + static constexpr uint32_t EXPONENT_BIAS = + FloatProperties::EXPONENT_BIAS; // If a number x is a NAN, then it is a quiet NAN if: // QuietNaNMask & bits(x) != 0 // Else, it is a signalling NAN. - static constexpr BitsType quietNaNMask = - FloatProperties::quietNaNMask; + static constexpr BitsType QUIET_NAN_MASK = + FloatProperties::QUIET_NAN_MASK; }; #elif defined(SPECIAL_X86_LONG_DOUBLE) // Properties for numbers represented in 80 bits long double on non-Windows x86 @@ -95,21 +95,22 @@ static_assert(sizeof(BitsType) == sizeof(long double), "Unexpected size of 'long double' type."); - static constexpr uint32_t bitWidth = (sizeof(BitsType) << 3) - 48; + static constexpr uint32_t BIT_WIDTH = (sizeof(BitsType) << 3) - 48; - static constexpr uint32_t mantissaWidth = 63; - static constexpr uint32_t exponentWidth = 15; - static constexpr BitsType mantissaMask = (BitsType(1) << mantissaWidth) - 1; - static constexpr BitsType signMask = BitsType(1) - << (exponentWidth + mantissaWidth + 1); - static constexpr BitsType exponentMask = ((BitsType(1) << exponentWidth) - 1) - << (mantissaWidth + 1); - static constexpr uint32_t exponentBias = 16383; + static constexpr uint32_t MANTISSA_WIDTH = 63; + static constexpr uint32_t EXPONENT_WIDTH = 15; + static constexpr BitsType MANTISSA_MASK = (BitsType(1) << MANTISSA_WIDTH) - 1; + static constexpr BitsType SIGN_MASK = + BitsType(1) << (EXPONENT_WIDTH + MANTISSA_WIDTH + 1); + static constexpr BitsType EXPONENT_MASK = + ((BitsType(1) << EXPONENT_WIDTH) - 1) << (MANTISSA_WIDTH + 1); + static constexpr uint32_t EXPONENT_BIAS = 16383; // If a number x is a NAN, then it is a quiet NAN if: // QuietNaNMask & bits(x) != 0 // Else, it is a signalling NAN. - static constexpr BitsType quietNaNMask = BitsType(1) << (mantissaWidth - 1); + static constexpr BitsType QUIET_NAN_MASK = BitsType(1) + << (MANTISSA_WIDTH - 1); }; #else // Properties for numbers represented in 128 bits long double on non x86 @@ -119,20 +120,21 @@ static_assert(sizeof(BitsType) == sizeof(long double), "Unexpected size of 'long double' type."); - static constexpr uint32_t bitWidth = sizeof(BitsType) << 3; + static constexpr uint32_t BIT_WIDTH = sizeof(BitsType) << 3; - static constexpr uint32_t mantissaWidth = 112; - static constexpr uint32_t exponentWidth = 15; - static constexpr BitsType mantissaMask = (BitsType(1) << mantissaWidth) - 1; - static constexpr BitsType signMask = BitsType(1) - << (exponentWidth + mantissaWidth); - static constexpr BitsType exponentMask = ~(signMask | mantissaMask); - static constexpr uint32_t exponentBias = 16383; + static constexpr uint32_t MANTISSA_WIDTH = 112; + static constexpr uint32_t EXPONENT_WIDTH = 15; + static constexpr BitsType MANTISSA_MASK = (BitsType(1) << MANTISSA_WIDTH) - 1; + static constexpr BitsType SIGN_MASK = BitsType(1) + << (EXPONENT_WIDTH + MANTISSA_WIDTH); + static constexpr BitsType EXPONENT_MASK = ~(SIGN_MASK | MANTISSA_MASK); + static constexpr uint32_t EXPONENT_BIAS = 16383; // If a number x is a NAN, then it is a quiet NAN if: // QuietNaNMask & bits(x) != 0 // Else, it is a signalling NAN. - static constexpr BitsType quietNaNMask = BitsType(1) << (mantissaWidth - 1); + static constexpr BitsType QUIET_NAN_MASK = BitsType(1) + << (MANTISSA_WIDTH - 1); }; #endif diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h --- a/libc/src/__support/FPUtil/Hypot.h +++ b/libc/src/__support/FPUtil/Hypot.h @@ -18,34 +18,35 @@ namespace internal { -template static inline T findLeadingOne(T mant, int &shift_length); +template +static inline T find_leading_one(T mant, int &shift_length); template <> -inline uint32_t findLeadingOne(uint32_t mant, int &shift_length) { +inline uint32_t find_leading_one(uint32_t mant, int &shift_length) { shift_length = 0; - constexpr int nsteps = 5; - constexpr uint32_t bounds[nsteps] = {1 << 16, 1 << 8, 1 << 4, 1 << 2, 1 << 1}; - constexpr int shifts[nsteps] = {16, 8, 4, 2, 1}; - for (int i = 0; i < nsteps; ++i) { - if (mant >= bounds[i]) { - shift_length += shifts[i]; - mant >>= shifts[i]; + constexpr int NSTEPS = 5; + constexpr uint32_t BOUNDS[NSTEPS] = {1 << 16, 1 << 8, 1 << 4, 1 << 2, 1 << 1}; + constexpr int SHIFTS[NSTEPS] = {16, 8, 4, 2, 1}; + for (int i = 0; i < NSTEPS; ++i) { + if (mant >= BOUNDS[i]) { + shift_length += SHIFTS[i]; + mant >>= SHIFTS[i]; } } return 1U << shift_length; } template <> -inline uint64_t findLeadingOne(uint64_t mant, int &shift_length) { +inline uint64_t find_leading_one(uint64_t mant, int &shift_length) { shift_length = 0; - constexpr int nsteps = 6; - constexpr uint64_t bounds[nsteps] = {1ULL << 32, 1ULL << 16, 1ULL << 8, + constexpr int NSTEPS = 6; + constexpr uint64_t BOUNDS[NSTEPS] = {1ULL << 32, 1ULL << 16, 1ULL << 8, 1ULL << 4, 1ULL << 2, 1ULL << 1}; - constexpr int shifts[nsteps] = {32, 16, 8, 4, 2, 1}; - for (int i = 0; i < nsteps; ++i) { - if (mant >= bounds[i]) { - shift_length += shifts[i]; - mant >>= shifts[i]; + constexpr int SHIFTS[NSTEPS] = {32, 16, 8, 4, 2, 1}; + for (int i = 0; i < NSTEPS; ++i) { + if (mant >= BOUNDS[i]) { + shift_length += SHIFTS[i]; + mant >>= SHIFTS[i]; } } return 1ULL << shift_length; @@ -116,7 +117,7 @@ // - HYPOT(x, y) is NaN if x or y is NaN. // template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T hypot(T x, T y) { using FPBits_t = FPBits; using UIntType = typename FPBits::UIntType; @@ -124,13 +125,13 @@ FPBits_t x_bits(x), y_bits(y); - if (x_bits.isInf() || y_bits.isInf()) { + if (x_bits.is_inf() || y_bits.is_inf()) { return T(FPBits_t::inf()); } - if (x_bits.isNaN()) { + if (x_bits.is_nan()) { return x; } - if (y_bits.isNaN()) { + if (y_bits.is_nan()) { return y; } @@ -139,33 +140,33 @@ DUIntType a_mant_sq, b_mant_sq; bool sticky_bits; - if ((x_bits.getUnbiasedExponent() >= - y_bits.getUnbiasedExponent() + MantissaWidth::value + 2) || + if ((x_bits.get_unbiased_exponent() >= + y_bits.get_unbiased_exponent() + MantissaWidth::VALUE + 2) || (y == 0)) { return abs(x); - } else if ((y_bits.getUnbiasedExponent() >= - x_bits.getUnbiasedExponent() + MantissaWidth::value + 2) || + } else if ((y_bits.get_unbiased_exponent() >= + x_bits.get_unbiased_exponent() + MantissaWidth::VALUE + 2) || (x == 0)) { - y_bits.setSign(0); + y_bits.set_sign(0); return abs(y); } if (x >= y) { - a_exp = x_bits.getUnbiasedExponent(); - a_mant = x_bits.getMantissa(); - b_exp = y_bits.getUnbiasedExponent(); - b_mant = y_bits.getMantissa(); + a_exp = x_bits.get_unbiased_exponent(); + a_mant = x_bits.get_mantissa(); + b_exp = y_bits.get_unbiased_exponent(); + b_mant = y_bits.get_mantissa(); } else { - a_exp = y_bits.getUnbiasedExponent(); - a_mant = y_bits.getMantissa(); - b_exp = x_bits.getUnbiasedExponent(); - b_mant = x_bits.getMantissa(); + a_exp = y_bits.get_unbiased_exponent(); + a_mant = y_bits.get_mantissa(); + b_exp = x_bits.get_unbiased_exponent(); + b_mant = x_bits.get_mantissa(); } out_exp = a_exp; // Add an extra bit to simplify the final rounding bit computation. - constexpr UIntType one = UIntType(1) << (MantissaWidth::value + 1); + constexpr UIntType ONE = UIntType(1) << (MantissaWidth::VALUE + 1); a_mant <<= 1; b_mant <<= 1; @@ -173,15 +174,15 @@ UIntType leading_one; int y_mant_width; if (a_exp != 0) { - leading_one = one; - a_mant |= one; - y_mant_width = MantissaWidth::value + 1; + leading_one = ONE; + a_mant |= ONE; + y_mant_width = MantissaWidth::VALUE + 1; } else { - leading_one = internal::findLeadingOne(a_mant, y_mant_width); + leading_one = internal::find_leading_one(a_mant, y_mant_width); } if (b_exp != 0) { - b_mant |= one; + b_mant |= ONE; } a_mant_sq = static_cast(a_mant) * a_mant; @@ -201,13 +202,13 @@ DUIntType sum = a_mant_sq + b_mant_sq; if (sum >= (DUIntType(1) << (2 * y_mant_width + 2))) { // a^2 + b^2 >= 4* leading_one^2, so we will need an extra bit to the left. - if (leading_one == one) { + if (leading_one == ONE) { // For normal result, we discard the last 2 bits of the sum and increase // the exponent. sticky_bits = sticky_bits || ((sum & 0x3U) != 0); sum >>= 2; ++out_exp; - if (out_exp >= FPBits_t::maxExponent) { + if (out_exp >= FPBits_t::MAX_EXPONENT) { return T(FPBits_t::inf()); } } else { @@ -218,48 +219,48 @@ } } - UIntType Y = leading_one; - UIntType R = static_cast(sum >> y_mant_width) - leading_one; - UIntType tailBits = static_cast(sum) & (leading_one - 1); + UIntType y_new = leading_one; + UIntType r = static_cast(sum >> y_mant_width) - leading_one; + UIntType tail_bits = static_cast(sum) & (leading_one - 1); for (UIntType current_bit = leading_one >> 1; current_bit; current_bit >>= 1) { - R = (R << 1) + ((tailBits & current_bit) ? 1 : 0); - UIntType tmp = (Y << 1) + current_bit; // 2*y(n - 1) + 2^(-n) - if (R >= tmp) { - R -= tmp; - Y += current_bit; + r = (r << 1) + ((tail_bits & current_bit) ? 1 : 0); + UIntType tmp = (y_new << 1) + current_bit; // 2*y_new(n - 1) + 2^(-n) + if (r >= tmp) { + r -= tmp; + y_new += current_bit; } } - bool round_bit = Y & UIntType(1); - bool lsb = Y & UIntType(2); + bool round_bit = y_new & UIntType(1); + bool lsb = y_new & UIntType(2); - if (Y >= one) { - Y -= one; + if (y_new >= ONE) { + y_new -= ONE; if (out_exp == 0) { out_exp = 1; } } - Y >>= 1; + y_new >>= 1; // Round to the nearest, tie to even. - if (round_bit && (lsb || sticky_bits || (R != 0))) { - ++Y; + if (round_bit && (lsb || sticky_bits || (r != 0))) { + ++y_new; } - if (Y >= (one >> 1)) { - Y -= one >> 1; + if (y_new >= (ONE >> 1)) { + y_new -= ONE >> 1; ++out_exp; - if (out_exp >= FPBits_t::maxExponent) { + if (out_exp >= FPBits_t::MAX_EXPONENT) { return T(FPBits_t::inf()); } } - Y |= static_cast(out_exp) << MantissaWidth::value; - return *reinterpret_cast(&Y); + y_new |= static_cast(out_exp) << MantissaWidth::VALUE; + return *reinterpret_cast(&y_new); } } // namespace fputil diff --git a/libc/src/__support/FPUtil/LongDoubleBitsX86.h b/libc/src/__support/FPUtil/LongDoubleBitsX86.h --- a/libc/src/__support/FPUtil/LongDoubleBitsX86.h +++ b/libc/src/__support/FPUtil/LongDoubleBitsX86.h @@ -19,68 +19,70 @@ template struct Padding; // i386 padding. -template <> struct Padding<4> { static constexpr unsigned value = 16; }; +template <> struct Padding<4> { static constexpr unsigned VALUE = 16; }; // x86_64 padding. -template <> struct Padding<8> { static constexpr unsigned value = 48; }; +template <> struct Padding<8> { static constexpr unsigned VALUE = 48; }; template <> union FPBits { using UIntType = __uint128_t; - static constexpr int exponentBias = 0x3FFF; - static constexpr int maxExponent = 0x7FFF; - static constexpr UIntType minSubnormal = UIntType(1); + static constexpr int EXPONENT_BIAS = 0x3FFF; + static constexpr int MAX_EXPONENT = 0x7FFF; + static constexpr UIntType MIN_SUBNORMAL = UIntType(1); // Subnormal numbers include the implicit bit in x86 long double formats. - static constexpr UIntType maxSubnormal = - (UIntType(1) << (MantissaWidth::value)) - 1; - static constexpr UIntType minNormal = - (UIntType(3) << MantissaWidth::value); - static constexpr UIntType maxNormal = - ((UIntType(maxExponent) - 1) << (MantissaWidth::value + 1)) | - (UIntType(1) << MantissaWidth::value) | maxSubnormal; + static constexpr UIntType MAX_SUBNORMAL = + (UIntType(1) << (MantissaWidth::VALUE)) - 1; + static constexpr UIntType MIN_NORMAL = + (UIntType(3) << MantissaWidth::VALUE); + static constexpr UIntType MAX_NORMAL = + ((UIntType(MAX_EXPONENT) - 1) + << (MantissaWidth::VALUE + 1)) | + (UIntType(1) << MantissaWidth::VALUE) | MAX_SUBNORMAL; using FloatProp = FloatProperties; UIntType bits; - void setMantissa(UIntType mantVal) { - mantVal &= (FloatProp::mantissaMask); - bits &= ~(FloatProp::mantissaMask); + void set_mantissa(UIntType mantVal) { + mantVal &= (FloatProp::MANTISSA_MASK); + bits &= ~(FloatProp::MANTISSA_MASK); bits |= mantVal; } - UIntType getMantissa() const { return bits & FloatProp::mantissaMask; } + UIntType get_mantissa() const { return bits & FloatProp::MANTISSA_MASK; } - void setUnbiasedExponent(UIntType expVal) { - expVal = (expVal << (FloatProp::bitWidth - 1 - FloatProp::exponentWidth)) & - FloatProp::exponentMask; - bits &= ~(FloatProp::exponentMask); + void set_unbiased_exponent(UIntType expVal) { + expVal = + (expVal << (FloatProp::BIT_WIDTH - 1 - FloatProp::EXPONENT_WIDTH)) & + FloatProp::EXPONENT_MASK; + bits &= ~(FloatProp::EXPONENT_MASK); bits |= expVal; } - uint16_t getUnbiasedExponent() const { - return uint16_t((bits & FloatProp::exponentMask) >> - (FloatProp::bitWidth - 1 - FloatProp::exponentWidth)); + uint16_t get_unbiased_exponent() const { + return uint16_t((bits & FloatProp::EXPONENT_MASK) >> + (FloatProp::BIT_WIDTH - 1 - FloatProp::EXPONENT_WIDTH)); } - void setImplicitBit(bool implicitVal) { - bits &= ~(UIntType(1) << FloatProp::mantissaWidth); - bits |= (UIntType(implicitVal) << FloatProp::mantissaWidth); + void set_implicit_bit(bool implicitVal) { + bits &= ~(UIntType(1) << FloatProp::MANTISSA_WIDTH); + bits |= (UIntType(implicitVal) << FloatProp::MANTISSA_WIDTH); } - bool getImplicitBit() const { - return ((bits & (UIntType(1) << FloatProp::mantissaWidth)) >> - FloatProp::mantissaWidth); + bool get_implicit_bit() const { + return ((bits & (UIntType(1) << FloatProp::MANTISSA_WIDTH)) >> + FloatProp::MANTISSA_WIDTH); } - void setSign(bool signVal) { - bits &= ~(FloatProp::signMask); - UIntType sign1 = UIntType(signVal) << (FloatProp::bitWidth - 1); + void set_sign(bool signVal) { + bits &= ~(FloatProp::SIGN_MASK); + UIntType sign1 = UIntType(signVal) << (FloatProp::BIT_WIDTH - 1); bits |= sign1; } - bool getSign() const { - return ((bits & FloatProp::signMask) >> (FloatProp::bitWidth - 1)); + bool get_sign() const { + return ((bits & FloatProp::SIGN_MASK) >> (FloatProp::BIT_WIDTH - 1)); } long double val; @@ -88,7 +90,7 @@ FPBits() : bits(0) {} template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> explicit FPBits(XType x) : val(x) { // bits starts uninitialized, and setting it to a long double only // overwrites the first 80 bits. This clears those upper bits. @@ -96,80 +98,80 @@ } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> explicit FPBits(XType x) : bits(x) {} operator long double() { return val; } UIntType uintval() { // We zero the padding bits as they can contain garbage. - static constexpr UIntType mask = + static constexpr UIntType MASK = (UIntType(1) << (sizeof(long double) * 8 - - Padding::value)) - + Padding::VALUE)) - 1; - return bits & mask; + return bits & MASK; } - int getExponent() const { - if (getUnbiasedExponent() == 0) - return int(1) - exponentBias; - return int(getUnbiasedExponent()) - exponentBias; + int get_exponent() const { + if (get_unbiased_exponent() == 0) + return int(1) - EXPONENT_BIAS; + return int(get_unbiased_exponent()) - EXPONENT_BIAS; } - bool isZero() const { - return getUnbiasedExponent() == 0 && getMantissa() == 0 && - getImplicitBit() == 0; + bool is_zero() const { + return get_unbiased_exponent() == 0 && get_mantissa() == 0 && + get_implicit_bit() == 0; } - bool isInf() const { - return getUnbiasedExponent() == maxExponent && getMantissa() == 0 && - getImplicitBit() == 1; + bool is_inf() const { + return get_unbiased_exponent() == MAX_EXPONENT && get_mantissa() == 0 && + get_implicit_bit() == 1; } - bool isNaN() const { - if (getUnbiasedExponent() == maxExponent) { - return (getImplicitBit() == 0) || getMantissa() != 0; - } else if (getUnbiasedExponent() != 0) { - return getImplicitBit() == 0; + bool is_nan() const { + if (get_unbiased_exponent() == MAX_EXPONENT) { + return (get_implicit_bit() == 0) || get_mantissa() != 0; + } else if (get_unbiased_exponent() != 0) { + return get_implicit_bit() == 0; } return false; } - bool isInfOrNaN() const { - return (getUnbiasedExponent() == maxExponent) || - (getUnbiasedExponent() != 0 && getImplicitBit() == 0); + bool is_inf_or_nan() const { + return (get_unbiased_exponent() == MAX_EXPONENT) || + (get_unbiased_exponent() != 0 && get_implicit_bit() == 0); } // Methods below this are used by tests. static FPBits zero() { return FPBits(0.0l); } - static FPBits negZero() { + static FPBits neg_zero() { FPBits bits(0.0l); - bits.setSign(1); + bits.set_sign(1); return bits; } static FPBits inf() { FPBits bits(0.0l); - bits.setUnbiasedExponent(maxExponent); - bits.setImplicitBit(1); + bits.set_unbiased_exponent(MAX_EXPONENT); + bits.set_implicit_bit(1); return bits; } - static FPBits negInf() { + static FPBits neg_inf() { FPBits bits(0.0l); - bits.setUnbiasedExponent(maxExponent); - bits.setImplicitBit(1); - bits.setSign(1); + bits.set_unbiased_exponent(MAX_EXPONENT); + bits.set_implicit_bit(1); + bits.set_sign(1); return bits; } - static long double buildNaN(UIntType v) { + static long double build_nan(UIntType v) { FPBits bits(0.0l); - bits.setUnbiasedExponent(maxExponent); - bits.setImplicitBit(1); - bits.setMantissa(v); + bits.set_unbiased_exponent(MAX_EXPONENT); + bits.set_implicit_bit(1); + bits.set_mantissa(v); return bits; } }; diff --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h --- a/libc/src/__support/FPUtil/ManipulationFunctions.h +++ b/libc/src/__support/FPUtil/ManipulationFunctions.h @@ -23,12 +23,12 @@ namespace fputil { template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T frexp(T x, int &exp) { FPBits bits(x); - if (bits.isInfOrNaN()) + if (bits.is_inf_or_nan()) return x; - if (bits.isZero()) { + if (bits.is_zero()) { exp = 0; return x; } @@ -40,21 +40,21 @@ } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T modf(T x, T &iptr) { FPBits bits(x); - if (bits.isZero() || bits.isNaN()) { + if (bits.is_zero() || bits.is_nan()) { iptr = x; return x; - } else if (bits.isInf()) { + } else if (bits.is_inf()) { iptr = x; - return bits.getSign() ? T(FPBits::negZero()) : T(FPBits::zero()); + return bits.get_sign() ? T(FPBits::neg_zero()) : T(FPBits::zero()); } else { iptr = trunc(x); if (x == iptr) { // If x is already an integer value, then return zero with the right // sign. - return bits.getSign() ? T(FPBits::negZero()) : T(FPBits::zero()); + return bits.get_sign() ? T(FPBits::neg_zero()) : T(FPBits::zero()); } else { return x - iptr; } @@ -62,24 +62,24 @@ } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T copysign(T x, T y) { FPBits xbits(x); - xbits.setSign(FPBits(y).getSign()); + xbits.set_sign(FPBits(y).get_sign()); return T(xbits); } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline int ilogb(T x) { // TODO: Raise appropriate floating point exceptions and set errno to the // an appropriate error value wherever relevant. FPBits bits(x); - if (bits.isZero()) { + if (bits.is_zero()) { return FP_ILOGB0; - } else if (bits.isNaN()) { + } else if (bits.is_nan()) { return FP_ILOGBNAN; - } else if (bits.isInf()) { + } else if (bits.is_inf()) { return INT_MAX; } @@ -99,16 +99,16 @@ } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T logb(T x) { FPBits bits(x); - if (bits.isZero()) { + if (bits.is_zero()) { // TODO(Floating point exception): Raise div-by-zero exception. // TODO(errno): POSIX requires setting errno to ERANGE. - return T(FPBits::negInf()); - } else if (bits.isNaN()) { + return T(FPBits::neg_inf()); + } else if (bits.is_nan()) { return x; - } else if (bits.isInf()) { + } else if (bits.is_inf()) { // Return positive infinity. return T(FPBits::inf()); } @@ -118,10 +118,10 @@ } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T ldexp(T x, int exp) { FPBits bits(x); - if (bits.isZero() || bits.isInfOrNaN() || exp == 0) + if (bits.is_zero() || bits.is_inf_or_nan() || exp == 0) return x; // NormalFloat uses int32_t to store the true exponent value. We should ensure @@ -130,13 +130,13 @@ // early. Because the result of the ldexp operation can be a subnormal number, // we need to accommodate the (mantissaWidht + 1) worth of shift in // calculating the limit. - int expLimit = FPBits::maxExponent + MantissaWidth::value + 1; - if (exp > expLimit) - return bits.getSign() ? T(FPBits::negInf()) : T(FPBits::inf()); + int exp_limit = FPBits::MAX_EXPONENT + MantissaWidth::VALUE + 1; + if (exp > exp_limit) + return bits.get_sign() ? T(FPBits::neg_inf()) : T(FPBits::inf()); // Similarly on the negative side we return zero early if |exp| is too small. - if (exp < -expLimit) - return bits.getSign() ? T(FPBits::negZero()) : T(FPBits::zero()); + if (exp < -exp_limit) + return bits.get_sign() ? T(FPBits::neg_zero()) : T(FPBits::zero()); // For all other values, NormalFloat to T conversion handles it the right way. NormalFloat normal(bits); @@ -145,33 +145,33 @@ } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T nextafter(T from, T to) { - FPBits fromBits(from); - if (fromBits.isNaN()) + FPBits from_bits(from); + if (from_bits.is_nan()) return from; - FPBits toBits(to); - if (toBits.isNaN()) + FPBits to_bits(to); + if (to_bits.is_nan()) return to; if (from == to) return to; using UIntType = typename FPBits::UIntType; - UIntType intVal = fromBits.uintval(); - UIntType signMask = (UIntType(1) << (sizeof(T) * 8 - 1)); + UIntType int_val = from_bits.uintval(); + UIntType sign_mask = (UIntType(1) << (sizeof(T) * 8 - 1)); if (from != T(0.0)) { if ((from < to) == (from > T(0.0))) { - ++intVal; + ++int_val; } else { - --intVal; + --int_val; } } else { - intVal = (toBits.uintval() & signMask) + UIntType(1); + int_val = (to_bits.uintval() & sign_mask) + UIntType(1); } - return *reinterpret_cast(&intVal); + return *reinterpret_cast(&int_val); // TODO: Raise floating point exceptions as required by the standard. } diff --git a/libc/src/__support/FPUtil/NearestIntegerOperations.h b/libc/src/__support/FPUtil/NearestIntegerOperations.h --- a/libc/src/__support/FPUtil/NearestIntegerOperations.h +++ b/libc/src/__support/FPUtil/NearestIntegerOperations.h @@ -23,7 +23,7 @@ namespace fputil { template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T trunc(T x) { FPBits bits(x); @@ -31,73 +31,73 @@ // If it is zero also we should return it as is, but the logic // later in this function takes care of it. But not doing a zero // check, we improve the run time of non-zero values. - if (bits.isInfOrNaN()) + if (bits.is_inf_or_nan()) return x; - int exponent = bits.getExponent(); + int exponent = bits.get_exponent(); // If the exponent is greater than the most negative mantissa // exponent, then x is already an integer. - if (exponent >= static_cast(MantissaWidth::value)) + if (exponent >= static_cast(MantissaWidth::VALUE)) return x; // If the exponent is such that abs(x) is less than 1, then return 0. if (exponent <= -1) { - if (bits.getSign()) + if (bits.get_sign()) return T(-0.0); else return T(0.0); } - int trimSize = MantissaWidth::value - exponent; - bits.setMantissa((bits.getMantissa() >> trimSize) << trimSize); + int trim_size = MantissaWidth::VALUE - exponent; + bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size); return T(bits); } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T ceil(T x) { FPBits bits(x); // If x is infinity NaN or zero, return it. - if (bits.isInfOrNaN() || bits.isZero()) + if (bits.is_inf_or_nan() || bits.is_zero()) return x; - bool isNeg = bits.getSign(); - int exponent = bits.getExponent(); + bool is_neg = bits.get_sign(); + int exponent = bits.get_exponent(); // If the exponent is greater than the most negative mantissa // exponent, then x is already an integer. - if (exponent >= static_cast(MantissaWidth::value)) + if (exponent >= static_cast(MantissaWidth::VALUE)) return x; if (exponent <= -1) { - if (isNeg) + if (is_neg) return T(-0.0); else return T(1.0); } - uint32_t trimSize = MantissaWidth::value - exponent; - bits.setMantissa((bits.getMantissa() >> trimSize) << trimSize); - T truncValue = T(bits); + uint32_t trim_size = MantissaWidth::VALUE - exponent; + bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size); + T trunc_value = T(bits); // If x is already an integer, return it. - if (truncValue == x) + if (trunc_value == x) return x; // If x is negative, the ceil operation is equivalent to the trunc operation. - if (isNeg) - return truncValue; + if (is_neg) + return trunc_value; - return truncValue + T(1.0); + return trunc_value + T(1.0); } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T floor(T x) { FPBits bits(x); - if (bits.getSign()) { + if (bits.get_sign()) { return -ceil(-x); } else { return trunc(x); @@ -105,26 +105,26 @@ } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T round(T x) { using UIntType = typename FPBits::UIntType; FPBits bits(x); // If x is infinity NaN or zero, return it. - if (bits.isInfOrNaN() || bits.isZero()) + if (bits.is_inf_or_nan() || bits.is_zero()) return x; - bool isNeg = bits.getSign(); - int exponent = bits.getExponent(); + bool is_neg = bits.get_sign(); + int exponent = bits.get_exponent(); // If the exponent is greater than the most negative mantissa // exponent, then x is already an integer. - if (exponent >= static_cast(MantissaWidth::value)) + if (exponent >= static_cast(MantissaWidth::VALUE)) return x; if (exponent == -1) { // Absolute value of x is greater than equal to 0.5 but less than 1. - if (isNeg) + if (is_neg) return T(-1.0); else return T(1.0); @@ -132,102 +132,102 @@ if (exponent <= -2) { // Absolute value of x is less than 0.5. - if (isNeg) + if (is_neg) return T(-0.0); else return T(0.0); } - uint32_t trimSize = MantissaWidth::value - exponent; - bool halfBitSet = bits.getMantissa() & (UIntType(1) << (trimSize - 1)); - bits.setMantissa((bits.getMantissa() >> trimSize) << trimSize); - T truncValue = T(bits); + uint32_t trim_size = MantissaWidth::VALUE - exponent; + bool half_bit_set = bits.get_mantissa() & (UIntType(1) << (trim_size - 1)); + bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size); + T trunc_value = T(bits); // If x is already an integer, return it. - if (truncValue == x) + if (trunc_value == x) return x; - if (!halfBitSet) { + if (!half_bit_set) { // Franctional part is less than 0.5 so round value is the // same as the trunc value. - return truncValue; + return trunc_value; } else { - return isNeg ? truncValue - T(1.0) : truncValue + T(1.0); + return is_neg ? trunc_value - T(1.0) : trunc_value + T(1.0); } } template ::Value, int> = 0> -static inline T roundUsingCurrentRoundingMode(T x) { + cpp::EnableIfType::VALUE, int> = 0> +static inline T round_using_current_rounding_mode(T x) { using UIntType = typename FPBits::UIntType; FPBits bits(x); // If x is infinity NaN or zero, return it. - if (bits.isInfOrNaN() || bits.isZero()) + if (bits.is_inf_or_nan() || bits.is_zero()) return x; - bool isNeg = bits.getSign(); - int exponent = bits.getExponent(); - int roundingMode = getRound(); + bool is_neg = bits.get_sign(); + int exponent = bits.get_exponent(); + int rounding_mode = get_round(); // If the exponent is greater than the most negative mantissa // exponent, then x is already an integer. - if (exponent >= static_cast(MantissaWidth::value)) + if (exponent >= static_cast(MantissaWidth::VALUE)) return x; if (exponent <= -1) { - switch (roundingMode) { + switch (rounding_mode) { case FE_DOWNWARD: - return isNeg ? T(-1.0) : T(0.0); + return is_neg ? T(-1.0) : T(0.0); case FE_UPWARD: - return isNeg ? T(-0.0) : T(1.0); + return is_neg ? T(-0.0) : T(1.0); case FE_TOWARDZERO: - return isNeg ? T(-0.0) : T(0.0); + return is_neg ? T(-0.0) : T(0.0); case FE_TONEAREST: - if (exponent <= -2 || bits.getMantissa() == 0) - return isNeg ? T(-0.0) : T(0.0); // abs(x) <= 0.5 + if (exponent <= -2 || bits.get_mantissa() == 0) + return is_neg ? T(-0.0) : T(0.0); // abs(x) <= 0.5 else - return isNeg ? T(-1.0) : T(1.0); // abs(x) > 0.5 + return is_neg ? T(-1.0) : T(1.0); // abs(x) > 0.5 default: __builtin_unreachable(); } } - uint32_t trimSize = MantissaWidth::value - exponent; - FPBits newBits = bits; - newBits.setMantissa((bits.getMantissa() >> trimSize) << trimSize); - T truncValue = T(newBits); + uint32_t trim_size = MantissaWidth::VALUE - exponent; + FPBits new_bits = bits; + new_bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size); + T trunc_value = T(new_bits); // If x is already an integer, return it. - if (truncValue == x) + if (trunc_value == x) return x; - UIntType trimValue = bits.getMantissa() & ((UIntType(1) << trimSize) - 1); - UIntType halfValue = (UIntType(1) << (trimSize - 1)); + UIntType trim_value = bits.get_mantissa() & ((UIntType(1) << trim_size) - 1); + UIntType half_value = (UIntType(1) << (trim_size - 1)); // If exponent is 0, trimSize will be equal to the mantissa width, and // truncIsOdd` will not be correct. So, we handle it as a special case // below. - UIntType truncIsOdd = newBits.getMantissa() & (UIntType(1) << trimSize); + UIntType trunc_is_odd = new_bits.get_mantissa() & (UIntType(1) << trim_size); - switch (roundingMode) { + switch (rounding_mode) { case FE_DOWNWARD: - return isNeg ? truncValue - T(1.0) : truncValue; + return is_neg ? trunc_value - T(1.0) : trunc_value; case FE_UPWARD: - return isNeg ? truncValue : truncValue + T(1.0); + return is_neg ? trunc_value : trunc_value + T(1.0); case FE_TOWARDZERO: - return truncValue; + return trunc_value; case FE_TONEAREST: - if (trimValue > halfValue) { - return isNeg ? truncValue - T(1.0) : truncValue + T(1.0); - } else if (trimValue == halfValue) { + if (trim_value > half_value) { + return is_neg ? trunc_value - T(1.0) : trunc_value + T(1.0); + } else if (trim_value == half_value) { if (exponent == 0) - return isNeg ? T(-2.0) : T(2.0); - if (truncIsOdd) - return isNeg ? truncValue - T(1.0) : truncValue + T(1.0); + return is_neg ? T(-2.0) : T(2.0); + if (trunc_is_odd) + return is_neg ? trunc_value - T(1.0) : trunc_value + T(1.0); else - return truncValue; + return trunc_value; } else { - return truncValue; + return trunc_value; } default: __builtin_unreachable(); @@ -237,36 +237,36 @@ namespace internal { template ::Value && - cpp::IsIntegral::Value, + cpp::EnableIfType::VALUE && + cpp::IsIntegral::VALUE, int> = 0> -static inline I roundedFloatToSignedInteger(F x) { - constexpr I IntegerMin = (I(1) << (sizeof(I) * 8 - 1)); - constexpr I IntegerMax = -(IntegerMin + 1); +static inline I rounded_float_to_signed_integer(F x) { + constexpr I INTEGER_MIN = (I(1) << (sizeof(I) * 8 - 1)); + constexpr I INTEGER_MAX = -(INTEGER_MIN + 1); FPBits bits(x); - auto setDomainErrorAndRaiseInvalid = []() { + auto set_domain_error_and_raise_invalid = []() { #if math_errhandling & MATH_ERRNO errno = EDOM; #endif #if math_errhandling & MATH_ERREXCEPT - raiseExcept(FE_INVALID); + raise_except(FE_INVALID); #endif }; - if (bits.isInfOrNaN()) { - setDomainErrorAndRaiseInvalid(); - return bits.getSign() ? IntegerMin : IntegerMax; + if (bits.is_inf_or_nan()) { + set_domain_error_and_raise_invalid(); + return bits.get_sign() ? INTEGER_MIN : INTEGER_MAX; } - int exponent = bits.getExponent(); - constexpr int exponentLimit = sizeof(I) * 8 - 1; - if (exponent > exponentLimit) { - setDomainErrorAndRaiseInvalid(); - return bits.getSign() ? IntegerMin : IntegerMax; - } else if (exponent == exponentLimit) { - if (bits.getSign() == 0 || bits.getMantissa() != 0) { - setDomainErrorAndRaiseInvalid(); - return bits.getSign() ? IntegerMin : IntegerMax; + int exponent = bits.get_exponent(); + constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1; + if (exponent > EXPONENT_LIMIT) { + set_domain_error_and_raise_invalid(); + return bits.get_sign() ? INTEGER_MIN : INTEGER_MAX; + } else if (exponent == EXPONENT_LIMIT) { + if (bits.get_sign() == 0 || bits.get_mantissa() != 0) { + set_domain_error_and_raise_invalid(); + return bits.get_sign() ? INTEGER_MIN : INTEGER_MAX; } // If the control reaches here, then it means that the rounded // value is the most negative number for the signed integer type I. @@ -281,20 +281,20 @@ } // namespace internal template ::Value && - cpp::IsIntegral::Value, + cpp::EnableIfType::VALUE && + cpp::IsIntegral::VALUE, int> = 0> -static inline I roundToSignedInteger(F x) { - return internal::roundedFloatToSignedInteger(round(x)); +static inline I round_to_signed_integer(F x) { + return internal::rounded_float_to_signed_integer(round(x)); } template ::Value && - cpp::IsIntegral::Value, + cpp::EnableIfType::VALUE && + cpp::IsIntegral::VALUE, int> = 0> -static inline I roundToSignedIntegerUsingCurrentRoundingMode(F x) { - return internal::roundedFloatToSignedInteger( - roundUsingCurrentRoundingMode(x)); +static inline I round_to_signed_integer_using_current_rounding_mode(F x) { + return internal::rounded_float_to_signed_integer( + round_using_current_rounding_mode(x)); } } // namespace fputil diff --git a/libc/src/__support/FPUtil/NextAfterLongDoubleX86.h b/libc/src/__support/FPUtil/NextAfterLongDoubleX86.h --- a/libc/src/__support/FPUtil/NextAfterLongDoubleX86.h +++ b/libc/src/__support/FPUtil/NextAfterLongDoubleX86.h @@ -18,93 +18,94 @@ static inline long double nextafter(long double from, long double to) { using FPBits = FPBits; - FPBits fromBits(from); - if (fromBits.isNaN()) + FPBits from_bits(from); + if (from_bits.is_nan()) return from; - FPBits toBits(to); - if (toBits.isNaN()) + FPBits to_bits(to); + if (to_bits.is_nan()) return to; if (from == to) return to; // Convert pseudo subnormal number to normal number. - if (fromBits.getImplicitBit() == 1 && fromBits.getUnbiasedExponent() == 0) { - fromBits.setUnbiasedExponent(1); + if (from_bits.get_implicit_bit() == 1 && + from_bits.get_unbiased_exponent() == 0) { + from_bits.set_unbiased_exponent(1); } using UIntType = FPBits::UIntType; - constexpr UIntType signVal = (UIntType(1) << 79); - constexpr UIntType mantissaMask = - (UIntType(1) << MantissaWidth::value) - 1; - UIntType intVal = fromBits.uintval(); + constexpr UIntType SIGN_VAL = (UIntType(1) << 79); + constexpr UIntType MANTISSA_MASK = + (UIntType(1) << MantissaWidth::VALUE) - 1; + UIntType int_val = from_bits.uintval(); if (from < 0.0l) { if (from > to) { - if (intVal == (signVal + FPBits::maxSubnormal)) { + if (int_val == (SIGN_VAL + FPBits::MAX_SUBNORMAL)) { // We deal with normal/subnormal boundary separately to avoid // dealing with the implicit bit. - intVal = signVal + FPBits::minNormal; - } else if ((intVal & mantissaMask) == mantissaMask) { - fromBits.setMantissa(0); + int_val = SIGN_VAL + FPBits::MIN_NORMAL; + } else if ((int_val & MANTISSA_MASK) == MANTISSA_MASK) { + from_bits.set_mantissa(0); // Incrementing exponent might overflow the value to infinity, // which is what is expected. Since NaNs are handling separately, // it will never overflow "beyond" infinity. - fromBits.setUnbiasedExponent(fromBits.getUnbiasedExponent() + 1); - return fromBits; + from_bits.set_unbiased_exponent(from_bits.get_unbiased_exponent() + 1); + return from_bits; } else { - ++intVal; + ++int_val; } } else { - if (intVal == (signVal + FPBits::minNormal)) { + if (int_val == (SIGN_VAL + FPBits::MIN_NORMAL)) { // We deal with normal/subnormal boundary separately to avoid // dealing with the implicit bit. - intVal = signVal + FPBits::maxSubnormal; - } else if ((intVal & mantissaMask) == 0) { - fromBits.setMantissa(mantissaMask); + int_val = SIGN_VAL + FPBits::MAX_SUBNORMAL; + } else if ((int_val & MANTISSA_MASK) == 0) { + from_bits.set_mantissa(MANTISSA_MASK); // from == 0 is handled separately so decrementing the exponent will not // lead to underflow. - fromBits.setUnbiasedExponent(fromBits.getUnbiasedExponent() - 1); - return fromBits; + from_bits.set_unbiased_exponent(from_bits.get_unbiased_exponent() - 1); + return from_bits; } else { - --intVal; + --int_val; } } } else if (from == 0.0l) { if (from > to) - intVal = signVal + 1; + int_val = SIGN_VAL + 1; else - intVal = 1; + int_val = 1; } else { if (from > to) { - if (intVal == FPBits::minNormal) { - intVal = FPBits::maxSubnormal; - } else if ((intVal & mantissaMask) == 0) { - fromBits.setMantissa(mantissaMask); + if (int_val == FPBits::MIN_NORMAL) { + int_val = FPBits::MAX_SUBNORMAL; + } else if ((int_val & MANTISSA_MASK) == 0) { + from_bits.set_mantissa(MANTISSA_MASK); // from == 0 is handled separately so decrementing the exponent will not // lead to underflow. - fromBits.setUnbiasedExponent(fromBits.getUnbiasedExponent() - 1); - return fromBits; + from_bits.set_unbiased_exponent(from_bits.get_unbiased_exponent() - 1); + return from_bits; } else { - --intVal; + --int_val; } } else { - if (intVal == FPBits::maxSubnormal) { - intVal = FPBits::minNormal; - } else if ((intVal & mantissaMask) == mantissaMask) { - fromBits.setMantissa(0); + if (int_val == FPBits::MAX_SUBNORMAL) { + int_val = FPBits::MIN_NORMAL; + } else if ((int_val & MANTISSA_MASK) == MANTISSA_MASK) { + from_bits.set_mantissa(0); // Incrementing exponent might overflow the value to infinity, // which is what is expected. Since NaNs are handling separately, // it will never overflow "beyond" infinity. - fromBits.setUnbiasedExponent(fromBits.getUnbiasedExponent() + 1); - return fromBits; + from_bits.set_unbiased_exponent(from_bits.get_unbiased_exponent() + 1); + return from_bits; } else { - ++intVal; + ++int_val; } } } - return *reinterpret_cast(&intVal); + return *reinterpret_cast(&int_val); // TODO: Raise floating point exceptions as required by the standard. } diff --git a/libc/src/__support/FPUtil/NormalFloat.h b/libc/src/__support/FPUtil/NormalFloat.h --- a/libc/src/__support/FPUtil/NormalFloat.h +++ b/libc/src/__support/FPUtil/NormalFloat.h @@ -27,11 +27,11 @@ // where is of the form 1.<...>. template struct NormalFloat { static_assert( - cpp::IsFloatingPointType::Value, + cpp::IsFloatingPointType::VALUE, "NormalFloat template parameter has to be a floating point type."); using UIntType = typename FPBits::UIntType; - static constexpr UIntType one = (UIntType(1) << MantissaWidth::value); + static constexpr UIntType ONE = (UIntType(1) << MantissaWidth::VALUE); // Unbiased exponent value. int32_t exponent; @@ -39,24 +39,24 @@ UIntType mantissa; // We want |UIntType| to have atleast one bit more than the actual mantissa // bit width to accommodate the implicit 1 value. - static_assert(sizeof(UIntType) * 8 >= MantissaWidth::value + 1, + static_assert(sizeof(UIntType) * 8 >= MantissaWidth::VALUE + 1, "Bad type for mantissa in NormalFloat."); bool sign; NormalFloat(int32_t e, UIntType m, bool s) : exponent(e), mantissa(m), sign(s) { - if (mantissa >= one) + if (mantissa >= ONE) return; - unsigned normalizationShift = evaluateNormalizationShift(mantissa); - mantissa = mantissa << normalizationShift; - exponent -= normalizationShift; + unsigned normalization_shift = evaluate_normalization_shift(mantissa); + mantissa = mantissa << normalization_shift; + exponent -= normalization_shift; } - explicit NormalFloat(T x) { initFromBits(FPBits(x)); } + explicit NormalFloat(T x) { init_from_bits(FPBits(x)); } - explicit NormalFloat(FPBits bits) { initFromBits(bits); } + explicit NormalFloat(FPBits bits) { init_from_bits(bits); } // Compares this normalized number with another normalized number. // Returns -1 is this number is less than |other|, 0 if this number is equal @@ -89,59 +89,59 @@ } operator T() const { - int biasedExponent = exponent + FPBits::exponentBias; + int biased_exponent = exponent + FPBits::EXPONENT_BIAS; // Max exponent is of the form 0xFF...E. That is why -2 and not -1. - constexpr int maxExponentValue = (1 << ExponentWidth::value) - 2; - if (biasedExponent > maxExponentValue) { - return sign ? T(FPBits::negInf()) : T(FPBits::inf()); + constexpr int MAX_EXPONENT_VALUE = (1 << ExponentWidth::VALUE) - 2; + if (biased_exponent > MAX_EXPONENT_VALUE) { + return sign ? T(FPBits::neg_inf()) : T(FPBits::inf()); } FPBits result(T(0.0)); - result.setSign(sign); + result.set_sign(sign); - constexpr int subnormalExponent = -FPBits::exponentBias + 1; - if (exponent < subnormalExponent) { - unsigned shift = subnormalExponent - exponent; + constexpr int SUBNORMAL_EXPONENT = -FPBits::EXPONENT_BIAS + 1; + if (exponent < SUBNORMAL_EXPONENT) { + unsigned shift = SUBNORMAL_EXPONENT - exponent; // Since exponent > subnormalExponent, shift is strictly greater than // zero. - if (shift <= MantissaWidth::value + 1) { + if (shift <= MantissaWidth::VALUE + 1) { // Generate a subnormal number. Might lead to loss of precision. // We round to nearest and round halfway cases to even. - const UIntType shiftOutMask = (UIntType(1) << shift) - 1; - const UIntType shiftOutValue = mantissa & shiftOutMask; - const UIntType halfwayValue = UIntType(1) << (shift - 1); - result.setUnbiasedExponent(0); - result.setMantissa(mantissa >> shift); - UIntType newMantissa = result.getMantissa(); - if (shiftOutValue > halfwayValue) { - newMantissa += 1; - } else if (shiftOutValue == halfwayValue) { + const UIntType shift_out_mask = (UIntType(1) << shift) - 1; + const UIntType shift_out_value = mantissa & shift_out_mask; + const UIntType halfway_value = UIntType(1) << (shift - 1); + result.set_unbiased_exponent(0); + result.set_mantissa(mantissa >> shift); + UIntType new_mantissa = result.get_mantissa(); + if (shift_out_value > halfway_value) { + new_mantissa += 1; + } else if (shift_out_value == halfway_value) { // Round to even. - if (result.getMantissa() & 0x1) - newMantissa += 1; + if (result.get_mantissa() & 0x1) + new_mantissa += 1; } - result.setMantissa(newMantissa); + result.set_mantissa(new_mantissa); // Adding 1 to mantissa can lead to overflow. This can only happen if // mantissa was all ones (0b111..11). For such a case, we will carry // the overflow into the exponent. - if (newMantissa == one) - result.setUnbiasedExponent(1); + if (new_mantissa == ONE) + result.set_unbiased_exponent(1); return T(result); } else { return T(result); } } - result.setUnbiasedExponent(exponent + FPBits::exponentBias); - result.setMantissa(mantissa); + result.set_unbiased_exponent(exponent + FPBits::EXPONENT_BIAS); + result.set_mantissa(mantissa); return T(result); } private: - void initFromBits(FPBits bits) { - sign = bits.getSign(); + void init_from_bits(FPBits bits) { + sign = bits.get_sign(); - if (bits.isInfOrNaN() || bits.isZero()) { + if (bits.is_inf_or_nan() || bits.is_zero()) { // Ignore special bit patterns. Implementations deal with them separately // anyway so this should not be a problem. exponent = 0; @@ -150,19 +150,19 @@ } // Normalize subnormal numbers. - if (bits.getUnbiasedExponent() == 0) { - unsigned shift = evaluateNormalizationShift(bits.getMantissa()); - mantissa = UIntType(bits.getMantissa()) << shift; - exponent = 1 - FPBits::exponentBias - shift; + if (bits.get_unbiased_exponent() == 0) { + unsigned shift = evaluate_normalization_shift(bits.get_mantissa()); + mantissa = UIntType(bits.get_mantissa()) << shift; + exponent = 1 - FPBits::EXPONENT_BIAS - shift; } else { - exponent = bits.getUnbiasedExponent() - FPBits::exponentBias; - mantissa = one | bits.getMantissa(); + exponent = bits.get_unbiased_exponent() - FPBits::EXPONENT_BIAS; + mantissa = ONE | bits.get_mantissa(); } } - unsigned evaluateNormalizationShift(UIntType m) { + unsigned evaluate_normalization_shift(UIntType m) { unsigned shift = 0; - for (; (one & m) == 0 && (shift < MantissaWidth::value); + for (; (ONE & m) == 0 && (shift < MantissaWidth::VALUE); m <<= 1, ++shift) ; return shift; @@ -171,10 +171,10 @@ #ifdef SPECIAL_X86_LONG_DOUBLE template <> -inline void NormalFloat::initFromBits(FPBits bits) { - sign = bits.getSign(); +inline void NormalFloat::init_from_bits(FPBits bits) { + sign = bits.get_sign(); - if (bits.isInfOrNaN() || bits.isZero()) { + if (bits.is_inf_or_nan() || bits.is_zero()) { // Ignore special bit patterns. Implementations deal with them separately // anyway so this should not be a problem. exponent = 0; @@ -182,67 +182,69 @@ return; } - if (bits.getUnbiasedExponent() == 0) { - if (bits.getImplicitBit() == 0) { + if (bits.get_unbiased_exponent() == 0) { + if (bits.get_implicit_bit() == 0) { // Since we ignore zero value, the mantissa in this case is non-zero. - int normalizationShift = evaluateNormalizationShift(bits.getMantissa()); - exponent = -16382 - normalizationShift; - mantissa = (bits.getMantissa() << normalizationShift); + int normalization_shift = + evaluate_normalization_shift(bits.get_mantissa()); + exponent = -16382 - normalization_shift; + mantissa = (bits.get_mantissa() << normalization_shift); } else { exponent = -16382; - mantissa = one | bits.getMantissa(); + mantissa = ONE | bits.get_mantissa(); } } else { - if (bits.getImplicitBit() == 0) { + if (bits.get_implicit_bit() == 0) { // Invalid number so just store 0 similar to a NaN. exponent = 0; mantissa = 0; } else { - exponent = bits.getUnbiasedExponent() - 16383; - mantissa = one | bits.getMantissa(); + exponent = bits.get_unbiased_exponent() - 16383; + mantissa = ONE | bits.get_mantissa(); } } } template <> inline NormalFloat::operator long double() const { - int biasedExponent = exponent + FPBits::exponentBias; + int biased_exponent = exponent + FPBits::EXPONENT_BIAS; // Max exponent is of the form 0xFF...E. That is why -2 and not -1. - constexpr int maxExponentValue = (1 << ExponentWidth::value) - 2; - if (biasedExponent > maxExponentValue) { - return sign ? FPBits::negInf() : FPBits::inf(); + constexpr int MAX_EXPONENT_VALUE = + (1 << ExponentWidth::VALUE) - 2; + if (biased_exponent > MAX_EXPONENT_VALUE) { + return sign ? FPBits::neg_inf() : FPBits::inf(); } FPBits result(0.0l); - result.setSign(sign); + result.set_sign(sign); - constexpr int subnormalExponent = -FPBits::exponentBias + 1; - if (exponent < subnormalExponent) { - unsigned shift = subnormalExponent - exponent; - if (shift <= MantissaWidth::value + 1) { + constexpr int SUBNORMAL_EXPONENT = -FPBits::EXPONENT_BIAS + 1; + if (exponent < SUBNORMAL_EXPONENT) { + unsigned shift = SUBNORMAL_EXPONENT - exponent; + if (shift <= MantissaWidth::VALUE + 1) { // Generate a subnormal number. Might lead to loss of precision. // We round to nearest and round halfway cases to even. - const UIntType shiftOutMask = (UIntType(1) << shift) - 1; - const UIntType shiftOutValue = mantissa & shiftOutMask; - const UIntType halfwayValue = UIntType(1) << (shift - 1); - result.setUnbiasedExponent(0); - result.setMantissa(mantissa >> shift); - UIntType newMantissa = result.getMantissa(); - if (shiftOutValue > halfwayValue) { - newMantissa += 1; - } else if (shiftOutValue == halfwayValue) { + const UIntType shift_out_mask = (UIntType(1) << shift) - 1; + const UIntType shift_out_value = mantissa & shift_out_mask; + const UIntType halfway_value = UIntType(1) << (shift - 1); + result.set_unbiased_exponent(0); + result.set_mantissa(mantissa >> shift); + UIntType new_mantissa = result.get_mantissa(); + if (shift_out_value > halfway_value) { + new_mantissa += 1; + } else if (shift_out_value == halfway_value) { // Round to even. - if (result.getMantissa() & 0x1) - newMantissa += 1; + if (result.get_mantissa() & 0x1) + new_mantissa += 1; } - result.setMantissa(newMantissa); + result.set_mantissa(new_mantissa); // Adding 1 to mantissa can lead to overflow. This can only happen if // mantissa was all ones (0b111..11). For such a case, we will carry // the overflow into the exponent and set the implicit bit to 1. - if (newMantissa == one) { - result.setUnbiasedExponent(1); - result.setImplicitBit(1); + if (new_mantissa == ONE) { + result.set_unbiased_exponent(1); + result.set_implicit_bit(1); } else { - result.setImplicitBit(0); + result.set_implicit_bit(0); } return static_cast(result); } else { @@ -250,9 +252,9 @@ } } - result.setUnbiasedExponent(biasedExponent); - result.setMantissa(mantissa); - result.setImplicitBit(1); + result.set_unbiased_exponent(biased_exponent); + result.set_mantissa(mantissa); + result.set_implicit_bit(1); return static_cast(result); } #endif // SPECIAL_X86_LONG_DOUBLE diff --git a/libc/src/__support/FPUtil/Sqrt.h b/libc/src/__support/FPUtil/Sqrt.h --- a/libc/src/__support/FPUtil/Sqrt.h +++ b/libc/src/__support/FPUtil/Sqrt.h @@ -94,35 +94,35 @@ // Correctly rounded IEEE 754 SQRT with round to nearest, ties to even. // Shift-and-add algorithm. template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> static inline T sqrt(T x) { using UIntType = typename FPBits::UIntType; - constexpr UIntType One = UIntType(1) << MantissaWidth::value; + constexpr UIntType One = UIntType(1) << MantissaWidth::VALUE; FPBits bits(x); - if (bits.isInfOrNaN()) { - if (bits.getSign() && (bits.getMantissa() == 0)) { + if (bits.is_inf_or_nan()) { + if (bits.get_sign() && (bits.get_mantissa() == 0)) { // sqrt(-Inf) = NaN - return FPBits::buildNaN(One >> 1); + return FPBits::build_nan(One >> 1); } else { // sqrt(NaN) = NaN // sqrt(+Inf) = +Inf return x; } - } else if (bits.isZero()) { + } else if (bits.is_zero()) { // sqrt(+0) = +0 // sqrt(-0) = -0 return x; - } else if (bits.getSign()) { + } else if (bits.get_sign()) { // sqrt( negative numbers ) = NaN - return FPBits::buildNaN(One >> 1); + return FPBits::build_nan(One >> 1); } else { - int xExp = bits.getExponent(); - UIntType xMant = bits.getMantissa(); + int xExp = bits.get_exponent(); + UIntType xMant = bits.get_mantissa(); // Step 1a: Normalize denormal input and append hidden bit to the mantissa - if (bits.getUnbiasedExponent() == 0) { + if (bits.get_unbiased_exponent() == 0) { ++xExp; // let xExp be the correct exponent of One bit. internal::normalize(xExp, xMant); } else { @@ -170,9 +170,9 @@ } // Remove hidden bit and append the exponent field. - xExp = ((xExp >> 1) + FPBits::exponentBias); + xExp = ((xExp >> 1) + FPBits::EXPONENT_BIAS); - y = (y - One) | (static_cast(xExp) << MantissaWidth::value); + y = (y - One) | (static_cast(xExp) << MantissaWidth::VALUE); // Round to nearest, ties to even if (rb && (lsb || (r != 0))) { ++y; diff --git a/libc/src/__support/FPUtil/SqrtLongDoubleX86.h b/libc/src/__support/FPUtil/SqrtLongDoubleX86.h --- a/libc/src/__support/FPUtil/SqrtLongDoubleX86.h +++ b/libc/src/__support/FPUtil/SqrtLongDoubleX86.h @@ -45,34 +45,34 @@ template <> inline long double sqrt(long double x) { using UIntType = typename FPBits::UIntType; constexpr UIntType One = UIntType(1) - << int(MantissaWidth::value); + << int(MantissaWidth::VALUE); FPBits bits(x); - if (bits.isInfOrNaN()) { - if (bits.getSign() && (bits.getMantissa() == 0)) { + if (bits.is_inf_or_nan()) { + if (bits.get_sign() && (bits.get_mantissa() == 0)) { // sqrt(-Inf) = NaN - return FPBits::buildNaN(One >> 1); + return FPBits::build_nan(One >> 1); } else { // sqrt(NaN) = NaN // sqrt(+Inf) = +Inf return x; } - } else if (bits.isZero()) { + } else if (bits.is_zero()) { // sqrt(+0) = +0 // sqrt(-0) = -0 return x; - } else if (bits.getSign()) { + } else if (bits.get_sign()) { // sqrt( negative numbers ) = NaN - return FPBits::buildNaN(One >> 1); + return FPBits::build_nan(One >> 1); } else { - int xExp = bits.getExponent(); - UIntType xMant = bits.getMantissa(); + int xExp = bits.get_exponent(); + UIntType xMant = bits.get_mantissa(); // Step 1a: Normalize denormal input if (bits.getImplicitBit()) { xMant |= One; - } else if (bits.getUnbiasedExponent() == 0) { + } else if (bits.get_unbiased_exponent() == 0) { internal::normalize(xExp, xMant); } @@ -117,9 +117,9 @@ } // Append the exponent field. - xExp = ((xExp >> 1) + FPBits::exponentBias); + xExp = ((xExp >> 1) + FPBits::EXPONENT_BIAS); y |= (static_cast(xExp) - << (MantissaWidth::value + 1)); + << (MantissaWidth::VALUE + 1)); // Round to nearest, ties to even if (rb && (lsb || (r != 0))) { @@ -128,9 +128,9 @@ // Extract output FPBits out(0.0L); - out.setUnbiasedExponent(xExp); + out.set_unbiased_exponent(xExp); out.setImplicitBit(1); - out.setMantissa((y & (One - 1))); + out.set_mantissa((y & (One - 1))); return out; } 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 @@ -69,7 +69,7 @@ static void writeStatusWord(uint32_t fpsr) { __arm_wsr("fpsr", fpsr); } }; -static inline int enableExcept(int excepts) { +static inline int enable_except(int excepts) { uint32_t newExcepts = FEnv::getStatusValueForExcept(excepts); uint32_t controlWord = FEnv::getControlWord(); int oldExcepts = @@ -79,7 +79,7 @@ return FEnv::exceptionStatusToMacro(oldExcepts); } -static inline int disableExcept(int excepts) { +static inline int disable_except(int excepts) { uint32_t disabledExcepts = FEnv::getStatusValueForExcept(excepts); uint32_t controlWord = FEnv::getControlWord(); int oldExcepts = @@ -89,14 +89,14 @@ return FEnv::exceptionStatusToMacro(oldExcepts); } -static inline int getExcept() { +static inline int get_except() { uint32_t controlWord = FEnv::getControlWord(); int enabledExcepts = (controlWord >> FEnv::ExceptionControlFlagsBitPosition) & 0x1F; return FEnv::exceptionStatusToMacro(enabledExcepts); } -static inline int clearExcept(int excepts) { +static inline int clear_except(int excepts) { uint32_t statusWord = FEnv::getStatusWord(); uint32_t toClear = FEnv::getStatusValueForExcept(excepts); statusWord &= ~(toClear << FEnv::ExceptionStatusFlagsBitPosition); @@ -104,14 +104,14 @@ return 0; } -static inline int testExcept(int excepts) { +static inline int test_except(int excepts) { uint32_t toTest = FEnv::getStatusValueForExcept(excepts); uint32_t statusWord = FEnv::getStatusWord(); return FEnv::exceptionStatusToMacro( (statusWord >> FEnv::ExceptionStatusFlagsBitPosition) & toTest); } -static inline int setExcept(int excepts) { +static inline int set_except(int excepts) { uint32_t statusWord = FEnv::getControlWord(); uint32_t statusValue = FEnv::getStatusValueForExcept(excepts); statusWord |= (statusValue << FEnv::ExceptionStatusFlagsBitPosition); @@ -119,11 +119,11 @@ return 0; } -static inline int raiseExcept(int excepts) { +static inline int raise_except(int excepts) { float zero = 0.0f; float one = 1.0f; - float largeValue = float(FPBits(FPBits::maxNormal)); - float smallValue = float(FPBits(FPBits::minNormal)); + float largeValue = float(FPBits(FPBits::MAX_NORMAL)); + float smallValue = float(FPBits(FPBits::MIN_NORMAL)); auto divfunc = [](float a, float b) { __asm__ __volatile__("ldr s0, %0\n\t" "ldr s1, %1\n\t" @@ -178,7 +178,7 @@ return 0; } -static inline int getRound() { +static inline int get_round() { uint32_t roundingMode = (FEnv::getControlWord() >> FEnv::RoundingControlBitPosition) & 0x3; switch (roundingMode) { @@ -195,7 +195,7 @@ } } -static inline int setRound(int mode) { +static inline int set_round(int mode) { uint16_t bitValue; switch (mode) { case FE_TONEAREST: @@ -222,14 +222,14 @@ return 0; } -static inline int getEnv(fenv_t *envp) { +static inline int get_env(fenv_t *envp) { FEnv::FPState *state = reinterpret_cast(envp); state->ControlWord = FEnv::getControlWord(); state->StatusWord = FEnv::getStatusWord(); return 0; } -static inline int setEnv(const fenv_t *envp) { +static inline int set_env(const fenv_t *envp) { if (envp == FE_DFL_ENV) { // Default status and control words bits are all zeros so we just // write zeros. diff --git a/libc/src/__support/FPUtil/aarch64/FMA.h b/libc/src/__support/FPUtil/aarch64/FMA.h --- a/libc/src/__support/FPUtil/aarch64/FMA.h +++ b/libc/src/__support/FPUtil/aarch64/FMA.h @@ -15,7 +15,7 @@ namespace fputil { template -cpp::EnableIfType::Value, T> fma(T x, T y, T z) { +cpp::EnableIfType::VALUE, T> fma(T x, T y, T z) { float result; __asm__ __volatile__("fmadd %s0, %s1, %s2, %s3\n\t" : "=w"(result) @@ -24,7 +24,7 @@ } template -cpp::EnableIfType::Value, T> fma(T x, T y, T z) { +cpp::EnableIfType::VALUE, T> fma(T x, T y, T z) { double result; __asm__ __volatile__("fmadd %d0, %d1, %d2, %d3\n\t" : "=w"(result) diff --git a/libc/src/__support/FPUtil/generic/FMA.h b/libc/src/__support/FPUtil/generic/FMA.h --- a/libc/src/__support/FPUtil/generic/FMA.h +++ b/libc/src/__support/FPUtil/generic/FMA.h @@ -16,7 +16,7 @@ namespace generic { template -static inline cpp::EnableIfType::Value, T> fma(T x, T y, +static inline cpp::EnableIfType::VALUE, T> fma(T x, T y, T z) { // Product is exact. double prod = static_cast(x) * static_cast(y); @@ -24,7 +24,7 @@ double sum = prod + z_d; fputil::FPBits bit_prod(prod), bitz(z_d), bit_sum(sum); - if (!(bit_sum.isInfOrNaN() || bit_sum.isZero())) { + if (!(bit_sum.is_inf_or_nan() || bit_sum.is_zero())) { // Since the sum is computed in double precision, rounding might happen // (for instance, when bitz.exponent > bit_prod.exponent + 5, or // bit_prod.exponent > bitz.exponent + 40). In that case, when we round @@ -47,17 +47,17 @@ // bit of sum, so that the sticky bits used when rounding sum to float are // correct (when it matters). fputil::FPBits t( - (bit_prod.getUnbiasedExponent() >= bitz.getUnbiasedExponent()) + (bit_prod.get_unbiased_exponent() >= bitz.get_unbiased_exponent()) ? ((double(bit_sum) - double(bit_prod)) - double(bitz)) : ((double(bit_sum) - double(bitz)) - double(bit_prod))); // Update sticky bits if t != 0.0 and the least (52 - 23 - 1 = 28) bits are // zero. - if (!t.isZero() && ((bit_sum.getMantissa() & 0xfff'ffffULL) == 0)) { - if (bit_sum.getSign() != t.getSign()) { - bit_sum.setMantissa(bit_sum.getMantissa() + 1); - } else if (bit_sum.getMantissa()) { - bit_sum.setMantissa(bit_sum.getMantissa() - 1); + if (!t.is_zero() && ((bit_sum.get_mantissa() & 0xfff'ffffULL) == 0)) { + if (bit_sum.get_sign() != t.get_sign()) { + bit_sum.set_mantissa(bit_sum.get_mantissa() + 1); + } else if (bit_sum.get_mantissa()) { + bit_sum.set_mantissa(bit_sum.get_mantissa() - 1); } } } diff --git a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h --- a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h +++ b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h @@ -30,59 +30,59 @@ // register have the same 2-bit enoding but have different bit positions. // See below for the bit positions. struct RoundingControlValue { - static constexpr uint16_t ToNearest = 0x0; - static constexpr uint16_t Downward = 0x1; - static constexpr uint16_t Upward = 0x2; - static constexpr uint16_t TowardZero = 0x3; + static constexpr uint16_t TO_NEAREST = 0x0; + static constexpr uint16_t DOWNWARD = 0x1; + static constexpr uint16_t UPWARD = 0x2; + static constexpr uint16_t TOWARD_ZERO = 0x3; }; -static constexpr uint16_t X87RoundingControlBitPosition = 10; -static constexpr uint16_t MXCSRRoundingControlBitPosition = 13; +static constexpr uint16_t X87_ROUNDING_CONTROL_BIT_POSITION = 10; +static constexpr uint16_t MXCSR_ROUNDING_CONTROL_BIT_POSITION = 13; // The exception flags in the x87 status register and the MXCSR have the same // encoding as well as the same bit positions. struct ExceptionFlags { - static constexpr uint16_t Invalid = 0x1; + static constexpr uint16_t INVALID = 0x1; // Some libcs define __FE_DENORM corresponding to the denormal input // exception and include it in FE_ALL_EXCEPTS. We define and use it to // support compiling against headers provided by such libcs. - static constexpr uint16_t Denormal = 0x2; - static constexpr uint16_t DivByZero = 0x4; - static constexpr uint16_t Overflow = 0x8; - static constexpr uint16_t Underflow = 0x10; - static constexpr uint16_t Inexact = 0x20; + static constexpr uint16_t DENORMAL = 0x2; + static constexpr uint16_t DIV_BY_ZERO = 0x4; + static constexpr uint16_t OVERFLOW = 0x8; + static constexpr uint16_t UNDERFLOW = 0x10; + static constexpr uint16_t INEXACT = 0x20; }; // The exception control bits occupy six bits, one bit for each exception. // In the x87 control word, they occupy the first 6 bits. In the MXCSR // register, they occupy bits 7 to 12. -static constexpr uint16_t X87ExceptionControlBitPosition = 0; -static constexpr uint16_t MXCSRExceptionContolBitPoistion = 7; +static constexpr uint16_t X87_EXCEPTION_CONTROL_BIT_POSITION = 0; +static constexpr uint16_t MXCSR_EXCEPTION_CONTOL_BIT_POISTION = 7; // Exception flags are individual bits in the corresponding registers. // So, we just OR the bit values to get the full set of exceptions. -static inline uint16_t getStatusValueForExcept(int excepts) { +static inline uint16_t get_status_value_for_except(int excepts) { // We will make use of the fact that exception control bits are single // bit flags in the control registers. - return (excepts & FE_INVALID ? ExceptionFlags::Invalid : 0) | + return (excepts & FE_INVALID ? ExceptionFlags::INVALID : 0) | #ifdef __FE_DENORM (excepts & __FE_DENORM ? ExceptionFlags::Denormal : 0) | #endif // __FE_DENORM - (excepts & FE_DIVBYZERO ? ExceptionFlags::DivByZero : 0) | - (excepts & FE_OVERFLOW ? ExceptionFlags::Overflow : 0) | - (excepts & FE_UNDERFLOW ? ExceptionFlags::Underflow : 0) | - (excepts & FE_INEXACT ? ExceptionFlags::Inexact : 0); + (excepts & FE_DIVBYZERO ? ExceptionFlags::DIV_BY_ZERO : 0) | + (excepts & FE_OVERFLOW ? ExceptionFlags::OVERFLOW : 0) | + (excepts & FE_UNDERFLOW ? ExceptionFlags::UNDERFLOW : 0) | + (excepts & FE_INEXACT ? ExceptionFlags::INEXACT : 0); } -static inline int exceptionStatusToMacro(uint16_t status) { - return (status & ExceptionFlags::Invalid ? FE_INVALID : 0) | +static inline int exception_status_to_macro(uint16_t status) { + return (status & ExceptionFlags::INVALID ? FE_INVALID : 0) | #ifdef __FE_DENORM (status & ExceptionFlags::Denormal ? __FE_DENORM : 0) | #endif // __FE_DENORM - (status & ExceptionFlags::DivByZero ? FE_DIVBYZERO : 0) | - (status & ExceptionFlags::Overflow ? FE_OVERFLOW : 0) | - (status & ExceptionFlags::Underflow ? FE_UNDERFLOW : 0) | - (status & ExceptionFlags::Inexact ? FE_INEXACT : 0); + (status & ExceptionFlags::DIV_BY_ZERO ? FE_DIVBYZERO : 0) | + (status & ExceptionFlags::OVERFLOW ? FE_OVERFLOW : 0) | + (status & ExceptionFlags::UNDERFLOW ? FE_UNDERFLOW : 0) | + (status & ExceptionFlags::INEXACT ? FE_INEXACT : 0); } struct X87StateDescriptor { @@ -94,45 +94,45 @@ uint32_t _[5]; }; -static inline uint16_t getX87ControlWord() { +static inline uint16_t get_x87_control_word() { uint16_t w; __asm__ __volatile__("fnstcw %0" : "=m"(w)::); SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w)); return w; } -static inline void writeX87ControlWord(uint16_t w) { +static inline void write_x87_control_word(uint16_t w) { __asm__ __volatile__("fldcw %0" : : "m"(w) :); } -static inline uint16_t getX87StatusWord() { +static inline uint16_t get_x87_status_word() { uint16_t w; __asm__ __volatile__("fnstsw %0" : "=m"(w)::); SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w)); return w; } -static inline void clearX87Exceptions() { +static inline void clear_x87_exceptions() { __asm__ __volatile__("fnclex" : : :); } -static inline uint32_t getMXCSR() { +static inline uint32_t get_mxcsr() { uint32_t w; __asm__ __volatile__("stmxcsr %0" : "=m"(w)::); SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w)); return w; } -static inline void writeMXCSR(uint32_t w) { +static inline void write_mxcsr(uint32_t w) { __asm__ __volatile__("ldmxcsr %0" : : "m"(w) :); } -static inline void getX87StateDescriptor(X87StateDescriptor &s) { +static inline void get_x87_state_descriptor(X87StateDescriptor &s) { __asm__ __volatile__("fnstenv %0" : "=m"(s)); SANITIZER_MEMORY_INITIALIZED(&s, sizeof(s)); } -static inline void writeX87StateDescriptor(const X87StateDescriptor &s) { +static inline void write_x87_state_descriptor(const X87StateDescriptor &s) { __asm__ __volatile__("fldenv %0" : : "m"(s) :); } @@ -140,96 +140,96 @@ } // namespace internal -static inline int enableExcept(int excepts) { +static inline int enable_except(int excepts) { // In the x87 control word and in MXCSR, an exception is blocked // if the corresponding bit is set. That is the reason for all the // bit-flip operations below as we need to turn the bits to zero // to enable them. - uint16_t bitMask = internal::getStatusValueForExcept(excepts); + uint16_t bit_mask = internal::get_status_value_for_except(excepts); - uint16_t x87CW = internal::getX87ControlWord(); - uint16_t oldExcepts = ~x87CW & 0x3F; // Save previously enabled exceptions. - x87CW &= ~bitMask; - internal::writeX87ControlWord(x87CW); + uint16_t x87_cw = internal::get_x87_control_word(); + uint16_t old_excepts = ~x87_cw & 0x3F; // Save previously enabled exceptions. + x87_cw &= ~bit_mask; + internal::write_x87_control_word(x87_cw); // Enabling SSE exceptions via MXCSR is a nice thing to do but // might not be of much use practically as SSE exceptions and the x87 // exceptions are independent of each other. - uint32_t mxcsr = internal::getMXCSR(); - mxcsr &= ~(bitMask << internal::MXCSRExceptionContolBitPoistion); - internal::writeMXCSR(mxcsr); + uint32_t mxcsr = internal::get_mxcsr(); + mxcsr &= ~(bit_mask << internal::MXCSR_EXCEPTION_CONTOL_BIT_POISTION); + internal::write_mxcsr(mxcsr); // Since the x87 exceptions and SSE exceptions are independent of each, // it doesn't make much sence to report both in the return value. Most // often, the standard floating point functions deal with FPU operations // so we will retrun only the old x87 exceptions. - return internal::exceptionStatusToMacro(oldExcepts); + return internal::exception_status_to_macro(old_excepts); } -static inline int disableExcept(int excepts) { +static inline int disable_except(int excepts) { // In the x87 control word and in MXCSR, an exception is blocked // if the corresponding bit is set. - uint16_t bitMask = internal::getStatusValueForExcept(excepts); + uint16_t bit_mask = internal::get_status_value_for_except(excepts); - uint16_t x87CW = internal::getX87ControlWord(); - uint16_t oldExcepts = ~x87CW & 0x3F; // Save previously enabled exceptions. - x87CW |= bitMask; - internal::writeX87ControlWord(x87CW); + uint16_t x87_cw = internal::get_x87_control_word(); + uint16_t old_excepts = ~x87_cw & 0x3F; // Save previously enabled exceptions. + x87_cw |= bit_mask; + internal::write_x87_control_word(x87_cw); - // Just like in enableExcept, it is not clear if disabling SSE exceptions + // Just like in enable_except, it is not clear if disabling SSE exceptions // is required. But, we will still do it only as a "nice thing to do". - uint32_t mxcsr = internal::getMXCSR(); - mxcsr |= (bitMask << internal::MXCSRExceptionContolBitPoistion); - internal::writeMXCSR(mxcsr); + uint32_t mxcsr = internal::get_mxcsr(); + mxcsr |= (bit_mask << internal::MXCSR_EXCEPTION_CONTOL_BIT_POISTION); + internal::write_mxcsr(mxcsr); - return internal::exceptionStatusToMacro(oldExcepts); + return internal::exception_status_to_macro(old_excepts); } -static inline int getExcept() { - uint16_t x87CW = internal::getX87ControlWord(); - uint16_t enabledExcepts = ~x87CW & 0x3F; - return internal::exceptionStatusToMacro(enabledExcepts); +static inline int get_except() { + uint16_t x87_cw = internal::get_x87_control_word(); + uint16_t enabled_excepts = ~x87_cw & 0x3F; + return internal::exception_status_to_macro(enabled_excepts); } -static inline int clearExcept(int excepts) { +static inline int clear_except(int excepts) { internal::X87StateDescriptor state; - internal::getX87StateDescriptor(state); - state.StatusWord &= ~internal::getStatusValueForExcept(excepts); - internal::writeX87StateDescriptor(state); + internal::get_x87_state_descriptor(state); + state.StatusWord &= ~internal::get_status_value_for_except(excepts); + internal::write_x87_state_descriptor(state); - uint32_t mxcsr = internal::getMXCSR(); - mxcsr &= ~internal::getStatusValueForExcept(excepts); - internal::writeMXCSR(mxcsr); + uint32_t mxcsr = internal::get_mxcsr(); + mxcsr &= ~internal::get_status_value_for_except(excepts); + internal::write_mxcsr(mxcsr); return 0; } -static inline int testExcept(int excepts) { - uint16_t statusValue = internal::getStatusValueForExcept(excepts); +static inline int test_except(int excepts) { + uint16_t status_value = internal::get_status_value_for_except(excepts); // Check both x87 status word and MXCSR. - return internal::exceptionStatusToMacro( - (statusValue & internal::getX87StatusWord()) | - (statusValue & internal::getMXCSR())); + return internal::exception_status_to_macro( + (status_value & internal::get_x87_status_word()) | + (status_value & internal::get_mxcsr())); } // Sets the exception flags but does not trigger the exception handler. -static inline int setExcept(int excepts) { - uint16_t statusValue = internal::getStatusValueForExcept(excepts); +static inline int set_except(int excepts) { + uint16_t status_value = internal::get_status_value_for_except(excepts); internal::X87StateDescriptor state; - internal::getX87StateDescriptor(state); - state.StatusWord |= statusValue; - internal::writeX87StateDescriptor(state); + internal::get_x87_state_descriptor(state); + state.StatusWord |= status_value; + internal::write_x87_state_descriptor(state); - uint32_t mxcsr = internal::getMXCSR(); - mxcsr |= statusValue; - internal::writeMXCSR(mxcsr); + uint32_t mxcsr = internal::get_mxcsr(); + mxcsr |= status_value; + internal::write_mxcsr(mxcsr); return 0; } -static inline int raiseExcept(int excepts) { - uint16_t statusValue = internal::getStatusValueForExcept(excepts); +static inline int raise_except(int excepts) { + uint16_t status_value = internal::get_status_value_for_except(excepts); // We set the status flag for exception one at a time and call the // fwait instruction to actually get the processor to raise the @@ -244,24 +244,24 @@ // ensure that the writes by the exception handler are maintained // when raising the next exception. - auto raiseHelper = [](uint16_t singleExceptFlag) { + auto raise_helper = [](uint16_t singleExceptFlag) { internal::X87StateDescriptor state; - internal::getX87StateDescriptor(state); + internal::get_x87_state_descriptor(state); state.StatusWord |= singleExceptFlag; - internal::writeX87StateDescriptor(state); + internal::write_x87_state_descriptor(state); internal::fwait(); }; - if (statusValue & internal::ExceptionFlags::Invalid) - raiseHelper(internal::ExceptionFlags::Invalid); - if (statusValue & internal::ExceptionFlags::DivByZero) - raiseHelper(internal::ExceptionFlags::DivByZero); - if (statusValue & internal::ExceptionFlags::Overflow) - raiseHelper(internal::ExceptionFlags::Overflow); - if (statusValue & internal::ExceptionFlags::Underflow) - raiseHelper(internal::ExceptionFlags::Underflow); - if (statusValue & internal::ExceptionFlags::Inexact) - raiseHelper(internal::ExceptionFlags::Inexact); + if (status_value & internal::ExceptionFlags::INVALID) + raise_helper(internal::ExceptionFlags::INVALID); + if (status_value & internal::ExceptionFlags::DIV_BY_ZERO) + raise_helper(internal::ExceptionFlags::DIV_BY_ZERO); + if (status_value & internal::ExceptionFlags::OVERFLOW) + raise_helper(internal::ExceptionFlags::OVERFLOW); + if (status_value & internal::ExceptionFlags::UNDERFLOW) + raise_helper(internal::ExceptionFlags::UNDERFLOW); + if (status_value & internal::ExceptionFlags::INEXACT) + raise_helper(internal::ExceptionFlags::INEXACT); #ifdef __FE_DENORM if (statusValue & internal::ExceptionFlags::Denormal) { raiseHelper(internal::ExceptionFlags::Denormal); @@ -276,57 +276,59 @@ return 0; } -static inline int getRound() { - uint16_t bitValue = - (internal::getMXCSR() >> internal::MXCSRRoundingControlBitPosition) & 0x3; - switch (bitValue) { - case internal::RoundingControlValue::ToNearest: +static inline int get_round() { + uint16_t bit_value = + (internal::get_mxcsr() >> internal::MXCSR_ROUNDING_CONTROL_BIT_POSITION) & + 0x3; + switch (bit_value) { + case internal::RoundingControlValue::TO_NEAREST: return FE_TONEAREST; - case internal::RoundingControlValue::Downward: + case internal::RoundingControlValue::DOWNWARD: return FE_DOWNWARD; - case internal::RoundingControlValue::Upward: + case internal::RoundingControlValue::UPWARD: return FE_UPWARD; - case internal::RoundingControlValue::TowardZero: + case internal::RoundingControlValue::TOWARD_ZERO: return FE_TOWARDZERO; default: return -1; // Error value. } } -static inline int setRound(int mode) { - uint16_t bitValue; +static inline int set_round(int mode) { + uint16_t bit_value; switch (mode) { case FE_TONEAREST: - bitValue = internal::RoundingControlValue::ToNearest; + bit_value = internal::RoundingControlValue::TO_NEAREST; break; case FE_DOWNWARD: - bitValue = internal::RoundingControlValue::Downward; + bit_value = internal::RoundingControlValue::DOWNWARD; break; case FE_UPWARD: - bitValue = internal::RoundingControlValue::Upward; + bit_value = internal::RoundingControlValue::UPWARD; break; case FE_TOWARDZERO: - bitValue = internal::RoundingControlValue::TowardZero; + bit_value = internal::RoundingControlValue::TOWARD_ZERO; break; default: return 1; // To indicate failure } - uint16_t x87Value = static_cast( - bitValue << internal::X87RoundingControlBitPosition); - uint16_t x87Control = internal::getX87ControlWord(); - x87Control = static_cast( - (x87Control & - ~(uint16_t(0x3) << internal::X87RoundingControlBitPosition)) | - x87Value); - internal::writeX87ControlWord(x87Control); - - uint32_t mxcsrValue = bitValue << internal::MXCSRRoundingControlBitPosition; - uint32_t mxcsrControl = internal::getMXCSR(); - mxcsrControl = - (mxcsrControl & ~(0x3 << internal::MXCSRRoundingControlBitPosition)) | - mxcsrValue; - internal::writeMXCSR(mxcsrControl); + uint16_t x87_value = static_cast( + bit_value << internal::X87_ROUNDING_CONTROL_BIT_POSITION); + uint16_t x87_control = internal::get_x87_control_word(); + x87_control = static_cast( + (x87_control & + ~(uint16_t(0x3) << internal::X87_ROUNDING_CONTROL_BIT_POSITION)) | + x87_value); + internal::write_x87_control_word(x87_control); + + uint32_t mxcsr_value = bit_value + << internal::MXCSR_ROUNDING_CONTROL_BIT_POSITION; + uint32_t mxcsr_control = internal::get_mxcsr(); + mxcsr_control = (mxcsr_control & + ~(0x3 << internal::MXCSR_ROUNDING_CONTROL_BIT_POSITION)) | + mxcsr_value; + internal::write_mxcsr(mxcsr_control); return 0; } @@ -354,7 +356,7 @@ "Internal floating point state does not match the public fenv_t type."); #ifdef _WIN32 -static inline int getEnv(fenv_t *envp) { +static inline int get_env(fenv_t *envp) { internal::FPState *state = reinterpret_cast(envp); internal::X87StateDescriptor X87Status; internal::getX87StateDescriptor(X87Status); @@ -363,7 +365,7 @@ return 0; } -static inline int setEnv(const fenv_t *envp) { +static inline int set_env(const fenv_t *envp) { const internal::FPState *state = reinterpret_cast(envp); internal::X87StateDescriptor X87Status; @@ -373,47 +375,47 @@ return 0; } #else -static inline int getEnv(fenv_t *envp) { +static inline int get_env(fenv_t *envp) { internal::FPState *state = reinterpret_cast(envp); - internal::getX87StateDescriptor(state->X87Status); - state->MXCSR = internal::getMXCSR(); + internal::get_x87_state_descriptor(state->X87Status); + state->MXCSR = internal::get_mxcsr(); return 0; } -static inline int setEnv(const fenv_t *envp) { +static inline int set_env(const fenv_t *envp) { // envp contains everything including pieces like the current // top of FPU stack. We cannot arbitrarily change them. So, we first // read the current status and update only those pieces which are // not disruptive. - internal::X87StateDescriptor x87Status; - internal::getX87StateDescriptor(x87Status); + internal::X87StateDescriptor x87_status; + internal::get_x87_state_descriptor(x87_status); if (envp == FE_DFL_ENV) { // Reset the exception flags in the status word. - x87Status.StatusWord &= ~uint16_t(0x3F); + x87_status.StatusWord &= ~uint16_t(0x3F); // Reset other non-sensitive parts of the status word. for (int i = 0; i < 5; i++) - x87Status._[i] = 0; + x87_status._[i] = 0; // In the control word, we do the following: // 1. Mask all exceptions // 2. Set rounding mode to round-to-nearest // 3. Set the internal precision to double extended precision. - x87Status.ControlWord |= uint16_t(0x3F); // Mask all exceptions. - x87Status.ControlWord &= ~(uint16_t(0x3) << 10); // Round to nearest. - x87Status.ControlWord |= (uint16_t(0x3) << 8); // Extended precision. - internal::writeX87StateDescriptor(x87Status); + x87_status.ControlWord |= uint16_t(0x3F); // Mask all exceptions. + x87_status.ControlWord &= ~(uint16_t(0x3) << 10); // Round to nearest. + x87_status.ControlWord |= (uint16_t(0x3) << 8); // Extended precision. + internal::write_x87_state_descriptor(x87_status); // We take the exact same approach MXCSR register as well. // MXCSR has two additional fields, "flush-to-zero" and // "denormals-are-zero". We reset those bits. Also, MXCSR does not // have a field which controls the precision of internal operations. - uint32_t mxcsr = internal::getMXCSR(); + uint32_t mxcsr = internal::get_mxcsr(); mxcsr &= ~uint16_t(0x3F); // Clear exception flags. mxcsr &= ~(uint16_t(0x1) << 6); // Reset denormals-are-zero mxcsr |= (uint16_t(0x3F) << 7); // Mask exceptions mxcsr &= ~(uint16_t(0x3) << 13); // Round to nearest. mxcsr &= ~(uint16_t(0x1) << 15); // Reset flush-to-zero - internal::writeMXCSR(mxcsr); + internal::write_mxcsr(mxcsr); return 0; } @@ -422,17 +424,17 @@ reinterpret_cast(envp); // Copy the exception status flags from envp. - x87Status.StatusWord &= ~uint16_t(0x3F); - x87Status.StatusWord |= (fpstate->X87Status.StatusWord & 0x3F); + x87_status.StatusWord &= ~uint16_t(0x3F); + x87_status.StatusWord |= (fpstate->X87Status.StatusWord & 0x3F); // Copy other non-sensitive parts of the status word. for (int i = 0; i < 5; i++) - x87Status._[i] = fpstate->X87Status._[i]; + x87_status._[i] = fpstate->X87Status._[i]; // We can set the x87 control word as is as there no sensitive bits. - x87Status.ControlWord = fpstate->X87Status.ControlWord; - internal::writeX87StateDescriptor(x87Status); + x87_status.ControlWord = fpstate->X87Status.ControlWord; + internal::write_x87_state_descriptor(x87_status); // We can write the MXCSR state as is as there are no sensitive bits. - internal::writeMXCSR(fpstate->MXCSR); + internal::write_mxcsr(fpstate->MXCSR); return 0; } #endif diff --git a/libc/src/__support/FPUtil/x86_64/FMA.h b/libc/src/__support/FPUtil/x86_64/FMA.h --- a/libc/src/__support/FPUtil/x86_64/FMA.h +++ b/libc/src/__support/FPUtil/x86_64/FMA.h @@ -15,7 +15,7 @@ namespace fputil { template -static inline cpp::EnableIfType::Value, T> fma(T x, T y, +static inline cpp::EnableIfType::VALUE, T> fma(T x, T y, T z) { float result = x; __asm__ __volatile__("vfmadd213ss %x2, %x1, %x0" @@ -25,7 +25,7 @@ } template -static inline cpp::EnableIfType::Value, T> fma(T x, T y, +static inline cpp::EnableIfType::VALUE, T> fma(T x, T y, T z) { double result = x; __asm__ __volatile__("vfmadd213sd %x2, %x1, %x0" diff --git a/libc/src/__support/detailed_powers_of_ten.h b/libc/src/__support/detailed_powers_of_ten.h --- a/libc/src/__support/detailed_powers_of_ten.h +++ b/libc/src/__support/detailed_powers_of_ten.h @@ -27,11 +27,11 @@ constexpr int32_t DETAILED_POWERS_OF_TEN_MAX_EXP_10 = 347; // This rescales the base 10 exponent by a factor of log(10)/log(2). -static inline int64_t exp10ToExp2(int64_t exp10) { +static inline int64_t exp10_to_exp2(int64_t exp10) { return (217706 * exp10) >> 16; } -static const uint64_t DETAILED_POWERS_OF_TEN[696][2] = { +static constexpr uint64_t DETAILED_POWERS_OF_TEN[696][2] = { {0x1732C869CD60E453, 0xFA8FD5A0081C0288}, // 1e-348 {0x0E7FBD42205C8EB4, 0x9C99E58405118195}, // 1e-347 {0x521FAC92A873B261, 0xC3C05EE50655E1FA}, // 1e-346 diff --git a/libc/src/__support/endian.h b/libc/src/__support/endian.h --- a/libc/src/__support/endian.h +++ b/libc/src/__support/endian.h @@ -28,108 +28,108 @@ // - to prevent fallback in (unlikely) case of middle-endianness. template struct Endian { - static constexpr const bool isLittle = ORDER == __ORDER_LITTLE_ENDIAN__; - static constexpr const bool isBig = ORDER == __ORDER_BIG_ENDIAN__; - template static T ToBigEndian(T value); - template static T ToLittleEndian(T value); + static constexpr const bool IS_LITTLE = ORDER == __ORDER_LITTLE_ENDIAN__; + static constexpr const bool IS_BIG = ORDER == __ORDER_BIG_ENDIAN__; + template static T to_big_endian(T value); + template static T to_little_endian(T value); }; // Little Endian specializations template <> template <> inline uint8_t -Endian<__ORDER_LITTLE_ENDIAN__>::ToBigEndian(uint8_t v) { +Endian<__ORDER_LITTLE_ENDIAN__>::to_big_endian(uint8_t v) { return v; } template <> template <> inline uint8_t -Endian<__ORDER_LITTLE_ENDIAN__>::ToLittleEndian(uint8_t v) { +Endian<__ORDER_LITTLE_ENDIAN__>::to_little_endian(uint8_t v) { return v; } template <> template <> inline uint16_t -Endian<__ORDER_LITTLE_ENDIAN__>::ToBigEndian(uint16_t v) { +Endian<__ORDER_LITTLE_ENDIAN__>::to_big_endian(uint16_t v) { return __builtin_bswap16(v); } template <> template <> inline uint16_t -Endian<__ORDER_LITTLE_ENDIAN__>::ToLittleEndian(uint16_t v) { +Endian<__ORDER_LITTLE_ENDIAN__>::to_little_endian(uint16_t v) { return v; } template <> template <> inline uint32_t -Endian<__ORDER_LITTLE_ENDIAN__>::ToBigEndian(uint32_t v) { +Endian<__ORDER_LITTLE_ENDIAN__>::to_big_endian(uint32_t v) { return __builtin_bswap32(v); } template <> template <> inline uint32_t -Endian<__ORDER_LITTLE_ENDIAN__>::ToLittleEndian(uint32_t v) { +Endian<__ORDER_LITTLE_ENDIAN__>::to_little_endian(uint32_t v) { return v; } template <> template <> inline uint64_t -Endian<__ORDER_LITTLE_ENDIAN__>::ToBigEndian(uint64_t v) { +Endian<__ORDER_LITTLE_ENDIAN__>::to_big_endian(uint64_t v) { return __builtin_bswap64(v); } template <> template <> inline uint64_t -Endian<__ORDER_LITTLE_ENDIAN__>::ToLittleEndian(uint64_t v) { +Endian<__ORDER_LITTLE_ENDIAN__>::to_little_endian(uint64_t v) { return v; } // Big Endian specializations template <> template <> -inline uint8_t Endian<__ORDER_BIG_ENDIAN__>::ToBigEndian(uint8_t v) { +inline uint8_t Endian<__ORDER_BIG_ENDIAN__>::to_big_endian(uint8_t v) { return v; } template <> template <> inline uint8_t -Endian<__ORDER_BIG_ENDIAN__>::ToLittleEndian(uint8_t v) { +Endian<__ORDER_BIG_ENDIAN__>::to_little_endian(uint8_t v) { return v; } template <> template <> inline uint16_t -Endian<__ORDER_BIG_ENDIAN__>::ToBigEndian(uint16_t v) { +Endian<__ORDER_BIG_ENDIAN__>::to_big_endian(uint16_t v) { return v; } template <> template <> inline uint16_t -Endian<__ORDER_BIG_ENDIAN__>::ToLittleEndian(uint16_t v) { +Endian<__ORDER_BIG_ENDIAN__>::to_little_endian(uint16_t v) { return __builtin_bswap16(v); } template <> template <> inline uint32_t -Endian<__ORDER_BIG_ENDIAN__>::ToBigEndian(uint32_t v) { +Endian<__ORDER_BIG_ENDIAN__>::to_big_endian(uint32_t v) { return v; } template <> template <> inline uint32_t -Endian<__ORDER_BIG_ENDIAN__>::ToLittleEndian(uint32_t v) { +Endian<__ORDER_BIG_ENDIAN__>::to_little_endian(uint32_t v) { return __builtin_bswap32(v); } template <> template <> inline uint64_t -Endian<__ORDER_BIG_ENDIAN__>::ToBigEndian(uint64_t v) { +Endian<__ORDER_BIG_ENDIAN__>::to_big_endian(uint64_t v) { return v; } template <> template <> inline uint64_t -Endian<__ORDER_BIG_ENDIAN__>::ToLittleEndian(uint64_t v) { +Endian<__ORDER_BIG_ENDIAN__>::to_little_endian(uint64_t v) { return __builtin_bswap64(v); } diff --git a/libc/src/__support/high_precision_decimal.h b/libc/src/__support/high_precision_decimal.h --- a/libc/src/__support/high_precision_decimal.h +++ b/libc/src/__support/high_precision_decimal.h @@ -111,7 +111,7 @@ uint8_t digits[MAX_NUM_DIGITS]; private: - bool shouldRoundUp(uint32_t roundToDigit) { + bool should_round_up(uint32_t roundToDigit) { if (roundToDigit < 0 || roundToDigit >= this->numDigits) { return false; } @@ -136,26 +136,28 @@ // Takes an amount to left shift and returns the number of new digits needed // to store the result based on LEFT_SHIFT_DIGIT_TABLE. - uint32_t getNumNewDigits(uint32_t lShiftAmount) { - const char *powerOfFive = LEFT_SHIFT_DIGIT_TABLE[lShiftAmount].powerOfFive; - uint32_t newDigits = LEFT_SHIFT_DIGIT_TABLE[lShiftAmount].newDigits; - uint32_t digitIndex = 0; - while (powerOfFive[digitIndex] != 0) { - if (digitIndex >= this->numDigits) { - return newDigits - 1; + uint32_t get_num_new_digits(uint32_t lShiftAmount) { + const char *power_of_five = + LEFT_SHIFT_DIGIT_TABLE[lShiftAmount].powerOfFive; + uint32_t new_digits = LEFT_SHIFT_DIGIT_TABLE[lShiftAmount].newDigits; + uint32_t digit_index = 0; + while (power_of_five[digit_index] != 0) { + if (digit_index >= this->numDigits) { + return new_digits - 1; } - if (this->digits[digitIndex] != powerOfFive[digitIndex] - '0') { - return newDigits - - ((this->digits[digitIndex] < powerOfFive[digitIndex] - '0') ? 1 - : 0); + if (this->digits[digit_index] != power_of_five[digit_index] - '0') { + return new_digits - + ((this->digits[digit_index] < power_of_five[digit_index] - '0') + ? 1 + : 0); } - ++digitIndex; + ++digit_index; } - return newDigits; + return new_digits; } // Trim all trailing 0s - void trimTrailingZeroes() { + void trim_trailing_zeroes() { while (this->numDigits > 0 && this->digits[this->numDigits - 1] == 0) { --this->numDigits; } @@ -167,68 +169,68 @@ // Perform a digitwise binary non-rounding right shift on this value by // shiftAmount. The shiftAmount can't be more than MAX_SHIFT_AMOUNT to prevent // overflow. - void rightShift(uint32_t shiftAmount) { - uint32_t readIndex = 0; - uint32_t writeIndex = 0; + void right_shift(uint32_t shiftAmount) { + uint32_t read_index = 0; + uint32_t write_index = 0; uint64_t accumulator = 0; - const uint64_t shiftMask = (uint64_t(1) << shiftAmount) - 1; + const uint64_t shift_mask = (uint64_t(1) << shiftAmount) - 1; // Warm Up phase: we don't have enough digits to start writing, so just // read them into the accumulator. while (accumulator >> shiftAmount == 0) { - uint64_t readDigit = 0; + uint64_t read_digit = 0; // If there are still digits to read, read the next one, else the digit is // assumed to be 0. - if (readIndex < this->numDigits) { - readDigit = this->digits[readIndex]; + if (read_index < this->numDigits) { + read_digit = this->digits[read_index]; } - accumulator = accumulator * 10 + readDigit; - ++readIndex; + accumulator = accumulator * 10 + read_digit; + ++read_index; } // Shift the decimal point by the number of digits it took to fill the // accumulator. - this->decimalPoint -= readIndex - 1; + this->decimalPoint -= read_index - 1; // Middle phase: we have enough digits to write, as well as more digits to // read. Keep reading until we run out of digits. - while (readIndex < this->numDigits) { - uint64_t readDigit = this->digits[readIndex]; - uint64_t writeDigit = accumulator >> shiftAmount; - accumulator &= shiftMask; - this->digits[writeIndex] = static_cast(writeDigit); - accumulator = accumulator * 10 + readDigit; - ++readIndex; - ++writeIndex; + while (read_index < this->numDigits) { + uint64_t read_digit = this->digits[read_index]; + uint64_t write_digit = accumulator >> shiftAmount; + accumulator &= shift_mask; + this->digits[write_index] = static_cast(write_digit); + accumulator = accumulator * 10 + read_digit; + ++read_index; + ++write_index; } // Cool Down phase: All of the readable digits have been read, so just write // the remainder, while treating any more digits as 0. while (accumulator > 0) { - uint64_t writeDigit = accumulator >> shiftAmount; - accumulator &= shiftMask; - if (writeIndex < MAX_NUM_DIGITS) { - this->digits[writeIndex] = static_cast(writeDigit); - ++writeIndex; - } else if (writeDigit > 0) { + uint64_t write_digit = accumulator >> shiftAmount; + accumulator &= shift_mask; + if (write_index < MAX_NUM_DIGITS) { + this->digits[write_index] = static_cast(write_digit); + ++write_index; + } else if (write_digit > 0) { this->truncated = true; } accumulator = accumulator * 10; } - this->numDigits = writeIndex; - this->trimTrailingZeroes(); + this->numDigits = write_index; + this->trim_trailing_zeroes(); } // Perform a digitwise binary non-rounding left shift on this value by // shiftAmount. The shiftAmount can't be more than MAX_SHIFT_AMOUNT to prevent // overflow. - void leftShift(uint32_t shiftAmount) { - uint32_t newDigits = this->getNumNewDigits(shiftAmount); + void left_shift(uint32_t shiftAmount) { + uint32_t new_digits = this->get_num_new_digits(shiftAmount); - int32_t readIndex = this->numDigits - 1; - uint32_t writeIndex = this->numDigits + newDigits; + int32_t read_index = this->numDigits - 1; + uint32_t write_index = this->numDigits + new_digits; uint64_t accumulator = 0; @@ -237,55 +239,55 @@ // Middle phase: while we have more digits to read, keep reading as well as // writing. - while (readIndex >= 0) { - accumulator += static_cast(this->digits[readIndex]) + while (read_index >= 0) { + accumulator += static_cast(this->digits[read_index]) << shiftAmount; - uint64_t nextAccumulator = accumulator / 10; - uint64_t writeDigit = accumulator - (10 * nextAccumulator); - --writeIndex; - if (writeIndex < MAX_NUM_DIGITS) { - this->digits[writeIndex] = static_cast(writeDigit); - } else if (writeDigit != 0) { + uint64_t next_accumulator = accumulator / 10; + uint64_t write_digit = accumulator - (10 * next_accumulator); + --write_index; + if (write_index < MAX_NUM_DIGITS) { + this->digits[write_index] = static_cast(write_digit); + } else if (write_digit != 0) { this->truncated = true; } - accumulator = nextAccumulator; - --readIndex; + accumulator = next_accumulator; + --read_index; } // Cool Down phase: there are no more digits to read, so just write the // remaining digits in the accumulator. while (accumulator > 0) { - uint64_t nextAccumulator = accumulator / 10; - uint64_t writeDigit = accumulator - (10 * nextAccumulator); - --writeIndex; - if (writeIndex < MAX_NUM_DIGITS) { - this->digits[writeIndex] = static_cast(writeDigit); - } else if (writeDigit != 0) { + uint64_t next_accumulator = accumulator / 10; + uint64_t write_digit = accumulator - (10 * next_accumulator); + --write_index; + if (write_index < MAX_NUM_DIGITS) { + this->digits[write_index] = static_cast(write_digit); + } else if (write_digit != 0) { this->truncated = true; } - accumulator = nextAccumulator; + accumulator = next_accumulator; } - this->numDigits += newDigits; + this->numDigits += new_digits; if (this->numDigits > MAX_NUM_DIGITS) { this->numDigits = MAX_NUM_DIGITS; } - this->decimalPoint += newDigits; - this->trimTrailingZeroes(); + this->decimalPoint += new_digits; + this->trim_trailing_zeroes(); } public: // numString is assumed to be a string of numeric characters. It doesn't // handle leading spaces. HighPrecisionDecimal(const char *__restrict numString) { - bool sawDot = false; + bool saw_dot = false; while (isdigit(*numString) || *numString == '.') { if (*numString == '.') { - if (sawDot) { + if (saw_dot) { break; } this->decimalPoint = this->numDigits; - sawDot = true; + saw_dot = true; } else { if (*numString == '0' && this->numDigits == 0) { --this->decimalPoint; @@ -302,24 +304,24 @@ ++numString; } - if (!sawDot) { + if (!saw_dot) { this->decimalPoint = this->numDigits; } if ((*numString | 32) == 'e') { ++numString; if (isdigit(*numString) || *numString == '+' || *numString == '-') { - int32_t addToExp = strtointeger(numString, nullptr, 10); - if (addToExp > 100000) { - addToExp = 100000; - } else if (addToExp < -100000) { - addToExp = -100000; + int32_t add_to_exp = strtointeger(numString, nullptr, 10); + if (add_to_exp > 100000) { + add_to_exp = 100000; + } else if (add_to_exp < -100000) { + add_to_exp = -100000; } - this->decimalPoint += addToExp; + this->decimalPoint += add_to_exp; } } - this->trimTrailingZeroes(); + this->trim_trailing_zeroes(); } // Binary shift left (shiftAmount > 0) or right (shiftAmount < 0) @@ -330,39 +332,39 @@ // Left else if (shiftAmount > 0) { while (static_cast(shiftAmount) > MAX_SHIFT_AMOUNT) { - this->leftShift(MAX_SHIFT_AMOUNT); + this->left_shift(MAX_SHIFT_AMOUNT); shiftAmount -= MAX_SHIFT_AMOUNT; } - this->leftShift(shiftAmount); + this->left_shift(shiftAmount); } // Right else { while (static_cast(shiftAmount) < -MAX_SHIFT_AMOUNT) { - this->rightShift(MAX_SHIFT_AMOUNT); + this->right_shift(MAX_SHIFT_AMOUNT); shiftAmount += MAX_SHIFT_AMOUNT; } - this->rightShift(-shiftAmount); + this->right_shift(-shiftAmount); } } // Round the number represented to the closest value of unsigned int type T. // This is done ignoring overflow. - template T roundToIntegerType() { + template T round_to_integer_type() { T result = 0; - uint32_t curDigit = 0; + uint32_t cur_digit = 0; - while (static_cast(curDigit) < this->decimalPoint && - curDigit < this->numDigits) { - result = result * 10 + (this->digits[curDigit]); - ++curDigit; + while (static_cast(cur_digit) < this->decimalPoint && + cur_digit < this->numDigits) { + result = result * 10 + (this->digits[cur_digit]); + ++cur_digit; } // If there are implicit 0s at the end of the number, include those. - while (static_cast(curDigit) < this->decimalPoint) { + while (static_cast(cur_digit) < this->decimalPoint) { result *= 10; - ++curDigit; + ++cur_digit; } - if (this->shouldRoundUp(this->decimalPoint)) { + if (this->should_round_up(this->decimalPoint)) { ++result; } return result; @@ -370,10 +372,10 @@ // Extra functions for testing. - uint8_t *getDigits() { return this->digits; } - uint32_t getNumDigits() { return this->numDigits; } - int32_t getDecimalPoint() { return this->decimalPoint; } - void setTruncated(bool trunc) { this->truncated = trunc; } + uint8_t *get_digits() { return this->digits; } + uint32_t get_num_digits() { return this->numDigits; } + int32_t get_decimal_point() { return this->decimalPoint; } + void set_truncated(bool trunc) { this->truncated = trunc; } }; } // namespace internal diff --git a/libc/src/__support/integer_operations.h b/libc/src/__support/integer_operations.h --- a/libc/src/__support/integer_operations.h +++ b/libc/src/__support/integer_operations.h @@ -14,14 +14,14 @@ namespace __llvm_libc { template -static constexpr cpp::EnableIfType::Value, T> -integerAbs(T n) { +static constexpr cpp::EnableIfType::VALUE, T> +integer_abs(T n) { return (n < 0) ? -n : n; } template -static constexpr cpp::EnableIfType::Value, void> -integerRemQuo(T x, T y, T ", T &rem) { +static constexpr cpp::EnableIfType::VALUE, void> +integer_rem_quo(T x, T y, T ", T &rem) { quot = x / y; rem = x % y; } diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h --- a/libc/src/__support/str_to_float.h +++ b/libc/src/__support/str_to_float.h @@ -20,42 +20,42 @@ namespace __llvm_libc { namespace internal { -template uint32_t inline leadingZeroes(T inputNumber) { +template uint32_t inline leading_zeroes(T inputNumber) { // TODO(michaelrj): investigate the portability of using something like // __builtin_clz for specific types. - constexpr uint32_t bitsInT = sizeof(T) * 8; + constexpr uint32_t BITS_IN_T = sizeof(T) * 8; if (inputNumber == 0) { - return bitsInT; + return BITS_IN_T; } - uint32_t curGuess = bitsInT / 2; - uint32_t rangeSize = bitsInT / 2; + uint32_t cur_guess = BITS_IN_T / 2; + uint32_t range_size = BITS_IN_T / 2; // while either shifting by curGuess does not get rid of all of the bits or // shifting by one less also gets rid of all of the bits then we have not // found the first bit. - while (((inputNumber >> curGuess) > 0) || - ((inputNumber >> (curGuess - 1)) == 0)) { + while (((inputNumber >> cur_guess) > 0) || + ((inputNumber >> (cur_guess - 1)) == 0)) { // Binary search for the first set bit - rangeSize /= 2; - if (rangeSize == 0) { + range_size /= 2; + if (range_size == 0) { break; } - if ((inputNumber >> curGuess) > 0) { - curGuess += rangeSize; + if ((inputNumber >> cur_guess) > 0) { + cur_guess += range_size; } else { - curGuess -= rangeSize; + cur_guess -= range_size; } } - if (inputNumber >> curGuess > 0) { - curGuess++; + if (inputNumber >> cur_guess > 0) { + cur_guess++; } - return bitsInT - curGuess; + return BITS_IN_T - cur_guess; } -template <> uint32_t inline leadingZeroes(uint32_t inputNumber) { +template <> uint32_t inline leading_zeroes(uint32_t inputNumber) { return inputNumber == 0 ? 32 : __builtin_clz(inputNumber); } -template <> uint32_t inline leadingZeroes(uint64_t inputNumber) { +template <> uint32_t inline leading_zeroes(uint64_t inputNumber) { return inputNumber == 0 ? 64 : __builtin_clzll(inputNumber); } @@ -77,9 +77,9 @@ // for some optimizations as well as handling 32 bit floats. template static inline bool -eiselLemire(typename fputil::FPBits::UIntType mantissa, int32_t exp10, - typename fputil::FPBits::UIntType *outputMantissa, - uint32_t *outputExp2) { +eisel_lemire(typename fputil::FPBits::UIntType mantissa, int32_t exp10, + typename fputil::FPBits::UIntType *outputMantissa, + uint32_t *outputExp2) { using BitsType = typename fputil::FPBits::UIntType; constexpr uint32_t BITS_IN_MANTISSA = sizeof(mantissa) * 8; @@ -96,71 +96,74 @@ } // Normalization - uint32_t clz = leadingZeroes(mantissa); + uint32_t clz = leading_zeroes(mantissa); mantissa <<= clz; - uint32_t exp2 = exp10ToExp2(exp10) + BITS_IN_MANTISSA + - fputil::FloatProperties::exponentBias - clz; + uint32_t exp2 = exp10_to_exp2(exp10) + BITS_IN_MANTISSA + + fputil::FloatProperties::EXPONENT_BIAS - clz; // Multiplication - const uint64_t *powerOfTen = + const uint64_t *power_of_ten = DETAILED_POWERS_OF_TEN[exp10 - DETAILED_POWERS_OF_TEN_MIN_EXP_10]; - __uint128_t firstApprox = static_cast<__uint128_t>(mantissa) * - static_cast<__uint128_t>(powerOfTen[1]); + __uint128_t first_approx = static_cast<__uint128_t>(mantissa) * + static_cast<__uint128_t>(power_of_ten[1]); // Wider Approximation - __uint128_t finalApprox; + __uint128_t final_approx; // The halfway constant is used to check if the bits that will be shifted away // intially are all 1. For doubles this is 64 (bitstype size) - 52 (final // mantissa size) - 3 (we shift away the last two bits separately for // accuracy, and the most significant bit is ignored.) = 9. Similarly, it's 6 // for floats in this case. - const uint64_t halfwayConstant = sizeof(T) == 8 ? 0x1FF : 0x3F; - if ((high64(firstApprox) & halfwayConstant) == halfwayConstant && - low64(firstApprox) + mantissa < mantissa) { - __uint128_t lowBits = static_cast<__uint128_t>(mantissa) * - static_cast<__uint128_t>(powerOfTen[0]); - __uint128_t secondApprox = - firstApprox + static_cast<__uint128_t>(high64(lowBits)); - - if ((high64(secondApprox) & halfwayConstant) == halfwayConstant && - low64(secondApprox) + 1 == 0 && low64(lowBits) + mantissa < mantissa) { + const uint64_t halfway_constant = sizeof(T) == 8 ? 0x1FF : 0x3F; + if ((high64(first_approx) & halfway_constant) == halfway_constant && + low64(first_approx) + mantissa < mantissa) { + __uint128_t low_bits = static_cast<__uint128_t>(mantissa) * + static_cast<__uint128_t>(power_of_ten[0]); + __uint128_t second_approx = + first_approx + static_cast<__uint128_t>(high64(low_bits)); + + if ((high64(second_approx) & halfway_constant) == halfway_constant && + low64(second_approx) + 1 == 0 && + low64(low_bits) + mantissa < mantissa) { return false; } - finalApprox = secondApprox; + final_approx = second_approx; } else { - finalApprox = firstApprox; + final_approx = first_approx; } // Shifting to 54 bits for doubles and 25 bits for floats - BitsType msb = high64(finalApprox) >> (BITS_IN_MANTISSA - 1); - BitsType finalMantissa = - high64(finalApprox) >> (msb + BITS_IN_MANTISSA - - (fputil::FloatProperties::mantissaWidth + 3)); + BitsType msb = high64(final_approx) >> (BITS_IN_MANTISSA - 1); + BitsType final_mantissa = high64(final_approx) >> + (msb + BITS_IN_MANTISSA - + (fputil::FloatProperties::MANTISSA_WIDTH + 3)); exp2 -= 1 ^ msb; // same as !msb // Half-way ambiguity - if (low64(finalApprox) == 0 && (high64(finalApprox) & halfwayConstant) == 0 && - (finalMantissa & 3) == 1) { + if (low64(final_approx) == 0 && + (high64(final_approx) & halfway_constant) == 0 && + (final_mantissa & 3) == 1) { return false; } // From 54 to 53 bits for doubles and 25 to 24 bits for floats - finalMantissa += finalMantissa & 1; - finalMantissa >>= 1; - if ((finalMantissa >> (fputil::FloatProperties::mantissaWidth + 1)) > 0) { - finalMantissa >>= 1; + final_mantissa += final_mantissa & 1; + final_mantissa >>= 1; + if ((final_mantissa >> (fputil::FloatProperties::MANTISSA_WIDTH + 1)) > + 0) { + final_mantissa >>= 1; ++exp2; } // The if block is equivalent to (but has fewer branches than): // if exp2 <= 0 || exp2 >= 0x7FF { etc } - if (exp2 - 1 >= (1 << fputil::FloatProperties::exponentWidth) - 2) { + if (exp2 - 1 >= (1 << fputil::FloatProperties::EXPONENT_WIDTH) - 2) { return false; } - *outputMantissa = finalMantissa; + *outputMantissa = final_mantissa; *outputExp2 = exp2; return true; } @@ -180,14 +183,14 @@ // link: https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html template static inline void -simpleDecimalConversion(const char *__restrict numStart, - typename fputil::FPBits::UIntType *outputMantissa, - uint32_t *outputExp2) { +simple_decimal_conversion(const char *__restrict numStart, + typename fputil::FPBits::UIntType *outputMantissa, + uint32_t *outputExp2) { int32_t exp2 = 0; HighPrecisionDecimal hpd = HighPrecisionDecimal(numStart); - if (hpd.getNumDigits() == 0) { + if (hpd.get_num_digits() == 0) { *outputMantissa = 0; *outputExp2 = 0; return; @@ -195,19 +198,19 @@ // If the exponent is too large and can't be represented in this size of // float, return inf. - if (hpd.getDecimalPoint() > 0 && - exp10ToExp2(hpd.getDecimalPoint() - 1) > - static_cast(fputil::FloatProperties::exponentBias)) { + if (hpd.get_decimal_point() > 0 && + exp10_to_exp2(hpd.get_decimal_point() - 1) > + static_cast(fputil::FloatProperties::EXPONENT_BIAS)) { *outputMantissa = 0; - *outputExp2 = fputil::FPBits::maxExponent; + *outputExp2 = fputil::FPBits::MAX_EXPONENT; errno = ERANGE; return; } // If the exponent is too small even for a subnormal, return 0. - if (hpd.getDecimalPoint() < 0 && - exp10ToExp2(-hpd.getDecimalPoint()) > - static_cast(fputil::FloatProperties::exponentBias + - fputil::FloatProperties::mantissaWidth)) { + if (hpd.get_decimal_point() < 0 && + exp10_to_exp2(-hpd.get_decimal_point()) > + static_cast(fputil::FloatProperties::EXPONENT_BIAS + + fputil::FloatProperties::MANTISSA_WIDTH)) { *outputMantissa = 0; *outputExp2 = 0; errno = ERANGE; @@ -215,31 +218,31 @@ } // Right shift until the number is smaller than 1. - while (hpd.getDecimalPoint() > 0) { - int32_t shiftAmount = 0; - if (hpd.getDecimalPoint() >= NUM_POWERS_OF_TWO) { - shiftAmount = 60; + while (hpd.get_decimal_point() > 0) { + int32_t shift_amount = 0; + if (hpd.get_decimal_point() >= NUM_POWERS_OF_TWO) { + shift_amount = 60; } else { - shiftAmount = POWERS_OF_TWO[hpd.getDecimalPoint()]; + shift_amount = POWERS_OF_TWO[hpd.get_decimal_point()]; } - exp2 += shiftAmount; - hpd.shift(-shiftAmount); + exp2 += shift_amount; + hpd.shift(-shift_amount); } // Left shift until the number is between 1/2 and 1 - while (hpd.getDecimalPoint() < 0 || - (hpd.getDecimalPoint() == 0 && hpd.getDigits()[0] < 5)) { - int32_t shiftAmount = 0; - - if (-hpd.getDecimalPoint() >= NUM_POWERS_OF_TWO) { - shiftAmount = 60; - } else if (hpd.getDecimalPoint() != 0) { - shiftAmount = POWERS_OF_TWO[-hpd.getDecimalPoint()]; + while (hpd.get_decimal_point() < 0 || + (hpd.get_decimal_point() == 0 && hpd.get_digits()[0] < 5)) { + int32_t shift_amount = 0; + + if (-hpd.get_decimal_point() >= NUM_POWERS_OF_TWO) { + shift_amount = 60; + } else if (hpd.get_decimal_point() != 0) { + shift_amount = POWERS_OF_TWO[-hpd.get_decimal_point()]; } else { // This handles the case of the number being between .1 and .5 - shiftAmount = 1; + shift_amount = 1; } - exp2 -= shiftAmount; - hpd.shift(shiftAmount); + exp2 -= shift_amount; + hpd.shift(shift_amount); } // Left shift once so that the number is between 1 and 2 @@ -247,20 +250,20 @@ hpd.shift(1); // Get the biased exponent - exp2 += fputil::FloatProperties::exponentBias; + exp2 += fputil::FloatProperties::EXPONENT_BIAS; // Handle the exponent being too large (and return inf). - if (exp2 >= fputil::FPBits::maxExponent) { + if (exp2 >= fputil::FPBits::MAX_EXPONENT) { *outputMantissa = 0; - *outputExp2 = fputil::FPBits::maxExponent; + *outputExp2 = fputil::FPBits::MAX_EXPONENT; errno = ERANGE; return; } // Shift left to fill the mantissa - hpd.shift(fputil::FloatProperties::mantissaWidth); - typename fputil::FPBits::UIntType finalMantissa = - hpd.roundToIntegerType::UIntType>(); + hpd.shift(fputil::FloatProperties::MANTISSA_WIDTH); + typename fputil::FPBits::UIntType final_mantissa = + hpd.round_to_integer_type::UIntType>(); // Handle subnormals if (exp2 <= 0) { @@ -272,19 +275,19 @@ // Shift right one more time to compensate for the left shift to get it // between 1 and 2. hpd.shift(-1); - finalMantissa = - hpd.roundToIntegerType::UIntType>(); + final_mantissa = + hpd.round_to_integer_type::UIntType>(); // Check if by shifting right we've caused this to round to a normal number. - if ((finalMantissa >> fputil::FloatProperties::mantissaWidth) != 0) { + if ((final_mantissa >> fputil::FloatProperties::MANTISSA_WIDTH) != 0) { ++exp2; } } // Check if rounding added a bit, and shift down if that's the case. - if (finalMantissa == typename fputil::FPBits::UIntType(2) - << fputil::FloatProperties::mantissaWidth) { - finalMantissa >>= 1; + if (final_mantissa == typename fputil::FPBits::UIntType(2) + << fputil::FloatProperties::MANTISSA_WIDTH) { + final_mantissa >>= 1; ++exp2; } @@ -292,7 +295,7 @@ errno = ERANGE; } - *outputMantissa = finalMantissa; + *outputMantissa = final_mantissa; *outputExp2 = exp2; } @@ -308,21 +311,21 @@ template <> class ClingerConsts { public: - static constexpr float powersOfTenArray[] = {1e0, 1e1, 1e2, 1e3, 1e4, 1e5, - 1e6, 1e7, 1e8, 1e9, 1e10}; - static constexpr int32_t exactPowersOfTen = 10; - static constexpr int32_t digitsInMantissa = 7; - static constexpr float maxExactInt = 16777215.0; + static constexpr float POWERS_OF_TEN_ARRAY[] = {1e0, 1e1, 1e2, 1e3, 1e4, 1e5, + 1e6, 1e7, 1e8, 1e9, 1e10}; + static constexpr int32_t EXACT_POWERS_OF_TEN = 10; + static constexpr int32_t DIGITS_IN_MANTISSA = 7; + static constexpr float MAX_EXACT_INT = 16777215.0; }; template <> class ClingerConsts { public: - static constexpr double powersOfTenArray[] = { + static constexpr double POWERS_OF_TEN_ARRAY[] = { 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22}; - static constexpr int32_t exactPowersOfTen = 22; - static constexpr int32_t digitsInMantissa = 15; - static constexpr double maxExactInt = 9007199254740991.0; + static constexpr int32_t EXACT_POWERS_OF_TEN = 22; + static constexpr int32_t DIGITS_IN_MANTISSA = 15; + static constexpr double MAX_EXACT_INT = 9007199254740991.0; }; // Take an exact mantissa and exponent and attempt to convert it using only @@ -331,45 +334,44 @@ // Fast Path, as described above. template static inline bool -clingerFastPath(typename fputil::FPBits::UIntType mantissa, int32_t exp10, - typename fputil::FPBits::UIntType *outputMantissa, - uint32_t *outputExp2) { - if (mantissa >> fputil::FloatProperties::mantissaWidth > 0) { +clinger_fast_path(typename fputil::FPBits::UIntType mantissa, int32_t exp10, + typename fputil::FPBits::UIntType *outputMantissa, + uint32_t *outputExp2) { + if (mantissa >> fputil::FloatProperties::MANTISSA_WIDTH > 0) { return false; } fputil::FPBits result; - T floatMantissa = static_cast(mantissa); + T float_mantissa = static_cast(mantissa); if (exp10 == 0) { - result = fputil::FPBits(floatMantissa); + result = fputil::FPBits(float_mantissa); } if (exp10 > 0) { - if (exp10 > ClingerConsts::exactPowersOfTen + - ClingerConsts::digitsInMantissa) { + if (exp10 > ClingerConsts::EXACT_POWERS_OF_TEN + + ClingerConsts::DIGITS_IN_MANTISSA) { return false; } - if (exp10 > ClingerConsts::exactPowersOfTen) { - floatMantissa = - floatMantissa * - ClingerConsts< - T>::powersOfTenArray[exp10 - ClingerConsts::exactPowersOfTen]; - exp10 = ClingerConsts::exactPowersOfTen; + if (exp10 > ClingerConsts::EXACT_POWERS_OF_TEN) { + float_mantissa = float_mantissa * + ClingerConsts::POWERS_OF_TEN_ARRAY + [exp10 - ClingerConsts::EXACT_POWERS_OF_TEN]; + exp10 = ClingerConsts::EXACT_POWERS_OF_TEN; } - if (floatMantissa > ClingerConsts::maxExactInt) { + if (float_mantissa > ClingerConsts::MAX_EXACT_INT) { return false; } - result = fputil::FPBits(floatMantissa * - ClingerConsts::powersOfTenArray[exp10]); + result = fputil::FPBits(float_mantissa * + ClingerConsts::POWERS_OF_TEN_ARRAY[exp10]); } else if (exp10 < 0) { - if (-exp10 > ClingerConsts::exactPowersOfTen) { + if (-exp10 > ClingerConsts::EXACT_POWERS_OF_TEN) { return false; } - result = fputil::FPBits(floatMantissa / - ClingerConsts::powersOfTenArray[-exp10]); + result = fputil::FPBits(float_mantissa / + ClingerConsts::POWERS_OF_TEN_ARRAY[-exp10]); } - *outputMantissa = result.getMantissa(); - *outputExp2 = result.getUnbiasedExponent(); + *outputMantissa = result.get_mantissa(); + *outputExp2 = result.get_unbiased_exponent(); return true; } @@ -380,25 +382,26 @@ // and outputExp2. template static inline void -decimalExpToFloat(typename fputil::FPBits::UIntType mantissa, int32_t exp10, - const char *__restrict numStart, bool truncated, - typename fputil::FPBits::UIntType *outputMantissa, - uint32_t *outputExp2) { +decimal_exp_to_float(typename fputil::FPBits::UIntType mantissa, + int32_t exp10, const char *__restrict numStart, + bool truncated, + typename fputil::FPBits::UIntType *outputMantissa, + uint32_t *outputExp2) { // If the exponent is too large and can't be represented in this size of // float, return inf. These bounds are very loose, but are mostly serving as a // first pass. Some close numbers getting through is okay. if (exp10 > - static_cast(fputil::FloatProperties::exponentBias) / 3) { + static_cast(fputil::FloatProperties::EXPONENT_BIAS) / 3) { *outputMantissa = 0; - *outputExp2 = fputil::FPBits::maxExponent; + *outputExp2 = fputil::FPBits::MAX_EXPONENT; errno = ERANGE; return; } // If the exponent is too small even for a subnormal, return 0. if (exp10 < 0 && -static_cast(exp10) > - static_cast(fputil::FloatProperties::exponentBias + - fputil::FloatProperties::mantissaWidth) / + static_cast(fputil::FloatProperties::EXPONENT_BIAS + + fputil::FloatProperties::MANTISSA_WIDTH) / 2) { *outputMantissa = 0; *outputExp2 = 0; @@ -407,29 +410,29 @@ } if (!truncated) { - if (clingerFastPath(mantissa, exp10, outputMantissa, outputExp2)) { + if (clinger_fast_path(mantissa, exp10, outputMantissa, outputExp2)) { return; } } // Try Eisel-Lemire - if (eiselLemire(mantissa, exp10, outputMantissa, outputExp2)) { + if (eisel_lemire(mantissa, exp10, outputMantissa, outputExp2)) { if (!truncated) { return; } // If the mantissa is truncated, then the result may be off by the LSB, so // check if rounding the mantissa up changes the result. If not, then it's // safe, else use the fallback. - typename fputil::FPBits::UIntType firstMantissa = *outputMantissa; - uint32_t firstExp2 = *outputExp2; - if (eiselLemire(mantissa + 1, exp10, outputMantissa, outputExp2)) { - if (*outputMantissa == firstMantissa && *outputExp2 == firstExp2) { + typename fputil::FPBits::UIntType first_mantissa = *outputMantissa; + uint32_t first_exp2 = *outputExp2; + if (eisel_lemire(mantissa + 1, exp10, outputMantissa, outputExp2)) { + if (*outputMantissa == first_mantissa && *outputExp2 == first_exp2) { return; } } } - simpleDecimalConversion(numStart, outputMantissa, outputExp2); + simple_decimal_conversion(numStart, outputMantissa, outputExp2); return; } @@ -440,46 +443,47 @@ // numbers since a base 16 exponent multiplied by 4 is the base 2 exponent. template static inline void -binaryExpToFloat(typename fputil::FPBits::UIntType mantissa, int32_t exp2, - bool truncated, - typename fputil::FPBits::UIntType *outputMantissa, - uint32_t *outputExp2) { +binary_exp_to_float(typename fputil::FPBits::UIntType mantissa, int32_t exp2, + bool truncated, + typename fputil::FPBits::UIntType *outputMantissa, + uint32_t *outputExp2) { using BitsType = typename fputil::FPBits::UIntType; // This is the number of leading zeroes a properly normalized float of type T // should have. constexpr int32_t NUMBITS = sizeof(BitsType) * 8; constexpr int32_t INF_EXP = - (1 << fputil::FloatProperties::exponentWidth) - 1; + (1 << fputil::FloatProperties::EXPONENT_WIDTH) - 1; // Normalization step 1: Bring the leading bit to the highest bit of BitsType. - uint32_t amountToShiftLeft = leadingZeroes(mantissa); - mantissa <<= amountToShiftLeft; + uint32_t amount_to_shift_left = leading_zeroes(mantissa); + mantissa <<= amount_to_shift_left; // Keep exp2 representing the exponent of the lowest bit of BitsType. - exp2 -= amountToShiftLeft; + exp2 -= amount_to_shift_left; // biasedExponent represents the biased exponent of the most significant bit. - int32_t biasedExponent = exp2 + NUMBITS + fputil::FPBits::exponentBias - 1; + int32_t biased_exponent = + exp2 + NUMBITS + fputil::FPBits::EXPONENT_BIAS - 1; // Handle numbers that're too large and get squashed to inf - if (biasedExponent >= INF_EXP) { + if (biased_exponent >= INF_EXP) { // This indicates an overflow, so we make the result INF and set errno. - *outputExp2 = (1 << fputil::FloatProperties::exponentWidth) - 1; + *outputExp2 = (1 << fputil::FloatProperties::EXPONENT_WIDTH) - 1; *outputMantissa = 0; errno = ERANGE; return; } - uint32_t amountToShiftRight = - NUMBITS - fputil::FloatProperties::mantissaWidth - 1; + uint32_t amount_to_shift_right = + NUMBITS - fputil::FloatProperties::MANTISSA_WIDTH - 1; // Handle subnormals. - if (biasedExponent <= 0) { - amountToShiftRight += 1 - biasedExponent; - biasedExponent = 0; + if (biased_exponent <= 0) { + amount_to_shift_right += 1 - biased_exponent; + biased_exponent = 0; - if (amountToShiftRight > NUMBITS) { + if (amount_to_shift_right > NUMBITS) { // Return 0 if the exponent is too small. *outputMantissa = 0; *outputExp2 = 0; @@ -488,39 +492,39 @@ } } - BitsType roundBitMask = BitsType(1) << (amountToShiftRight - 1); - BitsType stickyMask = roundBitMask - 1; - bool roundBit = mantissa & roundBitMask; - bool stickyBit = static_cast(mantissa & stickyMask) || truncated; + BitsType round_bit_mask = BitsType(1) << (amount_to_shift_right - 1); + BitsType sticky_mask = round_bit_mask - 1; + bool round_bit = mantissa & round_bit_mask; + bool sticky_bit = static_cast(mantissa & sticky_mask) || truncated; - if (amountToShiftRight < NUMBITS) { + if (amount_to_shift_right < NUMBITS) { // Shift the mantissa and clear the implicit bit. - mantissa >>= amountToShiftRight; - mantissa &= fputil::FloatProperties::mantissaMask; + mantissa >>= amount_to_shift_right; + mantissa &= fputil::FloatProperties::MANTISSA_MASK; } else { mantissa = 0; } - bool leastSignificantBit = mantissa & BitsType(1); + bool least_significant_bit = mantissa & BitsType(1); // Perform rounding-to-nearest, tie-to-even. - if (roundBit && (leastSignificantBit || stickyBit)) { + if (round_bit && (least_significant_bit || sticky_bit)) { ++mantissa; } - if (mantissa > fputil::FloatProperties::mantissaMask) { + if (mantissa > fputil::FloatProperties::MANTISSA_MASK) { // Rounding causes the exponent to increase. - ++biasedExponent; + ++biased_exponent; - if (biasedExponent == INF_EXP) { + if (biased_exponent == INF_EXP) { errno = ERANGE; } } - if (biasedExponent == 0) { + if (biased_exponent == 0) { errno = ERANGE; } - *outputMantissa = mantissa & fputil::FloatProperties::mantissaMask; - *outputExp2 = biasedExponent; + *outputMantissa = mantissa & fputil::FloatProperties::MANTISSA_MASK; + *outputExp2 = biased_exponent; } // checks if the next 4 characters of the string pointer are the start of a @@ -545,18 +549,18 @@ // here. template static inline bool -decimalStringToFloat(const char *__restrict src, const char DECIMAL_POINT, - char **__restrict strEnd, - typename fputil::FPBits::UIntType *outputMantissa, - uint32_t *outputExponent) { +decimal_string_to_float(const char *__restrict src, const char DECIMAL_POINT, + char **__restrict strEnd, + typename fputil::FPBits::UIntType *outputMantissa, + uint32_t *outputExponent) { using BitsType = typename fputil::FPBits::UIntType; constexpr uint32_t BASE = 10; constexpr char EXPONENT_MARKER = 'e'; - const char *__restrict numStart = src; + const char *__restrict num_start = src; bool truncated = false; - bool seenDigit = false; - bool afterDecimal = false; + bool seen_digit = false; + bool after_decimal = false; BitsType mantissa = 0; int32_t exponent = 0; @@ -564,22 +568,22 @@ // the format mantissa * (base ^ exponent) // The loop fills the mantissa with as many digits as it can hold - const BitsType BITSTYPE_MAX_DIV_BY_BASE = + const BitsType bitstype_max_div_by_base = __llvm_libc::cpp::NumericLimits::max() / BASE; while (true) { if (isdigit(*src)) { uint32_t digit = *src - '0'; - seenDigit = true; + seen_digit = true; - if (mantissa < BITSTYPE_MAX_DIV_BY_BASE) { + if (mantissa < bitstype_max_div_by_base) { mantissa = (mantissa * BASE) + digit; - if (afterDecimal) { + if (after_decimal) { --exponent; } } else { if (digit > 0) truncated = true; - if (!afterDecimal) + if (!after_decimal) ++exponent; } @@ -587,11 +591,11 @@ continue; } if (*src == DECIMAL_POINT) { - if (afterDecimal) { + if (after_decimal) { break; // this means that *src points to a second decimal point, ending // the number. } - afterDecimal = true; + after_decimal = true; ++src; continue; } @@ -599,20 +603,20 @@ break; } - if (!seenDigit) + if (!seen_digit) return false; if ((*src | 32) == EXPONENT_MARKER) { if (*(src + 1) == '+' || *(src + 1) == '-' || isdigit(*(src + 1))) { ++src; - char *tempStrEnd; - int32_t add_to_exponent = strtointeger(src, &tempStrEnd, 10); + char *temp_str_end; + int32_t add_to_exponent = strtointeger(src, &temp_str_end, 10); if (add_to_exponent > 100000) add_to_exponent = 100000; else if (add_to_exponent < -100000) add_to_exponent = -100000; - src = tempStrEnd; + src = temp_str_end; exponent += add_to_exponent; } } @@ -622,8 +626,8 @@ *outputMantissa = 0; *outputExponent = 0; } else { - decimalExpToFloat(mantissa, exponent, numStart, truncated, - outputMantissa, outputExponent); + decimal_exp_to_float(mantissa, exponent, num_start, truncated, + outputMantissa, outputExponent); } return true; } @@ -635,18 +639,18 @@ // If the return value is false, then it is assumed that there is no number // here. template -static inline bool -hexadecimalStringToFloat(const char *__restrict src, const char DECIMAL_POINT, - char **__restrict strEnd, - typename fputil::FPBits::UIntType *outputMantissa, - uint32_t *outputExponent) { +static inline bool hexadecimal_string_to_float( + const char *__restrict src, const char DECIMAL_POINT, + char **__restrict strEnd, + typename fputil::FPBits::UIntType *outputMantissa, + uint32_t *outputExponent) { using BitsType = typename fputil::FPBits::UIntType; constexpr uint32_t BASE = 16; constexpr char EXPONENT_MARKER = 'p'; bool truncated = false; - bool seenDigit = false; - bool afterDecimal = false; + bool seen_digit = false; + bool after_decimal = false; BitsType mantissa = 0; int32_t exponent = 0; @@ -654,35 +658,35 @@ // the format mantissa * (base ^ exponent) // The loop fills the mantissa with as many digits as it can hold - const BitsType BITSTYPE_MAX_DIV_BY_BASE = + const BitsType bitstype_max_div_by_base = __llvm_libc::cpp::NumericLimits::max() / BASE; while (true) { if (isalnum(*src)) { uint32_t digit = b36_char_to_int(*src); if (digit < BASE) - seenDigit = true; + seen_digit = true; else break; - if (mantissa < BITSTYPE_MAX_DIV_BY_BASE) { + if (mantissa < bitstype_max_div_by_base) { mantissa = (mantissa * BASE) + digit; - if (afterDecimal) + if (after_decimal) --exponent; } else { if (digit > 0) truncated = true; - if (!afterDecimal) + if (!after_decimal) ++exponent; } ++src; continue; } if (*src == DECIMAL_POINT) { - if (afterDecimal) { + if (after_decimal) { break; // this means that *src points to a second decimal point, ending // the number. } - afterDecimal = true; + after_decimal = true; ++src; continue; } @@ -690,7 +694,7 @@ break; } - if (!seenDigit) + if (!seen_digit) return false; // Convert the exponent from having a base of 16 to having a base of 2. @@ -699,13 +703,13 @@ if ((*src | 32) == EXPONENT_MARKER) { if (*(src + 1) == '+' || *(src + 1) == '-' || isdigit(*(src + 1))) { ++src; - char *tempStrEnd; - int32_t add_to_exponent = strtointeger(src, &tempStrEnd, 10); + char *temp_str_end; + int32_t add_to_exponent = strtointeger(src, &temp_str_end, 10); if (add_to_exponent > 100000) add_to_exponent = 100000; else if (add_to_exponent < -100000) add_to_exponent = -100000; - src = tempStrEnd; + src = temp_str_end; exponent += add_to_exponent; } } @@ -714,8 +718,8 @@ *outputMantissa = 0; *outputExponent = 0; } else { - binaryExpToFloat(mantissa, exponent, truncated, outputMantissa, - outputExponent); + binary_exp_to_float(mantissa, exponent, truncated, outputMantissa, + outputExponent); } return true; } @@ -727,20 +731,20 @@ char **__restrict strEnd) { using BitsType = typename fputil::FPBits::UIntType; fputil::FPBits result = fputil::FPBits(); - const char *originalSrc = src; - bool seenDigit = false; + const char *original_src = src; + bool seen_digit = false; src = first_non_whitespace(src); if (*src == '+' || *src == '-') { if (*src == '-') { - result.setSign(true); + result.set_sign(true); } ++src; } static constexpr char DECIMAL_POINT = '.'; - static const char *INF_STRING = "infinity"; - static const char *NAN_STRING = "nan"; + static const char *inf_string = "infinity"; + static const char *nan_string = "nan"; // bool truncated = false; @@ -749,74 +753,74 @@ if (is_float_hex_start(src, DECIMAL_POINT)) { base = 16; src += 2; - seenDigit = true; + seen_digit = true; } - char *newStrEnd = nullptr; + char *new_str_end = nullptr; - BitsType outputMantissa = 0; - uint32_t outputExponent = 0; + BitsType output_mantissa = 0; + uint32_t output_exponent = 0; if (base == 16) { - seenDigit = hexadecimalStringToFloat(src, DECIMAL_POINT, &newStrEnd, - &outputMantissa, &outputExponent); + seen_digit = hexadecimal_string_to_float( + src, DECIMAL_POINT, &new_str_end, &output_mantissa, &output_exponent); } else { // base is 10 - seenDigit = decimalStringToFloat(src, DECIMAL_POINT, &newStrEnd, - &outputMantissa, &outputExponent); + seen_digit = decimal_string_to_float( + src, DECIMAL_POINT, &new_str_end, &output_mantissa, &output_exponent); } - if (seenDigit) { - src += newStrEnd - src; - result.setMantissa(outputMantissa); - result.setUnbiasedExponent(outputExponent); + if (seen_digit) { + src += new_str_end - src; + result.set_mantissa(output_mantissa); + result.set_unbiased_exponent(output_exponent); } } else if ((*src | 32) == 'n') { // NaN - if ((src[1] | 32) == NAN_STRING[1] && (src[2] | 32) == NAN_STRING[2]) { - seenDigit = true; + if ((src[1] | 32) == nan_string[1] && (src[2] | 32) == nan_string[2]) { + seen_digit = true; src += 3; - BitsType NaNMantissa = 0; + BitsType nan_mantissa = 0; // this handles the case of `NaN(n-character-sequence)`, where the // n-character-sequence is made of 0 or more letters and numbers in any // order. if (*src == '(') { - const char *leftParen = src; + const char *left_paren = src; ++src; while (isalnum(*src)) ++src; if (*src == ')') { ++src; - char *tempSrc = 0; - if (isdigit(*(leftParen + 1))) { + char *temp_src = 0; + if (isdigit(*(left_paren + 1))) { // This is to prevent errors when BitsType is larger than 64 bits, // since strtointeger only supports up to 64 bits. This is actually // more than is required by the specification, which says for the // input type "NAN(n-char-sequence)" that "the meaning of // the n-char sequence is implementation-defined." - NaNMantissa = static_cast( - strtointeger(leftParen + 1, &tempSrc, 0)); - if (*tempSrc != ')') - NaNMantissa = 0; + nan_mantissa = static_cast( + strtointeger(left_paren + 1, &temp_src, 0)); + if (*temp_src != ')') + nan_mantissa = 0; } } else - src = leftParen; + src = left_paren; } - NaNMantissa |= fputil::FloatProperties::quietNaNMask; - if (result.getSign()) { - result = fputil::FPBits(result.buildNaN(NaNMantissa)); - result.setSign(true); + nan_mantissa |= fputil::FloatProperties::QUIET_NAN_MASK; + if (result.get_sign()) { + result = fputil::FPBits(result.build_nan(nan_mantissa)); + result.set_sign(true); } else { - result.setSign(false); - result = fputil::FPBits(result.buildNaN(NaNMantissa)); + result.set_sign(false); + result = fputil::FPBits(result.build_nan(nan_mantissa)); } } } else if ((*src | 32) == 'i') { // INF - if ((src[1] | 32) == INF_STRING[1] && (src[2] | 32) == INF_STRING[2]) { - seenDigit = true; - if (result.getSign()) - result = result.negInf(); + if ((src[1] | 32) == inf_string[1] && (src[2] | 32) == inf_string[2]) { + seen_digit = true; + if (result.get_sign()) + result = result.neg_inf(); else result = result.inf(); - if ((src[3] | 32) == INF_STRING[3] && (src[4] | 32) == INF_STRING[4] && - (src[5] | 32) == INF_STRING[5] && (src[6] | 32) == INF_STRING[6] && - (src[7] | 32) == INF_STRING[7]) { + if ((src[3] | 32) == inf_string[3] && (src[4] | 32) == inf_string[4] && + (src[5] | 32) == inf_string[5] && (src[6] | 32) == inf_string[6] && + (src[7] | 32) == inf_string[7]) { // if the string is "INFINITY" then strEnd needs to be set to src + 8. src += 8; } else { @@ -824,9 +828,9 @@ } } } - if (!seenDigit) { // If there is nothing to actually parse, then return 0. + if (!seen_digit) { // If there is nothing to actually parse, then return 0. if (strEnd != nullptr) - *strEnd = const_cast(originalSrc); + *strEnd = const_cast(original_src); return T(0); } diff --git a/libc/src/__support/str_to_integer.h b/libc/src/__support/str_to_integer.h --- a/libc/src/__support/str_to_integer.h +++ b/libc/src/__support/str_to_integer.h @@ -92,16 +92,16 @@ src = src + 2; } - constexpr bool is_unsigned = (__llvm_libc::cpp::NumericLimits::min() == 0); + constexpr bool IS_UNSIGNED = (__llvm_libc::cpp::NumericLimits::min() == 0); const bool is_positive = (result_sign == '+'); unsigned long long constexpr NEGATIVE_MAX = - !is_unsigned ? static_cast( + !IS_UNSIGNED ? static_cast( __llvm_libc::cpp::NumericLimits::max()) + 1 : __llvm_libc::cpp::NumericLimits::max(); - unsigned long long const ABS_MAX = + unsigned long long const abs_max = (is_positive ? __llvm_libc::cpp::NumericLimits::max() : NEGATIVE_MAX); - unsigned long long const ABS_MAX_DIV_BY_BASE = ABS_MAX / base; + unsigned long long const abs_max_div_by_base = abs_max / base; while (isalnum(*src)) { int cur_digit = b36_char_to_int(*src); if (cur_digit >= base) @@ -113,19 +113,19 @@ // If the number has already hit the maximum value for the current type then // the result cannot change, but we still need to advance src to the end of // the number. - if (result == ABS_MAX) { + if (result == abs_max) { errno = ERANGE; continue; } - if (result > ABS_MAX_DIV_BY_BASE) { - result = ABS_MAX; + if (result > abs_max_div_by_base) { + result = abs_max; errno = ERANGE; } else { result = result * base; } - if (result > ABS_MAX - cur_digit) { - result = ABS_MAX; + if (result > abs_max - cur_digit) { + result = abs_max; errno = ERANGE; } else { result = result + cur_digit; @@ -135,8 +135,8 @@ if (str_end != nullptr) *str_end = const_cast(is_number ? src : original_src); - if (result == ABS_MAX) { - if (is_positive || is_unsigned) + if (result == abs_max) { + if (is_positive || IS_UNSIGNED) return __llvm_libc::cpp::NumericLimits::max(); else // T is signed and there is a negative overflow return __llvm_libc::cpp::NumericLimits::min(); diff --git a/libc/src/assert/__assert_fail.cpp b/libc/src/assert/__assert_fail.cpp --- a/libc/src/assert/__assert_fail.cpp +++ b/libc/src/assert/__assert_fail.cpp @@ -18,7 +18,7 @@ // This is just a temporary solution to make assert available to internal // llvm libc code. In the future writeToStderr will not exist and __assert_fail // will call fprintf(stderr, ...). -static void writeToStderr(const char *s) { +static void write_to_stderr(const char *s) { size_t length = 0; for (const char *curr = s; *curr; ++curr, ++length); __llvm_libc::syscall(SYS_write, 2, s, length); @@ -27,12 +27,12 @@ LLVM_LIBC_FUNCTION(void, __assert_fail, (const char *assertion, const char *file, unsigned line, const char *function)) { - writeToStderr(file); - writeToStderr(": Assertion failed: '"); - writeToStderr(assertion); - writeToStderr("' in function: '"); - writeToStderr(function); - writeToStderr("'\n"); + write_to_stderr(file); + write_to_stderr(": Assertion failed: '"); + write_to_stderr(assertion); + write_to_stderr("' in function: '"); + write_to_stderr(function); + write_to_stderr("'\n"); __llvm_libc::abort(); } diff --git a/libc/src/errno/__errno_location.cpp b/libc/src/errno/__errno_location.cpp --- a/libc/src/errno/__errno_location.cpp +++ b/libc/src/errno/__errno_location.cpp @@ -12,11 +12,11 @@ namespace __llvm_libc { -static thread_local int __errno = 0; +static thread_local int errno = 0; // __errno_location is not really an entry point but we still want it to behave // like an entry point because the errno macro resolves to the C symbol // "__errno_location". -LLVM_LIBC_FUNCTION(int *, __errno_location, ()) { return &__errno; } +LLVM_LIBC_FUNCTION(int *, __errno_location, ()) { return &errno; } } // namespace __llvm_libc diff --git a/libc/src/fenv/feclearexcept.cpp b/libc/src/fenv/feclearexcept.cpp --- a/libc/src/fenv/feclearexcept.cpp +++ b/libc/src/fenv/feclearexcept.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, feclearexcept, (int e)) { - return fputil::clearExcept(e); + return fputil::clear_except(e); } } // namespace __llvm_libc diff --git a/libc/src/fenv/fedisableexcept.cpp b/libc/src/fenv/fedisableexcept.cpp --- a/libc/src/fenv/fedisableexcept.cpp +++ b/libc/src/fenv/fedisableexcept.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fedisableexcept, (int e)) { - return fputil::disableExcept(e); + return fputil::disable_except(e); } } // namespace __llvm_libc diff --git a/libc/src/fenv/feenableexcept.cpp b/libc/src/fenv/feenableexcept.cpp --- a/libc/src/fenv/feenableexcept.cpp +++ b/libc/src/fenv/feenableexcept.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, feenableexcept, (int e)) { - return fputil::enableExcept(e); + return fputil::enable_except(e); } } // namespace __llvm_libc diff --git a/libc/src/fenv/fegetenv.cpp b/libc/src/fenv/fegetenv.cpp --- a/libc/src/fenv/fegetenv.cpp +++ b/libc/src/fenv/fegetenv.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fegetenv, (fenv_t * envp)) { - return fputil::getEnv(envp); + return fputil::get_env(envp); } } // namespace __llvm_libc diff --git a/libc/src/fenv/fegetexcept.cpp b/libc/src/fenv/fegetexcept.cpp --- a/libc/src/fenv/fegetexcept.cpp +++ b/libc/src/fenv/fegetexcept.cpp @@ -12,6 +12,6 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, fegetexcept, ()) { return fputil::getExcept(); } +LLVM_LIBC_FUNCTION(int, fegetexcept, ()) { return fputil::get_except(); } } // namespace __llvm_libc diff --git a/libc/src/fenv/fegetexceptflag.cpp b/libc/src/fenv/fegetexceptflag.cpp --- a/libc/src/fenv/fegetexceptflag.cpp +++ b/libc/src/fenv/fegetexceptflag.cpp @@ -16,7 +16,7 @@ LLVM_LIBC_FUNCTION(int, fegetexceptflag, (fexcept_t * flagp, int excepts)) { // TODO: Add a compile time check to see if the excepts actually fit in flagp. - *flagp = static_cast(fputil::testExcept(FE_ALL_EXCEPT) & excepts); + *flagp = static_cast(fputil::test_except(FE_ALL_EXCEPT) & excepts); return 0; } diff --git a/libc/src/fenv/fegetround.cpp b/libc/src/fenv/fegetround.cpp --- a/libc/src/fenv/fegetround.cpp +++ b/libc/src/fenv/fegetround.cpp @@ -12,6 +12,6 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, fegetround, ()) { return fputil::getRound(); } +LLVM_LIBC_FUNCTION(int, fegetround, ()) { return fputil::get_round(); } } // namespace __llvm_libc diff --git a/libc/src/fenv/feholdexcept.cpp b/libc/src/fenv/feholdexcept.cpp --- a/libc/src/fenv/feholdexcept.cpp +++ b/libc/src/fenv/feholdexcept.cpp @@ -15,10 +15,10 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, feholdexcept, (fenv_t * envp)) { - if (fputil::getEnv(envp) != 0) + if (fputil::get_env(envp) != 0) return -1; - fputil::clearExcept(FE_ALL_EXCEPT); - fputil::disableExcept(FE_ALL_EXCEPT); + fputil::clear_except(FE_ALL_EXCEPT); + fputil::disable_except(FE_ALL_EXCEPT); return 0; } diff --git a/libc/src/fenv/feraiseexcept.cpp b/libc/src/fenv/feraiseexcept.cpp --- a/libc/src/fenv/feraiseexcept.cpp +++ b/libc/src/fenv/feraiseexcept.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, feraiseexcept, (int e)) { - return fputil::raiseExcept(e); + return fputil::raise_except(e); } } // namespace __llvm_libc diff --git a/libc/src/fenv/fesetenv.cpp b/libc/src/fenv/fesetenv.cpp --- a/libc/src/fenv/fesetenv.cpp +++ b/libc/src/fenv/fesetenv.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fesetenv, (const fenv_t *envp)) { - return fputil::setEnv(envp); + return fputil::set_env(envp); } } // namespace __llvm_libc diff --git a/libc/src/fenv/fesetexceptflag.cpp b/libc/src/fenv/fesetexceptflag.cpp --- a/libc/src/fenv/fesetexceptflag.cpp +++ b/libc/src/fenv/fesetexceptflag.cpp @@ -21,8 +21,8 @@ static_assert(sizeof(int) >= sizeof(fexcept_t), "fexcept_t value cannot fit in an int value."); int excepts_to_set = static_cast(*flagp) & excepts; - fputil::clearExcept(FE_ALL_EXCEPT); - return fputil::setExcept(excepts_to_set); + fputil::clear_except(FE_ALL_EXCEPT); + return fputil::set_except(excepts_to_set); } } // namespace __llvm_libc diff --git a/libc/src/fenv/fesetround.cpp b/libc/src/fenv/fesetround.cpp --- a/libc/src/fenv/fesetround.cpp +++ b/libc/src/fenv/fesetround.cpp @@ -12,6 +12,6 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, fesetround, (int m)) { return fputil::setRound(m); } +LLVM_LIBC_FUNCTION(int, fesetround, (int m)) { return fputil::set_round(m); } } // namespace __llvm_libc diff --git a/libc/src/fenv/fetestexcept.cpp b/libc/src/fenv/fetestexcept.cpp --- a/libc/src/fenv/fetestexcept.cpp +++ b/libc/src/fenv/fetestexcept.cpp @@ -12,6 +12,8 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, fetestexcept, (int e)) { return fputil::testExcept(e); } +LLVM_LIBC_FUNCTION(int, fetestexcept, (int e)) { + return fputil::test_except(e); +} } // namespace __llvm_libc diff --git a/libc/src/fenv/feupdateenv.cpp b/libc/src/fenv/feupdateenv.cpp --- a/libc/src/fenv/feupdateenv.cpp +++ b/libc/src/fenv/feupdateenv.cpp @@ -15,10 +15,10 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, feupdateenv, (const fenv_t *envp)) { - int current_excepts = fputil::testExcept(FE_ALL_EXCEPT); - if (fputil::setEnv(envp) != 0) + int current_excepts = fputil::test_except(FE_ALL_EXCEPT); + if (fputil::set_env(envp) != 0) return -1; - return fputil::raiseExcept(current_excepts); + return fputil::raise_except(current_excepts); } } // namespace __llvm_libc diff --git a/libc/src/inttypes/imaxdiv.cpp b/libc/src/inttypes/imaxdiv.cpp --- a/libc/src/inttypes/imaxdiv.cpp +++ b/libc/src/inttypes/imaxdiv.cpp @@ -14,7 +14,7 @@ LLVM_LIBC_FUNCTION(imaxdiv_t, imaxdiv, (intmax_t x, intmax_t y)) { imaxdiv_t res; - integerRemQuo(x, y, res.quot, res.rem); + integer_rem_quo(x, y, res.quot, res.rem); return res; } 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,7 +25,7 @@ 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)) { double x2 = x * x; @@ -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/dp_trig.cpp b/libc/src/math/generic/dp_trig.cpp --- a/libc/src/math/generic/dp_trig.cpp +++ b/libc/src/math/generic/dp_trig.cpp @@ -30,7 +30,7 @@ const uint64_t inv_y_bits[20], int y_exponent, int inv_y_exponent) { FPBits bits(x); - int exponent = bits.getExponent(); + int exponent = bits.get_exponent(); int bit_drop = (exponent - 52) + inv_y_exponent + 1; bit_drop = bit_drop >= 0 ? bit_drop : 0; int word_drop = bit_drop / 64; diff --git a/libc/src/math/generic/expm1f.cpp b/libc/src/math/generic/expm1f.cpp --- a/libc/src/math/generic/expm1f.cpp +++ b/libc/src/math/generic/expm1f.cpp @@ -23,12 +23,12 @@ // // See libc/utils/mathtools/expm1f.sollya for more detail. LLVM_LIBC_FUNCTION(float, expm1f, (float x)) { - const float Ln2 = + const float ln2 = 0.69314718055994530941723212145817656807550013436025f; // For C++17: // 0x1.62e'42ffp-1 float abs_x = __llvm_libc::fputil::abs(x); - if (abs_x <= Ln2) { + if (abs_x <= ln2) { if (abs_x <= 0.125f) { return x * __llvm_libc::fputil::polyeval( x, 1.0f, 0.5f, 0.16666664183139801025390625f, diff --git a/libc/src/math/generic/llrint.cpp b/libc/src/math/generic/llrint.cpp --- a/libc/src/math/generic/llrint.cpp +++ b/libc/src/math/generic/llrint.cpp @@ -13,8 +13,9 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, llrint, (double x)) { - return fputil::roundToSignedIntegerUsingCurrentRoundingMode(x); + return fputil::round_to_signed_integer_using_current_rounding_mode( + x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/llrintf.cpp b/libc/src/math/generic/llrintf.cpp --- a/libc/src/math/generic/llrintf.cpp +++ b/libc/src/math/generic/llrintf.cpp @@ -13,7 +13,8 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, llrintf, (float x)) { - return fputil::roundToSignedIntegerUsingCurrentRoundingMode( + return fputil::round_to_signed_integer_using_current_rounding_mode( x); } diff --git a/libc/src/math/generic/llrintl.cpp b/libc/src/math/generic/llrintl.cpp --- a/libc/src/math/generic/llrintl.cpp +++ b/libc/src/math/generic/llrintl.cpp @@ -13,8 +13,8 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, llrintl, (long double x)) { - return fputil::roundToSignedIntegerUsingCurrentRoundingMode(x); + return fputil::round_to_signed_integer_using_current_rounding_mode< + long double, long long>(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/llround.cpp b/libc/src/math/generic/llround.cpp --- a/libc/src/math/generic/llround.cpp +++ b/libc/src/math/generic/llround.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, llround, (double x)) { - return fputil::roundToSignedInteger(x); + return fputil::round_to_signed_integer(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/llroundf.cpp b/libc/src/math/generic/llroundf.cpp --- a/libc/src/math/generic/llroundf.cpp +++ b/libc/src/math/generic/llroundf.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, llroundf, (float x)) { - return fputil::roundToSignedInteger(x); + return fputil::round_to_signed_integer(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/llroundl.cpp b/libc/src/math/generic/llroundl.cpp --- a/libc/src/math/generic/llroundl.cpp +++ b/libc/src/math/generic/llroundl.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, llroundl, (long double x)) { - return fputil::roundToSignedInteger(x); + return fputil::round_to_signed_integer(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/lrint.cpp b/libc/src/math/generic/lrint.cpp --- a/libc/src/math/generic/lrint.cpp +++ b/libc/src/math/generic/lrint.cpp @@ -13,7 +13,8 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long, lrint, (double x)) { - return fputil::roundToSignedIntegerUsingCurrentRoundingMode(x); + return fputil::round_to_signed_integer_using_current_rounding_mode(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/lrintf.cpp b/libc/src/math/generic/lrintf.cpp --- a/libc/src/math/generic/lrintf.cpp +++ b/libc/src/math/generic/lrintf.cpp @@ -13,7 +13,8 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long, lrintf, (float x)) { - return fputil::roundToSignedIntegerUsingCurrentRoundingMode(x); + return fputil::round_to_signed_integer_using_current_rounding_mode(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/lrintl.cpp b/libc/src/math/generic/lrintl.cpp --- a/libc/src/math/generic/lrintl.cpp +++ b/libc/src/math/generic/lrintl.cpp @@ -13,8 +13,8 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long, lrintl, (long double x)) { - return fputil::roundToSignedIntegerUsingCurrentRoundingMode(x); + return fputil::round_to_signed_integer_using_current_rounding_mode< + long double, long>(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/lround.cpp b/libc/src/math/generic/lround.cpp --- a/libc/src/math/generic/lround.cpp +++ b/libc/src/math/generic/lround.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long, lround, (double x)) { - return fputil::roundToSignedInteger(x); + return fputil::round_to_signed_integer(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/lroundf.cpp b/libc/src/math/generic/lroundf.cpp --- a/libc/src/math/generic/lroundf.cpp +++ b/libc/src/math/generic/lroundf.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long, lroundf, (float x)) { - return fputil::roundToSignedInteger(x); + return fputil::round_to_signed_integer(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/lroundl.cpp b/libc/src/math/generic/lroundl.cpp --- a/libc/src/math/generic/lroundl.cpp +++ b/libc/src/math/generic/lroundl.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long, lroundl, (long double x)) { - return fputil::roundToSignedInteger(x); + return fputil::round_to_signed_integer(x); } } // namespace __llvm_libc 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 @@ -69,12 +69,12 @@ } template struct IsFloatOrDouble { - static constexpr bool Value = - cpp::IsSame::Value || cpp::IsSame::Value; + static constexpr bool VALUE = + cpp::IsSame::VALUE || cpp::IsSame::VALUE; }; template -using EnableIfFloatOrDouble = cpp::EnableIfType::Value, int>; +using EnableIfFloatOrDouble = cpp::EnableIfType::VALUE, int>; template = 0> T xflow(uint32_t sign, T y) { diff --git a/libc/src/math/generic/nearbyint.cpp b/libc/src/math/generic/nearbyint.cpp --- a/libc/src/math/generic/nearbyint.cpp +++ b/libc/src/math/generic/nearbyint.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(double, nearbyint, (double x)) { - return fputil::roundUsingCurrentRoundingMode(x); + return fputil::round_using_current_rounding_mode(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/nearbyintf.cpp b/libc/src/math/generic/nearbyintf.cpp --- a/libc/src/math/generic/nearbyintf.cpp +++ b/libc/src/math/generic/nearbyintf.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(float, nearbyintf, (float x)) { - return fputil::roundUsingCurrentRoundingMode(x); + return fputil::round_using_current_rounding_mode(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/nearbyintl.cpp b/libc/src/math/generic/nearbyintl.cpp --- a/libc/src/math/generic/nearbyintl.cpp +++ b/libc/src/math/generic/nearbyintl.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long double, nearbyintl, (long double x)) { - return fputil::roundUsingCurrentRoundingMode(x); + return fputil::round_using_current_rounding_mode(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/rint.cpp b/libc/src/math/generic/rint.cpp --- a/libc/src/math/generic/rint.cpp +++ b/libc/src/math/generic/rint.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(double, rint, (double x)) { - return fputil::roundUsingCurrentRoundingMode(x); + return fputil::round_using_current_rounding_mode(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/rintf.cpp b/libc/src/math/generic/rintf.cpp --- a/libc/src/math/generic/rintf.cpp +++ b/libc/src/math/generic/rintf.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(float, rintf, (float x)) { - return fputil::roundUsingCurrentRoundingMode(x); + return fputil::round_using_current_rounding_mode(x); } } // namespace __llvm_libc diff --git a/libc/src/math/generic/rintl.cpp b/libc/src/math/generic/rintl.cpp --- a/libc/src/math/generic/rintl.cpp +++ b/libc/src/math/generic/rintl.cpp @@ -13,7 +13,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(long double, rintl, (long double x)) { - return fputil::roundUsingCurrentRoundingMode(x); + return fputil::round_using_current_rounding_mode(x); } } // 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,7 +25,7 @@ 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)) { double x2 = x * x; @@ -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. -const sincos_t __sincosf_table[2] = { +const sincos_t sincosf_table[2] = { {{1.0, -1.0, -1.0, 1.0}, as_double(0x41645f306dc9c883), as_double(0x3ff921fb54442d18), @@ -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. -const uint32_t __inv_pio4[24] = { +const 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 @@ -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; 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,7 +25,7 @@ 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)) { s = x * x; @@ -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); } diff --git a/libc/src/signal/linux/sigaction.cpp b/libc/src/signal/linux/sigaction.cpp --- a/libc/src/signal/linux/sigaction.cpp +++ b/libc/src/signal/linux/sigaction.cpp @@ -21,7 +21,7 @@ extern "C" void __restore_rt(); template -static void copySigaction(T &dest, const V &source) { +static void copy_sigaction(T &dest, const V &source) { dest.sa_handler = source.sa_handler; dest.sa_mask = source.sa_mask; dest.sa_flags = source.sa_flags; @@ -33,7 +33,7 @@ struct __sigaction *__restrict libc_old)) { struct sigaction kernel_new; if (libc_new) { - copySigaction(kernel_new, *libc_new); + copy_sigaction(kernel_new, *libc_new); if (!(kernel_new.sa_flags & SA_RESTORER)) { kernel_new.sa_flags |= SA_RESTORER; kernel_new.sa_restorer = __restore_rt; @@ -49,7 +49,7 @@ } if (libc_old) - copySigaction(*libc_old, kernel_old); + copy_sigaction(*libc_old, kernel_old); return 0; } diff --git a/libc/src/signal/linux/sigemptyset.cpp b/libc/src/signal/linux/sigemptyset.cpp --- a/libc/src/signal/linux/sigemptyset.cpp +++ b/libc/src/signal/linux/sigemptyset.cpp @@ -20,7 +20,7 @@ llvmlibc_errno = EINVAL; return -1; } - *set = __llvm_libc::Sigset::emptySet(); + *set = __llvm_libc::Sigset::empty_set(); return 0; } diff --git a/libc/src/signal/linux/signal.h b/libc/src/signal/linux/signal.h --- a/libc/src/signal/linux/signal.h +++ b/libc/src/signal/linux/signal.h @@ -24,7 +24,7 @@ sigset_t nativeSigset; constexpr static Sigset fullset() { return {-1UL}; } - constexpr static Sigset emptySet() { return {0}; } + constexpr static Sigset empty_set() { return {0}; } constexpr void addset(int signal) { nativeSigset |= (1L << (signal - 1)); } @@ -33,20 +33,20 @@ operator sigset_t() const { return nativeSigset; } }; -constexpr static Sigset all = Sigset::fullset(); +constexpr static Sigset ALL = Sigset::fullset(); static inline int block_all_signals(Sigset &set) { - sigset_t nativeSigset = all; - sigset_t oldSet = set; - int ret = __llvm_libc::syscall(SYS_rt_sigprocmask, SIG_BLOCK, &nativeSigset, - &oldSet, sizeof(sigset_t)); - set = {oldSet}; + sigset_t native_sigset = ALL; + sigset_t old_set = set; + int ret = __llvm_libc::syscall(SYS_rt_sigprocmask, SIG_BLOCK, &native_sigset, + &old_set, sizeof(sigset_t)); + set = {old_set}; return ret; } static inline int restore_signals(const Sigset &set) { - sigset_t nativeSigset = set; - return __llvm_libc::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &nativeSigset, + sigset_t native_sigset = set; + return __llvm_libc::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &native_sigset, nullptr, sizeof(sigset_t)); } diff --git a/libc/src/stdlib/abs.cpp b/libc/src/stdlib/abs.cpp --- a/libc/src/stdlib/abs.cpp +++ b/libc/src/stdlib/abs.cpp @@ -12,6 +12,6 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(int, abs, (int n)) { return integerAbs(n); } +LLVM_LIBC_FUNCTION(int, abs, (int n)) { return integer_abs(n); } } // namespace __llvm_libc diff --git a/libc/src/stdlib/div.cpp b/libc/src/stdlib/div.cpp --- a/libc/src/stdlib/div.cpp +++ b/libc/src/stdlib/div.cpp @@ -14,7 +14,7 @@ LLVM_LIBC_FUNCTION(div_t, div, (int x, int y)) { div_t res; - integerRemQuo(x, y, res.quot, res.rem); + integer_rem_quo(x, y, res.quot, res.rem); return res; } diff --git a/libc/src/stdlib/labs.cpp b/libc/src/stdlib/labs.cpp --- a/libc/src/stdlib/labs.cpp +++ b/libc/src/stdlib/labs.cpp @@ -12,6 +12,6 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(long, labs, (long n)) { return integerAbs(n); } +LLVM_LIBC_FUNCTION(long, labs, (long n)) { return integer_abs(n); } } // namespace __llvm_libc diff --git a/libc/src/stdlib/ldiv.cpp b/libc/src/stdlib/ldiv.cpp --- a/libc/src/stdlib/ldiv.cpp +++ b/libc/src/stdlib/ldiv.cpp @@ -14,7 +14,7 @@ LLVM_LIBC_FUNCTION(ldiv_t, ldiv, (long x, long y)) { ldiv_t res; - integerRemQuo(x, y, res.quot, res.rem); + integer_rem_quo(x, y, res.quot, res.rem); return res; } diff --git a/libc/src/stdlib/llabs.cpp b/libc/src/stdlib/llabs.cpp --- a/libc/src/stdlib/llabs.cpp +++ b/libc/src/stdlib/llabs.cpp @@ -12,6 +12,6 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(long long, llabs, (long long n)) { return integerAbs(n); } +LLVM_LIBC_FUNCTION(long long, llabs, (long long n)) { return integer_abs(n); } } // namespace __llvm_libc diff --git a/libc/src/stdlib/lldiv.cpp b/libc/src/stdlib/lldiv.cpp --- a/libc/src/stdlib/lldiv.cpp +++ b/libc/src/stdlib/lldiv.cpp @@ -14,7 +14,7 @@ LLVM_LIBC_FUNCTION(lldiv_t, lldiv, (long long x, long long y)) { lldiv_t res; - integerRemQuo(x, y, res.quot, res.rem); + integer_rem_quo(x, y, res.quot, res.rem); return res; } diff --git a/libc/src/string/memccpy.cpp b/libc/src/string/memccpy.cpp --- a/libc/src/string/memccpy.cpp +++ b/libc/src/string/memccpy.cpp @@ -17,17 +17,17 @@ (void *__restrict dest, const void *__restrict src, int c, size_t count)) { unsigned char end = static_cast(c); - const unsigned char *ucSrc = static_cast(src); - unsigned char *ucDest = static_cast(dest); + const unsigned char *uc_src = static_cast(src); + unsigned char *uc_dest = static_cast(dest); size_t i = 0; // Copy up until end is found. - for (; i < count && ucSrc[i] != end; ++i) - ucDest[i] = ucSrc[i]; + for (; i < count && uc_src[i] != end; ++i) + uc_dest[i] = uc_src[i]; // if i < count, then end must have been found, so copy end into dest and // return the byte after. if (i < count) { - ucDest[i] = ucSrc[i]; - return ucDest + i + 1; + uc_dest[i] = uc_src[i]; + return uc_dest + i + 1; } return nullptr; } diff --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp --- a/libc/src/string/memmove.cpp +++ b/libc/src/string/memmove.cpp @@ -40,7 +40,7 @@ // dest_c:[_____yz_] [___yz___] [__yz____] // Call `memcpy` if `src_c` and `dest_c` do not overlap. - if (__llvm_libc::integerAbs(src_c - dest_c) >= + if (__llvm_libc::integer_abs(src_c - dest_c) >= static_cast(count)) { inline_memcpy(dest_c, src_c, count); return dest_c; diff --git a/libc/src/string/memory_utils/bcmp_implementations.h b/libc/src/string/memory_utils/bcmp_implementations.h --- a/libc/src/string/memory_utils/bcmp_implementations.h +++ b/libc/src/string/memory_utils/bcmp_implementations.h @@ -19,12 +19,12 @@ // Fixed-size difference between 'lhs' and 'rhs'. template bool Differs(const char *lhs, const char *rhs) { - return !Element::Equals(lhs, rhs); + return !Element::equals(lhs, rhs); } // Runtime-size difference between 'lhs' and 'rhs'. template bool Differs(const char *lhs, const char *rhs, size_t size) { - return !Element::Equals(lhs, rhs, size); + return !Element::equals(lhs, rhs, size); } static inline int inline_bcmp(const char *lhs, const char *rhs, size_t count) { diff --git a/libc/src/string/memory_utils/elements.h b/libc/src/string/memory_utils/elements.h --- a/libc/src/string/memory_utils/elements.h +++ b/libc/src/string/memory_utils/elements.h @@ -26,58 +26,58 @@ // Fixed-size copy from 'src' to 'dst'. template -void Copy(char *__restrict dst, const char *__restrict src) { - Element::Copy(dst, src); +void copy(char *__restrict dst, const char *__restrict src) { + Element::copy(dst, src); } // Runtime-size copy from 'src' to 'dst'. template -void Copy(char *__restrict dst, const char *__restrict src, size_t size) { - Element::Copy(dst, src, size); +void copy(char *__restrict dst, const char *__restrict src, size_t size) { + Element::copy(dst, src, size); } // Fixed-size move from 'src' to 'dst'. -template void Move(char *dst, const char *src) { - Element::Move(dst, src); +template void move(char *dst, const char *src) { + Element::move(dst, src); } // Runtime-size move from 'src' to 'dst'. -template void Move(char *dst, const char *src, size_t size) { - Element::Move(dst, src, size); +template void move(char *dst, const char *src, size_t size) { + Element::move(dst, src, size); } // Fixed-size equality between 'lhs' and 'rhs'. -template bool Equals(const char *lhs, const char *rhs) { - return Element::Equals(lhs, rhs); +template bool equals(const char *lhs, const char *rhs) { + return Element::equals(lhs, rhs); } // Runtime-size equality between 'lhs' and 'rhs'. template -bool Equals(const char *lhs, const char *rhs, size_t size) { - return Element::Equals(lhs, rhs, size); +bool equals(const char *lhs, const char *rhs, size_t size) { + return Element::equals(lhs, rhs, size); } // Fixed-size three-way comparison between 'lhs' and 'rhs'. template -int ThreeWayCompare(const char *lhs, const char *rhs) { - return Element::ThreeWayCompare(lhs, rhs); +int three_way_compare(const char *lhs, const char *rhs) { + return Element::three_way_compare(lhs, rhs); } // Runtime-size three-way comparison between 'lhs' and 'rhs'. template -int ThreeWayCompare(const char *lhs, const char *rhs, size_t size) { - return Element::ThreeWayCompare(lhs, rhs, size); +int three_way_compare(const char *lhs, const char *rhs, size_t size) { + return Element::three_way_compare(lhs, rhs, size); } // Fixed-size initialization. template -void SplatSet(char *dst, const unsigned char value) { - Element::SplatSet(dst, value); +void splat_set(char *dst, const unsigned char value) { + Element::splat_set(dst, value); } // Runtime-size initialization. template -void SplatSet(char *dst, const unsigned char value, size_t size) { - Element::SplatSet(dst, value, size); +void splat_set(char *dst, const unsigned char value, size_t size) { + Element::splat_set(dst, value, size); } // Stack placeholder for Move operations. -template struct Storage { char bytes[Element::kSize]; }; +template struct Storage { char bytes[Element::K_SIZE]; }; // Fixed-size Higher-Order Operations // ---------------------------------- @@ -86,62 +86,62 @@ // Repeat the operation several times in a row. template struct Repeated { - static constexpr size_t kSize = ElementCount * Element::kSize; + static constexpr size_t K_SIZE = ElementCount * Element::K_SIZE; - static void Copy(char *__restrict dst, const char *__restrict src) { + static void copy(char *__restrict dst, const char *__restrict src) { for (size_t i = 0; i < ElementCount; ++i) { - const size_t offset = i * Element::kSize; - Element::Copy(dst + offset, src + offset); + const size_t offset = i * Element::K_SIZE; + Element::copy(dst + offset, src + offset); } } - static void Move(char *dst, const char *src) { - const auto Value = Element::Load(src); - Repeated::Move(dst + Element::kSize, - src + Element::kSize); - Element::Store(dst, Value); + static void move(char *dst, const char *src) { + const auto value = Element::load(src); + Repeated::move(dst + Element::K_SIZE, + src + Element::K_SIZE); + Element::store(dst, value); } - static bool Equals(const char *lhs, const char *rhs) { + static bool equals(const char *lhs, const char *rhs) { for (size_t i = 0; i < ElementCount; ++i) { - const size_t offset = i * Element::kSize; - if (!Element::Equals(lhs + offset, rhs + offset)) + const size_t offset = i * Element::K_SIZE; + if (!Element::equals(lhs + offset, rhs + offset)) return false; } return true; } - static int ThreeWayCompare(const char *lhs, const char *rhs) { + static int three_way_compare(const char *lhs, const char *rhs) { for (size_t i = 0; i < ElementCount; ++i) { - const size_t offset = i * Element::kSize; + const size_t offset = i * Element::K_SIZE; // We make the assumption that 'Equals' si cheaper than 'ThreeWayCompare'. - if (Element::Equals(lhs + offset, rhs + offset)) + if (Element::equals(lhs + offset, rhs + offset)) continue; - return Element::ThreeWayCompare(lhs + offset, rhs + offset); + return Element::three_way_compare(lhs + offset, rhs + offset); } return 0; } - static void SplatSet(char *dst, const unsigned char value) { + static void splat_set(char *dst, const unsigned char value) { for (size_t i = 0; i < ElementCount; ++i) { - const size_t offset = i * Element::kSize; - Element::SplatSet(dst + offset, value); + const size_t offset = i * Element::K_SIZE; + Element::splat_set(dst + offset, value); } } - static Storage Load(const char *ptr) { + static Storage load(const char *ptr) { Storage value; - Copy(reinterpret_cast(&value), ptr); + copy(reinterpret_cast(&value), ptr); return value; } - static void Store(char *ptr, Storage value) { - Copy(ptr, reinterpret_cast(&value)); + static void store(char *ptr, Storage value) { + copy(ptr, reinterpret_cast(&value)); } }; template struct Repeated { - static void Move(char *dst, const char *src) {} + static void move(char *dst, const char *src) {} }; // Chain the operation of several types. @@ -150,128 +150,128 @@ template struct Chained; template struct Chained { - static constexpr size_t kSize = Head::kSize + Chained::kSize; + static constexpr size_t K_SIZE = Head::K_SIZE + Chained::K_SIZE; - static void Copy(char *__restrict dst, const char *__restrict src) { - Chained::Copy(dst + Head::kSize, src + Head::kSize); - __llvm_libc::Copy(dst, src); + static void copy(char *__restrict dst, const char *__restrict src) { + Chained::copy(dst + Head::K_SIZE, src + Head::K_SIZE); + __llvm_libc::copy(dst, src); } - static void Move(char *dst, const char *src) { - const auto Value = Head::Load(src); - Chained::Move(dst + Head::kSize, src + Head::kSize); - Head::Store(dst, Value); + static void move(char *dst, const char *src) { + const auto value = Head::load(src); + Chained::move(dst + Head::K_SIZE, src + Head::K_SIZE); + Head::store(dst, value); } - static bool Equals(const char *lhs, const char *rhs) { - if (!__llvm_libc::Equals(lhs, rhs)) + static bool equals(const char *lhs, const char *rhs) { + if (!__llvm_libc::equals(lhs, rhs)) return false; - return Chained::Equals(lhs + Head::kSize, rhs + Head::kSize); + return Chained::equals(lhs + Head::K_SIZE, rhs + Head::K_SIZE); } - static int ThreeWayCompare(const char *lhs, const char *rhs) { - if (__llvm_libc::Equals(lhs, rhs)) - return Chained::ThreeWayCompare(lhs + Head::kSize, - rhs + Head::kSize); - return __llvm_libc::ThreeWayCompare(lhs, rhs); + static int three_way_compare(const char *lhs, const char *rhs) { + if (__llvm_libc::equals(lhs, rhs)) + return Chained::three_way_compare(lhs + Head::K_SIZE, + rhs + Head::K_SIZE); + return __llvm_libc::three_way_compare(lhs, rhs); } - static void SplatSet(char *dst, const unsigned char value) { - Chained::SplatSet(dst + Head::kSize, value); - __llvm_libc::SplatSet(dst, value); + static void splat_set(char *dst, const unsigned char value) { + Chained::splat_set(dst + Head::K_SIZE, value); + __llvm_libc::splat_set(dst, value); } }; template <> struct Chained<> { - static constexpr size_t kSize = 0; - static void Copy(char *__restrict dst, const char *__restrict src) {} - static void Move(char *dst, const char *src) {} - static bool Equals(const char *lhs, const char *rhs) { return true; } - static int ThreeWayCompare(const char *lhs, const char *rhs) { return 0; } - static void SplatSet(char *dst, const unsigned char value) {} + static constexpr size_t K_SIZE = 0; + static void copy(char *__restrict dst, const char *__restrict src) {} + static void move(char *dst, const char *src) {} + static bool equals(const char *lhs, const char *rhs) { return true; } + static int three_way_compare(const char *lhs, const char *rhs) { return 0; } + static void splat_set(char *dst, const unsigned char value) {} }; // Overlap ElementA and ElementB so they span Size bytes. template struct Overlap { - static constexpr size_t kSize = Size; - static_assert(ElementB::kSize <= ElementA::kSize, "ElementB too big"); - static_assert(ElementA::kSize <= Size, "ElementA too big"); - static_assert((ElementA::kSize + ElementB::kSize) >= Size, + static constexpr size_t K_SIZE = Size; + static_assert(ElementB::K_SIZE <= ElementA::K_SIZE, "ElementB too big"); + static_assert(ElementA::K_SIZE <= Size, "ElementA too big"); + static_assert((ElementA::K_SIZE + ElementB::K_SIZE) >= Size, "Elements too small to overlap"); - static constexpr size_t kOffset = kSize - ElementB::kSize; + static constexpr size_t K_OFFSET = K_SIZE - ElementB::K_SIZE; - static void Copy(char *__restrict dst, const char *__restrict src) { - ElementA::Copy(dst, src); - ElementB::Copy(dst + kOffset, src + kOffset); + static void copy(char *__restrict dst, const char *__restrict src) { + ElementA::copy(dst, src); + ElementB::copy(dst + K_OFFSET, src + K_OFFSET); } - static void Move(char *dst, const char *src) { - const auto ValueA = ElementA::Load(src); - const auto ValueB = ElementB::Load(src + kOffset); - ElementB::Store(dst + kOffset, ValueB); - ElementA::Store(dst, ValueA); + static void move(char *dst, const char *src) { + const auto value_a = ElementA::load(src); + const auto value_b = ElementB::load(src + K_OFFSET); + ElementB::store(dst + K_OFFSET, value_b); + ElementA::store(dst, value_a); } - static bool Equals(const char *lhs, const char *rhs) { - if (!ElementA::Equals(lhs, rhs)) + static bool equals(const char *lhs, const char *rhs) { + if (!ElementA::equals(lhs, rhs)) return false; - if (!ElementB::Equals(lhs + kOffset, rhs + kOffset)) + if (!ElementB::equals(lhs + K_OFFSET, rhs + K_OFFSET)) return false; return true; } - static int ThreeWayCompare(const char *lhs, const char *rhs) { - if (!ElementA::Equals(lhs, rhs)) - return ElementA::ThreeWayCompare(lhs, rhs); - if (!ElementB::Equals(lhs + kOffset, rhs + kOffset)) - return ElementB::ThreeWayCompare(lhs + kOffset, rhs + kOffset); + static int three_way_compare(const char *lhs, const char *rhs) { + if (!ElementA::equals(lhs, rhs)) + return ElementA::three_way_compare(lhs, rhs); + if (!ElementB::equals(lhs + K_OFFSET, rhs + K_OFFSET)) + return ElementB::three_way_compare(lhs + K_OFFSET, rhs + K_OFFSET); return 0; } - static void SplatSet(char *dst, const unsigned char value) { - ElementA::SplatSet(dst, value); - ElementB::SplatSet(dst + kOffset, value); + static void splat_set(char *dst, const unsigned char value) { + ElementA::splat_set(dst, value); + ElementB::splat_set(dst + K_OFFSET, value); } }; // Runtime-size Higher-Order Operations // ------------------------------------ -// - Tail: Perform the operation on the last 'T::kSize' bytes of the buffer. -// - HeadTail: Perform the operation on the first and last 'T::kSize' bytes +// - Tail: Perform the operation on the last 'T::K_SIZE' bytes of the buffer. +// - HeadTail: Perform the operation on the first and last 'T::K_SIZE' bytes // of the buffer. // - Loop: Perform a loop of fixed-sized operations. -// Perform the operation on the last 'T::kSize' bytes of the buffer. +// Perform the operation on the last 'T::K_SIZE' bytes of the buffer. // // e.g. with // [1234567812345678123] // [__XXXXXXXXXXXXXX___] // [________XXXXXXXX___] // -// Precondition: `size >= T::kSize`. +// Precondition: `size >= T::K_SIZE`. template struct Tail { - static void Copy(char *__restrict dst, const char *__restrict src, + static void copy(char *__restrict dst, const char *__restrict src, size_t size) { - return T::Copy(dst + offset(size), src + offset(size)); + return T::copy(dst + offset(size), src + offset(size)); } - static bool Equals(const char *lhs, const char *rhs, size_t size) { - return T::Equals(lhs + offset(size), rhs + offset(size)); + static bool equals(const char *lhs, const char *rhs, size_t size) { + return T::equals(lhs + offset(size), rhs + offset(size)); } - static int ThreeWayCompare(const char *lhs, const char *rhs, size_t size) { - return T::ThreeWayCompare(lhs + offset(size), rhs + offset(size)); + static int three_way_compare(const char *lhs, const char *rhs, size_t size) { + return T::three_way_compare(lhs + offset(size), rhs + offset(size)); } - static void SplatSet(char *dst, const unsigned char value, size_t size) { - return T::SplatSet(dst + offset(size), value); + static void splat_set(char *dst, const unsigned char value, size_t size) { + return T::splat_set(dst + offset(size), value); } - static size_t offset(size_t size) { return size - T::kSize; } + static size_t offset(size_t size) { return size - T::K_SIZE; } }; -// Perform the operation on the first and last 'T::kSize' bytes of the buffer. +// Perform the operation on the first and last 'T::K_SIZE' bytes of the buffer. // This is useful for overlapping operations. // // e.g. with @@ -280,37 +280,37 @@ // [__XXXXXXXX_________] // [________XXXXXXXX___] // -// Precondition: `size >= T::kSize && size <= 2 x T::kSize`. +// Precondition: `size >= T::K_SIZE && size <= 2 x T::K_SIZE`. template struct HeadTail { - static void Copy(char *__restrict dst, const char *__restrict src, + static void copy(char *__restrict dst, const char *__restrict src, size_t size) { - T::Copy(dst, src); - Tail::Copy(dst, src, size); + T::copy(dst, src); + Tail::copy(dst, src, size); } - static void Move(char *dst, const char *src, size_t size) { + static void move(char *dst, const char *src, size_t size) { const size_t offset = Tail::offset(size); - const auto HeadValue = T::Load(src); - const auto TailValue = T::Load(src + offset); - T::Store(dst + offset, TailValue); - T::Store(dst, HeadValue); + const auto head_value = T::load(src); + const auto tail_value = T::load(src + offset); + T::store(dst + offset, tail_value); + T::store(dst, head_value); } - static bool Equals(const char *lhs, const char *rhs, size_t size) { - if (!T::Equals(lhs, rhs)) + static bool equals(const char *lhs, const char *rhs, size_t size) { + if (!T::equals(lhs, rhs)) return false; - return Tail::Equals(lhs, rhs, size); + return Tail::equals(lhs, rhs, size); } - static int ThreeWayCompare(const char *lhs, const char *rhs, size_t size) { - if (!T::Equals(lhs, rhs)) - return T::ThreeWayCompare(lhs, rhs); - return Tail::ThreeWayCompare(lhs, rhs, size); + static int three_way_compare(const char *lhs, const char *rhs, size_t size) { + if (!T::equals(lhs, rhs)) + return T::three_way_compare(lhs, rhs); + return Tail::three_way_compare(lhs, rhs, size); } - static void SplatSet(char *dst, const unsigned char value, size_t size) { - T::SplatSet(dst, value); - Tail::SplatSet(dst, value, size); + static void splat_set(char *dst, const unsigned char value, size_t size) { + T::splat_set(dst, value); + Tail::splat_set(dst, value, size); } }; @@ -325,48 +325,48 @@ // [______________________XXXXXXXX___] // // Precondition: -// - size >= T::kSize +// - size >= T::K_SIZE template struct Loop { - static_assert(T::kSize == TailT::kSize, + static_assert(T::K_SIZE == TailT::K_SIZE, "Tail type must have the same size as T"); - static void Copy(char *__restrict dst, const char *__restrict src, + static void copy(char *__restrict dst, const char *__restrict src, size_t size) { size_t offset = 0; do { - T::Copy(dst + offset, src + offset); - offset += T::kSize; - } while (offset < size - T::kSize); - Tail::Copy(dst, src, size); + T::copy(dst + offset, src + offset); + offset += T::K_SIZE; + } while (offset < size - T::K_SIZE); + Tail::copy(dst, src, size); } - static bool Equals(const char *lhs, const char *rhs, size_t size) { + static bool equals(const char *lhs, const char *rhs, size_t size) { size_t offset = 0; do { - if (!T::Equals(lhs + offset, rhs + offset)) + if (!T::equals(lhs + offset, rhs + offset)) return false; - offset += T::kSize; - } while (offset < size - T::kSize); - return Tail::Equals(lhs, rhs, size); + offset += T::K_SIZE; + } while (offset < size - T::K_SIZE); + return Tail::equals(lhs, rhs, size); } - static int ThreeWayCompare(const char *lhs, const char *rhs, size_t size) { + static int three_way_compare(const char *lhs, const char *rhs, size_t size) { size_t offset = 0; do { - if (!T::Equals(lhs + offset, rhs + offset)) - return T::ThreeWayCompare(lhs + offset, rhs + offset); - offset += T::kSize; - } while (offset < size - T::kSize); - return Tail::ThreeWayCompare(lhs, rhs, size); + if (!T::equals(lhs + offset, rhs + offset)) + return T::three_way_compare(lhs + offset, rhs + offset); + offset += T::K_SIZE; + } while (offset < size - T::K_SIZE); + return Tail::three_way_compare(lhs, rhs, size); } - static void SplatSet(char *dst, const unsigned char value, size_t size) { + static void splat_set(char *dst, const unsigned char value, size_t size) { size_t offset = 0; do { - T::SplatSet(dst + offset, value); - offset += T::kSize; - } while (offset < size - T::kSize); - Tail::SplatSet(dst, value, size); + T::splat_set(dst + offset, value); + offset += T::K_SIZE; + } while (offset < size - T::K_SIZE); + Tail::splat_set(dst, value, size); } }; @@ -374,14 +374,14 @@ namespace internal { -// Provides a specialized Bump function that adjusts pointers and size so first +// Provides a specialized bump function that adjusts pointers and size so first // argument (resp. second argument) gets aligned to Alignment. // We make sure the compiler knows about the adjusted pointer alignment. template struct AlignHelper {}; template struct AlignHelper { template - static void Bump(T1 *__restrict &p1ref, T2 *__restrict &p2ref, size_t &size) { + static void bump(T1 *__restrict &p1ref, T2 *__restrict &p2ref, size_t &size) { const intptr_t offset = offset_to_next_aligned(p1ref); p1ref += offset; p2ref += offset; @@ -392,7 +392,7 @@ template struct AlignHelper { template - static void Bump(T1 *__restrict &p1ref, T2 *__restrict &p2ref, size_t &size) { + static void bump(T1 *__restrict &p1ref, T2 *__restrict &p2ref, size_t &size) { const intptr_t offset = offset_to_next_aligned(p2ref); p1ref += offset; p2ref += offset; @@ -413,38 +413,39 @@ // Copy::Then>>(dst, src, count); template struct Align { private: - static constexpr size_t Alignment = AlignmentT::kSize; - static_assert(Alignment > 1, "Alignment must be more than 1"); - static_assert(is_power2(Alignment), "Alignment must be a power of 2"); + static constexpr size_t ALIGNMENT = AlignmentT::K_SIZE; + static_assert(ALIGNMENT > 1, "Alignment must be more than 1"); + static_assert(is_power2(ALIGNMENT), "Alignment must be a power of 2"); public: template struct Then { - static void Copy(char *__restrict dst, const char *__restrict src, + static void copy(char *__restrict dst, const char *__restrict src, size_t size) { - AlignmentT::Copy(dst, src); - internal::AlignHelper::Bump(dst, src, size); - NextT::Copy(dst, src, size); + AlignmentT::copy(dst, src); + internal::AlignHelper::bump(dst, src, size); + NextT::copy(dst, src, size); } - static bool Equals(const char *lhs, const char *rhs, size_t size) { - if (!AlignmentT::Equals(lhs, rhs)) + static bool equals(const char *lhs, const char *rhs, size_t size) { + if (!AlignmentT::equals(lhs, rhs)) return false; - internal::AlignHelper::Bump(lhs, rhs, size); - return NextT::Equals(lhs, rhs, size); + internal::AlignHelper::bump(lhs, rhs, size); + return NextT::equals(lhs, rhs, size); } - static int ThreeWayCompare(const char *lhs, const char *rhs, size_t size) { - if (!AlignmentT::Equals(lhs, rhs)) - return AlignmentT::ThreeWayCompare(lhs, rhs); - internal::AlignHelper::Bump(lhs, rhs, size); - return NextT::ThreeWayCompare(lhs, rhs, size); + static int three_way_compare(const char *lhs, const char *rhs, + size_t size) { + if (!AlignmentT::equals(lhs, rhs)) + return AlignmentT::three_way_compare(lhs, rhs); + internal::AlignHelper::bump(lhs, rhs, size); + return NextT::three_way_compare(lhs, rhs, size); } - static void SplatSet(char *dst, const unsigned char value, size_t size) { - AlignmentT::SplatSet(dst, value); + static void splat_set(char *dst, const unsigned char value, size_t size) { + AlignmentT::splat_set(dst, value); char *dummy = nullptr; - internal::AlignHelper::Bump(dst, dummy, size); - NextT::SplatSet(dst, value, size); + internal::AlignHelper::bump(dst, dummy, size); + NextT::splat_set(dst, value, size); } }; }; @@ -452,37 +453,38 @@ // An operation that allows to skip the specified amount of bytes. template struct Skip { template struct Then { - static void Copy(char *__restrict dst, const char *__restrict src, + static void copy(char *__restrict dst, const char *__restrict src, size_t size) { - NextT::Copy(dst + Bytes, src + Bytes, size - Bytes); + NextT::copy(dst + Bytes, src + Bytes, size - Bytes); } - static void Copy(char *__restrict dst, const char *__restrict src) { - NextT::Copy(dst + Bytes, src + Bytes); + static void copy(char *__restrict dst, const char *__restrict src) { + NextT::copy(dst + Bytes, src + Bytes); } - static bool Equals(const char *lhs, const char *rhs, size_t size) { - return NextT::Equals(lhs + Bytes, rhs + Bytes, size - Bytes); + static bool equals(const char *lhs, const char *rhs, size_t size) { + return NextT::equals(lhs + Bytes, rhs + Bytes, size - Bytes); } - static bool Equals(const char *lhs, const char *rhs) { - return NextT::Equals(lhs + Bytes, rhs + Bytes); + static bool equals(const char *lhs, const char *rhs) { + return NextT::equals(lhs + Bytes, rhs + Bytes); } - static int ThreeWayCompare(const char *lhs, const char *rhs, size_t size) { - return NextT::ThreeWayCompare(lhs + Bytes, rhs + Bytes, size - Bytes); + static int three_way_compare(const char *lhs, const char *rhs, + size_t size) { + return NextT::three_way_compare(lhs + Bytes, rhs + Bytes, size - Bytes); } - static int ThreeWayCompare(const char *lhs, const char *rhs) { - return NextT::ThreeWayCompare(lhs + Bytes, rhs + Bytes); + static int three_way_compare(const char *lhs, const char *rhs) { + return NextT::three_way_compare(lhs + Bytes, rhs + Bytes); } - static void SplatSet(char *dst, const unsigned char value, size_t size) { - NextT::SplatSet(dst + Bytes, value, size - Bytes); + static void splat_set(char *dst, const unsigned char value, size_t size) { + NextT::splat_set(dst + Bytes, value, size - Bytes); } - static void SplatSet(char *dst, const unsigned char value) { - NextT::SplatSet(dst + Bytes, value); + static void splat_set(char *dst, const unsigned char value) { + NextT::splat_set(dst + Bytes, value); } }; }; @@ -499,29 +501,29 @@ #endif template struct Builtin { - static constexpr size_t kSize = Size; + static constexpr size_t K_SIZE = Size; - static void Copy(char *__restrict dst, const char *__restrict src) { + static void copy(char *__restrict dst, const char *__restrict src) { #if LLVM_LIBC_HAVE_MEMORY_SANITIZER || LLVM_LIBC_HAVE_ADDRESS_SANITIZER ForLoopCopy(dst, src); #elif __has_builtin(__builtin_memcpy_inline) // __builtin_memcpy_inline guarantees to never call external functions. // Unfortunately it is not widely available. - __builtin_memcpy_inline(dst, src, kSize); + __builtin_memcpy_inline(dst, src, K_SIZE); #elif __has_builtin(__builtin_memcpy) - __builtin_memcpy(dst, src, kSize); + __builtin_memcpy(dst, src, K_SIZE); #else ForLoopCopy(dst, src); #endif } - static void Move(char *dst, const char *src) { + static void move(char *dst, const char *src) { #if LLVM_LIBC_HAVE_MEMORY_SANITIZER || LLVM_LIBC_HAVE_ADDRESS_SANITIZER - ForLoopMove(dst, src); + for_loop_move(dst, src); #elif __has_builtin(__builtin_memmove) - __builtin_memmove(dst, src, kSize); + __builtin_memmove(dst, src, K_SIZE); #else - ForLoopMove(dst, src); + for_loop_move(dst, src); #endif } @@ -531,29 +533,29 @@ #define LLVM_LIBC_MEMCMP __builtin_memcmp #endif - static bool Equals(const char *lhs, const char *rhs) { - return LLVM_LIBC_MEMCMP(lhs, rhs, kSize) == 0; + static bool equals(const char *lhs, const char *rhs) { + return LLVM_LIBC_MEMCMP(lhs, rhs, K_SIZE) == 0; } - static int ThreeWayCompare(const char *lhs, const char *rhs) { - return LLVM_LIBC_MEMCMP(lhs, rhs, kSize); + static int three_way_compare(const char *lhs, const char *rhs) { + return LLVM_LIBC_MEMCMP(lhs, rhs, K_SIZE); } - static void SplatSet(char *dst, const unsigned char value) { - __builtin_memset(dst, value, kSize); + static void splat_set(char *dst, const unsigned char value) { + __builtin_memset(dst, value, K_SIZE); } private: - // Copies `kSize` bytes from `src` to `dst` using a for loop. + // Copies `K_SIZE` bytes from `src` to `dst` using a for loop. // This code requires the use of `-fno-builtin-memcpy` to prevent the compiler // from turning the for-loop back into `__builtin_memcpy`. - static void ForLoopCopy(char *__restrict dst, const char *__restrict src) { - for (size_t i = 0; i < kSize; ++i) + static void for_loop_copy(char *__restrict dst, const char *__restrict src) { + for (size_t i = 0; i < K_SIZE; ++i) dst[i] = src[i]; } - static void ForLoopMove(char *dst, const char *src) { - for (size_t i = 0; i < kSize; ++i) + static void for_loop_move(char *dst, const char *src) { + for (size_t i = 0; i < K_SIZE; ++i) dst[i] = src[i]; } }; @@ -576,66 +578,65 @@ // The Scalar type makes use of simple sized integers. template struct Scalar { - static constexpr size_t kSize = sizeof(T); + static constexpr size_t K_SIZE = sizeof(T); - static void Copy(char *__restrict dst, const char *__restrict src) { - Store(dst, Load(src)); + static void copy(char *__restrict dst, const char *__restrict src) { + store(dst, load(src)); } - static void Move(char *dst, const char *src) { Store(dst, Load(src)); } + static void move(char *dst, const char *src) { store(dst, load(src)); } - static bool Equals(const char *lhs, const char *rhs) { - return Load(lhs) == Load(rhs); + static bool equals(const char *lhs, const char *rhs) { + return load(lhs) == load(rhs); } - static int ThreeWayCompare(const char *lhs, const char *rhs) { - return ScalarThreeWayCompare(Load(lhs), Load(rhs)); + static int three_way_compare(const char *lhs, const char *rhs) { + return scalar_three_way_compare(load(lhs), load(rhs)); } - static void SplatSet(char *dst, const unsigned char value) { - Store(dst, GetSplattedValue(value)); + static void splat_set(char *dst, const unsigned char value) { + store(dst, get_splatted_value(value)); } - static int ScalarThreeWayCompare(T a, T b); + static int scalar_three_way_compare(T a, T b); - static T Load(const char *ptr) { + static T load(const char *ptr) { T value; - builtin::Builtin::Copy(reinterpret_cast(&value), ptr); + builtin::Builtin::copy(reinterpret_cast(&value), ptr); return value; } - - static void Store(char *ptr, T value) { - builtin::Builtin::Copy(ptr, reinterpret_cast(&value)); + static void store(char *ptr, T value) { + builtin::Builtin::copy(ptr, reinterpret_cast(&value)); } private: - static T GetSplattedValue(const unsigned char value) { + static T get_splatted_value(const unsigned char value) { return T(~0) / T(0xFF) * T(value); } }; template <> -inline int Scalar::ScalarThreeWayCompare(uint8_t a, uint8_t b) { - const int16_t la = Endian::ToBigEndian(a); - const int16_t lb = Endian::ToBigEndian(b); +inline int Scalar::scalar_three_way_compare(uint8_t a, uint8_t b) { + const int16_t la = Endian::to_big_endian(a); + const int16_t lb = Endian::to_big_endian(b); return la - lb; } template <> -inline int Scalar::ScalarThreeWayCompare(uint16_t a, uint16_t b) { - const int32_t la = Endian::ToBigEndian(a); - const int32_t lb = Endian::ToBigEndian(b); +inline int Scalar::scalar_three_way_compare(uint16_t a, uint16_t b) { + const int32_t la = Endian::to_big_endian(a); + const int32_t lb = Endian::to_big_endian(b); return la - lb; } template <> -inline int Scalar::ScalarThreeWayCompare(uint32_t a, uint32_t b) { - const uint32_t la = Endian::ToBigEndian(a); - const uint32_t lb = Endian::ToBigEndian(b); +inline int Scalar::scalar_three_way_compare(uint32_t a, uint32_t b) { + const uint32_t la = Endian::to_big_endian(a); + const uint32_t lb = Endian::to_big_endian(b); return la > lb ? 1 : la < lb ? -1 : 0; } template <> -inline int Scalar::ScalarThreeWayCompare(uint64_t a, uint64_t b) { - const uint64_t la = Endian::ToBigEndian(a); - const uint64_t lb = Endian::ToBigEndian(b); +inline int Scalar::scalar_three_way_compare(uint64_t a, uint64_t b) { + const uint64_t la = Endian::to_big_endian(a); + const uint64_t lb = Endian::to_big_endian(b); return la > lb ? 1 : la < lb ? -1 : 0; } diff --git a/libc/src/string/memory_utils/elements_x86.h b/libc/src/string/memory_utils/elements_x86.h --- a/libc/src/string/memory_utils/elements_x86.h +++ b/libc/src/string/memory_utils/elements_x86.h @@ -30,30 +30,30 @@ #ifdef __SSE2__ template struct Vector : public Base { - static void Copy(char *__restrict dst, const char *__restrict src) { - Base::Store(dst, Base::Load(src)); + static void copy(char *__restrict dst, const char *__restrict src) { + Base::store(dst, Base::load(src)); } - static void Move(char *dst, const char *src) { - Base::Store(dst, Base::Load(src)); + static void move(char *dst, const char *src) { + Base::store(dst, Base::load(src)); } - static bool Equals(const char *a, const char *b) { - return Base::NotEqualMask(Base::Load(a), Base::Load(b)) == 0; + static bool equals(const char *a, const char *b) { + return Base::not_equal_mask(Base::load(a), Base::load(b)) == 0; } - static int ThreeWayCompare(const char *a, const char *b) { - const auto mask = Base::NotEqualMask(Base::Load(a), Base::Load(b)); + static int three_way_compare(const char *a, const char *b) { + const auto mask = Base::not_equal_mask(Base::load(a), Base::load(b)); if (!mask) return 0; - return CharDiff(a, b, mask); + return char_diff(a, b, mask); } - static void SplatSet(char *dst, const unsigned char value) { - Base::Store(dst, Base::GetSplattedValue(value)); + static void splat_set(char *dst, const unsigned char value) { + Base::store(dst, Base::get_splatted_value(value)); } - static int CharDiff(const char *a, const char *b, uint64_t mask) { + static int char_diff(const char *a, const char *b, uint64_t mask) { const size_t diff_index = __builtin_ctzll(mask); const int ca = (unsigned char)a[diff_index]; const int cb = (unsigned char)b[diff_index]; @@ -62,22 +62,22 @@ }; struct M128 { - static constexpr size_t kSize = 16; - using T = char __attribute__((__vector_size__(kSize))); + static constexpr size_t K_SIZE = 16; + using T = char __attribute__((__vector_size__(K_SIZE))); static uint16_t mask(T value) { // NOLINTNEXTLINE(llvmlibc-callee-namespace) return _mm_movemask_epi8(value); } - static uint16_t NotEqualMask(T a, T b) { return mask(a != b); } - static T Load(const char *ptr) { + static uint16_t not_equal_mask(T a, T b) { return mask(a != b); } + static T load(const char *ptr) { // NOLINTNEXTLINE(llvmlibc-callee-namespace) return _mm_loadu_si128(reinterpret_cast<__m128i_u const *>(ptr)); } - static void Store(char *ptr, T value) { + static void store(char *ptr, T value) { // NOLINTNEXTLINE(llvmlibc-callee-namespace) return _mm_storeu_si128(reinterpret_cast<__m128i_u *>(ptr), value); } - static T GetSplattedValue(const char v) { + static T get_splatted_value(const char v) { const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v}; return splatted; } @@ -87,22 +87,22 @@ #ifdef __AVX2__ struct M256 { - static constexpr size_t kSize = 32; - using T = char __attribute__((__vector_size__(kSize))); + static constexpr size_t K_SIZE = 32; + using T = char __attribute__((__vector_size__(K_SIZE))); static uint32_t mask(T value) { // NOLINTNEXTLINE(llvmlibc-callee-namespace) return _mm256_movemask_epi8(value); } - static uint32_t NotEqualMask(T a, T b) { return mask(a != b); } - static T Load(const char *ptr) { + static uint32_t not_equal_mask(T a, T b) { return mask(a != b); } + static T load(const char *ptr) { // NOLINTNEXTLINE(llvmlibc-callee-namespace) return _mm256_loadu_si256(reinterpret_cast<__m256i const *>(ptr)); } - static void Store(char *ptr, T value) { + static void store(char *ptr, T value) { // NOLINTNEXTLINE(llvmlibc-callee-namespace) return _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr), value); } - static T GetSplattedValue(const char v) { + static T get_splatted_value(const char v) { const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v}; return splatted; @@ -113,21 +113,21 @@ #if defined(__AVX512F__) and defined(__AVX512BW__) struct M512 { - static constexpr size_t kSize = 64; - using T = char __attribute__((__vector_size__(kSize))); - static uint64_t NotEqualMask(T a, T b) { + static constexpr size_t K_SIZE = 64; + using T = char __attribute__((__vector_size__(K_SIZE))); + static uint64_t not_equal_mask(T a, T b) { // NOLINTNEXTLINE(llvmlibc-callee-namespace) return _mm512_cmpneq_epi8_mask(a, b); } - static T Load(const char *ptr) { + static T load(const char *ptr) { // NOLINTNEXTLINE(llvmlibc-callee-namespace) return _mm512_loadu_epi8(ptr); } - static void Store(char *ptr, T value) { + static void store(char *ptr, T value) { // NOLINTNEXTLINE(llvmlibc-callee-namespace) return _mm512_storeu_epi8(ptr, value); } - static T GetSplattedValue(const char v) { + static T get_splatted_value(const char v) { const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, @@ -169,7 +169,7 @@ #endif struct Accelerator { - static void Copy(char *dst, const char *src, size_t count) { + static void copy(char *dst, const char *src, size_t count) { asm volatile("rep movsb" : "+D"(dst), "+S"(src), "+c"(count) : : "memory"); } }; diff --git a/libc/src/string/memory_utils/memcmp_implementations.h b/libc/src/string/memory_utils/memcmp_implementations.h --- a/libc/src/string/memory_utils/memcmp_implementations.h +++ b/libc/src/string/memory_utils/memcmp_implementations.h @@ -27,22 +27,22 @@ if (count == 0) return 0; if (count == 1) - return ThreeWayCompare<_1>(lhs, rhs); + return three_way_compare<_1>(lhs, rhs); if (count == 2) - return ThreeWayCompare<_2>(lhs, rhs); + return three_way_compare<_2>(lhs, rhs); if (count == 3) - return ThreeWayCompare<_3>(lhs, rhs); + return three_way_compare<_3>(lhs, rhs); if (count <= 8) - return ThreeWayCompare>(lhs, rhs, count); + return three_way_compare>(lhs, rhs, count); if (count <= 16) - return ThreeWayCompare>(lhs, rhs, count); + return three_way_compare>(lhs, rhs, count); if (count <= 32) - return ThreeWayCompare>(lhs, rhs, count); + return three_way_compare>(lhs, rhs, count); if (count <= 64) - return ThreeWayCompare>(lhs, rhs, count); + return three_way_compare>(lhs, rhs, count); if (count <= 128) - return ThreeWayCompare>(lhs, rhs, count); - return ThreeWayCompare::Then>>(lhs, rhs, count); + return three_way_compare>(lhs, rhs, count); + return three_way_compare::Then>>(lhs, rhs, count); #elif defined(LLVM_LIBC_ARCH_AARCH64) ///////////////////////////////////////////////////////////////////////////// // LLVM_LIBC_ARCH_AARCH64 diff --git a/libc/src/string/memory_utils/memcpy_implementations.h b/libc/src/string/memory_utils/memcpy_implementations.h --- a/libc/src/string/memory_utils/memcpy_implementations.h +++ b/libc/src/string/memory_utils/memcpy_implementations.h @@ -46,13 +46,13 @@ using namespace __llvm_libc::x86; // Whether to use only rep;movsb. - constexpr bool kUseOnlyRepMovsb = + constexpr bool K_USE_ONLY_REP_MOVSB = LLVM_LIBC_IS_DEFINED(LLVM_LIBC_MEMCPY_X86_USE_ONLY_REPMOVSB); // kRepMovsBSize == -1 : Only CopyAligned is used. // kRepMovsBSize == 0 : Only RepMovsb is used. // else CopyAligned is used up to kRepMovsBSize and then RepMovsb. - constexpr size_t kRepMovsBSize = + constexpr size_t K_REP_MOVS_B_SIZE = #if defined(LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE) LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE; #else @@ -60,7 +60,7 @@ #endif // LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE // Whether target supports AVX instructions. - constexpr bool kHasAvx = LLVM_LIBC_IS_DEFINED(__AVX__); + constexpr bool K_HAS_AVX = LLVM_LIBC_IS_DEFINED(__AVX__); #if defined(__AVX__) using LoopBlockSize = _64; @@ -68,35 +68,35 @@ using LoopBlockSize = _32; #endif - if (kUseOnlyRepMovsb) - return Copy(dst, src, count); + if (K_USE_ONLY_REP_MOVSB) + return copy(dst, src, count); if (count == 0) return; if (count == 1) - return Copy<_1>(dst, src); + return copy<_1>(dst, src); if (count == 2) - return Copy<_2>(dst, src); + return copy<_2>(dst, src); if (count == 3) - return Copy<_3>(dst, src); + return copy<_3>(dst, src); if (count == 4) - return Copy<_4>(dst, src); + return copy<_4>(dst, src); if (count < 8) - return Copy>(dst, src, count); + return copy>(dst, src, count); if (count < 16) - return Copy>(dst, src, count); + return copy>(dst, src, count); if (count < 32) - return Copy>(dst, src, count); + return copy>(dst, src, count); if (count < 64) - return Copy>(dst, src, count); + return copy>(dst, src, count); if (count < 128) - return Copy>(dst, src, count); - if (kHasAvx && count < 256) - return Copy>(dst, src, count); - if (count <= kRepMovsBSize) - return Copy::Then>>(dst, src, + return copy>(dst, src, count); + if (K_HAS_AVX && count < 256) + return copy>(dst, src, count); + if (count <= K_REP_MOVS_B_SIZE) + return copy::Then>>(dst, src, count); - return Copy(dst, src, count); + return copy(dst, src, count); #elif defined(LLVM_LIBC_ARCH_AARCH64) ///////////////////////////////////////////////////////////////////////////// // LLVM_LIBC_ARCH_AARCH64 diff --git a/libc/src/string/memory_utils/memset_implementations.h b/libc/src/string/memory_utils/memset_implementations.h --- a/libc/src/string/memory_utils/memset_implementations.h +++ b/libc/src/string/memory_utils/memset_implementations.h @@ -57,22 +57,22 @@ if (count == 0) return; if (count == 1) - return SplatSet<_1>(dst, value); + return splat_set<_1>(dst, value); if (count == 2) - return SplatSet<_2>(dst, value); + return splat_set<_2>(dst, value); if (count == 3) - return SplatSet<_3>(dst, value); + return splat_set<_3>(dst, value); if (count <= 8) - return SplatSet>(dst, value, count); + return splat_set>(dst, value, count); if (count <= 16) - return SplatSet>(dst, value, count); + return splat_set>(dst, value, count); if (count <= 32) - return SplatSet>(dst, value, count); + return splat_set>(dst, value, count); if (count <= 64) - return SplatSet>(dst, value, count); + return splat_set>(dst, value, count); if (count <= 128) - return SplatSet>(dst, value, count); - return SplatSet::Then>>(dst, value, count); + return splat_set>(dst, value, count); + return splat_set::Then>>(dst, value, count); #elif defined(LLVM_LIBC_ARCH_AARCH64) ///////////////////////////////////////////////////////////////////////////// // LLVM_LIBC_ARCH_AARCH64 diff --git a/libc/src/string/strcat.cpp b/libc/src/string/strcat.cpp --- a/libc/src/string/strcat.cpp +++ b/libc/src/string/strcat.cpp @@ -16,10 +16,10 @@ LLVM_LIBC_FUNCTION(char *, strcat, (char *__restrict dest, const char *__restrict src)) { - size_t destLength = internal::string_length(dest); - size_t srcLength = internal::string_length(src); - __llvm_libc::strcpy(dest + destLength, src); - dest[destLength + srcLength] = '\0'; + size_t dest_length = internal::string_length(dest); + size_t src_length = internal::string_length(src); + __llvm_libc::strcpy(dest + dest_length, src); + dest[dest_length + src_length] = '\0'; return dest; } diff --git a/libc/src/string/strncat.cpp b/libc/src/string/strncat.cpp --- a/libc/src/string/strncat.cpp +++ b/libc/src/string/strncat.cpp @@ -17,11 +17,11 @@ LLVM_LIBC_FUNCTION(char *, strncat, (char *__restrict dest, const char *__restrict src, size_t count)) { - size_t srcLength = internal::string_length(src); - size_t copyAmount = srcLength > count ? count : srcLength; - size_t destLength = internal::string_length(dest); - __llvm_libc::strncpy(dest + destLength, src, copyAmount); - dest[destLength + copyAmount] = '\0'; + size_t src_length = internal::string_length(src); + size_t copy_amount = src_length > count ? count : src_length; + size_t dest_length = internal::string_length(dest); + __llvm_libc::strncpy(dest + dest_length, src, copy_amount); + dest[dest_length + copy_amount] = '\0'; return dest; } diff --git a/libc/src/threads/linux/Thread.h b/libc/src/threads/linux/Thread.h --- a/libc/src/threads/linux/Thread.h +++ b/libc/src/threads/linux/Thread.h @@ -17,8 +17,8 @@ namespace __llvm_libc { struct ThreadParams { - static constexpr uintptr_t DefaultStackSize = 1 << 16; // 64 KB - static constexpr uint32_t ClearTIDValue = 0xABCD1234; + static constexpr uintptr_t DEFAULT_STACK_SIZE = 1 << 16; // 64 KB + static constexpr uint32_t CLEAR_TID_VALUE = 0xABCD1234; }; } // namespace __llvm_libc diff --git a/libc/src/threads/linux/thrd_create.cpp b/libc/src/threads/linux/thrd_create.cpp --- a/libc/src/threads/linux/thrd_create.cpp +++ b/libc/src/threads/linux/thrd_create.cpp @@ -52,18 +52,18 @@ // TODO: Add the CLONE_SETTLS flag and setup the TLS area correctly when // making the clone syscall. - void *stack = __llvm_libc::mmap(nullptr, ThreadParams::DefaultStackSize, + void *stack = __llvm_libc::mmap(nullptr, ThreadParams::DEFAULT_STACK_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (stack == MAP_FAILED) return llvmlibc_errno == ENOMEM ? thrd_nomem : thrd_error; thread->__stack = stack; - thread->__stack_size = ThreadParams::DefaultStackSize; + thread->__stack_size = ThreadParams::DEFAULT_STACK_SIZE; thread->__retval = -1; FutexWord *clear_tid_address = reinterpret_cast(thread->__clear_tid); - *clear_tid_address = ThreadParams::ClearTIDValue; + *clear_tid_address = ThreadParams::CLEAR_TID_VALUE; // When the new thread is spawned by the kernel, the new thread gets the // stack we pass to the clone syscall. However, this stack is empty and does @@ -72,7 +72,8 @@ // here. So, we pack them into the new stack from where the thread can sniff // them out. uintptr_t adjusted_stack = reinterpret_cast(stack) + - ThreadParams::DefaultStackSize - sizeof(StartArgs); + ThreadParams::DEFAULT_STACK_SIZE - + sizeof(StartArgs); StartArgs *start_args = reinterpret_cast(adjusted_stack); start_args->thread = thread; start_args->func = func; @@ -83,9 +84,8 @@ // architecture independent. May be implement a glibc like wrapper for clone // and use it here. long register clone_result asm("rax"); - clone_result = - __llvm_libc::syscall(SYS_clone, clone_flags, adjusted_stack, - &thread->__tid, clear_tid_address, 0); + clone_result = __llvm_libc::syscall(SYS_clone, clone_flags, adjusted_stack, + &thread->__tid, clear_tid_address, 0); if (clone_result == 0) { start_thread(); diff --git a/libc/src/threads/linux/thrd_join.cpp b/libc/src/threads/linux/thrd_join.cpp --- a/libc/src/threads/linux/thrd_join.cpp +++ b/libc/src/threads/linux/thrd_join.cpp @@ -31,7 +31,7 @@ // We cannot do a FUTEX_WAIT_PRIVATE here as the kernel does a // FUTEX_WAKE and not a FUTEX_WAKE_PRIVATE. __llvm_libc::syscall(SYS_futex, clear_tid_address, FUTEX_WAIT, - ThreadParams::ClearTIDValue, nullptr); + ThreadParams::CLEAR_TID_VALUE, nullptr); } *retval = thread->__retval; diff --git a/libc/src/time/asctime.h b/libc/src/time/asctime.h --- a/libc/src/time/asctime.h +++ b/libc/src/time/asctime.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -char *asctime(const struct tm *timeptr); +char *asctime(const struct Tm *timeptr); } // namespace __llvm_libc diff --git a/libc/src/time/asctime.cpp b/libc/src/time/asctime.cpp --- a/libc/src/time/asctime.cpp +++ b/libc/src/time/asctime.cpp @@ -14,9 +14,9 @@ using __llvm_libc::time_utils::TimeConstants; -LLVM_LIBC_FUNCTION(char *, asctime, (const struct tm *timeptr)) { - static char buffer[TimeConstants::AsctimeBufferSize]; - return time_utils::asctime(timeptr, buffer, TimeConstants::AsctimeMaxBytes); +LLVM_LIBC_FUNCTION(char *, asctime, (const struct Tm *timeptr)) { + static char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + return time_utils::asctime(timeptr, buffer, TimeConstants::ASCTIME_MAX_BYTES); } } // namespace __llvm_libc diff --git a/libc/src/time/asctime_r.h b/libc/src/time/asctime_r.h --- a/libc/src/time/asctime_r.h +++ b/libc/src/time/asctime_r.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -char *asctime_r(const struct tm *timeptr, char *buffer); +char *asctime_r(const struct Tm *timeptr, char *buffer); } // namespace __llvm_libc diff --git a/libc/src/time/asctime_r.cpp b/libc/src/time/asctime_r.cpp --- a/libc/src/time/asctime_r.cpp +++ b/libc/src/time/asctime_r.cpp @@ -15,8 +15,8 @@ using __llvm_libc::time_utils::TimeConstants; LLVM_LIBC_FUNCTION(char *, asctime_r, - (const struct tm *timeptr, char *buffer)) { - return time_utils::asctime(timeptr, buffer, TimeConstants::AsctimeMaxBytes); + (const struct Tm *timeptr, char *buffer)) { + return time_utils::asctime(timeptr, buffer, TimeConstants::ASCTIME_MAX_BYTES); } } // namespace __llvm_libc diff --git a/libc/src/time/gmtime.h b/libc/src/time/gmtime.h --- a/libc/src/time/gmtime.h +++ b/libc/src/time/gmtime.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -struct tm *gmtime(const time_t *timer); +struct Tm *gmtime(const time_t *timer); } // namespace __llvm_libc diff --git a/libc/src/time/gmtime.cpp b/libc/src/time/gmtime.cpp --- a/libc/src/time/gmtime.cpp +++ b/libc/src/time/gmtime.cpp @@ -12,8 +12,8 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(struct tm *, gmtime, (const time_t *timer)) { - static struct tm tm_out; +LLVM_LIBC_FUNCTION(struct Tm *, gmtime, (const time_t *timer)) { + static struct Tm tm_out; return time_utils::gmtime_internal(timer, &tm_out); } diff --git a/libc/src/time/gmtime_r.h b/libc/src/time/gmtime_r.h --- a/libc/src/time/gmtime_r.h +++ b/libc/src/time/gmtime_r.h @@ -13,7 +13,7 @@ namespace __llvm_libc { -struct tm *gmtime_r(const time_t *timer, struct tm *result); +struct Tm *gmtime_r(const time_t *timer, struct Tm *result); } // namespace __llvm_libc diff --git a/libc/src/time/gmtime_r.cpp b/libc/src/time/gmtime_r.cpp --- a/libc/src/time/gmtime_r.cpp +++ b/libc/src/time/gmtime_r.cpp @@ -12,8 +12,8 @@ namespace __llvm_libc { -LLVM_LIBC_FUNCTION(struct tm *, gmtime_r, - (const time_t *timer, struct tm *result)) { +LLVM_LIBC_FUNCTION(struct Tm *, gmtime_r, + (const time_t *timer, struct Tm *result)) { return time_utils::gmtime_internal(timer, result); } diff --git a/libc/src/time/mktime.h b/libc/src/time/mktime.h --- a/libc/src/time/mktime.h +++ b/libc/src/time/mktime.h @@ -14,7 +14,7 @@ namespace __llvm_libc { -time_t mktime(struct tm *t1); +time_t mktime(struct Tm *t1); } // namespace __llvm_libc diff --git a/libc/src/time/mktime.cpp b/libc/src/time/mktime.cpp --- a/libc/src/time/mktime.cpp +++ b/libc/src/time/mktime.cpp @@ -16,39 +16,39 @@ using __llvm_libc::time_utils::TimeConstants; -static constexpr int NonLeapYearDaysInMonth[] = {31, 28, 31, 30, 31, 30, - 31, 31, 30, 31, 30, 31}; +static constexpr int NON_LEAP_YEAR_DAYS_IN_MONTH[] = {31, 28, 31, 30, 31, 30, + 31, 31, 30, 31, 30, 31}; // Returns number of years from (1, year). -static constexpr int64_t getNumOfLeapYearsBefore(int64_t year) { +static constexpr int64_t get_num_of_leap_years_before(int64_t year) { return (year / 4) - (year / 100) + (year / 400); } // Returns True if year is a leap year. -static constexpr bool isLeapYear(const int64_t year) { +static constexpr bool is_leap_year(const int64_t year) { return (((year) % 4) == 0 && (((year) % 100) != 0 || ((year) % 400) == 0)); } -LLVM_LIBC_FUNCTION(time_t, mktime, (struct tm * tm_out)) { +LLVM_LIBC_FUNCTION(time_t, mktime, (struct Tm * tm_out)) { // Unlike most C Library functions, mktime doesn't just die on bad input. // TODO(rtenneti); Handle leap seconds. - int64_t tmYearFromBase = tm_out->tm_year + TimeConstants::TimeYearBase; + int64_t tm_year_from_base = tm_out->tm_year + TimeConstants::TIME_YEAR_BASE; // 32-bit end-of-the-world is 03:14:07 UTC on 19 January 2038. if (sizeof(time_t) == 4 && - tmYearFromBase >= TimeConstants::EndOf32BitEpochYear) { - if (tmYearFromBase > TimeConstants::EndOf32BitEpochYear) - return time_utils::OutOfRange(); + tm_year_from_base >= TimeConstants::END_OF32_BIT_EPOCH_YEAR) { + if (tm_year_from_base > TimeConstants::END_OF32_BIT_EPOCH_YEAR) + return time_utils::out_of_range(); if (tm_out->tm_mon > 0) - return time_utils::OutOfRange(); + return time_utils::out_of_range(); if (tm_out->tm_mday > 19) - return time_utils::OutOfRange(); + return time_utils::out_of_range(); if (tm_out->tm_hour > 3) - return time_utils::OutOfRange(); + return time_utils::out_of_range(); if (tm_out->tm_min > 14) - return time_utils::OutOfRange(); + return time_utils::out_of_range(); if (tm_out->tm_sec > 7) - return time_utils::OutOfRange(); + return time_utils::out_of_range(); } // Years are ints. A 32-bit year will fit into a 64-bit time_t. @@ -59,57 +59,57 @@ // Calculate number of months and years from tm_mon. int64_t month = tm_out->tm_mon; - if (month < 0 || month >= TimeConstants::MonthsPerYear - 1) { + if (month < 0 || month >= TimeConstants::MONTHS_PER_YEAR - 1) { int64_t years = month / 12; month %= 12; if (month < 0) { years--; month += 12; } - tmYearFromBase += years; + tm_year_from_base += years; } - bool tmYearIsLeap = isLeapYear(tmYearFromBase); + bool tm_year_is_leap = is_leap_year(tm_year_from_base); // Calculate total number of days based on the month and the day (tm_mday). - int64_t totalDays = tm_out->tm_mday - 1; + int64_t total_days = tm_out->tm_mday - 1; for (int64_t i = 0; i < month; ++i) - totalDays += NonLeapYearDaysInMonth[i]; + total_days += NON_LEAP_YEAR_DAYS_IN_MONTH[i]; // Add one day if it is a leap year and the month is after February. - if (tmYearIsLeap && month > 1) - totalDays++; + if (tm_year_is_leap && month > 1) + total_days++; // Calculate total numbers of days based on the year. - totalDays += (tmYearFromBase - TimeConstants::EpochYear) * - TimeConstants::DaysPerNonLeapYear; - if (tmYearFromBase >= TimeConstants::EpochYear) { - totalDays += getNumOfLeapYearsBefore(tmYearFromBase - 1) - - getNumOfLeapYearsBefore(TimeConstants::EpochYear); - } else if (tmYearFromBase >= 1) { - totalDays -= getNumOfLeapYearsBefore(TimeConstants::EpochYear) - - getNumOfLeapYearsBefore(tmYearFromBase - 1); + total_days += (tm_year_from_base - TimeConstants::EPOCH_YEAR) * + TimeConstants::DAYS_PER_NON_LEAP_YEAR; + if (tm_year_from_base >= TimeConstants::EPOCH_YEAR) { + total_days += get_num_of_leap_years_before(tm_year_from_base - 1) - + get_num_of_leap_years_before(TimeConstants::EPOCH_YEAR); + } else if (tm_year_from_base >= 1) { + total_days -= get_num_of_leap_years_before(TimeConstants::EPOCH_YEAR) - + get_num_of_leap_years_before(tm_year_from_base - 1); } else { // Calculate number of leap years until 0th year. - totalDays -= getNumOfLeapYearsBefore(TimeConstants::EpochYear) - - getNumOfLeapYearsBefore(0); - if (tmYearFromBase <= 0) { - totalDays -= 1; // Subtract 1 for 0th year. + total_days -= get_num_of_leap_years_before(TimeConstants::EPOCH_YEAR) - + get_num_of_leap_years_before(0); + if (tm_year_from_base <= 0) { + total_days -= 1; // Subtract 1 for 0th year. // Calculate number of leap years until -1 year - if (tmYearFromBase < 0) { - totalDays -= getNumOfLeapYearsBefore(-tmYearFromBase) - - getNumOfLeapYearsBefore(1); + if (tm_year_from_base < 0) { + total_days -= get_num_of_leap_years_before(-tm_year_from_base) - + get_num_of_leap_years_before(1); } } } // TODO(rtenneti): Need to handle timezone and update of tm_isdst. int64_t seconds = tm_out->tm_sec + - tm_out->tm_min * TimeConstants::SecondsPerMin + - tm_out->tm_hour * TimeConstants::SecondsPerHour + - totalDays * TimeConstants::SecondsPerDay; + tm_out->tm_min * TimeConstants::SECONDS_PER_MIN + + tm_out->tm_hour * TimeConstants::SECONDS_PER_HOUR + + total_days * TimeConstants::SECONDS_PER_DAY; // Update the tm structure's year, month, day, etc. from seconds. - if (time_utils::UpdateFromSeconds(seconds, tm_out) < 0) - return time_utils::OutOfRange(); + if (time_utils::update_from_seconds(seconds, tm_out) < 0) + return time_utils::out_of_range(); return static_cast(seconds); } diff --git a/libc/src/time/time_utils.h b/libc/src/time/time_utils.h --- a/libc/src/time/time_utils.h +++ b/libc/src/time/time_utils.h @@ -22,103 +22,103 @@ namespace time_utils { struct TimeConstants { - static constexpr int SecondsPerMin = 60; - static constexpr int SecondsPerHour = 3600; - static constexpr int SecondsPerDay = 86400; - static constexpr int DaysPerWeek = 7; - static constexpr int MonthsPerYear = 12; - static constexpr int DaysPerNonLeapYear = 365; - static constexpr int DaysPerLeapYear = 366; - static constexpr int TimeYearBase = 1900; - static constexpr int EpochYear = 1970; - static constexpr int EpochWeekDay = 4; - static constexpr int NumberOfSecondsInLeapYear = - (DaysPerNonLeapYear + 1) * SecondsPerDay; - - // For asctime the behavior is undefined if struct tm's tm_wday or tm_mon are - // not within the normal ranges as defined in , or if struct tm's + static constexpr int SECONDS_PER_MIN = 60; + static constexpr int SECONDS_PER_HOUR = 3600; + static constexpr int SECONDS_PER_DAY = 86400; + static constexpr int DAYS_PER_WEEK = 7; + static constexpr int MONTHS_PER_YEAR = 12; + static constexpr int DAYS_PER_NON_LEAP_YEAR = 365; + static constexpr int DAYS_PER_LEAP_YEAR = 366; + static constexpr int TIME_YEAR_BASE = 1900; + static constexpr int EPOCH_YEAR = 1970; + static constexpr int EPOCH_WEEK_DAY = 4; + static constexpr int NUMBER_OF_SECONDS_IN_LEAP_YEAR = + (DAYS_PER_NON_LEAP_YEAR + 1) * SECONDS_PER_DAY; + + // For asctime the behavior is undefined if struct Tm's tm_wday or tm_mon are + // not within the normal ranges as defined in , or if struct Tm's // tm_year exceeds {INT_MAX}-1990, or if the below asctime_internal algorithm // would attempt to generate more than 26 bytes of output (including the // terminating null). - static constexpr int AsctimeBufferSize = 256; - static constexpr int AsctimeMaxBytes = 26; + static constexpr int ASCTIME_BUFFER_SIZE = 256; + static constexpr int ASCTIME_MAX_BYTES = 26; /* 2000-03-01 (mod 400 year, immediately after feb29 */ - static constexpr int64_t SecondsUntil2000MarchFirst = - (946684800LL + SecondsPerDay * (31 + 29)); - static constexpr int WeekDayOf2000MarchFirst = 3; + static constexpr int64_t SECONDS_UNTIL2000_MARCH_FIRST = + (946684800LL + SECONDS_PER_DAY * (31 + 29)); + static constexpr int WEEK_DAY_OF2000_MARCH_FIRST = 3; - static constexpr int DaysPer400Years = - (DaysPerNonLeapYear * 400 + (400 / 4) - 3); - static constexpr int DaysPer100Years = - (DaysPerNonLeapYear * 100 + (100 / 4) - 1); - static constexpr int DaysPer4Years = (DaysPerNonLeapYear * 4 + 1); + static constexpr int DAYS_PER400_YEARS = + (DAYS_PER_NON_LEAP_YEAR * 400 + (400 / 4) - 3); + static constexpr int DAYS_PER100_YEARS = + (DAYS_PER_NON_LEAP_YEAR * 100 + (100 / 4) - 1); + static constexpr int DAYS_PER4_YEARS = (DAYS_PER_NON_LEAP_YEAR * 4 + 1); // The latest time that can be represented in this form is 03:14:07 UTC on // Tuesday, 19 January 2038 (corresponding to 2,147,483,647 seconds since the // start of the epoch). This means that systems using a 32-bit time_t type are // susceptible to the Year 2038 problem. - static constexpr int EndOf32BitEpochYear = 2038; + static constexpr int END_OF32_BIT_EPOCH_YEAR = 2038; - static constexpr time_t OutOfRangeReturnValue = -1; + static constexpr time_t OUT_OF_RANGE_RETURN_VALUE = -1; }; // Update the "tm" structure's year, month, etc. members from seconds. // "total_seconds" is the number of seconds since January 1st, 1970. -extern int64_t UpdateFromSeconds(int64_t total_seconds, struct tm *tm); +extern int64_t update_from_seconds(int64_t total_seconds, struct Tm *tm); // POSIX.1-2017 requires this. -static inline time_t OutOfRange() { +static inline time_t out_of_range() { llvmlibc_errno = EOVERFLOW; return static_cast(-1); } -static inline void InvalidValue() { llvmlibc_errno = EINVAL; } +static inline void invalid_value() { llvmlibc_errno = EINVAL; } -static inline char *asctime(const struct tm *timeptr, char *buffer, +static inline char *asctime(const struct Tm *timeptr, char *buffer, size_t bufferLength) { if (timeptr == nullptr || buffer == nullptr) { - InvalidValue(); + invalid_value(); return nullptr; } if (timeptr->tm_wday < 0 || - timeptr->tm_wday > (TimeConstants::DaysPerWeek - 1)) { - InvalidValue(); + timeptr->tm_wday > (TimeConstants::DAYS_PER_WEEK - 1)) { + invalid_value(); return nullptr; } if (timeptr->tm_mon < 0 || - timeptr->tm_mon > (TimeConstants::MonthsPerYear - 1)) { - InvalidValue(); + timeptr->tm_mon > (TimeConstants::MONTHS_PER_YEAR - 1)) { + invalid_value(); return nullptr; } // TODO(rtenneti): i18n the following strings. - static const char *WeekDaysName[TimeConstants::DaysPerWeek] = { + static const char *week_days_name[TimeConstants::DAYS_PER_WEEK] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; - static const char *MonthsName[TimeConstants::MonthsPerYear] = { + static const char *months_name[TimeConstants::MONTHS_PER_YEAR] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; int written_size = __builtin_snprintf( buffer, bufferLength, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", - WeekDaysName[timeptr->tm_wday], MonthsName[timeptr->tm_mon], + week_days_name[timeptr->tm_wday], months_name[timeptr->tm_mon], timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, - TimeConstants::TimeYearBase + timeptr->tm_year); + TimeConstants::TIME_YEAR_BASE + timeptr->tm_year); if (written_size < 0) return nullptr; if (static_cast(written_size) >= bufferLength) { - OutOfRange(); + out_of_range(); return nullptr; } return buffer; } -static inline struct tm *gmtime_internal(const time_t *timer, - struct tm *result) { +static inline struct Tm *gmtime_internal(const time_t *timer, + struct Tm *result) { int64_t seconds = *timer; // Update the tm structure's year, month, day, etc. from seconds. - if (UpdateFromSeconds(seconds, result) < 0) { - OutOfRange(); + if (update_from_seconds(seconds, result) < 0) { + out_of_range(); return nullptr; } diff --git a/libc/src/time/time_utils.cpp b/libc/src/time/time_utils.cpp --- a/libc/src/time/time_utils.cpp +++ b/libc/src/time/time_utils.cpp @@ -43,61 +43,63 @@ // // Compute the number of months from the remaining days. Finally, adjust years // to be 1900 and months to be from January. -int64_t UpdateFromSeconds(int64_t total_seconds, struct tm *tm) { +int64_t update_from_seconds(int64_t total_seconds, struct Tm *tm) { // Days in month starting from March in the year 2000. static const char daysInMonth[] = {31 /* Mar */, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29}; if (sizeof(time_t) == 4) { if (total_seconds < 0x80000000) - return time_utils::OutOfRange(); + return time_utils::out_of_range(); if (total_seconds > 0x7FFFFFFF) - return time_utils::OutOfRange(); + return time_utils::out_of_range(); } else { if (total_seconds < INT_MIN * static_cast( - TimeConstants::NumberOfSecondsInLeapYear) || - total_seconds > INT_MAX * static_cast( - TimeConstants::NumberOfSecondsInLeapYear)) - return time_utils::OutOfRange(); + TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR) || + total_seconds > + INT_MAX * static_cast( + TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR)) + return time_utils::out_of_range(); } - int64_t seconds = total_seconds - TimeConstants::SecondsUntil2000MarchFirst; - int64_t days = seconds / TimeConstants::SecondsPerDay; - int64_t remainingSeconds = seconds % TimeConstants::SecondsPerDay; + int64_t seconds = + total_seconds - TimeConstants::SECONDS_UNTIL2000_MARCH_FIRST; + int64_t days = seconds / TimeConstants::SECONDS_PER_DAY; + int64_t remainingSeconds = seconds % TimeConstants::SECONDS_PER_DAY; if (remainingSeconds < 0) { - remainingSeconds += TimeConstants::SecondsPerDay; + remainingSeconds += TimeConstants::SECONDS_PER_DAY; days--; } - int64_t wday = (TimeConstants::WeekDayOf2000MarchFirst + days) % - TimeConstants::DaysPerWeek; + int64_t wday = (TimeConstants::WEEK_DAY_OF2000_MARCH_FIRST + days) % + TimeConstants::DAYS_PER_WEEK; if (wday < 0) - wday += TimeConstants::DaysPerWeek; + wday += TimeConstants::DAYS_PER_WEEK; // Compute the number of 400 year cycles. - int64_t numOfFourHundredYearCycles = days / TimeConstants::DaysPer400Years; - int64_t remainingDays = days % TimeConstants::DaysPer400Years; + int64_t numOfFourHundredYearCycles = days / TimeConstants::DAYS_PER400_YEARS; + int64_t remainingDays = days % TimeConstants::DAYS_PER400_YEARS; if (remainingDays < 0) { - remainingDays += TimeConstants::DaysPer400Years; + remainingDays += TimeConstants::DAYS_PER400_YEARS; numOfFourHundredYearCycles--; } // The reminder number of years after computing number of // "four hundred year cycles" will be 4 hundred year cycles or less in 400 // years. - int64_t numOfHundredYearCycles = - computeRemainingYears(TimeConstants::DaysPer100Years, 4, &remainingDays); + int64_t numOfHundredYearCycles = computeRemainingYears( + TimeConstants::DAYS_PER100_YEARS, 4, &remainingDays); // The reminder number of years after computing number of // "hundred year cycles" will be 25 four year cycles or less in 100 years. int64_t numOfFourYearCycles = - computeRemainingYears(TimeConstants::DaysPer4Years, 25, &remainingDays); + computeRemainingYears(TimeConstants::DAYS_PER4_YEARS, 25, &remainingDays); // The reminder number of years after computing number of "four year cycles" // will be 4 one year cycles or less in 4 years. int64_t remainingYears = computeRemainingYears( - TimeConstants::DaysPerNonLeapYear, 4, &remainingDays); + TimeConstants::DAYS_PER_NON_LEAP_YEAR, 4, &remainingDays); // Calculate number of years from year 2000. int64_t years = remainingYears + 4 * numOfFourYearCycles + @@ -108,8 +110,8 @@ !remainingYears && (numOfFourYearCycles || !numOfHundredYearCycles); int64_t yday = remainingDays + 31 + 28 + leapDay; - if (yday >= TimeConstants::DaysPerNonLeapYear + leapDay) - yday -= TimeConstants::DaysPerNonLeapYear + leapDay; + if (yday >= TimeConstants::DAYS_PER_NON_LEAP_YEAR + leapDay) + yday -= TimeConstants::DAYS_PER_NON_LEAP_YEAR + leapDay; int64_t months = 0; while (daysInMonth[months] <= remainingDays) { @@ -117,26 +119,26 @@ months++; } - if (months >= TimeConstants::MonthsPerYear - 2) { - months -= TimeConstants::MonthsPerYear; + if (months >= TimeConstants::MONTHS_PER_YEAR - 2) { + months -= TimeConstants::MONTHS_PER_YEAR; years++; } if (years > INT_MAX || years < INT_MIN) - return time_utils::OutOfRange(); + return time_utils::out_of_range(); // All the data (years, month and remaining days) was calculated from // March, 2000. Thus adjust the data to be from January, 1900. - tm->tm_year = years + 2000 - TimeConstants::TimeYearBase; + tm->tm_year = years + 2000 - TimeConstants::TIME_YEAR_BASE; tm->tm_mon = months + 2; tm->tm_mday = remainingDays + 1; tm->tm_wday = wday; tm->tm_yday = yday; - tm->tm_hour = remainingSeconds / TimeConstants::SecondsPerHour; - tm->tm_min = remainingSeconds / TimeConstants::SecondsPerMin % - TimeConstants::SecondsPerMin; - tm->tm_sec = remainingSeconds % TimeConstants::SecondsPerMin; + tm->tm_hour = remainingSeconds / TimeConstants::SECONDS_PER_HOUR; + tm->tm_min = remainingSeconds / TimeConstants::SECONDS_PER_MIN % + TimeConstants::SECONDS_PER_MIN; + tm->tm_sec = remainingSeconds % TimeConstants::SECONDS_PER_MIN; // TODO(rtenneti): Need to handle timezone and update of tm_isdst. tm->tm_isdst = 0; diff --git a/libc/test/src/__support/endian_test.cpp b/libc/test/src/__support/endian_test.cpp --- a/libc/test/src/__support/endian_test.cpp +++ b/libc/test/src/__support/endian_test.cpp @@ -14,19 +14,19 @@ struct LlvmLibcEndian : testing::Test { template void check(const T original, const T swapped) { #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - EXPECT_EQ(Endian::ToLittleEndian(original), original); - EXPECT_EQ(Endian::ToBigEndian(original), swapped); + EXPECT_EQ(Endian::to_little_endian(original), original); + EXPECT_EQ(Endian::to_big_endian(original), swapped); #endif #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - EXPECT_EQ(Endian::ToBigEndian(original), original); - EXPECT_EQ(Endian::ToLittleEndian(original), swapped); + EXPECT_EQ(Endian::to_big_endian(original), original); + EXPECT_EQ(Endian::to_little_endian(original), swapped); #endif } }; TEST_F(LlvmLibcEndian, Field) { - EXPECT_EQ(Endian::isLittle, __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__); - EXPECT_EQ(Endian::isBig, __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__); + EXPECT_EQ(Endian::IS_LITTLE, __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__); + EXPECT_EQ(Endian::IS_BIG, __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__); } TEST_F(LlvmLibcEndian, uint8_t) { diff --git a/libc/test/src/__support/high_precision_decimal_test.cpp b/libc/test/src/__support/high_precision_decimal_test.cpp --- a/libc/test/src/__support/high_precision_decimal_test.cpp +++ b/libc/test/src/__support/high_precision_decimal_test.cpp @@ -13,33 +13,33 @@ TEST(LlvmLibcHighPrecisionDecimalTest, BasicInit) { __llvm_libc::internal::HighPrecisionDecimal hpd = __llvm_libc::internal::HighPrecisionDecimal("1.2345"); - uint8_t *digits = hpd.getDigits(); + uint8_t *digits = hpd.get_digits(); EXPECT_EQ(digits[0], uint8_t(1)); EXPECT_EQ(digits[1], uint8_t(2)); EXPECT_EQ(digits[2], uint8_t(3)); EXPECT_EQ(digits[3], uint8_t(4)); EXPECT_EQ(digits[4], uint8_t(5)); - EXPECT_EQ(hpd.getNumDigits(), 5u); - EXPECT_EQ(hpd.getDecimalPoint(), 1); + EXPECT_EQ(hpd.get_num_digits(), 5u); + EXPECT_EQ(hpd.get_decimal_point(), 1); } TEST(LlvmLibcHighPrecisionDecimalTest, BasicShift) { __llvm_libc::internal::HighPrecisionDecimal hpd = __llvm_libc::internal::HighPrecisionDecimal("1"); - uint8_t *digits = hpd.getDigits(); + uint8_t *digits = hpd.get_digits(); hpd.shift(1); // shift left 1, equal to multiplying by 2. EXPECT_EQ(digits[0], uint8_t(2)); - EXPECT_EQ(hpd.getNumDigits(), 1u); - EXPECT_EQ(hpd.getDecimalPoint(), 1); + EXPECT_EQ(hpd.get_num_digits(), 1u); + EXPECT_EQ(hpd.get_decimal_point(), 1); } TEST(LlvmLibcHighPrecisionDecimalTest, SmallShift) { __llvm_libc::internal::HighPrecisionDecimal hpd = __llvm_libc::internal::HighPrecisionDecimal("1.2345"); - uint8_t *digits = hpd.getDigits(); + uint8_t *digits = hpd.get_digits(); hpd.shift(-1); // shift right one, equal to dividing by 2 // result should be 0.61725 @@ -49,8 +49,8 @@ EXPECT_EQ(digits[2], uint8_t(7)); EXPECT_EQ(digits[3], uint8_t(2)); EXPECT_EQ(digits[4], uint8_t(5)); - EXPECT_EQ(hpd.getNumDigits(), 5u); - EXPECT_EQ(hpd.getDecimalPoint(), 0); + EXPECT_EQ(hpd.get_num_digits(), 5u); + EXPECT_EQ(hpd.get_decimal_point(), 0); hpd.shift(1); // shift left one, equal to multiplying by 2 // result should be 1.2345 again @@ -60,8 +60,8 @@ EXPECT_EQ(digits[2], uint8_t(3)); EXPECT_EQ(digits[3], uint8_t(4)); EXPECT_EQ(digits[4], uint8_t(5)); - EXPECT_EQ(hpd.getNumDigits(), 5u); - EXPECT_EQ(hpd.getDecimalPoint(), 1); + EXPECT_EQ(hpd.get_num_digits(), 5u); + EXPECT_EQ(hpd.get_decimal_point(), 1); hpd.shift(1); // shift left one again // result should be 2.469 @@ -70,8 +70,8 @@ EXPECT_EQ(digits[1], uint8_t(4)); EXPECT_EQ(digits[2], uint8_t(6)); EXPECT_EQ(digits[3], uint8_t(9)); - EXPECT_EQ(hpd.getNumDigits(), 4u); - EXPECT_EQ(hpd.getDecimalPoint(), 1); + EXPECT_EQ(hpd.get_num_digits(), 4u); + EXPECT_EQ(hpd.get_decimal_point(), 1); hpd.shift(-1); // shift right one again // result should be 1.2345 again @@ -81,14 +81,14 @@ EXPECT_EQ(digits[2], uint8_t(3)); EXPECT_EQ(digits[3], uint8_t(4)); EXPECT_EQ(digits[4], uint8_t(5)); - EXPECT_EQ(hpd.getNumDigits(), 5u); - EXPECT_EQ(hpd.getDecimalPoint(), 1); + EXPECT_EQ(hpd.get_num_digits(), 5u); + EXPECT_EQ(hpd.get_decimal_point(), 1); } TEST(LlvmLibcHighPrecisionDecimalTest, MediumShift) { __llvm_libc::internal::HighPrecisionDecimal hpd = __llvm_libc::internal::HighPrecisionDecimal(".299792458"); - uint8_t *digits = hpd.getDigits(); + uint8_t *digits = hpd.get_digits(); hpd.shift(-3); // shift right three, equal to dividing by 8 // result should be 0.03747405725 @@ -103,8 +103,8 @@ EXPECT_EQ(digits[7], uint8_t(7)); EXPECT_EQ(digits[8], uint8_t(2)); EXPECT_EQ(digits[9], uint8_t(5)); - EXPECT_EQ(hpd.getNumDigits(), 10u); - EXPECT_EQ(hpd.getDecimalPoint(), -1); + EXPECT_EQ(hpd.get_num_digits(), 10u); + EXPECT_EQ(hpd.get_decimal_point(), -1); hpd.shift(3); // shift left three, equal to multiplying by 8 // result should be 0.299792458 again @@ -118,14 +118,14 @@ EXPECT_EQ(digits[6], uint8_t(4)); EXPECT_EQ(digits[7], uint8_t(5)); EXPECT_EQ(digits[8], uint8_t(8)); - EXPECT_EQ(hpd.getNumDigits(), 9u); - EXPECT_EQ(hpd.getDecimalPoint(), 0); + EXPECT_EQ(hpd.get_num_digits(), 9u); + EXPECT_EQ(hpd.get_decimal_point(), 0); } TEST(LlvmLibcHighPrecisionDecimalTest, BigShift) { __llvm_libc::internal::HighPrecisionDecimal hpd = __llvm_libc::internal::HighPrecisionDecimal(".299792458"); - uint8_t *digits = hpd.getDigits(); + uint8_t *digits = hpd.get_digits(); hpd.shift(-29); // shift right 29, equal to dividing by 536,870,912 // result should be 0.0000000005584069676697254180908203125 @@ -158,8 +158,8 @@ EXPECT_EQ(digits[25], uint8_t(1)); EXPECT_EQ(digits[26], uint8_t(2)); EXPECT_EQ(digits[27], uint8_t(5)); - EXPECT_EQ(hpd.getNumDigits(), 28u); - EXPECT_EQ(hpd.getDecimalPoint(), -9); + EXPECT_EQ(hpd.get_num_digits(), 28u); + EXPECT_EQ(hpd.get_decimal_point(), -9); hpd.shift(29); // shift left 29, equal to multiplying by 536,870,912 // result should be 0.299792458 again @@ -173,14 +173,14 @@ EXPECT_EQ(digits[6], uint8_t(4)); EXPECT_EQ(digits[7], uint8_t(5)); EXPECT_EQ(digits[8], uint8_t(8)); - EXPECT_EQ(hpd.getNumDigits(), 9u); - EXPECT_EQ(hpd.getDecimalPoint(), 0); + EXPECT_EQ(hpd.get_num_digits(), 9u); + EXPECT_EQ(hpd.get_decimal_point(), 0); } TEST(LlvmLibcHighPrecisionDecimalTest, BigShiftInSteps) { __llvm_libc::internal::HighPrecisionDecimal hpd = __llvm_libc::internal::HighPrecisionDecimal("1"); - uint8_t *digits = hpd.getDigits(); + uint8_t *digits = hpd.get_digits(); hpd.shift(60); // shift left 60, equal to multiplying by // 1152921504606846976. @@ -204,8 +204,8 @@ EXPECT_EQ(digits[16], uint8_t(9)); EXPECT_EQ(digits[17], uint8_t(7)); EXPECT_EQ(digits[18], uint8_t(6)); - EXPECT_EQ(hpd.getNumDigits(), 19u); - EXPECT_EQ(hpd.getDecimalPoint(), 19); + EXPECT_EQ(hpd.get_num_digits(), 19u); + EXPECT_EQ(hpd.get_decimal_point(), 19); hpd.shift(40); // shift left 40, equal to multiplying by // 1099511627776. Result should be 2^100 @@ -242,8 +242,8 @@ EXPECT_EQ(digits[29], uint8_t(7)); EXPECT_EQ(digits[30], uint8_t(6)); - EXPECT_EQ(hpd.getNumDigits(), 31u); - EXPECT_EQ(hpd.getDecimalPoint(), 31); + EXPECT_EQ(hpd.get_num_digits(), 31u); + EXPECT_EQ(hpd.get_decimal_point(), 31); hpd.shift(-60); // shift right 60, equal to dividing by // 1152921504606846976. Result should be 2^40 @@ -262,22 +262,22 @@ EXPECT_EQ(digits[11], uint8_t(7)); EXPECT_EQ(digits[12], uint8_t(6)); - EXPECT_EQ(hpd.getNumDigits(), 13u); - EXPECT_EQ(hpd.getDecimalPoint(), 13); + EXPECT_EQ(hpd.get_num_digits(), 13u); + EXPECT_EQ(hpd.get_decimal_point(), 13); hpd.shift(-40); // shift right 40, equal to dividing by // 1099511627776. Result should be 1 EXPECT_EQ(digits[0], uint8_t(1)); - EXPECT_EQ(hpd.getNumDigits(), 1u); - EXPECT_EQ(hpd.getDecimalPoint(), 1); + EXPECT_EQ(hpd.get_num_digits(), 1u); + EXPECT_EQ(hpd.get_decimal_point(), 1); } TEST(LlvmLibcHighPrecisionDecimalTest, VeryBigShift) { __llvm_libc::internal::HighPrecisionDecimal hpd = __llvm_libc::internal::HighPrecisionDecimal("1"); - uint8_t *digits = hpd.getDigits(); + uint8_t *digits = hpd.get_digits(); hpd.shift(100); // shift left 100, equal to multiplying by // 1267650600228229401496703205376. @@ -315,52 +315,52 @@ EXPECT_EQ(digits[29], uint8_t(7)); EXPECT_EQ(digits[30], uint8_t(6)); - EXPECT_EQ(hpd.getNumDigits(), 31u); - EXPECT_EQ(hpd.getDecimalPoint(), 31); + EXPECT_EQ(hpd.get_num_digits(), 31u); + EXPECT_EQ(hpd.get_decimal_point(), 31); hpd.shift(-100); // shift right 100, equal to dividing by // 1267650600228229401496703205376. // result should be 1 EXPECT_EQ(digits[0], uint8_t(1)); - EXPECT_EQ(hpd.getNumDigits(), 1u); - EXPECT_EQ(hpd.getDecimalPoint(), 1); + EXPECT_EQ(hpd.get_num_digits(), 1u); + EXPECT_EQ(hpd.get_decimal_point(), 1); } TEST(LlvmLibcHighPrecisionDecimalTest, RoundingTest) { __llvm_libc::internal::HighPrecisionDecimal hpd = __llvm_libc::internal::HighPrecisionDecimal("1.2345"); - EXPECT_EQ(hpd.roundToIntegerType(), uint32_t(1)); - EXPECT_EQ(hpd.roundToIntegerType(), uint64_t(1)); - EXPECT_EQ(hpd.roundToIntegerType<__uint128_t>(), __uint128_t(1)); + EXPECT_EQ(hpd.round_to_integer_type(), uint32_t(1)); + EXPECT_EQ(hpd.round_to_integer_type(), uint64_t(1)); + EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), __uint128_t(1)); hpd.shift(1); // shift left 1 to get 2.469 (rounds to 2) - EXPECT_EQ(hpd.roundToIntegerType(), uint32_t(2)); - EXPECT_EQ(hpd.roundToIntegerType(), uint64_t(2)); - EXPECT_EQ(hpd.roundToIntegerType<__uint128_t>(), __uint128_t(2)); + EXPECT_EQ(hpd.round_to_integer_type(), uint32_t(2)); + EXPECT_EQ(hpd.round_to_integer_type(), uint64_t(2)); + EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), __uint128_t(2)); hpd.shift(1); // shift left 1 to get 4.938 (rounds to 5) - EXPECT_EQ(hpd.roundToIntegerType(), uint32_t(5)); - EXPECT_EQ(hpd.roundToIntegerType(), uint64_t(5)); - EXPECT_EQ(hpd.roundToIntegerType<__uint128_t>(), __uint128_t(5)); + EXPECT_EQ(hpd.round_to_integer_type(), uint32_t(5)); + EXPECT_EQ(hpd.round_to_integer_type(), uint64_t(5)); + EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), __uint128_t(5)); // 2.5 is right between two integers, so we round to even (2) hpd = __llvm_libc::internal::HighPrecisionDecimal("2.5"); - EXPECT_EQ(hpd.roundToIntegerType(), uint32_t(2)); - EXPECT_EQ(hpd.roundToIntegerType(), uint64_t(2)); - EXPECT_EQ(hpd.roundToIntegerType<__uint128_t>(), __uint128_t(2)); + EXPECT_EQ(hpd.round_to_integer_type(), uint32_t(2)); + EXPECT_EQ(hpd.round_to_integer_type(), uint64_t(2)); + EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), __uint128_t(2)); // unless it's marked as having truncated, which means it's actually slightly // higher, forcing a round up (3) - hpd.setTruncated(true); + hpd.set_truncated(true); - EXPECT_EQ(hpd.roundToIntegerType(), uint32_t(3)); - EXPECT_EQ(hpd.roundToIntegerType(), uint64_t(3)); - EXPECT_EQ(hpd.roundToIntegerType<__uint128_t>(), __uint128_t(3)); + EXPECT_EQ(hpd.round_to_integer_type(), uint32_t(3)); + EXPECT_EQ(hpd.round_to_integer_type(), uint64_t(3)); + EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), __uint128_t(3)); // Check that the larger int types are being handled properly (overflow is not // handled, so int types that are too small are ignored for this test.) @@ -368,8 +368,9 @@ // 1099511627776 = 2^40 hpd = __llvm_libc::internal::HighPrecisionDecimal("1099511627776"); - EXPECT_EQ(hpd.roundToIntegerType(), uint64_t(1099511627776)); - EXPECT_EQ(hpd.roundToIntegerType<__uint128_t>(), __uint128_t(1099511627776)); + EXPECT_EQ(hpd.round_to_integer_type(), uint64_t(1099511627776)); + EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), + __uint128_t(1099511627776)); // 1267650600228229401496703205376 = 2^100 hpd = __llvm_libc::internal::HighPrecisionDecimal( @@ -377,5 +378,5 @@ __uint128_t result = __uint128_t(1) << 100; - EXPECT_EQ(hpd.roundToIntegerType<__uint128_t>(), result); + EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), result); } diff --git a/libc/test/src/__support/str_to_float_test.cpp b/libc/test/src/__support/str_to_float_test.cpp --- a/libc/test/src/__support/str_to_float_test.cpp +++ b/libc/test/src/__support/str_to_float_test.cpp @@ -23,7 +23,7 @@ typename __llvm_libc::fputil::FPBits::UIntType actualOutputMantissa = 0; uint32_t actualOutputExp2 = 0; - ASSERT_TRUE(__llvm_libc::internal::clingerFastPath( + ASSERT_TRUE(__llvm_libc::internal::clinger_fast_path( inputMantissa, inputExp10, &actualOutputMantissa, &actualOutputExp2)); EXPECT_EQ(actualOutputMantissa, expectedOutputMantissa); EXPECT_EQ(actualOutputExp2, expectedOutputExp2); @@ -36,7 +36,7 @@ typename __llvm_libc::fputil::FPBits::UIntType actualOutputMantissa = 0; uint32_t actualOutputExp2 = 0; - ASSERT_FALSE(__llvm_libc::internal::clingerFastPath( + ASSERT_FALSE(__llvm_libc::internal::clinger_fast_path( inputMantissa, inputExp10, &actualOutputMantissa, &actualOutputExp2)); } @@ -50,7 +50,7 @@ typename __llvm_libc::fputil::FPBits::UIntType actualOutputMantissa = 0; uint32_t actualOutputExp2 = 0; - ASSERT_TRUE(__llvm_libc::internal::eiselLemire( + ASSERT_TRUE(__llvm_libc::internal::eisel_lemire( inputMantissa, inputExp10, &actualOutputMantissa, &actualOutputExp2)); EXPECT_EQ(actualOutputMantissa, expectedOutputMantissa); EXPECT_EQ(actualOutputExp2, expectedOutputExp2); @@ -66,7 +66,7 @@ uint32_t actualOutputExp2 = 0; errno = 0; - __llvm_libc::internal::simpleDecimalConversion( + __llvm_libc::internal::simple_decimal_conversion( numStart, &actualOutputMantissa, &actualOutputExp2); EXPECT_EQ(actualOutputMantissa, expectedOutputMantissa); EXPECT_EQ(actualOutputExp2, expectedOutputExp2); @@ -77,38 +77,38 @@ TEST(LlvmLibcStrToFloatTest, LeadingZeroes) { uint64_t testNum64 = 1; uint32_t numOfZeroes = 63; - EXPECT_EQ(__llvm_libc::internal::leadingZeroes(0), 64u); + EXPECT_EQ(__llvm_libc::internal::leading_zeroes(0), 64u); for (; numOfZeroes < 64; testNum64 <<= 1, numOfZeroes--) { - EXPECT_EQ(__llvm_libc::internal::leadingZeroes(testNum64), + EXPECT_EQ(__llvm_libc::internal::leading_zeroes(testNum64), numOfZeroes); } testNum64 = 3; numOfZeroes = 62; for (; numOfZeroes > 63; testNum64 <<= 1, numOfZeroes--) { - EXPECT_EQ(__llvm_libc::internal::leadingZeroes(testNum64), + EXPECT_EQ(__llvm_libc::internal::leading_zeroes(testNum64), numOfZeroes); } - EXPECT_EQ(__llvm_libc::internal::leadingZeroes(0xffffffffffffffff), + EXPECT_EQ(__llvm_libc::internal::leading_zeroes(0xffffffffffffffff), 0u); testNum64 = 1; numOfZeroes = 63; for (; numOfZeroes > 63; testNum64 = (testNum64 << 1) + 1, numOfZeroes--) { - EXPECT_EQ(__llvm_libc::internal::leadingZeroes(testNum64), + EXPECT_EQ(__llvm_libc::internal::leading_zeroes(testNum64), numOfZeroes); } uint64_t testNum32 = 1; numOfZeroes = 31; - EXPECT_EQ(__llvm_libc::internal::leadingZeroes(0), 32u); + EXPECT_EQ(__llvm_libc::internal::leading_zeroes(0), 32u); for (; numOfZeroes < 32; testNum32 <<= 1, numOfZeroes--) { - EXPECT_EQ(__llvm_libc::internal::leadingZeroes(testNum32), + EXPECT_EQ(__llvm_libc::internal::leading_zeroes(testNum32), numOfZeroes); } - EXPECT_EQ(__llvm_libc::internal::leadingZeroes(0xffffffff), 0u); + EXPECT_EQ(__llvm_libc::internal::leading_zeroes(0xffffffff), 0u); } TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat64Simple) { @@ -171,16 +171,16 @@ uint32_t outputExp2 = 0; // This Eisel-Lemire implementation doesn't support long doubles yet. - ASSERT_FALSE(__llvm_libc::internal::eiselLemire( + ASSERT_FALSE(__llvm_libc::internal::eisel_lemire( tooLongMantissa, 0, &tooLongMantissa, &outputExp2)); // This number can't be evaluated by Eisel-Lemire since it's exactly 1024 away // from both of its closest floating point approximations // (12345678901234548736 and 12345678901234550784) - ASSERT_FALSE(__llvm_libc::internal::eiselLemire( + ASSERT_FALSE(__llvm_libc::internal::eisel_lemire( 12345678901234549760u, 0, &doubleOutputMantissa, &outputExp2)); - ASSERT_FALSE(__llvm_libc::internal::eiselLemire( + ASSERT_FALSE(__llvm_libc::internal::eisel_lemire( 20040229, 0, &floatOutputMantissa, &outputExp2)); } @@ -236,7 +236,7 @@ uint32_t outputExp2 = 0; errno = 0; - __llvm_libc::internal::simpleDecimalConversion( + __llvm_libc::internal::simple_decimal_conversion( "123456789012345678900", &floatOutputMantissa, &outputExp2); EXPECT_EQ(floatOutputMantissa, uint32_t(0xd629d4)); EXPECT_EQ(outputExp2, uint32_t(193)); @@ -246,7 +246,7 @@ outputExp2 = 0; errno = 0; - __llvm_libc::internal::simpleDecimalConversion( + __llvm_libc::internal::simple_decimal_conversion( "123456789012345678900", &doubleOutputMantissa, &outputExp2); EXPECT_EQ(doubleOutputMantissa, uint64_t(0x1AC53A7E04BCDA)); EXPECT_EQ(outputExp2, uint32_t(1089)); @@ -258,7 +258,7 @@ // outputExp2 = 0; // errno = 0; - // __llvm_libc::internal::simpleDecimalConversion( + // __llvm_libc::internal::simple_decimal_conversion( // "123456789012345678900", &longDoubleOutputMantissa, &outputExp2); // EXPECT_EQ(longDoubleOutputMantissa, __uint128_t(0x1AC53A7E04BCDA)); // EXPECT_EQ(outputExp2, uint32_t(1089)); diff --git a/libc/test/src/fenv/enabled_exceptions_test.cpp b/libc/test/src/fenv/enabled_exceptions_test.cpp --- a/libc/test/src/fenv/enabled_exceptions_test.cpp +++ b/libc/test/src/fenv/enabled_exceptions_test.cpp @@ -29,9 +29,9 @@ // exception and reading back to see if the exception got enabled. If the // exception did not get enabled, then it means that the HW does not support // trapping exceptions. - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); - __llvm_libc::fputil::enableExcept(FE_DIVBYZERO); - if (__llvm_libc::fputil::getExcept() == 0) + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); + __llvm_libc::fputil::enable_except(FE_DIVBYZERO); + if (__llvm_libc::fputil::get_except() == 0) return; #endif // defined(LLVM_LIBC_ARCH_AARCH64) @@ -50,8 +50,8 @@ FE_DIVBYZERO | FE_INVALID | FE_INEXACT | FE_OVERFLOW | FE_UNDERFLOW; for (int e : excepts) { - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); - __llvm_libc::fputil::enableExcept(e); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); + __llvm_libc::fputil::enable_except(e); ASSERT_EQ(__llvm_libc::feclearexcept(FE_ALL_EXCEPT), 0); // Raising all exceptions except |e| should not call the // SIGFPE handler. They should set the exception flag though, @@ -69,12 +69,12 @@ // a death test which runs this closure in a different thread. So, // we enable the exception again inside this closure so that the // exception gets enabled for the thread running this closure. - __llvm_libc::fputil::enableExcept(e); + __llvm_libc::fputil::enable_except(e); __llvm_libc::feraiseexcept(e); }); // Cleanup. - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); ASSERT_EQ(__llvm_libc::feclearexcept(FE_ALL_EXCEPT), 0); } } diff --git a/libc/test/src/fenv/exception_flags_test.cpp b/libc/test/src/fenv/exception_flags_test.cpp --- a/libc/test/src/fenv/exception_flags_test.cpp +++ b/libc/test/src/fenv/exception_flags_test.cpp @@ -17,8 +17,8 @@ TEST(LlvmLibcFenvTest, GetExceptFlagAndSetExceptFlag) { // We will disable all exceptions to prevent invocation of the exception // handler. - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); - __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW, FE_UNDERFLOW}; @@ -27,32 +27,32 @@ // The overall idea is to raise an except and save the exception flags. // Next, clear the flags and then set the saved exception flags. This // should set the flag corresponding to the previously raised exception. - __llvm_libc::fputil::raiseExcept(e); + __llvm_libc::fputil::raise_except(e); // Make sure that the exception flag is set. - ASSERT_NE(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT) & e, 0); + ASSERT_NE(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT) & e, 0); fexcept_t eflags; ASSERT_EQ(__llvm_libc::fegetexceptflag(&eflags, FE_ALL_EXCEPT), 0); - __llvm_libc::fputil::clearExcept(e); - ASSERT_EQ(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT) & e, 0); + __llvm_libc::fputil::clear_except(e); + ASSERT_EQ(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT) & e, 0); ASSERT_EQ(__llvm_libc::fesetexceptflag(&eflags, FE_ALL_EXCEPT), 0); - ASSERT_NE(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT) & e, 0); + ASSERT_NE(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT) & e, 0); // Cleanup. We clear all excepts as raising excepts like FE_OVERFLOW // can also raise FE_INEXACT. - __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); } // Next, we will raise one exception and save the flags. - __llvm_libc::fputil::raiseExcept(FE_INVALID); + __llvm_libc::fputil::raise_except(FE_INVALID); fexcept_t eflags; __llvm_libc::fegetexceptflag(&eflags, FE_ALL_EXCEPT); // Clear all exceptions and raise two other exceptions. - __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT); - __llvm_libc::fputil::raiseExcept(FE_OVERFLOW | FE_INEXACT); + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); + __llvm_libc::fputil::raise_except(FE_OVERFLOW | FE_INEXACT); // When we set the flags and test, we should only see FE_INVALID. __llvm_libc::fesetexceptflag(&eflags, FE_ALL_EXCEPT); - EXPECT_EQ(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT), FE_INVALID); + EXPECT_EQ(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT), FE_INVALID); } diff --git a/libc/test/src/fenv/exception_status_test.cpp b/libc/test/src/fenv/exception_status_test.cpp --- a/libc/test/src/fenv/exception_status_test.cpp +++ b/libc/test/src/fenv/exception_status_test.cpp @@ -20,7 +20,7 @@ // status flags are updated. The intention is really not to invoke the // exception handler. Hence, we will disable all exceptions at the // beginning. - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW, FE_UNDERFLOW}; diff --git a/libc/test/src/fenv/feclearexcept_test.cpp b/libc/test/src/fenv/feclearexcept_test.cpp --- a/libc/test/src/fenv/feclearexcept_test.cpp +++ b/libc/test/src/fenv/feclearexcept_test.cpp @@ -17,28 +17,28 @@ TEST(LlvmLibcFEnvTest, ClearTest) { uint16_t excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW, FE_UNDERFLOW}; - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); - __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); for (uint16_t e : excepts) - ASSERT_EQ(__llvm_libc::fputil::testExcept(e), 0); + ASSERT_EQ(__llvm_libc::fputil::test_except(e), 0); - __llvm_libc::fputil::raiseExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::raise_except(FE_ALL_EXCEPT); for (uint16_t e : excepts) { // We clear one exception and test to verify that it was cleared. __llvm_libc::feclearexcept(e); - ASSERT_EQ(uint16_t(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT)), + ASSERT_EQ(uint16_t(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT)), uint16_t(FE_ALL_EXCEPT & ~e)); // After clearing, we raise the exception again. - __llvm_libc::fputil::raiseExcept(e); + __llvm_libc::fputil::raise_except(e); } for (uint16_t e1 : excepts) { for (uint16_t e2 : excepts) { __llvm_libc::feclearexcept(e1 | e2); - ASSERT_EQ(uint16_t(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT)), + ASSERT_EQ(uint16_t(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT)), uint16_t(FE_ALL_EXCEPT & ~(e1 | e2))); - __llvm_libc::fputil::raiseExcept(e1 | e2); + __llvm_libc::fputil::raise_except(e1 | e2); } } @@ -46,9 +46,9 @@ for (uint16_t e2 : excepts) { for (uint16_t e3 : excepts) { __llvm_libc::feclearexcept(e1 | e2 | e3); - ASSERT_EQ(uint16_t(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT)), + ASSERT_EQ(uint16_t(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT)), uint16_t(FE_ALL_EXCEPT & ~(e1 | e2 | e3))); - __llvm_libc::fputil::raiseExcept(e1 | e2 | e3); + __llvm_libc::fputil::raise_except(e1 | e2 | e3); } } } @@ -58,9 +58,9 @@ for (uint16_t e3 : excepts) { for (uint16_t e4 : excepts) { __llvm_libc::feclearexcept(e1 | e2 | e3 | e4); - ASSERT_EQ(uint16_t(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT)), + ASSERT_EQ(uint16_t(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT)), uint16_t(FE_ALL_EXCEPT & ~(e1 | e2 | e3 | e4))); - __llvm_libc::fputil::raiseExcept(e1 | e2 | e3 | e4); + __llvm_libc::fputil::raise_except(e1 | e2 | e3 | e4); } } } @@ -72,9 +72,9 @@ for (uint16_t e4 : excepts) { for (uint16_t e5 : excepts) { __llvm_libc::feclearexcept(e1 | e2 | e3 | e4 | e5); - ASSERT_EQ(uint16_t(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT)), + ASSERT_EQ(uint16_t(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT)), uint16_t(FE_ALL_EXCEPT & ~(e1 | e2 | e3 | e4 | e5))); - __llvm_libc::fputil::raiseExcept(e1 | e2 | e3 | e4 | e5); + __llvm_libc::fputil::raise_except(e1 | e2 | e3 | e4 | e5); } } } diff --git a/libc/test/src/fenv/feholdexcept_test.cpp b/libc/test/src/fenv/feholdexcept_test.cpp --- a/libc/test/src/fenv/feholdexcept_test.cpp +++ b/libc/test/src/fenv/feholdexcept_test.cpp @@ -24,9 +24,9 @@ // exception and reading back to see if the exception got enabled. If the // exception did not get enabled, then it means that the HW does not support // trapping exceptions. - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); - __llvm_libc::fputil::enableExcept(FE_DIVBYZERO); - if (__llvm_libc::fputil::getExcept() == 0) + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); + __llvm_libc::fputil::enable_except(FE_DIVBYZERO); + if (__llvm_libc::fputil::get_except() == 0) return; #endif // defined(LLVM_LIBC_ARCH_AARCH64) @@ -35,13 +35,13 @@ for (int e : excepts) { fenv_t env; - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); - __llvm_libc::fputil::enableExcept(e); - ASSERT_EQ(__llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT), 0); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); + __llvm_libc::fputil::enable_except(e); + ASSERT_EQ(__llvm_libc::fputil::clear_except(FE_ALL_EXCEPT), 0); ASSERT_EQ(__llvm_libc::feholdexcept(&env), 0); // feholdexcept should disable all excepts so raising an exception // should not crash/invoke the exception handler. - ASSERT_EQ(__llvm_libc::fputil::raiseExcept(e), 0); + ASSERT_EQ(__llvm_libc::fputil::raise_except(e), 0); ASSERT_RAISES_FP_EXCEPT([=] { // When we put back the saved env, which has the exception enabled, it @@ -51,12 +51,12 @@ // run in a different thread. So, we set the old environment inside // this closure so that the exception gets enabled for the thread running // this closure. - __llvm_libc::fputil::setEnv(&env); - __llvm_libc::fputil::raiseExcept(e); + __llvm_libc::fputil::set_env(&env); + __llvm_libc::fputil::raise_except(e); }); // Cleanup - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); - ASSERT_EQ(__llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT), 0); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); + ASSERT_EQ(__llvm_libc::fputil::clear_except(FE_ALL_EXCEPT), 0); } } diff --git a/libc/test/src/fenv/feupdateenv_test.cpp b/libc/test/src/fenv/feupdateenv_test.cpp --- a/libc/test/src/fenv/feupdateenv_test.cpp +++ b/libc/test/src/fenv/feupdateenv_test.cpp @@ -15,13 +15,13 @@ #include TEST(LlvmLibcFEnvTest, UpdateEnvTest) { - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); - __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); fenv_t env; - ASSERT_EQ(__llvm_libc::fputil::getEnv(&env), 0); - __llvm_libc::fputil::setExcept(FE_INVALID | FE_INEXACT); + ASSERT_EQ(__llvm_libc::fputil::get_env(&env), 0); + __llvm_libc::fputil::set_except(FE_INVALID | FE_INEXACT); ASSERT_EQ(__llvm_libc::feupdateenv(&env), 0); - ASSERT_EQ(__llvm_libc::fputil::testExcept(FE_INVALID | FE_INEXACT), + ASSERT_EQ(__llvm_libc::fputil::test_except(FE_INVALID | FE_INEXACT), FE_INVALID | FE_INEXACT); } diff --git a/libc/test/src/fenv/getenv_and_setenv_test.cpp b/libc/test/src/fenv/getenv_and_setenv_test.cpp --- a/libc/test/src/fenv/getenv_and_setenv_test.cpp +++ b/libc/test/src/fenv/getenv_and_setenv_test.cpp @@ -19,49 +19,49 @@ TEST(LlvmLibcFenvTest, GetEnvAndSetEnv) { // We will disable all exceptions to prevent invocation of the exception // handler. - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW, FE_UNDERFLOW}; for (int e : excepts) { - __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); // Save the cleared environment. fenv_t env; ASSERT_EQ(__llvm_libc::fegetenv(&env), 0); - __llvm_libc::fputil::raiseExcept(e); + __llvm_libc::fputil::raise_except(e); // Make sure that the exception is raised. - ASSERT_NE(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT) & e, 0); + ASSERT_NE(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT) & e, 0); ASSERT_EQ(__llvm_libc::fesetenv(&env), 0); - ASSERT_EQ(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT) & e, 0); + ASSERT_EQ(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT) & e, 0); } } TEST(LlvmLibcFenvTest, Set_FE_DFL_ENV) { // We will disable all exceptions to prevent invocation of the exception // handler. - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW, FE_UNDERFLOW}; for (int e : excepts) { - __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); // Save the cleared environment. fenv_t env; ASSERT_EQ(__llvm_libc::fegetenv(&env), 0); - __llvm_libc::fputil::raiseExcept(e); + __llvm_libc::fputil::raise_except(e); // Make sure that the exception is raised. - ASSERT_NE(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT) & e, 0); + ASSERT_NE(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT) & e, 0); ASSERT_EQ(__llvm_libc::fesetenv(FE_DFL_ENV), 0); // Setting the default env should clear all exceptions. - ASSERT_EQ(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT) & e, 0); + ASSERT_EQ(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT) & e, 0); } ASSERT_EQ(__llvm_libc::fesetround(FE_DOWNWARD), 0); diff --git a/libc/test/src/math/CeilTest.h b/libc/test/src/math/CeilTest.h --- a/libc/test/src/math/CeilTest.h +++ b/libc/test/src/math/CeilTest.h @@ -23,10 +23,10 @@ void testSpecialNumbers(CeilFunc func) { EXPECT_FP_EQ(zero, func(zero)); - EXPECT_FP_EQ(negZero, func(negZero)); + EXPECT_FP_EQ(neg_zero, func(neg_zero)); EXPECT_FP_EQ(inf, func(inf)); - EXPECT_FP_EQ(negInf, func(negInf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf)); EXPECT_FP_EQ(aNaN, func(aNaN)); } diff --git a/libc/test/src/math/CopySignTest.h b/libc/test/src/math/CopySignTest.h --- a/libc/test/src/math/CopySignTest.h +++ b/libc/test/src/math/CopySignTest.h @@ -25,11 +25,11 @@ EXPECT_FP_EQ(aNaN, func(aNaN, -1.0)); EXPECT_FP_EQ(aNaN, func(aNaN, 1.0)); - EXPECT_FP_EQ(negInf, func(inf, -1.0)); - EXPECT_FP_EQ(inf, func(negInf, 1.0)); + EXPECT_FP_EQ(neg_inf, func(inf, -1.0)); + EXPECT_FP_EQ(inf, func(neg_inf, 1.0)); - EXPECT_FP_EQ(negZero, func(zero, -1.0)); - EXPECT_FP_EQ(zero, func(negZero, 1.0)); + EXPECT_FP_EQ(neg_zero, func(zero, -1.0)); + EXPECT_FP_EQ(zero, func(neg_zero, 1.0)); } void testRange(CopySignFunc func) { diff --git a/libc/test/src/math/FAbsTest.h b/libc/test/src/math/FAbsTest.h --- a/libc/test/src/math/FAbsTest.h +++ b/libc/test/src/math/FAbsTest.h @@ -25,10 +25,10 @@ EXPECT_FP_EQ(aNaN, func(aNaN)); EXPECT_FP_EQ(inf, func(inf)); - EXPECT_FP_EQ(inf, func(negInf)); + EXPECT_FP_EQ(inf, func(neg_inf)); EXPECT_FP_EQ(zero, func(zero)); - EXPECT_FP_EQ(zero, func(negZero)); + EXPECT_FP_EQ(zero, func(neg_zero)); } void testRange(FabsFunc func) { diff --git a/libc/test/src/math/FDimTest.h b/libc/test/src/math/FDimTest.h --- a/libc/test/src/math/FDimTest.h +++ b/libc/test/src/math/FDimTest.h @@ -21,35 +21,35 @@ void testNaNArg(FuncPtr func) { EXPECT_FP_EQ(nan, func(nan, inf)); - EXPECT_FP_EQ(nan, func(negInf, nan)); + EXPECT_FP_EQ(nan, func(neg_inf, nan)); EXPECT_FP_EQ(nan, func(nan, zero)); - EXPECT_FP_EQ(nan, func(negZero, nan)); + EXPECT_FP_EQ(nan, func(neg_zero, nan)); EXPECT_FP_EQ(nan, func(nan, T(-1.2345))); EXPECT_FP_EQ(nan, func(T(1.2345), nan)); EXPECT_FP_EQ(func(nan, nan), nan); } void testInfArg(FuncPtr func) { - EXPECT_FP_EQ(zero, func(negInf, inf)); + EXPECT_FP_EQ(zero, func(neg_inf, inf)); EXPECT_FP_EQ(inf, func(inf, zero)); - EXPECT_FP_EQ(zero, func(negZero, inf)); + EXPECT_FP_EQ(zero, func(neg_zero, inf)); EXPECT_FP_EQ(inf, func(inf, T(1.2345))); EXPECT_FP_EQ(zero, func(T(-1.2345), inf)); } void testNegInfArg(FuncPtr func) { - EXPECT_FP_EQ(inf, func(inf, negInf)); - EXPECT_FP_EQ(zero, func(negInf, zero)); - EXPECT_FP_EQ(inf, func(negZero, negInf)); - EXPECT_FP_EQ(zero, func(negInf, T(-1.2345))); - EXPECT_FP_EQ(inf, func(T(1.2345), negInf)); + EXPECT_FP_EQ(inf, func(inf, neg_inf)); + EXPECT_FP_EQ(zero, func(neg_inf, zero)); + EXPECT_FP_EQ(inf, func(neg_zero, neg_inf)); + EXPECT_FP_EQ(zero, func(neg_inf, T(-1.2345))); + EXPECT_FP_EQ(inf, func(T(1.2345), neg_inf)); } void testBothZero(FuncPtr func) { EXPECT_FP_EQ(zero, func(zero, zero)); - EXPECT_FP_EQ(zero, func(zero, negZero)); - EXPECT_FP_EQ(zero, func(negZero, zero)); - EXPECT_FP_EQ(zero, func(negZero, negZero)); + EXPECT_FP_EQ(zero, func(zero, neg_zero)); + EXPECT_FP_EQ(zero, func(neg_zero, zero)); + EXPECT_FP_EQ(zero, func(neg_zero, neg_zero)); } void testInRange(FuncPtr func) { @@ -74,9 +74,9 @@ private: // constexpr does not work on FPBits yet, so we cannot have these constants as // static. - const T nan = T(__llvm_libc::fputil::FPBits::buildNaN(1)); + const T nan = T(__llvm_libc::fputil::FPBits::build_nan(1)); const T inf = T(__llvm_libc::fputil::FPBits::inf()); - const T negInf = T(__llvm_libc::fputil::FPBits::negInf()); + const T neg_inf = T(__llvm_libc::fputil::FPBits::neg_inf()); const T zero = T(__llvm_libc::fputil::FPBits::zero()); - const T negZero = T(__llvm_libc::fputil::FPBits::negZero()); + const T neg_zero = T(__llvm_libc::fputil::FPBits::neg_zero()); }; diff --git a/libc/test/src/math/FMaxTest.h b/libc/test/src/math/FMaxTest.h --- a/libc/test/src/math/FMaxTest.h +++ b/libc/test/src/math/FMaxTest.h @@ -23,7 +23,7 @@ void testNaN(FMaxFunc func) { EXPECT_FP_EQ(inf, func(aNaN, inf)); - EXPECT_FP_EQ(negInf, func(negInf, aNaN)); + EXPECT_FP_EQ(neg_inf, func(neg_inf, aNaN)); EXPECT_FP_EQ(0.0, func(aNaN, 0.0)); EXPECT_FP_EQ(-0.0, func(-0.0, aNaN)); EXPECT_FP_EQ(T(-1.2345), func(aNaN, T(-1.2345))); @@ -32,7 +32,7 @@ } void testInfArg(FMaxFunc func) { - EXPECT_FP_EQ(inf, func(negInf, inf)); + EXPECT_FP_EQ(inf, func(neg_inf, inf)); EXPECT_FP_EQ(inf, func(inf, 0.0)); EXPECT_FP_EQ(inf, func(-0.0, inf)); EXPECT_FP_EQ(inf, func(inf, T(1.2345))); @@ -40,11 +40,11 @@ } void testNegInfArg(FMaxFunc func) { - EXPECT_FP_EQ(inf, func(inf, negInf)); - EXPECT_FP_EQ(0.0, func(negInf, 0.0)); - EXPECT_FP_EQ(-0.0, func(-0.0, negInf)); - EXPECT_FP_EQ(T(-1.2345), func(negInf, T(-1.2345))); - EXPECT_FP_EQ(T(1.2345), func(T(1.2345), negInf)); + EXPECT_FP_EQ(inf, func(inf, neg_inf)); + EXPECT_FP_EQ(0.0, func(neg_inf, 0.0)); + EXPECT_FP_EQ(-0.0, func(-0.0, neg_inf)); + EXPECT_FP_EQ(T(-1.2345), func(neg_inf, T(-1.2345))); + EXPECT_FP_EQ(T(1.2345), func(T(1.2345), neg_inf)); } void testBothZero(FMaxFunc func) { diff --git a/libc/test/src/math/FMinTest.h b/libc/test/src/math/FMinTest.h --- a/libc/test/src/math/FMinTest.h +++ b/libc/test/src/math/FMinTest.h @@ -23,7 +23,7 @@ void testNaN(FMinFunc func) { EXPECT_FP_EQ(inf, func(aNaN, inf)); - EXPECT_FP_EQ(negInf, func(negInf, aNaN)); + EXPECT_FP_EQ(neg_inf, func(neg_inf, aNaN)); EXPECT_FP_EQ(0.0, func(aNaN, 0.0)); EXPECT_FP_EQ(-0.0, func(-0.0, aNaN)); EXPECT_FP_EQ(T(-1.2345), func(aNaN, T(-1.2345))); @@ -32,7 +32,7 @@ } void testInfArg(FMinFunc func) { - EXPECT_FP_EQ(negInf, func(negInf, inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf, inf)); EXPECT_FP_EQ(0.0, func(inf, 0.0)); EXPECT_FP_EQ(-0.0, func(-0.0, inf)); EXPECT_FP_EQ(T(1.2345), func(inf, T(1.2345))); @@ -40,11 +40,11 @@ } void testNegInfArg(FMinFunc func) { - EXPECT_FP_EQ(negInf, func(inf, negInf)); - EXPECT_FP_EQ(negInf, func(negInf, 0.0)); - EXPECT_FP_EQ(negInf, func(-0.0, negInf)); - EXPECT_FP_EQ(negInf, func(negInf, T(-1.2345))); - EXPECT_FP_EQ(negInf, func(T(1.2345), negInf)); + EXPECT_FP_EQ(neg_inf, func(inf, neg_inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf, 0.0)); + EXPECT_FP_EQ(neg_inf, func(-0.0, neg_inf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf, T(-1.2345))); + EXPECT_FP_EQ(neg_inf, func(T(1.2345), neg_inf)); } void testBothZero(FMinFunc func) { diff --git a/libc/test/src/math/FloorTest.h b/libc/test/src/math/FloorTest.h --- a/libc/test/src/math/FloorTest.h +++ b/libc/test/src/math/FloorTest.h @@ -23,10 +23,10 @@ void testSpecialNumbers(FloorFunc func) { EXPECT_FP_EQ(zero, func(zero)); - EXPECT_FP_EQ(negZero, func(negZero)); + EXPECT_FP_EQ(neg_zero, func(neg_zero)); EXPECT_FP_EQ(inf, func(inf)); - EXPECT_FP_EQ(negInf, func(negInf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf)); EXPECT_FP_EQ(aNaN, func(aNaN)); } diff --git a/libc/test/src/math/FmaTest.h b/libc/test/src/math/FmaTest.h --- a/libc/test/src/math/FmaTest.h +++ b/libc/test/src/math/FmaTest.h @@ -23,11 +23,11 @@ using Func = T (*)(T, T, T); using FPBits = __llvm_libc::fputil::FPBits; using UIntType = typename FPBits::UIntType; - const T nan = T(__llvm_libc::fputil::FPBits::buildNaN(1)); + const T nan = T(__llvm_libc::fputil::FPBits::build_nan(1)); const T inf = T(__llvm_libc::fputil::FPBits::inf()); - const T negInf = T(__llvm_libc::fputil::FPBits::negInf()); + const T neg_inf = T(__llvm_libc::fputil::FPBits::neg_inf()); const T zero = T(__llvm_libc::fputil::FPBits::zero()); - const T negZero = T(__llvm_libc::fputil::FPBits::negZero()); + const T neg_zero = T(__llvm_libc::fputil::FPBits::neg_zero()); UIntType getRandomBitPattern() { UIntType bits{0}; @@ -41,34 +41,34 @@ public: void testSpecialNumbers(Func func) { EXPECT_FP_EQ(func(zero, zero, zero), zero); - EXPECT_FP_EQ(func(zero, negZero, negZero), negZero); + EXPECT_FP_EQ(func(zero, neg_zero, neg_zero), neg_zero); EXPECT_FP_EQ(func(inf, inf, zero), inf); - EXPECT_FP_EQ(func(negInf, inf, negInf), negInf); + EXPECT_FP_EQ(func(neg_inf, inf, neg_inf), neg_inf); EXPECT_FP_EQ(func(inf, zero, zero), nan); - EXPECT_FP_EQ(func(inf, negInf, inf), nan); + EXPECT_FP_EQ(func(inf, neg_inf, inf), nan); EXPECT_FP_EQ(func(nan, zero, inf), nan); - EXPECT_FP_EQ(func(inf, negInf, nan), nan); + EXPECT_FP_EQ(func(inf, neg_inf, nan), nan); // Test underflow rounding up. - EXPECT_FP_EQ(func(T(0.5), T(FPBits(FPBits::minSubnormal)), - T(FPBits(FPBits::minSubnormal))), + EXPECT_FP_EQ(func(T(0.5), T(FPBits(FPBits::MIN_SUBNORMAL)), + T(FPBits(FPBits::MIN_SUBNORMAL))), T(FPBits(UIntType(2)))); // Test underflow rounding down. - T v = T(FPBits(FPBits::minNormal + UIntType(1))); - EXPECT_FP_EQ( - func(T(1) / T(FPBits::minNormal << 1), v, T(FPBits(FPBits::minNormal))), - v); + T v = T(FPBits(FPBits::MIN_NORMAL + UIntType(1))); + EXPECT_FP_EQ(func(T(1) / T(FPBits::MIN_NORMAL << 1), v, + T(FPBits(FPBits::MIN_NORMAL))), + v); // Test overflow. - T z = T(FPBits(FPBits::maxNormal)); + T z = T(FPBits(FPBits::MAX_NORMAL)); EXPECT_FP_EQ(func(T(1.75), z, -z), T(0.75) * z); } void testSubnormalRange(Func func) { constexpr UIntType count = 1000001; constexpr UIntType step = - (FPBits::maxSubnormal - FPBits::minSubnormal) / count; - for (UIntType v = FPBits::minSubnormal, w = FPBits::maxSubnormal; - v <= FPBits::maxSubnormal && w >= FPBits::minSubnormal; + (FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count; + for (UIntType v = FPBits::MIN_SUBNORMAL, w = FPBits::MAX_SUBNORMAL; + v <= FPBits::MAX_SUBNORMAL && w >= FPBits::MIN_SUBNORMAL; v += step, w -= step) { T x = T(FPBits(getRandomBitPattern())), y = T(FPBits(v)), z = T(FPBits(w)); @@ -80,9 +80,9 @@ void testNormalRange(Func func) { constexpr UIntType count = 1000001; - constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count; - for (UIntType v = FPBits::minNormal, w = FPBits::maxNormal; - v <= FPBits::maxNormal && w >= FPBits::minNormal; + constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count; + for (UIntType v = FPBits::MIN_NORMAL, w = FPBits::MAX_NORMAL; + v <= FPBits::MAX_NORMAL && w >= FPBits::MIN_NORMAL; v += step, w -= step) { T x = T(FPBits(v)), y = T(FPBits(w)), z = T(FPBits(getRandomBitPattern())); diff --git a/libc/test/src/math/FrexpTest.h b/libc/test/src/math/FrexpTest.h --- a/libc/test/src/math/FrexpTest.h +++ b/libc/test/src/math/FrexpTest.h @@ -20,7 +20,7 @@ DECLARE_SPECIAL_CONSTANTS(T) static constexpr UIntType HiddenBit = - UIntType(1) << __llvm_libc::fputil::MantissaWidth::value; + UIntType(1) << __llvm_libc::fputil::MantissaWidth::VALUE; public: typedef T (*FrexpFunc)(T, int *); @@ -29,7 +29,7 @@ int exponent; ASSERT_FP_EQ(aNaN, func(aNaN, &exponent)); ASSERT_FP_EQ(inf, func(inf, &exponent)); - ASSERT_FP_EQ(negInf, func(negInf, &exponent)); + ASSERT_FP_EQ(neg_inf, func(neg_inf, &exponent)); ASSERT_FP_EQ(0.0, func(0.0, &exponent)); ASSERT_EQ(exponent, 0); diff --git a/libc/test/src/math/HypotTest.h b/libc/test/src/math/HypotTest.h --- a/libc/test/src/math/HypotTest.h +++ b/libc/test/src/math/HypotTest.h @@ -25,32 +25,32 @@ using Func = T (*)(T, T); using FPBits = __llvm_libc::fputil::FPBits; using UIntType = typename FPBits::UIntType; - const T nan = T(__llvm_libc::fputil::FPBits::buildNaN(1)); + const T nan = T(__llvm_libc::fputil::FPBits::build_nan(1)); const T inf = T(__llvm_libc::fputil::FPBits::inf()); - const T negInf = T(__llvm_libc::fputil::FPBits::negInf()); + const T neg_inf = T(__llvm_libc::fputil::FPBits::neg_inf()); const T zero = T(__llvm_libc::fputil::FPBits::zero()); - const T negZero = T(__llvm_libc::fputil::FPBits::negZero()); + const T neg_zero = T(__llvm_libc::fputil::FPBits::neg_zero()); public: void testSpecialNumbers(Func func) { EXPECT_FP_EQ(func(inf, nan), inf); - EXPECT_FP_EQ(func(nan, negInf), inf); + EXPECT_FP_EQ(func(nan, neg_inf), inf); EXPECT_FP_EQ(func(zero, inf), inf); - EXPECT_FP_EQ(func(negInf, negZero), inf); + EXPECT_FP_EQ(func(neg_inf, neg_zero), inf); EXPECT_FP_EQ(func(nan, nan), nan); EXPECT_FP_EQ(func(nan, zero), nan); - EXPECT_FP_EQ(func(negZero, nan), nan); + EXPECT_FP_EQ(func(neg_zero, nan), nan); - EXPECT_FP_EQ(func(negZero, zero), zero); + EXPECT_FP_EQ(func(neg_zero, zero), zero); } void testSubnormalRange(Func func) { constexpr UIntType count = 1000001; constexpr UIntType step = - (FPBits::maxSubnormal - FPBits::minSubnormal) / count; - for (UIntType v = FPBits::minSubnormal, w = FPBits::maxSubnormal; - v <= FPBits::maxSubnormal && w >= FPBits::minSubnormal; + (FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count; + for (UIntType v = FPBits::MIN_SUBNORMAL, w = FPBits::MAX_SUBNORMAL; + v <= FPBits::MAX_SUBNORMAL && w >= FPBits::MIN_SUBNORMAL; v += step, w -= step) { T x = T(FPBits(v)), y = T(FPBits(w)); T result = func(x, y); @@ -61,9 +61,9 @@ void testNormalRange(Func func) { constexpr UIntType count = 1000001; - constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count; - for (UIntType v = FPBits::minNormal, w = FPBits::maxNormal; - v <= FPBits::maxNormal && w >= FPBits::minNormal; + constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count; + for (UIntType v = FPBits::MIN_NORMAL, w = FPBits::MAX_NORMAL; + v <= FPBits::MAX_NORMAL && w >= FPBits::MIN_NORMAL; v += step, w -= step) { T x = T(FPBits(v)), y = T(FPBits(w)); T result = func(x, y); diff --git a/libc/test/src/math/ILogbTest.h b/libc/test/src/math/ILogbTest.h --- a/libc/test/src/math/ILogbTest.h +++ b/libc/test/src/math/ILogbTest.h @@ -23,13 +23,13 @@ template void testSpecialNumbers(typename ILogbFunc::Func func) { EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits::zero()))); - EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits::negZero()))); + EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits::neg_zero()))); EXPECT_EQ(FP_ILOGBNAN, - func(T(__llvm_libc::fputil::FPBits::buildNaN(1)))); + func(T(__llvm_libc::fputil::FPBits::build_nan(1)))); EXPECT_EQ(INT_MAX, func(T(__llvm_libc::fputil::FPBits::inf()))); - EXPECT_EQ(INT_MAX, func(T(__llvm_libc::fputil::FPBits::negInf()))); + EXPECT_EQ(INT_MAX, func(T(__llvm_libc::fputil::FPBits::neg_inf()))); } template void testPowersOfTwo(typename ILogbFunc::Func func) { @@ -76,8 +76,8 @@ using UIntType = typename FPBits::UIntType; constexpr UIntType count = 1000001; constexpr UIntType step = - (FPBits::maxSubnormal - FPBits::minSubnormal) / count; - for (UIntType v = FPBits::minSubnormal; v <= FPBits::maxSubnormal; + (FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count; + for (UIntType v = FPBits::MIN_SUBNORMAL; v <= FPBits::MAX_SUBNORMAL; v += step) { T x = T(FPBits(v)); if (isnan(x) || isinf(x) || x == 0.0) @@ -93,8 +93,8 @@ using FPBits = __llvm_libc::fputil::FPBits; using UIntType = typename FPBits::UIntType; constexpr UIntType count = 1000001; - constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count; - for (UIntType v = FPBits::minNormal; v <= FPBits::maxNormal; v += step) { + constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count; + for (UIntType v = FPBits::MIN_NORMAL; v <= FPBits::MAX_NORMAL; v += step) { T x = T(FPBits(v)); if (isnan(x) || isinf(x) || x == 0.0) continue; diff --git a/libc/test/src/math/LdExpTest.h b/libc/test/src/math/LdExpTest.h --- a/libc/test/src/math/LdExpTest.h +++ b/libc/test/src/math/LdExpTest.h @@ -24,15 +24,15 @@ using NormalFloat = __llvm_libc::fputil::NormalFloat; using UIntType = typename FPBits::UIntType; static constexpr UIntType mantissaWidth = - __llvm_libc::fputil::MantissaWidth::value; + __llvm_libc::fputil::MantissaWidth::VALUE; // A normalized mantissa to be used with tests. - static constexpr UIntType mantissa = NormalFloat::one + 0x1234; + static constexpr UIntType mantissa = NormalFloat::ONE + 0x1234; const T zero = T(__llvm_libc::fputil::FPBits::zero()); - const T negZero = T(__llvm_libc::fputil::FPBits::negZero()); + const T neg_zero = T(__llvm_libc::fputil::FPBits::neg_zero()); const T inf = T(__llvm_libc::fputil::FPBits::inf()); - const T negInf = T(__llvm_libc::fputil::FPBits::negInf()); - const T nan = T(__llvm_libc::fputil::FPBits::buildNaN(1)); + const T neg_inf = T(__llvm_libc::fputil::FPBits::neg_inf()); + const T nan = T(__llvm_libc::fputil::FPBits::build_nan(1)); public: typedef T (*LdExpFunc)(T, int); @@ -41,9 +41,9 @@ int expArray[5] = {-INT_MAX - 1, -10, 0, 10, INT_MAX}; for (int exp : expArray) { ASSERT_FP_EQ(zero, func(zero, exp)); - ASSERT_FP_EQ(negZero, func(negZero, exp)); + ASSERT_FP_EQ(neg_zero, func(neg_zero, exp)); ASSERT_FP_EQ(inf, func(inf, exp)); - ASSERT_FP_EQ(negInf, func(negInf, exp)); + ASSERT_FP_EQ(neg_inf, func(neg_inf, exp)); ASSERT_FP_EQ(nan, func(nan, exp)); } } @@ -60,34 +60,34 @@ } void testOverflow(LdExpFunc func) { - NormalFloat x(FPBits::maxExponent - 10, NormalFloat::one + 0xF00BA, 0); + NormalFloat x(FPBits::MAX_EXPONENT - 10, NormalFloat::ONE + 0xF00BA, 0); for (int32_t exp = 10; exp < 100; ++exp) { ASSERT_FP_EQ(inf, func(T(x), exp)); - ASSERT_FP_EQ(negInf, func(-T(x), exp)); + ASSERT_FP_EQ(neg_inf, func(-T(x), exp)); } } void testUnderflowToZeroOnNormal(LdExpFunc func) { // In this test, we pass a normal nubmer to func and expect zero // to be returned due to underflow. - int32_t baseExponent = FPBits::exponentBias + mantissaWidth; + int32_t baseExponent = FPBits::EXPONENT_BIAS + mantissaWidth; int32_t expArray[] = {baseExponent + 5, baseExponent + 4, baseExponent + 3, baseExponent + 2, baseExponent + 1}; T x = NormalFloat(0, mantissa, 0); for (int32_t exp : expArray) { - ASSERT_FP_EQ(func(x, -exp), x > 0 ? zero : negZero); + ASSERT_FP_EQ(func(x, -exp), x > 0 ? zero : neg_zero); } } void testUnderflowToZeroOnSubnormal(LdExpFunc func) { // In this test, we pass a normal nubmer to func and expect zero // to be returned due to underflow. - int32_t baseExponent = FPBits::exponentBias + mantissaWidth; + int32_t baseExponent = FPBits::EXPONENT_BIAS + mantissaWidth; int32_t expArray[] = {baseExponent + 5, baseExponent + 4, baseExponent + 3, baseExponent + 2, baseExponent + 1}; - T x = NormalFloat(-FPBits::exponentBias, mantissa, 0); + T x = NormalFloat(-FPBits::EXPONENT_BIAS, mantissa, 0); for (int32_t exp : expArray) { - ASSERT_FP_EQ(func(x, -exp), x > 0 ? zero : negZero); + ASSERT_FP_EQ(func(x, -exp), x > 0 ? zero : neg_zero); } } @@ -97,8 +97,8 @@ NormalFloat(100, mantissa, 0), NormalFloat(-100, mantissa, 0), NormalFloat(100, mantissa, 1), NormalFloat(-100, mantissa, 1), // Subnormal numbers - NormalFloat(-FPBits::exponentBias, mantissa, 0), - NormalFloat(-FPBits::exponentBias, mantissa, 1)}; + NormalFloat(-FPBits::EXPONENT_BIAS, mantissa, 0), + NormalFloat(-FPBits::EXPONENT_BIAS, mantissa, 1)}; for (int32_t exp = 0; exp <= static_cast(mantissaWidth); ++exp) { for (T x : valArray) { // We compare the result of ldexp with the result @@ -109,32 +109,32 @@ } // Normal which trigger mantissa overflow. - T x = NormalFloat(-FPBits::exponentBias + 1, 2 * NormalFloat::one - 1, 0); + T x = NormalFloat(-FPBits::EXPONENT_BIAS + 1, 2 * NormalFloat::ONE - 1, 0); ASSERT_FP_EQ(func(x, -1), x / 2); ASSERT_FP_EQ(func(-x, -1), -x / 2); // Start with a normal number high exponent but pass a very low number for // exp. The result should be a subnormal number. - x = NormalFloat(FPBits::exponentBias, NormalFloat::one, 0); - int exp = -FPBits::maxExponent - 5; + x = NormalFloat(FPBits::EXPONENT_BIAS, NormalFloat::ONE, 0); + int exp = -FPBits::MAX_EXPONENT - 5; T result = func(x, exp); FPBits resultBits(result); - ASSERT_FALSE(resultBits.isZero()); + ASSERT_FALSE(resultBits.is_zero()); // Verify that the result is indeed subnormal. - ASSERT_EQ(resultBits.getUnbiasedExponent(), uint16_t(0)); + ASSERT_EQ(resultBits.get_unbiased_exponent(), uint16_t(0)); // But if the exp is so less that normalization leads to zero, then // the result should be zero. - result = func(x, -FPBits::maxExponent - int(mantissaWidth) - 5); - ASSERT_TRUE(FPBits(result).isZero()); + result = func(x, -FPBits::MAX_EXPONENT - int(mantissaWidth) - 5); + ASSERT_TRUE(FPBits(result).is_zero()); // Start with a subnormal number but pass a very high number for exponent. // The result should not be infinity. - x = NormalFloat(-FPBits::exponentBias + 1, NormalFloat::one >> 10, 0); - exp = FPBits::maxExponent + 5; - ASSERT_FALSE(FPBits(func(x, exp)).isInf()); + x = NormalFloat(-FPBits::EXPONENT_BIAS + 1, NormalFloat::ONE >> 10, 0); + exp = FPBits::MAX_EXPONENT + 5; + ASSERT_FALSE(FPBits(func(x, exp)).is_inf()); // But if the exp is large enough to oversome than the normalization shift, // then it should result in infinity. - exp = FPBits::maxExponent + 15; + exp = FPBits::MAX_EXPONENT + 15; ASSERT_FP_EQ(func(x, exp), inf); } }; diff --git a/libc/test/src/math/LogbTest.h b/libc/test/src/math/LogbTest.h --- a/libc/test/src/math/LogbTest.h +++ b/libc/test/src/math/LogbTest.h @@ -20,7 +20,7 @@ DECLARE_SPECIAL_CONSTANTS(T) static constexpr UIntType HiddenBit = - UIntType(1) << __llvm_libc::fputil::MantissaWidth::value; + UIntType(1) << __llvm_libc::fputil::MantissaWidth::VALUE; public: typedef T (*LogbFunc)(T); @@ -28,9 +28,9 @@ void testSpecialNumbers(LogbFunc func) { ASSERT_FP_EQ(aNaN, func(aNaN)); ASSERT_FP_EQ(inf, func(inf)); - ASSERT_FP_EQ(inf, func(negInf)); - ASSERT_FP_EQ(negInf, func(0.0)); - ASSERT_FP_EQ(negInf, func(-0.0)); + ASSERT_FP_EQ(inf, func(neg_inf)); + ASSERT_FP_EQ(neg_inf, func(0.0)); + ASSERT_FP_EQ(neg_inf, func(-0.0)); } void testPowersOfTwo(LogbFunc func) { diff --git a/libc/test/src/math/ModfTest.h b/libc/test/src/math/ModfTest.h --- a/libc/test/src/math/ModfTest.h +++ b/libc/test/src/math/ModfTest.h @@ -28,13 +28,13 @@ EXPECT_FP_EQ(zero, func(zero, &integral)); EXPECT_FP_EQ(integral, zero); - EXPECT_FP_EQ(negZero, func(negZero, &integral)); - EXPECT_FP_EQ(integral, negZero); + EXPECT_FP_EQ(neg_zero, func(neg_zero, &integral)); + EXPECT_FP_EQ(integral, neg_zero); EXPECT_FP_EQ(zero, func(inf, &integral)); EXPECT_FP_EQ(inf, integral); - EXPECT_FP_EQ(negZero, func(negInf, &integral)); - EXPECT_FP_EQ(negInf, integral); + EXPECT_FP_EQ(neg_zero, func(neg_inf, &integral)); + EXPECT_FP_EQ(neg_inf, integral); EXPECT_FP_EQ(aNaN, func(aNaN, &integral)); } diff --git a/libc/test/src/math/NextAfterTest.h b/libc/test/src/math/NextAfterTest.h --- a/libc/test/src/math/NextAfterTest.h +++ b/libc/test/src/math/NextAfterTest.h @@ -23,17 +23,17 @@ using UIntType = typename FPBits::UIntType; static constexpr int bitWidthOfType = - __llvm_libc::fputil::FloatProperties::bitWidth; + __llvm_libc::fputil::FloatProperties::BIT_WIDTH; const T zero = T(FPBits::zero()); - const T negZero = T(FPBits::negZero()); + const T neg_zero = T(FPBits::neg_zero()); const T inf = T(FPBits::inf()); - const T negInf = T(FPBits::negInf()); - const T nan = T(FPBits::buildNaN(1)); - const UIntType minSubnormal = FPBits::minSubnormal; - const UIntType maxSubnormal = FPBits::maxSubnormal; - const UIntType minNormal = FPBits::minNormal; - const UIntType maxNormal = FPBits::maxNormal; + const T neg_inf = T(FPBits::neg_inf()); + const T nan = T(FPBits::build_nan(1)); + const UIntType MIN_SUBNORMAL = FPBits::MIN_SUBNORMAL; + const UIntType MAX_SUBNORMAL = FPBits::MAX_SUBNORMAL; + const UIntType MIN_NORMAL = FPBits::MIN_NORMAL; + const UIntType MAX_NORMAL = FPBits::MAX_NORMAL; public: typedef T (*NextAfterFunc)(T, T); @@ -44,10 +44,10 @@ } void testBoundaries(NextAfterFunc func) { - ASSERT_FP_EQ(func(zero, negZero), negZero); - ASSERT_FP_EQ(func(negZero, zero), zero); + ASSERT_FP_EQ(func(zero, neg_zero), neg_zero); + ASSERT_FP_EQ(func(neg_zero, zero), zero); - // 'from' is zero|negZero. + // 'from' is zero|neg_zero. T x = zero; T result = func(x, T(1)); UIntType expectedBits = 1; @@ -59,7 +59,7 @@ expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); - x = negZero; + x = neg_zero; result = func(x, 1); expectedBits = 1; expected = *reinterpret_cast(&expectedBits); @@ -71,68 +71,68 @@ ASSERT_FP_EQ(result, expected); // 'from' is max subnormal value. - x = *reinterpret_cast(&maxSubnormal); + x = *reinterpret_cast(&MAX_SUBNORMAL); result = func(x, 1); - expected = *reinterpret_cast(&minNormal); + expected = *reinterpret_cast(&MIN_NORMAL); ASSERT_FP_EQ(result, expected); result = func(x, 0); - expectedBits = maxSubnormal - 1; + expectedBits = MAX_SUBNORMAL - 1; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); x = -x; result = func(x, -1); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + minNormal; + expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MIN_NORMAL; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); result = func(x, 0); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + maxSubnormal - 1; + expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MAX_SUBNORMAL - 1; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); // 'from' is min subnormal value. - x = *reinterpret_cast(&minSubnormal); + x = *reinterpret_cast(&MIN_SUBNORMAL); result = func(x, 1); - expectedBits = minSubnormal + 1; + expectedBits = MIN_SUBNORMAL + 1; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); ASSERT_FP_EQ(func(x, 0), 0); x = -x; result = func(x, -1); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + minSubnormal + 1; + expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MIN_SUBNORMAL + 1; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); ASSERT_FP_EQ(func(x, 0), T(-0.0)); // 'from' is min normal. - x = *reinterpret_cast(&minNormal); + x = *reinterpret_cast(&MIN_NORMAL); result = func(x, 0); - expectedBits = maxSubnormal; + expectedBits = MAX_SUBNORMAL; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); result = func(x, inf); - expectedBits = minNormal + 1; + expectedBits = MIN_NORMAL + 1; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); x = -x; result = func(x, 0); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + maxSubnormal; + expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MAX_SUBNORMAL; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); result = func(x, -inf); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + minNormal + 1; + expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MIN_NORMAL + 1; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); // 'from' is max normal and 'to' is infinity. - x = *reinterpret_cast(&maxNormal); + x = *reinterpret_cast(&MAX_NORMAL); result = func(x, inf); ASSERT_FP_EQ(result, inf); @@ -142,46 +142,48 @@ // 'from' is infinity. x = inf; result = func(x, 0); - expectedBits = maxNormal; + expectedBits = MAX_NORMAL; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); ASSERT_FP_EQ(func(x, inf), inf); - x = negInf; + x = neg_inf; result = func(x, 0); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + maxNormal; + expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MAX_NORMAL; expected = *reinterpret_cast(&expectedBits); ASSERT_FP_EQ(result, expected); - ASSERT_FP_EQ(func(x, negInf), negInf); + ASSERT_FP_EQ(func(x, neg_inf), neg_inf); // 'from' is a power of 2. x = T(32.0); result = func(x, 0); FPBits xBits = FPBits(x); FPBits resultBits = FPBits(result); - ASSERT_EQ(resultBits.getUnbiasedExponent(), - uint16_t(xBits.getUnbiasedExponent() - 1)); - ASSERT_EQ(resultBits.getMantissa(), - (UIntType(1) << MantissaWidth::value) - 1); + ASSERT_EQ(resultBits.get_unbiased_exponent(), + uint16_t(xBits.get_unbiased_exponent() - 1)); + ASSERT_EQ(resultBits.get_mantissa(), + (UIntType(1) << MantissaWidth::VALUE) - 1); result = func(x, T(33.0)); resultBits = FPBits(result); - ASSERT_EQ(resultBits.getUnbiasedExponent(), xBits.getUnbiasedExponent()); - ASSERT_EQ(resultBits.getMantissa(), xBits.getMantissa() + UIntType(1)); + ASSERT_EQ(resultBits.get_unbiased_exponent(), + xBits.get_unbiased_exponent()); + ASSERT_EQ(resultBits.get_mantissa(), xBits.get_mantissa() + UIntType(1)); x = -x; result = func(x, 0); resultBits = FPBits(result); - ASSERT_EQ(resultBits.getUnbiasedExponent(), - uint16_t(xBits.getUnbiasedExponent() - 1)); - ASSERT_EQ(resultBits.getMantissa(), - (UIntType(1) << MantissaWidth::value) - 1); + ASSERT_EQ(resultBits.get_unbiased_exponent(), + uint16_t(xBits.get_unbiased_exponent() - 1)); + ASSERT_EQ(resultBits.get_mantissa(), + (UIntType(1) << MantissaWidth::VALUE) - 1); result = func(x, T(-33.0)); resultBits = FPBits(result); - ASSERT_EQ(resultBits.getUnbiasedExponent(), xBits.getUnbiasedExponent()); - ASSERT_EQ(resultBits.getMantissa(), xBits.getMantissa() + UIntType(1)); + ASSERT_EQ(resultBits.get_unbiased_exponent(), + xBits.get_unbiased_exponent()); + ASSERT_EQ(resultBits.get_mantissa(), xBits.get_mantissa() + UIntType(1)); } }; diff --git a/libc/test/src/math/RIntTest.h b/libc/test/src/math/RIntTest.h --- a/libc/test/src/math/RIntTest.h +++ b/libc/test/src/math/RIntTest.h @@ -34,10 +34,10 @@ using UIntType = typename FPBits::UIntType; const T zero = T(FPBits::zero()); - const T negZero = T(FPBits::negZero()); + const T neg_zero = T(FPBits::neg_zero()); const T inf = T(FPBits::inf()); - const T negInf = T(FPBits::negInf()); - const T nan = T(FPBits::buildNaN(1)); + const T neg_inf = T(FPBits::neg_inf()); + const T nan = T(FPBits::build_nan(1)); static inline mpfr::RoundingMode toMPFRRoundingMode(int mode) { switch (mode) { @@ -57,18 +57,18 @@ public: void testSpecialNumbers(RIntFunc func) { for (int mode : roundingModes) { - __llvm_libc::fputil::setRound(mode); + __llvm_libc::fputil::set_round(mode); ASSERT_FP_EQ(inf, func(inf)); - ASSERT_FP_EQ(negInf, func(negInf)); + ASSERT_FP_EQ(neg_inf, func(neg_inf)); ASSERT_FP_EQ(nan, func(nan)); ASSERT_FP_EQ(zero, func(zero)); - ASSERT_FP_EQ(negZero, func(negZero)); + ASSERT_FP_EQ(neg_zero, func(neg_zero)); } } void testRoundNumbers(RIntFunc func) { for (int mode : roundingModes) { - __llvm_libc::fputil::setRound(mode); + __llvm_libc::fputil::set_round(mode); mpfr::RoundingMode mpfrMode = toMPFRRoundingMode(mode); ASSERT_FP_EQ(func(T(1.0)), mpfr::Round(T(1.0), mpfrMode)); ASSERT_FP_EQ(func(T(-1.0)), mpfr::Round(T(-1.0), mpfrMode)); @@ -81,7 +81,7 @@ void testFractions(RIntFunc func) { for (int mode : roundingModes) { - __llvm_libc::fputil::setRound(mode); + __llvm_libc::fputil::set_round(mode); mpfr::RoundingMode mpfrMode = toMPFRRoundingMode(mode); ASSERT_FP_EQ(func(T(0.5)), mpfr::Round(T(0.5), mpfrMode)); ASSERT_FP_EQ(func(T(-0.5)), mpfr::Round(T(-0.5), mpfrMode)); @@ -95,12 +95,12 @@ void testSubnormalRange(RIntFunc func) { constexpr UIntType count = 1000001; constexpr UIntType step = - (FPBits::maxSubnormal - FPBits::minSubnormal) / count; - for (UIntType i = FPBits::minSubnormal; i <= FPBits::maxSubnormal; + (FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count; + for (UIntType i = FPBits::MIN_SUBNORMAL; i <= FPBits::MAX_SUBNORMAL; i += step) { T x = T(FPBits(i)); for (int mode : roundingModes) { - __llvm_libc::fputil::setRound(mode); + __llvm_libc::fputil::set_round(mode); mpfr::RoundingMode mpfrMode = toMPFRRoundingMode(mode); ASSERT_FP_EQ(func(x), mpfr::Round(x, mpfrMode)); } @@ -109,8 +109,8 @@ void testNormalRange(RIntFunc func) { constexpr UIntType count = 1000001; - constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count; - for (UIntType i = FPBits::minNormal; i <= FPBits::maxNormal; i += step) { + constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count; + for (UIntType i = FPBits::MIN_NORMAL; i <= FPBits::MAX_NORMAL; i += step) { T x = T(FPBits(i)); // In normal range on x86 platforms, the long double implicit 1 bit can be // zero making the numbers NaN. We will skip them. @@ -119,7 +119,7 @@ } for (int mode : roundingModes) { - __llvm_libc::fputil::setRound(mode); + __llvm_libc::fputil::set_round(mode); mpfr::RoundingMode mpfrMode = toMPFRRoundingMode(mode); ASSERT_FP_EQ(func(x), mpfr::Round(x, mpfrMode)); } diff --git a/libc/test/src/math/RemQuoTest.h b/libc/test/src/math/RemQuoTest.h --- a/libc/test/src/math/RemQuoTest.h +++ b/libc/test/src/math/RemQuoTest.h @@ -24,10 +24,10 @@ using UIntType = typename FPBits::UIntType; const T zero = T(__llvm_libc::fputil::FPBits::zero()); - const T negZero = T(__llvm_libc::fputil::FPBits::negZero()); + const T neg_zero = T(__llvm_libc::fputil::FPBits::neg_zero()); const T inf = T(__llvm_libc::fputil::FPBits::inf()); - const T negInf = T(__llvm_libc::fputil::FPBits::negInf()); - const T nan = T(__llvm_libc::fputil::FPBits::buildNaN(1)); + const T neg_inf = T(__llvm_libc::fputil::FPBits::neg_inf()); + const T nan = T(__llvm_libc::fputil::FPBits::build_nan(1)); public: typedef T (*RemQuoFunc)(T, T, int *); @@ -39,13 +39,13 @@ y = T(1.0); x = inf; EXPECT_FP_EQ(nan, func(x, y, "ient)); - x = negInf; + x = neg_inf; EXPECT_FP_EQ(nan, func(x, y, "ient)); x = T(1.0); y = zero; EXPECT_FP_EQ(nan, func(x, y, "ient)); - y = negZero; + y = neg_zero; EXPECT_FP_EQ(nan, func(x, y, "ient)); y = nan; @@ -64,9 +64,9 @@ y = T(1.0); EXPECT_FP_EQ(func(x, y, "ient), zero); - x = negZero; + x = neg_zero; y = T(1.0); - EXPECT_FP_EQ(func(x, y, "ient), negZero); + EXPECT_FP_EQ(func(x, y, "ient), neg_zero); x = T(1.125); y = inf; @@ -87,19 +87,19 @@ EXPECT_FP_EQ(func(x, -y, &q), zero); EXPECT_EQ(q, -1); - EXPECT_FP_EQ(func(-x, y, &q), negZero); + EXPECT_FP_EQ(func(-x, y, &q), neg_zero); EXPECT_EQ(q, -1); - EXPECT_FP_EQ(func(-x, -y, &q), negZero); + EXPECT_FP_EQ(func(-x, -y, &q), neg_zero); EXPECT_EQ(q, 1); } void testSubnormalRange(RemQuoFunc func) { constexpr UIntType count = 1000001; constexpr UIntType step = - (FPBits::maxSubnormal - FPBits::minSubnormal) / count; - for (UIntType v = FPBits::minSubnormal, w = FPBits::maxSubnormal; - v <= FPBits::maxSubnormal && w >= FPBits::minSubnormal; + (FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count; + for (UIntType v = FPBits::MIN_SUBNORMAL, w = FPBits::MAX_SUBNORMAL; + v <= FPBits::MAX_SUBNORMAL && w >= FPBits::MIN_SUBNORMAL; v += step, w -= step) { T x = T(FPBits(v)), y = T(FPBits(w)); mpfr::BinaryOutput result; @@ -111,9 +111,9 @@ void testNormalRange(RemQuoFunc func) { constexpr UIntType count = 1000001; - constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count; - for (UIntType v = FPBits::minNormal, w = FPBits::maxNormal; - v <= FPBits::maxNormal && w >= FPBits::minNormal; + constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count; + for (UIntType v = FPBits::MIN_NORMAL, w = FPBits::MAX_NORMAL; + v <= FPBits::MAX_NORMAL && w >= FPBits::MIN_NORMAL; v += step, w -= step) { T x = T(FPBits(v)), y = T(FPBits(w)); mpfr::BinaryOutput result; diff --git a/libc/test/src/math/RoundTest.h b/libc/test/src/math/RoundTest.h --- a/libc/test/src/math/RoundTest.h +++ b/libc/test/src/math/RoundTest.h @@ -23,10 +23,10 @@ void testSpecialNumbers(RoundFunc func) { EXPECT_FP_EQ(zero, func(zero)); - EXPECT_FP_EQ(negZero, func(negZero)); + EXPECT_FP_EQ(neg_zero, func(neg_zero)); EXPECT_FP_EQ(inf, func(inf)); - EXPECT_FP_EQ(negInf, func(negInf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf)); EXPECT_FP_EQ(aNaN, func(aNaN)); } diff --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h --- a/libc/test/src/math/RoundToIntegerTest.h +++ b/libc/test/src/math/RoundToIntegerTest.h @@ -36,10 +36,10 @@ using UIntType = typename FPBits::UIntType; const F zero = F(__llvm_libc::fputil::FPBits::zero()); - const F negZero = F(__llvm_libc::fputil::FPBits::negZero()); + const F neg_zero = F(__llvm_libc::fputil::FPBits::neg_zero()); const F inf = F(__llvm_libc::fputil::FPBits::inf()); - const F negInf = F(__llvm_libc::fputil::FPBits::negInf()); - const F nan = F(__llvm_libc::fputil::FPBits::buildNaN(1)); + const F neg_inf = F(__llvm_libc::fputil::FPBits::neg_inf()); + const F nan = F(__llvm_libc::fputil::FPBits::build_nan(1)); static constexpr I IntegerMin = I(1) << (sizeof(I) * 8 - 1); static constexpr I IntegerMax = -(IntegerMin + 1); @@ -49,21 +49,21 @@ errno = 0; #endif #if math_errhandling & MATH_ERREXCEPT - __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); #endif ASSERT_EQ(func(input), expected); if (expectError) { #if math_errhandling & MATH_ERREXCEPT - ASSERT_EQ(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT), FE_INVALID); + ASSERT_EQ(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT), FE_INVALID); #endif #if math_errhandling & MATH_ERRNO ASSERT_EQ(errno, EDOM); #endif } else { #if math_errhandling & MATH_ERREXCEPT - ASSERT_EQ(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT), 0); + ASSERT_EQ(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT), 0); #endif #if math_errhandling & MATH_ERRNO ASSERT_EQ(errno, 0); @@ -92,20 +92,20 @@ // We will disable all exceptions so that the test will not // crash with SIGFPE. We can still use fetestexcept to check // if the appropriate flag was raised. - __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT); + __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); #endif } void doInfinityAndNaNTest(RoundToIntegerFunc func) { testOneInput(func, inf, IntegerMax, true); - testOneInput(func, negInf, IntegerMin, true); + testOneInput(func, neg_inf, IntegerMin, true); testOneInput(func, nan, IntegerMax, true); } void testInfinityAndNaN(RoundToIntegerFunc func) { if (TestModes) { for (int mode : roundingModes) { - __llvm_libc::fputil::setRound(mode); + __llvm_libc::fputil::set_round(mode); doInfinityAndNaNTest(func); } } else { @@ -115,7 +115,7 @@ void doRoundNumbersTest(RoundToIntegerFunc func) { testOneInput(func, zero, I(0), false); - testOneInput(func, negZero, I(0), false); + testOneInput(func, neg_zero, I(0), false); testOneInput(func, F(1.0), I(1), false); testOneInput(func, F(-1.0), I(-1), false); testOneInput(func, F(10.0), I(10), false); @@ -135,9 +135,9 @@ // We start with 1.0 so that the implicit bit for x86 long doubles // is set. FPBits bits(F(1.0)); - bits.setUnbiasedExponent(exponentLimit + FPBits::exponentBias); - bits.setSign(1); - bits.setMantissa(0); + bits.set_unbiased_exponent(exponentLimit + FPBits::EXPONENT_BIAS); + bits.set_sign(1); + bits.set_mantissa(0); F x = F(bits); long mpfrResult; @@ -149,7 +149,7 @@ void testRoundNumbers(RoundToIntegerFunc func) { if (TestModes) { for (int mode : roundingModes) { - __llvm_libc::fputil::setRound(mode); + __llvm_libc::fputil::set_round(mode); doRoundNumbersTest(func); } } else { @@ -176,7 +176,7 @@ void testFractions(RoundToIntegerFunc func) { if (TestModes) { for (int mode : roundingModes) { - __llvm_libc::fputil::setRound(mode); + __llvm_libc::fputil::set_round(mode); doFractionsTest(func, mode); } } else { @@ -199,14 +199,15 @@ // We start with 1.0 so that the implicit bit for x86 long doubles // is set. FPBits bits(F(1.0)); - bits.setUnbiasedExponent(exponentLimit + FPBits::exponentBias); - bits.setSign(1); - bits.setMantissa(UIntType(0x1) << (__llvm_libc::fputil::MantissaWidth::value - 1)); + bits.set_unbiased_exponent(exponentLimit + FPBits::EXPONENT_BIAS); + bits.set_sign(1); + bits.set_mantissa(UIntType(0x1) + << (__llvm_libc::fputil::MantissaWidth::VALUE - 1)); F x = F(bits); if (TestModes) { for (int m : roundingModes) { - __llvm_libc::fputil::setRound(m); + __llvm_libc::fputil::set_round(m); long mpfrLongResult; bool erangeflag = mpfr::RoundToLong(x, toMPFRRoundingMode(m), mpfrLongResult); @@ -224,8 +225,8 @@ void testSubnormalRange(RoundToIntegerFunc func) { constexpr UIntType count = 1000001; constexpr UIntType step = - (FPBits::maxSubnormal - FPBits::minSubnormal) / count; - for (UIntType i = FPBits::minSubnormal; i <= FPBits::maxSubnormal; + (FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count; + for (UIntType i = FPBits::MIN_SUBNORMAL; i <= FPBits::MAX_SUBNORMAL; i += step) { F x = F(FPBits(i)); if (x == F(0.0)) @@ -233,22 +234,22 @@ // All subnormal numbers should round to zero. if (TestModes) { if (x > 0) { - __llvm_libc::fputil::setRound(FE_UPWARD); + __llvm_libc::fputil::set_round(FE_UPWARD); testOneInput(func, x, I(1), false); - __llvm_libc::fputil::setRound(FE_DOWNWARD); + __llvm_libc::fputil::set_round(FE_DOWNWARD); testOneInput(func, x, I(0), false); - __llvm_libc::fputil::setRound(FE_TOWARDZERO); + __llvm_libc::fputil::set_round(FE_TOWARDZERO); testOneInput(func, x, I(0), false); - __llvm_libc::fputil::setRound(FE_TONEAREST); + __llvm_libc::fputil::set_round(FE_TONEAREST); testOneInput(func, x, I(0), false); } else { - __llvm_libc::fputil::setRound(FE_UPWARD); + __llvm_libc::fputil::set_round(FE_UPWARD); testOneInput(func, x, I(0), false); - __llvm_libc::fputil::setRound(FE_DOWNWARD); + __llvm_libc::fputil::set_round(FE_DOWNWARD); testOneInput(func, x, I(-1), false); - __llvm_libc::fputil::setRound(FE_TOWARDZERO); + __llvm_libc::fputil::set_round(FE_TOWARDZERO); testOneInput(func, x, I(0), false); - __llvm_libc::fputil::setRound(FE_TONEAREST); + __llvm_libc::fputil::set_round(FE_TONEAREST); testOneInput(func, x, I(0), false); } } else { @@ -267,8 +268,8 @@ return; constexpr UIntType count = 1000001; - constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count; - for (UIntType i = FPBits::minNormal; i <= FPBits::maxNormal; i += step) { + constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count; + for (UIntType i = FPBits::MIN_NORMAL; i <= FPBits::MAX_NORMAL; i += step) { F x = F(FPBits(i)); // In normal range on x86 platforms, the long double implicit 1 bit can be // zero making the numbers NaN. We will skip them. @@ -282,7 +283,7 @@ bool erangeflag = mpfr::RoundToLong(x, toMPFRRoundingMode(m), mpfrLongResult); I mpfrResult = mpfrLongResult; - __llvm_libc::fputil::setRound(m); + __llvm_libc::fputil::set_round(m); if (erangeflag) testOneInput(func, x, x > 0 ? IntegerMax : IntegerMin, true); else diff --git a/libc/test/src/math/SqrtTest.h b/libc/test/src/math/SqrtTest.h --- a/libc/test/src/math/SqrtTest.h +++ b/libc/test/src/math/SqrtTest.h @@ -19,7 +19,7 @@ DECLARE_SPECIAL_CONSTANTS(T) static constexpr UIntType HiddenBit = - UIntType(1) << __llvm_libc::fputil::MantissaWidth::value; + UIntType(1) << __llvm_libc::fputil::MantissaWidth::VALUE; public: typedef T (*SqrtFunc)(T); @@ -27,7 +27,7 @@ void testSpecialNumbers(SqrtFunc func) { ASSERT_FP_EQ(aNaN, func(aNaN)); ASSERT_FP_EQ(inf, func(inf)); - ASSERT_FP_EQ(aNaN, func(negInf)); + ASSERT_FP_EQ(aNaN, func(neg_inf)); ASSERT_FP_EQ(0.0, func(0.0)); ASSERT_FP_EQ(-0.0, func(-0.0)); ASSERT_FP_EQ(aNaN, func(T(-1.0))); @@ -39,7 +39,7 @@ void testDenormalValues(SqrtFunc func) { for (UIntType mant = 1; mant < HiddenBit; mant <<= 1) { FPBits denormal(T(0.0)); - denormal.setMantissa(mant); + denormal.set_mantissa(mant); ASSERT_MPFR_MATCH(mpfr::Operation::Sqrt, T(denormal), func(T(denormal)), T(0.5)); diff --git a/libc/test/src/math/TruncTest.h b/libc/test/src/math/TruncTest.h --- a/libc/test/src/math/TruncTest.h +++ b/libc/test/src/math/TruncTest.h @@ -23,10 +23,10 @@ void testSpecialNumbers(TruncFunc func) { EXPECT_FP_EQ(zero, func(zero)); - EXPECT_FP_EQ(negZero, func(negZero)); + EXPECT_FP_EQ(neg_zero, func(neg_zero)); EXPECT_FP_EQ(inf, func(inf)); - EXPECT_FP_EQ(negInf, func(negInf)); + EXPECT_FP_EQ(neg_inf, func(neg_inf)); EXPECT_FP_EQ(aNaN, func(aNaN)); } diff --git a/libc/test/src/math/cosf_test.cpp b/libc/test/src/math/cosf_test.cpp --- a/libc/test/src/math/cosf_test.cpp +++ b/libc/test/src/math/cosf_test.cpp @@ -42,7 +42,7 @@ EXPECT_EQ(errno, EDOM); errno = 0; - EXPECT_FP_EQ(aNaN, __llvm_libc::cosf(negInf)); + EXPECT_FP_EQ(aNaN, __llvm_libc::cosf(neg_inf)); EXPECT_EQ(errno, EDOM); } diff --git a/libc/test/src/math/exhaustive/expm1f_test.cpp b/libc/test/src/math/exhaustive/expm1f_test.cpp --- a/libc/test/src/math/exhaustive/expm1f_test.cpp +++ b/libc/test/src/math/exhaustive/expm1f_test.cpp @@ -20,7 +20,7 @@ uint32_t bits = 0; do { FPBits x(bits); - if (!x.isInfOrNaN() && float(x) < 88.70f) { + if (!x.is_inf_or_nan() && float(x) < 88.70f) { ASSERT_MPFR_MATCH(mpfr::Operation::Expm1, float(x), __llvm_libc::expm1f(float(x)), 1.5); } diff --git a/libc/test/src/math/exp2f_test.cpp b/libc/test/src/math/exp2f_test.cpp --- a/libc/test/src/math/exp2f_test.cpp +++ b/libc/test/src/math/exp2f_test.cpp @@ -29,7 +29,7 @@ EXPECT_FP_EQ(inf, __llvm_libc::exp2f(inf)); EXPECT_EQ(errno, 0); - EXPECT_FP_EQ(0.0f, __llvm_libc::exp2f(negInf)); + EXPECT_FP_EQ(0.0f, __llvm_libc::exp2f(neg_inf)); EXPECT_EQ(errno, 0); EXPECT_FP_EQ(1.0f, __llvm_libc::exp2f(0.0f)); diff --git a/libc/test/src/math/expf_test.cpp b/libc/test/src/math/expf_test.cpp --- a/libc/test/src/math/expf_test.cpp +++ b/libc/test/src/math/expf_test.cpp @@ -29,7 +29,7 @@ EXPECT_FP_EQ(inf, __llvm_libc::expf(inf)); EXPECT_EQ(errno, 0); - EXPECT_FP_EQ(0.0f, __llvm_libc::expf(negInf)); + EXPECT_FP_EQ(0.0f, __llvm_libc::expf(neg_inf)); EXPECT_EQ(errno, 0); EXPECT_FP_EQ(1.0f, __llvm_libc::expf(0.0f)); diff --git a/libc/test/src/math/expm1f_test.cpp b/libc/test/src/math/expm1f_test.cpp --- a/libc/test/src/math/expm1f_test.cpp +++ b/libc/test/src/math/expm1f_test.cpp @@ -29,7 +29,7 @@ EXPECT_FP_EQ(inf, __llvm_libc::expm1f(inf)); EXPECT_EQ(errno, 0); - EXPECT_FP_EQ(-1.0f, __llvm_libc::expm1f(negInf)); + EXPECT_FP_EQ(-1.0f, __llvm_libc::expm1f(neg_inf)); EXPECT_EQ(errno, 0); EXPECT_FP_EQ(0.0f, __llvm_libc::expm1f(0.0f)); diff --git a/libc/test/src/math/sincosf_test.cpp b/libc/test/src/math/sincosf_test.cpp --- a/libc/test/src/math/sincosf_test.cpp +++ b/libc/test/src/math/sincosf_test.cpp @@ -51,7 +51,7 @@ EXPECT_EQ(errno, EDOM); errno = 0; - __llvm_libc::sincosf(negInf, &sin, &cos); + __llvm_libc::sincosf(neg_inf, &sin, &cos); EXPECT_FP_EQ(aNaN, cos); EXPECT_FP_EQ(aNaN, sin); EXPECT_EQ(errno, EDOM); diff --git a/libc/test/src/math/sinf_test.cpp b/libc/test/src/math/sinf_test.cpp --- a/libc/test/src/math/sinf_test.cpp +++ b/libc/test/src/math/sinf_test.cpp @@ -42,7 +42,7 @@ EXPECT_EQ(errno, EDOM); errno = 0; - EXPECT_FP_EQ(aNaN, __llvm_libc::sinf(negInf)); + EXPECT_FP_EQ(aNaN, __llvm_libc::sinf(neg_inf)); EXPECT_EQ(errno, EDOM); } diff --git a/libc/test/src/stdlib/atof_test.cpp b/libc/test/src/stdlib/atof_test.cpp --- a/libc/test/src/stdlib/atof_test.cpp +++ b/libc/test/src/stdlib/atof_test.cpp @@ -28,9 +28,9 @@ __llvm_libc::fputil::FPBits(result); EXPECT_EQ(actualFP.bits, expectedFP.bits); - EXPECT_EQ(actualFP.getSign(), expectedFP.getSign()); - EXPECT_EQ(actualFP.getExponent(), expectedFP.getExponent()); - EXPECT_EQ(actualFP.getMantissa(), expectedFP.getMantissa()); + EXPECT_EQ(actualFP.get_sign(), expectedFP.get_sign()); + EXPECT_EQ(actualFP.get_exponent(), expectedFP.get_exponent()); + EXPECT_EQ(actualFP.get_mantissa(), expectedFP.get_mantissa()); EXPECT_EQ(errno, 0); } @@ -45,8 +45,8 @@ __llvm_libc::fputil::FPBits(result); EXPECT_EQ(actualFP.bits, expectedFP.bits); - EXPECT_EQ(actualFP.getSign(), expectedFP.getSign()); - EXPECT_EQ(actualFP.getExponent(), expectedFP.getExponent()); - EXPECT_EQ(actualFP.getMantissa(), expectedFP.getMantissa()); + EXPECT_EQ(actualFP.get_sign(), expectedFP.get_sign()); + EXPECT_EQ(actualFP.get_exponent(), expectedFP.get_exponent()); + EXPECT_EQ(actualFP.get_mantissa(), expectedFP.get_mantissa()); EXPECT_EQ(errno, 0); } diff --git a/libc/test/src/stdlib/strtod_test.cpp b/libc/test/src/stdlib/strtod_test.cpp --- a/libc/test/src/stdlib/strtod_test.cpp +++ b/libc/test/src/stdlib/strtod_test.cpp @@ -47,9 +47,9 @@ EXPECT_EQ(strEnd - inputString, expectedStrLen); EXPECT_EQ(actualFP.bits, expectedFP.bits); - EXPECT_EQ(actualFP.getSign(), expectedFP.getSign()); - EXPECT_EQ(actualFP.getExponent(), expectedFP.getExponent()); - EXPECT_EQ(actualFP.getMantissa(), expectedFP.getMantissa()); + EXPECT_EQ(actualFP.get_sign(), expectedFP.get_sign()); + EXPECT_EQ(actualFP.get_exponent(), expectedFP.get_exponent()); + EXPECT_EQ(actualFP.get_mantissa(), expectedFP.get_mantissa()); EXPECT_EQ(errno, expectedErrno); } }; diff --git a/libc/test/src/stdlib/strtof_test.cpp b/libc/test/src/stdlib/strtof_test.cpp --- a/libc/test/src/stdlib/strtof_test.cpp +++ b/libc/test/src/stdlib/strtof_test.cpp @@ -47,9 +47,9 @@ EXPECT_EQ(strEnd - inputString, expectedStrLen); EXPECT_EQ(actualFP.bits, expectedFP.bits); - EXPECT_EQ(actualFP.getSign(), expectedFP.getSign()); - EXPECT_EQ(actualFP.getExponent(), expectedFP.getExponent()); - EXPECT_EQ(actualFP.getMantissa(), expectedFP.getMantissa()); + EXPECT_EQ(actualFP.get_sign(), expectedFP.get_sign()); + EXPECT_EQ(actualFP.get_exponent(), expectedFP.get_exponent()); + EXPECT_EQ(actualFP.get_mantissa(), expectedFP.get_mantissa()); EXPECT_EQ(errno, expectedErrno); } }; diff --git a/libc/test/src/string/memory_utils/elements_test.cpp b/libc/test/src/string/memory_utils/elements_test.cpp --- a/libc/test/src/string/memory_utils/elements_test.cpp +++ b/libc/test/src/string/memory_utils/elements_test.cpp @@ -56,7 +56,7 @@ current = GetRandomChar(); } -template using Buffer = cpp::Array; +template using Buffer = cpp::Array; template Buffer GetRandomBuffer() { Buffer buffer; @@ -64,15 +64,15 @@ return buffer; } -TYPED_TEST(LlvmLibcMemoryElements, Copy, FixedSizeTypes) { +TYPED_TEST(LlvmLibcMemoryElements, copy, FixedSizeTypes) { Buffer Dst; const auto buffer = GetRandomBuffer(); - Copy(Dst.data(), buffer.data()); - for (size_t i = 0; i < ParamType::kSize; ++i) + copy(Dst.data(), buffer.data()); + for (size_t i = 0; i < ParamType::K_SIZE; ++i) EXPECT_EQ(Dst[i], buffer[i]); } -template T Copy(const T &Input) { +template T copy(const T &Input) { T Output; for (size_t I = 0; I < Input.size(); ++I) Output[I] = Input[I]; @@ -80,29 +80,29 @@ } TYPED_TEST(LlvmLibcMemoryElements, Move, FixedSizeTypes) { - constexpr size_t kSize = ParamType::kSize; - using LargeBuffer = cpp::Array; + constexpr size_t K_SIZE = ParamType::K_SIZE; + using LargeBuffer = cpp::Array; LargeBuffer GroundTruth; Randomize(GroundTruth); - // Forward, we move the kSize first bytes from offset 0 to kSize. - for (size_t Offset = 0; Offset < kSize; ++Offset) { - LargeBuffer Buffer = Copy(GroundTruth); - Move(&Buffer[Offset], &Buffer[0]); - for (size_t I = 0; I < kSize; ++I) + // Forward, we move the K_SIZE first bytes from offset 0 to K_SIZE. + for (size_t Offset = 0; Offset < K_SIZE; ++Offset) { + LargeBuffer Buffer = copy(GroundTruth); + move(&Buffer[Offset], &Buffer[0]); + for (size_t I = 0; I < K_SIZE; ++I) EXPECT_EQ(Buffer[I + Offset], GroundTruth[I]); } - // Backward, we move the kSize last bytes from offset 0 to kSize. - for (size_t Offset = 0; Offset < kSize; ++Offset) { - LargeBuffer Buffer = Copy(GroundTruth); - Move(&Buffer[Offset], &Buffer[kSize]); - for (size_t I = 0; I < kSize; ++I) - EXPECT_EQ(Buffer[I + Offset], GroundTruth[kSize + I]); + // Backward, we move the K_SIZE last bytes from offset 0 to K_SIZE. + for (size_t Offset = 0; Offset < K_SIZE; ++Offset) { + LargeBuffer Buffer = copy(GroundTruth); + move(&Buffer[Offset], &Buffer[K_SIZE]); + for (size_t I = 0; I < K_SIZE; ++I) + EXPECT_EQ(Buffer[I + Offset], GroundTruth[K_SIZE + I]); } } TYPED_TEST(LlvmLibcMemoryElements, Equals, FixedSizeTypes) { const auto buffer = GetRandomBuffer(); - EXPECT_TRUE(Equals(buffer.data(), buffer.data())); + EXPECT_TRUE(equals(buffer.data(), buffer.data())); } TYPED_TEST(LlvmLibcMemoryElements, ThreeWayCompare, FixedSizeTypes) { @@ -111,16 +111,16 @@ c = 5; // Testing equality - EXPECT_EQ(ThreeWayCompare(initial.data(), initial.data()), 0); + EXPECT_EQ(three_way_compare(initial.data(), initial.data()), 0); // Testing all mismatching positions - for (size_t i = 0; i < ParamType::kSize; ++i) { + for (size_t i = 0; i < ParamType::K_SIZE; ++i) { auto copy = initial; - ++copy[i]; // Copy is now lexicographycally greated than initial + ++copy[i]; // copy is now lexicographycally greated than initial const auto *less = initial.data(); const auto *greater = copy.data(); - EXPECT_LT(ThreeWayCompare(less, greater), 0); - EXPECT_GT(ThreeWayCompare(greater, less), 0); + EXPECT_LT(three_way_compare(less, greater), 0); + EXPECT_GT(three_way_compare(greater, less), 0); } } @@ -128,8 +128,8 @@ Buffer Dst; const cpp::Array values = {char(0x00), char(0x7F), char(0xFF)}; for (char value : values) { - SplatSet(Dst.data(), value); - for (size_t i = 0; i < ParamType::kSize; ++i) + splat_set(Dst.data(), value); + for (size_t i = 0; i < ParamType::K_SIZE; ++i) EXPECT_EQ(Dst[i], value); } } diff --git a/libc/test/src/string/memory_utils/memory_access_test.cpp b/libc/test/src/string/memory_utils/memory_access_test.cpp --- a/libc/test/src/string/memory_utils/memory_access_test.cpp +++ b/libc/test/src/string/memory_utils/memory_access_test.cpp @@ -73,27 +73,27 @@ MemoryAccessObserver Observer; template struct TestingElement { - static constexpr size_t kSize = Size; + static constexpr size_t K_SIZE = Size; - static void Copy(char *__restrict dst, const char *__restrict src) { - Observer.ObserveRead(src, kSize); - Observer.ObserveWrite(dst, kSize); + static void copy(char *__restrict dst, const char *__restrict src) { + Observer.ObserveRead(src, K_SIZE); + Observer.ObserveWrite(dst, K_SIZE); } - static bool Equals(const char *lhs, const char *rhs) { - Observer.ObserveRead(lhs, kSize); - Observer.ObserveRead(rhs, kSize); + static bool equals(const char *lhs, const char *rhs) { + Observer.ObserveRead(lhs, K_SIZE); + Observer.ObserveRead(rhs, K_SIZE); return true; } - static int ThreeWayCompare(const char *lhs, const char *rhs) { - Observer.ObserveRead(lhs, kSize); - Observer.ObserveRead(rhs, kSize); + static int three_way_compare(const char *lhs, const char *rhs) { + Observer.ObserveRead(lhs, K_SIZE); + Observer.ObserveRead(rhs, K_SIZE); return 0; } - static void SplatSet(char *dst, const unsigned char value) { - Observer.ObserveWrite(dst, kSize); + static void splat_set(char *dst, const unsigned char value) { + Observer.ObserveWrite(dst, K_SIZE); } }; @@ -112,25 +112,26 @@ static const BufferAccess untouched; Observer.Reset(); - HigherOrder::Copy(dst_ptr() + Offset, src_ptr() + Offset, Size); + HigherOrder::copy(dst_ptr() + Offset, src_ptr() + Offset, Size); ASSERT_STREQ(src().writes, untouched); ASSERT_STREQ(dst().reads, untouched); ASSERT_STREQ(src().reads, expected); ASSERT_STREQ(dst().writes, expected); Observer.Reset(); - HigherOrder::Equals(lhs_ptr() + Offset, rhs_ptr() + Offset, Size); + HigherOrder::equals(lhs_ptr() + Offset, rhs_ptr() + Offset, Size); ASSERT_STREQ(lhs().writes, untouched); ASSERT_STREQ(rhs().writes, untouched); ASSERT_STREQ(lhs().reads, expected); ASSERT_STREQ(rhs().reads, expected); Observer.Reset(); - HigherOrder::ThreeWayCompare(lhs_ptr() + Offset, rhs_ptr() + Offset, Size); + HigherOrder::three_way_compare(lhs_ptr() + Offset, rhs_ptr() + Offset, + Size); ASSERT_STREQ(lhs().writes, untouched); ASSERT_STREQ(rhs().writes, untouched); ASSERT_STREQ(lhs().reads, expected); ASSERT_STREQ(rhs().reads, expected); Observer.Reset(); - HigherOrder::SplatSet(dst_ptr() + Offset, 5, Size); + HigherOrder::splat_set(dst_ptr() + Offset, 5, Size); ASSERT_STREQ(src().reads, untouched); ASSERT_STREQ(src().writes, untouched); ASSERT_STREQ(dst().reads, untouched); @@ -165,7 +166,7 @@ static constexpr size_t Size = 10; BufferAccess expected; - expected.Touch(Size - ParamType::kSize, ParamType::kSize); + expected.Touch(Size - ParamType::K_SIZE, ParamType::K_SIZE); checkMaxAccess(expected, 1); checkOperations, Size>(expected); @@ -179,8 +180,8 @@ static constexpr size_t Size = 10; BufferAccess expected; - expected.Touch(0, ParamType::kSize); - expected.Touch(Size - ParamType::kSize, ParamType::kSize); + expected.Touch(0, ParamType::K_SIZE); + expected.Touch(Size - ParamType::K_SIZE, ParamType::K_SIZE); checkMaxAccess(expected, 2); checkOperations, Size>(expected); @@ -194,9 +195,9 @@ static constexpr size_t Size = 20; BufferAccess expected; - for (size_t i = 0; i < Size - ParamType::kSize; i += ParamType::kSize) - expected.Touch(i, ParamType::kSize); - expected.Touch(Size - ParamType::kSize, ParamType::kSize); + for (size_t i = 0; i < Size - ParamType::K_SIZE; i += ParamType::K_SIZE) + expected.Touch(i, ParamType::K_SIZE); + expected.Touch(Size - ParamType::K_SIZE, ParamType::K_SIZE); checkMaxAccess(expected, 2); checkOperations, Size>(expected); @@ -212,9 +213,9 @@ using AlignmentT = TestingElement<4>; BufferAccess expected; - expected.Touch(Offset, AlignmentT::kSize); - expected.Touch(AlignmentT::kSize, ParamType::kSize); - expected.Touch(Offset + Size - ParamType::kSize, ParamType::kSize); + expected.Touch(Offset, AlignmentT::K_SIZE); + expected.Touch(AlignmentT::K_SIZE, ParamType::K_SIZE); + expected.Touch(Offset + Size - ParamType::K_SIZE, ParamType::K_SIZE); checkMaxAccess(expected, 3); checkOperations::Then>, Size, diff --git a/libc/test/src/time/TmHelper.h b/libc/test/src/time/TmHelper.h --- a/libc/test/src/time/TmHelper.h +++ b/libc/test/src/time/TmHelper.h @@ -20,16 +20,16 @@ namespace testing { // A helper function to initialize tm data structure. -static inline void InitializeTmData(struct tm *tm_data, int year, int month, +static inline void InitializeTmData(struct Tm *tm_data, int year, int month, int mday, int hour, int min, int sec, int wday, int yday) { - struct tm temp = {.tm_sec = sec, + struct Tm temp = {.tm_sec = sec, .tm_min = min, .tm_hour = hour, .tm_mday = mday, .tm_mon = month - 1, // tm_mon starts with 0 for Jan // years since 1900 - .tm_year = year - TimeConstants::TimeYearBase, + .tm_year = year - TimeConstants::TIME_YEAR_BASE, .tm_wday = wday, .tm_yday = yday}; *tm_data = temp; diff --git a/libc/test/src/time/TmMatcher.h b/libc/test/src/time/TmMatcher.h --- a/libc/test/src/time/TmMatcher.h +++ b/libc/test/src/time/TmMatcher.h @@ -17,14 +17,14 @@ namespace tmmatcher { namespace testing { -class StructTmMatcher : public __llvm_libc::testing::Matcher<::tm> { - ::tm expected; - ::tm actual; +class StructTmMatcher : public __llvm_libc::testing::Matcher<::Tm> { + ::Tm expected; + ::Tm actual; public: - StructTmMatcher(::tm expectedValue) : expected(expectedValue) {} + StructTmMatcher(::Tm expectedValue) : expected(expectedValue) {} - bool match(::tm actualValue) { + bool match(::Tm actualValue) { actual = actualValue; return (actual.tm_sec == expected.tm_sec || actual.tm_min == expected.tm_min || @@ -37,7 +37,7 @@ actual.tm_isdst == expected.tm_isdst); } - void describeValue(const char *label, ::tm value, + void describeValue(const char *label, ::Tm value, __llvm_libc::testutils::StreamWrapper &stream) { stream << label; stream << " sec: " << value.tm_sec; diff --git a/libc/test/src/time/asctime_r_test.cpp b/libc/test/src/time/asctime_r_test.cpp --- a/libc/test/src/time/asctime_r_test.cpp +++ b/libc/test/src/time/asctime_r_test.cpp @@ -14,7 +14,7 @@ using __llvm_libc::time_utils::TimeConstants; -static inline char *call_asctime_r(struct tm *tm_data, int year, int month, +static inline char *call_asctime_r(struct Tm *tm_data, int year, int month, int mday, int hour, int min, int sec, int wday, int yday, char *buffer) { __llvm_libc::tmhelper::testing::InitializeTmData(tm_data, year, month, mday, @@ -30,20 +30,20 @@ ASSERT_EQ(EINVAL, llvmlibc_errno); ASSERT_STREQ(nullptr, result); - char buffer[TimeConstants::AsctimeBufferSize]; + char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; result = __llvm_libc::asctime_r(nullptr, buffer); ASSERT_EQ(EINVAL, llvmlibc_errno); ASSERT_STREQ(nullptr, result); - struct tm tm_data; + struct Tm tm_data; result = __llvm_libc::asctime_r(&tm_data, nullptr); ASSERT_EQ(EINVAL, llvmlibc_errno); ASSERT_STREQ(nullptr, result); } TEST(LlvmLibcAsctimeR, ValidDate) { - char buffer[TimeConstants::AsctimeBufferSize]; - struct tm tm_data; + char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + struct Tm tm_data; char *result; // 1970-01-01 00:00:00. Test with a valid buffer size. result = call_asctime_r(&tm_data, diff --git a/libc/test/src/time/asctime_test.cpp b/libc/test/src/time/asctime_test.cpp --- a/libc/test/src/time/asctime_test.cpp +++ b/libc/test/src/time/asctime_test.cpp @@ -10,7 +10,7 @@ #include "test/src/time/TmHelper.h" #include "utils/UnitTest/Test.h" -static inline char *call_asctime(struct tm *tm_data, int year, int month, +static inline char *call_asctime(struct Tm *tm_data, int year, int month, int mday, int hour, int min, int sec, int wday, int yday) { __llvm_libc::tmhelper::testing::InitializeTmData(tm_data, year, month, mday, @@ -27,7 +27,7 @@ // Weekdays are in the range 0 to 6. Test passing invalid value in wday. TEST(LlvmLibcAsctime, InvalidWday) { - struct tm tm_data; + struct Tm tm_data; char *result; // Test with wday = -1. @@ -57,7 +57,7 @@ // Months are from January to December. Test passing invalid value in month. TEST(LlvmLibcAsctime, InvalidMonth) { - struct tm tm_data; + struct Tm tm_data; char *result; // Test with month = 0. @@ -86,7 +86,7 @@ } TEST(LlvmLibcAsctime, ValidWeekdays) { - struct tm tm_data; + struct Tm tm_data; char *result; // 1970-01-01 00:00:00. result = call_asctime(&tm_data, @@ -126,7 +126,7 @@ } TEST(LlvmLibcAsctime, ValidMonths) { - struct tm tm_data; + struct Tm tm_data; char *result; // 1970-01-01 00:00:00. result = call_asctime(&tm_data, @@ -166,7 +166,7 @@ } TEST(LlvmLibcAsctime, EndOf32BitEpochYear) { - struct tm tm_data; + struct Tm tm_data; char *result; // Test for maximum value of a signed 32-bit integer. // Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC. @@ -186,7 +186,7 @@ if (sizeof(time_t) == 4) return; // Mon Jan 1 12:50:50 2170 (200 years from 1970), - struct tm tm_data; + struct Tm tm_data; char *result; result = call_asctime(&tm_data, 2170, // year diff --git a/libc/test/src/time/gmtime_r_test.cpp b/libc/test/src/time/gmtime_r_test.cpp --- a/libc/test/src/time/gmtime_r_test.cpp +++ b/libc/test/src/time/gmtime_r_test.cpp @@ -19,17 +19,17 @@ // Test for maximum value of a signed 32-bit integer. // Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC. time_t seconds = 0x7FFFFFFF; - struct tm tm_data; - struct tm *tm_data_ptr; + struct Tm tm_data; + struct Tm *tm_data_ptr; tm_data_ptr = __llvm_libc::gmtime_r(&seconds, &tm_data); - EXPECT_TM_EQ((tm{7, // sec + EXPECT_TM_EQ((Tm{7, // sec 14, // min 3, // hr 19, // day 0, // tm_mon starts with 0 for Jan - 2038 - TimeConstants::TimeYearBase, // year - 2, // wday - 7, // yday + 2038 - TimeConstants::TIME_YEAR_BASE, // year + 2, // wday + 7, // yday 0}), *tm_data_ptr); EXPECT_TM_EQ(*tm_data_ptr, tm_data); @@ -40,17 +40,17 @@ return; // Test for Tue Jan 1 12:50:50 in 2,147,483,647th year. time_t seconds = 67767976202043050; - struct tm tm_data; - struct tm *tm_data_ptr; + struct Tm tm_data; + struct Tm *tm_data_ptr; tm_data_ptr = __llvm_libc::gmtime_r(&seconds, &tm_data); - EXPECT_TM_EQ((tm{50, // sec + EXPECT_TM_EQ((Tm{50, // sec 50, // min 12, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 2147483647 - TimeConstants::TimeYearBase, // year - 2, // wday - 50, // yday + 2147483647 - TimeConstants::TIME_YEAR_BASE, // year + 2, // wday + 50, // yday 0}), *tm_data_ptr); EXPECT_TM_EQ(*tm_data_ptr, tm_data); diff --git a/libc/test/src/time/gmtime_test.cpp b/libc/test/src/time/gmtime_test.cpp --- a/libc/test/src/time/gmtime_test.cpp +++ b/libc/test/src/time/gmtime_test.cpp @@ -21,16 +21,17 @@ using __llvm_libc::time_utils::TimeConstants; TEST(LlvmLibcGmTime, OutOfRange) { - time_t seconds = 1 + INT_MAX * static_cast( - TimeConstants::NumberOfSecondsInLeapYear); - struct tm *tm_data = __llvm_libc::gmtime(&seconds); + time_t seconds = + 1 + INT_MAX * static_cast( + TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR); + struct Tm *tm_data = __llvm_libc::gmtime(&seconds); EXPECT_TRUE(tm_data == nullptr); EXPECT_EQ(llvmlibc_errno, EOVERFLOW); llvmlibc_errno = 0; - seconds = - INT_MIN * static_cast(TimeConstants::NumberOfSecondsInLeapYear) - - 1; + seconds = INT_MIN * static_cast( + TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR) - + 1; tm_data = __llvm_libc::gmtime(&seconds); EXPECT_TRUE(tm_data == nullptr); EXPECT_EQ(llvmlibc_errno, EOVERFLOW); @@ -38,93 +39,93 @@ TEST(LlvmLibcGmTime, InvalidSeconds) { time_t seconds = 0; - struct tm *tm_data = nullptr; + struct Tm *tm_data = nullptr; // -1 second from 1970-01-01 00:00:00 returns 1969-12-31 23:59:59. seconds = -1; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{59, // sec + EXPECT_TM_EQ((Tm{59, // sec 59, // min 23, // hr 31, // day 12 - 1, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 3, // wday - 364, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 364, // yday 0}), *tm_data); // 60 seconds from 1970-01-01 00:00:00 returns 1970-01-01 00:01:00. seconds = 60; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 1, // min 0, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TimeYearBase, // year - 4, // wday - 0, // yday + 1970 - TimeConstants::TIME_YEAR_BASE, // year + 4, // wday + 0, // yday 0}), *tm_data); } TEST(LlvmLibcGmTime, InvalidMinutes) { time_t seconds = 0; - struct tm *tm_data = nullptr; + struct Tm *tm_data = nullptr; // -1 minute from 1970-01-01 00:00:00 returns 1969-12-31 23:59:00. - seconds = -TimeConstants::SecondsPerMin; + seconds = -TimeConstants::SECONDS_PER_MIN; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 59, // min 23, // hr 31, // day 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 3, // wday - 0, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday 0}), *tm_data); // 60 minutes from 1970-01-01 00:00:00 returns 1970-01-01 01:00:00. - seconds = 60 * TimeConstants::SecondsPerMin; + seconds = 60 * TimeConstants::SECONDS_PER_MIN; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 0, // min 1, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TimeYearBase, // year - 4, // wday - 0, // yday + 1970 - TimeConstants::TIME_YEAR_BASE, // year + 4, // wday + 0, // yday 0}), *tm_data); } TEST(LlvmLibcGmTime, InvalidHours) { time_t seconds = 0; - struct tm *tm_data = nullptr; + struct Tm *tm_data = nullptr; // -1 hour from 1970-01-01 00:00:00 returns 1969-12-31 23:00:00. - seconds = -TimeConstants::SecondsPerHour; + seconds = -TimeConstants::SECONDS_PER_HOUR; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 0, // min 23, // hr 31, // day 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 3, // wday - 0, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday 0}), *tm_data); // 24 hours from 1970-01-01 00:00:00 returns 1970-01-02 00:00:00. - seconds = 24 * TimeConstants::SecondsPerHour; + seconds = 24 * TimeConstants::SECONDS_PER_HOUR; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 2, // day 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TimeYearBase, // year - 5, // wday - 0, // yday + 1970 - TimeConstants::TIME_YEAR_BASE, // year + 5, // wday + 0, // yday 0}), *tm_data); } @@ -132,108 +133,109 @@ TEST(LlvmLibcGmTime, InvalidYear) { // -1 year from 1970-01-01 00:00:00 returns 1969-01-01 00:00:00. time_t seconds = - -TimeConstants::DaysPerNonLeapYear * TimeConstants::SecondsPerDay; - struct tm *tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + -TimeConstants::DAYS_PER_NON_LEAP_YEAR * TimeConstants::SECONDS_PER_DAY; + struct Tm *tm_data = __llvm_libc::gmtime(&seconds); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 3, // wday - 0, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday 0}), *tm_data); } TEST(LlvmLibcGmTime, InvalidMonths) { time_t seconds = 0; - struct tm *tm_data = nullptr; + struct Tm *tm_data = nullptr; // -1 month from 1970-01-01 00:00:00 returns 1969-12-01 00:00:00. - seconds = -31 * TimeConstants::SecondsPerDay; + seconds = -31 * TimeConstants::SECONDS_PER_DAY; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 12 - 1, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 1, // wday - 0, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 1, // wday + 0, // yday 0}), *tm_data); // 1970-13-01 00:00:00 returns 1971-01-01 00:00:00. - seconds = TimeConstants::DaysPerNonLeapYear * TimeConstants::SecondsPerDay; + seconds = + TimeConstants::DAYS_PER_NON_LEAP_YEAR * TimeConstants::SECONDS_PER_DAY; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 1971 - TimeConstants::TimeYearBase, // year - 5, // wday - 0, // yday + 1971 - TimeConstants::TIME_YEAR_BASE, // year + 5, // wday + 0, // yday 0}), *tm_data); } TEST(LlvmLibcGmTime, InvalidDays) { time_t seconds = 0; - struct tm *tm_data = nullptr; + struct Tm *tm_data = nullptr; // -1 day from 1970-01-01 00:00:00 returns 1969-12-31 00:00:00. - seconds = -1 * TimeConstants::SecondsPerDay; + seconds = -1 * TimeConstants::SECONDS_PER_DAY; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 31, // day 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 3, // wday - 0, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday 0}), *tm_data); // 1970-01-32 00:00:00 returns 1970-02-01 00:00:00. - seconds = 31 * TimeConstants::SecondsPerDay; + seconds = 31 * TimeConstants::SECONDS_PER_DAY; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TimeYearBase, // year - 0, // wday - 0, // yday + 1970 - TimeConstants::TIME_YEAR_BASE, // year + 0, // wday + 0, // yday 0}), *tm_data); // 1970-02-29 00:00:00 returns 1970-03-01 00:00:00. - seconds = 59 * TimeConstants::SecondsPerDay; + seconds = 59 * TimeConstants::SECONDS_PER_DAY; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 2, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TimeYearBase, // year - 0, // wday - 0, // yday + 1970 - TimeConstants::TIME_YEAR_BASE, // year + 0, // wday + 0, // yday 0}), *tm_data); // 1972-02-30 00:00:00 returns 1972-03-01 00:00:00. - seconds = ((2 * TimeConstants::DaysPerNonLeapYear) + 60) * - TimeConstants::SecondsPerDay; + seconds = ((2 * TimeConstants::DAYS_PER_NON_LEAP_YEAR) + 60) * + TimeConstants::SECONDS_PER_DAY; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 2, // tm_mon starts with 0 for Jan - 1972 - TimeConstants::TimeYearBase, // year - 3, // wday - 0, // yday + 1972 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday 0}), *tm_data); } @@ -242,15 +244,15 @@ // Test for maximum value of a signed 32-bit integer. // Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC. time_t seconds = 0x7FFFFFFF; - struct tm *tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{7, // sec + struct Tm *tm_data = __llvm_libc::gmtime(&seconds); + EXPECT_TM_EQ((Tm{7, // sec 14, // min 3, // hr 19, // day 0, // tm_mon starts with 0 for Jan - 2038 - TimeConstants::TimeYearBase, // year - 2, // wday - 7, // yday + 2038 - TimeConstants::TIME_YEAR_BASE, // year + 2, // wday + 7, // yday 0}), *tm_data); } @@ -260,29 +262,29 @@ return; // Mon Jan 1 12:50:50 2170 (200 years from 1970), time_t seconds = 6311479850; - struct tm *tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{50, // sec + struct Tm *tm_data = __llvm_libc::gmtime(&seconds); + EXPECT_TM_EQ((Tm{50, // sec 50, // min 12, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 2170 - TimeConstants::TimeYearBase, // year - 1, // wday - 50, // yday + 2170 - TimeConstants::TIME_YEAR_BASE, // year + 1, // wday + 50, // yday 0}), *tm_data); // Test for Tue Jan 1 12:50:50 in 2,147,483,647th year. seconds = 67767976202043050; tm_data = __llvm_libc::gmtime(&seconds); - EXPECT_TM_EQ((tm{50, // sec + EXPECT_TM_EQ((Tm{50, // sec 50, // min 12, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 2147483647 - TimeConstants::TimeYearBase, // year - 2, // wday - 50, // yday + 2147483647 - TimeConstants::TIME_YEAR_BASE, // year + 2, // wday + 50, // yday 0}), *tm_data); } diff --git a/libc/test/src/time/mktime_test.cpp b/libc/test/src/time/mktime_test.cpp --- a/libc/test/src/time/mktime_test.cpp +++ b/libc/test/src/time/mktime_test.cpp @@ -21,7 +21,7 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; using __llvm_libc::time_utils::TimeConstants; -static inline time_t call_mktime(struct tm *tm_data, int year, int month, +static inline time_t call_mktime(struct Tm *tm_data, int year, int month, int mday, int hour, int min, int sec, int wday, int yday) { __llvm_libc::tmhelper::testing::InitializeTmData(tm_data, year, month, mday, @@ -30,14 +30,14 @@ } TEST(LlvmLibcMkTime, FailureSetsErrno) { - struct tm tm_data; + struct Tm tm_data; __llvm_libc::tmhelper::testing::InitializeTmData( &tm_data, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, -1, 0, 0); EXPECT_THAT(__llvm_libc::mktime(&tm_data), Fails(EOVERFLOW)); } TEST(LlvmLibcMkTime, InvalidSeconds) { - struct tm tm_data; + struct Tm tm_data; // -1 second from 1970-01-01 00:00:00 returns 1969-12-31 23:59:59. EXPECT_THAT(call_mktime(&tm_data, 1970, // year @@ -49,14 +49,14 @@ 0, // wday 0), // yday Succeeds(-1)); - EXPECT_TM_EQ((tm{59, // sec + EXPECT_TM_EQ((Tm{59, // sec 59, // min 23, // hr 31, // day 12 - 1, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 3, // wday - 364, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 364, // yday 0}), tm_data); // 60 seconds from 1970-01-01 00:00:00 returns 1970-01-01 00:01:00. @@ -70,20 +70,20 @@ 0, // wday 0), // yday Succeeds(60)); - EXPECT_TM_EQ((tm{0, // sec + EXPECT_TM_EQ((Tm{0, // sec 1, // min 0, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TimeYearBase, // year - 4, // wday - 0, // yday + 1970 - TimeConstants::TIME_YEAR_BASE, // year + 4, // wday + 0, // yday 0}), tm_data); } TEST(LlvmLibcMkTime, InvalidMinutes) { - struct tm tm_data; + struct Tm tm_data; // -1 minute from 1970-01-01 00:00:00 returns 1969-12-31 23:59:00. EXPECT_THAT(call_mktime(&tm_data, 1970, // year @@ -94,15 +94,15 @@ 0, // sec 0, // wday 0), // yday - Succeeds(-TimeConstants::SecondsPerMin)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(-TimeConstants::SECONDS_PER_MIN)); + EXPECT_TM_EQ((Tm{0, // sec 59, // min 23, // hr 31, // day 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 3, // wday - 0, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday 0}), tm_data); // 60 minutes from 1970-01-01 00:00:00 returns 1970-01-01 01:00:00. @@ -115,21 +115,21 @@ 0, // sec 0, // wday 0), // yday - Succeeds(60 * TimeConstants::SecondsPerMin)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(60 * TimeConstants::SECONDS_PER_MIN)); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 1, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TimeYearBase, // year - 4, // wday - 0, // yday + 1970 - TimeConstants::TIME_YEAR_BASE, // year + 4, // wday + 0, // yday 0}), tm_data); } TEST(LlvmLibcMkTime, InvalidHours) { - struct tm tm_data; + struct Tm tm_data; // -1 hour from 1970-01-01 00:00:00 returns 1969-12-31 23:00:00. EXPECT_THAT(call_mktime(&tm_data, 1970, // year @@ -140,15 +140,15 @@ 0, // sec 0, // wday 0), // yday - Succeeds(-TimeConstants::SecondsPerHour)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(-TimeConstants::SECONDS_PER_HOUR)); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 23, // hr 31, // day 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 3, // wday - 0, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday 0}), tm_data); // 24 hours from 1970-01-01 00:00:00 returns 1970-01-02 00:00:00. @@ -161,21 +161,21 @@ 0, // sec 0, // wday 0), // yday - Succeeds(24 * TimeConstants::SecondsPerHour)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(24 * TimeConstants::SECONDS_PER_HOUR)); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 2, // day 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TimeYearBase, // year - 5, // wday - 0, // yday + 1970 - TimeConstants::TIME_YEAR_BASE, // year + 5, // wday + 0, // yday 0}), tm_data); } TEST(LlvmLibcMkTime, InvalidYear) { - struct tm tm_data; + struct Tm tm_data; // -1 year from 1970-01-01 00:00:00 returns 1969-01-01 00:00:00. EXPECT_THAT(call_mktime(&tm_data, 1969, // year @@ -186,16 +186,16 @@ 0, // sec 0, // wday 0), // yday - Succeeds(-TimeConstants::DaysPerNonLeapYear * - TimeConstants::SecondsPerDay)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(-TimeConstants::DAYS_PER_NON_LEAP_YEAR * + TimeConstants::SECONDS_PER_DAY)); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 3, // wday - 0, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday 0}), tm_data); } @@ -203,29 +203,29 @@ TEST(LlvmLibcMkTime, InvalidEndOf32BitEpochYear) { if (sizeof(size_t) != 4) return; - struct tm tm_data; + struct Tm tm_data; // 2038-01-19 03:14:08 tests overflow of the second in 2038. EXPECT_THAT(call_mktime(&tm_data, 2038, 1, 19, 3, 14, 8, 0, 0), - Succeeds(TimeConstants::OutOfRangeReturnValue)); + Succeeds(TimeConstants::OUT_OF_RANGE_RETURN_VALUE)); // 2038-01-19 03:15:07 tests overflow of the minute in 2038. EXPECT_THAT(call_mktime(&tm_data, 2038, 1, 19, 3, 15, 7, 0, 0), - Succeeds(TimeConstants::OutOfRangeReturnValue)); + Succeeds(TimeConstants::OUT_OF_RANGE_RETURN_VALUE)); // 2038-01-19 04:14:07 tests overflow of the hour in 2038. EXPECT_THAT(call_mktime(&tm_data, 2038, 1, 19, 4, 14, 7, 0, 0), - Succeeds(TimeConstants::OutOfRangeReturnValue)); + Succeeds(TimeConstants::OUT_OF_RANGE_RETURN_VALUE)); // 2038-01-20 03:14:07 tests overflow of the day in 2038. EXPECT_THAT(call_mktime(&tm_data, 2038, 1, 20, 3, 14, 7, 0, 0), - Succeeds(TimeConstants::OutOfRangeReturnValue)); + Succeeds(TimeConstants::OUT_OF_RANGE_RETURN_VALUE)); // 2038-02-19 03:14:07 tests overflow of the month in 2038. EXPECT_THAT(call_mktime(&tm_data, 2038, 2, 19, 3, 14, 7, 0, 0), - Succeeds(TimeConstants::OutOfRangeReturnValue)); + Succeeds(TimeConstants::OUT_OF_RANGE_RETURN_VALUE)); // 2039-01-19 03:14:07 tests overflow of the year. EXPECT_THAT(call_mktime(&tm_data, 2039, 1, 19, 3, 14, 7, 0, 0), - Succeeds(TimeConstants::OutOfRangeReturnValue)); + Succeeds(TimeConstants::OUT_OF_RANGE_RETURN_VALUE)); } TEST(LlvmLibcMkTime, InvalidMonths) { - struct tm tm_data; + struct Tm tm_data; // -1 month from 1970-01-01 00:00:00 returns 1969-12-01 00:00:00. EXPECT_THAT(call_mktime(&tm_data, 1970, // year @@ -236,15 +236,15 @@ 0, // sec 0, // wday 0), // yday - Succeeds(-31 * TimeConstants::SecondsPerDay)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(-31 * TimeConstants::SECONDS_PER_DAY)); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 12 - 1, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 1, // wday - 0, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 1, // wday + 0, // yday 0}), tm_data); // 1970-13-01 00:00:00 returns 1971-01-01 00:00:00. @@ -257,22 +257,22 @@ 0, // sec 0, // wday 0), // yday - Succeeds(TimeConstants::DaysPerNonLeapYear * - TimeConstants::SecondsPerDay)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(TimeConstants::DAYS_PER_NON_LEAP_YEAR * + TimeConstants::SECONDS_PER_DAY)); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 1971 - TimeConstants::TimeYearBase, // year - 5, // wday - 0, // yday + 1971 - TimeConstants::TIME_YEAR_BASE, // year + 5, // wday + 0, // yday 0}), tm_data); } TEST(LlvmLibcMkTime, InvalidDays) { - struct tm tm_data; + struct Tm tm_data; // -1 day from 1970-01-01 00:00:00 returns 1969-12-31 00:00:00. EXPECT_THAT(call_mktime(&tm_data, 1970, // year @@ -283,15 +283,15 @@ 0, // sec 0, // wday 0), // yday - Succeeds(-1 * TimeConstants::SecondsPerDay)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(-1 * TimeConstants::SECONDS_PER_DAY)); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 31, // day 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TimeYearBase, // year - 3, // wday - 0, // yday + 1969 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday 0}), tm_data); @@ -305,15 +305,15 @@ 0, // sec 0, // wday 0), // yday - Succeeds(31 * TimeConstants::SecondsPerDay)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(31 * TimeConstants::SECONDS_PER_DAY)); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TimeYearBase, // year - 0, // wday - 0, // yday + 1970 - TimeConstants::TIME_YEAR_BASE, // year + 0, // wday + 0, // yday 0}), tm_data); @@ -327,15 +327,15 @@ 0, // sec 0, // wday 0), // yday - Succeeds(59 * TimeConstants::SecondsPerDay)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(59 * TimeConstants::SECONDS_PER_DAY)); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 2, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TimeYearBase, // year - 0, // wday - 0, // yday + 1970 - TimeConstants::TIME_YEAR_BASE, // year + 0, // wday + 0, // yday 0}), tm_data); @@ -349,22 +349,22 @@ 0, // sec 0, // wday 0), // yday - Succeeds(((2 * TimeConstants::DaysPerNonLeapYear) + 60) * - TimeConstants::SecondsPerDay)); - EXPECT_TM_EQ((tm{0, // sec + Succeeds(((2 * TimeConstants::DAYS_PER_NON_LEAP_YEAR) + 60) * + TimeConstants::SECONDS_PER_DAY)); + EXPECT_TM_EQ((Tm{0, // sec 0, // min 0, // hr 1, // day 2, // tm_mon starts with 0 for Jan - 1972 - TimeConstants::TimeYearBase, // year - 3, // wday - 0, // yday + 1972 - TimeConstants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday 0}), tm_data); } TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { - struct tm tm_data; + struct Tm tm_data; // Test for maximum value of a signed 32-bit integer. // Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC. EXPECT_THAT(call_mktime(&tm_data, @@ -377,14 +377,14 @@ 0, // wday 0), // yday Succeeds(0x7FFFFFFF)); - EXPECT_TM_EQ((tm{7, // sec + EXPECT_TM_EQ((Tm{7, // sec 14, // min 3, // hr 19, // day 0, // tm_mon starts with 0 for Jan - 2038 - TimeConstants::TimeYearBase, // year - 2, // wday - 7, // yday + 2038 - TimeConstants::TIME_YEAR_BASE, // year + 2, // wday + 7, // yday 0}), tm_data); } @@ -393,7 +393,7 @@ if (sizeof(time_t) == 4) return; // Mon Jan 1 12:50:50 2170 (200 years from 1970), - struct tm tm_data; + struct Tm tm_data; EXPECT_THAT(call_mktime(&tm_data, 2170, // year 1, // month @@ -404,28 +404,28 @@ 0, // wday 0), // yday Succeeds(6311479850)); - EXPECT_TM_EQ((tm{50, // sec + EXPECT_TM_EQ((Tm{50, // sec 50, // min 12, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 2170 - TimeConstants::TimeYearBase, // year - 1, // wday - 50, // yday + 2170 - TimeConstants::TIME_YEAR_BASE, // year + 1, // wday + 50, // yday 0}), tm_data); // Test for Tue Jan 1 12:50:50 in 2,147,483,647th year. EXPECT_THAT(call_mktime(&tm_data, 2147483647, 1, 1, 12, 50, 50, 0, 0), Succeeds(67767976202043050)); - EXPECT_TM_EQ((tm{50, // sec + EXPECT_TM_EQ((Tm{50, // sec 50, // min 12, // hr 1, // day 0, // tm_mon starts with 0 for Jan - 2147483647 - TimeConstants::TimeYearBase, // year - 2, // wday - 50, // yday + 2147483647 - TimeConstants::TIME_YEAR_BASE, // year + 2, // wday + 50, // yday 0}), tm_data); } diff --git a/libc/test/utils/FPUtil/x86_long_double_test.cpp b/libc/test/utils/FPUtil/x86_long_double_test.cpp --- a/libc/test/utils/FPUtil/x86_long_double_test.cpp +++ b/libc/test/utils/FPUtil/x86_long_double_test.cpp @@ -13,7 +13,7 @@ using FPBits = __llvm_libc::fputil::FPBits; -TEST(X86LongDoubleTest, isNaN) { +TEST(X86LongDoubleTest, is_nan) { // In the nan checks below, we use the macro isnan from math.h to ensure that // a number is actually a NaN. The isnan macro resolves to the compiler // builtin function. Hence, matching LLVM-libc's notion of NaN with the @@ -21,14 +21,14 @@ // behavior. FPBits bits(0.0l); - bits.exponent = FPBits::maxExponent; + bits.exponent = FPBits::MAX_EXPONENT; for (unsigned int i = 0; i < 1000000; ++i) { // If exponent has the max value and the implicit bit is 0, // then the number is a NaN for all values of mantissa. bits.mantissa = i; long double nan = bits; ASSERT_NE(isnan(nan), 0); - ASSERT_TRUE(bits.isNaN()); + ASSERT_TRUE(bits.is_nan()); } bits.implicitBit = 1; @@ -39,7 +39,7 @@ bits.mantissa = i; long double nan = bits; ASSERT_NE(isnan(nan), 0); - ASSERT_TRUE(bits.isNaN()); + ASSERT_TRUE(bits.is_nan()); } bits.exponent = 1; @@ -50,7 +50,7 @@ bits.mantissa = i; long double nan = bits; ASSERT_NE(isnan(nan), 0); - ASSERT_TRUE(bits.isNaN()); + ASSERT_TRUE(bits.is_nan()); } bits.exponent = 1; @@ -61,7 +61,7 @@ bits.mantissa = i; long double valid = bits; ASSERT_EQ(isnan(valid), 0); - ASSERT_FALSE(bits.isNaN()); + ASSERT_FALSE(bits.is_nan()); } bits.exponent = 0; @@ -71,7 +71,7 @@ bits.mantissa = i; long double valid = bits; ASSERT_EQ(isnan(valid), 0); - ASSERT_FALSE(bits.isNaN()); + ASSERT_FALSE(bits.is_nan()); } bits.exponent = 0; @@ -81,6 +81,6 @@ bits.mantissa = i; long double valid = bits; ASSERT_EQ(isnan(valid), 0); - ASSERT_FALSE(bits.isNaN()); + ASSERT_FALSE(bits.is_nan()); } } diff --git a/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp b/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp --- a/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp +++ b/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp @@ -64,7 +64,7 @@ if (i < size - 1) OS << ", "; } - OS << "), decltype(" << entrypoint << ")>::Value, "; + OS << "), decltype(" << entrypoint << ")>::VALUE, "; OS << '"' << entrypoint << " prototype in TableGen does not match public header" << '"'; OS << ");\n"; diff --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h --- a/libc/utils/MPFRWrapper/MPFRUtils.h +++ b/libc/utils/MPFRWrapper/MPFRUtils.h @@ -72,7 +72,7 @@ template struct BinaryInput { static_assert( - __llvm_libc::cpp::IsFloatingPointType::Value, + __llvm_libc::cpp::IsFloatingPointType::VALUE, "Template parameter of BinaryInput must be a floating point type."); using Type = T; @@ -81,7 +81,7 @@ template struct TernaryInput { static_assert( - __llvm_libc::cpp::IsFloatingPointType::Value, + __llvm_libc::cpp::IsFloatingPointType::VALUE, "Template parameter of TernaryInput must be a floating point type."); using Type = T; @@ -102,7 +102,7 @@ template struct AreMatchingBinaryInputAndBinaryOutput, BinaryOutput> { - static constexpr bool value = cpp::IsFloatingPointType::Value; + static constexpr bool value = cpp::IsFloatingPointType::VALUE; }; template @@ -234,24 +234,24 @@ constexpr bool isValidOperation() { return (Operation::BeginUnaryOperationsSingleOutput < op && op < Operation::EndUnaryOperationsSingleOutput && - cpp::IsSame::Value && - cpp::IsFloatingPointType::Value) || + cpp::IsSame::VALUE && + cpp::IsFloatingPointType::VALUE) || (Operation::BeginUnaryOperationsTwoOutputs < op && op < Operation::EndUnaryOperationsTwoOutputs && - cpp::IsFloatingPointType::Value && - cpp::IsSame>::Value) || + cpp::IsFloatingPointType::VALUE && + cpp::IsSame>::VALUE) || (Operation::BeginBinaryOperationsSingleOutput < op && op < Operation::EndBinaryOperationsSingleOutput && - cpp::IsFloatingPointType::Value && - cpp::IsSame>::Value) || + cpp::IsFloatingPointType::VALUE && + cpp::IsSame>::VALUE) || (Operation::BeginBinaryOperationsTwoOutputs < op && op < Operation::EndBinaryOperationsTwoOutputs && internal::AreMatchingBinaryInputAndBinaryOutput::value) || (Operation::BeginTernaryOperationsSingleOuput < op && op < Operation::EndTernaryOperationsSingleOutput && - cpp::IsFloatingPointType::Value && - cpp::IsSame>::Value); + cpp::IsFloatingPointType::VALUE && + cpp::IsSame>::VALUE); } template diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp --- a/libc/utils/MPFRWrapper/MPFRUtils.cpp +++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp @@ -69,28 +69,28 @@ // conversions. Implicit conversions can potentially lead to loss of // precision. template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> explicit MPFRNumber(XType x, int precision = 128) : mpfrPrecision(precision) { mpfr_init2(value, mpfrPrecision); mpfr_set_flt(value, x, MPFR_RNDN); } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> explicit MPFRNumber(XType x, int precision = 128) : mpfrPrecision(precision) { mpfr_init2(value, mpfrPrecision); mpfr_set_d(value, x, MPFR_RNDN); } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> explicit MPFRNumber(XType x, int precision = 128) : mpfrPrecision(precision) { mpfr_init2(value, mpfrPrecision); mpfr_set_ld(value, x, MPFR_RNDN); } template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> explicit MPFRNumber(XType x, int precision = 128) : mpfrPrecision(precision) { mpfr_init2(value, mpfrPrecision); mpfr_set_sj(value, x, MPFR_RNDN); @@ -305,13 +305,13 @@ // of N between this number and [input]. // 4. A values of +0.0 and -0.0 are treated as equal. template - cpp::EnableIfType::Value, double> ulp(T input) { + cpp::EnableIfType::VALUE, double> ulp(T input) { T thisAsT = as(); if (thisAsT == input) return T(0.0); - int thisExponent = fputil::FPBits(thisAsT).getExponent(); - int inputExponent = fputil::FPBits(input).getExponent(); + int thisExponent = fputil::FPBits(thisAsT).get_exponent(); + int inputExponent = fputil::FPBits(input).get_exponent(); if (thisAsT * input < 0 || thisExponent == inputExponent) { MPFRNumber inputMPFR(input); mpfr_sub(inputMPFR.value, value, inputMPFR.value, MPFR_RNDN); @@ -327,8 +327,8 @@ input = std::abs(input); T min = thisAsT > input ? input : thisAsT; T max = thisAsT > input ? thisAsT : input; - int minExponent = fputil::FPBits(min).getExponent(); - int maxExponent = fputil::FPBits(max).getExponent(); + int minExponent = fputil::FPBits(min).get_exponent(); + int maxExponent = fputil::FPBits(max).get_exponent(); MPFRNumber minMPFR(min); MPFRNumber maxMPFR(max); @@ -350,7 +350,7 @@ namespace internal { template -cpp::EnableIfType::Value, MPFRNumber> +cpp::EnableIfType::VALUE, MPFRNumber> unaryOperation(Operation op, InputType input) { MPFRNumber mpfrInput(input); switch (op) { @@ -390,7 +390,7 @@ } template -cpp::EnableIfType::Value, MPFRNumber> +cpp::EnableIfType::VALUE, MPFRNumber> unaryOperationTwoOutputs(Operation op, InputType input, int &output) { MPFRNumber mpfrInput(input); switch (op) { @@ -402,7 +402,7 @@ } template -cpp::EnableIfType::Value, MPFRNumber> +cpp::EnableIfType::VALUE, MPFRNumber> binaryOperationOneOutput(Operation op, InputType x, InputType y) { MPFRNumber inputX(x), inputY(y); switch (op) { @@ -414,7 +414,7 @@ } template -cpp::EnableIfType::Value, MPFRNumber> +cpp::EnableIfType::VALUE, MPFRNumber> binaryOperationTwoOutputs(Operation op, InputType x, InputType y, int &output) { MPFRNumber inputX(x), inputY(y); switch (op) { @@ -426,7 +426,7 @@ } template -cpp::EnableIfType::Value, MPFRNumber> +cpp::EnableIfType::VALUE, MPFRNumber> ternaryOperationOneOutput(Operation op, InputType x, InputType y, InputType z) { // For FMA function, we just need to compare with the mpfr_fma with the same // precision as InputType. Using higher precision as the intermediate results diff --git a/libc/utils/UnitTest/FPMatcher.h b/libc/utils/UnitTest/FPMatcher.h --- a/libc/utils/UnitTest/FPMatcher.h +++ b/libc/utils/UnitTest/FPMatcher.h @@ -18,13 +18,13 @@ namespace testing { template -cpp::EnableIfType::Value, void> +cpp::EnableIfType::VALUE, void> describeValue(const char *label, ValType value, testutils::StreamWrapper &stream); template class FPMatcher : public __llvm_libc::testing::Matcher { - static_assert(__llvm_libc::cpp::IsFloatingPointType::Value, + static_assert(__llvm_libc::cpp::IsFloatingPointType::VALUE, "FPMatcher can only be used with floating point values."); static_assert(Condition == __llvm_libc::testing::Cond_EQ || Condition == __llvm_libc::testing::Cond_NE, @@ -40,13 +40,13 @@ actual = actualValue; fputil::FPBits actualBits(actual), expectedBits(expected); if (Condition == __llvm_libc::testing::Cond_EQ) - return (actualBits.isNaN() && expectedBits.isNaN()) || + return (actualBits.is_nan() && expectedBits.is_nan()) || (actualBits.uintval() == expectedBits.uintval()); // If condition == Cond_NE. - if (actualBits.isNaN()) - return !expectedBits.isNaN(); - return expectedBits.isNaN() || + if (actualBits.is_nan()) + return !expectedBits.is_nan(); + return expectedBits.is_nan() || (actualBits.uintval() != expectedBits.uintval()); } @@ -69,10 +69,10 @@ using FPBits = __llvm_libc::fputil::FPBits; \ using UIntType = typename FPBits::UIntType; \ const T zero = T(FPBits::zero()); \ - const T negZero = T(FPBits::negZero()); \ - const T aNaN = T(FPBits::buildNaN(1)); \ + const T neg_zero = T(FPBits::neg_zero()); \ + const T aNaN = T(FPBits::build_nan(1)); \ const T inf = T(FPBits::inf()); \ - const T negInf = T(FPBits::negInf()); + const T neg_inf = T(FPBits::neg_inf()); #define EXPECT_FP_EQ(expected, actual) \ EXPECT_THAT( \ diff --git a/libc/utils/UnitTest/FPMatcher.cpp b/libc/utils/UnitTest/FPMatcher.cpp --- a/libc/utils/UnitTest/FPMatcher.cpp +++ b/libc/utils/UnitTest/FPMatcher.cpp @@ -18,7 +18,7 @@ // Return the first N hex digits of an integer as a string in upper case. template -cpp::EnableIfType::Value, std::string> +cpp::EnableIfType::VALUE, std::string> uintToHex(T X, size_t Length = sizeof(T) * 2) { std::string s(Length, '0'); @@ -31,33 +31,33 @@ } template -cpp::EnableIfType::Value, void> +cpp::EnableIfType::VALUE, void> describeValue(const char *label, ValType value, testutils::StreamWrapper &stream) { stream << label; FPBits bits(value); - if (bits.isNaN()) { + if (bits.is_nan()) { stream << "(NaN)"; - } else if (bits.isInf()) { - if (bits.getSign()) + } else if (bits.is_inf()) { + if (bits.get_sign()) stream << "(-Infinity)"; else stream << "(+Infinity)"; } else { constexpr int exponentWidthInHex = - (fputil::ExponentWidth::value - 1) / 4 + 1; + (fputil::ExponentWidth::VALUE - 1) / 4 + 1; constexpr int mantissaWidthInHex = - (fputil::MantissaWidth::value - 1) / 4 + 1; + (fputil::MantissaWidth::VALUE - 1) / 4 + 1; - stream << "Sign: " << (bits.getSign() ? '1' : '0') << ", " + stream << "Sign: " << (bits.get_sign() ? '1' : '0') << ", " << "Exponent: 0x" - << uintToHex(bits.getUnbiasedExponent(), + << uintToHex(bits.get_unbiased_exponent(), exponentWidthInHex) << ", " << "Mantissa: 0x" << uintToHex::UIntType>( - bits.getMantissa(), mantissaWidthInHex); + bits.get_mantissa(), mantissaWidthInHex); } stream << '\n'; diff --git a/libc/utils/UnitTest/LibcTest.h b/libc/utils/UnitTest/LibcTest.h --- a/libc/utils/UnitTest/LibcTest.h +++ b/libc/utils/UnitTest/LibcTest.h @@ -83,7 +83,7 @@ // |Cond| on mismatched |LHS| and |RHS| types can potentially succeed because // of type promotion. template ::Value, int> = 0> + cpp::EnableIfType::VALUE, int> = 0> bool test(TestCondition Cond, ValType LHS, ValType RHS, const char *LHSStr, const char *RHSStr, const char *File, unsigned long Line) { return internal::test(Ctx, Cond, LHS, RHS, LHSStr, RHSStr, File, Line); @@ -91,7 +91,7 @@ template < typename ValType, - cpp::EnableIfType::Value, ValType> = nullptr> + cpp::EnableIfType::VALUE, ValType> = nullptr> bool test(TestCondition Cond, ValType LHS, ValType RHS, const char *LHSStr, const char *RHSStr, const char *File, unsigned long Line) { return internal::test(Ctx, Cond, (unsigned long long)LHS, diff --git a/libc/utils/UnitTest/LibcTest.cpp b/libc/utils/UnitTest/LibcTest.cpp --- a/libc/utils/UnitTest/LibcTest.cpp +++ b/libc/utils/UnitTest/LibcTest.cpp @@ -35,7 +35,7 @@ // When the value is of integral type, just display it as normal. template -cpp::EnableIfType::Value, std::string> +cpp::EnableIfType::VALUE, std::string> describeValue(ValType Value) { return std::to_string(Value); }