Skip to content

Commit 2a746eb

Browse files
committed
[libc][Obvious] Change all __builtin_clz* calls to clz in builtin_wrappers.h.
1 parent 08ea27b commit 2a746eb

File tree

4 files changed

+9
-39
lines changed

4 files changed

+9
-39
lines changed

libc/src/__support/FPUtil/Hypot.h

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "BasicOperations.h"
1313
#include "FEnvImpl.h"
1414
#include "FPBits.h"
15+
#include "builtin_wrappers.h"
1516
#include "src/__support/CPP/Bit.h"
1617
#include "src/__support/CPP/TypeTraits.h"
1718

@@ -21,43 +22,12 @@ namespace fputil {
2122
namespace internal {
2223

2324
template <typename T>
24-
static inline T find_leading_one(T mant, int &shift_length);
25-
26-
// The following overloads are matched based on what is accepted by
27-
// __builtin_clz* rather than using the exactly-sized aliases from stdint.h
28-
// (such as uint32_t). There are 3 overloads even though 2 will only ever be
29-
// used by a specific platform, since unsigned long varies in size depending on
30-
// the word size of the architecture.
31-
32-
template <>
33-
inline unsigned int find_leading_one<unsigned int>(unsigned int mant,
34-
int &shift_length) {
35-
shift_length = 0;
36-
if (mant > 0) {
37-
shift_length = (sizeof(mant) * 8) - 1 - __builtin_clz(mant);
38-
}
39-
return 1U << shift_length;
40-
}
41-
42-
template <>
43-
inline unsigned long find_leading_one<unsigned long>(unsigned long mant,
44-
int &shift_length) {
45-
shift_length = 0;
46-
if (mant > 0) {
47-
shift_length = (sizeof(mant) * 8) - 1 - __builtin_clzl(mant);
48-
}
49-
return 1UL << shift_length;
50-
}
51-
52-
template <>
53-
inline unsigned long long
54-
find_leading_one<unsigned long long>(unsigned long long mant,
55-
int &shift_length) {
25+
static inline T find_leading_one(T mant, int &shift_length) {
5626
shift_length = 0;
5727
if (mant > 0) {
58-
shift_length = (sizeof(mant) * 8) - 1 - __builtin_clzll(mant);
28+
shift_length = (sizeof(mant) * 8) - 1 - clz(mant);
5929
}
60-
return 1ULL << shift_length;
30+
return T(1) << shift_length;
6131
}
6232

6333
} // namespace internal

libc/src/__support/FPUtil/generic/sqrt.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ template <> struct SpecialLongDouble<long double> {
3232
};
3333
#endif // SPECIAL_X86_LONG_DOUBLE
3434

35-
using fputil::ctz;
36-
3735
template <typename T>
3836
static inline void normalize(int &exponent,
3937
typename FPBits<T>::UIntType &mantissa) {

libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
#include "src/__support/FPUtil/FEnvImpl.h"
1313
#include "src/__support/FPUtil/FPBits.h"
1414
#include "src/__support/FPUtil/PlatformDefs.h"
15+
#include "src/__support/FPUtil/builtin_wrappers.h"
1516

1617
namespace __llvm_libc {
1718
namespace fputil {
1819
namespace x86 {
1920

2021
inline void normalize(int &exponent, __uint128_t &mantissa) {
2122
const int shift =
22-
__builtin_clzll(static_cast<uint64_t>(mantissa)) -
23+
clz(static_cast<uint64_t>(mantissa)) -
2324
(8 * sizeof(uint64_t) - 1 - MantissaWidth<long double>::VALUE);
2425
exponent -= shift;
2526
mantissa <<= shift;

libc/src/__support/str_to_float.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "src/__support/CPP/Limits.h"
1313
#include "src/__support/FPUtil/FPBits.h"
14+
#include "src/__support/FPUtil/builtin_wrappers.h"
1415
#include "src/__support/ctype_utils.h"
1516
#include "src/__support/detailed_powers_of_ten.h"
1617
#include "src/__support/high_precision_decimal.h"
@@ -50,11 +51,11 @@ template <class T> uint32_t inline leading_zeroes(T inputNumber) {
5051
}
5152

5253
template <> uint32_t inline leading_zeroes<uint32_t>(uint32_t inputNumber) {
53-
return inputNumber == 0 ? 32 : __builtin_clz(inputNumber);
54+
return inputNumber == 0 ? 32 : fputil::clz(inputNumber);
5455
}
5556

5657
template <> uint32_t inline leading_zeroes<uint64_t>(uint64_t inputNumber) {
57-
return inputNumber == 0 ? 64 : __builtin_clzll(inputNumber);
58+
return inputNumber == 0 ? 64 : fputil::clz(inputNumber);
5859
}
5960

6061
static inline uint64_t low64(__uint128_t num) {

0 commit comments

Comments
 (0)