From 2a746ebf1a4e746f0a3797146fc6750b607e896a Mon Sep 17 00:00:00 2001 From: Tue Ly Date: Fri, 10 Jun 2022 16:00:13 -0400 Subject: [PATCH] [libc][Obvious] Change all __builtin_clz* calls to clz in builtin_wrappers.h. --- libc/src/__support/FPUtil/Hypot.h | 38 +++------------------- libc/src/__support/FPUtil/generic/sqrt.h | 2 -- .../FPUtil/generic/sqrt_80_bit_long_double.h | 3 +- libc/src/__support/str_to_float.h | 5 +-- 4 files changed, 9 insertions(+), 39 deletions(-) diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h index bcb1cb2..dc1056b 100644 --- a/libc/src/__support/FPUtil/Hypot.h +++ b/libc/src/__support/FPUtil/Hypot.h @@ -12,6 +12,7 @@ #include "BasicOperations.h" #include "FEnvImpl.h" #include "FPBits.h" +#include "builtin_wrappers.h" #include "src/__support/CPP/Bit.h" #include "src/__support/CPP/TypeTraits.h" @@ -21,43 +22,12 @@ namespace fputil { namespace internal { template -static inline T find_leading_one(T mant, int &shift_length); - -// The following overloads are matched based on what is accepted by -// __builtin_clz* rather than using the exactly-sized aliases from stdint.h -// (such as uint32_t). There are 3 overloads even though 2 will only ever be -// used by a specific platform, since unsigned long varies in size depending on -// the word size of the architecture. - -template <> -inline unsigned int find_leading_one(unsigned int mant, - int &shift_length) { - shift_length = 0; - if (mant > 0) { - shift_length = (sizeof(mant) * 8) - 1 - __builtin_clz(mant); - } - return 1U << shift_length; -} - -template <> -inline unsigned long find_leading_one(unsigned long mant, - int &shift_length) { - shift_length = 0; - if (mant > 0) { - shift_length = (sizeof(mant) * 8) - 1 - __builtin_clzl(mant); - } - return 1UL << shift_length; -} - -template <> -inline unsigned long long -find_leading_one(unsigned long long mant, - int &shift_length) { +static inline T find_leading_one(T mant, int &shift_length) { shift_length = 0; if (mant > 0) { - shift_length = (sizeof(mant) * 8) - 1 - __builtin_clzll(mant); + shift_length = (sizeof(mant) * 8) - 1 - clz(mant); } - return 1ULL << shift_length; + return T(1) << shift_length; } } // namespace internal diff --git a/libc/src/__support/FPUtil/generic/sqrt.h b/libc/src/__support/FPUtil/generic/sqrt.h index 03ea57d..cd3a5ec 100644 --- a/libc/src/__support/FPUtil/generic/sqrt.h +++ b/libc/src/__support/FPUtil/generic/sqrt.h @@ -32,8 +32,6 @@ template <> struct SpecialLongDouble { }; #endif // SPECIAL_X86_LONG_DOUBLE -using fputil::ctz; - template static inline void normalize(int &exponent, typename FPBits::UIntType &mantissa) { diff --git a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h index b754704..0fa720b 100644 --- a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h +++ b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h @@ -12,6 +12,7 @@ #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/PlatformDefs.h" +#include "src/__support/FPUtil/builtin_wrappers.h" namespace __llvm_libc { namespace fputil { @@ -19,7 +20,7 @@ namespace x86 { inline void normalize(int &exponent, __uint128_t &mantissa) { const int shift = - __builtin_clzll(static_cast(mantissa)) - + clz(static_cast(mantissa)) - (8 * sizeof(uint64_t) - 1 - MantissaWidth::VALUE); exponent -= shift; mantissa <<= shift; diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h index b654c4b..30a1f0e 100644 --- a/libc/src/__support/str_to_float.h +++ b/libc/src/__support/str_to_float.h @@ -11,6 +11,7 @@ #include "src/__support/CPP/Limits.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/builtin_wrappers.h" #include "src/__support/ctype_utils.h" #include "src/__support/detailed_powers_of_ten.h" #include "src/__support/high_precision_decimal.h" @@ -50,11 +51,11 @@ template uint32_t inline leading_zeroes(T inputNumber) { } template <> uint32_t inline leading_zeroes(uint32_t inputNumber) { - return inputNumber == 0 ? 32 : __builtin_clz(inputNumber); + return inputNumber == 0 ? 32 : fputil::clz(inputNumber); } template <> uint32_t inline leading_zeroes(uint64_t inputNumber) { - return inputNumber == 0 ? 64 : __builtin_clzll(inputNumber); + return inputNumber == 0 ? 64 : fputil::clz(inputNumber); } static inline uint64_t low64(__uint128_t num) { -- 2.7.4