[libc][Obvious] Change all __builtin_clz* calls to clz in builtin_wrappers.h.

This commit is contained in:
Tue Ly 2022-06-10 16:00:13 -04:00
parent 08ea27bf13
commit 2a746ebf1a
4 changed files with 9 additions and 39 deletions

View File

@ -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 <typename T>
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>(unsigned int 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_clz(mant);
shift_length = (sizeof(mant) * 8) - 1 - clz(mant);
}
return 1U << shift_length;
}
template <>
inline unsigned long find_leading_one<unsigned long>(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>(unsigned long long mant,
int &shift_length) {
shift_length = 0;
if (mant > 0) {
shift_length = (sizeof(mant) * 8) - 1 - __builtin_clzll(mant);
}
return 1ULL << shift_length;
return T(1) << shift_length;
}
} // namespace internal

View File

@ -32,8 +32,6 @@ template <> struct SpecialLongDouble<long double> {
};
#endif // SPECIAL_X86_LONG_DOUBLE
using fputil::ctz;
template <typename T>
static inline void normalize(int &exponent,
typename FPBits<T>::UIntType &mantissa) {

View File

@ -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<uint64_t>(mantissa)) -
clz(static_cast<uint64_t>(mantissa)) -
(8 * sizeof(uint64_t) - 1 - MantissaWidth<long double>::VALUE);
exponent -= shift;
mantissa <<= shift;

View File

@ -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 <class T> uint32_t inline leading_zeroes(T inputNumber) {
}
template <> uint32_t inline leading_zeroes<uint32_t>(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>(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) {