about summary refs log tree commit diff stats
path: root/src/tools/bitutils.c
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2023-03-16 14:43:53 +0800
committerGitHub <noreply@github.com>2023-03-16 07:43:53 +0100
commite579450af61a2b953b6309c5a3aad4a3d94a8393 (patch)
tree061d1c76e4113ac1ba7d58ee1bc31953addb8e64 /src/tools/bitutils.c
parent50e463917ca388d1fd7285ce0b12476963e97c0f (diff)
downloadbox64-e579450af61a2b953b6309c5a3aad4a3d94a8393.tar.gz
box64-e579450af61a2b953b6309c5a3aad4a3d94a8393.zip
[RV64_DYNAREC] Optimize MOV64 emitter (#572)
Diffstat (limited to 'src/tools/bitutils.c')
-rw-r--r--src/tools/bitutils.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/tools/bitutils.c b/src/tools/bitutils.c
new file mode 100644
index 00000000..518085c2
--- /dev/null
+++ b/src/tools/bitutils.c
@@ -0,0 +1,17 @@
+#include <stdint.h>
+
+const uint64_t deBruijn64 = 0x03f79d71b4ca8b09;
+const uint8_t deBruijn64tab[64] = {
+	0, 1, 56, 2, 57, 49, 28, 3, 61, 58, 42, 50, 38, 29, 17, 4,
+	62, 47, 59, 36, 45, 43, 51, 22, 53, 39, 33, 30, 24, 18, 12, 5,
+	63, 55, 48, 27, 60, 41, 37, 16, 46, 35, 44, 21, 52, 32, 23, 11,
+	54, 26, 40, 15, 34, 20, 31, 10, 25, 14, 19, 9, 13, 8, 7, 6,
+};
+
+int TrailingZeros64(uint64_t x) {
+    if (x == 0) {
+        return 64;
+    }
+
+    return (int)deBruijn64tab[(x&-x)*deBruijn64>>(64-6)];
+}