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 134 of file xxhash.c.

◆ MEM_MODULE

#define MEM_MODULE

Definition at line 587 of file xxhash.c.

◆ PROCESS1

#define PROCESS1
Value:
h32 += (*p++) * PRIME32_5; \
h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
void * p
Definition: libc.cpp:67
static const U32 PRIME32_5
Definition: xxhash.c:267
static const U32 PRIME32_1
Definition: xxhash.c:263
#define XXH_rotl32(x, r)
Definition: xxhash.c:194

◆ PROCESS1_64

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

◆ PROCESS4

#define PROCESS4
Value:
h32 += XXH_get32bits(p) * PRIME32_3; \
p+=4; \
h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
static const U32 PRIME32_3
Definition: xxhash.c:265
static const U32 PRIME32_4
Definition: xxhash.c:266
#define XXH_get32bits(p)
Definition: xxhash.c:288

◆ 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:667
static const U64 PRIME64_3
Definition: xxhash.c:668

◆ 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:669
#define XXH_get64bits(p)
Definition: xxhash.c:699
static U64 XXH64_round(U64 acc, U64 input)
Definition: xxhash.c:672

◆ 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 71 of file xxhash.c.

◆ XXH_CPU_LITTLE_ENDIAN

#define XXH_CPU_LITTLE_ENDIAN   XXH_isLittleEndian()

Definition at line 225 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 97 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 83 of file xxhash.c.

◆ XXH_GCC_VERSION

#define XXH_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)

Definition at line 187 of file xxhash.c.

◆ XXH_get32bits

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

Definition at line 288 of file xxhash.c.

◆ XXH_get64bits

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

Definition at line 699 of file xxhash.c.

◆ XXH_rotl32

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

Definition at line 194 of file xxhash.c.

◆ XXH_rotl64

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

Definition at line 195 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 256 of file xxhash.c.

◆ XXH_STATIC_LINKING_ONLY

#define XXH_STATIC_LINKING_ONLY

Definition at line 116 of file xxhash.c.

Typedef Documentation

◆ BYTE

typedef unsigned char BYTE

Definition at line 151 of file xxhash.c.

◆ U16

typedef unsigned short U16

Definition at line 152 of file xxhash.c.

◆ U32

typedef unsigned int U32

Definition at line 153 of file xxhash.c.

◆ U64

typedef unsigned long long U64

Definition at line 595 of file xxhash.c.

Enumeration Type Documentation

◆ XXH_alignment

Enumerator
XXH_aligned 
XXH_unaligned 
XXH_aligned 
XXH_unaligned 

Definition at line 232 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 216 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 392 of file xxhash.c.

393 {
394 #if 0
395  /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
397  XXH32_reset(&state, seed);
399  return XXH32_digest(&state);
400 #else
402 
403  if (XXH_FORCE_ALIGN_CHECK) {
404  if ((((size_t)input) & 3) == 0) { /* Input is 4-bytes aligned, leverage the speed benefit */
405  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
407  else
409  } }
410 
411  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
413  else
415 #endif
416 }
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
#define XXH_CPU_LITTLE_ENDIAN
Definition: xxhash.c:225
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t *statePtr, unsigned int seed)
Definition: xxhash.c:437
#define XXH_FORCE_ALIGN_CHECK
Definition: xxhash.c:97
XXH_PUBLIC_API XXH_errorcode XXH32_update(XXH32_state_t *state_in, const void *input, size_t len)
Definition: xxhash.c:515
#define XXH_FORCE_NATIVE_FORMAT
Definition: xxhash.c:83
struct XXH32_state_s XXH32_state_t
Definition: xxhash.h:172
Definition: dis.h:43
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.

Referenced by fullSpeedBench(), FUZ_test(), FUZ_unitTests(), FUZZ_seed(), fuzzerTests(), LZ4F_decompress(), LZ4F_headerChecksum(), LZ4F_makeBlock(), main(), plugin_xxhash32_small_block(), rz_hash_xxhash(), and select_clevel().

◆ XXH32_avalanche()

static U32 XXH32_avalanche ( U32  h32)
static

Definition at line 278 of file xxhash.c.

279 {
280  h32 ^= h32 >> 15;
281  h32 *= PRIME32_2;
282  h32 ^= h32 >> 13;
283  h32 *= PRIME32_3;
284  h32 ^= h32 >> 16;
285  return(h32);
286 }
static const U32 PRIME32_2
Definition: xxhash.c:264

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 565 of file xxhash.c.

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

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 432 of file xxhash.c.

433 {
434  memcpy(dstState, srcState, sizeof(*dstState));
435 }

References memcpy().

◆ XXH32_createState()

XXH_PUBLIC_API XXH32_state_t* XXH32_createState ( void  )

Definition at line 422 of file xxhash.c.

423 {
424  return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t));
425 }
static void * XXH_malloc(size_t s)
Definition: xxhash.c:108

References XXH_malloc().

Referenced by plugin_xxhash32_context_new().

◆ XXH32_digest()

XXH_PUBLIC_API unsigned int XXH32_digest ( const XXH32_state_t state_in)

Definition at line 546 of file xxhash.c.

547 {
549 
550  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
551  return XXH32_digest_endian(state_in, XXH_littleEndian);
552  else
553  return XXH32_digest_endian(state_in, XXH_bigEndian);
554 }
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.

Referenced by LZ4F_compressEnd(), LZ4F_decompress(), plugin_xxhash32_final(), and XXH32().

◆ XXH32_digest_endian()

FORCE_INLINE U32 XXH32_digest_endian ( const XXH32_state_t state,
XXH_endianess  endian 
)

Definition at line 527 of file xxhash.c.

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

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

Referenced by XXH32_digest().

◆ 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 352 of file xxhash.c.

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

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

Referenced by XXH32().

◆ XXH32_finalize()

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

Definition at line 291 of file xxhash.c.

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

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 426 of file xxhash.c.

427 {
428  XXH_free(statePtr);
429  return XXH_OK;
430 }
static void XXH_free(void *p)
Definition: xxhash.c:109
@ XXH_OK
Definition: xxhash.h:79

References XXH_free(), and XXH_OK.

Referenced by plugin_xxhash32_context_free().

◆ XXH32_hashFromCanonical()

XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical ( const XXH32_canonical_t src)

Definition at line 572 of file xxhash.c.

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

References src, and XXH_readBE32().

◆ XXH32_reset()

XXH_PUBLIC_API XXH_errorcode XXH32_reset ( XXH32_state_t statePtr,
unsigned int  seed 
)

Definition at line 437 of file xxhash.c.

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

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

Referenced by LZ4F_compressBegin_usingCDict(), LZ4F_decompress(), plugin_xxhash32_init(), and XXH32().

◆ XXH32_round()

static U32 XXH32_round ( U32  seed,
U32  input 
)
static

Definition at line 269 of file xxhash.c.

270 {
271  seed += input * PRIME32_2;
272  seed = XXH_rotl32(seed, 13);
273  seed *= PRIME32_1;
274  return seed;
275 }

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 515 of file xxhash.c.

516 {
518 
519  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
520  return XXH32_update_endian(state_in, input, len, XXH_littleEndian);
521  else
522  return XXH32_update_endian(state_in, input, len, XXH_bigEndian);
523 }
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.

Referenced by LZ4F_compressUpdate(), LZ4F_decompress(), plugin_xxhash32_update(), and XXH32().

◆ 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 452 of file xxhash.c.

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

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

Referenced by XXH32_update().

◆ 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 855 of file xxhash.c.

856 {
857 #if 0
858  /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
860  XXH64_reset(&state, seed);
862  return XXH64_digest(&state);
863 #else
865 
866  if (XXH_FORCE_ALIGN_CHECK) {
867  if ((((size_t)input) & 7)==0) { /* Input is aligned, let's leverage the speed advantage */
868  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
870  else
872  } }
873 
874  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
876  else
878 #endif
879 }
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.

Referenced by basicTests(), BMK_benchMem(), FUZ_unitTests(), and fuzzerTests().

◆ XXH64_avalanche()

static U64 XXH64_avalanche ( U64  h64)
static

Definition at line 688 of file xxhash.c.

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

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 1018 of file xxhash.c.

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

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 893 of file xxhash.c.

894 {
895  memcpy(dstState, srcState, sizeof(*dstState));
896 }

References memcpy().

◆ XXH64_createState()

XXH_PUBLIC_API XXH64_state_t* XXH64_createState ( void  )

Definition at line 883 of file xxhash.c.

884 {
885  return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t));
886 }

References XXH_malloc().

◆ XXH64_digest()

XXH_PUBLIC_API unsigned long long XXH64_digest ( const XXH64_state_t state_in)

Definition at line 1005 of file xxhash.c.

1006 {
1008 
1009  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
1010  return XXH64_digest_endian(state_in, XXH_littleEndian);
1011  else
1012  return XXH64_digest_endian(state_in, XXH_bigEndian);
1013 }
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.

Referenced by FUZ_unitTests(), test_lz4f_decompression_wBuffers(), and XXH64().

◆ XXH64_digest_endian()

FORCE_INLINE U64 XXH64_digest_endian ( const XXH64_state_t state,
XXH_endianess  endian 
)

Definition at line 981 of file xxhash.c.

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

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

Referenced by XXH64_digest().

◆ 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 811 of file xxhash.c.

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

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

Referenced by XXH64().

◆ XXH64_finalize()

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

Definition at line 702 of file xxhash.c.

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

888 {
889  XXH_free(statePtr);
890  return XXH_OK;
891 }

References XXH_free(), and XXH_OK.

◆ XXH64_hashFromCanonical()

XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical ( const XXH64_canonical_t src)

Definition at line 1025 of file xxhash.c.

1026 {
1027  return XXH_readBE64(src);
1028 }
static U64 XXH_readBE64(const void *ptr)
Definition: xxhash.c:658

References src, and XXH_readBE64().

◆ XXH64_mergeRound()

static U64 XXH64_mergeRound ( U64  acc,
U64  val 
)
static

Definition at line 680 of file xxhash.c.

681 {
682  val = XXH64_round(0, val);
683  acc ^= val;
684  acc = acc * PRIME64_1 + PRIME64_4;
685  return acc;
686 }
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 898 of file xxhash.c.

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

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

Referenced by FUZ_unitTests(), test_lz4f_decompression_wBuffers(), and XXH64().

◆ XXH64_round()

static U64 XXH64_round ( U64  acc,
U64  input 
)
static

Definition at line 672 of file xxhash.c.

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

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 971 of file xxhash.c.

972 {
974 
975  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
976  return XXH64_update_endian(state_in, input, len, XXH_littleEndian);
977  else
978  return XXH64_update_endian(state_in, input, len, XXH_bigEndian);
979 }
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.

Referenced by FUZ_unitTests(), test_lz4f_decompression_wBuffers(), and XXH64().

◆ 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 912 of file xxhash.c.

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

Referenced by XXH64_update().

◆ XXH_free()

static void XXH_free ( void *  p)
static

Definition at line 109 of file xxhash.c.

109 { 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 220 of file xxhash.c.

221 {
222  const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
223  return one.c[0];
224 }
#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 108 of file xxhash.c.

108 { 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 112 of file xxhash.c.

112 { 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 174 of file xxhash.c.

175 {
176  U32 val;
177  memcpy(&val, memPtr, sizeof(val));
178  return val;
179 }

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 618 of file xxhash.c.

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

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 247 of file xxhash.c.

248 {
250 }
static U32 XXH_read32(const void *memPtr)
Definition: xxhash.c:174

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 658 of file xxhash.c.

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

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 242 of file xxhash.c.

243 {
244  return XXH_readLE32_align(ptr, endian, XXH_unaligned);
245 }
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.

Referenced by XXH32_update_endian().

◆ XXH_readLE32_align()

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

Definition at line 234 of file xxhash.c.

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

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

Referenced by XXH_readLE32().

◆ XXH_readLE64()

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

Definition at line 653 of file xxhash.c.

654 {
655  return XXH_readLE64_align(ptr, endian, XXH_unaligned);
656 }
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.

Referenced by XXH64_update_endian().

◆ XXH_readLE64_align()

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

Definition at line 645 of file xxhash.c.

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

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

Referenced by XXH_readLE64().

◆ XXH_swap32()

static U32 XXH_swap32 ( U32  x)
static

Definition at line 203 of file xxhash.c.

204 {
205  return ((x << 24) & 0xff000000 ) |
206  ((x << 8) & 0x00ff0000 ) |
207  ((x >> 8) & 0x0000ff00 ) |
208  ((x >> 24) & 0x000000ff );
209 }
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 632 of file xxhash.c.

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

References x.

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

◆ XXH_versionNumber()

XXH_PUBLIC_API unsigned XXH_versionNumber ( void  )

Definition at line 257 of file xxhash.c.

257 { 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 263 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 264 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 265 of file xxhash.c.

Referenced by XXH32_avalanche().

◆ PRIME32_4

const U32 PRIME32_4 = 668265263U
static

Definition at line 266 of file xxhash.c.

◆ PRIME32_5

const U32 PRIME32_5 = 374761393U
static

Definition at line 267 of file xxhash.c.

Referenced by XXH32_digest_endian(), and XXH32_endian_align().

◆ PRIME64_1

const U64 PRIME64_1 = 11400714785074694791ULL
static

Definition at line 666 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 667 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 668 of file xxhash.c.

Referenced by XXH64_avalanche().

◆ PRIME64_4

const U64 PRIME64_4 = 9650029242287828579ULL
static

Definition at line 669 of file xxhash.c.

Referenced by XXH64_mergeRound().

◆ PRIME64_5

const U64 PRIME64_5 = 2870177450012600261ULL
static

Definition at line 670 of file xxhash.c.

Referenced by XXH64_digest_endian(), and XXH64_endian_align().