#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"
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) {
- 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>(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) {
+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
#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 {
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;
#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"
}
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) {