xxHash  0.8.0
Extremely fast non-cryptographic hash function
Data Structures | Macros | Typedefs | Functions | Variables
x86 Dispatcher

Data Structures

struct  XXH_dispatchFunctions_s
 
struct  XXH_dispatch128Functions_s
 

Macros

#define XXH_X86DISPATCH_ALLOW_AVX
 Disables the AVX sanity check. More...
 
#define XXH_HAS_INCLUDE(header)   0
 
#define XXH_DISPATCH_SCALAR   1
 Enables/dispatching the scalar code path. More...
 
#define XXH_DISPATCH_AVX2   0
 Enables/disables dispatching for AVX2. More...
 
#define XXH_DISPATCH_AVX512   0
 Enables/disables dispatching for AVX512. More...
 
#define XXH_TARGET_SSE2   /* disable attribute target */
 Allows a function to be compiled with SSE2 intrinsics. More...
 
#define XXH_TARGET_AVX2   /* disable attribute target */
 Like XXH_TARGET_SSE2, but for AVX2.
 
#define XXH_TARGET_AVX512   /* disable attribute target */
 Like XXH_TARGET_SSE2, but for AVX512.
 
#define XXH_debugPrint(str)   ((void)0)
 
#define NDEBUG
 
#define XXH_INLINE_ALL
 
#define XXH_X86DISPATCH
 
#define XXH_I_ATT(intel, att)   "{" att "|" intel "}\n\t"
 
#define XXH_SSE2_CPUID_MASK   (1 << 26)
 
#define XXH_OSXSAVE_CPUID_MASK   ((1 << 26) | (1 << 27))
 
#define XXH_AVX2_CPUID_MASK   (1 << 5)
 
#define XXH_AVX2_XGETBV_MASK   ((1 << 2) | (1 << 1))
 
#define XXH_AVX512F_CPUID_MASK   (1 << 16)
 
#define XXH_AVX512F_XGETBV_MASK   ((7 << 5) | (1 << 2) | (1 << 1))
 
#define XXH_DEFINE_DISPATCH_FUNCS(suffix, target)
 Defines the various dispatch functions. More...
 
#define XXH_NB_DISPATCHES   4
 

Typedefs

typedef XXH64_hash_t(* XXH3_dispatchx86_hashLong64_default) (const void *restrict, size_t)
 
typedef XXH64_hash_t(* XXH3_dispatchx86_hashLong64_withSeed) (const void *restrict, size_t, XXH64_hash_t)
 
typedef XXH64_hash_t(* XXH3_dispatchx86_hashLong64_withSecret) (const void *restrict, size_t, const void *restrict, size_t)
 
typedef XXH_errorcode(* XXH3_dispatchx86_update) (XXH3_state_t *, const void *, size_t)
 
typedef XXH128_hash_t(* XXH3_dispatchx86_hashLong128_default) (const void *restrict, size_t)
 
typedef XXH128_hash_t(* XXH3_dispatchx86_hashLong128_withSeed) (const void *restrict, size_t, XXH64_hash_t)
 
typedef XXH128_hash_t(* XXH3_dispatchx86_hashLong128_withSecret) (const void *restrict, size_t, const void *restrict, size_t)
 

Functions

static void XXH_cpuid (xxh_u32 eax, xxh_u32 ecx, xxh_u32 *abcd)
 Runs CPUID. More...
 
static int XXH_featureTest (void)
 Returns the best XXH3 implementation. More...
 
static void XXH_setDispatch (void)
 Runs a CPUID check and sets the correct dispatch tables. More...
 
static XXH64_hash_t XXH3_hashLong_64b_defaultSecret_selection (const void *input, size_t len, XXH64_hash_t seed64, const xxh_u8 *secret, size_t secretLen)
 
XXH64_hash_t XXH3_64bits_dispatch (const void *input, size_t len)
 
static XXH64_hash_t XXH3_hashLong_64b_withSeed_selection (const void *input, size_t len, XXH64_hash_t seed64, const xxh_u8 *secret, size_t secretLen)
 
XXH64_hash_t XXH3_64bits_withSeed_dispatch (const void *input, size_t len, XXH64_hash_t seed)
 
static XXH64_hash_t XXH3_hashLong_64b_withSecret_selection (const void *input, size_t len, XXH64_hash_t seed64, const xxh_u8 *secret, size_t secretLen)
 
XXH64_hash_t XXH3_64bits_withSecret_dispatch (const void *input, size_t len, const void *secret, size_t secretLen)
 
XXH_errorcode XXH3_64bits_update_dispatch (XXH3_state_t *state, const void *input, size_t len)
 
static XXH128_hash_t XXH3_hashLong_128b_defaultSecret_selection (const void *input, size_t len, XXH64_hash_t seed64, const void *secret, size_t secretLen)
 
XXH128_hash_t XXH3_128bits_dispatch (const void *input, size_t len)
 
static XXH128_hash_t XXH3_hashLong_128b_withSeed_selection (const void *input, size_t len, XXH64_hash_t seed64, const void *secret, size_t secretLen)
 
XXH128_hash_t XXH3_128bits_withSeed_dispatch (const void *input, size_t len, XXH64_hash_t seed)
 
static XXH128_hash_t XXH3_hashLong_128b_withSecret_selection (const void *input, size_t len, XXH64_hash_t seed64, const void *secret, size_t secretLen)
 
XXH128_hash_t XXH3_128bits_withSecret_dispatch (const void *input, size_t len, const void *secret, size_t secretLen)
 
XXH_errorcode XXH3_128bits_update_dispatch (XXH3_state_t *state, const void *input, size_t len)
 

Variables

static const XXH_dispatchFunctions_s XXH_kDispatch [XXH_NB_DISPATCHES]
 Table of dispatchers for XXH3_64bits(). More...
 
static XXH_dispatchFunctions_s XXH_g_dispatch = { NULL, NULL, NULL, NULL }
 The selected dispatch table for XXH3_64bits(). More...
 
static const XXH_dispatch128Functions_s XXH_kDispatch128 [XXH_NB_DISPATCHES]
 Table of dispatchers for XXH3_128bits(). More...
 
static XXH_dispatch128Functions_s XXH_g_dispatch128 = { NULL, NULL, NULL, NULL }
 The selected dispatch table for XXH3_64bits(). More...
 

Detailed Description

Macro Definition Documentation

◆ XXH_X86DISPATCH_ALLOW_AVX

#define XXH_X86DISPATCH_ALLOW_AVX

Disables the AVX sanity check.

Don't compile xxh_x86dispatch.c with options like -mavx*, -march=native, or /arch:AVX*. It is intended to be compiled for the minimum target, and it selectively enables SSE2, AVX2, and AVX512 when it is needed.

Using this option globally allows this feature, and therefore makes it undefined behavior to execute on any CPU without said feature.

Even if the source code isn't directly using AVX intrinsics in a function, the compiler can still generate AVX code from autovectorization and by "upgrading" SSE2 intrinsics to use the VEX prefixes (a.k.a. AVX128).

Use the same flags that you use to compile the rest of the program; this file will safely generate SSE2, AVX2, and AVX512 without these flags.

Define XXH_X86DISPATCH_ALLOW_AVX to ignore this check, and feel free to open an issue if there is a target in the future where AVX is a default feature.

◆ XXH_DISPATCH_SCALAR

#define XXH_DISPATCH_SCALAR   1

Enables/dispatching the scalar code path.

If this is defined to 0, SSE2 support is assumed. This reduces code size when the scalar path is not needed.

This is automatically defined to 0 when...

  • SSE2 support is enabled in the compiler
  • Targeting x86_64
  • Targeting Android x86
  • Targeting macOS

◆ XXH_DISPATCH_AVX2

#define XXH_DISPATCH_AVX2   0

Enables/disables dispatching for AVX2.

This is automatically detected if it is not defined.

  • GCC 4.7 and later are known to support AVX2, but >4.9 is required for to get the AVX2 intrinsics and typedefs without -mavx -mavx2.
  • Visual Studio 2013 Update 2 and later are known to support AVX2.
  • The GCC/Clang internal header <avx2intrin.h> is detected. While this is not allowed to be included directly, it still appears in the builtin include path and is detectable with __has_include.
See also
XXH_AVX2

◆ XXH_DISPATCH_AVX512

#define XXH_DISPATCH_AVX512   0

Enables/disables dispatching for AVX512.

Automatically detected if one of the following conditions is met:

  • GCC 4.9 and later are known to support AVX512.
  • Visual Studio 2017 and later are known to support AVX2.
  • The GCC/Clang internal header <avx512fintrin.h> is detected. While this is not allowed to be included directly, it still appears in the builtin include path and is detectable with __has_include.
See also
XXH_AVX512

◆ XXH_TARGET_SSE2

#define XXH_TARGET_SSE2   /* disable attribute target */

Allows a function to be compiled with SSE2 intrinsics.

Uses __attribute__((__target__("sse2"))) on GCC to allow SSE2 to be used even with -mno-sse2.

◆ XXH_DEFINE_DISPATCH_FUNCS

#define XXH_DEFINE_DISPATCH_FUNCS (   suffix,
  target 
)

Defines the various dispatch functions.

TODO: Consolidate?

Parameters
suffixThe suffix for the functions, e.g. sse2 or scalar
targetXXH_TARGET_* or empty.

Function Documentation

◆ XXH_cpuid()

static void XXH_cpuid ( xxh_u32  eax,
xxh_u32  ecx,
xxh_u32 *  abcd 
)
static

Runs CPUID.

Parameters
eax,ecxThe parameters to pass to CPUID, eax and ecx respectively.
abcdThe array to store the result in, { eax, ebx, ecx, edx }

◆ XXH_featureTest()

static int XXH_featureTest ( void  )
static

Returns the best XXH3 implementation.

Runs various CPUID/XGETBV tests to try and determine the best implementation.

@ret The best XXH_VECTOR implementation.

See also
XXH_VECTOR_TYPES

◆ XXH_setDispatch()

static void XXH_setDispatch ( void  )
static

Runs a CPUID check and sets the correct dispatch tables.

Variable Documentation

◆ XXH_kDispatch

const XXH_dispatchFunctions_s XXH_kDispatch[XXH_NB_DISPATCHES]
static
Initial value:
= {
{ XXHL64_default_scalar, XXHL64_seed_scalar, XXHL64_secret_scalar, XXH3_update_scalar },
{ XXHL64_default_sse2, XXHL64_seed_sse2, XXHL64_secret_sse2, XXH3_update_sse2 },
{ NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL }
}

Table of dispatchers for XXH3_64bits().

Precondition
The indices must match XXH_VECTOR_TYPE.

◆ XXH_g_dispatch

XXH_dispatchFunctions_s XXH_g_dispatch = { NULL, NULL, NULL, NULL }
static

The selected dispatch table for XXH3_64bits().

◆ XXH_kDispatch128

const XXH_dispatch128Functions_s XXH_kDispatch128[XXH_NB_DISPATCHES]
static
Initial value:
= {
{ XXHL128_default_scalar, XXHL128_seed_scalar, XXHL128_secret_scalar, XXH3_update_scalar },
{ XXHL128_default_sse2, XXHL128_seed_sse2, XXHL128_secret_sse2, XXH3_update_sse2 },
{ NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL }
}

Table of dispatchers for XXH3_128bits().

Precondition
The indices must match XXH_VECTOR_TYPE.

◆ XXH_g_dispatch128

XXH_dispatch128Functions_s XXH_g_dispatch128 = { NULL, NULL, NULL, NULL }
static

The selected dispatch table for XXH3_64bits().