diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -66,7 +66,9 @@ /// Only unsigned integral types are allowed. /// /// Returns std::numeric_limits::digits on an input of 0. -template unsigned countTrailingZeros(T Val) { +template +LLVM_DEPRECATED("Use llvm::countr_zero instead.", "llvm::countr_zero") +unsigned countTrailingZeros(T Val) { static_assert(std::is_unsigned_v, "Only unsigned integral types are allowed."); return llvm::countr_zero(Val); @@ -78,7 +80,9 @@ /// Only unsigned integral types are allowed. /// /// Returns std::numeric_limits::digits on an input of 0. -template unsigned countLeadingZeros(T Val) { +template +LLVM_DEPRECATED("Use llvm::countl_zero instead.", "llvm::countl_zero") +unsigned countLeadingZeros(T Val) { static_assert(std::is_unsigned_v, "Only unsigned integral types are allowed."); return llvm::countl_zero(Val); @@ -301,7 +305,9 @@ /// Only unsigned integral types are allowed. /// /// Returns std::numeric_limits::digits on an input of all ones. -template unsigned countLeadingOnes(T Value) { +template +LLVM_DEPRECATED("Use llvm::countl_one instead.", "llvm::countl_one") +unsigned countLeadingOnes(T Value) { static_assert(std::is_unsigned_v, "Only unsigned integral types are allowed."); return llvm::countl_one(Value); @@ -314,7 +320,9 @@ /// Only unsigned integral types are allowed. /// /// Returns std::numeric_limits::digits on an input of all ones. -template unsigned countTrailingOnes(T Value) { +template +LLVM_DEPRECATED("Use llvm::countr_one instead.", "llvm::countr_one") +unsigned countTrailingOnes(T Value) { static_assert(std::is_unsigned_v, "Only unsigned integral types are allowed."); return llvm::countr_one(Value); @@ -324,6 +332,7 @@ /// Ex. countPopulation(0xF000F000) = 8 /// Returns 0 if the word is zero. template +LLVM_DEPRECATED("Use llvm::popcount instead.", "llvm::popcount") inline unsigned countPopulation(T Value) { static_assert(std::is_unsigned_v, "Only unsigned integral types are allowed."); diff --git a/llvm/unittests/Support/MathExtrasTest.cpp b/llvm/unittests/Support/MathExtrasTest.cpp --- a/llvm/unittests/Support/MathExtrasTest.cpp +++ b/llvm/unittests/Support/MathExtrasTest.cpp @@ -13,58 +13,6 @@ namespace { -TEST(MathExtras, countTrailingZeros) { - uint8_t Z8 = 0; - uint16_t Z16 = 0; - uint32_t Z32 = 0; - uint64_t Z64 = 0; - EXPECT_EQ(8u, countTrailingZeros(Z8)); - EXPECT_EQ(16u, countTrailingZeros(Z16)); - EXPECT_EQ(32u, countTrailingZeros(Z32)); - EXPECT_EQ(64u, countTrailingZeros(Z64)); - - uint8_t NZ8 = 42; - uint16_t NZ16 = 42; - uint32_t NZ32 = 42; - uint64_t NZ64 = 42; - EXPECT_EQ(1u, countTrailingZeros(NZ8)); - EXPECT_EQ(1u, countTrailingZeros(NZ16)); - EXPECT_EQ(1u, countTrailingZeros(NZ32)); - EXPECT_EQ(1u, countTrailingZeros(NZ64)); -} - -TEST(MathExtras, countLeadingZeros) { - uint8_t Z8 = 0; - uint16_t Z16 = 0; - uint32_t Z32 = 0; - uint64_t Z64 = 0; - EXPECT_EQ(8u, countLeadingZeros(Z8)); - EXPECT_EQ(16u, countLeadingZeros(Z16)); - EXPECT_EQ(32u, countLeadingZeros(Z32)); - EXPECT_EQ(64u, countLeadingZeros(Z64)); - - uint8_t NZ8 = 42; - uint16_t NZ16 = 42; - uint32_t NZ32 = 42; - uint64_t NZ64 = 42; - EXPECT_EQ(2u, countLeadingZeros(NZ8)); - EXPECT_EQ(10u, countLeadingZeros(NZ16)); - EXPECT_EQ(26u, countLeadingZeros(NZ32)); - EXPECT_EQ(58u, countLeadingZeros(NZ64)); - - EXPECT_EQ(8u, countLeadingZeros(0x00F000FFu)); - EXPECT_EQ(8u, countLeadingZeros(0x00F12345u)); - for (unsigned i = 0; i <= 30; ++i) { - EXPECT_EQ(31 - i, countLeadingZeros(1u << i)); - } - - EXPECT_EQ(8u, countLeadingZeros(0x00F1234500F12345ULL)); - EXPECT_EQ(1u, countLeadingZeros(1ULL << 62)); - for (unsigned i = 0; i <= 62; ++i) { - EXPECT_EQ(63 - i, countLeadingZeros(1ULL << i)); - } -} - TEST(MathExtras, onesMask) { EXPECT_EQ(0U, maskLeadingOnes(0)); EXPECT_EQ(0U, maskTrailingOnes(0)); @@ -220,21 +168,6 @@ EXPECT_EQ(CTLog2<1ULL << 15>(), 15U); } -TEST(MathExtras, countLeadingOnes) { - for (int i = 30; i >= 0; --i) { - // Start with all ones and unset some bit. - EXPECT_EQ(31u - i, countLeadingOnes(0xFFFFFFFF ^ (1 << i))); - } - for (int i = 62; i >= 0; --i) { - // Start with all ones and unset some bit. - EXPECT_EQ(63u - i, countLeadingOnes(0xFFFFFFFFFFFFFFFFULL ^ (1LL << i))); - } - for (int i = 30; i >= 0; --i) { - // Start with all ones and unset some bit. - EXPECT_EQ(31u - i, countLeadingOnes(0xFFFFFFFF ^ (1 << i))); - } -} - TEST(MathExtras, FloatBits) { static const float kValue = 5632.34f; EXPECT_FLOAT_EQ(kValue, BitsToFloat(FloatToBits(kValue)));