17 #include "gtest/gtest.h" 21 int CLZ64(uint64_t
n) {
24 EXPECT_EQ(fast, slow) <<
n;
29 EXPECT_EQ(64, CLZ64(uint64_t{}));
30 EXPECT_EQ(0, CLZ64(~uint64_t{}));
32 for (
int index = 0; index < 64; index++) {
33 uint64_t x =
static_cast<uint64_t
>(1) << index;
34 const auto cnt = 63 - index;
35 ASSERT_EQ(cnt, CLZ64(x)) << index;
36 ASSERT_EQ(cnt, CLZ64(x + x - 1)) << index;
40 int CLZ32(uint32_t
n) {
43 EXPECT_EQ(fast, slow) <<
n;
48 EXPECT_EQ(32, CLZ32(uint32_t{}));
49 EXPECT_EQ(0, CLZ32(~uint32_t{}));
51 for (
int index = 0; index < 32; index++) {
52 uint32_t x =
static_cast<uint32_t
>(1) << index;
53 const auto cnt = 31 - index;
54 ASSERT_EQ(cnt, CLZ32(x)) << index;
55 ASSERT_EQ(cnt, CLZ32(x + x - 1)) << index;
56 ASSERT_EQ(CLZ64(x), CLZ32(x) + 32);
60 int CTZ64(uint64_t
n) {
63 EXPECT_EQ(fast, slow) <<
n;
68 EXPECT_EQ(0, CTZ64(~uint64_t{}));
70 for (
int index = 0; index < 64; index++) {
71 uint64_t x =
static_cast<uint64_t
>(1) << index;
72 const auto cnt = index;
73 ASSERT_EQ(cnt, CTZ64(x)) << index;
74 ASSERT_EQ(cnt, CTZ64(~(x - 1))) << index;
78 int CTZ32(uint32_t
n) {
81 EXPECT_EQ(fast, slow) <<
n;
86 EXPECT_EQ(0, CTZ32(~uint32_t{}));
88 for (
int index = 0; index < 32; index++) {
89 uint32_t x =
static_cast<uint32_t
>(1) << index;
90 const auto cnt = index;
91 ASSERT_EQ(cnt, CTZ32(x)) << index;
92 ASSERT_EQ(cnt, CTZ32(~(x - 1))) << index;
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros32(uint32_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros64Slow(uint64_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros64(uint64_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero32(uint32_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros32Slow(uint64_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero64Slow(uint64_t n)
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero32Slow(uint32_t n)
TEST(Symbolize, Unimplemented)
ABSL_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero64(uint64_t n)