diff options
author | Kefu Chai <kchai@redhat.com> | 2021-07-27 08:24:18 +0200 |
---|---|---|
committer | Kefu Chai <kchai@redhat.com> | 2021-07-27 14:03:32 +0200 |
commit | 943b91a11bb1b6e9409d865f1ec6bfc3c3ae87a0 (patch) | |
tree | d8db1d0b93652ee779839604f1e7593090d09535 /src/test/test_intarith.cc | |
parent | cmake: add unittest_intarith back (diff) | |
download | ceph-943b91a11bb1b6e9409d865f1ec6bfc3c3ae87a0.tar.xz ceph-943b91a11bb1b6e9409d865f1ec6bfc3c3ae87a0.zip |
test/test_intarith: adapt to the change in intarith.h
back in 2623fec1cdd5fd9b15ee67c4b115385c67129ef4, the vaiants of, for
instance, ctz() are consolidated to a single template. so the
ctz<>() dispatches by the size of argument after that change.
but the tests were not updated accordingly.
in this change:
* the tests are updated to use the template.
* instead of using integer literal postfix, use the macros like
UINT64_C to define integer constants for better portability on
different architectures where the lengths of integer *might* be
different from amd64. also, it's more readable than postfixes
like ULL in this context, as we really care about the exact
length of an integer in this context when counting the leading
zeros.
Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to 'src/test/test_intarith.cc')
-rw-r--r-- | src/test/test_intarith.cc | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/test/test_intarith.cc b/src/test/test_intarith.cc index 239222046e3..0a225d40e09 100644 --- a/src/test/test_intarith.cc +++ b/src/test/test_intarith.cc @@ -12,34 +12,34 @@ TEST(intarith, cbits) { ASSERT_EQ(2u, cbits(2)); ASSERT_EQ(2u, cbits(3)); ASSERT_EQ(3u, cbits(4)); - ASSERT_EQ(0u, cbitsl(0)); - ASSERT_EQ(1u, cbitsl(1)); - ASSERT_EQ(2u, cbitsl(2)); - ASSERT_EQ(2u, cbitsl(3)); - ASSERT_EQ(3u, cbitsl(4)); + ASSERT_EQ(0u, cbits(0)); + ASSERT_EQ(1u, cbits(1)); + ASSERT_EQ(2u, cbits(2)); + ASSERT_EQ(2u, cbits(3)); + ASSERT_EQ(3u, cbits(4)); ASSERT_EQ(9u, cbits(0x100)); ASSERT_EQ(32u, cbits(0xffffffff)); - ASSERT_EQ(32u, cbitsl(0xffffffff)); - ASSERT_EQ(32u, cbitsll(0xffffffff)); - ASSERT_EQ(64u, cbitsll(0xffffffffffffffff)); + ASSERT_EQ(32u, cbits(0xffffffff)); + ASSERT_EQ(32u, cbits(0xffffffff)); + ASSERT_EQ(64u, cbits(0xffffffffffffffff)); } TEST(intarith, clz) { - ASSERT_EQ(32u, clz(0)); - ASSERT_EQ(31u, clz(1)); - ASSERT_EQ(30u, clz(2)); - ASSERT_EQ(30u, clz(3)); - ASSERT_EQ(29u, clz(4)); - ASSERT_EQ(64u, clzll(0)); - ASSERT_EQ(63u, clzll(1)); - ASSERT_EQ(62u, clzll(2)); - ASSERT_EQ(62u, clzll(3)); - ASSERT_EQ(61u, clzll(4)); - ASSERT_EQ(23u, clz(0x100)); - ASSERT_EQ(55u, clzll(0x100)); + 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, clzll(0xffffffff)); - ASSERT_EQ(0u, clzll(0xffffffffffffffff)); + ASSERT_EQ(32u, clz(UINT64_C(0xffffffff))); + ASSERT_EQ(0u, clz(UINT64_C(0xffffffffffffffff))); } TEST(intarith, ctz) { @@ -48,18 +48,18 @@ TEST(intarith, ctz) { ASSERT_EQ(1u, ctz(2)); ASSERT_EQ(0u, ctz(3)); ASSERT_EQ(2u, ctz(4)); - ASSERT_EQ(64u, ctzll(0)); - ASSERT_EQ(0u, ctzll(1)); - ASSERT_EQ(1u, ctzll(2)); - ASSERT_EQ(0u, ctzll(3)); - ASSERT_EQ(2u, ctzll(4)); + ASSERT_EQ(64u, ctz(UINT64_C(0))); + ASSERT_EQ(0u, ctz(UINT64_C(1))); + ASSERT_EQ(1u, ctz(UINT64_C(2))); + ASSERT_EQ(0u, ctz(UINT64_C(3))); + ASSERT_EQ(2u, ctz(UINT64_C(4))); ASSERT_EQ(8u, ctz(0x100)); - ASSERT_EQ(8u, ctzll(0x100)); + ASSERT_EQ(8u, ctz(UINT64_C(0x100))); ASSERT_EQ(0u, ctz(0xffffffff)); - ASSERT_EQ(0u, ctzl(0xffffffff)); - ASSERT_EQ(0u, ctzll(0xffffffff)); - ASSERT_EQ(20u, ctzll(0xffffffff00000)); - ASSERT_EQ(48u, ctzll(0xff000000000000ull)); + ASSERT_EQ(0u, ctz(UINT32_C(0xffffffff))); + ASSERT_EQ(0u, ctz(UINT64_C(0xffffffff))); + ASSERT_EQ(20u, ctz(UINT64_C(0xffffffff00000))); + ASSERT_EQ(48u, ctz(UINT64_C(0xff000000000000))); } TEST(intarith, p2family) { |