244#if defined(__cplusplus) && !defined(XXH_NO_EXTERNC_GUARD)
268# define XXH_STATIC_LINKING_ONLY
281# define XXH_IMPLEMENTATION
302# define XXH_INLINE_ALL
303# undef XXH_INLINE_ALL
307# define XXH_PRIVATE_API
308# undef XXH_PRIVATE_API
322# define XXH_NAMESPACE
326#define XXH_CAT(A,B) A##B
327#define XXH_NAME2(A,B) XXH_CAT(A,B)
328#define XXH_IPREF(Id) XXH_NAME2(XXH_NAMESPACE, Id)
330#if (defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)) \
331 && !defined(XXH_INLINE_ALL_31684351384)
333# define XXH_INLINE_ALL_31684351384
335# undef XXH_STATIC_LINKING_ONLY
336# define XXH_STATIC_LINKING_ONLY
338# undef XXH_PUBLIC_API
339# if defined(__GNUC__)
340# define XXH_PUBLIC_API static __inline __attribute__((__unused__))
341# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) )
342# define XXH_PUBLIC_API static inline
343# elif defined(_MSC_VER)
344# define XXH_PUBLIC_API static __inline
347# define XXH_PUBLIC_API static
363# undef XXH_versionNumber
366# undef XXH32_createState
367# undef XXH32_freeState
371# undef XXH32_copyState
372# undef XXH32_canonicalFromHash
373# undef XXH32_hashFromCanonical
376# undef XXH64_createState
377# undef XXH64_freeState
381# undef XXH64_copyState
382# undef XXH64_canonicalFromHash
383# undef XXH64_hashFromCanonical
386# undef XXH3_64bits_withSecret
387# undef XXH3_64bits_withSeed
388# undef XXH3_64bits_withSecretandSeed
389# undef XXH3_createState
390# undef XXH3_freeState
391# undef XXH3_copyState
392# undef XXH3_64bits_reset
393# undef XXH3_64bits_reset_withSeed
394# undef XXH3_64bits_reset_withSecret
395# undef XXH3_64bits_update
396# undef XXH3_64bits_digest
397# undef XXH3_generateSecret
401# undef XXH3_128bits_withSeed
402# undef XXH3_128bits_withSecret
403# undef XXH3_128bits_reset
404# undef XXH3_128bits_reset_withSeed
405# undef XXH3_128bits_reset_withSecret
406# undef XXH3_128bits_reset_withSecretandSeed
407# undef XXH3_128bits_update
408# undef XXH3_128bits_digest
409# undef XXH128_isEqual
411# undef XXH128_canonicalFromHash
412# undef XXH128_hashFromCanonical
417# define XXH_NAMESPACE XXH_INLINE_
425# define XXH_OK XXH_IPREF(XXH_OK)
426# define XXH_ERROR XXH_IPREF(XXH_ERROR)
427# define XXH_errorcode XXH_IPREF(XXH_errorcode)
428# define XXH32_canonical_t XXH_IPREF(XXH32_canonical_t)
429# define XXH64_canonical_t XXH_IPREF(XXH64_canonical_t)
430# define XXH128_canonical_t XXH_IPREF(XXH128_canonical_t)
431# define XXH32_state_s XXH_IPREF(XXH32_state_s)
432# define XXH32_state_t XXH_IPREF(XXH32_state_t)
433# define XXH64_state_s XXH_IPREF(XXH64_state_s)
434# define XXH64_state_t XXH_IPREF(XXH64_state_t)
435# define XXH3_state_s XXH_IPREF(XXH3_state_s)
436# define XXH3_state_t XXH_IPREF(XXH3_state_t)
437# define XXH128_hash_t XXH_IPREF(XXH128_hash_t)
439# undef XXHASH_H_5627135585666179
440# undef XXHASH_H_STATIC_13879238742
446#ifndef XXHASH_H_5627135585666179
447#define XXHASH_H_5627135585666179 1
450#if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API)
451# if defined(_WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
453# define XXH_PUBLIC_API __declspec(dllexport)
455# define XXH_PUBLIC_API __declspec(dllimport)
458# define XXH_PUBLIC_API
463# define XXH_versionNumber XXH_IPREF(XXH_versionNumber)
465# define XXH32 XXH_IPREF(XXH32)
466# define XXH32_createState XXH_IPREF(XXH32_createState)
467# define XXH32_freeState XXH_IPREF(XXH32_freeState)
468# define XXH32_reset XXH_IPREF(XXH32_reset)
469# define XXH32_update XXH_IPREF(XXH32_update)
470# define XXH32_digest XXH_IPREF(XXH32_digest)
471# define XXH32_copyState XXH_IPREF(XXH32_copyState)
472# define XXH32_canonicalFromHash XXH_IPREF(XXH32_canonicalFromHash)
473# define XXH32_hashFromCanonical XXH_IPREF(XXH32_hashFromCanonical)
475# define XXH64 XXH_IPREF(XXH64)
476# define XXH64_createState XXH_IPREF(XXH64_createState)
477# define XXH64_freeState XXH_IPREF(XXH64_freeState)
478# define XXH64_reset XXH_IPREF(XXH64_reset)
479# define XXH64_update XXH_IPREF(XXH64_update)
480# define XXH64_digest XXH_IPREF(XXH64_digest)
481# define XXH64_copyState XXH_IPREF(XXH64_copyState)
482# define XXH64_canonicalFromHash XXH_IPREF(XXH64_canonicalFromHash)
483# define XXH64_hashFromCanonical XXH_IPREF(XXH64_hashFromCanonical)
485# define XXH3_64bits XXH_IPREF(XXH3_64bits)
486# define XXH3_64bits_withSecret XXH_IPREF(XXH3_64bits_withSecret)
487# define XXH3_64bits_withSeed XXH_IPREF(XXH3_64bits_withSeed)
488# define XXH3_64bits_withSecretandSeed XXH_IPREF(XXH3_64bits_withSecretandSeed)
489# define XXH3_createState XXH_IPREF(XXH3_createState)
490# define XXH3_freeState XXH_IPREF(XXH3_freeState)
491# define XXH3_copyState XXH_IPREF(XXH3_copyState)
492# define XXH3_64bits_reset XXH_IPREF(XXH3_64bits_reset)
493# define XXH3_64bits_reset_withSeed XXH_IPREF(XXH3_64bits_reset_withSeed)
494# define XXH3_64bits_reset_withSecret XXH_IPREF(XXH3_64bits_reset_withSecret)
495# define XXH3_64bits_reset_withSecretandSeed XXH_IPREF(XXH3_64bits_reset_withSecretandSeed)
496# define XXH3_64bits_update XXH_IPREF(XXH3_64bits_update)
497# define XXH3_64bits_digest XXH_IPREF(XXH3_64bits_digest)
498# define XXH3_generateSecret XXH_IPREF(XXH3_generateSecret)
499# define XXH3_generateSecret_fromSeed XXH_IPREF(XXH3_generateSecret_fromSeed)
501# define XXH128 XXH_IPREF(XXH128)
502# define XXH3_128bits XXH_IPREF(XXH3_128bits)
503# define XXH3_128bits_withSeed XXH_IPREF(XXH3_128bits_withSeed)
504# define XXH3_128bits_withSecret XXH_IPREF(XXH3_128bits_withSecret)
505# define XXH3_128bits_withSecretandSeed XXH_IPREF(XXH3_128bits_withSecretandSeed)
506# define XXH3_128bits_reset XXH_IPREF(XXH3_128bits_reset)
507# define XXH3_128bits_reset_withSeed XXH_IPREF(XXH3_128bits_reset_withSeed)
508# define XXH3_128bits_reset_withSecret XXH_IPREF(XXH3_128bits_reset_withSecret)
509# define XXH3_128bits_reset_withSecretandSeed XXH_IPREF(XXH3_128bits_reset_withSecretandSeed)
510# define XXH3_128bits_update XXH_IPREF(XXH3_128bits_update)
511# define XXH3_128bits_digest XXH_IPREF(XXH3_128bits_digest)
512# define XXH128_isEqual XXH_IPREF(XXH128_isEqual)
513# define XXH128_cmp XXH_IPREF(XXH128_cmp)
514# define XXH128_canonicalFromHash XXH_IPREF(XXH128_canonicalFromHash)
515# define XXH128_hashFromCanonical XXH_IPREF(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 4
553#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
582#if defined(XXH_DOXYGEN)
590#elif !defined (__VMS) \
591 && (defined (__cplusplus) \
592 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
594# include <inttypes.h>
602# if UINT_MAX == 0xFFFFFFFFUL
604# elif ULONG_MAX == 0xFFFFFFFFUL
607# error "unsupported platform: need a 32-bit type"
756 unsigned char digest[4];
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
1675#ifndef XXH_NO_LONG_LONG
1700#if defined(__cplusplus) && (__cplusplus >= 201103L)
1702# define XXH_ALIGN(n) alignas(n)
1703#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
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
1770 XXH_ALIGN_MEMBER(64,
unsigned char buffer[XXH3_INTERNALBUFFER_SIZE]);
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; \
1940#define XXH3_MIDSIZE_MAX 240
1978 XXH_NOESCAPE
const void* secret,
size_t secretSize,
1997 XXH_NOESCAPE
const void* secret,
size_t secretSize,
2000#ifndef XXH_NO_STREAM
2016 XXH_NOESCAPE
const void* secret,
size_t secretSize,
2042 XXH_NOESCAPE
const void* secret,
size_t secretSize,
2049#if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)
2050# define XXH_IMPLEMENTATION
2055#if defined (__cplusplus) && !defined(XXH_NO_EXTERNC_GUARD)
2087#if ( defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) \
2088 || defined(XXH_IMPLEMENTATION) ) && !defined(XXH_IMPLEM_13a8737387)
2089# define XXH_IMPLEM_13a8737387
2107# define XXH_NO_LONG_LONG
2108# undef XXH_NO_LONG_LONG
2159# define XXH_FORCE_MEMORY_ACCESS 0
2187# define XXH_SIZE_OPT 0
2217# define XXH_FORCE_ALIGN_CHECK 0
2239# define XXH_NO_INLINE_HINTS 0
2256# define XXH3_INLINE_SECRET 0
2268# define XXH32_ENDJMP 0
2277# define XXH_OLD_NAMES
2278# undef XXH_OLD_NAMES
2288# define XXH_NO_STREAM
2289# undef XXH_NO_STREAM
2295#ifndef XXH_FORCE_MEMORY_ACCESS
2299# if defined(__GNUC__) && !(defined(__ARM_ARCH) && __ARM_ARCH < 7 && defined(__ARM_FEATURE_UNALIGNED))
2300# define XXH_FORCE_MEMORY_ACCESS 1
2306# if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE_SIZE__)
2307# define XXH_SIZE_OPT 1
2309# define XXH_SIZE_OPT 0
2313#ifndef XXH_FORCE_ALIGN_CHECK
2315# if XXH_SIZE_OPT >= 1 || \
2316 defined(__i386) || defined(__x86_64__) || defined(__aarch64__) || defined(__ARM_FEATURE_UNALIGNED) \
2317 || defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64) || defined(_M_ARM)
2318# define XXH_FORCE_ALIGN_CHECK 0
2320# define XXH_FORCE_ALIGN_CHECK 1
2324#ifndef XXH_NO_INLINE_HINTS
2325# if XXH_SIZE_OPT >= 1 || defined(__NO_INLINE__)
2326# define XXH_NO_INLINE_HINTS 1
2328# define XXH_NO_INLINE_HINTS 0
2332#ifndef XXH3_INLINE_SECRET
2333# if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 12) \
2334 || !defined(XXH_INLINE_ALL)
2335# define XXH3_INLINE_SECRET 0
2337# define XXH3_INLINE_SECRET 1
2343# define XXH32_ENDJMP 0
2355#if defined(XXH_NO_STREAM)
2357#elif defined(XXH_NO_STDLIB)
2368static XXH_CONSTF
void* XXH_malloc(
size_t s) { (void)s;
return NULL; }
2369static void XXH_free(
void* p) { (void)p; }
2383static XXH_MALLOCF
void* XXH_malloc(
size_t s) {
return malloc(s); }
2389static void XXH_free(
void* p) { free(p); }
2399# define XXH_memcpy memcpy
2408# define XXH_memset memset
2418# define XXH_memcmp memcmp
2430# pragma warning(disable : 4127)
2433#if XXH_NO_INLINE_HINTS
2434# if defined(__GNUC__) || defined(__clang__)
2435# define XXH_FORCE_INLINE static __attribute__((__unused__))
2437# define XXH_FORCE_INLINE static
2439# define XXH_NO_INLINE static
2441#elif defined(__GNUC__) || defined(__clang__)
2442# define XXH_FORCE_INLINE static __inline__ __attribute__((__always_inline__, __unused__))
2443# define XXH_NO_INLINE static __attribute__((__noinline__))
2444#elif defined(_MSC_VER)
2445# define XXH_FORCE_INLINE static __forceinline
2446# define XXH_NO_INLINE static __declspec(noinline)
2447#elif defined (__cplusplus) \
2448 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
2449# define XXH_FORCE_INLINE static inline
2450# define XXH_NO_INLINE static
2452# define XXH_FORCE_INLINE static
2453# define XXH_NO_INLINE static
2456#if defined(XXH_INLINE_ALL)
2457# define XXH_STATIC XXH_FORCE_INLINE
2459# define XXH_STATIC static
2462#if XXH3_INLINE_SECRET
2463# define XXH3_WITH_SECRET_INLINE XXH_FORCE_INLINE
2465# define XXH3_WITH_SECRET_INLINE XXH_NO_INLINE
2469#if ((defined(sun) || defined(__sun)) && defined(__cplusplus))
2470# define XXH_RESTRICT
2471#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
2472# define XXH_RESTRICT restrict
2473#elif (defined (__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) \
2474 || (defined (__clang__)) \
2475 || (defined (_MSC_VER) && (_MSC_VER >= 1400)) \
2476 || (defined (__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300))
2481# define XXH_RESTRICT __restrict
2483# define XXH_RESTRICT
2497#ifndef XXH_DEBUGLEVEL
2499# define XXH_DEBUGLEVEL DEBUGLEVEL
2501# define XXH_DEBUGLEVEL 0
2505#if (XXH_DEBUGLEVEL>=1)
2507# define XXH_ASSERT(c) assert(c)
2509# if defined(__INTEL_COMPILER)
2510# define XXH_ASSERT(c) XXH_ASSUME((unsigned char) (c))
2512# define XXH_ASSERT(c) XXH_ASSUME(c)
2517#ifndef XXH_STATIC_ASSERT
2518# if defined(__cplusplus) && (__cplusplus >= 201103L)
2519# define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { static_assert((c),m); } while(0)
2520# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
2521# define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { _Static_assert((c),m); } while(0)
2523# define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { struct xxh_sa { char x[(c) ? 1 : -1]; }; } while(0)
2525# define XXH_STATIC_ASSERT(c) XXH_STATIC_ASSERT_WITH_MESSAGE((c),#c)
2544#if defined(__GNUC__) || defined(__clang__)
2545# define XXH_COMPILER_GUARD(var) __asm__("" : "+r" (var))
2547# define XXH_COMPILER_GUARD(var) ((void)0)
2552#if defined(__clang__) && defined(__ARM_ARCH) && !defined(__wasm__)
2553# define XXH_COMPILER_GUARD_CLANG_NEON(var) __asm__("" : "+w" (var))
2555# define XXH_COMPILER_GUARD_CLANG_NEON(var) ((void)0)
2561#if !defined (__VMS) \
2562 && (defined (__cplusplus) \
2563 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
2565# include <inttypes.h>
2569 typedef uint8_t xxh_u8;
2571 typedef unsigned char xxh_u8;
2576# 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"
2634#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
2639#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
2645static xxh_u32 XXH_read32(
const void* memPtr) {
return *(
const xxh_u32*) memPtr; }
2647#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
2657typedef union { xxh_u32 u32; } __attribute__((__packed__)) unalign;
2659static xxh_u32 XXH_read32(
const void* ptr)
2661 typedef __attribute__((__aligned__(1))) __attribute__((__may_alias__)) xxh_u32 xxh_unalign32;
2662 return *((const xxh_unalign32*)ptr);
2671static xxh_u32 XXH_read32(
const void* memPtr)
2674 XXH_memcpy(&val, memPtr,
sizeof(val));
2699#ifndef XXH_CPU_LITTLE_ENDIAN
2704# if defined(_WIN32) \
2705 || defined(__LITTLE_ENDIAN__) \
2706 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2707# define XXH_CPU_LITTLE_ENDIAN 1
2708# elif defined(__BIG_ENDIAN__) \
2709 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
2710# define XXH_CPU_LITTLE_ENDIAN 0
2718static int XXH_isLittleEndian(
void)
2724 const union { xxh_u32 u; xxh_u8 c[4]; } one = { 1 };
2727# define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian()
2737#define XXH_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
2740# define XXH_HAS_BUILTIN(x) __has_builtin(x)
2742# define XXH_HAS_BUILTIN(x) 0
2774#if XXH_HAS_BUILTIN(__builtin_unreachable)
2775# define XXH_UNREACHABLE() __builtin_unreachable()
2777#elif defined(_MSC_VER)
2778# define XXH_UNREACHABLE() __assume(0)
2781# define XXH_UNREACHABLE()
2784#if XXH_HAS_BUILTIN(__builtin_assume)
2785# define XXH_ASSUME(c) __builtin_assume(c)
2787# define XXH_ASSUME(c) if (!(c)) { XXH_UNREACHABLE(); }
2803#if !defined(NO_CLANG_BUILTIN) && XXH_HAS_BUILTIN(__builtin_rotateleft32) \
2804 && XXH_HAS_BUILTIN(__builtin_rotateleft64)
2805# define XXH_rotl32 __builtin_rotateleft32
2806# define XXH_rotl64 __builtin_rotateleft64
2807#elif XXH_HAS_BUILTIN(__builtin_stdc_rotate_left)
2808# define XXH_rotl32 __builtin_stdc_rotate_left
2809# define XXH_rotl64 __builtin_stdc_rotate_left
2811#elif defined(_MSC_VER)
2812# define XXH_rotl32(x,r) _rotl(x,r)
2813# define XXH_rotl64(x,r) _rotl64(x,r)
2815# define XXH_rotl32(x,r) (((x) << (r)) | ((x) >> (32 - (r))))
2816# define XXH_rotl64(x,r) (((x) << (r)) | ((x) >> (64 - (r))))
2827#if defined(_MSC_VER)
2828# define XXH_swap32 _byteswap_ulong
2829#elif XXH_GCC_VERSION >= 403
2830# define XXH_swap32 __builtin_bswap32
2832static xxh_u32 XXH_swap32 (xxh_u32 x)
2834 return ((x << 24) & 0xff000000 ) |
2835 ((x << 8) & 0x00ff0000 ) |
2836 ((x >> 8) & 0x0000ff00 ) |
2837 ((x >> 24) & 0x000000ff );
2860#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
2862XXH_FORCE_INLINE xxh_u32 XXH_readLE32(
const void* memPtr)
2864 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
2866 | ((xxh_u32)bytePtr[1] << 8)
2867 | ((xxh_u32)bytePtr[2] << 16)
2868 | ((xxh_u32)bytePtr[3] << 24);
2871XXH_FORCE_INLINE xxh_u32 XXH_readBE32(
const void* memPtr)
2873 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
2875 | ((xxh_u32)bytePtr[2] << 8)
2876 | ((xxh_u32)bytePtr[1] << 16)
2877 | ((xxh_u32)bytePtr[0] << 24);
2881XXH_FORCE_INLINE xxh_u32 XXH_readLE32(
const void* ptr)
2886static xxh_u32 XXH_readBE32(
const void* ptr)
2892XXH_FORCE_INLINE xxh_u32
2896 return XXH_readLE32(ptr);
2922#define XXH_PRIME32_1 0x9E3779B1U
2923#define XXH_PRIME32_2 0x85EBCA77U
2924#define XXH_PRIME32_3 0xC2B2AE3DU
2925#define XXH_PRIME32_4 0x27D4EB2FU
2926#define XXH_PRIME32_5 0x165667B1U
2929# define PRIME32_1 XXH_PRIME32_1
2930# define PRIME32_2 XXH_PRIME32_2
2931# define PRIME32_3 XXH_PRIME32_3
2932# define PRIME32_4 XXH_PRIME32_4
2933# define PRIME32_5 XXH_PRIME32_5
2947static xxh_u32 XXH32_round(xxh_u32 acc, xxh_u32 input)
2950 acc = XXH_rotl32(acc, 13);
2952#if (defined(__SSE4_1__) || defined(__aarch64__) || defined(__wasm_simd128__)) && !defined(XXH_ENABLE_AUTOVECTORIZE)
2989 XXH_COMPILER_GUARD(acc);
3004static xxh_u32 XXH32_avalanche(xxh_u32 hash)
3014#define XXH_get32bits(p) XXH_readLE32_align(p, align)
3020XXH_FORCE_INLINE
void
3021XXH32_initAccs(xxh_u32 *acc, xxh_u32 seed)
3023 XXH_ASSERT(acc != NULL);
3036XXH_FORCE_INLINE
const xxh_u8 *
3038 xxh_u32 *XXH_RESTRICT acc,
3039 xxh_u8
const *XXH_RESTRICT input,
3044 const xxh_u8*
const bEnd = input + len;
3045 const xxh_u8*
const limit = bEnd - 15;
3046 XXH_ASSERT(acc != NULL);
3047 XXH_ASSERT(input != NULL);
3048 XXH_ASSERT(len >= 16);
3050 acc[0] = XXH32_round(acc[0], XXH_get32bits(input)); input += 4;
3051 acc[1] = XXH32_round(acc[1], XXH_get32bits(input)); input += 4;
3052 acc[2] = XXH32_round(acc[2], XXH_get32bits(input)); input += 4;
3053 acc[3] = XXH32_round(acc[3], XXH_get32bits(input)); input += 4;
3054 }
while (input < limit);
3063XXH_FORCE_INLINE XXH_PUREF xxh_u32
3064XXH32_mergeAccs(
const xxh_u32 *acc)
3066 XXH_ASSERT(acc != NULL);
3067 return XXH_rotl32(acc[0], 1) + XXH_rotl32(acc[1], 7)
3068 + XXH_rotl32(acc[2], 12) + XXH_rotl32(acc[3], 18);
3086static XXH_PUREF xxh_u32
3087XXH32_finalize(xxh_u32 hash,
const xxh_u8* ptr,
size_t len,
XXH_alignment align)
3089#define XXH_PROCESS1 do { \
3090 hash += (*ptr++) * XXH_PRIME32_5; \
3091 hash = XXH_rotl32(hash, 11) * XXH_PRIME32_1; \
3094#define XXH_PROCESS4 do { \
3095 hash += XXH_get32bits(ptr) * XXH_PRIME32_3; \
3097 hash = XXH_rotl32(hash, 17) * XXH_PRIME32_4; \
3100 if (ptr==NULL) XXH_ASSERT(len == 0);
3113 return XXH32_avalanche(hash);
3116 case 12: XXH_PROCESS4;
3118 case 8: XXH_PROCESS4;
3120 case 4: XXH_PROCESS4;
3121 return XXH32_avalanche(hash);
3123 case 13: XXH_PROCESS4;
3125 case 9: XXH_PROCESS4;
3127 case 5: XXH_PROCESS4;
3129 return XXH32_avalanche(hash);
3131 case 14: XXH_PROCESS4;
3133 case 10: XXH_PROCESS4;
3135 case 6: XXH_PROCESS4;
3138 return XXH32_avalanche(hash);
3140 case 15: XXH_PROCESS4;
3142 case 11: XXH_PROCESS4;
3144 case 7: XXH_PROCESS4;
3146 case 3: XXH_PROCESS1;
3148 case 2: XXH_PROCESS1;
3150 case 1: XXH_PROCESS1;
3152 case 0:
return XXH32_avalanche(hash);
3160# define PROCESS1 XXH_PROCESS1
3161# define PROCESS4 XXH_PROCESS4
3175#if defined(_MSC_VER)
3176# pragma warning(push)
3178# pragma warning(disable : 4702)
3180XXH_FORCE_INLINE XXH_PUREF xxh_u32
3181XXH32_endian_align(
const xxh_u8* input,
size_t len, xxh_u32 seed,
XXH_alignment align)
3185 if (input==NULL) XXH_ASSERT(len == 0);
3189 XXH32_initAccs(acc, seed);
3191 input = XXH32_consumeLong(acc, input, len, align);
3193 h32 = XXH32_mergeAccs(acc);
3198 h32 += (xxh_u32)len;
3200 return XXH32_finalize(h32, input, len&15, align);
3202#if defined(_MSC_VER)
3203# pragma warning(pop)
3209#if !defined(XXH_NO_STREAM) && XXH_SIZE_OPT >= 2
3217 if ((((
size_t)input) & 3) == 0) {
3218 return XXH32_endian_align((
const xxh_u8*)input, len, seed,
XXH_aligned);
3221 return XXH32_endian_align((
const xxh_u8*)input, len, seed,
XXH_unaligned);
3228#ifndef XXH_NO_STREAM
3244 XXH_memcpy(dstState, srcState,
sizeof(*dstState));
3250 XXH_ASSERT(statePtr != NULL);
3251 XXH_memset(statePtr, 0,
sizeof(*statePtr));
3252 XXH32_initAccs(statePtr->
acc, seed);
3262 XXH_ASSERT(len == 0);
3276 {
const xxh_u8* xinput = (
const xxh_u8*)input;
3277 const xxh_u8*
const bEnd = xinput + len;
3287 XXH_ASSERT(xinput <= bEnd);
3288 if ((
size_t)(bEnd - xinput) >=
sizeof(state->
buffer)) {
3290 xinput = XXH32_consumeLong(state->
acc, xinput, (
size_t)(bEnd - xinput),
XXH_unaligned);
3293 if (xinput < bEnd) {
3295 XXH_memcpy(state->
buffer, xinput, (
size_t)(bEnd-xinput));
3310 h32 = XXH32_mergeAccs(state->
acc);
3328 XXH_memcpy(dst, &hash,
sizeof(*dst));
3333 return XXH_readBE32(src);
3337#ifndef XXH_NO_LONG_LONG
3355#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
3360#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
3363static xxh_u64 XXH_read64(
const void* memPtr)
3365 return *(
const xxh_u64*) memPtr;
3368#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
3378typedef union { xxh_u32 u32; xxh_u64 u64; } __attribute__((__packed__)) unalign64;
3380static xxh_u64 XXH_read64(
const void* ptr)
3382 typedef __attribute__((__aligned__(1))) __attribute__((__may_alias__)) xxh_u64 xxh_unalign64;
3383 return *((const xxh_unalign64*)ptr);
3392static xxh_u64 XXH_read64(
const void* memPtr)
3395 XXH_memcpy(&val, memPtr,
sizeof(val));
3401#if defined(_MSC_VER)
3402# define XXH_swap64 _byteswap_uint64
3403#elif XXH_GCC_VERSION >= 403
3404# define XXH_swap64 __builtin_bswap64
3406static xxh_u64 XXH_swap64(xxh_u64 x)
3408 return ((x << 56) & 0xff00000000000000ULL) |
3409 ((x << 40) & 0x00ff000000000000ULL) |
3410 ((x << 24) & 0x0000ff0000000000ULL) |
3411 ((x << 8) & 0x000000ff00000000ULL) |
3412 ((x >> 8) & 0x00000000ff000000ULL) |
3413 ((x >> 24) & 0x0000000000ff0000ULL) |
3414 ((x >> 40) & 0x000000000000ff00ULL) |
3415 ((x >> 56) & 0x00000000000000ffULL);
3421#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3))
3423XXH_FORCE_INLINE xxh_u64 XXH_readLE64(
const void* memPtr)
3425 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
3427 | ((xxh_u64)bytePtr[1] << 8)
3428 | ((xxh_u64)bytePtr[2] << 16)
3429 | ((xxh_u64)bytePtr[3] << 24)
3430 | ((xxh_u64)bytePtr[4] << 32)
3431 | ((xxh_u64)bytePtr[5] << 40)
3432 | ((xxh_u64)bytePtr[6] << 48)
3433 | ((xxh_u64)bytePtr[7] << 56);
3436XXH_FORCE_INLINE xxh_u64 XXH_readBE64(
const void* memPtr)
3438 const xxh_u8* bytePtr = (
const xxh_u8 *)memPtr;
3440 | ((xxh_u64)bytePtr[6] << 8)
3441 | ((xxh_u64)bytePtr[5] << 16)
3442 | ((xxh_u64)bytePtr[4] << 24)
3443 | ((xxh_u64)bytePtr[3] << 32)
3444 | ((xxh_u64)bytePtr[2] << 40)
3445 | ((xxh_u64)bytePtr[1] << 48)
3446 | ((xxh_u64)bytePtr[0] << 56);
3450XXH_FORCE_INLINE xxh_u64 XXH_readLE64(
const void* ptr)
3455static xxh_u64 XXH_readBE64(
const void* ptr)
3461XXH_FORCE_INLINE xxh_u64
3465 return XXH_readLE64(ptr);
3481#define XXH_PRIME64_1 0x9E3779B185EBCA87ULL
3482#define XXH_PRIME64_2 0xC2B2AE3D27D4EB4FULL
3483#define XXH_PRIME64_3 0x165667B19E3779F9ULL
3484#define XXH_PRIME64_4 0x85EBCA77C2B2AE63ULL
3485#define XXH_PRIME64_5 0x27D4EB2F165667C5ULL
3488# define PRIME64_1 XXH_PRIME64_1
3489# define PRIME64_2 XXH_PRIME64_2
3490# define PRIME64_3 XXH_PRIME64_3
3491# define PRIME64_4 XXH_PRIME64_4
3492# define PRIME64_5 XXH_PRIME64_5
3496static xxh_u64 XXH64_round(xxh_u64 acc, xxh_u64 input)
3499 acc = XXH_rotl64(acc, 31);
3501#if (defined(__AVX512F__)) && !defined(XXH_ENABLE_AUTOVECTORIZE)
3516 XXH_COMPILER_GUARD(acc);
3521static xxh_u64 XXH64_mergeRound(xxh_u64 acc, xxh_u64 val)
3523 val = XXH64_round(0, val);
3530static xxh_u64 XXH64_avalanche(xxh_u64 hash)
3541#define XXH_get64bits(p) XXH_readLE64_align(p, align)
3547XXH_FORCE_INLINE
void
3548XXH64_initAccs(xxh_u64 *acc, xxh_u64 seed)
3550 XXH_ASSERT(acc != NULL);
3563XXH_FORCE_INLINE
const xxh_u8 *
3565 xxh_u64 *XXH_RESTRICT acc,
3566 xxh_u8
const *XXH_RESTRICT input,
3571 const xxh_u8*
const bEnd = input + len;
3572 const xxh_u8*
const limit = bEnd - 31;
3573 XXH_ASSERT(acc != NULL);
3574 XXH_ASSERT(input != NULL);
3575 XXH_ASSERT(len >= 32);
3578 if (
sizeof(
void *) <
sizeof(xxh_u64)) {
3580 for (i = 0; i < 4; i++) {
3581 acc[i] = XXH64_round(acc[i], XXH_get64bits(input));
3585 acc[0] = XXH64_round(acc[0], XXH_get64bits(input)); input += 8;
3586 acc[1] = XXH64_round(acc[1], XXH_get64bits(input)); input += 8;
3587 acc[2] = XXH64_round(acc[2], XXH_get64bits(input)); input += 8;
3588 acc[3] = XXH64_round(acc[3], XXH_get64bits(input)); input += 8;
3590 }
while (input < limit);
3599XXH_FORCE_INLINE XXH_PUREF xxh_u64
3600XXH64_mergeAccs(
const xxh_u64 *acc)
3602 XXH_ASSERT(acc != NULL);
3604 xxh_u64 h64 = XXH_rotl64(acc[0], 1) + XXH_rotl64(acc[1], 7)
3605 + XXH_rotl64(acc[2], 12) + XXH_rotl64(acc[3], 18);
3607 if (
sizeof(
void *) <
sizeof(xxh_u64)) {
3609 for (i = 0; i < 4; i++) {
3610 h64 = XXH64_mergeRound(h64, acc[i]);
3613 h64 = XXH64_mergeRound(h64, acc[0]);
3614 h64 = XXH64_mergeRound(h64, acc[1]);
3615 h64 = XXH64_mergeRound(h64, acc[2]);
3616 h64 = XXH64_mergeRound(h64, acc[3]);
3637XXH_STATIC XXH_PUREF xxh_u64
3638XXH64_finalize(xxh_u64 hash,
const xxh_u8* ptr,
size_t len,
XXH_alignment align)
3640 if (ptr==NULL) XXH_ASSERT(len == 0);
3643 xxh_u64
const k1 = XXH64_round(0, XXH_get64bits(ptr));
3660 return XXH64_avalanche(hash);
3664# define PROCESS1_64 XXH_PROCESS1_64
3665# define PROCESS4_64 XXH_PROCESS4_64
3666# define PROCESS8_64 XXH_PROCESS8_64
3668# undef XXH_PROCESS1_64
3669# undef XXH_PROCESS4_64
3670# undef XXH_PROCESS8_64
3681XXH_FORCE_INLINE XXH_PUREF xxh_u64
3682XXH64_endian_align(
const xxh_u8* input,
size_t len, xxh_u64 seed,
XXH_alignment align)
3685 if (input==NULL) XXH_ASSERT(len == 0);
3689 XXH64_initAccs(acc, seed);
3691 input = XXH64_consumeLong(acc, input, len, align);
3693 h64 = XXH64_mergeAccs(acc);
3698 h64 += (xxh_u64) len;
3700 return XXH64_finalize(h64, input, len, align);
3707#if !defined(XXH_NO_STREAM) && XXH_SIZE_OPT >= 2
3715 if ((((
size_t)input) & 7)==0) {
3716 return XXH64_endian_align((
const xxh_u8*)input, len, seed,
XXH_aligned);
3719 return XXH64_endian_align((
const xxh_u8*)input, len, seed,
XXH_unaligned);
3725#ifndef XXH_NO_STREAM
3741 XXH_memcpy(dstState, srcState,
sizeof(*dstState));
3747 XXH_ASSERT(statePtr != NULL);
3748 XXH_memset(statePtr, 0,
sizeof(*statePtr));
3749 XXH64_initAccs(statePtr->acc, seed);
3758 XXH_ASSERT(len == 0);
3762 state->total_len += len;
3764 XXH_ASSERT(state->bufferedSize <=
sizeof(state->buffer));
3765 if (len <
sizeof(state->buffer) - state->bufferedSize) {
3766 XXH_memcpy(state->buffer + state->bufferedSize, input, len);
3771 {
const xxh_u8* xinput = (
const xxh_u8*)input;
3772 const xxh_u8*
const bEnd = xinput + len;
3774 if (state->bufferedSize) {
3775 XXH_memcpy(state->buffer + state->bufferedSize, xinput,
sizeof(state->buffer) - state->bufferedSize);
3776 xinput +=
sizeof(state->buffer) - state->bufferedSize;
3778 (void)XXH64_consumeLong(state->acc, state->buffer,
sizeof(state->buffer),
XXH_aligned);
3779 state->bufferedSize = 0;
3782 XXH_ASSERT(xinput <= bEnd);
3783 if ((
size_t)(bEnd - xinput) >=
sizeof(state->buffer)) {
3785 xinput = XXH64_consumeLong(state->acc, xinput, (
size_t)(bEnd - xinput),
XXH_unaligned);
3788 if (xinput < bEnd) {
3790 XXH_memcpy(state->buffer, xinput, (
size_t)(bEnd-xinput));
3791 state->bufferedSize = (unsigned)(bEnd-xinput);
3804 if (state->total_len >= 32) {
3805 h64 = XXH64_mergeAccs(state->acc);
3810 h64 += (xxh_u64) state->total_len;
3812 return XXH64_finalize(h64, state->buffer, (
size_t)state->total_len,
XXH_aligned);
3823 XXH_memcpy(dst, &hash,
sizeof(*dst));
3829 return XXH_readBE64(src);
3848#if (defined(__GNUC__) && (__GNUC__ >= 3)) \
3849 || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) \
3850 || defined(__clang__)
3851# define XXH_likely(x) __builtin_expect(x, 1)
3852# define XXH_unlikely(x) __builtin_expect(x, 0)
3854# define XXH_likely(x) (x)
3855# define XXH_unlikely(x) (x)
3858#ifndef XXH_HAS_INCLUDE
3859# ifdef __has_include
3864# define XXH_HAS_INCLUDE __has_include
3866# define XXH_HAS_INCLUDE(x) 0
3870#if defined(__GNUC__) || defined(__clang__)
3871# if defined(__ARM_FEATURE_SVE)
3872# include <arm_sve.h>
3874# if defined(__ARM_NEON__) || defined(__ARM_NEON) \
3875 || (defined(_M_ARM) && _M_ARM >= 7) \
3876 || defined(_M_ARM64) || defined(_M_ARM64EC) \
3877 || (defined(__wasm_simd128__) && XXH_HAS_INCLUDE(<arm_neon.h>))
3878# define inline __inline__
3879# include <arm_neon.h>
3881# elif defined(__AVX2__)
3882# include <immintrin.h>
3883# elif defined(__SSE2__)
3884# include <emmintrin.h>
3885# elif defined(__loongarch_asx)
3886# include <lasxintrin.h>
3887# include <lsxintrin.h>
3888# elif defined(__loongarch_sx)
3889# include <lsxintrin.h>
3890# elif defined(__riscv_vector)
3891# include <riscv_vector.h>
3895#if defined(_MSC_VER)
3968#if defined(__thumb__) && !defined(__thumb2__) && defined(__ARM_ARCH_ISA_ARM)
3969# warning "XXH3 is highly inefficient without ARM or Thumb-2."
3987# define XXH_VECTOR XXH_SCALAR
3997# define XXH_ACC_ALIGN 8
4006 defined(__ARM_NEON__) || defined(__ARM_NEON) \
4007 || defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC) \
4008 || (defined(__wasm_simd128__) && XXH_HAS_INCLUDE(<arm_neon.h>)) \
4010 defined(_WIN32) || defined(__LITTLE_ENDIAN__) \
4011 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) \
4013# define XXH_VECTOR XXH_NEON
4014# elif defined(__ARM_FEATURE_SVE)
4015# define XXH_VECTOR XXH_SVE
4016# elif defined(__AVX512F__)
4017# define XXH_VECTOR XXH_AVX512
4018# elif defined(__AVX2__)
4019# define XXH_VECTOR XXH_AVX2
4020# elif defined(__SSE2__) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP == 2))
4021# define XXH_VECTOR XXH_SSE2
4022# elif (defined(__PPC64__) && defined(__POWER8_VECTOR__)) \
4023 || (defined(__s390x__) && defined(__VEC__)) \
4024 && defined(__GNUC__)
4025# define XXH_VECTOR XXH_VSX
4026# elif defined(__loongarch_asx)
4027# define XXH_VECTOR XXH_LASX
4028# elif defined(__loongarch_sx)
4029# define XXH_VECTOR XXH_LSX
4030# elif defined(__riscv_vector)
4031# define XXH_VECTOR XXH_RVV
4033# define XXH_VECTOR XXH_SCALAR
4038#if (XXH_VECTOR == XXH_SVE) && !defined(__ARM_FEATURE_SVE)
4040# pragma warning(once : 4606)
4042# warning "__ARM_FEATURE_SVE isn't supported. Use SCALAR instead."
4045# define XXH_VECTOR XXH_SCALAR
4052#ifndef XXH_ACC_ALIGN
4053# if defined(XXH_X86DISPATCH)
4054# define XXH_ACC_ALIGN 64
4055# elif XXH_VECTOR == XXH_SCALAR
4056# define XXH_ACC_ALIGN 8
4057# elif XXH_VECTOR == XXH_SSE2
4058# define XXH_ACC_ALIGN 16
4059# elif XXH_VECTOR == XXH_AVX2
4060# define XXH_ACC_ALIGN 32
4061# elif XXH_VECTOR == XXH_NEON
4062# define XXH_ACC_ALIGN 16
4063# elif XXH_VECTOR == XXH_VSX
4064# define XXH_ACC_ALIGN 16
4065# elif XXH_VECTOR == XXH_AVX512
4066# define XXH_ACC_ALIGN 64
4067# elif XXH_VECTOR == XXH_SVE
4068# define XXH_ACC_ALIGN 64
4069# elif XXH_VECTOR == XXH_LASX
4070# define XXH_ACC_ALIGN 64
4071# elif XXH_VECTOR == XXH_LSX
4072# define XXH_ACC_ALIGN 64
4073# elif XXH_VECTOR == XXH_RVV
4074# define XXH_ACC_ALIGN 64
4078#if defined(XXH_X86DISPATCH) || XXH_VECTOR == XXH_SSE2 \
4079 || XXH_VECTOR == XXH_AVX2 || XXH_VECTOR == XXH_AVX512
4080# define XXH_SEC_ALIGN XXH_ACC_ALIGN
4081#elif XXH_VECTOR == XXH_SVE
4082# define XXH_SEC_ALIGN XXH_ACC_ALIGN
4083#elif XXH_VECTOR == XXH_RVV
4084# define XXH_SEC_ALIGN XXH_ACC_ALIGN
4086# define XXH_SEC_ALIGN 8
4089#if defined(__GNUC__) || defined(__clang__)
4090# define XXH_ALIASING __attribute__((__may_alias__))
4092# define XXH_ALIASING
4116#if XXH_VECTOR == XXH_AVX2 \
4117 && defined(__GNUC__) && !defined(__clang__) \
4118 && defined(__OPTIMIZE__) && XXH_SIZE_OPT <= 0
4119# pragma GCC push_options
4120# pragma GCC optimize("-O2")
4123#if XXH_VECTOR == XXH_NEON
4132typedef uint64x2_t xxh_aliasing_uint64x2_t XXH_ALIASING;
4147#if defined(__aarch64__) && defined(__GNUC__) && !defined(__clang__)
4148XXH_FORCE_INLINE uint64x2_t XXH_vld1q_u64(
void const* ptr)
4150 return *(xxh_aliasing_uint64x2_t
const *)ptr;
4153XXH_FORCE_INLINE uint64x2_t XXH_vld1q_u64(
void const* ptr)
4155 return vreinterpretq_u64_u8(vld1q_u8((uint8_t
const*)ptr));
4167#if defined(__aarch64__) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 11
4168XXH_FORCE_INLINE uint64x2_t
4169XXH_vmlal_low_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
4172 __asm__(
"umlal %0.2d, %1.2s, %2.2s" :
"+w" (acc) :
"w" (lhs),
"w" (rhs));
4175XXH_FORCE_INLINE uint64x2_t
4176XXH_vmlal_high_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
4179 return vmlal_high_u32(acc, lhs, rhs);
4183XXH_FORCE_INLINE uint64x2_t
4184XXH_vmlal_low_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
4186 return vmlal_u32(acc, vget_low_u32(lhs), vget_low_u32(rhs));
4190XXH_FORCE_INLINE uint64x2_t
4191XXH_vmlal_high_u32(uint64x2_t acc, uint32x4_t lhs, uint32x4_t rhs)
4193 return vmlal_u32(acc, vget_high_u32(lhs), vget_high_u32(rhs));
4235# ifndef XXH3_NEON_LANES
4236# if (defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || defined(_M_ARM64EC)) \
4237 && !defined(__APPLE__) && XXH_SIZE_OPT <= 0
4238# define XXH3_NEON_LANES 6
4240# define XXH3_NEON_LANES XXH_ACC_NB
4253#if XXH_VECTOR == XXH_VSX
4262# pragma push_macro("bool")
4263# pragma push_macro("vector")
4264# pragma push_macro("pixel")
4270# if defined(__s390x__)
4271# include <s390intrin.h>
4273# include <altivec.h>
4277# pragma pop_macro("pixel")
4278# pragma pop_macro("vector")
4279# pragma pop_macro("bool")
4281typedef __vector
unsigned long long xxh_u64x2;
4282typedef __vector
unsigned char xxh_u8x16;
4283typedef __vector
unsigned xxh_u32x4;
4288typedef xxh_u64x2 xxh_aliasing_u64x2 XXH_ALIASING;
4291# if defined(__BIG_ENDIAN__) \
4292 || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
4293# define XXH_VSX_BE 1
4294# elif defined(__VEC_ELEMENT_REG_ORDER__) && __VEC_ELEMENT_REG_ORDER__ == __ORDER_BIG_ENDIAN__
4295# warning "-maltivec=be is not recommended. Please use native endianness."
4296# define XXH_VSX_BE 1
4298# define XXH_VSX_BE 0
4303# if defined(__POWER9_VECTOR__) || (defined(__clang__) && defined(__s390x__))
4304# define XXH_vec_revb vec_revb
4309XXH_FORCE_INLINE xxh_u64x2 XXH_vec_revb(xxh_u64x2 val)
4311 xxh_u8x16
const vByteSwap = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
4312 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08 };
4313 return vec_perm(val, val, vByteSwap);
4321XXH_FORCE_INLINE xxh_u64x2 XXH_vec_loadu(
const void *ptr)
4324 XXH_memcpy(&ret, ptr,
sizeof(xxh_u64x2));
4326 ret = XXH_vec_revb(ret);
4337# if defined(__s390x__)
4339# define XXH_vec_mulo vec_mulo
4340# define XXH_vec_mule vec_mule
4341# elif defined(__clang__) && XXH_HAS_BUILTIN(__builtin_altivec_vmuleuw) && !defined(__ibmxl__)
4344# define XXH_vec_mulo __builtin_altivec_vmulouw
4345# define XXH_vec_mule __builtin_altivec_vmuleuw
4349XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mulo(xxh_u32x4 a, xxh_u32x4 b)
4352 __asm__(
"vmulouw %0, %1, %2" :
"=v" (result) :
"v" (a),
"v" (b));
4355XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mule(xxh_u32x4 a, xxh_u32x4 b)
4358 __asm__(
"vmuleuw %0, %1, %2" :
"=v" (result) :
"v" (a),
"v" (b));
4364#if XXH_VECTOR == XXH_SVE
4365#define ACCRND(acc, offset) \
4367 svuint64_t input_vec = svld1_u64(mask, xinput + offset); \
4368 svuint64_t secret_vec = svld1_u64(mask, xsecret + offset); \
4369 svuint64_t mixed = sveor_u64_x(mask, secret_vec, input_vec); \
4370 svuint64_t swapped = svtbl_u64(input_vec, kSwap); \
4371 svuint64_t mixed_lo = svextw_u64_x(mask, mixed); \
4372 svuint64_t mixed_hi = svlsr_n_u64_x(mask, mixed, 32); \
4373 svuint64_t mul = svmad_u64_x(mask, mixed_lo, mixed_hi, swapped); \
4374 acc = svadd_u64_x(mask, acc, mul); \
4380#if defined(XXH_NO_PREFETCH)
4381# define XXH_PREFETCH(ptr) (void)(ptr)
4383# if XXH_SIZE_OPT >= 1
4384# define XXH_PREFETCH(ptr) (void)(ptr)
4385# elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
4386# include <mmintrin.h>
4387# define XXH_PREFETCH(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
4388# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
4389# define XXH_PREFETCH(ptr) __builtin_prefetch((ptr), 0 , 3 )
4391# define XXH_PREFETCH(ptr) (void)(ptr)
4400#define XXH_SECRET_DEFAULT_SIZE 192
4402#if (XXH_SECRET_DEFAULT_SIZE < XXH3_SECRET_SIZE_MIN)
4403# error "default keyset is not large enough"
4410XXH_ALIGN(64) static const xxh_u8 XXH3_kSecret[XXH_SECRET_DEFAULT_SIZE] = {
4411 0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c,
4412 0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f,
4413 0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21,
4414 0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c,
4415 0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3,
4416 0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8,
4417 0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d,
4418 0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64,
4419 0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb,
4420 0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e,
4421 0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce,
4422 0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e,
4425static const xxh_u64 PRIME_MX1 = 0x165667919E3779F9ULL;
4426static const xxh_u64 PRIME_MX2 = 0x9FB21C651E98DF25ULL;
4429# define kSecret XXH3_kSecret
4449XXH_FORCE_INLINE xxh_u64
4450XXH_mult32to64(xxh_u64 x, xxh_u64 y)
4452 return (x & 0xFFFFFFFF) * (y & 0xFFFFFFFF);
4454#elif defined(_MSC_VER) && defined(_M_IX86)
4455# define XXH_mult32to64(x, y) __emulu((unsigned)(x), (unsigned)(y))
4464# define XXH_mult32to64(x, y) ((xxh_u64)(xxh_u32)(x) * (xxh_u64)(xxh_u32)(y))
4477XXH_mult64to128(xxh_u64 lhs, xxh_u64 rhs)
4494#if (defined(__GNUC__) || defined(__clang__)) && !defined(__wasm__) \
4495 && defined(__SIZEOF_INT128__) \
4496 || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
4498 __uint128_t
const product = (__uint128_t)lhs * (__uint128_t)rhs;
4500 r128.
low64 = (xxh_u64)(product);
4501 r128.
high64 = (xxh_u64)(product >> 64);
4511#elif (defined(_M_X64) || defined(_M_IA64)) && !defined(_M_ARM64EC)
4514# pragma intrinsic(_umul128)
4516 xxh_u64 product_high;
4517 xxh_u64
const product_low = _umul128(lhs, rhs, &product_high);
4519 r128.
low64 = product_low;
4520 r128.
high64 = product_high;
4528#elif defined(_M_ARM64) || defined(_M_ARM64EC)
4531# pragma intrinsic(__umulh)
4534 r128.
low64 = lhs * rhs;
4535 r128.
high64 = __umulh(lhs, rhs);
4583 xxh_u64
const lo_lo = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs & 0xFFFFFFFF);
4584 xxh_u64
const hi_lo = XXH_mult32to64(lhs >> 32, rhs & 0xFFFFFFFF);
4585 xxh_u64
const lo_hi = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs >> 32);
4586 xxh_u64
const hi_hi = XXH_mult32to64(lhs >> 32, rhs >> 32);
4589 xxh_u64
const cross = (lo_lo >> 32) + (hi_lo & 0xFFFFFFFF) + lo_hi;
4590 xxh_u64
const upper = (hi_lo >> 32) + (cross >> 32) + hi_hi;
4591 xxh_u64
const lower = (cross << 32) | (lo_lo & 0xFFFFFFFF);
4611XXH3_mul128_fold64(xxh_u64 lhs, xxh_u64 rhs)
4618XXH_FORCE_INLINE XXH_CONSTF xxh_u64 XXH_xorshift64(xxh_u64 v64,
int shift)
4620 XXH_ASSERT(0 <= shift && shift < 64);
4621 return v64 ^ (v64 >> shift);
4630 h64 = XXH_xorshift64(h64, 37);
4632 h64 = XXH_xorshift64(h64, 32);
4641static XXH64_hash_t XXH3_rrmxmx(xxh_u64 h64, xxh_u64 len)
4644 h64 ^= XXH_rotl64(h64, 49) ^ XXH_rotl64(h64, 24);
4646 h64 ^= (h64 >> 35) + len ;
4648 return XXH_xorshift64(h64, 28);
4686XXH3_len_1to3_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4688 XXH_ASSERT(input != NULL);
4689 XXH_ASSERT(1 <= len && len <= 3);
4690 XXH_ASSERT(secret != NULL);
4696 { xxh_u8
const c1 = input[0];
4697 xxh_u8
const c2 = input[len >> 1];
4698 xxh_u8
const c3 = input[len - 1];
4699 xxh_u32
const combined = ((xxh_u32)c1 << 16) | ((xxh_u32)c2 << 24)
4700 | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8);
4701 xxh_u64
const bitflip = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed;
4702 xxh_u64
const keyed = (xxh_u64)combined ^ bitflip;
4703 return XXH64_avalanche(keyed);
4708XXH3_len_4to8_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4710 XXH_ASSERT(input != NULL);
4711 XXH_ASSERT(secret != NULL);
4712 XXH_ASSERT(4 <= len && len <= 8);
4713 seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32;
4714 { xxh_u32
const input1 = XXH_readLE32(input);
4715 xxh_u32
const input2 = XXH_readLE32(input + len - 4);
4716 xxh_u64
const bitflip = (XXH_readLE64(secret+8) ^ XXH_readLE64(secret+16)) - seed;
4717 xxh_u64
const input64 = input2 + (((xxh_u64)input1) << 32);
4718 xxh_u64
const keyed = input64 ^ bitflip;
4719 return XXH3_rrmxmx(keyed, len);
4724XXH3_len_9to16_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4726 XXH_ASSERT(input != NULL);
4727 XXH_ASSERT(secret != NULL);
4728 XXH_ASSERT(9 <= len && len <= 16);
4729 { xxh_u64
const bitflip1 = (XXH_readLE64(secret+24) ^ XXH_readLE64(secret+32)) + seed;
4730 xxh_u64
const bitflip2 = (XXH_readLE64(secret+40) ^ XXH_readLE64(secret+48)) - seed;
4731 xxh_u64
const input_lo = XXH_readLE64(input) ^ bitflip1;
4732 xxh_u64
const input_hi = XXH_readLE64(input + len - 8) ^ bitflip2;
4733 xxh_u64
const acc = len
4734 + XXH_swap64(input_lo) + input_hi
4735 + XXH3_mul128_fold64(input_lo, input_hi);
4736 return XXH3_avalanche(acc);
4741XXH3_len_0to16_64b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
4743 XXH_ASSERT(len <= 16);
4744 {
if (XXH_likely(len > 8))
return XXH3_len_9to16_64b(input, len, secret, seed);
4745 if (XXH_likely(len >= 4))
return XXH3_len_4to8_64b(input, len, secret, seed);
4746 if (len)
return XXH3_len_1to3_64b(input, len, secret, seed);
4747 return XXH64_avalanche(seed ^ (XXH_readLE64(secret+56) ^ XXH_readLE64(secret+64)));
4806XXH_FORCE_INLINE xxh_u64 XXH3_mix16B(
const xxh_u8* XXH_RESTRICT input,
4807 const xxh_u8* XXH_RESTRICT secret, xxh_u64 seed64)
4809#if defined(__GNUC__) && !defined(__clang__) \
4810 && defined(__i386__) && defined(__SSE2__) \
4811 && !defined(XXH_ENABLE_AUTOVECTORIZE)
4827 XXH_COMPILER_GUARD(seed64);
4829 { xxh_u64
const input_lo = XXH_readLE64(input);
4830 xxh_u64
const input_hi = XXH_readLE64(input+8);
4831 return XXH3_mul128_fold64(
4832 input_lo ^ (XXH_readLE64(secret) + seed64),
4833 input_hi ^ (XXH_readLE64(secret+8) - seed64)
4840XXH3_len_17to128_64b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
4841 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
4845 XXH_ASSERT(16 < len && len <= 128);
4848#if XXH_SIZE_OPT >= 1
4850 unsigned int i = (
unsigned int)(len - 1) / 32;
4852 acc += XXH3_mix16B(input+16 * i, secret+32*i, seed);
4853 acc += XXH3_mix16B(input+len-16*(i+1), secret+32*i+16, seed);
4859 acc += XXH3_mix16B(input+48, secret+96, seed);
4860 acc += XXH3_mix16B(input+len-64, secret+112, seed);
4862 acc += XXH3_mix16B(input+32, secret+64, seed);
4863 acc += XXH3_mix16B(input+len-48, secret+80, seed);
4865 acc += XXH3_mix16B(input+16, secret+32, seed);
4866 acc += XXH3_mix16B(input+len-32, secret+48, seed);
4868 acc += XXH3_mix16B(input+0, secret+0, seed);
4869 acc += XXH3_mix16B(input+len-16, secret+16, seed);
4871 return XXH3_avalanche(acc);
4876XXH3_len_129to240_64b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
4877 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
4883 #define XXH3_MIDSIZE_STARTOFFSET 3
4884 #define XXH3_MIDSIZE_LASTOFFSET 17
4888 unsigned int const nbRounds = (
unsigned int)len / 16;
4891 for (i=0; i<8; i++) {
4892 acc += XXH3_mix16B(input+(16*i), secret+(16*i), seed);
4895 acc_end = XXH3_mix16B(input + len - 16, secret +
XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET, seed);
4896 XXH_ASSERT(nbRounds >= 8);
4897 acc = XXH3_avalanche(acc);
4898#if defined(__clang__) \
4899 && (defined(__ARM_NEON) || defined(__ARM_NEON__)) \
4900 && !defined(XXH_ENABLE_AUTOVECTORIZE)
4921 #pragma clang loop vectorize(disable)
4923 for (i=8 ; i < nbRounds; i++) {
4927 XXH_COMPILER_GUARD(acc);
4928 acc_end += XXH3_mix16B(input+(16*i), secret+(16*(i-8)) + XXH3_MIDSIZE_STARTOFFSET, seed);
4930 return XXH3_avalanche(acc + acc_end);
4937#define XXH_STRIPE_LEN 64
4938#define XXH_SECRET_CONSUME_RATE 8
4939#define XXH_ACC_NB (XXH_STRIPE_LEN / sizeof(xxh_u64))
4942# define STRIPE_LEN XXH_STRIPE_LEN
4943# define ACC_NB XXH_ACC_NB
4946#ifndef XXH_PREFETCH_DIST
4948# define XXH_PREFETCH_DIST 320
4950# if (XXH_VECTOR == XXH_AVX512)
4951# define XXH_PREFETCH_DIST 512
4953# define XXH_PREFETCH_DIST 384
4968#define XXH3_ACCUMULATE_TEMPLATE(name) \
4970XXH3_accumulate_##name(xxh_u64* XXH_RESTRICT acc, \
4971 const xxh_u8* XXH_RESTRICT input, \
4972 const xxh_u8* XXH_RESTRICT secret, \
4976 for (n = 0; n < nbStripes; n++ ) { \
4977 const xxh_u8* const in = input + n*XXH_STRIPE_LEN; \
4978 XXH_PREFETCH(in + XXH_PREFETCH_DIST); \
4979 XXH3_accumulate_512_##name( \
4982 secret + n*XXH_SECRET_CONSUME_RATE); \
4987XXH_FORCE_INLINE
void XXH_writeLE64(
void* dst, xxh_u64 v64)
4990 XXH_memcpy(dst, &v64,
sizeof(v64));
4998#if !defined (__VMS) \
4999 && (defined (__cplusplus) \
5000 || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) )
5001 typedef int64_t xxh_i64;
5004 typedef long long xxh_i64;
5031#if (XXH_VECTOR == XXH_AVX512) \
5032 || (defined(XXH_DISPATCH_AVX512) && XXH_DISPATCH_AVX512 != 0)
5034#ifndef XXH_TARGET_AVX512
5035# define XXH_TARGET_AVX512
5039XXH3_accumulate_512_avx512(
void* XXH_RESTRICT acc,
5040 const void* XXH_RESTRICT input,
5041 const void* XXH_RESTRICT secret)
5043 __m512i*
const xacc = (__m512i *) acc;
5044 XXH_ASSERT((((
size_t)acc) & 63) == 0);
5045 XXH_STATIC_ASSERT(XXH_STRIPE_LEN ==
sizeof(__m512i));
5049 __m512i
const data_vec = _mm512_loadu_si512 (input);
5051 __m512i
const key_vec = _mm512_loadu_si512 (secret);
5053 __m512i
const data_key = _mm512_xor_si512 (data_vec, key_vec);
5055 __m512i
const data_key_lo = _mm512_srli_epi64 (data_key, 32);
5057 __m512i
const product = _mm512_mul_epu32 (data_key, data_key_lo);
5059 __m512i
const data_swap = _mm512_shuffle_epi32(data_vec, (_MM_PERM_ENUM)_MM_SHUFFLE(1, 0, 3, 2));
5060 __m512i
const sum = _mm512_add_epi64(*xacc, data_swap);
5062 *xacc = _mm512_add_epi64(product, sum);
5089XXH3_scrambleAcc_avx512(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5091 XXH_ASSERT((((
size_t)acc) & 63) == 0);
5092 XXH_STATIC_ASSERT(XXH_STRIPE_LEN ==
sizeof(__m512i));
5093 { __m512i*
const xacc = (__m512i*) acc;
5094 const __m512i prime32 = _mm512_set1_epi32((
int)
XXH_PRIME32_1);
5097 __m512i
const acc_vec = *xacc;
5098 __m512i
const shifted = _mm512_srli_epi64 (acc_vec, 47);
5100 __m512i
const key_vec = _mm512_loadu_si512 (secret);
5101 __m512i
const data_key = _mm512_ternarylogic_epi32(key_vec, acc_vec, shifted, 0x96 );
5104 __m512i
const data_key_hi = _mm512_srli_epi64 (data_key, 32);
5105 __m512i
const prod_lo = _mm512_mul_epu32 (data_key, prime32);
5106 __m512i
const prod_hi = _mm512_mul_epu32 (data_key_hi, prime32);
5107 *xacc = _mm512_add_epi64(prod_lo, _mm512_slli_epi64(prod_hi, 32));
5112XXH3_initCustomSecret_avx512(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
5114 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 63) == 0);
5115 XXH_STATIC_ASSERT(XXH_SEC_ALIGN == 64);
5116 XXH_ASSERT(((
size_t)customSecret & 63) == 0);
5117 (void)(&XXH_writeLE64);
5118 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE /
sizeof(__m512i);
5119 __m512i
const seed_pos = _mm512_set1_epi64((xxh_i64)seed64);
5120 __m512i
const seed = _mm512_mask_sub_epi64(seed_pos, 0xAA, _mm512_setzero_si512(), seed_pos);
5122 const __m512i*
const src = (
const __m512i*) ((
const void*) XXH3_kSecret);
5123 __m512i*
const dest = ( __m512i*) customSecret;
5125 XXH_ASSERT(((
size_t)src & 63) == 0);
5126 XXH_ASSERT(((
size_t)dest & 63) == 0);
5127 for (i=0; i < nbRounds; ++i) {
5128 dest[i] = _mm512_add_epi64(_mm512_load_si512(src + i), seed);
5134#if (XXH_VECTOR == XXH_AVX2) \
5135 || (defined(XXH_DISPATCH_AVX2) && XXH_DISPATCH_AVX2 != 0)
5137#ifndef XXH_TARGET_AVX2
5138# define XXH_TARGET_AVX2
5142XXH3_accumulate_512_avx2(
void* XXH_RESTRICT acc,
5143 const void* XXH_RESTRICT input,
5144 const void* XXH_RESTRICT secret)
5146 XXH_ASSERT((((
size_t)acc) & 31) == 0);
5147 { __m256i*
const xacc = (__m256i *) acc;
5150 const __m256i*
const xinput = (
const __m256i *) input;
5153 const __m256i*
const xsecret = (
const __m256i *) secret;
5156 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m256i); i++) {
5158 __m256i
const data_vec = _mm256_loadu_si256 (xinput+i);
5160 __m256i
const key_vec = _mm256_loadu_si256 (xsecret+i);
5162 __m256i
const data_key = _mm256_xor_si256 (data_vec, key_vec);
5164 __m256i
const data_key_lo = _mm256_srli_epi64 (data_key, 32);
5166 __m256i
const product = _mm256_mul_epu32 (data_key, data_key_lo);
5168 __m256i
const data_swap = _mm256_shuffle_epi32(data_vec, _MM_SHUFFLE(1, 0, 3, 2));
5169 __m256i
const sum = _mm256_add_epi64(xacc[i], data_swap);
5171 xacc[i] = _mm256_add_epi64(product, sum);
5177XXH3_scrambleAcc_avx2(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5179 XXH_ASSERT((((
size_t)acc) & 31) == 0);
5180 { __m256i*
const xacc = (__m256i*) acc;
5183 const __m256i*
const xsecret = (
const __m256i *) secret;
5184 const __m256i prime32 = _mm256_set1_epi32((
int)
XXH_PRIME32_1);
5187 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m256i); i++) {
5189 __m256i
const acc_vec = xacc[i];
5190 __m256i
const shifted = _mm256_srli_epi64 (acc_vec, 47);
5191 __m256i
const data_vec = _mm256_xor_si256 (acc_vec, shifted);
5193 __m256i
const key_vec = _mm256_loadu_si256 (xsecret+i);
5194 __m256i
const data_key = _mm256_xor_si256 (data_vec, key_vec);
5197 __m256i
const data_key_hi = _mm256_srli_epi64 (data_key, 32);
5198 __m256i
const prod_lo = _mm256_mul_epu32 (data_key, prime32);
5199 __m256i
const prod_hi = _mm256_mul_epu32 (data_key_hi, prime32);
5200 xacc[i] = _mm256_add_epi64(prod_lo, _mm256_slli_epi64(prod_hi, 32));
5205XXH_FORCE_INLINE
XXH_TARGET_AVX2 void XXH3_initCustomSecret_avx2(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
5207 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 31) == 0);
5208 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE /
sizeof(__m256i)) == 6);
5209 XXH_STATIC_ASSERT(XXH_SEC_ALIGN <= 64);
5210 (void)(&XXH_writeLE64);
5211 XXH_PREFETCH(customSecret);
5212 { __m256i
const seed = _mm256_set_epi64x((xxh_i64)(0U - seed64), (xxh_i64)seed64, (xxh_i64)(0U - seed64), (xxh_i64)seed64);
5214 const __m256i*
const src = (
const __m256i*) ((
const void*) XXH3_kSecret);
5215 __m256i* dest = ( __m256i*) customSecret;
5217# if defined(__GNUC__) || defined(__clang__)
5223 XXH_COMPILER_GUARD(dest);
5225 XXH_ASSERT(((
size_t)src & 31) == 0);
5226 XXH_ASSERT(((
size_t)dest & 31) == 0);
5229 dest[0] = _mm256_add_epi64(_mm256_load_si256(src+0), seed);
5230 dest[1] = _mm256_add_epi64(_mm256_load_si256(src+1), seed);
5231 dest[2] = _mm256_add_epi64(_mm256_load_si256(src+2), seed);
5232 dest[3] = _mm256_add_epi64(_mm256_load_si256(src+3), seed);
5233 dest[4] = _mm256_add_epi64(_mm256_load_si256(src+4), seed);
5234 dest[5] = _mm256_add_epi64(_mm256_load_si256(src+5), seed);
5241#if (XXH_VECTOR == XXH_SSE2) || defined(XXH_X86DISPATCH)
5243#ifndef XXH_TARGET_SSE2
5244# define XXH_TARGET_SSE2
5248XXH3_accumulate_512_sse2(
void* XXH_RESTRICT acc,
5249 const void* XXH_RESTRICT input,
5250 const void* XXH_RESTRICT secret)
5253 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5254 { __m128i*
const xacc = (__m128i *) acc;
5257 const __m128i*
const xinput = (
const __m128i *) input;
5260 const __m128i*
const xsecret = (
const __m128i *) secret;
5263 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m128i); i++) {
5265 __m128i
const data_vec = _mm_loadu_si128 (xinput+i);
5267 __m128i
const key_vec = _mm_loadu_si128 (xsecret+i);
5269 __m128i
const data_key = _mm_xor_si128 (data_vec, key_vec);
5271 __m128i
const data_key_lo = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1));
5273 __m128i
const product = _mm_mul_epu32 (data_key, data_key_lo);
5275 __m128i
const data_swap = _mm_shuffle_epi32(data_vec, _MM_SHUFFLE(1,0,3,2));
5276 __m128i
const sum = _mm_add_epi64(xacc[i], data_swap);
5278 xacc[i] = _mm_add_epi64(product, sum);
5284XXH3_scrambleAcc_sse2(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5286 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5287 { __m128i*
const xacc = (__m128i*) acc;
5290 const __m128i*
const xsecret = (
const __m128i *) secret;
5294 for (i=0; i < XXH_STRIPE_LEN/
sizeof(__m128i); i++) {
5296 __m128i
const acc_vec = xacc[i];
5297 __m128i
const shifted = _mm_srli_epi64 (acc_vec, 47);
5298 __m128i
const data_vec = _mm_xor_si128 (acc_vec, shifted);
5300 __m128i
const key_vec = _mm_loadu_si128 (xsecret+i);
5301 __m128i
const data_key = _mm_xor_si128 (data_vec, key_vec);
5304 __m128i
const data_key_hi = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1));
5305 __m128i
const prod_lo = _mm_mul_epu32 (data_key, prime32);
5306 __m128i
const prod_hi = _mm_mul_epu32 (data_key_hi, prime32);
5307 xacc[i] = _mm_add_epi64(prod_lo, _mm_slli_epi64(prod_hi, 32));
5312XXH_FORCE_INLINE
XXH_TARGET_SSE2 void XXH3_initCustomSecret_sse2(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
5314 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0);
5315 (void)(&XXH_writeLE64);
5316 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE /
sizeof(__m128i);
5318# if defined(_MSC_VER) && defined(_M_IX86) && _MSC_VER <= 1900
5322 xxh_u64
const seed64_unsigned = (xxh_u64)seed64;
5323 xxh_u64
const neg_seed64 = (xxh_u64)(0ULL - seed64_unsigned);
5324 __m128i
const seed = _mm_set_epi32(
5325 (
int)(neg_seed64 >> 32),
5327 (
int)(seed64_unsigned >> 32),
5328 (
int)(seed64_unsigned)
5331 __m128i
const seed = _mm_set_epi64x((xxh_i64)(0U - seed64), (xxh_i64)seed64);
5335 const void*
const src16 = XXH3_kSecret;
5336 __m128i* dst16 = (__m128i*) customSecret;
5337# if defined(__GNUC__) || defined(__clang__)
5343 XXH_COMPILER_GUARD(dst16);
5345 XXH_ASSERT(((
size_t)src16 & 15) == 0);
5346 XXH_ASSERT(((
size_t)dst16 & 15) == 0);
5348 for (i=0; i < nbRounds; ++i) {
5349 dst16[i] = _mm_add_epi64(_mm_load_si128((
const __m128i *)src16+i), seed);
5355#if (XXH_VECTOR == XXH_NEON)
5358XXH_FORCE_INLINE
void
5359XXH3_scalarRound(
void* XXH_RESTRICT acc,
void const* XXH_RESTRICT input,
5360 void const* XXH_RESTRICT secret,
size_t lane);
5362XXH_FORCE_INLINE
void
5363XXH3_scalarScrambleRound(
void* XXH_RESTRICT acc,
5364 void const* XXH_RESTRICT secret,
size_t lane);
5390XXH_FORCE_INLINE
void
5391XXH3_accumulate_512_neon(
void* XXH_RESTRICT acc,
5392 const void* XXH_RESTRICT input,
5393 const void* XXH_RESTRICT secret)
5395 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5398 xxh_aliasing_uint64x2_t*
const xacc = (xxh_aliasing_uint64x2_t*) acc;
5400 uint8_t
const* xinput = (
const uint8_t *) input;
5401 uint8_t
const* xsecret = (
const uint8_t *) secret;
5404#ifdef __wasm_simd128__
5422 XXH_COMPILER_GUARD(xsecret);
5426 XXH3_scalarRound(acc, input, secret, i);
5432 uint64x2_t data_vec_1 = XXH_vld1q_u64(xinput + (i * 16));
5433 uint64x2_t data_vec_2 = XXH_vld1q_u64(xinput + ((i+1) * 16));
5435 uint64x2_t key_vec_1 = XXH_vld1q_u64(xsecret + (i * 16));
5436 uint64x2_t key_vec_2 = XXH_vld1q_u64(xsecret + ((i+1) * 16));
5438 uint64x2_t data_swap_1 = vextq_u64(data_vec_1, data_vec_1, 1);
5439 uint64x2_t data_swap_2 = vextq_u64(data_vec_2, data_vec_2, 1);
5441 uint64x2_t data_key_1 = veorq_u64(data_vec_1, key_vec_1);
5442 uint64x2_t data_key_2 = veorq_u64(data_vec_2, key_vec_2);
5457 uint32x4x2_t unzipped = vuzpq_u32(
5458 vreinterpretq_u32_u64(data_key_1),
5459 vreinterpretq_u32_u64(data_key_2)
5462 uint32x4_t data_key_lo = unzipped.val[0];
5464 uint32x4_t data_key_hi = unzipped.val[1];
5472 uint64x2_t sum_1 = XXH_vmlal_low_u32(data_swap_1, data_key_lo, data_key_hi);
5473 uint64x2_t sum_2 = XXH_vmlal_high_u32(data_swap_2, data_key_lo, data_key_hi);
5486 XXH_COMPILER_GUARD_CLANG_NEON(sum_1);
5487 XXH_COMPILER_GUARD_CLANG_NEON(sum_2);
5489 xacc[i] = vaddq_u64(xacc[i], sum_1);
5490 xacc[i+1] = vaddq_u64(xacc[i+1], sum_2);
5495 uint64x2_t data_vec = XXH_vld1q_u64(xinput + (i * 16));
5497 uint64x2_t key_vec = XXH_vld1q_u64(xsecret + (i * 16));
5499 uint64x2_t data_swap = vextq_u64(data_vec, data_vec, 1);
5501 uint64x2_t data_key = veorq_u64(data_vec, key_vec);
5504 uint32x2_t data_key_lo = vmovn_u64(data_key);
5506 uint32x2_t data_key_hi = vshrn_n_u64(data_key, 32);
5508 uint64x2_t sum = vmlal_u32(data_swap, data_key_lo, data_key_hi);
5510 XXH_COMPILER_GUARD_CLANG_NEON(sum);
5512 xacc[i] = vaddq_u64 (xacc[i], sum);
5516XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(neon)
5518XXH_FORCE_INLINE
void
5519XXH3_scrambleAcc_neon(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5521 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5523 { xxh_aliasing_uint64x2_t* xacc = (xxh_aliasing_uint64x2_t*) acc;
5524 uint8_t
const* xsecret = (uint8_t
const*) secret;
5528#ifndef __wasm_simd128__
5532 uint32x4_t
const kPrimeHi = vreinterpretq_u32_u64(vdupq_n_u64((xxh_u64)
XXH_PRIME32_1 << 32));
5537 XXH3_scalarScrambleRound(acc, secret, i);
5541 uint64x2_t acc_vec = xacc[i];
5542 uint64x2_t shifted = vshrq_n_u64(acc_vec, 47);
5543 uint64x2_t data_vec = veorq_u64(acc_vec, shifted);
5546 uint64x2_t key_vec = XXH_vld1q_u64(xsecret + (i * 16));
5547 uint64x2_t data_key = veorq_u64(data_vec, key_vec);
5549#ifdef __wasm_simd128__
5564 uint32x4_t prod_hi = vmulq_u32 (vreinterpretq_u32_u64(data_key), kPrimeHi);
5566 uint32x2_t data_key_lo = vmovn_u64(data_key);
5568 xacc[i] = vmlal_u32(vreinterpretq_u64_u32(prod_hi), data_key_lo, kPrimeLo);
5575#if (XXH_VECTOR == XXH_VSX)
5577XXH_FORCE_INLINE
void
5578XXH3_accumulate_512_vsx(
void* XXH_RESTRICT acc,
5579 const void* XXH_RESTRICT input,
5580 const void* XXH_RESTRICT secret)
5583 xxh_aliasing_u64x2*
const xacc = (xxh_aliasing_u64x2*) acc;
5584 xxh_u8
const*
const xinput = (xxh_u8
const*) input;
5585 xxh_u8
const*
const xsecret = (xxh_u8
const*) secret;
5586 xxh_u64x2
const v32 = { 32, 32 };
5588 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(xxh_u64x2); i++) {
5590 xxh_u64x2
const data_vec = XXH_vec_loadu(xinput + 16*i);
5592 xxh_u64x2
const key_vec = XXH_vec_loadu(xsecret + 16*i);
5593 xxh_u64x2
const data_key = data_vec ^ key_vec;
5595 xxh_u32x4
const shuffled = (xxh_u32x4)vec_rl(data_key, v32);
5597 xxh_u64x2
const product = XXH_vec_mulo((xxh_u32x4)data_key, shuffled);
5599 xxh_u64x2 acc_vec = xacc[i];
5604 acc_vec += vec_permi(data_vec, data_vec, 2);
5606 acc_vec += vec_xxpermdi(data_vec, data_vec, 2);
5611XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(vsx)
5613XXH_FORCE_INLINE
void
5614XXH3_scrambleAcc_vsx(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5616 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5618 { xxh_aliasing_u64x2*
const xacc = (xxh_aliasing_u64x2*) acc;
5619 const xxh_u8*
const xsecret = (
const xxh_u8*) secret;
5621 xxh_u64x2
const v32 = { 32, 32 };
5622 xxh_u64x2
const v47 = { 47, 47 };
5625 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(xxh_u64x2); i++) {
5627 xxh_u64x2
const acc_vec = xacc[i];
5628 xxh_u64x2
const data_vec = acc_vec ^ (acc_vec >> v47);
5631 xxh_u64x2
const key_vec = XXH_vec_loadu(xsecret + 16*i);
5632 xxh_u64x2
const data_key = data_vec ^ key_vec;
5636 xxh_u64x2
const prod_even = XXH_vec_mule((xxh_u32x4)data_key, prime);
5638 xxh_u64x2
const prod_odd = XXH_vec_mulo((xxh_u32x4)data_key, prime);
5639 xacc[i] = prod_odd + (prod_even << v32);
5645#if (XXH_VECTOR == XXH_SVE)
5647XXH_FORCE_INLINE
void
5648XXH3_accumulate_512_sve(
void* XXH_RESTRICT acc,
5649 const void* XXH_RESTRICT input,
5650 const void* XXH_RESTRICT secret)
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);
5661 svst1_u64(mask, xacc, vacc);
5662 }
else if (element_count == 2) {
5663 svbool_t mask = svptrue_pat_b64(SV_VL2);
5664 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5665 svuint64_t acc1 = svld1_u64(mask, xacc + 2);
5666 svuint64_t acc2 = svld1_u64(mask, xacc + 4);
5667 svuint64_t acc3 = svld1_u64(mask, xacc + 6);
5672 svst1_u64(mask, xacc + 0, acc0);
5673 svst1_u64(mask, xacc + 2, acc1);
5674 svst1_u64(mask, xacc + 4, acc2);
5675 svst1_u64(mask, xacc + 6, acc3);
5677 svbool_t mask = svptrue_pat_b64(SV_VL4);
5678 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5679 svuint64_t acc1 = svld1_u64(mask, xacc + 4);
5682 svst1_u64(mask, xacc + 0, acc0);
5683 svst1_u64(mask, xacc + 4, acc1);
5687XXH_FORCE_INLINE
void
5688XXH3_accumulate_sve(xxh_u64* XXH_RESTRICT acc,
5689 const xxh_u8* XXH_RESTRICT input,
5690 const xxh_u8* XXH_RESTRICT secret,
5693 if (nbStripes != 0) {
5694 uint64_t *xacc = (uint64_t *)acc;
5695 const uint64_t *xinput = (
const uint64_t *)(
const void *)input;
5696 const uint64_t *xsecret = (
const uint64_t *)(
const void *)secret;
5697 svuint64_t kSwap = sveor_n_u64_z(svptrue_b64(), svindex_u64(0, 1), 1);
5698 uint64_t element_count = svcntd();
5699 if (element_count >= 8) {
5700 svbool_t mask = svptrue_pat_b64(SV_VL8);
5701 svuint64_t vacc = svld1_u64(mask, xacc + 0);
5704 svprfd(mask, xinput + 128, SV_PLDL1STRM);
5709 }
while (nbStripes != 0);
5711 svst1_u64(mask, xacc + 0, vacc);
5712 }
else if (element_count == 2) {
5713 svbool_t mask = svptrue_pat_b64(SV_VL2);
5714 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5715 svuint64_t acc1 = svld1_u64(mask, xacc + 2);
5716 svuint64_t acc2 = svld1_u64(mask, xacc + 4);
5717 svuint64_t acc3 = svld1_u64(mask, xacc + 6);
5719 svprfd(mask, xinput + 128, SV_PLDL1STRM);
5727 }
while (nbStripes != 0);
5729 svst1_u64(mask, xacc + 0, acc0);
5730 svst1_u64(mask, xacc + 2, acc1);
5731 svst1_u64(mask, xacc + 4, acc2);
5732 svst1_u64(mask, xacc + 6, acc3);
5734 svbool_t mask = svptrue_pat_b64(SV_VL4);
5735 svuint64_t acc0 = svld1_u64(mask, xacc + 0);
5736 svuint64_t acc1 = svld1_u64(mask, xacc + 4);
5738 svprfd(mask, xinput + 128, SV_PLDL1STRM);
5744 }
while (nbStripes != 0);
5746 svst1_u64(mask, xacc + 0, acc0);
5747 svst1_u64(mask, xacc + 4, acc1);
5754#if (XXH_VECTOR == XXH_LSX)
5755#define _LSX_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
5757XXH_FORCE_INLINE
void
5758XXH3_accumulate_512_lsx(
void* XXH_RESTRICT acc,
5759 const void* XXH_RESTRICT input,
5760 const void* XXH_RESTRICT secret)
5762 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5764 __m128i*
const xacc = (__m128i *) acc;
5765 const __m128i*
const xinput = (
const __m128i *) input;
5766 const __m128i*
const xsecret = (
const __m128i *) secret;
5769 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(__m128i); i++) {
5771 __m128i
const data_vec = __lsx_vld(xinput + i, 0);
5773 __m128i
const key_vec = __lsx_vld(xsecret + i, 0);
5775 __m128i
const data_key = __lsx_vxor_v(data_vec, key_vec);
5777 __m128i
const data_key_lo = __lsx_vsrli_d(data_key, 32);
5780 __m128i
const product = __lsx_vmulwev_d_wu(data_key, data_key_lo);
5782 __m128i
const data_swap = __lsx_vshuf4i_w(data_vec, _LSX_SHUFFLE(1, 0, 3, 2));
5783 __m128i
const sum = __lsx_vadd_d(xacc[i], data_swap);
5785 xacc[i] = __lsx_vadd_d(product, sum);
5789XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(lsx)
5791XXH_FORCE_INLINE
void
5792XXH3_scrambleAcc_lsx(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5794 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5796 __m128i*
const xacc = (__m128i*) acc;
5797 const __m128i*
const xsecret = (
const __m128i *) secret;
5801 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(__m128i); i++) {
5803 __m128i
const acc_vec = xacc[i];
5804 __m128i
const shifted = __lsx_vsrli_d(acc_vec, 47);
5805 __m128i
const data_vec = __lsx_vxor_v(acc_vec, shifted);
5807 __m128i
const key_vec = __lsx_vld(xsecret + i, 0);
5808 __m128i
const data_key = __lsx_vxor_v(data_vec, key_vec);
5811 xacc[i] = __lsx_vmul_d(data_key, prime32);
5818#if (XXH_VECTOR == XXH_LASX)
5819#define _LASX_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
5821XXH_FORCE_INLINE
void
5822XXH3_accumulate_512_lasx(
void* XXH_RESTRICT acc,
5823 const void* XXH_RESTRICT input,
5824 const void* XXH_RESTRICT secret)
5826 XXH_ASSERT((((
size_t)acc) & 31) == 0);
5829 __m256i*
const xacc = (__m256i *) acc;
5830 const __m256i*
const xinput = (
const __m256i *) input;
5831 const __m256i*
const xsecret = (
const __m256i *) secret;
5833 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(__m256i); i++) {
5835 __m256i
const data_vec = __lasx_xvld(xinput + i, 0);
5837 __m256i
const key_vec = __lasx_xvld(xsecret + i, 0);
5839 __m256i
const data_key = __lasx_xvxor_v(data_vec, key_vec);
5841 __m256i
const data_key_lo = __lasx_xvsrli_d(data_key, 32);
5844 __m256i
const product = __lasx_xvmulwev_d_wu(data_key, data_key_lo);
5846 __m256i
const data_swap = __lasx_xvshuf4i_w(data_vec, _LASX_SHUFFLE(1, 0, 3, 2));
5847 __m256i
const sum = __lasx_xvadd_d(xacc[i], data_swap);
5849 xacc[i] = __lasx_xvadd_d(product, sum);
5853XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(lasx)
5855XXH_FORCE_INLINE
void
5856XXH3_scrambleAcc_lasx(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5858 XXH_ASSERT((((
size_t)acc) & 31) == 0);
5860 __m256i*
const xacc = (__m256i*) acc;
5861 const __m256i*
const xsecret = (
const __m256i *) secret;
5862 const __m256i prime32 = __lasx_xvreplgr2vr_d(
XXH_PRIME32_1);
5865 for (i = 0; i < XXH_STRIPE_LEN /
sizeof(__m256i); i++) {
5867 __m256i
const acc_vec = xacc[i];
5868 __m256i
const shifted = __lasx_xvsrli_d(acc_vec, 47);
5869 __m256i
const data_vec = __lasx_xvxor_v(acc_vec, shifted);
5871 __m256i
const key_vec = __lasx_xvld(xsecret + i, 0);
5872 __m256i
const data_key = __lasx_xvxor_v(data_vec, key_vec);
5875 xacc[i] = __lasx_xvmul_d(data_key, prime32);
5882#if (XXH_VECTOR == XXH_RVV)
5883 #define XXH_CONCAT2(X, Y) X ## Y
5884 #define XXH_CONCAT(X, Y) XXH_CONCAT2(X, Y)
5885#if ((defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 13) || \
5886 (defined(__clang__) && __clang_major__ < 16))
5887 #define XXH_RVOP(op) op
5888 #define XXH_RVCAST(op) XXH_CONCAT(vreinterpret_v_, op)
5890 #define XXH_RVOP(op) XXH_CONCAT(__riscv_, op)
5891 #define XXH_RVCAST(op) XXH_CONCAT(__riscv_vreinterpret_v_, op)
5893XXH_FORCE_INLINE
void
5894XXH3_accumulate_512_rvv(
void* XXH_RESTRICT acc,
5895 const void* XXH_RESTRICT input,
5896 const void* XXH_RESTRICT secret)
5898 XXH_ASSERT((((
size_t)acc) & 63) == 0);
5902 size_t vl = XXH_RVOP(vsetvl_e64m2)(8);
5904 uint64_t* xacc = (uint64_t*) acc;
5905 const uint64_t* xinput = (
const uint64_t*) input;
5906 const uint64_t* xsecret = (
const uint64_t*) secret;
5907 static const uint64_t swap_mask[16] = {1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14};
5908 vuint64m2_t xswap_mask = XXH_RVOP(vle64_v_u64m2)(swap_mask, vl);
5911 for (i = 0; i < XXH_STRIPE_LEN/8; i += vl) {
5913 vuint64m2_t data_vec = XXH_RVCAST(u8m2_u64m2)(XXH_RVOP(vle8_v_u8m2)((
const uint8_t*)(xinput + i), vl * 8));
5915 vuint64m2_t key_vec = XXH_RVCAST(u8m2_u64m2)(XXH_RVOP(vle8_v_u8m2)((
const uint8_t*)(xsecret + i), vl * 8));
5917 vuint64m2_t acc_vec = XXH_RVOP(vle64_v_u64m2)(xacc + i, vl);
5919 vuint64m2_t data_key = XXH_RVOP(vxor_vv_u64m2)(data_vec, key_vec, vl);
5921 vuint64m2_t data_key_hi = XXH_RVOP(vsrl_vx_u64m2)(data_key, 32, vl);
5923 vuint64m2_t data_key_lo = XXH_RVOP(vand_vx_u64m2)(data_key, 0xffffffff, vl);
5925 vuint64m2_t data_swap = XXH_RVOP(vrgather_vv_u64m2)(data_vec, xswap_mask, vl);
5927 acc_vec = XXH_RVOP(vmacc_vv_u64m2)(acc_vec, data_key_lo, data_key_hi, vl);
5929 acc_vec = XXH_RVOP(vadd_vv_u64m2)(acc_vec, data_swap, vl);
5931 XXH_RVOP(vse64_v_u64m2)(xacc + i, acc_vec, vl);
5936XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(rvv)
5938XXH_FORCE_INLINE
void
5939XXH3_scrambleAcc_rvv(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
5941 XXH_ASSERT((((
size_t)acc) & 15) == 0);
5943 size_t count = XXH_STRIPE_LEN/8;
5944 uint64_t* xacc = (uint64_t*)acc;
5945 const uint8_t* xsecret = (
const uint8_t *)secret;
5947 for (; count > 0; count -= vl, xacc += vl, xsecret += vl*8) {
5948 vl = XXH_RVOP(vsetvl_e64m2)(count);
5951 vuint64m2_t key_vec = XXH_RVCAST(u8m2_u64m2)(XXH_RVOP(vle8_v_u8m2)(xsecret, vl*8));
5953 vuint64m2_t acc_vec = XXH_RVOP(vle64_v_u64m2)(xacc, vl);
5955 vuint64m2_t vsrl = XXH_RVOP(vsrl_vx_u64m2)(acc_vec, 47, vl);
5956 acc_vec = XXH_RVOP(vxor_vv_u64m2)(acc_vec, vsrl, vl);
5958 acc_vec = XXH_RVOP(vxor_vv_u64m2)(acc_vec, key_vec, vl);
5960 acc_vec = XXH_RVOP(vmul_vx_u64m2)(acc_vec,
XXH_PRIME32_1, vl);
5962 XXH_RVOP(vse64_v_u64m2)(xacc, acc_vec, vl);
5968XXH_FORCE_INLINE
void
5969XXH3_initCustomSecret_rvv(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
5971 XXH_STATIC_ASSERT(XXH_SEC_ALIGN >= 8);
5972 XXH_ASSERT(((
size_t)customSecret & 7) == 0);
5973 (void)(&XXH_writeLE64);
5975 size_t count = XXH_SECRET_DEFAULT_SIZE/8;
5977 size_t VLMAX = XXH_RVOP(vsetvlmax_e64m2)();
5978 int64_t* cSecret = (int64_t*)customSecret;
5979 const int64_t* kSecret = (
const int64_t*)(
const void*)XXH3_kSecret;
5981#if __riscv_v_intrinsic >= 1000000
5983 vbool32_t mneg = XXH_RVCAST(u8m1_b32)(
5984 XXH_RVOP(vmv_v_x_u8m1)(0xaa, XXH_RVOP(vsetvlmax_e8m1)()));
5987 size_t vlmax = XXH_RVOP(vsetvlmax_e8m1)();
5988 vbool32_t mneg = XXH_RVOP(vmseq_vx_u8mf4_b32)(
5989 XXH_RVOP(vand_vx_u8mf4)(
5990 XXH_RVOP(vid_v_u8mf4)(vlmax), 1, vlmax), 1, vlmax);
5992 vint64m2_t seed = XXH_RVOP(vmv_v_x_i64m2)((int64_t)seed64, VLMAX);
5993 seed = XXH_RVOP(vneg_v_i64m2_mu)(mneg, seed, seed, VLMAX);
5995 for (; count > 0; count -= vl, cSecret += vl, kSecret += vl) {
5997 vl = XXH_RVOP(vsetvl_e64m2)(count < VLMAX ? count : VLMAX);
5999 vint64m2_t src = XXH_RVOP(vle64_v_i64m2)(kSecret, vl);
6000 vint64m2_t res = XXH_RVOP(vadd_vv_i64m2)(src, seed, vl);
6001 XXH_RVOP(vse64_v_i64m2)(cSecret, res, vl);
6011#if defined(__aarch64__) && (defined(__GNUC__) || defined(__clang__))
6026XXH_FORCE_INLINE xxh_u64
6027XXH_mult32to64_add64(xxh_u64 lhs, xxh_u64 rhs, xxh_u64 acc)
6031 __asm__(
"umaddl %x0, %w1, %w2, %x3" :
"=r" (ret) :
"r" (lhs),
"r" (rhs),
"r" (acc));
6035XXH_FORCE_INLINE xxh_u64
6036XXH_mult32to64_add64(xxh_u64 lhs, xxh_u64 rhs, xxh_u64 acc)
6038 return XXH_mult32to64((xxh_u32)lhs, (xxh_u32)rhs) + acc;
6049XXH_FORCE_INLINE
void
6050XXH3_scalarRound(
void* XXH_RESTRICT acc,
6051 void const* XXH_RESTRICT input,
6052 void const* XXH_RESTRICT secret,
6055 xxh_u64* xacc = (xxh_u64*) acc;
6056 xxh_u8
const* xinput = (xxh_u8
const*) input;
6057 xxh_u8
const* xsecret = (xxh_u8
const*) secret;
6058 XXH_ASSERT(lane < XXH_ACC_NB);
6061 xxh_u64
const data_val = XXH_readLE64(xinput + lane * 8);
6062 xxh_u64
const data_key = data_val ^ XXH_readLE64(xsecret + lane * 8);
6063 xacc[lane ^ 1] += data_val;
6064 xacc[lane] = XXH_mult32to64_add64(data_key , data_key >> 32, xacc[lane]);
6072XXH_FORCE_INLINE
void
6073XXH3_accumulate_512_scalar(
void* XXH_RESTRICT acc,
6074 const void* XXH_RESTRICT input,
6075 const void* XXH_RESTRICT secret)
6079#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 8 \
6080 && (defined(__arm__) || defined(__thumb2__)) \
6081 && defined(__ARM_FEATURE_UNALIGNED) \
6082 && XXH_SIZE_OPT <= 0
6083# pragma GCC unroll 8
6085 for (i=0; i < XXH_ACC_NB; i++) {
6086 XXH3_scalarRound(acc, input, secret, i);
6089XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(scalar)
6098XXH_FORCE_INLINE
void
6099XXH3_scalarScrambleRound(
void* XXH_RESTRICT acc,
6100 void const* XXH_RESTRICT secret,
6103 xxh_u64*
const xacc = (xxh_u64*) acc;
6104 const xxh_u8*
const xsecret = (
const xxh_u8*) secret;
6106 XXH_ASSERT(lane < XXH_ACC_NB);
6108 xxh_u64
const key64 = XXH_readLE64(xsecret + lane * 8);
6109 xxh_u64 acc64 = xacc[lane];
6110 acc64 = XXH_xorshift64(acc64, 47);
6121XXH_FORCE_INLINE
void
6122XXH3_scrambleAcc_scalar(
void* XXH_RESTRICT acc,
const void* XXH_RESTRICT secret)
6125 for (i=0; i < XXH_ACC_NB; i++) {
6126 XXH3_scalarScrambleRound(acc, secret, i);
6130XXH_FORCE_INLINE
void
6131XXH3_initCustomSecret_scalar(
void* XXH_RESTRICT customSecret, xxh_u64 seed64)
6138 const xxh_u8* kSecretPtr = XXH3_kSecret;
6139 XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0);
6141#if defined(__GNUC__) && defined(__aarch64__)
6174 XXH_COMPILER_GUARD(kSecretPtr);
6176 {
int const nbRounds = XXH_SECRET_DEFAULT_SIZE / 16;
6178 for (i=0; i < nbRounds; i++) {
6185 xxh_u64 lo = XXH_readLE64(kSecretPtr + 16*i) + seed64;
6186 xxh_u64 hi = XXH_readLE64(kSecretPtr + 16*i + 8) - seed64;
6187 XXH_writeLE64((xxh_u8*)customSecret + 16*i, lo);
6188 XXH_writeLE64((xxh_u8*)customSecret + 16*i + 8, hi);
6193typedef void (*XXH3_f_accumulate)(xxh_u64* XXH_RESTRICT,
const xxh_u8* XXH_RESTRICT,
const xxh_u8* XXH_RESTRICT, size_t);
6194typedef void (*XXH3_f_scrambleAcc)(
void* XXH_RESTRICT,
const void*);
6195typedef void (*XXH3_f_initCustomSecret)(
void* XXH_RESTRICT, xxh_u64);
6198#if (XXH_VECTOR == XXH_AVX512)
6200#define XXH3_accumulate_512 XXH3_accumulate_512_avx512
6201#define XXH3_accumulate XXH3_accumulate_avx512
6202#define XXH3_scrambleAcc XXH3_scrambleAcc_avx512
6203#define XXH3_initCustomSecret XXH3_initCustomSecret_avx512
6205#elif (XXH_VECTOR == XXH_AVX2)
6207#define XXH3_accumulate_512 XXH3_accumulate_512_avx2
6208#define XXH3_accumulate XXH3_accumulate_avx2
6209#define XXH3_scrambleAcc XXH3_scrambleAcc_avx2
6210#define XXH3_initCustomSecret XXH3_initCustomSecret_avx2
6212#elif (XXH_VECTOR == XXH_SSE2)
6214#define XXH3_accumulate_512 XXH3_accumulate_512_sse2
6215#define XXH3_accumulate XXH3_accumulate_sse2
6216#define XXH3_scrambleAcc XXH3_scrambleAcc_sse2
6217#define XXH3_initCustomSecret XXH3_initCustomSecret_sse2
6219#elif (XXH_VECTOR == XXH_NEON)
6221#define XXH3_accumulate_512 XXH3_accumulate_512_neon
6222#define XXH3_accumulate XXH3_accumulate_neon
6223#define XXH3_scrambleAcc XXH3_scrambleAcc_neon
6224#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6226#elif (XXH_VECTOR == XXH_VSX)
6228#define XXH3_accumulate_512 XXH3_accumulate_512_vsx
6229#define XXH3_accumulate XXH3_accumulate_vsx
6230#define XXH3_scrambleAcc XXH3_scrambleAcc_vsx
6231#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6233#elif (XXH_VECTOR == XXH_SVE)
6234#define XXH3_accumulate_512 XXH3_accumulate_512_sve
6235#define XXH3_accumulate XXH3_accumulate_sve
6236#define XXH3_scrambleAcc XXH3_scrambleAcc_scalar
6237#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6239#elif (XXH_VECTOR == XXH_LASX)
6240#define XXH3_accumulate_512 XXH3_accumulate_512_lasx
6241#define XXH3_accumulate XXH3_accumulate_lasx
6242#define XXH3_scrambleAcc XXH3_scrambleAcc_lasx
6243#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6245#elif (XXH_VECTOR == XXH_LSX)
6246#define XXH3_accumulate_512 XXH3_accumulate_512_lsx
6247#define XXH3_accumulate XXH3_accumulate_lsx
6248#define XXH3_scrambleAcc XXH3_scrambleAcc_lsx
6249#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6251#elif (XXH_VECTOR == XXH_RVV)
6252#define XXH3_accumulate_512 XXH3_accumulate_512_rvv
6253#define XXH3_accumulate XXH3_accumulate_rvv
6254#define XXH3_scrambleAcc XXH3_scrambleAcc_rvv
6255#define XXH3_initCustomSecret XXH3_initCustomSecret_rvv
6259#define XXH3_accumulate_512 XXH3_accumulate_512_scalar
6260#define XXH3_accumulate XXH3_accumulate_scalar
6261#define XXH3_scrambleAcc XXH3_scrambleAcc_scalar
6262#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6266#if XXH_SIZE_OPT >= 1
6267# undef XXH3_initCustomSecret
6268# define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
6271XXH_FORCE_INLINE
void
6272XXH3_hashLong_internal_loop(xxh_u64* XXH_RESTRICT acc,
6273 const xxh_u8* XXH_RESTRICT input,
size_t len,
6274 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
6275 XXH3_f_accumulate f_acc,
6276 XXH3_f_scrambleAcc f_scramble)
6278 size_t const nbStripesPerBlock = (secretSize - XXH_STRIPE_LEN) / XXH_SECRET_CONSUME_RATE;
6279 size_t const block_len = XXH_STRIPE_LEN * nbStripesPerBlock;
6280 size_t const nb_blocks = (len - 1) / block_len;
6286 for (n = 0; n < nb_blocks; n++) {
6287 f_acc(acc, input + n*block_len, secret, nbStripesPerBlock);
6288 f_scramble(acc, secret + secretSize - XXH_STRIPE_LEN);
6292 XXH_ASSERT(len > XXH_STRIPE_LEN);
6293 {
size_t const nbStripes = ((len - 1) - (block_len * nb_blocks)) / XXH_STRIPE_LEN;
6294 XXH_ASSERT(nbStripes <= (secretSize / XXH_SECRET_CONSUME_RATE));
6295 f_acc(acc, input + nb_blocks*block_len, secret, nbStripes);
6298 {
const xxh_u8*
const p = input + len - XXH_STRIPE_LEN;
6299#define XXH_SECRET_LASTACC_START 7
6300 XXH3_accumulate_512(acc, p, secret + secretSize - XXH_STRIPE_LEN - XXH_SECRET_LASTACC_START);
6304XXH_FORCE_INLINE xxh_u64
6305XXH3_mix2Accs(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret)
6307 return XXH3_mul128_fold64(
6308 acc[0] ^ XXH_readLE64(secret),
6309 acc[1] ^ XXH_readLE64(secret+8) );
6313XXH3_mergeAccs(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret, xxh_u64 start)
6315 xxh_u64 result64 = start;
6318 for (i = 0; i < 4; i++) {
6319 result64 += XXH3_mix2Accs(acc+2*i, secret + 16*i);
6320#if defined(__clang__) \
6321 && (defined(__arm__) || defined(__thumb__)) \
6322 && (defined(__ARM_NEON) || defined(__ARM_NEON__)) \
6323 && !defined(XXH_ENABLE_AUTOVECTORIZE)
6332 XXH_COMPILER_GUARD(result64);
6336 return XXH3_avalanche(result64);
6340#define XXH_SECRET_MERGEACCS_START 11
6343XXH3_finalizeLong_64b(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret, xxh_u64 len)
6345 return XXH3_mergeAccs(acc, secret + XXH_SECRET_MERGEACCS_START, len *
XXH_PRIME64_1);
6348#define XXH3_INIT_ACC { XXH_PRIME32_3, XXH_PRIME64_1, XXH_PRIME64_2, XXH_PRIME64_3, \
6349 XXH_PRIME64_4, XXH_PRIME32_2, XXH_PRIME64_5, XXH_PRIME32_1 }
6352XXH3_hashLong_64b_internal(
const void* XXH_RESTRICT input,
size_t len,
6353 const void* XXH_RESTRICT secret,
size_t secretSize,
6354 XXH3_f_accumulate f_acc,
6355 XXH3_f_scrambleAcc f_scramble)
6357 XXH_ALIGN(
XXH_ACC_ALIGN) xxh_u64 acc[XXH_ACC_NB] = XXH3_INIT_ACC;
6359 XXH3_hashLong_internal_loop(acc, (
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretSize, f_acc, f_scramble);
6362 XXH_STATIC_ASSERT(
sizeof(acc) == 64);
6363 XXH_ASSERT(secretSize >=
sizeof(acc) + XXH_SECRET_MERGEACCS_START);
6364 return XXH3_finalizeLong_64b(acc, (
const xxh_u8*)secret, (xxh_u64)len);
6375XXH3_hashLong_64b_withSecret(
const void* XXH_RESTRICT input,
size_t len,
6376 XXH64_hash_t seed64,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
6379 return XXH3_hashLong_64b_internal(input, len, secret, secretLen, XXH3_accumulate, XXH3_scrambleAcc);
6389XXH3_hashLong_64b_default(
const void* XXH_RESTRICT input,
size_t len,
6390 XXH64_hash_t seed64,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
6392 (void)seed64; (void)secret; (void)secretLen;
6393 return XXH3_hashLong_64b_internal(input, len, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_accumulate, XXH3_scrambleAcc);
6408XXH3_hashLong_64b_withSeed_internal(
const void* input,
size_t len,
6410 XXH3_f_accumulate f_acc,
6411 XXH3_f_scrambleAcc f_scramble,
6412 XXH3_f_initCustomSecret f_initSec)
6414#if XXH_SIZE_OPT <= 0
6416 return XXH3_hashLong_64b_internal(input, len,
6417 XXH3_kSecret,
sizeof(XXH3_kSecret),
6420 { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
6421 f_initSec(secret, seed);
6422 return XXH3_hashLong_64b_internal(input, len, secret,
sizeof(secret),
6431XXH3_hashLong_64b_withSeed(
const void* XXH_RESTRICT input,
size_t len,
6432 XXH64_hash_t seed,
const xxh_u8* XXH_RESTRICT secret,
size_t secretLen)
6434 (void)secret; (void)secretLen;
6435 return XXH3_hashLong_64b_withSeed_internal(input, len, seed,
6436 XXH3_accumulate, XXH3_scrambleAcc, XXH3_initCustomSecret);
6440typedef XXH64_hash_t (*XXH3_hashLong64_f)(
const void* XXH_RESTRICT, size_t,
6444XXH3_64bits_internal(
const void* XXH_RESTRICT input,
size_t len,
6445 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen,
6446 XXH3_hashLong64_f f_hashLong)
6457 return XXH3_len_0to16_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, seed64);
6459 return XXH3_len_17to128_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
6461 return XXH3_len_129to240_64b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
6462 return f_hashLong(input, len, seed64, (
const xxh_u8*)secret, secretLen);
6471 return XXH3_64bits_internal(input, length, 0, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_hashLong_64b_default);
6478 return XXH3_64bits_internal(input, length, 0, secret, secretSize, XXH3_hashLong_64b_withSecret);
6485 return XXH3_64bits_internal(input, length, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), XXH3_hashLong_64b_withSeed);
6492 return XXH3_64bits_internal(input, length, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), NULL);
6493 return XXH3_hashLong_64b_withSecret(input, length, seed, (
const xxh_u8*)secret, secretSize);
6498#ifndef XXH_NO_STREAM
6522static XXH_MALLOCF
void* XXH_alignedMalloc(
size_t s,
size_t align)
6524 XXH_ASSERT(align <= 128 && align >= 8);
6525 XXH_ASSERT((align & (align-1)) == 0);
6526 XXH_ASSERT(s != 0 && s < (s + align));
6528 xxh_u8* base = (xxh_u8*)XXH_malloc(s + align);
6536 size_t offset = align - ((size_t)base & (align - 1));
6538 xxh_u8* ptr = base + offset;
6540 XXH_ASSERT((
size_t)ptr % align == 0);
6543 ptr[-1] = (xxh_u8)offset;
6553static void XXH_alignedFree(
void* p)
6556 xxh_u8* ptr = (xxh_u8*)p;
6558 xxh_u8 offset = ptr[-1];
6560 xxh_u8* base = ptr - offset;
6578 if (state==NULL)
return NULL;
6597 XXH_alignedFree(statePtr);
6605 XXH_memcpy(dst_state, src_state,
sizeof(*dst_state));
6611 const void* secret,
size_t secretSize)
6613 size_t const initStart = offsetof(
XXH3_state_t, bufferedSize);
6614 size_t const initLength = offsetof(
XXH3_state_t, nbStripesPerBlock) - initStart;
6615 XXH_ASSERT(offsetof(
XXH3_state_t, nbStripesPerBlock) > initStart);
6616 XXH_ASSERT(statePtr != NULL);
6618 XXH_memset((
char*)statePtr + initStart, 0, initLength);
6627 statePtr->
seed = seed;
6628 statePtr->
useSeed = (seed != 0);
6629 statePtr->
extSecret = (
const unsigned char*)secret;
6631 statePtr->
secretLimit = secretSize - XXH_STRIPE_LEN;
6640 XXH3_reset_internal(statePtr, 0, XXH3_kSecret, XXH_SECRET_DEFAULT_SIZE);
6649 XXH3_reset_internal(statePtr, 0, secret, secretSize);
6661 if ((seed != statePtr->seed) || (statePtr->extSecret != NULL))
6662 XXH3_initCustomSecret(statePtr->customSecret, seed);
6663 XXH3_reset_internal(statePtr, seed, NULL, XXH_SECRET_DEFAULT_SIZE);
6674 XXH3_reset_internal(statePtr, seed64, secret, secretSize);
6675 statePtr->useSeed = 1;
6696XXH_FORCE_INLINE
const xxh_u8 *
6697XXH3_consumeStripes(xxh_u64* XXH_RESTRICT acc,
6698 size_t* XXH_RESTRICT nbStripesSoFarPtr,
size_t nbStripesPerBlock,
6699 const xxh_u8* XXH_RESTRICT input,
size_t nbStripes,
6700 const xxh_u8* XXH_RESTRICT secret,
size_t secretLimit,
6701 XXH3_f_accumulate f_acc,
6702 XXH3_f_scrambleAcc f_scramble)
6704 const xxh_u8* initialSecret = secret + *nbStripesSoFarPtr * XXH_SECRET_CONSUME_RATE;
6706 if (nbStripes >= (nbStripesPerBlock - *nbStripesSoFarPtr)) {
6708 size_t nbStripesThisIter = nbStripesPerBlock - *nbStripesSoFarPtr;
6712 f_acc(acc, input, initialSecret, nbStripesThisIter);
6713 f_scramble(acc, secret + secretLimit);
6714 input += nbStripesThisIter * XXH_STRIPE_LEN;
6715 nbStripes -= nbStripesThisIter;
6717 nbStripesThisIter = nbStripesPerBlock;
6718 initialSecret = secret;
6719 }
while (nbStripes >= nbStripesPerBlock);
6720 *nbStripesSoFarPtr = 0;
6723 if (nbStripes > 0) {
6724 f_acc(acc, input, initialSecret, nbStripes);
6725 input += nbStripes * XXH_STRIPE_LEN;
6726 *nbStripesSoFarPtr += nbStripes;
6732#ifndef XXH3_STREAM_USE_STACK
6733# if XXH_SIZE_OPT <= 0 && !defined(__clang__)
6734# define XXH3_STREAM_USE_STACK 1
6743 const xxh_u8* XXH_RESTRICT input,
size_t len,
6744 XXH3_f_accumulate f_acc,
6745 XXH3_f_scrambleAcc f_scramble)
6748 XXH_ASSERT(len == 0);
6752 XXH_ASSERT(state != NULL);
6753 state->totalLen += len;
6756 XXH_ASSERT(state->bufferedSize <= XXH3_INTERNALBUFFER_SIZE);
6757 if (len <= XXH3_INTERNALBUFFER_SIZE - state->bufferedSize) {
6758 XXH_memcpy(state->buffer + state->bufferedSize, input, len);
6763 {
const xxh_u8*
const bEnd = input + len;
6764 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
6765#if defined(XXH3_STREAM_USE_STACK) && XXH3_STREAM_USE_STACK >= 1
6771 XXH_memcpy(acc, state->acc,
sizeof(acc));
6773 xxh_u64* XXH_RESTRICT
const acc = state->acc;
6777 #define XXH3_INTERNALBUFFER_STRIPES (XXH3_INTERNALBUFFER_SIZE / XXH_STRIPE_LEN)
6778 XXH_STATIC_ASSERT(XXH3_INTERNALBUFFER_SIZE % XXH_STRIPE_LEN == 0);
6784 if (state->bufferedSize) {
6785 size_t const loadSize = XXH3_INTERNALBUFFER_SIZE - state->bufferedSize;
6786 XXH_memcpy(state->buffer + state->bufferedSize, input, loadSize);
6788 XXH3_consumeStripes(acc,
6789 &state->nbStripesSoFar, state->nbStripesPerBlock,
6790 state->buffer, XXH3_INTERNALBUFFER_STRIPES,
6791 secret, state->secretLimit,
6793 state->bufferedSize = 0;
6795 XXH_ASSERT(input < bEnd);
6796 if (bEnd - input > XXH3_INTERNALBUFFER_SIZE) {
6797 size_t nbStripes = (size_t)(bEnd - 1 - input) / XXH_STRIPE_LEN;
6798 input = XXH3_consumeStripes(acc,
6799 &state->nbStripesSoFar, state->nbStripesPerBlock,
6801 secret, state->secretLimit,
6803 XXH_memcpy(state->buffer +
sizeof(state->buffer) - XXH_STRIPE_LEN, input - XXH_STRIPE_LEN, XXH_STRIPE_LEN);
6807 XXH_ASSERT(input < bEnd);
6808 XXH_ASSERT(bEnd - input <= XXH3_INTERNALBUFFER_SIZE);
6809 XXH_ASSERT(state->bufferedSize == 0);
6810 XXH_memcpy(state->buffer, input, (
size_t)(bEnd-input));
6812#if defined(XXH3_STREAM_USE_STACK) && XXH3_STREAM_USE_STACK >= 1
6814 XXH_memcpy(state->acc, acc,
sizeof(acc));
6825XXH3_update_regular(XXH_NOESCAPE
XXH3_state_t* state, XXH_NOESCAPE
const void* input,
size_t len)
6827 return XXH3_update(state, (
const xxh_u8*)input, len,
6828 XXH3_accumulate, XXH3_scrambleAcc);
6835 return XXH3_update_regular(state, input, len);
6839XXH_FORCE_INLINE
void
6842 const unsigned char* secret)
6844 xxh_u8 lastStripe[XXH_STRIPE_LEN];
6845 const xxh_u8* lastStripePtr;
6851 XXH_memcpy(acc, state->
acc,
sizeof(state->
acc));
6854 size_t const nbStripes = (state->
bufferedSize - 1) / XXH_STRIPE_LEN;
6856 XXH3_consumeStripes(acc,
6858 state->
buffer, nbStripes,
6860 XXH3_accumulate, XXH3_scrambleAcc);
6864 size_t const catchupSize = XXH_STRIPE_LEN - state->
bufferedSize;
6866 XXH_memcpy(lastStripe, state->
buffer +
sizeof(state->
buffer) - catchupSize, catchupSize);
6868 lastStripePtr = lastStripe;
6871 XXH3_accumulate_512(acc,
6873 secret + state->
secretLimit - XXH_SECRET_LASTACC_START);
6879 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
6882 XXH3_digest_long(acc, state, secret);
6883 return XXH3_finalizeLong_64b(acc, secret, (xxh_u64)state->totalLen);
6889 secret, state->secretLimit + XXH_STRIPE_LEN);
6914XXH3_len_1to3_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
6917 XXH_ASSERT(input != NULL);
6918 XXH_ASSERT(1 <= len && len <= 3);
6919 XXH_ASSERT(secret != NULL);
6925 { xxh_u8
const c1 = input[0];
6926 xxh_u8
const c2 = input[len >> 1];
6927 xxh_u8
const c3 = input[len - 1];
6928 xxh_u32
const combinedl = ((xxh_u32)c1 <<16) | ((xxh_u32)c2 << 24)
6929 | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8);
6930 xxh_u32
const combinedh = XXH_rotl32(XXH_swap32(combinedl), 13);
6931 xxh_u64
const bitflipl = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed;
6932 xxh_u64
const bitfliph = (XXH_readLE32(secret+8) ^ XXH_readLE32(secret+12)) - seed;
6933 xxh_u64
const keyed_lo = (xxh_u64)combinedl ^ bitflipl;
6934 xxh_u64
const keyed_hi = (xxh_u64)combinedh ^ bitfliph;
6936 h128.
low64 = XXH64_avalanche(keyed_lo);
6937 h128.
high64 = XXH64_avalanche(keyed_hi);
6943XXH3_len_4to8_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
6945 XXH_ASSERT(input != NULL);
6946 XXH_ASSERT(secret != NULL);
6947 XXH_ASSERT(4 <= len && len <= 8);
6948 seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32;
6949 { xxh_u32
const input_lo = XXH_readLE32(input);
6950 xxh_u32
const input_hi = XXH_readLE32(input + len - 4);
6951 xxh_u64
const input_64 = input_lo + ((xxh_u64)input_hi << 32);
6952 xxh_u64
const bitflip = (XXH_readLE64(secret+16) ^ XXH_readLE64(secret+24)) + seed;
6953 xxh_u64
const keyed = input_64 ^ bitflip;
6962 m128.
low64 *= PRIME_MX2;
6970XXH3_len_9to16_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
6972 XXH_ASSERT(input != NULL);
6973 XXH_ASSERT(secret != NULL);
6974 XXH_ASSERT(9 <= len && len <= 16);
6975 { xxh_u64
const bitflipl = (XXH_readLE64(secret+32) ^ XXH_readLE64(secret+40)) - seed;
6976 xxh_u64
const bitfliph = (XXH_readLE64(secret+48) ^ XXH_readLE64(secret+56)) + seed;
6977 xxh_u64
const input_lo = XXH_readLE64(input);
6978 xxh_u64 input_hi = XXH_readLE64(input + len - 8);
6984 m128.
low64 += (xxh_u64)(len - 1) << 54;
6985 input_hi ^= bitfliph;
6993 if (
sizeof(
void *) <
sizeof(xxh_u64)) {
7000 m128.
high64 += (input_hi & 0xFFFFFFFF00000000ULL) + XXH_mult32to64((xxh_u32)input_hi,
XXH_PRIME32_2);
7045XXH3_len_0to16_128b(
const xxh_u8* input,
size_t len,
const xxh_u8* secret,
XXH64_hash_t seed)
7047 XXH_ASSERT(len <= 16);
7048 {
if (len > 8)
return XXH3_len_9to16_128b(input, len, secret, seed);
7049 if (len >= 4)
return XXH3_len_4to8_128b(input, len, secret, seed);
7050 if (len)
return XXH3_len_1to3_128b(input, len, secret, seed);
7052 xxh_u64
const bitflipl = XXH_readLE64(secret+64) ^ XXH_readLE64(secret+72);
7053 xxh_u64
const bitfliph = XXH_readLE64(secret+80) ^ XXH_readLE64(secret+88);
7054 h128.
low64 = XXH64_avalanche(seed ^ bitflipl);
7055 h128.
high64 = XXH64_avalanche( seed ^ bitfliph);
7064XXH128_mix32B(
XXH128_hash_t acc,
const xxh_u8* input_1,
const xxh_u8* input_2,
7067 acc.
low64 += XXH3_mix16B (input_1, secret+0, seed);
7068 acc.
low64 ^= XXH_readLE64(input_2) + XXH_readLE64(input_2 + 8);
7069 acc.
high64 += XXH3_mix16B (input_2, secret+16, seed);
7070 acc.
high64 ^= XXH_readLE64(input_1) + XXH_readLE64(input_1 + 8);
7076XXH3_len_17to128_128b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
7077 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
7081 XXH_ASSERT(16 < len && len <= 128);
7087#if XXH_SIZE_OPT >= 1
7090 unsigned int i = (
unsigned int)(len - 1) / 32;
7092 acc = XXH128_mix32B(acc, input+16*i, input+len-16*(i+1), secret+32*i, seed);
7099 acc = XXH128_mix32B(acc, input+48, input+len-64, secret+96, seed);
7101 acc = XXH128_mix32B(acc, input+32, input+len-48, secret+64, seed);
7103 acc = XXH128_mix32B(acc, input+16, input+len-32, secret+32, seed);
7105 acc = XXH128_mix32B(acc, input, input+len-16, secret, seed);
7120XXH3_len_129to240_128b(
const xxh_u8* XXH_RESTRICT input,
size_t len,
7121 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
7137 for (i = 32; i < 160; i += 32) {
7138 acc = XXH128_mix32B(acc,
7151 for (i=160; i <= len; i += 32) {
7152 acc = XXH128_mix32B(acc,
7155 secret + XXH3_MIDSIZE_STARTOFFSET + i - 160,
7159 acc = XXH128_mix32B(acc,
7178XXH3_finalizeLong_128b(
const xxh_u64* XXH_RESTRICT acc,
const xxh_u8* XXH_RESTRICT secret,
size_t secretSize, xxh_u64 len)
7181 h128.
low64 = XXH3_finalizeLong_64b(acc, secret, len);
7182 h128.
high64 = XXH3_mergeAccs(acc, secret + secretSize
7183 - XXH_STRIPE_LEN - XXH_SECRET_MERGEACCS_START,
7189XXH3_hashLong_128b_internal(
const void* XXH_RESTRICT input,
size_t len,
7190 const xxh_u8* XXH_RESTRICT secret,
size_t secretSize,
7191 XXH3_f_accumulate f_acc,
7192 XXH3_f_scrambleAcc f_scramble)
7194 XXH_ALIGN(
XXH_ACC_ALIGN) xxh_u64 acc[XXH_ACC_NB] = XXH3_INIT_ACC;
7196 XXH3_hashLong_internal_loop(acc, (
const xxh_u8*)input, len, secret, secretSize, f_acc, f_scramble);
7199 XXH_STATIC_ASSERT(
sizeof(acc) == 64);
7200 XXH_ASSERT(secretSize >=
sizeof(acc) + XXH_SECRET_MERGEACCS_START);
7201 return XXH3_finalizeLong_128b(acc, secret, secretSize, (xxh_u64)len);
7208XXH3_hashLong_128b_default(
const void* XXH_RESTRICT input,
size_t len,
7210 const void* XXH_RESTRICT secret,
size_t secretLen)
7212 (void)seed64; (void)secret; (void)secretLen;
7213 return XXH3_hashLong_128b_internal(input, len, XXH3_kSecret,
sizeof(XXH3_kSecret),
7214 XXH3_accumulate, XXH3_scrambleAcc);
7225XXH3_hashLong_128b_withSecret(
const void* XXH_RESTRICT input,
size_t len,
7227 const void* XXH_RESTRICT secret,
size_t secretLen)
7230 return XXH3_hashLong_128b_internal(input, len, (
const xxh_u8*)secret, secretLen,
7231 XXH3_accumulate, XXH3_scrambleAcc);
7235XXH3_hashLong_128b_withSeed_internal(
const void* XXH_RESTRICT input,
size_t len,
7237 XXH3_f_accumulate f_acc,
7238 XXH3_f_scrambleAcc f_scramble,
7239 XXH3_f_initCustomSecret f_initSec)
7242 return XXH3_hashLong_128b_internal(input, len,
7243 XXH3_kSecret,
sizeof(XXH3_kSecret),
7245 { XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
7246 f_initSec(secret, seed64);
7247 return XXH3_hashLong_128b_internal(input, len, (
const xxh_u8*)secret,
sizeof(secret),
7256XXH3_hashLong_128b_withSeed(
const void* input,
size_t len,
7257 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen)
7259 (void)secret; (void)secretLen;
7260 return XXH3_hashLong_128b_withSeed_internal(input, len, seed64,
7261 XXH3_accumulate, XXH3_scrambleAcc, XXH3_initCustomSecret);
7264typedef XXH128_hash_t (*XXH3_hashLong128_f)(
const void* XXH_RESTRICT, size_t,
7268XXH3_128bits_internal(
const void* input,
size_t len,
7269 XXH64_hash_t seed64,
const void* XXH_RESTRICT secret,
size_t secretLen,
7270 XXH3_hashLong128_f f_hl128)
7280 return XXH3_len_0to16_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, seed64);
7282 return XXH3_len_17to128_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
7284 return XXH3_len_129to240_128b((
const xxh_u8*)input, len, (
const xxh_u8*)secret, secretLen, seed64);
7285 return f_hl128(input, len, seed64, secret, secretLen);
7294 return XXH3_128bits_internal(input, len, 0,
7295 XXH3_kSecret,
sizeof(XXH3_kSecret),
7296 XXH3_hashLong_128b_default);
7303 return XXH3_128bits_internal(input, len, 0,
7304 (
const xxh_u8*)secret, secretSize,
7305 XXH3_hashLong_128b_withSecret);
7312 return XXH3_128bits_internal(input, len, seed,
7313 XXH3_kSecret,
sizeof(XXH3_kSecret),
7314 XXH3_hashLong_128b_withSeed);
7322 return XXH3_128bits_internal(input, len, seed, XXH3_kSecret,
sizeof(XXH3_kSecret), NULL);
7323 return XXH3_hashLong_128b_withSecret(input, len, seed, secret, secretSize);
7335#ifndef XXH_NO_STREAM
7373 return XXH3_update_regular(state, input, len);
7379 const unsigned char*
const secret = (state->extSecret == NULL) ? state->customSecret : state->extSecret;
7382 XXH3_digest_long(acc, state, secret);
7383 XXH_ASSERT(state->secretLimit + XXH_STRIPE_LEN >=
sizeof(acc) + XXH_SECRET_MERGEACCS_START);
7384 return XXH3_finalizeLong_128b(acc, secret, state->secretLimit + XXH_STRIPE_LEN, (xxh_u64)state->totalLen);
7390 secret, state->secretLimit + XXH_STRIPE_LEN);
7400 return !(XXH_memcmp(&h1, &h2,
sizeof(h1)));
7414 if (hcmp)
return hcmp;
7430 XXH_memcpy((
char*)dst +
sizeof(hash.
high64), &hash.
low64,
sizeof(hash.
low64));
7438 h.
high64 = XXH_readBE64(src);
7439 h.
low64 = XXH_readBE64(src->digest + 8);
7449#define XXH_MIN(x, y) (((x) > (y)) ? (y) : (x))
7451XXH_FORCE_INLINE
void XXH3_combine16(
void* dst,
XXH128_hash_t h128)
7453 XXH_writeLE64( dst, XXH_readLE64(dst) ^ h128.
low64 );
7454 XXH_writeLE64( (
char*)dst+8, XXH_readLE64((
char*)dst+8) ^ h128.
high64 );
7459XXH3_generateSecret(XXH_NOESCAPE
void* secretBuffer,
size_t secretSize, XXH_NOESCAPE
const void* customSeed,
size_t customSeedSize)
7461#if (XXH_DEBUGLEVEL >= 1)
7462 XXH_ASSERT(secretBuffer != NULL);
7466 if (secretBuffer == NULL)
return XXH_ERROR;
7470 if (customSeedSize == 0) {
7471 customSeed = XXH3_kSecret;
7472 customSeedSize = XXH_SECRET_DEFAULT_SIZE;
7474#if (XXH_DEBUGLEVEL >= 1)
7475 XXH_ASSERT(customSeed != NULL);
7477 if (customSeed == NULL)
return XXH_ERROR;
7482 while (pos < secretSize) {
7483 size_t const toCopy = XXH_MIN((secretSize - pos), customSeedSize);
7484 XXH_memcpy((
char*)secretBuffer + pos, customSeed, toCopy);
7488 {
size_t const nbSeg16 = secretSize / 16;
7492 for (n=0; n<nbSeg16; n++) {
7494 XXH3_combine16((
char*)secretBuffer + n*16, h128);
7506 XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
7507 XXH3_initCustomSecret(secret, seed);
7508 XXH_ASSERT(secretBuffer != NULL);
7509 XXH_memcpy(secretBuffer, secret, XXH_SECRET_DEFAULT_SIZE);
7515#if XXH_VECTOR == XXH_AVX2 \
7516 && defined(__GNUC__) && !defined(__clang__) \
7517 && defined(__OPTIMIZE__) && XXH_SIZE_OPT <= 0
7518# pragma GCC pop_options
XXH_errorcode XXH32_reset(XXH32_state_t *statePtr, XXH32_hash_t seed)
Resets an XXH32_state_t to begin a new hash.
Definition xxhash.h:3248
XXH32_hash_t XXH32(const void *input, size_t length, XXH32_hash_t seed)
Calculates the 32-bit hash of input using xxHash32.
Definition xxhash.h:3207
XXH_errorcode XXH32_update(XXH32_state_t *statePtr, const void *input, size_t length)
Consumes a block of input to an XXH32_state_t.
Definition xxhash.h:3259
XXH32_state_t * XXH32_createState(void)
Allocates an XXH32_state_t.
Definition xxhash.h:3230
XXH_errorcode XXH32_freeState(XXH32_state_t *statePtr)
Frees an XXH32_state_t.
Definition xxhash.h:3235
void XXH32_canonicalFromHash(XXH32_canonical_t *dst, XXH32_hash_t hash)
Converts an XXH32_hash_t to a big endian XXH32_canonical_t.
Definition xxhash.h:3324
XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t *src)
Converts an XXH32_canonical_t to a native XXH32_hash_t.
Definition xxhash.h:3331
XXH32_hash_t XXH32_digest(const XXH32_state_t *statePtr)
Returns the calculated hash value from an XXH32_state_t.
Definition xxhash.h:3305
void XXH32_copyState(XXH32_state_t *dst_state, const XXH32_state_t *src_state)
Copies one XXH32_state_t to another.
Definition xxhash.h:3242
#define XXH_PRIME32_2
Definition xxhash.h:2923
#define XXH_PRIME32_1
Definition xxhash.h:2922
#define XXH_PRIME32_5
Definition xxhash.h:2926
#define XXH_PRIME32_3
Definition xxhash.h:2924
XXH64_hash_t XXH3_64bits_digest(const XXH3_state_t *statePtr)
Returns the calculated XXH3 64-bit hash value from an XXH3_state_t.
Definition xxhash.h:6877
XXH_errorcode XXH3_128bits_update(XXH3_state_t *statePtr, const void *input, size_t length)
Consumes a block of input to an XXH3_state_t.
Definition xxhash.h:7371
void XXH3_generateSecret_fromSeed(void *secretBuffer, XXH64_hash_t seed)
Generate the same secret as the _withSeed() variants.
Definition xxhash.h:7504
void XXH128_canonicalFromHash(XXH128_canonical_t *dst, XXH128_hash_t hash)
Converts an XXH128_hash_t to a big endian XXH128_canonical_t.
Definition xxhash.h:7422
XXH64_hash_t XXH3_64bits_withSeed(const void *input, size_t length, XXH64_hash_t seed)
Calculates 64-bit seeded variant of XXH3 hash of input.
Definition xxhash.h:6483
int XXH128_cmp(const void *h128_1, const void *h128_2)
Compares two XXH128_hash_t.
Definition xxhash.h:7408
XXH128_hash_t XXH3_128bits_withSeed(const void *data, size_t len, XXH64_hash_t seed)
Calculates 128-bit seeded variant of XXH3 hash of data.
Definition xxhash.h:7310
XXH128_hash_t XXH128(const void *data, size_t len, XXH64_hash_t seed)
Calculates the 128-bit hash of data using XXH3.
Definition xxhash.h:7328
XXH_errorcode XXH3_generateSecret(void *secretBuffer, size_t secretSize, const void *customSeed, size_t customSeedSize)
Derive a high-entropy secret from any user-defined content, named customSeed.
Definition xxhash.h:7459
XXH_errorcode XXH3_64bits_reset_withSecretandSeed(XXH3_state_t *statePtr, const void *secret, size_t secretSize, XXH64_hash_t seed64)
Resets an XXH3_state_t with secret data to begin a new hash.
Definition xxhash.h:6669
XXH_errorcode XXH3_64bits_reset_withSeed(XXH3_state_t *statePtr, XXH64_hash_t seed)
Resets an XXH3_state_t with 64-bit seed to begin a new hash.
Definition xxhash.h:6657
XXH128_hash_t XXH3_128bits_digest(const XXH3_state_t *statePtr)
Returns the calculated XXH3 128-bit hash value from an XXH3_state_t.
Definition xxhash.h:7377
XXH_errorcode XXH3_64bits_reset_withSecret(XXH3_state_t *statePtr, const void *secret, size_t secretSize)
Resets an XXH3_state_t with secret data to begin a new hash.
Definition xxhash.h:6646
XXH3_state_t * XXH3_createState(void)
Allocate an XXH3_state_t.
Definition xxhash.h:6575
XXH_errorcode XXH3_128bits_reset_withSeed(XXH3_state_t *statePtr, XXH64_hash_t seed)
Resets an XXH3_state_t with 64-bit seed to begin a new hash.
Definition xxhash.h:7357
XXH128_hash_t XXH3_128bits(const void *data, size_t len)
Calculates 128-bit unseeded variant of XXH3 of data.
Definition xxhash.h:7292
XXH128_hash_t XXH3_128bits_withSecret(const void *data, size_t len, const void *secret, size_t secretSize)
Calculates 128-bit variant of XXH3 with a custom "secret".
Definition xxhash.h:7301
XXH_errorcode XXH3_128bits_reset_withSecretandSeed(XXH3_state_t *statePtr, const void *secret, size_t secretSize, XXH64_hash_t seed64)
Resets an XXH3_state_t with secret data to begin a new hash.
Definition xxhash.h:7364
XXH_errorcode XXH3_128bits_reset(XXH3_state_t *statePtr)
Resets an XXH3_state_t to begin a new hash.
Definition xxhash.h:7343
XXH128_hash_t XXH128_hashFromCanonical(const XXH128_canonical_t *src)
Converts an XXH128_canonical_t to a native XXH128_hash_t.
Definition xxhash.h:7435
void XXH3_copyState(XXH3_state_t *dst_state, const XXH3_state_t *src_state)
Copies one XXH3_state_t to another.
Definition xxhash.h:6603
XXH64_hash_t XXH3_64bits_withSecret(const void *data, size_t len, const void *secret, size_t secretSize)
Calculates 64-bit variant of XXH3 with a custom "secret".
Definition xxhash.h:6476
XXH64_hash_t XXH3_64bits(const void *input, size_t length)
Calculates 64-bit unseeded variant of XXH3 hash of input.
Definition xxhash.h:6469
XXH_errorcode XXH3_64bits_update(XXH3_state_t *statePtr, const void *input, size_t length)
Consumes a block of input to an XXH3_state_t.
Definition xxhash.h:6833
XXH128_hash_t XXH3_128bits_withSecretandSeed(const void *input, size_t length, const void *secret, size_t secretSize, XXH64_hash_t seed64)
Calculates 128-bit seeded variant of XXH3 hash of data.
Definition xxhash.h:7319
XXH_errorcode XXH3_64bits_reset(XXH3_state_t *statePtr)
Resets an XXH3_state_t to begin a new hash.
Definition xxhash.h:6637
int XXH128_isEqual(XXH128_hash_t h1, XXH128_hash_t h2)
Check equality of two XXH128_hash_t values.
Definition xxhash.h:7397
#define XXH3_SECRET_SIZE_MIN
Definition xxhash.h:1184
XXH_errorcode XXH3_freeState(XXH3_state_t *statePtr)
Frees an XXH3_state_t.
Definition xxhash.h:6595
XXH_errorcode XXH3_128bits_reset_withSecret(XXH3_state_t *statePtr, const void *secret, size_t secretSize)
Resets an XXH3_state_t with secret data to begin a new hash.
Definition xxhash.h:7350
XXH64_hash_t XXH3_64bits_withSecretandSeed(const void *data, size_t len, const void *secret, size_t secretSize, XXH64_hash_t seed)
Calculates 64/128-bit seeded variant of XXH3 hash of data.
Definition xxhash.h:6489
void XXH64_canonicalFromHash(XXH64_canonical_t *dst, XXH64_hash_t hash)
Converts an XXH64_hash_t to a big endian XXH64_canonical_t.
Definition xxhash.h:3819
void XXH64_copyState(XXH64_state_t *dst_state, const XXH64_state_t *src_state)
Copies one XXH64_state_t to another.
Definition xxhash.h:3739
XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t *src)
Converts an XXH64_canonical_t to a native XXH64_hash_t.
Definition xxhash.h:3827
XXH64_hash_t XXH64(const void *input, size_t length, XXH64_hash_t seed)
Calculates the 64-bit hash of input using xxHash64.
Definition xxhash.h:3705
XXH_errorcode XXH64_freeState(XXH64_state_t *statePtr)
Frees an XXH64_state_t.
Definition xxhash.h:3732
XXH64_state_t * XXH64_createState(void)
Allocates an XXH64_state_t.
Definition xxhash.h:3727
XXH_errorcode XXH64_update(XXH64_state_t *statePtr, const void *input, size_t length)
Consumes a block of input to an XXH64_state_t.
Definition xxhash.h:3755
XXH64_hash_t XXH64_digest(const XXH64_state_t *statePtr)
Returns the calculated hash value from an XXH64_state_t.
Definition xxhash.h:3800
XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, XXH64_hash_t seed)
Resets an XXH64_state_t to begin a new hash.
Definition xxhash.h:3745
#define XXH_PRIME64_1
Definition xxhash.h:3481
#define XXH_PRIME64_2
Definition xxhash.h:3482
#define XXH_PRIME64_4
Definition xxhash.h:3484
#define XXH_PRIME64_3
Definition xxhash.h:3483
#define XXH_PRIME64_5
Definition xxhash.h:3485
#define XXH_TARGET_SSE2
Allows a function to be compiled with SSE2 intrinsics.
Definition xxhash.h:5244
#define XXH_TARGET_AVX512
Like XXH_TARGET_SSE2, but for AVX512.
Definition xxhash.h:5035
#define XXH_TARGET_AVX2
Like XXH_TARGET_SSE2, but for AVX2.
Definition xxhash.h:5138
XXH_alignment
Definition xxhash.h:2850
@ XXH_aligned
Definition xxhash.h:2851
@ XXH_unaligned
Definition xxhash.h:2852
uint32_t XXH32_hash_t
An unsigned 32-bit integer.
Definition xxhash.h:588
XXH_errorcode
Exit code for the streaming API.
Definition xxhash.h:573
uint64_t XXH64_hash_t
An unsigned 64-bit integer.
Definition xxhash.h:858
#define XXH_PUBLIC_API
Marks a global symbol.
Definition xxhash.h:458
unsigned XXH_versionNumber(void)
Obtains the xxHash version.
Definition xxhash.h:2907
#define XXH_VERSION_NUMBER
Version number, encoded as two digits each.
Definition xxhash.h:553
@ XXH_ERROR
Definition xxhash.h:575
@ XXH_OK
Definition xxhash.h:574
#define XXH_ACC_ALIGN
Selects the minimum alignment for XXH3's accumulators.
Definition xxhash.h:3997
#define XXH_CPU_LITTLE_ENDIAN
Whether the target is little endian.
Definition xxhash.h:2727
#define XXH3_NEON_LANES
Controls the NEON to scalar ratio for XXH3.
Definition xxhash.h:4240
#define XXH32_ENDJMP
Whether to use a jump for XXH32_finalize.
Definition xxhash.h:2268
#define XXH_FORCE_ALIGN_CHECK
If defined to non-zero, adds a special path for aligned inputs (XXH32() and XXH64() only).
Definition xxhash.h:2217
The return value from 128-bit hashes.
Definition xxhash.h:1375
XXH64_hash_t low64
Definition xxhash.h:1376
XXH64_hash_t high64
Definition xxhash.h:1377
Canonical (big endian) representation of XXH32_hash_t.
Definition xxhash.h:755
XXH32_hash_t bufferedSize
Definition xxhash.h:1670
XXH32_hash_t total_len_32
Definition xxhash.h:1666
XXH32_hash_t large_len
Definition xxhash.h:1667
XXH32_hash_t reserved
Definition xxhash.h:1671
XXH32_hash_t acc[4]
Definition xxhash.h:1668
unsigned char buffer[16]
Definition xxhash.h:1669
const unsigned char * extSecret
Definition xxhash.h:1788
XXH32_hash_t bufferedSize
Definition xxhash.h:1772
XXH64_hash_t reserved64
Definition xxhash.h:1786
XXH64_hash_t totalLen
Definition xxhash.h:1778
size_t nbStripesSoFar
Definition xxhash.h:1776
XXH32_hash_t useSeed
Definition xxhash.h:1774
size_t secretLimit
Definition xxhash.h:1782
size_t nbStripesPerBlock
Definition xxhash.h:1780
XXH64_hash_t seed
Definition xxhash.h:1784
unsigned char buffer[XXH3_INTERNALBUFFER_SIZE]
Definition xxhash.h:1770
unsigned char customSecret[XXH3_SECRET_DEFAULT_SIZE]
Definition xxhash.h:1768
XXH64_hash_t acc[8]
Definition xxhash.h:1766
Canonical (big endian) representation of XXH64_hash_t.
Definition xxhash.h:1020
unsigned char buffer[32]
Definition xxhash.h:1692
XXH32_hash_t reserved32
Definition xxhash.h:1694
XXH64_hash_t acc[4]
Definition xxhash.h:1691
XXH64_hash_t reserved64
Definition xxhash.h:1695
XXH32_hash_t bufferedSize
Definition xxhash.h:1693
XXH64_hash_t total_len
Definition xxhash.h:1690
#define XXH3_MIDSIZE_MAX
Maximum size of "short" key in bytes.
Definition xxhash.h:1940
#define XXH3_SECRET_DEFAULT_SIZE
Default Secret's size.
Definition xxhash.h:1741
#define XXH3_INITSTATE(XXH3_state_ptr)
Initializes a stack-allocated XXH3_state_s.
Definition xxhash.h:1807