summaryrefslogtreecommitdiffstats
path: root/src/tests/common
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2019-03-16 04:18:11 +0100
committerFernandoS27 <fsahmkow27@gmail.com>2019-03-27 19:34:29 +0100
commit3bc815a5dc18a646334ba933c74ce7ce44099625 (patch)
tree61229ef6188b264bc7606e62759edd14e5ac2589 /src/tests/common
parentImplement a MultiLevelQueue (diff)
downloadyuzu-3bc815a5dc18a646334ba933c74ce7ce44099625.tar
yuzu-3bc815a5dc18a646334ba933c74ce7ce44099625.tar.gz
yuzu-3bc815a5dc18a646334ba933c74ce7ce44099625.tar.bz2
yuzu-3bc815a5dc18a646334ba933c74ce7ce44099625.tar.lz
yuzu-3bc815a5dc18a646334ba933c74ce7ce44099625.tar.xz
yuzu-3bc815a5dc18a646334ba933c74ce7ce44099625.tar.zst
yuzu-3bc815a5dc18a646334ba933c74ce7ce44099625.zip
Diffstat (limited to 'src/tests/common')
-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 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include <catch2/catch.hpp>
+#include <math.h>
+#include "common/bit_util.h"
+
+namespace Common {
+
+inline u32 CTZ32(u32 value) {
+ u32 count = 0;
+ while (((value >> count) & 0xf) == 0 && count < 32)
+ count += 4;
+ while (((value >> count) & 1) == 0 && count < 32)
+ count++;
+ return count;
+}
+
+inline u64 CTZ64(u64 value) {
+ u64 count = 0;
+ while (((value >> count) & 0xf) == 0 && count < 64)
+ count += 4;
+ while (((value >> count) & 1) == 0 && count < 64)
+ count++;
+ return count;
+}
+
+
+TEST_CASE("BitUtils", "[common]") {
+ REQUIRE(Common::CountTrailingZeroes32(0) == CTZ32(0));
+ REQUIRE(Common::CountTrailingZeroes64(0) == CTZ64(0));
+ REQUIRE(Common::CountTrailingZeroes32(9) == CTZ32(9));
+ REQUIRE(Common::CountTrailingZeroes32(8) == CTZ32(8));
+ REQUIRE(Common::CountTrailingZeroes32(0x801000) == CTZ32(0x801000));
+ REQUIRE(Common::CountTrailingZeroes64(9) == CTZ64(9));
+ REQUIRE(Common::CountTrailingZeroes64(8) == CTZ64(8));
+ REQUIRE(Common::CountTrailingZeroes64(0x801000) == CTZ64(0x801000));
+ REQUIRE(Common::CountTrailingZeroes64(0x801000000000UL) == CTZ64(0x801000000000UL));
+}
+
+} // namespace Common