]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/intarith: drop popcount() 47718/head
authorKefu Chai <tchaikov@gmail.com>
Sun, 21 Aug 2022 16:37:59 +0000 (00:37 +0800)
committerKefu Chai <tchaikov@gmail.com>
Mon, 22 Aug 2022 10:03:59 +0000 (18:03 +0800)
as it is not used anymore.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/include/intarith.h
src/test/test_intarith.cc

index bb50d79f73a16b7a23823a6202cc6565f9b5f3c3..ff626681704b2ab287bedc205739bded4515046f 100644 (file)
@@ -123,16 +123,4 @@ unsigned cbits(T v) {
   return (sizeof(v) * 8) - std::countl_zero(std::make_unsigned_t<T>(v));
 }
 
-// count the bits set to 1, a.k.a. population count
-template<class T>
-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
index d8943caf39053d9d4d9215b674a3914cfdb59b1c..11bfbc6d1564af1c9cf38ea03733444e48c953a4 100644 (file)
@@ -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));
-}