10 #include "caffe2/utils/murmur_hash3.h" 19 #define FORCE_INLINE __forceinline 21 #define FALLTHROUGH_INTENDED 25 #define ROTL32(x, y) _rotl(x, y) 26 #define ROTL64(x, y) _rotl64(x, y) 28 #define BIG_CONSTANT(x) (x) 32 #else // defined(_MSC_VER) 34 #define FORCE_INLINE inline __attribute__((__always_inline__)) 36 #if defined(__clang__) && defined(__has_cpp_attribute) 37 #if __has_cpp_attribute(clang::fallthrough) 38 #define FALLTHROUGH_INTENDED [[clang::fallthrough]] 40 #elif defined(__GNUC__) && __GNUC__ > 6 41 #define FALLTHROUGH_INTENDED [[gnu::fallthrough]] 43 #ifndef FALLTHROUGH_INTENDED 44 #define FALLTHROUGH_INTENDED 47 inline uint32_t rotl32(uint32_t x, int8_t r) {
48 return (x << r) | (x >> (32 - r));
51 inline uint64_t rotl64(uint64_t x, int8_t r) {
52 return (x << r) | (x >> (64 - r));
55 #define ROTL32(x, y) rotl32(x, y) 56 #define ROTL64(x, y) rotl64(x, y) 58 #define BIG_CONSTANT(x) (x##LLU) 60 #endif // !defined(_MSC_VER) 66 FORCE_INLINE uint32_t getblock32(
const uint32_t* p,
int i) {
70 FORCE_INLINE uint64_t getblock64(
const uint64_t* p,
int i) {
77 FORCE_INLINE uint32_t fmix32(uint32_t h) {
89 FORCE_INLINE uint64_t fmix64(uint64_t k) {
91 k *= BIG_CONSTANT(0xff51afd7ed558ccd);
93 k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
101 void MurmurHash3_x86_32(
const void* key,
int len, uint32_t seed,
void* out) {
102 const uint8_t* data = (
const uint8_t*)key;
103 const int nblocks = len / 4;
107 const uint32_t c1 = 0xcc9e2d51;
108 const uint32_t c2 = 0x1b873593;
113 const uint32_t* blocks = (
const uint32_t*)(data + nblocks * 4);
115 for (
int i = -nblocks; i; i++) {
116 uint32_t k1 = getblock32(blocks, i);
124 h1 = h1 * 5 + 0xe6546b64;
130 const uint8_t* tail = (
const uint8_t*)(data + nblocks * 4);
137 FALLTHROUGH_INTENDED;
140 FALLTHROUGH_INTENDED;
156 *(uint32_t*)out = h1;
161 void MurmurHash3_x86_128(
166 const uint8_t* data = (
const uint8_t*)key;
167 const int nblocks = len / 16;
174 const uint32_t c1 = 0x239b961b;
175 const uint32_t c2 = 0xab0e9789;
176 const uint32_t c3 = 0x38b34ae5;
177 const uint32_t c4 = 0xa1e38b93;
182 const uint32_t* blocks = (
const uint32_t*)(data + nblocks * 16);
184 for (
int i = -nblocks; i; i++) {
185 uint32_t k1 = getblock32(blocks, i * 4 + 0);
186 uint32_t k2 = getblock32(blocks, i * 4 + 1);
187 uint32_t k3 = getblock32(blocks, i * 4 + 2);
188 uint32_t k4 = getblock32(blocks, i * 4 + 3);
197 h1 = h1 * 5 + 0x561ccd1b;
206 h2 = h2 * 5 + 0x0bcaa747;
215 h3 = h3 * 5 + 0x96cd1c35;
224 h4 = h4 * 5 + 0x32ac3b17;
230 const uint8_t* tail = (
const uint8_t*)(data + nblocks * 16);
239 k4 ^= tail[14] << 16;
240 FALLTHROUGH_INTENDED;
243 FALLTHROUGH_INTENDED;
250 FALLTHROUGH_INTENDED;
253 k3 ^= tail[11] << 24;
254 FALLTHROUGH_INTENDED;
256 k3 ^= tail[10] << 16;
257 FALLTHROUGH_INTENDED;
260 FALLTHROUGH_INTENDED;
267 FALLTHROUGH_INTENDED;
271 FALLTHROUGH_INTENDED;
274 FALLTHROUGH_INTENDED;
277 FALLTHROUGH_INTENDED;
284 FALLTHROUGH_INTENDED;
288 FALLTHROUGH_INTENDED;
291 FALLTHROUGH_INTENDED;
294 FALLTHROUGH_INTENDED;
330 ((uint32_t*)out)[0] = h1;
331 ((uint32_t*)out)[1] = h2;
332 ((uint32_t*)out)[2] = h3;
333 ((uint32_t*)out)[3] = h4;
338 void MurmurHash3_x64_128(
343 const uint8_t* data = (
const uint8_t*)key;
344 const int nblocks = len / 16;
349 const uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
350 const uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
355 const uint64_t* blocks = (
const uint64_t*)(data);
357 for (
int i = 0; i < nblocks; i++) {
358 uint64_t k1 = getblock64(blocks, i * 2 + 0);
359 uint64_t k2 = getblock64(blocks, i * 2 + 1);
368 h1 = h1 * 5 + 0x52dce729;
377 h2 = h2 * 5 + 0x38495ab5;
383 const uint8_t* tail = (
const uint8_t*)(data + nblocks * 16);
390 k2 ^= ((uint64_t)tail[14]) << 48;
391 FALLTHROUGH_INTENDED;
393 k2 ^= ((uint64_t)tail[13]) << 40;
394 FALLTHROUGH_INTENDED;
396 k2 ^= ((uint64_t)tail[12]) << 32;
397 FALLTHROUGH_INTENDED;
399 k2 ^= ((uint64_t)tail[11]) << 24;
400 FALLTHROUGH_INTENDED;
402 k2 ^= ((uint64_t)tail[10]) << 16;
403 FALLTHROUGH_INTENDED;
405 k2 ^= ((uint64_t)tail[9]) << 8;
406 FALLTHROUGH_INTENDED;
408 k2 ^= ((uint64_t)tail[8]) << 0;
413 FALLTHROUGH_INTENDED;
416 k1 ^= ((uint64_t)tail[7]) << 56;
417 FALLTHROUGH_INTENDED;
419 k1 ^= ((uint64_t)tail[6]) << 48;
420 FALLTHROUGH_INTENDED;
422 k1 ^= ((uint64_t)tail[5]) << 40;
423 FALLTHROUGH_INTENDED;
425 k1 ^= ((uint64_t)tail[4]) << 32;
426 FALLTHROUGH_INTENDED;
428 k1 ^= ((uint64_t)tail[3]) << 24;
429 FALLTHROUGH_INTENDED;
431 k1 ^= ((uint64_t)tail[2]) << 16;
432 FALLTHROUGH_INTENDED;
434 k1 ^= ((uint64_t)tail[1]) << 8;
435 FALLTHROUGH_INTENDED;
437 k1 ^= ((uint64_t)tail[0]) << 0;
459 ((uint64_t*)out)[0] = h1;
460 ((uint64_t*)out)[1] = h2;
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...