From 9f5d223c60793748f04a9d5b4b4eacddfc1f755d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Paolacci?= Date: Sat, 19 Aug 2017 09:11:01 +0200 Subject: [PATCH] Ease `IMUL 5, h1` 32 bits hash (~10 % for > 256 B). Replace by a left shift and an addition. Generated code for 64 bits version already map to the even most adequate `LEA`. On a mid-2012 MBA, benchmark old MB/s new MB/s speedup Benchmark32_1-4 90.18 91.08 1.01x Benchmark32_2-4 168.26 168.55 1.00x Benchmark32_4-4 342.13 338.26 0.99x Benchmark32_8-4 587.46 584.68 1.00x Benchmark32_16-4 981.80 990.72 1.01x Benchmark32_32-4 1349.67 1370.62 1.02x Benchmark32_64-4 1684.94 1696.83 1.01x Benchmark32_128-4 1748.24 1746.80 1.00x Benchmark32_256-4 1805.96 1933.24 1.07x Benchmark32_512-4 1845.56 2019.75 1.09x Benchmark32_1024-4 1856.36 2031.61 1.09x Benchmark32_2048-4 1890.43 2032.47 1.08x Benchmark32_4096-4 1881.13 2085.36 1.11x Benchmark32_8192-4 1889.83 2103.02 1.11x --- murmur32.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/murmur32.go b/murmur32.go index 22dd11b..e32c995 100644 --- a/murmur32.go +++ b/murmur32.go @@ -60,7 +60,7 @@ func (d *digest32) bmix(p []byte) (tail []byte) { h1 ^= k1 h1 = (h1 << 13) | (h1 >> 19) // rotl32(h1, 13) - h1 = h1*5 + 0xe6546b64 + h1 = h1*4 + h1 + 0xe6546b64 } d.h1 = h1 return p[nblocks*d.Size():] @@ -134,7 +134,7 @@ func Sum32WithSeed(data []byte, seed uint32) uint32 { h1 ^= k1 h1 = (h1 << 13) | (h1 >> 19) // rotl32(h1, 13) - h1 = h1*5 + 0xe6546b64 + h1 = h1*4 + h1 + 0xe6546b64 } tail := data[nblocks*4:]