[libc][Obvious] Change all __builtin_clz* calls to clz in builtin_wrappers.h.
authorTue Ly <lntue@google.com>
Fri, 10 Jun 2022 20:00:13 +0000 (16:00 -0400)
committerTue Ly <lntue@google.com>
Fri, 10 Jun 2022 20:03:10 +0000 (16:03 -0400)
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

index bcb1cb2..dc1056b 100644 (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) {
-  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
index 03ea57d..cd3a5ec 100644 (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) {
index b754704..0fa720b 100644 (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;
index b654c4b..30a1f0e 100644 (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) {