summaryrefslogtreecommitdiff
path: root/src/tests/common/bit_utils.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-03-15 23:18:11 -0400
committerGravatar FernandoS272019-03-27 14:34:29 -0400
commit3bc815a5dc18a646334ba933c74ce7ce44099625 (patch)
tree61229ef6188b264bc7606e62759edd14e5ac2589 /src/tests/common/bit_utils.cpp
parentImplement a MultiLevelQueue (diff)
downloadyuzu-3bc815a5dc18a646334ba933c74ce7ce44099625.tar.gz
yuzu-3bc815a5dc18a646334ba933c74ce7ce44099625.tar.xz
yuzu-3bc815a5dc18a646334ba933c74ce7ce44099625.zip
Implement intrinsics CountTrailingZeroes and test it.
Diffstat (limited to 'src/tests/common/bit_utils.cpp')
-rw-r--r--src/tests/common/bit_utils.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/tests/common/bit_utils.cpp b/src/tests/common/bit_utils.cpp
new file mode 100644
index 000000000..77c17c526
--- /dev/null
+++ b/src/tests/common/bit_utils.cpp
@@ -0,0 +1,42 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <catch2/catch.hpp>
6#include <math.h>
7#include "common/bit_util.h"
8
9namespace Common {
10
11inline u32 CTZ32(u32 value) {
12 u32 count = 0;
13 while (((value >> count) & 0xf) == 0 && count < 32)
14 count += 4;
15 while (((value >> count) & 1) == 0 && count < 32)
16 count++;
17 return count;
18}
19
20inline u64 CTZ64(u64 value) {
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
30TEST_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}
41
42} // namespace Common