59 #define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
60 #if (GCC_VERSION == 404)
61 # pragma GCC diagnostic ignored "-Wstrict-aliasing"
72 namespace Murmur3Implementation {
96 inline uint32_t
rotl32 ( uint32_t
x, int8_t r )
98 return (x << r) | (x >> (32 - r));
101 inline uint64_t
rotl64 ( uint64_t
x, int8_t r )
103 return (x << r) | (x >> (64 - r));
106 #define BIG_CONSTANT(x) (x##LLU)
112 inline uint32_t
getblock (
const uint32_t * p,
int i )
117 inline uint64_t
getblock (
const uint64_t * p,
int i )
125 inline uint32_t
fmix ( uint32_t h )
138 inline uint64_t
fmix ( uint64_t k )
153 uint32_t seed,
void * out );
155 uint32_t seed,
void * out );
159 uint32_t seed,
void * out )
167 uint32_t seed,
void * out )
169 const uint8_t *
data = (
const uint8_t*)key;
170 const int nblocks = len / 4;
174 uint32_t c1 = 0xcc9e2d51;
175 uint32_t c2 = 0x1b873593;
180 const uint32_t * blocks = (
const uint32_t *)(data + nblocks*4);
182 for(
int i = -nblocks; i; i++)
192 h1 = h1*5+0xe6546b64;
198 const uint8_t * tail = (
const uint8_t*)(data + nblocks*4);
204 case 3: k1 ^= tail[2] << 16;
205 case 2: k1 ^= tail[1] << 8;
206 case 1: k1 ^= tail[0];
207 k1 *= c1; k1 =
rotl32(k1,15); k1 *= c2; h1 ^= k1;
210 *(uint32_t *)out = h1;
215 uint32_t seed,
void * out )
226 *(uint32_t *)out = h1;
233 uint32_t * seeds,
void * out );
235 uint32_t * seeds,
void * out );
239 uint32_t seed,
void * out )
243 seeds[0] = seeds[1] = seeds[2] = seeds[3] = seed;
249 uint32_t * seeds,
void * out )
251 const uint8_t *
data = (
const uint8_t*)key;
252 const int nblocks = len / 16;
254 uint32_t h1 = seeds[0];
255 uint32_t h2 = seeds[1];
256 uint32_t h3 = seeds[2];
257 uint32_t h4 = seeds[3];
259 uint32_t c1 = 0x239b961b;
260 uint32_t c2 = 0xab0e9789;
261 uint32_t c3 = 0x38b34ae5;
262 uint32_t c4 = 0xa1e38b93;
267 const uint32_t * blocks = (
const uint32_t *)(data + nblocks*16);
269 for(
int i = -nblocks; i; i++)
271 uint32_t k1 =
getblock(blocks,i*4+0);
272 uint32_t k2 =
getblock(blocks,i*4+1);
273 uint32_t k3 =
getblock(blocks,i*4+2);
274 uint32_t k4 =
getblock(blocks,i*4+3);
276 k1 *= c1; k1 =
rotl32(k1,15); k1 *= c2; h1 ^= k1;
278 h1 =
rotl32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
280 k2 *= c2; k2 =
rotl32(k2,16); k2 *= c3; h2 ^= k2;
282 h2 =
rotl32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
284 k3 *= c3; k3 =
rotl32(k3,17); k3 *= c4; h3 ^= k3;
286 h3 =
rotl32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
288 k4 *= c4; k4 =
rotl32(k4,18); k4 *= c1; h4 ^= k4;
290 h4 =
rotl32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
296 const uint8_t * tail = (
const uint8_t*)(data + nblocks*16);
305 case 15: k4 ^= tail[14] << 16;
306 case 14: k4 ^= tail[13] << 8;
307 case 13: k4 ^= tail[12] << 0;
308 k4 *= c4; k4 =
rotl32(k4,18); k4 *= c1; h4 ^= k4;
310 case 12: k3 ^= tail[11] << 24;
311 case 11: k3 ^= tail[10] << 16;
312 case 10: k3 ^= tail[ 9] << 8;
313 case 9: k3 ^= tail[ 8] << 0;
314 k3 *= c3; k3 =
rotl32(k3,17); k3 *= c4; h3 ^= k3;
316 case 8: k2 ^= tail[ 7] << 24;
317 case 7: k2 ^= tail[ 6] << 16;
318 case 6: k2 ^= tail[ 5] << 8;
319 case 5: k2 ^= tail[ 4] << 0;
320 k2 *= c2; k2 =
rotl32(k2,16); k2 *= c3; h2 ^= k2;
322 case 4: k1 ^= tail[ 3] << 24;
323 case 3: k1 ^= tail[ 2] << 16;
324 case 2: k1 ^= tail[ 1] << 8;
325 case 1: k1 ^= tail[ 0] << 0;
326 k1 *= c1; k1 =
rotl32(k1,15); k1 *= c2; h1 ^= k1;
329 ((uint32_t *)out)[0] = h1;
330 ((uint32_t *)out)[1] = h2;
331 ((uint32_t *)out)[2] = h3;
332 ((uint32_t *)out)[3] = h4;
337 uint32_t * seeds,
void * out )
342 uint32_t h1 = seeds[0];
343 uint32_t h2 = seeds[1];
344 uint32_t h3 = seeds[2];
345 uint32_t h4 = seeds[3];
347 h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
349 h1 += h2; h1 += h3; h1 += h4;
350 h2 += h1; h3 += h1; h4 += h1;
357 h1 += h2; h1 += h3; h1 += h4;
358 h2 += h1; h3 += h1; h4 += h1;
360 ((uint32_t *)out)[0] = h1;
361 ((uint32_t *)out)[1] = h2;
362 ((uint32_t *)out)[2] = h3;
363 ((uint32_t *)out)[3] = h4;
369 const uint32_t seed,
void * out )
371 const uint8_t *
data = (
const uint8_t*)key;
372 const int nblocks = len / 16;
383 const uint64_t * blocks = (
const uint64_t *)(data);
385 for(
int i = 0; i < nblocks; i++)
387 uint64_t k1 =
getblock(blocks,i*2+0);
388 uint64_t k2 =
getblock(blocks,i*2+1);
390 k1 *= c1; k1 =
rotl64(k1,31); k1 *= c2; h1 ^= k1;
392 h1 =
rotl64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
394 k2 *= c2; k2 =
rotl64(k2,33); k2 *= c1; h2 ^= k2;
396 h2 =
rotl64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
402 const uint8_t * tail = (
const uint8_t*)(data + nblocks*16);
409 case 15: k2 ^= uint64_t(tail[14]) << 48;
410 case 14: k2 ^= uint64_t(tail[13]) << 40;
411 case 13: k2 ^= uint64_t(tail[12]) << 32;
412 case 12: k2 ^= uint64_t(tail[11]) << 24;
413 case 11: k2 ^= uint64_t(tail[10]) << 16;
414 case 10: k2 ^= uint64_t(tail[ 9]) << 8;
415 case 9: k2 ^= uint64_t(tail[ 8]) << 0;
416 k2 *= c2; k2 =
rotl64(k2,33); k2 *= c1; h2 ^= k2;
418 case 8: k1 ^= uint64_t(tail[ 7]) << 56;
419 case 7: k1 ^= uint64_t(tail[ 6]) << 48;
420 case 6: k1 ^= uint64_t(tail[ 5]) << 40;
421 case 5: k1 ^= uint64_t(tail[ 4]) << 32;
422 case 4: k1 ^= uint64_t(tail[ 3]) << 24;
423 case 3: k1 ^= uint64_t(tail[ 2]) << 16;
424 case 2: k1 ^= uint64_t(tail[ 1]) << 8;
425 case 1: k1 ^= uint64_t(tail[ 0]) << 0;
426 k1 *= c1; k1 =
rotl64(k1,31); k1 *= c2; h1 ^= k1;
432 h1 ^= len; h2 ^= len;
443 ((uint32_t *)out)[0] = h1;
444 ((uint32_t *)out)[1] = h2;
467 using namespace Murmur3Implementation;
480 using namespace Murmur3Implementation;
486 (uint32_t*)(
void *)
m_hash64, (
void *)hash);