172#if defined (__cplusplus)
196# define XXH_STATIC_LINKING_ONLY
209# define XXH_IMPLEMENTATION
230# define XXH_INLINE_ALL
231# undef XXH_INLINE_ALL
235# define XXH_PRIVATE_API
236# undef XXH_PRIVATE_API
250# define XXH_NAMESPACE
254#if (defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)) \
255 && !defined(XXH_INLINE_ALL_31684351384)
257# define XXH_INLINE_ALL_31684351384
259# undef XXH_STATIC_LINKING_ONLY
260# define XXH_STATIC_LINKING_ONLY
262# undef XXH_PUBLIC_API
263# if defined(__GNUC__)
264# define XXH_PUBLIC_API static __inline __attribute__((unused))
265# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) )
266# define XXH_PUBLIC_API static inline
267# elif defined(_MSC_VER)
268# define XXH_PUBLIC_API static __inline
271# define XXH_PUBLIC_API static
287# undef XXH_versionNumber
290# undef XXH32_createState
291# undef XXH32_freeState
295# undef XXH32_copyState
296# undef XXH32_canonicalFromHash
297# undef XXH32_hashFromCanonical
300# undef XXH64_createState
301# undef XXH64_freeState
305# undef XXH64_copyState
306# undef XXH64_canonicalFromHash
307# undef XXH64_hashFromCanonical
310# undef XXH3_64bits_withSecret
311# undef XXH3_64bits_withSeed
312# undef XXH3_64bits_withSecretandSeed
313# undef XXH3_createState
314# undef XXH3_freeState
315# undef XXH3_copyState
316# undef XXH3_64bits_reset
317# undef XXH3_64bits_reset_withSeed
318# undef XXH3_64bits_reset_withSecret
319# undef XXH3_64bits_update
320# undef XXH3_64bits_digest
321# undef XXH3_generateSecret
325# undef XXH3_128bits_withSeed
326# undef XXH3_128bits_withSecret
327# undef XXH3_128bits_reset
328# undef XXH3_128bits_reset_withSeed
329# undef XXH3_128bits_reset_withSecret
330# undef XXH3_128bits_reset_withSecretandSeed
331# undef XXH3_128bits_update
332# undef XXH3_128bits_digest
333# undef XXH128_isEqual
335# undef XXH128_canonicalFromHash
336# undef XXH128_hashFromCanonical
341# define XXH_NAMESPACE XXH_INLINE_
349# define XXH_IPREF(Id) XXH_NAMESPACE ## Id
350# define XXH_OK XXH_IPREF(XXH_OK)
351# define XXH_ERROR XXH_IPREF(XXH_ERROR)
352# define XXH_errorcode XXH_IPREF(XXH_errorcode)
353# define XXH32_canonical_t XXH_IPREF(XXH32_canonical_t)
354# define XXH64_canonical_t XXH_IPREF(XXH64_canonical_t)
355# define XXH128_canonical_t XXH_IPREF(XXH128_canonical_t)
356# define XXH32_state_s XXH_IPREF(XXH32_state_s)
357# define XXH32_state_t XXH_IPREF(XXH32_state_t)
358# define XXH64_state_s XXH_IPREF(XXH64_state_s)
359# define XXH64_state_t XXH_IPREF(XXH64_state_t)
360# define XXH3_state_s XXH_IPREF(XXH3_state_s)
361# define XXH3_state_t XXH_IPREF(XXH3_state_t)
362# define XXH128_hash_t XXH_IPREF(XXH128_hash_t)
364# undef XXHASH_H_5627135585666179
365# undef XXHASH_H_STATIC_13879238742
371#ifndef XXHASH_H_5627135585666179
372#define XXHASH_H_5627135585666179 1
375#if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API)
376# if defined(WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
378# define XXH_PUBLIC_API __declspec(dllexport)
380# define XXH_PUBLIC_API __declspec(dllimport)
383# define XXH_PUBLIC_API
388# define XXH_CAT(A,B) A##B
389# define XXH_NAME2(A,B) XXH_CAT(A,B)
390# define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber)
392# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
393# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
394# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
395# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
396# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
397# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
398# define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState)
399# define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash)
400# define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical)
402# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
403# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
404# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
405# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
406# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
407# define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
408# define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState)
409# define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash)
410# define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical)
412# define XXH3_64bits XXH_NAME2(XXH_NAMESPACE, XXH3_64bits)
413# define XXH3_64bits_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSecret)
414# define XXH3_64bits_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSeed)
415# define XXH3_64bits_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSecretandSeed)
416# define XXH3_createState XXH_NAME2(XXH_NAMESPACE, XXH3_createState)
417# define XXH3_freeState XXH_NAME2(XXH_NAMESPACE, XXH3_freeState)
418# define XXH3_copyState XXH_NAME2(XXH_NAMESPACE, XXH3_copyState)
419# define XXH3_64bits_reset XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset)
420# define XXH3_64bits_reset_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSeed)
421# define XXH3_64bits_reset_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSecret)
422# define XXH3_64bits_reset_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSecretandSeed)
423# define XXH3_64bits_update XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_update)
424# define XXH3_64bits_digest XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_digest)
425# define XXH3_generateSecret XXH_NAME2(XXH_NAMESPACE, XXH3_generateSecret)
426# define XXH3_generateSecret_fromSeed XXH_NAME2(XXH_NAMESPACE, XXH3_generateSecret_fromSeed)
428# define XXH128 XXH_NAME2(XXH_NAMESPACE, XXH128)
429# define XXH3_128bits XXH_NAME2(XXH_NAMESPACE, XXH3_128bits)
430# define XXH3_128bits_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSeed)
431# define XXH3_128bits_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSecret)
432# define XXH3_128bits_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSecretandSeed)
433# define XXH3_128bits_reset XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset)
434# define XXH3_128bits_reset_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSeed)
435# define XXH3_128bits_reset_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSecret)
436# define XXH3_128bits_reset_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSecretandSeed)
437# define XXH3_128bits_update XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_update)
438# define XXH3_128bits_digest XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_digest)
439# define XXH128_isEqual XXH_NAME2(XXH_NAMESPACE, XXH128_isEqual)
440# define XXH128_cmp XXH_NAME2(XXH_NAMESPACE, XXH128_cmp)
441# define XXH128_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH128_canonicalFromHash)
442# define XXH128_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH128_hashFromCanonical)
451#if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API)
452# if defined(WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
454# define XXH_PUBLIC_API __declspec(dllexport)
456# define XXH_PUBLIC_API __declspec(dllimport)
459# define XXH_PUBLIC_API
463#if defined (__GNUC__)
464# define XXH_CONSTF __attribute__((const))
465# define XXH_PUREF __attribute__((pure))
466# define XXH_MALLOCF __attribute__((malloc))
476#define XXH_VERSION_MAJOR 0
477#define XXH_VERSION_MINOR 8
478#define XXH_VERSION_RELEASE 2
480#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
509#if defined(XXH_DOXYGEN)
517#elif !defined (__VMS) \
518 && (defined (__cplusplus) \
519 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
525# if UINT_MAX == 0xFFFFFFFFUL
527# elif ULONG_MAX == 0xFFFFFFFFUL
530# error "unsupported platform: need a 32-bit type"
713 unsigned char digest[4];
741#ifdef __has_attribute
742# define XXH_HAS_ATTRIBUTE(x) __has_attribute(x)
744# define XXH_HAS_ATTRIBUTE(x) 0
754#define XXH_C23_VN 201711L
759#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= XXH_C23_VN) && defined(__has_c_attribute)
760# define XXH_HAS_C_ATTRIBUTE(x) __has_c_attribute(x)
762# define XXH_HAS_C_ATTRIBUTE(x) 0
767#if defined(__cplusplus) && defined(__has_cpp_attribute)
768# define XXH_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
770# define XXH_HAS_CPP_ATTRIBUTE(x) 0
781#if XXH_HAS_C_ATTRIBUTE(fallthrough) || XXH_HAS_CPP_ATTRIBUTE(fallthrough)
782# define XXH_FALLTHROUGH [[fallthrough]]
783#elif XXH_HAS_ATTRIBUTE(__fallthrough__)
784# define XXH_FALLTHROUGH __attribute__ ((__fallthrough__))
786# define XXH_FALLTHROUGH
796#if XXH_HAS_ATTRIBUTE(noescape)
797# define XXH_NOESCAPE __attribute__((noescape))
810#ifndef XXH_NO_LONG_LONG
814#if defined(XXH_DOXYGEN)
821#elif !defined (__VMS) \
822 && (defined (__cplusplus) \
823 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
828# if defined(__LP64__) && ULONG_MAX == 0xFFFFFFFFFFFFFFFFULL
1093#define XXH3_SECRET_SIZE_MIN 136
1117#ifndef XXH_NO_STREAM
1268#ifndef XXH_NO_STREAM
1412#if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXHASH_H_STATIC_13879238742)
1413#define XXHASH_H_STATIC_13879238742
1450#ifndef XXH_NO_LONG_LONG
1475#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
1476# include <stdalign.h>
1477# define XXH_ALIGN(n) alignas(n)
1478#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1480# define XXH_ALIGN(n) alignas(n)
1481#elif defined(__GNUC__)
1482# define XXH_ALIGN(n) __attribute__ ((aligned(n)))
1483#elif defined(_MSC_VER)
1484# define XXH_ALIGN(n) __declspec(align(n))
1486# define XXH_ALIGN(n)
1490#if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) \
1491 && ! (defined(__cplusplus) && (__cplusplus >= 201103L)) \
1492 && defined(__GNUC__)
1493# define XXH_ALIGN_MEMBER(align, type) type XXH_ALIGN(align)
1495# define XXH_ALIGN_MEMBER(align, type) XXH_ALIGN(align) type
1505#define XXH3_INTERNALBUFFER_SIZE 256
1515#define XXH3_SECRET_DEFAULT_SIZE 192
1542 XXH_ALIGN_MEMBER(64,
unsigned char customSecret[XXH3_SECRET_DEFAULT_SIZE]);
1568#undef XXH_ALIGN_MEMBER
1581#define XXH3_INITSTATE(XXH3_state_ptr) \
1583 XXH3_state_t* tmp_xxh3_state_ptr = (XXH3_state_ptr); \
1584 tmp_xxh3_state_ptr->seed = 0; \
1585 tmp_xxh3_state_ptr->extSecret = NULL; \
1718 XXH_NOESCAPE
const void* secret,
size_t secretSize,
1723 XXH_NOESCAPE
const void* secret,
size_t secretSize,
1725#ifndef XXH_NO_STREAM
1729 XXH_NOESCAPE
const void* secret,
size_t secretSize,
1734 XXH_NOESCAPE
const void* secret,
size_t secretSize,
1740#if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)
1741# define XXH_IMPLEMENTATION
1774#if ( defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) \
1775 || defined(XXH_IMPLEMENTATION) ) && !defined(XXH_IMPLEM_13a8737387)
1776# define XXH_IMPLEM_13a8737387
1794# define XXH_NO_LONG_LONG
1795# undef XXH_NO_LONG_LONG
1846# define XXH_FORCE_MEMORY_ACCESS 0
1874# define XXH_SIZE_OPT 0
1904# define XXH_FORCE_ALIGN_CHECK 0
1926# define XXH_NO_INLINE_HINTS 0
1943# define XXH3_INLINE_SECRET 0
1955# define XXH32_ENDJMP 0
1964# define XXH_OLD_NAMES
1965# undef XXH_OLD_NAMES
1975# define XXH_NO_STREAM
1976# undef XXH_NO_STREAM
1982#ifndef XXH_FORCE_MEMORY_ACCESS
1986# if defined(__GNUC__) && !(defined(__ARM_ARCH) && __ARM_ARCH < 7 && defined(__ARM_FEATURE_UNALIGNED))
1987# define XXH_FORCE_MEMORY_ACCESS 1
1993# if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE_SIZE__)
1994# define XXH_SIZE_OPT 1
1996# define XXH_SIZE_OPT 0
2000#ifndef XXH_FORCE_ALIGN_CHECK
2002# if XXH_SIZE_OPT >= 1 || \
2003 defined(__i386) || defined(__x86_64__) || defined(__aarch64__) || defined(__ARM_FEATURE_UNALIGNED) \
2004 || defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64) || defined(_M_ARM)
2005# define XXH_FORCE_ALIGN_CHECK 0
2007# define XXH_FORCE_ALIGN_CHECK 1
2011#ifndef XXH_NO_INLINE_HINTS
2012# if XXH_SIZE_OPT >= 1 || defined(__NO_INLINE__)
2013# define XXH_NO_INLINE_HINTS 1
2015# define XXH_NO_INLINE_HINTS 0
2019#ifndef XXH3_INLINE_SECRET
2020# if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 12) \
2021 || !defined(XXH_INLINE_ALL)
2022# define XXH3_INLINE_SECRET 0
2024# define XXH3_INLINE_SECRET 1
2030# define XXH32_ENDJMP 0
2042#if defined(XXH_NO_STREAM)
2044#elif defined(XXH_NO_STDLIB)
2055static XXH_CONSTF
void* XXH_malloc(
size_t s) { (void)s;
return NULL; }
2056static void XXH_free(
void* p) { (void)p; }
2070static XXH_MALLOCF
void* XXH_malloc(
size_t s) {
return malloc(s); }
2076static void XXH_free(
void* p) { free(p); }
2086static void* XXH_memcpy(
void* dest,
const void* src,
size_t size)
2088 return memcpy(dest,src,size);
2098# pragma warning(disable : 4127)
2101#if XXH_NO_INLINE_HINTS
2102# if defined(__GNUC__) || defined(__clang__)
2103# define XXH_FORCE_INLINE static __attribute__((unused))
2105# define XXH_FORCE_INLINE static
2107# define XXH_NO_INLINE static
2109#elif defined(__GNUC__) || defined(__clang__)
2110# define XXH_FORCE_INLINE static __inline__ __attribute__((always_inline, unused))
2111# define XXH_NO_INLINE static __attribute__((noinline))
2112#elif defined(_MSC_VER)
2113# define XXH_FORCE_INLINE static __forceinline
2114# define XXH_NO_INLINE static __declspec(noinline)
2115#elif defined (__cplusplus) \
2116 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
2117# define XXH_FORCE_INLINE static inline
2118# define XXH_NO_INLINE static
2120# define XXH_FORCE_INLINE static
2121# define XXH_NO_INLINE static
2124#if XXH3_INLINE_SECRET
2125# define XXH3_WITH_SECRET_INLINE XXH_FORCE_INLINE
2127# define XXH3_WITH_SECRET_INLINE XXH_NO_INLINE
2142#ifndef XXH_DEBUGLEVEL
2144# define XXH_DEBUGLEVEL DEBUGLEVEL
2146# define XXH_DEBUGLEVEL 0
2150#if (XXH_DEBUGLEVEL>=1)
2152# define XXH_ASSERT(c) assert(c)
2154# if defined(__INTEL_COMPILER)
2155# define XXH_ASSERT(c) XXH_ASSUME((unsigned char) (c))
2157# define XXH_ASSERT(c) XXH_ASSUME(c)
2162#ifndef XXH_STATIC_ASSERT
2163# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
2164# define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { _Static_assert((c),m); } while(0)
2165# elif defined(__cplusplus) && (__cplusplus >= 201103L)
2166# define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { static_assert((c),m); } while(0)
2168# define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { struct xxh_sa { char x[(c) ? 1 : -1]; }; } while(0)
2170# define XXH_STATIC_ASSERT(c) XXH_STATIC_ASSERT_WITH_MESSAGE((c),#c)
2189#if defined(__GNUC__) || defined(__clang__)
2190# define XXH_COMPILER_GUARD(var) __asm__("" : "+r" (var))
2192# define XXH_COMPILER_GUARD(var) ((void)0)
2197#if defined(__clang__) && defined(__ARM_ARCH) && !defined(__wasm__)
2198# define XXH_COMPILER_GUARD_CLANG_NEON(var) __asm__("" : "+w" (var))
2200# define XXH_COMPILER_GUARD_CLANG_NEON(var) ((void)0)
2206#if !defined (__VMS) \
2207 && (defined (__cplusplus) \
2208 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
2210 typedef uint8_t xxh_u8;
2212 typedef unsigned char xxh_u8;
2217# warning "XXH_OLD_NAMES is planned to be removed starting v0.9. If the program depends on it, consider moving away from it by employing newer type names directly"
2275#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
2280#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
2286static xxh_u32 XXH_read32(
const void* memPtr) {
return *(
const xxh_u32*) memPtr; }
2288#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
2298typedef union { xxh_u32 u32; } __attribute__((packed)) unalign;
2300static xxh_u32 XXH_read32(
const void* ptr)
2302 typedef __attribute__((aligned(1))) xxh_u32 xxh_unalign32;
2303 return *((const xxh_unalign32*)ptr);
2312static xxh_u32 XXH_read32(
const void* memPtr)
2315 XXH_memcpy(&val, memPtr,
sizeof(val));
2340#ifndef XXH_CPU_LITTLE_ENDIAN
2345# if defined(_WIN32) \
2346 || defined(__LITTLE_ENDIAN__) \
2347 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2348# define XXH_CPU_LITTLE_ENDIAN 1
2349# elif defined(__BIG_ENDIAN__) \
2350 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
2351# define XXH_CPU_LITTLE_ENDIAN 0
2359static int XXH_isLittleEndian(
void)
2365 const union { xxh_u32 u; xxh_u8 c[4]; } one = { 1 };
2368# define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian()
2378#define XXH_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
2381# define XXH_HAS_BUILTIN(x) __has_builtin(x)
2383# define XXH_HAS_BUILTIN(x) 0
2415#if XXH_HAS_BUILTIN(__builtin_unreachable)
2416# define XXH_UNREACHABLE() __builtin_unreachable()
2418#elif defined(_MSC_VER)
2419# define XXH_UNREACHABLE() __assume(0)
2422# define XXH_UNREACHABLE()
2425#if XXH_HAS_BUILTIN(__builtin_assume)
2426# define XXH_ASSUME(c) __builtin_assume(c)
2428# define XXH_ASSUME(c) if (!(c)) { XXH_UNREACHABLE(); }
2444#if !defined(NO_CLANG_BUILTIN) && XXH_HAS_BUILTIN(__builtin_rotateleft32) \
2445 && XXH_HAS_BUILTIN(__builtin_rotateleft64)
2446# define XXH_rotl32 __builtin_rotateleft32
2447# define XXH_rotl64 __builtin_rotateleft64
2449#elif defined(_MSC_VER)
2450# define XXH_rotl32(x,r) _rotl(x,r)
2451# define XXH_rotl64(x,r) _rotl64(x,r)
2453# define XXH_rotl32(x,r) (((x) << (r)) | ((x) >> (32 - (r))))
2454# define XXH_rotl64(x,r) (((x) << (r)) | ((x) >> (64 - (r))))
2465#if defined(_MSC_VER)
2466# define XXH_swap32 _byteswap_ulong
2467#elif XXH_GCC_VERSION >= 403
2468# define XXH_swap32 __builtin_bswap32
2470static xxh_u32 XXH_swap32 (xxh_u32 x)
2472 return ((x << 24) & 0xff000000 ) |
2473 ((x << 8) & 0x00ff0000 ) |
2474 ((x >> 8) & 0x0000ff00 ) |
2475 ((x >> 24) & 0x000000ff );
2498#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
2500XXH_FORCE_INLINE xxh_u32 XXH_readLE32(
const void* memPtr)
2502 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
2504 | ((xxh_u32)bytePtr[1] << 8)
2505 | ((xxh_u32)bytePtr[2] << 16)
2506 | ((xxh_u32)bytePtr[3] << 24);
2509XXH_FORCE_INLINE xxh_u32 XXH_readBE32(
const void* memPtr)
2511 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
2513 | ((xxh_u32)bytePtr[2] << 8)
2514 | ((xxh_u32)bytePtr[1] << 16)
2515 | ((xxh_u32)bytePtr[0] << 24);
2519XXH_FORCE_INLINE xxh_u32 XXH_readLE32(
const void* ptr)
2524static xxh_u32 XXH_readBE32(
const void* ptr)
2530XXH_FORCE_INLINE xxh_u32
2534 return XXH_readLE32(ptr);
2560#define XXH_PRIME32_1 0x9E3779B1U
2561#define XXH_PRIME32_2 0x85EBCA77U
2562#define XXH_PRIME32_3 0xC2B2AE3DU
2563#define XXH_PRIME32_4 0x27D4EB2FU
2564#define XXH_PRIME32_5 0x165667B1U
2567# define PRIME32_1 XXH_PRIME32_1
2568# define PRIME32_2 XXH_PRIME32_2
2569# define PRIME32_3 XXH_PRIME32_3
2570# define PRIME32_4 XXH_PRIME32_4
2571# define PRIME32_5 XXH_PRIME32_5
2585static xxh_u32 XXH32_round(xxh_u32 acc, xxh_u32 input)
2588 acc = XXH_rotl32(acc, 13);
2590#if (defined(__SSE4_1__) || defined(__aarch64__) || defined(__wasm_simd128__)) && !defined(XXH_ENABLE_AUTOVECTORIZE)
2627 XXH_COMPILER_GUARD(acc);
2642static xxh_u32 XXH32_avalanche(xxh_u32 hash)
2652#define XXH_get32bits(p) XXH_readLE32_align(p, align)
2669static XXH_PUREF xxh_u32
2670XXH32_finalize(xxh_u32 hash,
const xxh_u8* ptr,
size_t len,
XXH_alignment align)
2672#define XXH_PROCESS1 do { \
2673 hash += (*ptr++) * XXH_PRIME32_5; \
2674 hash = XXH_rotl32(hash, 11) * XXH_PRIME32_1; \
2677#define XXH_PROCESS4 do { \
2678 hash += XXH_get32bits(ptr) * XXH_PRIME32_3; \
2680 hash = XXH_rotl32(hash, 17) * XXH_PRIME32_4; \
2683 if (ptr==NULL) XXH_ASSERT(len == 0);
2696 return XXH32_avalanche(hash);
2699 case 12: XXH_PROCESS4;
2701 case 8: XXH_PROCESS4;
2703 case 4: XXH_PROCESS4;
2704 return XXH32_avalanche(hash);
2706 case 13: XXH_PROCESS4;
2708 case 9: XXH_PROCESS4;
2710 case 5: XXH_PROCESS4;
2712 return XXH32_avalanche(hash);
2714 case 14: XXH_PROCESS4;
2716 case 10: XXH_PROCESS4;
2718 case 6: XXH_PROCESS4;
2721 return XXH32_avalanche(hash);
2723 case 15: XXH_PROCESS4;
2725 case 11: XXH_PROCESS4;
2727 case 7: XXH_PROCESS4;
2729 case 3: XXH_PROCESS1;
2731 case 2: XXH_PROCESS1;
2733 case 1: XXH_PROCESS1;
2735 case 0:
return XXH32_avalanche(hash);
2743# define PROCESS1 XXH_PROCESS1
2744# define PROCESS4 XXH_PROCESS4
2758XXH_FORCE_INLINE XXH_PUREF xxh_u32
2759XXH32_endian_align(
const xxh_u8* input,
size_t len, xxh_u32 seed,
XXH_alignment align)
2763 if (input==NULL) XXH_ASSERT(len == 0);
2766 const xxh_u8*
const bEnd = input + len;
2767 const xxh_u8*
const limit = bEnd - 15;
2770 xxh_u32 v3 = seed + 0;
2774 v1 = XXH32_round(v1, XXH_get32bits(input)); input += 4;
2775 v2 = XXH32_round(v2, XXH_get32bits(input)); input += 4;
2776 v3 = XXH32_round(v3, XXH_get32bits(input)); input += 4;
2777 v4 = XXH32_round(v4, XXH_get32bits(input)); input += 4;
2778 }
while (input < limit);
2780 h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7)
2781 + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
2786 h32 += (xxh_u32)len;
2788 return XXH32_finalize(h32, input, len&15, align);
2794#if !defined(XXH_NO_STREAM) && XXH_SIZE_OPT >= 2
2802 if ((((
size_t)input) & 3) == 0) {
2803 return XXH32_endian_align((
const xxh_u8*)input, len, seed,
XXH_aligned);
2806 return XXH32_endian_align((
const xxh_u8*)input, len, seed,
XXH_unaligned);
2813#ifndef XXH_NO_STREAM
2829 XXH_memcpy(dstState, srcState,
sizeof(*dstState));
2835 XXH_ASSERT(statePtr != NULL);
2836 memset(statePtr, 0,
sizeof(*statePtr));
2839 statePtr->
v[2] = seed + 0;
2850 XXH_ASSERT(len == 0);
2854 {
const xxh_u8* p = (
const xxh_u8*)input;
2855 const xxh_u8*
const bEnd = p + len;
2860 if (state->
memsize + len < 16) {
2861 XXH_memcpy((xxh_u8*)(state->
mem32) + state->
memsize, input, len);
2868 {
const xxh_u32* p32 = state->
mem32;
2869 state->
v[0] = XXH32_round(state->
v[0], XXH_readLE32(p32)); p32++;
2870 state->
v[1] = XXH32_round(state->
v[1], XXH_readLE32(p32)); p32++;
2871 state->
v[2] = XXH32_round(state->
v[2], XXH_readLE32(p32)); p32++;
2872 state->
v[3] = XXH32_round(state->
v[3], XXH_readLE32(p32));
2879 const xxh_u8*
const limit = bEnd - 16;
2882 state->
v[0] = XXH32_round(state->
v[0], XXH_readLE32(p)); p+=4;
2883 state->
v[1] = XXH32_round(state->
v[1], XXH_readLE32(p)); p+=4;
2884 state->
v[2] = XXH32_round(state->
v[2], XXH_readLE32(p)); p+=4;
2885 state->
v[3] = XXH32_round(state->
v[3], XXH_readLE32(p)); p+=4;
2891 XXH_memcpy(state->
mem32, p, (
size_t)(bEnd-p));
2892 state->
memsize = (unsigned)(bEnd-p);
2906 h32 = XXH_rotl32(state->
v[0], 1)
2907 + XXH_rotl32(state->
v[1], 7)
2908 + XXH_rotl32(state->
v[2], 12)
2909 + XXH_rotl32(state->
v[3], 18);
2940 XXH_memcpy(dst, &hash,
sizeof(*dst));
2945 return XXH_readBE32(src);
2949#ifndef XXH_NO_LONG_LONG
2967#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
2972#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
2975static xxh_u64 XXH_read64(
const void* memPtr)
2977 return *(
const xxh_u64*) memPtr;
2980#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
2990typedef union { xxh_u32 u32; xxh_u64 u64; } __attribute__((packed)) unalign64;
2992static xxh_u64 XXH_read64(
const void* ptr)
2994 typedef __attribute__((aligned(1))) xxh_u64 xxh_unalign64;
2995 return *((const xxh_unalign64*)ptr);
3004static xxh_u64 XXH_read64(
const void* memPtr)
3007 XXH_memcpy(&val, memPtr,
sizeof(val));
3013#if defined(_MSC_VER)
3014# define XXH_swap64 _byteswap_uint64
3015#elif XXH_GCC_VERSION >= 403
3016# define XXH_swap64 __builtin_bswap64
3018static xxh_u64 XXH_swap64(xxh_u64 x)
3020 return ((x << 56) & 0xff00000000000000ULL) |
3021 ((x << 40) & 0x00ff000000000000ULL) |
3022 ((x << 24) & 0x0000ff0000000000ULL) |
3023 ((x << 8) & 0x000000ff00000000ULL) |
3024 ((x >> 8) & 0x00000000ff000000ULL) |
3025 ((x >> 24) & 0x0000000000ff0000ULL) |
3026 ((x >> 40) & 0x000000000000ff00ULL) |
3027 ((x >> 56) & 0x00000000000000ffULL);
3033#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
3035XXH_FORCE_INLINE xxh_u64 XXH_readLE64(
const void* memPtr)
3037 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
3039 | ((xxh_u64)bytePtr[1] << 8)
3040 | ((xxh_u64)bytePtr[2] << 16)
3041 | ((xxh_u64)bytePtr[3] << 24)
3042 | ((xxh_u64)bytePtr[4] << 32)
3043 | ((xxh_u64)bytePtr[5] << 40)
3044 | ((xxh_u64)bytePtr[6] << 48)
3045 | ((xxh_u64)bytePtr[7] << 56);
3048XXH_FORCE_INLINE xxh_u64 XXH_readBE64(
const void* memPtr)
3050 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
3052 | ((xxh_u64)bytePtr[6] << 8)
3053 | ((xxh_u64)bytePtr[5] << 16)
3054 | ((xxh_u64)bytePtr[4] << 24)
3055 | ((xxh_u64)bytePtr[3] << 32)
3056 | ((xxh_u64)bytePtr[2] << 40)
3057 | ((xxh_u64)bytePtr[1] << 48)
3058 | ((xxh_u64)bytePtr[0] << 56);
3062XXH_FORCE_INLINE xxh_u64 XXH_readLE64(
const void* ptr)
3067static xxh_u64 XXH_readBE64(
const void* ptr)
3073XXH_FORCE_INLINE xxh_u64
3077 return XXH_readLE64(ptr);
3093#define XXH_PRIME64_1 0x9E3779B185EBCA87ULL
3094#define XXH_PRIME64_2 0xC2B2AE3D27D4EB4FULL
3095#define XXH_PRIME64_3 0x165667B19E3779F9ULL
3096#define XXH_PRIME64_4 0x85EBCA77C2B2AE63ULL
3097#define XXH_PRIME64_5 0x27D4EB2F165667C5ULL
3100# define PRIME64_1 XXH_PRIME64_1
3101# define PRIME64_2 XXH_PRIME64_2
3102# define PRIME64_3 XXH_PRIME64_3
3103# define PRIME64_4 XXH_PRIME64_4
3104# define PRIME64_5 XXH_PRIME64_5
3108static xxh_u64 XXH64_round(xxh_u64 acc, xxh_u64 input)
3111 acc = XXH_rotl64(acc, 31);
3116static xxh_u64 XXH64_mergeRound(xxh_u64 acc, xxh_u64 val)
3118 val = XXH64_round(0, val);
3125static xxh_u64 XXH64_avalanche(xxh_u64 hash)
3136#define XXH_get64bits(p) XXH_readLE64_align(p, align)
3153static XXH_PUREF xxh_u64
3154XXH64_finalize(xxh_u64 hash,
const xxh_u8* ptr,
size_t len,
XXH_alignment align)
3156 if (ptr==NULL) XXH_ASSERT(len == 0);
3159 xxh_u64
const k1 = XXH64_round(0, XXH_get64bits(ptr));
3176 return XXH64_avalanche(hash);
3180# define PROCESS1_64 XXH_PROCESS1_64
3181# define PROCESS4_64 XXH_PROCESS4_64
3182# define PROCESS8_64 XXH_PROCESS8_64
3184# undef XXH_PROCESS1_64
3185# undef XXH_PROCESS4_64
3186# undef XXH_PROCESS8_64
3197XXH_FORCE_INLINE XXH_PUREF xxh_u64
3198XXH64_endian_align(
const xxh_u8* input,
size_t len, xxh_u64 seed,
XXH_alignment align)
3201 if (input==NULL) XXH_ASSERT(len == 0);
3204 const xxh_u8*
const bEnd = input + len;
3205 const xxh_u8*
const limit = bEnd - 31;
3208 xxh_u64 v3 = seed + 0;
3212 v1 = XXH64_round(v1, XXH_get64bits(input)); input+=8;
3213 v2 = XXH64_round(v2, XXH_get64bits(input)); input+=8;
3214 v3 = XXH64_round(v3, XXH_get64bits(input)); input+=8;
3215 v4 = XXH64_round(v4, XXH_get64bits(input)); input+=8;
3216 }
while (input<limit);
3218 h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
3219 h64 = XXH64_mergeRound(h64, v1);
3220 h64 = XXH64_mergeRound(h64, v2);
3221 h64 = XXH64_mergeRound(h64, v3);
3222 h64 = XXH64_mergeRound(h64, v4);
3228 h64 += (xxh_u64) len;
3230 return XXH64_finalize(h64, input, len, align);
3237#if !defined(XXH_NO_STREAM) && XXH_SIZE_OPT >= 2
3245 if ((((
size_t)input) & 7)==0) {
3246 return XXH64_endian_align((
const xxh_u8*)input, len, seed,
XXH_aligned);
3249 return XXH64_endian_align((
const xxh_u8*)input, len, seed,
XXH_unaligned);
3255#ifndef XXH_NO_STREAM
3271 XXH_memcpy(dstState, srcState,
sizeof(*dstState));
3277 XXH_ASSERT(statePtr != NULL);
3278 memset(statePtr, 0,
sizeof(*statePtr));
3281 statePtr->v[2] = seed + 0;
3291 XXH_ASSERT(len == 0);
3295 {
const xxh_u8* p = (
const xxh_u8*)input;
3296 const xxh_u8*
const bEnd = p + len;
3298 state->total_len += len;
3300 if (state->memsize + len < 32) {
3301 XXH_memcpy(((xxh_u8*)state->mem64) + state->memsize, input, len);
3302 state->memsize += (xxh_u32)len;
3306 if (state->memsize) {
3307 XXH_memcpy(((xxh_u8*)state->mem64) + state->memsize, input, 32-state->memsize);
3308 state->v[0] = XXH64_round(state->v[0], XXH_readLE64(state->mem64+0));
3309 state->v[1] = XXH64_round(state->v[1], XXH_readLE64(state->mem64+1));
3310 state->v[2] = XXH64_round(state->v[2], XXH_readLE64(state->mem64+2));
3311 state->v[3] = XXH64_round(state->v[3], XXH_readLE64(state->mem64+3));
3312 p += 32 - state->memsize;
3317 const xxh_u8*
const limit = bEnd - 32;
3320 state->v[0] = XXH64_round(state->v[0], XXH_readLE64(p)); p+=8;
3321 state->v[1] = XXH64_round(state->v[1], XXH_readLE64(p)); p+=8;
3322 state->v[2] = XXH64_round(state->v[2], XXH_readLE64(p)); p+=8;
3323 state->v[3] = XXH64_round(state->v[3], XXH_readLE64(p)); p+=8;
3329 XXH_memcpy(state->mem64, p, (
size_t)(bEnd-p));
3330 state->memsize = (unsigned)(bEnd-p);
3343 if (state->total_len >= 32) {
3344 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);
3345 h64 = XXH64_mergeRound(h64, state->v[0]);
3346 h64 = XXH64_mergeRound(h64, state->v[1]);
3347 h64 = XXH64_mergeRound(h64, state->v[2]);
3348 h64 = XXH64_mergeRound(h64, state->v[3]);
3353 h64 += (xxh_u64) state->total_len;
3355 return XXH64_finalize(h64, (
const xxh_u8*)state->mem64, (
size_t)state->total_len,
XXH_aligned);
3366 XXH_memcpy(dst, &hash,
sizeof(*dst));
3372 return XXH_readBE64(src);
3390#if ((defined(sun) || defined(__sun)) && __cplusplus)
3391# define XXH_RESTRICT
3392#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
3393# define XXH_RESTRICT restrict
3394#elif (defined (__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) \
3395 || (defined (__clang__)) \
3396 || (defined (_MSC_VER) && (_MSC_VER >= 1400)) \
3397 || (defined (__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300))
3402# define XXH_RESTRICT __restrict
3404# define XXH_RESTRICT
3407#if (defined(__GNUC__) && (__GNUC__ >= 3)) \
3408 || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) \
3409 || defined(__clang__)
3410# define XXH_likely(x) __builtin_expect(x, 1)
3411# define XXH_unlikely(x) __builtin_expect(x, 0)
3413# define XXH_likely(x) (x)
3414# define XXH_unlikely(x) (x)
3417#ifndef XXH_HAS_INCLUDE
3418# ifdef __has_include
3419# define XXH_HAS_INCLUDE(x) __has_include(x)
3421# define XXH_HAS_INCLUDE(x) 0
3425#if defined(__GNUC__) || defined(__clang__)
3426# if defined(__ARM_FEATURE_SVE)
3427# include <arm_sve.h>
3429# if defined(__ARM_NEON__) || defined(__ARM_NEON) \
3430 || (defined(_M_ARM) && _M_ARM >= 7) \
3431 || defined(_M_ARM64) || defined(_M_ARM64EC) \
3432 || (defined(__wasm_simd128__) && XXH_HAS_INCLUDE(<arm_neon.h>))
3433# define inline __inline__
3434# include <arm_neon.h>
3436# elif defined(__AVX2__)
3437# include <immintrin.h>
3438# elif defined(__SSE2__)
3439# include <emmintrin.h>
3443#if defined(_MSC_VER)
3516#if defined(__thumb__) && !defined(__thumb2__) && defined(__ARM_ARCH_ISA_ARM)
3517# warning "XXH3 is highly inefficient without ARM or Thumb-2."
3535# define XXH_VECTOR XXH_SCALAR
3572# define XXH_ACC_ALIGN 8
3577# define XXH_SCALAR 0
3580# define XXH_AVX512 3
3587# if defined(__ARM_FEATURE_SVE)
3588# define XXH_VECTOR XXH_SVE
3590 defined(__ARM_NEON__) || defined(__ARM_NEON) \
3591 || defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC) \
3592 || (defined(__wasm_simd128__) && XXH_HAS_INCLUDE(<arm_neon.h>)) \
3594 defined(_WIN32) || defined(__LITTLE_ENDIAN__) \
3595 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) \
3597# define XXH_VECTOR XXH_NEON
3598# elif defined(__AVX512F__)
3599# define XXH_VECTOR XXH_AVX512
3600# elif defined(__AVX2__)
3601# define XXH_VECTOR XXH_AVX2
3602# elif defined(__SSE2__) || defined(_M_AMD64) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP == 2))
3603# define XXH_VECTOR XXH_SSE2
3604# elif (defined(__PPC64__) && defined(__POWER8_VECTOR__)) \
3605 || (defined(__s390x__) && defined(__VEC__)) \
3606 && defined(__GNUC__)
3607# define XXH_VECTOR XXH_VSX
3609# define XXH_VECTOR XXH_SCALAR
3614#if (XXH_VECTOR == XXH_SVE) && !defined(__ARM_FEATURE_SVE)
3616# pragma warning(once : 4606)
3618# warning "__ARM_FEATURE_SVE isn't supported. Use SCALAR instead."
3621# define XXH_VECTOR XXH_SCALAR
3628#ifndef XXH_ACC_ALIGN
3629# if defined(XXH_X86DISPATCH)
3630# define XXH_ACC_ALIGN 64
3631# elif XXH_VECTOR == XXH_SCALAR
3632# define XXH_ACC_ALIGN 8
3633# elif XXH_VECTOR == XXH_SSE2
3634# define XXH_ACC_ALIGN 16
3635# elif XXH_VECTOR == XXH_AVX2
3636# define XXH_ACC_ALIGN 32
3637# elif XXH_VECTOR == XXH_NEON
3638# define XXH_ACC_ALIGN 16
3639# elif XXH_VECTOR == XXH_VSX
3640# define XXH_ACC_ALIGN 16
3641# elif XXH_VECTOR == XXH_AVX512
3642# define XXH_ACC_ALIGN 64
3643# elif XXH_VECTOR == XXH_SVE
3644# define XXH_ACC_ALIGN 64
3648#if defined(XXH_X86DISPATCH) || XXH_VECTOR == XXH_SSE2 \
3649 || XXH_VECTOR == XXH_AVX2 || XXH_VECTOR == XXH_AVX512
3650# define XXH_SEC_ALIGN XXH_ACC_ALIGN
3651#elif XXH_VECTOR == XXH_SVE
3652# define XXH_SEC_ALIGN XXH_ACC_ALIGN
3654# define XXH_SEC_ALIGN 8
3657#if defined(__GNUC__) || defined(__clang__)
3658# define XXH_ALIASING __attribute__((may_alias))
3660# define XXH_ALIASING
3684#if XXH_VECTOR == XXH_AVX2 \
3685 && defined(__GNUC__) && !defined(__clang__) \
3686 && defined(__OPTIMIZE__) && XXH_SIZE_OPT <= 0
3687# pragma GCC push_options
3688# pragma GCC optimize("-O2")
3691#if XXH_VECTOR == XXH_NEON
3700typedef uint64x2_t xxh_aliasing_uint64x2_t XXH_ALIASING;
3715#if defined(__aarch64__) && defined(__GNUC__) && !defined(__clang__)
3716XXH_FORCE_INLINE uint64x2_t XXH_vld1q_u64(
void const* ptr)
3718 return *(xxh_aliasing_uint64x2_t
const *)ptr;
3721XXH_FORCE_INLINE uint64x2_t XXH_vld1q_u64(
void const* ptr)
3723 return vreinterpretq_u64_u8(vld1q_u8((uint8_t
const*)ptr));
3735#if defined(__aarch64__) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 11
3736XXH_FORCE_INLINE uint64x2_t
3737XXH_vmlal_low_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
3740 __asm__(
"umlal %0.2d, %1.2s, %2.2s" :
"+w" (acc) :
"w" (lhs),
"w" (rhs));
3743XXH_FORCE_INLINE uint64x2_t
3744XXH_vmlal_high_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
3747 return vmlal_high_u32(acc, lhs, rhs);
3751XXH_FORCE_INLINE uint64x2_t
3752XXH_vmlal_low_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
3754 return vmlal_u32(acc, vget_low_u32(lhs), vget_low_u32(rhs));
3758XXH_FORCE_INLINE uint64x2_t
3759XXH_vmlal_high_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
3761 return vmlal_u32(acc, vget_high_u32(lhs), vget_high_u32(rhs));
3803# ifndef XXH3_NEON_LANES
3804# if (defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || defined(_M_ARM64EC)) \
3805 && !defined(__APPLE__) && XXH_SIZE_OPT <= 0
3806# define XXH3_NEON_LANES 6
3808# define XXH3_NEON_LANES XXH_ACC_NB
3821#if XXH_VECTOR == XXH_VSX
3830# pragma push_macro("bool")
3831# pragma push_macro("vector")
3832# pragma push_macro("pixel")
3838# if defined(__s390x__)
3839# include <s390intrin.h>
3841# include <altivec.h>
3845# pragma pop_macro("pixel")
3846# pragma pop_macro("vector")
3847# pragma pop_macro("bool")
3849typedef __vector
unsigned long long xxh_u64x2;
3850typedef __vector
unsigned char xxh_u8x16;
3851typedef __vector
unsigned xxh_u32x4;
3856typedef xxh_u64x2 xxh_aliasing_u64x2 XXH_ALIASING;
3859# if defined(__BIG_ENDIAN__) \
3860 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
3861# define XXH_VSX_BE 1
3862# elif defined(__VEC_ELEMENT_REG_ORDER__) && __VEC_ELEMENT_REG_ORDER__ == __ORDER_BIG_ENDIAN__
3863# warning "-maltivec=be is not recommended. Please use native endianness."
3864# define XXH_VSX_BE 1
3866# define XXH_VSX_BE 0
3871# if defined(__POWER9_VECTOR__) || (defined(__clang__) && defined(__s390x__))
3872# define XXH_vec_revb vec_revb
3877XXH_FORCE_INLINE xxh_u64x2 XXH_vec_revb(xxh_u64x2 val)
3879 xxh_u8x16
const vByteSwap = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
3880 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08 };
3881 return vec_perm(val, val, vByteSwap);
3889XXH_FORCE_INLINE xxh_u64x2 XXH_vec_loadu(
const void *ptr)
3892 XXH_memcpy(&ret, ptr,
sizeof(xxh_u64x2));
3894 ret = XXH_vec_revb(ret);
3905# if defined(__s390x__)
3907# define XXH_vec_mulo vec_mulo
3908# define XXH_vec_mule vec_mule
3909# elif defined(__clang__) && XXH_HAS_BUILTIN(__builtin_altivec_vmuleuw) && !defined(__ibmxl__)
3912# define XXH_vec_mulo __builtin_altivec_vmulouw
3913# define XXH_vec_mule __builtin_altivec_vmuleuw
3917XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mulo(xxh_u32x4 a, xxh_u32x4 b)
3920 __asm__(
"vmulouw %0, %1, %2" :
"=v" (result) :
"v" (a),
"v" (b));
3923XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mule(xxh_u32x4 a, xxh_u32x4 b)
3926 __asm__(
"vmuleuw %0, %1, %2" :
"=v" (result) :
"v" (a),
"v" (b));
3932#if XXH_VECTOR == XXH_SVE
3933#define ACCRND(acc, offset) \
3935 svuint64_t input_vec = svld1_u64(mask, xinput + offset); \
3936 svuint64_t secret_vec = svld1_u64(mask, xsecret + offset); \
3937 svuint64_t mixed = sveor_u64_x(mask, secret_vec, input_vec); \
3938 svuint64_t swapped = svtbl_u64(input_vec, kSwap); \
3939 svuint64_t mixed_lo = svextw_u64_x(mask, mixed); \
3940 svuint64_t mixed_hi = svlsr_n_u64_x(mask, mixed, 32); \
3941 svuint64_t mul = svmad_u64_x(mask, mixed_lo, mixed_hi, swapped); \
3942 acc = svadd_u64_x(mask, acc, mul); \
3948#if defined(XXH_NO_PREFETCH)
3949# define XXH_PREFETCH(ptr) (void)(ptr)
3951# if XXH_SIZE_OPT >= 1
3952# define XXH_PREFETCH(ptr) (void)(ptr)
3953# elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
3954# include <mmintrin.h>
3955# define XXH_PREFETCH(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
3956# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
3957# define XXH_PREFETCH(ptr) __builtin_prefetch((ptr), 0 , 3 )
3959# define XXH_PREFETCH(ptr) (void)(ptr)
3968#define XXH_SECRET_DEFAULT_SIZE 192
3970#if (XXH_SECRET_DEFAULT_SIZE < XXH3_SECRET_SIZE_MIN)
3971# error "default keyset is not large enough"
3975XXH_ALIGN(64) static const xxh_u8 XXH3_kSecret[XXH_SECRET_DEFAULT_SIZE] = {
3976 0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c,
3977 0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f,
3978 0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21,
3979 0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c,
3980 0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3,
3981 0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8,
3982 0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d,
3983 0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64,
3984 0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb,
3985 0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e,
3986 0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce,
3987 0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e,
3990static const xxh_u64 PRIME_MX1 = 0x165667919E3779F9ULL;
3991static const xxh_u64 PRIME_MX2 = 0x9FB21C651E98DF25ULL;
3994# define kSecret XXH3_kSecret
4014XXH_FORCE_INLINE xxh_u64
4015XXH_mult32to64(xxh_u64 x, xxh_u64 y)
4017 return (x & 0xFFFFFFFF) * (y & 0xFFFFFFFF);
4019#elif defined(_MSC_VER) && defined(_M_IX86)
4020# define XXH_mult32to64(x, y) __emulu((unsigned)(x), (unsigned)(y))
4029# define XXH_mult32to64(x, y) ((xxh_u64)(xxh_u32)(x) * (xxh_u64)(xxh_u32)(y))
4042XXH_mult64to128(xxh_u64 lhs, xxh_u64 rhs)
4059#if (defined(__GNUC__) || defined(__clang__)) && !defined(__wasm__) \
4060 && defined(__SIZEOF_INT128__) \
4061 || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
4063 __uint128_t
const product = (__uint128_t)lhs * (__uint128_t)rhs;
4065 r128.
low64 = (xxh_u64)(product);
4066 r128.
high64 = (xxh_u64)(product >> 64);
4076#elif (defined(_M_X64) || defined(_M_IA64)) && !defined(_M_ARM64EC)
4079# pragma intrinsic(_umul128)
4081 xxh_u64 product_high;
4082 xxh_u64
const product_low = _umul128(lhs, rhs, &product_high);
4084 r128.
low64 = product_low;
4085 r128.
high64 = product_high;
4093#elif defined(_M_ARM64) || defined(_M_ARM64EC)
4096# pragma intrinsic(__umulh)
4099 r128.
low64 = lhs * rhs;
4100 r128.
high64 = __umulh(lhs, rhs);
4148 xxh_u64
const lo_lo = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs & 0xFFFFFFFF);
4149 xxh_u64
const hi_lo = XXH_mult32to64(lhs >> 32, rhs & 0xFFFFFFFF);
4150 xxh_u64
const lo_hi = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs >> 32);
4151 xxh_u64
const hi_hi = XXH_mult32to64(lhs >> 32, rhs >> 32);
4154 xxh_u64
const cross = (lo_lo >> 32) + (hi_lo & 0xFFFFFFFF) + lo_hi;
4155 xxh_u64
const upper = (hi_lo >> 32) + (cross >> 32) + hi_hi;
4156 xxh_u64
const lower = (cross << 32) | (lo_lo & 0xFFFFFFFF);
4176XXH3_mul128_fold64(xxh_u64 lhs, xxh_u64 rhs)
4183XXH_FORCE_INLINE XXH_CONSTF xxh_u64 XXH_xorshift64(xxh_u64 v64,
int shift)
4185 XXH_ASSERT(0 <= shift && shift < 64);
4186 return v64 ^ (v64 >> shift);
4195 h64 = XXH_xorshift64(h64, 37);
4197 h64 = XXH_xorshift64(h64, 32);
4206static XXH64_hash_t XXH3_rrmxmx(xxh_u64 h64, xxh_u64 len)
4209 h64 ^= XXH_rotl64(h64, 49) ^ XXH_rotl64(h64, 24);
4211 h64 ^= (h64 >> 35) + len ;
4213 return XXH_xorshift64(h64, 28);
4251XXH3_len_1to3_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4253 XXH_ASSERT(input != NULL);
4254 XXH_ASSERT(1 <= len && len <= 3);
4255 XXH_ASSERT(secret != NULL);
4261 { xxh_u8
const c1 = input[0];
4262 xxh_u8
const c2 = input[len >> 1];
4263 xxh_u8
const c3 = input[len - 1];
4264 xxh_u32
const combined = ((xxh_u32)c1 << 16) | ((xxh_u32)c2 << 24)
4265 | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8);
4266 xxh_u64
const bitflip = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed;
4267 xxh_u64
const keyed = (xxh_u64)combined ^ bitflip;
4268 return XXH64_avalanche(keyed);
4273XXH3_len_4to8_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4275 XXH_ASSERT(input != NULL);
4276 XXH_ASSERT(secret != NULL);
4277 XXH_ASSERT(4 <= len && len <= 8);
4278 seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32;
4279 { xxh_u32
const input1 = XXH_readLE32(input);
4280 xxh_u32
const input2 = XXH_readLE32(input + len - 4);
4281 xxh_u64
const bitflip = (XXH_readLE64(secret+8) ^ XXH_readLE64(secret+16)) - seed;
4282 xxh_u64
const input64 = input2 + (((xxh_u64)input1) << 32);
4283 xxh_u64
const keyed = input64 ^ bitflip;
4284 return XXH3_rrmxmx(keyed, len);
4289XXH3_len_9to16_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4291 XXH_ASSERT(input != NULL);
4292 XXH_ASSERT(secret != NULL);
4293 XXH_ASSERT(9 <= len && len <= 16);
4294 { xxh_u64
const bitflip1 = (XXH_readLE64(secret+24) ^ XXH_readLE64(secret+32)) + seed;
4295 xxh_u64
const bitflip2 = (XXH_readLE64(secret+40) ^ XXH_readLE64(secret+48)) - seed;
4296 xxh_u64
const input_lo = XXH_readLE64(input) ^ bitflip1;
4297 xxh_u64
const input_hi = XXH_readLE64(input + len - 8) ^ bitflip2;
4298 xxh_u64
const acc = len
4299 + XXH_swap64(input_lo) + input_hi
4300 + XXH3_mul128_fold64(input_lo, input_hi);
4301 return XXH3_avalanche(acc);
4306XXH3_len_0to16_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4308 XXH_ASSERT(len <= 16);
4309 {
if (XXH_likely(len > 8))
return XXH3_len_9to16_64b(input, len, secret, seed);
4310 if (XXH_likely(len >= 4))
return XXH3_len_4to8_64b(input, len, secret, seed);
4311 if (len)
return XXH3_len_1to3_64b(input, len, secret, seed);
4312 return XXH64_avalanche(seed ^ (XXH_readLE64(secret+56) ^ XXH_readLE64(secret+64)));
4342XXH_FORCE_INLINE xxh_u64 XXH3_mix16B(
const xxh_u8* XXH_RESTRICT input,
4343 const xxh_u8* XXH_RESTRICT secret, xxh_u64 seed64)
4345#if defined(__GNUC__) && !defined(__clang__) \
4346 && defined(__i386__) && defined(__SSE2__) \
4347 && !defined(XXH_ENABLE_AUTOVECTORIZE)
4363 XXH_COMPILER_GUARD(seed64);
4365 { xxh_u64
const input_lo = XXH_readLE64(input);
4366 xxh_u64
const input_hi = XXH_readLE64(input+8);
4367 return XXH3_mul128_fold64(
4368 input_lo ^ (XXH_readLE64(secret) + seed64),
4369 input_hi ^ (XXH_readLE64(secret+8) - seed64)
4376XXH3_len_17to128_64b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
4377 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
4381 XXH_ASSERT(16 < len && len <= 128);
4384#if XXH_SIZE_OPT >= 1
4386 unsigned int i = (
unsigned int)(len - 1) / 32;
4388 acc += XXH3_mix16B(input+16 * i, secret+32*i, seed);
4389 acc += XXH3_mix16B(input+len-16*(i+1), secret+32*i+16, seed);
4395 acc += XXH3_mix16B(input+48, secret+96, seed);
4396 acc += XXH3_mix16B(input+len-64, secret+112, seed);
4398 acc += XXH3_mix16B(input+32, secret+64, seed);
4399 acc += XXH3_mix16B(input+len-48, secret+80, seed);
4401 acc += XXH3_mix16B(input+16, secret+32, seed);
4402 acc += XXH3_mix16B(input+len-32, secret+48, seed);
4404 acc += XXH3_mix16B(input+0, secret+0, seed);
4405 acc += XXH3_mix16B(input+len-16, secret+16, seed);
4407 return XXH3_avalanche(acc);
4411#define XXH3_MIDSIZE_MAX 240
4414XXH3_len_129to240_64b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
4415 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
4419 XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX);
4421 #define XXH3_MIDSIZE_STARTOFFSET 3
4422 #define XXH3_MIDSIZE_LASTOFFSET 17
4426 unsigned int const nbRounds = (
unsigned int)len / 16;
4428 XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX);
4429 for (i=0; i<8; i++) {
4430 acc += XXH3_mix16B(input+(16*i), secret+(16*i), seed);
4433 acc_end = XXH3_mix16B(input + len - 16, secret +
XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET, seed);
4434 XXH_ASSERT(nbRounds >= 8);
4435 acc = XXH3_avalanche(acc);
4436#if defined(__clang__) \
4437 && (defined(__ARM_NEON) || defined(__ARM_NEON__)) \
4438 && !defined(XXH_ENABLE_AUTOVECTORIZE)
4459 #pragma clang loop vectorize(disable)
4461 for (i=8 ; i < nbRounds; i++) {
4465 XXH_COMPILER_GUARD(acc);
4466 acc_end += XXH3_mix16B(input+(16*i), secret+(16*(i-8)) + XXH3_MIDSIZE_STARTOFFSET, seed);
4468 return XXH3_avalanche(acc + acc_end);
4475#define XXH_STRIPE_LEN 64
4476#define XXH_SECRET_CONSUME_RATE 8
4477#define XXH_ACC_NB (XXH_STRIPE_LEN / sizeof(xxh_u64))
4480# define STRIPE_LEN XXH_STRIPE_LEN
4481# define ACC_NB XXH_ACC_NB
4484#ifndef XXH_PREFETCH_DIST
4486# define XXH_PREFETCH_DIST 320
4488# if (XXH_VECTOR == XXH_AVX512)
4489# define XXH_PREFETCH_DIST 512
4491# define XXH_PREFETCH_DIST 384
4506#define XXH3_ACCUMULATE_TEMPLATE(name) \
4508XXH3_accumulate_##name(xxh_u64* XXH_RESTRICT acc, \
4509 const xxh_u8* XXH_RESTRICT input, \
4510 const xxh_u8* XXH_RESTRICT secret, \
4514 for (n = 0; n < nbStripes; n++ ) { \
4515 const xxh_u8* const in = input + n*XXH_STRIPE_LEN; \
4516 XXH_PREFETCH(in + XXH_PREFETCH_DIST); \
4517 XXH3_accumulate_512_##name( \
4520 secret + n*XXH_SECRET_CONSUME_RATE); \
4525XXH_FORCE_INLINE
void XXH_writeLE64(
void* dst, xxh_u64 v64)
4528 XXH_memcpy(dst, &v64,
sizeof(v64));
4536#if !defined (__VMS) \
4537 && (defined (__cplusplus) \
4538 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
4539 typedef int64_t xxh_i64;
4542 typedef long long xxh_i64;
4569#if (XXH_VECTOR == XXH_AVX512) \
4570 || (defined(XXH_DISPATCH_AVX512) && XXH_DISPATCH_AVX512 != 0)
4572#ifndef XXH_TARGET_AVX512
4573# define XXH_TARGET_AVX512
4577XXH3_accumulate_512_avx512(
void* XXH_RESTRICT acc,
4578 const void* XXH_RESTRICT input,
4579 const void* XXH_RESTRICT secret)
4581 __m512i*
const xacc = (__m512i *) acc;
4582 XXH_ASSERT((((
size_t)acc) & 63) == 0);
4583 XXH_STATIC_ASSERT(XXH_STRIPE_LEN ==
sizeof(__m512i));
4587 __m512i
const data_vec = _mm512_loadu_si512 (input);
4589 __m512i
const key_vec = _mm512_loadu_si512 (secret);
4591 __m512i
const data_key = _mm512_xor_si512 (data_vec, key_vec);
4593 __m512i
const data_key_lo = _mm512_srli_epi64 (data_key, 32);
4595 __m512i
const product = _mm512_mul_epu32 (data_key, data_key_lo);
4597 __m512i
const data_swap = _mm512_shuffle_epi32(data_vec, (_MM_PERM_ENUM)_MM_SHUFFLE(1, 0, 3, 2));
4598 __m512i
const sum = _mm512_add_epi64(*xacc, data_swap);
4600 *xacc = _mm512_add_epi64(product, sum);
4627XXH3_scrambleAcc_avx512(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
4629 XXH_ASSERT((((
size_t)acc) & 63) == 0);
4630 XXH_STATIC_ASSERT(XXH_STRIPE_LEN ==
sizeof(__m512i));
4631 { __m512i*
const xacc = (__m512i*) acc;
4632 const __m512i prime32 = _mm512_set1_epi32((
int)
XXH_PRIME32_1);
4635 __m512i
const acc_vec = *xacc;
4636 __m512i
const shifted = _mm512_srli_epi64 (acc_vec, 47);
4638 __m512i
const key_vec = _mm512_loadu_si512 (secret);
4639 __m512i
const data_key = _mm512_ternarylogic_epi32(key_vec, acc_vec, shifted, 0x96 );
4642 __m512i
const data_key_hi = _mm512_srli_epi64 (data_key, 32);
4643 __m512i
const prod_lo = _mm512_mul_epu32 (data_key, prime32);
4644 __m512i
const prod_hi = _mm512_mul_epu32 (data_key_hi, prime32);
4645 *xacc = _mm512_add_epi64(prod_lo, _mm512_slli_epi64(prod_hi, 32));
4650XXH3_initCustomSecret_avx512(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
4652 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 63) == 0);
4653 XXH_STATIC_ASSERT(XXH_SEC_ALIGN == 64);
4654 XXH_ASSERT(((
size_t)customSecret & 63) == 0);
4655 (void)(&XXH_writeLE64);
4656 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE /
sizeof(__m512i);
4657 __m512i
const seed_pos = _mm512_set1_epi64((xxh_i64)seed64);
4658 __m512i
const seed = _mm512_mask_sub_epi64(seed_pos, 0xAA, _mm512_set1_epi8(0), seed_pos);
4660 const __m512i*
const src = (
const __m512i*) ((
const void*) XXH3_kSecret);
4661 __m512i*
const dest = ( __m512i*) customSecret;
4663 XXH_ASSERT(((
size_t)src & 63) == 0);
4664 XXH_ASSERT(((
size_t)dest & 63) == 0);
4665 for (i=0; i < nbRounds; ++i) {
4666 dest[i] = _mm512_add_epi64(_mm512_load_si512(src + i), seed);
4672#if (XXH_VECTOR == XXH_AVX2) \
4673 || (defined(XXH_DISPATCH_AVX2) && XXH_DISPATCH_AVX2 != 0)
4675#ifndef XXH_TARGET_AVX2
4676# define XXH_TARGET_AVX2
4680XXH3_accumulate_512_avx2(
void* XXH_RESTRICT acc,
4681 const void* XXH_RESTRICT input,
4682 const void* XXH_RESTRICT secret)
4684 XXH_ASSERT((((
size_t)acc) & 31) == 0);
4685 { __m256i*
const xacc = (__m256i *) acc;
4688 const __m256i*
const xinput = (
const __m256i *) input;
4691 const __m256i*
const xsecret = (
const __m256i *) secret;
4694 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m256i); i++) {
4696 __m256i
const data_vec = _mm256_loadu_si256 (xinput+i);
4698 __m256i
const key_vec = _mm256_loadu_si256 (xsecret+i);
4700 __m256i
const data_key = _mm256_xor_si256 (data_vec, key_vec);
4702 __m256i
const data_key_lo = _mm256_srli_epi64 (data_key, 32);
4704 __m256i
const product = _mm256_mul_epu32 (data_key, data_key_lo);
4706 __m256i
const data_swap = _mm256_shuffle_epi32(data_vec, _MM_SHUFFLE(1, 0, 3, 2));
4707 __m256i
const sum = _mm256_add_epi64(xacc[i], data_swap);
4709 xacc[i] = _mm256_add_epi64(product, sum);
4715XXH3_scrambleAcc_avx2(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
4717 XXH_ASSERT((((
size_t)acc) & 31) == 0);
4718 { __m256i*
const xacc = (__m256i*) acc;
4721 const __m256i*
const xsecret = (
const __m256i *) secret;
4722 const __m256i prime32 = _mm256_set1_epi32((
int)
XXH_PRIME32_1);
4725 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m256i); i++) {
4727 __m256i
const acc_vec = xacc[i];
4728 __m256i
const shifted = _mm256_srli_epi64 (acc_vec, 47);
4729 __m256i
const data_vec = _mm256_xor_si256 (acc_vec, shifted);
4731 __m256i
const key_vec = _mm256_loadu_si256 (xsecret+i);
4732 __m256i
const data_key = _mm256_xor_si256 (data_vec, key_vec);
4735 __m256i
const data_key_hi = _mm256_srli_epi64 (data_key, 32);
4736 __m256i
const prod_lo = _mm256_mul_epu32 (data_key, prime32);
4737 __m256i
const prod_hi = _mm256_mul_epu32 (data_key_hi, prime32);
4738 xacc[i] = _mm256_add_epi64(prod_lo, _mm256_slli_epi64(prod_hi, 32));
4743XXH_FORCE_INLINE
XXH_TARGET_AVX2 void XXH3_initCustomSecret_avx2(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
4745 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 31) == 0);
4746 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE /
sizeof(__m256i)) == 6);
4747 XXH_STATIC_ASSERT(XXH_SEC_ALIGN <= 64);
4748 (void)(&XXH_writeLE64);
4749 XXH_PREFETCH(customSecret);
4750 { __m256i
const seed = _mm256_set_epi64x((xxh_i64)(0U - seed64), (xxh_i64)seed64, (xxh_i64)(0U - seed64), (xxh_i64)seed64);
4752 const __m256i*
const src = (
const __m256i*) ((
const void*) XXH3_kSecret);
4753 __m256i* dest = ( __m256i*) customSecret;
4755# if defined(__GNUC__) || defined(__clang__)
4761 XXH_COMPILER_GUARD(dest);
4763 XXH_ASSERT(((
size_t)src & 31) == 0);
4764 XXH_ASSERT(((
size_t)dest & 31) == 0);
4767 dest[0] = _mm256_add_epi64(_mm256_load_si256(src+0), seed);
4768 dest[1] = _mm256_add_epi64(_mm256_load_si256(src+1), seed);
4769 dest[2] = _mm256_add_epi64(_mm256_load_si256(src+2), seed);
4770 dest[3] = _mm256_add_epi64(_mm256_load_si256(src+3), seed);
4771 dest[4] = _mm256_add_epi64(_mm256_load_si256(src+4), seed);
4772 dest[5] = _mm256_add_epi64(_mm256_load_si256(src+5), seed);
4779#if (XXH_VECTOR == XXH_SSE2) || defined(XXH_X86DISPATCH)
4781#ifndef XXH_TARGET_SSE2
4782# define XXH_TARGET_SSE2
4786XXH3_accumulate_512_sse2(
void* XXH_RESTRICT acc,
4787 const void* XXH_RESTRICT input,
4788 const void* XXH_RESTRICT secret)
4791 XXH_ASSERT((((
size_t)acc) & 15) == 0);
4792 { __m128i*
const xacc = (__m128i *) acc;
4795 const __m128i*
const xinput = (
const __m128i *) input;
4798 const __m128i*
const xsecret = (
const __m128i *) secret;
4801 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m128i); i++) {
4803 __m128i
const data_vec = _mm_loadu_si128 (xinput+i);
4805 __m128i
const key_vec = _mm_loadu_si128 (xsecret+i);
4807 __m128i
const data_key = _mm_xor_si128 (data_vec, key_vec);
4809 __m128i
const data_key_lo = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1));
4811 __m128i
const product = _mm_mul_epu32 (data_key, data_key_lo);
4813 __m128i
const data_swap = _mm_shuffle_epi32(data_vec, _MM_SHUFFLE(1,0,3,2));
4814 __m128i
const sum = _mm_add_epi64(xacc[i], data_swap);
4816 xacc[i] = _mm_add_epi64(product, sum);
4822XXH3_scrambleAcc_sse2(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
4824 XXH_ASSERT((((
size_t)acc) & 15) == 0);
4825 { __m128i*
const xacc = (__m128i*) acc;
4828 const __m128i*
const xsecret = (
const __m128i *) secret;
4832 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m128i); i++) {
4834 __m128i
const acc_vec = xacc[i];
4835 __m128i
const shifted = _mm_srli_epi64 (acc_vec, 47);
4836 __m128i
const data_vec = _mm_xor_si128 (acc_vec, shifted);
4838 __m128i
const key_vec = _mm_loadu_si128 (xsecret+i);
4839 __m128i
const data_key = _mm_xor_si128 (data_vec, key_vec);
4842 __m128i
const data_key_hi = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1));
4843 __m128i
const prod_lo = _mm_mul_epu32 (data_key, prime32);
4844 __m128i
const prod_hi = _mm_mul_epu32 (data_key_hi, prime32);
4845 xacc[i] = _mm_add_epi64(prod_lo, _mm_slli_epi64(prod_hi, 32));
4850XXH_FORCE_INLINE
XXH_TARGET_SSE2 void XXH3_initCustomSecret_sse2(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
4852 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0);
4853 (void)(&XXH_writeLE64);
4854 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE /
sizeof(__m128i);
4856# if defined(_MSC_VER) && defined(_M_IX86) && _MSC_VER < 1900
4858 XXH_ALIGN(16) const xxh_i64 seed64x2[2] = { (xxh_i64)seed64, (xxh_i64)(0U - seed64) };
4859 __m128i
const seed = _mm_load_si128((__m128i
const*)seed64x2);
4861 __m128i
const seed = _mm_set_epi64x((xxh_i64)(0U - seed64), (xxh_i64)seed64);
4865 const void*
const src16 = XXH3_kSecret;
4866 __m128i* dst16 = (__m128i*) customSecret;
4867# if defined(__GNUC__) || defined(__clang__)
4873 XXH_COMPILER_GUARD(dst16);
4875 XXH_ASSERT(((
size_t)src16 & 15) == 0);
4876 XXH_ASSERT(((
size_t)dst16 & 15) == 0);
4878 for (i=0; i < nbRounds; ++i) {
4879 dst16[i] = _mm_add_epi64(_mm_load_si128((
const __m128i *)src16+i), seed);
4885#if (XXH_VECTOR == XXH_NEON)
4888XXH_FORCE_INLINE
void
4889XXH3_scalarRound(
void* XXH_RESTRICT acc,
void const* XXH_RESTRICT input,
4890 void const* XXH_RESTRICT secret,
size_t lane);
4892XXH_FORCE_INLINE
void
4893XXH3_scalarScrambleRound(
void* XXH_RESTRICT acc,
4894 void const* XXH_RESTRICT secret,
size_t lane);
4920XXH_FORCE_INLINE
void
4921XXH3_accumulate_512_neon(
void* XXH_RESTRICT acc,
4922 const void* XXH_RESTRICT input,
4923 const void* XXH_RESTRICT secret)
4925 XXH_ASSERT((((
size_t)acc) & 15) == 0);
4928 xxh_aliasing_uint64x2_t*
const xacc = (xxh_aliasing_uint64x2_t*) acc;
4930 uint8_t
const* xinput = (
const uint8_t *) input;
4931 uint8_t
const* xsecret = (
const uint8_t *) secret;
4934#ifdef __wasm_simd128__
4952 XXH_COMPILER_GUARD(xsecret);
4956 XXH3_scalarRound(acc, input, secret, i);
4962 uint64x2_t data_vec_1 = XXH_vld1q_u64(xinput + (i * 16));
4963 uint64x2_t data_vec_2 = XXH_vld1q_u64(xinput + ((i+1) * 16));
4965 uint64x2_t key_vec_1 = XXH_vld1q_u64(xsecret + (i * 16));
4966 uint64x2_t key_vec_2 = XXH_vld1q_u64(xsecret + ((i+1) * 16));
4968 uint64x2_t data_swap_1 = vextq_u64(data_vec_1, data_vec_1, 1);
4969 uint64x2_t data_swap_2 = vextq_u64(data_vec_2, data_vec_2, 1);
4971 uint64x2_t data_key_1 = veorq_u64(data_vec_1, key_vec_1);
4972 uint64x2_t data_key_2 = veorq_u64(data_vec_2, key_vec_2);
4987 uint32x4x2_t unzipped = vuzpq_u32(
4988 vreinterpretq_u32_u64(data_key_1),
4989 vreinterpretq_u32_u64(data_key_2)
4992 uint32x4_t data_key_lo = unzipped.val[0];
4994 uint32x4_t data_key_hi = unzipped.val[1];
5002 uint64x2_t sum_1 = XXH_vmlal_low_u32(data_swap_1, data_key_lo, data_key_hi);
5003 uint64x2_t sum_2 = XXH_vmlal_high_u32(data_swap_2, data_key_lo, data_key_hi);
5016 XXH_COMPILER_GUARD_CLANG_NEON(sum_1);
5017 XXH_COMPILER_GUARD_CLANG_NEON(sum_2);
5019 xacc[i] = vaddq_u64(xacc[i], sum_1);
5020 xacc[i+1] = vaddq_u64(xacc[i+1], sum_2);
5025 uint64x2_t data_vec = XXH_vld1q_u64(xinput + (i * 16));
5027 uint64x2_t key_vec = XXH_vld1q_u64(xsecret + (i * 16));
5029 uint64x2_t data_swap = vextq_u64(data_vec, data_vec, 1);
5031 uint64x2_t data_key = veorq_u64(data_vec, key_vec);
5034 uint32x2_t data_key_lo = vmovn_u64(data_key);
5036 uint32x2_t data_key_hi = vshrn_n_u64(data_key, 32);
5038 uint64x2_t sum = vmlal_u32(data_swap, data_key_lo, data_key_hi);
5040 XXH_COMPILER_GUARD_CLANG_NEON(sum);
5042 xacc[i] = vaddq_u64 (xacc[i], sum);
5046XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(neon)
5048XXH_FORCE_INLINE
void
5049XXH3_scrambleAcc_neon(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5051 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5053 { xxh_aliasing_uint64x2_t* xacc = (xxh_aliasing_uint64x2_t*) acc;
5054 uint8_t
const* xsecret = (uint8_t
const*) secret;
5058#ifndef __wasm_simd128__
5062 uint32x4_t
const kPrimeHi = vreinterpretq_u32_u64(vdupq_n_u64((xxh_u64)
XXH_PRIME32_1 << 32));
5067 XXH3_scalarScrambleRound(acc, secret, i);
5071 uint64x2_t acc_vec = xacc[i];
5072 uint64x2_t shifted = vshrq_n_u64(acc_vec, 47);
5073 uint64x2_t data_vec = veorq_u64(acc_vec, shifted);
5076 uint64x2_t key_vec = XXH_vld1q_u64(xsecret + (i * 16));
5077 uint64x2_t data_key = veorq_u64(data_vec, key_vec);
5079#ifdef __wasm_simd128__
5094 uint32x4_t prod_hi = vmulq_u32 (vreinterpretq_u32_u64(data_key), kPrimeHi);
5096 uint32x2_t data_key_lo = vmovn_u64(data_key);
5098 xacc[i] = vmlal_u32(vreinterpretq_u64_u32(prod_hi), data_key_lo, kPrimeLo);
5105#if (XXH_VECTOR == XXH_VSX)
5107XXH_FORCE_INLINE
void
5108XXH3_accumulate_512_vsx(
void* XXH_RESTRICT acc,
5109 const void* XXH_RESTRICT input,
5110 const void* XXH_RESTRICT secret)
5113 xxh_aliasing_u64x2*
const xacc = (xxh_aliasing_u64x2*) acc;
5114 xxh_u8
const*
const xinput = (xxh_u8
const*) input;
5115 xxh_u8
const*
const xsecret = (xxh_u8
const*) secret;
5116 xxh_u64x2
const v32 = { 32, 32 };
5118 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(xxh_u64x2); i++) {
5120 xxh_u64x2
const data_vec = XXH_vec_loadu(xinput + 16*i);
5122 xxh_u64x2
const key_vec = XXH_vec_loadu(xsecret + 16*i);
5123 xxh_u64x2
const data_key = data_vec ^ key_vec;
5125 xxh_u32x4
const shuffled = (xxh_u32x4)vec_rl(data_key, v32);
5127 xxh_u64x2
const product = XXH_vec_mulo((xxh_u32x4)data_key, shuffled);
5129 xxh_u64x2 acc_vec = xacc[i];
5134 acc_vec += vec_permi(data_vec, data_vec, 2);
5136 acc_vec += vec_xxpermdi(data_vec, data_vec, 2);
5141XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(vsx)
5143XXH_FORCE_INLINE
void
5144XXH3_scrambleAcc_vsx(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5146 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5148 { xxh_aliasing_u64x2*
const xacc = (xxh_aliasing_u64x2*) acc;
5149 const xxh_u8*
const xsecret = (
const xxh_u8*) secret;
5151 xxh_u64x2
const v32 = { 32, 32 };
5152 xxh_u64x2
const v47 = { 47, 47 };
5155 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(xxh_u64x2); i++) {
5157 xxh_u64x2
const acc_vec = xacc[i];
5158 xxh_u64x2
const data_vec = acc_vec ^ (acc_vec >> v47);
5161 xxh_u64x2
const key_vec = XXH_vec_loadu(xsecret + 16*i);
5162 xxh_u64x2
const data_key = data_vec ^ key_vec;
5166 xxh_u64x2
const prod_even = XXH_vec_mule((xxh_u32x4)data_key, prime);
5168 xxh_u64x2
const prod_odd = XXH_vec_mulo((xxh_u32x4)data_key, prime);
5169 xacc[i] = prod_odd + (prod_even << v32);
5175#if (XXH_VECTOR == XXH_SVE)
5177XXH_FORCE_INLINE
void
5178XXH3_accumulate_512_sve(
void* XXH_RESTRICT acc,
5179 const void* XXH_RESTRICT input,
5180 const void* XXH_RESTRICT secret)
5182 uint64_t *xacc = (uint64_t *)acc;
5183 const uint64_t *xinput = (
const uint64_t *)(
const void *)input;
5184 const uint64_t *xsecret = (
const uint64_t *)(
const void *)secret;
5185 svuint64_t kSwap = sveor_n_u64_z(svptrue_b64(), svindex_u64(0, 1), 1);
5186 uint64_t element_count = svcntd();
5187 if (element_count >= 8) {
5188 svbool_t mask = svptrue_pat_b64(SV_VL8);
5189 svuint64_t vacc = svld1_u64(mask, xacc);
5191 svst1_u64(mask, xacc, vacc);
5192 }
else if (element_count == 2) {
5193 svbool_t mask = svptrue_pat_b64(SV_VL2);
5194 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5195 svuint64_t acc1 = svld1_u64(mask, xacc + 2);
5196 svuint64_t acc2 = svld1_u64(mask, xacc + 4);
5197 svuint64_t acc3 = svld1_u64(mask, xacc + 6);
5202 svst1_u64(mask, xacc + 0, acc0);
5203 svst1_u64(mask, xacc + 2, acc1);
5204 svst1_u64(mask, xacc + 4, acc2);
5205 svst1_u64(mask, xacc + 6, acc3);
5207 svbool_t mask = svptrue_pat_b64(SV_VL4);
5208 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5209 svuint64_t acc1 = svld1_u64(mask, xacc + 4);
5212 svst1_u64(mask, xacc + 0, acc0);
5213 svst1_u64(mask, xacc + 4, acc1);
5217XXH_FORCE_INLINE
void
5218XXH3_accumulate_sve(xxh_u64* XXH_RESTRICT acc,
5219 const xxh_u8* XXH_RESTRICT input,
5220 const xxh_u8* XXH_RESTRICT secret,
5223 if (nbStripes != 0) {
5224 uint64_t *xacc = (uint64_t *)acc;
5225 const uint64_t *xinput = (
const uint64_t *)(
const void *)input;
5226 const uint64_t *xsecret = (
const uint64_t *)(
const void *)secret;
5227 svuint64_t kSwap = sveor_n_u64_z(svptrue_b64(), svindex_u64(0, 1), 1);
5228 uint64_t element_count = svcntd();
5229 if (element_count >= 8) {
5230 svbool_t mask = svptrue_pat_b64(SV_VL8);
5231 svuint64_t vacc = svld1_u64(mask, xacc + 0);
5234 svprfd(mask, xinput + 128, SV_PLDL1STRM);
5239 }
while (nbStripes != 0);
5241 svst1_u64(mask, xacc + 0, vacc);
5242 }
else if (element_count == 2) {
5243 svbool_t mask = svptrue_pat_b64(SV_VL2);
5244 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5245 svuint64_t acc1 = svld1_u64(mask, xacc + 2);
5246 svuint64_t acc2 = svld1_u64(mask, xacc + 4);
5247 svuint64_t acc3 = svld1_u64(mask, xacc + 6);
5249 svprfd(mask, xinput + 128, SV_PLDL1STRM);
5257 }
while (nbStripes != 0);
5259 svst1_u64(mask, xacc + 0, acc0);
5260 svst1_u64(mask, xacc + 2, acc1);
5261 svst1_u64(mask, xacc + 4, acc2);
5262 svst1_u64(mask, xacc + 6, acc3);
5264 svbool_t mask = svptrue_pat_b64(SV_VL4);
5265 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5266 svuint64_t acc1 = svld1_u64(mask, xacc + 4);
5268 svprfd(mask, xinput + 128, SV_PLDL1STRM);
5274 }
while (nbStripes != 0);
5276 svst1_u64(mask, xacc + 0, acc0);
5277 svst1_u64(mask, xacc + 4, acc1);
5286#if defined(__aarch64__) && (defined(__GNUC__) || defined(__clang__))
5301XXH_FORCE_INLINE xxh_u64
5302XXH_mult32to64_add64(xxh_u64 lhs, xxh_u64 rhs, xxh_u64 acc)
5306 __asm__(
"umaddl %x0, %w1, %w2, %x3" :
"=r" (ret) :
"r" (lhs),
"r" (rhs),
"r" (acc));
5310XXH_FORCE_INLINE xxh_u64
5311XXH_mult32to64_add64(xxh_u64 lhs, xxh_u64 rhs, xxh_u64 acc)
5313 return XXH_mult32to64((xxh_u32)lhs, (xxh_u32)rhs) + acc;
5324XXH_FORCE_INLINE
void
5325XXH3_scalarRound(
void* XXH_RESTRICT acc,
5326 void const* XXH_RESTRICT input,
5327 void const* XXH_RESTRICT secret,
5330 xxh_u64* xacc = (xxh_u64*) acc;
5331 xxh_u8
const* xinput = (xxh_u8
const*) input;
5332 xxh_u8
const* xsecret = (xxh_u8
const*) secret;
5333 XXH_ASSERT(lane < XXH_ACC_NB);
5336 xxh_u64
const data_val = XXH_readLE64(xinput + lane * 8);
5337 xxh_u64
const data_key = data_val ^ XXH_readLE64(xsecret + lane * 8);
5338 xacc[lane ^ 1] += data_val;
5339 xacc[lane] = XXH_mult32to64_add64(data_key , data_key >> 32, xacc[lane]);
5347XXH_FORCE_INLINE
void
5348XXH3_accumulate_512_scalar(
void* XXH_RESTRICT acc,
5349 const void* XXH_RESTRICT input,
5350 const void* XXH_RESTRICT secret)
5354#if defined(__GNUC__) && !defined(__clang__) \
5355 && (defined(__arm__) || defined(__thumb2__)) \
5356 && defined(__ARM_FEATURE_UNALIGNED) \
5357 && XXH_SIZE_OPT <= 0
5358# pragma GCC unroll 8
5360 for (i=0; i < XXH_ACC_NB; i++) {
5361 XXH3_scalarRound(acc, input, secret, i);
5364XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(scalar)
5373XXH_FORCE_INLINE
void
5374XXH3_scalarScrambleRound(
void* XXH_RESTRICT acc,
5375 void const* XXH_RESTRICT secret,
5378 xxh_u64*
const xacc = (xxh_u64*) acc;
5379 const xxh_u8*
const xsecret = (
const xxh_u8*) secret;
5381 XXH_ASSERT(lane < XXH_ACC_NB);
5383 xxh_u64
const key64 = XXH_readLE64(xsecret + lane * 8);
5384 xxh_u64 acc64 = xacc[lane];
5385 acc64 = XXH_xorshift64(acc64, 47);
5396XXH_FORCE_INLINE
void
5397XXH3_scrambleAcc_scalar(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5400 for (i=0; i < XXH_ACC_NB; i++) {
5401 XXH3_scalarScrambleRound(acc, secret, i);
5405XXH_FORCE_INLINE
void
5406XXH3_initCustomSecret_scalar(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
5413 const xxh_u8* kSecretPtr = XXH3_kSecret;
5414 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0);
5416#if defined(__GNUC__) && defined(__aarch64__)
5449 XXH_COMPILER_GUARD(kSecretPtr);
5451 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE / 16;
5453 for (i=0; i < nbRounds; i++) {
5460 xxh_u64 lo = XXH_readLE64(kSecretPtr + 16*i) + seed64;
5461 xxh_u64 hi = XXH_readLE64(kSecretPtr + 16*i + 8) - seed64;
5462 XXH_writeLE64((xxh_u8*)customSecret + 16*i, lo);
5463 XXH_writeLE64((xxh_u8*)customSecret + 16*i + 8, hi);
5468typedef void (*XXH3_f_accumulate)(xxh_u64* XXH_RESTRICT,
const xxh_u8* XXH_RESTRICT,
const xxh_u8* XXH_RESTRICT, size_t);
5469typedef void (*XXH3_f_scrambleAcc)(
void* XXH_RESTRICT,
const void*);
5470typedef void (*XXH3_f_initCustomSecret)(
void* XXH_RESTRICT, xxh_u64);
5473#if (XXH_VECTOR == XXH_AVX512)
5475#define XXH3_accumulate_512 XXH3_accumulate_512_avx512
5476#define XXH3_accumulate XXH3_accumulate_avx512
5477#define XXH3_scrambleAcc XXH3_scrambleAcc_avx512
5478#define XXH3_initCustomSecret XXH3_initCustomSecret_avx512
5480#elif (XXH_VECTOR == XXH_AVX2)
5482#define XXH3_accumulate_512 XXH3_accumulate_512_avx2
5483#define XXH3_accumulate XXH3_accumulate_avx2
5484#define XXH3_scrambleAcc XXH3_scrambleAcc_avx2
5485#define XXH3_initCustomSecret XXH3_initCustomSecret_avx2
5487#elif (XXH_VECTOR == XXH_SSE2)
5489#define XXH3_accumulate_512 XXH3_accumulate_512_sse2
5490#define XXH3_accumulate XXH3_accumulate_sse2
5491#define XXH3_scrambleAcc XXH3_scrambleAcc_sse2
5492#define XXH3_initCustomSecret XXH3_initCustomSecret_sse2
5494#elif (XXH_VECTOR == XXH_NEON)
5496#define XXH3_accumulate_512 XXH3_accumulate_512_neon
5497#define XXH3_accumulate XXH3_accumulate_neon
5498#define XXH3_scrambleAcc XXH3_scrambleAcc_neon
5499#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
5501#elif (XXH_VECTOR == XXH_VSX)
5503#define XXH3_accumulate_512 XXH3_accumulate_512_vsx
5504#define XXH3_accumulate XXH3_accumulate_vsx
5505#define XXH3_scrambleAcc XXH3_scrambleAcc_vsx
5506#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
5508#elif (XXH_VECTOR == XXH_SVE)
5509#define XXH3_accumulate_512 XXH3_accumulate_512_sve
5510#define XXH3_accumulate XXH3_accumulate_sve
5511#define XXH3_scrambleAcc XXH3_scrambleAcc_scalar
5512#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
5516#define XXH3_accumulate_512 XXH3_accumulate_512_scalar
5517#define XXH3_accumulate XXH3_accumulate_scalar
5518#define XXH3_scrambleAcc XXH3_scrambleAcc_scalar
5519#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
5523#if XXH_SIZE_OPT >= 1
5524# undef XXH3_initCustomSecret
5525# define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
5528XXH_FORCE_INLINE
void
5529XXH3_hashLong_internal_loop(xxh_u64* XXH_RESTRICT acc,
5530 const xxh_u8* XXH_RESTRICT input,
size_t len,
5531 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
5532 XXH3_f_accumulate f_acc,
5533 XXH3_f_scrambleAcc f_scramble)
5535 size_t const nbStripesPerBlock = (secretSize - XXH_STRIPE_LEN) / XXH_SECRET_CONSUME_RATE;
5536 size_t const block_len = XXH_STRIPE_LEN * nbStripesPerBlock;
5537 size_t const nb_blocks = (len - 1) / block_len;
5543 for (n = 0; n < nb_blocks; n++) {
5544 f_acc(acc, input + n*block_len, secret, nbStripesPerBlock);
5545 f_scramble(acc, secret + secretSize - XXH_STRIPE_LEN);
5549 XXH_ASSERT(len > XXH_STRIPE_LEN);
5550 {
size_t const nbStripes = ((len - 1) - (block_len * nb_blocks)) / XXH_STRIPE_LEN;
5551 XXH_ASSERT(nbStripes <= (secretSize / XXH_SECRET_CONSUME_RATE));
5552 f_acc(acc, input + nb_blocks*block_len, secret, nbStripes);
5555 {
const xxh_u8*
const p = input + len - XXH_STRIPE_LEN;
5556#define XXH_SECRET_LASTACC_START 7
5557 XXH3_accumulate_512(acc, p, secret + secretSize - XXH_STRIPE_LEN - XXH_SECRET_LASTACC_START);
5561XXH_FORCE_INLINE xxh_u64
5562XXH3_mix2Accs(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret)
5564 return XXH3_mul128_fold64(
5565 acc[0] ^ XXH_readLE64(secret),
5566 acc[1] ^ XXH_readLE64(secret+8) );
5570XXH3_mergeAccs(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret, xxh_u64 start)
5572 xxh_u64 result64 = start;
5575 for (i = 0; i < 4; i++) {
5576 result64 += XXH3_mix2Accs(acc+2*i, secret + 16*i);
5577#if defined(__clang__) \
5578 && (defined(__arm__) || defined(__thumb__)) \
5579 && (defined(__ARM_NEON) || defined(__ARM_NEON__)) \
5580 && !defined(XXH_ENABLE_AUTOVECTORIZE)
5589 XXH_COMPILER_GUARD(result64);
5593 return XXH3_avalanche(result64);
5596#define XXH3_INIT_ACC { XXH_PRIME32_3, XXH_PRIME64_1, XXH_PRIME64_2, XXH_PRIME64_3, \
5597 XXH_PRIME64_4, XXH_PRIME32_2, XXH_PRIME64_5, XXH_PRIME32_1 }
5600XXH3_hashLong_64b_internal(
const void* XXH_RESTRICT input,
size_t len,
5601 const void* XXH_RESTRICT secret,
size_t secretSize,
5602 XXH3_f_accumulate f_acc,
5603 XXH3_f_scrambleAcc f_scramble)
5605 XXH_ALIGN(
XXH_ACC_ALIGN) xxh_u64 acc[XXH_ACC_NB] = XXH3_INIT_ACC;
5607 XXH3_hashLong_internal_loop(acc, (
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretSize, f_acc, f_scramble);
5610 XXH_STATIC_ASSERT(
sizeof(acc) == 64);
5612#define XXH_SECRET_MERGEACCS_START 11
5613 XXH_ASSERT(secretSize >=
sizeof(acc) + XXH_SECRET_MERGEACCS_START);
5614 return XXH3_mergeAccs(acc, (
const xxh_u8*)secret + XXH_SECRET_MERGEACCS_START, (xxh_u64)len *
XXH_PRIME64_1);
5625XXH3_hashLong_64b_withSecret(
const void* XXH_RESTRICT input,
size_t len,
5626 XXH64_hash_t seed64,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
5629 return XXH3_hashLong_64b_internal(input, len, secret, secretLen, XXH3_accumulate, XXH3_scrambleAcc);
5639XXH3_hashLong_64b_default(
const void* XXH_RESTRICT input,
size_t len,
5640 XXH64_hash_t seed64,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
5642 (void)seed64; (void)secret; (void)secretLen;
5643 return XXH3_hashLong_64b_internal(input, len, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_accumulate, XXH3_scrambleAcc);
5658XXH3_hashLong_64b_withSeed_internal(
const void* input,
size_t len,
5660 XXH3_f_accumulate f_acc,
5661 XXH3_f_scrambleAcc f_scramble,
5662 XXH3_f_initCustomSecret f_initSec)
5664#if XXH_SIZE_OPT <= 0
5666 return XXH3_hashLong_64b_internal(input, len,
5667 XXH3_kSecret,
sizeof(XXH3_kSecret),
5670 { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
5671 f_initSec(secret, seed);
5672 return XXH3_hashLong_64b_internal(input, len, secret,
sizeof(secret),
5681XXH3_hashLong_64b_withSeed(
const void* XXH_RESTRICT input,
size_t len,
5682 XXH64_hash_t seed,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
5684 (void)secret; (void)secretLen;
5685 return XXH3_hashLong_64b_withSeed_internal(input, len, seed,
5686 XXH3_accumulate, XXH3_scrambleAcc, XXH3_initCustomSecret);
5690typedef XXH64_hash_t (*XXH3_hashLong64_f)(
const void* XXH_RESTRICT, size_t,
5694XXH3_64bits_internal(
const void* XXH_RESTRICT input,
size_t len,
5695 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen,
5696 XXH3_hashLong64_f f_hashLong)
5707 return XXH3_len_0to16_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, seed64);
5709 return XXH3_len_17to128_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
5710 if (len <= XXH3_MIDSIZE_MAX)
5711 return XXH3_len_129to240_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
5712 return f_hashLong(input, len, seed64, (
const xxh_u8*)secret, secretLen);
5721 return XXH3_64bits_internal(input, length, 0, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_hashLong_64b_default);
5728 return XXH3_64bits_internal(input, length, 0, secret, secretSize, XXH3_hashLong_64b_withSecret);
5735 return XXH3_64bits_internal(input, length, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_hashLong_64b_withSeed);
5741 if (length <= XXH3_MIDSIZE_MAX)
5742 return XXH3_64bits_internal(input, length, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), NULL);
5743 return XXH3_hashLong_64b_withSecret(input, length, seed, (
const xxh_u8*)secret, secretSize);
5748#ifndef XXH_NO_STREAM
5772static XXH_MALLOCF
void* XXH_alignedMalloc(
size_t s,
size_t align)
5774 XXH_ASSERT(align <= 128 && align >= 8);
5775 XXH_ASSERT((align & (align-1)) == 0);
5776 XXH_ASSERT(s != 0 && s < (s + align));
5778 xxh_u8* base = (xxh_u8*)XXH_malloc(s + align);
5786 size_t offset = align - ((size_t)base & (align - 1));
5788 xxh_u8* ptr = base + offset;
5790 XXH_ASSERT((
size_t)ptr % align == 0);
5793 ptr[-1] = (xxh_u8)offset;
5803static void XXH_alignedFree(
void* p)
5806 xxh_u8* ptr = (xxh_u8*)p;
5808 xxh_u8 offset = ptr[-1];
5810 xxh_u8* base = ptr - offset;
5824 if (state==NULL)
return NULL;
5839 XXH_alignedFree(statePtr);
5847 XXH_memcpy(dst_state, src_state,
sizeof(*dst_state));
5853 const void* secret,
size_t secretSize)
5855 size_t const initStart = offsetof(
XXH3_state_t, bufferedSize);
5856 size_t const initLength = offsetof(
XXH3_state_t, nbStripesPerBlock) - initStart;
5857 XXH_ASSERT(offsetof(
XXH3_state_t, nbStripesPerBlock) > initStart);
5858 XXH_ASSERT(statePtr != NULL);
5860 memset((
char*)statePtr + initStart, 0, initLength);
5869 statePtr->
seed = seed;
5870 statePtr->
useSeed = (seed != 0);
5871 statePtr->
extSecret = (
const unsigned char*)secret;
5873 statePtr->
secretLimit = secretSize - XXH_STRIPE_LEN;
5882 XXH3_reset_internal(statePtr, 0, XXH3_kSecret, XXH_SECRET_DEFAULT_SIZE);
5891 XXH3_reset_internal(statePtr, 0, secret, secretSize);
5903 if ((seed != statePtr->seed) || (statePtr->extSecret != NULL))
5904 XXH3_initCustomSecret(statePtr->customSecret, seed);
5905 XXH3_reset_internal(statePtr, seed, NULL, XXH_SECRET_DEFAULT_SIZE);
5916 XXH3_reset_internal(statePtr, seed64, secret, secretSize);
5917 statePtr->useSeed = 1;
5938XXH_FORCE_INLINE
const xxh_u8 *
5939XXH3_consumeStripes(xxh_u64* XXH_RESTRICT acc,
5940 size_t* XXH_RESTRICT nbStripesSoFarPtr,
size_t nbStripesPerBlock,
5941 const xxh_u8* XXH_RESTRICT input,
size_t nbStripes,
5942 const xxh_u8* XXH_RESTRICT secret,
size_t secretLimit,
5943 XXH3_f_accumulate f_acc,
5944 XXH3_f_scrambleAcc f_scramble)
5946 const xxh_u8* initialSecret = secret + *nbStripesSoFarPtr * XXH_SECRET_CONSUME_RATE;
5948 if (nbStripes >= (nbStripesPerBlock - *nbStripesSoFarPtr)) {
5950 size_t nbStripesThisIter = nbStripesPerBlock - *nbStripesSoFarPtr;
5954 f_acc(acc, input, initialSecret, nbStripesThisIter);
5955 f_scramble(acc, secret + secretLimit);
5956 input += nbStripesThisIter * XXH_STRIPE_LEN;
5957 nbStripes -= nbStripesThisIter;
5959 nbStripesThisIter = nbStripesPerBlock;
5960 initialSecret = secret;
5961 }
while (nbStripes >= nbStripesPerBlock);
5962 *nbStripesSoFarPtr = 0;
5965 if (nbStripes > 0) {
5966 f_acc(acc, input, initialSecret, nbStripes);
5967 input += nbStripes * XXH_STRIPE_LEN;
5968 *nbStripesSoFarPtr += nbStripes;
5974#ifndef XXH3_STREAM_USE_STACK
5975# if XXH_SIZE_OPT <= 0 && !defined(__clang__)
5976# define XXH3_STREAM_USE_STACK 1
5984 const xxh_u8* XXH_RESTRICT input,
size_t len,
5985 XXH3_f_accumulate f_acc,
5986 XXH3_f_scrambleAcc f_scramble)
5989 XXH_ASSERT(len == 0);
5993 XXH_ASSERT(state != NULL);
5994 {
const xxh_u8*
const bEnd = input + len;
5995 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
5996#if defined(XXH3_STREAM_USE_STACK) && XXH3_STREAM_USE_STACK >= 1
6002 XXH_memcpy(acc, state->acc,
sizeof(acc));
6004 xxh_u64* XXH_RESTRICT
const acc = state->acc;
6006 state->totalLen += len;
6010 if (len <= XXH3_INTERNALBUFFER_SIZE - state->bufferedSize) {
6011 XXH_memcpy(state->buffer + state->bufferedSize, input, len);
6017 #define XXH3_INTERNALBUFFER_STRIPES (XXH3_INTERNALBUFFER_SIZE / XXH_STRIPE_LEN)
6024 if (state->bufferedSize) {
6026 XXH_memcpy(state->buffer + state->bufferedSize, input, loadSize);
6028 XXH3_consumeStripes(acc,
6029 &state->nbStripesSoFar, state->nbStripesPerBlock,
6030 state->buffer, XXH3_INTERNALBUFFER_STRIPES,
6031 secret, state->secretLimit,
6033 state->bufferedSize = 0;
6035 XXH_ASSERT(input < bEnd);
6037 size_t nbStripes = (size_t)(bEnd - 1 - input) / XXH_STRIPE_LEN;
6038 input = XXH3_consumeStripes(acc,
6039 &state->nbStripesSoFar, state->nbStripesPerBlock,
6041 secret, state->secretLimit,
6043 XXH_memcpy(state->buffer +
sizeof(state->buffer) - XXH_STRIPE_LEN, input - XXH_STRIPE_LEN, XXH_STRIPE_LEN);
6047 XXH_ASSERT(input < bEnd);
6049 XXH_ASSERT(state->bufferedSize == 0);
6050 XXH_memcpy(state->buffer, input, (
size_t)(bEnd-input));
6052#if defined(XXH3_STREAM_USE_STACK) && XXH3_STREAM_USE_STACK >= 1
6054 XXH_memcpy(state->acc, acc,
sizeof(acc));
6065 return XXH3_update(state, (
const xxh_u8*)input, len,
6066 XXH3_accumulate, XXH3_scrambleAcc);
6070XXH_FORCE_INLINE
void
6073 const unsigned char* secret)
6075 xxh_u8 lastStripe[XXH_STRIPE_LEN];
6076 const xxh_u8* lastStripePtr;
6082 XXH_memcpy(acc, state->
acc,
sizeof(state->
acc));
6085 size_t const nbStripes = (state->
bufferedSize - 1) / XXH_STRIPE_LEN;
6087 XXH3_consumeStripes(acc,
6089 state->
buffer, nbStripes,
6091 XXH3_accumulate, XXH3_scrambleAcc);
6095 size_t const catchupSize = XXH_STRIPE_LEN - state->
bufferedSize;
6097 XXH_memcpy(lastStripe, state->
buffer +
sizeof(state->
buffer) - catchupSize, catchupSize);
6099 lastStripePtr = lastStripe;
6102 XXH3_accumulate_512(acc,
6104 secret + state->
secretLimit - XXH_SECRET_LASTACC_START);
6110 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
6111 if (state->totalLen > XXH3_MIDSIZE_MAX) {
6113 XXH3_digest_long(acc, state, secret);
6114 return XXH3_mergeAccs(acc,
6115 secret + XXH_SECRET_MERGEACCS_START,
6122 secret, state->secretLimit + XXH_STRIPE_LEN);
6145XXH3_len_1to3_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
6148 XXH_ASSERT(input != NULL);
6149 XXH_ASSERT(1 <= len && len <= 3);
6150 XXH_ASSERT(secret != NULL);
6156 { xxh_u8
const c1 = input[0];
6157 xxh_u8
const c2 = input[len >> 1];
6158 xxh_u8
const c3 = input[len - 1];
6159 xxh_u32
const combinedl = ((xxh_u32)c1 <<16) | ((xxh_u32)c2 << 24)
6160 | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8);
6161 xxh_u32
const combinedh = XXH_rotl32(XXH_swap32(combinedl), 13);
6162 xxh_u64
const bitflipl = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed;
6163 xxh_u64
const bitfliph = (XXH_readLE32(secret+8) ^ XXH_readLE32(secret+12)) - seed;
6164 xxh_u64
const keyed_lo = (xxh_u64)combinedl ^ bitflipl;
6165 xxh_u64
const keyed_hi = (xxh_u64)combinedh ^ bitfliph;
6167 h128.
low64 = XXH64_avalanche(keyed_lo);
6168 h128.
high64 = XXH64_avalanche(keyed_hi);
6174XXH3_len_4to8_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
6176 XXH_ASSERT(input != NULL);
6177 XXH_ASSERT(secret != NULL);
6178 XXH_ASSERT(4 <= len && len <= 8);
6179 seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32;
6180 { xxh_u32
const input_lo = XXH_readLE32(input);
6181 xxh_u32
const input_hi = XXH_readLE32(input + len - 4);
6182 xxh_u64
const input_64 = input_lo + ((xxh_u64)input_hi << 32);
6183 xxh_u64
const bitflip = (XXH_readLE64(secret+16) ^ XXH_readLE64(secret+24)) + seed;
6184 xxh_u64
const keyed = input_64 ^ bitflip;
6193 m128.
low64 *= PRIME_MX2;
6201XXH3_len_9to16_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
6203 XXH_ASSERT(input != NULL);
6204 XXH_ASSERT(secret != NULL);
6205 XXH_ASSERT(9 <= len && len <= 16);
6206 { xxh_u64
const bitflipl = (XXH_readLE64(secret+32) ^ XXH_readLE64(secret+40)) - seed;
6207 xxh_u64
const bitfliph = (XXH_readLE64(secret+48) ^ XXH_readLE64(secret+56)) + seed;
6208 xxh_u64
const input_lo = XXH_readLE64(input);
6209 xxh_u64 input_hi = XXH_readLE64(input + len - 8);
6215 m128.
low64 += (xxh_u64)(len - 1) << 54;
6216 input_hi ^= bitfliph;
6224 if (
sizeof(
void *) <
sizeof(xxh_u64)) {
6231 m128.
high64 += (input_hi & 0xFFFFFFFF00000000ULL) + XXH_mult32to64((xxh_u32)input_hi,
XXH_PRIME32_2);
6276XXH3_len_0to16_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
6278 XXH_ASSERT(len <= 16);
6279 {
if (len > 8)
return XXH3_len_9to16_128b(input, len, secret, seed);
6280 if (len >= 4)
return XXH3_len_4to8_128b(input, len, secret, seed);
6281 if (len)
return XXH3_len_1to3_128b(input, len, secret, seed);
6283 xxh_u64
const bitflipl = XXH_readLE64(secret+64) ^ XXH_readLE64(secret+72);
6284 xxh_u64
const bitfliph = XXH_readLE64(secret+80) ^ XXH_readLE64(secret+88);
6285 h128.
low64 = XXH64_avalanche(seed ^ bitflipl);
6286 h128.
high64 = XXH64_avalanche( seed ^ bitfliph);
6295XXH128_mix32B(
XXH128_hash_t acc,
const xxh_u8* input_1,
const xxh_u8* input_2,
6298 acc.
low64 += XXH3_mix16B (input_1, secret+0, seed);
6299 acc.
low64 ^= XXH_readLE64(input_2) + XXH_readLE64(input_2 + 8);
6300 acc.
high64 += XXH3_mix16B (input_2, secret+16, seed);
6301 acc.
high64 ^= XXH_readLE64(input_1) + XXH_readLE64(input_1 + 8);
6307XXH3_len_17to128_128b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
6308 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
6312 XXH_ASSERT(16 < len && len <= 128);
6318#if XXH_SIZE_OPT >= 1
6321 unsigned int i = (
unsigned int)(len - 1) / 32;
6323 acc = XXH128_mix32B(acc, input+16*i, input+len-16*(i+1), secret+32*i, seed);
6330 acc = XXH128_mix32B(acc, input+48, input+len-64, secret+96, seed);
6332 acc = XXH128_mix32B(acc, input+32, input+len-48, secret+64, seed);
6334 acc = XXH128_mix32B(acc, input+16, input+len-32, secret+32, seed);
6336 acc = XXH128_mix32B(acc, input, input+len-16, secret, seed);
6351XXH3_len_129to240_128b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
6352 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
6356 XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX);
6368 for (i = 32; i < 160; i += 32) {
6369 acc = XXH128_mix32B(acc,
6382 for (i=160; i <= len; i += 32) {
6383 acc = XXH128_mix32B(acc,
6386 secret + XXH3_MIDSIZE_STARTOFFSET + i - 160,
6390 acc = XXH128_mix32B(acc,
6409XXH3_hashLong_128b_internal(
const void* XXH_RESTRICT input,
size_t len,
6410 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
6411 XXH3_f_accumulate f_acc,
6412 XXH3_f_scrambleAcc f_scramble)
6414 XXH_ALIGN(
XXH_ACC_ALIGN) xxh_u64 acc[XXH_ACC_NB] = XXH3_INIT_ACC;
6416 XXH3_hashLong_internal_loop(acc, (
const xxh_u8*)input, len, secret, secretSize, f_acc, f_scramble);
6419 XXH_STATIC_ASSERT(
sizeof(acc) == 64);
6420 XXH_ASSERT(secretSize >=
sizeof(acc) + XXH_SECRET_MERGEACCS_START);
6422 h128.
low64 = XXH3_mergeAccs(acc,
6423 secret + XXH_SECRET_MERGEACCS_START,
6425 h128.
high64 = XXH3_mergeAccs(acc,
6427 -
sizeof(acc) - XXH_SECRET_MERGEACCS_START,
6437XXH3_hashLong_128b_default(
const void* XXH_RESTRICT input,
size_t len,
6439 const void* XXH_RESTRICT secret,
size_t secretLen)
6441 (void)seed64; (void)secret; (void)secretLen;
6442 return XXH3_hashLong_128b_internal(input, len, XXH3_kSecret,
sizeof(XXH3_kSecret),
6443 XXH3_accumulate, XXH3_scrambleAcc);
6454XXH3_hashLong_128b_withSecret(
const void* XXH_RESTRICT input,
size_t len,
6456 const void* XXH_RESTRICT secret,
size_t secretLen)
6459 return XXH3_hashLong_128b_internal(input, len, (
const xxh_u8*)secret, secretLen,
6460 XXH3_accumulate, XXH3_scrambleAcc);
6464XXH3_hashLong_128b_withSeed_internal(
const void* XXH_RESTRICT input,
size_t len,
6466 XXH3_f_accumulate f_acc,
6467 XXH3_f_scrambleAcc f_scramble,
6468 XXH3_f_initCustomSecret f_initSec)
6471 return XXH3_hashLong_128b_internal(input, len,
6472 XXH3_kSecret,
sizeof(XXH3_kSecret),
6474 { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
6475 f_initSec(secret, seed64);
6476 return XXH3_hashLong_128b_internal(input, len, (
const xxh_u8*)secret,
sizeof(secret),
6485XXH3_hashLong_128b_withSeed(
const void* input,
size_t len,
6486 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen)
6488 (void)secret; (void)secretLen;
6489 return XXH3_hashLong_128b_withSeed_internal(input, len, seed64,
6490 XXH3_accumulate, XXH3_scrambleAcc, XXH3_initCustomSecret);
6493typedef XXH128_hash_t (*XXH3_hashLong128_f)(
const void* XXH_RESTRICT, size_t,
6497XXH3_128bits_internal(
const void* input,
size_t len,
6498 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen,
6499 XXH3_hashLong128_f f_hl128)
6509 return XXH3_len_0to16_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, seed64);
6511 return XXH3_len_17to128_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
6512 if (len <= XXH3_MIDSIZE_MAX)
6513 return XXH3_len_129to240_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
6514 return f_hl128(input, len, seed64, secret, secretLen);
6523 return XXH3_128bits_internal(input, len, 0,
6524 XXH3_kSecret,
sizeof(XXH3_kSecret),
6525 XXH3_hashLong_128b_default);
6532 return XXH3_128bits_internal(input, len, 0,
6533 (
const xxh_u8*)secret, secretSize,
6534 XXH3_hashLong_128b_withSecret);
6541 return XXH3_128bits_internal(input, len, seed,
6542 XXH3_kSecret,
sizeof(XXH3_kSecret),
6543 XXH3_hashLong_128b_withSeed);
6550 if (len <= XXH3_MIDSIZE_MAX)
6551 return XXH3_128bits_internal(input, len, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), NULL);
6552 return XXH3_hashLong_128b_withSecret(input, len, seed, secret, secretSize);
6564#ifndef XXH_NO_STREAM
6608 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
6609 if (state->totalLen > XXH3_MIDSIZE_MAX) {
6611 XXH3_digest_long(acc, state, secret);
6612 XXH_ASSERT(state->secretLimit + XXH_STRIPE_LEN >=
sizeof(acc) + XXH_SECRET_MERGEACCS_START);
6614 h128.
low64 = XXH3_mergeAccs(acc,
6615 secret + XXH_SECRET_MERGEACCS_START,
6617 h128.
high64 = XXH3_mergeAccs(acc,
6618 secret + state->secretLimit + XXH_STRIPE_LEN
6619 -
sizeof(acc) - XXH_SECRET_MERGEACCS_START,
6628 secret, state->secretLimit + XXH_STRIPE_LEN);
6640 return !(memcmp(&h1, &h2,
sizeof(h1)));
6654 if (hcmp)
return hcmp;
6670 XXH_memcpy((
char*)dst +
sizeof(hash.
high64), &hash.
low64,
sizeof(hash.
low64));
6678 h.
high64 = XXH_readBE64(src);
6679 h.
low64 = XXH_readBE64(src->digest + 8);
6689#define XXH_MIN(x, y) (((x) > (y)) ? (y) : (x))
6691XXH_FORCE_INLINE
void XXH3_combine16(
void* dst,
XXH128_hash_t h128)
6693 XXH_writeLE64( dst, XXH_readLE64(dst) ^ h128.
low64 );
6694 XXH_writeLE64( (
char*)dst+8, XXH_readLE64((
char*)dst+8) ^ h128.
high64 );
6699XXH3_generateSecret(XXH_NOESCAPE
void* secretBuffer,
size_t secretSize, XXH_NOESCAPE
const void* customSeed,
size_t customSeedSize)
6701#if (XXH_DEBUGLEVEL >= 1)
6702 XXH_ASSERT(secretBuffer != NULL);
6706 if (secretBuffer == NULL)
return XXH_ERROR;
6710 if (customSeedSize == 0) {
6711 customSeed = XXH3_kSecret;
6712 customSeedSize = XXH_SECRET_DEFAULT_SIZE;
6714#if (XXH_DEBUGLEVEL >= 1)
6715 XXH_ASSERT(customSeed != NULL);
6717 if (customSeed == NULL)
return XXH_ERROR;
6722 while (pos < secretSize) {
6723 size_t const toCopy = XXH_MIN((secretSize - pos), customSeedSize);
6724 memcpy((
char*)secretBuffer + pos, customSeed, toCopy);
6728 {
size_t const nbSeg16 = secretSize / 16;
6732 for (n=0; n<nbSeg16; n++) {
6734 XXH3_combine16((
char*)secretBuffer + n*16, h128);
6746 XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
6747 XXH3_initCustomSecret(secret, seed);
6748 XXH_ASSERT(secretBuffer != NULL);
6749 memcpy(secretBuffer, secret, XXH_SECRET_DEFAULT_SIZE);
6755#if XXH_VECTOR == XXH_AVX2 \
6756 && defined(__GNUC__) && !defined(__clang__) \
6757 && defined(__OPTIMIZE__) && XXH_SIZE_OPT <= 0
6758# pragma GCC pop_options
6771#if defined (__cplusplus)
XXH_errorcode XXH32_reset(XXH32_state_t *statePtr, XXH32_hash_t seed)
Resets an XXH32_state_t to begin a new hash.
Definition xxhash.h:2833
XXH32_hash_t XXH32(const void *input, size_t length, XXH32_hash_t seed)
Calculates the 32-bit hash of input using xxHash32.
Definition xxhash.h:2792
XXH_errorcode XXH32_update(XXH32_state_t *statePtr, const void *input, size_t length)
Consumes a block of input to an XXH32_state_t.
Definition xxhash.h:2847
XXH32_state_t * XXH32_createState(void)
Allocates an XXH32_state_t.
Definition xxhash.h:2815
XXH_errorcode XXH32_freeState(XXH32_state_t *statePtr)
Frees an XXH32_state_t.
Definition xxhash.h:2820
void XXH32_canonicalFromHash(XXH32_canonical_t *dst, XXH32_hash_t hash)
Converts an XXH32_hash_t to a big endian XXH32_canonical_t.
Definition xxhash.h:2936
XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t *src)
Converts an XXH32_canonical_t to a native XXH32_hash_t.
Definition xxhash.h:2943
XXH32_hash_t XXH32_digest(const XXH32_state_t *statePtr)
Returns the calculated hash value from an XXH32_state_t.
Definition xxhash.h:2901
void XXH32_copyState(XXH32_state_t *dst_state, const XXH32_state_t *src_state)
Copies one XXH32_state_t to another.
Definition xxhash.h:2827
#define XXH_PRIME32_2
Definition xxhash.h:2561
#define XXH_PRIME32_1
Definition xxhash.h:2560
#define XXH_PRIME32_5
Definition xxhash.h:2564
#define XXH_PRIME32_3
Definition xxhash.h:2562
void XXH128_canonicalFromHash(XXH_NOESCAPE XXH128_canonical_t *dst, XXH128_hash_t hash)
Converts an XXH128_hash_t to a big endian XXH128_canonical_t.
Definition xxhash.h:6662
XXH_errorcode XXH3_128bits_update(XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *input, size_t length)
Consumes a block of input to an XXH3_state_t.
Definition xxhash.h:6600
XXH64_hash_t XXH3_64bits(XXH_NOESCAPE const void *input, size_t length)
64-bit unseeded variant of XXH3.
Definition xxhash.h:5719
XXH_errorcode XXH3_64bits_reset_withSecret(XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *secret, size_t secretSize)
Definition xxhash.h:5888
XXH128_hash_t XXH3_128bits_digest(XXH_NOESCAPE const XXH3_state_t *statePtr)
Returns the calculated XXH3 128-bit hash value from an XXH3_state_t.
Definition xxhash.h:6606
XXH_errorcode XXH3_128bits_reset_withSecret(XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *secret, size_t secretSize)
Custom secret 128-bit variant of XXH3.
Definition xxhash.h:6579
XXH128_hash_t XXH3_128bits_withSecret(XXH_NOESCAPE const void *data, size_t len, XXH_NOESCAPE const void *secret, size_t secretSize)
Custom secret 128-bit variant of XXH3.
Definition xxhash.h:6530
XXH_errorcode XXH3_64bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *secret, size_t secretSize, XXH64_hash_t seed64)
Definition xxhash.h:5911
XXH128_hash_t XXH3_128bits_withSeed(XXH_NOESCAPE const void *data, size_t len, XXH64_hash_t seed)
Seeded 128-bit variant of XXH3.
Definition xxhash.h:6539
XXH64_hash_t XXH3_64bits_withSeed(XXH_NOESCAPE const void *input, size_t length, XXH64_hash_t seed)
64-bit seeded variant of XXH3
Definition xxhash.h:5733
XXH_errorcode XXH3_128bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *secret, size_t secretSize, XXH64_hash_t seed64)
Definition xxhash.h:6593
int XXH128_cmp(XXH_NOESCAPE const void *h128_1, XXH_NOESCAPE const void *h128_2)
Compares two XXH128_hash_t This comparator is compatible with stdlib's qsort()/bsearch().
Definition xxhash.h:6648
XXH128_hash_t XXH128(XXH_NOESCAPE const void *data, size_t len, XXH64_hash_t seed)
Definition xxhash.h:6557
void XXH3_copyState(XXH_NOESCAPE XXH3_state_t *dst_state, XXH_NOESCAPE const XXH3_state_t *src_state)
Copies one XXH3_state_t to another.
Definition xxhash.h:5845
XXH128_hash_t XXH3_128bits_withSecretandSeed(XXH_NOESCAPE const void *input, size_t length, XXH_NOESCAPE const void *secret, size_t secretSize, XXH64_hash_t seed64)
Definition xxhash.h:6548
XXH_errorcode XXH3_128bits_reset_withSeed(XXH_NOESCAPE XXH3_state_t *statePtr, XXH64_hash_t seed)
Resets an XXH3_state_t with 64-bit seed to begin a new hash.
Definition xxhash.h:6586
XXH128_hash_t XXH3_128bits(XXH_NOESCAPE const void *data, size_t len)
Unseeded 128-bit variant of XXH3.
Definition xxhash.h:6521
XXH64_hash_t XXH3_64bits_withSecret(XXH_NOESCAPE const void *data, size_t len, XXH_NOESCAPE const void *secret, size_t secretSize)
64-bit variant of XXH3 with a custom "secret".
Definition xxhash.h:5726
XXH_errorcode XXH3_generateSecret(XXH_NOESCAPE void *secretBuffer, size_t secretSize, XXH_NOESCAPE const void *customSeed, size_t customSeedSize)
Definition xxhash.h:6699
XXH64_hash_t XXH3_64bits_digest(XXH_NOESCAPE const XXH3_state_t *statePtr)
Returns the calculated XXH3 64-bit hash value from an XXH3_state_t.
Definition xxhash.h:6108
XXH3_state_t * XXH3_createState(void)
Allocate an XXH3_state_t.
Definition xxhash.h:5821
XXH128_hash_t XXH128_hashFromCanonical(XXH_NOESCAPE const XXH128_canonical_t *src)
Converts an XXH128_canonical_t to a native XXH128_hash_t.
Definition xxhash.h:6675
XXH_errorcode XXH3_64bits_reset_withSeed(XXH_NOESCAPE XXH3_state_t *statePtr, XXH64_hash_t seed)
Resets an XXH3_state_t with 64-bit seed to begin a new hash.
Definition xxhash.h:5899
void XXH3_generateSecret_fromSeed(XXH_NOESCAPE void *secretBuffer, XXH64_hash_t seed)
Generate the same secret as the _withSeed() variants.
Definition xxhash.h:6744
XXH_errorcode XXH3_64bits_reset(XXH_NOESCAPE XXH3_state_t *statePtr)
Resets an XXH3_state_t to begin a new hash.
Definition xxhash.h:5879
XXH_errorcode XXH3_64bits_update(XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *input, size_t length)
Consumes a block of input to an XXH3_state_t.
Definition xxhash.h:6063
int XXH128_isEqual(XXH128_hash_t h1, XXH128_hash_t h2)
Definition xxhash.h:6637
#define XXH3_SECRET_SIZE_MIN
Definition xxhash.h:1093
XXH_errorcode XXH3_freeState(XXH3_state_t *statePtr)
Frees an XXH3_state_t.
Definition xxhash.h:5837
XXH_errorcode XXH3_128bits_reset(XXH_NOESCAPE XXH3_state_t *statePtr)
Resets an XXH3_state_t to begin a new hash.
Definition xxhash.h:6572
XXH64_hash_t XXH3_64bits_withSecretandSeed(XXH_NOESCAPE const void *data, size_t len, XXH_NOESCAPE const void *secret, size_t secretSize, XXH64_hash_t seed)
Definition xxhash.h:5739
XXH64_hash_t XXH64(XXH_NOESCAPE const void *input, size_t length, XXH64_hash_t seed)
Calculates the 64-bit hash of input using xxHash64.
Definition xxhash.h:3235
XXH_errorcode XXH64_reset(XXH_NOESCAPE XXH64_state_t *statePtr, XXH64_hash_t seed)
Resets an XXH64_state_t to begin a new hash.
Definition xxhash.h:3275
void XXH64_copyState(XXH_NOESCAPE XXH64_state_t *dst_state, const XXH64_state_t *src_state)
Copies one XXH64_state_t to another.
Definition xxhash.h:3269
void XXH64_canonicalFromHash(XXH_NOESCAPE XXH64_canonical_t *dst, XXH64_hash_t hash)
Converts an XXH64_hash_t to a big endian XXH64_canonical_t.
Definition xxhash.h:3362
XXH64_hash_t XXH64_hashFromCanonical(XXH_NOESCAPE const XXH64_canonical_t *src)
Converts an XXH64_canonical_t to a native XXH64_hash_t.
Definition xxhash.h:3370
XXH_errorcode XXH64_freeState(XXH64_state_t *statePtr)
Frees an XXH64_state_t.
Definition xxhash.h:3262
XXH64_state_t * XXH64_createState(void)
Allocates an XXH64_state_t.
Definition xxhash.h:3257
XXH64_hash_t XXH64_digest(XXH_NOESCAPE const XXH64_state_t *statePtr)
Returns the calculated hash value from an XXH64_state_t.
Definition xxhash.h:3339
XXH_errorcode XXH64_update(XXH_NOESCAPE XXH64_state_t *statePtr, XXH_NOESCAPE const void *input, size_t length)
Consumes a block of input to an XXH64_state_t.
Definition xxhash.h:3288
#define XXH_PRIME64_1
Definition xxhash.h:3093
#define XXH_PRIME64_2
Definition xxhash.h:3094
#define XXH_PRIME64_4
Definition xxhash.h:3096
#define XXH_PRIME64_3
Definition xxhash.h:3095
#define XXH_PRIME64_5
Definition xxhash.h:3097
#define XXH_TARGET_SSE2
Allows a function to be compiled with SSE2 intrinsics.
Definition xxhash.h:4782
#define XXH_TARGET_AVX512
Like XXH_TARGET_SSE2, but for AVX512.
Definition xxhash.h:4573
#define XXH_TARGET_AVX2
Like XXH_TARGET_SSE2, but for AVX2.
Definition xxhash.h:4676
XXH_alignment
Definition xxhash.h:2488
@ XXH_aligned
Definition xxhash.h:2489
@ XXH_unaligned
Definition xxhash.h:2490
uint32_t XXH32_hash_t
An unsigned 32-bit integer.
Definition xxhash.h:515
XXH_errorcode
Exit code for the streaming API.
Definition xxhash.h:500
uint64_t XXH64_hash_t
An unsigned 64-bit integer.
Definition xxhash.h:820
#define XXH_PUBLIC_API
Marks a global symbol.
Definition xxhash.h:383
unsigned XXH_versionNumber(void)
Obtains the xxHash version.
Definition xxhash.h:2545
#define XXH_VERSION_NUMBER
Version number, encoded as two digits each.
Definition xxhash.h:480
@ XXH_ERROR
Definition xxhash.h:502
@ XXH_OK
Definition xxhash.h:501
#define XXH_ACC_ALIGN
Selects the minimum alignment for XXH3's accumulators.
Definition xxhash.h:3572
#define XXH_CPU_LITTLE_ENDIAN
Whether the target is little endian.
Definition xxhash.h:2368
XXH_VECTOR_TYPE
Possible values for XXH_VECTOR.
Definition xxhash.h:3545
#define XXH3_NEON_LANES
Controls the NEON to scalar ratio for XXH3.
Definition xxhash.h:3808
#define XXH32_ENDJMP
Whether to use a jump for XXH32_finalize.
Definition xxhash.h:1955
#define XXH_FORCE_ALIGN_CHECK
If defined to non-zero, adds a special path for aligned inputs (XXH32() and XXH64() only).
Definition xxhash.h:1904
@ XXH_NEON
Definition xxhash.h:3555
@ XXH_AVX512
Definition xxhash.h:3554
@ XXH_SSE2
Definition xxhash.h:3547
@ XXH_VSX
Definition xxhash.h:3560
@ XXH_AVX2
Definition xxhash.h:3553
@ XXH_SCALAR
Definition xxhash.h:3546
@ XXH_SVE
Definition xxhash.h:3561
The return value from 128-bit hashes.
Definition xxhash.h:1239
XXH64_hash_t low64
Definition xxhash.h:1240
XXH64_hash_t high64
Definition xxhash.h:1241
Canonical (big endian) representation of XXH32_hash_t.
Definition xxhash.h:712
XXH32_hash_t memsize
Definition xxhash.h:1445
XXH32_hash_t total_len_32
Definition xxhash.h:1441
XXH32_hash_t mem32[4]
Definition xxhash.h:1444
XXH32_hash_t large_len
Definition xxhash.h:1442
XXH32_hash_t v[4]
Definition xxhash.h:1443
XXH32_hash_t reserved
Definition xxhash.h:1446
const unsigned char * extSecret
Definition xxhash.h:1562
XXH32_hash_t bufferedSize
Definition xxhash.h:1546
XXH64_hash_t reserved64
Definition xxhash.h:1560
XXH64_hash_t totalLen
Definition xxhash.h:1552
size_t nbStripesSoFar
Definition xxhash.h:1550
XXH32_hash_t useSeed
Definition xxhash.h:1548
size_t secretLimit
Definition xxhash.h:1556
size_t nbStripesPerBlock
Definition xxhash.h:1554
XXH64_hash_t seed
Definition xxhash.h:1558
unsigned char buffer[XXH3_INTERNALBUFFER_SIZE]
Definition xxhash.h:1544
unsigned char customSecret[XXH3_SECRET_DEFAULT_SIZE]
Definition xxhash.h:1542
XXH64_hash_t acc[8]
Definition xxhash.h:1540
Canonical (big endian) representation of XXH64_hash_t.
Definition xxhash.h:968
XXH64_hash_t v[4]
Definition xxhash.h:1466
XXH32_hash_t memsize
Definition xxhash.h:1468
XXH32_hash_t reserved32
Definition xxhash.h:1469
XXH64_hash_t mem64[4]
Definition xxhash.h:1467
XXH64_hash_t reserved64
Definition xxhash.h:1470
XXH64_hash_t total_len
Definition xxhash.h:1465
#define XXH3_INTERNALBUFFER_SIZE
The size of the internal XXH3 buffer.
Definition xxhash.h:1505
#define XXH3_INITSTATE(XXH3_state_ptr)
Initializes a stack-allocated XXH3_state_s.
Definition xxhash.h:1581