245#if defined(__cplusplus) && !defined(XXH_NO_EXTERNC_GUARD)
269# define XXH_STATIC_LINKING_ONLY
282# define XXH_IMPLEMENTATION
303# define XXH_INLINE_ALL
304# undef XXH_INLINE_ALL
308# define XXH_PRIVATE_API
309# undef XXH_PRIVATE_API
323# define XXH_NAMESPACE
327#if (defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)) \
328 && !defined(XXH_INLINE_ALL_31684351384)
330# define XXH_INLINE_ALL_31684351384
332# undef XXH_STATIC_LINKING_ONLY
333# define XXH_STATIC_LINKING_ONLY
335# undef XXH_PUBLIC_API
336# if defined(__GNUC__)
337# define XXH_PUBLIC_API static __inline __attribute__((__unused__))
338# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) )
339# define XXH_PUBLIC_API static inline
340# elif defined(_MSC_VER)
341# define XXH_PUBLIC_API static __inline
344# define XXH_PUBLIC_API static
360# undef XXH_versionNumber
363# undef XXH32_createState
364# undef XXH32_freeState
368# undef XXH32_copyState
369# undef XXH32_canonicalFromHash
370# undef XXH32_hashFromCanonical
373# undef XXH64_createState
374# undef XXH64_freeState
378# undef XXH64_copyState
379# undef XXH64_canonicalFromHash
380# undef XXH64_hashFromCanonical
383# undef XXH3_64bits_withSecret
384# undef XXH3_64bits_withSeed
385# undef XXH3_64bits_withSecretandSeed
386# undef XXH3_createState
387# undef XXH3_freeState
388# undef XXH3_copyState
389# undef XXH3_64bits_reset
390# undef XXH3_64bits_reset_withSeed
391# undef XXH3_64bits_reset_withSecret
392# undef XXH3_64bits_update
393# undef XXH3_64bits_digest
394# undef XXH3_generateSecret
398# undef XXH3_128bits_withSeed
399# undef XXH3_128bits_withSecret
400# undef XXH3_128bits_reset
401# undef XXH3_128bits_reset_withSeed
402# undef XXH3_128bits_reset_withSecret
403# undef XXH3_128bits_reset_withSecretandSeed
404# undef XXH3_128bits_update
405# undef XXH3_128bits_digest
406# undef XXH128_isEqual
408# undef XXH128_canonicalFromHash
409# undef XXH128_hashFromCanonical
414# define XXH_NAMESPACE XXH_INLINE_
422# define XXH_IPREF(Id) XXH_NAMESPACE ## Id
423# define XXH_OK XXH_IPREF(XXH_OK)
424# define XXH_ERROR XXH_IPREF(XXH_ERROR)
425# define XXH_errorcode XXH_IPREF(XXH_errorcode)
426# define XXH32_canonical_t XXH_IPREF(XXH32_canonical_t)
427# define XXH64_canonical_t XXH_IPREF(XXH64_canonical_t)
428# define XXH128_canonical_t XXH_IPREF(XXH128_canonical_t)
429# define XXH32_state_s XXH_IPREF(XXH32_state_s)
430# define XXH32_state_t XXH_IPREF(XXH32_state_t)
431# define XXH64_state_s XXH_IPREF(XXH64_state_s)
432# define XXH64_state_t XXH_IPREF(XXH64_state_t)
433# define XXH3_state_s XXH_IPREF(XXH3_state_s)
434# define XXH3_state_t XXH_IPREF(XXH3_state_t)
435# define XXH128_hash_t XXH_IPREF(XXH128_hash_t)
437# undef XXHASH_H_5627135585666179
438# undef XXHASH_H_STATIC_13879238742
444#ifndef XXHASH_H_5627135585666179
445#define XXHASH_H_5627135585666179 1
448#if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API)
449# if defined(_WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
451# define XXH_PUBLIC_API __declspec(dllexport)
453# define XXH_PUBLIC_API __declspec(dllimport)
456# define XXH_PUBLIC_API
461# define XXH_CAT(A,B) A##B
462# define XXH_NAME2(A,B) XXH_CAT(A,B)
463# define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber)
465# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
466# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
467# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
468# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
469# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
470# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
471# define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState)
472# define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash)
473# define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical)
475# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
476# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
477# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
478# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
479# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
480# define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
481# define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState)
482# define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash)
483# define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical)
485# define XXH3_64bits XXH_NAME2(XXH_NAMESPACE, XXH3_64bits)
486# define XXH3_64bits_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSecret)
487# define XXH3_64bits_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSeed)
488# define XXH3_64bits_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSecretandSeed)
489# define XXH3_createState XXH_NAME2(XXH_NAMESPACE, XXH3_createState)
490# define XXH3_freeState XXH_NAME2(XXH_NAMESPACE, XXH3_freeState)
491# define XXH3_copyState XXH_NAME2(XXH_NAMESPACE, XXH3_copyState)
492# define XXH3_64bits_reset XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset)
493# define XXH3_64bits_reset_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSeed)
494# define XXH3_64bits_reset_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSecret)
495# define XXH3_64bits_reset_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSecretandSeed)
496# define XXH3_64bits_update XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_update)
497# define XXH3_64bits_digest XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_digest)
498# define XXH3_generateSecret XXH_NAME2(XXH_NAMESPACE, XXH3_generateSecret)
499# define XXH3_generateSecret_fromSeed XXH_NAME2(XXH_NAMESPACE, XXH3_generateSecret_fromSeed)
501# define XXH128 XXH_NAME2(XXH_NAMESPACE, XXH128)
502# define XXH3_128bits XXH_NAME2(XXH_NAMESPACE, XXH3_128bits)
503# define XXH3_128bits_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSeed)
504# define XXH3_128bits_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSecret)
505# define XXH3_128bits_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSecretandSeed)
506# define XXH3_128bits_reset XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset)
507# define XXH3_128bits_reset_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSeed)
508# define XXH3_128bits_reset_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSecret)
509# define XXH3_128bits_reset_withSecretandSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSecretandSeed)
510# define XXH3_128bits_update XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_update)
511# define XXH3_128bits_digest XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_digest)
512# define XXH128_isEqual XXH_NAME2(XXH_NAMESPACE, XXH128_isEqual)
513# define XXH128_cmp XXH_NAME2(XXH_NAMESPACE, XXH128_cmp)
514# define XXH128_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH128_canonicalFromHash)
515# define XXH128_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH128_hashFromCanonical)
524#if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API)
525# if defined(_WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
527# define XXH_PUBLIC_API __declspec(dllexport)
529# define XXH_PUBLIC_API __declspec(dllimport)
532# define XXH_PUBLIC_API
536#if defined (__GNUC__)
537# define XXH_CONSTF __attribute__((__const__))
538# define XXH_PUREF __attribute__((__pure__))
539# define XXH_MALLOCF __attribute__((__malloc__))
549#define XXH_VERSION_MAJOR 0
550#define XXH_VERSION_MINOR 8
551#define XXH_VERSION_RELEASE 3
553#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
582#if defined(XXH_DOXYGEN)
588typedef uint32_t XXH32_hash_t;
590#elif !defined (__VMS) \
591 && (defined (__cplusplus) \
592 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
594# include <inttypes.h>
598 typedef uint32_t XXH32_hash_t;
602# if UINT_MAX == 0xFFFFFFFFUL
603 typedef unsigned int XXH32_hash_t;
604# elif ULONG_MAX == 0xFFFFFFFFUL
605 typedef unsigned long XXH32_hash_t;
607# error "unsupported platform: need a 32-bit type"
788#ifdef __has_attribute
789# define XXH_HAS_ATTRIBUTE(x) __has_attribute(x)
791# define XXH_HAS_ATTRIBUTE(x) 0
797#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) && defined(__has_c_attribute)
798# define XXH_HAS_C_ATTRIBUTE(x) __has_c_attribute(x)
800# define XXH_HAS_C_ATTRIBUTE(x) 0
805#if defined(__cplusplus) && defined(__has_cpp_attribute)
806# define XXH_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
808# define XXH_HAS_CPP_ATTRIBUTE(x) 0
819#if XXH_HAS_C_ATTRIBUTE(fallthrough) || XXH_HAS_CPP_ATTRIBUTE(fallthrough)
820# define XXH_FALLTHROUGH [[fallthrough]]
821#elif XXH_HAS_ATTRIBUTE(__fallthrough__)
822# define XXH_FALLTHROUGH __attribute__ ((__fallthrough__))
824# define XXH_FALLTHROUGH
834#if XXH_HAS_ATTRIBUTE(noescape)
835# define XXH_NOESCAPE __attribute__((__noescape__))
848#ifndef XXH_NO_LONG_LONG
852#if defined(XXH_DOXYGEN)
859#elif !defined (__VMS) \
860 && (defined (__cplusplus) \
861 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
863# include <inttypes.h>
870# if defined(__LP64__) && ULONG_MAX == 0xFFFFFFFFFFFFFFFFULL
1112# define XXH_SCALAR 0
1115# define XXH_AVX512 3
1184#define XXH3_SECRET_SIZE_MIN 136
1222#ifndef XXH_NO_STREAM
1449#ifndef XXH_NO_STREAM
1637#if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXHASH_H_STATIC_13879238742)
1638#define XXHASH_H_STATIC_13879238742
1665struct XXH32_state_s {
1666 XXH32_hash_t total_len_32;
1667 XXH32_hash_t large_len;
1668 XXH32_hash_t acc[4];
1669 unsigned char buffer[16];
1670 XXH32_hash_t bufferedSize;
1671 XXH32_hash_t reserved;
1675#ifndef XXH_NO_LONG_LONG
1689struct XXH64_state_s {
1692 unsigned char buffer[32];
1693 XXH32_hash_t bufferedSize;
1694 XXH32_hash_t reserved32;
1700#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
1701# define XXH_ALIGN(n) _Alignas(n)
1702#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1704# define XXH_ALIGN(n) alignas(n)
1705#elif defined(__GNUC__)
1706# define XXH_ALIGN(n) __attribute__ ((aligned(n)))
1707#elif defined(_MSC_VER)
1708# define XXH_ALIGN(n) __declspec(align(n))
1710# define XXH_ALIGN(n)
1714#if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) \
1715 && ! (defined(__cplusplus) && (__cplusplus >= 201103L)) \
1716 && defined(__GNUC__)
1717# define XXH_ALIGN_MEMBER(align, type) type XXH_ALIGN(align)
1719# define XXH_ALIGN_MEMBER(align, type) XXH_ALIGN(align) type
1730#define XXH3_INTERNALBUFFER_SIZE 256
1741#define XXH3_SECRET_DEFAULT_SIZE 192
1765struct XXH3_state_s {
1768 XXH_ALIGN_MEMBER(64,
unsigned char customSecret[XXH3_SECRET_DEFAULT_SIZE]);
1770 XXH_ALIGN_MEMBER(64,
unsigned char buffer[XXH3_INTERNALBUFFER_SIZE]);
1772 XXH32_hash_t bufferedSize;
1774 XXH32_hash_t useSeed;
1776 size_t nbStripesSoFar;
1780 size_t nbStripesPerBlock;
1788 const unsigned char* extSecret;
1794#undef XXH_ALIGN_MEMBER
1807#define XXH3_INITSTATE(XXH3_state_ptr) \
1809 XXH3_state_t* tmp_xxh3_state_ptr = (XXH3_state_ptr); \
1810 tmp_xxh3_state_ptr->seed = 0; \
1811 tmp_xxh3_state_ptr->extSecret = NULL; \
1895XXH_PUBLIC_API XXH_errorcode XXH3_generateSecret(XXH_NOESCAPE
void* secretBuffer,
size_t secretSize, XXH_NOESCAPE
const void* customSeed,
size_t customSeedSize);
1940#define XXH3_MIDSIZE_MAX 240
1977XXH3_64bits_withSecretandSeed(XXH_NOESCAPE
const void* data,
size_t len,
1978 XXH_NOESCAPE
const void* secret,
size_t secretSize,
1996XXH3_128bits_withSecretandSeed(XXH_NOESCAPE
const void* input,
size_t length,
1997 XXH_NOESCAPE
const void* secret,
size_t secretSize,
2000#ifndef XXH_NO_STREAM
2015XXH3_64bits_reset_withSecretandSeed(XXH_NOESCAPE
XXH3_state_t* statePtr,
2016 XXH_NOESCAPE
const void* secret,
size_t secretSize,
2041XXH3_128bits_reset_withSecretandSeed(XXH_NOESCAPE
XXH3_state_t* statePtr,
2042 XXH_NOESCAPE
const void* secret,
size_t secretSize,
2049#if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)
2050# define XXH_IMPLEMENTATION
2083#if ( defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) \
2084 || defined(XXH_IMPLEMENTATION) ) && !defined(XXH_IMPLEM_13a8737387)
2085# define XXH_IMPLEM_13a8737387
2103# define XXH_NO_LONG_LONG
2104# undef XXH_NO_LONG_LONG
2155# define XXH_FORCE_MEMORY_ACCESS 0
2183# define XXH_SIZE_OPT 0
2213# define XXH_FORCE_ALIGN_CHECK 0
2235# define XXH_NO_INLINE_HINTS 0
2252# define XXH3_INLINE_SECRET 0
2264# define XXH32_ENDJMP 0
2273# define XXH_OLD_NAMES
2274# undef XXH_OLD_NAMES
2284# define XXH_NO_STREAM
2285# undef XXH_NO_STREAM
2291#ifndef XXH_FORCE_MEMORY_ACCESS
2295# if defined(__GNUC__) && !(defined(__ARM_ARCH) && __ARM_ARCH < 7 && defined(__ARM_FEATURE_UNALIGNED))
2296# define XXH_FORCE_MEMORY_ACCESS 1
2302# if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE_SIZE__)
2303# define XXH_SIZE_OPT 1
2305# define XXH_SIZE_OPT 0
2309#ifndef XXH_FORCE_ALIGN_CHECK
2311# if XXH_SIZE_OPT >= 1 || \
2312 defined(__i386) || defined(__x86_64__) || defined(__aarch64__) || defined(__ARM_FEATURE_UNALIGNED) \
2313 || defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64) || defined(_M_ARM)
2314# define XXH_FORCE_ALIGN_CHECK 0
2316# define XXH_FORCE_ALIGN_CHECK 1
2320#ifndef XXH_NO_INLINE_HINTS
2321# if XXH_SIZE_OPT >= 1 || defined(__NO_INLINE__)
2322# define XXH_NO_INLINE_HINTS 1
2324# define XXH_NO_INLINE_HINTS 0
2328#ifndef XXH3_INLINE_SECRET
2329# if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 12) \
2330 || !defined(XXH_INLINE_ALL)
2331# define XXH3_INLINE_SECRET 0
2333# define XXH3_INLINE_SECRET 1
2339# define XXH32_ENDJMP 0
2351#if defined(XXH_NO_STREAM)
2353#elif defined(XXH_NO_STDLIB)
2364static XXH_CONSTF void* XXH_malloc(
size_t s) { (void)s;
return NULL; }
2365static void XXH_free(
void* p) { (void)p; }
2379static XXH_MALLOCF void* XXH_malloc(
size_t s) {
return malloc(s); }
2385static void XXH_free(
void* p) { free(p); }
2395# define XXH_memcpy memcpy
2404# define XXH_memset memset
2414# define XXH_memcmp memcmp
2426# pragma warning(disable : 4127)
2429#if XXH_NO_INLINE_HINTS
2430# if defined(__GNUC__) || defined(__clang__)
2431# define XXH_FORCE_INLINE static __attribute__((__unused__))
2433# define XXH_FORCE_INLINE static
2435# define XXH_NO_INLINE static
2437#elif defined(__GNUC__) || defined(__clang__)
2438# define XXH_FORCE_INLINE static __inline__ __attribute__((__always_inline__, __unused__))
2439# define XXH_NO_INLINE static __attribute__((__noinline__))
2440#elif defined(_MSC_VER)
2441# define XXH_FORCE_INLINE static __forceinline
2442# define XXH_NO_INLINE static __declspec(noinline)
2443#elif defined (__cplusplus) \
2444 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
2445# define XXH_FORCE_INLINE static inline
2446# define XXH_NO_INLINE static
2448# define XXH_FORCE_INLINE static
2449# define XXH_NO_INLINE static
2452#if defined(XXH_INLINE_ALL)
2453# define XXH_STATIC XXH_FORCE_INLINE
2455# define XXH_STATIC static
2458#if XXH3_INLINE_SECRET
2459# define XXH3_WITH_SECRET_INLINE XXH_FORCE_INLINE
2461# define XXH3_WITH_SECRET_INLINE XXH_NO_INLINE
2464#if ((defined(sun) || defined(__sun)) && __cplusplus)
2465# define XXH_RESTRICT
2466#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
2467# define XXH_RESTRICT restrict
2468#elif (defined (__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) \
2469 || (defined (__clang__)) \
2470 || (defined (_MSC_VER) && (_MSC_VER >= 1400)) \
2471 || (defined (__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300))
2476# define XXH_RESTRICT __restrict
2478# define XXH_RESTRICT
2492#ifndef XXH_DEBUGLEVEL
2494# define XXH_DEBUGLEVEL DEBUGLEVEL
2496# define XXH_DEBUGLEVEL 0
2500#if (XXH_DEBUGLEVEL>=1)
2502# define XXH_ASSERT(c) assert(c)
2504# if defined(__INTEL_COMPILER)
2505# define XXH_ASSERT(c) XXH_ASSUME((unsigned char) (c))
2507# define XXH_ASSERT(c) XXH_ASSUME(c)
2512#ifndef XXH_STATIC_ASSERT
2513# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
2514# define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { _Static_assert((c),m); } while(0)
2515# elif defined(__cplusplus) && (__cplusplus >= 201103L)
2516# define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { static_assert((c),m); } while(0)
2518# define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { struct xxh_sa { char x[(c) ? 1 : -1]; }; } while(0)
2520# define XXH_STATIC_ASSERT(c) XXH_STATIC_ASSERT_WITH_MESSAGE((c),#c)
2539#if defined(__GNUC__) || defined(__clang__)
2540# define XXH_COMPILER_GUARD(var) __asm__("" : "+r" (var))
2542# define XXH_COMPILER_GUARD(var) ((void)0)
2547#if defined(__clang__) && defined(__ARM_ARCH) && !defined(__wasm__)
2548# define XXH_COMPILER_GUARD_CLANG_NEON(var) __asm__("" : "+w" (var))
2550# define XXH_COMPILER_GUARD_CLANG_NEON(var) ((void)0)
2556#if !defined (__VMS) \
2557 && (defined (__cplusplus) \
2558 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
2560# include <inttypes.h>
2564 typedef uint8_t xxh_u8;
2566 typedef unsigned char xxh_u8;
2568typedef XXH32_hash_t xxh_u32;
2571# 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"
2629#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
2634#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
2640static xxh_u32 XXH_read32(
const void* memPtr) {
return *(
const xxh_u32*) memPtr; }
2642#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
2652typedef union { xxh_u32 u32; } __attribute__((__packed__)) unalign;
2654static xxh_u32 XXH_read32(
const void* ptr)
2656 typedef __attribute__((__aligned__(1))) __attribute__((__may_alias__)) xxh_u32 xxh_unalign32;
2657 return *((const xxh_unalign32*)ptr);
2666static xxh_u32 XXH_read32(
const void* memPtr)
2669 XXH_memcpy(&val, memPtr,
sizeof(val));
2694#ifndef XXH_CPU_LITTLE_ENDIAN
2699# if defined(_WIN32) \
2700 || defined(__LITTLE_ENDIAN__) \
2701 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2702# define XXH_CPU_LITTLE_ENDIAN 1
2703# elif defined(__BIG_ENDIAN__) \
2704 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
2705# define XXH_CPU_LITTLE_ENDIAN 0
2713static int XXH_isLittleEndian(
void)
2719 const union { xxh_u32 u; xxh_u8 c[4]; } one = { 1 };
2722# define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian()
2732#define XXH_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
2735# define XXH_HAS_BUILTIN(x) __has_builtin(x)
2737# define XXH_HAS_BUILTIN(x) 0
2769#if XXH_HAS_BUILTIN(__builtin_unreachable)
2770# define XXH_UNREACHABLE() __builtin_unreachable()
2772#elif defined(_MSC_VER)
2773# define XXH_UNREACHABLE() __assume(0)
2776# define XXH_UNREACHABLE()
2779#if XXH_HAS_BUILTIN(__builtin_assume)
2780# define XXH_ASSUME(c) __builtin_assume(c)
2782# define XXH_ASSUME(c) if (!(c)) { XXH_UNREACHABLE(); }
2798#if !defined(NO_CLANG_BUILTIN) && XXH_HAS_BUILTIN(__builtin_rotateleft32) \
2799 && XXH_HAS_BUILTIN(__builtin_rotateleft64)
2800# define XXH_rotl32 __builtin_rotateleft32
2801# define XXH_rotl64 __builtin_rotateleft64
2802#elif XXH_HAS_BUILTIN(__builtin_stdc_rotate_left)
2803# define XXH_rotl32 __builtin_stdc_rotate_left
2804# define XXH_rotl64 __builtin_stdc_rotate_left
2806#elif defined(_MSC_VER)
2807# define XXH_rotl32(x,r) _rotl(x,r)
2808# define XXH_rotl64(x,r) _rotl64(x,r)
2810# define XXH_rotl32(x,r) (((x) << (r)) | ((x) >> (32 - (r))))
2811# define XXH_rotl64(x,r) (((x) << (r)) | ((x) >> (64 - (r))))
2822#if defined(_MSC_VER)
2823# define XXH_swap32 _byteswap_ulong
2824#elif XXH_GCC_VERSION >= 403
2825# define XXH_swap32 __builtin_bswap32
2827static xxh_u32 XXH_swap32 (xxh_u32 x)
2829 return ((x << 24) & 0xff000000 ) |
2830 ((x << 8) & 0x00ff0000 ) |
2831 ((x >> 8) & 0x0000ff00 ) |
2832 ((x >> 24) & 0x000000ff );
2855#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
2857XXH_FORCE_INLINE xxh_u32 XXH_readLE32(
const void* memPtr)
2859 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
2861 | ((xxh_u32)bytePtr[1] << 8)
2862 | ((xxh_u32)bytePtr[2] << 16)
2863 | ((xxh_u32)bytePtr[3] << 24);
2866XXH_FORCE_INLINE xxh_u32 XXH_readBE32(
const void* memPtr)
2868 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
2870 | ((xxh_u32)bytePtr[2] << 8)
2871 | ((xxh_u32)bytePtr[1] << 16)
2872 | ((xxh_u32)bytePtr[0] << 24);
2876XXH_FORCE_INLINE xxh_u32 XXH_readLE32(
const void* ptr)
2878 return XXH_CPU_LITTLE_ENDIAN ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
2881static xxh_u32 XXH_readBE32(
const void* ptr)
2883 return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr);
2887XXH_FORCE_INLINE xxh_u32
2888XXH_readLE32_align(
const void* ptr, XXH_alignment align)
2890 if (align==XXH_unaligned) {
2891 return XXH_readLE32(ptr);
2893 return XXH_CPU_LITTLE_ENDIAN ? *(
const xxh_u32*)ptr : XXH_swap32(*(const xxh_u32*)ptr);
2917#define XXH_PRIME32_1 0x9E3779B1U
2918#define XXH_PRIME32_2 0x85EBCA77U
2919#define XXH_PRIME32_3 0xC2B2AE3DU
2920#define XXH_PRIME32_4 0x27D4EB2FU
2921#define XXH_PRIME32_5 0x165667B1U
2924# define PRIME32_1 XXH_PRIME32_1
2925# define PRIME32_2 XXH_PRIME32_2
2926# define PRIME32_3 XXH_PRIME32_3
2927# define PRIME32_4 XXH_PRIME32_4
2928# define PRIME32_5 XXH_PRIME32_5
2942static xxh_u32 XXH32_round(xxh_u32 acc, xxh_u32 input)
2944 acc += input * XXH_PRIME32_2;
2945 acc = XXH_rotl32(acc, 13);
2946 acc *= XXH_PRIME32_1;
2947#if (defined(__SSE4_1__) || defined(__aarch64__) || defined(__wasm_simd128__)) && !defined(XXH_ENABLE_AUTOVECTORIZE)
2984 XXH_COMPILER_GUARD(acc);
2999static xxh_u32 XXH32_avalanche(xxh_u32 hash)
3002 hash *= XXH_PRIME32_2;
3004 hash *= XXH_PRIME32_3;
3009#define XXH_get32bits(p) XXH_readLE32_align(p, align)
3015XXH_FORCE_INLINE
void
3016XXH32_initAccs(xxh_u32 *acc, xxh_u32 seed)
3018 XXH_ASSERT(acc != NULL);
3019 acc[0] = seed + XXH_PRIME32_1 + XXH_PRIME32_2;
3020 acc[1] = seed + XXH_PRIME32_2;
3022 acc[3] = seed - XXH_PRIME32_1;
3031XXH_FORCE_INLINE
const xxh_u8 *
3033 xxh_u32 *XXH_RESTRICT acc,
3034 xxh_u8
const *XXH_RESTRICT input,
3039 const xxh_u8*
const bEnd = input + len;
3040 const xxh_u8*
const limit = bEnd - 15;
3041 XXH_ASSERT(acc != NULL);
3042 XXH_ASSERT(input != NULL);
3043 XXH_ASSERT(len >= 16);
3045 acc[0] = XXH32_round(acc[0], XXH_get32bits(input)); input += 4;
3046 acc[1] = XXH32_round(acc[1], XXH_get32bits(input)); input += 4;
3047 acc[2] = XXH32_round(acc[2], XXH_get32bits(input)); input += 4;
3048 acc[3] = XXH32_round(acc[3], XXH_get32bits(input)); input += 4;
3049 }
while (input < limit);
3059XXH32_mergeAccs(
const xxh_u32 *acc)
3061 XXH_ASSERT(acc != NULL);
3062 return XXH_rotl32(acc[0], 1) + XXH_rotl32(acc[1], 7)
3063 + XXH_rotl32(acc[2], 12) + XXH_rotl32(acc[3], 18);
3082XXH32_finalize(xxh_u32 hash,
const xxh_u8* ptr,
size_t len, XXH_alignment align)
3084#define XXH_PROCESS1 do { \
3085 hash += (*ptr++) * XXH_PRIME32_5; \
3086 hash = XXH_rotl32(hash, 11) * XXH_PRIME32_1; \
3089#define XXH_PROCESS4 do { \
3090 hash += XXH_get32bits(ptr) * XXH_PRIME32_3; \
3092 hash = XXH_rotl32(hash, 17) * XXH_PRIME32_4; \
3095 if (ptr==NULL) XXH_ASSERT(len == 0);
3098 if (!XXH32_ENDJMP) {
3108 return XXH32_avalanche(hash);
3111 case 12: XXH_PROCESS4;
3113 case 8: XXH_PROCESS4;
3115 case 4: XXH_PROCESS4;
3116 return XXH32_avalanche(hash);
3118 case 13: XXH_PROCESS4;
3120 case 9: XXH_PROCESS4;
3122 case 5: XXH_PROCESS4;
3124 return XXH32_avalanche(hash);
3126 case 14: XXH_PROCESS4;
3128 case 10: XXH_PROCESS4;
3130 case 6: XXH_PROCESS4;
3133 return XXH32_avalanche(hash);
3135 case 15: XXH_PROCESS4;
3137 case 11: XXH_PROCESS4;
3139 case 7: XXH_PROCESS4;
3141 case 3: XXH_PROCESS1;
3143 case 2: XXH_PROCESS1;
3145 case 1: XXH_PROCESS1;
3147 case 0:
return XXH32_avalanche(hash);
3155# define PROCESS1 XXH_PROCESS1
3156# define PROCESS4 XXH_PROCESS4
3171XXH32_endian_align(
const xxh_u8* input,
size_t len, xxh_u32 seed, XXH_alignment align)
3175 if (input==NULL) XXH_ASSERT(len == 0);
3179 XXH32_initAccs(acc, seed);
3181 input = XXH32_consumeLong(acc, input, len, align);
3183 h32 = XXH32_mergeAccs(acc);
3185 h32 = seed + XXH_PRIME32_5;
3188 h32 += (xxh_u32)len;
3190 return XXH32_finalize(h32, input, len&15, align);
3196#if !defined(XXH_NO_STREAM) && XXH_SIZE_OPT >= 2
3203 if (XXH_FORCE_ALIGN_CHECK) {
3204 if ((((
size_t)input) & 3) == 0) {
3205 return XXH32_endian_align((
const xxh_u8*)input, len, seed, XXH_aligned);
3208 return XXH32_endian_align((
const xxh_u8*)input, len, seed, XXH_unaligned);
3215#ifndef XXH_NO_STREAM
3231 XXH_memcpy(dstState, srcState,
sizeof(*dstState));
3237 XXH_ASSERT(statePtr != NULL);
3238 XXH_memset(statePtr, 0,
sizeof(*statePtr));
3239 XXH32_initAccs(statePtr->acc, seed);
3249 XXH_ASSERT(len == 0);
3253 state->total_len_32 += (XXH32_hash_t)len;
3254 state->large_len |= (XXH32_hash_t)((len>=16) | (state->total_len_32>=16));
3256 XXH_ASSERT(state->bufferedSize <
sizeof(state->buffer));
3257 if (len <
sizeof(state->buffer) - state->bufferedSize) {
3258 XXH_memcpy(state->buffer + state->bufferedSize, input, len);
3259 state->bufferedSize += (XXH32_hash_t)len;
3263 {
const xxh_u8* xinput = (
const xxh_u8*)input;
3264 const xxh_u8*
const bEnd = xinput + len;
3266 if (state->bufferedSize) {
3267 XXH_memcpy(state->buffer + state->bufferedSize, xinput,
sizeof(state->buffer) - state->bufferedSize);
3268 xinput +=
sizeof(state->buffer) - state->bufferedSize;
3270 (void)XXH32_consumeLong(state->acc, state->buffer,
sizeof(state->buffer), XXH_aligned);
3271 state->bufferedSize = 0;
3274 XXH_ASSERT(xinput <= bEnd);
3275 if ((
size_t)(bEnd - xinput) >=
sizeof(state->buffer)) {
3277 xinput = XXH32_consumeLong(state->acc, xinput, (
size_t)(bEnd - xinput), XXH_unaligned);
3280 if (xinput < bEnd) {
3282 XXH_memcpy(state->buffer, xinput, (
size_t)(bEnd-xinput));
3283 state->bufferedSize = (unsigned)(bEnd-xinput);
3296 if (state->large_len) {
3297 h32 = XXH32_mergeAccs(state->acc);
3299 h32 = state->acc[2] + XXH_PRIME32_5;
3302 h32 += state->total_len_32;
3304 return XXH32_finalize(h32, state->buffer, state->bufferedSize, XXH_aligned);
3314 if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
3315 XXH_memcpy(dst, &hash,
sizeof(*dst));
3320 return XXH_readBE32(src);
3324#ifndef XXH_NO_LONG_LONG
3342#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
3347#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
3350static xxh_u64 XXH_read64(
const void* memPtr)
3352 return *(
const xxh_u64*) memPtr;
3355#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
3365typedef union { xxh_u32 u32; xxh_u64 u64; } __attribute__((__packed__)) unalign64;
3367static xxh_u64 XXH_read64(
const void* ptr)
3369 typedef __attribute__((__aligned__(1))) __attribute__((__may_alias__)) xxh_u64 xxh_unalign64;
3370 return *((const xxh_unalign64*)ptr);
3379static xxh_u64 XXH_read64(
const void* memPtr)
3382 XXH_memcpy(&val, memPtr,
sizeof(val));
3388#if defined(_MSC_VER)
3389# define XXH_swap64 _byteswap_uint64
3390#elif XXH_GCC_VERSION >= 403
3391# define XXH_swap64 __builtin_bswap64
3393static xxh_u64 XXH_swap64(xxh_u64 x)
3395 return ((x << 56) & 0xff00000000000000ULL) |
3396 ((x << 40) & 0x00ff000000000000ULL) |
3397 ((x << 24) & 0x0000ff0000000000ULL) |
3398 ((x << 8) & 0x000000ff00000000ULL) |
3399 ((x >> 8) & 0x00000000ff000000ULL) |
3400 ((x >> 24) & 0x0000000000ff0000ULL) |
3401 ((x >> 40) & 0x000000000000ff00ULL) |
3402 ((x >> 56) & 0x00000000000000ffULL);
3408#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
3410XXH_FORCE_INLINE xxh_u64 XXH_readLE64(
const void* memPtr)
3412 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
3414 | ((xxh_u64)bytePtr[1] << 8)
3415 | ((xxh_u64)bytePtr[2] << 16)
3416 | ((xxh_u64)bytePtr[3] << 24)
3417 | ((xxh_u64)bytePtr[4] << 32)
3418 | ((xxh_u64)bytePtr[5] << 40)
3419 | ((xxh_u64)bytePtr[6] << 48)
3420 | ((xxh_u64)bytePtr[7] << 56);
3423XXH_FORCE_INLINE xxh_u64 XXH_readBE64(
const void* memPtr)
3425 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
3427 | ((xxh_u64)bytePtr[6] << 8)
3428 | ((xxh_u64)bytePtr[5] << 16)
3429 | ((xxh_u64)bytePtr[4] << 24)
3430 | ((xxh_u64)bytePtr[3] << 32)
3431 | ((xxh_u64)bytePtr[2] << 40)
3432 | ((xxh_u64)bytePtr[1] << 48)
3433 | ((xxh_u64)bytePtr[0] << 56);
3437XXH_FORCE_INLINE xxh_u64 XXH_readLE64(
const void* ptr)
3439 return XXH_CPU_LITTLE_ENDIAN ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
3442static xxh_u64 XXH_readBE64(
const void* ptr)
3444 return XXH_CPU_LITTLE_ENDIAN ? XXH_swap64(XXH_read64(ptr)) : XXH_read64(ptr);
3448XXH_FORCE_INLINE xxh_u64
3449XXH_readLE64_align(
const void* ptr, XXH_alignment align)
3451 if (align==XXH_unaligned)
3452 return XXH_readLE64(ptr);
3454 return XXH_CPU_LITTLE_ENDIAN ? *(
const xxh_u64*)ptr : XXH_swap64(*(const xxh_u64*)ptr);
3468#define XXH_PRIME64_1 0x9E3779B185EBCA87ULL
3469#define XXH_PRIME64_2 0xC2B2AE3D27D4EB4FULL
3470#define XXH_PRIME64_3 0x165667B19E3779F9ULL
3471#define XXH_PRIME64_4 0x85EBCA77C2B2AE63ULL
3472#define XXH_PRIME64_5 0x27D4EB2F165667C5ULL
3475# define PRIME64_1 XXH_PRIME64_1
3476# define PRIME64_2 XXH_PRIME64_2
3477# define PRIME64_3 XXH_PRIME64_3
3478# define PRIME64_4 XXH_PRIME64_4
3479# define PRIME64_5 XXH_PRIME64_5
3483static xxh_u64 XXH64_round(xxh_u64 acc, xxh_u64 input)
3485 acc += input * XXH_PRIME64_2;
3486 acc = XXH_rotl64(acc, 31);
3487 acc *= XXH_PRIME64_1;
3488#if (defined(__AVX512F__)) && !defined(XXH_ENABLE_AUTOVECTORIZE)
3503 XXH_COMPILER_GUARD(acc);
3508static xxh_u64 XXH64_mergeRound(xxh_u64 acc, xxh_u64 val)
3510 val = XXH64_round(0, val);
3512 acc = acc * XXH_PRIME64_1 + XXH_PRIME64_4;
3517static xxh_u64 XXH64_avalanche(xxh_u64 hash)
3520 hash *= XXH_PRIME64_2;
3522 hash *= XXH_PRIME64_3;
3528#define XXH_get64bits(p) XXH_readLE64_align(p, align)
3534XXH_FORCE_INLINE
void
3535XXH64_initAccs(xxh_u64 *acc, xxh_u64 seed)
3537 XXH_ASSERT(acc != NULL);
3538 acc[0] = seed + XXH_PRIME64_1 + XXH_PRIME64_2;
3539 acc[1] = seed + XXH_PRIME64_2;
3541 acc[3] = seed - XXH_PRIME64_1;
3550XXH_FORCE_INLINE
const xxh_u8 *
3552 xxh_u64 *XXH_RESTRICT acc,
3553 xxh_u8
const *XXH_RESTRICT input,
3558 const xxh_u8*
const bEnd = input + len;
3559 const xxh_u8*
const limit = bEnd - 31;
3560 XXH_ASSERT(acc != NULL);
3561 XXH_ASSERT(input != NULL);
3562 XXH_ASSERT(len >= 32);
3565 if (
sizeof(
void *) <
sizeof(xxh_u64)) {
3567 for (i = 0; i < 4; i++) {
3568 acc[i] = XXH64_round(acc[i], XXH_get64bits(input));
3572 acc[0] = XXH64_round(acc[0], XXH_get64bits(input)); input += 8;
3573 acc[1] = XXH64_round(acc[1], XXH_get64bits(input)); input += 8;
3574 acc[2] = XXH64_round(acc[2], XXH_get64bits(input)); input += 8;
3575 acc[3] = XXH64_round(acc[3], XXH_get64bits(input)); input += 8;
3577 }
while (input < limit);
3587XXH64_mergeAccs(
const xxh_u64 *acc)
3589 XXH_ASSERT(acc != NULL);
3591 xxh_u64 h64 = XXH_rotl64(acc[0], 1) + XXH_rotl64(acc[1], 7)
3592 + XXH_rotl64(acc[2], 12) + XXH_rotl64(acc[3], 18);
3594 if (
sizeof(
void *) <
sizeof(xxh_u64)) {
3596 for (i = 0; i < 4; i++) {
3597 h64 = XXH64_mergeRound(h64, acc[i]);
3600 h64 = XXH64_mergeRound(h64, acc[0]);
3601 h64 = XXH64_mergeRound(h64, acc[1]);
3602 h64 = XXH64_mergeRound(h64, acc[2]);
3603 h64 = XXH64_mergeRound(h64, acc[3]);
3625XXH64_finalize(xxh_u64 hash,
const xxh_u8* ptr,
size_t len, XXH_alignment align)
3627 if (ptr==NULL) XXH_ASSERT(len == 0);
3630 xxh_u64
const k1 = XXH64_round(0, XXH_get64bits(ptr));
3633 hash = XXH_rotl64(hash,27) * XXH_PRIME64_1 + XXH_PRIME64_4;
3637 hash ^= (xxh_u64)(XXH_get32bits(ptr)) * XXH_PRIME64_1;
3639 hash = XXH_rotl64(hash, 23) * XXH_PRIME64_2 + XXH_PRIME64_3;
3643 hash ^= (*ptr++) * XXH_PRIME64_5;
3644 hash = XXH_rotl64(hash, 11) * XXH_PRIME64_1;
3647 return XXH64_avalanche(hash);
3651# define PROCESS1_64 XXH_PROCESS1_64
3652# define PROCESS4_64 XXH_PROCESS4_64
3653# define PROCESS8_64 XXH_PROCESS8_64
3655# undef XXH_PROCESS1_64
3656# undef XXH_PROCESS4_64
3657# undef XXH_PROCESS8_64
3669XXH64_endian_align(
const xxh_u8* input,
size_t len, xxh_u64 seed, XXH_alignment align)
3672 if (input==NULL) XXH_ASSERT(len == 0);
3676 XXH64_initAccs(acc, seed);
3678 input = XXH64_consumeLong(acc, input, len, align);
3680 h64 = XXH64_mergeAccs(acc);
3682 h64 = seed + XXH_PRIME64_5;
3685 h64 += (xxh_u64) len;
3687 return XXH64_finalize(h64, input, len, align);
3694#if !defined(XXH_NO_STREAM) && XXH_SIZE_OPT >= 2
3701 if (XXH_FORCE_ALIGN_CHECK) {
3702 if ((((
size_t)input) & 7)==0) {
3703 return XXH64_endian_align((
const xxh_u8*)input, len, seed, XXH_aligned);
3706 return XXH64_endian_align((
const xxh_u8*)input, len, seed, XXH_unaligned);
3712#ifndef XXH_NO_STREAM
3728 XXH_memcpy(dstState, srcState,
sizeof(*dstState));
3734 XXH_ASSERT(statePtr != NULL);
3735 XXH_memset(statePtr, 0,
sizeof(*statePtr));
3736 XXH64_initAccs(statePtr->acc, seed);
3745 XXH_ASSERT(len == 0);
3749 state->total_len += len;
3751 XXH_ASSERT(state->bufferedSize <=
sizeof(state->buffer));
3752 if (len <
sizeof(state->buffer) - state->bufferedSize) {
3753 XXH_memcpy(state->buffer + state->bufferedSize, input, len);
3754 state->bufferedSize += (XXH32_hash_t)len;
3758 {
const xxh_u8* xinput = (
const xxh_u8*)input;
3759 const xxh_u8*
const bEnd = xinput + len;
3761 if (state->bufferedSize) {
3762 XXH_memcpy(state->buffer + state->bufferedSize, xinput,
sizeof(state->buffer) - state->bufferedSize);
3763 xinput +=
sizeof(state->buffer) - state->bufferedSize;
3765 (void)XXH64_consumeLong(state->acc, state->buffer,
sizeof(state->buffer), XXH_aligned);
3766 state->bufferedSize = 0;
3769 XXH_ASSERT(xinput <= bEnd);
3770 if ((
size_t)(bEnd - xinput) >=
sizeof(state->buffer)) {
3772 xinput = XXH64_consumeLong(state->acc, xinput, (
size_t)(bEnd - xinput), XXH_unaligned);
3775 if (xinput < bEnd) {
3777 XXH_memcpy(state->buffer, xinput, (
size_t)(bEnd-xinput));
3778 state->bufferedSize = (unsigned)(bEnd-xinput);
3791 if (state->total_len >= 32) {
3792 h64 = XXH64_mergeAccs(state->acc);
3794 h64 = state->acc[2] + XXH_PRIME64_5;
3797 h64 += (xxh_u64) state->total_len;
3799 return XXH64_finalize(h64, state->buffer, (
size_t)state->total_len, XXH_aligned);
3809 if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
3810 XXH_memcpy(dst, &hash,
sizeof(*dst));
3816 return XXH_readBE64(src);
3835#if (defined(__GNUC__) && (__GNUC__ >= 3)) \
3836 || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) \
3837 || defined(__clang__)
3838# define XXH_likely(x) __builtin_expect(x, 1)
3839# define XXH_unlikely(x) __builtin_expect(x, 0)
3841# define XXH_likely(x) (x)
3842# define XXH_unlikely(x) (x)
3845#ifndef XXH_HAS_INCLUDE
3846# ifdef __has_include
3851# define XXH_HAS_INCLUDE __has_include
3853# define XXH_HAS_INCLUDE(x) 0
3857#if defined(__GNUC__) || defined(__clang__)
3858# if defined(__ARM_FEATURE_SVE)
3859# include <arm_sve.h>
3861# if defined(__ARM_NEON__) || defined(__ARM_NEON) \
3862 || (defined(_M_ARM) && _M_ARM >= 7) \
3863 || defined(_M_ARM64) || defined(_M_ARM64EC) \
3864 || (defined(__wasm_simd128__) && XXH_HAS_INCLUDE(<arm_neon.h>))
3865# define inline __inline__
3866# include <arm_neon.h>
3868# elif defined(__AVX2__)
3869# include <immintrin.h>
3870# elif defined(__SSE2__)
3871# include <emmintrin.h>
3872# elif defined(__loongarch_asx)
3873# include <lasxintrin.h>
3874# include <lsxintrin.h>
3875# elif defined(__loongarch_sx)
3876# include <lsxintrin.h>
3877# elif defined(__riscv_vector)
3878# include <riscv_vector.h>
3882#if defined(_MSC_VER)
3955#if defined(__thumb__) && !defined(__thumb2__) && defined(__ARM_ARCH_ISA_ARM)
3956# warning "XXH3 is highly inefficient without ARM or Thumb-2."
3974# define XXH_VECTOR XXH_SCALAR
3984# define XXH_ACC_ALIGN 8
3993 defined(__ARM_NEON__) || defined(__ARM_NEON) \
3994 || defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC) \
3995 || (defined(__wasm_simd128__) && XXH_HAS_INCLUDE(<arm_neon.h>)) \
3997 defined(_WIN32) || defined(__LITTLE_ENDIAN__) \
3998 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) \
4000# define XXH_VECTOR XXH_NEON
4001# elif defined(__ARM_FEATURE_SVE)
4002# define XXH_VECTOR XXH_SVE
4003# elif defined(__AVX512F__)
4004# define XXH_VECTOR XXH_AVX512
4005# elif defined(__AVX2__)
4006# define XXH_VECTOR XXH_AVX2
4007# elif defined(__SSE2__) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP == 2))
4008# define XXH_VECTOR XXH_SSE2
4009# elif (defined(__PPC64__) && defined(__POWER8_VECTOR__)) \
4010 || (defined(__s390x__) && defined(__VEC__)) \
4011 && defined(__GNUC__)
4012# define XXH_VECTOR XXH_VSX
4013# elif defined(__loongarch_asx)
4014# define XXH_VECTOR XXH_LASX
4015# elif defined(__loongarch_sx)
4016# define XXH_VECTOR XXH_LSX
4017# elif defined(__riscv_vector)
4018# define XXH_VECTOR XXH_RVV
4020# define XXH_VECTOR XXH_SCALAR
4025#if (XXH_VECTOR == XXH_SVE) && !defined(__ARM_FEATURE_SVE)
4027# pragma warning(once : 4606)
4029# warning "__ARM_FEATURE_SVE isn't supported. Use SCALAR instead."
4032# define XXH_VECTOR XXH_SCALAR
4039#ifndef XXH_ACC_ALIGN
4040# if defined(XXH_X86DISPATCH)
4041# define XXH_ACC_ALIGN 64
4042# elif XXH_VECTOR == XXH_SCALAR
4043# define XXH_ACC_ALIGN 8
4044# elif XXH_VECTOR == XXH_SSE2
4045# define XXH_ACC_ALIGN 16
4046# elif XXH_VECTOR == XXH_AVX2
4047# define XXH_ACC_ALIGN 32
4048# elif XXH_VECTOR == XXH_NEON
4049# define XXH_ACC_ALIGN 16
4050# elif XXH_VECTOR == XXH_VSX
4051# define XXH_ACC_ALIGN 16
4052# elif XXH_VECTOR == XXH_AVX512
4053# define XXH_ACC_ALIGN 64
4054# elif XXH_VECTOR == XXH_SVE
4055# define XXH_ACC_ALIGN 64
4056# elif XXH_VECTOR == XXH_LASX
4057# define XXH_ACC_ALIGN 64
4058# elif XXH_VECTOR == XXH_LSX
4059# define XXH_ACC_ALIGN 64
4060# elif XXH_VECTOR == XXH_RVV
4061# define XXH_ACC_ALIGN 64
4065#if defined(XXH_X86DISPATCH) || XXH_VECTOR == XXH_SSE2 \
4066 || XXH_VECTOR == XXH_AVX2 || XXH_VECTOR == XXH_AVX512
4067# define XXH_SEC_ALIGN XXH_ACC_ALIGN
4068#elif XXH_VECTOR == XXH_SVE
4069# define XXH_SEC_ALIGN XXH_ACC_ALIGN
4070#elif XXH_VECTOR == XXH_RVV
4071# define XXH_SEC_ALIGN XXH_ACC_ALIGN
4073# define XXH_SEC_ALIGN 8
4076#if defined(__GNUC__) || defined(__clang__)
4077# define XXH_ALIASING __attribute__((__may_alias__))
4079# define XXH_ALIASING
4103#if XXH_VECTOR == XXH_AVX2 \
4104 && defined(__GNUC__) && !defined(__clang__) \
4105 && defined(__OPTIMIZE__) && XXH_SIZE_OPT <= 0
4106# pragma GCC push_options
4107# pragma GCC optimize("-O2")
4110#if XXH_VECTOR == XXH_NEON
4119typedef uint64x2_t xxh_aliasing_uint64x2_t XXH_ALIASING;
4134#if defined(__aarch64__) && defined(__GNUC__) && !defined(__clang__)
4135XXH_FORCE_INLINE uint64x2_t XXH_vld1q_u64(
void const* ptr)
4137 return *(xxh_aliasing_uint64x2_t
const *)ptr;
4140XXH_FORCE_INLINE uint64x2_t XXH_vld1q_u64(
void const* ptr)
4142 return vreinterpretq_u64_u8(vld1q_u8((uint8_t
const*)ptr));
4154#if defined(__aarch64__) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 11
4155XXH_FORCE_INLINE uint64x2_t
4156XXH_vmlal_low_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
4159 __asm__(
"umlal %0.2d, %1.2s, %2.2s" :
"+w" (acc) :
"w" (lhs),
"w" (rhs));
4162XXH_FORCE_INLINE uint64x2_t
4163XXH_vmlal_high_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
4166 return vmlal_high_u32(acc, lhs, rhs);
4170XXH_FORCE_INLINE uint64x2_t
4171XXH_vmlal_low_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
4173 return vmlal_u32(acc, vget_low_u32(lhs), vget_low_u32(rhs));
4177XXH_FORCE_INLINE uint64x2_t
4178XXH_vmlal_high_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
4180 return vmlal_u32(acc, vget_high_u32(lhs), vget_high_u32(rhs));
4222# ifndef XXH3_NEON_LANES
4223# if (defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || defined(_M_ARM64EC)) \
4224 && !defined(__APPLE__) && XXH_SIZE_OPT <= 0
4225# define XXH3_NEON_LANES 6
4227# define XXH3_NEON_LANES XXH_ACC_NB
4240#if XXH_VECTOR == XXH_VSX
4249# pragma push_macro("bool")
4250# pragma push_macro("vector")
4251# pragma push_macro("pixel")
4257# if defined(__s390x__)
4258# include <s390intrin.h>
4260# include <altivec.h>
4264# pragma pop_macro("pixel")
4265# pragma pop_macro("vector")
4266# pragma pop_macro("bool")
4268typedef __vector
unsigned long long xxh_u64x2;
4269typedef __vector
unsigned char xxh_u8x16;
4270typedef __vector
unsigned xxh_u32x4;
4275typedef xxh_u64x2 xxh_aliasing_u64x2 XXH_ALIASING;
4278# if defined(__BIG_ENDIAN__) \
4279 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
4280# define XXH_VSX_BE 1
4281# elif defined(__VEC_ELEMENT_REG_ORDER__) && __VEC_ELEMENT_REG_ORDER__ == __ORDER_BIG_ENDIAN__
4282# warning "-maltivec=be is not recommended. Please use native endianness."
4283# define XXH_VSX_BE 1
4285# define XXH_VSX_BE 0
4290# if defined(__POWER9_VECTOR__) || (defined(__clang__) && defined(__s390x__))
4291# define XXH_vec_revb vec_revb
4296XXH_FORCE_INLINE xxh_u64x2 XXH_vec_revb(xxh_u64x2 val)
4298 xxh_u8x16
const vByteSwap = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
4299 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08 };
4300 return vec_perm(val, val, vByteSwap);
4308XXH_FORCE_INLINE xxh_u64x2 XXH_vec_loadu(
const void *ptr)
4311 XXH_memcpy(&ret, ptr,
sizeof(xxh_u64x2));
4313 ret = XXH_vec_revb(ret);
4324# if defined(__s390x__)
4326# define XXH_vec_mulo vec_mulo
4327# define XXH_vec_mule vec_mule
4328# elif defined(__clang__) && XXH_HAS_BUILTIN(__builtin_altivec_vmuleuw) && !defined(__ibmxl__)
4331# define XXH_vec_mulo __builtin_altivec_vmulouw
4332# define XXH_vec_mule __builtin_altivec_vmuleuw
4336XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mulo(xxh_u32x4 a, xxh_u32x4 b)
4339 __asm__(
"vmulouw %0, %1, %2" :
"=v" (result) :
"v" (a),
"v" (b));
4342XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mule(xxh_u32x4 a, xxh_u32x4 b)
4345 __asm__(
"vmuleuw %0, %1, %2" :
"=v" (result) :
"v" (a),
"v" (b));
4351#if XXH_VECTOR == XXH_SVE
4352#define ACCRND(acc, offset) \
4354 svuint64_t input_vec = svld1_u64(mask, xinput + offset); \
4355 svuint64_t secret_vec = svld1_u64(mask, xsecret + offset); \
4356 svuint64_t mixed = sveor_u64_x(mask, secret_vec, input_vec); \
4357 svuint64_t swapped = svtbl_u64(input_vec, kSwap); \
4358 svuint64_t mixed_lo = svextw_u64_x(mask, mixed); \
4359 svuint64_t mixed_hi = svlsr_n_u64_x(mask, mixed, 32); \
4360 svuint64_t mul = svmad_u64_x(mask, mixed_lo, mixed_hi, swapped); \
4361 acc = svadd_u64_x(mask, acc, mul); \
4367#if defined(XXH_NO_PREFETCH)
4368# define XXH_PREFETCH(ptr) (void)(ptr)
4370# if XXH_SIZE_OPT >= 1
4371# define XXH_PREFETCH(ptr) (void)(ptr)
4372# elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
4373# include <mmintrin.h>
4374# define XXH_PREFETCH(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
4375# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
4376# define XXH_PREFETCH(ptr) __builtin_prefetch((ptr), 0 , 3 )
4378# define XXH_PREFETCH(ptr) (void)(ptr)
4387#define XXH_SECRET_DEFAULT_SIZE 192
4389#if (XXH_SECRET_DEFAULT_SIZE < XXH3_SECRET_SIZE_MIN)
4390# error "default keyset is not large enough"
4397XXH_ALIGN(64) static const xxh_u8 XXH3_kSecret[XXH_SECRET_DEFAULT_SIZE] = {
4398 0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c,
4399 0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f,
4400 0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21,
4401 0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c,
4402 0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3,
4403 0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8,
4404 0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d,
4405 0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64,
4406 0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb,
4407 0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e,
4408 0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce,
4409 0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e,
4412static const xxh_u64 PRIME_MX1 = 0x165667919E3779F9ULL;
4413static const xxh_u64 PRIME_MX2 = 0x9FB21C651E98DF25ULL;
4416# define kSecret XXH3_kSecret
4436XXH_FORCE_INLINE xxh_u64
4437XXH_mult32to64(xxh_u64 x, xxh_u64 y)
4439 return (x & 0xFFFFFFFF) * (y & 0xFFFFFFFF);
4441#elif defined(_MSC_VER) && defined(_M_IX86)
4442# define XXH_mult32to64(x, y) __emulu((unsigned)(x), (unsigned)(y))
4451# define XXH_mult32to64(x, y) ((xxh_u64)(xxh_u32)(x) * (xxh_u64)(xxh_u32)(y))
4464XXH_mult64to128(xxh_u64 lhs, xxh_u64 rhs)
4481#if (defined(__GNUC__) || defined(__clang__)) && !defined(__wasm__) \
4482 && defined(__SIZEOF_INT128__) \
4483 || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
4485 __uint128_t
const product = (__uint128_t)lhs * (__uint128_t)rhs;
4487 r128.
low64 = (xxh_u64)(product);
4488 r128.
high64 = (xxh_u64)(product >> 64);
4498#elif (defined(_M_X64) || defined(_M_IA64)) && !defined(_M_ARM64EC)
4501# pragma intrinsic(_umul128)
4503 xxh_u64 product_high;
4504 xxh_u64
const product_low = _umul128(lhs, rhs, &product_high);
4506 r128.
low64 = product_low;
4507 r128.
high64 = product_high;
4515#elif defined(_M_ARM64) || defined(_M_ARM64EC)
4518# pragma intrinsic(__umulh)
4521 r128.
low64 = lhs * rhs;
4522 r128.
high64 = __umulh(lhs, rhs);
4570 xxh_u64
const lo_lo = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs & 0xFFFFFFFF);
4571 xxh_u64
const hi_lo = XXH_mult32to64(lhs >> 32, rhs & 0xFFFFFFFF);
4572 xxh_u64
const lo_hi = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs >> 32);
4573 xxh_u64
const hi_hi = XXH_mult32to64(lhs >> 32, rhs >> 32);
4576 xxh_u64
const cross = (lo_lo >> 32) + (hi_lo & 0xFFFFFFFF) + lo_hi;
4577 xxh_u64
const upper = (hi_lo >> 32) + (cross >> 32) + hi_hi;
4578 xxh_u64
const lower = (cross << 32) | (lo_lo & 0xFFFFFFFF);
4598XXH3_mul128_fold64(xxh_u64 lhs, xxh_u64 rhs)
4605XXH_FORCE_INLINE
XXH_CONSTF xxh_u64 XXH_xorshift64(xxh_u64 v64,
int shift)
4607 XXH_ASSERT(0 <= shift && shift < 64);
4608 return v64 ^ (v64 >> shift);
4617 h64 = XXH_xorshift64(h64, 37);
4619 h64 = XXH_xorshift64(h64, 32);
4628static XXH64_hash_t XXH3_rrmxmx(xxh_u64 h64, xxh_u64 len)
4631 h64 ^= XXH_rotl64(h64, 49) ^ XXH_rotl64(h64, 24);
4633 h64 ^= (h64 >> 35) + len ;
4635 return XXH_xorshift64(h64, 28);
4673XXH3_len_1to3_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4675 XXH_ASSERT(input != NULL);
4676 XXH_ASSERT(1 <= len && len <= 3);
4677 XXH_ASSERT(secret != NULL);
4683 { xxh_u8
const c1 = input[0];
4684 xxh_u8
const c2 = input[len >> 1];
4685 xxh_u8
const c3 = input[len - 1];
4686 xxh_u32
const combined = ((xxh_u32)c1 << 16) | ((xxh_u32)c2 << 24)
4687 | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8);
4688 xxh_u64
const bitflip = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed;
4689 xxh_u64
const keyed = (xxh_u64)combined ^ bitflip;
4690 return XXH64_avalanche(keyed);
4695XXH3_len_4to8_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4697 XXH_ASSERT(input != NULL);
4698 XXH_ASSERT(secret != NULL);
4699 XXH_ASSERT(4 <= len && len <= 8);
4700 seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32;
4701 { xxh_u32
const input1 = XXH_readLE32(input);
4702 xxh_u32
const input2 = XXH_readLE32(input + len - 4);
4703 xxh_u64
const bitflip = (XXH_readLE64(secret+8) ^ XXH_readLE64(secret+16)) - seed;
4704 xxh_u64
const input64 = input2 + (((xxh_u64)input1) << 32);
4705 xxh_u64
const keyed = input64 ^ bitflip;
4706 return XXH3_rrmxmx(keyed, len);
4711XXH3_len_9to16_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4713 XXH_ASSERT(input != NULL);
4714 XXH_ASSERT(secret != NULL);
4715 XXH_ASSERT(9 <= len && len <= 16);
4716 { xxh_u64
const bitflip1 = (XXH_readLE64(secret+24) ^ XXH_readLE64(secret+32)) + seed;
4717 xxh_u64
const bitflip2 = (XXH_readLE64(secret+40) ^ XXH_readLE64(secret+48)) - seed;
4718 xxh_u64
const input_lo = XXH_readLE64(input) ^ bitflip1;
4719 xxh_u64
const input_hi = XXH_readLE64(input + len - 8) ^ bitflip2;
4720 xxh_u64
const acc = len
4721 + XXH_swap64(input_lo) + input_hi
4722 + XXH3_mul128_fold64(input_lo, input_hi);
4723 return XXH3_avalanche(acc);
4728XXH3_len_0to16_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4730 XXH_ASSERT(len <= 16);
4731 {
if (XXH_likely(len > 8))
return XXH3_len_9to16_64b(input, len, secret, seed);
4732 if (XXH_likely(len >= 4))
return XXH3_len_4to8_64b(input, len, secret, seed);
4733 if (len)
return XXH3_len_1to3_64b(input, len, secret, seed);
4734 return XXH64_avalanche(seed ^ (XXH_readLE64(secret+56) ^ XXH_readLE64(secret+64)));
4764XXH_FORCE_INLINE xxh_u64 XXH3_mix16B(
const xxh_u8* XXH_RESTRICT input,
4765 const xxh_u8* XXH_RESTRICT secret, xxh_u64 seed64)
4767#if defined(__GNUC__) && !defined(__clang__) \
4768 && defined(__i386__) && defined(__SSE2__) \
4769 && !defined(XXH_ENABLE_AUTOVECTORIZE)
4785 XXH_COMPILER_GUARD(seed64);
4787 { xxh_u64
const input_lo = XXH_readLE64(input);
4788 xxh_u64
const input_hi = XXH_readLE64(input+8);
4789 return XXH3_mul128_fold64(
4790 input_lo ^ (XXH_readLE64(secret) + seed64),
4791 input_hi ^ (XXH_readLE64(secret+8) - seed64)
4798XXH3_len_17to128_64b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
4799 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
4803 XXH_ASSERT(16 < len && len <= 128);
4805 { xxh_u64 acc = len * XXH_PRIME64_1;
4806#if XXH_SIZE_OPT >= 1
4808 unsigned int i = (
unsigned int)(len - 1) / 32;
4810 acc += XXH3_mix16B(input+16 * i, secret+32*i, seed);
4811 acc += XXH3_mix16B(input+len-16*(i+1), secret+32*i+16, seed);
4817 acc += XXH3_mix16B(input+48, secret+96, seed);
4818 acc += XXH3_mix16B(input+len-64, secret+112, seed);
4820 acc += XXH3_mix16B(input+32, secret+64, seed);
4821 acc += XXH3_mix16B(input+len-48, secret+80, seed);
4823 acc += XXH3_mix16B(input+16, secret+32, seed);
4824 acc += XXH3_mix16B(input+len-32, secret+48, seed);
4826 acc += XXH3_mix16B(input+0, secret+0, seed);
4827 acc += XXH3_mix16B(input+len-16, secret+16, seed);
4829 return XXH3_avalanche(acc);
4834XXH3_len_129to240_64b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
4835 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
4839 XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX);
4841 #define XXH3_MIDSIZE_STARTOFFSET 3
4842 #define XXH3_MIDSIZE_LASTOFFSET 17
4844 { xxh_u64 acc = len * XXH_PRIME64_1;
4846 unsigned int const nbRounds = (
unsigned int)len / 16;
4848 XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX);
4849 for (i=0; i<8; i++) {
4850 acc += XXH3_mix16B(input+(16*i), secret+(16*i), seed);
4853 acc_end = XXH3_mix16B(input + len - 16, secret +
XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET, seed);
4854 XXH_ASSERT(nbRounds >= 8);
4855 acc = XXH3_avalanche(acc);
4856#if defined(__clang__) \
4857 && (defined(__ARM_NEON) || defined(__ARM_NEON__)) \
4858 && !defined(XXH_ENABLE_AUTOVECTORIZE)
4879 #pragma clang loop vectorize(disable)
4881 for (i=8 ; i < nbRounds; i++) {
4885 XXH_COMPILER_GUARD(acc);
4886 acc_end += XXH3_mix16B(input+(16*i), secret+(16*(i-8)) + XXH3_MIDSIZE_STARTOFFSET, seed);
4888 return XXH3_avalanche(acc + acc_end);
4895#define XXH_STRIPE_LEN 64
4896#define XXH_SECRET_CONSUME_RATE 8
4897#define XXH_ACC_NB (XXH_STRIPE_LEN / sizeof(xxh_u64))
4900# define STRIPE_LEN XXH_STRIPE_LEN
4901# define ACC_NB XXH_ACC_NB
4904#ifndef XXH_PREFETCH_DIST
4906# define XXH_PREFETCH_DIST 320
4908# if (XXH_VECTOR == XXH_AVX512)
4909# define XXH_PREFETCH_DIST 512
4911# define XXH_PREFETCH_DIST 384
4926#define XXH3_ACCUMULATE_TEMPLATE(name) \
4928XXH3_accumulate_##name(xxh_u64* XXH_RESTRICT acc, \
4929 const xxh_u8* XXH_RESTRICT input, \
4930 const xxh_u8* XXH_RESTRICT secret, \
4934 for (n = 0; n < nbStripes; n++ ) { \
4935 const xxh_u8* const in = input + n*XXH_STRIPE_LEN; \
4936 XXH_PREFETCH(in + XXH_PREFETCH_DIST); \
4937 XXH3_accumulate_512_##name( \
4940 secret + n*XXH_SECRET_CONSUME_RATE); \
4945XXH_FORCE_INLINE
void XXH_writeLE64(
void* dst, xxh_u64 v64)
4947 if (!XXH_CPU_LITTLE_ENDIAN) v64 = XXH_swap64(v64);
4948 XXH_memcpy(dst, &v64,
sizeof(v64));
4956#if !defined (__VMS) \
4957 && (defined (__cplusplus) \
4958 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
4959 typedef int64_t xxh_i64;
4962 typedef long long xxh_i64;
4989#if (XXH_VECTOR == XXH_AVX512) \
4990 || (defined(XXH_DISPATCH_AVX512) && XXH_DISPATCH_AVX512 != 0)
4992#ifndef XXH_TARGET_AVX512
4993# define XXH_TARGET_AVX512
4996XXH_FORCE_INLINE XXH_TARGET_AVX512
void
4997XXH3_accumulate_512_avx512(
void* XXH_RESTRICT acc,
4998 const void* XXH_RESTRICT input,
4999 const void* XXH_RESTRICT secret)
5001 __m512i*
const xacc = (__m512i *) acc;
5002 XXH_ASSERT((((
size_t)acc) & 63) == 0);
5003 XXH_STATIC_ASSERT(XXH_STRIPE_LEN ==
sizeof(__m512i));
5007 __m512i
const data_vec = _mm512_loadu_si512 (input);
5009 __m512i
const key_vec = _mm512_loadu_si512 (secret);
5011 __m512i
const data_key = _mm512_xor_si512 (data_vec, key_vec);
5013 __m512i
const data_key_lo = _mm512_srli_epi64 (data_key, 32);
5015 __m512i
const product = _mm512_mul_epu32 (data_key, data_key_lo);
5017 __m512i
const data_swap = _mm512_shuffle_epi32(data_vec, (_MM_PERM_ENUM)_MM_SHUFFLE(1, 0, 3, 2));
5018 __m512i
const sum = _mm512_add_epi64(*xacc, data_swap);
5020 *xacc = _mm512_add_epi64(product, sum);
5023XXH_FORCE_INLINE XXH_TARGET_AVX512 XXH3_ACCUMULATE_TEMPLATE(avx512)
5046XXH_FORCE_INLINE XXH_TARGET_AVX512
void
5047XXH3_scrambleAcc_avx512(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5049 XXH_ASSERT((((
size_t)acc) & 63) == 0);
5050 XXH_STATIC_ASSERT(XXH_STRIPE_LEN ==
sizeof(__m512i));
5051 { __m512i*
const xacc = (__m512i*) acc;
5052 const __m512i prime32 = _mm512_set1_epi32((
int)XXH_PRIME32_1);
5055 __m512i
const acc_vec = *xacc;
5056 __m512i
const shifted = _mm512_srli_epi64 (acc_vec, 47);
5058 __m512i
const key_vec = _mm512_loadu_si512 (secret);
5059 __m512i
const data_key = _mm512_ternarylogic_epi32(key_vec, acc_vec, shifted, 0x96 );
5062 __m512i
const data_key_hi = _mm512_srli_epi64 (data_key, 32);
5063 __m512i
const prod_lo = _mm512_mul_epu32 (data_key, prime32);
5064 __m512i
const prod_hi = _mm512_mul_epu32 (data_key_hi, prime32);
5065 *xacc = _mm512_add_epi64(prod_lo, _mm512_slli_epi64(prod_hi, 32));
5069XXH_FORCE_INLINE XXH_TARGET_AVX512
void
5070XXH3_initCustomSecret_avx512(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
5072 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 63) == 0);
5073 XXH_STATIC_ASSERT(XXH_SEC_ALIGN == 64);
5074 XXH_ASSERT(((
size_t)customSecret & 63) == 0);
5075 (void)(&XXH_writeLE64);
5076 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE /
sizeof(__m512i);
5077 __m512i
const seed_pos = _mm512_set1_epi64((xxh_i64)seed64);
5078 __m512i
const seed = _mm512_mask_sub_epi64(seed_pos, 0xAA, _mm512_set1_epi8(0), seed_pos);
5080 const __m512i*
const src = (
const __m512i*) ((
const void*) XXH3_kSecret);
5081 __m512i*
const dest = ( __m512i*) customSecret;
5083 XXH_ASSERT(((
size_t)src & 63) == 0);
5084 XXH_ASSERT(((
size_t)dest & 63) == 0);
5085 for (i=0; i < nbRounds; ++i) {
5086 dest[i] = _mm512_add_epi64(_mm512_load_si512(src + i), seed);
5092#if (XXH_VECTOR == XXH_AVX2) \
5093 || (defined(XXH_DISPATCH_AVX2) && XXH_DISPATCH_AVX2 != 0)
5095#ifndef XXH_TARGET_AVX2
5096# define XXH_TARGET_AVX2
5099XXH_FORCE_INLINE XXH_TARGET_AVX2
void
5100XXH3_accumulate_512_avx2(
void* XXH_RESTRICT acc,
5101 const void* XXH_RESTRICT input,
5102 const void* XXH_RESTRICT secret)
5104 XXH_ASSERT((((
size_t)acc) & 31) == 0);
5105 { __m256i*
const xacc = (__m256i *) acc;
5108 const __m256i*
const xinput = (
const __m256i *) input;
5111 const __m256i*
const xsecret = (
const __m256i *) secret;
5114 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m256i); i++) {
5116 __m256i
const data_vec = _mm256_loadu_si256 (xinput+i);
5118 __m256i
const key_vec = _mm256_loadu_si256 (xsecret+i);
5120 __m256i
const data_key = _mm256_xor_si256 (data_vec, key_vec);
5122 __m256i
const data_key_lo = _mm256_srli_epi64 (data_key, 32);
5124 __m256i
const product = _mm256_mul_epu32 (data_key, data_key_lo);
5126 __m256i
const data_swap = _mm256_shuffle_epi32(data_vec, _MM_SHUFFLE(1, 0, 3, 2));
5127 __m256i
const sum = _mm256_add_epi64(xacc[i], data_swap);
5129 xacc[i] = _mm256_add_epi64(product, sum);
5132XXH_FORCE_INLINE XXH_TARGET_AVX2 XXH3_ACCUMULATE_TEMPLATE(avx2)
5134XXH_FORCE_INLINE XXH_TARGET_AVX2
void
5135XXH3_scrambleAcc_avx2(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5137 XXH_ASSERT((((
size_t)acc) & 31) == 0);
5138 { __m256i*
const xacc = (__m256i*) acc;
5141 const __m256i*
const xsecret = (
const __m256i *) secret;
5142 const __m256i prime32 = _mm256_set1_epi32((
int)XXH_PRIME32_1);
5145 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m256i); i++) {
5147 __m256i
const acc_vec = xacc[i];
5148 __m256i
const shifted = _mm256_srli_epi64 (acc_vec, 47);
5149 __m256i
const data_vec = _mm256_xor_si256 (acc_vec, shifted);
5151 __m256i
const key_vec = _mm256_loadu_si256 (xsecret+i);
5152 __m256i
const data_key = _mm256_xor_si256 (data_vec, key_vec);
5155 __m256i
const data_key_hi = _mm256_srli_epi64 (data_key, 32);
5156 __m256i
const prod_lo = _mm256_mul_epu32 (data_key, prime32);
5157 __m256i
const prod_hi = _mm256_mul_epu32 (data_key_hi, prime32);
5158 xacc[i] = _mm256_add_epi64(prod_lo, _mm256_slli_epi64(prod_hi, 32));
5163XXH_FORCE_INLINE XXH_TARGET_AVX2
void XXH3_initCustomSecret_avx2(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
5165 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 31) == 0);
5166 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE /
sizeof(__m256i)) == 6);
5167 XXH_STATIC_ASSERT(XXH_SEC_ALIGN <= 64);
5168 (void)(&XXH_writeLE64);
5169 XXH_PREFETCH(customSecret);
5170 { __m256i
const seed = _mm256_set_epi64x((xxh_i64)(0U - seed64), (xxh_i64)seed64, (xxh_i64)(0U - seed64), (xxh_i64)seed64);
5172 const __m256i*
const src = (
const __m256i*) ((
const void*) XXH3_kSecret);
5173 __m256i* dest = ( __m256i*) customSecret;
5175# if defined(__GNUC__) || defined(__clang__)
5181 XXH_COMPILER_GUARD(dest);
5183 XXH_ASSERT(((
size_t)src & 31) == 0);
5184 XXH_ASSERT(((
size_t)dest & 31) == 0);
5187 dest[0] = _mm256_add_epi64(_mm256_load_si256(src+0), seed);
5188 dest[1] = _mm256_add_epi64(_mm256_load_si256(src+1), seed);
5189 dest[2] = _mm256_add_epi64(_mm256_load_si256(src+2), seed);
5190 dest[3] = _mm256_add_epi64(_mm256_load_si256(src+3), seed);
5191 dest[4] = _mm256_add_epi64(_mm256_load_si256(src+4), seed);
5192 dest[5] = _mm256_add_epi64(_mm256_load_si256(src+5), seed);
5199#if (XXH_VECTOR == XXH_SSE2) || defined(XXH_X86DISPATCH)
5201#ifndef XXH_TARGET_SSE2
5202# define XXH_TARGET_SSE2
5205XXH_FORCE_INLINE XXH_TARGET_SSE2
void
5206XXH3_accumulate_512_sse2(
void* XXH_RESTRICT acc,
5207 const void* XXH_RESTRICT input,
5208 const void* XXH_RESTRICT secret)
5211 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5212 { __m128i*
const xacc = (__m128i *) acc;
5215 const __m128i*
const xinput = (
const __m128i *) input;
5218 const __m128i*
const xsecret = (
const __m128i *) secret;
5221 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m128i); i++) {
5223 __m128i
const data_vec = _mm_loadu_si128 (xinput+i);
5225 __m128i
const key_vec = _mm_loadu_si128 (xsecret+i);
5227 __m128i
const data_key = _mm_xor_si128 (data_vec, key_vec);
5229 __m128i
const data_key_lo = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1));
5231 __m128i
const product = _mm_mul_epu32 (data_key, data_key_lo);
5233 __m128i
const data_swap = _mm_shuffle_epi32(data_vec, _MM_SHUFFLE(1,0,3,2));
5234 __m128i
const sum = _mm_add_epi64(xacc[i], data_swap);
5236 xacc[i] = _mm_add_epi64(product, sum);
5239XXH_FORCE_INLINE XXH_TARGET_SSE2 XXH3_ACCUMULATE_TEMPLATE(sse2)
5241XXH_FORCE_INLINE XXH_TARGET_SSE2
void
5242XXH3_scrambleAcc_sse2(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5244 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5245 { __m128i*
const xacc = (__m128i*) acc;
5248 const __m128i*
const xsecret = (
const __m128i *) secret;
5249 const __m128i prime32 = _mm_set1_epi32((
int)XXH_PRIME32_1);
5252 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m128i); i++) {
5254 __m128i
const acc_vec = xacc[i];
5255 __m128i
const shifted = _mm_srli_epi64 (acc_vec, 47);
5256 __m128i
const data_vec = _mm_xor_si128 (acc_vec, shifted);
5258 __m128i
const key_vec = _mm_loadu_si128 (xsecret+i);
5259 __m128i
const data_key = _mm_xor_si128 (data_vec, key_vec);
5262 __m128i
const data_key_hi = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1));
5263 __m128i
const prod_lo = _mm_mul_epu32 (data_key, prime32);
5264 __m128i
const prod_hi = _mm_mul_epu32 (data_key_hi, prime32);
5265 xacc[i] = _mm_add_epi64(prod_lo, _mm_slli_epi64(prod_hi, 32));
5270XXH_FORCE_INLINE XXH_TARGET_SSE2
void XXH3_initCustomSecret_sse2(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
5272 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0);
5273 (void)(&XXH_writeLE64);
5274 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE /
sizeof(__m128i);
5276# if defined(_MSC_VER) && defined(_M_IX86) && _MSC_VER <= 1900
5280 xxh_u64
const seed64_unsigned = (xxh_u64)seed64;
5281 xxh_u64
const neg_seed64 = (xxh_u64)(0ULL - seed64_unsigned);
5282 __m128i
const seed = _mm_set_epi32(
5283 (
int)(neg_seed64 >> 32),
5285 (
int)(seed64_unsigned >> 32),
5286 (
int)(seed64_unsigned)
5289 __m128i
const seed = _mm_set_epi64x((xxh_i64)(0U - seed64), (xxh_i64)seed64);
5293 const void*
const src16 = XXH3_kSecret;
5294 __m128i* dst16 = (__m128i*) customSecret;
5295# if defined(__GNUC__) || defined(__clang__)
5301 XXH_COMPILER_GUARD(dst16);
5303 XXH_ASSERT(((
size_t)src16 & 15) == 0);
5304 XXH_ASSERT(((
size_t)dst16 & 15) == 0);
5306 for (i=0; i < nbRounds; ++i) {
5307 dst16[i] = _mm_add_epi64(_mm_load_si128((
const __m128i *)src16+i), seed);
5313#if (XXH_VECTOR == XXH_NEON)
5316XXH_FORCE_INLINE
void
5317XXH3_scalarRound(
void* XXH_RESTRICT acc,
void const* XXH_RESTRICT input,
5318 void const* XXH_RESTRICT secret,
size_t lane);
5320XXH_FORCE_INLINE
void
5321XXH3_scalarScrambleRound(
void* XXH_RESTRICT acc,
5322 void const* XXH_RESTRICT secret,
size_t lane);
5348XXH_FORCE_INLINE
void
5349XXH3_accumulate_512_neon(
void* XXH_RESTRICT acc,
5350 const void* XXH_RESTRICT input,
5351 const void* XXH_RESTRICT secret)
5353 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5354 XXH_STATIC_ASSERT(XXH3_NEON_LANES > 0 && XXH3_NEON_LANES <= XXH_ACC_NB && XXH3_NEON_LANES % 2 == 0);
5356 xxh_aliasing_uint64x2_t*
const xacc = (xxh_aliasing_uint64x2_t*) acc;
5358 uint8_t
const* xinput = (
const uint8_t *) input;
5359 uint8_t
const* xsecret = (
const uint8_t *) secret;
5362#ifdef __wasm_simd128__
5380 XXH_COMPILER_GUARD(xsecret);
5383 for (i = XXH3_NEON_LANES; i < XXH_ACC_NB; i++) {
5384 XXH3_scalarRound(acc, input, secret, i);
5388 for (; i+1 < XXH3_NEON_LANES / 2; i+=2) {
5390 uint64x2_t data_vec_1 = XXH_vld1q_u64(xinput + (i * 16));
5391 uint64x2_t data_vec_2 = XXH_vld1q_u64(xinput + ((i+1) * 16));
5393 uint64x2_t key_vec_1 = XXH_vld1q_u64(xsecret + (i * 16));
5394 uint64x2_t key_vec_2 = XXH_vld1q_u64(xsecret + ((i+1) * 16));
5396 uint64x2_t data_swap_1 = vextq_u64(data_vec_1, data_vec_1, 1);
5397 uint64x2_t data_swap_2 = vextq_u64(data_vec_2, data_vec_2, 1);
5399 uint64x2_t data_key_1 = veorq_u64(data_vec_1, key_vec_1);
5400 uint64x2_t data_key_2 = veorq_u64(data_vec_2, key_vec_2);
5415 uint32x4x2_t unzipped = vuzpq_u32(
5416 vreinterpretq_u32_u64(data_key_1),
5417 vreinterpretq_u32_u64(data_key_2)
5420 uint32x4_t data_key_lo = unzipped.val[0];
5422 uint32x4_t data_key_hi = unzipped.val[1];
5430 uint64x2_t sum_1 = XXH_vmlal_low_u32(data_swap_1, data_key_lo, data_key_hi);
5431 uint64x2_t sum_2 = XXH_vmlal_high_u32(data_swap_2, data_key_lo, data_key_hi);
5444 XXH_COMPILER_GUARD_CLANG_NEON(sum_1);
5445 XXH_COMPILER_GUARD_CLANG_NEON(sum_2);
5447 xacc[i] = vaddq_u64(xacc[i], sum_1);
5448 xacc[i+1] = vaddq_u64(xacc[i+1], sum_2);
5451 for (; i < XXH3_NEON_LANES / 2; i++) {
5453 uint64x2_t data_vec = XXH_vld1q_u64(xinput + (i * 16));
5455 uint64x2_t key_vec = XXH_vld1q_u64(xsecret + (i * 16));
5457 uint64x2_t data_swap = vextq_u64(data_vec, data_vec, 1);
5459 uint64x2_t data_key = veorq_u64(data_vec, key_vec);
5462 uint32x2_t data_key_lo = vmovn_u64(data_key);
5464 uint32x2_t data_key_hi = vshrn_n_u64(data_key, 32);
5466 uint64x2_t sum = vmlal_u32(data_swap, data_key_lo, data_key_hi);
5468 XXH_COMPILER_GUARD_CLANG_NEON(sum);
5470 xacc[i] = vaddq_u64 (xacc[i], sum);
5474XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(neon)
5476XXH_FORCE_INLINE
void
5477XXH3_scrambleAcc_neon(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5479 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5481 { xxh_aliasing_uint64x2_t* xacc = (xxh_aliasing_uint64x2_t*) acc;
5482 uint8_t
const* xsecret = (uint8_t
const*) secret;
5486#ifndef __wasm_simd128__
5488 uint32x2_t
const kPrimeLo = vdup_n_u32(XXH_PRIME32_1);
5490 uint32x4_t
const kPrimeHi = vreinterpretq_u32_u64(vdupq_n_u64((xxh_u64)XXH_PRIME32_1 << 32));
5494 for (i = XXH3_NEON_LANES; i < XXH_ACC_NB; i++) {
5495 XXH3_scalarScrambleRound(acc, secret, i);
5497 for (i=0; i < XXH3_NEON_LANES / 2; i++) {
5499 uint64x2_t acc_vec = xacc[i];
5500 uint64x2_t shifted = vshrq_n_u64(acc_vec, 47);
5501 uint64x2_t data_vec = veorq_u64(acc_vec, shifted);
5504 uint64x2_t key_vec = XXH_vld1q_u64(xsecret + (i * 16));
5505 uint64x2_t data_key = veorq_u64(data_vec, key_vec);
5507#ifdef __wasm_simd128__
5509 xacc[i] = data_key * XXH_PRIME32_1;
5522 uint32x4_t prod_hi = vmulq_u32 (vreinterpretq_u32_u64(data_key), kPrimeHi);
5524 uint32x2_t data_key_lo = vmovn_u64(data_key);
5526 xacc[i] = vmlal_u32(vreinterpretq_u64_u32(prod_hi), data_key_lo, kPrimeLo);
5533#if (XXH_VECTOR == XXH_VSX)
5535XXH_FORCE_INLINE
void
5536XXH3_accumulate_512_vsx(
void* XXH_RESTRICT acc,
5537 const void* XXH_RESTRICT input,
5538 const void* XXH_RESTRICT secret)
5541 xxh_aliasing_u64x2*
const xacc = (xxh_aliasing_u64x2*) acc;
5542 xxh_u8
const*
const xinput = (xxh_u8
const*) input;
5543 xxh_u8
const*
const xsecret = (xxh_u8
const*) secret;
5544 xxh_u64x2
const v32 = { 32, 32 };
5546 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(xxh_u64x2); i++) {
5548 xxh_u64x2
const data_vec = XXH_vec_loadu(xinput + 16*i);
5550 xxh_u64x2
const key_vec = XXH_vec_loadu(xsecret + 16*i);
5551 xxh_u64x2
const data_key = data_vec ^ key_vec;
5553 xxh_u32x4
const shuffled = (xxh_u32x4)vec_rl(data_key, v32);
5555 xxh_u64x2
const product = XXH_vec_mulo((xxh_u32x4)data_key, shuffled);
5557 xxh_u64x2 acc_vec = xacc[i];
5562 acc_vec += vec_permi(data_vec, data_vec, 2);
5564 acc_vec += vec_xxpermdi(data_vec, data_vec, 2);
5569XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(vsx)
5571XXH_FORCE_INLINE
void
5572XXH3_scrambleAcc_vsx(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5574 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5576 { xxh_aliasing_u64x2*
const xacc = (xxh_aliasing_u64x2*) acc;
5577 const xxh_u8*
const xsecret = (
const xxh_u8*) secret;
5579 xxh_u64x2
const v32 = { 32, 32 };
5580 xxh_u64x2
const v47 = { 47, 47 };
5581 xxh_u32x4
const prime = { XXH_PRIME32_1, XXH_PRIME32_1, XXH_PRIME32_1, XXH_PRIME32_1 };
5583 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(xxh_u64x2); i++) {
5585 xxh_u64x2
const acc_vec = xacc[i];
5586 xxh_u64x2
const data_vec = acc_vec ^ (acc_vec >> v47);
5589 xxh_u64x2
const key_vec = XXH_vec_loadu(xsecret + 16*i);
5590 xxh_u64x2
const data_key = data_vec ^ key_vec;
5594 xxh_u64x2
const prod_even = XXH_vec_mule((xxh_u32x4)data_key, prime);
5596 xxh_u64x2
const prod_odd = XXH_vec_mulo((xxh_u32x4)data_key, prime);
5597 xacc[i] = prod_odd + (prod_even << v32);
5603#if (XXH_VECTOR == XXH_SVE)
5605XXH_FORCE_INLINE
void
5606XXH3_accumulate_512_sve(
void* XXH_RESTRICT acc,
5607 const void* XXH_RESTRICT input,
5608 const void* XXH_RESTRICT secret)
5610 uint64_t *xacc = (uint64_t *)acc;
5611 const uint64_t *xinput = (
const uint64_t *)(
const void *)input;
5612 const uint64_t *xsecret = (
const uint64_t *)(
const void *)secret;
5613 svuint64_t kSwap = sveor_n_u64_z(svptrue_b64(), svindex_u64(0, 1), 1);
5614 uint64_t element_count = svcntd();
5615 if (element_count >= 8) {
5616 svbool_t mask = svptrue_pat_b64(SV_VL8);
5617 svuint64_t vacc = svld1_u64(mask, xacc);
5619 svst1_u64(mask, xacc, vacc);
5620 }
else if (element_count == 2) {
5621 svbool_t mask = svptrue_pat_b64(SV_VL2);
5622 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5623 svuint64_t acc1 = svld1_u64(mask, xacc + 2);
5624 svuint64_t acc2 = svld1_u64(mask, xacc + 4);
5625 svuint64_t acc3 = svld1_u64(mask, xacc + 6);
5630 svst1_u64(mask, xacc + 0, acc0);
5631 svst1_u64(mask, xacc + 2, acc1);
5632 svst1_u64(mask, xacc + 4, acc2);
5633 svst1_u64(mask, xacc + 6, acc3);
5635 svbool_t mask = svptrue_pat_b64(SV_VL4);
5636 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5637 svuint64_t acc1 = svld1_u64(mask, xacc + 4);
5640 svst1_u64(mask, xacc + 0, acc0);
5641 svst1_u64(mask, xacc + 4, acc1);
5645XXH_FORCE_INLINE
void
5646XXH3_accumulate_sve(xxh_u64* XXH_RESTRICT acc,
5647 const xxh_u8* XXH_RESTRICT input,
5648 const xxh_u8* XXH_RESTRICT secret,
5651 if (nbStripes != 0) {
5652 uint64_t *xacc = (uint64_t *)acc;
5653 const uint64_t *xinput = (
const uint64_t *)(
const void *)input;
5654 const uint64_t *xsecret = (
const uint64_t *)(
const void *)secret;
5655 svuint64_t kSwap = sveor_n_u64_z(svptrue_b64(), svindex_u64(0, 1), 1);
5656 uint64_t element_count = svcntd();
5657 if (element_count >= 8) {
5658 svbool_t mask = svptrue_pat_b64(SV_VL8);
5659 svuint64_t vacc = svld1_u64(mask, xacc + 0);
5662 svprfd(mask, xinput + 128, SV_PLDL1STRM);
5667 }
while (nbStripes != 0);
5669 svst1_u64(mask, xacc + 0, vacc);
5670 }
else if (element_count == 2) {
5671 svbool_t mask = svptrue_pat_b64(SV_VL2);
5672 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5673 svuint64_t acc1 = svld1_u64(mask, xacc + 2);
5674 svuint64_t acc2 = svld1_u64(mask, xacc + 4);
5675 svuint64_t acc3 = svld1_u64(mask, xacc + 6);
5677 svprfd(mask, xinput + 128, SV_PLDL1STRM);
5685 }
while (nbStripes != 0);
5687 svst1_u64(mask, xacc + 0, acc0);
5688 svst1_u64(mask, xacc + 2, acc1);
5689 svst1_u64(mask, xacc + 4, acc2);
5690 svst1_u64(mask, xacc + 6, acc3);
5692 svbool_t mask = svptrue_pat_b64(SV_VL4);
5693 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5694 svuint64_t acc1 = svld1_u64(mask, xacc + 4);
5696 svprfd(mask, xinput + 128, SV_PLDL1STRM);
5702 }
while (nbStripes != 0);
5704 svst1_u64(mask, xacc + 0, acc0);
5705 svst1_u64(mask, xacc + 4, acc1);
5712#if (XXH_VECTOR == XXH_LSX)
5713#define _LSX_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
5715XXH_FORCE_INLINE
void
5716XXH3_accumulate_512_lsx(
void* XXH_RESTRICT acc,
5717 const void* XXH_RESTRICT input,
5718 const void* XXH_RESTRICT secret)
5720 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5722 __m128i*
const xacc = (__m128i *) acc;
5723 const __m128i*
const xinput = (
const __m128i *) input;
5724 const __m128i*
const xsecret = (
const __m128i *) secret;
5727 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(__m128i); i++) {
5729 __m128i
const data_vec = __lsx_vld(xinput + i, 0);
5731 __m128i
const key_vec = __lsx_vld(xsecret + i, 0);
5733 __m128i
const data_key = __lsx_vxor_v(data_vec, key_vec);
5735 __m128i
const data_key_lo = __lsx_vsrli_d(data_key, 32);
5738 __m128i
const product = __lsx_vmulwev_d_wu(data_key, data_key_lo);
5740 __m128i
const data_swap = __lsx_vshuf4i_w(data_vec, _LSX_SHUFFLE(1, 0, 3, 2));
5741 __m128i
const sum = __lsx_vadd_d(xacc[i], data_swap);
5743 xacc[i] = __lsx_vadd_d(product, sum);
5747XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(lsx)
5749XXH_FORCE_INLINE
void
5750XXH3_scrambleAcc_lsx(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5752 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5754 __m128i*
const xacc = (__m128i*) acc;
5755 const __m128i*
const xsecret = (
const __m128i *) secret;
5756 const __m128i prime32 = __lsx_vreplgr2vr_d(XXH_PRIME32_1);
5759 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(__m128i); i++) {
5761 __m128i
const acc_vec = xacc[i];
5762 __m128i
const shifted = __lsx_vsrli_d(acc_vec, 47);
5763 __m128i
const data_vec = __lsx_vxor_v(acc_vec, shifted);
5765 __m128i
const key_vec = __lsx_vld(xsecret + i, 0);
5766 __m128i
const data_key = __lsx_vxor_v(data_vec, key_vec);
5769 xacc[i] = __lsx_vmul_d(data_key, prime32);
5776#if (XXH_VECTOR == XXH_LASX)
5777#define _LASX_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
5779XXH_FORCE_INLINE
void
5780XXH3_accumulate_512_lasx(
void* XXH_RESTRICT acc,
5781 const void* XXH_RESTRICT input,
5782 const void* XXH_RESTRICT secret)
5784 XXH_ASSERT((((
size_t)acc) & 31) == 0);
5787 __m256i*
const xacc = (__m256i *) acc;
5788 const __m256i*
const xinput = (
const __m256i *) input;
5789 const __m256i*
const xsecret = (
const __m256i *) secret;
5791 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(__m256i); i++) {
5793 __m256i
const data_vec = __lasx_xvld(xinput + i, 0);
5795 __m256i
const key_vec = __lasx_xvld(xsecret + i, 0);
5797 __m256i
const data_key = __lasx_xvxor_v(data_vec, key_vec);
5799 __m256i
const data_key_lo = __lasx_xvsrli_d(data_key, 32);
5802 __m256i
const product = __lasx_xvmulwev_d_wu(data_key, data_key_lo);
5804 __m256i
const data_swap = __lasx_xvshuf4i_w(data_vec, _LASX_SHUFFLE(1, 0, 3, 2));
5805 __m256i
const sum = __lasx_xvadd_d(xacc[i], data_swap);
5807 xacc[i] = __lasx_xvadd_d(product, sum);
5811XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(lasx)
5813XXH_FORCE_INLINE
void
5814XXH3_scrambleAcc_lasx(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5816 XXH_ASSERT((((
size_t)acc) & 31) == 0);
5818 __m256i*
const xacc = (__m256i*) acc;
5819 const __m256i*
const xsecret = (
const __m256i *) secret;
5820 const __m256i prime32 = __lasx_xvreplgr2vr_d(XXH_PRIME32_1);
5823 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(__m256i); i++) {
5825 __m256i
const acc_vec = xacc[i];
5826 __m256i
const shifted = __lasx_xvsrli_d(acc_vec, 47);
5827 __m256i
const data_vec = __lasx_xvxor_v(acc_vec, shifted);
5829 __m256i
const key_vec = __lasx_xvld(xsecret + i, 0);
5830 __m256i
const data_key = __lasx_xvxor_v(data_vec, key_vec);
5833 xacc[i] = __lasx_xvmul_d(data_key, prime32);
5840#if (XXH_VECTOR == XXH_RVV)
5841 #define XXH_CONCAT2(X, Y) X ## Y
5842 #define XXH_CONCAT(X, Y) XXH_CONCAT2(X, Y)
5843#if ((defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 13) || \
5844 (defined(__clang__) && __clang_major__ < 16))
5845 #define XXH_RVOP(op) op
5846 #define XXH_RVCAST(op) XXH_CONCAT(vreinterpret_v_, op)
5848 #define XXH_RVOP(op) XXH_CONCAT(__riscv_, op)
5849 #define XXH_RVCAST(op) XXH_CONCAT(__riscv_vreinterpret_v_, op)
5851XXH_FORCE_INLINE
void
5852XXH3_accumulate_512_rvv(
void* XXH_RESTRICT acc,
5853 const void* XXH_RESTRICT input,
5854 const void* XXH_RESTRICT secret)
5856 XXH_ASSERT((((
size_t)acc) & 63) == 0);
5860 size_t vl = XXH_RVOP(vsetvl_e64m2)(8);
5862 uint64_t* xacc = (uint64_t*) acc;
5863 const uint64_t* xinput = (
const uint64_t*) input;
5864 const uint64_t* xsecret = (
const uint64_t*) secret;
5865 static const uint64_t swap_mask[16] = {1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14};
5866 vuint64m2_t xswap_mask = XXH_RVOP(vle64_v_u64m2)(swap_mask, vl);
5869 for (i = 0; i < XXH_STRIPE_LEN/8; i += vl) {
5871 vuint64m2_t data_vec = XXH_RVCAST(u8m2_u64m2)(XXH_RVOP(vle8_v_u8m2)((
const uint8_t*)(xinput + i), vl * 8));
5873 vuint64m2_t key_vec = XXH_RVCAST(u8m2_u64m2)(XXH_RVOP(vle8_v_u8m2)((
const uint8_t*)(xsecret + i), vl * 8));
5875 vuint64m2_t acc_vec = XXH_RVOP(vle64_v_u64m2)(xacc + i, vl);
5877 vuint64m2_t data_key = XXH_RVOP(vxor_vv_u64m2)(data_vec, key_vec, vl);
5879 vuint64m2_t data_key_hi = XXH_RVOP(vsrl_vx_u64m2)(data_key, 32, vl);
5881 vuint64m2_t data_key_lo = XXH_RVOP(vand_vx_u64m2)(data_key, 0xffffffff, vl);
5883 vuint64m2_t data_swap = XXH_RVOP(vrgather_vv_u64m2)(data_vec, xswap_mask, vl);
5885 acc_vec = XXH_RVOP(vmacc_vv_u64m2)(acc_vec, data_key_lo, data_key_hi, vl);
5887 acc_vec = XXH_RVOP(vadd_vv_u64m2)(acc_vec, data_swap, vl);
5889 XXH_RVOP(vse64_v_u64m2)(xacc + i, acc_vec, vl);
5894XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(rvv)
5896XXH_FORCE_INLINE
void
5897XXH3_scrambleAcc_rvv(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5899 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5901 size_t count = XXH_STRIPE_LEN/8;
5902 uint64_t* xacc = (uint64_t*)acc;
5903 const uint8_t* xsecret = (
const uint8_t *)secret;
5905 for (; count > 0; count -= vl, xacc += vl, xsecret += vl*8) {
5906 vl = XXH_RVOP(vsetvl_e64m2)(count);
5909 vuint64m2_t key_vec = XXH_RVCAST(u8m2_u64m2)(XXH_RVOP(vle8_v_u8m2)(xsecret, vl*8));
5911 vuint64m2_t acc_vec = XXH_RVOP(vle64_v_u64m2)(xacc, vl);
5913 vuint64m2_t vsrl = XXH_RVOP(vsrl_vx_u64m2)(acc_vec, 47, vl);
5914 acc_vec = XXH_RVOP(vxor_vv_u64m2)(acc_vec, vsrl, vl);
5916 acc_vec = XXH_RVOP(vxor_vv_u64m2)(acc_vec, key_vec, vl);
5918 acc_vec = XXH_RVOP(vmul_vx_u64m2)(acc_vec, XXH_PRIME32_1, vl);
5920 XXH_RVOP(vse64_v_u64m2)(xacc, acc_vec, vl);
5926XXH_FORCE_INLINE
void
5927XXH3_initCustomSecret_rvv(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
5929 XXH_STATIC_ASSERT(XXH_SEC_ALIGN >= 8);
5930 XXH_ASSERT(((
size_t)customSecret & 7) == 0);
5931 (void)(&XXH_writeLE64);
5933 size_t count = XXH_SECRET_DEFAULT_SIZE/8;
5935 size_t VLMAX = XXH_RVOP(vsetvlmax_e64m2)();
5936 int64_t* cSecret = (int64_t*)customSecret;
5937 const int64_t* kSecret = (
const int64_t*)(
const void*)XXH3_kSecret;
5939#if __riscv_v_intrinsic >= 1000000
5941 vbool32_t mneg = XXH_RVCAST(u8m1_b32)(
5942 XXH_RVOP(vmv_v_x_u8m1)(0xaa, XXH_RVOP(vsetvlmax_e8m1)()));
5945 size_t vlmax = XXH_RVOP(vsetvlmax_e8m1)();
5946 vbool32_t mneg = XXH_RVOP(vmseq_vx_u8mf4_b32)(
5947 XXH_RVOP(vand_vx_u8mf4)(
5948 XXH_RVOP(vid_v_u8mf4)(vlmax), 1, vlmax), 1, vlmax);
5950 vint64m2_t seed = XXH_RVOP(vmv_v_x_i64m2)((int64_t)seed64, VLMAX);
5951 seed = XXH_RVOP(vneg_v_i64m2_mu)(mneg, seed, seed, VLMAX);
5953 for (; count > 0; count -= vl, cSecret += vl, kSecret += vl) {
5955 vl = XXH_RVOP(vsetvl_e64m2)(count < VLMAX ? count : VLMAX);
5957 vint64m2_t src = XXH_RVOP(vle64_v_i64m2)(kSecret, vl);
5958 vint64m2_t res = XXH_RVOP(vadd_vv_i64m2)(src, seed, vl);
5959 XXH_RVOP(vse64_v_i64m2)(cSecret, res, vl);
5969#if defined(__aarch64__) && (defined(__GNUC__) || defined(__clang__))
5984XXH_FORCE_INLINE xxh_u64
5985XXH_mult32to64_add64(xxh_u64 lhs, xxh_u64 rhs, xxh_u64 acc)
5989 __asm__(
"umaddl %x0, %w1, %w2, %x3" :
"=r" (ret) :
"r" (lhs),
"r" (rhs),
"r" (acc));
5993XXH_FORCE_INLINE xxh_u64
5994XXH_mult32to64_add64(xxh_u64 lhs, xxh_u64 rhs, xxh_u64 acc)
5996 return XXH_mult32to64((xxh_u32)lhs, (xxh_u32)rhs) + acc;
6007XXH_FORCE_INLINE
void
6008XXH3_scalarRound(
void* XXH_RESTRICT acc,
6009 void const* XXH_RESTRICT input,
6010 void const* XXH_RESTRICT secret,
6013 xxh_u64* xacc = (xxh_u64*) acc;
6014 xxh_u8
const* xinput = (xxh_u8
const*) input;
6015 xxh_u8
const* xsecret = (xxh_u8
const*) secret;
6016 XXH_ASSERT(lane < XXH_ACC_NB);
6017 XXH_ASSERT(((
size_t)acc & (XXH_ACC_ALIGN-1)) == 0);
6019 xxh_u64
const data_val = XXH_readLE64(xinput + lane * 8);
6020 xxh_u64
const data_key = data_val ^ XXH_readLE64(xsecret + lane * 8);
6021 xacc[lane ^ 1] += data_val;
6022 xacc[lane] = XXH_mult32to64_add64(data_key , data_key >> 32, xacc[lane]);
6030XXH_FORCE_INLINE
void
6031XXH3_accumulate_512_scalar(
void* XXH_RESTRICT acc,
6032 const void* XXH_RESTRICT input,
6033 const void* XXH_RESTRICT secret)
6037#if defined(__GNUC__) && !defined(__clang__) \
6038 && (defined(__arm__) || defined(__thumb2__)) \
6039 && defined(__ARM_FEATURE_UNALIGNED) \
6040 && XXH_SIZE_OPT <= 0
6041# pragma GCC unroll 8
6043 for (i=0; i < XXH_ACC_NB; i++) {
6044 XXH3_scalarRound(acc, input, secret, i);
6047XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(scalar)
6056XXH_FORCE_INLINE
void
6057XXH3_scalarScrambleRound(
void* XXH_RESTRICT acc,
6058 void const* XXH_RESTRICT secret,
6061 xxh_u64*
const xacc = (xxh_u64*) acc;
6062 const xxh_u8*
const xsecret = (
const xxh_u8*) secret;
6063 XXH_ASSERT((((
size_t)acc) & (XXH_ACC_ALIGN-1)) == 0);
6064 XXH_ASSERT(lane < XXH_ACC_NB);
6066 xxh_u64
const key64 = XXH_readLE64(xsecret + lane * 8);
6067 xxh_u64 acc64 = xacc[lane];
6068 acc64 = XXH_xorshift64(acc64, 47);
6070 acc64 *= XXH_PRIME32_1;
6079XXH_FORCE_INLINE
void
6080XXH3_scrambleAcc_scalar(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
6083 for (i=0; i < XXH_ACC_NB; i++) {
6084 XXH3_scalarScrambleRound(acc, secret, i);
6088XXH_FORCE_INLINE
void
6089XXH3_initCustomSecret_scalar(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
6096 const xxh_u8* kSecretPtr = XXH3_kSecret;
6097 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0);
6099#if defined(__GNUC__) && defined(__aarch64__)
6132 XXH_COMPILER_GUARD(kSecretPtr);
6134 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE / 16;
6136 for (i=0; i < nbRounds; i++) {
6143 xxh_u64 lo = XXH_readLE64(kSecretPtr + 16*i) + seed64;
6144 xxh_u64 hi = XXH_readLE64(kSecretPtr + 16*i + 8) - seed64;
6145 XXH_writeLE64((xxh_u8*)customSecret + 16*i, lo);
6146 XXH_writeLE64((xxh_u8*)customSecret + 16*i + 8, hi);
6151typedef void (*XXH3_f_accumulate)(xxh_u64* XXH_RESTRICT,
const xxh_u8* XXH_RESTRICT,
const xxh_u8* XXH_RESTRICT, size_t);
6152typedef void (*XXH3_f_scrambleAcc)(
void* XXH_RESTRICT,
const void*);
6153typedef void (*XXH3_f_initCustomSecret)(
void* XXH_RESTRICT, xxh_u64);
6156#if (XXH_VECTOR == XXH_AVX512)
6158#define XXH3_accumulate_512 XXH3_accumulate_512_avx512
6159#define XXH3_accumulate XXH3_accumulate_avx512
6160#define XXH3_scrambleAcc XXH3_scrambleAcc_avx512
6161#define XXH3_initCustomSecret XXH3_initCustomSecret_avx512
6163#elif (XXH_VECTOR == XXH_AVX2)
6165#define XXH3_accumulate_512 XXH3_accumulate_512_avx2
6166#define XXH3_accumulate XXH3_accumulate_avx2
6167#define XXH3_scrambleAcc XXH3_scrambleAcc_avx2
6168#define XXH3_initCustomSecret XXH3_initCustomSecret_avx2
6170#elif (XXH_VECTOR == XXH_SSE2)
6172#define XXH3_accumulate_512 XXH3_accumulate_512_sse2
6173#define XXH3_accumulate XXH3_accumulate_sse2
6174#define XXH3_scrambleAcc XXH3_scrambleAcc_sse2
6175#define XXH3_initCustomSecret XXH3_initCustomSecret_sse2
6177#elif (XXH_VECTOR == XXH_NEON)
6179#define XXH3_accumulate_512 XXH3_accumulate_512_neon
6180#define XXH3_accumulate XXH3_accumulate_neon
6181#define XXH3_scrambleAcc XXH3_scrambleAcc_neon
6182#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6184#elif (XXH_VECTOR == XXH_VSX)
6186#define XXH3_accumulate_512 XXH3_accumulate_512_vsx
6187#define XXH3_accumulate XXH3_accumulate_vsx
6188#define XXH3_scrambleAcc XXH3_scrambleAcc_vsx
6189#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6191#elif (XXH_VECTOR == XXH_SVE)
6192#define XXH3_accumulate_512 XXH3_accumulate_512_sve
6193#define XXH3_accumulate XXH3_accumulate_sve
6194#define XXH3_scrambleAcc XXH3_scrambleAcc_scalar
6195#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6197#elif (XXH_VECTOR == XXH_LASX)
6198#define XXH3_accumulate_512 XXH3_accumulate_512_lasx
6199#define XXH3_accumulate XXH3_accumulate_lasx
6200#define XXH3_scrambleAcc XXH3_scrambleAcc_lasx
6201#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6203#elif (XXH_VECTOR == XXH_LSX)
6204#define XXH3_accumulate_512 XXH3_accumulate_512_lsx
6205#define XXH3_accumulate XXH3_accumulate_lsx
6206#define XXH3_scrambleAcc XXH3_scrambleAcc_lsx
6207#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6209#elif (XXH_VECTOR == XXH_RVV)
6210#define XXH3_accumulate_512 XXH3_accumulate_512_rvv
6211#define XXH3_accumulate XXH3_accumulate_rvv
6212#define XXH3_scrambleAcc XXH3_scrambleAcc_rvv
6213#define XXH3_initCustomSecret XXH3_initCustomSecret_rvv
6217#define XXH3_accumulate_512 XXH3_accumulate_512_scalar
6218#define XXH3_accumulate XXH3_accumulate_scalar
6219#define XXH3_scrambleAcc XXH3_scrambleAcc_scalar
6220#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6224#if XXH_SIZE_OPT >= 1
6225# undef XXH3_initCustomSecret
6226# define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6229XXH_FORCE_INLINE
void
6230XXH3_hashLong_internal_loop(xxh_u64* XXH_RESTRICT acc,
6231 const xxh_u8* XXH_RESTRICT input,
size_t len,
6232 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
6233 XXH3_f_accumulate f_acc,
6234 XXH3_f_scrambleAcc f_scramble)
6236 size_t const nbStripesPerBlock = (secretSize - XXH_STRIPE_LEN) / XXH_SECRET_CONSUME_RATE;
6237 size_t const block_len = XXH_STRIPE_LEN * nbStripesPerBlock;
6238 size_t const nb_blocks = (len - 1) / block_len;
6244 for (
n = 0;
n < nb_blocks;
n++) {
6245 f_acc(acc, input +
n*block_len, secret, nbStripesPerBlock);
6246 f_scramble(acc, secret + secretSize - XXH_STRIPE_LEN);
6250 XXH_ASSERT(len > XXH_STRIPE_LEN);
6251 {
size_t const nbStripes = ((len - 1) - (block_len * nb_blocks)) / XXH_STRIPE_LEN;
6252 XXH_ASSERT(nbStripes <= (secretSize / XXH_SECRET_CONSUME_RATE));
6253 f_acc(acc, input + nb_blocks*block_len, secret, nbStripes);
6256 {
const xxh_u8*
const p = input + len - XXH_STRIPE_LEN;
6257#define XXH_SECRET_LASTACC_START 7
6258 XXH3_accumulate_512(acc, p, secret + secretSize - XXH_STRIPE_LEN - XXH_SECRET_LASTACC_START);
6262XXH_FORCE_INLINE xxh_u64
6263XXH3_mix2Accs(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret)
6265 return XXH3_mul128_fold64(
6266 acc[0] ^ XXH_readLE64(secret),
6267 acc[1] ^ XXH_readLE64(secret+8) );
6271XXH3_mergeAccs(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret, xxh_u64 start)
6273 xxh_u64 result64 = start;
6276 for (i = 0; i < 4; i++) {
6277 result64 += XXH3_mix2Accs(acc+2*i, secret + 16*i);
6278#if defined(__clang__) \
6279 && (defined(__arm__) || defined(__thumb__)) \
6280 && (defined(__ARM_NEON) || defined(__ARM_NEON__)) \
6281 && !defined(XXH_ENABLE_AUTOVECTORIZE)
6290 XXH_COMPILER_GUARD(result64);
6294 return XXH3_avalanche(result64);
6298#define XXH_SECRET_MERGEACCS_START 11
6301XXH3_finalizeLong_64b(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret, xxh_u64 len)
6303 return XXH3_mergeAccs(acc, secret + XXH_SECRET_MERGEACCS_START, len * XXH_PRIME64_1);
6306#define XXH3_INIT_ACC { XXH_PRIME32_3, XXH_PRIME64_1, XXH_PRIME64_2, XXH_PRIME64_3, \
6307 XXH_PRIME64_4, XXH_PRIME32_2, XXH_PRIME64_5, XXH_PRIME32_1 }
6310XXH3_hashLong_64b_internal(
const void* XXH_RESTRICT input,
size_t len,
6311 const void* XXH_RESTRICT secret,
size_t secretSize,
6312 XXH3_f_accumulate f_acc,
6313 XXH3_f_scrambleAcc f_scramble)
6315 XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[XXH_ACC_NB] = XXH3_INIT_ACC;
6317 XXH3_hashLong_internal_loop(acc, (
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretSize, f_acc, f_scramble);
6320 XXH_STATIC_ASSERT(
sizeof(acc) == 64);
6321 XXH_ASSERT(secretSize >=
sizeof(acc) + XXH_SECRET_MERGEACCS_START);
6322 return XXH3_finalizeLong_64b(acc, (
const xxh_u8*)secret, (xxh_u64)len);
6333XXH3_hashLong_64b_withSecret(
const void* XXH_RESTRICT input,
size_t len,
6334 XXH64_hash_t seed64,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
6337 return XXH3_hashLong_64b_internal(input, len, secret, secretLen, XXH3_accumulate, XXH3_scrambleAcc);
6347XXH3_hashLong_64b_default(
const void* XXH_RESTRICT input,
size_t len,
6348 XXH64_hash_t seed64,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
6350 (void)seed64; (void)secret; (void)secretLen;
6351 return XXH3_hashLong_64b_internal(input, len, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_accumulate, XXH3_scrambleAcc);
6366XXH3_hashLong_64b_withSeed_internal(
const void* input,
size_t len,
6368 XXH3_f_accumulate f_acc,
6369 XXH3_f_scrambleAcc f_scramble,
6370 XXH3_f_initCustomSecret f_initSec)
6372#if XXH_SIZE_OPT <= 0
6374 return XXH3_hashLong_64b_internal(input, len,
6375 XXH3_kSecret,
sizeof(XXH3_kSecret),
6378 { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
6379 f_initSec(secret, seed);
6380 return XXH3_hashLong_64b_internal(input, len, secret,
sizeof(secret),
6389XXH3_hashLong_64b_withSeed(
const void* XXH_RESTRICT input,
size_t len,
6390 XXH64_hash_t seed,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
6392 (void)secret; (void)secretLen;
6393 return XXH3_hashLong_64b_withSeed_internal(input, len, seed,
6394 XXH3_accumulate, XXH3_scrambleAcc, XXH3_initCustomSecret);
6398typedef XXH64_hash_t (*XXH3_hashLong64_f)(
const void* XXH_RESTRICT, size_t,
6402XXH3_64bits_internal(
const void* XXH_RESTRICT input,
size_t len,
6403 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen,
6404 XXH3_hashLong64_f f_hashLong)
6415 return XXH3_len_0to16_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, seed64);
6417 return XXH3_len_17to128_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
6418 if (len <= XXH3_MIDSIZE_MAX)
6419 return XXH3_len_129to240_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
6420 return f_hashLong(input, len, seed64, (
const xxh_u8*)secret, secretLen);
6429 return XXH3_64bits_internal(input, length, 0, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_hashLong_64b_default);
6434XXH3_64bits_withSecret(XXH_NOESCAPE
const void* input,
size_t length, XXH_NOESCAPE
const void* secret,
size_t secretSize)
6436 return XXH3_64bits_internal(input, length, 0, secret, secretSize, XXH3_hashLong_64b_withSecret);
6443 return XXH3_64bits_internal(input, length, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_hashLong_64b_withSeed);
6447XXH3_64bits_withSecretandSeed(XXH_NOESCAPE
const void* input,
size_t length, XXH_NOESCAPE
const void* secret,
size_t secretSize,
XXH64_hash_t seed)
6449 if (length <= XXH3_MIDSIZE_MAX)
6450 return XXH3_64bits_internal(input, length, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), NULL);
6451 return XXH3_hashLong_64b_withSecret(input, length, seed, (
const xxh_u8*)secret, secretSize);
6456#ifndef XXH_NO_STREAM
6480static XXH_MALLOCF void* XXH_alignedMalloc(
size_t s,
size_t align)
6482 XXH_ASSERT(align <= 128 && align >= 8);
6483 XXH_ASSERT((align & (align-1)) == 0);
6484 XXH_ASSERT(s != 0 && s < (s + align));
6486 xxh_u8* base = (xxh_u8*)XXH_malloc(s + align);
6494 size_t offset = align - ((size_t)base & (align - 1));
6496 xxh_u8* ptr = base + offset;
6498 XXH_ASSERT((
size_t)ptr % align == 0);
6501 ptr[-1] = (xxh_u8)offset;
6511static void XXH_alignedFree(
void* p)
6514 xxh_u8* ptr = (xxh_u8*)p;
6516 xxh_u8 offset = ptr[-1];
6518 xxh_u8* base = ptr - offset;
6536 if (state==NULL)
return NULL;
6537 XXH3_INITSTATE(state);
6555 XXH_alignedFree(statePtr);
6563 XXH_memcpy(dst_state, src_state,
sizeof(*dst_state));
6569 const void* secret,
size_t secretSize)
6571 size_t const initStart = offsetof(
XXH3_state_t, bufferedSize);
6572 size_t const initLength = offsetof(
XXH3_state_t, nbStripesPerBlock) - initStart;
6573 XXH_ASSERT(offsetof(
XXH3_state_t, nbStripesPerBlock) > initStart);
6574 XXH_ASSERT(statePtr != NULL);
6576 XXH_memset((
char*)statePtr + initStart, 0, initLength);
6577 statePtr->acc[0] = XXH_PRIME32_3;
6578 statePtr->acc[1] = XXH_PRIME64_1;
6579 statePtr->acc[2] = XXH_PRIME64_2;
6580 statePtr->acc[3] = XXH_PRIME64_3;
6581 statePtr->acc[4] = XXH_PRIME64_4;
6582 statePtr->acc[5] = XXH_PRIME32_2;
6583 statePtr->acc[6] = XXH_PRIME64_5;
6584 statePtr->acc[7] = XXH_PRIME32_1;
6585 statePtr->seed = seed;
6586 statePtr->useSeed = (seed != 0);
6587 statePtr->extSecret = (
const unsigned char*)secret;
6589 statePtr->secretLimit = secretSize - XXH_STRIPE_LEN;
6590 statePtr->nbStripesPerBlock = statePtr->secretLimit / XXH_SECRET_CONSUME_RATE;
6598 XXH3_reset_internal(statePtr, 0, XXH3_kSecret, XXH_SECRET_DEFAULT_SIZE);
6607 XXH3_reset_internal(statePtr, 0, secret, secretSize);
6619 if ((seed != statePtr->seed) || (statePtr->extSecret != NULL))
6620 XXH3_initCustomSecret(statePtr->customSecret, seed);
6621 XXH3_reset_internal(statePtr, seed, NULL, XXH_SECRET_DEFAULT_SIZE);
6627XXH3_64bits_reset_withSecretandSeed(XXH_NOESCAPE
XXH3_state_t* statePtr, XXH_NOESCAPE
const void* secret,
size_t secretSize,
XXH64_hash_t seed64)
6632 XXH3_reset_internal(statePtr, seed64, secret, secretSize);
6633 statePtr->useSeed = 1;
6654XXH_FORCE_INLINE
const xxh_u8 *
6655XXH3_consumeStripes(xxh_u64* XXH_RESTRICT acc,
6656 size_t* XXH_RESTRICT nbStripesSoFarPtr,
size_t nbStripesPerBlock,
6657 const xxh_u8* XXH_RESTRICT input,
size_t nbStripes,
6658 const xxh_u8* XXH_RESTRICT secret,
size_t secretLimit,
6659 XXH3_f_accumulate f_acc,
6660 XXH3_f_scrambleAcc f_scramble)
6662 const xxh_u8* initialSecret = secret + *nbStripesSoFarPtr * XXH_SECRET_CONSUME_RATE;
6664 if (nbStripes >= (nbStripesPerBlock - *nbStripesSoFarPtr)) {
6666 size_t nbStripesThisIter = nbStripesPerBlock - *nbStripesSoFarPtr;
6670 f_acc(acc, input, initialSecret, nbStripesThisIter);
6671 f_scramble(acc, secret + secretLimit);
6672 input += nbStripesThisIter * XXH_STRIPE_LEN;
6673 nbStripes -= nbStripesThisIter;
6675 nbStripesThisIter = nbStripesPerBlock;
6676 initialSecret = secret;
6677 }
while (nbStripes >= nbStripesPerBlock);
6678 *nbStripesSoFarPtr = 0;
6681 if (nbStripes > 0) {
6682 f_acc(acc, input, initialSecret, nbStripes);
6683 input += nbStripes * XXH_STRIPE_LEN;
6684 *nbStripesSoFarPtr += nbStripes;
6690#ifndef XXH3_STREAM_USE_STACK
6691# if XXH_SIZE_OPT <= 0 && !defined(__clang__)
6692# define XXH3_STREAM_USE_STACK 1
6701 const xxh_u8* XXH_RESTRICT input,
size_t len,
6702 XXH3_f_accumulate f_acc,
6703 XXH3_f_scrambleAcc f_scramble)
6706 XXH_ASSERT(len == 0);
6710 XXH_ASSERT(state != NULL);
6711 state->totalLen += len;
6714 XXH_ASSERT(state->bufferedSize <= XXH3_INTERNALBUFFER_SIZE);
6715 if (len <= XXH3_INTERNALBUFFER_SIZE - state->bufferedSize) {
6716 XXH_memcpy(state->buffer + state->bufferedSize, input, len);
6717 state->bufferedSize += (XXH32_hash_t)len;
6721 {
const xxh_u8*
const bEnd = input + len;
6722 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
6723#if defined(XXH3_STREAM_USE_STACK) && XXH3_STREAM_USE_STACK >= 1
6728 XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[8];
6729 XXH_memcpy(acc, state->acc,
sizeof(acc));
6731 xxh_u64* XXH_RESTRICT
const acc = state->acc;
6735 #define XXH3_INTERNALBUFFER_STRIPES (XXH3_INTERNALBUFFER_SIZE / XXH_STRIPE_LEN)
6736 XXH_STATIC_ASSERT(XXH3_INTERNALBUFFER_SIZE % XXH_STRIPE_LEN == 0);
6742 if (state->bufferedSize) {
6743 size_t const loadSize = XXH3_INTERNALBUFFER_SIZE - state->bufferedSize;
6744 XXH_memcpy(state->buffer + state->bufferedSize, input, loadSize);
6746 XXH3_consumeStripes(acc,
6747 &state->nbStripesSoFar, state->nbStripesPerBlock,
6748 state->buffer, XXH3_INTERNALBUFFER_STRIPES,
6749 secret, state->secretLimit,
6751 state->bufferedSize = 0;
6753 XXH_ASSERT(input < bEnd);
6754 if (bEnd - input > XXH3_INTERNALBUFFER_SIZE) {
6755 size_t nbStripes = (size_t)(bEnd - 1 - input) / XXH_STRIPE_LEN;
6756 input = XXH3_consumeStripes(acc,
6757 &state->nbStripesSoFar, state->nbStripesPerBlock,
6759 secret, state->secretLimit,
6761 XXH_memcpy(state->buffer +
sizeof(state->buffer) - XXH_STRIPE_LEN, input - XXH_STRIPE_LEN, XXH_STRIPE_LEN);
6765 XXH_ASSERT(input < bEnd);
6766 XXH_ASSERT(bEnd - input <= XXH3_INTERNALBUFFER_SIZE);
6767 XXH_ASSERT(state->bufferedSize == 0);
6768 XXH_memcpy(state->buffer, input, (
size_t)(bEnd-input));
6769 state->bufferedSize = (XXH32_hash_t)(bEnd-input);
6770#if defined(XXH3_STREAM_USE_STACK) && XXH3_STREAM_USE_STACK >= 1
6772 XXH_memcpy(state->acc, acc,
sizeof(acc));
6783XXH3_update_regular(XXH_NOESCAPE
XXH3_state_t* state, XXH_NOESCAPE
const void* input,
size_t len)
6785 return XXH3_update(state, (
const xxh_u8*)input, len,
6786 XXH3_accumulate, XXH3_scrambleAcc);
6793 return XXH3_update_regular(state, input, len);
6797XXH_FORCE_INLINE
void
6800 const unsigned char* secret)
6802 xxh_u8 lastStripe[XXH_STRIPE_LEN];
6803 const xxh_u8* lastStripePtr;
6809 XXH_memcpy(acc, state->acc,
sizeof(state->acc));
6810 if (state->bufferedSize >= XXH_STRIPE_LEN) {
6812 size_t const nbStripes = (state->bufferedSize - 1) / XXH_STRIPE_LEN;
6813 size_t nbStripesSoFar = state->nbStripesSoFar;
6814 XXH3_consumeStripes(acc,
6815 &nbStripesSoFar, state->nbStripesPerBlock,
6816 state->buffer, nbStripes,
6817 secret, state->secretLimit,
6818 XXH3_accumulate, XXH3_scrambleAcc);
6819 lastStripePtr = state->buffer + state->bufferedSize - XXH_STRIPE_LEN;
6822 size_t const catchupSize = XXH_STRIPE_LEN - state->bufferedSize;
6823 XXH_ASSERT(state->bufferedSize > 0);
6824 XXH_memcpy(lastStripe, state->buffer +
sizeof(state->buffer) - catchupSize, catchupSize);
6825 XXH_memcpy(lastStripe + catchupSize, state->buffer, state->bufferedSize);
6826 lastStripePtr = lastStripe;
6829 XXH3_accumulate_512(acc,
6831 secret + state->secretLimit - XXH_SECRET_LASTACC_START);
6837 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
6838 if (state->totalLen > XXH3_MIDSIZE_MAX) {
6840 XXH3_digest_long(acc, state, secret);
6841 return XXH3_finalizeLong_64b(acc, secret, (xxh_u64)state->totalLen);
6847 secret, state->secretLimit + XXH_STRIPE_LEN);
6870XXH3_len_1to3_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
6873 XXH_ASSERT(input != NULL);
6874 XXH_ASSERT(1 <= len && len <= 3);
6875 XXH_ASSERT(secret != NULL);
6881 { xxh_u8
const c1 = input[0];
6882 xxh_u8
const c2 = input[len >> 1];
6883 xxh_u8
const c3 = input[len - 1];
6884 xxh_u32
const combinedl = ((xxh_u32)c1 <<16) | ((xxh_u32)c2 << 24)
6885 | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8);
6886 xxh_u32
const combinedh = XXH_rotl32(XXH_swap32(combinedl), 13);
6887 xxh_u64
const bitflipl = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed;
6888 xxh_u64
const bitfliph = (XXH_readLE32(secret+8) ^ XXH_readLE32(secret+12)) - seed;
6889 xxh_u64
const keyed_lo = (xxh_u64)combinedl ^ bitflipl;
6890 xxh_u64
const keyed_hi = (xxh_u64)combinedh ^ bitfliph;
6892 h128.
low64 = XXH64_avalanche(keyed_lo);
6893 h128.
high64 = XXH64_avalanche(keyed_hi);
6899XXH3_len_4to8_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
6901 XXH_ASSERT(input != NULL);
6902 XXH_ASSERT(secret != NULL);
6903 XXH_ASSERT(4 <= len && len <= 8);
6904 seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32;
6905 { xxh_u32
const input_lo = XXH_readLE32(input);
6906 xxh_u32
const input_hi = XXH_readLE32(input + len - 4);
6907 xxh_u64
const input_64 = input_lo + ((xxh_u64)input_hi << 32);
6908 xxh_u64
const bitflip = (XXH_readLE64(secret+16) ^ XXH_readLE64(secret+24)) + seed;
6909 xxh_u64
const keyed = input_64 ^ bitflip;
6912 XXH128_hash_t m128 = XXH_mult64to128(keyed, XXH_PRIME64_1 + (len << 2));
6918 m128.
low64 *= PRIME_MX2;
6926XXH3_len_9to16_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
6928 XXH_ASSERT(input != NULL);
6929 XXH_ASSERT(secret != NULL);
6930 XXH_ASSERT(9 <= len && len <= 16);
6931 { xxh_u64
const bitflipl = (XXH_readLE64(secret+32) ^ XXH_readLE64(secret+40)) - seed;
6932 xxh_u64
const bitfliph = (XXH_readLE64(secret+48) ^ XXH_readLE64(secret+56)) + seed;
6933 xxh_u64
const input_lo = XXH_readLE64(input);
6934 xxh_u64 input_hi = XXH_readLE64(input + len - 8);
6935 XXH128_hash_t m128 = XXH_mult64to128(input_lo ^ input_hi ^ bitflipl, XXH_PRIME64_1);
6940 m128.
low64 += (xxh_u64)(len - 1) << 54;
6941 input_hi ^= bitfliph;
6949 if (
sizeof(
void *) <
sizeof(xxh_u64)) {
6956 m128.
high64 += (input_hi & 0xFFFFFFFF00000000ULL) + XXH_mult32to64((xxh_u32)input_hi, XXH_PRIME32_2);
6982 m128.
high64 += input_hi + XXH_mult32to64((xxh_u32)input_hi, XXH_PRIME32_2 - 1);
7001XXH3_len_0to16_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
7003 XXH_ASSERT(len <= 16);
7004 {
if (len > 8)
return XXH3_len_9to16_128b(input, len, secret, seed);
7005 if (len >= 4)
return XXH3_len_4to8_128b(input, len, secret, seed);
7006 if (len)
return XXH3_len_1to3_128b(input, len, secret, seed);
7008 xxh_u64
const bitflipl = XXH_readLE64(secret+64) ^ XXH_readLE64(secret+72);
7009 xxh_u64
const bitfliph = XXH_readLE64(secret+80) ^ XXH_readLE64(secret+88);
7010 h128.
low64 = XXH64_avalanche(seed ^ bitflipl);
7011 h128.
high64 = XXH64_avalanche( seed ^ bitfliph);
7020XXH128_mix32B(
XXH128_hash_t acc,
const xxh_u8* input_1,
const xxh_u8* input_2,
7023 acc.
low64 += XXH3_mix16B (input_1, secret+0, seed);
7024 acc.
low64 ^= XXH_readLE64(input_2) + XXH_readLE64(input_2 + 8);
7025 acc.
high64 += XXH3_mix16B (input_2, secret+16, seed);
7026 acc.
high64 ^= XXH_readLE64(input_1) + XXH_readLE64(input_1 + 8);
7032XXH3_len_17to128_128b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
7033 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
7037 XXH_ASSERT(16 < len && len <= 128);
7040 acc.
low64 = len * XXH_PRIME64_1;
7043#if XXH_SIZE_OPT >= 1
7046 unsigned int i = (
unsigned int)(len - 1) / 32;
7048 acc = XXH128_mix32B(acc, input+16*i, input+len-16*(i+1), secret+32*i, seed);
7055 acc = XXH128_mix32B(acc, input+48, input+len-64, secret+96, seed);
7057 acc = XXH128_mix32B(acc, input+32, input+len-48, secret+64, seed);
7059 acc = XXH128_mix32B(acc, input+16, input+len-32, secret+32, seed);
7061 acc = XXH128_mix32B(acc, input, input+len-16, secret, seed);
7066 + (acc.
high64 * XXH_PRIME64_4)
7067 + ((len - seed) * XXH_PRIME64_2);
7076XXH3_len_129to240_128b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
7077 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
7081 XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX);
7085 acc.
low64 = len * XXH_PRIME64_1;
7093 for (i = 32; i < 160; i += 32) {
7094 acc = XXH128_mix32B(acc,
7107 for (i=160; i <= len; i += 32) {
7108 acc = XXH128_mix32B(acc,
7111 secret + XXH3_MIDSIZE_STARTOFFSET + i - 160,
7115 acc = XXH128_mix32B(acc,
7124 + (acc.
high64 * XXH_PRIME64_4)
7125 + ((len - seed) * XXH_PRIME64_2);
7134XXH3_finalizeLong_128b(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret,
size_t secretSize, xxh_u64 len)
7137 h128.
low64 = XXH3_finalizeLong_64b(acc, secret, len);
7138 h128.
high64 = XXH3_mergeAccs(acc, secret + secretSize
7139 - XXH_STRIPE_LEN - XXH_SECRET_MERGEACCS_START,
7140 ~(len * XXH_PRIME64_2));
7145XXH3_hashLong_128b_internal(
const void* XXH_RESTRICT input,
size_t len,
7146 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
7147 XXH3_f_accumulate f_acc,
7148 XXH3_f_scrambleAcc f_scramble)
7150 XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[XXH_ACC_NB] = XXH3_INIT_ACC;
7152 XXH3_hashLong_internal_loop(acc, (
const xxh_u8*)input, len, secret, secretSize, f_acc, f_scramble);
7155 XXH_STATIC_ASSERT(
sizeof(acc) == 64);
7156 XXH_ASSERT(secretSize >=
sizeof(acc) + XXH_SECRET_MERGEACCS_START);
7157 return XXH3_finalizeLong_128b(acc, secret, secretSize, (xxh_u64)len);
7164XXH3_hashLong_128b_default(
const void* XXH_RESTRICT input,
size_t len,
7166 const void* XXH_RESTRICT secret,
size_t secretLen)
7168 (void)seed64; (void)secret; (void)secretLen;
7169 return XXH3_hashLong_128b_internal(input, len, XXH3_kSecret,
sizeof(XXH3_kSecret),
7170 XXH3_accumulate, XXH3_scrambleAcc);
7181XXH3_hashLong_128b_withSecret(
const void* XXH_RESTRICT input,
size_t len,
7183 const void* XXH_RESTRICT secret,
size_t secretLen)
7186 return XXH3_hashLong_128b_internal(input, len, (
const xxh_u8*)secret, secretLen,
7187 XXH3_accumulate, XXH3_scrambleAcc);
7191XXH3_hashLong_128b_withSeed_internal(
const void* XXH_RESTRICT input,
size_t len,
7193 XXH3_f_accumulate f_acc,
7194 XXH3_f_scrambleAcc f_scramble,
7195 XXH3_f_initCustomSecret f_initSec)
7198 return XXH3_hashLong_128b_internal(input, len,
7199 XXH3_kSecret,
sizeof(XXH3_kSecret),
7201 { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
7202 f_initSec(secret, seed64);
7203 return XXH3_hashLong_128b_internal(input, len, (
const xxh_u8*)secret,
sizeof(secret),
7212XXH3_hashLong_128b_withSeed(
const void* input,
size_t len,
7213 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen)
7215 (void)secret; (void)secretLen;
7216 return XXH3_hashLong_128b_withSeed_internal(input, len, seed64,
7217 XXH3_accumulate, XXH3_scrambleAcc, XXH3_initCustomSecret);
7220typedef XXH128_hash_t (*XXH3_hashLong128_f)(
const void* XXH_RESTRICT, size_t,
7224XXH3_128bits_internal(
const void* input,
size_t len,
7225 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen,
7226 XXH3_hashLong128_f f_hl128)
7236 return XXH3_len_0to16_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, seed64);
7238 return XXH3_len_17to128_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
7239 if (len <= XXH3_MIDSIZE_MAX)
7240 return XXH3_len_129to240_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
7241 return f_hl128(input, len, seed64, secret, secretLen);
7250 return XXH3_128bits_internal(input, len, 0,
7251 XXH3_kSecret,
sizeof(XXH3_kSecret),
7252 XXH3_hashLong_128b_default);
7257XXH3_128bits_withSecret(XXH_NOESCAPE
const void* input,
size_t len, XXH_NOESCAPE
const void* secret,
size_t secretSize)
7259 return XXH3_128bits_internal(input, len, 0,
7260 (
const xxh_u8*)secret, secretSize,
7261 XXH3_hashLong_128b_withSecret);
7268 return XXH3_128bits_internal(input, len, seed,
7269 XXH3_kSecret,
sizeof(XXH3_kSecret),
7270 XXH3_hashLong_128b_withSeed);
7275XXH3_128bits_withSecretandSeed(XXH_NOESCAPE
const void* input,
size_t len, XXH_NOESCAPE
const void* secret,
size_t secretSize,
XXH64_hash_t seed)
7277 if (len <= XXH3_MIDSIZE_MAX)
7278 return XXH3_128bits_internal(input, len, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), NULL);
7279 return XXH3_hashLong_128b_withSecret(input, len, seed, secret, secretSize);
7284XXH128(XXH_NOESCAPE
const void* input,
size_t len,
XXH64_hash_t seed)
7291#ifndef XXH_NO_STREAM
7320XXH3_128bits_reset_withSecretandSeed(XXH_NOESCAPE
XXH3_state_t* statePtr, XXH_NOESCAPE
const void* secret,
size_t secretSize,
XXH64_hash_t seed)
7322 return XXH3_64bits_reset_withSecretandSeed(statePtr, secret, secretSize, seed);
7329 return XXH3_update_regular(state, input, len);
7335 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
7336 if (state->totalLen > XXH3_MIDSIZE_MAX) {
7338 XXH3_digest_long(acc, state, secret);
7339 XXH_ASSERT(state->secretLimit + XXH_STRIPE_LEN >=
sizeof(acc) + XXH_SECRET_MERGEACCS_START);
7340 return XXH3_finalizeLong_128b(acc, secret, state->secretLimit + XXH_STRIPE_LEN, (xxh_u64)state->totalLen);
7346 secret, state->secretLimit + XXH_STRIPE_LEN);
7356 return !(XXH_memcmp(&h1, &h2,
sizeof(h1)));
7370 if (hcmp)
return hcmp;
7381 if (XXH_CPU_LITTLE_ENDIAN) {
7386 XXH_memcpy((
char*)dst +
sizeof(hash.
high64), &hash.
low64,
sizeof(hash.
low64));
7394 h.
high64 = XXH_readBE64(src);
7395 h.
low64 = XXH_readBE64(src->digest + 8);
7405#define XXH_MIN(x, y) (((x) > (y)) ? (y) : (x))
7407XXH_FORCE_INLINE
void XXH3_combine16(
void* dst,
XXH128_hash_t h128)
7409 XXH_writeLE64( dst, XXH_readLE64(dst) ^ h128.
low64 );
7410 XXH_writeLE64( (
char*)dst+8, XXH_readLE64((
char*)dst+8) ^ h128.
high64 );
7415XXH3_generateSecret(XXH_NOESCAPE
void* secretBuffer,
size_t secretSize, XXH_NOESCAPE
const void* customSeed,
size_t customSeedSize)
7417#if (XXH_DEBUGLEVEL >= 1)
7418 XXH_ASSERT(secretBuffer != NULL);
7422 if (secretBuffer == NULL)
return XXH_ERROR;
7426 if (customSeedSize == 0) {
7427 customSeed = XXH3_kSecret;
7428 customSeedSize = XXH_SECRET_DEFAULT_SIZE;
7430#if (XXH_DEBUGLEVEL >= 1)
7431 XXH_ASSERT(customSeed != NULL);
7433 if (customSeed == NULL)
return XXH_ERROR;
7438 while (pos < secretSize) {
7439 size_t const toCopy = XXH_MIN((secretSize - pos), customSeedSize);
7440 XXH_memcpy((
char*)secretBuffer + pos, customSeed, toCopy);
7444 {
size_t const nbSeg16 = secretSize / 16;
7448 for (
n=0;
n<nbSeg16;
n++) {
7449 XXH128_hash_t const h128 = XXH128(&scrambler,
sizeof(scrambler),
n);
7450 XXH3_combine16((
char*)secretBuffer +
n*16, h128);
7460XXH3_generateSecret_fromSeed(XXH_NOESCAPE
void* secretBuffer,
XXH64_hash_t seed)
7462 XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
7463 XXH3_initCustomSecret(secret, seed);
7464 XXH_ASSERT(secretBuffer != NULL);
7465 XXH_memcpy(secretBuffer, secret, XXH_SECRET_DEFAULT_SIZE);
7471#if XXH_VECTOR == XXH_AVX2 \
7472 && defined(__GNUC__) && !defined(__clang__) \
7473 && defined(__OPTIMIZE__) && XXH_SIZE_OPT <= 0
7474# pragma GCC pop_options
7487#if defined (__cplusplus) && !defined(XXH_NO_EXTERNC_GUARD)
static int const char char buffer[256]
struct XXH32_state_s XXH32_state_t
The opaque state struct for the XXH32 streaming API.
XXH_PUBLIC_API XXH_PUREF XXH32_hash_t XXH32_digest(const XXH32_state_t *statePtr)
Returns the calculated hash value from an XXH32_state_t.
XXH_PUBLIC_API XXH_PUREF XXH32_hash_t XXH32(const void *input, size_t length, XXH32_hash_t seed)
Calculates the 32-bit hash of input using xxHash32.
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t *statePtr, XXH32_hash_t seed)
Resets an XXH32_state_t to begin a new hash.
XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t *dst_state, const XXH32_state_t *src_state)
Copies one XXH32_state_t to another.
XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t *statePtr)
Frees an XXH32_state_t.
XXH_PUBLIC_API XXH_errorcode XXH32_update(XXH32_state_t *statePtr, const void *input, size_t length)
Consumes a block of input to an XXH32_state_t.
XXH_PUBLIC_API XXH_MALLOCF XXH32_state_t * XXH32_createState(void)
Allocates an XXH32_state_t.
XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t *dst, XXH32_hash_t hash)
Converts an XXH32_hash_t to a big endian XXH32_canonical_t.
XXH_PUBLIC_API XXH_PUREF XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t *src)
Converts an XXH32_canonical_t to a native XXH32_hash_t.
XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH3_64bits_withSeed(XXH_NOESCAPE const void *input, size_t length, XXH64_hash_t seed)
Calculates 64-bit seeded variant of XXH3 hash of input.
XXH_PUBLIC_API 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.
XXH_PUBLIC_API XXH_PUREF XXH128_hash_t XXH128_hashFromCanonical(XXH_NOESCAPE const XXH128_canonical_t *src)
Converts an XXH128_canonical_t to a native XXH128_hash_t.
XXH_PUBLIC_API 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.
XXH_PUBLIC_API XXH_MALLOCF XXH3_state_t * XXH3_createState(void)
XXH_PUBLIC_API XXH_PUREF int XXH128_cmp(XXH_NOESCAPE const void *h128_1, XXH_NOESCAPE const void *h128_2)
Compares two XXH128_hash_t.
XXH_PUBLIC_API XXH_errorcode XXH3_128bits_reset(XXH_NOESCAPE XXH3_state_t *statePtr)
Resets an XXH3_state_t to begin a new hash.
XXH_PUBLIC_API XXH_PUREF 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.
XXH_PUBLIC_API XXH_PUREF 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.
XXH_PUBLIC_API XXH_PUREF XXH128_hash_t XXH3_128bits_withSecret(XXH_NOESCAPE const void *data, size_t len, XXH_NOESCAPE const void *secret, size_t secretSize)
Calculates 128-bit variant of XXH3 with a custom "secret".
XXH_PUBLIC_API XXH_errorcode XXH3_64bits_reset(XXH_NOESCAPE XXH3_state_t *statePtr)
Resets an XXH3_state_t to begin a new hash.
XXH_PUBLIC_API XXH_PUREF int XXH128_isEqual(XXH128_hash_t h1, XXH128_hash_t h2)
Check equality of two XXH128_hash_t values.
struct XXH3_state_s XXH3_state_t
The opaque state struct for the XXH3 streaming API.
XXH_PUBLIC_API 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.
XXH_PUBLIC_API XXH_errorcode XXH3_freeState(XXH3_state_t *statePtr)
XXH_PUBLIC_API XXH_PUREF XXH128_hash_t XXH3_128bits(XXH_NOESCAPE const void *data, size_t len)
Calculates 128-bit unseeded variant of XXH3 of data.
XXH_PUBLIC_API XXH_errorcode XXH3_64bits_reset_withSecret(XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *secret, size_t secretSize)
Resets an XXH3_state_t with secret data to begin a new hash.
XXH_PUBLIC_API XXH_errorcode XXH3_128bits_reset_withSecret(XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *secret, size_t secretSize)
Resets an XXH3_state_t with secret data to begin a new hash.
XXH_PUBLIC_API XXH_PUREF XXH128_hash_t XXH3_128bits_withSeed(XXH_NOESCAPE const void *data, size_t len, XXH64_hash_t seed)
Calculates 128-bit seeded variant of XXH3 hash of data.
XXH_PUBLIC_API 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.
XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH3_64bits_withSecret(XXH_NOESCAPE const void *data, size_t len, XXH_NOESCAPE const void *secret, size_t secretSize)
Calculates 64-bit variant of XXH3 with a custom "secret".
XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH3_64bits(XXH_NOESCAPE const void *input, size_t length)
Calculates 64-bit unseeded variant of XXH3 hash of input.
XXH_PUBLIC_API 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.
XXH_PUBLIC_API 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.
#define XXH3_SECRET_SIZE_MIN
struct XXH64_state_s XXH64_state_t
The opaque state struct for the XXH64 streaming API.
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH_NOESCAPE XXH64_state_t *statePtr, XXH64_hash_t seed)
Resets an XXH64_state_t to begin a new hash.
XXH_PUBLIC_API XXH_PUREF 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.
XXH_PUBLIC_API 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.
XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH64_hashFromCanonical(XXH_NOESCAPE const XXH64_canonical_t *src)
Converts an XXH64_canonical_t to a native XXH64_hash_t.
XXH_PUBLIC_API void XXH64_copyState(XXH_NOESCAPE XXH64_state_t *dst_state, const XXH64_state_t *src_state)
Copies one XXH64_state_t to another.
XXH_PUBLIC_API 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.
XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH64_digest(XXH_NOESCAPE const XXH64_state_t *statePtr)
Returns the calculated hash value from an XXH64_state_t.
XXH_PUBLIC_API XXH_MALLOCF XXH64_state_t * XXH64_createState(void)
Allocates an XXH64_state_t.
XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t *statePtr)
Frees an XXH64_state_t.
unsigned long long XXH64_hash_t
XXH_errorcode
Exit code for the streaming API.
#define XXH_PUBLIC_API
Marks a global symbol.
#define XXH_VERSION_NUMBER
Version number, encoded as two digits each.
XXH_PUBLIC_API XXH_CONSTF unsigned XXH_versionNumber(void)
Obtains the xxHash version.
unsigned char digest[sizeof(XXH128_hash_t)]
The return value from 128-bit hashes.
Canonical (big endian) representation of XXH32_hash_t.
Canonical (big endian) representation of XXH64_hash_t.
unsigned char digest[sizeof(XXH64_hash_t)]