xxHash  0.8.0
Extremely fast non-cryptographic hash function
Modules | Macros | Typedefs | Enumerations | Functions
Implementation

Modules

 XXH32 implementation
 
 XXH64 implementation
 
 XXH3 implementation
 

Macros

#define XXH_FORCE_INLINE   static
 
#define XXH_NO_INLINE   static
 
#define XXH_ASSERT(c)   ((void)0)
 
#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)
 Used to prevent unwanted optimizations for var. More...
 
#define XXH_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)
 
#define XXH_HAS_BUILTIN(x)   0
 
#define XXH_rotl32(x, r)   (((x) << (r)) | ((x) >> (32 - (r))))
 32-bit rotate left. More...
 
#define XXH_rotl64(x, r)   (((x) << (r)) | ((x) >> (64 - (r))))
 

Typedefs

typedef unsigned char xxh_u8
 
typedef XXH32_hash_t xxh_u32
 

Enumerations

enum  XXH_alignment { XXH_aligned , XXH_unaligned }
 Enum to indicate whether a pointer is aligned. More...
 

Functions

static void * XXH_malloc (size_t s)
 Modify this function to use a different routine than malloc(). More...
 
static void XXH_free (void *p)
 Modify this function to use a different routine than free(). More...
 
static void * XXH_memcpy (void *dest, const void *src, size_t size)
 Modify this function to use a different routine than memcpy(). More...
 
static xxh_u32 XXH_read32 (const void *memPtr)
 Reads an unaligned 32-bit integer from ptr in native endianness. More...
 
static int XXH_isLittleEndian (void)
 Runtime check for XXH_CPU_LITTLE_ENDIAN. More...
 
static xxh_u32 XXH_swap32 (xxh_u32 x)
 A 32-bit byteswap. More...
 
static xxh_u32 XXH_readLE32 (const void *ptr)
 Reads an unaligned 32-bit little endian integer from ptr. More...
 
static xxh_u32 XXH_readBE32 (const void *ptr)
 Reads an unaligned 32-bit big endian integer from ptr. More...
 
static xxh_u32 XXH_readLE32_align (const void *ptr, XXH_alignment align)
 Like XXH_readLE32(), but has an option for aligned reads. More...
 
typedef XXH64_hash_t xxh_u64
 
static xxh_u64 XXH_read64 (const void *memPtr)
 
static xxh_u64 XXH_swap64 (xxh_u64 x)
 
static xxh_u64 XXH_readLE64 (const void *ptr)
 
static xxh_u64 XXH_readBE64 (const void *ptr)
 
static xxh_u64 XXH_readLE64_align (const void *ptr, XXH_alignment align)
 

Detailed Description

Macro Definition Documentation

◆ XXH_COMPILER_GUARD

#define XXH_COMPILER_GUARD (   var)    ((void)0)

Used to prevent unwanted optimizations for var.

It uses an empty GCC inline assembly statement with a register constraint which forces var into a general purpose register (eg eax, ebx, ecx on x86) and marks it as modified.

This is used in a few places to avoid unwanted autovectorization (e.g. XXH32_round()). All vectorization we want is explicit via intrinsics, and usually isn't wanted elsewhere.

We also use it to prevent unwanted constant folding for AArch64 in XXH3_initCustomSecret_scalar().

◆ XXH_rotl32

#define XXH_rotl32 (   x,
 
)    (((x) << (r)) | ((x) >> (32 - (r))))

32-bit rotate left.

Parameters
xThe 32-bit integer to be rotated.
rThe number of bits to rotate.
Precondition
r > 0 && r < 32
Note
x and r may be evaluated multiple times.
Returns
The rotated result.

Enumeration Type Documentation

◆ XXH_alignment

Enum to indicate whether a pointer is aligned.

Enumerator
XXH_aligned 

Aligned

XXH_unaligned 

Possibly unaligned

Function Documentation

◆ XXH_malloc()

static void* XXH_malloc ( size_t  s)
static

Modify this function to use a different routine than malloc().

◆ XXH_free()

static void XXH_free ( void *  p)
static

Modify this function to use a different routine than free().

◆ XXH_memcpy()

static void* XXH_memcpy ( void *  dest,
const void *  src,
size_t  size 
)
static

Modify this function to use a different routine than memcpy().

◆ XXH_read32()

xxh_u32 XXH_read32 ( const void *  ptr)
static

Reads an unaligned 32-bit integer from ptr in native endianness.

Affected by XXH_FORCE_MEMORY_ACCESS.

Parameters
ptrThe pointer to read from.
Returns
The 32-bit native endian integer from the bytes at ptr.

◆ XXH_isLittleEndian()

static int XXH_isLittleEndian ( void  )
static

Runtime check for XXH_CPU_LITTLE_ENDIAN.

Most compilers will constant fold this.

◆ XXH_swap32()

xxh_u32 XXH_swap32 ( xxh_u32  x)
static

A 32-bit byteswap.

Parameters
xThe 32-bit integer to byteswap.
Returns
x, byteswapped.

◆ XXH_readLE32()

xxh_u32 XXH_readLE32 ( const void *  ptr)
inlinestatic

Reads an unaligned 32-bit little endian integer from ptr.

Affected by XXH_FORCE_MEMORY_ACCESS.

Parameters
ptrThe pointer to read from.
Returns
The 32-bit little endian integer from the bytes at ptr.

◆ XXH_readBE32()

xxh_u32 XXH_readBE32 ( const void *  ptr)
static

Reads an unaligned 32-bit big endian integer from ptr.

Affected by XXH_FORCE_MEMORY_ACCESS.

Parameters
ptrThe pointer to read from.
Returns
The 32-bit big endian integer from the bytes at ptr.

◆ XXH_readLE32_align()

xxh_u32 XXH_readLE32_align ( const void *  ptr,
XXH_alignment  align 
)
inlinestatic

Like XXH_readLE32(), but has an option for aligned reads.

Affected by XXH_FORCE_MEMORY_ACCESS. Note that when XXH_FORCE_ALIGN_CHECK == 0, the align parameter is always XXH_alignment::XXH_unaligned.

Parameters
ptrThe pointer to read from.
alignWhether ptr is aligned.
Precondition
If align == XXH_alignment::XXH_aligned, ptr must be 4 byte aligned.
Returns
The 32-bit little endian integer from the bytes at ptr.