aboutsummaryrefslogtreecommitdiff
path: root/src/ptr_map.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-11-05 18:04:18 +0000
committergingerBill <bill@gingerbill.org>2021-11-05 18:04:18 +0000
commit36985f8da0cea59cb1912f62ae4e700983159b6a (patch)
tree7bfd15490ddc4be6fcd41b4f969df6c901d98f76 /src/ptr_map.cpp
parenteb0faf9602224eb1ab381e28ac7b41b71ada3fbc (diff)
Simplification to `ptr_map_hash_key`
Diffstat (limited to 'src/ptr_map.cpp')
-rw-r--r--src/ptr_map.cpp20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/ptr_map.cpp b/src/ptr_map.cpp
index 66a6f0fc5..3d6be1d44 100644
--- a/src/ptr_map.cpp
+++ b/src/ptr_map.cpp
@@ -28,21 +28,11 @@ struct PtrMap {
u32 ptr_map_hash_key(uintptr key) {
#if defined(GB_ARCH_64_BIT)
- // TODO(bill): Improve ptr_map_hash_key
- u32 key0 = (u32)(key & 0xffffffff);
- u32 key1 = (u32)(key >> 32);
-
- u32 word;
- u32 state = 0;
-
- state += key0 * 747796405u + 2891336453u;
- word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
- state = (word >> 22u) ^ word;
- state += key1 * 747796405u + 2891336453u;
- word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
- state = (word >> 22u) ^ word;
- return state;
-
+ u64 x = (u64)key;
+ u8 count = (u8)(x >> 59);
+ x ^= x >> (5 + count);
+ x *= 12605985483714917081ull;
+ return (u32)(x ^ (x >> 43));
#elif defined(GB_ARCH_32_BIT)
u32 state = ((u32)key) * 747796405u + 2891336453u;
u32 word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;