Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
xxhash.c File Reference
#include <stdlib.h>
#include <string.h>
#include "xxhash.h"
Include dependency graph for xxhash.c:

Go to the source code of this file.

Macros

#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)
 
#define XXH_rotl64(x, r)
 
#define XXH_CPU_LITTLE_ENDIAN   (*(const char*)(&g_one))
 
#define XXH_STATIC_ASSERT(c)
 
#define XXH_get32bits(p)
 
#define MEM_MODULE
 
#define XXH_get64bits(p)
 

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 }
 
enum  XXH_alignment { XXH_aligned , XXH_unaligned }
 

Functions

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)
 
XXH_PUBLIC_API unsigned XXH_versionNumber (void)
 
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)
 
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)
 
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)
 

Macro Definition Documentation

◆ FORCE_INLINE

#define FORCE_INLINE   static

Definition at line 126 of file xxhash.c.

◆ MEM_MODULE

#define MEM_MODULE

Definition at line 525 of file xxhash.c.

◆ XXH_CPU_LITTLE_ENDIAN

#define XXH_CPU_LITTLE_ENDIAN   (*(const char*)(&g_one))

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

◆ XXH_FORCE_NATIVE_FORMAT

#define XXH_FORCE_NATIVE_FORMAT   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 the input pointer is a null pointer, xxHash default behavior is to trigger a memory access error, since it is a bad pointer. When this option is enabled, xxHash output for null input pointers will be the same as a null-length input. By default, this option is disabled. To enable it, uncomment below define :

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

◆ XXH_GCC_VERSION

#define XXH_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)

Definition at line 177 of file xxhash.c.

◆ XXH_get32bits

#define XXH_get32bits ( p)
Value:
XXH_readLE32_align(p, endian, align)
const mie::Vuint & p
Definition bn.cpp:27
FORCE_INLINE U32 XXH_readLE32_align(const void *ptr, XXH_endianess endian, XXH_alignment align)
Definition xxhash.c:220

◆ XXH_get64bits

#define XXH_get64bits ( p)
Value:
XXH_readLE64_align(p, endian, align)
FORCE_INLINE U64 XXH_readLE64_align(const void *ptr, XXH_endianess endian, XXH_alignment align)
Definition xxhash.c:580

◆ XXH_rotl32

#define XXH_rotl32 ( x,
r )
Value:
((x << r) | (x >> (32 - r)))
const mie::Vuint & r
Definition bn.cpp:28

Definition at line 184 of file xxhash.c.

◆ XXH_rotl64

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

Definition at line 185 of file xxhash.c.

◆ XXH_STATIC_ASSERT

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

Definition at line 242 of file xxhash.c.

◆ XXH_STATIC_LINKING_ONLY

#define XXH_STATIC_LINKING_ONLY

Definition at line 108 of file xxhash.c.

Typedef Documentation

◆ BYTE

typedef unsigned char BYTE

Definition at line 141 of file xxhash.c.

◆ U16

typedef unsigned short U16

Definition at line 142 of file xxhash.c.

◆ U32

typedef unsigned int U32

Definition at line 143 of file xxhash.c.

◆ U64

typedef unsigned long long U64

Definition at line 530 of file xxhash.c.

Enumeration Type Documentation

◆ XXH_alignment

Enumerator
XXH_aligned 
XXH_unaligned 

Definition at line 218 of file xxhash.c.

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

◆ XXH_endianess

Enumerator
XXH_bigEndian 
XXH_littleEndian 

Definition at line 206 of file xxhash.c.

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

Function Documentation

◆ XXH32()

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

XXH32() : Calculate the 32-bits 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 320 of file xxhash.c.

321{
322#if 0
323 /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
325 XXH32_reset(&state, seed);
326 XXH32_update(&state, input, len);
327 return XXH32_digest(&state);
328#else
330
332 if ((((size_t)input) & 3) == 0) { /* Input is 4-bytes aligned, leverage the speed benefit */
333 if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
334 return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
335 else
336 return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
337 } }
338
339 if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
341 else
342 return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
343#endif
344}
XXH_PUBLIC_API unsigned int XXH32_digest(const XXH32_state_t *state_in)
Definition xxhash.c:484
FORCE_INLINE U32 XXH32_endian_align(const void *input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
Definition xxhash.c:263
#define XXH_CPU_LITTLE_ENDIAN
Definition xxhash.c:211
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t *statePtr, unsigned int seed)
Definition xxhash.c:365
#define XXH_FORCE_ALIGN_CHECK
Definition xxhash.c:91
XXH_PUBLIC_API XXH_errorcode XXH32_update(XXH32_state_t *state_in, const void *input, size_t len)
Definition xxhash.c:436
#define XXH_FORCE_NATIVE_FORMAT
Definition xxhash.c:77
struct XXH32_state_s XXH32_state_t
Definition xxhash.h:170
size_t len
Here is the call graph for this function:

◆ 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, and remain comparable across different systems and programs.

Definition at line 503 of file xxhash.c.

504{
506 if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
507 memcpy(dst, &hash, sizeof(*dst));
508}
#define XXH_STATIC_ASSERT(c)
Definition xxhash.c:242
unsigned int XXH32_hash_t
Definition xxhash.h:160
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:

◆ XXH32_copyState()

XXH_PUBLIC_API void XXH32_copyState ( XXH32_state_t * dstState,
const XXH32_state_t * srcState )

Definition at line 360 of file xxhash.c.

361{
362 memcpy(dstState, srcState, sizeof(*dstState));
363}
Here is the call graph for this function:

◆ XXH32_createState()

XXH_PUBLIC_API XXH32_state_t * XXH32_createState ( void )

Definition at line 350 of file xxhash.c.

351{
352 return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t));
353}

◆ XXH32_digest()

XXH_PUBLIC_API unsigned int XXH32_digest ( const XXH32_state_t * state_in)

Definition at line 484 of file xxhash.c.

485{
487
488 if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
489 return XXH32_digest_endian(state_in, XXH_littleEndian);
490 else
491 return XXH32_digest_endian(state_in, XXH_bigEndian);
492}
FORCE_INLINE U32 XXH32_digest_endian(const XXH32_state_t *state, XXH_endianess endian)
Definition xxhash.c:448
Here is the call graph for this function:
Here is the caller graph for this function:

◆ XXH32_digest_endian()

FORCE_INLINE U32 XXH32_digest_endian ( const XXH32_state_t * state,
XXH_endianess endian )

Definition at line 448 of file xxhash.c.

449{
450 const BYTE * p = (const BYTE*)state->mem32;
451 const BYTE* const bEnd = (const BYTE*)(state->mem32) + state->memsize;
452 U32 h32;
453
454 if (state->large_len) {
455 h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18);
456 } else {
457 h32 = state->v3 /* == seed */ + PRIME32_5;
458 }
459
460 h32 += state->total_len_32;
461
462 while (p+4<=bEnd) {
463 h32 += XXH_readLE32(p, endian) * PRIME32_3;
464 h32 = XXH_rotl32(h32, 17) * PRIME32_4;
465 p+=4;
466 }
467
468 while (p<bEnd) {
469 h32 += (*p) * PRIME32_5;
470 h32 = XXH_rotl32(h32, 11) * PRIME32_1;
471 p++;
472 }
473
474 h32 ^= h32 >> 15;
475 h32 *= PRIME32_2;
476 h32 ^= h32 >> 13;
477 h32 *= PRIME32_3;
478 h32 ^= h32 >> 16;
479
480 return h32;
481}
uint32_t U32
Definition BasicTypes.h:9
unsigned char BYTE
Definition xxhash.c:141
FORCE_INLINE U32 XXH_readLE32(const void *ptr, XXH_endianess endian)
Definition xxhash.c:228
#define XXH_rotl32(x, r)
Definition xxhash.c:184
Here is the call graph for this function:
Here is the caller graph for this function:

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

264{
265 const BYTE* p = (const BYTE*)input;
266 const BYTE* bEnd = p + len;
267 U32 h32;
268#define XXH_get32bits(p) XXH_readLE32_align(p, endian, align)
269
270#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
271 if (p==NULL) {
272 len=0;
273 bEnd=p=(const BYTE*)(size_t)16;
274 }
275#endif
276
277 if (len>=16) {
278 const BYTE* const limit = bEnd - 16;
279 U32 v1 = seed + PRIME32_1 + PRIME32_2;
280 U32 v2 = seed + PRIME32_2;
281 U32 v3 = seed + 0;
282 U32 v4 = seed - PRIME32_1;
283
284 do {
285 v1 = XXH32_round(v1, XXH_get32bits(p)); p+=4;
286 v2 = XXH32_round(v2, XXH_get32bits(p)); p+=4;
287 v3 = XXH32_round(v3, XXH_get32bits(p)); p+=4;
288 v4 = XXH32_round(v4, XXH_get32bits(p)); p+=4;
289 } while (p<=limit);
290
291 h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
292 } else {
293 h32 = seed + PRIME32_5;
294 }
295
296 h32 += (U32) len;
297
298 while (p+4<=bEnd) {
299 h32 += XXH_get32bits(p) * PRIME32_3;
300 h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
301 p+=4;
302 }
303
304 while (p<bEnd) {
305 h32 += (*p) * PRIME32_5;
306 h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
307 p++;
308 }
309
310 h32 ^= h32 >> 15;
311 h32 *= PRIME32_2;
312 h32 ^= h32 >> 13;
313 h32 *= PRIME32_3;
314 h32 ^= h32 >> 16;
315
316 return h32;
317}
unsigned int U32
Definition xxhash.c:143
#define XXH_get32bits(p)
Here is the caller graph for this function:

◆ XXH32_freeState()

XXH_PUBLIC_API XXH_errorcode XXH32_freeState ( XXH32_state_t * statePtr)

Definition at line 354 of file xxhash.c.

355{
356 XXH_free(statePtr);
357 return XXH_OK;
358}
@ XXH_OK
Definition xxhash.h:79

◆ XXH32_hashFromCanonical()

XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical ( const XXH32_canonical_t * src)

Definition at line 510 of file xxhash.c.

511{
512 return XXH_readBE32(src);
513}

◆ XXH32_reset()

XXH_PUBLIC_API XXH_errorcode XXH32_reset ( XXH32_state_t * statePtr,
unsigned int seed )

Definition at line 365 of file xxhash.c.

366{
367 XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
368 memset(&state, 0, sizeof(state)-4); /* do not write into reserved, for future removal */
369 state.v1 = seed + PRIME32_1 + PRIME32_2;
370 state.v2 = seed + PRIME32_2;
371 state.v3 = seed + 0;
372 state.v4 = seed - PRIME32_1;
373 memcpy(statePtr, &state, sizeof(state));
374 return XXH_OK;
375}
memset(pInfo->slotDescription, ' ', 64)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ XXH32_update()

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

Definition at line 436 of file xxhash.c.

437{
439
440 if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
441 return XXH32_update_endian(state_in, input, len, XXH_littleEndian);
442 else
443 return XXH32_update_endian(state_in, input, len, XXH_bigEndian);
444}
FORCE_INLINE XXH_errorcode XXH32_update_endian(XXH32_state_t *state, const void *input, size_t len, XXH_endianess endian)
Definition xxhash.c:378
Here is the call graph for this function:
Here is the caller graph for this function:

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

379{
380 const BYTE* p = (const BYTE*)input;
381 const BYTE* const bEnd = p + len;
382
383#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
384 if (input==NULL) return XXH_ERROR;
385#endif
386
387 state->total_len_32 += (unsigned)len;
388 state->large_len |= (len>=16) | (state->total_len_32>=16);
389
390 if (state->memsize + len < 16) { /* fill in tmp buffer */
391 XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len);
392 state->memsize += (unsigned)len;
393 return XXH_OK;
394 }
395
396 if (state->memsize) { /* some data left from previous update */
397 XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, 16-state->memsize);
398 { const U32* p32 = state->mem32;
399 state->v1 = XXH32_round(state->v1, XXH_readLE32(p32, endian)); p32++;
400 state->v2 = XXH32_round(state->v2, XXH_readLE32(p32, endian)); p32++;
401 state->v3 = XXH32_round(state->v3, XXH_readLE32(p32, endian)); p32++;
402 state->v4 = XXH32_round(state->v4, XXH_readLE32(p32, endian));
403 }
404 p += 16-state->memsize;
405 state->memsize = 0;
406 }
407
408 if (p <= bEnd-16) {
409 const BYTE* const limit = bEnd - 16;
410 U32 v1 = state->v1;
411 U32 v2 = state->v2;
412 U32 v3 = state->v3;
413 U32 v4 = state->v4;
414
415 do {
416 v1 = XXH32_round(v1, XXH_readLE32(p, endian)); p+=4;
417 v2 = XXH32_round(v2, XXH_readLE32(p, endian)); p+=4;
418 v3 = XXH32_round(v3, XXH_readLE32(p, endian)); p+=4;
419 v4 = XXH32_round(v4, XXH_readLE32(p, endian)); p+=4;
420 } while (p<=limit);
421
422 state->v1 = v1;
423 state->v2 = v2;
424 state->v3 = v3;
425 state->v4 = v4;
426 }
427
428 if (p < bEnd) {
429 XXH_memcpy(state->mem32, p, (size_t)(bEnd-p));
430 state->memsize = (unsigned)(bEnd-p);
431 }
432
433 return XXH_OK;
434}
@ XXH_ERROR
Definition xxhash.h:79
Here is the call graph for this function:
Here is the caller graph for this function:

◆ XXH64()

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

XXH64() : Calculate the 64-bits 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-bits systems, but slower on 32-bits systems (see benchmark).

Definition at line 692 of file xxhash.c.

693{
694#if 0
695 /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
697 XXH64_reset(&state, seed);
698 XXH64_update(&state, input, len);
699 return XXH64_digest(&state);
700#else
702
704 if ((((size_t)input) & 7)==0) { /* Input is aligned, let's leverage the speed advantage */
705 if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
706 return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
707 else
708 return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
709 } }
710
711 if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
713 else
714 return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
715#endif
716}
XXH_PUBLIC_API XXH_errorcode XXH64_update(XXH64_state_t *state_in, const void *input, size_t len)
Definition xxhash.c:802
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, unsigned long long seed)
Definition xxhash.c:735
XXH_PUBLIC_API unsigned long long XXH64_digest(const XXH64_state_t *state_in)
Definition xxhash.c:863
FORCE_INLINE U64 XXH64_endian_align(const void *input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
Definition xxhash.c:623
struct XXH64_state_s XXH64_state_t
Definition xxhash.h:228
Here is the call graph for this function:

◆ XXH64_canonicalFromHash()

XXH_PUBLIC_API void XXH64_canonicalFromHash ( XXH64_canonical_t * dst,
XXH64_hash_t hash )

Definition at line 876 of file xxhash.c.

877{
879 if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
880 memcpy(dst, &hash, sizeof(*dst));
881}
unsigned long long XXH64_hash_t
Definition xxhash.h:218
Here is the call graph for this function:

◆ XXH64_copyState()

XXH_PUBLIC_API void XXH64_copyState ( XXH64_state_t * dstState,
const XXH64_state_t * srcState )

Definition at line 730 of file xxhash.c.

731{
732 memcpy(dstState, srcState, sizeof(*dstState));
733}
Here is the call graph for this function:

◆ XXH64_createState()

XXH_PUBLIC_API XXH64_state_t * XXH64_createState ( void )

Definition at line 720 of file xxhash.c.

721{
722 return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t));
723}

◆ XXH64_digest()

XXH_PUBLIC_API unsigned long long XXH64_digest ( const XXH64_state_t * state_in)

Definition at line 863 of file xxhash.c.

864{
866
867 if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
868 return XXH64_digest_endian(state_in, XXH_littleEndian);
869 else
870 return XXH64_digest_endian(state_in, XXH_bigEndian);
871}
FORCE_INLINE U64 XXH64_digest_endian(const XXH64_state_t *state, XXH_endianess endian)
Definition xxhash.c:812
Here is the call graph for this function:
Here is the caller graph for this function:

◆ XXH64_digest_endian()

FORCE_INLINE U64 XXH64_digest_endian ( const XXH64_state_t * state,
XXH_endianess endian )

Definition at line 812 of file xxhash.c.

813{
814 const BYTE * p = (const BYTE*)state->mem64;
815 const BYTE* const bEnd = (const BYTE*)state->mem64 + state->memsize;
816 U64 h64;
817
818 if (state->total_len >= 32) {
819 U64 const v1 = state->v1;
820 U64 const v2 = state->v2;
821 U64 const v3 = state->v3;
822 U64 const v4 = state->v4;
823
824 h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
825 h64 = XXH64_mergeRound(h64, v1);
826 h64 = XXH64_mergeRound(h64, v2);
827 h64 = XXH64_mergeRound(h64, v3);
828 h64 = XXH64_mergeRound(h64, v4);
829 } else {
830 h64 = state->v3 + PRIME64_5;
831 }
832
833 h64 += (U64) state->total_len;
834
835 while (p+8<=bEnd) {
836 U64 const k1 = XXH64_round(0, XXH_readLE64(p, endian));
837 h64 ^= k1;
838 h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4;
839 p+=8;
840 }
841
842 if (p+4<=bEnd) {
843 h64 ^= (U64)(XXH_readLE32(p, endian)) * PRIME64_1;
844 h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
845 p+=4;
846 }
847
848 while (p<bEnd) {
849 h64 ^= (*p) * PRIME64_5;
850 h64 = XXH_rotl64(h64, 11) * PRIME64_1;
851 p++;
852 }
853
854 h64 ^= h64 >> 33;
855 h64 *= PRIME64_2;
856 h64 ^= h64 >> 29;
857 h64 *= PRIME64_3;
858 h64 ^= h64 >> 32;
859
860 return h64;
861}
uint64_t U64
Definition BasicTypes.h:11
static const Opmask k1(1)
#define XXH_rotl64(x, r)
Definition xxhash.c:185
unsigned long long U64
Definition xxhash.c:530
FORCE_INLINE U64 XXH_readLE64(const void *ptr, XXH_endianess endian)
Definition xxhash.c:588
Here is the call graph for this function:
Here is the caller graph for this function:

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

624{
625 const BYTE* p = (const BYTE*)input;
626 const BYTE* bEnd = p + len;
627 U64 h64;
628#define XXH_get64bits(p) XXH_readLE64_align(p, endian, align)
629
630#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
631 if (p==NULL) {
632 len=0;
633 bEnd=p=(const BYTE*)(size_t)32;
634 }
635#endif
636
637 if (len>=32) {
638 const BYTE* const limit = bEnd - 32;
639 U64 v1 = seed + PRIME64_1 + PRIME64_2;
640 U64 v2 = seed + PRIME64_2;
641 U64 v3 = seed + 0;
642 U64 v4 = seed - PRIME64_1;
643
644 do {
645 v1 = XXH64_round(v1, XXH_get64bits(p)); p+=8;
646 v2 = XXH64_round(v2, XXH_get64bits(p)); p+=8;
647 v3 = XXH64_round(v3, XXH_get64bits(p)); p+=8;
648 v4 = XXH64_round(v4, XXH_get64bits(p)); p+=8;
649 } while (p<=limit);
650
651 h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
652 h64 = XXH64_mergeRound(h64, v1);
653 h64 = XXH64_mergeRound(h64, v2);
654 h64 = XXH64_mergeRound(h64, v3);
655 h64 = XXH64_mergeRound(h64, v4);
656
657 } else {
658 h64 = seed + PRIME64_5;
659 }
660
661 h64 += (U64) len;
662
663 while (p+8<=bEnd) {
664 U64 const k1 = XXH64_round(0, XXH_get64bits(p));
665 h64 ^= k1;
666 h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4;
667 p+=8;
668 }
669
670 if (p+4<=bEnd) {
671 h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1;
672 h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
673 p+=4;
674 }
675
676 while (p<bEnd) {
677 h64 ^= (*p) * PRIME64_5;
678 h64 = XXH_rotl64(h64, 11) * PRIME64_1;
679 p++;
680 }
681
682 h64 ^= h64 >> 33;
683 h64 *= PRIME64_2;
684 h64 ^= h64 >> 29;
685 h64 *= PRIME64_3;
686 h64 ^= h64 >> 32;
687
688 return h64;
689}
#define XXH_get64bits(p)
Here is the caller graph for this function:

◆ XXH64_freeState()

XXH_PUBLIC_API XXH_errorcode XXH64_freeState ( XXH64_state_t * statePtr)

Definition at line 724 of file xxhash.c.

725{
726 XXH_free(statePtr);
727 return XXH_OK;
728}

◆ XXH64_hashFromCanonical()

XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical ( const XXH64_canonical_t * src)

Definition at line 883 of file xxhash.c.

884{
885 return XXH_readBE64(src);
886}

◆ XXH64_reset()

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

Definition at line 735 of file xxhash.c.

736{
737 XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
738 memset(&state, 0, sizeof(state)-8); /* do not write into reserved, for future removal */
739 state.v1 = seed + PRIME64_1 + PRIME64_2;
740 state.v2 = seed + PRIME64_2;
741 state.v3 = seed + 0;
742 state.v4 = seed - PRIME64_1;
743 memcpy(statePtr, &state, sizeof(state));
744 return XXH_OK;
745}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ XXH64_update()

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

Definition at line 802 of file xxhash.c.

803{
805
806 if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
807 return XXH64_update_endian(state_in, input, len, XXH_littleEndian);
808 else
809 return XXH64_update_endian(state_in, input, len, XXH_bigEndian);
810}
FORCE_INLINE XXH_errorcode XXH64_update_endian(XXH64_state_t *state, const void *input, size_t len, XXH_endianess endian)
Definition xxhash.c:747
Here is the call graph for this function:
Here is the caller graph for this function:

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

748{
749 const BYTE* p = (const BYTE*)input;
750 const BYTE* const bEnd = p + len;
751
752#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
753 if (input==NULL) return XXH_ERROR;
754#endif
755
756 state->total_len += len;
757
758 if (state->memsize + len < 32) { /* fill in tmp buffer */
759 XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
760 state->memsize += (U32)len;
761 return XXH_OK;
762 }
763
764 if (state->memsize) { /* tmp buffer is full */
765 XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, 32-state->memsize);
766 state->v1 = XXH64_round(state->v1, XXH_readLE64(state->mem64+0, endian));
767 state->v2 = XXH64_round(state->v2, XXH_readLE64(state->mem64+1, endian));
768 state->v3 = XXH64_round(state->v3, XXH_readLE64(state->mem64+2, endian));
769 state->v4 = XXH64_round(state->v4, XXH_readLE64(state->mem64+3, endian));
770 p += 32-state->memsize;
771 state->memsize = 0;
772 }
773
774 if (p+32 <= bEnd) {
775 const BYTE* const limit = bEnd - 32;
776 U64 v1 = state->v1;
777 U64 v2 = state->v2;
778 U64 v3 = state->v3;
779 U64 v4 = state->v4;
780
781 do {
782 v1 = XXH64_round(v1, XXH_readLE64(p, endian)); p+=8;
783 v2 = XXH64_round(v2, XXH_readLE64(p, endian)); p+=8;
784 v3 = XXH64_round(v3, XXH_readLE64(p, endian)); p+=8;
785 v4 = XXH64_round(v4, XXH_readLE64(p, endian)); p+=8;
786 } while (p<=limit);
787
788 state->v1 = v1;
789 state->v2 = v2;
790 state->v3 = v3;
791 state->v4 = v4;
792 }
793
794 if (p < bEnd) {
795 XXH_memcpy(state->mem64, p, (size_t)(bEnd-p));
796 state->memsize = (unsigned)(bEnd-p);
797 }
798
799 return XXH_OK;
800}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ XXH_readLE32()

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

Definition at line 228 of file xxhash.c.

229{
230 return XXH_readLE32_align(ptr, endian, XXH_unaligned);
231}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ XXH_readLE32_align()

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

Definition at line 220 of file xxhash.c.

221{
222 if (align==XXH_unaligned)
223 return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
224 else
225 return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr);
226}
Here is the caller graph for this function:

◆ XXH_readLE64()

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

Definition at line 588 of file xxhash.c.

589{
590 return XXH_readLE64_align(ptr, endian, XXH_unaligned);
591}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ XXH_readLE64_align()

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

Definition at line 580 of file xxhash.c.

581{
582 if (align==XXH_unaligned)
583 return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
584 else
585 return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr);
586}
Here is the caller graph for this function:

◆ XXH_versionNumber()

XXH_PUBLIC_API unsigned XXH_versionNumber ( void )

Definition at line 243 of file xxhash.c.

243{ return XXH_VERSION_NUMBER; }
#define XXH_VERSION_NUMBER
Definition xxhash.h:153