From f4706f95e6e4e0c92610def09eb7b78b726be293 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 22 Aug 2022 00:42:58 +0800 Subject: [PATCH] include/intarith: drop clz() it is not used anymore Signed-off-by: Kefu Chai --- src/include/intarith.h | 34 ---------------------------------- src/test/test_intarith.cc | 18 ------------------ 2 files changed, 52 deletions(-) diff --git a/src/include/intarith.h b/src/include/intarith.h index b3d76ecd530..bb50d79f73a 100644 --- a/src/include/intarith.h +++ b/src/include/intarith.h @@ -117,40 +117,6 @@ template return __builtin_ctzll(v); } -// count leading zeros -// NOTE: the builtin is nondeterministic on 0 input -template - inline typename std::enable_if< - (std::is_integral::value && - sizeof(T) <= sizeof(unsigned)), - unsigned>::type clz(T v) { - if (v == 0) - return sizeof(v) * 8; - return __builtin_clz(v); -} - -template - inline typename std::enable_if< - (std::is_integral::value && - sizeof(T) > sizeof(unsigned int) && - sizeof(T) <= sizeof(unsigned long)), - unsigned>::type clz(T v) { - if (v == 0) - return sizeof(v) * 8; - return __builtin_clzl(v); -} - -template - inline typename std::enable_if< - (std::is_integral::value && - sizeof(T) > sizeof(unsigned long) && - sizeof(T) <= sizeof(unsigned long long)), - unsigned>::type clz(T v) { - if (v == 0) - return sizeof(v) * 8; - return __builtin_clzll(v); -} - // count bits (set + any 0's that follow) template unsigned cbits(T v) { diff --git a/src/test/test_intarith.cc b/src/test/test_intarith.cc index bb01343d4d1..d8943caf390 100644 --- a/src/test/test_intarith.cc +++ b/src/test/test_intarith.cc @@ -23,24 +23,6 @@ TEST(intarith, cbits) { ASSERT_EQ(64u, cbits(0xffffffffffffffff)); } -TEST(intarith, clz) { - ASSERT_EQ(32u, clz(UINT32_C(0))); - ASSERT_EQ(31u, clz(UINT32_C(1))); - ASSERT_EQ(30u, clz(UINT32_C(2))); - ASSERT_EQ(30u, clz(UINT32_C(3))); - ASSERT_EQ(29u, clz(UINT32_C(4))); - ASSERT_EQ(64u, clz(UINT64_C(0))); - ASSERT_EQ(63u, clz(UINT64_C(1))); - ASSERT_EQ(62u, clz(UINT64_C(2))); - ASSERT_EQ(62u, clz(UINT64_C(3))); - ASSERT_EQ(61u, clz(UINT64_C(4))); - ASSERT_EQ(23u, clz(UINT32_C(0x100))); - ASSERT_EQ(55u, clz(UINT64_C(0x100))); - ASSERT_EQ(0u, clz(0xffffffff)); - ASSERT_EQ(32u, clz(UINT64_C(0xffffffff))); - ASSERT_EQ(0u, clz(UINT64_C(0xffffffffffffffff))); -} - TEST(intarith, ctz) { ASSERT_EQ(32u, ctz(0)); ASSERT_EQ(0u, ctz(1)); -- 2.39.5