xxHash 0.8.2
Extremely fast non-cryptographic hash function
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
xxhash.h File Reference
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <altivec.h>

Go to the source code of this file.

Data Structures

struct  XXH32_canonical_t
 Canonical (big endian) representation of XXH32_hash_t. More...
 
struct  XXH64_canonical_t
 Canonical (big endian) representation of XXH64_hash_t. More...
 
struct  XXH128_hash_t
 The return value from 128-bit hashes. More...
 
struct  XXH128_canonical_t
 
struct  XXH32_state_s
 
struct  XXH64_state_s
 
struct  XXH3_state_s
 

Macros

#define XXH_STATIC_LINKING_ONLY
 Gives access to internal state declaration, required for static allocation.
 
#define XXH_IMPLEMENTATION
 Gives access to internal definitions.
 
#define XXH_INLINE_ALL
 Exposes the implementation and marks all functions as inline.
 
#define XXH_PRIVATE_API
 Exposes the implementation without marking functions as inline.
 
#define XXH_NAMESPACE   /* YOUR NAME HERE */
 Emulate a namespace by transparently prefixing all symbols.
 
#define XXHASH_H_5627135585666179   1
 
#define XXH_PUBLIC_API   /* do nothing */
 Marks a global symbol.
 
#define XXH_PUBLIC_API   /* do nothing */
 Marks a global symbol.
 
#define XXH_CONSTF   /* disable */
 
#define XXH_PUREF
 
#define XXH_MALLOCF
 
#define XXH_VERSION_MAJOR   0
 
#define XXH_VERSION_MINOR   8
 
#define XXH_VERSION_RELEASE   2
 
#define XXH_VERSION_NUMBER   (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
 Version number, encoded as two digits each.
 
#define XXH3_SECRET_SIZE_MIN   136
 
#define XXHASH_H_STATIC_13879238742
 
#define XXH_ALIGN(n)   /* disabled */
 
#define XXH_ALIGN_MEMBER(align, type)   XXH_ALIGN(align) type
 
#define XXH3_INTERNALBUFFER_SIZE   256
 The size of the internal XXH3 buffer.
 
#define XXH3_SECRET_DEFAULT_SIZE   192
 
#define XXH3_INITSTATE(XXH3_state_ptr)
 Initializes a stack-allocated XXH3_state_s.
 
#define XXH_IMPLEM_13a8737387
 
#define XXH_NO_LONG_LONG
 Define this to disable 64-bit code.
 
#define XXH_FORCE_MEMORY_ACCESS   0
 Controls how unaligned memory is accessed.
 
#define XXH_SIZE_OPT   0
 Controls how much xxHash optimizes for size.
 
#define XXH_FORCE_ALIGN_CHECK   0
 If defined to non-zero, adds a special path for aligned inputs (XXH32() and XXH64() only).
 
#define XXH_NO_INLINE_HINTS   0
 When non-zero, sets all functions to static.
 
#define XXH3_INLINE_SECRET   0
 Determines whether to inline the XXH3 withSecret code.
 
#define XXH32_ENDJMP   0
 Whether to use a jump for XXH32_finalize.
 
#define XXH_OLD_NAMES
 
#define XXH_NO_STREAM
 Disables the streaming API.
 
#define XXH_FORCE_INLINE   static
 
#define XXH_NO_INLINE   static
 
#define XXH3_WITH_SECRET_INLINE   XXH_NO_INLINE
 
#define XXH_DEBUGLEVEL   0
 Sets the debugging level.
 
#define XXH_ASSERT(c)   XXH_ASSUME(c)
 
#define XXH_STATIC_ASSERT_WITH_MESSAGE(c, m)   do { struct xxh_sa { char x[(c) ? 1 : -1]; }; } while(0)
 
#define XXH_STATIC_ASSERT(c)   XXH_STATIC_ASSERT_WITH_MESSAGE((c),#c)
 
#define XXH_COMPILER_GUARD(var)   ((void)0)
 
#define XXH_COMPILER_GUARD_CLANG_NEON(var)   ((void)0)
 
#define XXH_CPU_LITTLE_ENDIAN   XXH_isLittleEndian()
 Whether the target is little endian.
 
#define XXH_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)
 
#define XXH_HAS_BUILTIN(x)   0
 
#define XXH_UNREACHABLE()
 
#define XXH_ASSUME(c)   if (!(c)) { XXH_UNREACHABLE(); }
 
#define XXH_rotl32(x, r)   (((x) << (r)) | ((x) >> (32 - (r))))
 
#define XXH_rotl64(x, r)   (((x) << (r)) | ((x) >> (64 - (r))))
 
#define XXH_PRIME32_1   0x9E3779B1U
 
#define XXH_PRIME32_2   0x85EBCA77U
 
#define XXH_PRIME32_3   0xC2B2AE3DU
 
#define XXH_PRIME32_4   0x27D4EB2FU
 
#define XXH_PRIME32_5   0x165667B1U
 
#define XXH_get32bits(p)   XXH_readLE32_align(p, align)
 
#define XXH_PROCESS1
 
#define XXH_PROCESS4
 
#define XXH_PRIME64_1   0x9E3779B185EBCA87ULL
 
#define XXH_PRIME64_2   0xC2B2AE3D27D4EB4FULL
 
#define XXH_PRIME64_3   0x165667B19E3779F9ULL
 
#define XXH_PRIME64_4   0x85EBCA77C2B2AE63ULL
 
#define XXH_PRIME64_5   0x27D4EB2F165667C5ULL
 
#define XXH_get64bits(p)   XXH_readLE64_align(p, align)
 
#define XXH_RESTRICT   /* disable */
 
#define XXH_likely(x)   (x)
 
#define XXH_unlikely(x)   (x)
 
#define XXH_HAS_INCLUDE(x)   0
 
#define XXH_VECTOR   XXH_SCALAR
 Overrides the vectorization implementation chosen for XXH3.
 
#define XXH_ACC_ALIGN   8
 Selects the minimum alignment for XXH3's accumulators.
 
#define XXH_VECTOR   XXH_SCALAR
 Overrides the vectorization implementation chosen for XXH3.
 
#define XXH_SEC_ALIGN   XXH_ACC_ALIGN
 
#define XXH_ALIASING   /* nothing */
 
#define XXH3_NEON_LANES   XXH_ACC_NB
 Controls the NEON to scalar ratio for XXH3.
 
#define XXH_VSX_BE   0
 
#define ACCRND(acc, offset)
 
#define XXH_PREFETCH(ptr)   (void)(ptr) /* disabled */
 
#define XXH_SECRET_DEFAULT_SIZE   192 /* minimum XXH3_SECRET_SIZE_MIN */
 
#define XXH3_MIDSIZE_MAX   240
 
#define XXH3_MIDSIZE_STARTOFFSET   3
 
#define XXH3_MIDSIZE_LASTOFFSET   17
 
#define XXH_STRIPE_LEN   64
 
#define XXH_SECRET_CONSUME_RATE   8 /* nb of secret bytes consumed at each accumulation */
 
#define XXH_ACC_NB   (XXH_STRIPE_LEN / sizeof(xxh_u64))
 
#define XXH_PREFETCH_DIST   512
 
#define XXH3_ACCUMULATE_TEMPLATE(name)
 
#define XXH_TARGET_AVX512   /* disable attribute target */
 Like XXH_TARGET_SSE2, but for AVX512.
 
#define XXH_TARGET_AVX2   /* disable attribute target */
 Like XXH_TARGET_SSE2, but for AVX2.
 
#define XXH_TARGET_SSE2   /* disable attribute target */
 Allows a function to be compiled with SSE2 intrinsics.
 
#define XXH3_accumulate_512   XXH3_accumulate_512_avx512
 
#define XXH3_accumulate   XXH3_accumulate_avx512
 
#define XXH3_scrambleAcc   XXH3_scrambleAcc_avx512
 
#define XXH3_initCustomSecret   XXH3_initCustomSecret_avx512
 
#define XXH_SECRET_LASTACC_START   7 /* not aligned on 8, last secret is different from acc & scrambler */
 
#define XXH3_INIT_ACC
 
#define XXH_SECRET_MERGEACCS_START   11
 
#define XXH3_STREAM_USE_STACK   1
 
#define XXH3_INTERNALBUFFER_STRIPES   (XXH3_INTERNALBUFFER_SIZE / XXH_STRIPE_LEN)
 
#define XXH_MIN(x, y)   (((x) > (y)) ? (y) : (x))
 

Typedefs

typedef uint32_t XXH32_hash_t
 An unsigned 32-bit integer.
 
typedef struct XXH32_state_s XXH32_state_t
 The opaque state struct for the XXH32 streaming API.
 
typedef struct XXH64_state_s XXH64_state_t
 The opaque state struct for the XXH64 streaming API.
 
typedef struct XXH3_state_s XXH3_state_t
 The state struct for the XXH3 streaming API.
 
typedef unsigned char xxh_u8
 
typedef XXH32_hash_t xxh_u32
 
typedef uint64x2_t xxh_aliasing_uint64x2_t XXH_ALIASING
 
typedef __vector unsigned long long xxh_u64x2
 
typedef __vector unsigned char xxh_u8x16
 
typedef __vector unsigned xxh_u32x4
 
typedef long long xxh_i64
 
typedef void(* XXH3_f_accumulate) (xxh_u64 *restrict, const xxh_u8 *restrict, const xxh_u8 *restrict, size_t)
 
typedef void(* XXH3_f_scrambleAcc) (void *restrict, const void *)
 
typedef void(* XXH3_f_initCustomSecret) (void *restrict, xxh_u64)
 
typedef XXH64_hash_t(* XXH3_hashLong64_f) (const void *restrict, size_t, XXH64_hash_t, const xxh_u8 *restrict, size_t)
 
typedef XXH128_hash_t(* XXH3_hashLong128_f) (const void *restrict, size_t, XXH64_hash_t, const void *restrict, size_t)
 
typedef uint64_t XXH64_hash_t
 An unsigned 64-bit integer.
 

Enumerations

enum  XXH_errorcode { XXH_OK = 0 , XXH_ERROR }
 Exit code for the streaming API. More...
 
enum  XXH_alignment { XXH_aligned , XXH_unaligned }
 
enum  XXH_VECTOR_TYPE {
  XXH_SCALAR = 0 , XXH_SSE2 = 1 , XXH_AVX2 = 2 , XXH_AVX512 = 3 ,
  XXH_NEON = 4 , XXH_VSX = 5 , XXH_SVE = 6
}
 Possible values for XXH_VECTOR. More...
 

Functions

unsigned XXH_versionNumber (void)
 Obtains the xxHash version.
 
XXH32_hash_t XXH32 (const void *input, size_t length, XXH32_hash_t seed)
 Calculates the 32-bit hash of input using xxHash32.
 
XXH32_state_tXXH32_createState (void)
 Allocates an XXH32_state_t.
 
XXH_errorcode XXH32_freeState (XXH32_state_t *statePtr)
 Frees an XXH32_state_t.
 
void XXH32_copyState (XXH32_state_t *dst_state, const XXH32_state_t *src_state)
 Copies one XXH32_state_t to another.
 
XXH_errorcode XXH32_reset (XXH32_state_t *statePtr, XXH32_hash_t seed)
 Resets an XXH32_state_t to begin a new hash.
 
XXH_errorcode XXH32_update (XXH32_state_t *statePtr, const void *input, size_t length)
 Consumes a block of input to an XXH32_state_t.
 
XXH32_hash_t XXH32_digest (const XXH32_state_t *statePtr)
 Returns the calculated hash value from an XXH32_state_t.
 
void XXH32_canonicalFromHash (XXH32_canonical_t *dst, XXH32_hash_t hash)
 Converts an XXH32_hash_t to a big endian XXH32_canonical_t.
 
XXH32_hash_t XXH32_hashFromCanonical (const XXH32_canonical_t *src)
 Converts an XXH32_canonical_t to a native XXH32_hash_t.
 
XXH64_hash_t XXH64 (XXH_NOESCAPE const void *input, size_t length, XXH64_hash_t seed)
 Calculates the 64-bit hash of input using xxHash64.
 
XXH64_state_tXXH64_createState (void)
 Allocates an XXH64_state_t.
 
XXH_errorcode XXH64_freeState (XXH64_state_t *statePtr)
 Frees an XXH64_state_t.
 
void XXH64_copyState (XXH_NOESCAPE XXH64_state_t *dst_state, const XXH64_state_t *src_state)
 Copies one XXH64_state_t to another.
 
XXH_errorcode XXH64_reset (XXH_NOESCAPE XXH64_state_t *statePtr, XXH64_hash_t seed)
 Resets an XXH64_state_t to begin a new hash.
 
XXH_errorcode XXH64_update (XXH_NOESCAPE XXH64_state_t *statePtr, XXH_NOESCAPE const void *input, size_t length)
 Consumes a block of input to an XXH64_state_t.
 
XXH64_hash_t XXH64_digest (XXH_NOESCAPE const XXH64_state_t *statePtr)
 Returns the calculated hash value from an XXH64_state_t.
 
void XXH64_canonicalFromHash (XXH_NOESCAPE XXH64_canonical_t *dst, XXH64_hash_t hash)
 Converts an XXH64_hash_t to a big endian XXH64_canonical_t.
 
XXH64_hash_t XXH64_hashFromCanonical (XXH_NOESCAPE const XXH64_canonical_t *src)
 Converts an XXH64_canonical_t to a native XXH64_hash_t.
 
XXH64_hash_t XXH3_64bits (XXH_NOESCAPE const void *input, size_t length)
 64-bit unseeded variant of XXH3.
 
XXH64_hash_t XXH3_64bits_withSeed (XXH_NOESCAPE const void *input, size_t length, XXH64_hash_t seed)
 64-bit seeded variant of XXH3
 
XXH64_hash_t XXH3_64bits_withSecret (XXH_NOESCAPE const void *data, size_t len, XXH_NOESCAPE const void *secret, size_t secretSize)
 64-bit variant of XXH3 with a custom "secret".
 
XXH3_state_tXXH3_createState (void)
 Allocate an XXH3_state_t.
 
XXH_errorcode XXH3_freeState (XXH3_state_t *statePtr)
 Frees an XXH3_state_t.
 
void XXH3_copyState (XXH_NOESCAPE XXH3_state_t *dst_state, XXH_NOESCAPE const XXH3_state_t *src_state)
 Copies one XXH3_state_t to another.
 
XXH_errorcode XXH3_64bits_reset (XXH_NOESCAPE XXH3_state_t *statePtr)
 Resets an XXH3_state_t to begin a new hash.
 
XXH_errorcode XXH3_64bits_reset_withSeed (XXH_NOESCAPE XXH3_state_t *statePtr, XXH64_hash_t seed)
 Resets an XXH3_state_t with 64-bit seed to begin a new hash.
 
XXH_errorcode XXH3_64bits_reset_withSecret (XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *secret, size_t secretSize)
 
XXH_errorcode XXH3_64bits_update (XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *input, size_t length)
 Consumes a block of input to an XXH3_state_t.
 
XXH64_hash_t XXH3_64bits_digest (XXH_NOESCAPE const XXH3_state_t *statePtr)
 Returns the calculated XXH3 64-bit hash value from an XXH3_state_t.
 
XXH128_hash_t XXH3_128bits (XXH_NOESCAPE const void *data, size_t len)
 Unseeded 128-bit variant of XXH3.
 
XXH128_hash_t XXH3_128bits_withSeed (XXH_NOESCAPE const void *data, size_t len, XXH64_hash_t seed)
 Seeded 128-bit variant of XXH3.
 
XXH128_hash_t XXH3_128bits_withSecret (XXH_NOESCAPE const void *data, size_t len, XXH_NOESCAPE const void *secret, size_t secretSize)
 Custom secret 128-bit variant of XXH3.
 
XXH_errorcode XXH3_128bits_reset (XXH_NOESCAPE XXH3_state_t *statePtr)
 Resets an XXH3_state_t to begin a new hash.
 
XXH_errorcode XXH3_128bits_reset_withSeed (XXH_NOESCAPE XXH3_state_t *statePtr, XXH64_hash_t seed)
 Resets an XXH3_state_t with 64-bit seed to begin a new hash.
 
XXH_errorcode XXH3_128bits_reset_withSecret (XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *secret, size_t secretSize)
 Custom secret 128-bit variant of XXH3.
 
XXH_errorcode XXH3_128bits_update (XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *input, size_t length)
 Consumes a block of input to an XXH3_state_t.
 
XXH128_hash_t XXH3_128bits_digest (XXH_NOESCAPE const XXH3_state_t *statePtr)
 Returns the calculated XXH3 128-bit hash value from an XXH3_state_t.
 
int XXH128_isEqual (XXH128_hash_t h1, XXH128_hash_t h2)
 
int XXH128_cmp (XXH_NOESCAPE const void *h128_1, XXH_NOESCAPE const void *h128_2)
 Compares two XXH128_hash_t This comparator is compatible with stdlib's qsort()/bsearch().
 
void XXH128_canonicalFromHash (XXH_NOESCAPE XXH128_canonical_t *dst, XXH128_hash_t hash)
 Converts an XXH128_hash_t to a big endian XXH128_canonical_t.
 
XXH128_hash_t XXH128_hashFromCanonical (XXH_NOESCAPE const XXH128_canonical_t *src)
 Converts an XXH128_canonical_t to a native XXH128_hash_t.
 
XXH128_hash_t XXH128 (XXH_NOESCAPE const void *data, size_t len, XXH64_hash_t seed)
 
XXH_errorcode XXH3_generateSecret (XXH_NOESCAPE void *secretBuffer, size_t secretSize, XXH_NOESCAPE const void *customSeed, size_t customSeedSize)
 
void XXH3_generateSecret_fromSeed (XXH_NOESCAPE void *secretBuffer, XXH64_hash_t seed)
 Generate the same secret as the _withSeed() variants.
 
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)
 
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)
 
XXH_errorcode XXH3_64bits_reset_withSecretandSeed (XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *secret, size_t secretSize, XXH64_hash_t seed64)
 
XXH_errorcode XXH3_128bits_reset_withSecretandSeed (XXH_NOESCAPE XXH3_state_t *statePtr, XXH_NOESCAPE const void *secret, size_t secretSize, XXH64_hash_t seed64)
 
 XXH_STATIC_ASSERT (XXH_STRIPE_LEN==sizeof(__m512i))
 
 for (i=0;i< XXH_STRIPE_LEN/sizeof(__m256i);i++)
 
 XXH_ASSERT ((((size_t) acc) &(XXH_ACC_ALIGN-1))==0)
 
 XXH_ASSERT (lane< XXH_ACC_NB)
 
XXH3_WITH_SECRET_INLINE XXH64_hash_t XXH3_hashLong_64b_withSecret (const void *restrict input, size_t len, XXH64_hash_t seed64, const xxh_u8 *restrict secret, size_t secretLen)
 
XXH3_WITH_SECRET_INLINE XXH128_hash_t XXH3_hashLong_128b_withSecret (const void *restrict input, size_t len, XXH64_hash_t seed64, const void *restrict secret, size_t secretLen)
 

Variables

static XXH_TARGET_AVX512 const void *restrict secret
 
const __m512i prime32 = _mm512_set1_epi32((int)XXH_PRIME32_1)
 
__m512i const acc_vec = *xacc
 
__m512i const shifted = _mm512_srli_epi64 (acc_vec, 47)
 
__m512i const key_vec = _mm512_loadu_si512 (secret)
 
__m512i const data_key = _mm512_ternarylogic_epi32(key_vec, acc_vec, shifted, 0x96 )
 
__m512i const data_key_hi = _mm512_srli_epi64 (data_key, 32)
 
__m512i const prod_lo = _mm512_mul_epu32 (data_key, prime32)
 
__m512i const prod_hi = _mm512_mul_epu32 (data_key_hi, prime32)
 
xacc = _mm512_add_epi64(prod_lo, _mm512_slli_epi64(prod_hi, 32))
 
const __m256i *const xsecret = (const __m256i *) secret
 
size_t i
 
uint32x2_t const kPrimeLo = vdup_n_u32(XXH_PRIME32_1)
 
uint32x4_t const kPrimeHi = vreinterpretq_u32_u64(vdupq_n_u64((xxh_u64)XXH_PRIME32_1 << 32))
 
xxh_u64x2 const v32 = { 32, 32 }
 
xxh_u64x2 const v47 = { 47, 47 }
 
xxh_u32x4 const prime = { XXH_PRIME32_1, XXH_PRIME32_1, XXH_PRIME32_1, XXH_PRIME32_1 }
 
static void const *restrict size_t lane
 
xxh_u64 acc64 = xacc[lane]
 
typedef XXH64_hash_t xxh_u64
 

Detailed Description

xxHash prototypes and implementation

Macro Definition Documentation

◆ XXH3_INTERNALBUFFER_SIZE

#define XXH3_INTERNALBUFFER_SIZE   256

The size of the internal XXH3 buffer.

This is the optimal update size for incremental hashing.

See also
XXH3_64b_update(), XXH3_128b_update().

◆ XXH3_INITSTATE

#define XXH3_INITSTATE (   XXH3_state_ptr)
Value:
do { \
XXH3_state_t* tmp_xxh3_state_ptr = (XXH3_state_ptr); \
tmp_xxh3_state_ptr->seed = 0; \
tmp_xxh3_state_ptr->extSecret = NULL; \
} while(0)
Definition xxhash.h:1539
const unsigned char * extSecret
Definition xxhash.h:1562
XXH64_hash_t seed
Definition xxhash.h:1558

Initializes a stack-allocated XXH3_state_s.

When the XXH3_state_t structure is merely emplaced on stack, it should be initialized with XXH3_INITSTATE() or a memset() in case its first reset uses XXH3_NNbits_reset_withSeed(). This init can be omitted if the first reset uses default or _withSecret mode. This operation isn't necessary when the state is created with XXH3_createState(). Note that this doesn't prepare the state for a streaming operation, it's still necessary to use XXH3_NNbits_reset*() afterwards.

◆ XXH_PROCESS1

#define XXH_PROCESS1
Value:
do { \
hash += (*ptr++) * XXH_PRIME32_5; \
hash = XXH_rotl32(hash, 11) * XXH_PRIME32_1; \
} while (0)
#define XXH_PRIME32_1
Definition xxhash.h:2560
#define XXH_PRIME32_5
Definition xxhash.h:2564

◆ XXH_PROCESS4

#define XXH_PROCESS4
Value:
do { \
hash += XXH_get32bits(ptr) * XXH_PRIME32_3; \
ptr += 4; \
hash = XXH_rotl32(hash, 17) * XXH_PRIME32_4; \
} while (0)
#define XXH_PRIME32_4
Definition xxhash.h:2563
#define XXH_PRIME32_3
Definition xxhash.h:2562