9 #include "jasl/jasl_internal/jasl_diagnostic.hpp" 28 #if defined(_MSC_VER) && (_MSC_VER < 1600) 30 typedef unsigned char uint8_t;
31 typedef unsigned int uint32_t;
32 typedef unsigned __int64 uint64_t;
36 #else // defined(_MSC_VER) 40 #endif // !defined(_MSC_VER) 46 # define FORCE_INLINE __forceinline 50 # define ROTL32(x, y) _rotl(x, y) 51 # define ROTL64(x, y) _rotl64(x, y) 53 # define BIG_CONSTANT(x) (x) 57 #else // defined(_MSC_VER) 59 # define FORCE_INLINE inline __attribute__((always_inline)) 62 namespace murmurhash3 {
64 inline uint32_t rotl32(uint32_t x, int8_t r) {
65 return (x << r) | (x >> (32 - r));
68 inline uint64_t rotl64(uint64_t x, int8_t r) {
69 return (x << r) | (x >> (64 - r));
75 # define ROTL32(x, y) rotl32(x, y) 76 # define ROTL64(x, y) rotl64(x, y) 78 # define BIG_CONSTANT(x) (x##LLU) 80 #endif // !defined(_MSC_VER) 83 namespace murmurhash3 {
85 JASL_DIAGNOSTIC_PUSH()
86 JASL_DIAGNOSTIC_IGNORED_CLANG(JASL_WARNING_OLD_STYLE_CAST)
87 JASL_DIAGNOSTIC_IGNORED_CLANG(JASL_WARNING_SIGN_CONVERSION)
88 JASL_DIAGNOSTIC_IGNORED_CLANG(JASL_WARNING_IMPLICIT_FALLTHROUGH)
89 JASL_DIAGNOSTIC_IGNORED_GCC_SINCE7(JASL_WARNING_IMPLICIT_FALLTHROUGH)
90 JASL_DIAGNOSTIC_IGNORED_CLANG(JAS_WARNING_CAST_ALING)
92 #if defined(__clang__) 93 # if __has_attribute(no_sanitize) 94 # define JASL_USAN_IGNORE(type) __attribute__((no_sanitize(# type))) 96 # define JASL_USAN_IGNORE(type) 99 # define JASL_USAN_IGNORE(type) 106 FORCE_INLINE uint32_t getblock32(
const uint32_t* p,
int i) {
110 FORCE_INLINE uint64_t getblock64(
const uint64_t* p,
int i) {
117 JASL_USAN_IGNORE(integer) FORCE_INLINE uint32_t fmix32(uint32_t h) {
129 JASL_USAN_IGNORE(integer) FORCE_INLINE uint64_t fmix64(uint64_t k) {
131 k *= BIG_CONSTANT(0xff51afd7ed558ccd);
133 k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
141 JASL_USAN_IGNORE(integer)
142 void MurmurHash3_x86_128(
const void* key,
146 const uint8_t* data = (
const uint8_t*)key;
147 const int nblocks = len / 16;
154 const uint32_t c1 = 0x239b961b;
155 const uint32_t c2 = 0xab0e9789;
156 const uint32_t c3 = 0x38b34ae5;
157 const uint32_t c4 = 0xa1e38b93;
162 const uint32_t* blocks = (
const uint32_t*)(data + nblocks * 16);
164 for (
int i = -nblocks; i; i++) {
165 uint32_t k1 = getblock32(blocks, i * 4 + 0);
166 uint32_t k2 = getblock32(blocks, i * 4 + 1);
167 uint32_t k3 = getblock32(blocks, i * 4 + 2);
168 uint32_t k4 = getblock32(blocks, i * 4 + 3);
177 h1 = h1 * 5 + 0x561ccd1b;
186 h2 = h2 * 5 + 0x0bcaa747;
195 h3 = h3 * 5 + 0x96cd1c35;
204 h4 = h4 * 5 + 0x32ac3b17;
210 const uint8_t* tail = (
const uint8_t*)(data + nblocks * 16);
219 k4 ^= tail[14] << 16;
230 k3 ^= tail[11] << 24;
232 k3 ^= tail[10] << 16;
296 ((uint32_t*)out)[0] = h1;
297 ((uint32_t*)out)[1] = h2;
298 ((uint32_t*)out)[2] = h3;
299 ((uint32_t*)out)[3] = h4;
304 JASL_USAN_IGNORE(integer)
305 void MurmurHash3_x64_128(
const void* key,
309 const uint8_t* data = (
const uint8_t*)key;
310 const int nblocks = len / 16;
315 const uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
316 const uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
321 const uint64_t* blocks = (
const uint64_t*)(data);
323 for (
int i = 0; i < nblocks; i++) {
324 uint64_t k1 = getblock64(blocks, i * 2 + 0);
325 uint64_t k2 = getblock64(blocks, i * 2 + 1);
334 h1 = h1 * 5 + 0x52dce729;
343 h2 = h2 * 5 + 0x38495ab5;
349 const uint8_t* tail = (
const uint8_t*)(data + nblocks * 16);
356 k2 ^= ((uint64_t)tail[14]) << 48;
358 k2 ^= ((uint64_t)tail[13]) << 40;
360 k2 ^= ((uint64_t)tail[12]) << 32;
362 k2 ^= ((uint64_t)tail[11]) << 24;
364 k2 ^= ((uint64_t)tail[10]) << 16;
366 k2 ^= ((uint64_t)tail[9]) << 8;
368 k2 ^= ((uint64_t)tail[8]) << 0;
375 k1 ^= ((uint64_t)tail[7]) << 56;
377 k1 ^= ((uint64_t)tail[6]) << 48;
379 k1 ^= ((uint64_t)tail[5]) << 40;
381 k1 ^= ((uint64_t)tail[4]) << 32;
383 k1 ^= ((uint64_t)tail[3]) << 24;
385 k1 ^= ((uint64_t)tail[2]) << 16;
387 k1 ^= ((uint64_t)tail[1]) << 8;
389 k1 ^= ((uint64_t)tail[0]) << 0;
411 ((uint64_t*)out)[0] = h1;
412 ((uint64_t*)out)[1] = h2;
415 JASL_DIAGNOSTIC_POP()
Definition: jasl_static_string.hpp:18