Skip to content

Commit 32ac9db

Browse files
[Support] Remove findFirstSet and findLastSet
This patch removes findFirstSet and findLastSet as there are no uses left in LLVM. I am not aware of any uses of findFirstSet and findLastSet in the open-source world outside LLVM, so I am skipping the deprecation step. Differential Revision: https://reviews.llvm.org/D142603
1 parent 1b9fbc8 commit 32ac9db

File tree

2 files changed

+0
-76
lines changed

2 files changed

+0
-76
lines changed

llvm/include/llvm/Support/MathExtras.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424

2525
namespace llvm {
2626

27-
/// The behavior an operation has on an input of 0.
28-
enum ZeroBehavior {
29-
/// The returned value is undefined.
30-
ZB_Undefined,
31-
/// The returned value is numeric_limits<T>::max()
32-
ZB_Max
33-
};
34-
3527
/// Mathematical constants.
3628
namespace numbers {
3729
// TODO: Track C++20 std::numbers.
@@ -92,19 +84,6 @@ template <typename T> unsigned countLeadingZeros(T Val) {
9284
return llvm::countl_zero(Val);
9385
}
9486

95-
/// Get the index of the first set bit starting from the least
96-
/// significant bit.
97-
///
98-
/// Only unsigned integral types are allowed.
99-
///
100-
/// \param ZB the behavior on an input of 0.
101-
template <typename T> T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) {
102-
if (ZB == ZB_Max && Val == 0)
103-
return std::numeric_limits<T>::max();
104-
105-
return llvm::countr_zero(Val);
106-
}
107-
10887
/// Create a bitmask with the N right-most bits set to 1, and all other
10988
/// bits set to 0. Only unsigned types are allowed.
11089
template <typename T> T maskTrailingOnes(unsigned N) {
@@ -132,21 +111,6 @@ template <typename T> T maskLeadingZeros(unsigned N) {
132111
return maskTrailingOnes<T>(CHAR_BIT * sizeof(T) - N);
133112
}
134113

135-
/// Get the index of the last set bit starting from the least
136-
/// significant bit.
137-
///
138-
/// Only unsigned integral types are allowed.
139-
///
140-
/// \param ZB the behavior on an input of 0.
141-
template <typename T> T findLastSet(T Val, ZeroBehavior ZB = ZB_Max) {
142-
if (ZB == ZB_Max && Val == 0)
143-
return std::numeric_limits<T>::max();
144-
145-
// Use ^ instead of - because both gcc and llvm can remove the associated ^
146-
// in the __builtin_clz intrinsic on x86.
147-
return llvm::countl_zero(Val) ^ (std::numeric_limits<T>::digits - 1);
148-
}
149-
150114
/// Macro compressed bit reversal table for 256 bits.
151115
///
152116
/// http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable

llvm/unittests/Support/MathExtrasTest.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -90,46 +90,6 @@ TEST(MathExtras, onesMask) {
9090
EXPECT_EQ(0xFFFFFFFFFFFF0000ULL, maskLeadingOnes<uint64_t>(48U));
9191
}
9292

93-
TEST(MathExtras, findFirstSet) {
94-
uint8_t Z8 = 0;
95-
uint16_t Z16 = 0;
96-
uint32_t Z32 = 0;
97-
uint64_t Z64 = 0;
98-
EXPECT_EQ(0xFFULL, findFirstSet(Z8));
99-
EXPECT_EQ(0xFFFFULL, findFirstSet(Z16));
100-
EXPECT_EQ(0xFFFFFFFFULL, findFirstSet(Z32));
101-
EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, findFirstSet(Z64));
102-
103-
uint8_t NZ8 = 42;
104-
uint16_t NZ16 = 42;
105-
uint32_t NZ32 = 42;
106-
uint64_t NZ64 = 42;
107-
EXPECT_EQ(1u, findFirstSet(NZ8));
108-
EXPECT_EQ(1u, findFirstSet(NZ16));
109-
EXPECT_EQ(1u, findFirstSet(NZ32));
110-
EXPECT_EQ(1u, findFirstSet(NZ64));
111-
}
112-
113-
TEST(MathExtras, findLastSet) {
114-
uint8_t Z8 = 0;
115-
uint16_t Z16 = 0;
116-
uint32_t Z32 = 0;
117-
uint64_t Z64 = 0;
118-
EXPECT_EQ(0xFFULL, findLastSet(Z8));
119-
EXPECT_EQ(0xFFFFULL, findLastSet(Z16));
120-
EXPECT_EQ(0xFFFFFFFFULL, findLastSet(Z32));
121-
EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, findLastSet(Z64));
122-
123-
uint8_t NZ8 = 42;
124-
uint16_t NZ16 = 42;
125-
uint32_t NZ32 = 42;
126-
uint64_t NZ64 = 42;
127-
EXPECT_EQ(5u, findLastSet(NZ8));
128-
EXPECT_EQ(5u, findLastSet(NZ16));
129-
EXPECT_EQ(5u, findLastSet(NZ32));
130-
EXPECT_EQ(5u, findLastSet(NZ64));
131-
}
132-
13393
TEST(MathExtras, isIntN) {
13494
EXPECT_TRUE(isIntN(16, 32767));
13595
EXPECT_FALSE(isIntN(16, 32768));

0 commit comments

Comments
 (0)