extzstd 0.0.2.CONCEPT-x86-mingw32 → 0.0.3.CONCEPT-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +72 -22
  3. data/Rakefile +73 -19
  4. data/contrib/zstd/README.md +68 -0
  5. data/contrib/zstd/common/bitstream.h +414 -0
  6. data/contrib/zstd/common/entropy_common.c +231 -0
  7. data/contrib/zstd/common/error_private.h +125 -0
  8. data/contrib/zstd/common/error_public.h +77 -0
  9. data/contrib/zstd/common/fse.h +628 -0
  10. data/contrib/zstd/common/fse_decompress.c +331 -0
  11. data/contrib/zstd/common/huf.h +228 -0
  12. data/contrib/zstd/common/mem.h +377 -0
  13. data/contrib/zstd/common/xxhash.c +854 -0
  14. data/contrib/zstd/common/xxhash.h +273 -0
  15. data/contrib/zstd/common/zbuff.h +197 -0
  16. data/contrib/zstd/common/zstd.h +475 -0
  17. data/contrib/zstd/common/zstd_common.c +91 -0
  18. data/contrib/zstd/common/zstd_internal.h +238 -0
  19. data/contrib/zstd/compress/fse_compress.c +807 -0
  20. data/contrib/zstd/compress/huf_compress.c +577 -0
  21. data/contrib/zstd/compress/zbuff_compress.c +327 -0
  22. data/contrib/zstd/compress/zstd_compress.c +3074 -0
  23. data/contrib/zstd/compress/zstd_opt.h +1046 -0
  24. data/contrib/zstd/decompress/huf_decompress.c +894 -0
  25. data/contrib/zstd/decompress/zbuff_decompress.c +294 -0
  26. data/contrib/zstd/decompress/zstd_decompress.c +1362 -0
  27. data/contrib/zstd/dictBuilder/divsufsort.c +1913 -0
  28. data/contrib/zstd/dictBuilder/divsufsort.h +67 -0
  29. data/contrib/zstd/dictBuilder/zdict.c +1045 -0
  30. data/contrib/zstd/dictBuilder/zdict.h +113 -0
  31. data/contrib/zstd/legacy/zstd_legacy.h +140 -0
  32. data/contrib/zstd/legacy/zstd_v01.c +2178 -0
  33. data/contrib/zstd/{zstd.h → legacy/zstd_v01.h} +46 -39
  34. data/contrib/zstd/legacy/zstd_v02.c +3748 -0
  35. data/contrib/zstd/legacy/zstd_v02.h +99 -0
  36. data/contrib/zstd/legacy/zstd_v03.c +3389 -0
  37. data/contrib/zstd/legacy/zstd_v03.h +99 -0
  38. data/contrib/zstd/legacy/zstd_v04.c +4056 -0
  39. data/contrib/zstd/legacy/zstd_v04.h +148 -0
  40. data/contrib/zstd/legacy/zstd_v05.c +4325 -0
  41. data/contrib/zstd/legacy/zstd_v05.h +171 -0
  42. data/contrib/zstd/legacy/zstd_v06.c +4581 -0
  43. data/contrib/zstd/legacy/zstd_v06.h +185 -0
  44. data/ext/extconf.rb +10 -12
  45. data/ext/extzstd.c +497 -144
  46. data/ext/extzstd.h +127 -22
  47. data/ext/extzstd_buffered.c +265 -0
  48. data/ext/extzstd_nogvls.h +174 -0
  49. data/ext/zstd_amalgam.c +18 -0
  50. data/ext/zstd_legacy_v01.c +1 -0
  51. data/ext/zstd_legacy_v02.c +1 -0
  52. data/ext/zstd_legacy_v03.c +1 -0
  53. data/ext/zstd_legacy_v04.c +1 -0
  54. data/ext/zstd_legacy_v05.c +1 -0
  55. data/ext/zstd_legacy_v06.c +1 -0
  56. data/gemstub.rb +17 -1
  57. data/lib/2.0/extzstd.so +0 -0
  58. data/lib/2.1/extzstd.so +0 -0
  59. data/lib/2.2/extzstd.so +0 -0
  60. data/lib/2.3/extzstd.so +0 -0
  61. data/lib/extzstd.rb +197 -77
  62. data/lib/extzstd/version.rb +1 -1
  63. data/test/test_basic.rb +41 -0
  64. metadata +71 -20
  65. data/contrib/zstd/Makefile +0 -115
  66. data/contrib/zstd/fse.c +0 -2466
  67. data/contrib/zstd/fse.h +0 -320
  68. data/contrib/zstd/fse_static.h +0 -282
  69. data/contrib/zstd/libzstd.pc.in +0 -14
  70. data/contrib/zstd/zstd.c +0 -1768
  71. data/contrib/zstd/zstd_static.h +0 -89
  72. data/ext/extzstd-stream.c +0 -398
@@ -0,0 +1,377 @@
1
+ /* ******************************************************************
2
+ mem.h
3
+ low-level memory access routines
4
+ Copyright (C) 2013-2015, Yann Collet.
5
+
6
+ BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7
+
8
+ Redistribution and use in source and binary forms, with or without
9
+ modification, are permitted provided that the following conditions are
10
+ met:
11
+
12
+ * Redistributions of source code must retain the above copyright
13
+ notice, this list of conditions and the following disclaimer.
14
+ * Redistributions in binary form must reproduce the above
15
+ copyright notice, this list of conditions and the following disclaimer
16
+ in the documentation and/or other materials provided with the
17
+ distribution.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ You can contact the author at :
32
+ - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
33
+ - Public forum : https://groups.google.com/forum/#!forum/lz4c
34
+ ****************************************************************** */
35
+ #ifndef MEM_H_MODULE
36
+ #define MEM_H_MODULE
37
+
38
+ #if defined (__cplusplus)
39
+ extern "C" {
40
+ #endif
41
+
42
+ /*-****************************************
43
+ * Dependencies
44
+ ******************************************/
45
+ #include <stddef.h> /* size_t, ptrdiff_t */
46
+ #include <string.h> /* memcpy */
47
+ #if defined(_MSC_VER) /* Visual Studio */
48
+ # include <stdlib.h> /* _byteswap_ulong */
49
+ #endif
50
+
51
+
52
+ /*-****************************************
53
+ * Compiler specifics
54
+ ******************************************/
55
+ #if defined(_MSC_VER)
56
+ # include <intrin.h> /* _byteswap_ */
57
+ #endif
58
+ #if defined(__GNUC__)
59
+ # define MEM_STATIC static __attribute__((unused))
60
+ #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
61
+ # define MEM_STATIC static inline
62
+ #elif defined(_MSC_VER)
63
+ # define MEM_STATIC static __inline
64
+ #else
65
+ # define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
66
+ #endif
67
+
68
+
69
+ /*-**************************************************************
70
+ * Basic Types
71
+ *****************************************************************/
72
+ #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
73
+ # include <stdint.h>
74
+ typedef uint8_t BYTE;
75
+ typedef uint16_t U16;
76
+ typedef int16_t S16;
77
+ typedef uint32_t U32;
78
+ typedef int32_t S32;
79
+ typedef uint64_t U64;
80
+ typedef int64_t S64;
81
+ #else
82
+ typedef unsigned char BYTE;
83
+ typedef unsigned short U16;
84
+ typedef signed short S16;
85
+ typedef unsigned int U32;
86
+ typedef signed int S32;
87
+ typedef unsigned long long U64;
88
+ typedef signed long long S64;
89
+ #endif
90
+
91
+
92
+ /*-**************************************************************
93
+ * Memory I/O
94
+ *****************************************************************/
95
+ /* MEM_FORCE_MEMORY_ACCESS :
96
+ * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
97
+ * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
98
+ * The below switch allow to select different access method for improved performance.
99
+ * Method 0 (default) : use `memcpy()`. Safe and portable.
100
+ * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
101
+ * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
102
+ * Method 2 : direct access. This method is portable but violate C standard.
103
+ * It can generate buggy code on targets depending on alignment.
104
+ * In some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
105
+ * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
106
+ * Prefer these methods in priority order (0 > 1 > 2)
107
+ */
108
+ #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
109
+ # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
110
+ # define MEM_FORCE_MEMORY_ACCESS 2
111
+ # elif defined(__INTEL_COMPILER) || \
112
+ (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
113
+ # define MEM_FORCE_MEMORY_ACCESS 1
114
+ # endif
115
+ #endif
116
+
117
+ MEM_STATIC unsigned MEM_32bits(void) { return sizeof(size_t)==4; }
118
+ MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; }
119
+
120
+ MEM_STATIC unsigned MEM_isLittleEndian(void)
121
+ {
122
+ const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
123
+ return one.c[0];
124
+ }
125
+
126
+ #if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
127
+
128
+ /* violates C standard, by lying on structure alignment.
129
+ Only use if no other choice to achieve best performance on target platform */
130
+ MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
131
+ MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
132
+ MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
133
+ MEM_STATIC U64 MEM_readST(const void* memPtr) { return *(const size_t*) memPtr; }
134
+
135
+ MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
136
+ MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; }
137
+ MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; }
138
+
139
+ #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
140
+
141
+ /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
142
+ /* currently only defined for gcc and icc */
143
+ typedef union { U16 u16; U32 u32; U64 u64; size_t st; } __attribute__((packed)) unalign;
144
+
145
+ MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
146
+ MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
147
+ MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
148
+ MEM_STATIC U64 MEM_readST(const void* ptr) { return ((const unalign*)ptr)->st; }
149
+
150
+ MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
151
+ MEM_STATIC void MEM_write32(void* memPtr, U32 value) { ((unalign*)memPtr)->u32 = value; }
152
+ MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign*)memPtr)->u64 = value; }
153
+
154
+ #else
155
+
156
+ /* default method, safe and standard.
157
+ can sometimes prove slower */
158
+
159
+ MEM_STATIC U16 MEM_read16(const void* memPtr)
160
+ {
161
+ U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
162
+ }
163
+
164
+ MEM_STATIC U32 MEM_read32(const void* memPtr)
165
+ {
166
+ U32 val; memcpy(&val, memPtr, sizeof(val)); return val;
167
+ }
168
+
169
+ MEM_STATIC U64 MEM_read64(const void* memPtr)
170
+ {
171
+ U64 val; memcpy(&val, memPtr, sizeof(val)); return val;
172
+ }
173
+
174
+ MEM_STATIC size_t MEM_readST(const void* memPtr)
175
+ {
176
+ size_t val; memcpy(&val, memPtr, sizeof(val)); return val;
177
+ }
178
+
179
+ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
180
+ {
181
+ memcpy(memPtr, &value, sizeof(value));
182
+ }
183
+
184
+ MEM_STATIC void MEM_write32(void* memPtr, U32 value)
185
+ {
186
+ memcpy(memPtr, &value, sizeof(value));
187
+ }
188
+
189
+ MEM_STATIC void MEM_write64(void* memPtr, U64 value)
190
+ {
191
+ memcpy(memPtr, &value, sizeof(value));
192
+ }
193
+
194
+ #endif /* MEM_FORCE_MEMORY_ACCESS */
195
+
196
+ MEM_STATIC U32 MEM_swap32(U32 in)
197
+ {
198
+ #if defined(_MSC_VER) /* Visual Studio */
199
+ return _byteswap_ulong(in);
200
+ #elif defined (__GNUC__)
201
+ return __builtin_bswap32(in);
202
+ #else
203
+ return ((in << 24) & 0xff000000 ) |
204
+ ((in << 8) & 0x00ff0000 ) |
205
+ ((in >> 8) & 0x0000ff00 ) |
206
+ ((in >> 24) & 0x000000ff );
207
+ #endif
208
+ }
209
+
210
+ MEM_STATIC U64 MEM_swap64(U64 in)
211
+ {
212
+ #if defined(_MSC_VER) /* Visual Studio */
213
+ return _byteswap_uint64(in);
214
+ #elif defined (__GNUC__)
215
+ return __builtin_bswap64(in);
216
+ #else
217
+ return ((in << 56) & 0xff00000000000000ULL) |
218
+ ((in << 40) & 0x00ff000000000000ULL) |
219
+ ((in << 24) & 0x0000ff0000000000ULL) |
220
+ ((in << 8) & 0x000000ff00000000ULL) |
221
+ ((in >> 8) & 0x00000000ff000000ULL) |
222
+ ((in >> 24) & 0x0000000000ff0000ULL) |
223
+ ((in >> 40) & 0x000000000000ff00ULL) |
224
+ ((in >> 56) & 0x00000000000000ffULL);
225
+ #endif
226
+ }
227
+
228
+ MEM_STATIC size_t MEM_swapST(size_t in)
229
+ {
230
+ if (MEM_32bits())
231
+ return (size_t)MEM_swap32((U32)in);
232
+ else
233
+ return (size_t)MEM_swap64((U64)in);
234
+ }
235
+
236
+ /*=== Little endian r/w ===*/
237
+
238
+ MEM_STATIC U16 MEM_readLE16(const void* memPtr)
239
+ {
240
+ if (MEM_isLittleEndian())
241
+ return MEM_read16(memPtr);
242
+ else {
243
+ const BYTE* p = (const BYTE*)memPtr;
244
+ return (U16)(p[0] + (p[1]<<8));
245
+ }
246
+ }
247
+
248
+ MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val)
249
+ {
250
+ if (MEM_isLittleEndian()) {
251
+ MEM_write16(memPtr, val);
252
+ } else {
253
+ BYTE* p = (BYTE*)memPtr;
254
+ p[0] = (BYTE)val;
255
+ p[1] = (BYTE)(val>>8);
256
+ }
257
+ }
258
+
259
+ MEM_STATIC U32 MEM_readLE32(const void* memPtr)
260
+ {
261
+ if (MEM_isLittleEndian())
262
+ return MEM_read32(memPtr);
263
+ else
264
+ return MEM_swap32(MEM_read32(memPtr));
265
+ }
266
+
267
+ MEM_STATIC void MEM_writeLE32(void* memPtr, U32 val32)
268
+ {
269
+ if (MEM_isLittleEndian())
270
+ MEM_write32(memPtr, val32);
271
+ else
272
+ MEM_write32(memPtr, MEM_swap32(val32));
273
+ }
274
+
275
+ MEM_STATIC U64 MEM_readLE64(const void* memPtr)
276
+ {
277
+ if (MEM_isLittleEndian())
278
+ return MEM_read64(memPtr);
279
+ else
280
+ return MEM_swap64(MEM_read64(memPtr));
281
+ }
282
+
283
+ MEM_STATIC void MEM_writeLE64(void* memPtr, U64 val64)
284
+ {
285
+ if (MEM_isLittleEndian())
286
+ MEM_write64(memPtr, val64);
287
+ else
288
+ MEM_write64(memPtr, MEM_swap64(val64));
289
+ }
290
+
291
+ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
292
+ {
293
+ if (MEM_32bits())
294
+ return (size_t)MEM_readLE32(memPtr);
295
+ else
296
+ return (size_t)MEM_readLE64(memPtr);
297
+ }
298
+
299
+ MEM_STATIC void MEM_writeLEST(void* memPtr, size_t val)
300
+ {
301
+ if (MEM_32bits())
302
+ MEM_writeLE32(memPtr, (U32)val);
303
+ else
304
+ MEM_writeLE64(memPtr, (U64)val);
305
+ }
306
+
307
+ /*=== Big endian r/w ===*/
308
+
309
+ MEM_STATIC U32 MEM_readBE32(const void* memPtr)
310
+ {
311
+ if (MEM_isLittleEndian())
312
+ return MEM_swap32(MEM_read32(memPtr));
313
+ else
314
+ return MEM_read32(memPtr);
315
+ }
316
+
317
+ MEM_STATIC void MEM_writeBE32(void* memPtr, U32 val32)
318
+ {
319
+ if (MEM_isLittleEndian())
320
+ MEM_write32(memPtr, MEM_swap32(val32));
321
+ else
322
+ MEM_write32(memPtr, val32);
323
+ }
324
+
325
+ MEM_STATIC U64 MEM_readBE64(const void* memPtr)
326
+ {
327
+ if (MEM_isLittleEndian())
328
+ return MEM_swap64(MEM_read64(memPtr));
329
+ else
330
+ return MEM_read64(memPtr);
331
+ }
332
+
333
+ MEM_STATIC void MEM_writeBE64(void* memPtr, U64 val64)
334
+ {
335
+ if (MEM_isLittleEndian())
336
+ MEM_write64(memPtr, MEM_swap64(val64));
337
+ else
338
+ MEM_write64(memPtr, val64);
339
+ }
340
+
341
+ MEM_STATIC size_t MEM_readBEST(const void* memPtr)
342
+ {
343
+ if (MEM_32bits())
344
+ return (size_t)MEM_readBE32(memPtr);
345
+ else
346
+ return (size_t)MEM_readBE64(memPtr);
347
+ }
348
+
349
+ MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val)
350
+ {
351
+ if (MEM_32bits())
352
+ MEM_writeBE32(memPtr, (U32)val);
353
+ else
354
+ MEM_writeBE64(memPtr, (U64)val);
355
+ }
356
+
357
+
358
+ /* function safe only for comparisons */
359
+ MEM_STATIC U32 MEM_readMINMATCH(const void* memPtr, U32 length)
360
+ {
361
+ switch (length)
362
+ {
363
+ default :
364
+ case 4 : return MEM_read32(memPtr);
365
+ case 3 : if (MEM_isLittleEndian())
366
+ return MEM_read32(memPtr)<<8;
367
+ else
368
+ return MEM_read32(memPtr)>>8;
369
+ }
370
+ }
371
+
372
+ #if defined (__cplusplus)
373
+ }
374
+ #endif
375
+
376
+ #endif /* MEM_H_MODULE */
377
+
@@ -0,0 +1,854 @@
1
+ /*
2
+ * xxHash - Fast Hash algorithm
3
+ * Copyright (C) 2012-2016, Yann Collet
4
+ *
5
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are
9
+ * met:
10
+ *
11
+ * * Redistributions of source code must retain the above copyright
12
+ * notice, this list of conditions and the following disclaimer.
13
+ * * Redistributions in binary form must reproduce the above
14
+ * copyright notice, this list of conditions and the following disclaimer
15
+ * in the documentation and/or other materials provided with the
16
+ * distribution.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ *
30
+ * You can contact the author at :
31
+ * - xxHash homepage: http://www.xxhash.com
32
+ * - xxHash source repository : https://github.com/Cyan4973/xxHash
33
+ */
34
+
35
+
36
+ /* *************************************
37
+ * Tuning parameters
38
+ ***************************************/
39
+ /*!XXH_FORCE_MEMORY_ACCESS :
40
+ * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
41
+ * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
42
+ * The below switch allow to select different access method for improved performance.
43
+ * Method 0 (default) : use `memcpy()`. Safe and portable.
44
+ * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
45
+ * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
46
+ * Method 2 : direct access. This method doesn't depend on compiler but violate C standard.
47
+ * It can generate buggy code on targets which do not support unaligned memory accesses.
48
+ * But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
49
+ * See http://stackoverflow.com/a/32095106/646947 for details.
50
+ * Prefer these methods in priority order (0 > 1 > 2)
51
+ */
52
+ #ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
53
+ # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
54
+ # define XXH_FORCE_MEMORY_ACCESS 2
55
+ # elif defined(__INTEL_COMPILER) || \
56
+ (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
57
+ # define XXH_FORCE_MEMORY_ACCESS 1
58
+ # endif
59
+ #endif
60
+
61
+ /*!XXH_ACCEPT_NULL_INPUT_POINTER :
62
+ * If the input pointer is a null pointer, xxHash default behavior is to trigger a memory access error, since it is a bad pointer.
63
+ * When this option is enabled, xxHash output for null input pointers will be the same as a null-length input.
64
+ * By default, this option is disabled. To enable it, uncomment below define :
65
+ */
66
+ /* #define XXH_ACCEPT_NULL_INPUT_POINTER 1 */
67
+
68
+ /*!XXH_FORCE_NATIVE_FORMAT :
69
+ * By default, xxHash library provides endian-independant Hash values, based on little-endian convention.
70
+ * Results are therefore identical for little-endian and big-endian CPU.
71
+ * This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format.
72
+ * Should endian-independance be of no importance for your application, you may set the #define below to 1,
73
+ * to improve speed for Big-endian CPU.
74
+ * This option has no impact on Little_Endian CPU.
75
+ */
76
+ #ifndef XXH_FORCE_NATIVE_FORMAT /* can be defined externally */
77
+ # define XXH_FORCE_NATIVE_FORMAT 0
78
+ #endif
79
+
80
+ /*!XXH_FORCE_ALIGN_CHECK :
81
+ * This is a minor performance trick, only useful with lots of very small keys.
82
+ * It means : check for aligned/unaligned input.
83
+ * The check costs one initial branch per hash; set to 0 when the input data
84
+ * is guaranteed to be aligned.
85
+ */
86
+ #ifndef XXH_FORCE_ALIGN_CHECK /* can be defined externally */
87
+ # if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
88
+ # define XXH_FORCE_ALIGN_CHECK 0
89
+ # else
90
+ # define XXH_FORCE_ALIGN_CHECK 1
91
+ # endif
92
+ #endif
93
+
94
+
95
+ /* *************************************
96
+ * Includes & Memory related functions
97
+ ***************************************/
98
+ /* Modify the local functions below should you wish to use some other memory routines */
99
+ /* for malloc(), free() */
100
+ #include <stdlib.h>
101
+ static void* XXH_malloc(size_t s) { return malloc(s); }
102
+ static void XXH_free (void* p) { free(p); }
103
+ /* for memcpy() */
104
+ #include <string.h>
105
+ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
106
+
107
+ #define XXH_STATIC_LINKING_ONLY
108
+ #include "xxhash.h"
109
+
110
+
111
+ /* *************************************
112
+ * Compiler Specific Options
113
+ ***************************************/
114
+ #ifdef _MSC_VER /* Visual Studio */
115
+ # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
116
+ # define FORCE_INLINE static __forceinline
117
+ #else
118
+ # if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
119
+ # ifdef __GNUC__
120
+ # define FORCE_INLINE static inline __attribute__((always_inline))
121
+ # else
122
+ # define FORCE_INLINE static inline
123
+ # endif
124
+ # else
125
+ # define FORCE_INLINE static
126
+ # endif /* __STDC_VERSION__ */
127
+ #endif
128
+
129
+
130
+ /* *************************************
131
+ * Basic Types
132
+ ***************************************/
133
+ #ifndef MEM_MODULE
134
+ # define MEM_MODULE
135
+ # if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
136
+ # include <stdint.h>
137
+ typedef uint8_t BYTE;
138
+ typedef uint16_t U16;
139
+ typedef uint32_t U32;
140
+ typedef int32_t S32;
141
+ typedef uint64_t U64;
142
+ # else
143
+ typedef unsigned char BYTE;
144
+ typedef unsigned short U16;
145
+ typedef unsigned int U32;
146
+ typedef signed int S32;
147
+ typedef unsigned long long U64;
148
+ # endif
149
+ #endif
150
+
151
+
152
+ #if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
153
+
154
+ /* Force direct memory access. Only works on CPU which support unaligned memory access in hardware */
155
+ static U32 XXH_read32(const void* memPtr) { return *(const U32*) memPtr; }
156
+ static U64 XXH_read64(const void* memPtr) { return *(const U64*) memPtr; }
157
+
158
+ #elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
159
+
160
+ /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
161
+ /* currently only defined for gcc and icc */
162
+ typedef union { U32 u32; U64 u64; } __attribute__((packed)) unalign;
163
+
164
+ static U32 XXH_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
165
+ static U64 XXH_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
166
+
167
+ #else
168
+
169
+ /* portable and safe solution. Generally efficient.
170
+ * see : http://stackoverflow.com/a/32095106/646947
171
+ */
172
+
173
+ static U32 XXH_read32(const void* memPtr)
174
+ {
175
+ U32 val;
176
+ memcpy(&val, memPtr, sizeof(val));
177
+ return val;
178
+ }
179
+
180
+ static U64 XXH_read64(const void* memPtr)
181
+ {
182
+ U64 val;
183
+ memcpy(&val, memPtr, sizeof(val));
184
+ return val;
185
+ }
186
+
187
+ #endif /* XXH_FORCE_DIRECT_MEMORY_ACCESS */
188
+
189
+
190
+ /* ****************************************
191
+ * Compiler-specific Functions and Macros
192
+ ******************************************/
193
+ #define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
194
+
195
+ /* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */
196
+ #if defined(_MSC_VER)
197
+ # define XXH_rotl32(x,r) _rotl(x,r)
198
+ # define XXH_rotl64(x,r) _rotl64(x,r)
199
+ #else
200
+ # define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
201
+ # define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
202
+ #endif
203
+
204
+ #if defined(_MSC_VER) /* Visual Studio */
205
+ # define XXH_swap32 _byteswap_ulong
206
+ # define XXH_swap64 _byteswap_uint64
207
+ #elif GCC_VERSION >= 403
208
+ # define XXH_swap32 __builtin_bswap32
209
+ # define XXH_swap64 __builtin_bswap64
210
+ #else
211
+ static U32 XXH_swap32 (U32 x)
212
+ {
213
+ return ((x << 24) & 0xff000000 ) |
214
+ ((x << 8) & 0x00ff0000 ) |
215
+ ((x >> 8) & 0x0000ff00 ) |
216
+ ((x >> 24) & 0x000000ff );
217
+ }
218
+ static U64 XXH_swap64 (U64 x)
219
+ {
220
+ return ((x << 56) & 0xff00000000000000ULL) |
221
+ ((x << 40) & 0x00ff000000000000ULL) |
222
+ ((x << 24) & 0x0000ff0000000000ULL) |
223
+ ((x << 8) & 0x000000ff00000000ULL) |
224
+ ((x >> 8) & 0x00000000ff000000ULL) |
225
+ ((x >> 24) & 0x0000000000ff0000ULL) |
226
+ ((x >> 40) & 0x000000000000ff00ULL) |
227
+ ((x >> 56) & 0x00000000000000ffULL);
228
+ }
229
+ #endif
230
+
231
+
232
+ /* *************************************
233
+ * Architecture Macros
234
+ ***************************************/
235
+ typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
236
+
237
+ /* XXH_CPU_LITTLE_ENDIAN can be defined externally, for example on the compiler command line */
238
+ #ifndef XXH_CPU_LITTLE_ENDIAN
239
+ static const int g_one = 1;
240
+ # define XXH_CPU_LITTLE_ENDIAN (*(const char*)(&g_one))
241
+ #endif
242
+
243
+
244
+ /* ***************************
245
+ * Memory reads
246
+ *****************************/
247
+ typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment;
248
+
249
+ FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
250
+ {
251
+ if (align==XXH_unaligned)
252
+ return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
253
+ else
254
+ return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr);
255
+ }
256
+
257
+ FORCE_INLINE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
258
+ {
259
+ return XXH_readLE32_align(ptr, endian, XXH_unaligned);
260
+ }
261
+
262
+ static U32 XXH_readBE32(const void* ptr)
263
+ {
264
+ return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr);
265
+ }
266
+
267
+ FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
268
+ {
269
+ if (align==XXH_unaligned)
270
+ return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
271
+ else
272
+ return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr);
273
+ }
274
+
275
+ FORCE_INLINE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
276
+ {
277
+ return XXH_readLE64_align(ptr, endian, XXH_unaligned);
278
+ }
279
+
280
+ static U64 XXH_readBE64(const void* ptr)
281
+ {
282
+ return XXH_CPU_LITTLE_ENDIAN ? XXH_swap64(XXH_read64(ptr)) : XXH_read64(ptr);
283
+ }
284
+
285
+
286
+ /* *************************************
287
+ * Macros
288
+ ***************************************/
289
+ #define XXH_STATIC_ASSERT(c) { enum { XXH_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
290
+
291
+
292
+ /* *************************************
293
+ * Constants
294
+ ***************************************/
295
+ static const U32 PRIME32_1 = 2654435761U;
296
+ static const U32 PRIME32_2 = 2246822519U;
297
+ static const U32 PRIME32_3 = 3266489917U;
298
+ static const U32 PRIME32_4 = 668265263U;
299
+ static const U32 PRIME32_5 = 374761393U;
300
+
301
+ static const U64 PRIME64_1 = 11400714785074694791ULL;
302
+ static const U64 PRIME64_2 = 14029467366897019727ULL;
303
+ static const U64 PRIME64_3 = 1609587929392839161ULL;
304
+ static const U64 PRIME64_4 = 9650029242287828579ULL;
305
+ static const U64 PRIME64_5 = 2870177450012600261ULL;
306
+
307
+ XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; }
308
+
309
+
310
+ /* ***************************
311
+ * Simple Hash Functions
312
+ *****************************/
313
+
314
+ static U32 XXH32_round(U32 seed, U32 input)
315
+ {
316
+ seed += input * PRIME32_2;
317
+ seed = XXH_rotl32(seed, 13);
318
+ seed *= PRIME32_1;
319
+ return seed;
320
+ }
321
+
322
+ FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
323
+ {
324
+ const BYTE* p = (const BYTE*)input;
325
+ const BYTE* bEnd = p + len;
326
+ U32 h32;
327
+ #define XXH_get32bits(p) XXH_readLE32_align(p, endian, align)
328
+
329
+ #ifdef XXH_ACCEPT_NULL_INPUT_POINTER
330
+ if (p==NULL) {
331
+ len=0;
332
+ bEnd=p=(const BYTE*)(size_t)16;
333
+ }
334
+ #endif
335
+
336
+ if (len>=16) {
337
+ const BYTE* const limit = bEnd - 16;
338
+ U32 v1 = seed + PRIME32_1 + PRIME32_2;
339
+ U32 v2 = seed + PRIME32_2;
340
+ U32 v3 = seed + 0;
341
+ U32 v4 = seed - PRIME32_1;
342
+
343
+ do {
344
+ v1 = XXH32_round(v1, XXH_get32bits(p)); p+=4;
345
+ v2 = XXH32_round(v2, XXH_get32bits(p)); p+=4;
346
+ v3 = XXH32_round(v3, XXH_get32bits(p)); p+=4;
347
+ v4 = XXH32_round(v4, XXH_get32bits(p)); p+=4;
348
+ } while (p<=limit);
349
+
350
+ h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
351
+ } else {
352
+ h32 = seed + PRIME32_5;
353
+ }
354
+
355
+ h32 += (U32) len;
356
+
357
+ while (p+4<=bEnd) {
358
+ h32 += XXH_get32bits(p) * PRIME32_3;
359
+ h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
360
+ p+=4;
361
+ }
362
+
363
+ while (p<bEnd) {
364
+ h32 += (*p) * PRIME32_5;
365
+ h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
366
+ p++;
367
+ }
368
+
369
+ h32 ^= h32 >> 15;
370
+ h32 *= PRIME32_2;
371
+ h32 ^= h32 >> 13;
372
+ h32 *= PRIME32_3;
373
+ h32 ^= h32 >> 16;
374
+
375
+ return h32;
376
+ }
377
+
378
+
379
+ XXH_PUBLIC_API unsigned int XXH32 (const void* input, size_t len, unsigned int seed)
380
+ {
381
+ #if 0
382
+ /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
383
+ XXH32_CREATESTATE_STATIC(state);
384
+ XXH32_reset(state, seed);
385
+ XXH32_update(state, input, len);
386
+ return XXH32_digest(state);
387
+ #else
388
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
389
+
390
+ if (XXH_FORCE_ALIGN_CHECK) {
391
+ if ((((size_t)input) & 3) == 0) { /* Input is 4-bytes aligned, leverage the speed benefit */
392
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
393
+ return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
394
+ else
395
+ return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
396
+ } }
397
+
398
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
399
+ return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
400
+ else
401
+ return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
402
+ #endif
403
+ }
404
+
405
+
406
+ static U64 XXH64_round(U64 acc, U64 input)
407
+ {
408
+ acc += input * PRIME64_2;
409
+ acc = XXH_rotl64(acc, 31);
410
+ acc *= PRIME64_1;
411
+ return acc;
412
+ }
413
+
414
+ static U64 XXH64_mergeRound(U64 acc, U64 val)
415
+ {
416
+ val = XXH64_round(0, val);
417
+ acc ^= val;
418
+ acc = acc * PRIME64_1 + PRIME64_4;
419
+ return acc;
420
+ }
421
+
422
+ FORCE_INLINE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
423
+ {
424
+ const BYTE* p = (const BYTE*)input;
425
+ const BYTE* const bEnd = p + len;
426
+ U64 h64;
427
+ #define XXH_get64bits(p) XXH_readLE64_align(p, endian, align)
428
+
429
+ #ifdef XXH_ACCEPT_NULL_INPUT_POINTER
430
+ if (p==NULL) {
431
+ len=0;
432
+ bEnd=p=(const BYTE*)(size_t)32;
433
+ }
434
+ #endif
435
+
436
+ if (len>=32) {
437
+ const BYTE* const limit = bEnd - 32;
438
+ U64 v1 = seed + PRIME64_1 + PRIME64_2;
439
+ U64 v2 = seed + PRIME64_2;
440
+ U64 v3 = seed + 0;
441
+ U64 v4 = seed - PRIME64_1;
442
+
443
+ do {
444
+ v1 = XXH64_round(v1, XXH_get64bits(p)); p+=8;
445
+ v2 = XXH64_round(v2, XXH_get64bits(p)); p+=8;
446
+ v3 = XXH64_round(v3, XXH_get64bits(p)); p+=8;
447
+ v4 = XXH64_round(v4, XXH_get64bits(p)); p+=8;
448
+ } while (p<=limit);
449
+
450
+ h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
451
+ h64 = XXH64_mergeRound(h64, v1);
452
+ h64 = XXH64_mergeRound(h64, v2);
453
+ h64 = XXH64_mergeRound(h64, v3);
454
+ h64 = XXH64_mergeRound(h64, v4);
455
+
456
+ } else {
457
+ h64 = seed + PRIME64_5;
458
+ }
459
+
460
+ h64 += (U64) len;
461
+
462
+ while (p+8<=bEnd) {
463
+ U64 const k1 = XXH64_round(0, XXH_get64bits(p));
464
+ h64 ^= k1;
465
+ h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4;
466
+ p+=8;
467
+ }
468
+
469
+ if (p+4<=bEnd) {
470
+ h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1;
471
+ h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
472
+ p+=4;
473
+ }
474
+
475
+ while (p<bEnd) {
476
+ h64 ^= (*p) * PRIME64_5;
477
+ h64 = XXH_rotl64(h64, 11) * PRIME64_1;
478
+ p++;
479
+ }
480
+
481
+ h64 ^= h64 >> 33;
482
+ h64 *= PRIME64_2;
483
+ h64 ^= h64 >> 29;
484
+ h64 *= PRIME64_3;
485
+ h64 ^= h64 >> 32;
486
+
487
+ return h64;
488
+ }
489
+
490
+
491
+ XXH_PUBLIC_API unsigned long long XXH64 (const void* input, size_t len, unsigned long long seed)
492
+ {
493
+ #if 0
494
+ /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
495
+ XXH64_CREATESTATE_STATIC(state);
496
+ XXH64_reset(state, seed);
497
+ XXH64_update(state, input, len);
498
+ return XXH64_digest(state);
499
+ #else
500
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
501
+
502
+ if (XXH_FORCE_ALIGN_CHECK) {
503
+ if ((((size_t)input) & 7)==0) { /* Input is aligned, let's leverage the speed advantage */
504
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
505
+ return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
506
+ else
507
+ return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
508
+ } }
509
+
510
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
511
+ return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
512
+ else
513
+ return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
514
+ #endif
515
+ }
516
+
517
+
518
+ /* **************************************************
519
+ * Advanced Hash Functions
520
+ ****************************************************/
521
+
522
+ XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void)
523
+ {
524
+ return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t));
525
+ }
526
+ XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr)
527
+ {
528
+ XXH_free(statePtr);
529
+ return XXH_OK;
530
+ }
531
+
532
+ XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void)
533
+ {
534
+ return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t));
535
+ }
536
+ XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
537
+ {
538
+ XXH_free(statePtr);
539
+ return XXH_OK;
540
+ }
541
+
542
+
543
+ /*** Hash feed ***/
544
+
545
+ XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int seed)
546
+ {
547
+ XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
548
+ memset(&state, 0, sizeof(state));
549
+ state.seed = seed;
550
+ state.v1 = seed + PRIME32_1 + PRIME32_2;
551
+ state.v2 = seed + PRIME32_2;
552
+ state.v3 = seed + 0;
553
+ state.v4 = seed - PRIME32_1;
554
+ memcpy(statePtr, &state, sizeof(state));
555
+ return XXH_OK;
556
+ }
557
+
558
+
559
+ XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long long seed)
560
+ {
561
+ XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
562
+ memset(&state, 0, sizeof(state));
563
+ state.seed = seed;
564
+ state.v1 = seed + PRIME64_1 + PRIME64_2;
565
+ state.v2 = seed + PRIME64_2;
566
+ state.v3 = seed + 0;
567
+ state.v4 = seed - PRIME64_1;
568
+ memcpy(statePtr, &state, sizeof(state));
569
+ return XXH_OK;
570
+ }
571
+
572
+
573
+ FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void* input, size_t len, XXH_endianess endian)
574
+ {
575
+ const BYTE* p = (const BYTE*)input;
576
+ const BYTE* const bEnd = p + len;
577
+
578
+ #ifdef XXH_ACCEPT_NULL_INPUT_POINTER
579
+ if (input==NULL) return XXH_ERROR;
580
+ #endif
581
+
582
+ state->total_len += len;
583
+
584
+ if (state->memsize + len < 16) { /* fill in tmp buffer */
585
+ XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len);
586
+ state->memsize += (U32)len;
587
+ return XXH_OK;
588
+ }
589
+
590
+ if (state->memsize) { /* some data left from previous update */
591
+ XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, 16-state->memsize);
592
+ { const U32* p32 = state->mem32;
593
+ state->v1 = XXH32_round(state->v1, XXH_readLE32(p32, endian)); p32++;
594
+ state->v2 = XXH32_round(state->v2, XXH_readLE32(p32, endian)); p32++;
595
+ state->v3 = XXH32_round(state->v3, XXH_readLE32(p32, endian)); p32++;
596
+ state->v4 = XXH32_round(state->v4, XXH_readLE32(p32, endian)); p32++;
597
+ }
598
+ p += 16-state->memsize;
599
+ state->memsize = 0;
600
+ }
601
+
602
+ if (p <= bEnd-16) {
603
+ const BYTE* const limit = bEnd - 16;
604
+ U32 v1 = state->v1;
605
+ U32 v2 = state->v2;
606
+ U32 v3 = state->v3;
607
+ U32 v4 = state->v4;
608
+
609
+ do {
610
+ v1 = XXH32_round(v1, XXH_readLE32(p, endian)); p+=4;
611
+ v2 = XXH32_round(v2, XXH_readLE32(p, endian)); p+=4;
612
+ v3 = XXH32_round(v3, XXH_readLE32(p, endian)); p+=4;
613
+ v4 = XXH32_round(v4, XXH_readLE32(p, endian)); p+=4;
614
+ } while (p<=limit);
615
+
616
+ state->v1 = v1;
617
+ state->v2 = v2;
618
+ state->v3 = v3;
619
+ state->v4 = v4;
620
+ }
621
+
622
+ if (p < bEnd) {
623
+ XXH_memcpy(state->mem32, p, bEnd-p);
624
+ state->memsize = (int)(bEnd-p);
625
+ }
626
+
627
+ return XXH_OK;
628
+ }
629
+
630
+ XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void* input, size_t len)
631
+ {
632
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
633
+
634
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
635
+ return XXH32_update_endian(state_in, input, len, XXH_littleEndian);
636
+ else
637
+ return XXH32_update_endian(state_in, input, len, XXH_bigEndian);
638
+ }
639
+
640
+
641
+
642
+ FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian)
643
+ {
644
+ const BYTE * p = (const BYTE*)state->mem32;
645
+ const BYTE* const bEnd = (const BYTE*)(state->mem32) + state->memsize;
646
+ U32 h32;
647
+
648
+ if (state->total_len >= 16) {
649
+ h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18);
650
+ } else {
651
+ h32 = state->seed + PRIME32_5;
652
+ }
653
+
654
+ h32 += (U32) state->total_len;
655
+
656
+ while (p+4<=bEnd) {
657
+ h32 += XXH_readLE32(p, endian) * PRIME32_3;
658
+ h32 = XXH_rotl32(h32, 17) * PRIME32_4;
659
+ p+=4;
660
+ }
661
+
662
+ while (p<bEnd) {
663
+ h32 += (*p) * PRIME32_5;
664
+ h32 = XXH_rotl32(h32, 11) * PRIME32_1;
665
+ p++;
666
+ }
667
+
668
+ h32 ^= h32 >> 15;
669
+ h32 *= PRIME32_2;
670
+ h32 ^= h32 >> 13;
671
+ h32 *= PRIME32_3;
672
+ h32 ^= h32 >> 16;
673
+
674
+ return h32;
675
+ }
676
+
677
+
678
+ XXH_PUBLIC_API unsigned int XXH32_digest (const XXH32_state_t* state_in)
679
+ {
680
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
681
+
682
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
683
+ return XXH32_digest_endian(state_in, XXH_littleEndian);
684
+ else
685
+ return XXH32_digest_endian(state_in, XXH_bigEndian);
686
+ }
687
+
688
+
689
+
690
+ /* **** XXH64 **** */
691
+
692
+ FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void* input, size_t len, XXH_endianess endian)
693
+ {
694
+ const BYTE* p = (const BYTE*)input;
695
+ const BYTE* const bEnd = p + len;
696
+
697
+ #ifdef XXH_ACCEPT_NULL_INPUT_POINTER
698
+ if (input==NULL) return XXH_ERROR;
699
+ #endif
700
+
701
+ state->total_len += len;
702
+
703
+ if (state->memsize + len < 32) { /* fill in tmp buffer */
704
+ XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
705
+ state->memsize += (U32)len;
706
+ return XXH_OK;
707
+ }
708
+
709
+ if (state->memsize) { /* tmp buffer is full */
710
+ XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, 32-state->memsize);
711
+ state->v1 = XXH64_round(state->v1, XXH_readLE64(state->mem64+0, endian));
712
+ state->v2 = XXH64_round(state->v2, XXH_readLE64(state->mem64+1, endian));
713
+ state->v3 = XXH64_round(state->v3, XXH_readLE64(state->mem64+2, endian));
714
+ state->v4 = XXH64_round(state->v4, XXH_readLE64(state->mem64+3, endian));
715
+ p += 32-state->memsize;
716
+ state->memsize = 0;
717
+ }
718
+
719
+ if (p+32 <= bEnd) {
720
+ const BYTE* const limit = bEnd - 32;
721
+ U64 v1 = state->v1;
722
+ U64 v2 = state->v2;
723
+ U64 v3 = state->v3;
724
+ U64 v4 = state->v4;
725
+
726
+ do {
727
+ v1 = XXH64_round(v1, XXH_readLE64(p, endian)); p+=8;
728
+ v2 = XXH64_round(v2, XXH_readLE64(p, endian)); p+=8;
729
+ v3 = XXH64_round(v3, XXH_readLE64(p, endian)); p+=8;
730
+ v4 = XXH64_round(v4, XXH_readLE64(p, endian)); p+=8;
731
+ } while (p<=limit);
732
+
733
+ state->v1 = v1;
734
+ state->v2 = v2;
735
+ state->v3 = v3;
736
+ state->v4 = v4;
737
+ }
738
+
739
+ if (p < bEnd) {
740
+ XXH_memcpy(state->mem64, p, bEnd-p);
741
+ state->memsize = (int)(bEnd-p);
742
+ }
743
+
744
+ return XXH_OK;
745
+ }
746
+
747
+ XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void* input, size_t len)
748
+ {
749
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
750
+
751
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
752
+ return XXH64_update_endian(state_in, input, len, XXH_littleEndian);
753
+ else
754
+ return XXH64_update_endian(state_in, input, len, XXH_bigEndian);
755
+ }
756
+
757
+
758
+
759
+ FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian)
760
+ {
761
+ const BYTE * p = (const BYTE*)state->mem64;
762
+ const BYTE* const bEnd = (const BYTE*)state->mem64 + state->memsize;
763
+ U64 h64;
764
+
765
+ if (state->total_len >= 32) {
766
+ U64 const v1 = state->v1;
767
+ U64 const v2 = state->v2;
768
+ U64 const v3 = state->v3;
769
+ U64 const v4 = state->v4;
770
+
771
+ h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
772
+ h64 = XXH64_mergeRound(h64, v1);
773
+ h64 = XXH64_mergeRound(h64, v2);
774
+ h64 = XXH64_mergeRound(h64, v3);
775
+ h64 = XXH64_mergeRound(h64, v4);
776
+ } else {
777
+ h64 = state->seed + PRIME64_5;
778
+ }
779
+
780
+ h64 += (U64) state->total_len;
781
+
782
+ while (p+8<=bEnd) {
783
+ U64 const k1 = XXH64_round(0, XXH_readLE64(p, endian));
784
+ h64 ^= k1;
785
+ h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4;
786
+ p+=8;
787
+ }
788
+
789
+ if (p+4<=bEnd) {
790
+ h64 ^= (U64)(XXH_readLE32(p, endian)) * PRIME64_1;
791
+ h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
792
+ p+=4;
793
+ }
794
+
795
+ while (p<bEnd) {
796
+ h64 ^= (*p) * PRIME64_5;
797
+ h64 = XXH_rotl64(h64, 11) * PRIME64_1;
798
+ p++;
799
+ }
800
+
801
+ h64 ^= h64 >> 33;
802
+ h64 *= PRIME64_2;
803
+ h64 ^= h64 >> 29;
804
+ h64 *= PRIME64_3;
805
+ h64 ^= h64 >> 32;
806
+
807
+ return h64;
808
+ }
809
+
810
+
811
+ XXH_PUBLIC_API unsigned long long XXH64_digest (const XXH64_state_t* state_in)
812
+ {
813
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
814
+
815
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
816
+ return XXH64_digest_endian(state_in, XXH_littleEndian);
817
+ else
818
+ return XXH64_digest_endian(state_in, XXH_bigEndian);
819
+ }
820
+
821
+
822
+ /* **************************
823
+ * Canonical representation
824
+ ****************************/
825
+
826
+ /*! Default XXH result types are basic unsigned 32 and 64 bits.
827
+ * The canonical representation follows human-readable write convention, aka big-endian (large digits first).
828
+ * These functions allow transformation of hash result into and from its canonical format.
829
+ * This way, hash values can be written into a file or buffer, and remain comparable across different systems and programs.
830
+ */
831
+
832
+ XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash)
833
+ {
834
+ XXH_STATIC_ASSERT(sizeof(XXH32_canonical_t) == sizeof(XXH32_hash_t));
835
+ if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
836
+ memcpy(dst, &hash, sizeof(*dst));
837
+ }
838
+
839
+ XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash)
840
+ {
841
+ XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t));
842
+ if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
843
+ memcpy(dst, &hash, sizeof(*dst));
844
+ }
845
+
846
+ XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src)
847
+ {
848
+ return XXH_readBE32(src);
849
+ }
850
+
851
+ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src)
852
+ {
853
+ return XXH_readBE64(src);
854
+ }