[libc-commits] [libc] 2a746eb - [libc][Obvious] Change all __builtin_clz* calls to clz in builtin_wrappers.h.
Tue Ly via libc-commits
libc-commits at lists.llvm.org
Fri Jun 10 13:03:32 PDT 2022
Author: Tue Ly
Date: 2022-06-10T16:03:10-04:00
New Revision: 2a746ebf1a4e746f0a3797146fc6750b607e896a
URL: https://github.com/llvm/llvm-project/commit/2a746ebf1a4e746f0a3797146fc6750b607e896a
DIFF: https://github.com/llvm/llvm-project/commit/2a746ebf1a4e746f0a3797146fc6750b607e896a.diff
LOG: [libc][Obvious] Change all __builtin_clz* calls to clz in builtin_wrappers.h.
Added:
Modified:
libc/src/__support/FPUtil/Hypot.h
libc/src/__support/FPUtil/generic/sqrt.h
libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
libc/src/__support/str_to_float.h
Removed:
################################################################################
diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index bcb1cb2d9c84f..dc1056b22289c 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 <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
diff --git a/libc/src/__support/FPUtil/generic/sqrt.h b/libc/src/__support/FPUtil/generic/sqrt.h
index 03ea57d699433..cd3a5ec48c82c 100644
--- a/libc/src/__support/FPUtil/generic/sqrt.h
+++ b/libc/src/__support/FPUtil/generic/sqrt.h
@@ -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) {
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 b7547045196e3..0fa720b1ae8ae 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<uint64_t>(mantissa)) -
+ clz(static_cast<uint64_t>(mantissa)) -
(8 * sizeof(uint64_t) - 1 - MantissaWidth<long double>::VALUE);
exponent -= shift;
mantissa <<= shift;
diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h
index b654c4b3c7396..30a1f0eb4a9bc 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 <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) {
More information about the libc-commits
mailing list