diff options
Diffstat (limited to 'src/tests/common/bit_utils.cpp')
| -rw-r--r-- | src/tests/common/bit_utils.cpp | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/src/tests/common/bit_utils.cpp b/src/tests/common/bit_utils.cpp index 77c17c526..479b5995a 100644 --- a/src/tests/common/bit_utils.cpp +++ b/src/tests/common/bit_utils.cpp | |||
| @@ -8,35 +8,16 @@ | |||
| 8 | 8 | ||
| 9 | namespace Common { | 9 | namespace Common { |
| 10 | 10 | ||
| 11 | inline u32 CTZ32(u32 value) { | 11 | TEST_CASE("BitUtils::CountTrailingZeroes", "[common]") { |
| 12 | u32 count = 0; | 12 | REQUIRE(Common::CountTrailingZeroes32(0) == 32); |
| 13 | while (((value >> count) & 0xf) == 0 && count < 32) | 13 | REQUIRE(Common::CountTrailingZeroes64(0) == 64); |
| 14 | count += 4; | 14 | REQUIRE(Common::CountTrailingZeroes32(9) == 0); |
| 15 | while (((value >> count) & 1) == 0 && count < 32) | 15 | REQUIRE(Common::CountTrailingZeroes32(8) == 3); |
| 16 | count++; | 16 | REQUIRE(Common::CountTrailingZeroes32(0x801000) == 12); |
| 17 | return count; | 17 | REQUIRE(Common::CountTrailingZeroes64(9) == 0); |
| 18 | } | 18 | REQUIRE(Common::CountTrailingZeroes64(8) == 3); |
| 19 | 19 | REQUIRE(Common::CountTrailingZeroes64(0x801000) == 12); | |
| 20 | inline u64 CTZ64(u64 value) { | 20 | REQUIRE(Common::CountTrailingZeroes64(0x801000000000UL) == 36); |
| 21 | u64 count = 0; | ||
| 22 | while (((value >> count) & 0xf) == 0 && count < 64) | ||
| 23 | count += 4; | ||
| 24 | while (((value >> count) & 1) == 0 && count < 64) | ||
| 25 | count++; | ||
| 26 | return count; | ||
| 27 | } | ||
| 28 | |||
| 29 | |||
| 30 | TEST_CASE("BitUtils", "[common]") { | ||
| 31 | REQUIRE(Common::CountTrailingZeroes32(0) == CTZ32(0)); | ||
| 32 | REQUIRE(Common::CountTrailingZeroes64(0) == CTZ64(0)); | ||
| 33 | REQUIRE(Common::CountTrailingZeroes32(9) == CTZ32(9)); | ||
| 34 | REQUIRE(Common::CountTrailingZeroes32(8) == CTZ32(8)); | ||
| 35 | REQUIRE(Common::CountTrailingZeroes32(0x801000) == CTZ32(0x801000)); | ||
| 36 | REQUIRE(Common::CountTrailingZeroes64(9) == CTZ64(9)); | ||
| 37 | REQUIRE(Common::CountTrailingZeroes64(8) == CTZ64(8)); | ||
| 38 | REQUIRE(Common::CountTrailingZeroes64(0x801000) == CTZ64(0x801000)); | ||
| 39 | REQUIRE(Common::CountTrailingZeroes64(0x801000000000UL) == CTZ64(0x801000000000UL)); | ||
| 40 | } | 21 | } |
| 41 | 22 | ||
| 42 | } // namespace Common | 23 | } // namespace Common |