HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
farmhash.h
Go to the documentation of this file.
1 // Copyright (c) 2014 Google, Inc.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 //
21 // FarmHash, by Geoff Pike
22 
23 // clang-format off
24 
25 // https://github.com/google/farmhash
26 
27 #pragma once
28 
29 #include <OpenImageIO/hash.h>
30 
31 #define NAMESPACE_FOR_HASH_FUNCTIONS OIIO::farmhash
32 
33 #ifdef _MSC_VER
34 // Disable pointless windows warning
35 #pragma warning( disable : 4319 )
36 #endif
37 
38 
39 // FARMHASH ASSUMPTIONS: Modify as needed, or use -DFARMHASH_ASSUME_SSE42 etc.
40 // Note that if you use -DFARMHASH_ASSUME_SSE42 you likely need -msse42
41 // (or its equivalent for your compiler); if you use -DFARMHASH_ASSUME_AESNI
42 // you likely need -maes (or its equivalent for your compiler).
43 
44 #ifdef FARMHASH_ASSUME_SSSE3
45 #undef FARMHASH_ASSUME_SSSE3
46 #define FARMHASH_ASSUME_SSSE3 1
47 #endif
48 
49 #ifdef FARMHASH_ASSUME_SSE41
50 #undef FARMHASH_ASSUME_SSE41
51 #define FARMHASH_ASSUME_SSE41 1
52 #endif
53 
54 #ifdef FARMHASH_ASSUME_SSE42
55 #undef FARMHASH_ASSUME_SSE42
56 #define FARMHASH_ASSUME_SSE42 1
57 #endif
58 
59 #ifdef FARMHASH_ASSUME_AESNI
60 #undef FARMHASH_ASSUME_AESNI
61 #define FARMHASH_ASSUME_AESNI 1
62 #endif
63 
64 #ifdef FARMHASH_ASSUME_AVX
65 #undef FARMHASH_ASSUME_AVX
66 #define FARMHASH_ASSUME_AVX 1
67 #endif
68 
69 #if !defined(FARMHASH_CAN_USE_CXX11) && defined(LANG_CXX11)
70 #define FARMHASH_CAN_USE_CXX11 1
71 #else
72 #undef FARMHASH_CAN_USE_CXX11
73 #define FARMHASH_CAN_USE_CXX11 0
74 #endif
75 
76 // FARMHASH PORTABILITY LAYER: "static inline" or similar
77 
78 // Make static inline 'const expr, if possible. Also, try to make CUDA friendly
79 // for device code.
80 #undef STATIC_INLINE
81 #if OIIO_CPLUSPLUS_VERSION >= 14
82 # define HASH_CAN_USE_CONSTEXPR 1
83 #endif
84 #define STATIC_INLINE OIIO_HOSTDEVICE inline OIIO_CONSTEXPR14
85 
86 // FARMHASH PORTABILITY LAYER: Runtime error if misconfigured
87 
88 #ifndef FARMHASH_DIE_IF_MISCONFIGURED
89 #ifdef HASH_CAN_USE_CONSTEXPR
90 #define FARMHASH_DIE_IF_MISCONFIGURED
91 #else
92 #define FARMHASH_DIE_IF_MISCONFIGURED do { *(char*)(len % 17) = 0; } while (0)
93 #endif
94 #endif
95 
96 // FARMHASH PORTABILITY LAYER: endianness and byteswapping functions
97 
98 #ifdef WORDS_BIGENDIAN
99 #undef FARMHASH_BIG_ENDIAN
100 #define FARMHASH_BIG_ENDIAN 1
101 #endif
102 
103 #if defined(FARMHASH_LITTLE_ENDIAN) && defined(FARMHASH_BIG_ENDIAN)
104 #error
105 #endif
106 
107 #if !defined(FARMHASH_LITTLE_ENDIAN) && !defined(FARMHASH_BIG_ENDIAN)
108 #define FARMHASH_UNKNOWN_ENDIAN 1
109 #endif
110 
111 #if !defined(bswap_32) || !defined(bswap_64)
112 #undef bswap_32
113 #undef bswap_64
114 
115 #if defined(HAVE_BUILTIN_BSWAP) || defined(__clang__) || \
116  (defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || \
117  __GNUC__ >= 5))
118 // Easy case for bswap: no header file needed.
119 #define bswap_32(x) __builtin_bswap32(x)
120 #define bswap_64(x) __builtin_bswap64(x)
121 #endif
122 
123 #endif
124 
125 #if defined(FARMHASH_UNKNOWN_ENDIAN) || !defined(bswap_64)
126 
127 #ifdef _WIN32
128 
129 #undef bswap_32
130 #undef bswap_64
131 #define bswap_32(x) _byteswap_ulong(x)
132 #define bswap_64(x) _byteswap_uint64(x)
133 
134 #elif defined(__APPLE__)
135 
136 // Mac OS X / Darwin features
137 #include <libkern/OSByteOrder.h>
138 #undef bswap_32
139 #undef bswap_64
140 #define bswap_32(x) OSSwapInt32(x)
141 #define bswap_64(x) OSSwapInt64(x)
142 
143 #elif defined(__sun) || defined(sun)
144 
145 #include <sys/byteorder.h>
146 #undef bswap_32
147 #undef bswap_64
148 #define bswap_32(x) BSWAP_32(x)
149 #define bswap_64(x) BSWAP_64(x)
150 
151 #elif defined(__FreeBSD__)
152 
153 #include <sys/endian.h>
154 #undef bswap_32
155 #undef bswap_64
156 #define bswap_32(x) bswap32(x)
157 #define bswap_64(x) bswap64(x)
158 
159 #elif defined(__OpenBSD__)
160 
161 #include <sys/types.h>
162 #undef bswap_32
163 #undef bswap_64
164 #define bswap_32(x) swap32(x)
165 #define bswap_64(x) swap64(x)
166 
167 #elif defined(__NetBSD__)
168 
169 #include <sys/types.h>
170 #include <machine/bswap.h>
171 #if defined(__BSWAP_RENAME) && !defined(__bswap_32)
172 #undef bswap_32
173 #undef bswap_64
174 #define bswap_32(x) bswap32(x)
175 #define bswap_64(x) bswap64(x)
176 #endif
177 
178 #else
179 
180 #undef bswap_32
181 #undef bswap_64
182 #include <byteswap.h>
183 
184 #endif
185 
186 #ifdef WORDS_BIGENDIAN
187 #define FARMHASH_BIG_ENDIAN 1
188 #endif
189 
190 #endif
191 
192 
193 #ifdef FARMHASH_BIG_ENDIAN
194 #define uint32_in_expected_order(x) (bswap_32(x))
195 #define uint64_in_expected_order(x) (bswap_64(x))
196 #else
197 #define uint32_in_expected_order(x) (x)
198 #define uint64_in_expected_order(x) (x)
199 #endif
200 
201 #if !defined(FARMHASH_UINT128_T_DEFINED)
202 #define uint128_t OIIO::farmhash::uint128_t
203 #endif
204 
205 // Simple GPU-friendly swap function
206 template <typename T>
208  T c = a;
209  a = b;
210  b = c;
211 }
212 
213 #define Uint128 OIIO::farmhash::Uint128
214 #define CopyUint128 OIIO::farmhash::CopyUint128
215 #define Uint128Low64 OIIO::farmhash::Uint128Low64
216 #define Uint128High64 OIIO::farmhash::Uint128High64
217 #define Hash128to64 OIIO::farmhash::Hash128to64
218 
219 // namespace NAMESPACE_FOR_HASH_FUNCTIONS {
221 
222 namespace farmhash {
223 namespace inlined {
224 
225 
226 #if !defined(HASH_CAN_USE_CONSTEXPR) || HASH_CAN_USE_CONSTEXPR == 0
227 
228 STATIC_INLINE uint64_t Fetch64(const char *p) {
229  uint64_t result = 0;
230  memcpy(&result, p, sizeof(result));
231  return uint64_in_expected_order(result);
232 }
233 
234 STATIC_INLINE uint32_t Fetch32(const char *p) {
235  uint32_t result;
236  memcpy(&result, p, sizeof(result));
237  return uint32_in_expected_order(result);
238 }
239 
240 #else
241 
242 template <typename T>
243 STATIC_INLINE T FetchType(const char *p) {
244  T result = 0;
245  for (size_t i = 0; i < sizeof(T); i++)
246  reinterpret_cast<char *>(&result)[i] = p[i];
247  return result;
248 }
249 
250 STATIC_INLINE uint64_t Fetch64(const char *p) {
251  return FetchType<uint64_t>(p);
252 }
253 
254 STATIC_INLINE uint32_t Fetch32(const char *p) {
255  return FetchType<uint32_t>(p);
256 }
257 
258 // devices don't seem to have bswap_64() or bswap_32()
259 template<typename T>
260 STATIC_INLINE T bswap(T v) {
261  const int S = sizeof(T);
262  T result = 0;
263 
264  const T mask = 0xff;
265  for (int i = 0; i < S/2; i++) {
266  int hi = 8 * (7 - i);
267  int lo = 8 * i;
268  int shift = 8 * (S - (2*i + 1));
269  T lo_mask = mask << lo;
270  T hi_mask = mask << hi;
271  T new_lo = (v & hi_mask) >> shift;
272  T new_hi = (v & lo_mask) << shift;
273  result |= (new_lo | new_hi);
274  }
275  return result;
276 }
277 #undef bswap_32
278 #undef bswap_64
279 
280 #define bswap_32(x) bswap<uint32_t>(x)
281 #define bswap_64(x) bswap<uint64_t>(x)
282 
283 #endif
284 
285 STATIC_INLINE uint32_t Bswap32(uint32_t val) { return bswap_32(val); }
286 STATIC_INLINE uint64_t Bswap64(uint64_t val) { return bswap_64(val); }
287 
288 // FARMHASH PORTABILITY LAYER: bitwise rot
289 
290 STATIC_INLINE uint32_t BasicRotate32(uint32_t val, int shift) {
291  // Avoid shifting by 32: doing so yields an undefined result.
292  return shift == 0 ? val : ((val >> shift) | (val << (32 - shift)));
293 }
294 
295 STATIC_INLINE uint64_t BasicRotate64(uint64_t val, int shift) {
296  // Avoid shifting by 64: doing so yields an undefined result.
297  return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
298 }
299 
300 #if defined(_MSC_VER) && defined(FARMHASH_ROTR)
301 
302 STATIC_INLINE uint32_t Rotate32(uint32_t val, int shift) {
303  return sizeof(unsigned long) == sizeof(val) ?
304  _lrotr(val, shift) :
305  BasicRotate32(val, shift);
306 }
307 
308 STATIC_INLINE uint64_t Rotate64(uint64_t val, int shift) {
309  return sizeof(unsigned long) == sizeof(val) ?
310  _lrotr(val, shift) :
311  BasicRotate64(val, shift);
312 }
313 
314 #else
315 
316 STATIC_INLINE uint32_t Rotate32(uint32_t val, int shift) {
317  return BasicRotate32(val, shift);
318 }
319 STATIC_INLINE uint64_t Rotate64(uint64_t val, int shift) {
320  return BasicRotate64(val, shift);
321 }
322 
323 #endif
324 
325 // } // namespace NAMESPACE_FOR_HASH_FUNCTIONS
326 } /*end namespace inlined */
327 } /*end namespace farmhash*/ OIIO_NAMESPACE_END
328 
329 // FARMHASH PORTABILITY LAYER: debug mode or max speed?
330 // One may use -DFARMHASH_DEBUG=1 or -DFARMHASH_DEBUG=0 to force the issue.
331 
332 #define FARMHASH_DEBUG 0 /*OIIO addition to ensure no debug vs opt differences*/
333 
334 #if !defined(FARMHASH_DEBUG) && (!defined(NDEBUG) || defined(_DEBUG))
335 #define FARMHASH_DEBUG 1
336 #endif
337 
338 #undef debug_mode
339 #if FARMHASH_DEBUG
340 #define debug_mode 1
341 #else
342 #define debug_mode 0
343 #endif
344 
345 // PLATFORM-SPECIFIC FUNCTIONS AND MACROS
346 
347 #undef x86_64
348 #if defined (__x86_64) || defined (__x86_64__)
349 #define x86_64 1
350 #else
351 #define x86_64 0
352 #endif
353 
354 #undef x86
355 #if defined(__i386__) || defined(__i386) || defined(__X86__)
356 #define x86 1
357 #else
358 #define x86 x86_64
359 #endif
360 
361 #if !defined(is_64bit)
362 #define is_64bit (x86_64 || (sizeof(void*) == 8))
363 #endif
364 
365 #undef can_use_ssse3
366 #if defined(__SSSE3__) || defined(FARMHASH_ASSUME_SSSE3)
367 
368 #include <immintrin.h>
369 #define can_use_ssse3 1
370 // Now we can use _mm_hsub_epi16 and so on.
371 
372 #else
373 #define can_use_ssse3 0
374 #endif
375 
376 #undef can_use_sse41
377 #if defined(__SSE4_1__) || defined(FARMHASH_ASSUME_SSE41)
378 
379 #include <immintrin.h>
380 #define can_use_sse41 1
381 // Now we can use _mm_insert_epi64 and so on.
382 
383 #else
384 #define can_use_sse41 0
385 #endif
386 
387 #undef can_use_sse42
388 #if defined(__SSE4_2__) || defined(FARMHASH_ASSUME_SSE42)
389 
390 #include <nmmintrin.h>
391 #define can_use_sse42 1
392 // Now we can use _mm_crc32_u{32,16,8}. And on 64-bit platforms, _mm_crc32_u64.
393 
394 #else
395 #define can_use_sse42 0
396 #endif
397 
398 #undef can_use_aesni
399 #if defined(__AES__) || defined(FARMHASH_ASSUME_AESNI)
400 
401 #include <wmmintrin.h>
402 #define can_use_aesni 1
403 // Now we can use _mm_aesimc_si128 and so on.
404 
405 #else
406 #define can_use_aesni 0
407 #endif
408 
409 #undef can_use_avx
410 #if defined(__AVX__) || defined(FARMHASH_ASSUME_AVX)
411 
412 #include <immintrin.h>
413 #define can_use_avx 1
414 
415 #else
416 #define can_use_avx 0
417 #endif
418 
419 // clang seems to define __x86_64 flags etc. even if you're compiling for gpu-device
420 #ifdef __CUDA_ARCH__
421 # undef _x86_64
422 # define _x86_64 0
423 # undef x86
424 # define x86 x86_64
425 #endif
426 
427 // skip non-constexpr code-path
428 #ifdef HASH_CAN_USE_CONSTEXPR
429 # undef can_use_ssse3
430 # define can_use_ssse3 0
431 # undef can_use_sse41
432 # define can_use_sse41 0
433 # undef can_use_sse42
434 # define can_use_sse42 0
435 # undef can_use_aesni
436 # define can_use_aesni 0
437 # undef can_use_avx
438 # define can_use_avx 0
439 #endif
440 
441 
442 // Building blocks for hash functions
443 
444 // std::swap() was in <algorithm> but is in <utility> from C++11 on.
445 #if !FARMHASH_CAN_USE_CXX11
446 #include <algorithm>
447 #endif
448 
449 #undef PERMUTE3
450 #define PERMUTE3(a, b, c) do { simpleSwap(a, b); simpleSwap(a, c); } while (0)
451 
452 
453 // namespace NAMESPACE_FOR_HASH_FUNCTIONS {
455 //using namespace OIIO::farmhash;
456  namespace farmhash {
457  namespace inlined {
458 
459 #ifndef __CUDA_ARCH__
460 #if can_use_ssse3 || can_use_sse41 || can_use_sse42 || can_use_aesni || can_use_avx
461 STATIC_INLINE __m128i Fetch128(const char* s) {
462  return _mm_loadu_si128(reinterpret_cast<const __m128i*>(s));
463 }
464 #endif
465 #endif
466 
467 // Some primes between 2^63 and 2^64 for various uses.
468 static const uint64_t k0 = 0xc3a5c85c97cb3127ULL;
469 static const uint64_t k1 = 0xb492b66fbe98f273ULL;
470 static const uint64_t k2 = 0x9ae16a3b2f90404fULL;
471 
472 // Magic numbers for 32-bit hashing. Copied from Murmur3.
473 static const uint32_t c1 = 0xcc9e2d51;
474 static const uint32_t c2 = 0x1b873593;
475 
476 // A 32-bit to 32-bit integer hash copied from Murmur3.
477 STATIC_INLINE uint32_t fmix(uint32_t h)
478 {
479  h ^= h >> 16;
480  h *= 0x85ebca6b;
481  h ^= h >> 13;
482  h *= 0xc2b2ae35;
483  h ^= h >> 16;
484  return h;
485 }
486 
487 STATIC_INLINE uint32_t Mur(uint32_t a, uint32_t h) {
488  // Helper from Murmur3 for combining two 32-bit values.
489  a *= inlined::c1;
490  a = Rotate32(a, 17);
491  a *= inlined::c2;
492  h ^= a;
493  h = Rotate32(h, 19);
494  return h * 5 + 0xe6546b64;
495 }
496 
497 template <typename T> STATIC_INLINE T DebugTweak(T x) {
498  if (debug_mode) {
499  if (sizeof(x) == 4) {
500  x = ~Bswap32(x * inlined::c1);
501  } else {
502  x = ~Bswap64(x * inlined::k1);
503  }
504  }
505  return x;
506 }
507 
509  if (debug_mode) {
510  uint64_t y = DebugTweak(Uint128Low64(x));
511  uint64_t z = DebugTweak(Uint128High64(x));
512  y += z;
513  z += y;
514  CopyUint128(x, Uint128(y, z * inlined::k1));
515  }
516  return x;
517 }
518 
519 // } // namespace NAMESPACE_FOR_HASH_FUNCTIONS
520 } /*end namespace inlined*/
521 
522 using namespace std;
523 // using namespace NAMESPACE_FOR_HASH_FUNCTIONS;
524 namespace farmhashna {
525 #undef Fetch
526 #define Fetch farmhash::inlined::Fetch64
527 
528 #undef Rotate
529 #define Rotate farmhash::inlined::Rotate64
530 
531 #undef Bswap
532 #define Bswap farmhash::inlined::Bswap64
533 
534 STATIC_INLINE uint64_t ShiftMix(uint64_t val) {
535  return val ^ (val >> 47);
536 }
537 
538 STATIC_INLINE uint64_t HashLen16(uint64_t u, uint64_t v) {
539  return Hash128to64(Uint128(u, v));
540 }
541 
542 STATIC_INLINE uint64_t HashLen16(uint64_t u, uint64_t v, uint64_t mul) {
543  // Murmur-inspired hashing.
544  uint64_t a = (u ^ v) * mul;
545  a ^= (a >> 47);
546  uint64_t b = (v ^ a) * mul;
547  b ^= (b >> 47);
548  b *= mul;
549  return b;
550 }
551 
552 STATIC_INLINE uint64_t HashLen0to16(const char *s, size_t len) {
553  if (len >= 8) {
554  uint64_t mul = inlined::k2 + len * 2;
555  uint64_t a = Fetch(s) + inlined::k2;
556  uint64_t b = Fetch(s + len - 8);
557  uint64_t c = Rotate(b, 37) * mul + a;
558  uint64_t d = (Rotate(a, 25) + b) * mul;
559  return HashLen16(c, d, mul);
560  }
561  if (len >= 4) {
562  uint64_t mul = inlined::k2 + len * 2;
563  uint64_t a = inlined::Fetch32(s);
564  return HashLen16(len + (a << 3), inlined::Fetch32(s + len - 4), mul);
565  }
566  if (len > 0) {
567  uint8_t a = s[0];
568  uint8_t b = s[len >> 1];
569  uint8_t c = s[len - 1];
570  uint32_t y = static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8);
571  uint32_t z = len + (static_cast<uint32_t>(c) << 2);
572  return ShiftMix(y * inlined::k2 ^ z * inlined::k0) * inlined::k2;
573  }
574  return inlined::k2;
575 }
576 
577 // This probably works well for 16-byte strings as well, but it may be overkill
578 // in that case.
579 STATIC_INLINE uint64_t HashLen17to32(const char *s, size_t len) {
580  uint64_t mul = inlined::k2 + len * 2;
581  uint64_t a = Fetch(s) * inlined::k1;
582  uint64_t b = Fetch(s + 8);
583  uint64_t c = Fetch(s + len - 8) * mul;
584  uint64_t d = Fetch(s + len - 16) * inlined::k2;
585  return HashLen16(Rotate(a + b, 43) + Rotate(c, 30) + d,
586  a + Rotate(b + inlined::k2, 18) + c, mul);
587 }
588 
589 // Return a 16-byte hash for 48 bytes. Quick and dirty.
590 // Callers do best to use "random-looking" values for a and b.
591 STATIC_INLINE pair<uint64_t, uint64_t> WeakHashLen32WithSeeds(
592  uint64_t w, uint64_t x, uint64_t y, uint64_t z, uint64_t a, uint64_t b) {
593  a += w;
594  b = Rotate(b + a + z, 21);
595  uint64_t c = a;
596  a += x;
597  a += y;
598  b += Rotate(a, 44);
599  return make_pair(a + z, b + c);
600 }
601 
602 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
603 STATIC_INLINE pair<uint64_t, uint64_t> WeakHashLen32WithSeeds(
604  const char* s, uint64_t a, uint64_t b) {
605  return WeakHashLen32WithSeeds(Fetch(s),
606  Fetch(s + 8),
607  Fetch(s + 16),
608  Fetch(s + 24),
609  a,
610  b);
611 }
612 
613 // Return an 8-byte hash for 33 to 64 bytes.
614 STATIC_INLINE uint64_t HashLen33to64(const char *s, size_t len) {
615  uint64_t mul = inlined::k2 + len * 2;
616  uint64_t a = Fetch(s) * inlined::k2;
617  uint64_t b = Fetch(s + 8);
618  uint64_t c = Fetch(s + len - 8) * mul;
619  uint64_t d = Fetch(s + len - 16) * inlined::k2;
620  uint64_t y = Rotate(a + b, 43) + Rotate(c, 30) + d;
621  uint64_t z = HashLen16(y, a + Rotate(b + inlined::k2, 18) + c, mul);
622  uint64_t e = Fetch(s + 16) * mul;
623  uint64_t f = Fetch(s + 24);
624  uint64_t g = (y + Fetch(s + len - 32)) * mul;
625  uint64_t h = (z + Fetch(s + len - 24)) * mul;
626  return HashLen16(Rotate(e + f, 43) + Rotate(g, 30) + h,
627  e + Rotate(f + a, 18) + g, mul);
628 }
629 
630 STATIC_INLINE uint64_t Hash64(const char *s, size_t len) {
631  const uint64_t seed = 81;
632  if (len <= 32) {
633  if (len <= 16) {
634  return HashLen0to16(s, len);
635  } else {
636  return HashLen17to32(s, len);
637  }
638  } else if (len <= 64) {
639  return HashLen33to64(s, len);
640  }
641 
642  // For strings over 64 bytes we loop. Internal state consists of
643  // 56 bytes: v, w, x, y, and z.
644  uint64_t x = seed;
645  uint64_t y = seed * inlined::k1 + 113;
646  uint64_t z = ShiftMix(y * inlined::k2 + 113) * inlined::k2;
647  pair<uint64_t, uint64_t> v = make_pair(0, 0);
648  pair<uint64_t, uint64_t> w = make_pair(0, 0);
649  x = x * inlined::k2 + Fetch(s);
650 
651  // Set end so that after the loop we have 1 to 64 bytes left to process.
652  const char* end = s + ((len - 1) / 64) * 64;
653  const char* last64 = end + ((len - 1) & 63) - 63;
654  assert(s + len - 64 == last64);
655  do {
656  x = Rotate(x + y + v.first + Fetch(s + 8), 37) * inlined::k1;
657  y = Rotate(y + v.second + Fetch(s + 48), 42) * inlined::k1;
658  x ^= w.second;
659  y += v.first + Fetch(s + 40);
660  z = Rotate(z + w.first, 33) * inlined::k1;
661  CopyUint128(v, WeakHashLen32WithSeeds(s, v.second * inlined::k1, x + w.first));
662  CopyUint128(w, WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch(s + 16)));
663  simpleSwap(z, x);
664  s += 64;
665  } while (s != end);
666  uint64_t mul = inlined::k1 + ((z & 0xff) << 1);
667  // Make s point to the last 64 bytes of input.
668  s = last64;
669  w.first += ((len - 1) & 63);
670  v.first += w.first;
671  w.first += v.first;
672  x = Rotate(x + y + v.first + Fetch(s + 8), 37) * mul;
673  y = Rotate(y + v.second + Fetch(s + 48), 42) * mul;
674  x ^= w.second * 9;
675  y += v.first * 9 + Fetch(s + 40);
676  z = Rotate(z + w.first, 33) * mul;
677  CopyUint128(v, WeakHashLen32WithSeeds(s, v.second * mul, x + w.first));
678  CopyUint128(w, WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch(s + 16)));
679  simpleSwap(z, x);
680  return HashLen16(HashLen16(v.first, w.first, mul) + ShiftMix(y) * inlined::k0 + z,
681  HashLen16(v.second, w.second, mul) + x,
682  mul);
683 }
684 
685 STATIC_INLINE uint64_t Hash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1) {
686  return HashLen16(Hash64(s, len) - seed0, seed1);
687 }
688 
689 STATIC_INLINE uint64_t Hash64WithSeed(const char *s, size_t len, uint64_t seed) {
690  return Hash64WithSeeds(s, len, inlined::k2, seed);
691 }
692 
693 } // namespace farmhashna
694 namespace farmhashuo {
695 #undef Fetch
696 #define Fetch inlined::Fetch64
697 
698 #undef Rotate
699 #define Rotate inlined::Rotate64
700 
701 STATIC_INLINE uint64_t H(uint64_t x, uint64_t y, uint64_t mul, int r) {
702  uint64_t a = (x ^ y) * mul;
703  a ^= (a >> 47);
704  uint64_t b = (y ^ a) * mul;
705  return Rotate(b, r) * mul;
706 }
707 
708 STATIC_INLINE uint64_t Hash64WithSeeds(const char *s, size_t len,
709  uint64_t seed0, uint64_t seed1) {
710  if (len <= 64) {
711  return farmhashna::Hash64WithSeeds(s, len, seed0, seed1);
712  }
713 
714  // For strings over 64 bytes we loop. Internal state consists of
715  // 64 bytes: u, v, w, x, y, and z.
716  uint64_t x = seed0;
717  uint64_t y = seed1 * inlined::k2 + 113;
718  uint64_t z = farmhashna::ShiftMix(y * inlined::k2) * inlined::k2;
719  pair<uint64_t, uint64_t> v = make_pair(seed0, seed1);
720  pair<uint64_t, uint64_t> w = make_pair(0, 0);
721  uint64_t u = x - z;
722  x *= inlined::k2;
723  uint64_t mul = inlined::k2 + (u & 0x82);
724 
725  // Set end so that after the loop we have 1 to 64 bytes left to process.
726  const char* end = s + ((len - 1) / 64) * 64;
727  const char* last64 = end + ((len - 1) & 63) - 63;
728  assert(s + len - 64 == last64);
729  do {
730  uint64_t a0 = Fetch(s);
731  uint64_t a1 = Fetch(s + 8);
732  uint64_t a2 = Fetch(s + 16);
733  uint64_t a3 = Fetch(s + 24);
734  uint64_t a4 = Fetch(s + 32);
735  uint64_t a5 = Fetch(s + 40);
736  uint64_t a6 = Fetch(s + 48);
737  uint64_t a7 = Fetch(s + 56);
738  x += a0 + a1;
739  y += a2;
740  z += a3;
741  v.first += a4;
742  v.second += a5 + a1;
743  w.first += a6;
744  w.second += a7;
745 
746  x = Rotate(x, 26);
747  x *= 9;
748  y = Rotate(y, 29);
749  z *= mul;
750  v.first = Rotate(v.first, 33);
751  v.second = Rotate(v.second, 30);
752  w.first ^= x;
753  w.first *= 9;
754  z = Rotate(z, 32);
755  z += w.second;
756  w.second += z;
757  z *= 9;
758  simpleSwap(u, y);
759 
760  z += a0 + a6;
761  v.first += a2;
762  v.second += a3;
763  w.first += a4;
764  w.second += a5 + a6;
765  x += a1;
766  y += a7;
767 
768  y += v.first;
769  v.first += x - y;
770  v.second += w.first;
771  w.first += v.second;
772  w.second += x - y;
773  x += w.second;
774  w.second = Rotate(w.second, 34);
775  simpleSwap(u, z);
776  s += 64;
777  } while (s != end);
778  // Make s point to the last 64 bytes of input.
779  s = last64;
780  u *= 9;
781  v.second = Rotate(v.second, 28);
782  v.first = Rotate(v.first, 20);
783  w.first += ((len - 1) & 63);
784  u += y;
785  y += u;
786  x = Rotate(y - x + v.first + Fetch(s + 8), 37) * mul;
787  y = Rotate(y ^ v.second ^ Fetch(s + 48), 42) * mul;
788  x ^= w.second * 9;
789  y += v.first + Fetch(s + 40);
790  z = Rotate(z + w.first, 33) * mul;
791  CopyUint128(v, farmhashna::WeakHashLen32WithSeeds(s, v.second * mul, x + w.first));
792  CopyUint128(w, farmhashna::WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch(s + 16)));
793  return H(farmhashna::HashLen16(v.first + x, w.first ^ y, mul) + z - u,
794  H(v.second + y, w.second + z, inlined::k2, 30) ^ x,
795  inlined::k2,
796  31);
797 }
798 
799 STATIC_INLINE uint64_t Hash64WithSeed(const char *s, size_t len, uint64_t seed) {
800  return len <= 64 ? farmhashna::Hash64WithSeed(s, len, seed) :
801  Hash64WithSeeds(s, len, 0, seed);
802 }
803 
804 STATIC_INLINE uint64_t Hash64(const char *s, size_t len) {
805  return len <= 64 ? farmhashna::Hash64(s, len) :
806  Hash64WithSeeds(s, len, 81, 0);
807 }
808 } // namespace farmhashuo
809 namespace farmhashxo {
810 #undef Fetch
811 #define Fetch inlined::Fetch64
812 
813 #undef Rotate
814 #define Rotate inlined::Rotate64
815 
816 STATIC_INLINE uint64_t H32(const char *s, size_t len, uint64_t mul,
817  uint64_t seed0 = 0, uint64_t seed1 = 0) {
818  uint64_t a = Fetch(s) * inlined::k1;
819  uint64_t b = Fetch(s + 8);
820  uint64_t c = Fetch(s + len - 8) * mul;
821  uint64_t d = Fetch(s + len - 16) * inlined::k2;
822  uint64_t u = Rotate(a + b, 43) + Rotate(c, 30) + d + seed0;
823  uint64_t v = a + Rotate(b + inlined::k2, 18) + c + seed1;
824  a = farmhashna::ShiftMix((u ^ v) * mul);
825  b = farmhashna::ShiftMix((v ^ a) * mul);
826  return b;
827 }
828 
829 // Return an 8-byte hash for 33 to 64 bytes.
830 STATIC_INLINE uint64_t HashLen33to64(const char *s, size_t len) {
831  uint64_t mul0 = inlined::k2 - 30;
832  uint64_t mul1 = inlined::k2 - 30 + 2 * len;
833  uint64_t h0 = H32(s, 32, mul0);
834  uint64_t h1 = H32(s + len - 32, 32, mul1);
835  return ((h1 * mul1) + h0) * mul1;
836 }
837 
838 // Return an 8-byte hash for 65 to 96 bytes.
839 STATIC_INLINE uint64_t HashLen65to96(const char *s, size_t len) {
840  uint64_t mul0 = inlined::k2 - 114;
841  uint64_t mul1 = inlined::k2 - 114 + 2 * len;
842  uint64_t h0 = H32(s, 32, mul0);
843  uint64_t h1 = H32(s + 32, 32, mul1);
844  uint64_t h2 = H32(s + len - 32, 32, mul1, h0, h1);
845  return (h2 * 9 + (h0 >> 17) + (h1 >> 21)) * mul1;
846 }
847 
848 STATIC_INLINE uint64_t Hash64(const char *s, size_t len) {
849  if (len <= 32) {
850  if (len <= 16) {
851  return farmhashna::HashLen0to16(s, len);
852  } else {
853  return farmhashna::HashLen17to32(s, len);
854  }
855  } else if (len <= 64) {
856  return HashLen33to64(s, len);
857  } else if (len <= 96) {
858  return HashLen65to96(s, len);
859  } else if (len <= 256) {
860  return farmhashna::Hash64(s, len);
861  } else {
862  return farmhashuo::Hash64(s, len);
863  }
864 }
865 
866 STATIC_INLINE uint64_t Hash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1) {
867  return farmhashuo::Hash64WithSeeds(s, len, seed0, seed1);
868 }
869 
870 STATIC_INLINE uint64_t Hash64WithSeed(const char *s, size_t len, uint64_t seed) {
871  return farmhashuo::Hash64WithSeed(s, len, seed);
872 }
873 } // namespace farmhashxo
874 namespace farmhashte {
875 #if !can_use_sse41 || !x86_64
876 
877 STATIC_INLINE uint64_t Hash64(const char *s, size_t len) {
879  return s == NULL ? 0 : len;
880 }
881 
882 STATIC_INLINE uint64_t Hash64WithSeed(const char *s, size_t len, uint64_t seed) {
884  return seed + Hash64(s, len);
885 }
886 
887 STATIC_INLINE uint64_t Hash64WithSeeds(const char *s, size_t len,
888  uint64_t seed0, uint64_t seed1) {
890  return seed0 + seed1 + Hash64(s, len);
891 }
892 
893 #else
894 
895 #undef Fetch
896 #define Fetch inlined::Fetch64
897 
898 #undef Rotate
899 #define Rotate inlined::Rotate64
900 
901 #undef Bswap
902 #define Bswap inlined::Bswap64
903 
904 // Helpers for data-parallel operations (1x 128 bits or 2x 64 or 4x 32).
905 STATIC_INLINE __m128i Add(__m128i x, __m128i y) { return _mm_add_epi64(x, y); }
906 STATIC_INLINE __m128i Xor(__m128i x, __m128i y) { return _mm_xor_si128(x, y); }
907 STATIC_INLINE __m128i Mul(__m128i x, __m128i y) { return _mm_mullo_epi32(x, y); }
908 STATIC_INLINE __m128i Shuf(__m128i x, __m128i y) { return _mm_shuffle_epi8(y, x); }
909 
910 // Requires n >= 256. Requires SSE4.1. Should be slightly faster if the
911 // compiler uses AVX instructions (e.g., use the -mavx flag with GCC).
912 STATIC_INLINE uint64_t Hash64Long(const char* s, size_t n,
913  uint64_t seed0, uint64_t seed1) {
914  const __m128i kShuf =
915  _mm_set_epi8(4, 11, 10, 5, 8, 15, 6, 9, 12, 2, 14, 13, 0, 7, 3, 1);
916  const __m128i kMult =
917  _mm_set_epi8(0xbd, 0xd6, 0x33, 0x39, 0x45, 0x54, 0xfa, 0x03,
918  0x34, 0x3e, 0x33, 0xed, 0xcc, 0x9e, 0x2d, 0x51);
919  uint64_t seed2 = (seed0 + 113) * (seed1 + 9);
920  uint64_t seed3 = (Rotate(seed0, 23) + 27) * (Rotate(seed1, 30) + 111);
921  __m128i d0 = _mm_cvtsi64_si128(seed0);
922  __m128i d1 = _mm_cvtsi64_si128(seed1);
923  __m128i d2 = Shuf(kShuf, d0);
924  __m128i d3 = Shuf(kShuf, d1);
925  __m128i d4 = Xor(d0, d1);
926  __m128i d5 = Xor(d1, d2);
927  __m128i d6 = Xor(d2, d4);
928  __m128i d7 = _mm_set1_epi32(seed2 >> 32);
929  __m128i d8 = Mul(kMult, d2);
930  __m128i d9 = _mm_set1_epi32(seed3 >> 32);
931  __m128i d10 = _mm_set1_epi32(seed3);
932  __m128i d11 = Add(d2, _mm_set1_epi32(seed2));
933  const char* end = s + (n & ~static_cast<size_t>(255));
934  do {
935  __m128i z;
936  z = inlined::Fetch128(s);
937  d0 = Add(d0, z);
938  d1 = Shuf(kShuf, d1);
939  d2 = Xor(d2, d0);
940  d4 = Xor(d4, z);
941  d4 = Xor(d4, d1);
942  simpleSwap(d0, d6);
943  z = inlined::Fetch128(s + 16);
944  d5 = Add(d5, z);
945  d6 = Shuf(kShuf, d6);
946  d8 = Shuf(kShuf, d8);
947  d7 = Xor(d7, d5);
948  d0 = Xor(d0, z);
949  d0 = Xor(d0, d6);
950  simpleSwap(d5, d11);
951  z = inlined::Fetch128(s + 32);
952  d1 = Add(d1, z);
953  d2 = Shuf(kShuf, d2);
954  d4 = Shuf(kShuf, d4);
955  d5 = Xor(d5, z);
956  d5 = Xor(d5, d2);
957  simpleSwap(d10, d4);
958  z = inlined::Fetch128(s + 48);
959  d6 = Add(d6, z);
960  d7 = Shuf(kShuf, d7);
961  d0 = Shuf(kShuf, d0);
962  d8 = Xor(d8, d6);
963  d1 = Xor(d1, z);
964  d1 = Add(d1, d7);
965  z = inlined::Fetch128(s + 64);
966  d2 = Add(d2, z);
967  d5 = Shuf(kShuf, d5);
968  d4 = Add(d4, d2);
969  d6 = Xor(d6, z);
970  d6 = Xor(d6, d11);
971  simpleSwap(d8, d2);
972  z = inlined::Fetch128(s + 80);
973  d7 = Xor(d7, z);
974  d8 = Shuf(kShuf, d8);
975  d1 = Shuf(kShuf, d1);
976  d0 = Add(d0, d7);
977  d2 = Add(d2, z);
978  d2 = Add(d2, d8);
979  simpleSwap(d1, d7);
980  z = inlined::Fetch128(s + 96);
981  d4 = Shuf(kShuf, d4);
982  d6 = Shuf(kShuf, d6);
983  d8 = Mul(kMult, d8);
984  d5 = Xor(d5, d11);
985  d7 = Xor(d7, z);
986  d7 = Add(d7, d4);
987  simpleSwap(d6, d0);
988  z = inlined::Fetch128(s + 112);
989  d8 = Add(d8, z);
990  d0 = Shuf(kShuf, d0);
991  d2 = Shuf(kShuf, d2);
992  d1 = Xor(d1, d8);
993  d10 = Xor(d10, z);
994  d10 = Xor(d10, d0);
995  simpleSwap(d11, d5);
996  z = inlined::Fetch128(s + 128);
997  d4 = Add(d4, z);
998  d5 = Shuf(kShuf, d5);
999  d7 = Shuf(kShuf, d7);
1000  d6 = Add(d6, d4);
1001  d8 = Xor(d8, z);
1002  d8 = Xor(d8, d5);
1003  simpleSwap(d4, d10);
1004  z = inlined::Fetch128(s + 144);
1005  d0 = Add(d0, z);
1006  d1 = Shuf(kShuf, d1);
1007  d2 = Add(d2, d0);
1008  d4 = Xor(d4, z);
1009  d4 = Xor(d4, d1);
1010  z = inlined::Fetch128(s + 160);
1011  d5 = Add(d5, z);
1012  d6 = Shuf(kShuf, d6);
1013  d8 = Shuf(kShuf, d8);
1014  d7 = Xor(d7, d5);
1015  d0 = Xor(d0, z);
1016  d0 = Xor(d0, d6);
1017  simpleSwap(d2, d8);
1018  z = inlined::Fetch128(s + 176);
1019  d1 = Add(d1, z);
1020  d2 = Shuf(kShuf, d2);
1021  d4 = Shuf(kShuf, d4);
1022  d5 = Mul(kMult, d5);
1023  d5 = Xor(d5, z);
1024  d5 = Xor(d5, d2);
1025  simpleSwap(d7, d1);
1026  z = inlined::Fetch128(s + 192);
1027  d6 = Add(d6, z);
1028  d7 = Shuf(kShuf, d7);
1029  d0 = Shuf(kShuf, d0);
1030  d8 = Add(d8, d6);
1031  d1 = Xor(d1, z);
1032  d1 = Xor(d1, d7);
1033  simpleSwap(d0, d6);
1034  z = inlined::Fetch128(s + 208);
1035  d2 = Add(d2, z);
1036  d5 = Shuf(kShuf, d5);
1037  d4 = Xor(d4, d2);
1038  d6 = Xor(d6, z);
1039  d6 = Xor(d6, d9);
1040  simpleSwap(d5, d11);
1041  z = inlined::Fetch128(s + 224);
1042  d7 = Add(d7, z);
1043  d8 = Shuf(kShuf, d8);
1044  d1 = Shuf(kShuf, d1);
1045  d0 = Xor(d0, d7);
1046  d2 = Xor(d2, z);
1047  d2 = Xor(d2, d8);
1048  simpleSwap(d10, d4);
1049  z = inlined::Fetch128(s + 240);
1050  d3 = Add(d3, z);
1051  d4 = Shuf(kShuf, d4);
1052  d6 = Shuf(kShuf, d6);
1053  d7 = Mul(kMult, d7);
1054  d5 = Add(d5, d3);
1055  d7 = Xor(d7, z);
1056  d7 = Xor(d7, d4);
1057  simpleSwap(d3, d9);
1058  s += 256;
1059  } while (s != end);
1060  d6 = Add(Mul(kMult, d6), _mm_cvtsi64_si128(n));
1061  if (n % 256 != 0) {
1062  d7 = Add(_mm_shuffle_epi32(d8, (0 << 6) + (3 << 4) + (2 << 2) + (1 << 0)), d7);
1063  d8 = Add(Mul(kMult, d8), _mm_cvtsi64_si128(farmhashxo::Hash64(s, n % 256)));
1064  }
1065  __m128i t[8];
1066  d0 = Mul(kMult, Shuf(kShuf, Mul(kMult, d0)));
1067  d3 = Mul(kMult, Shuf(kShuf, Mul(kMult, d3)));
1068  d9 = Mul(kMult, Shuf(kShuf, Mul(kMult, d9)));
1069  d1 = Mul(kMult, Shuf(kShuf, Mul(kMult, d1)));
1070  d0 = Add(d11, d0);
1071  d3 = Xor(d7, d3);
1072  d9 = Add(d8, d9);
1073  d1 = Add(d10, d1);
1074  d4 = Add(d3, d4);
1075  d5 = Add(d9, d5);
1076  d6 = Xor(d1, d6);
1077  d2 = Add(d0, d2);
1078  t[0] = d0;
1079  t[1] = d3;
1080  t[2] = d9;
1081  t[3] = d1;
1082  t[4] = d4;
1083  t[5] = d5;
1084  t[6] = d6;
1085  t[7] = d2;
1086  return farmhashxo::Hash64(reinterpret_cast<const char*>(t), sizeof(t));
1087 }
1088 
1089 STATIC_INLINE uint64_t Hash64(const char *s, size_t len) {
1090  // Empirically, farmhashxo seems faster until length 512.
1091  return len >= 512 ? Hash64Long(s, len, inlined::k2, inlined::k1) : farmhashxo::Hash64(s, len);
1092 }
1093 
1094 STATIC_INLINE uint64_t Hash64WithSeed(const char *s, size_t len, uint64_t seed) {
1095  return len >= 512 ? Hash64Long(s, len, inlined::k1, seed) :
1096  farmhashxo::Hash64WithSeed(s, len, seed);
1097 }
1098 
1099 STATIC_INLINE uint64_t Hash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1) {
1100  return len >= 512 ? Hash64Long(s, len, seed0, seed1) :
1101  farmhashxo::Hash64WithSeeds(s, len, seed0, seed1);
1102 }
1103 
1104 #endif
1105 } // namespace farmhashte
1106 namespace farmhashnt {
1107 #if !can_use_sse41 || !x86_64
1108 
1109 STATIC_INLINE uint32_t Hash32(const char *s, size_t len) {
1111  return s == NULL ? 0 : len;
1112 }
1113 
1114 STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
1116  return seed + Hash32(s, len);
1117 }
1118 
1119 #else
1120 
1121 STATIC_INLINE uint32_t Hash32(const char *s, size_t len) {
1122  return static_cast<uint32_t>(farmhashte::Hash64(s, len));
1123 }
1124 
1125 STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
1126  return static_cast<uint32_t>(farmhashte::Hash64WithSeed(s, len, seed));
1127 }
1128 
1129 #endif
1130 } // namespace farmhashnt
1131 namespace farmhashmk {
1132 #undef Fetch
1133 #define Fetch inlined::Fetch32
1134 
1135 #undef Rotate
1136 #define Rotate inlined::Rotate32
1137 
1138 #undef Bswap
1139 #define Bswap inlined::Bswap32
1140 
1141 #undef fmix
1142 #define fmix farmhash::inlined::fmix
1143 
1144 
1145 STATIC_INLINE uint32_t Hash32Len13to24(const char *s, size_t len, uint32_t seed = 0) {
1146  uint32_t a = Fetch(s - 4 + (len >> 1));
1147  uint32_t b = Fetch(s + 4);
1148  uint32_t c = Fetch(s + len - 8);
1149  uint32_t d = Fetch(s + (len >> 1));
1150  uint32_t e = Fetch(s);
1151  uint32_t f = Fetch(s + len - 4);
1152  uint32_t h = d * inlined::c1 + len + seed;
1153  a = Rotate(a, 12) + f;
1154  h = inlined::Mur(c, h) + a;
1155  a = Rotate(a, 3) + c;
1156  h = inlined::Mur(e, h) + a;
1157  a = Rotate(a + f, 12) + d;
1158  h = inlined::Mur(b ^ seed, h) + a;
1159  return fmix(h);
1160 }
1161 
1162 STATIC_INLINE uint32_t Hash32Len0to4(const char *s, size_t len, uint32_t seed = 0) {
1163  uint32_t b = seed;
1164  uint32_t c = 9;
1165  for (size_t i = 0; i < len; i++) {
1166  signed char v = s[i];
1167  b = b * inlined::c1 + v;
1168  c ^= b;
1169  }
1170  return fmix(inlined::Mur(b, inlined::Mur(len, c)));
1171 }
1172 
1173 STATIC_INLINE uint32_t Hash32Len5to12(const char *s, size_t len, uint32_t seed = 0) {
1174  uint32_t a = len, b = len * 5, c = 9, d = b + seed;
1175  a += Fetch(s);
1176  b += Fetch(s + len - 4);
1177  c += Fetch(s + ((len >> 1) & 4));
1178  return fmix(seed ^ inlined::Mur(c, inlined::Mur(b, inlined::Mur(a, d))));
1179 }
1180 
1181 STATIC_INLINE uint32_t Hash32(const char *s, size_t len) {
1182  if (len <= 24) {
1183  return len <= 12 ?
1184  (len <= 4 ? Hash32Len0to4(s, len) : Hash32Len5to12(s, len)) :
1185  Hash32Len13to24(s, len);
1186  }
1187 
1188  // len > 24
1189  uint32_t h = len, g = inlined::c1 * len, f = g;
1190  uint32_t a0 = Rotate(Fetch(s + len - 4) * inlined::c1, 17) * inlined::c2;
1191  uint32_t a1 = Rotate(Fetch(s + len - 8) * inlined::c1, 17) * inlined::c2;
1192  uint32_t a2 = Rotate(Fetch(s + len - 16) * inlined::c1, 17) * inlined::c2;
1193  uint32_t a3 = Rotate(Fetch(s + len - 12) * inlined::c1, 17) * inlined::c2;
1194  uint32_t a4 = Rotate(Fetch(s + len - 20) * inlined::c1, 17) * inlined::c2;
1195  h ^= a0;
1196  h = Rotate(h, 19);
1197  h = h * 5 + 0xe6546b64;
1198  h ^= a2;
1199  h = Rotate(h, 19);
1200  h = h * 5 + 0xe6546b64;
1201  g ^= a1;
1202  g = Rotate(g, 19);
1203  g = g * 5 + 0xe6546b64;
1204  g ^= a3;
1205  g = Rotate(g, 19);
1206  g = g * 5 + 0xe6546b64;
1207  f += a4;
1208  f = Rotate(f, 19) + 113;
1209  size_t iters = (len - 1) / 20;
1210  do {
1211  uint32_t a = Fetch(s);
1212  uint32_t b = Fetch(s + 4);
1213  uint32_t c = Fetch(s + 8);
1214  uint32_t d = Fetch(s + 12);
1215  uint32_t e = Fetch(s + 16);
1216  h += a;
1217  g += b;
1218  f += c;
1219  h = inlined::Mur(d, h) + e;
1220  g = inlined::Mur(c, g) + a;
1221  f = inlined::Mur(b + e * inlined::c1, f) + d;
1222  f += g;
1223  g += f;
1224  s += 20;
1225  } while (--iters != 0);
1226  g = Rotate(g, 11) * inlined::c1;
1227  g = Rotate(g, 17) * inlined::c1;
1228  f = Rotate(f, 11) * inlined::c1;
1229  f = Rotate(f, 17) * inlined::c1;
1230  h = Rotate(h + g, 19);
1231  h = h * 5 + 0xe6546b64;
1232  h = Rotate(h, 17) * inlined::c1;
1233  h = Rotate(h + f, 19);
1234  h = h * 5 + 0xe6546b64;
1235  h = Rotate(h, 17) * inlined::c1;
1236  return h;
1237 }
1238 
1239 STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
1240  if (len <= 24) {
1241  if (len >= 13) return Hash32Len13to24(s, len, seed * inlined::c1);
1242  else if (len >= 5) return Hash32Len5to12(s, len, seed);
1243  else return Hash32Len0to4(s, len, seed);
1244  }
1245  uint32_t h = Hash32Len13to24(s, 24, seed ^ len);
1246  return inlined::Mur(Hash32(s + 24, len - 24) + seed, h);
1247 }
1248 } // namespace farmhashmk
1249 namespace farmhashsu {
1250 #if !can_use_sse42 || !can_use_aesni
1251 
1252 STATIC_INLINE uint32_t Hash32(const char *s, size_t len) {
1254  return s == NULL ? 0 : len;
1255 }
1256 
1257 STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
1259  return seed + Hash32(s, len);
1260 }
1261 
1262 #else
1263 
1264 #undef Fetch
1265 #define Fetch inlined::Fetch32
1266 
1267 #undef Rotate
1268 #define Rotate inlined::Rotate32
1269 
1270 #undef Bswap
1271 #define Bswap inlined::Bswap32
1272 
1273 // Helpers for data-parallel operations (4x 32-bits).
1274 STATIC_INLINE __m128i Add(__m128i x, __m128i y) { return _mm_add_epi32(x, y); }
1275 STATIC_INLINE __m128i Xor(__m128i x, __m128i y) { return _mm_xor_si128(x, y); }
1276 STATIC_INLINE __m128i Or(__m128i x, __m128i y) { return _mm_or_si128(x, y); }
1277 STATIC_INLINE __m128i Mul(__m128i x, __m128i y) { return _mm_mullo_epi32(x, y); }
1278 STATIC_INLINE __m128i Mul5(__m128i x) { return Add(x, _mm_slli_epi32(x, 2)); }
1279 STATIC_INLINE __m128i RotateLeft(__m128i x, int c) {
1280  return Or(_mm_slli_epi32(x, c),
1281  _mm_srli_epi32(x, 32 - c));
1282 }
1283 STATIC_INLINE __m128i Rol17(__m128i x) { return RotateLeft(x, 17); }
1284 STATIC_INLINE __m128i Rol19(__m128i x) { return RotateLeft(x, 19); }
1285 STATIC_INLINE __m128i Shuffle0321(__m128i x) {
1286  return _mm_shuffle_epi32(x, (0 << 6) + (3 << 4) + (2 << 2) + (1 << 0));
1287 }
1288 
1289 STATIC_INLINE uint32_t Hash32(const char *s, size_t len) {
1290  const uint32_t seed = 81;
1291  if (len <= 24) {
1292  return len <= 12 ?
1293  (len <= 4 ?
1294  farmhashmk::Hash32Len0to4(s, len) :
1295  farmhashmk::Hash32Len5to12(s, len)) :
1296  farmhashmk::Hash32Len13to24(s, len);
1297  }
1298 
1299  if (len < 40) {
1300  uint32_t a = len, b = seed * inlined::c2, c = a + b;
1301  a += Fetch(s + len - 4);
1302  b += Fetch(s + len - 20);
1303  c += Fetch(s + len - 16);
1304  uint32_t d = a;
1305  a = inlined::Rotate32(a, 21);
1306  a = inlined::Mur(a, inlined::Mur(b, _mm_crc32_u32(c, d)));
1307  a += Fetch(s + len - 12);
1308  b += Fetch(s + len - 8);
1309  d += a;
1310  a += d;
1311  b = inlined::Mur(b, d) * inlined::c2;
1312  a = _mm_crc32_u32(a, b + c);
1313  return farmhashmk::Hash32Len13to24(s, (len + 1) / 2, a) + b;
1314  }
1315 
1316 #undef Mulc1
1317 #define Mulc1(x) Mul((x), cc1)
1318 
1319 #undef Mulc2
1320 #define Mulc2(x) Mul((x), cc2)
1321 
1322 #undef Murk
1323 #define Murk(a, h) \
1324  Add(k, \
1325  Mul5( \
1326  Rol19( \
1327  Xor( \
1328  Mulc2( \
1329  Rol17( \
1330  Mulc1(a))), \
1331  (h)))))
1332 
1333  const __m128i cc1 = _mm_set1_epi32(inlined::c1);
1334  const __m128i cc2 = _mm_set1_epi32(inlined::c2);
1335  __m128i h = _mm_set1_epi32(seed);
1336  __m128i g = _mm_set1_epi32(inlined::c1 * seed);
1337  __m128i f = g;
1338  __m128i k = _mm_set1_epi32(0xe6546b64);
1339  __m128i q;
1340  if (len < 80) {
1341  __m128i a = inlined::Fetch128(s);
1342  __m128i b = inlined::Fetch128(s + 16);
1343  __m128i c = inlined::Fetch128(s + (len - 15) / 2);
1344  __m128i d = inlined::Fetch128(s + len - 32);
1345  __m128i e = inlined::Fetch128(s + len - 16);
1346  h = Add(h, a);
1347  g = Add(g, b);
1348  q = g;
1349  g = Shuffle0321(g);
1350  f = Add(f, c);
1351  __m128i be = Add(b, Mulc1(e));
1352  h = Add(h, f);
1353  f = Add(f, h);
1354  h = Add(Murk(d, h), e);
1355  k = Xor(k, _mm_shuffle_epi8(g, f));
1356  g = Add(Xor(c, g), a);
1357  f = Add(Xor(be, f), d);
1358  k = Add(k, be);
1359  k = Add(k, _mm_shuffle_epi8(f, h));
1360  f = Add(f, g);
1361  g = Add(g, f);
1362  g = Add(_mm_set1_epi32(len), Mulc1(g));
1363  } else {
1364  // len >= 80
1365  // The following is loosely modelled after farmhashmk::Hash32.
1366  size_t iters = (len - 1) / 80;
1367  len -= iters * 80;
1368 
1369 #undef Chunk
1370 #define Chunk() do { \
1371  __m128i a = inlined::Fetch128(s); \
1372  __m128i b = inlined::Fetch128(s + 16); \
1373  __m128i c = inlined::Fetch128(s + 32); \
1374  __m128i d = inlined::Fetch128(s + 48); \
1375  __m128i e = inlined::Fetch128(s + 64); \
1376  h = Add(h, a); \
1377  g = Add(g, b); \
1378  g = Shuffle0321(g); \
1379  f = Add(f, c); \
1380  __m128i be = Add(b, Mulc1(e)); \
1381  h = Add(h, f); \
1382  f = Add(f, h); \
1383  h = Add(h, d); \
1384  q = Add(q, e); \
1385  h = Rol17(h); \
1386  h = Mulc1(h); \
1387  k = Xor(k, _mm_shuffle_epi8(g, f)); \
1388  g = Add(Xor(c, g), a); \
1389  f = Add(Xor(be, f), d); \
1390  simpleSwap(f, q); \
1391  q = _mm_aesimc_si128(q); \
1392  k = Add(k, be); \
1393  k = Add(k, _mm_shuffle_epi8(f, h)); \
1394  f = Add(f, g); \
1395  g = Add(g, f); \
1396  f = Mulc1(f); \
1397 } while (0)
1398 
1399  q = g;
1400  while (iters-- != 0) {
1401  Chunk();
1402  s += 80;
1403  }
1404 
1405  if (len != 0) {
1406  h = Add(h, _mm_set1_epi32(len));
1407  s = s + len - 80;
1408  Chunk();
1409  }
1410  }
1411 
1412  g = Shuffle0321(g);
1413  k = Xor(k, g);
1414  k = Xor(k, q);
1415  h = Xor(h, q);
1416  f = Mulc1(f);
1417  k = Mulc2(k);
1418  g = Mulc1(g);
1419  h = Mulc2(h);
1420  k = Add(k, _mm_shuffle_epi8(g, f));
1421  h = Add(h, f);
1422  f = Add(f, h);
1423  g = Add(g, k);
1424  k = Add(k, g);
1425  k = Xor(k, _mm_shuffle_epi8(f, h));
1426  __m128i buf[4];
1427  buf[0] = f;
1428  buf[1] = g;
1429  buf[2] = k;
1430  buf[3] = h;
1431  s = reinterpret_cast<char*>(buf);
1432  uint32_t x = Fetch(s);
1433  uint32_t y = Fetch(s+4);
1434  uint32_t z = Fetch(s+8);
1435  x = _mm_crc32_u32(x, Fetch(s+12));
1436  y = _mm_crc32_u32(y, Fetch(s+16));
1437  z = _mm_crc32_u32(z * inlined::c1, Fetch(s+20));
1438  x = _mm_crc32_u32(x, Fetch(s+24));
1439  y = _mm_crc32_u32(y * inlined::c1, Fetch(s+28));
1440  uint32_t o = y;
1441  z = _mm_crc32_u32(z, Fetch(s+32));
1442  x = _mm_crc32_u32(x * inlined::c1, Fetch(s+36));
1443  y = _mm_crc32_u32(y, Fetch(s+40));
1444  z = _mm_crc32_u32(z * inlined::c1, Fetch(s+44));
1445  x = _mm_crc32_u32(x, Fetch(s+48));
1446  y = _mm_crc32_u32(y * inlined::c1, Fetch(s+52));
1447  z = _mm_crc32_u32(z, Fetch(s+56));
1448  x = _mm_crc32_u32(x, Fetch(s+60));
1449  return (o - x + y - z) * inlined::c1;
1450 }
1451 
1452 #undef Chunk
1453 #undef Murk
1454 #undef Mulc2
1455 #undef Mulc1
1456 
1457 STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
1458  if (len <= 24) {
1459  if (len >= 13) return farmhashmk::Hash32Len13to24(s, len, seed * inlined::c1);
1460  else if (len >= 5) return farmhashmk::Hash32Len5to12(s, len, seed);
1461  else return farmhashmk::Hash32Len0to4(s, len, seed);
1462  }
1463  uint32_t h = farmhashmk::Hash32Len13to24(s, 24, seed ^ len);
1464  return _mm_crc32_u32(Hash32(s + 24, len - 24) + seed, h);
1465 }
1466 
1467 #endif
1468 } // namespace farmhashsu
1469 namespace farmhashsa {
1470 #if !can_use_sse42
1471 
1472 STATIC_INLINE uint32_t Hash32(const char *s, size_t len) {
1474  return s == NULL ? 0 : len;
1475 }
1476 
1477 STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
1479  return seed + Hash32(s, len);
1480 }
1481 
1482 #else
1483 
1484 #undef Fetch
1485 #define Fetch inlined::Fetch32
1486 
1487 #undef Rotate
1488 #define Rotate inlined::Rotate32
1489 
1490 #undef Bswap
1491 #define Bswap inlined::Bswap32
1492 
1493 // Helpers for data-parallel operations (4x 32-bits).
1494 STATIC_INLINE __m128i Add(__m128i x, __m128i y) { return _mm_add_epi32(x, y); }
1495 STATIC_INLINE __m128i Xor(__m128i x, __m128i y) { return _mm_xor_si128(x, y); }
1496 STATIC_INLINE __m128i Or(__m128i x, __m128i y) { return _mm_or_si128(x, y); }
1497 STATIC_INLINE __m128i Mul(__m128i x, __m128i y) { return _mm_mullo_epi32(x, y); }
1498 STATIC_INLINE __m128i Mul5(__m128i x) { return Add(x, _mm_slli_epi32(x, 2)); }
1499 STATIC_INLINE __m128i Rotatesse(__m128i x, int c) {
1500  return Or(_mm_slli_epi32(x, c),
1501  _mm_srli_epi32(x, 32 - c));
1502 }
1503 STATIC_INLINE __m128i Rot17(__m128i x) { return Rotatesse(x, 17); }
1504 STATIC_INLINE __m128i Rot19(__m128i x) { return Rotatesse(x, 19); }
1505 STATIC_INLINE __m128i Shuffle0321(__m128i x) {
1506  return _mm_shuffle_epi32(x, (0 << 6) + (3 << 4) + (2 << 2) + (1 << 0));
1507 }
1508 
1509 STATIC_INLINE uint32_t Hash32(const char *s, size_t len) {
1510  const uint32_t seed = 81;
1511  if (len <= 24) {
1512  return len <= 12 ?
1513  (len <= 4 ?
1514  farmhashmk::Hash32Len0to4(s, len) :
1515  farmhashmk::Hash32Len5to12(s, len)) :
1516  farmhashmk::Hash32Len13to24(s, len);
1517  }
1518 
1519  if (len < 40) {
1520  uint32_t a = len, b = seed * inlined::c2, c = a + b;
1521  a += Fetch(s + len - 4);
1522  b += Fetch(s + len - 20);
1523  c += Fetch(s + len - 16);
1524  uint32_t d = a;
1525  a = inlined::Rotate32(a, 21);
1526  a = inlined::Mur(a, inlined::Mur(b, inlined::Mur(c, d)));
1527  a += Fetch(s + len - 12);
1528  b += Fetch(s + len - 8);
1529  d += a;
1530  a += d;
1531  b = inlined::Mur(b, d) * inlined::c2;
1532  a = _mm_crc32_u32(a, b + c);
1533  return farmhashmk::Hash32Len13to24(s, (len + 1) / 2, a) + b;
1534  }
1535 
1536 #undef Mulc1
1537 #define Mulc1(x) Mul((x), cc1)
1538 
1539 #undef Mulc2
1540 #define Mulc2(x) Mul((x), cc2)
1541 
1542 #undef Murk
1543 #define Murk(a, h) \
1544  Add(k, \
1545  Mul5( \
1546  Rot19( \
1547  Xor( \
1548  Mulc2( \
1549  Rot17( \
1550  Mulc1(a))), \
1551  (h)))))
1552 
1553  const __m128i cc1 = _mm_set1_epi32(inlined::c1);
1554  const __m128i cc2 = _mm_set1_epi32(inlined::c2);
1555  __m128i h = _mm_set1_epi32(seed);
1556  __m128i g = _mm_set1_epi32(inlined::c1 * seed);
1557  __m128i f = g;
1558  __m128i k = _mm_set1_epi32(0xe6546b64);
1559  if (len < 80) {
1560  __m128i a = inlined::Fetch128(s);
1561  __m128i b = inlined::Fetch128(s + 16);
1562  __m128i c = inlined::Fetch128(s + (len - 15) / 2);
1563  __m128i d = inlined::Fetch128(s + len - 32);
1564  __m128i e = inlined::Fetch128(s + len - 16);
1565  h = Add(h, a);
1566  g = Add(g, b);
1567  g = Shuffle0321(g);
1568  f = Add(f, c);
1569  __m128i be = Add(b, Mulc1(e));
1570  h = Add(h, f);
1571  f = Add(f, h);
1572  h = Add(Murk(d, h), e);
1573  k = Xor(k, _mm_shuffle_epi8(g, f));
1574  g = Add(Xor(c, g), a);
1575  f = Add(Xor(be, f), d);
1576  k = Add(k, be);
1577  k = Add(k, _mm_shuffle_epi8(f, h));
1578  f = Add(f, g);
1579  g = Add(g, f);
1580  g = Add(_mm_set1_epi32(len), Mulc1(g));
1581  } else {
1582  // len >= 80
1583  // The following is loosely modelled after farmhashmk::Hash32.
1584  size_t iters = (len - 1) / 80;
1585  len -= iters * 80;
1586 
1587 #undef Chunk
1588 #define Chunk() do { \
1589  __m128i a = inlined::Fetch128(s); \
1590  __m128i b = inlined::Fetch128(s + 16); \
1591  __m128i c = inlined::Fetch128(s + 32); \
1592  __m128i d = inlined::Fetch128(s + 48); \
1593  __m128i e = inlined::Fetch128(s + 64); \
1594  h = Add(h, a); \
1595  g = Add(g, b); \
1596  g = Shuffle0321(g); \
1597  f = Add(f, c); \
1598  __m128i be = Add(b, Mulc1(e)); \
1599  h = Add(h, f); \
1600  f = Add(f, h); \
1601  h = Add(Murk(d, h), e); \
1602  k = Xor(k, _mm_shuffle_epi8(g, f)); \
1603  g = Add(Xor(c, g), a); \
1604  f = Add(Xor(be, f), d); \
1605  k = Add(k, be); \
1606  k = Add(k, _mm_shuffle_epi8(f, h)); \
1607  f = Add(f, g); \
1608  g = Add(g, f); \
1609  f = Mulc1(f); \
1610 } while (0)
1611 
1612  while (iters-- != 0) {
1613  Chunk();
1614  s += 80;
1615  }
1616 
1617  if (len != 0) {
1618  h = Add(h, _mm_set1_epi32(len));
1619  s = s + len - 80;
1620  Chunk();
1621  }
1622  }
1623 
1624  g = Shuffle0321(g);
1625  k = Xor(k, g);
1626  f = Mulc1(f);
1627  k = Mulc2(k);
1628  g = Mulc1(g);
1629  h = Mulc2(h);
1630  k = Add(k, _mm_shuffle_epi8(g, f));
1631  h = Add(h, f);
1632  f = Add(f, h);
1633  g = Add(g, k);
1634  k = Add(k, g);
1635  k = Xor(k, _mm_shuffle_epi8(f, h));
1636  __m128i buf[4];
1637  buf[0] = f;
1638  buf[1] = g;
1639  buf[2] = k;
1640  buf[3] = h;
1641  s = reinterpret_cast<char*>(buf);
1642  uint32_t x = Fetch(s);
1643  uint32_t y = Fetch(s+4);
1644  uint32_t z = Fetch(s+8);
1645  x = _mm_crc32_u32(x, Fetch(s+12));
1646  y = _mm_crc32_u32(y, Fetch(s+16));
1647  z = _mm_crc32_u32(z * inlined::c1, Fetch(s+20));
1648  x = _mm_crc32_u32(x, Fetch(s+24));
1649  y = _mm_crc32_u32(y * inlined::c1, Fetch(s+28));
1650  uint32_t o = y;
1651  z = _mm_crc32_u32(z, Fetch(s+32));
1652  x = _mm_crc32_u32(x * inlined::c1, Fetch(s+36));
1653  y = _mm_crc32_u32(y, Fetch(s+40));
1654  z = _mm_crc32_u32(z * inlined::c1, Fetch(s+44));
1655  x = _mm_crc32_u32(x, Fetch(s+48));
1656  y = _mm_crc32_u32(y * inlined::c1, Fetch(s+52));
1657  z = _mm_crc32_u32(z, Fetch(s+56));
1658  x = _mm_crc32_u32(x, Fetch(s+60));
1659  return (o - x + y - z) * inlined::c1;
1660 }
1661 
1662 #undef Chunk
1663 #undef Murk
1664 #undef Mulc2
1665 #undef Mulc1
1666 
1667 STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
1668  if (len <= 24) {
1669  if (len >= 13) return farmhashmk::Hash32Len13to24(s, len, seed * inlined::c1);
1670  else if (len >= 5) return farmhashmk::Hash32Len5to12(s, len, seed);
1671  else return farmhashmk::Hash32Len0to4(s, len, seed);
1672  }
1673  uint32_t h = farmhashmk::Hash32Len13to24(s, 24, seed ^ len);
1674  return _mm_crc32_u32(Hash32(s + 24, len - 24) + seed, h);
1675 }
1676 
1677 #endif
1678 } // namespace farmhashsa
1679 namespace farmhashcc {
1680 // This file provides a 32-bit hash equivalent to CityHash32 (v1.1.1)
1681 // and a 128-bit hash equivalent to CityHash128 (v1.1.1). It also provides
1682 // a seeded 32-bit hash function similar to CityHash32.
1683 
1684 #undef Fetch
1685 #define Fetch inlined::Fetch32
1686 
1687 #undef Rotate
1688 #define Rotate inlined::Rotate32
1689 
1690 #undef Bswap
1691 #define Bswap inlined::Bswap32
1692 
1693 #undef fmix
1694 #define fmix farmhash::inlined::fmix
1695 
1696 STATIC_INLINE uint32_t Hash32Len13to24(const char *s, size_t len) {
1697  uint32_t a = Fetch(s - 4 + (len >> 1));
1698  uint32_t b = Fetch(s + 4);
1699  uint32_t c = Fetch(s + len - 8);
1700  uint32_t d = Fetch(s + (len >> 1));
1701  uint32_t e = Fetch(s);
1702  uint32_t f = Fetch(s + len - 4);
1703  uint32_t h = len;
1704 
1706 }
1707 
1708 STATIC_INLINE uint32_t Hash32Len0to4(const char *s, size_t len) {
1709  uint32_t b = 0;
1710  uint32_t c = 9;
1711  for (size_t i = 0; i < len; i++) {
1712  signed char v = s[i];
1713  b = b * inlined::c1 + v;
1714  c ^= b;
1715  }
1716  return fmix(inlined::Mur(b, inlined::Mur(len, c)));
1717 }
1718 
1719 STATIC_INLINE uint32_t Hash32Len5to12(const char *s, size_t len) {
1720  uint32_t a = len, b = len * 5, c = 9, d = b;
1721  a += Fetch(s);
1722  b += Fetch(s + len - 4);
1723  c += Fetch(s + ((len >> 1) & 4));
1724  return fmix(inlined::Mur(c, inlined::Mur(b, inlined::Mur(a, d))));
1725 }
1726 
1727 STATIC_INLINE uint32_t Hash32(const char *s, size_t len) {
1728  if (len <= 24) {
1729  return len <= 12 ?
1730  (len <= 4 ? Hash32Len0to4(s, len) : Hash32Len5to12(s, len)) :
1731  Hash32Len13to24(s, len);
1732  }
1733 
1734  // len > 24
1735  uint32_t h = len, g = inlined::c1 * len, f = g;
1736  uint32_t a0 = Rotate(Fetch(s + len - 4) * inlined::c1, 17) * inlined::c2;
1737  uint32_t a1 = Rotate(Fetch(s + len - 8) * inlined::c1, 17) * inlined::c2;
1738  uint32_t a2 = Rotate(Fetch(s + len - 16) * inlined::c1, 17) * inlined::c2;
1739  uint32_t a3 = Rotate(Fetch(s + len - 12) * inlined::c1, 17) * inlined::c2;
1740  uint32_t a4 = Rotate(Fetch(s + len - 20) * inlined::c1, 17) * inlined::c2;
1741  h ^= a0;
1742  h = Rotate(h, 19);
1743  h = h * 5 + 0xe6546b64;
1744  h ^= a2;
1745  h = Rotate(h, 19);
1746  h = h * 5 + 0xe6546b64;
1747  g ^= a1;
1748  g = Rotate(g, 19);
1749  g = g * 5 + 0xe6546b64;
1750  g ^= a3;
1751  g = Rotate(g, 19);
1752  g = g * 5 + 0xe6546b64;
1753  f += a4;
1754  f = Rotate(f, 19);
1755  f = f * 5 + 0xe6546b64;
1756  size_t iters = (len - 1) / 20;
1757  do {
1758  uint32_t a0 = Rotate(Fetch(s) * inlined::c1, 17) * inlined::c2;
1759  uint32_t a1 = Fetch(s + 4);
1760  uint32_t a2 = Rotate(Fetch(s + 8) * inlined::c1, 17) * inlined::c2;
1761  uint32_t a3 = Rotate(Fetch(s + 12) * inlined::c1, 17) * inlined::c2;
1762  uint32_t a4 = Fetch(s + 16);
1763  h ^= a0;
1764  h = Rotate(h, 18);
1765  h = h * 5 + 0xe6546b64;
1766  f += a1;
1767  f = Rotate(f, 19);
1768  f = f * inlined::c1;
1769  g += a2;
1770  g = Rotate(g, 18);
1771  g = g * 5 + 0xe6546b64;
1772  h ^= a3 + a1;
1773  h = Rotate(h, 19);
1774  h = h * 5 + 0xe6546b64;
1775  g ^= a4;
1776  g = Bswap(g) * 5;
1777  h += a4 * 5;
1778  h = Bswap(h);
1779  f += a0;
1780  PERMUTE3(f, h, g);
1781  s += 20;
1782  } while (--iters != 0);
1783  g = Rotate(g, 11) * inlined::c1;
1784  g = Rotate(g, 17) * inlined::c1;
1785  f = Rotate(f, 11) * inlined::c1;
1786  f = Rotate(f, 17) * inlined::c1;
1787  h = Rotate(h + g, 19);
1788  h = h * 5 + 0xe6546b64;
1789  h = Rotate(h, 17) * inlined::c1;
1790  h = Rotate(h + f, 19);
1791  h = h * 5 + 0xe6546b64;
1792  h = Rotate(h, 17) * inlined::c1;
1793  return h;
1794 }
1795 
1796 STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
1797  if (len <= 24) {
1798  if (len >= 13) return farmhashmk::Hash32Len13to24(s, len, seed * inlined::c1);
1799  else if (len >= 5) return farmhashmk::Hash32Len5to12(s, len, seed);
1800  else return farmhashmk::Hash32Len0to4(s, len, seed);
1801  }
1802  uint32_t h = farmhashmk::Hash32Len13to24(s, 24, seed ^ len);
1803  return inlined::Mur(Hash32(s + 24, len - 24) + seed, h);
1804 }
1805 
1806 #undef Fetch
1807 #define Fetch farmhash::inlined::Fetch64
1808 
1809 #undef Rotate
1810 #define Rotate inlined::Rotate64
1811 
1812 #undef Bswap
1813 #define Bswap inlined::Bswap64
1814 
1815 #undef DebugTweak
1816 #define DebugTweak farmhash::inlined::DebugTweak
1817 
1818 STATIC_INLINE uint64_t ShiftMix(uint64_t val) {
1819  return val ^ (val >> 47);
1820 }
1821 
1822 STATIC_INLINE uint64_t HashLen16(uint64_t u, uint64_t v) {
1823  return Hash128to64(Uint128(u, v));
1824 }
1825 
1826 STATIC_INLINE uint64_t HashLen16(uint64_t u, uint64_t v, uint64_t mul) {
1827  // Murmur-inspired hashing.
1828  uint64_t a = (u ^ v) * mul;
1829  a ^= (a >> 47);
1830  uint64_t b = (v ^ a) * mul;
1831  b ^= (b >> 47);
1832  b *= mul;
1833  return b;
1834 }
1835 
1836 STATIC_INLINE uint64_t HashLen0to16(const char *s, size_t len) {
1837  if (len >= 8) {
1838  uint64_t mul = inlined::k2 + len * 2;
1839  uint64_t a = Fetch(s) + inlined::k2;
1840  uint64_t b = Fetch(s + len - 8);
1841  uint64_t c = Rotate(b, 37) * mul + a;
1842  uint64_t d = (Rotate(a, 25) + b) * mul;
1843  return HashLen16(c, d, mul);
1844  }
1845  if (len >= 4) {
1846  uint64_t mul = inlined::k2 + len * 2;
1847  uint64_t a = inlined::Fetch32(s);
1848  return HashLen16(len + (a << 3), inlined::Fetch32(s + len - 4), mul);
1849  }
1850  if (len > 0) {
1851  uint8_t a = s[0];
1852  uint8_t b = s[len >> 1];
1853  uint8_t c = s[len - 1];
1854  uint32_t y = static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8);
1855  uint32_t z = len + (static_cast<uint32_t>(c) << 2);
1856  return ShiftMix(y * inlined::k2 ^ z * inlined::k0) * inlined::k2;
1857  }
1858  return inlined::k2;
1859 }
1860 
1861 // Return a 16-byte hash for 48 bytes. Quick and dirty.
1862 // Callers do best to use "random-looking" values for a and b.
1863 STATIC_INLINE pair<uint64_t, uint64_t> WeakHashLen32WithSeeds(
1864  uint64_t w, uint64_t x, uint64_t y, uint64_t z, uint64_t a, uint64_t b) {
1865  a += w;
1866  b = Rotate(b + a + z, 21);
1867  uint64_t c = a;
1868  a += x;
1869  a += y;
1870  b += Rotate(a, 44);
1871  return make_pair(a + z, b + c);
1872 }
1873 
1874 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
1875 STATIC_INLINE pair<uint64_t, uint64_t> WeakHashLen32WithSeeds(
1876  const char* s, uint64_t a, uint64_t b) {
1877  return WeakHashLen32WithSeeds(Fetch(s),
1878  Fetch(s + 8),
1879  Fetch(s + 16),
1880  Fetch(s + 24),
1881  a,
1882  b);
1883 }
1884 
1885 
1886 
1887 // A subroutine for CityHash128(). Returns a decent 128-bit hash for strings
1888 // of any length representable in signed long. Based on City and Murmur.
1889 STATIC_INLINE uint128_t CityMurmur(const char *s, size_t len, uint128_t seed) {
1890  uint64_t a = Uint128Low64(seed);
1891  uint64_t b = Uint128High64(seed);
1892  uint64_t c = 0;
1893  uint64_t d = 0;
1894  signed long l = len - 16;
1895  if (l <= 0) { // len <= 16
1896  a = ShiftMix(a * inlined::k1) * inlined::k1;
1897  c = b * inlined::k1 + HashLen0to16(s, len);
1898  d = ShiftMix(a + (len >= 8 ? Fetch(s) : c));
1899  } else { // len > 16
1900  c = HashLen16(Fetch(s + len - 8) + inlined::k1, a);
1901  d = HashLen16(b + len, c + Fetch(s + len - 16));
1902  a += d;
1903  do {
1904  a ^= ShiftMix(Fetch(s) * inlined::k1) * inlined::k1;
1905  a *= inlined::k1;
1906  b ^= a;
1907  c ^= ShiftMix(Fetch(s + 8) * inlined::k1) * inlined::k1;
1908  c *= inlined::k1;
1909  d ^= c;
1910  s += 16;
1911  l -= 16;
1912  } while (l > 0);
1913  }
1914  a = HashLen16(a, c);
1915  b = HashLen16(d, b);
1916  return uint128_t(a ^ b, HashLen16(b, a));
1917 }
1918 
1919 STATIC_INLINE uint128_t CityHash128WithSeed(const char *s, size_t len, uint128_t seed) {
1920  if (len < 128) {
1921  return CityMurmur(s, len, seed);
1922  }
1923 
1924  // We expect len >= 128 to be the common case. Keep 56 bytes of state:
1925  // v, w, x, y, and z.
1926  pair<uint64_t, uint64_t> v, w;
1927  uint64_t x = Uint128Low64(seed);
1928  uint64_t y = Uint128High64(seed);
1929  uint64_t z = len * inlined::k1;
1930  v.first = Rotate(y ^ inlined::k1, 49) * inlined::k1 + Fetch(s);
1931  v.second = Rotate(v.first, 42) * inlined::k1 + Fetch(s + 8);
1932  w.first = Rotate(y + z, 35) * inlined::k1 + x;
1933  w.second = Rotate(x + Fetch(s + 88), 53) * inlined::k1;
1934 
1935  // This is the same inner loop as CityHash64(), manually unrolled.
1936  do {
1937  x = Rotate(x + y + v.first + Fetch(s + 8), 37) * inlined::k1;
1938  y = Rotate(y + v.second + Fetch(s + 48), 42) * inlined::k1;
1939  x ^= w.second;
1940  y += v.first + Fetch(s + 40);
1941  z = Rotate(z + w.first, 33) * inlined::k1;
1942  CopyUint128(v, WeakHashLen32WithSeeds(s, v.second * inlined::k1, x + w.first));
1943  CopyUint128(w, WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch(s + 16)));
1944  simpleSwap(z, x);
1945  s += 64;
1946  x = Rotate(x + y + v.first + Fetch(s + 8), 37) * inlined::k1;
1947  y = Rotate(y + v.second + Fetch(s + 48), 42) * inlined::k1;
1948  x ^= w.second;
1949  y += v.first + Fetch(s + 40);
1950  z = Rotate(z + w.first, 33) * inlined::k1;
1951  CopyUint128(v, WeakHashLen32WithSeeds(s, v.second * inlined::k1, x + w.first));
1952  CopyUint128(w, WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch(s + 16)));
1953  simpleSwap(z, x);
1954  s += 64;
1955  len -= 128;
1956  } while (OIIO_LIKELY(len >= 128));
1957  x += Rotate(v.first + z, 49) * inlined::k0;
1958  y = y * inlined::k0 + Rotate(w.second, 37);
1959  z = z * inlined::k0 + Rotate(w.first, 27);
1960  w.first *= 9;
1961  v.first *= inlined::k0;
1962  // If 0 < len < 128, hash up to 4 chunks of 32 bytes each from the end of s.
1963  for (size_t tail_done = 0; tail_done < len; ) {
1964  tail_done += 32;
1965  y = Rotate(x + y, 42) * inlined::k0 + v.second;
1966  w.first += Fetch(s + len - tail_done + 16);
1967  x = x * inlined::k0 + w.first;
1968  z += w.second + Fetch(s + len - tail_done);
1969  w.second += v.first;
1970  CopyUint128(v, WeakHashLen32WithSeeds(s + len - tail_done, v.first + z, v.second));
1971  v.first *= inlined::k0;
1972  }
1973  // At this point our 56 bytes of state should contain more than
1974  // enough information for a strong 128-bit hash. We use two
1975  // different 56-byte-to-8-byte hashes to get a 16-byte final result.
1976  x = HashLen16(x, v.first);
1977  y = HashLen16(y + z, w.first);
1978  return uint128_t(HashLen16(x + v.second, w.second) + y,
1979  HashLen16(x + w.second, y + v.second));
1980 }
1981 
1982 STATIC_INLINE uint128_t CityHash128(const char *s, size_t len) {
1983  return len >= 16 ?
1984  CityHash128WithSeed(s + 16, len - 16,
1985  uint128_t(Fetch(s), Fetch(s + 8) + inlined::k0)) :
1986  CityHash128WithSeed(s, len, uint128_t(inlined::k0, inlined::k1));
1987 }
1988 
1989 uint128_t STATIC_INLINE Fingerprint128(const char* s, size_t len) {
1990  return CityHash128(s, len);
1991 }
1992 } // namespace farmhashcc
1993 
1994 
1995 // namespace NAMESPACE_FOR_HASH_FUNCTIONS {
1996 namespace inlined {
1997 
1998 
1999 // BASIC STRING HASHING
2000 
2001 // Hash function for a byte array. See also Hash(), below.
2002 // May change from time to time, may differ on different platforms, may differ
2003 // depending on NDEBUG.
2004 STATIC_INLINE uint32_t Hash32(const char* s, size_t len) {
2005  return DebugTweak(
2006  (can_use_sse41 & x86_64) ? farmhashnt::Hash32(s, len) :
2008  can_use_sse42 ? farmhashsa::Hash32(s, len) :
2009  farmhashmk::Hash32(s, len));
2010 }
2011 
2012 // Hash function for a byte array. For convenience, a 32-bit seed is also
2013 // hashed into the result.
2014 // May change from time to time, may differ on different platforms, may differ
2015 // depending on NDEBUG.
2016 STATIC_INLINE uint32_t Hash32WithSeed(const char* s, size_t len, uint32_t seed) {
2017  return DebugTweak(
2018  (can_use_sse41 & x86_64) ? farmhashnt::Hash32WithSeed(s, len, seed) :
2020  can_use_sse42 ? farmhashsa::Hash32WithSeed(s, len, seed) :
2021  farmhashmk::Hash32WithSeed(s, len, seed));
2022 }
2023 
2024 // Hash function for a byte array. For convenience, a 64-bit seed is also
2025 // hashed into the result. See also Hash(), below.
2026 // May change from time to time, may differ on different platforms, may differ
2027 // depending on NDEBUG.
2028 STATIC_INLINE uint64_t Hash64(const char* s, size_t len) {
2029  return DebugTweak(
2030  (can_use_sse42 & x86_64) ?
2031  farmhashte::Hash64(s, len) :
2032  farmhashxo::Hash64(s, len));
2033 }
2034 
2035 // Hash function for a byte array.
2036 // May change from time to time, may differ on different platforms, may differ
2037 // depending on NDEBUG.
2038 STATIC_INLINE size_t Hash(const char* s, size_t len) {
2039  return sizeof(size_t) == 8 ? Hash64(s, len) : Hash32(s, len);
2040 }
2041 
2042 // Hash function for a byte array. For convenience, a 64-bit seed is also
2043 // hashed into the result.
2044 // May change from time to time, may differ on different platforms, may differ
2045 // depending on NDEBUG.
2046 STATIC_INLINE uint64_t Hash64WithSeed(const char* s, size_t len, uint64_t seed) {
2047  return DebugTweak(farmhashna::Hash64WithSeed(s, len, seed));
2048 }
2049 
2050 // Hash function for a byte array. For convenience, two seeds are also
2051 // hashed into the result.
2052 // May change from time to time, may differ on different platforms, may differ
2053 // depending on NDEBUG.
2054 STATIC_INLINE uint64_t Hash64WithSeeds(const char* s, size_t len, uint64_t seed0, uint64_t seed1) {
2055  return DebugTweak(farmhashna::Hash64WithSeeds(s, len, seed0, seed1));
2056 }
2057 
2058 // Hash function for a byte array.
2059 // May change from time to time, may differ on different platforms, may differ
2060 // depending on NDEBUG.
2061 STATIC_INLINE uint128_t Hash128(const char* s, size_t len) {
2062  return DebugTweak(farmhashcc::Fingerprint128(s, len));
2063 }
2064 
2065 // Hash function for a byte array. For convenience, a 128-bit seed is also
2066 // hashed into the result.
2067 // May change from time to time, may differ on different platforms, may differ
2068 // depending on NDEBUG.
2069 STATIC_INLINE uint128_t Hash128WithSeed(const char* s, size_t len, uint128_t seed) {
2070  return DebugTweak(farmhashcc::CityHash128WithSeed(s, len, seed));
2071 }
2072 
2073 // BASIC NON-STRING HASHING
2074 
2075 // FINGERPRINTING (i.e., good, portable, forever-fixed hash functions)
2076 
2077 // Fingerprint function for a byte array. Most useful in 32-bit binaries.
2078 STATIC_INLINE uint32_t Fingerprint32(const char* s, size_t len) {
2079  return farmhashmk::Hash32(s, len);
2080 }
2081 
2082 // Fingerprint function for a byte array.
2083 STATIC_INLINE uint64_t Fingerprint64(const char* s, size_t len) {
2084  return farmhashna::Hash64(s, len);
2085 }
2086 
2087 // Fingerprint function for a byte array.
2088 STATIC_INLINE uint128_t Fingerprint128(const char* s, size_t len) {
2089  return farmhashcc::Fingerprint128(s, len);
2090 }
2091 
2092 // Older and still available but perhaps not as fast as the above:
2093 // farmhashns::Hash32{,WithSeed}()
2094 
2095 } /*end namespace inlined*/
2096 // } // namespace NAMESPACE_FOR_HASH_FUNCTIONS
2097 } /*end namespace farmhash*/
2098 
2099 #undef Fetch
2100 #undef Rotate
2101 #undef Bswap
2102 #undef DebugTweak
2103 #undef uint128_t
2104 #undef Uint128
2105 #undef Uint128Low64
2106 #undef Uint128High64
2107 #undef Hash128to64
2108 #undef Hash64WithSeeds
2109 #undef x86
2110 #undef x86_64
2111 
2113 
2114 #undef STATIC_INLINE
2115 
2116 
STATIC_INLINE uint32_t Hash32(const char *s, size_t len)
Definition: farmhash.h:1181
STATIC_INLINE uint128_t CityHash128WithSeed(const char *s, size_t len, uint128_t seed)
Definition: farmhash.h:1919
OIIO_HOSTDEVICE constexpr uint128_t Uint128(uint64_t lo, uint64_t hi)
Definition: hash.h:334
#define OIIO_LIKELY(x)
Definition: platform.h:342
STATIC_INLINE uint32_t Hash32(const char *s, size_t len)
Definition: farmhash.h:1109
STATIC_INLINE pair< uint64_t, uint64_t > WeakHashLen32WithSeeds(const char *s, uint64_t a, uint64_t b)
Definition: farmhash.h:1875
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
#define STATIC_INLINE
Definition: farmhash.h:84
STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed)
Definition: farmhash.h:1257
STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed)
Definition: farmhash.h:1477
STATIC_INLINE uint32_t Hash32(const char *s, size_t len)
Definition: farmhash.h:1472
#define Rotate
Definition: farmhash.h:1810
STATIC_INLINE uint32_t fmix(uint32_t h)
Definition: farmhash.h:477
uint128_t STATIC_INLINE Fingerprint128(const char *s, size_t len)
Definition: farmhash.h:1989
STATIC_INLINE uint64_t Hash64(const char *s, size_t len)
Definition: farmhash.h:804
OIIO_HOSTDEVICE constexpr uint64_t Uint128Low64(const uint128_t x)
Definition: hash.h:326
#define x86_64
Definition: farmhash.h:351
uint128_t OIIO_API Hash128WithSeed(const char *s, size_t len, uint128_t seed)
Definition: farmhash.h:2069
STATIC_INLINE uint64_t HashLen33to64(const char *s, size_t len)
Definition: farmhash.h:830
const GLfloat * c
Definition: glew.h:16631
GLboolean GLboolean g
Definition: glcorearb.h:1221
STATIC_INLINE uint64_t Hash64WithSeed(const char *s, size_t len, uint64_t seed)
Definition: farmhash.h:882
#define can_use_sse42
Definition: farmhash.h:395
STATIC_INLINE uint32_t Bswap32(uint32_t val)
Definition: farmhash.h:285
STATIC_INLINE uint32_t Hash32Len13to24(const char *s, size_t len)
Definition: farmhash.h:1696
STATIC_INLINE uint64_t HashLen16(uint64_t u, uint64_t v)
Definition: farmhash.h:538
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 uint64_t Hash128to64(uint128_t x)
Definition: hash.h:400
STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed)
Definition: farmhash.h:1239
GLdouble GLdouble t
Definition: glew.h:1403
STATIC_INLINE uint64_t HashLen65to96(const char *s, size_t len)
Definition: farmhash.h:839
uint64_t OIIO_API Hash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1)
Definition: farmhash.h:685
size_t OIIO_API Hash(const char *s, size_t len)
Definition: farmhash.h:2038
STATIC_INLINE uint32_t Rotate32(uint32_t val, int shift)
Definition: farmhash.h:316
GLdouble l
Definition: glew.h:9164
STATIC_INLINE uint64_t H32(const char *s, size_t len, uint64_t mul, uint64_t seed0=0, uint64_t seed1=0)
Definition: farmhash.h:816
GLint GLenum GLint x
Definition: glcorearb.h:408
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
STATIC_INLINE uint32_t Fetch32(const char *p)
Definition: farmhash.h:234
GLdouble GLdouble GLdouble GLdouble q
Definition: glew.h:1419
STATIC_INLINE T DebugTweak(T x)
Definition: farmhash.h:497
#define can_use_sse41
Definition: farmhash.h:384
GLuint64EXT * result
Definition: glew.h:14311
STATIC_INLINE uint32_t BasicRotate32(uint32_t val, int shift)
Definition: farmhash.h:290
#define Bswap
Definition: farmhash.h:1813
#define DebugTweak
Definition: farmhash.h:1816
STATIC_INLINE uint32_t Hash32Len5to12(const char *s, size_t len)
Definition: farmhash.h:1719
GLint GLuint mask
Definition: glcorearb.h:123
GLenum GLsizei len
Definition: glew.h:7782
STATIC_INLINE uint64_t Hash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1)
Definition: farmhash.h:708
STATIC_INLINE uint32_t Mur(uint32_t a, uint32_t h)
Definition: farmhash.h:487
const GLdouble * v
Definition: glcorearb.h:836
STATIC_INLINE uint64_t ShiftMix(uint64_t val)
Definition: farmhash.h:1818
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GLuint GLuint end
Definition: glcorearb.h:474
#define uint64_in_expected_order(x)
Definition: farmhash.h:198
#define can_use_aesni
Definition: farmhash.h:406
STATIC_INLINE uint128_t CityHash128(const char *s, size_t len)
Definition: farmhash.h:1982
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
GLfloat GLfloat p
Definition: glew.h:16656
STATIC_INLINE uint32_t Hash32Len5to12(const char *s, size_t len, uint32_t seed=0)
Definition: farmhash.h:1173
OIIO_HOSTDEVICE constexpr uint64_t Uint128High64(const uint128_t x)
Definition: hash.h:330
STATIC_INLINE uint64_t H(uint64_t x, uint64_t y, uint64_t mul, int r)
Definition: farmhash.h:701
#define uint32_in_expected_order(x)
Definition: farmhash.h:197
STATIC_INLINE uint64_t Hash64(const char *s, size_t len)
Definition: farmhash.h:848
STATIC_INLINE uint64_t HashLen17to32(const char *s, size_t len)
Definition: farmhash.h:579
STATIC_INLINE uint64_t Hash64WithSeed(const char *s, size_t len, uint64_t seed)
Definition: farmhash.h:689
uint64_t OIIO_API Hash64(const char *s, size_t len)
Definition: farmhash.h:630
uint32_t OIIO_API Fingerprint32(const char *s, size_t len)
Definition: farmhash.h:2078
STATIC_INLINE uint32_t Hash32Len13to24(const char *s, size_t len, uint32_t seed=0)
Definition: farmhash.h:1145
STATIC_INLINE uint64_t Rotate64(uint64_t val, int shift)
Definition: farmhash.h:319
STATIC_INLINE uint64_t Bswap64(uint64_t val)
Definition: farmhash.h:286
uint128_t OIIO_API Hash128(const char *s, size_t len)
Definition: farmhash.h:2061
#define PERMUTE3(a, b, c)
Definition: farmhash.h:450
GLdouble n
Definition: glcorearb.h:2007
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2539
uint64_t OIIO_API Fingerprint64(const char *s, size_t len)
Definition: farmhash.h:2083
STATIC_INLINE uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed)
Definition: farmhash.h:1114
STATIC_INLINE uint32_t Hash32(const char *s, size_t len)
Definition: farmhash.h:1252
GLuint GLfloat * val
Definition: glcorearb.h:1607
STATIC_INLINE pair< uint64_t, uint64_t > WeakHashLen32WithSeeds(uint64_t w, uint64_t x, uint64_t y, uint64_t z, uint64_t a, uint64_t b)
Definition: farmhash.h:591
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
STATIC_INLINE uint64_t HashLen0to16(const char *s, size_t len)
Definition: farmhash.h:1836
STATIC_INLINE uint32_t Hash32Len0to4(const char *s, size_t len)
Definition: farmhash.h:1708
STATIC_INLINE void simpleSwap(T &a, T &b)
Definition: farmhash.h:207
STATIC_INLINE uint64_t HashLen0to16(const char *s, size_t len)
Definition: farmhash.h:552
STATIC_INLINE uint128_t CityMurmur(const char *s, size_t len, uint128_t seed)
Definition: farmhash.h:1889
uint64_t OIIO_API Hash64WithSeed(const char *s, size_t len, uint64_t seed)
Definition: farmhash.h:689
STATIC_INLINE uint64_t Hash64(const char *s, size_t len)
Definition: farmhash.h:630
#define fmix
Definition: farmhash.h:1694
STATIC_INLINE uint64_t Fetch64(const char *p)
Definition: farmhash.h:228
GLfloat f
Definition: glcorearb.h:1925
#define Fetch
Definition: farmhash.h:1807
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:94
STATIC_INLINE uint64_t HashLen16(uint64_t u, uint64_t v, uint64_t mul)
Definition: farmhash.h:1826
#define FARMHASH_DIE_IF_MISCONFIGURED
Definition: farmhash.h:92
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 void CopyUint128(uint128_t &dst, const uint128_t src)
Definition: hash.h:339
STATIC_INLINE uint64_t BasicRotate64(uint64_t val, int shift)
Definition: farmhash.h:295
STATIC_INLINE uint64_t Hash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1)
Definition: farmhash.h:685
GLboolean r
Definition: glcorearb.h:1221
uint32_t OIIO_API Hash32WithSeed(const char *s, size_t len, uint32_t seed)
Definition: farmhash.h:1114
GLdouble s
Definition: glew.h:1395
STATIC_INLINE uint64_t Hash64(const char *s, size_t len)
Definition: farmhash.h:877
GLint y
Definition: glcorearb.h:102
uint32_t OIIO_API Hash32(const char *s, size_t len)
Definition: farmhash.h:1109
std::pair< uint64_t, uint64_t > uint128_t
Definition: hash.h:325
#define debug_mode
Definition: farmhash.h:342
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:93
ImageBuf OIIO_API mul(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
STATIC_INLINE uint64_t ShiftMix(uint64_t val)
Definition: farmhash.h:534
STATIC_INLINE uint64_t Hash64WithSeed(const char *s, size_t len, uint64_t seed)
Definition: farmhash.h:799
uint128_t OIIO_API Fingerprint128(const char *s, size_t len)
Definition: farmhash.h:1989
STATIC_INLINE uint32_t Hash32Len0to4(const char *s, size_t len, uint32_t seed=0)
Definition: farmhash.h:1162