33 #if defined(__sparc) || defined(__sparc__) \ 34 || defined(_POWER) || defined(__powerpc__) \ 35 || defined(__ppc__) || defined(__hpux) || defined(__hppa) \ 36 || defined(_MIPSEB) || defined(_POWER) \ 38 # define WORDS_BIGENDIAN 39 #elif defined(__i386__) || defined(__alpha__) \ 40 || defined(__ia64) || defined(__ia64__) \ 41 || defined(_M_IX86) || defined(_M_IA64) \ 42 || defined(_M_ALPHA) || defined(__amd64) \ 43 || defined(__amd64__) || defined(_M_AMD64) \ 44 || defined(__x86_64) || defined(__x86_64__) \ 45 || defined(_M_X64) || defined(__bfin__) 46 # define WORDS_LITTLEENDIAN 49 #if !defined(WORDS_BIGENDIAN) 50 # define uint32_in_expected_order(x) (x) 51 # define uint64_in_expected_order(x) (x) 55 # define bswap_32(x) _byteswap_ulong(x) 56 # define bswap_64(x) _byteswap_uint64(x) 57 # elif defined(__APPLE__) 59 # include <libkern/OSByteOrder.h> 60 # define bswap_32(x) OSSwapInt32(x) 61 # define bswap_64(x) OSSwapInt64(x) 63 # include <byteswap.h> 65 # define uint32_in_expected_order(x) (bswap_32(x)) 66 # define uint64_in_expected_order(x) (bswap_64(x)) 67 #endif // WORDS_BIGENDIAN 71 # define inline __inline 76 # if defined __GNUC__ && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))//GCC 2.96 above 77 # define LIKELY(x) (__builtin_expect(!!(x), 1)) 79 # define LIKELY(x) (x) 83 #define UNSAFE_SWAP(type, a, b) do {type tmp;tmp=(a);(a)=(b);(b)=tmp;} while (0) 94 memcpy(&result, p,
sizeof(result));
100 memcpy(&result, p,
sizeof(result));
106 static const uint64 kMul = 0x9ddfea08eb382d69ULL;
134 return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
141 return (val >> shift) | (val << (64 - shift));
145 return val ^ (val >> 47);
165 uint8 b = s[len >> 1];
166 uint8 c = s[len - 1];
190 b =
Rotate(b + a + z, 21);
219 vs = b +
Rotate(a, 31) + c;
228 ws = b +
Rotate(a, 31) + c;
240 }
else if (len <= 64) {
255 len = (len - 1) & ~(
size_t)63;
288 signed long l = len - 16;
352 }
while (
LIKELY(len >= 128));
356 for (tail_done = 0; tail_done < len; ) {
381 }
else if (len >= 8) {
393 #include <nmmintrin.h> 396 static void CityHashCrc256Long(
const char *s,
size_t len,
uint32 seed,
uint64 *result) {
410 size_t iters = len / 240;
413 #define CHUNK(multiplier, z) \ 416 a = Rotate(b, 41 ^ z) * multiplier + Fetch64(s); \ 417 b = Rotate(c, 27 ^ z) * multiplier + Fetch64(s + 8); \ 418 c = Rotate(d, 41 ^ z) * multiplier + Fetch64(s + 16); \ 419 d = Rotate(e, 33 ^ z) * multiplier + Fetch64(s + 24); \ 420 e = Rotate(t, 25 ^ z) * multiplier + Fetch64(s + 32); \ 423 f = _mm_crc32_u64(f, a); \ 424 g = _mm_crc32_u64(g, b); \ 425 h = _mm_crc32_u64(h, c); \ 426 i = _mm_crc32_u64(i, d); \ 427 j = _mm_crc32_u64(j, e); \ 430 CHUNK(1, 1); CHUNK(
k0, 0);
431 CHUNK(1, 1); CHUNK(
k0, 0);
432 CHUNK(1, 1); CHUNK(
k0, 0);
433 }
while (--iters > 0);
454 result[0] = e + f + g + h;
456 result[1] += a + result[0];
458 result[2] = a + result[1];
460 result[3] = a + result[2];
464 static inline void CityHashCrc256Short(
const char *s,
size_t len,
uint64 *result) {
467 memset(buf + len, 0, 240 - len);
468 CityHashCrc256Long(buf, 240, ~(
uint32)len, result);
473 CityHashCrc256Long(s, len, 0, result);
475 CityHashCrc256Short(s, len, result);
498 return UInt128(result[2], result[3]);
static uint32 Fetch32(const char *p)
static uint128 WeakHashLen32WithSeeds3(const char *s, uint64 a, uint64 b)
uint128 CityHash128WithSeed(const char *s, size_t len, uint128 seed)
uint128 CityHash128(const char *s, size_t len)
uint128 CityHashCrc128(const char *s, size_t len)
uint128 CityHashCrc128WithSeed(const char *s, size_t len, uint128 seed)
#define UNSAFE_SWAP(type, a, b)
static uint64 RotateByAtLeast1(uint64 val, int shift)
static uint64 UNALIGNED_LOAD64(const char *p)
uint64 CityHash64WithSeeds(const char *s, size_t len, uint64 seed0, uint64 seed1)
static uint32 UNALIGNED_LOAD32(const char *p)
static uint64 Rotate(uint64 val, int shift)
uint64 CityHash64(const char *s, size_t len)
static uint64 HashLen17to32(const char *s, size_t len)
static uint64 Hash64Pairto64(uint64 u, uint64 v)
#define uint32_in_expected_order(x)
static uint128 WeakHashLen32WithSeeds6(uint64 w, uint64 x, uint64 y, uint64 z, uint64 a, uint64 b)
static uint128 CityMurmur(const char *s, size_t len, uint128 seed)
uint64 CityHash64WithSeed(const char *s, size_t len, uint64 seed)
static uint64 Fetch64(const char *p)
static uint64 ShiftMix(uint64 val)
static uint64 HashLen0to16(const char *s, size_t len)
#define uint64_in_expected_order(x)
static uint128 UInt128(uint64 low, uint64 high)
static uint64 HashLen33to64(const char *s, size_t len)
static uint64 HashLen16(uint64 u, uint64 v)
void CityHashCrc256(const char *s, size_t len, uint64 *result)