@@ -29,30 +29,37 @@ typedef unsigned char uint8_t;
2929typedef unsigned int uint32_t ;
3030typedef unsigned __int64 uint64_t ;
3131
32- #define MURMUR3_FORCE_INLINE __forceinline
32+ #define FORCE_INLINE __forceinline
3333
3434#include <stdlib.h>
3535
36- #define MURMUR3_ROTL64 (x ,y ) _rotl64(x,y)
36+ #define ROTL32 (x ,y ) _rotl(x,y)
37+ #define ROTL64 (x ,y ) _rotl64(x,y)
3738
38- #define MURMUR3_BIG_CONSTANT (x ) (x)
39+ #define BIG_CONSTANT (x ) (x)
3940
4041// Other compilers
4142
4243#else // defined(_MSC_VER)
4344
4445#include <stdint.h>
4546
46- #define MURMUR3_FORCE_INLINE inline __attribute__((always_inline))
47+ #define FORCE_INLINE inline __attribute__((always_inline))
48+
49+ inline uint32_t rotl32 ( uint32_t x , int8_t r )
50+ {
51+ return (x << r ) | (x >> (32 - r ));
52+ }
4753
4854inline uint64_t rotl64 ( uint64_t x , int8_t r )
4955{
5056 return (x << r ) | (x >> (64 - r ));
5157}
5258
53- #define MURMUR3_ROTL64 (x ,y ) rotl64(x,y)
59+ #define ROTL32 (x ,y ) rotl32(x,y)
60+ #define ROTL64 (x ,y ) rotl64(x,y)
5461
55- #define MURMUR3_BIG_CONSTANT (x ) (x##LLU)
62+ #define BIG_CONSTANT (x ) (x##LLU)
5663
5764#endif // !defined(_MSC_VER)
5865
@@ -71,7 +78,7 @@ typedef struct {
7178// Block read - if your platform needs to do endian-swapping or can only
7279// handle aligned reads, do the conversion here
7380
74- MURMUR3_FORCE_INLINE uint64_t getblock64 ( const uint64_t * p , size_t i )
81+ FORCE_INLINE uint64_t getblock64 ( const uint64_t * p , size_t i )
7582{
7683 uint64_t res ;
7784 memcpy (& res , p + i , sizeof (res ));
@@ -81,21 +88,20 @@ MURMUR3_FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, size_t i )
8188//-----------------------------------------------------------------------------
8289// Finalization mix - force all bits of a hash block to avalanche
8390
84- MURMUR3_FORCE_INLINE uint64_t fmix64 ( uint64_t k )
91+ FORCE_INLINE uint64_t fmix64 ( uint64_t k )
8592{
8693 k ^= k >> 33 ;
87- k *= MURMUR3_BIG_CONSTANT (0xff51afd7ed558ccd );
94+ k *= BIG_CONSTANT (0xff51afd7ed558ccd );
8895 k ^= k >> 33 ;
89- k *= MURMUR3_BIG_CONSTANT (0xc4ceb9fe1a85ec53 );
96+ k *= BIG_CONSTANT (0xc4ceb9fe1a85ec53 );
9097 k ^= k >> 33 ;
9198
9299 return k ;
93100}
94101
95- MURMUR3_FORCE_INLINE void MurmurHash3_x64_128 (const void * key , size_t lenBytes ,
96- uint64_t seed , HashState & out ) {
97- static const uint64_t c1 = MURMUR3_BIG_CONSTANT (0x87c37b91114253d5 );
98- static const uint64_t c2 = MURMUR3_BIG_CONSTANT (0x4cf5ad432745937f );
102+ FORCE_INLINE void MurmurHash3_x64_128 (const void * key , size_t lenBytes , uint64_t seed , HashState & out ) {
103+ static const uint64_t c1 = BIG_CONSTANT (0x87c37b91114253d5 );
104+ static const uint64_t c2 = BIG_CONSTANT (0x4cf5ad432745937f );
99105
100106 const uint8_t * data = (const uint8_t * )key ;
101107
@@ -112,13 +118,13 @@ MURMUR3_FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes,
112118 uint64_t k1 = getblock64 (blocks , i * 2 + 0 );
113119 uint64_t k2 = getblock64 (blocks , i * 2 + 1 );
114120
115- k1 *= c1 ; k1 = MURMUR3_ROTL64 (k1 ,31 ); k1 *= c2 ; out .h1 ^= k1 ;
116- out .h1 = MURMUR3_ROTL64 (out .h1 ,27 );
121+ k1 *= c1 ; k1 = ROTL64 (k1 ,31 ); k1 *= c2 ; out .h1 ^= k1 ;
122+ out .h1 = ROTL64 (out .h1 ,27 );
117123 out .h1 += out .h2 ;
118124 out .h1 = out .h1 * 5 + 0x52dce729 ;
119125
120- k2 *= c2 ; k2 = MURMUR3_ROTL64 (k2 ,33 ); k2 *= c1 ; out .h2 ^= k2 ;
121- out .h2 = MURMUR3_ROTL64 (out .h2 ,31 );
126+ k2 *= c2 ; k2 = ROTL64 (k2 ,33 ); k2 *= c1 ; out .h2 ^= k2 ;
127+ out .h2 = ROTL64 (out .h2 ,31 );
122128 out .h2 += out .h1 ;
123129 out .h2 = out .h2 * 5 + 0x38495ab5 ;
124130 }
@@ -138,7 +144,7 @@ MURMUR3_FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes,
138144 case 11 : k2 ^= ((uint64_t )tail [10 ]) << 16 ; // falls through
139145 case 10 : k2 ^= ((uint64_t )tail [ 9 ]) << 8 ; // falls through
140146 case 9 : k2 ^= ((uint64_t )tail [ 8 ]) << 0 ;
141- k2 *= c2 ; k2 = MURMUR3_ROTL64 (k2 ,33 ); k2 *= c1 ; out .h2 ^= k2 ;
147+ k2 *= c2 ; k2 = ROTL64 (k2 ,33 ); k2 *= c1 ; out .h2 ^= k2 ;
142148 // falls through
143149 case 8 : k1 ^= ((uint64_t )tail [ 7 ]) << 56 ; // falls through
144150 case 7 : k1 ^= ((uint64_t )tail [ 6 ]) << 48 ; // falls through
@@ -148,7 +154,7 @@ MURMUR3_FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes,
148154 case 3 : k1 ^= ((uint64_t )tail [ 2 ]) << 16 ; // falls through
149155 case 2 : k1 ^= ((uint64_t )tail [ 1 ]) << 8 ; // falls through
150156 case 1 : k1 ^= ((uint64_t )tail [ 0 ]) << 0 ;
151- k1 *= c1 ; k1 = MURMUR3_ROTL64 (k1 ,31 ); k1 *= c2 ; out .h1 ^= k1 ;
157+ k1 *= c1 ; k1 = ROTL64 (k1 ,31 ); k1 *= c2 ; out .h1 ^= k1 ;
152158 };
153159
154160 //----------
@@ -169,14 +175,10 @@ MURMUR3_FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes,
169175
170176//-----------------------------------------------------------------------------
171177
172- MURMUR3_FORCE_INLINE uint16_t compute_seed_hash (uint64_t seed ) {
178+ FORCE_INLINE uint16_t compute_seed_hash (uint64_t seed ) {
173179 HashState hashes ;
174180 MurmurHash3_x64_128 (& seed , sizeof (seed ), 0 , hashes );
175181 return static_cast < uint16_t > (hashes .h1 & 0xffff );
176182}
177183
178- #undef MURMUR3_FORCE_INLINE
179- #undef MURMUR3_ROTL64
180- #undef MURMUR3_BIG_CONSTANT
181-
182184#endif // _MURMURHASH3_H_
0 commit comments