From b8dd567c54ba6926c4e5bacade81f310ea680613 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 22 Aug 2022 00:37:59 +0800 Subject: [PATCH] include/intarith: drop popcount() as it is not used anymore. Signed-off-by: Kefu Chai --- src/include/intarith.h | 12 ------------ src/test/test_intarith.cc | 19 ------------------- 2 files changed, 31 deletions(-) diff --git a/src/include/intarith.h b/src/include/intarith.h index bb50d79f73a16..ff626681704b2 100644 --- a/src/include/intarith.h +++ b/src/include/intarith.h @@ -123,16 +123,4 @@ unsigned cbits(T v) { return (sizeof(v) * 8) - std::countl_zero(std::make_unsigned_t(v)); } -// count the bits set to 1, a.k.a. population count -template -unsigned popcount(T v) { - static_assert(sizeof(T) <= sizeof(unsigned long long), "type too large"); - if constexpr (sizeof(T) <= sizeof(unsigned int)) { - return __builtin_popcount(v); - } else if constexpr (sizeof(T) <= sizeof(unsigned long)) { - return __builtin_popcountl(v); - } else { - return __builtin_popcountll(v); - } -} #endif diff --git a/src/test/test_intarith.cc b/src/test/test_intarith.cc index d8943caf39053..11bfbc6d1564a 100644 --- a/src/test/test_intarith.cc +++ b/src/test/test_intarith.cc @@ -58,22 +58,3 @@ TEST(intarith, p2family) { ASSERT_EQ(0x1300, p2roundup(0x1234, 0x100)); ASSERT_EQ(0x5600, p2roundup(0x5600, 0x100)); } - -TEST(intarith, popcount) { - // char, unsigned char - EXPECT_EQ(0, popcount((char)(0))); - EXPECT_EQ(1, popcount((unsigned char)(1))); - // short, unsigned short - EXPECT_EQ(1, popcount((short)0b10)); - EXPECT_EQ(2, popcount((unsigned char)(0b11U))); - // int, unsigned int - EXPECT_EQ(sizeof(int) * CHAR_BIT, popcount(-1)); - EXPECT_EQ(0, popcount(0)); - EXPECT_EQ(1, popcount(0b10U)); - // long, unsigned long - EXPECT_EQ(1, popcount(0b1000'0000'0000'0000L)); - EXPECT_EQ(3, popcount(0b1100'1000'0000'0000UL)); - // long long, unsigned long long - EXPECT_EQ(4, popcount(0x1111'0000LL)); - EXPECT_EQ(1, popcount(0x1000'0000ULL)); -} -- 2.39.5