Rizin
unix-like reverse engineering framework and cli tools
xxhash.c File Reference
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "xxhash.h"

Go to the source code of this file.

Macros

#define XXH_ACCEPT_NULL_INPUT_POINTER   0
 
#define XXH_FORCE_NATIVE_FORMAT   0
 
#define XXH_FORCE_ALIGN_CHECK   1
 
#define XXH_STATIC_LINKING_ONLY
 
#define FORCE_INLINE   static
 
#define XXH_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)
 
#define XXH_rotl32(x, r)   ((x << r) | (x >> (32 - r)))
 
#define XXH_rotl64(x, r)   ((x << r) | (x >> (64 - r)))
 
#define XXH_CPU_LITTLE_ENDIAN   XXH_isLittleEndian()
 
#define XXH_STATIC_ASSERT(c)   { enum { XXH_sa = 1/(int)(!!(c)) }; } /* use after variable declarations */
 
#define XXH_get32bits(p)   XXH_readLE32_align(p, endian, align)
 
#define PROCESS1
 
#define PROCESS4
 
#define MEM_MODULE
 
#define XXH_get64bits(p)   XXH_readLE64_align(p, endian, align)
 
#define PROCESS1_64
 
#define PROCESS4_64
 
#define PROCESS8_64
 

Typedefs

typedef unsigned char BYTE
 
typedef unsigned short U16
 
typedef unsigned int U32
 
typedef unsigned long long U64
 

Enumerations

enum  XXH_endianess { XXH_bigEndian =0 , XXH_littleEndian =1 , XXH_bigEndian =0 , XXH_littleEndian =1 }
 
enum  XXH_alignment { XXH_aligned , XXH_unaligned , XXH_aligned , XXH_unaligned }
 

Functions

static void * XXH_malloc (size_t s)
 
static void XXH_free (void *p)
 
static void * XXH_memcpy (void *dest, const void *src, size_t size)
 
static U32 XXH_read32 (const void *memPtr)
 
static U32 XXH_swap32 (U32 x)
 
static int XXH_isLittleEndian (void)
 
FORCE_INLINE U32 XXH_readLE32_align (const void *ptr, XXH_endianess endian, XXH_alignment align)
 
FORCE_INLINE U32 XXH_readLE32 (const void *ptr, XXH_endianess endian)
 
static U32 XXH_readBE32 (const void *ptr)
 
XXH_PUBLIC_API unsigned XXH_versionNumber (void)
 
static U32 XXH32_round (U32 seed, U32 input)
 
static U32 XXH32_avalanche (U32 h32)
 
static U32 XXH32_finalize (U32 h32, const void *ptr, size_t len, XXH_endianess endian, XXH_alignment align)
 
FORCE_INLINE U32 XXH32_endian_align (const void *input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
 
XXH_PUBLIC_API unsigned int XXH32 (const void *input, size_t len, unsigned int seed)
 
XXH_PUBLIC_API XXH32_state_tXXH32_createState (void)
 
XXH_PUBLIC_API XXH_errorcode XXH32_freeState (XXH32_state_t *statePtr)
 
XXH_PUBLIC_API void XXH32_copyState (XXH32_state_t *dstState, const XXH32_state_t *srcState)
 
XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t *statePtr, unsigned int seed)
 
FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t *state, const void *input, size_t len, XXH_endianess endian)
 
XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t *state_in, const void *input, size_t len)
 
FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t *state, XXH_endianess endian)
 
XXH_PUBLIC_API unsigned int XXH32_digest (const XXH32_state_t *state_in)
 
XXH_PUBLIC_API void XXH32_canonicalFromHash (XXH32_canonical_t *dst, XXH32_hash_t hash)
 
XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical (const XXH32_canonical_t *src)
 
static U64 XXH_read64 (const void *memPtr)
 
static U64 XXH_swap64 (U64 x)
 
FORCE_INLINE U64 XXH_readLE64_align (const void *ptr, XXH_endianess endian, XXH_alignment align)
 
FORCE_INLINE U64 XXH_readLE64 (const void *ptr, XXH_endianess endian)
 
static U64 XXH_readBE64 (const void *ptr)
 
static U64 XXH64_round (U64 acc, U64 input)
 
static U64 XXH64_mergeRound (U64 acc, U64 val)
 
static U64 XXH64_avalanche (U64 h64)
 
static U64 XXH64_finalize (U64 h64, const void *ptr, size_t len, XXH_endianess endian, XXH_alignment align)
 
FORCE_INLINE U64 XXH64_endian_align (const void *input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
 
XXH_PUBLIC_API unsigned long long XXH64 (const void *input, size_t len, unsigned long long seed)
 
XXH_PUBLIC_API XXH64_state_tXXH64_createState (void)
 
XXH_PUBLIC_API XXH_errorcode XXH64_freeState (XXH64_state_t *statePtr)
 
XXH_PUBLIC_API void XXH64_copyState (XXH64_state_t *dstState, const XXH64_state_t *srcState)
 
XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t *statePtr, unsigned long long seed)
 
FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t *state, const void *input, size_t len, XXH_endianess endian)
 
XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t *state_in, const void *input, size_t len)
 
FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t *state, XXH_endianess endian)
 
XXH_PUBLIC_API unsigned long long XXH64_digest (const XXH64_state_t *state_in)
 
XXH_PUBLIC_API void XXH64_canonicalFromHash (XXH64_canonical_t *dst, XXH64_hash_t hash)
 
XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical (const XXH64_canonical_t *src)
 

Variables

static const U32 PRIME32_1 = 2654435761U
 
static const U32 PRIME32_2 = 2246822519U
 
static const U32 PRIME32_3 = 3266489917U
 
static const U32 PRIME32_4 = 668265263U
 
static const U32 PRIME32_5 = 374761393U
 
static const U64 PRIME64_1 = 11400714785074694791ULL
 
static const U64 PRIME64_2 = 14029467366897019727ULL
 
static const U64 PRIME64_3 = 1609587929392839161ULL
 
static const U64 PRIME64_4 = 9650029242287828579ULL
 
static const U64 PRIME64_5 = 2870177450012600261ULL
 

Macro Definition Documentation

◆ FORCE_INLINE

#define FORCE_INLINE   static

Definition at line 137 of file xxhash.c.

◆ MEM_MODULE

#define MEM_MODULE

Definition at line 589 of file xxhash.c.

◆ PROCESS1

#define PROCESS1
Value:
h32 += (*p) * PRIME32_5; \
p++; \
h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
static const U32 PRIME32_5
Definition: xxhash.c:270
static const U32 PRIME32_1
Definition: xxhash.c:266
#define XXH_rotl32(x, r)
Definition: xxhash.c:197

◆ PROCESS1_64

#define PROCESS1_64
Value:
h64 ^= (*p) * PRIME64_5; \
p++; \
h64 = XXH_rotl64(h64, 11) * PRIME64_1;
#define XXH_rotl64(x, r)
Definition: xxhash.c:198
static const U64 PRIME64_5
Definition: xxhash.c:672
static const U64 PRIME64_1
Definition: xxhash.c:668

◆ PROCESS4

#define PROCESS4
Value:
h32 += XXH_get32bits(p) * PRIME32_3; \
p+=4; \
h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
void * p
Definition: libc.cpp:67
static const U32 PRIME32_3
Definition: xxhash.c:268
static const U32 PRIME32_4
Definition: xxhash.c:269
#define XXH_get32bits(p)
Definition: xxhash.c:291

◆ PROCESS4_64

#define PROCESS4_64
Value:
h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1; \
p+=4; \
h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
unsigned long long U64
Definition: xxhash.c:595
static const U64 PRIME64_2
Definition: xxhash.c:669
static const U64 PRIME64_3
Definition: xxhash.c:670

◆ PROCESS8_64

#define PROCESS8_64
Value:
{ \
U64 const k1 = XXH64_round(0, XXH_get64bits(p)); \
p+=8; \
h64 ^= k1; \
h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; \
}
static const U64 PRIME64_4
Definition: xxhash.c:671
#define XXH_get64bits(p)
Definition: xxhash.c:701
static U64 XXH64_round(U64 acc, U64 input)
Definition: xxhash.c:674

◆ XXH_ACCEPT_NULL_INPUT_POINTER

#define XXH_ACCEPT_NULL_INPUT_POINTER   0

XXH_FORCE_MEMORY_ACCESS : By default, access to unaligned memory is controlled by memcpy(), which is safe and portable. Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. The below switch allow to select different access method for improved performance. Method 0 (default) : use memcpy(). Safe and portable. Method 1 : __packed statement. It depends on compiler extension (ie, not portable). This method is safe if your compiler supports it, and generally as fast or faster than memcpy. Method 2 : direct access. This method doesn't depend on compiler but violate C standard. It can generate buggy code on targets which do not support unaligned memory accesses. But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6) See http://stackoverflow.com/a/32095106/646947 for details. Prefer these methods in priority order (0 > 1 > 2)

XXH_ACCEPT_NULL_INPUT_POINTER : If input pointer is NULL, xxHash default behavior is to dereference it, triggering a segfault. When this macro is enabled, xxHash actively checks input for null pointer. It it is, result for null input pointers is the same as a null-length input.

Definition at line 74 of file xxhash.c.

◆ XXH_CPU_LITTLE_ENDIAN

#define XXH_CPU_LITTLE_ENDIAN   XXH_isLittleEndian()

Definition at line 228 of file xxhash.c.

◆ XXH_FORCE_ALIGN_CHECK

#define XXH_FORCE_ALIGN_CHECK   1

XXH_FORCE_ALIGN_CHECK : This is a minor performance trick, only useful with lots of very small keys. It means : check for aligned/unaligned input. The check costs one initial branch per hash; set it to 0 when the input is guaranteed to be aligned, or when alignment doesn't matter for performance.

Definition at line 100 of file xxhash.c.

◆ XXH_FORCE_NATIVE_FORMAT

#define XXH_FORCE_NATIVE_FORMAT   0

XXH_FORCE_NATIVE_FORMAT : By default, xxHash library provides endian-independent Hash values, based on little-endian convention. Results are therefore identical for little-endian and big-endian CPU. This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format. Should endian-independence be of no importance for your application, you may set the #define below to 1, to improve speed for Big-endian CPU. This option has no impact on Little_Endian CPU.

Definition at line 86 of file xxhash.c.

◆ XXH_GCC_VERSION

#define XXH_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)

Definition at line 190 of file xxhash.c.

◆ XXH_get32bits

#define XXH_get32bits (   p)    XXH_readLE32_align(p, endian, align)

Definition at line 291 of file xxhash.c.

◆ XXH_get64bits

#define XXH_get64bits (   p)    XXH_readLE64_align(p, endian, align)

Definition at line 701 of file xxhash.c.

◆ XXH_rotl32

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

Definition at line 197 of file xxhash.c.

◆ XXH_rotl64

#define XXH_rotl64 (   x,
  r 
)    ((x << r) | (x >> (64 - r)))

Definition at line 198 of file xxhash.c.

◆ XXH_STATIC_ASSERT

#define XXH_STATIC_ASSERT (   c)    { enum { XXH_sa = 1/(int)(!!(c)) }; } /* use after variable declarations */

Definition at line 259 of file xxhash.c.

◆ XXH_STATIC_LINKING_ONLY

#define XXH_STATIC_LINKING_ONLY

Definition at line 119 of file xxhash.c.

Typedef Documentation

◆ BYTE

typedef unsigned char BYTE

Definition at line 154 of file xxhash.c.

◆ U16

typedef unsigned short U16

Definition at line 155 of file xxhash.c.

◆ U32

typedef unsigned int U32

Definition at line 156 of file xxhash.c.

◆ U64

typedef unsigned long long U64

Definition at line 597 of file xxhash.c.

Enumeration Type Documentation

◆ XXH_alignment

Enumerator
XXH_aligned 
XXH_unaligned 
XXH_aligned 
XXH_unaligned 

Definition at line 235 of file xxhash.c.

XXH_alignment
Definition: xxhash.c:232
@ XXH_aligned
Definition: xxhash.c:232
@ XXH_unaligned
Definition: xxhash.c:232

◆ XXH_endianess

Enumerator
XXH_bigEndian 
XXH_littleEndian 
XXH_bigEndian 
XXH_littleEndian 

Definition at line 219 of file xxhash.c.

XXH_endianess
Definition: xxhash.c:216
@ XXH_littleEndian
Definition: xxhash.c:216
@ XXH_bigEndian
Definition: xxhash.c:216

Function Documentation

◆ XXH32()

XXH_PUBLIC_API unsigned int XXH32 ( const void *  input,
size_t  length,
unsigned int  seed 
)

XXH32() : Calculate the 32-bit hash of sequence "length" bytes stored at memory address "input". The memory between input & input+length must be valid (allocated and read-accessible). "seed" can be used to alter the result predictably. Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s

Definition at line 395 of file xxhash.c.

396 {
397 #if 0
398  /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
400  XXH32_reset(&state, seed);
402  return XXH32_digest(&state);
403 #else
405 
406  if (XXH_FORCE_ALIGN_CHECK) {
407  if ((((size_t)input) & 3) == 0) { /* Input is 4-bytes aligned, leverage the speed benefit */
408  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
410  else
412  } }
413 
414  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
416  else
418 #endif
419 }
size_t len
Definition: 6502dis.c:15
XXH_PUBLIC_API unsigned int XXH32_digest(const XXH32_state_t *state_in)
Definition: xxhash.c:546
FORCE_INLINE U32 XXH32_endian_align(const void *input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
Definition: xxhash.c:352
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t *statePtr, unsigned int seed)
Definition: xxhash.c:437
XXH_PUBLIC_API XXH_errorcode XXH32_update(XXH32_state_t *state_in, const void *input, size_t len)
Definition: xxhash.c:515
struct XXH32_state_s XXH32_state_t
Definition: xxhash.h:172
Definition: dis.h:43
#define XXH_CPU_LITTLE_ENDIAN
Definition: xxhash.c:228
#define XXH_FORCE_ALIGN_CHECK
Definition: xxhash.c:100
#define XXH_FORCE_NATIVE_FORMAT
Definition: xxhash.c:86
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References input(), len, XXH32_digest(), XXH32_endian_align(), XXH32_reset(), XXH32_update(), XXH_aligned, XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_ALIGN_CHECK, XXH_FORCE_NATIVE_FORMAT, XXH_littleEndian, and XXH_unaligned.

◆ XXH32_avalanche()

static U32 XXH32_avalanche ( U32  h32)
static

Definition at line 281 of file xxhash.c.

282 {
283  h32 ^= h32 >> 15;
284  h32 *= PRIME32_2;
285  h32 ^= h32 >> 13;
286  h32 *= PRIME32_3;
287  h32 ^= h32 >> 16;
288  return(h32);
289 }
static const U32 PRIME32_2
Definition: xxhash.c:267

References PRIME32_2, and PRIME32_3.

Referenced by XXH32_finalize().

◆ XXH32_canonicalFromHash()

XXH_PUBLIC_API void XXH32_canonicalFromHash ( XXH32_canonical_t dst,
XXH32_hash_t  hash 
)

Default XXH result types are basic unsigned 32 and 64 bits. The canonical representation follows human-readable write convention, aka big-endian (large digits first). These functions allow transformation of hash result into and from its canonical format. This way, hash values can be written into a file or buffer, remaining comparable across different systems.

Definition at line 567 of file xxhash.c.

568 {
570  if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
571  memcpy(dst, &hash, sizeof(*dst));
572 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
unsigned int XXH32_hash_t
Definition: xxhash.h:162
char * dst
Definition: lz4.h:724
#define XXH_STATIC_ASSERT(c)
Definition: xxhash.c:259
static U32 XXH_swap32(U32 x)
Definition: xxhash.c:206

References dst, memcpy(), XXH_CPU_LITTLE_ENDIAN, XXH_STATIC_ASSERT, and XXH_swap32().

◆ XXH32_copyState()

XXH_PUBLIC_API void XXH32_copyState ( XXH32_state_t dstState,
const XXH32_state_t srcState 
)

Definition at line 435 of file xxhash.c.

436 {
437  memcpy(dstState, srcState, sizeof(*dstState));
438 }

References memcpy().

◆ XXH32_createState()

XXH_PUBLIC_API XXH32_state_t* XXH32_createState ( void  )

Definition at line 425 of file xxhash.c.

426 {
427  return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t));
428 }
static void * XXH_malloc(size_t s)
Definition: xxhash.c:111

References XXH_malloc().

◆ XXH32_digest()

XXH_PUBLIC_API unsigned int XXH32_digest ( const XXH32_state_t state_in)

Definition at line 548 of file xxhash.c.

549 {
551 
552  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
553  return XXH32_digest_endian(state_in, XXH_littleEndian);
554  else
555  return XXH32_digest_endian(state_in, XXH_bigEndian);
556 }
FORCE_INLINE U32 XXH32_digest_endian(const XXH32_state_t *state, XXH_endianess endian)
Definition: xxhash.c:527

References XXH32_digest_endian(), XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_NATIVE_FORMAT, and XXH_littleEndian.

◆ XXH32_digest_endian()

FORCE_INLINE U32 XXH32_digest_endian ( const XXH32_state_t state,
XXH_endianess  endian 
)

Definition at line 529 of file xxhash.c.

530 {
531  U32 h32;
532 
533  if (state->large_len) {
534  h32 = XXH_rotl32(state->v1, 1)
535  + XXH_rotl32(state->v2, 7)
536  + XXH_rotl32(state->v3, 12)
537  + XXH_rotl32(state->v4, 18);
538  } else {
539  h32 = state->v3 /* == seed */ + PRIME32_5;
540  }
541 
542  h32 += state->total_len_32;
543 
544  return XXH32_finalize(h32, state->mem32, state->memsize, endian, XXH_aligned);
545 }
unsigned int U32
Definition: lz4.c:288
static U32 XXH32_finalize(U32 h32, const void *ptr, size_t len, XXH_endianess endian, XXH_alignment align)
Definition: xxhash.c:294

References PRIME32_5, XXH32_finalize(), XXH_aligned, and XXH_rotl32.

◆ XXH32_endian_align()

FORCE_INLINE U32 XXH32_endian_align ( const void *  input,
size_t  len,
U32  seed,
XXH_endianess  endian,
XXH_alignment  align 
)

Definition at line 355 of file xxhash.c.

357 {
358  const BYTE* p = (const BYTE*)input;
359  const BYTE* bEnd = p + len;
360  U32 h32;
361 
362 #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
363  if (p==NULL) {
364  len=0;
365  bEnd=p=(const BYTE*)(size_t)16;
366  }
367 #endif
368 
369  if (len>=16) {
370  const BYTE* const limit = bEnd - 15;
371  U32 v1 = seed + PRIME32_1 + PRIME32_2;
372  U32 v2 = seed + PRIME32_2;
373  U32 v3 = seed + 0;
374  U32 v4 = seed - PRIME32_1;
375 
376  do {
377  v1 = XXH32_round(v1, XXH_get32bits(p)); p+=4;
378  v2 = XXH32_round(v2, XXH_get32bits(p)); p+=4;
379  v3 = XXH32_round(v3, XXH_get32bits(p)); p+=4;
380  v4 = XXH32_round(v4, XXH_get32bits(p)); p+=4;
381  } while (p < limit);
382 
383  h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7)
384  + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
385  } else {
386  h32 = seed + PRIME32_5;
387  }
388 
389  h32 += (U32)len;
390 
391  return XXH32_finalize(h32, p, len&15, endian, align);
392 }
#define NULL
Definition: cris-opc.c:27
@ v1
Definition: lanai.h:85
unsigned int U32
Definition: xxhash.c:153
unsigned char BYTE
Definition: lz4.c:286
static uint32_t const uint8_t uint32_t uint32_t limit
Definition: memcmplen.h:45
static U32 XXH32_round(U32 seed, U32 input)
Definition: xxhash.c:272

References input(), len, limit, NULL, p, PRIME32_1, PRIME32_2, PRIME32_5, v1, XXH32_finalize(), XXH32_round(), XXH_get32bits, and XXH_rotl32.

◆ XXH32_finalize()

static U32 XXH32_finalize ( U32  h32,
const void *  ptr,
size_t  len,
XXH_endianess  endian,
XXH_alignment  align 
)
static

Definition at line 294 of file xxhash.c.

297 {
298  const BYTE* p = (const BYTE*)ptr;
299 #define PROCESS1 \
300  h32 += (*p) * PRIME32_5; \
301  p++; \
302  h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
303 
304 #define PROCESS4 \
305  h32 += XXH_get32bits(p) * PRIME32_3; \
306  p+=4; \
307  h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
308 
309  switch(len&15) /* or switch(bEnd - p) */
310  {
311  case 12: PROCESS4;
312  /* fallthrough */
313  case 8: PROCESS4;
314  /* fallthrough */
315  case 4: PROCESS4;
316  return XXH32_avalanche(h32);
317 
318  case 13: PROCESS4;
319  /* fallthrough */
320  case 9: PROCESS4;
321  /* fallthrough */
322  case 5: PROCESS4;
323  PROCESS1;
324  return XXH32_avalanche(h32);
325 
326  case 14: PROCESS4;
327  /* fallthrough */
328  case 10: PROCESS4;
329  /* fallthrough */
330  case 6: PROCESS4;
331  PROCESS1;
332  PROCESS1;
333  return XXH32_avalanche(h32);
334 
335  case 15: PROCESS4;
336  /* fallthrough */
337  case 11: PROCESS4;
338  /* fallthrough */
339  case 7: PROCESS4;
340  /* fallthrough */
341  case 3: PROCESS1;
342  /* fallthrough */
343  case 2: PROCESS1;
344  /* fallthrough */
345  case 1: PROCESS1;
346  /* fallthrough */
347  case 0: return XXH32_avalanche(h32);
348  }
349  assert(0);
350  return h32; /* reaching this point is deemed impossible */
351 }
assert(limit<=UINT32_MAX/2)
#define PROCESS4
#define PROCESS1
static U32 XXH32_avalanche(U32 h32)
Definition: xxhash.c:281

References assert(), len, p, PROCESS1, PROCESS4, and XXH32_avalanche().

Referenced by XXH32_digest_endian(), and XXH32_endian_align().

◆ XXH32_freeState()

XXH_PUBLIC_API XXH_errorcode XXH32_freeState ( XXH32_state_t statePtr)

Definition at line 429 of file xxhash.c.

430 {
431  XXH_free(statePtr);
432  return XXH_OK;
433 }
@ XXH_OK
Definition: xxhash.h:79
static void XXH_free(void *p)
Definition: xxhash.c:112

References XXH_free(), and XXH_OK.

◆ XXH32_hashFromCanonical()

XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical ( const XXH32_canonical_t src)

Definition at line 574 of file xxhash.c.

575 {
576  return XXH_readBE32(src);
577 }
lzma_index * src
Definition: index.h:567
static U32 XXH_readBE32(const void *ptr)
Definition: xxhash.c:250

References src, and XXH_readBE32().

◆ XXH32_reset()

XXH_PUBLIC_API XXH_errorcode XXH32_reset ( XXH32_state_t statePtr,
unsigned int  seed 
)

Definition at line 440 of file xxhash.c.

441 {
442  XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
443  memset(&state, 0, sizeof(state));
444  state.v1 = seed + PRIME32_1 + PRIME32_2;
445  state.v2 = seed + PRIME32_2;
446  state.v3 = seed + 0;
447  state.v4 = seed - PRIME32_1;
448  /* do not write into reserved, planned to be removed in a future version */
449  memcpy(statePtr, &state, sizeof(state) - sizeof(state.reserved));
450  return XXH_OK;
451 }
return memset(p, 0, total)

References memcpy(), memset(), PRIME32_1, PRIME32_2, and XXH_OK.

◆ XXH32_round()

static U32 XXH32_round ( U32  seed,
U32  input 
)
static

Definition at line 272 of file xxhash.c.

273 {
274  seed += input * PRIME32_2;
275  seed = XXH_rotl32(seed, 13);
276  seed *= PRIME32_1;
277  return seed;
278 }

References input(), PRIME32_1, PRIME32_2, and XXH_rotl32.

Referenced by XXH32_endian_align(), and XXH32_update_endian().

◆ XXH32_update()

XXH_PUBLIC_API XXH_errorcode XXH32_update ( XXH32_state_t state_in,
const void *  input,
size_t  len 
)

Definition at line 517 of file xxhash.c.

518 {
520 
521  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
522  return XXH32_update_endian(state_in, input, len, XXH_littleEndian);
523  else
524  return XXH32_update_endian(state_in, input, len, XXH_bigEndian);
525 }
FORCE_INLINE XXH_errorcode XXH32_update_endian(XXH32_state_t *state, const void *input, size_t len, XXH_endianess endian)
Definition: xxhash.c:452

References input(), len, XXH32_update_endian(), XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_NATIVE_FORMAT, and XXH_littleEndian.

◆ XXH32_update_endian()

FORCE_INLINE XXH_errorcode XXH32_update_endian ( XXH32_state_t state,
const void *  input,
size_t  len,
XXH_endianess  endian 
)

Definition at line 455 of file xxhash.c.

456 {
457  const BYTE* p = (const BYTE*)input;
458  const BYTE* const bEnd = p + len;
459 
460  if (input==NULL)
461 #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
462  return XXH_OK;
463 #else
464  return XXH_ERROR;
465 #endif
466 
467  state->total_len_32 += (unsigned)len;
468  state->large_len |= (len>=16) | (state->total_len_32>=16);
469 
470  if (state->memsize + len < 16) { /* fill in tmp buffer */
471  XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len);
472  state->memsize += (unsigned)len;
473  return XXH_OK;
474  }
475 
476  if (state->memsize) { /* some data left from previous update */
477  XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, 16-state->memsize);
478  { const U32* p32 = state->mem32;
479  state->v1 = XXH32_round(state->v1, XXH_readLE32(p32, endian)); p32++;
480  state->v2 = XXH32_round(state->v2, XXH_readLE32(p32, endian)); p32++;
481  state->v3 = XXH32_round(state->v3, XXH_readLE32(p32, endian)); p32++;
482  state->v4 = XXH32_round(state->v4, XXH_readLE32(p32, endian));
483  }
484  p += 16-state->memsize;
485  state->memsize = 0;
486  }
487 
488  if (p <= bEnd-16) {
489  const BYTE* const limit = bEnd - 16;
490  U32 v1 = state->v1;
491  U32 v2 = state->v2;
492  U32 v3 = state->v3;
493  U32 v4 = state->v4;
494 
495  do {
496  v1 = XXH32_round(v1, XXH_readLE32(p, endian)); p+=4;
497  v2 = XXH32_round(v2, XXH_readLE32(p, endian)); p+=4;
498  v3 = XXH32_round(v3, XXH_readLE32(p, endian)); p+=4;
499  v4 = XXH32_round(v4, XXH_readLE32(p, endian)); p+=4;
500  } while (p<=limit);
501 
502  state->v1 = v1;
503  state->v2 = v2;
504  state->v3 = v3;
505  state->v4 = v4;
506  }
507 
508  if (p < bEnd) {
509  XXH_memcpy(state->mem32, p, (size_t)(bEnd-p));
510  state->memsize = (unsigned)(bEnd-p);
511  }
512 
513  return XXH_OK;
514 }
static void struct sockaddr socklen_t static fromlen static backlog static fork char char char static envp int struct rusage static rusage struct utsname static buf struct sembuf unsigned
Definition: sflib.h:97
FORCE_INLINE U32 XXH_readLE32(const void *ptr, XXH_endianess endian)
Definition: xxhash.c:242
@ XXH_ERROR
Definition: xxhash.h:79
static void * XXH_memcpy(void *dest, const void *src, size_t size)
Definition: xxhash.c:115

References input(), len, limit, NULL, p, unsigned, v1, XXH32_round(), XXH_ERROR, XXH_memcpy(), XXH_OK, and XXH_readLE32().

◆ XXH64()

XXH_PUBLIC_API unsigned long long XXH64 ( const void *  input,
size_t  length,
unsigned long long  seed 
)

XXH64() : Calculate the 64-bit hash of sequence of length "len" stored at memory address "input". "seed" can be used to alter the result predictably. This function runs faster on 64-bit systems, but slower on 32-bit systems (see benchmark).

Definition at line 858 of file xxhash.c.

859 {
860 #if 0
861  /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
863  XXH64_reset(&state, seed);
865  return XXH64_digest(&state);
866 #else
868 
869  if (XXH_FORCE_ALIGN_CHECK) {
870  if ((((size_t)input) & 7)==0) { /* Input is aligned, let's leverage the speed advantage */
871  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
873  else
875  } }
876 
877  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
879  else
881 #endif
882 }
XXH_PUBLIC_API XXH_errorcode XXH64_update(XXH64_state_t *state_in, const void *input, size_t len)
Definition: xxhash.c:971
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, unsigned long long seed)
Definition: xxhash.c:898
XXH_PUBLIC_API unsigned long long XXH64_digest(const XXH64_state_t *state_in)
Definition: xxhash.c:1005
FORCE_INLINE U64 XXH64_endian_align(const void *input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
Definition: xxhash.c:811
struct XXH64_state_s XXH64_state_t
Definition: xxhash.h:229

References input(), len, XXH64_digest(), XXH64_endian_align(), XXH64_reset(), XXH64_update(), XXH_aligned, XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_ALIGN_CHECK, XXH_FORCE_NATIVE_FORMAT, XXH_littleEndian, and XXH_unaligned.

◆ XXH64_avalanche()

static U64 XXH64_avalanche ( U64  h64)
static

Definition at line 690 of file xxhash.c.

691 {
692  h64 ^= h64 >> 33;
693  h64 *= PRIME64_2;
694  h64 ^= h64 >> 29;
695  h64 *= PRIME64_3;
696  h64 ^= h64 >> 32;
697  return h64;
698 }

References PRIME64_2, and PRIME64_3.

Referenced by XXH64_finalize().

◆ XXH64_canonicalFromHash()

XXH_PUBLIC_API void XXH64_canonicalFromHash ( XXH64_canonical_t dst,
XXH64_hash_t  hash 
)

Definition at line 1020 of file xxhash.c.

1021 {
1022  XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t));
1023  if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
1024  memcpy(dst, &hash, sizeof(*dst));
1025 }
unsigned long long XXH64_hash_t
Definition: xxhash.h:219
static U64 XXH_swap64(U64 x)
Definition: xxhash.c:634

References dst, memcpy(), XXH_CPU_LITTLE_ENDIAN, XXH_STATIC_ASSERT, and XXH_swap64().

◆ XXH64_copyState()

XXH_PUBLIC_API void XXH64_copyState ( XXH64_state_t dstState,
const XXH64_state_t srcState 
)

Definition at line 896 of file xxhash.c.

897 {
898  memcpy(dstState, srcState, sizeof(*dstState));
899 }

References memcpy().

◆ XXH64_createState()

XXH_PUBLIC_API XXH64_state_t* XXH64_createState ( void  )

Definition at line 886 of file xxhash.c.

887 {
888  return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t));
889 }

References XXH_malloc().

◆ XXH64_digest()

XXH_PUBLIC_API unsigned long long XXH64_digest ( const XXH64_state_t state_in)

Definition at line 1007 of file xxhash.c.

1008 {
1010 
1011  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
1012  return XXH64_digest_endian(state_in, XXH_littleEndian);
1013  else
1014  return XXH64_digest_endian(state_in, XXH_bigEndian);
1015 }
FORCE_INLINE U64 XXH64_digest_endian(const XXH64_state_t *state, XXH_endianess endian)
Definition: xxhash.c:981

References XXH64_digest_endian(), XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_NATIVE_FORMAT, and XXH_littleEndian.

◆ XXH64_digest_endian()

FORCE_INLINE U64 XXH64_digest_endian ( const XXH64_state_t state,
XXH_endianess  endian 
)

Definition at line 983 of file xxhash.c.

984 {
985  U64 h64;
986 
987  if (state->total_len >= 32) {
988  U64 const v1 = state->v1;
989  U64 const v2 = state->v2;
990  U64 const v3 = state->v3;
991  U64 const v4 = state->v4;
992 
993  h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
994  h64 = XXH64_mergeRound(h64, v1);
995  h64 = XXH64_mergeRound(h64, v2);
996  h64 = XXH64_mergeRound(h64, v3);
997  h64 = XXH64_mergeRound(h64, v4);
998  } else {
999  h64 = state->v3 /*seed*/ + PRIME64_5;
1000  }
1001 
1002  h64 += (U64) state->total_len;
1003 
1004  return XXH64_finalize(h64, state->mem64, (size_t)state->total_len, endian, XXH_aligned);
1005 }
unsigned long long U64
Definition: lz4.c:290
static U64 XXH64_finalize(U64 h64, const void *ptr, size_t len, XXH_endianess endian, XXH_alignment align)
Definition: xxhash.c:704
static U64 XXH64_mergeRound(U64 acc, U64 val)
Definition: xxhash.c:682

References PRIME64_5, v1, XXH64_finalize(), XXH64_mergeRound(), XXH_aligned, and XXH_rotl64.

◆ XXH64_endian_align()

FORCE_INLINE U64 XXH64_endian_align ( const void *  input,
size_t  len,
U64  seed,
XXH_endianess  endian,
XXH_alignment  align 
)

Definition at line 814 of file xxhash.c.

816 {
817  const BYTE* p = (const BYTE*)input;
818  const BYTE* bEnd = p + len;
819  U64 h64;
820 
821 #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
822  if (p==NULL) {
823  len=0;
824  bEnd=p=(const BYTE*)(size_t)32;
825  }
826 #endif
827 
828  if (len>=32) {
829  const BYTE* const limit = bEnd - 32;
830  U64 v1 = seed + PRIME64_1 + PRIME64_2;
831  U64 v2 = seed + PRIME64_2;
832  U64 v3 = seed + 0;
833  U64 v4 = seed - PRIME64_1;
834 
835  do {
836  v1 = XXH64_round(v1, XXH_get64bits(p)); p+=8;
837  v2 = XXH64_round(v2, XXH_get64bits(p)); p+=8;
838  v3 = XXH64_round(v3, XXH_get64bits(p)); p+=8;
839  v4 = XXH64_round(v4, XXH_get64bits(p)); p+=8;
840  } while (p<=limit);
841 
842  h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
843  h64 = XXH64_mergeRound(h64, v1);
844  h64 = XXH64_mergeRound(h64, v2);
845  h64 = XXH64_mergeRound(h64, v3);
846  h64 = XXH64_mergeRound(h64, v4);
847 
848  } else {
849  h64 = seed + PRIME64_5;
850  }
851 
852  h64 += (U64) len;
853 
854  return XXH64_finalize(h64, p, len, endian, align);
855 }

References input(), len, limit, NULL, p, PRIME64_1, PRIME64_2, PRIME64_5, v1, XXH64_finalize(), XXH64_mergeRound(), XXH64_round(), XXH_get64bits, and XXH_rotl64.

◆ XXH64_finalize()

static U64 XXH64_finalize ( U64  h64,
const void *  ptr,
size_t  len,
XXH_endianess  endian,
XXH_alignment  align 
)
static

Definition at line 704 of file xxhash.c.

706 {
707  const BYTE* p = (const BYTE*)ptr;
708 
709 #define PROCESS1_64 \
710  h64 ^= (*p) * PRIME64_5; \
711  p++; \
712  h64 = XXH_rotl64(h64, 11) * PRIME64_1;
713 
714 #define PROCESS4_64 \
715  h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1; \
716  p+=4; \
717  h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
718 
719 #define PROCESS8_64 { \
720  U64 const k1 = XXH64_round(0, XXH_get64bits(p)); \
721  p+=8; \
722  h64 ^= k1; \
723  h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; \
724 }
725 
726  switch(len&31) {
727  case 24: PROCESS8_64;
728  /* fallthrough */
729  case 16: PROCESS8_64;
730  /* fallthrough */
731  case 8: PROCESS8_64;
732  return XXH64_avalanche(h64);
733 
734  case 28: PROCESS8_64;
735  /* fallthrough */
736  case 20: PROCESS8_64;
737  /* fallthrough */
738  case 12: PROCESS8_64;
739  /* fallthrough */
740  case 4: PROCESS4_64;
741  return XXH64_avalanche(h64);
742 
743  case 25: PROCESS8_64;
744  /* fallthrough */
745  case 17: PROCESS8_64;
746  /* fallthrough */
747  case 9: PROCESS8_64;
748  PROCESS1_64;
749  return XXH64_avalanche(h64);
750 
751  case 29: PROCESS8_64;
752  /* fallthrough */
753  case 21: PROCESS8_64;
754  /* fallthrough */
755  case 13: PROCESS8_64;
756  /* fallthrough */
757  case 5: PROCESS4_64;
758  PROCESS1_64;
759  return XXH64_avalanche(h64);
760 
761  case 26: PROCESS8_64;
762  /* fallthrough */
763  case 18: PROCESS8_64;
764  /* fallthrough */
765  case 10: PROCESS8_64;
766  PROCESS1_64;
767  PROCESS1_64;
768  return XXH64_avalanche(h64);
769 
770  case 30: PROCESS8_64;
771  /* fallthrough */
772  case 22: PROCESS8_64;
773  /* fallthrough */
774  case 14: PROCESS8_64;
775  /* fallthrough */
776  case 6: PROCESS4_64;
777  PROCESS1_64;
778  PROCESS1_64;
779  return XXH64_avalanche(h64);
780 
781  case 27: PROCESS8_64;
782  /* fallthrough */
783  case 19: PROCESS8_64;
784  /* fallthrough */
785  case 11: PROCESS8_64;
786  PROCESS1_64;
787  PROCESS1_64;
788  PROCESS1_64;
789  return XXH64_avalanche(h64);
790 
791  case 31: PROCESS8_64;
792  /* fallthrough */
793  case 23: PROCESS8_64;
794  /* fallthrough */
795  case 15: PROCESS8_64;
796  /* fallthrough */
797  case 7: PROCESS4_64;
798  /* fallthrough */
799  case 3: PROCESS1_64;
800  /* fallthrough */
801  case 2: PROCESS1_64;
802  /* fallthrough */
803  case 1: PROCESS1_64;
804  /* fallthrough */
805  case 0: return XXH64_avalanche(h64);
806  }
807 
808  /* impossible to reach */
809  assert(0);
810  return 0; /* unreachable, but some compilers complain without it */
811 }
#define PROCESS4_64
static U64 XXH64_avalanche(U64 h64)
Definition: xxhash.c:690
#define PROCESS8_64
#define PROCESS1_64

References assert(), len, p, PROCESS1_64, PROCESS4_64, PROCESS8_64, and XXH64_avalanche().

Referenced by XXH64_digest_endian(), and XXH64_endian_align().

◆ XXH64_freeState()

XXH_PUBLIC_API XXH_errorcode XXH64_freeState ( XXH64_state_t statePtr)

Definition at line 890 of file xxhash.c.

891 {
892  XXH_free(statePtr);
893  return XXH_OK;
894 }

References XXH_free(), and XXH_OK.

◆ XXH64_hashFromCanonical()

XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical ( const XXH64_canonical_t src)

Definition at line 1027 of file xxhash.c.

1028 {
1029  return XXH_readBE64(src);
1030 }
static U64 XXH_readBE64(const void *ptr)
Definition: xxhash.c:660

References src, and XXH_readBE64().

◆ XXH64_mergeRound()

static U64 XXH64_mergeRound ( U64  acc,
U64  val 
)
static

Definition at line 682 of file xxhash.c.

683 {
684  val = XXH64_round(0, val);
685  acc ^= val;
686  acc = acc * PRIME64_1 + PRIME64_4;
687  return acc;
688 }
ut16 val
Definition: armass64_const.h:6

References PRIME64_1, PRIME64_4, val, and XXH64_round().

Referenced by XXH64_digest_endian(), and XXH64_endian_align().

◆ XXH64_reset()

XXH_PUBLIC_API XXH_errorcode XXH64_reset ( XXH64_state_t statePtr,
unsigned long long  seed 
)

Definition at line 901 of file xxhash.c.

902 {
903  XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
904  memset(&state, 0, sizeof(state));
905  state.v1 = seed + PRIME64_1 + PRIME64_2;
906  state.v2 = seed + PRIME64_2;
907  state.v3 = seed + 0;
908  state.v4 = seed - PRIME64_1;
909  /* do not write into reserved, planned to be removed in a future version */
910  memcpy(statePtr, &state, sizeof(state) - sizeof(state.reserved));
911  return XXH_OK;
912 }

References memcpy(), memset(), PRIME64_1, PRIME64_2, and XXH_OK.

◆ XXH64_round()

static U64 XXH64_round ( U64  acc,
U64  input 
)
static

Definition at line 674 of file xxhash.c.

675 {
676  acc += input * PRIME64_2;
677  acc = XXH_rotl64(acc, 31);
678  acc *= PRIME64_1;
679  return acc;
680 }

References input(), PRIME64_1, PRIME64_2, and XXH_rotl64.

Referenced by XXH64_endian_align(), XXH64_mergeRound(), and XXH64_update_endian().

◆ XXH64_update()

XXH_PUBLIC_API XXH_errorcode XXH64_update ( XXH64_state_t state_in,
const void *  input,
size_t  len 
)

Definition at line 973 of file xxhash.c.

974 {
976 
977  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
978  return XXH64_update_endian(state_in, input, len, XXH_littleEndian);
979  else
980  return XXH64_update_endian(state_in, input, len, XXH_bigEndian);
981 }
FORCE_INLINE XXH_errorcode XXH64_update_endian(XXH64_state_t *state, const void *input, size_t len, XXH_endianess endian)
Definition: xxhash.c:912

References input(), len, XXH64_update_endian(), XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_NATIVE_FORMAT, and XXH_littleEndian.

◆ XXH64_update_endian()

FORCE_INLINE XXH_errorcode XXH64_update_endian ( XXH64_state_t state,
const void *  input,
size_t  len,
XXH_endianess  endian 
)

Definition at line 915 of file xxhash.c.

916 {
917  const BYTE* p = (const BYTE*)input;
918  const BYTE* const bEnd = p + len;
919 
920  if (input==NULL)
921 #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
922  return XXH_OK;
923 #else
924  return XXH_ERROR;
925 #endif
926 
927  state->total_len += len;
928 
929  if (state->memsize + len < 32) { /* fill in tmp buffer */
930  XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
931  state->memsize += (U32)len;
932  return XXH_OK;
933  }
934 
935  if (state->memsize) { /* tmp buffer is full */
936  XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, 32-state->memsize);
937  state->v1 = XXH64_round(state->v1, XXH_readLE64(state->mem64+0, endian));
938  state->v2 = XXH64_round(state->v2, XXH_readLE64(state->mem64+1, endian));
939  state->v3 = XXH64_round(state->v3, XXH_readLE64(state->mem64+2, endian));
940  state->v4 = XXH64_round(state->v4, XXH_readLE64(state->mem64+3, endian));
941  p += 32-state->memsize;
942  state->memsize = 0;
943  }
944 
945  if (p+32 <= bEnd) {
946  const BYTE* const limit = bEnd - 32;
947  U64 v1 = state->v1;
948  U64 v2 = state->v2;
949  U64 v3 = state->v3;
950  U64 v4 = state->v4;
951 
952  do {
953  v1 = XXH64_round(v1, XXH_readLE64(p, endian)); p+=8;
954  v2 = XXH64_round(v2, XXH_readLE64(p, endian)); p+=8;
955  v3 = XXH64_round(v3, XXH_readLE64(p, endian)); p+=8;
956  v4 = XXH64_round(v4, XXH_readLE64(p, endian)); p+=8;
957  } while (p<=limit);
958 
959  state->v1 = v1;
960  state->v2 = v2;
961  state->v3 = v3;
962  state->v4 = v4;
963  }
964 
965  if (p < bEnd) {
966  XXH_memcpy(state->mem64, p, (size_t)(bEnd-p));
967  state->memsize = (unsigned)(bEnd-p);
968  }
969 
970  return XXH_OK;
971 }
FORCE_INLINE U64 XXH_readLE64(const void *ptr, XXH_endianess endian)
Definition: xxhash.c:653

References input(), len, limit, NULL, p, unsigned, v1, XXH64_round(), XXH_ERROR, XXH_memcpy(), XXH_OK, and XXH_readLE64().

◆ XXH_free()

static void XXH_free ( void *  p)
static

Definition at line 112 of file xxhash.c.

112 { free(p); }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free(), and p.

Referenced by XXH32_freeState(), and XXH64_freeState().

◆ XXH_isLittleEndian()

static int XXH_isLittleEndian ( void  )
static

Definition at line 223 of file xxhash.c.

224 {
225  const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
226  return one.c[0];
227 }
#define c(i)
Definition: sha256.c:43

References c.

◆ XXH_malloc()

static void* XXH_malloc ( size_t  s)
static

Modify the local functions below should you wish to use some other memory routines for malloc(), free()

Definition at line 111 of file xxhash.c.

111 { return malloc(s); }
void * malloc(size_t size)
Definition: malloc.c:123
static RzSocket * s
Definition: rtr.c:28

References malloc(), and s.

Referenced by XXH32_createState(), and XXH64_createState().

◆ XXH_memcpy()

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

and for memcpy()

Definition at line 115 of file xxhash.c.

115 { return memcpy(dest,src,size); }
voidpf void uLong size
Definition: ioapi.h:138
char * dest
Definition: lz4.h:697

References dest, memcpy(), and src.

Referenced by XXH32_update_endian(), and XXH64_update_endian().

◆ XXH_read32()

static U32 XXH_read32 ( const void *  memPtr)
static

Definition at line 177 of file xxhash.c.

178 {
179  U32 val;
180  memcpy(&val, memPtr, sizeof(val));
181  return val;
182 }

References memcpy(), and val.

Referenced by XXH_readBE32(), and XXH_readLE32_align().

◆ XXH_read64()

static U64 XXH_read64 ( const void *  memPtr)
static

Definition at line 620 of file xxhash.c.

621 {
622  U64 val;
623  memcpy(&val, memPtr, sizeof(val));
624  return val;
625 }

References memcpy(), and val.

Referenced by XXH_readBE64(), and XXH_readLE64_align().

◆ XXH_readBE32()

static U32 XXH_readBE32 ( const void *  ptr)
static

Definition at line 250 of file xxhash.c.

251 {
253 }
static U32 XXH_read32(const void *memPtr)
Definition: xxhash.c:177

References XXH_CPU_LITTLE_ENDIAN, XXH_read32(), and XXH_swap32().

Referenced by XXH32_hashFromCanonical().

◆ XXH_readBE64()

static U64 XXH_readBE64 ( const void *  ptr)
static

Definition at line 660 of file xxhash.c.

661 {
663 }
static U64 XXH_read64(const void *memPtr)
Definition: xxhash.c:620

References XXH_CPU_LITTLE_ENDIAN, XXH_read64(), and XXH_swap64().

Referenced by XXH64_hashFromCanonical().

◆ XXH_readLE32()

FORCE_INLINE U32 XXH_readLE32 ( const void *  ptr,
XXH_endianess  endian 
)

Definition at line 245 of file xxhash.c.

246 {
247  return XXH_readLE32_align(ptr, endian, XXH_unaligned);
248 }
FORCE_INLINE U32 XXH_readLE32_align(const void *ptr, XXH_endianess endian, XXH_alignment align)
Definition: xxhash.c:234

References XXH_readLE32_align(), and XXH_unaligned.

◆ XXH_readLE32_align()

FORCE_INLINE U32 XXH_readLE32_align ( const void *  ptr,
XXH_endianess  endian,
XXH_alignment  align 
)

Definition at line 237 of file xxhash.c.

238 {
239  if (align==XXH_unaligned)
240  return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
241  else
242  return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr);
243 }

References XXH_littleEndian, XXH_read32(), XXH_swap32(), and XXH_unaligned.

◆ XXH_readLE64()

FORCE_INLINE U64 XXH_readLE64 ( const void *  ptr,
XXH_endianess  endian 
)

Definition at line 655 of file xxhash.c.

656 {
657  return XXH_readLE64_align(ptr, endian, XXH_unaligned);
658 }
FORCE_INLINE U64 XXH_readLE64_align(const void *ptr, XXH_endianess endian, XXH_alignment align)
Definition: xxhash.c:645

References XXH_readLE64_align(), and XXH_unaligned.

◆ XXH_readLE64_align()

FORCE_INLINE U64 XXH_readLE64_align ( const void *  ptr,
XXH_endianess  endian,
XXH_alignment  align 
)

Definition at line 647 of file xxhash.c.

648 {
649  if (align==XXH_unaligned)
650  return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
651  else
652  return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr);
653 }

References XXH_littleEndian, XXH_read64(), XXH_swap64(), and XXH_unaligned.

◆ XXH_swap32()

static U32 XXH_swap32 ( U32  x)
static

Definition at line 206 of file xxhash.c.

207 {
208  return ((x << 24) & 0xff000000 ) |
209  ((x << 8) & 0x00ff0000 ) |
210  ((x >> 8) & 0x0000ff00 ) |
211  ((x >> 24) & 0x000000ff );
212 }
int x
Definition: mipsasm.c:20

References x.

Referenced by XXH32_canonicalFromHash(), XXH_readBE32(), and XXH_readLE32_align().

◆ XXH_swap64()

static U64 XXH_swap64 ( U64  x)
static

Definition at line 634 of file xxhash.c.

635 {
636  return ((x << 56) & 0xff00000000000000ULL) |
637  ((x << 40) & 0x00ff000000000000ULL) |
638  ((x << 24) & 0x0000ff0000000000ULL) |
639  ((x << 8) & 0x000000ff00000000ULL) |
640  ((x >> 8) & 0x00000000ff000000ULL) |
641  ((x >> 24) & 0x0000000000ff0000ULL) |
642  ((x >> 40) & 0x000000000000ff00ULL) |
643  ((x >> 56) & 0x00000000000000ffULL);
644 }

References x.

Referenced by XXH64_canonicalFromHash(), XXH_readBE64(), and XXH_readLE64_align().

◆ XXH_versionNumber()

XXH_PUBLIC_API unsigned XXH_versionNumber ( void  )

Definition at line 260 of file xxhash.c.

260 { return XXH_VERSION_NUMBER; }
#define XXH_VERSION_NUMBER
Definition: xxhash.h:155

References XXH_VERSION_NUMBER.

Variable Documentation

◆ PRIME32_1

const U32 PRIME32_1 = 2654435761U
static

Definition at line 266 of file xxhash.c.

Referenced by XXH32_endian_align(), XXH32_reset(), and XXH32_round().

◆ PRIME32_2

const U32 PRIME32_2 = 2246822519U
static

Definition at line 267 of file xxhash.c.

Referenced by XXH32_avalanche(), XXH32_endian_align(), XXH32_reset(), and XXH32_round().

◆ PRIME32_3

const U32 PRIME32_3 = 3266489917U
static

Definition at line 268 of file xxhash.c.

Referenced by XXH32_avalanche().

◆ PRIME32_4

const U32 PRIME32_4 = 668265263U
static

Definition at line 269 of file xxhash.c.

◆ PRIME32_5

const U32 PRIME32_5 = 374761393U
static

Definition at line 270 of file xxhash.c.

Referenced by XXH32_digest_endian(), and XXH32_endian_align().

◆ PRIME64_1

const U64 PRIME64_1 = 11400714785074694791ULL
static

Definition at line 668 of file xxhash.c.

Referenced by XXH64_endian_align(), XXH64_mergeRound(), XXH64_reset(), and XXH64_round().

◆ PRIME64_2

const U64 PRIME64_2 = 14029467366897019727ULL
static

Definition at line 669 of file xxhash.c.

Referenced by XXH64_avalanche(), XXH64_endian_align(), XXH64_reset(), and XXH64_round().

◆ PRIME64_3

const U64 PRIME64_3 = 1609587929392839161ULL
static

Definition at line 670 of file xxhash.c.

Referenced by XXH64_avalanche().

◆ PRIME64_4

const U64 PRIME64_4 = 9650029242287828579ULL
static

Definition at line 671 of file xxhash.c.

Referenced by XXH64_mergeRound().

◆ PRIME64_5

const U64 PRIME64_5 = 2870177450012600261ULL
static

Definition at line 672 of file xxhash.c.

Referenced by XXH64_digest_endian(), and XXH64_endian_align().