174 #if defined (__cplusplus)
187 #define XXH_NAMESPACE UT_ // SideFX modification
208 # define XXH_INLINE_ALL
209 # undef XXH_INLINE_ALL
213 # define XXH_PRIVATE_API
214 # undef XXH_PRIVATE_API
228 # define XXH_NAMESPACE UT_ // SideFX modification
229 # undef XXH_NAMESPACE
232 #if (defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)) \
233 && !defined(XXH_INLINE_ALL_31684351384)
235 # define XXH_INLINE_ALL_31684351384
237 # undef XXH_STATIC_LINKING_ONLY
238 # define XXH_STATIC_LINKING_ONLY
240 # undef XXH_PUBLIC_API
241 # if defined(__GNUC__)
242 # define XXH_PUBLIC_API static __inline __attribute__((unused))
243 # elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) )
244 # define XXH_PUBLIC_API static inline
245 # elif defined(_MSC_VER)
246 # define XXH_PUBLIC_API static __inline
249 # define XXH_PUBLIC_API static
265 # undef XXH_versionNumber
268 # undef XXH32_createState
269 # undef XXH32_freeState
273 # undef XXH32_copyState
274 # undef XXH32_canonicalFromHash
275 # undef XXH32_hashFromCanonical
278 # undef XXH64_createState
279 # undef XXH64_freeState
283 # undef XXH64_copyState
284 # undef XXH64_canonicalFromHash
285 # undef XXH64_hashFromCanonical
288 # undef XXH3_64bits_withSecret
289 # undef XXH3_64bits_withSeed
290 # undef XXH3_64bits_withSecretandSeed
291 # undef XXH3_createState
292 # undef XXH3_freeState
293 # undef XXH3_copyState
294 # undef XXH3_64bits_reset
295 # undef XXH3_64bits_reset_withSeed
296 # undef XXH3_64bits_reset_withSecret
297 # undef XXH3_64bits_update
298 # undef XXH3_64bits_digest
299 # undef XXH3_generateSecret
303 # undef XXH3_128bits_withSeed
304 # undef XXH3_128bits_withSecret
305 # undef XXH3_128bits_reset
306 # undef XXH3_128bits_reset_withSeed
307 # undef XXH3_128bits_reset_withSecret
308 # undef XXH3_128bits_reset_withSecretandSeed
309 # undef XXH3_128bits_update
310 # undef XXH3_128bits_digest
311 # undef XXH128_isEqual
313 # undef XXH128_canonicalFromHash
314 # undef XXH128_hashFromCanonical
316 # undef XXH_NAMESPACE
319 # define XXH_NAMESPACE XXH_INLINE_
327 # define XXH_IPREF(Id) XXH_NAMESPACE ## Id
328 # define XXH_OK XXH_IPREF(XXH_OK)
329 # define XXH_ERROR XXH_IPREF(XXH_ERROR)
330 # define XXH_errorcode XXH_IPREF(XXH_errorcode)
331 # define XXH32_canonical_t XXH_IPREF(XXH32_canonical_t)
332 # define XXH64_canonical_t XXH_IPREF(XXH64_canonical_t)
333 # define XXH128_canonical_t XXH_IPREF(XXH128_canonical_t)
334 # define XXH32_state_s XXH_IPREF(XXH32_state_s)
335 # define XXH32_state_t XXH_IPREF(XXH32_state_t)
336 # define XXH64_state_s XXH_IPREF(XXH64_state_s)
337 # define XXH64_state_t XXH_IPREF(XXH64_state_t)
338 # define XXH3_state_s XXH_IPREF(XXH3_state_s)
339 # define XXH3_state_t XXH_IPREF(XXH3_state_t)
340 # define XXH128_hash_t XXH_IPREF(XXH128_hash_t)
342 # undef XXHASH_H_5627135585666179
343 # undef XXHASH_H_STATIC_13879238742
349 #ifndef XXHASH_H_5627135585666179
350 #define XXHASH_H_5627135585666179 1
353 #if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API)
354 # if defined(WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
356 # define XXH_PUBLIC_API __declspec(dllexport)
358 # define XXH_PUBLIC_API __declspec(dllimport)
361 # define XXH_PUBLIC_API
363 # undef XXH_PUBLIC_API // SideFX modification
364 # define XXH_PUBLIC_API UT_API // SideFX modification
368 # define XXH_CAT(A,B) A##B
369 # define XXH_NAME2(A,B) XXH_CAT(A,B)
370 # define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber)
372 # define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
373 # define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
374 # define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
375 # define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
376 # define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
377 # define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
378 # define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState)
379 # define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash)
380 # define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical)
382 # define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
383 # define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
384 # define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
385 # define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
386 # define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
387 # define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
388 # define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState)
389 # define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash)
390 # define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical)
392 # define XXH3_64bits XXH_NAME2(XXH_NAMESPACE, XXH3_64bits)
393 # define XXH3_64bits_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSecret)
394 # define XXH3_64bits_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSeed)
395 # define XXH3_64bits_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSecretandSeed)
396 # define XXH3_createState XXH_NAME2(XXH_NAMESPACE, XXH3_createState)
397 # define XXH3_freeState XXH_NAME2(XXH_NAMESPACE, XXH3_freeState)
398 # define XXH3_copyState XXH_NAME2(XXH_NAMESPACE, XXH3_copyState)
399 # define XXH3_64bits_reset XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset)
400 # define XXH3_64bits_reset_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSeed)
401 # define XXH3_64bits_reset_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSecret)
402 # define XXH3_64bits_reset_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSecretandSeed)
403 # define XXH3_64bits_update XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_update)
404 # define XXH3_64bits_digest XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_digest)
405 # define XXH3_generateSecret XXH_NAME2(XXH_NAMESPACE, XXH3_generateSecret)
406 # define XXH3_generateSecret_fromSeed XXH_NAME2(XXH_NAMESPACE, XXH3_generateSecret_fromSeed)
408 # define XXH128 XXH_NAME2(XXH_NAMESPACE, XXH128)
409 # define XXH3_128bits XXH_NAME2(XXH_NAMESPACE, XXH3_128bits)
410 # define XXH3_128bits_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSeed)
411 # define XXH3_128bits_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSecret)
412 # define XXH3_128bits_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSecretandSeed)
413 # define XXH3_128bits_reset XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset)
414 # define XXH3_128bits_reset_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSeed)
415 # define XXH3_128bits_reset_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSecret)
416 # define XXH3_128bits_reset_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSecretandSeed)
417 # define XXH3_128bits_update XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_update)
418 # define XXH3_128bits_digest XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_digest)
419 # define XXH128_isEqual XXH_NAME2(XXH_NAMESPACE, XXH128_isEqual)
420 # define XXH128_cmp XXH_NAME2(XXH_NAMESPACE, XXH128_cmp)
421 # define XXH128_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH128_canonicalFromHash)
422 # define XXH128_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH128_hashFromCanonical)
431 #if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API)
432 # undef XXH_PUBLIC_API // SideFX modification
433 # if defined(WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
435 # define XXH_PUBLIC_API __declspec(dllexport)
437 # define XXH_PUBLIC_API __declspec(dllimport)
440 # define XXH_PUBLIC_API
442 # undef XXH_PUBLIC_API // SideFX modification
443 # define XXH_PUBLIC_API UT_API // SideFX modification
446 #if defined (__GNUC__)
447 # define XXH_CONSTF __attribute__((const))
448 # define XXH_PUREF __attribute__((pure))
449 # define XXH_MALLOCF __attribute__((malloc))
459 #define XXH_VERSION_MAJOR 0
460 #define XXH_VERSION_MINOR 8
461 #define XXH_VERSION_RELEASE 1
463 #define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
492 #if defined(XXH_DOXYGEN)
498 typedef uint32_t XXH32_hash_t;
500 #elif !defined (__VMS) \
501 && (defined (__cplusplus) \
502 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
504 typedef uint32_t XXH32_hash_t;
508 # if UINT_MAX == 0xFFFFFFFFUL
509 typedef unsigned int XXH32_hash_t;
510 # elif ULONG_MAX == 0xFFFFFFFFUL
511 typedef unsigned long XXH32_hash_t;
513 # error "unsupported platform: need a 32-bit type"
560 #ifndef XXH_NO_STREAM
696 unsigned char digest[4];
723 #ifdef __has_attribute
724 # define XXH_HAS_ATTRIBUTE(x) __has_attribute(x)
726 # define XXH_HAS_ATTRIBUTE(x) 0
730 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) && defined(__has_c_attribute)
731 # define XXH_HAS_C_ATTRIBUTE(x) __has_c_attribute(x)
733 # define XXH_HAS_C_ATTRIBUTE(x) 0
736 #if defined(__cplusplus) && defined(__has_cpp_attribute)
737 # define XXH_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
739 # define XXH_HAS_CPP_ATTRIBUTE(x) 0
748 #if XXH_HAS_C_ATTRIBUTE(fallthrough) || XXH_HAS_CPP_ATTRIBUTE(fallthrough)
749 # define XXH_FALLTHROUGH [[fallthrough]]
750 #elif XXH_HAS_ATTRIBUTE(__fallthrough__)
751 # define XXH_FALLTHROUGH __attribute__ ((__fallthrough__))
753 # define XXH_FALLTHROUGH
762 #ifndef XXH_NO_LONG_LONG
766 #if defined(XXH_DOXYGEN)
773 #elif !defined (__VMS) \
774 && (defined (__cplusplus) \
775 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
780 # if defined(__LP64__) && ULONG_MAX == 0xFFFFFFFFFFFFFFFFULL
829 #ifndef XXH_NO_STREAM
941 #define XXH3_SECRET_SIZE_MIN 136
965 #ifndef XXH_NO_STREAM
1053 #ifndef XXH_NO_STREAM
1111 #if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXHASH_H_STATIC_13879238742)
1112 #define XXHASH_H_STATIC_13879238742
1139 struct XXH32_state_s {
1140 XXH32_hash_t total_len_32;
1141 XXH32_hash_t large_len;
1143 XXH32_hash_t mem32[4];
1144 XXH32_hash_t memsize;
1145 XXH32_hash_t reserved;
1149 #ifndef XXH_NO_LONG_LONG
1163 struct XXH64_state_s {
1164 XXH64_hash_t total_len;
1166 XXH64_hash_t mem64[4];
1167 XXH32_hash_t memsize;
1168 XXH32_hash_t reserved32;
1169 XXH64_hash_t reserved64;
1174 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
1175 # include <stdalign.h>
1176 # define XXH_ALIGN(n) alignas(n)
1177 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1179 # define XXH_ALIGN(n) alignas(n)
1180 #elif defined(__GNUC__)
1181 # define XXH_ALIGN(n) __attribute__ ((aligned(n)))
1182 #elif defined(_MSC_VER)
1183 # define XXH_ALIGN(n) __declspec(align(n))
1185 # define XXH_ALIGN(n)
1189 #if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) \
1190 && ! (defined(__cplusplus) && (__cplusplus >= 201103L)) \
1191 && defined(__GNUC__)
1192 # define XXH_ALIGN_MEMBER(align, type) type XXH_ALIGN(align)
1194 # define XXH_ALIGN_MEMBER(align, type) XXH_ALIGN(align) type
1204 #define XXH3_INTERNALBUFFER_SIZE 256
1213 #define XXH3_SECRET_DEFAULT_SIZE 192
1237 struct XXH3_state_s {
1238 XXH_ALIGN_MEMBER(64, XXH64_hash_t acc[8]);
1240 XXH_ALIGN_MEMBER(64,
unsigned char customSecret[XXH3_SECRET_DEFAULT_SIZE]);
1242 XXH_ALIGN_MEMBER(64,
unsigned char buffer[XXH3_INTERNALBUFFER_SIZE]);
1244 XXH32_hash_t bufferedSize;
1246 XXH32_hash_t useSeed;
1248 size_t nbStripesSoFar;
1250 XXH64_hash_t totalLen;
1252 size_t nbStripesPerBlock;
1258 XXH64_hash_t reserved64;
1260 const unsigned char* extSecret;
1266 #undef XXH_ALIGN_MEMBER
1279 #define XXH3_INITSTATE(XXH3_state_ptr) { (XXH3_state_ptr)->seed = 0; }
1411 const void* secret,
size_t secretSize,
1416 const void* secret,
size_t secretSize,
1417 XXH64_hash_t seed64);
1418 #ifndef XXH_NO_STREAM
1422 const void* secret,
size_t secretSize,
1423 XXH64_hash_t seed64);
1427 const void* secret,
size_t secretSize,
1428 XXH64_hash_t seed64);
1433 #if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)
1434 # define XXH_IMPLEMENTATION
1467 #if ( defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) \
1468 || defined(XXH_IMPLEMENTATION) ) && !defined(XXH_IMPLEM_13a8737387)
1469 # define XXH_IMPLEM_13a8737387
1487 # define XXH_NO_LONG_LONG
1488 # undef XXH_NO_LONG_LONG
1539 # define XXH_FORCE_MEMORY_ACCESS 0
1567 # define XXH_SIZE_OPT 0
1597 # define XXH_FORCE_ALIGN_CHECK 0
1619 # define XXH_NO_INLINE_HINTS 0
1631 # define XXH32_ENDJMP 0
1640 # define XXH_OLD_NAMES
1641 # undef XXH_OLD_NAMES
1651 # define XXH_NO_STREAM
1652 # undef XXH_NO_STREAM
1658 #ifndef XXH_FORCE_MEMORY_ACCESS
1662 # if defined(__GNUC__) && !(defined(__ARM_ARCH) && __ARM_ARCH < 7 && defined(__ARM_FEATURE_UNALIGNED))
1663 # define XXH_FORCE_MEMORY_ACCESS 1
1667 #ifndef XXH_SIZE_OPT
1669 # if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE_SIZE__)
1670 # define XXH_SIZE_OPT 1
1672 # define XXH_SIZE_OPT 0
1676 #ifndef XXH_FORCE_ALIGN_CHECK
1678 # if XXH_SIZE_OPT >= 1 || \
1679 defined(__i386) || defined(__x86_64__) || defined(__aarch64__) || defined(__ARM_FEATURE_UNALIGNED) \
1680 || defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64) || defined(_M_ARM)
1681 # define XXH_FORCE_ALIGN_CHECK 0
1683 # define XXH_FORCE_ALIGN_CHECK 1
1687 #ifndef XXH_NO_INLINE_HINTS
1688 # if XXH_SIZE_OPT >= 1 || defined(__NO_INLINE__)
1689 # define XXH_NO_INLINE_HINTS 1
1691 # define XXH_NO_INLINE_HINTS 0
1695 #ifndef XXH32_ENDJMP
1697 # define XXH32_ENDJMP 0
1709 #if defined(XXH_NO_STREAM)
1711 #elif defined(XXH_NO_STDLIB)
1722 static XXH_CONSTF void* XXH_malloc(
size_t s) { (
void)s;
return NULL; }
1723 static void XXH_free(
void* p) { (
void)p; }
1737 static XXH_MALLOCF void* XXH_malloc(
size_t s) {
return malloc(s); }
1743 static void XXH_free(
void* p) { free(p); }
1753 static void* XXH_memcpy(
void* dest,
const void*
src,
size_t size)
1755 return memcpy(dest,src,size);
1764 #if XXH_NO_INLINE_HINTS
1765 # if defined(__GNUC__) || defined(__clang__)
1766 # define XXH_FORCE_INLINE static __attribute__((unused))
1768 # define XXH_FORCE_INLINE static
1770 # define XXH_NO_INLINE static
1772 #elif defined(__GNUC__) || defined(__clang__)
1773 # define XXH_FORCE_INLINE static __inline__ __attribute__((always_inline, unused))
1774 # define XXH_NO_INLINE static __attribute__((noinline))
1775 #elif defined(_MSC_VER)
1776 # define XXH_FORCE_INLINE static __forceinline
1777 # define XXH_NO_INLINE static __declspec(noinline)
1778 #elif defined (__cplusplus) \
1779 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
1780 # define XXH_FORCE_INLINE static inline
1781 # define XXH_NO_INLINE static
1783 # define XXH_FORCE_INLINE static
1784 # define XXH_NO_INLINE static
1800 #ifndef XXH_DEBUGLEVEL
1802 # define XXH_DEBUGLEVEL DEBUGLEVEL
1804 # define XXH_DEBUGLEVEL 0
1808 #if (XXH_DEBUGLEVEL>=1)
1809 # include <assert.h>
1810 # define XXH_ASSERT(c) assert(c)
1812 # define XXH_ASSERT(c) ((void)0)
1816 #ifndef XXH_STATIC_ASSERT
1817 # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
1818 # define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { _Static_assert((c),m); } while(0)
1819 # elif defined(__cplusplus) && (__cplusplus >= 201103L)
1820 # define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { static_assert((c),m); } while(0)
1822 # define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { struct xxh_sa { char x[(c) ? 1 : -1]; }; } while(0)
1824 # define XXH_STATIC_ASSERT(c) XXH_STATIC_ASSERT_WITH_MESSAGE((c),#c)
1843 #if defined(__GNUC__) || defined(__clang__)
1844 # define XXH_COMPILER_GUARD(var) __asm__ __volatile__("" : "+r" (var))
1846 # define XXH_COMPILER_GUARD(var) ((void)0)
1849 #if defined(__GNUC__) || defined(__clang__)
1850 # define XXH_COMPILER_GUARD_W(var) __asm__ __volatile__("" : "+w" (var))
1852 # define XXH_COMPILER_GUARD_W(var) ((void)0)
1858 #if !defined (__VMS) \
1859 && (defined (__cplusplus) \
1860 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
1861 # include <stdint.h>
1862 typedef uint8_t xxh_u8;
1864 typedef unsigned char xxh_u8;
1866 typedef XXH32_hash_t xxh_u32;
1868 #ifdef XXH_OLD_NAMES
1869 # define BYTE xxh_u8
1871 # define U32 xxh_u32
1926 #if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
1931 #elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
1937 static xxh_u32 XXH_read32(
const void* memPtr) {
return *(
const xxh_u32*) memPtr; }
1939 #elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
1948 #ifdef XXH_OLD_NAMES
1951 static xxh_u32 XXH_read32(
const void*
ptr)
1954 return *((const xxh_unalign32*)ptr);
1963 static xxh_u32 XXH_read32(
const void* memPtr)
1966 XXH_memcpy(&val, memPtr,
sizeof(val));
1991 #ifndef XXH_CPU_LITTLE_ENDIAN
1996 # if defined(_WIN32) \
1997 || defined(__LITTLE_ENDIAN__) \
1998 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
1999 # define XXH_CPU_LITTLE_ENDIAN 1
2000 # elif defined(__BIG_ENDIAN__) \
2001 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
2002 # define XXH_CPU_LITTLE_ENDIAN 0
2010 static int XXH_isLittleEndian(
void)
2016 const union { xxh_u32 u; xxh_u8
c[4]; } one = { 1 };
2019 # define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian()
2029 #define XXH_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
2031 #ifdef __has_builtin
2032 # define XXH_HAS_BUILTIN(x) __has_builtin(x)
2034 # define XXH_HAS_BUILTIN(x) 0
2050 #if !defined(NO_CLANG_BUILTIN) && XXH_HAS_BUILTIN(__builtin_rotateleft32) \
2051 && XXH_HAS_BUILTIN(__builtin_rotateleft64)
2052 # define XXH_rotl32 __builtin_rotateleft32
2053 # define XXH_rotl64 __builtin_rotateleft64
2055 #elif defined(_MSC_VER)
2056 # define XXH_rotl32(x,r) _rotl(x,r)
2057 # define XXH_rotl64(x,r) _rotl64(x,r)
2059 # define XXH_rotl32(x,r) (((x) << (r)) | ((x) >> (32 - (r))))
2060 # define XXH_rotl64(x,r) (((x) << (r)) | ((x) >> (64 - (r))))
2071 #if defined(_MSC_VER)
2072 # define XXH_swap32 _byteswap_ulong
2073 #elif XXH_GCC_VERSION >= 403
2074 # define XXH_swap32 __builtin_bswap32
2076 static xxh_u32 XXH_swap32 (xxh_u32
x)
2078 return ((x << 24) & 0xff000000 ) |
2079 ((x << 8) & 0x00ff0000 ) |
2080 ((x >> 8) & 0x0000ff00 ) |
2081 ((x >> 24) & 0x000000ff );
2104 #if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
2106 XXH_FORCE_INLINE xxh_u32 XXH_readLE32(
const void* memPtr)
2108 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
2110 | ((xxh_u32)bytePtr[1] << 8)
2111 | ((xxh_u32)bytePtr[2] << 16)
2112 | ((xxh_u32)bytePtr[3] << 24);
2115 XXH_FORCE_INLINE xxh_u32 XXH_readBE32(
const void* memPtr)
2117 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
2119 | ((xxh_u32)bytePtr[2] << 8)
2120 | ((xxh_u32)bytePtr[1] << 16)
2121 | ((xxh_u32)bytePtr[0] << 24);
2125 XXH_FORCE_INLINE xxh_u32 XXH_readLE32(
const void* ptr)
2127 return XXH_CPU_LITTLE_ENDIAN ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
2130 static xxh_u32 XXH_readBE32(
const void* ptr)
2132 return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr);
2136 XXH_FORCE_INLINE xxh_u32
2137 XXH_readLE32_align(
const void* ptr, XXH_alignment align)
2139 if (align==XXH_unaligned) {
2140 return XXH_readLE32(ptr);
2142 return XXH_CPU_LITTLE_ENDIAN ? *(
const xxh_u32*)ptr : XXH_swap32(*(
const xxh_u32*)ptr);
2166 #define XXH_PRIME32_1 0x9E3779B1U
2167 #define XXH_PRIME32_2 0x85EBCA77U
2168 #define XXH_PRIME32_3 0xC2B2AE3DU
2169 #define XXH_PRIME32_4 0x27D4EB2FU
2170 #define XXH_PRIME32_5 0x165667B1U
2172 #ifdef XXH_OLD_NAMES
2173 # define PRIME32_1 XXH_PRIME32_1
2174 # define PRIME32_2 XXH_PRIME32_2
2175 # define PRIME32_3 XXH_PRIME32_3
2176 # define PRIME32_4 XXH_PRIME32_4
2177 # define PRIME32_5 XXH_PRIME32_5
2191 static xxh_u32 XXH32_round(xxh_u32 acc, xxh_u32 input)
2193 acc += input * XXH_PRIME32_2;
2194 acc = XXH_rotl32(acc, 13);
2195 acc *= XXH_PRIME32_1;
2196 #if (defined(__SSE4_1__) || defined(__aarch64__)) && !defined(XXH_ENABLE_AUTOVECTORIZE)
2230 XXH_COMPILER_GUARD(acc);
2245 static xxh_u32 XXH32_avalanche(xxh_u32 hash)
2248 hash *= XXH_PRIME32_2;
2250 hash *= XXH_PRIME32_3;
2255 #define XXH_get32bits(p) XXH_readLE32_align(p, align)
2273 XXH32_finalize(xxh_u32 hash,
const xxh_u8* ptr,
size_t len, XXH_alignment align)
2275 #define XXH_PROCESS1 do { \
2276 hash += (*ptr++) * XXH_PRIME32_5; \
2277 hash = XXH_rotl32(hash, 11) * XXH_PRIME32_1; \
2280 #define XXH_PROCESS4 do { \
2281 hash += XXH_get32bits(ptr) * XXH_PRIME32_3; \
2283 hash = XXH_rotl32(hash, 17) * XXH_PRIME32_4; \
2286 if (ptr==NULL) XXH_ASSERT(len == 0);
2289 if (!XXH32_ENDJMP) {
2299 return XXH32_avalanche(hash);
2302 case 12: XXH_PROCESS4;
2304 case 8: XXH_PROCESS4;
2306 case 4: XXH_PROCESS4;
2307 return XXH32_avalanche(hash);
2309 case 13: XXH_PROCESS4;
2311 case 9: XXH_PROCESS4;
2313 case 5: XXH_PROCESS4;
2315 return XXH32_avalanche(hash);
2317 case 14: XXH_PROCESS4;
2319 case 10: XXH_PROCESS4;
2321 case 6: XXH_PROCESS4;
2324 return XXH32_avalanche(hash);
2326 case 15: XXH_PROCESS4;
2328 case 11: XXH_PROCESS4;
2330 case 7: XXH_PROCESS4;
2332 case 3: XXH_PROCESS1;
2334 case 2: XXH_PROCESS1;
2336 case 1: XXH_PROCESS1;
2338 case 0:
return XXH32_avalanche(hash);
2345 #ifdef XXH_OLD_NAMES
2346 # define PROCESS1 XXH_PROCESS1
2347 # define PROCESS4 XXH_PROCESS4
2349 # undef XXH_PROCESS1
2350 # undef XXH_PROCESS4
2362 XXH32_endian_align(
const xxh_u8* input,
size_t len, xxh_u32 seed, XXH_alignment align)
2366 if (input==NULL) XXH_ASSERT(len == 0);
2369 const xxh_u8*
const bEnd = input + len;
2370 const xxh_u8*
const limit = bEnd - 15;
2371 xxh_u32
v1 = seed + XXH_PRIME32_1 + XXH_PRIME32_2;
2372 xxh_u32
v2 = seed + XXH_PRIME32_2;
2373 xxh_u32
v3 = seed + 0;
2374 xxh_u32 v4 = seed - XXH_PRIME32_1;
2377 v1 = XXH32_round(v1, XXH_get32bits(input)); input += 4;
2378 v2 = XXH32_round(v2, XXH_get32bits(input)); input += 4;
2379 v3 = XXH32_round(v3, XXH_get32bits(input)); input += 4;
2380 v4 = XXH32_round(v4, XXH_get32bits(input)); input += 4;
2381 }
while (input < limit);
2383 h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7)
2384 + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
2386 h32 = seed + XXH_PRIME32_5;
2389 h32 += (xxh_u32)len;
2391 return XXH32_finalize(h32, input, len&15, align);
2397 #if !defined(XXH_NO_STREAM) && XXH_SIZE_OPT >= 2
2404 if (XXH_FORCE_ALIGN_CHECK) {
2405 if ((((
size_t)input) & 3) == 0) {
2406 return XXH32_endian_align((
const xxh_u8*)input, len, seed, XXH_aligned);
2409 return XXH32_endian_align((
const xxh_u8*)input, len, seed, XXH_unaligned);
2416 #ifndef XXH_NO_STREAM
2432 XXH_memcpy(dstState, srcState,
sizeof(*dstState));
2438 XXH_ASSERT(statePtr != NULL);
2439 memset(statePtr, 0,
sizeof(*statePtr));
2440 statePtr->v[0] = seed + XXH_PRIME32_1 + XXH_PRIME32_2;
2441 statePtr->v[1] = seed + XXH_PRIME32_2;
2442 statePtr->v[2] = seed + 0;
2443 statePtr->v[3] = seed - XXH_PRIME32_1;
2453 XXH_ASSERT(len == 0);
2457 {
const xxh_u8* p = (
const xxh_u8*)input;
2458 const xxh_u8*
const bEnd = p + len;
2460 state->total_len_32 += (XXH32_hash_t)len;
2461 state->large_len |= (XXH32_hash_t)((len>=16) | (state->total_len_32>=16));
2463 if (state->memsize + len < 16) {
2464 XXH_memcpy((xxh_u8*)(state->mem32) + state->memsize, input, len);
2465 state->memsize += (XXH32_hash_t)len;
2469 if (state->memsize) {
2470 XXH_memcpy((xxh_u8*)(state->mem32) + state->memsize, input, 16-state->memsize);
2471 {
const xxh_u32* p32 = state->mem32;
2472 state->v[0] = XXH32_round(state->v[0], XXH_readLE32(p32)); p32++;
2473 state->v[1] = XXH32_round(state->v[1], XXH_readLE32(p32)); p32++;
2474 state->v[2] = XXH32_round(state->v[2], XXH_readLE32(p32)); p32++;
2475 state->v[3] = XXH32_round(state->v[3], XXH_readLE32(p32));
2477 p += 16-state->memsize;
2482 const xxh_u8*
const limit = bEnd - 16;
2485 state->v[0] = XXH32_round(state->v[0], XXH_readLE32(p)); p+=4;
2486 state->v[1] = XXH32_round(state->v[1], XXH_readLE32(p)); p+=4;
2487 state->v[2] = XXH32_round(state->v[2], XXH_readLE32(p)); p+=4;
2488 state->v[3] = XXH32_round(state->v[3], XXH_readLE32(p)); p+=4;
2494 XXH_memcpy(state->mem32, p, (
size_t)(bEnd-p));
2495 state->memsize = (unsigned)(bEnd-p);
2508 if (state->large_len) {
2509 h32 = XXH_rotl32(state->v[0], 1)
2510 + XXH_rotl32(state->v[1], 7)
2511 + XXH_rotl32(state->v[2], 12)
2512 + XXH_rotl32(state->v[3], 18);
2514 h32 = state->v[2] + XXH_PRIME32_5;
2517 h32 += state->total_len_32;
2519 return XXH32_finalize(h32, (
const xxh_u8*)state->mem32, state->memsize, XXH_aligned);
2542 if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
2543 XXH_memcpy(dst, &hash,
sizeof(*dst));
2548 return XXH_readBE32(src);
2552 #ifndef XXH_NO_LONG_LONG
2564 typedef XXH64_hash_t xxh_u64;
2566 #ifdef XXH_OLD_NAMES
2567 # define U64 xxh_u64
2570 #if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
2575 #elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
2578 static xxh_u64 XXH_read64(
const void* memPtr)
2580 return *(
const xxh_u64*) memPtr;
2583 #elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
2592 #ifdef XXH_OLD_NAMES
2595 static xxh_u64 XXH_read64(
const void* ptr)
2598 return *((const xxh_unalign64*)ptr);
2607 static xxh_u64 XXH_read64(
const void* memPtr)
2610 XXH_memcpy(&val, memPtr,
sizeof(val));
2616 #if defined(_MSC_VER)
2617 # define XXH_swap64 _byteswap_uint64
2618 #elif XXH_GCC_VERSION >= 403
2619 # define XXH_swap64 __builtin_bswap64
2621 static xxh_u64 XXH_swap64(xxh_u64 x)
2623 return ((x << 56) & 0xff00000000000000ULL) |
2624 ((x << 40) & 0x00ff000000000000ULL) |
2625 ((x << 24) & 0x0000ff0000000000ULL) |
2626 ((x << 8) & 0x000000ff00000000ULL) |
2627 ((x >> 8) & 0x00000000ff000000ULL) |
2628 ((x >> 24) & 0x0000000000ff0000ULL) |
2629 ((x >> 40) & 0x000000000000ff00ULL) |
2630 ((x >> 56) & 0x00000000000000ffULL);
2636 #if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
2638 XXH_FORCE_INLINE xxh_u64 XXH_readLE64(
const void* memPtr)
2640 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
2642 | ((xxh_u64)bytePtr[1] << 8)
2643 | ((xxh_u64)bytePtr[2] << 16)
2644 | ((xxh_u64)bytePtr[3] << 24)
2645 | ((xxh_u64)bytePtr[4] << 32)
2646 | ((xxh_u64)bytePtr[5] << 40)
2647 | ((xxh_u64)bytePtr[6] << 48)
2648 | ((xxh_u64)bytePtr[7] << 56);
2651 XXH_FORCE_INLINE xxh_u64 XXH_readBE64(
const void* memPtr)
2653 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
2655 | ((xxh_u64)bytePtr[6] << 8)
2656 | ((xxh_u64)bytePtr[5] << 16)
2657 | ((xxh_u64)bytePtr[4] << 24)
2658 | ((xxh_u64)bytePtr[3] << 32)
2659 | ((xxh_u64)bytePtr[2] << 40)
2660 | ((xxh_u64)bytePtr[1] << 48)
2661 | ((xxh_u64)bytePtr[0] << 56);
2665 XXH_FORCE_INLINE xxh_u64 XXH_readLE64(
const void* ptr)
2667 return XXH_CPU_LITTLE_ENDIAN ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
2670 static xxh_u64 XXH_readBE64(
const void* ptr)
2672 return XXH_CPU_LITTLE_ENDIAN ? XXH_swap64(XXH_read64(ptr)) : XXH_read64(ptr);
2676 XXH_FORCE_INLINE xxh_u64
2677 XXH_readLE64_align(
const void* ptr, XXH_alignment align)
2679 if (align==XXH_unaligned)
2680 return XXH_readLE64(ptr);
2682 return XXH_CPU_LITTLE_ENDIAN ? *(
const xxh_u64*)ptr : XXH_swap64(*(
const xxh_u64*)ptr);
2696 #define XXH_PRIME64_1 0x9E3779B185EBCA87ULL
2697 #define XXH_PRIME64_2 0xC2B2AE3D27D4EB4FULL
2698 #define XXH_PRIME64_3 0x165667B19E3779F9ULL
2699 #define XXH_PRIME64_4 0x85EBCA77C2B2AE63ULL
2700 #define XXH_PRIME64_5 0x27D4EB2F165667C5ULL
2702 #ifdef XXH_OLD_NAMES
2703 # define PRIME64_1 XXH_PRIME64_1
2704 # define PRIME64_2 XXH_PRIME64_2
2705 # define PRIME64_3 XXH_PRIME64_3
2706 # define PRIME64_4 XXH_PRIME64_4
2707 # define PRIME64_5 XXH_PRIME64_5
2711 static xxh_u64 XXH64_round(xxh_u64 acc, xxh_u64 input)
2713 acc += input * XXH_PRIME64_2;
2714 acc = XXH_rotl64(acc, 31);
2715 acc *= XXH_PRIME64_1;
2719 static xxh_u64 XXH64_mergeRound(xxh_u64 acc, xxh_u64 val)
2721 val = XXH64_round(0, val);
2723 acc = acc * XXH_PRIME64_1 + XXH_PRIME64_4;
2728 static xxh_u64 XXH64_avalanche(xxh_u64 hash)
2731 hash *= XXH_PRIME64_2;
2733 hash *= XXH_PRIME64_3;
2739 #define XXH_get64bits(p) XXH_readLE64_align(p, align)
2757 XXH64_finalize(xxh_u64 hash,
const xxh_u8* ptr,
size_t len, XXH_alignment align)
2759 if (ptr==NULL) XXH_ASSERT(len == 0);
2762 xxh_u64
const k1 = XXH64_round(0, XXH_get64bits(ptr));
2765 hash = XXH_rotl64(hash,27) * XXH_PRIME64_1 + XXH_PRIME64_4;
2769 hash ^= (xxh_u64)(XXH_get32bits(ptr)) * XXH_PRIME64_1;
2771 hash = XXH_rotl64(hash, 23) * XXH_PRIME64_2 + XXH_PRIME64_3;
2775 hash ^= (*ptr++) * XXH_PRIME64_5;
2776 hash = XXH_rotl64(hash, 11) * XXH_PRIME64_1;
2779 return XXH64_avalanche(hash);
2782 #ifdef XXH_OLD_NAMES
2783 # define PROCESS1_64 XXH_PROCESS1_64
2784 # define PROCESS4_64 XXH_PROCESS4_64
2785 # define PROCESS8_64 XXH_PROCESS8_64
2787 # undef XXH_PROCESS1_64
2788 # undef XXH_PROCESS4_64
2789 # undef XXH_PROCESS8_64
2801 XXH64_endian_align(
const xxh_u8* input,
size_t len, xxh_u64 seed, XXH_alignment align)
2804 if (input==NULL) XXH_ASSERT(len == 0);
2807 const xxh_u8*
const bEnd = input + len;
2808 const xxh_u8*
const limit = bEnd - 31;
2809 xxh_u64 v1 = seed + XXH_PRIME64_1 + XXH_PRIME64_2;
2810 xxh_u64 v2 = seed + XXH_PRIME64_2;
2811 xxh_u64 v3 = seed + 0;
2812 xxh_u64 v4 = seed - XXH_PRIME64_1;
2815 v1 = XXH64_round(v1, XXH_get64bits(input)); input+=8;
2816 v2 = XXH64_round(v2, XXH_get64bits(input)); input+=8;
2817 v3 = XXH64_round(v3, XXH_get64bits(input)); input+=8;
2818 v4 = XXH64_round(v4, XXH_get64bits(input)); input+=8;
2819 }
while (input<limit);
2821 h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
2822 h64 = XXH64_mergeRound(h64, v1);
2823 h64 = XXH64_mergeRound(h64, v2);
2824 h64 = XXH64_mergeRound(h64, v3);
2825 h64 = XXH64_mergeRound(h64, v4);
2828 h64 = seed + XXH_PRIME64_5;
2831 h64 += (xxh_u64) len;
2833 return XXH64_finalize(h64, input, len, align);
2840 #if !defined(XXH_NO_STREAM) && XXH_SIZE_OPT >= 2
2847 if (XXH_FORCE_ALIGN_CHECK) {
2848 if ((((
size_t)input) & 7)==0) {
2849 return XXH64_endian_align((
const xxh_u8*)input, len, seed, XXH_aligned);
2852 return XXH64_endian_align((
const xxh_u8*)input, len, seed, XXH_unaligned);
2858 #ifndef XXH_NO_STREAM
2874 XXH_memcpy(dstState, srcState,
sizeof(*dstState));
2880 XXH_ASSERT(statePtr != NULL);
2881 memset(statePtr, 0,
sizeof(*statePtr));
2882 statePtr->v[0] = seed + XXH_PRIME64_1 + XXH_PRIME64_2;
2883 statePtr->v[1] = seed + XXH_PRIME64_2;
2884 statePtr->v[2] = seed + 0;
2885 statePtr->v[3] = seed - XXH_PRIME64_1;
2894 XXH_ASSERT(len == 0);
2898 {
const xxh_u8* p = (
const xxh_u8*)input;
2899 const xxh_u8*
const bEnd = p + len;
2901 state->total_len += len;
2903 if (state->memsize + len < 32) {
2904 XXH_memcpy(((xxh_u8*)state->mem64) + state->memsize, input, len);
2905 state->memsize += (xxh_u32)len;
2909 if (state->memsize) {
2910 XXH_memcpy(((xxh_u8*)state->mem64) + state->memsize, input, 32-state->memsize);
2911 state->v[0] = XXH64_round(state->v[0], XXH_readLE64(state->mem64+0));
2912 state->v[1] = XXH64_round(state->v[1], XXH_readLE64(state->mem64+1));
2913 state->v[2] = XXH64_round(state->v[2], XXH_readLE64(state->mem64+2));
2914 state->v[3] = XXH64_round(state->v[3], XXH_readLE64(state->mem64+3));
2915 p += 32 - state->memsize;
2920 const xxh_u8*
const limit = bEnd - 32;
2923 state->v[0] = XXH64_round(state->v[0], XXH_readLE64(p)); p+=8;
2924 state->v[1] = XXH64_round(state->v[1], XXH_readLE64(p)); p+=8;
2925 state->v[2] = XXH64_round(state->v[2], XXH_readLE64(p)); p+=8;
2926 state->v[3] = XXH64_round(state->v[3], XXH_readLE64(p)); p+=8;
2932 XXH_memcpy(state->mem64, p, (
size_t)(bEnd-p));
2933 state->memsize = (unsigned)(bEnd-p);
2946 if (state->total_len >= 32) {
2947 h64 = XXH_rotl64(state->v[0], 1) + XXH_rotl64(state->v[1], 7) + XXH_rotl64(state->v[2], 12) + XXH_rotl64(state->v[3], 18);
2948 h64 = XXH64_mergeRound(h64, state->v[0]);
2949 h64 = XXH64_mergeRound(h64, state->v[1]);
2950 h64 = XXH64_mergeRound(h64, state->v[2]);
2951 h64 = XXH64_mergeRound(h64, state->v[3]);
2953 h64 = state->v[2] + XXH_PRIME64_5;
2956 h64 += (xxh_u64) state->total_len;
2958 return XXH64_finalize(h64, (
const xxh_u8*)state->mem64, (size_t)state->total_len, XXH_aligned);
2968 if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
2969 XXH_memcpy(dst, &hash,
sizeof(*dst));
2975 return XXH_readBE64(src);
2993 #if ((defined(sun) || defined(__sun)) && __cplusplus)
2994 # define XXH_RESTRICT
2995 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
2996 # define XXH_RESTRICT restrict
2999 # define XXH_RESTRICT
3002 #if (defined(__GNUC__) && (__GNUC__ >= 3)) \
3003 || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) \
3004 || defined(__clang__)
3005 # define XXH_likely(x) __builtin_expect(x, 1)
3006 # define XXH_unlikely(x) __builtin_expect(x, 0)
3008 # define XXH_likely(x) (x)
3009 # define XXH_unlikely(x) (x)
3012 #if defined(__GNUC__) || defined(__clang__)
3013 # if defined(__ARM_FEATURE_SVE)
3014 # include <arm_sve.h>
3015 # elif defined(__ARM_NEON__) || defined(__ARM_NEON) \
3016 || defined(__aarch64__) || defined(_M_ARM) \
3017 || defined(_M_ARM64) || defined(_M_ARM64EC)
3018 # define inline __inline__
3019 # include <arm_neon.h>
3021 # elif defined(__AVX2__)
3022 # include <immintrin.h>
3023 # elif defined(__SSE2__)
3024 # include <emmintrin.h>
3028 #if defined(_MSC_VER)
3029 # include <intrin.h>
3101 #if defined(__thumb__) && !defined(__thumb2__) && defined(__ARM_ARCH_ISA_ARM)
3102 # warning "XXH3 is highly inefficient without ARM or Thumb-2."
3120 # define XXH_VECTOR XXH_SCALAR
3130 enum XXH_VECTOR_TYPE {
3153 # define XXH_ACC_ALIGN 8
3158 # define XXH_SCALAR 0
3161 # define XXH_AVX512 3
3168 # if defined(__ARM_FEATURE_SVE)
3169 # define XXH_VECTOR XXH_SVE
3171 defined(__ARM_NEON__) || defined(__ARM_NEON) \
3172 || defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC) \
3174 defined(_WIN32) || defined(__LITTLE_ENDIAN__) \
3175 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) \
3177 # define XXH_VECTOR XXH_NEON
3178 # elif defined(__AVX512F__)
3179 # define XXH_VECTOR XXH_AVX512
3180 # elif defined(__AVX2__)
3181 # define XXH_VECTOR XXH_AVX2
3182 # elif defined(__SSE2__) || defined(_M_AMD64) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP == 2))
3183 # define XXH_VECTOR XXH_SSE2
3184 # elif (defined(__PPC64__) && defined(__POWER8_VECTOR__)) \
3185 || (defined(__s390x__) && defined(__VEC__)) \
3186 && defined(__GNUC__)
3187 # define XXH_VECTOR XXH_VSX
3189 # define XXH_VECTOR XXH_SCALAR
3194 #if (XXH_VECTOR == XXH_SVE) && !defined(__ARM_FEATURE_SVE)
3196 # pragma warning(once : 4606)
3198 # warning "__ARM_FEATURE_SVE isn't supported. Use SCALAR instead."
3201 # define XXH_VECTOR XXH_SCALAR
3208 #ifndef XXH_ACC_ALIGN
3209 # if defined(XXH_X86DISPATCH)
3210 # define XXH_ACC_ALIGN 64
3211 # elif XXH_VECTOR == XXH_SCALAR
3212 # define XXH_ACC_ALIGN 8
3213 # elif XXH_VECTOR == XXH_SSE2
3214 # define XXH_ACC_ALIGN 16
3215 # elif XXH_VECTOR == XXH_AVX2
3216 # define XXH_ACC_ALIGN 32
3217 # elif XXH_VECTOR == XXH_NEON
3218 # define XXH_ACC_ALIGN 16
3219 # elif XXH_VECTOR == XXH_VSX
3220 # define XXH_ACC_ALIGN 16
3221 # elif XXH_VECTOR == XXH_AVX512
3222 # define XXH_ACC_ALIGN 64
3223 # elif XXH_VECTOR == XXH_SVE
3224 # define XXH_ACC_ALIGN 64
3228 #if defined(XXH_X86DISPATCH) || XXH_VECTOR == XXH_SSE2 \
3229 || XXH_VECTOR == XXH_AVX2 || XXH_VECTOR == XXH_AVX512
3230 # define XXH_SEC_ALIGN XXH_ACC_ALIGN
3231 #elif XXH_VECTOR == XXH_SVE
3232 # define XXH_SEC_ALIGN XXH_ACC_ALIGN
3234 # define XXH_SEC_ALIGN 8
3258 #if XXH_VECTOR == XXH_AVX2 \
3259 && defined(__GNUC__) && !defined(__clang__) \
3260 && defined(__OPTIMIZE__) && XXH_SIZE_OPT <= 0
3261 # pragma GCC push_options
3262 # pragma GCC optimize("-O2")
3266 #if XXH_VECTOR == XXH_NEON
3347 # if !defined(XXH_NO_VZIP_HACK) \
3348 && (defined(__GNUC__) || defined(__clang__)) \
3349 && (defined(__arm__) || defined(__thumb__) || defined(_M_ARM))
3350 # define XXH_SPLIT_IN_PLACE(in, outLo, outHi) \
3355 __asm__("vzip.32 %e0, %f0" : "+w" (in)); \
3356 (outLo) = vget_low_u32 (vreinterpretq_u32_u64(in)); \
3357 (outHi) = vget_high_u32(vreinterpretq_u32_u64(in)); \
3360 # define XXH_SPLIT_IN_PLACE(in, outLo, outHi) \
3362 (outLo) = vmovn_u64 (in); \
3363 (outHi) = vshrn_n_u64 ((in), 32); \
3380 #if defined(__aarch64__) && defined(__GNUC__) && !defined(__clang__)
3381 XXH_FORCE_INLINE uint64x2_t XXH_vld1q_u64(
void const* ptr)
3383 return *(uint64x2_t
const*)ptr;
3386 XXH_FORCE_INLINE uint64x2_t XXH_vld1q_u64(
void const* ptr)
3388 return vreinterpretq_u64_u8(vld1q_u8((uint8_t
const*)ptr));
3430 # ifndef XXH3_NEON_LANES
3431 # if (defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || defined(_M_ARM64EC)) \
3432 && !defined(__APPLE__) && XXH_SIZE_OPT <= 0
3433 # define XXH3_NEON_LANES 6
3435 # define XXH3_NEON_LANES XXH_ACC_NB
3448 #if XXH_VECTOR == XXH_VSX
3457 # pragma push_macro("bool")
3458 # pragma push_macro("vector")
3459 # pragma push_macro("pixel")
3465 # if defined(__s390x__)
3466 # include <s390intrin.h>
3468 # include <altivec.h>
3472 # pragma pop_macro("pixel")
3473 # pragma pop_macro("vector")
3474 # pragma pop_macro("bool")
3476 typedef __vector
unsigned long long xxh_u64x2;
3477 typedef __vector
unsigned char xxh_u8x16;
3478 typedef __vector
unsigned xxh_u32x4;
3481 # if defined(__BIG_ENDIAN__) \
3482 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
3483 # define XXH_VSX_BE 1
3484 # elif defined(__VEC_ELEMENT_REG_ORDER__) && __VEC_ELEMENT_REG_ORDER__ == __ORDER_BIG_ENDIAN__
3485 # warning "-maltivec=be is not recommended. Please use native endianness."
3486 # define XXH_VSX_BE 1
3488 # define XXH_VSX_BE 0
3493 # if defined(__POWER9_VECTOR__) || (defined(__clang__) && defined(__s390x__))
3494 # define XXH_vec_revb vec_revb
3499 XXH_FORCE_INLINE xxh_u64x2 XXH_vec_revb(xxh_u64x2 val)
3501 xxh_u8x16
const vByteSwap = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
3502 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08 };
3503 return vec_perm(val, val, vByteSwap);
3511 XXH_FORCE_INLINE xxh_u64x2 XXH_vec_loadu(
const void *ptr)
3514 XXH_memcpy(&ret, ptr,
sizeof(xxh_u64x2));
3516 ret = XXH_vec_revb(ret);
3527 # if defined(__s390x__)
3529 # define XXH_vec_mulo vec_mulo
3530 # define XXH_vec_mule vec_mule
3531 # elif defined(__clang__) && XXH_HAS_BUILTIN(__builtin_altivec_vmuleuw) && !defined(__ibmxl__)
3534 # define XXH_vec_mulo __builtin_altivec_vmulouw
3535 # define XXH_vec_mule __builtin_altivec_vmuleuw
3539 XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mulo(xxh_u32x4
a, xxh_u32x4
b)
3542 __asm__(
"vmulouw %0, %1, %2" :
"=v" (result) :
"v" (a),
"v" (b));
3545 XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mule(xxh_u32x4 a, xxh_u32x4 b)
3548 __asm__(
"vmuleuw %0, %1, %2" :
"=v" (result) :
"v" (a),
"v" (b));
3554 #if XXH_VECTOR == XXH_SVE
3555 #define ACCRND(acc, offset) \
3557 svuint64_t input_vec = svld1_u64(mask, xinput + offset); \
3558 svuint64_t secret_vec = svld1_u64(mask, xsecret + offset); \
3559 svuint64_t mixed = sveor_u64_x(mask, secret_vec, input_vec); \
3560 svuint64_t swapped = svtbl_u64(input_vec, kSwap); \
3561 svuint64_t mixed_lo = svextw_u64_x(mask, mixed); \
3562 svuint64_t mixed_hi = svlsr_n_u64_x(mask, mixed, 32); \
3563 svuint64_t mul = svmad_u64_x(mask, mixed_lo, mixed_hi, swapped); \
3564 acc = svadd_u64_x(mask, acc, mul); \
3571 #if defined(XXH_NO_PREFETCH)
3572 # define XXH_PREFETCH(ptr) (void)(ptr)
3574 # if XXH_SIZE_OPT >= 1
3575 # define XXH_PREFETCH(ptr) (void)(ptr)
3576 # elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
3577 # include <mmintrin.h>
3578 # define XXH_PREFETCH(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
3579 # elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
3580 # define XXH_PREFETCH(ptr) __builtin_prefetch((ptr), 0 , 3 )
3582 # define XXH_PREFETCH(ptr) (void)(ptr)
3591 #define XXH_SECRET_DEFAULT_SIZE 192
3593 #if (XXH_SECRET_DEFAULT_SIZE < XXH3_SECRET_SIZE_MIN)
3594 # error "default keyset is not large enough"
3598 XXH_ALIGN(64) static const xxh_u8 XXH3_kSecret[XXH_SECRET_DEFAULT_SIZE] = {
3599 0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c,
3600 0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f,
3601 0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21,
3602 0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c,
3603 0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3,
3604 0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8,
3605 0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d,
3606 0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64,
3607 0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb,
3608 0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e,
3609 0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce,
3610 0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e,
3614 #ifdef XXH_OLD_NAMES
3615 # define kSecret XXH3_kSecret
3635 XXH_FORCE_INLINE xxh_u64
3636 XXH_mult32to64(xxh_u64 x, xxh_u64
y)
3638 return (x & 0xFFFFFFFF) * (y & 0xFFFFFFFF);
3640 #elif defined(_MSC_VER) && defined(_M_IX86)
3641 # define XXH_mult32to64(x, y) __emulu((unsigned)(x), (unsigned)(y))
3650 # define XXH_mult32to64(x, y) ((xxh_u64)(xxh_u32)(x) * (xxh_u64)(xxh_u32)(y))
3663 XXH_mult64to128(xxh_u64 lhs, xxh_u64 rhs)
3680 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__wasm__) \
3681 && defined(__SIZEOF_INT128__) \
3682 || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
3684 __uint128_t
const product = (__uint128_t)lhs * (__uint128_t)rhs;
3686 r128.
low64 = (xxh_u64)(product);
3687 r128.
high64 = (xxh_u64)(product >> 64);
3697 #elif (defined(_M_X64) || defined(_M_IA64)) && !defined(_M_ARM64EC)
3700 # pragma intrinsic(_umul128)
3702 xxh_u64 product_high;
3703 xxh_u64
const product_low = _umul128(lhs, rhs, &product_high);
3705 r128.
low64 = product_low;
3706 r128.
high64 = product_high;
3714 #elif defined(_M_ARM64) || defined(_M_ARM64EC)
3717 # pragma intrinsic(__umulh)
3720 r128.
low64 = lhs * rhs;
3721 r128.
high64 = __umulh(lhs, rhs);
3769 xxh_u64
const lo_lo = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs & 0xFFFFFFFF);
3770 xxh_u64
const hi_lo = XXH_mult32to64(lhs >> 32, rhs & 0xFFFFFFFF);
3771 xxh_u64
const lo_hi = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs >> 32);
3772 xxh_u64
const hi_hi = XXH_mult32to64(lhs >> 32, rhs >> 32);
3775 xxh_u64
const cross = (lo_lo >> 32) + (hi_lo & 0xFFFFFFFF) + lo_hi;
3776 xxh_u64
const upper = (hi_lo >> 32) + (cross >> 32) + hi_hi;
3777 xxh_u64
const lower = (cross << 32) | (lo_lo & 0xFFFFFFFF);
3797 XXH3_mul128_fold64(xxh_u64 lhs, xxh_u64 rhs)
3804 XXH_FORCE_INLINE
XXH_CONSTF xxh_u64 XXH_xorshift64(xxh_u64 v64,
int shift)
3806 XXH_ASSERT(0 <= shift && shift < 64);
3807 return v64 ^ (v64 >> shift);
3814 static XXH64_hash_t XXH3_avalanche(xxh_u64 h64)
3816 h64 = XXH_xorshift64(h64, 37);
3817 h64 *= 0x165667919E3779F9ULL;
3818 h64 = XXH_xorshift64(h64, 32);
3827 static XXH64_hash_t XXH3_rrmxmx(xxh_u64 h64, xxh_u64 len)
3830 h64 ^= XXH_rotl64(h64, 49) ^ XXH_rotl64(h64, 24);
3831 h64 *= 0x9FB21C651E98DF25ULL;
3832 h64 ^= (h64 >> 35) + len ;
3833 h64 *= 0x9FB21C651E98DF25ULL;
3834 return XXH_xorshift64(h64, 28);
3872 XXH3_len_1to3_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret, XXH64_hash_t seed)
3874 XXH_ASSERT(input != NULL);
3875 XXH_ASSERT(1 <= len && len <= 3);
3876 XXH_ASSERT(secret != NULL);
3882 { xxh_u8
const c1 = input[0];
3883 xxh_u8
const c2 = input[len >> 1];
3884 xxh_u8
const c3 = input[len - 1];
3885 xxh_u32
const combined = ((xxh_u32)c1 << 16) | ((xxh_u32)c2 << 24)
3886 | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8);
3887 xxh_u64
const bitflip = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed;
3888 xxh_u64
const keyed = (xxh_u64)combined ^ bitflip;
3889 return XXH64_avalanche(keyed);
3894 XXH3_len_4to8_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret, XXH64_hash_t seed)
3896 XXH_ASSERT(input != NULL);
3897 XXH_ASSERT(secret != NULL);
3898 XXH_ASSERT(4 <= len && len <= 8);
3899 seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32;
3900 { xxh_u32
const input1 = XXH_readLE32(input);
3901 xxh_u32
const input2 = XXH_readLE32(input + len - 4);
3902 xxh_u64
const bitflip = (XXH_readLE64(secret+8) ^ XXH_readLE64(secret+16)) - seed;
3903 xxh_u64
const input64 = input2 + (((xxh_u64)input1) << 32);
3904 xxh_u64
const keyed = input64 ^ bitflip;
3905 return XXH3_rrmxmx(keyed, len);
3910 XXH3_len_9to16_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret, XXH64_hash_t seed)
3912 XXH_ASSERT(input != NULL);
3913 XXH_ASSERT(secret != NULL);
3914 XXH_ASSERT(9 <= len && len <= 16);
3915 { xxh_u64
const bitflip1 = (XXH_readLE64(secret+24) ^ XXH_readLE64(secret+32)) + seed;
3916 xxh_u64
const bitflip2 = (XXH_readLE64(secret+40) ^ XXH_readLE64(secret+48)) - seed;
3917 xxh_u64
const input_lo = XXH_readLE64(input) ^ bitflip1;
3918 xxh_u64
const input_hi = XXH_readLE64(input + len - 8) ^ bitflip2;
3919 xxh_u64
const acc = len
3920 + XXH_swap64(input_lo) + input_hi
3921 + XXH3_mul128_fold64(input_lo, input_hi);
3922 return XXH3_avalanche(acc);
3927 XXH3_len_0to16_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret, XXH64_hash_t seed)
3929 XXH_ASSERT(len <= 16);
3930 {
if (XXH_likely(len > 8))
return XXH3_len_9to16_64b(input, len, secret, seed);
3931 if (XXH_likely(len >= 4))
return XXH3_len_4to8_64b(input, len, secret, seed);
3932 if (len)
return XXH3_len_1to3_64b(input, len, secret, seed);
3933 return XXH64_avalanche(seed ^ (XXH_readLE64(secret+56) ^ XXH_readLE64(secret+64)));
3963 XXH_FORCE_INLINE xxh_u64 XXH3_mix16B(
const xxh_u8* XXH_RESTRICT input,
3964 const xxh_u8* XXH_RESTRICT secret, xxh_u64 seed64)
3966 #if defined(__GNUC__) && !defined(__clang__) \
3967 && defined(__i386__) && defined(__SSE2__) \
3968 && !defined(XXH_ENABLE_AUTOVECTORIZE)
3984 XXH_COMPILER_GUARD(seed64);
3986 { xxh_u64
const input_lo = XXH_readLE64(input);
3987 xxh_u64
const input_hi = XXH_readLE64(input+8);
3988 return XXH3_mul128_fold64(
3989 input_lo ^ (XXH_readLE64(secret) + seed64),
3990 input_hi ^ (XXH_readLE64(secret+8) - seed64)
3997 XXH3_len_17to128_64b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
3998 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
4002 XXH_ASSERT(16 < len && len <= 128);
4004 { xxh_u64 acc = len * XXH_PRIME64_1;
4005 #if XXH_SIZE_OPT >= 1
4007 size_t i = (len - 1) / 32;
4009 acc += XXH3_mix16B(input+16 * i, secret+32*i, seed);
4010 acc += XXH3_mix16B(input+len-16*(i+1), secret+32*i+16, seed);
4016 acc += XXH3_mix16B(input+48, secret+96, seed);
4017 acc += XXH3_mix16B(input+len-64, secret+112, seed);
4019 acc += XXH3_mix16B(input+32, secret+64, seed);
4020 acc += XXH3_mix16B(input+len-48, secret+80, seed);
4022 acc += XXH3_mix16B(input+16, secret+32, seed);
4023 acc += XXH3_mix16B(input+len-32, secret+48, seed);
4025 acc += XXH3_mix16B(input+0, secret+0, seed);
4026 acc += XXH3_mix16B(input+len-16, secret+16, seed);
4028 return XXH3_avalanche(acc);
4032 #define XXH3_MIDSIZE_MAX 240
4035 XXH3_len_129to240_64b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
4036 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
4040 XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX);
4042 #define XXH3_MIDSIZE_STARTOFFSET 3
4043 #define XXH3_MIDSIZE_LASTOFFSET 17
4045 { xxh_u64 acc = len * XXH_PRIME64_1;
4046 int const nbRounds = (
int)len / 16;
4048 for (i=0; i<8; i++) {
4049 acc += XXH3_mix16B(input+(16*i), secret+(16*i), seed);
4051 acc = XXH3_avalanche(acc);
4052 XXH_ASSERT(nbRounds >= 8);
4053 #if defined(__clang__) \
4054 && (defined(__ARM_NEON) || defined(__ARM_NEON__)) \
4055 && !defined(XXH_ENABLE_AUTOVECTORIZE)
4076 #pragma clang loop vectorize(disable)
4078 for (i=8 ; i < nbRounds; i++) {
4079 acc += XXH3_mix16B(input+(16*i), secret+(16*(i-8)) + XXH3_MIDSIZE_STARTOFFSET, seed);
4082 acc += XXH3_mix16B(input + len - 16, secret +
XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET, seed);
4083 return XXH3_avalanche(acc);
4090 #define XXH_STRIPE_LEN 64
4091 #define XXH_SECRET_CONSUME_RATE 8
4092 #define XXH_ACC_NB (XXH_STRIPE_LEN / sizeof(xxh_u64))
4094 #ifdef XXH_OLD_NAMES
4095 # define STRIPE_LEN XXH_STRIPE_LEN
4096 # define ACC_NB XXH_ACC_NB
4099 XXH_FORCE_INLINE
void XXH_writeLE64(
void* dst, xxh_u64 v64)
4101 if (!XXH_CPU_LITTLE_ENDIAN) v64 = XXH_swap64(v64);
4102 XXH_memcpy(dst, &v64,
sizeof(v64));
4110 #if !defined (__VMS) \
4111 && (defined (__cplusplus) \
4112 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
4113 typedef int64_t xxh_i64;
4116 typedef long long xxh_i64;
4143 #if (XXH_VECTOR == XXH_AVX512) \
4144 || (defined(XXH_DISPATCH_AVX512) && XXH_DISPATCH_AVX512 != 0)
4146 #ifndef XXH_TARGET_AVX512
4147 # define XXH_TARGET_AVX512
4150 XXH_FORCE_INLINE XXH_TARGET_AVX512
void
4151 XXH3_accumulate_512_avx512(
void* XXH_RESTRICT acc,
4152 const void* XXH_RESTRICT input,
4153 const void* XXH_RESTRICT secret)
4155 __m512i*
const xacc = (__m512i *) acc;
4156 XXH_ASSERT((((
size_t)acc) & 63) == 0);
4157 XXH_STATIC_ASSERT(XXH_STRIPE_LEN ==
sizeof(__m512i));
4161 __m512i
const data_vec = _mm512_loadu_si512 (input);
4163 __m512i
const key_vec = _mm512_loadu_si512 (secret);
4165 __m512i
const data_key = _mm512_xor_si512 (data_vec, key_vec);
4167 __m512i
const data_key_lo = _mm512_shuffle_epi32 (data_key, (_MM_PERM_ENUM)_MM_SHUFFLE(0, 3, 0, 1));
4169 __m512i
const product = _mm512_mul_epu32 (data_key, data_key_lo);
4171 __m512i
const data_swap = _mm512_shuffle_epi32(data_vec, (_MM_PERM_ENUM)_MM_SHUFFLE(1, 0, 3, 2));
4172 __m512i
const sum = _mm512_add_epi64(*xacc, data_swap);
4174 *xacc = _mm512_add_epi64(product, sum);
4199 XXH_FORCE_INLINE XXH_TARGET_AVX512
void
4200 XXH3_scrambleAcc_avx512(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
4202 XXH_ASSERT((((
size_t)acc) & 63) == 0);
4203 XXH_STATIC_ASSERT(XXH_STRIPE_LEN ==
sizeof(__m512i));
4204 { __m512i*
const xacc = (__m512i*) acc;
4205 const __m512i prime32 = _mm512_set1_epi32((
int)XXH_PRIME32_1);
4208 __m512i
const acc_vec = *xacc;
4209 __m512i
const shifted = _mm512_srli_epi64 (acc_vec, 47);
4210 __m512i
const data_vec = _mm512_xor_si512 (acc_vec, shifted);
4212 __m512i
const key_vec = _mm512_loadu_si512 (secret);
4213 __m512i
const data_key = _mm512_xor_si512 (data_vec, key_vec);
4216 __m512i
const data_key_hi = _mm512_shuffle_epi32 (data_key, (_MM_PERM_ENUM)_MM_SHUFFLE(0, 3, 0, 1));
4217 __m512i
const prod_lo = _mm512_mul_epu32 (data_key, prime32);
4218 __m512i
const prod_hi = _mm512_mul_epu32 (data_key_hi, prime32);
4219 *xacc = _mm512_add_epi64(prod_lo, _mm512_slli_epi64(prod_hi, 32));
4223 XXH_FORCE_INLINE XXH_TARGET_AVX512
void
4224 XXH3_initCustomSecret_avx512(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
4226 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 63) == 0);
4227 XXH_STATIC_ASSERT(XXH_SEC_ALIGN == 64);
4228 XXH_ASSERT(((
size_t)customSecret & 63) == 0);
4229 (
void)(&XXH_writeLE64);
4230 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE /
sizeof(__m512i);
4231 __m512i
const seed_pos = _mm512_set1_epi64(seed64);
4232 __m512i
const seed = _mm512_mask_sub_epi64(seed_pos, 0xAA, _mm512_set1_epi8(0), seed_pos);
4234 const __m512i*
const src = (
const __m512i*) ((
const void*) XXH3_kSecret);
4235 __m512i*
const dest = ( __m512i*) customSecret;
4237 XXH_ASSERT(((
size_t)src & 63) == 0);
4238 XXH_ASSERT(((
size_t)dest & 63) == 0);
4239 for (i=0; i < nbRounds; ++i) {
4240 dest[i] = _mm512_add_epi64(_mm512_load_si512(src + i), seed);
4246 #if (XXH_VECTOR == XXH_AVX2) \
4247 || (defined(XXH_DISPATCH_AVX2) && XXH_DISPATCH_AVX2 != 0)
4249 #ifndef XXH_TARGET_AVX2
4250 # define XXH_TARGET_AVX2
4253 XXH_FORCE_INLINE XXH_TARGET_AVX2
void
4254 XXH3_accumulate_512_avx2(
void* XXH_RESTRICT acc,
4255 const void* XXH_RESTRICT input,
4256 const void* XXH_RESTRICT secret)
4258 XXH_ASSERT((((
size_t)acc) & 31) == 0);
4259 { __m256i*
const xacc = (__m256i *) acc;
4262 const __m256i*
const xinput = (
const __m256i *) input;
4265 const __m256i*
const xsecret = (
const __m256i *) secret;
4268 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m256i); i++) {
4270 __m256i
const data_vec = _mm256_loadu_si256 (xinput+i);
4272 __m256i
const key_vec = _mm256_loadu_si256 (xsecret+i);
4274 __m256i
const data_key = _mm256_xor_si256 (data_vec, key_vec);
4276 __m256i
const data_key_lo = _mm256_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1));
4278 __m256i
const product = _mm256_mul_epu32 (data_key, data_key_lo);
4280 __m256i
const data_swap = _mm256_shuffle_epi32(data_vec, _MM_SHUFFLE(1, 0, 3, 2));
4281 __m256i
const sum = _mm256_add_epi64(xacc[i], data_swap);
4283 xacc[i] = _mm256_add_epi64(product, sum);
4287 XXH_FORCE_INLINE XXH_TARGET_AVX2
void
4288 XXH3_scrambleAcc_avx2(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
4290 XXH_ASSERT((((
size_t)acc) & 31) == 0);
4291 { __m256i*
const xacc = (__m256i*) acc;
4294 const __m256i*
const xsecret = (
const __m256i *) secret;
4295 const __m256i prime32 = _mm256_set1_epi32((
int)XXH_PRIME32_1);
4298 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m256i); i++) {
4300 __m256i
const acc_vec = xacc[i];
4301 __m256i
const shifted = _mm256_srli_epi64 (acc_vec, 47);
4302 __m256i
const data_vec = _mm256_xor_si256 (acc_vec, shifted);
4304 __m256i
const key_vec = _mm256_loadu_si256 (xsecret+i);
4305 __m256i
const data_key = _mm256_xor_si256 (data_vec, key_vec);
4308 __m256i
const data_key_hi = _mm256_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1));
4309 __m256i
const prod_lo = _mm256_mul_epu32 (data_key, prime32);
4310 __m256i
const prod_hi = _mm256_mul_epu32 (data_key_hi, prime32);
4311 xacc[i] = _mm256_add_epi64(prod_lo, _mm256_slli_epi64(prod_hi, 32));
4316 XXH_FORCE_INLINE XXH_TARGET_AVX2
void XXH3_initCustomSecret_avx2(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
4318 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 31) == 0);
4319 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE /
sizeof(__m256i)) == 6);
4320 XXH_STATIC_ASSERT(XXH_SEC_ALIGN <= 64);
4321 (
void)(&XXH_writeLE64);
4322 XXH_PREFETCH(customSecret);
4323 { __m256i
const seed = _mm256_set_epi64x((xxh_i64)(0U - seed64), (xxh_i64)seed64, (xxh_i64)(0U - seed64), (xxh_i64)seed64);
4325 const __m256i*
const src = (
const __m256i*) ((
const void*) XXH3_kSecret);
4326 __m256i* dest = ( __m256i*) customSecret;
4328 # if defined(__GNUC__) || defined(__clang__)
4334 XXH_COMPILER_GUARD(dest);
4336 XXH_ASSERT(((
size_t)src & 31) == 0);
4337 XXH_ASSERT(((
size_t)dest & 31) == 0);
4340 dest[0] = _mm256_add_epi64(_mm256_load_si256(src+0), seed);
4341 dest[1] = _mm256_add_epi64(_mm256_load_si256(src+1), seed);
4342 dest[2] = _mm256_add_epi64(_mm256_load_si256(src+2), seed);
4343 dest[3] = _mm256_add_epi64(_mm256_load_si256(src+3), seed);
4344 dest[4] = _mm256_add_epi64(_mm256_load_si256(src+4), seed);
4345 dest[5] = _mm256_add_epi64(_mm256_load_si256(src+5), seed);
4352 #if (XXH_VECTOR == XXH_SSE2) || defined(XXH_X86DISPATCH)
4354 #ifndef XXH_TARGET_SSE2
4355 # define XXH_TARGET_SSE2
4358 XXH_FORCE_INLINE XXH_TARGET_SSE2
void
4359 XXH3_accumulate_512_sse2(
void* XXH_RESTRICT acc,
4360 const void* XXH_RESTRICT input,
4361 const void* XXH_RESTRICT secret)
4364 XXH_ASSERT((((
size_t)acc) & 15) == 0);
4365 { __m128i*
const xacc = (__m128i *) acc;
4368 const __m128i*
const xinput = (
const __m128i *) input;
4371 const __m128i*
const xsecret = (
const __m128i *) secret;
4374 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m128i); i++) {
4376 __m128i
const data_vec = _mm_loadu_si128 (xinput+i);
4378 __m128i
const key_vec = _mm_loadu_si128 (xsecret+i);
4380 __m128i
const data_key = _mm_xor_si128 (data_vec, key_vec);
4382 __m128i
const data_key_lo = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1));
4384 __m128i
const product = _mm_mul_epu32 (data_key, data_key_lo);
4386 __m128i
const data_swap = _mm_shuffle_epi32(data_vec, _MM_SHUFFLE(1,0,3,2));
4387 __m128i
const sum = _mm_add_epi64(xacc[i], data_swap);
4389 xacc[i] = _mm_add_epi64(product, sum);
4393 XXH_FORCE_INLINE XXH_TARGET_SSE2
void
4394 XXH3_scrambleAcc_sse2(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
4396 XXH_ASSERT((((
size_t)acc) & 15) == 0);
4397 { __m128i*
const xacc = (__m128i*) acc;
4400 const __m128i*
const xsecret = (
const __m128i *) secret;
4401 const __m128i prime32 = _mm_set1_epi32((
int)XXH_PRIME32_1);
4404 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m128i); i++) {
4406 __m128i
const acc_vec = xacc[i];
4407 __m128i
const shifted = _mm_srli_epi64 (acc_vec, 47);
4408 __m128i
const data_vec = _mm_xor_si128 (acc_vec, shifted);
4410 __m128i
const key_vec = _mm_loadu_si128 (xsecret+i);
4411 __m128i
const data_key = _mm_xor_si128 (data_vec, key_vec);
4414 __m128i
const data_key_hi = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1));
4415 __m128i
const prod_lo = _mm_mul_epu32 (data_key, prime32);
4416 __m128i
const prod_hi = _mm_mul_epu32 (data_key_hi, prime32);
4417 xacc[i] = _mm_add_epi64(prod_lo, _mm_slli_epi64(prod_hi, 32));
4422 XXH_FORCE_INLINE XXH_TARGET_SSE2
void XXH3_initCustomSecret_sse2(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
4424 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0);
4425 (
void)(&XXH_writeLE64);
4426 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE /
sizeof(__m128i);
4428 # if defined(_MSC_VER) && defined(_M_IX86) && _MSC_VER < 1900
4430 XXH_ALIGN(16) const xxh_i64 seed64x2[2] = { (xxh_i64)seed64, (xxh_i64)(0U - seed64) };
4431 __m128i
const seed = _mm_load_si128((__m128i
const*)seed64x2);
4433 __m128i
const seed = _mm_set_epi64x((xxh_i64)(0U - seed64), (xxh_i64)seed64);
4437 const void*
const src16 = XXH3_kSecret;
4438 __m128i* dst16 = (__m128i*) customSecret;
4439 # if defined(__GNUC__) || defined(__clang__)
4445 XXH_COMPILER_GUARD(dst16);
4447 XXH_ASSERT(((
size_t)src16 & 15) == 0);
4448 XXH_ASSERT(((
size_t)dst16 & 15) == 0);
4450 for (i=0; i < nbRounds; ++i) {
4451 dst16[i] = _mm_add_epi64(_mm_load_si128((
const __m128i *)src16+i), seed);
4457 #if (XXH_VECTOR == XXH_NEON)
4460 XXH_FORCE_INLINE
void
4461 XXH3_scalarRound(
void* XXH_RESTRICT acc,
void const* XXH_RESTRICT input,
4462 void const* XXH_RESTRICT secret,
size_t lane);
4464 XXH_FORCE_INLINE
void
4465 XXH3_scalarScrambleRound(
void* XXH_RESTRICT acc,
4466 void const* XXH_RESTRICT secret,
size_t lane);
4478 XXH_FORCE_INLINE
void
4479 XXH3_accumulate_512_neon(
void* XXH_RESTRICT acc,
4480 const void* XXH_RESTRICT input,
4481 const void* XXH_RESTRICT secret)
4483 XXH_ASSERT((((
size_t)acc) & 15) == 0);
4484 XXH_STATIC_ASSERT(XXH3_NEON_LANES > 0 && XXH3_NEON_LANES <= XXH_ACC_NB && XXH3_NEON_LANES % 2 == 0);
4486 uint64x2_t*
const xacc = (uint64x2_t *) acc;
4488 uint8_t
const*
const xinput = (
const uint8_t *) input;
4489 uint8_t
const*
const xsecret = (
const uint8_t *) secret;
4493 for (i = XXH3_NEON_LANES; i < XXH_ACC_NB; i++) {
4494 XXH3_scalarRound(acc, input, secret, i);
4497 for (; i+1 < XXH3_NEON_LANES / 2; i+=2) {
4498 uint64x2_t acc_vec1 = xacc[i];
4500 uint64x2_t data_vec1 = XXH_vld1q_u64(xinput + (i * 16));
4502 uint64x2_t key_vec1 = XXH_vld1q_u64(xsecret + (i * 16));
4504 uint64x2_t acc_vec_21 = vextq_u64(data_vec1, data_vec1, 1);
4506 uint64x2_t data_key1 = veorq_u64(data_vec1, key_vec1);
4508 uint64x2_t acc_vec2 = xacc[i+1];
4510 uint64x2_t data_vec2 = XXH_vld1q_u64(xinput + ((i+1) * 16));
4512 uint64x2_t key_vec2 = XXH_vld1q_u64(xsecret + ((i+1) * 16));
4514 uint64x2_t acc_vec_22 = vextq_u64(data_vec2, data_vec2, 1);
4516 uint64x2_t data_key2 = veorq_u64(data_vec2, key_vec2);
4521 uint32x4x2_t zipped = vuzpq_u32(vreinterpretq_u32_u64(data_key1), vreinterpretq_u32_u64(data_key2));
4522 uint32x4_t data_key_lo = zipped.val[0];
4523 uint32x4_t data_key_hi = zipped.val[1];
4526 acc_vec_21 = vmlal_u32 (acc_vec_21, vget_low_u32(data_key_lo), vget_low_u32(data_key_hi));
4527 XXH_COMPILER_GUARD_W(acc_vec_21);
4529 acc_vec1 = vaddq_u64 (acc_vec1, acc_vec_21);
4532 acc_vec_22 = vmlal_u32 (acc_vec_22, vget_high_u32(data_key_lo), vget_high_u32(data_key_hi));
4533 XXH_COMPILER_GUARD_W(acc_vec_22);
4535 acc_vec2 = vaddq_u64 (acc_vec2, acc_vec_22);
4536 xacc[i+1] = acc_vec2;
4538 for (; i < XXH3_NEON_LANES / 2; i++) {
4539 uint64x2_t acc_vec = xacc[i];
4541 uint64x2_t data_vec = XXH_vld1q_u64(xinput + (i * 16));
4543 uint64x2_t key_vec = XXH_vld1q_u64(xsecret + (i * 16));
4544 uint64x2_t data_key;
4545 uint32x2_t data_key_lo, data_key_hi;
4547 uint64x2_t acc_vec_2 = vextq_u64(data_vec, data_vec, 1);
4549 data_key = veorq_u64(data_vec, key_vec);
4553 XXH_SPLIT_IN_PLACE(data_key, data_key_lo, data_key_hi);
4555 acc_vec_2 = vmlal_u32 (acc_vec_2, data_key_lo, data_key_hi);
4556 XXH_COMPILER_GUARD_W(acc_vec_2);
4558 acc_vec = vaddq_u64 (acc_vec, acc_vec_2);
4565 XXH_FORCE_INLINE
void
4566 XXH3_scrambleAcc_neon(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
4568 XXH_ASSERT((((
size_t)acc) & 15) == 0);
4570 { uint64x2_t* xacc = (uint64x2_t*) acc;
4571 uint8_t
const* xsecret = (uint8_t
const*) secret;
4572 uint32x2_t prime = vdup_n_u32 (XXH_PRIME32_1);
4576 for (i = XXH3_NEON_LANES; i < XXH_ACC_NB; i++) {
4577 XXH3_scalarScrambleRound(acc, secret, i);
4579 for (i=0; i < XXH3_NEON_LANES / 2; i++) {
4581 uint64x2_t acc_vec = xacc[i];
4582 uint64x2_t shifted = vshrq_n_u64 (acc_vec, 47);
4583 uint64x2_t data_vec = veorq_u64 (acc_vec, shifted);
4586 uint64x2_t key_vec = XXH_vld1q_u64 (xsecret + (i * 16));
4587 uint64x2_t data_key = veorq_u64 (data_vec, key_vec);
4590 uint32x2_t data_key_lo, data_key_hi;
4594 XXH_SPLIT_IN_PLACE(data_key, data_key_lo, data_key_hi);
4613 uint64x2_t prod_hi = vmull_u32 (data_key_hi, prime);
4615 prod_hi = vshlq_n_u64(prod_hi, 32);
4617 xacc[i] = vmlal_u32(prod_hi, data_key_lo, prime);
4625 #if (XXH_VECTOR == XXH_VSX)
4627 XXH_FORCE_INLINE
void
4628 XXH3_accumulate_512_vsx(
void* XXH_RESTRICT acc,
4629 const void* XXH_RESTRICT input,
4630 const void* XXH_RESTRICT secret)
4633 unsigned int*
const xacc = (
unsigned int*) acc;
4634 xxh_u64x2
const*
const xinput = (xxh_u64x2
const*) input;
4635 xxh_u64x2
const*
const xsecret = (xxh_u64x2
const*) secret;
4636 xxh_u64x2
const v32 = { 32, 32 };
4638 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(xxh_u64x2); i++) {
4640 xxh_u64x2
const data_vec = XXH_vec_loadu(xinput + i);
4642 xxh_u64x2
const key_vec = XXH_vec_loadu(xsecret + i);
4643 xxh_u64x2
const data_key = data_vec ^ key_vec;
4645 xxh_u32x4
const shuffled = (xxh_u32x4)vec_rl(data_key, v32);
4647 xxh_u64x2
const product = XXH_vec_mulo((xxh_u32x4)data_key, shuffled);
4649 xxh_u64x2 acc_vec = (xxh_u64x2)vec_xl(0, xacc + 4 * i);
4654 acc_vec += vec_permi(data_vec, data_vec, 2);
4656 acc_vec += vec_xxpermdi(data_vec, data_vec, 2);
4659 vec_xst((xxh_u32x4)acc_vec, 0, xacc + 4 * i);
4663 XXH_FORCE_INLINE
void
4664 XXH3_scrambleAcc_vsx(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
4666 XXH_ASSERT((((
size_t)acc) & 15) == 0);
4668 { xxh_u64x2*
const xacc = (xxh_u64x2*) acc;
4669 const xxh_u64x2*
const xsecret = (
const xxh_u64x2*) secret;
4671 xxh_u64x2
const v32 = { 32, 32 };
4672 xxh_u64x2
const v47 = { 47, 47 };
4673 xxh_u32x4
const prime = { XXH_PRIME32_1, XXH_PRIME32_1, XXH_PRIME32_1, XXH_PRIME32_1 };
4675 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(xxh_u64x2); i++) {
4677 xxh_u64x2
const acc_vec = xacc[i];
4678 xxh_u64x2
const data_vec = acc_vec ^ (acc_vec >> v47);
4681 xxh_u64x2
const key_vec = XXH_vec_loadu(xsecret + i);
4682 xxh_u64x2
const data_key = data_vec ^ key_vec;
4686 xxh_u64x2
const prod_even = XXH_vec_mule((xxh_u32x4)data_key, prime);
4688 xxh_u64x2
const prod_odd = XXH_vec_mulo((xxh_u32x4)data_key, prime);
4689 xacc[i] = prod_odd + (prod_even << v32);
4695 #if (XXH_VECTOR == XXH_SVE)
4697 XXH_FORCE_INLINE
void
4698 XXH3_accumulate_512_sve(
void* XXH_RESTRICT acc,
4699 const void* XXH_RESTRICT input,
4700 const void* XXH_RESTRICT secret)
4702 uint64_t *xacc = (uint64_t *)acc;
4703 const uint64_t *xinput = (
const uint64_t *)(
const void *)input;
4704 const uint64_t *xsecret = (
const uint64_t *)(
const void *)secret;
4705 svuint64_t kSwap = sveor_n_u64_z(svptrue_b64(), svindex_u64(0, 1), 1);
4706 uint64_t element_count = svcntd();
4707 if (element_count >= 8) {
4708 svbool_t
mask = svptrue_pat_b64(SV_VL8);
4709 svuint64_t vacc = svld1_u64(mask, xacc);
4711 svst1_u64(mask, xacc, vacc);
4712 }
else if (element_count == 2) {
4713 svbool_t
mask = svptrue_pat_b64(SV_VL2);
4714 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
4715 svuint64_t acc1 = svld1_u64(mask, xacc + 2);
4716 svuint64_t acc2 = svld1_u64(mask, xacc + 4);
4717 svuint64_t acc3 = svld1_u64(mask, xacc + 6);
4722 svst1_u64(mask, xacc + 0, acc0);
4723 svst1_u64(mask, xacc + 2, acc1);
4724 svst1_u64(mask, xacc + 4, acc2);
4725 svst1_u64(mask, xacc + 6, acc3);
4727 svbool_t
mask = svptrue_pat_b64(SV_VL4);
4728 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
4729 svuint64_t acc1 = svld1_u64(mask, xacc + 4);
4732 svst1_u64(mask, xacc + 0, acc0);
4733 svst1_u64(mask, xacc + 4, acc1);
4748 XXH_FORCE_INLINE
void
4749 XXH3_scalarRound(
void* XXH_RESTRICT acc,
4750 void const* XXH_RESTRICT input,
4751 void const* XXH_RESTRICT secret,
4754 xxh_u64* xacc = (xxh_u64*) acc;
4755 xxh_u8
const* xinput = (xxh_u8
const*) input;
4756 xxh_u8
const* xsecret = (xxh_u8
const*) secret;
4757 XXH_ASSERT(lane < XXH_ACC_NB);
4758 XXH_ASSERT(((
size_t)acc & (XXH_ACC_ALIGN-1)) == 0);
4760 xxh_u64
const data_val = XXH_readLE64(xinput + lane * 8);
4761 xxh_u64
const data_key = data_val ^ XXH_readLE64(xsecret + lane * 8);
4762 xacc[lane ^ 1] += data_val;
4763 xacc[lane] += XXH_mult32to64(data_key & 0xFFFFFFFF, data_key >> 32);
4771 XXH_FORCE_INLINE
void
4772 XXH3_accumulate_512_scalar(
void* XXH_RESTRICT acc,
4773 const void* XXH_RESTRICT input,
4774 const void* XXH_RESTRICT secret)
4778 #if defined(__GNUC__) && !defined(__clang__) \
4779 && (defined(__arm__) || defined(__thumb2__)) \
4780 && defined(__ARM_FEATURE_UNALIGNED) \
4781 && XXH_SIZE_OPT <= 0
4782 # pragma GCC unroll 8
4784 for (i=0; i < XXH_ACC_NB; i++) {
4785 XXH3_scalarRound(acc, input, secret, i);
4796 XXH_FORCE_INLINE
void
4797 XXH3_scalarScrambleRound(
void* XXH_RESTRICT acc,
4798 void const* XXH_RESTRICT secret,
4801 xxh_u64*
const xacc = (xxh_u64*) acc;
4802 const xxh_u8*
const xsecret = (
const xxh_u8*) secret;
4803 XXH_ASSERT((((
size_t)acc) & (XXH_ACC_ALIGN-1)) == 0);
4804 XXH_ASSERT(lane < XXH_ACC_NB);
4806 xxh_u64
const key64 = XXH_readLE64(xsecret + lane * 8);
4807 xxh_u64 acc64 = xacc[lane];
4808 acc64 = XXH_xorshift64(acc64, 47);
4810 acc64 *= XXH_PRIME32_1;
4819 XXH_FORCE_INLINE
void
4820 XXH3_scrambleAcc_scalar(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
4823 for (i=0; i < XXH_ACC_NB; i++) {
4824 XXH3_scalarScrambleRound(acc, secret, i);
4828 XXH_FORCE_INLINE
void
4829 XXH3_initCustomSecret_scalar(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
4836 const xxh_u8* kSecretPtr = XXH3_kSecret;
4837 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0);
4839 #if defined(__clang__) && defined(__aarch64__)
4872 XXH_COMPILER_GUARD(kSecretPtr);
4878 XXH_ASSERT(kSecretPtr == XXH3_kSecret);
4880 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE / 16;
4882 for (i=0; i < nbRounds; i++) {
4889 xxh_u64 lo = XXH_readLE64(kSecretPtr + 16*i) + seed64;
4890 xxh_u64 hi = XXH_readLE64(kSecretPtr + 16*i + 8) - seed64;
4891 XXH_writeLE64((xxh_u8*)customSecret + 16*i, lo);
4892 XXH_writeLE64((xxh_u8*)customSecret + 16*i + 8, hi);
4897 typedef void (*XXH3_f_accumulate_512)(
void* XXH_RESTRICT,
const void*,
const void*);
4898 typedef void (*XXH3_f_scrambleAcc)(
void* XXH_RESTRICT,
const void*);
4899 typedef void (*XXH3_f_initCustomSecret)(
void* XXH_RESTRICT, xxh_u64);
4902 #if (XXH_VECTOR == XXH_AVX512)
4904 #define XXH3_accumulate_512 XXH3_accumulate_512_avx512
4905 #define XXH3_scrambleAcc XXH3_scrambleAcc_avx512
4906 #define XXH3_initCustomSecret XXH3_initCustomSecret_avx512
4908 #elif (XXH_VECTOR == XXH_AVX2)
4910 #define XXH3_accumulate_512 XXH3_accumulate_512_avx2
4911 #define XXH3_scrambleAcc XXH3_scrambleAcc_avx2
4912 #define XXH3_initCustomSecret XXH3_initCustomSecret_avx2
4914 #elif (XXH_VECTOR == XXH_SSE2)
4916 #define XXH3_accumulate_512 XXH3_accumulate_512_sse2
4917 #define XXH3_scrambleAcc XXH3_scrambleAcc_sse2
4918 #define XXH3_initCustomSecret XXH3_initCustomSecret_sse2
4920 #elif (XXH_VECTOR == XXH_NEON)
4922 #define XXH3_accumulate_512 XXH3_accumulate_512_neon
4923 #define XXH3_scrambleAcc XXH3_scrambleAcc_neon
4924 #define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
4926 #elif (XXH_VECTOR == XXH_VSX)
4928 #define XXH3_accumulate_512 XXH3_accumulate_512_vsx
4929 #define XXH3_scrambleAcc XXH3_scrambleAcc_vsx
4930 #define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
4932 #elif (XXH_VECTOR == XXH_SVE)
4933 #define XXH3_accumulate_512 XXH3_accumulate_512_sve
4934 #define XXH3_scrambleAcc XXH3_scrambleAcc_scalar
4935 #define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
4939 #define XXH3_accumulate_512 XXH3_accumulate_512_scalar
4940 #define XXH3_scrambleAcc XXH3_scrambleAcc_scalar
4941 #define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
4945 #if XXH_SIZE_OPT >= 1
4946 # undef XXH3_initCustomSecret
4947 # define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
4950 #ifndef XXH_PREFETCH_DIST
4952 # define XXH_PREFETCH_DIST 320
4954 # if (XXH_VECTOR == XXH_AVX512)
4955 # define XXH_PREFETCH_DIST 512
4957 # define XXH_PREFETCH_DIST 384
4967 XXH_FORCE_INLINE
void
4968 XXH3_accumulate( xxh_u64* XXH_RESTRICT acc,
4969 const xxh_u8* XXH_RESTRICT input,
4970 const xxh_u8* XXH_RESTRICT secret,
4972 XXH3_f_accumulate_512 f_acc512)
4975 for (n = 0; n < nbStripes; n++ ) {
4976 const xxh_u8*
const in = input + n*XXH_STRIPE_LEN;
4977 XXH_PREFETCH(in + XXH_PREFETCH_DIST);
4980 secret + n*XXH_SECRET_CONSUME_RATE);
4984 XXH_FORCE_INLINE
void
4985 XXH3_hashLong_internal_loop(xxh_u64* XXH_RESTRICT acc,
4986 const xxh_u8* XXH_RESTRICT input,
size_t len,
4987 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
4988 XXH3_f_accumulate_512 f_acc512,
4989 XXH3_f_scrambleAcc f_scramble)
4991 size_t const nbStripesPerBlock = (secretSize - XXH_STRIPE_LEN) / XXH_SECRET_CONSUME_RATE;
4992 size_t const block_len = XXH_STRIPE_LEN * nbStripesPerBlock;
4993 size_t const nb_blocks = (len - 1) / block_len;
4999 for (n = 0; n < nb_blocks; n++) {
5000 XXH3_accumulate(acc, input + n*block_len, secret, nbStripesPerBlock, f_acc512);
5001 f_scramble(acc, secret + secretSize - XXH_STRIPE_LEN);
5005 XXH_ASSERT(len > XXH_STRIPE_LEN);
5006 {
size_t const nbStripes = ((len - 1) - (block_len * nb_blocks)) / XXH_STRIPE_LEN;
5007 XXH_ASSERT(nbStripes <= (secretSize / XXH_SECRET_CONSUME_RATE));
5008 XXH3_accumulate(acc, input + nb_blocks*block_len, secret, nbStripes, f_acc512);
5011 {
const xxh_u8*
const p = input + len - XXH_STRIPE_LEN;
5012 #define XXH_SECRET_LASTACC_START 7
5013 f_acc512(acc, p, secret + secretSize - XXH_STRIPE_LEN - XXH_SECRET_LASTACC_START);
5017 XXH_FORCE_INLINE xxh_u64
5018 XXH3_mix2Accs(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret)
5020 return XXH3_mul128_fold64(
5021 acc[0] ^ XXH_readLE64(secret),
5022 acc[1] ^ XXH_readLE64(secret+8) );
5026 XXH3_mergeAccs(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret, xxh_u64
start)
5028 xxh_u64 result64 =
start;
5031 for (i = 0; i < 4; i++) {
5032 result64 += XXH3_mix2Accs(acc+2*i, secret + 16*i);
5033 #if defined(__clang__) \
5034 && (defined(__arm__) || defined(__thumb__)) \
5035 && (defined(__ARM_NEON) || defined(__ARM_NEON__)) \
5036 && !defined(XXH_ENABLE_AUTOVECTORIZE)
5045 XXH_COMPILER_GUARD(result64);
5049 return XXH3_avalanche(result64);
5052 #define XXH3_INIT_ACC { XXH_PRIME32_3, XXH_PRIME64_1, XXH_PRIME64_2, XXH_PRIME64_3, \
5053 XXH_PRIME64_4, XXH_PRIME32_2, XXH_PRIME64_5, XXH_PRIME32_1 }
5055 XXH_FORCE_INLINE XXH64_hash_t
5056 XXH3_hashLong_64b_internal(
const void* XXH_RESTRICT input,
size_t len,
5057 const void* XXH_RESTRICT secret,
size_t secretSize,
5058 XXH3_f_accumulate_512 f_acc512,
5059 XXH3_f_scrambleAcc f_scramble)
5061 XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[XXH_ACC_NB] = XXH3_INIT_ACC;
5063 XXH3_hashLong_internal_loop(acc, (const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, f_acc512, f_scramble);
5066 XXH_STATIC_ASSERT(sizeof(acc) == 64);
5068 #define XXH_SECRET_MERGEACCS_START 11
5069 XXH_ASSERT(secretSize >=
sizeof(acc) + XXH_SECRET_MERGEACCS_START);
5070 return XXH3_mergeAccs(acc, (
const xxh_u8*)secret + XXH_SECRET_MERGEACCS_START, (xxh_u64)len * XXH_PRIME64_1);
5078 XXH_FORCE_INLINE XXH64_hash_t
5079 XXH3_hashLong_64b_withSecret(
const void* XXH_RESTRICT input,
size_t len,
5080 XXH64_hash_t seed64,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
5083 return XXH3_hashLong_64b_internal(input, len, secret, secretLen, XXH3_accumulate_512, XXH3_scrambleAcc);
5093 XXH3_hashLong_64b_default(
const void* XXH_RESTRICT input,
size_t len,
5094 XXH64_hash_t seed64,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
5097 return XXH3_hashLong_64b_internal(input, len, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_accumulate_512, XXH3_scrambleAcc);
5111 XXH_FORCE_INLINE XXH64_hash_t
5112 XXH3_hashLong_64b_withSeed_internal(
const void* input,
size_t len,
5114 XXH3_f_accumulate_512 f_acc512,
5115 XXH3_f_scrambleAcc f_scramble,
5116 XXH3_f_initCustomSecret f_initSec)
5118 #if XXH_SIZE_OPT <= 0
5120 return XXH3_hashLong_64b_internal(input, len,
5121 XXH3_kSecret,
sizeof(XXH3_kSecret),
5122 f_acc512, f_scramble);
5124 { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
5125 f_initSec(secret, seed);
5126 return XXH3_hashLong_64b_internal(input, len, secret, sizeof(secret),
5127 f_acc512, f_scramble);
5134 XXH_NO_INLINE XXH64_hash_t
5135 XXH3_hashLong_64b_withSeed(const
void* XXH_RESTRICT input,
size_t len,
5136 XXH64_hash_t seed, const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
5139 return XXH3_hashLong_64b_withSeed_internal(input, len, seed,
5140 XXH3_accumulate_512, XXH3_scrambleAcc, XXH3_initCustomSecret);
5144 typedef XXH64_hash_t (*XXH3_hashLong64_f)(
const void* XXH_RESTRICT, size_t,
5147 XXH_FORCE_INLINE XXH64_hash_t
5148 XXH3_64bits_internal(
const void* XXH_RESTRICT input,
size_t len,
5149 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen,
5150 XXH3_hashLong64_f f_hashLong)
5161 return XXH3_len_0to16_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, seed64);
5163 return XXH3_len_17to128_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
5164 if (len <= XXH3_MIDSIZE_MAX)
5165 return XXH3_len_129to240_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
5166 return f_hashLong(input, len, seed64, (
const xxh_u8*)secret, secretLen);
5175 return XXH3_64bits_internal(input, length, 0, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_hashLong_64b_default);
5182 return XXH3_64bits_internal(input, length, 0, secret, secretSize, XXH3_hashLong_64b_withSecret);
5189 return XXH3_64bits_internal(input, length, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_hashLong_64b_withSeed);
5195 if (length <= XXH3_MIDSIZE_MAX)
5196 return XXH3_64bits_internal(input, length, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), NULL);
5197 return XXH3_hashLong_64b_withSecret(input, length, seed, (
const xxh_u8*)secret, secretSize);
5202 #ifndef XXH_NO_STREAM
5226 static XXH_MALLOCF void* XXH_alignedMalloc(
size_t s,
size_t align)
5228 XXH_ASSERT(align <= 128 && align >= 8);
5229 XXH_ASSERT((align & (align-1)) == 0);
5230 XXH_ASSERT(s != 0 && s < (s + align));
5232 xxh_u8* base = (xxh_u8*)XXH_malloc(s + align);
5240 size_t offset = align - ((size_t)base & (align - 1));
5242 xxh_u8* ptr = base +
offset;
5244 XXH_ASSERT((
size_t)ptr % align == 0);
5247 ptr[-1] = (xxh_u8)offset;
5257 static void XXH_alignedFree(
void* p)
5260 xxh_u8* ptr = (xxh_u8*)p;
5264 xxh_u8* base = ptr -
offset;
5272 if (state==NULL)
return NULL;
5273 XXH3_INITSTATE(state);
5280 XXH_alignedFree(statePtr);
5288 XXH_memcpy(dst_state, src_state,
sizeof(*dst_state));
5294 const void* secret,
size_t secretSize)
5296 size_t const initStart = offsetof(
XXH3_state_t, bufferedSize);
5297 size_t const initLength = offsetof(
XXH3_state_t, nbStripesPerBlock) - initStart;
5298 XXH_ASSERT(offsetof(
XXH3_state_t, nbStripesPerBlock) > initStart);
5299 XXH_ASSERT(statePtr != NULL);
5301 memset((
char*)statePtr + initStart, 0, initLength);
5302 statePtr->acc[0] = XXH_PRIME32_3;
5303 statePtr->acc[1] = XXH_PRIME64_1;
5304 statePtr->acc[2] = XXH_PRIME64_2;
5305 statePtr->acc[3] = XXH_PRIME64_3;
5306 statePtr->acc[4] = XXH_PRIME64_4;
5307 statePtr->acc[5] = XXH_PRIME32_2;
5308 statePtr->acc[6] = XXH_PRIME64_5;
5309 statePtr->acc[7] = XXH_PRIME32_1;
5310 statePtr->seed = seed;
5311 statePtr->useSeed = (seed != 0);
5312 statePtr->extSecret = (
const unsigned char*)secret;
5314 statePtr->secretLimit = secretSize - XXH_STRIPE_LEN;
5315 statePtr->nbStripesPerBlock = statePtr->secretLimit / XXH_SECRET_CONSUME_RATE;
5323 XXH3_reset_internal(statePtr, 0, XXH3_kSecret, XXH_SECRET_DEFAULT_SIZE);
5332 XXH3_reset_internal(statePtr, 0, secret, secretSize);
5344 if ((seed != statePtr->seed) || (statePtr->extSecret != NULL))
5345 XXH3_initCustomSecret(statePtr->customSecret, seed);
5346 XXH3_reset_internal(statePtr, seed, NULL, XXH_SECRET_DEFAULT_SIZE);
5357 XXH3_reset_internal(statePtr, seed64, secret, secretSize);
5358 statePtr->useSeed = 1;
5365 XXH_FORCE_INLINE
void
5366 XXH3_consumeStripes(xxh_u64* XXH_RESTRICT acc,
5367 size_t* XXH_RESTRICT nbStripesSoFarPtr,
size_t nbStripesPerBlock,
5368 const xxh_u8* XXH_RESTRICT input,
size_t nbStripes,
5369 const xxh_u8* XXH_RESTRICT secret,
size_t secretLimit,
5370 XXH3_f_accumulate_512 f_acc512,
5371 XXH3_f_scrambleAcc f_scramble)
5373 XXH_ASSERT(nbStripes <= nbStripesPerBlock);
5374 XXH_ASSERT(*nbStripesSoFarPtr < nbStripesPerBlock);
5375 if (nbStripesPerBlock - *nbStripesSoFarPtr <= nbStripes) {
5377 size_t const nbStripesToEndofBlock = nbStripesPerBlock - *nbStripesSoFarPtr;
5378 size_t const nbStripesAfterBlock = nbStripes - nbStripesToEndofBlock;
5379 XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripesToEndofBlock, f_acc512);
5380 f_scramble(acc, secret + secretLimit);
5381 XXH3_accumulate(acc, input + nbStripesToEndofBlock * XXH_STRIPE_LEN, secret, nbStripesAfterBlock, f_acc512);
5382 *nbStripesSoFarPtr = nbStripesAfterBlock;
5384 XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripes, f_acc512);
5385 *nbStripesSoFarPtr += nbStripes;
5389 #ifndef XXH3_STREAM_USE_STACK
5390 # if XXH_SIZE_OPT <= 0 && !defined(__clang__)
5391 # define XXH3_STREAM_USE_STACK 1
5399 const xxh_u8* XXH_RESTRICT input,
size_t len,
5400 XXH3_f_accumulate_512 f_acc512,
5401 XXH3_f_scrambleAcc f_scramble)
5404 XXH_ASSERT(len == 0);
5408 XXH_ASSERT(state != NULL);
5409 {
const xxh_u8*
const bEnd = input + len;
5410 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
5411 #
if defined(XXH3_STREAM_USE_STACK) && XXH3_STREAM_USE_STACK >= 1
5416 XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[8]; memcpy(acc, state->acc, sizeof(acc));
5418 xxh_u64* XXH_RESTRICT
const acc = state->acc;
5420 state->totalLen += len;
5421 XXH_ASSERT(state->bufferedSize <= XXH3_INTERNALBUFFER_SIZE);
5424 if (state->bufferedSize + len <= XXH3_INTERNALBUFFER_SIZE) {
5425 XXH_memcpy(state->buffer + state->bufferedSize, input, len);
5426 state->bufferedSize += (XXH32_hash_t)len;
5431 #define XXH3_INTERNALBUFFER_STRIPES (XXH3_INTERNALBUFFER_SIZE / XXH_STRIPE_LEN)
5432 XXH_STATIC_ASSERT(XXH3_INTERNALBUFFER_SIZE % XXH_STRIPE_LEN == 0);
5438 if (state->bufferedSize) {
5439 size_t const loadSize = XXH3_INTERNALBUFFER_SIZE - state->bufferedSize;
5440 XXH_memcpy(state->buffer + state->bufferedSize, input, loadSize);
5442 XXH3_consumeStripes(acc,
5443 &state->nbStripesSoFar, state->nbStripesPerBlock,
5444 state->buffer, XXH3_INTERNALBUFFER_STRIPES,
5445 secret, state->secretLimit,
5446 f_acc512, f_scramble);
5447 state->bufferedSize = 0;
5449 XXH_ASSERT(input < bEnd);
5452 if ((
size_t)(bEnd - input) > state->nbStripesPerBlock * XXH_STRIPE_LEN) {
5453 size_t nbStripes = (size_t)(bEnd - 1 - input) / XXH_STRIPE_LEN;
5454 XXH_ASSERT(state->nbStripesPerBlock >= state->nbStripesSoFar);
5456 {
size_t const nbStripesToEnd = state->nbStripesPerBlock - state->nbStripesSoFar;
5457 XXH_ASSERT(nbStripesToEnd <= nbStripes);
5458 XXH3_accumulate(acc, input, secret + state->nbStripesSoFar * XXH_SECRET_CONSUME_RATE, nbStripesToEnd, f_acc512);
5459 f_scramble(acc, secret + state->secretLimit);
5460 state->nbStripesSoFar = 0;
5461 input += nbStripesToEnd * XXH_STRIPE_LEN;
5462 nbStripes -= nbStripesToEnd;
5465 while(nbStripes >= state->nbStripesPerBlock) {
5466 XXH3_accumulate(acc, input, secret, state->nbStripesPerBlock, f_acc512);
5467 f_scramble(acc, secret + state->secretLimit);
5468 input += state->nbStripesPerBlock * XXH_STRIPE_LEN;
5469 nbStripes -= state->nbStripesPerBlock;
5472 XXH3_accumulate(acc, input, secret, nbStripes, f_acc512);
5473 input += nbStripes * XXH_STRIPE_LEN;
5474 XXH_ASSERT(input < bEnd);
5475 state->nbStripesSoFar = nbStripes;
5477 XXH_memcpy(state->buffer +
sizeof(state->buffer) - XXH_STRIPE_LEN, input - XXH_STRIPE_LEN, XXH_STRIPE_LEN);
5478 XXH_ASSERT(bEnd - input <= XXH_STRIPE_LEN);
5482 if (bEnd - input > XXH3_INTERNALBUFFER_SIZE) {
5483 const xxh_u8*
const limit = bEnd - XXH3_INTERNALBUFFER_SIZE;
5485 XXH3_consumeStripes(acc,
5486 &state->nbStripesSoFar, state->nbStripesPerBlock,
5487 input, XXH3_INTERNALBUFFER_STRIPES,
5488 secret, state->secretLimit,
5489 f_acc512, f_scramble);
5490 input += XXH3_INTERNALBUFFER_SIZE;
5491 }
while (input<limit);
5493 XXH_memcpy(state->buffer +
sizeof(state->buffer) - XXH_STRIPE_LEN, input - XXH_STRIPE_LEN, XXH_STRIPE_LEN);
5498 XXH_ASSERT(input < bEnd);
5499 XXH_ASSERT(bEnd - input <= XXH3_INTERNALBUFFER_SIZE);
5500 XXH_ASSERT(state->bufferedSize == 0);
5501 XXH_memcpy(state->buffer, input, (
size_t)(bEnd-input));
5502 state->bufferedSize = (XXH32_hash_t)(bEnd-input);
5503 #if defined(XXH3_STREAM_USE_STACK) && XXH3_STREAM_USE_STACK >= 1
5505 memcpy(state->acc, acc,
sizeof(acc));
5516 return XXH3_update(state, (
const xxh_u8*)input, len,
5517 XXH3_accumulate_512, XXH3_scrambleAcc);
5521 XXH_FORCE_INLINE
void
5522 XXH3_digest_long (XXH64_hash_t* acc,
5524 const unsigned char* secret)
5530 XXH_memcpy(acc, state->acc,
sizeof(state->acc));
5531 if (state->bufferedSize >= XXH_STRIPE_LEN) {
5532 size_t const nbStripes = (state->bufferedSize - 1) / XXH_STRIPE_LEN;
5533 size_t nbStripesSoFar = state->nbStripesSoFar;
5534 XXH3_consumeStripes(acc,
5535 &nbStripesSoFar, state->nbStripesPerBlock,
5536 state->buffer, nbStripes,
5537 secret, state->secretLimit,
5538 XXH3_accumulate_512, XXH3_scrambleAcc);
5540 XXH3_accumulate_512(acc,
5541 state->buffer + state->bufferedSize - XXH_STRIPE_LEN,
5542 secret + state->secretLimit - XXH_SECRET_LASTACC_START);
5544 xxh_u8 lastStripe[XXH_STRIPE_LEN];
5545 size_t const catchupSize = XXH_STRIPE_LEN - state->bufferedSize;
5546 XXH_ASSERT(state->bufferedSize > 0);
5547 XXH_memcpy(lastStripe, state->buffer +
sizeof(state->buffer) - catchupSize, catchupSize);
5548 XXH_memcpy(lastStripe + catchupSize, state->buffer, state->bufferedSize);
5549 XXH3_accumulate_512(acc,
5551 secret + state->secretLimit - XXH_SECRET_LASTACC_START);
5558 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
5559 if (state->totalLen > XXH3_MIDSIZE_MAX) {
5560 XXH_ALIGN(XXH_ACC_ALIGN) XXH64_hash_t acc[XXH_ACC_NB];
5561 XXH3_digest_long(acc, state, secret);
5562 return XXH3_mergeAccs(acc,
5563 secret + XXH_SECRET_MERGEACCS_START,
5564 (xxh_u64)state->totalLen * XXH_PRIME64_1);
5570 secret, state->secretLimit + XXH_STRIPE_LEN);
5593 XXH3_len_1to3_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret, XXH64_hash_t seed)
5596 XXH_ASSERT(input != NULL);
5597 XXH_ASSERT(1 <= len && len <= 3);
5598 XXH_ASSERT(secret != NULL);
5604 { xxh_u8
const c1 = input[0];
5605 xxh_u8
const c2 = input[len >> 1];
5606 xxh_u8
const c3 = input[len - 1];
5607 xxh_u32
const combinedl = ((xxh_u32)c1 <<16) | ((xxh_u32)c2 << 24)
5608 | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8);
5609 xxh_u32
const combinedh = XXH_rotl32(XXH_swap32(combinedl), 13);
5610 xxh_u64
const bitflipl = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed;
5611 xxh_u64
const bitfliph = (XXH_readLE32(secret+8) ^ XXH_readLE32(secret+12)) - seed;
5612 xxh_u64
const keyed_lo = (xxh_u64)combinedl ^ bitflipl;
5613 xxh_u64
const keyed_hi = (xxh_u64)combinedh ^ bitfliph;
5615 h128.
low64 = XXH64_avalanche(keyed_lo);
5616 h128.
high64 = XXH64_avalanche(keyed_hi);
5622 XXH3_len_4to8_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret, XXH64_hash_t seed)
5624 XXH_ASSERT(input != NULL);
5625 XXH_ASSERT(secret != NULL);
5626 XXH_ASSERT(4 <= len && len <= 8);
5627 seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32;
5628 { xxh_u32
const input_lo = XXH_readLE32(input);
5629 xxh_u32
const input_hi = XXH_readLE32(input + len - 4);
5630 xxh_u64
const input_64 = input_lo + ((xxh_u64)input_hi << 32);
5631 xxh_u64
const bitflip = (XXH_readLE64(secret+16) ^ XXH_readLE64(secret+24)) + seed;
5632 xxh_u64
const keyed = input_64 ^ bitflip;
5635 XXH128_hash_t m128 = XXH_mult64to128(keyed, XXH_PRIME64_1 + (len << 2));
5641 m128.
low64 *= 0x9FB21C651E98DF25ULL;
5649 XXH3_len_9to16_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret, XXH64_hash_t seed)
5651 XXH_ASSERT(input != NULL);
5652 XXH_ASSERT(secret != NULL);
5653 XXH_ASSERT(9 <= len && len <= 16);
5654 { xxh_u64
const bitflipl = (XXH_readLE64(secret+32) ^ XXH_readLE64(secret+40)) - seed;
5655 xxh_u64
const bitfliph = (XXH_readLE64(secret+48) ^ XXH_readLE64(secret+56)) + seed;
5656 xxh_u64
const input_lo = XXH_readLE64(input);
5657 xxh_u64 input_hi = XXH_readLE64(input + len - 8);
5658 XXH128_hash_t m128 = XXH_mult64to128(input_lo ^ input_hi ^ bitflipl, XXH_PRIME64_1);
5663 m128.
low64 += (xxh_u64)(len - 1) << 54;
5664 input_hi ^= bitfliph;
5672 if (
sizeof(
void *) <
sizeof(xxh_u64)) {
5679 m128.
high64 += (input_hi & 0xFFFFFFFF00000000ULL) + XXH_mult32to64((xxh_u32)input_hi, XXH_PRIME32_2);
5705 m128.
high64 += input_hi + XXH_mult32to64((xxh_u32)input_hi, XXH_PRIME32_2 - 1);
5724 XXH3_len_0to16_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret, XXH64_hash_t seed)
5726 XXH_ASSERT(len <= 16);
5727 {
if (len > 8)
return XXH3_len_9to16_128b(input, len, secret, seed);
5728 if (len >= 4)
return XXH3_len_4to8_128b(input, len, secret, seed);
5729 if (len)
return XXH3_len_1to3_128b(input, len, secret, seed);
5731 xxh_u64
const bitflipl = XXH_readLE64(secret+64) ^ XXH_readLE64(secret+72);
5732 xxh_u64
const bitfliph = XXH_readLE64(secret+80) ^ XXH_readLE64(secret+88);
5733 h128.
low64 = XXH64_avalanche(seed ^ bitflipl);
5734 h128.
high64 = XXH64_avalanche( seed ^ bitfliph);
5743 XXH128_mix32B(
XXH128_hash_t acc,
const xxh_u8* input_1,
const xxh_u8* input_2,
5744 const xxh_u8* secret, XXH64_hash_t seed)
5746 acc.
low64 += XXH3_mix16B (input_1, secret+0, seed);
5747 acc.
low64 ^= XXH_readLE64(input_2) + XXH_readLE64(input_2 + 8);
5748 acc.
high64 += XXH3_mix16B (input_2, secret+16, seed);
5749 acc.
high64 ^= XXH_readLE64(input_1) + XXH_readLE64(input_1 + 8);
5755 XXH3_len_17to128_128b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
5756 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
5760 XXH_ASSERT(16 < len && len <= 128);
5763 acc.
low64 = len * XXH_PRIME64_1;
5766 #if XXH_SIZE_OPT >= 1
5769 size_t i = (len - 1) / 32;
5771 acc = XXH128_mix32B(acc, input+16*i, input+len-16*(i+1), secret+32*i, seed);
5778 acc = XXH128_mix32B(acc, input+48, input+len-64, secret+96, seed);
5780 acc = XXH128_mix32B(acc, input+32, input+len-48, secret+64, seed);
5782 acc = XXH128_mix32B(acc, input+16, input+len-32, secret+32, seed);
5784 acc = XXH128_mix32B(acc, input, input+len-16, secret, seed);
5789 + (acc.
high64 * XXH_PRIME64_4)
5790 + ((len - seed) * XXH_PRIME64_2);
5799 XXH3_len_129to240_128b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
5800 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
5804 XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX);
5807 int const nbRounds = (
int)len / 32;
5809 acc.
low64 = len * XXH_PRIME64_1;
5811 for (i=0; i<4; i++) {
5812 acc = XXH128_mix32B(acc,
5814 input + (32 * i) + 16,
5820 XXH_ASSERT(nbRounds >= 4);
5821 for (i=4 ; i < nbRounds; i++) {
5822 acc = XXH128_mix32B(acc,
5824 input + (32 * i) + 16,
5825 secret + XXH3_MIDSIZE_STARTOFFSET + (32 * (i - 4)),
5829 acc = XXH128_mix32B(acc,
5838 + (acc.
high64 * XXH_PRIME64_4)
5839 + ((len - seed) * XXH_PRIME64_2);
5848 XXH3_hashLong_128b_internal(
const void* XXH_RESTRICT input,
size_t len,
5849 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
5850 XXH3_f_accumulate_512 f_acc512,
5851 XXH3_f_scrambleAcc f_scramble)
5853 XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[XXH_ACC_NB] = XXH3_INIT_ACC;
5855 XXH3_hashLong_internal_loop(acc, (const xxh_u8*)input, len, secret, secretSize, f_acc512, f_scramble);
5858 XXH_STATIC_ASSERT(sizeof(acc) == 64);
5859 XXH_ASSERT(secretSize >= sizeof(acc) + XXH_SECRET_MERGEACCS_START);
5861 h128.
low64 = XXH3_mergeAccs(acc,
5862 secret + XXH_SECRET_MERGEACCS_START,
5863 (xxh_u64)len * XXH_PRIME64_1);
5864 h128.
high64 = XXH3_mergeAccs(acc,
5866 -
sizeof(acc) - XXH_SECRET_MERGEACCS_START,
5867 ~((xxh_u64)len * XXH_PRIME64_2));
5876 XXH3_hashLong_128b_default(
const void* XXH_RESTRICT input,
size_t len,
5877 XXH64_hash_t seed64,
5878 const void* XXH_RESTRICT secret,
size_t secretLen)
5881 return XXH3_hashLong_128b_internal(input, len, XXH3_kSecret,
sizeof(XXH3_kSecret),
5882 XXH3_accumulate_512, XXH3_scrambleAcc);
5890 XXH3_hashLong_128b_withSecret(
const void* XXH_RESTRICT input,
size_t len,
5891 XXH64_hash_t seed64,
5892 const void* XXH_RESTRICT secret,
size_t secretLen)
5895 return XXH3_hashLong_128b_internal(input, len, (
const xxh_u8*)secret, secretLen,
5896 XXH3_accumulate_512, XXH3_scrambleAcc);
5900 XXH3_hashLong_128b_withSeed_internal(
const void* XXH_RESTRICT input,
size_t len,
5901 XXH64_hash_t seed64,
5902 XXH3_f_accumulate_512 f_acc512,
5903 XXH3_f_scrambleAcc f_scramble,
5904 XXH3_f_initCustomSecret f_initSec)
5907 return XXH3_hashLong_128b_internal(input, len,
5908 XXH3_kSecret,
sizeof(XXH3_kSecret),
5909 f_acc512, f_scramble);
5910 { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
5911 f_initSec(secret, seed64);
5912 return XXH3_hashLong_128b_internal(input, len, (const xxh_u8*)secret, sizeof(secret),
5913 f_acc512, f_scramble);
5921 XXH3_hashLong_128b_withSeed(const
void* input,
size_t len,
5922 XXH64_hash_t seed64, const
void* XXH_RESTRICT secret,
size_t secretLen)
5925 return XXH3_hashLong_128b_withSeed_internal(input, len, seed64,
5926 XXH3_accumulate_512, XXH3_scrambleAcc, XXH3_initCustomSecret);
5929 typedef XXH128_hash_t (*XXH3_hashLong128_f)(
const void* XXH_RESTRICT, size_t,
5933 XXH3_128bits_internal(
const void* input,
size_t len,
5934 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen,
5935 XXH3_hashLong128_f f_hl128)
5945 return XXH3_len_0to16_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, seed64);
5947 return XXH3_len_17to128_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
5948 if (len <= XXH3_MIDSIZE_MAX)
5949 return XXH3_len_129to240_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
5950 return f_hl128(input, len, seed64, secret, secretLen);
5959 return XXH3_128bits_internal(input, len, 0,
5960 XXH3_kSecret,
sizeof(XXH3_kSecret),
5961 XXH3_hashLong_128b_default);
5968 return XXH3_128bits_internal(input, len, 0,
5969 (
const xxh_u8*)secret, secretSize,
5970 XXH3_hashLong_128b_withSecret);
5977 return XXH3_128bits_internal(input, len, seed,
5978 XXH3_kSecret,
sizeof(XXH3_kSecret),
5979 XXH3_hashLong_128b_withSeed);
5986 if (len <= XXH3_MIDSIZE_MAX)
5987 return XXH3_128bits_internal(input, len, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), NULL);
5988 return XXH3_hashLong_128b_withSecret(input, len, seed, secret, secretSize);
5993 XXH128(
const void* input,
size_t len, XXH64_hash_t seed)
6000 #ifndef XXH_NO_STREAM
6038 return XXH3_update(state, (
const xxh_u8*)input, len,
6039 XXH3_accumulate_512, XXH3_scrambleAcc);
6045 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
6046 if (state->totalLen > XXH3_MIDSIZE_MAX) {
6047 XXH_ALIGN(XXH_ACC_ALIGN) XXH64_hash_t acc[XXH_ACC_NB];
6048 XXH3_digest_long(acc, state, secret);
6049 XXH_ASSERT(state->secretLimit + XXH_STRIPE_LEN >= sizeof(acc) + XXH_SECRET_MERGEACCS_START);
6051 h128.
low64 = XXH3_mergeAccs(acc,
6052 secret + XXH_SECRET_MERGEACCS_START,
6053 (xxh_u64)state->totalLen * XXH_PRIME64_1);
6054 h128.
high64 = XXH3_mergeAccs(acc,
6055 secret + state->secretLimit + XXH_STRIPE_LEN
6056 -
sizeof(acc) - XXH_SECRET_MERGEACCS_START,
6057 ~((xxh_u64)state->totalLen * XXH_PRIME64_2));
6065 secret, state->secretLimit + XXH_STRIPE_LEN);
6077 return !(memcmp(&h1, &h2,
sizeof(h1)));
6091 if (hcmp)
return hcmp;
6102 if (XXH_CPU_LITTLE_ENDIAN) {
6107 XXH_memcpy((
char*)dst +
sizeof(hash.
high64), &hash.
low64,
sizeof(hash.
low64));
6115 h.
high64 = XXH_readBE64(src);
6126 #define XXH_MIN(x, y) (((x) > (y)) ? (y) : (x))
6128 XXH_FORCE_INLINE
void XXH3_combine16(
void* dst,
XXH128_hash_t h128)
6130 XXH_writeLE64( dst, XXH_readLE64(dst) ^ h128.
low64 );
6131 XXH_writeLE64( (
char*)dst+8, XXH_readLE64((
char*)dst+8) ^ h128.
high64 );
6136 XXH3_generateSecret(
void* secretBuffer,
size_t secretSize,
const void* customSeed,
size_t customSeedSize)
6138 #if (XXH_DEBUGLEVEL >= 1)
6139 XXH_ASSERT(secretBuffer != NULL);
6143 if (secretBuffer == NULL)
return XXH_ERROR;
6147 if (customSeedSize == 0) {
6148 customSeed = XXH3_kSecret;
6149 customSeedSize = XXH_SECRET_DEFAULT_SIZE;
6151 #if (XXH_DEBUGLEVEL >= 1)
6152 XXH_ASSERT(customSeed != NULL);
6154 if (customSeed == NULL)
return XXH_ERROR;
6159 while (pos < secretSize) {
6160 size_t const toCopy = XXH_MIN((secretSize - pos), customSeedSize);
6161 memcpy((
char*)secretBuffer + pos, customSeed, toCopy);
6165 {
size_t const nbSeg16 = secretSize / 16;
6169 for (n=0; n<nbSeg16; n++) {
6171 XXH3_combine16((
char*)secretBuffer + n*16, h128);
6183 XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
6184 XXH3_initCustomSecret(secret, seed);
6185 XXH_ASSERT(secretBuffer != NULL);
6186 memcpy(secretBuffer, secret, XXH_SECRET_DEFAULT_SIZE);
6192 #if XXH_VECTOR == XXH_AVX2 \
6193 && defined(__GNUC__) && !defined(__clang__) \
6194 && defined(__OPTIMIZE__) && XXH_SIZE_OPT <= 0
6195 # pragma GCC pop_options
6208 #if defined (__cplusplus)
6225 #endif // __UT_XXHash__
#define XXH3_generateSecret_fromSeed
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
std::string upper(string_view a)
Return an all-upper case version of a (locale-independent).
unsigned char digest[sizeof(XXH128_hash_t)]
#define XXH64_createState
#define XXH_PUBLIC_API
Marks a global symbol.
#define XXH3_64bits_withSecret
SYS_FORCE_INLINE UT_API XXH64_hash_t UTxxhash64(const void *data, size_t len)
#define XXH3_64bits_withSecretandSeed
GLboolean GLboolean GLboolean GLboolean a
#define XXH32_hashFromCanonical
GLuint GLsizei GLsizei * length
struct XXH3_state_s XXH3_state_t
The state struct for the XXH3 streaming API.
#define XXH3_128bits_reset
The return value from 128-bit hashes.
**But if you need a result
GLfloat GLfloat GLfloat v2
GLfloat GLfloat GLfloat GLfloat v3
XXH_errorcode
Exit code for the streaming API.
#define XXH3_64bits_digest
#define XXH_versionNumber
#define XXH3_128bits_reset_withSeed
__attribute__((visibility("default")))
unsigned long long XXH64_hash_t
#define XXH3_128bits_reset_withSecretandSeed
#define XXH3_128bits_withSecret
#define XXH3_generateSecret
#define XXH3_64bits_reset_withSecretandSeed
struct XXH64_state_s XXH64_state_t
The opaque state struct for the XXH64 streaming API.
#define XXH3_128bits_update
#define XXH_VERSION_NUMBER
Version number, encoded as two digits each.
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_14 uint8_t packed(VULKAN_HPP_NAMESPACE::Format format)
GLboolean GLboolean GLboolean b
#define XXH3_64bits_update
#define XXH3_128bits_reset_withSecret
#define XXH3_128bits_withSecretandSeed
GLfloat GLfloat GLfloat GLfloat h
#define XXH64_canonicalFromHash
#define XXH3_64bits_reset_withSecret
std::string lower(string_view a)
Return an all-upper case version of a (locale-independent).
Canonical (big endian) representation of XXH32_hash_t.
#define XXH128_hashFromCanonical
#define XXH3_SECRET_SIZE_MIN
#define XXH3_64bits_reset_withSeed
#define XXH3_64bits_reset
#define XXH32_createState
#define XXH32_canonicalFromHash
#define XXH3_64bits_withSeed
#define XXH3_128bits_digest
#define XXH64_hashFromCanonical
#define XXH128_canonicalFromHash
SIM_DerVector3 cross(const SIM_DerVector3 &lhs, const SIM_DerVector3 &rhs)
#define XXH3_128bits_withSeed
struct XXH32_state_s XXH32_state_t
The opaque state struct for the XXH32 streaming API.