From 32ac9db7a5c8b8b63f3f3cf1849ec752a679a797 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 26 Jan 2023 12:29:48 -0800 Subject: [PATCH] [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 --- llvm/include/llvm/Support/MathExtras.h | 36 ---------------------------- llvm/unittests/Support/MathExtrasTest.cpp | 40 ------------------------------- 2 files changed, 76 deletions(-) diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h index ff136ba..44af0fd 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -24,14 +24,6 @@ namespace llvm { -/// The behavior an operation has on an input of 0. -enum ZeroBehavior { - /// The returned value is undefined. - ZB_Undefined, - /// The returned value is numeric_limits::max() - ZB_Max -}; - /// Mathematical constants. namespace numbers { // TODO: Track C++20 std::numbers. @@ -92,19 +84,6 @@ template unsigned countLeadingZeros(T Val) { return llvm::countl_zero(Val); } -/// Get the index of the first set bit starting from the least -/// significant bit. -/// -/// Only unsigned integral types are allowed. -/// -/// \param ZB the behavior on an input of 0. -template T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) { - if (ZB == ZB_Max && Val == 0) - return std::numeric_limits::max(); - - return llvm::countr_zero(Val); -} - /// Create a bitmask with the N right-most bits set to 1, and all other /// bits set to 0. Only unsigned types are allowed. template T maskTrailingOnes(unsigned N) { @@ -132,21 +111,6 @@ template T maskLeadingZeros(unsigned N) { return maskTrailingOnes(CHAR_BIT * sizeof(T) - N); } -/// Get the index of the last set bit starting from the least -/// significant bit. -/// -/// Only unsigned integral types are allowed. -/// -/// \param ZB the behavior on an input of 0. -template T findLastSet(T Val, ZeroBehavior ZB = ZB_Max) { - if (ZB == ZB_Max && Val == 0) - return std::numeric_limits::max(); - - // Use ^ instead of - because both gcc and llvm can remove the associated ^ - // in the __builtin_clz intrinsic on x86. - return llvm::countl_zero(Val) ^ (std::numeric_limits::digits - 1); -} - /// Macro compressed bit reversal table for 256 bits. /// /// http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable diff --git a/llvm/unittests/Support/MathExtrasTest.cpp b/llvm/unittests/Support/MathExtrasTest.cpp index 8558719..d45197a 100644 --- a/llvm/unittests/Support/MathExtrasTest.cpp +++ b/llvm/unittests/Support/MathExtrasTest.cpp @@ -90,46 +90,6 @@ TEST(MathExtras, onesMask) { EXPECT_EQ(0xFFFFFFFFFFFF0000ULL, maskLeadingOnes(48U)); } -TEST(MathExtras, findFirstSet) { - uint8_t Z8 = 0; - uint16_t Z16 = 0; - uint32_t Z32 = 0; - uint64_t Z64 = 0; - EXPECT_EQ(0xFFULL, findFirstSet(Z8)); - EXPECT_EQ(0xFFFFULL, findFirstSet(Z16)); - EXPECT_EQ(0xFFFFFFFFULL, findFirstSet(Z32)); - EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, findFirstSet(Z64)); - - uint8_t NZ8 = 42; - uint16_t NZ16 = 42; - uint32_t NZ32 = 42; - uint64_t NZ64 = 42; - EXPECT_EQ(1u, findFirstSet(NZ8)); - EXPECT_EQ(1u, findFirstSet(NZ16)); - EXPECT_EQ(1u, findFirstSet(NZ32)); - EXPECT_EQ(1u, findFirstSet(NZ64)); -} - -TEST(MathExtras, findLastSet) { - uint8_t Z8 = 0; - uint16_t Z16 = 0; - uint32_t Z32 = 0; - uint64_t Z64 = 0; - EXPECT_EQ(0xFFULL, findLastSet(Z8)); - EXPECT_EQ(0xFFFFULL, findLastSet(Z16)); - EXPECT_EQ(0xFFFFFFFFULL, findLastSet(Z32)); - EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, findLastSet(Z64)); - - uint8_t NZ8 = 42; - uint16_t NZ16 = 42; - uint32_t NZ32 = 42; - uint64_t NZ64 = 42; - EXPECT_EQ(5u, findLastSet(NZ8)); - EXPECT_EQ(5u, findLastSet(NZ16)); - EXPECT_EQ(5u, findLastSet(NZ32)); - EXPECT_EQ(5u, findLastSet(NZ64)); -} - TEST(MathExtras, isIntN) { EXPECT_TRUE(isIntN(16, 32767)); EXPECT_FALSE(isIntN(16, 32768)); -- 2.7.4