1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
From: Faidon Liambotis <paravoid@debian.org>
Date: Sat, 11 Feb 2023 22:35:16 +0200
Subject: Patch MurmurHash2 to be endian- and alignment-neutral
This is based on the popular MurmurHashNeutral2 as shipped by multiple
other projects. As that's reportedly half as fast, place the new code
under an #if guard. Rather than do alignment and endianness check to
select the variant, statically select the faster variant on i386/amd64,
as that's what most projects (e.g. rocksdb) seem to be doing...
Forwarded: https://github.com/twitter/twemproxy/issues/680
Last-Updated: 2023-02-11
---
src/hashkit/nc_murmur.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/hashkit/nc_murmur.c b/src/hashkit/nc_murmur.c
index 697218b..5c62835 100644
--- a/src/hashkit/nc_murmur.c
+++ b/src/hashkit/nc_murmur.c
@@ -56,7 +56,16 @@ hash_murmur(const char *key, size_t length)
const unsigned char * data = (const unsigned char *)key;
while (length >= 4) {
- unsigned int k = *(unsigned int *)data;
+ unsigned int k;
+#if defined(__x86_64__) || defined(__i386__)
+ k = *(unsigned int *)data;
+#else
+ /* endian- and alignment-neutral; also known as "MurmurHashNeutral2" */
+ k = data[0];
+ k |= data[1] << 8;
+ k |= data[2] << 16;
+ k |= data[3] << 24;
+#endif
k *= m;
k ^= k >> r;
|