[llvm] 8e4dc4c - [Support] Use functions from bit.h (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 22 10:41:19 PST 2023
Author: Kazu Hirata
Date: 2023-01-22T10:41:13-08:00
New Revision: 8e4dc4cfb81e8baf4692d78226fcac6e47acc133
URL: https://github.com/llvm/llvm-project/commit/8e4dc4cfb81e8baf4692d78226fcac6e47acc133
DIFF: https://github.com/llvm/llvm-project/commit/8e4dc4cfb81e8baf4692d78226fcac6e47acc133.diff
LOG: [Support] Use functions from bit.h (NFC)
This patch makes the following replacements:
countLeadingZeros -> llvm::countl_zero
countTrailingZeros -> llvm::countr_zero
countPopulation -> llvm::popcount
Added:
Modified:
llvm/include/llvm/Support/MathExtras.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index 9777a2b0c05df..b2b2721d03310 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -102,7 +102,7 @@ template <typename T> T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) {
if (ZB == ZB_Max && Val == 0)
return std::numeric_limits<T>::max();
- return countTrailingZeros(Val);
+ return llvm::countr_zero(Val);
}
/// Create a bitmask with the N right-most bits set to 1, and all other
@@ -144,7 +144,7 @@ template <typename T> T findLastSet(T Val, ZeroBehavior ZB = ZB_Max) {
// Use ^ instead of - because both gcc and llvm can remove the associated ^
// in the __builtin_clz intrinsic on x86.
- return countLeadingZeros(Val) ^ (std::numeric_limits<T>::digits - 1);
+ return llvm::countl_zero(Val) ^ (std::numeric_limits<T>::digits - 1);
}
/// Macro compressed bit reversal table for 256 bits.
@@ -375,8 +375,8 @@ inline bool isShiftedMask_32(uint32_t Value, unsigned &MaskIdx,
unsigned &MaskLen) {
if (!isShiftedMask_32(Value))
return false;
- MaskIdx = countTrailingZeros(Value);
- MaskLen = countPopulation(Value);
+ MaskIdx = llvm::countr_zero(Value);
+ MaskLen = llvm::popcount(Value);
return true;
}
@@ -388,8 +388,8 @@ inline bool isShiftedMask_64(uint64_t Value, unsigned &MaskIdx,
unsigned &MaskLen) {
if (!isShiftedMask_64(Value))
return false;
- MaskIdx = countTrailingZeros(Value);
- MaskLen = countPopulation(Value);
+ MaskIdx = llvm::countr_zero(Value);
+ MaskLen = llvm::popcount(Value);
return true;
}
@@ -407,26 +407,26 @@ template <> constexpr inline size_t CTLog2<1>() { return 0; }
/// (32 bit edition.)
/// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2
inline unsigned Log2_32(uint32_t Value) {
- return 31 - countLeadingZeros(Value);
+ return 31 - llvm::countl_zero(Value);
}
/// Return the floor log base 2 of the specified value, -1 if the value is zero.
/// (64 bit edition.)
inline unsigned Log2_64(uint64_t Value) {
- return 63 - countLeadingZeros(Value);
+ return 63 - llvm::countl_zero(Value);
}
/// Return the ceil log base 2 of the specified value, 32 if the value is zero.
/// (32 bit edition).
/// Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3
inline unsigned Log2_32_Ceil(uint32_t Value) {
- return 32 - countLeadingZeros(Value - 1);
+ return 32 - llvm::countl_zero(Value - 1);
}
/// Return the ceil log base 2 of the specified value, 64 if the value is zero.
/// (64 bit edition.)
inline unsigned Log2_64_Ceil(uint64_t Value) {
- return 64 - countLeadingZeros(Value - 1);
+ return 64 - llvm::countl_zero(Value - 1);
}
/// This function takes a 64-bit integer and returns the bit equivalent double.
@@ -484,7 +484,7 @@ constexpr inline uint64_t NextPowerOf2(uint64_t A) {
/// Essentially, it is a floor operation across the domain of powers of two.
inline uint64_t PowerOf2Floor(uint64_t A) {
if (!A) return 0;
- return 1ull << (63 - countLeadingZeros(A));
+ return 1ull << (63 - llvm::countl_zero(A));
}
/// Returns the power of two which is greater than or equal to the given value.
More information about the llvm-commits
mailing list