Skip to content

Commit 55ecfcf

Browse files
committed
new compressor & finisher
1 parent 33540ae commit 55ecfcf

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Things may change at any point without notice.
55

66
Some major improvement compared to v1:
77

8-
- Faster performance on short string (49 cycles/hash vs 35 cycles/hash).
8+
- Faster performance on short string (49 cycles/hash vs 34 cycles/hash).
99
The tail end handling has been reworked entirely with some inspiration from
1010
wyhash's short input reading.
1111
- Better seeding. v1 seed only affected 64 bits of the initial state.
@@ -17,8 +17,6 @@ Some major improvement compared to v1:
1717
Avenue for improvement:
1818

1919
- Faster bulk handling without using 128 bit multiplication.
20-
- Investigate better/faster compressor for the 256 bit -> 64 bit reduction.
21-
- Drop moremur in favor of using existing multiplier (digits of e) for the finisher ??
2220

2321
---
2422

chibihash64.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ static inline uint64_t chibihash64__rotl(uint64_t x, int n)
2222
{
2323
return (x << n) | (x >> (-n & 63));
2424
}
25-
static inline uint64_t chibihash64__reduce(uint64_t a, uint64_t b)
26-
{
27-
uint64_t x = a * (chibihash64__rotl(b, 9) | 1);
28-
x ^= chibihash64__rotl(b, 41) + chibihash64__rotl(a, 31);
29-
return x;
30-
}
3125

3226
static inline uint64_t
3327
chibihash64(const void *keyIn, ptrdiff_t len, uint64_t seed)
@@ -68,15 +62,19 @@ chibihash64(const void *keyIn, ptrdiff_t len, uint64_t seed)
6862
h[3] ^= p[l/2] | ((uint64_t)p[l-1] << 8);
6963
}
7064

65+
h[0] += chibihash64__rotl(h[2] * K, 31) ^ (h[2] >> 31);
66+
h[1] += chibihash64__rotl(h[3] * K, 31) ^ (h[3] >> 31);
67+
h[0] *= K; h[0] ^= h[0] >> 31;
68+
h[1] += h[0];
69+
7170
uint64_t x = (uint64_t)len * K;
7271
x ^= chibihash64__rotl(x, 29);
73-
x ^= chibihash64__reduce(h[0], h[1]);
74-
x ^= chibihash64__reduce(h[2], h[3]) + seed;
72+
x += seed;
73+
x ^= h[1];
7574

76-
// moremur: https://mostlymangling.blogspot.com/2019/12/stronger-better-morer-moremur-better.html
77-
x ^= x >> 27; x *= UINT64_C(0x3C79AC492BA7B653);
78-
x ^= x >> 33; x *= UINT64_C(0x1C69B3F74AC4AE35);
79-
x ^= x >> 27;
75+
x ^= chibihash64__rotl(x, 15) ^ chibihash64__rotl(x, 42);
76+
x *= K;
77+
x ^= chibihash64__rotl(x, 13) ^ chibihash64__rotl(x, 31);
8078

8179
return x;
8280
}

0 commit comments

Comments
 (0)