7 using WorldStone::Utils::signExtend;
14 SUBCASE(
"Positive input")
16 CHECK(signExtend<int32_t,13>( 0) == 0);
17 CHECK(signExtend<int32_t,32>(0x16641337) == 0x16641337);
18 CHECK(signExtend<int32_t,32>(0x7FFFFFFF) == 0x7FFFFFFF);
19 CHECK(signExtend<int32_t, 2>( 0b01) == 1);
20 CHECK(signExtend<int32_t, 3>( 0b011) == 3);
22 SUBCASE(
"Negative input")
24 CHECK(signExtend<int32_t, 5>( 0b10110) == -10);
25 CHECK(signExtend<int32_t, 8>( 0xFF) == -1);
26 CHECK(signExtend<int32_t,32>(0xFFFFFFFF) == -1);
27 CHECK(signExtend<int32_t,32>(0xDEADBEEF) == 0xDEADBEEF);
28 CHECK(signExtend<int32_t,16>(0xDEADBEEF) == 0xFFFFBEEF);
29 CHECK(signExtend<int32_t,16>(0x16641337) == 0x1337);
30 CHECK(signExtend<int32_t, 8>( 0x80) == -128);
31 CHECK(signExtend<int32_t, 3>( 0x07) == -1);
32 CHECK(signExtend<int32_t, 9>( 0x1CE) == -50);
34 SUBCASE(
"1-bit special case")
36 CHECK(signExtend<int32_t, 1>(0b0) == 0);
37 CHECK(signExtend<int32_t, 1>(0b1) == -1);
42 using WorldStone::Utils::reverseBits;
46 CHECK(reverseBits<uint8_t>(0xF0) == 0x0F);
47 CHECK(reverseBits<uint16_t>(0xF0) == 0x0F00);
48 CHECK(reverseBits<uint32_t>(0xF0) == 0x0F000000);
49 CHECK(reverseBits<uint64_t>(0xF0) == 0x0F00000000000000);
50 CHECK(reverseBits<uint32_t>(0x01234567) == 0xE6A2C480);
53 using WorldStone::Utils::popCount;
59 CHECK(popCount(uint16_t(0b0000000000000000)) == 0);
60 CHECK(popCount(uint16_t(0b0000000000011111)) == 5);
61 CHECK(popCount(uint16_t(0b1110011101011001)) == 10);
62 CHECK(popCount(uint16_t(0b1111111111111111)) == 16);
64 CHECK(popCount(uint32_t(0x00000000)) == 0);
65 CHECK(popCount(uint32_t(0x000F000F)) == 8);
66 CHECK(popCount(uint32_t(0x0F000F00)) == 8);
67 CHECK(popCount(uint32_t(0xFFFFFFFF)) == 32);
69 CHECK(popCount(uint64_t(0x0000000000000000)) == 0);
70 CHECK(popCount(uint64_t(0x00000000000000FF)) == 8);
71 CHECK(popCount(uint64_t(0x000000000000FF00)) == 8);
72 CHECK(popCount(uint64_t(0xFFFFFFFFFFFFFFFF)) == 64);
TEST_CASE("SignExtend")
Test that SignExtend is giving the right values.