summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2025-02-04 00:49:46 +0800
committerruki <[email protected]>2025-02-04 00:49:46 +0800
commit11b8a36ff31d29c4768c78005ef8231468b80904 (patch)
tree2926c58ed4690f6baa446ddc6e17b1cf02a52626 /core/src
parentc6cf8f109644f2dfb65e9dedd5629cd4a564db02 (diff)
update xxhash
Diffstat (limited to 'core/src')
-rwxr-xr-xcore/src/cli/xmake.sh1
-rw-r--r--core/src/xxhash/xxhash/xxhash.h792
2 files changed, 529 insertions, 264 deletions
diff --git a/core/src/cli/xmake.sh b/core/src/cli/xmake.sh
index 92825e26f..845e14163 100755
--- a/core/src/cli/xmake.sh
+++ b/core/src/cli/xmake.sh
@@ -30,7 +30,6 @@ target "cli"
add_installfiles "${projectdir}/(xmake/scripts/xpack/**)" "share"
add_installfiles "${projectdir}/(xmake/scripts/xrepo/**)" "share"
add_installfiles "${projectdir}/(xmake/scripts/virtualenvs/**)" "share"
- add_installfiles "${projectdir}/(xmake/scripts/pac/**)" "share"
add_installfiles "${projectdir}/(xmake/scripts/conan/**)" "share"
add_installfiles "${projectdir}/(xmake/scripts/module/**)" "share"
add_installfiles "${projectdir}/(xmake/templates/**)" "share"
diff --git a/core/src/xxhash/xxhash/xxhash.h b/core/src/xxhash/xxhash/xxhash.h
index ee1bcdffe..1ad2ddb61 100644
--- a/core/src/xxhash/xxhash/xxhash.h
+++ b/core/src/xxhash/xxhash/xxhash.h
@@ -241,7 +241,7 @@
* xxHash prototypes and implementation
*/
-#if defined (__cplusplus)
+#if defined(__cplusplus) && !defined(XXH_NO_EXTERNC_GUARD)
extern "C" {
#endif
@@ -333,7 +333,7 @@ extern "C" {
/* make all functions private */
# undef XXH_PUBLIC_API
# if defined(__GNUC__)
-# define XXH_PUBLIC_API static __inline __attribute__((unused))
+# define XXH_PUBLIC_API static __inline __attribute__((__unused__))
# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
# define XXH_PUBLIC_API static inline
# elif defined(_MSC_VER)
@@ -445,7 +445,7 @@ extern "C" {
/*! @brief Marks a global symbol. */
#if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API)
-# if defined(WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
+# if defined(_WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
# ifdef XXH_EXPORT
# define XXH_PUBLIC_API __declspec(dllexport)
# elif XXH_IMPORT
@@ -521,7 +521,7 @@ extern "C" {
/* specific declaration modes for Windows */
#if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API)
-# if defined(WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
+# if defined(_WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT))
# ifdef XXH_EXPORT
# define XXH_PUBLIC_API __declspec(dllexport)
# elif XXH_IMPORT
@@ -533,9 +533,9 @@ extern "C" {
#endif
#if defined (__GNUC__)
-# define XXH_CONSTF __attribute__((const))
-# define XXH_PUREF __attribute__((pure))
-# define XXH_MALLOCF __attribute__((malloc))
+# define XXH_CONSTF __attribute__((__const__))
+# define XXH_PUREF __attribute__((__pure__))
+# define XXH_MALLOCF __attribute__((__malloc__))
#else
# define XXH_CONSTF /* disable */
# define XXH_PUREF
@@ -547,7 +547,7 @@ extern "C" {
***************************************/
#define XXH_VERSION_MAJOR 0
#define XXH_VERSION_MINOR 8
-#define XXH_VERSION_RELEASE 2
+#define XXH_VERSION_RELEASE 3
/*! @brief Version number, encoded as two digits each */
#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
@@ -840,7 +840,7 @@ XXH_PUBLIC_API XXH_PUREF XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canoni
* As of writing this, only supported by clang.
*/
#if XXH_HAS_ATTRIBUTE(noescape)
-# define XXH_NOESCAPE __attribute__((noescape))
+# define XXH_NOESCAPE __attribute__((__noescape__))
#else
# define XXH_NOESCAPE
#endif
@@ -1110,6 +1110,24 @@ XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH64_hashFromCanonical(XXH_NOESCAPE const
*
* The API supports one-shot hashing, streaming mode, and custom secrets.
*/
+
+/*!
+ * @ingroup tuning
+ * @brief Possible values for @ref XXH_VECTOR.
+ *
+ * Unless set explicitly, determined automatically.
+ */
+# define XXH_SCALAR 0 /*!< Portable scalar version */
+# define XXH_SSE2 1 /*!< SSE2 for Pentium 4, Opteron, all x86_64. */
+# define XXH_AVX2 2 /*!< AVX2 for Haswell and Bulldozer */
+# define XXH_AVX512 3 /*!< AVX512 for Skylake and Icelake */
+# define XXH_NEON 4 /*!< NEON for most ARMv7-A, all AArch64, and WASM SIMD128 */
+# define XXH_VSX 5 /*!< VSX and ZVector for POWER8/z13 (64-bit) */
+# define XXH_SVE 6 /*!< SVE for some ARMv8-A and ARMv9-A */
+# define XXH_LSX 7 /*!< LSX (128-bit SIMD) for LoongArch64 */
+# define XXH_LASX 8 /*!< LASX (256-bit SIMD) for LoongArch64 */
+
+
/*-**********************************************************************
* XXH3 64-bit variant
************************************************************************/
@@ -1345,7 +1363,7 @@ XXH_PUBLIC_API XXH_errorcode XXH3_64bits_update (XXH_NOESCAPE XXH3_state_t* stat
*
* @see @ref streaming_example "Streaming Example"
*/
-XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH3_64bits_digest (XXH_NOESCAPE const XXH3_state_t* statePtr);
+XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH3_64bits_digest (XXH_NOESCAPE const XXH3_state_t* statePtr);
#endif /* !XXH_NO_STREAM */
/* note : canonical representation of XXH3 is the same as XXH64
@@ -1655,9 +1673,9 @@ XXH_PUBLIC_API XXH_PUREF XXH128_hash_t XXH128_hashFromCanonical(XXH_NOESCAPE con
struct XXH32_state_s {
XXH32_hash_t total_len_32; /*!< Total length hashed, modulo 2^32 */
XXH32_hash_t large_len; /*!< Whether the hash is >= 16 (handles @ref total_len_32 overflow) */
- XXH32_hash_t v[4]; /*!< Accumulator lanes */
- XXH32_hash_t mem32[4]; /*!< Internal buffer for partial reads. Treated as unsigned char[16]. */
- XXH32_hash_t memsize; /*!< Amount of data in @ref mem32 */
+ XXH32_hash_t acc[4]; /*!< Accumulator lanes */
+ unsigned char buffer[16]; /*!< Internal buffer for partial reads. */
+ XXH32_hash_t bufferedSize; /*!< Amount of data in @ref buffer */
XXH32_hash_t reserved; /*!< Reserved field. Do not read nor write to it. */
}; /* typedef'd to XXH32_state_t */
@@ -1678,9 +1696,9 @@ struct XXH32_state_s {
*/
struct XXH64_state_s {
XXH64_hash_t total_len; /*!< Total length hashed. This is always 64-bit. */
- XXH64_hash_t v[4]; /*!< Accumulator lanes */
- XXH64_hash_t mem64[4]; /*!< Internal buffer for partial reads. Treated as unsigned char[32]. */
- XXH32_hash_t memsize; /*!< Amount of data in @ref mem64 */
+ XXH64_hash_t acc[4]; /*!< Accumulator lanes */
+ unsigned char buffer[32]; /*!< Internal buffer for partial reads.. */
+ XXH32_hash_t bufferedSize; /*!< Amount of data in @ref buffer */
XXH32_hash_t reserved32; /*!< Reserved field, needed for padding anyways*/
XXH64_hash_t reserved64; /*!< Reserved field. Do not read or write to it. */
}; /* typedef'd to XXH64_state_t */
@@ -1688,8 +1706,7 @@ struct XXH64_state_s {
#ifndef XXH_NO_XXH3
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* >= C11 */
-# include <stdalign.h>
-# define XXH_ALIGN(n) alignas(n)
+# define XXH_ALIGN(n) _Alignas(n)
#elif defined(__cplusplus) && (__cplusplus >= 201103L) /* >= C++11 */
/* In C++ alignas() is a keyword */
# define XXH_ALIGN(n) alignas(n)
@@ -1711,6 +1728,7 @@ struct XXH64_state_s {
#endif
/*!
+ * @internal
* @brief The size of the internal XXH3 buffer.
*
* This is the optimal update size for incremental hashing.
@@ -1720,10 +1738,11 @@ struct XXH64_state_s {
#define XXH3_INTERNALBUFFER_SIZE 256
/*!
- * @internal
- * @brief Default size of the secret buffer (and @ref XXH3_kSecret).
+ * @def XXH3_SECRET_DEFAULT_SIZE
+ * @brief Default Secret's size
*
- * This is the size used in @ref XXH3_kSecret and the seeded functions.
+ * This is the size of internal XXH3_kSecret
+ * and is needed by XXH3_generateSecret_fromSeed().
*
* Not to be confused with @ref XXH3_SECRET_SIZE_MIN.
*/
@@ -1753,7 +1772,7 @@ struct XXH64_state_s {
*/
struct XXH3_state_s {
XXH_ALIGN_MEMBER(64, XXH64_hash_t acc[8]);
- /*!< The 8 accumulators. See @ref XXH32_state_s::v and @ref XXH64_state_s::v */
+ /*!< The 8 accumulators. See @ref XXH32_state_s::acc and @ref XXH64_state_s::acc */
XXH_ALIGN_MEMBER(64, unsigned char customSecret[XXH3_SECRET_DEFAULT_SIZE]);
/*!< Used to store a custom secret generated from a seed. */
XXH_ALIGN_MEMBER(64, unsigned char buffer[XXH3_INTERNALBUFFER_SIZE]);
@@ -1924,6 +1943,11 @@ XXH_PUBLIC_API XXH_errorcode XXH3_generateSecret(XXH_NOESCAPE void* secretBuffer
XXH_PUBLIC_API void XXH3_generateSecret_fromSeed(XXH_NOESCAPE void* secretBuffer, XXH64_hash_t seed);
/*!
+ * @brief Maximum size of "short" key in bytes.
+ */
+#define XXH3_MIDSIZE_MAX 240
+
+/*!
* @brief Calculates 64/128-bit seeded variant of XXH3 hash of @p data.
*
* @param data The block of data to be hashed, at least @p len bytes in size.
@@ -1932,9 +1956,9 @@ XXH_PUBLIC_API void XXH3_generateSecret_fromSeed(XXH_NOESCAPE void* secretBuffer
* @param secretSize The length of @p secret, in bytes.
* @param seed The 64-bit seed to alter the hash result predictably.
*
- * These variants generate hash values using either
- * @p seed for "short" keys (< @ref XXH3_MIDSIZE_MAX = 240 bytes)
- * or @p secret for "large" keys (>= @ref XXH3_MIDSIZE_MAX).
+ * These variants generate hash values using either:
+ * - @p seed for "short" keys (< @ref XXH3_MIDSIZE_MAX = 240 bytes)
+ * - @p secret for "large" keys (>= @ref XXH3_MIDSIZE_MAX).
*
* This generally benefits speed, compared to `_withSeed()` or `_withSecret()`.
* `_withSeed()` has to generate the secret on the fly for "large" keys.
@@ -1961,24 +1985,26 @@ XXH_PUBLIC_API XXH_PUREF XXH64_hash_t
XXH3_64bits_withSecretandSeed(XXH_NOESCAPE const void* data, size_t len,
XXH_NOESCAPE const void* secret, size_t secretSize,
XXH64_hash_t seed);
+
/*!
* @brief Calculates 128-bit seeded variant of XXH3 hash of @p data.
*
- * @param input The block of data to be hashed, at least @p len bytes in size.
+ * @param input The memory segment to be hashed, at least @p len bytes in size.
* @param length The length of @p data, in bytes.
- * @param secret The secret data.
- * @param secretSize The length of @p secret, in bytes.
+ * @param secret The secret used to alter hash result predictably.
+ * @param secretSize The length of @p secret, in bytes (must be >= XXH3_SECRET_SIZE_MIN)
* @param seed64 The 64-bit seed to alter the hash result predictably.
*
* @return @ref XXH_OK on success.
* @return @ref XXH_ERROR on failure.
*
- * @see XXH3_64bits_withSecretandSeed()
+ * @see XXH3_64bits_withSecretandSeed(): contract is the same.
*/
XXH_PUBLIC_API XXH_PUREF XXH128_hash_t
XXH3_128bits_withSecretandSeed(XXH_NOESCAPE const void* input, size_t length,
XXH_NOESCAPE const void* secret, size_t secretSize,
XXH64_hash_t seed64);
+
#ifndef XXH_NO_STREAM
/*!
* @brief Resets an @ref XXH3_state_t with secret data to begin a new hash.
@@ -1991,12 +2017,13 @@ XXH3_128bits_withSecretandSeed(XXH_NOESCAPE const void* input, size_t length,
* @return @ref XXH_OK on success.
* @return @ref XXH_ERROR on failure.
*
- * @see XXH3_64bits_withSecretandSeed()
+ * @see XXH3_64bits_withSecretandSeed(). Contract is identical.
*/
XXH_PUBLIC_API XXH_errorcode
XXH3_64bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t* statePtr,
XXH_NOESCAPE const void* secret, size_t secretSize,
XXH64_hash_t seed64);
+
/*!
* @brief Resets an @ref XXH3_state_t with secret data to begin a new hash.
*
@@ -2008,12 +2035,21 @@ XXH3_64bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t* statePtr,
* @return @ref XXH_OK on success.
* @return @ref XXH_ERROR on failure.
*
- * @see XXH3_64bits_withSecretandSeed()
+ * @see XXH3_64bits_withSecretandSeed(). Contract is identical.
+ *
+ * Note: there was a bug in an earlier version of this function (<= v0.8.2)
+ * that would make it generate an incorrect hash value
+ * when @p seed == 0 and @p length < XXH3_MIDSIZE_MAX
+ * and @p secret is different from XXH3_generateSecret_fromSeed().
+ * As stated in the contract, the correct hash result must be
+ * the same as XXH3_128bits_withSeed() when @p length <= XXH3_MIDSIZE_MAX.
+ * Results generated by this older version are wrong, hence not comparable.
*/
XXH_PUBLIC_API XXH_errorcode
XXH3_128bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t* statePtr,
XXH_NOESCAPE const void* secret, size_t secretSize,
XXH64_hash_t seed64);
+
#endif /* !XXH_NO_STREAM */
#endif /* !XXH_NO_XXH3 */
@@ -2358,16 +2394,35 @@ static void XXH_free(void* p) { free(p); }
#endif /* XXH_NO_STDLIB */
-#include <string.h>
+#ifndef XXH_memcpy
+/*!
+ * @internal
+ * @brief XXH_memcpy() macro can be redirected at compile time
+ */
+# include <string.h>
+# define XXH_memcpy memcpy
+#endif
+#ifndef XXH_memset
/*!
* @internal
- * @brief Modify this function to use a different routine than memcpy().
+ * @brief XXH_memset() macro can be redirected at compile time
*/
-static void* XXH_memcpy(void* dest, const void* src, size_t size)
-{
- return memcpy(dest,src,size);
-}
+# include <string.h>
+# define XXH_memset memset
+#endif
+
+#ifndef XXH_memcmp
+/*!
+ * @internal
+ * @brief XXH_memcmp() macro can be redirected at compile time
+ * Note: only needed by XXH128.
+ */
+# include <string.h>
+# define XXH_memcmp memcmp
+#endif
+
+
#include <limits.h> /* ULLONG_MAX */
@@ -2381,15 +2436,15 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size)
#if XXH_NO_INLINE_HINTS /* disable inlining hints */
# if defined(__GNUC__) || defined(__clang__)
-# define XXH_FORCE_INLINE static __attribute__((unused))
+# define XXH_FORCE_INLINE static __attribute__((__unused__))
# else
# define XXH_FORCE_INLINE static
# endif
# define XXH_NO_INLINE static
/* enable inlining hints */
#elif defined(__GNUC__) || defined(__clang__)
-# define XXH_FORCE_INLINE static __inline__ __attribute__((always_inline, unused))
-# define XXH_NO_INLINE static __attribute__((noinline))
+# define XXH_FORCE_INLINE static __inline__ __attribute__((__always_inline__, __unused__))
+# define XXH_NO_INLINE static __attribute__((__noinline__))
#elif defined(_MSC_VER) /* Visual Studio */
# define XXH_FORCE_INLINE static __forceinline
# define XXH_NO_INLINE static __declspec(noinline)
@@ -2402,12 +2457,34 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size)
# define XXH_NO_INLINE static
#endif
+#if defined(XXH_INLINE_ALL)
+# define XXH_STATIC XXH_FORCE_INLINE
+#else
+# define XXH_STATIC static
+#endif
+
#if XXH3_INLINE_SECRET
# define XXH3_WITH_SECRET_INLINE XXH_FORCE_INLINE
#else
# define XXH3_WITH_SECRET_INLINE XXH_NO_INLINE
#endif
+#if ((defined(sun) || defined(__sun)) && __cplusplus) /* Solaris includes __STDC_VERSION__ with C++. Tested with GCC 5.5 */
+# define XXH_RESTRICT /* disable */
+#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* >= C99 */
+# define XXH_RESTRICT restrict
+#elif (defined (__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) \
+ || (defined (__clang__)) \
+ || (defined (_MSC_VER) && (_MSC_VER >= 1400)) \
+ || (defined (__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300))
+/*
+ * There are a LOT more compilers that recognize __restrict but this
+ * covers the major ones.
+ */
+# define XXH_RESTRICT __restrict
+#else
+# define XXH_RESTRICT /* disable */
+#endif
/* *************************************
* Debug
@@ -2580,11 +2657,11 @@ static xxh_u32 XXH_read32(const void* memPtr) { return *(const xxh_u32*) memPtr;
* https://gcc.godbolt.org/z/xYez1j67Y.
*/
#ifdef XXH_OLD_NAMES
-typedef union { xxh_u32 u32; } __attribute__((packed)) unalign;
+typedef union { xxh_u32 u32; } __attribute__((__packed__)) unalign;
#endif
static xxh_u32 XXH_read32(const void* ptr)
{
- typedef __attribute__((aligned(1))) xxh_u32 xxh_unalign32;
+ typedef __attribute__((__aligned__(1))) xxh_u32 xxh_unalign32;
return *((const xxh_unalign32*)ptr);
}
@@ -2730,6 +2807,9 @@ static int XXH_isLittleEndian(void)
&& XXH_HAS_BUILTIN(__builtin_rotateleft64)
# define XXH_rotl32 __builtin_rotateleft32
# define XXH_rotl64 __builtin_rotateleft64
+#elif XXH_HAS_BUILTIN(__builtin_stdc_rotate_left)
+# define XXH_rotl32 __builtin_stdc_rotate_left
+# define XXH_rotl64 __builtin_stdc_rotate_left
/* Note: although _rotl exists for minGW (GCC under windows), performance seems poor */
#elif defined(_MSC_VER)
# define XXH_rotl32(x,r) _rotl(x,r)
@@ -2938,6 +3018,61 @@ static xxh_u32 XXH32_avalanche(xxh_u32 hash)
/*!
* @internal
+ * @brief Sets up the initial accumulator state for XXH32().
+ */
+XXH_FORCE_INLINE void
+XXH32_initAccs(xxh_u32 *acc, xxh_u32 seed)
+{
+ XXH_ASSERT(acc != NULL);
+ acc[0] = seed + XXH_PRIME32_1 + XXH_PRIME32_2;
+ acc[1] = seed + XXH_PRIME32_2;
+ acc[2] = seed + 0;
+ acc[3] = seed - XXH_PRIME32_1;
+}
+
+/*!
+ * @internal
+ * @brief Consumes a block of data for XXH32().
+ *
+ * @return the end input pointer.
+ */
+XXH_FORCE_INLINE const xxh_u8 *
+XXH32_consumeLong(
+ xxh_u32 *XXH_RESTRICT acc,
+ xxh_u8 const *XXH_RESTRICT input,
+ size_t len,
+ XXH_alignment align
+)
+{
+ const xxh_u8* const bEnd = input + len;
+ const xxh_u8* const limit = bEnd - 15;
+ XXH_ASSERT(acc != NULL);
+ XXH_ASSERT(input != NULL);
+ XXH_ASSERT(len >= 16);
+ do {
+ acc[0] = XXH32_round(acc[0], XXH_get32bits(input)); input += 4;
+ acc[1] = XXH32_round(acc[1], XXH_get32bits(input)); input += 4;
+ acc[2] = XXH32_round(acc[2], XXH_get32bits(input)); input += 4;
+ acc[3] = XXH32_round(acc[3], XXH_get32bits(input)); input += 4;
+ } while (input < limit);
+
+ return input;
+}
+
+/*!
+ * @internal
+ * @brief Merges the accumulator lanes together for XXH32()
+ */
+XXH_FORCE_INLINE XXH_PUREF xxh_u32
+XXH32_mergeAccs(const xxh_u32 *acc)
+{
+ XXH_ASSERT(acc != NULL);
+ return XXH_rotl32(acc[0], 1) + XXH_rotl32(acc[1], 7)
+ + XXH_rotl32(acc[2], 12) + XXH_rotl32(acc[3], 18);
+}
+
+/*!
+ * @internal
* @brief Processes the last 0-15 bytes of @p ptr.
*
* There may be up to 15 bytes remaining to consume from the input.
@@ -3048,22 +3183,12 @@ XXH32_endian_align(const xxh_u8* input, size_t len, xxh_u32 seed, XXH_alignment
if (input==NULL) XXH_ASSERT(len == 0);
if (len>=16) {
- const xxh_u8* const bEnd = input + len;
- const xxh_u8* const limit = bEnd - 15;
- xxh_u32 v1 = seed + XXH_PRIME32_1 + XXH_PRIME32_2;
- xxh_u32 v2 = seed + XXH_PRIME32_2;
- xxh_u32 v3 = seed + 0;
- xxh_u32 v4 = seed - XXH_PRIME32_1;
+ xxh_u32 acc[4];
+ XXH32_initAccs(acc, seed);
- do {
- v1 = XXH32_round(v1, XXH_get32bits(input)); input += 4;
- v2 = XXH32_round(v2, XXH_get32bits(input)); input += 4;
- v3 = XXH32_round(v3, XXH_get32bits(input)); input += 4;
- v4 = XXH32_round(v4, XXH_get32bits(input)); input += 4;
- } while (input < limit);
+ input = XXH32_consumeLong(acc, input, len, align);
- h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7)
- + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
+ h32 = XXH32_mergeAccs(acc);
} else {
h32 = seed + XXH_PRIME32_5;
}
@@ -3118,11 +3243,8 @@ XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* dstState, const XXH32_state_t
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, XXH32_hash_t seed)
{
XXH_ASSERT(statePtr != NULL);
- memset(statePtr, 0, sizeof(*statePtr));
- statePtr->v[0] = seed + XXH_PRIME32_1 + XXH_PRIME32_2;
- statePtr->v[1] = seed + XXH_PRIME32_2;
- statePtr->v[2] = seed + 0;
- statePtr->v[3] = seed - XXH_PRIME32_1;
+ XXH_memset(statePtr, 0, sizeof(*statePtr));
+ XXH32_initAccs(statePtr->acc, seed);
return XXH_OK;
}
@@ -3136,45 +3258,37 @@ XXH32_update(XXH32_state_t* state, const void* input, size_t len)
return XXH_OK;
}
- { const xxh_u8* p = (const xxh_u8*)input;
- const xxh_u8* const bEnd = p + len;
+ state->total_len_32 += (XXH32_hash_t)len;
+ state->large_len |= (XXH32_hash_t)((len>=16) | (state->total_len_32>=16));
- state->total_len_32 += (XXH32_hash_t)len;
- state->large_len |= (XXH32_hash_t)((len>=16) | (state->total_len_32>=16));
+ XXH_ASSERT(state->bufferedSize < sizeof(state->buffer));
+ if (len < sizeof(state->buffer) - state->bufferedSize) { /* fill in tmp buffer */
+ XXH_memcpy(state->buffer + state->bufferedSize, input, len);
+ state->bufferedSize += (XXH32_hash_t)len;
+ return XXH_OK;
+ }
- if (state->memsize + len < 16) { /* fill in tmp buffer */
- XXH_memcpy((xxh_u8*)(state->mem32) + state->memsize, input, len);
- state->memsize += (XXH32_hash_t)len;
- return XXH_OK;
- }
+ { const xxh_u8* xinput = (const xxh_u8*)input;
+ const xxh_u8* const bEnd = xinput + len;
- if (state->memsize) { /* some data left from previous update */
- XXH_memcpy((xxh_u8*)(state->mem32) + state->memsize, input, 16-state->memsize);
- { const xxh_u32* p32 = state->mem32;
- state->v[0] = XXH32_round(state->v[0], XXH_readLE32(p32)); p32++;
- state->v[1] = XXH32_round(state->v[1], XXH_readLE32(p32)); p32++;
- state->v[2] = XXH32_round(state->v[2], XXH_readLE32(p32)); p32++;
- state->v[3] = XXH32_round(state->v[3], XXH_readLE32(p32));
- }
- p += 16-state->memsize;
- state->memsize = 0;
+ if (state->bufferedSize) { /* non-empty buffer: complete first */
+ XXH_memcpy(state->buffer + state->bufferedSize, xinput, sizeof(state->buffer) - state->bufferedSize);
+ xinput += sizeof(state->buffer) - state->bufferedSize;
+ /* then process one round */
+ (void)XXH32_consumeLong(state->acc, state->buffer, sizeof(state->buffer), XXH_aligned);
+ state->bufferedSize = 0;
}
- if (p <= bEnd-16) {
- const xxh_u8* const limit = bEnd - 16;
-
- do {
- state->v[0] = XXH32_round(state->v[0], XXH_readLE32(p)); p+=4;
- state->v[1] = XXH32_round(state->v[1], XXH_readLE32(p)); p+=4;
- state->v[2] = XXH32_round(state->v[2], XXH_readLE32(p)); p+=4;
- state->v[3] = XXH32_round(state->v[3], XXH_readLE32(p)); p+=4;
- } while (p<=limit);
-
+ XXH_ASSERT(xinput <= bEnd);
+ if ((size_t)(bEnd - xinput) >= sizeof(state->buffer)) {
+ /* Process the remaining data */
+ xinput = XXH32_consumeLong(state->acc, xinput, (size_t)(bEnd - xinput), XXH_unaligned);
}
- if (p < bEnd) {
- XXH_memcpy(state->mem32, p, (size_t)(bEnd-p));
- state->memsize = (unsigned)(bEnd-p);
+ if (xinput < bEnd) {
+ /* Copy the leftover to the tmp buffer */
+ XXH_memcpy(state->buffer, xinput, (size_t)(bEnd-xinput));
+ state->bufferedSize = (unsigned)(bEnd-xinput);
}
}
@@ -3188,17 +3302,14 @@ XXH_PUBLIC_API XXH32_hash_t XXH32_digest(const XXH32_state_t* state)
xxh_u32 h32;
if (state->large_len) {
- h32 = XXH_rotl32(state->v[0], 1)
- + XXH_rotl32(state->v[1], 7)
- + XXH_rotl32(state->v[2], 12)
- + XXH_rotl32(state->v[3], 18);
+ h32 = XXH32_mergeAccs(state->acc);
} else {
- h32 = state->v[2] /* == seed */ + XXH_PRIME32_5;
+ h32 = state->acc[2] /* == seed */ + XXH_PRIME32_5;
}
h32 += state->total_len_32;
- return XXH32_finalize(h32, (const xxh_u8*)state->mem32, state->memsize, XXH_aligned);
+ return XXH32_finalize(h32, state->buffer, state->bufferedSize, XXH_aligned);
}
#endif /* !XXH_NO_STREAM */
@@ -3259,11 +3370,11 @@ static xxh_u64 XXH_read64(const void* memPtr)
* https://gcc.godbolt.org/z/xYez1j67Y.
*/
#ifdef XXH_OLD_NAMES
-typedef union { xxh_u32 u32; xxh_u64 u64; } __attribute__((packed)) unalign64;
+typedef union { xxh_u32 u32; xxh_u64 u64; } __attribute__((__packed__)) unalign64;
#endif
static xxh_u64 XXH_read64(const void* ptr)
{
- typedef __attribute__((aligned(1))) xxh_u64 xxh_unalign64;
+ typedef __attribute__((__aligned__(1))) xxh_u64 xxh_unalign64;
return *((const xxh_unalign64*)ptr);
}
@@ -3426,6 +3537,85 @@ static xxh_u64 XXH64_avalanche(xxh_u64 hash)
/*!
* @internal
+ * @brief Sets up the initial accumulator state for XXH64().
+ */
+XXH_FORCE_INLINE void
+XXH64_initAccs(xxh_u64 *acc, xxh_u64 seed)
+{
+ XXH_ASSERT(acc != NULL);
+ acc[0] = seed + XXH_PRIME64_1 + XXH_PRIME64_2;
+ acc[1] = seed + XXH_PRIME64_2;
+ acc[2] = seed + 0;
+ acc[3] = seed - XXH_PRIME64_1;
+}
+
+/*!
+ * @internal
+ * @brief Consumes a block of data for XXH64().
+ *
+ * @return the end input pointer.
+ */
+XXH_FORCE_INLINE const xxh_u8 *
+XXH64_consumeLong(
+ xxh_u64 *XXH_RESTRICT acc,
+ xxh_u8 const *XXH_RESTRICT input,
+ size_t len,
+ XXH_alignment align
+)
+{
+ const xxh_u8* const bEnd = input + len;
+ const xxh_u8* const limit = bEnd - 31;
+ XXH_ASSERT(acc != NULL);
+ XXH_ASSERT(input != NULL);
+ XXH_ASSERT(len >= 32);
+ do {
+ /* reroll on 32-bit */
+ if (sizeof(void *) < sizeof(xxh_u64)) {
+ size_t i;
+ for (i = 0; i < 4; i++) {
+ acc[i] = XXH64_round(acc[i], XXH_get64bits(input));
+ input += 8;
+ }
+ } else {
+ acc[0] = XXH64_round(acc[0], XXH_get64bits(input)); input += 8;
+ acc[1] = XXH64_round(acc[1], XXH_get64bits(input)); input += 8;
+ acc[2] = XXH64_round(acc[2], XXH_get64bits(input)); input += 8;
+ acc[3] = XXH64_round(acc[3], XXH_get64bits(input)); input += 8;
+ }
+ } while (input < limit);
+
+ return input;
+}
+
+/*!
+ * @internal
+ * @brief Merges the accumulator lanes together for XXH64()
+ */
+XXH_FORCE_INLINE XXH_PUREF xxh_u64
+XXH64_mergeAccs(const xxh_u64 *acc)
+{
+ XXH_ASSERT(acc != NULL);
+ {
+ xxh_u64 h64 = XXH_rotl64(acc[0], 1) + XXH_rotl64(acc[1], 7)
+ + XXH_rotl64(acc[2], 12) + XXH_rotl64(acc[3], 18);
+ /* reroll on 32-bit */
+ if (sizeof(void *) < sizeof(xxh_u64)) {
+ size_t i;
+ for (i = 0; i < 4; i++) {
+ h64 = XXH64_mergeRound(h64, acc[i]);
+ }
+ } else {
+ h64 = XXH64_mergeRound(h64, acc[0]);
+ h64 = XXH64_mergeRound(h64, acc[1]);
+ h64 = XXH64_mergeRound(h64, acc[2]);
+ h64 = XXH64_mergeRound(h64, acc[3]);
+ }
+ return h64;
+ }
+}
+
+/*!
+ * @internal
* @brief Processes the last 0-31 bytes of @p ptr.
*
* There may be up to 31 bytes remaining to consume from the input.
@@ -3439,7 +3629,7 @@ static xxh_u64 XXH64_avalanche(xxh_u64 hash)
* @return The finalized hash
* @see XXH32_finalize().
*/
-static XXH_PUREF xxh_u64
+XXH_STATIC XXH_PUREF xxh_u64
XXH64_finalize(xxh_u64 hash, const xxh_u8* ptr, size_t len, XXH_alignment align)
{
if (ptr==NULL) XXH_ASSERT(len == 0);
@@ -3489,27 +3679,13 @@ XXH64_endian_align(const xxh_u8* input, size_t len, xxh_u64 seed, XXH_alignment
xxh_u64 h64;
if (input==NULL) XXH_ASSERT(len == 0);
- if (len>=32) {
- const xxh_u8* const bEnd = input + len;
- const xxh_u8* const limit = bEnd - 31;
- xxh_u64 v1 = seed + XXH_PRIME64_1 + XXH_PRIME64_2;
- xxh_u64 v2 = seed + XXH_PRIME64_2;
- xxh_u64 v3 = seed + 0;
- xxh_u64 v4 = seed - XXH_PRIME64_1;
-
- do {
- v1 = XXH64_round(v1, XXH_get64bits(input)); input+=8;
- v2 = XXH64_round(v2, XXH_get64bits(input)); input+=8;
- v3 = XXH64_round(v3, XXH_get64bits(input)); input+=8;
- v4 = XXH64_round(v4, XXH_get64bits(input)); input+=8;
- } while (input<limit);
+ if (len>=32) { /* Process a large block of data */
+ xxh_u64 acc[4];
+ XXH64_initAccs(acc, seed);
- h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
- h64 = XXH64_mergeRound(h64, v1);
- h64 = XXH64_mergeRound(h64, v2);
- h64 = XXH64_mergeRound(h64, v3);
- h64 = XXH64_mergeRound(h64, v4);
+ input = XXH64_consumeLong(acc, input, len, align);
+ h64 = XXH64_mergeAccs(acc);
} else {
h64 = seed + XXH_PRIME64_5;
}
@@ -3564,11 +3740,8 @@ XXH_PUBLIC_API void XXH64_copyState(XXH_NOESCAPE XXH64_state_t* dstState, const
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH_NOESCAPE XXH64_state_t* statePtr, XXH64_hash_t seed)
{
XXH_ASSERT(statePtr != NULL);
- memset(statePtr, 0, sizeof(*statePtr));
- statePtr->v[0] = seed + XXH_PRIME64_1 + XXH_PRIME64_2;
- statePtr->v[1] = seed + XXH_PRIME64_2;
- statePtr->v[2] = seed + 0;
- statePtr->v[3] = seed - XXH_PRIME64_1;
+ XXH_memset(statePtr, 0, sizeof(*statePtr));
+ XXH64_initAccs(statePtr->acc, seed);
return XXH_OK;
}
@@ -3581,42 +3754,36 @@ XXH64_update (XXH_NOESCAPE XXH64_state_t* state, XXH_NOESCAPE const void* input,
return XXH_OK;
}
- { const xxh_u8* p = (const xxh_u8*)input;
- const xxh_u8* const bEnd = p + len;
+ state->total_len += len;
- state->total_len += len;
+ XXH_ASSERT(state->bufferedSize <= sizeof(state->buffer));
+ if (len < sizeof(state->buffer) - state->bufferedSize) { /* fill in tmp buffer */
+ XXH_memcpy(state->buffer + state->bufferedSize, input, len);
+ state->bufferedSize += (XXH32_hash_t)len;
+ return XXH_OK;
+ }
- if (state->memsize + len < 32) { /* fill in tmp buffer */
- XXH_memcpy(((xxh_u8*)state->mem64) + state->memsize, input, len);
- state->memsize += (xxh_u32)len;
- return XXH_OK;
- }
+ { const xxh_u8* xinput = (const xxh_u8*)input;
+ const xxh_u8* const bEnd = xinput + len;
- if (state->memsize) { /* tmp buffer is full */
- XXH_memcpy(((xxh_u8*)state->mem64) + state->memsize, input, 32-state->memsize);
- state->v[0] = XXH64_round(state->v[0], XXH_readLE64(state->mem64+0));
- state->v[1] = XXH64_round(state->v[1], XXH_readLE64(state->mem64+1));
- state->v[2] = XXH64_round(state->v[2], XXH_readLE64(state->mem64+2));
- state->v[3] = XXH64_round(state->v[3], XXH_readLE64(state->mem64+3));
- p += 32 - state->memsize;
- state->memsize = 0;
+ if (state->bufferedSize) { /* non-empty buffer => complete first */
+ XXH_memcpy(state->buffer + state->bufferedSize, xinput, sizeof(state->buffer) - state->bufferedSize);
+ xinput += sizeof(state->buffer) - state->bufferedSize;
+ /* and process one round */
+ (void)XXH64_consumeLong(state->acc, state->buffer, sizeof(state->buffer), XXH_aligned);
+ state->bufferedSize = 0;
}
- if (p+32 <= bEnd) {
- const xxh_u8* const limit = bEnd - 32;
-
- do {
- state->v[0] = XXH64_round(state->v[0], XXH_readLE64(p)); p+=8;
- state->v[1] = XXH64_round(state->v[1], XXH_readLE64(p)); p+=8;
- state->v[2] = XXH64_round(state->v[2], XXH_readLE64(p)); p+=8;
- state->v[3] = XXH64_round(state->v[3], XXH_readLE64(p)); p+=8;
- } while (p<=limit);
-
+ XXH_ASSERT(xinput <= bEnd);
+ if ((size_t)(bEnd - xinput) >= sizeof(state->buffer)) {
+ /* Process the remaining data */
+ xinput = XXH64_consumeLong(state->acc, xinput, (size_t)(bEnd - xinput), XXH_unaligned);
}
- if (p < bEnd) {
- XXH_memcpy(state->mem64, p, (size_t)(bEnd-p));
- state->memsize = (unsigned)(bEnd-p);
+ if (xinput < bEnd) {
+ /* Copy the leftover to the tmp buffer */
+ XXH_memcpy(state->buffer, xinput, (size_t)(bEnd-xinput));
+ state->bufferedSize = (unsigned)(bEnd-xinput);
}
}
@@ -3630,18 +3797,14 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_digest(XXH_NOESCAPE const XXH64_state_t* state
xxh_u64 h64;
if (state->total_len >= 32) {
- h64 = XXH_rotl64(state->v[0], 1) + XXH_rotl64(state->v[1], 7) + XXH_rotl64(state->v[2], 12) + XXH_rotl64(state->v[3], 18);
- h64 = XXH64_mergeRound(h64, state->v[0]);
- h64 = XXH64_mergeRound(h64, state->v[1]);
- h64 = XXH64_mergeRound(h64, state->v[2]);
- h64 = XXH64_mergeRound(h64, state->v[3]);
+ h64 = XXH64_mergeAccs(state->acc);
} else {
- h64 = state->v[2] /*seed*/ + XXH_PRIME64_5;
+ h64 = state->acc[2] /*seed*/ + XXH_PRIME64_5;
}
h64 += (xxh_u64) state->total_len;
- return XXH64_finalize(h64, (const xxh_u8*)state->mem64, (size_t)state->total_len, XXH_aligned);
+ return XXH64_finalize(h64, state->buffer, (size_t)state->total_len, XXH_aligned);
}
#endif /* !XXH_NO_STREAM */
@@ -3676,22 +3839,6 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(XXH_NOESCAPE const XXH64_can
/* === Compiler specifics === */
-#if ((defined(sun) || defined(__sun)) && __cplusplus) /* Solaris includes __STDC_VERSION__ with C++. Tested with GCC 5.5 */
-# define XXH_RESTRICT /* disable */
-#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* >= C99 */
-# define XXH_RESTRICT restrict
-#elif (defined (__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) \
- || (defined (__clang__)) \
- || (defined (_MSC_VER) && (_MSC_VER >= 1400)) \
- || (defined (__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300))
-/*
- * There are a LOT more compilers that recognize __restrict but this
- * covers the major ones.
- */
-# define XXH_RESTRICT __restrict
-#else
-# define XXH_RESTRICT /* disable */
-#endif
#if (defined(__GNUC__) && (__GNUC__ >= 3)) \
|| (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) \
@@ -3730,6 +3877,11 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(XXH_NOESCAPE const XXH64_can
# include <immintrin.h>
# elif defined(__SSE2__)
# include <emmintrin.h>
+# elif defined(__loongarch_asx)
+# include <lasxintrin.h>
+# include <lsxintrin.h>
+# elif defined(__loongarch_sx)
+# include <lsxintrin.h>
# endif
#endif
@@ -3819,8 +3971,8 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(XXH_NOESCAPE const XXH64_can
* @ingroup tuning
* @brief Overrides the vectorization implementation chosen for XXH3.
*
- * Can be defined to 0 to disable SIMD or any of the values mentioned in
- * @ref XXH_VECTOR_TYPE.
+ * Can be defined to 0 to disable SIMD,
+ * or any other authorized value of @ref XXH_VECTOR.
*
* If this is not defined, it uses predefined macros to determine the best
* implementation.
@@ -3828,33 +3980,6 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(XXH_NOESCAPE const XXH64_can
# define XXH_VECTOR XXH_SCALAR
/*!
* @ingroup tuning
- * @brief Possible values for @ref XXH_VECTOR.
- *
- * Note that these are actually implemented as macros.
- *
- * If this is not defined, it is detected automatically.
- * internal macro XXH_X86DISPATCH overrides this.
- */
-enum XXH_VECTOR_TYPE /* fake enum */ {
- XXH_SCALAR = 0, /*!< Portable scalar version */
- XXH_SSE2 = 1, /*!<
- * SSE2 for Pentium 4, Opteron, all x86_64.
- *
- * @note SSE2 is also guaranteed on Windows 10, macOS, and
- * Android x86.
- */
- XXH_AVX2 = 2, /*!< AVX2 for Haswell and Bulldozer */
- XXH_AVX512 = 3, /*!< AVX512 for Skylake and Icelake */
- XXH_NEON = 4, /*!<
- * NEON for most ARMv7-A, all AArch64, and WASM SIMD128
- * via the SIMDeverywhere polyfill provided with the
- * Emscripten SDK.
- */
- XXH_VSX = 5, /*!< VSX and ZVector for POWER8/z13 (64-bit) */
- XXH_SVE = 6, /*!< SVE for some ARMv8-A and ARMv9-A */
-};
-/*!
- * @ingroup tuning
* @brief Selects the minimum alignment for XXH3's accumulators.
*
* When using SIMD, this should match the alignment required for said vector
@@ -3867,13 +3992,6 @@ enum XXH_VECTOR_TYPE /* fake enum */ {
/* Actual definition */
#ifndef XXH_DOXYGEN
-# define XXH_SCALAR 0
-# define XXH_SSE2 1
-# define XXH_AVX2 2
-# define XXH_AVX512 3
-# define XXH_NEON 4
-# define XXH_VSX 5
-# define XXH_SVE 6
#endif
#ifndef XXH_VECTOR /* can be defined on command line */
@@ -3892,12 +4010,16 @@ enum XXH_VECTOR_TYPE /* fake enum */ {
# define XXH_VECTOR XXH_AVX512
# elif defined(__AVX2__)
# define XXH_VECTOR XXH_AVX2
-# elif defined(__SSE2__) || defined(_M_AMD64) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP == 2))
+# elif defined(__SSE2__) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP == 2))
# define XXH_VECTOR XXH_SSE2
# elif (defined(__PPC64__) && defined(__POWER8_VECTOR__)) \
|| (defined(__s390x__) && defined(__VEC__)) \
&& defined(__GNUC__) /* TODO: IBM XL */
# define XXH_VECTOR XXH_VSX
+# elif defined(__loongarch_asx)
+# define XXH_VECTOR XXH_LASX
+# elif defined(__loongarch_sx)
+# define XXH_VECTOR XXH_LSX
# else
# define XXH_VECTOR XXH_SCALAR
# endif
@@ -3935,6 +4057,10 @@ enum XXH_VECTOR_TYPE /* fake enum */ {
# define XXH_ACC_ALIGN 64
# elif XXH_VECTOR == XXH_SVE /* sve */
# define XXH_ACC_ALIGN 64
+# elif XXH_VECTOR == XXH_LASX /* lasx */
+# define XXH_ACC_ALIGN 64
+# elif XXH_VECTOR == XXH_LSX /* lsx */
+# define XXH_ACC_ALIGN 64
# endif
#endif
@@ -3948,7 +4074,7 @@ enum XXH_VECTOR_TYPE /* fake enum */ {
#endif
#if defined(__GNUC__) || defined(__clang__)
-# define XXH_ALIASING __attribute__((may_alias))
+# define XXH_ALIASING __attribute__((__may_alias__))
#else
# define XXH_ALIASING /* nothing */
#endif
@@ -4264,7 +4390,10 @@ do { \
# error "default keyset is not large enough"
#endif
-/*! Pseudorandom secret taken directly from FARSH. */
+/*!
+ * @internal
+ * @def XXH3_kSecret
+ * @brief Pseudorandom secret taken directly from FARSH. */
XXH_ALIGN(64) static const xxh_u8 XXH3_kSecret[XXH_SECRET_DEFAULT_SIZE] = {
0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c,
0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f,
@@ -4701,11 +4830,6 @@ XXH3_len_17to128_64b(const xxh_u8* XXH_RESTRICT input, size_t len,
}
}
-/*!
- * @brief Maximum size of "short" key in bytes.
- */
-#define XXH3_MIDSIZE_MAX 240
-
XXH_NO_INLINE XXH_PUREF XXH64_hash_t
XXH3_len_129to240_64b(const xxh_u8* XXH_RESTRICT input, size_t len,
const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
@@ -5577,6 +5701,130 @@ XXH3_accumulate_sve(xxh_u64* XXH_RESTRICT acc,
#endif
+#if (XXH_VECTOR == XXH_LSX)
+#define _LSX_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
+
+XXH_FORCE_INLINE void
+XXH3_accumulate_512_lsx( void* XXH_RESTRICT acc,
+ const void* XXH_RESTRICT input,
+ const void* XXH_RESTRICT secret)
+{
+ XXH_ASSERT((((size_t)acc) & 15) == 0);
+ {
+ __m128i* const xacc = (__m128i *) acc;
+ const __m128i* const xinput = (const __m128i *) input;
+ const __m128i* const xsecret = (const __m128i *) secret;
+
+ for (size_t i = 0; i < XXH_STRIPE_LEN / sizeof(__m128i); i++) {
+ /* data_vec = xinput[i]; */
+ __m128i const data_vec = __lsx_vld(xinput + i, 0);
+ /* key_vec = xsecret[i]; */
+ __m128i const key_vec = __lsx_vld(xsecret + i, 0);
+ /* data_key = data_vec ^ key_vec; */
+ __m128i const data_key = __lsx_vxor_v(data_vec, key_vec);
+ /* data_key_lo = data_key >> 32; */
+ __m128i const data_key_lo = __lsx_vsrli_d(data_key, 32);
+ // __m128i const data_key_lo = __lsx_vsrli_d(data_key, 32);
+ /* product = (data_key & 0xffffffff) * (data_key_lo & 0xffffffff); */
+ __m128i const product = __lsx_vmulwev_d_wu(data_key, data_key_lo);
+ /* xacc[i] += swap(data_vec); */
+ __m128i const data_swap = __lsx_vshuf4i_w(data_vec, _LSX_SHUFFLE(1, 0, 3, 2));
+ __m128i const sum = __lsx_vadd_d(xacc[i], data_swap);
+ /* xacc[i] += product; */
+ xacc[i] = __lsx_vadd_d(product, sum);
+ }
+ }
+}
+XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(lsx)
+
+XXH_FORCE_INLINE void
+XXH3_scrambleAcc_lsx(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret)
+{
+ XXH_ASSERT((((size_t)acc) & 15) == 0);
+ {
+ __m128i* const xacc = (__m128i*) acc;
+ const __m128i* const xsecret = (const __m128i *) secret;
+ const __m128i prime32 = __lsx_vreplgr2vr_d(XXH_PRIME32_1);
+
+ for (size_t i = 0; i < XXH_STRIPE_LEN / sizeof(__m128i); i++) {
+ /* xacc[i] ^= (xacc[i] >> 47) */
+ __m128i const acc_vec = xacc[i];
+ __m128i const shifted = __lsx_vsrli_d(acc_vec, 47);
+ __m128i const data_vec = __lsx_vxor_v(acc_vec, shifted);
+ /* xacc[i] ^= xsecret[i]; */
+ __m128i const key_vec = __lsx_vld(xsecret + i, 0);
+ __m128i const data_key = __lsx_vxor_v(data_vec, key_vec);
+
+ /* xacc[i] *= XXH_PRIME32_1; */
+ xacc[i] = __lsx_vmul_d(data_key, prime32);
+ }
+ }
+}
+
+#endif
+
+#if (XXH_VECTOR == XXH_LASX)
+#define _LASX_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
+
+XXH_FORCE_INLINE void
+XXH3_accumulate_512_lasx( void* XXH_RESTRICT acc,
+ const void* XXH_RESTRICT input,
+ const void* XXH_RESTRICT secret)
+{
+ XXH_ASSERT((((size_t)acc) & 31) == 0);
+ {
+ __m256i* const xacc = (__m256i *) acc;
+ const __m256i* const xinput = (const __m256i *) input;
+ const __m256i* const xsecret = (const __m256i *) secret;
+
+ for (size_t i = 0; i < XXH_STRIPE_LEN / sizeof(__m256i); i++) {
+ /* data_vec = xinput[i]; */
+ __m256i const data_vec = __lasx_xvld(xinput + i, 0);
+ /* key_vec = xsecret[i]; */
+ __m256i const key_vec = __lasx_xvld(xsecret + i, 0);
+ /* data_key = data_vec ^ key_vec; */
+ __m256i const data_key = __lasx_xvxor_v(data_vec, key_vec);
+ /* data_key_lo = data_key >> 32; */
+ __m256i const data_key_lo = __lasx_xvsrli_d(data_key, 32);
+ // __m256i const data_key_lo = __lasx_xvsrli_d(data_key, 32);
+ /* product = (data_key & 0xffffffff) * (data_key_lo & 0xffffffff); */
+ __m256i const product = __lasx_xvmulwev_d_wu(data_key, data_key_lo);
+ /* xacc[i] += swap(data_vec); */
+ __m256i const data_swap = __lasx_xvshuf4i_w(data_vec, _LASX_SHUFFLE(1, 0, 3, 2));
+ __m256i const sum = __lasx_xvadd_d(xacc[i], data_swap);
+ /* xacc[i] += product; */
+ xacc[i] = __lasx_xvadd_d(product, sum);
+ }
+ }
+}
+XXH_FORCE_INLINE XXH3_ACCUMULATE_TEMPLATE(lasx)
+
+XXH_FORCE_INLINE void
+XXH3_scrambleAcc_lasx(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret)
+{
+ XXH_ASSERT((((size_t)acc) & 31) == 0);
+ {
+ __m256i* const xacc = (__m256i*) acc;
+ const __m256i* const xsecret = (const __m256i *) secret;
+ const __m256i prime32 = __lasx_xvreplgr2vr_d(XXH_PRIME32_1);
+
+ for (size_t i = 0; i < XXH_STRIPE_LEN / sizeof(__m256i); i++) {
+ /* xacc[i] ^= (xacc[i] >> 47) */
+ __m256i const acc_vec = xacc[i];
+ __m256i const shifted = __lasx_xvsrli_d(acc_vec, 47);
+ __m256i const data_vec = __lasx_xvxor_v(acc_vec, shifted);
+ /* xacc[i] ^= xsecret[i]; */
+ __m256i const key_vec = __lasx_xvld(xsecret + i, 0);
+ __m256i const data_key = __lasx_xvxor_v(data_vec, key_vec);
+
+ /* xacc[i] *= XXH_PRIME32_1; */
+ xacc[i] = __lasx_xvmul_d(data_key, prime32);
+ }
+ }
+}
+
+#endif
+
/* scalar variants - universal */
#if defined(__aarch64__) && (defined(__GNUC__) || defined(__clang__))
@@ -5807,6 +6055,18 @@ typedef void (*XXH3_f_initCustomSecret)(void* XXH_RESTRICT, xxh_u64);
#define XXH3_scrambleAcc XXH3_scrambleAcc_scalar
#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
+#elif (XXH_VECTOR == XXH_LASX)
+#define XXH3_accumulate_512 XXH3_accumulate_512_lasx
+#define XXH3_accumulate XXH3_accumulate_lasx
+#define XXH3_scrambleAcc XXH3_scrambleAcc_lasx
+#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
+
+#elif (XXH_VECTOR == XXH_LSX)
+#define XXH3_accumulate_512 XXH3_accumulate_512_lsx
+#define XXH3_accumulate XXH3_accumulate_lsx
+#define XXH3_scrambleAcc XXH3_scrambleAcc_lsx
+#define XXH3_initCustomSecret XXH3_initCustomSecret_scalar
+
#else /* scalar */
#define XXH3_accumulate_512 XXH3_accumulate_512_scalar
@@ -5862,7 +6122,7 @@ XXH3_mix2Accs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret
acc[1] ^ XXH_readLE64(secret+8) );
}
-static XXH64_hash_t
+static XXH_PUREF XXH64_hash_t
XXH3_mergeAccs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret, xxh_u64 start)
{
xxh_u64 result64 = start;
@@ -5889,6 +6149,15 @@ XXH3_mergeAccs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secre
return XXH3_avalanche(result64);
}
+/* do not align on 8, so that the secret is different from the accumulator */
+#define XXH_SECRET_MERGEACCS_START 11
+
+static XXH_PUREF XXH64_hash_t
+XXH3_finalizeLong_64b(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret, xxh_u64 len)
+{
+ return XXH3_mergeAccs(acc, secret + XXH_SECRET_MERGEACCS_START, len * XXH_PRIME64_1);
+}
+
#define XXH3_INIT_ACC { XXH_PRIME32_3, XXH_PRIME64_1, XXH_PRIME64_2, XXH_PRIME64_3, \
XXH_PRIME64_4, XXH_PRIME32_2, XXH_PRIME64_5, XXH_PRIME32_1 }
@@ -5904,10 +6173,8 @@ XXH3_hashLong_64b_internal(const void* XXH_RESTRICT input, size_t len,
/* converge into final hash */
XXH_STATIC_ASSERT(sizeof(acc) == 64);
- /* do not align on 8, so that the secret is different from the accumulator */
-#define XXH_SECRET_MERGEACCS_START 11
XXH_ASSERT(secretSize >= sizeof(acc) + XXH_SECRET_MERGEACCS_START);
- return XXH3_mergeAccs(acc, (const xxh_u8*)secret + XXH_SECRET_MERGEACCS_START, (xxh_u64)len * XXH_PRIME64_1);
+ return XXH3_finalizeLong_64b(acc, (const xxh_u8*)secret, (xxh_u64)len);
}
/*
@@ -6043,7 +6310,7 @@ XXH3_64bits_withSecretandSeed(XXH_NOESCAPE const void* input, size_t length, XXH
/* === XXH3 streaming === */
#ifndef XXH_NO_STREAM
/*
- * Malloc's a pointer that is always aligned to align.
+ * Malloc's a pointer that is always aligned to @align.
*
* This must be freed with `XXH_alignedFree()`.
*
@@ -6161,7 +6428,7 @@ XXH3_reset_internal(XXH3_state_t* statePtr,
XXH_ASSERT(offsetof(XXH3_state_t, nbStripesPerBlock) > initStart);
XXH_ASSERT(statePtr != NULL);
/* set members from bufferedSize to nbStripesPerBlock (excluded) to 0 */
- memset((char*)statePtr + initStart, 0, initLength);
+ XXH_memset((char*)statePtr + initStart, 0, initLength);
statePtr->acc[0] = XXH_PRIME32_3;
statePtr->acc[1] = XXH_PRIME64_1;
statePtr->acc[2] = XXH_PRIME64_2;
@@ -6280,8 +6547,9 @@ XXH3_consumeStripes(xxh_u64* XXH_RESTRICT acc,
# define XXH3_STREAM_USE_STACK 1
# endif
#endif
-/*
- * Both XXH3_64bits_update and XXH3_128bits_update use this routine.
+/* This function accepts f_acc and f_scramble as function pointers,
+ * making it possible to implement multiple variants with different acc & scramble stages.
+ * This is notably useful to implement multiple vector variants with different intrinsics.
*/
XXH_FORCE_INLINE XXH_errorcode
XXH3_update(XXH3_state_t* XXH_RESTRICT const state,
@@ -6362,12 +6630,21 @@ XXH3_update(XXH3_state_t* XXH_RESTRICT const state,
return XXH_OK;
}
+/*
+ * Both XXH3_64bits_update and XXH3_128bits_update use this routine.
+ */
+XXH_NO_INLINE XXH_errorcode
+XXH3_update_regular(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len)
+{
+ return XXH3_update(state, (const xxh_u8*)input, len,
+ XXH3_accumulate, XXH3_scrambleAcc);
+}
+
/*! @ingroup XXH3_family */
XXH_PUBLIC_API XXH_errorcode
XXH3_64bits_update(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len)
{
- return XXH3_update(state, (const xxh_u8*)input, len,
- XXH3_accumulate, XXH3_scrambleAcc);
+ return XXH3_update_regular(state, input, len);
}
@@ -6415,9 +6692,7 @@ XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_digest (XXH_NOESCAPE const XXH3_state_t*
if (state->totalLen > XXH3_MIDSIZE_MAX) {
XXH_ALIGN(XXH_ACC_ALIGN) XXH64_hash_t acc[XXH_ACC_NB];
XXH3_digest_long(acc, state, secret);
- return XXH3_mergeAccs(acc,
- secret + XXH_SECRET_MERGEACCS_START,
- (xxh_u64)state->totalLen * XXH_PRIME64_1);
+ return XXH3_finalizeLong_64b(acc, secret, (xxh_u64)state->totalLen);
}
/* totalLen <= XXH3_MIDSIZE_MAX: digesting a short input */
if (state->useSeed)
@@ -6709,6 +6984,17 @@ XXH3_len_129to240_128b(const xxh_u8* XXH_RESTRICT input, size_t len,
}
}
+static XXH_PUREF XXH128_hash_t
+XXH3_finalizeLong_128b(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret, size_t secretSize, xxh_u64 len)
+{
+ XXH128_hash_t h128;
+ h128.low64 = XXH3_finalizeLong_64b(acc, secret, len);
+ h128.high64 = XXH3_mergeAccs(acc, secret + secretSize
+ - XXH_STRIPE_LEN - XXH_SECRET_MERGEACCS_START,
+ ~(len * XXH_PRIME64_2));
+ return h128;
+}
+
XXH_FORCE_INLINE XXH128_hash_t
XXH3_hashLong_128b_internal(const void* XXH_RESTRICT input, size_t len,
const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
@@ -6722,16 +7008,7 @@ XXH3_hashLong_128b_internal(const void* XXH_RESTRICT input, size_t len,
/* converge into final hash */
XXH_STATIC_ASSERT(sizeof(acc) == 64);
XXH_ASSERT(secretSize >= sizeof(acc) + XXH_SECRET_MERGEACCS_START);
- { XXH128_hash_t h128;
- h128.low64 = XXH3_mergeAccs(acc,
- secret + XXH_SECRET_MERGEACCS_START,
- (xxh_u64)len * XXH_PRIME64_1);
- h128.high64 = XXH3_mergeAccs(acc,
- secret + secretSize
- - sizeof(acc) - XXH_SECRET_MERGEACCS_START,
- ~((xxh_u64)len * XXH_PRIME64_2));
- return h128;
- }
+ return XXH3_finalizeLong_128b(acc, secret, secretSize, (xxh_u64)len);
}
/*
@@ -6903,7 +7180,7 @@ XXH3_128bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t* statePtr, XXH_NO
XXH_PUBLIC_API XXH_errorcode
XXH3_128bits_update(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len)
{
- return XXH3_64bits_update(state, input, len);
+ return XXH3_update_regular(state, input, len);
}
/*! @ingroup XXH3_family */
@@ -6914,19 +7191,10 @@ XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_digest (XXH_NOESCAPE const XXH3_state_
XXH_ALIGN(XXH_ACC_ALIGN) XXH64_hash_t acc[XXH_ACC_NB];
XXH3_digest_long(acc, state, secret);
XXH_ASSERT(state->secretLimit + XXH_STRIPE_LEN >= sizeof(acc) + XXH_SECRET_MERGEACCS_START);
- { XXH128_hash_t h128;
- h128.low64 = XXH3_mergeAccs(acc,
- secret + XXH_SECRET_MERGEACCS_START,
- (xxh_u64)state->totalLen * XXH_PRIME64_1);
- h128.high64 = XXH3_mergeAccs(acc,
- secret + state->secretLimit + XXH_STRIPE_LEN
- - sizeof(acc) - XXH_SECRET_MERGEACCS_START,
- ~((xxh_u64)state->totalLen * XXH_PRIME64_2));
- return h128;
- }
+ return XXH3_finalizeLong_128b(acc, secret, state->secretLimit + XXH_STRIPE_LEN, (xxh_u64)state->totalLen);
}
/* len <= XXH3_MIDSIZE_MAX : short code */
- if (state->seed)
+ if (state->useSeed)
return XXH3_128bits_withSeed(state->buffer, (size_t)state->totalLen, state->seed);
return XXH3_128bits_withSecret(state->buffer, (size_t)(state->totalLen),
secret, state->secretLimit + XXH_STRIPE_LEN);
@@ -6934,14 +7202,12 @@ XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_digest (XXH_NOESCAPE const XXH3_state_
#endif /* !XXH_NO_STREAM */
/* 128-bit utility functions */
-#include <string.h> /* memcmp, memcpy */
-
/* return : 1 is equal, 0 if different */
/*! @ingroup XXH3_family */
XXH_PUBLIC_API int XXH128_isEqual(XXH128_hash_t h1, XXH128_hash_t h2)
{
/* note : XXH128_hash_t is compact, it has no padding byte */
- return !(memcmp(&h1, &h2, sizeof(h1)));
+ return !(XXH_memcmp(&h1, &h2, sizeof(h1)));
}
/* This prototype is compatible with stdlib's qsort().
@@ -7025,7 +7291,7 @@ XXH3_generateSecret(XXH_NOESCAPE void* secretBuffer, size_t secretSize, XXH_NOES
{ size_t pos = 0;
while (pos < secretSize) {
size_t const toCopy = XXH_MIN((secretSize - pos), customSeedSize);
- memcpy((char*)secretBuffer + pos, customSeed, toCopy);
+ XXH_memcpy((char*)secretBuffer + pos, customSeed, toCopy);
pos += toCopy;
} }
@@ -7050,7 +7316,7 @@ XXH3_generateSecret_fromSeed(XXH_NOESCAPE void* secretBuffer, XXH64_hash_t seed)
XXH_ALIGN(XXH_SEC_ALIGN) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
XXH3_initCustomSecret(secret, seed);
XXH_ASSERT(secretBuffer != NULL);
- memcpy(secretBuffer, secret, XXH_SECRET_DEFAULT_SIZE);
+ XXH_memcpy(secretBuffer, secret, XXH_SECRET_DEFAULT_SIZE);
}
@@ -7072,6 +7338,6 @@ XXH3_generateSecret_fromSeed(XXH_NOESCAPE void* secretBuffer, XXH64_hash_t seed)
#endif /* XXH_IMPLEMENTATION */
-#if defined (__cplusplus)
+#if defined (__cplusplus) && !defined(XXH_NO_EXTERNC_GUARD)
} /* extern "C" */
#endif