digest-xxhash 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5aa94f079152f6f34485582fffd2dfa9a405d7e202fef418d9c569c28404b99a
4
- data.tar.gz: aaaceebacfe3616bb16f974e1a4611d79d9662baf72e4e84622f6ea91232e7cc
3
+ metadata.gz: 67c1180d8629bae85bc269796cdae0b67e1fb1942dd5048906c5b785b94b878b
4
+ data.tar.gz: 0f35b3b820f91b12e0439e91dac4bf45a390dfc901d20c730d746886c132ca5a
5
5
  SHA512:
6
- metadata.gz: 3800479093f35a377f17faf7f41a7624ba5fecff8ce12a13a3b88cdd75ec79e053f216203e02399ad0557e741d6051159866a0d75279897fe2a053cb06370fce
7
- data.tar.gz: 79c51f9b3bc4ef219419441133276b3b6cb90a2db53e7f44c2d0c7e277a6ed7918a4759aaf0c629660024f870f84b36a01241b6214caf8e7e1682d41f597682c
6
+ metadata.gz: e7177998d433255ccb0e222257f9161c2e9514418052cf757621b3b13fbdb348dc6a47bd460b94398466496b28ebc7c06b845fc44329156a46309aef749c3bd5
7
+ data.tar.gz: af71a1e091b287e7d2ff9a41f74fc1adb2af73f625a66c9a5f1d64d3001c99034ec00e5b88085d93362b0820e0a33e2ad1f5f70df8b19551247d9a8d84d757da
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017 konsolebox
1
+ Copyright (c) 2021 konsolebox
2
2
 
3
3
  MIT License
4
4
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2017 konsolebox
2
+ * Copyright (c) 2021 konsolebox
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -121,29 +121,78 @@ extern "C" {
121
121
 
122
122
  /*
123
123
  * This part deals with the special case where a unit wants to inline xxHash,
124
- * but "xxhash.h" has previously been included without XXH_INLINE_ALL, such
125
- * as part of some previously included *.h header file.
124
+ * but "xxhash.h" has previously been included without XXH_INLINE_ALL,
125
+ * such as part of some previously included *.h header file.
126
126
  * Without further action, the new include would just be ignored,
127
127
  * and functions would effectively _not_ be inlined (silent failure).
128
128
  * The following macros solve this situation by prefixing all inlined names,
129
129
  * avoiding naming collision with previous inclusions.
130
130
  */
131
- # ifdef XXH_NAMESPACE
132
- # error "XXH_INLINE_ALL with XXH_NAMESPACE is not supported"
133
- /*
134
- * Note: Alternative: #undef all symbols (it's a pretty large list).
135
- * Without #error: it compiles, but functions are actually not inlined.
136
- */
137
- # endif
131
+ /* Before that, we unconditionally #undef all symbols,
132
+ * in case they were already defined with XXH_NAMESPACE.
133
+ * They will then be redefined for XXH_INLINE_ALL
134
+ */
135
+ # undef XXH_versionNumber
136
+ /* XXH32 */
137
+ # undef XXH32
138
+ # undef XXH32_createState
139
+ # undef XXH32_freeState
140
+ # undef XXH32_reset
141
+ # undef XXH32_update
142
+ # undef XXH32_digest
143
+ # undef XXH32_copyState
144
+ # undef XXH32_canonicalFromHash
145
+ # undef XXH32_hashFromCanonical
146
+ /* XXH64 */
147
+ # undef XXH64
148
+ # undef XXH64_createState
149
+ # undef XXH64_freeState
150
+ # undef XXH64_reset
151
+ # undef XXH64_update
152
+ # undef XXH64_digest
153
+ # undef XXH64_copyState
154
+ # undef XXH64_canonicalFromHash
155
+ # undef XXH64_hashFromCanonical
156
+ /* XXH3_64bits */
157
+ # undef XXH3_64bits
158
+ # undef XXH3_64bits_withSecret
159
+ # undef XXH3_64bits_withSeed
160
+ # undef XXH3_createState
161
+ # undef XXH3_freeState
162
+ # undef XXH3_copyState
163
+ # undef XXH3_64bits_reset
164
+ # undef XXH3_64bits_reset_withSeed
165
+ # undef XXH3_64bits_reset_withSecret
166
+ # undef XXH3_64bits_update
167
+ # undef XXH3_64bits_digest
168
+ # undef XXH3_generateSecret
169
+ /* XXH3_128bits */
170
+ # undef XXH128
171
+ # undef XXH3_128bits
172
+ # undef XXH3_128bits_withSeed
173
+ # undef XXH3_128bits_withSecret
174
+ # undef XXH3_128bits_reset
175
+ # undef XXH3_128bits_reset_withSeed
176
+ # undef XXH3_128bits_reset_withSecret
177
+ # undef XXH3_128bits_update
178
+ # undef XXH3_128bits_digest
179
+ # undef XXH128_isEqual
180
+ # undef XXH128_cmp
181
+ # undef XXH128_canonicalFromHash
182
+ # undef XXH128_hashFromCanonical
183
+ /* Finally, free the namespace itself */
184
+ # undef XXH_NAMESPACE
185
+
186
+ /* employ the namespace for XXH_INLINE_ALL */
138
187
  # define XXH_NAMESPACE XXH_INLINE_
139
188
  /*
140
- * Some identifiers (enums, type names) are not symbols, but they must
141
- * still be renamed to avoid redeclaration.
189
+ * Some identifiers (enums, type names) are not symbols,
190
+ * but they must nonetheless be renamed to avoid redeclaration.
142
191
  * Alternative solution: do not redeclare them.
143
- * However, this requires some #ifdefs, and is a more dispersed action.
144
- * Meanwhile, renaming can be achieved in a single block
192
+ * However, this requires some #ifdefs, and has a more dispersed impact.
193
+ * Meanwhile, renaming can be achieved in a single place.
145
194
  */
146
- # define XXH_IPREF(Id) XXH_INLINE_ ## Id
195
+ # define XXH_IPREF(Id) XXH_NAMESPACE ## Id
147
196
  # define XXH_OK XXH_IPREF(XXH_OK)
148
197
  # define XXH_ERROR XXH_IPREF(XXH_ERROR)
149
198
  # define XXH_errorcode XXH_IPREF(XXH_errorcode)
@@ -266,7 +315,7 @@ extern "C" {
266
315
  ***************************************/
267
316
  #define XXH_VERSION_MAJOR 0
268
317
  #define XXH_VERSION_MINOR 8
269
- #define XXH_VERSION_RELEASE 0
318
+ #define XXH_VERSION_RELEASE 1
270
319
  #define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
271
320
 
272
321
  /*!
@@ -275,7 +324,7 @@ extern "C" {
275
324
  * This is only useful when xxHash is compiled as a shared library, as it is
276
325
  * independent of the version defined in the header.
277
326
  *
278
- * @return `XXH_VERSION_NUMBER` as of when the function was compiled.
327
+ * @return `XXH_VERSION_NUMBER` as of when the libray was compiled.
279
328
  */
280
329
  XXH_PUBLIC_API unsigned XXH_versionNumber (void);
281
330
 
@@ -297,11 +346,13 @@ typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
297
346
  * Not necessarily defined to `uint32_t` but functionally equivalent.
298
347
  */
299
348
  typedef uint32_t XXH32_hash_t;
349
+
300
350
  #elif !defined (__VMS) \
301
351
  && (defined (__cplusplus) \
302
352
  || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
303
353
  # include <stdint.h>
304
354
  typedef uint32_t XXH32_hash_t;
355
+
305
356
  #else
306
357
  # include <limits.h>
307
358
  # if UINT_MAX == 0xFFFFFFFFUL
@@ -543,6 +594,38 @@ XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t
543
594
  XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src);
544
595
 
545
596
 
597
+ /*
598
+ Define XXH_FALLTHROUGH macro for annotating switch case with the 'fallthrough' attribute
599
+ introduced in CPP17 and C23.
600
+ CPP17 : https://en.cppreference.com/w/cpp/language/attributes/fallthrough
601
+ C23 : https://en.cppreference.com/w/c/language/attributes/fallthrough
602
+ */
603
+
604
+ #if defined (__has_c_attribute) && defined (__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) /* C2x */
605
+ # if __has_c_attribute(fallthrough)
606
+ # define XXH_FALLTHROUGH [[fallthrough]]
607
+ # endif
608
+
609
+ #elif defined(__cplusplus) && defined(__has_cpp_attribute)
610
+ # if __has_cpp_attribute(fallthrough)
611
+ # define XXH_FALLTHROUGH [[fallthrough]]
612
+ # endif
613
+ #endif
614
+
615
+ #ifndef XXH_FALLTHROUGH
616
+ # if defined(__GNUC__) && __GNUC__ >= 7
617
+ # define XXH_FALLTHROUGH __attribute__ ((fallthrough))
618
+ # elif defined(__clang__) && (__clang_major__ >= 10) \
619
+ && (!defined(__APPLE__) || (__clang_major__ >= 12))
620
+ /* Apple clang 12 is effectively clang-10 ,
621
+ * see https://en.wikipedia.org/wiki/Xcode for details
622
+ */
623
+ # define XXH_FALLTHROUGH __attribute__ ((fallthrough))
624
+ # else
625
+ # define XXH_FALLTHROUGH
626
+ # endif
627
+ #endif
628
+
546
629
  /*!
547
630
  * @}
548
631
  * @ingroup public
@@ -915,9 +998,12 @@ struct XXH64_state_s {
915
998
  XXH64_hash_t reserved64; /*!< Reserved field. Do not read or write to it, it may be removed. */
916
999
  }; /* typedef'd to XXH64_state_t */
917
1000
 
918
- #if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11+ */
1001
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* >= C11 */
919
1002
  # include <stdalign.h>
920
1003
  # define XXH_ALIGN(n) alignas(n)
1004
+ #elif defined(__cplusplus) && (__cplusplus >= 201103L) /* >= C++11 */
1005
+ /* In C++ alignas() is a keyword */
1006
+ # define XXH_ALIGN(n) alignas(n)
921
1007
  #elif defined(__GNUC__)
922
1008
  # define XXH_ALIGN(n) __attribute__ ((aligned(n)))
923
1009
  #elif defined(_MSC_VER)
@@ -928,6 +1014,7 @@ struct XXH64_state_s {
928
1014
 
929
1015
  /* Old GCC versions only accept the attribute after the type in structures. */
930
1016
  #if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) /* C11+ */ \
1017
+ && ! (defined(__cplusplus) && (__cplusplus >= 201103L)) /* >= C++11 */ \
931
1018
  && defined(__GNUC__)
932
1019
  # define XXH_ALIGN_MEMBER(align, type) type XXH_ALIGN(align)
933
1020
  #else
@@ -957,16 +1044,18 @@ struct XXH64_state_s {
957
1044
  * @brief Structure for XXH3 streaming API.
958
1045
  *
959
1046
  * @note This is only defined when @ref XXH_STATIC_LINKING_ONLY,
960
- * @ref XXH_INLINE_ALL, or @ref XXH_IMPLEMENTATION is defined. Otherwise it is
961
- * an opaque type. This allows fields to safely be changed.
1047
+ * @ref XXH_INLINE_ALL, or @ref XXH_IMPLEMENTATION is defined.
1048
+ * Otherwise it is an opaque type.
1049
+ * Never use this definition in combination with dynamic library.
1050
+ * This allows fields to safely be changed in the future.
962
1051
  *
963
- * @note **This structure has a strict alignment requirement of 64 bytes.** Do
964
- * not allocate this with `malloc()` or `new`, it will not be sufficiently
965
- * aligned. Use @ref XXH3_createState() and @ref XXH3_freeState(), or stack
966
- * allocation.
1052
+ * @note ** This structure has a strict alignment requirement of 64 bytes!! **
1053
+ * Do not allocate this with `malloc()` or `new`,
1054
+ * it will not be sufficiently aligned.
1055
+ * Use @ref XXH3_createState() and @ref XXH3_freeState(), or stack allocation.
967
1056
  *
968
1057
  * Typedef'd to @ref XXH3_state_t.
969
- * Do not access the members of this struct directly.
1058
+ * Do never access the members of this struct directly.
970
1059
  *
971
1060
  * @see XXH3_INITSTATE() for stack initialization.
972
1061
  * @see XXH3_createState(), XXH3_freeState().
@@ -1227,13 +1316,13 @@ XXH_PUBLIC_API XXH128_hash_t XXH128(const void* data, size_t len, XXH64_hash_t s
1227
1316
 
1228
1317
  /*!
1229
1318
  * @def XXH_REROLL
1230
- * @brief Whether to reroll `XXH32_finalize` and `XXH64_finalize`.
1319
+ * @brief Whether to reroll `XXH32_finalize`.
1231
1320
  *
1232
- * For performance, `XXH32_finalize` and `XXH64_finalize` use an unrolled loop
1321
+ * For performance, `XXH32_finalize` uses an unrolled loop
1233
1322
  * in the form of a switch statement.
1234
1323
  *
1235
- * This is not always desirable, as it generates larger code, and depending on
1236
- * the architecture, may even be slower
1324
+ * This is not always desirable, as it generates larger code,
1325
+ * and depending on the architecture, may even be slower
1237
1326
  *
1238
1327
  * This is automatically defined with `-Os`/`-Oz` on GCC and Clang.
1239
1328
  */
@@ -1254,10 +1343,21 @@ XXH_PUBLIC_API XXH128_hash_t XXH128(const void* data, size_t len, XXH64_hash_t s
1254
1343
  */
1255
1344
 
1256
1345
  #ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
1257
- /* prefer __packed__ structures (method 1) for gcc on armv7 and armv8 */
1258
- # if !defined(__clang__) && ( \
1346
+ /* prefer __packed__ structures (method 1) for gcc on armv7+ and mips */
1347
+ # if !defined(__clang__) && \
1348
+ ( \
1259
1349
  (defined(__INTEL_COMPILER) && !defined(_WIN32)) || \
1260
- (defined(__GNUC__) && (defined(__ARM_ARCH) && __ARM_ARCH >= 7)) )
1350
+ ( \
1351
+ defined(__GNUC__) && ( \
1352
+ (defined(__ARM_ARCH) && __ARM_ARCH >= 7) || \
1353
+ ( \
1354
+ defined(__mips__) && \
1355
+ (__mips <= 5 || __mips_isa_rev < 6) && \
1356
+ (!defined(__mips16) || defined(__mips_mips16e2)) \
1357
+ ) \
1358
+ ) \
1359
+ ) \
1360
+ )
1261
1361
  # define XXH_FORCE_MEMORY_ACCESS 1
1262
1362
  # endif
1263
1363
  #endif
@@ -1285,7 +1385,9 @@ XXH_PUBLIC_API XXH128_hash_t XXH128(const void* data, size_t len, XXH64_hash_t s
1285
1385
  #endif
1286
1386
 
1287
1387
  #ifndef XXH_REROLL
1288
- # if defined(__OPTIMIZE_SIZE__)
1388
+ # if defined(__OPTIMIZE_SIZE__) /* -Os, -Oz */ || \
1389
+ (defined(__GNUC__) && !defined(__clang__))
1390
+ /* The if/then loop is preferable to switch/case on gcc (on x64) */
1289
1391
  # define XXH_REROLL 1
1290
1392
  # else
1291
1393
  # define XXH_REROLL 0
@@ -1311,13 +1413,13 @@ XXH_PUBLIC_API XXH128_hash_t XXH128(const void* data, size_t len, XXH64_hash_t s
1311
1413
  * @internal
1312
1414
  * @brief Modify this function to use a different routine than malloc().
1313
1415
  */
1314
- static void* XXH_malloc(size_t s) { return ruby_xmalloc(s); }
1416
+ static void* XXH_malloc(size_t s) { return malloc(s); }
1315
1417
 
1316
1418
  /*!
1317
1419
  * @internal
1318
1420
  * @brief Modify this function to use a different routine than free().
1319
1421
  */
1320
- static void XXH_free(void* p) { ruby_xfree(p); }
1422
+ static void XXH_free(void* p) { free(p); }
1321
1423
 
1322
1424
  #include <string.h>
1323
1425
 
@@ -1392,7 +1494,17 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size)
1392
1494
  #endif
1393
1495
 
1394
1496
  /* note: use after variable declarations */
1395
- #define XXH_STATIC_ASSERT(c) do { enum { XXH_sa = 1/(int)(!!(c)) }; } while (0)
1497
+ #ifndef XXH_STATIC_ASSERT
1498
+ # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
1499
+ # include <assert.h>
1500
+ # define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { static_assert((c),m); } while(0)
1501
+ # elif defined(__cplusplus) && (__cplusplus >= 201103L) /* C++11 */
1502
+ # define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { static_assert((c),m); } while(0)
1503
+ # else
1504
+ # define XXH_STATIC_ASSERT_WITH_MESSAGE(c,m) do { struct xxh_sa { char x[(c) ? 1 : -1]; }; } while(0)
1505
+ # endif
1506
+ # define XXH_STATIC_ASSERT(c) XXH_STATIC_ASSERT_WITH_MESSAGE((c),#c)
1507
+ #endif
1396
1508
 
1397
1509
  /*!
1398
1510
  * @internal
@@ -1534,7 +1646,6 @@ static xxh_u32 XXH_read32(const void* memPtr)
1534
1646
 
1535
1647
 
1536
1648
  /* *** Endianness *** */
1537
- typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
1538
1649
 
1539
1650
  /*!
1540
1651
  * @ingroup tuning
@@ -1544,8 +1655,8 @@ typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
1544
1655
  * Defined to 1 if the target is little endian, or 0 if it is big endian.
1545
1656
  * It can be defined externally, for example on the compiler command line.
1546
1657
  *
1547
- * If it is not defined, a runtime check (which is usually constant folded)
1548
- * is used instead.
1658
+ * If it is not defined,
1659
+ * a runtime check (which is usually constant folded) is used instead.
1549
1660
  *
1550
1661
  * @note
1551
1662
  * This is not necessarily defined to an integer constant.
@@ -1859,41 +1970,41 @@ XXH32_finalize(xxh_u32 h32, const xxh_u8* ptr, size_t len, XXH_alignment align)
1859
1970
  } else {
1860
1971
  switch(len&15) /* or switch(bEnd - p) */ {
1861
1972
  case 12: XXH_PROCESS4;
1862
- /* fallthrough */
1973
+ XXH_FALLTHROUGH;
1863
1974
  case 8: XXH_PROCESS4;
1864
- /* fallthrough */
1975
+ XXH_FALLTHROUGH;
1865
1976
  case 4: XXH_PROCESS4;
1866
1977
  return XXH32_avalanche(h32);
1867
1978
 
1868
1979
  case 13: XXH_PROCESS4;
1869
- /* fallthrough */
1980
+ XXH_FALLTHROUGH;
1870
1981
  case 9: XXH_PROCESS4;
1871
- /* fallthrough */
1982
+ XXH_FALLTHROUGH;
1872
1983
  case 5: XXH_PROCESS4;
1873
1984
  XXH_PROCESS1;
1874
1985
  return XXH32_avalanche(h32);
1875
1986
 
1876
1987
  case 14: XXH_PROCESS4;
1877
- /* fallthrough */
1988
+ XXH_FALLTHROUGH;
1878
1989
  case 10: XXH_PROCESS4;
1879
- /* fallthrough */
1990
+ XXH_FALLTHROUGH;
1880
1991
  case 6: XXH_PROCESS4;
1881
1992
  XXH_PROCESS1;
1882
1993
  XXH_PROCESS1;
1883
1994
  return XXH32_avalanche(h32);
1884
1995
 
1885
1996
  case 15: XXH_PROCESS4;
1886
- /* fallthrough */
1997
+ XXH_FALLTHROUGH;
1887
1998
  case 11: XXH_PROCESS4;
1888
- /* fallthrough */
1999
+ XXH_FALLTHROUGH;
1889
2000
  case 7: XXH_PROCESS4;
1890
- /* fallthrough */
2001
+ XXH_FALLTHROUGH;
1891
2002
  case 3: XXH_PROCESS1;
1892
- /* fallthrough */
2003
+ XXH_FALLTHROUGH;
1893
2004
  case 2: XXH_PROCESS1;
1894
- /* fallthrough */
2005
+ XXH_FALLTHROUGH;
1895
2006
  case 1: XXH_PROCESS1;
1896
- /* fallthrough */
2007
+ XXH_FALLTHROUGH;
1897
2008
  case 0: return XXH32_avalanche(h32);
1898
2009
  }
1899
2010
  XXH_ASSERT(0);
@@ -1920,7 +2031,7 @@ XXH32_finalize(xxh_u32 h32, const xxh_u8* ptr, size_t len, XXH_alignment align)
1920
2031
  XXH_FORCE_INLINE xxh_u32
1921
2032
  XXH32_endian_align(const xxh_u8* input, size_t len, xxh_u32 seed, XXH_alignment align)
1922
2033
  {
1923
- const xxh_u8* bEnd = input + len;
2034
+ const xxh_u8* bEnd = input ? input + len : NULL;
1924
2035
  xxh_u32 h32;
1925
2036
 
1926
2037
  #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
@@ -2348,7 +2459,7 @@ XXH64_finalize(xxh_u64 h64, const xxh_u8* ptr, size_t len, XXH_alignment align)
2348
2459
  XXH_FORCE_INLINE xxh_u64
2349
2460
  XXH64_endian_align(const xxh_u8* input, size_t len, xxh_u64 seed, XXH_alignment align)
2350
2461
  {
2351
- const xxh_u8* bEnd = input + len;
2462
+ const xxh_u8* bEnd = input ? input + len : NULL;
2352
2463
  xxh_u64 h64;
2353
2464
 
2354
2465
  #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
@@ -3341,7 +3452,7 @@ XXH3_len_9to16_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_
3341
3452
  {
3342
3453
  XXH_ASSERT(input != NULL);
3343
3454
  XXH_ASSERT(secret != NULL);
3344
- XXH_ASSERT(8 <= len && len <= 16);
3455
+ XXH_ASSERT(9 <= len && len <= 16);
3345
3456
  { xxh_u64 const bitflip1 = (XXH_readLE64(secret+24) ^ XXH_readLE64(secret+32)) + seed;
3346
3457
  xxh_u64 const bitflip2 = (XXH_readLE64(secret+40) ^ XXH_readLE64(secret+48)) - seed;
3347
3458
  xxh_u64 const input_lo = XXH_readLE64(input) ^ bitflip1;
@@ -3649,17 +3760,19 @@ XXH3_initCustomSecret_avx512(void* XXH_RESTRICT customSecret, xxh_u64 seed64)
3649
3760
  XXH_ASSERT(((size_t)customSecret & 63) == 0);
3650
3761
  (void)(&XXH_writeLE64);
3651
3762
  { int const nbRounds = XXH_SECRET_DEFAULT_SIZE / sizeof(__m512i);
3652
- __m512i const seed = _mm512_mask_set1_epi64(_mm512_set1_epi64((xxh_i64)seed64), 0xAA, -(xxh_i64)seed64);
3763
+ __m512i const seed = _mm512_mask_set1_epi64(_mm512_set1_epi64((xxh_i64)seed64), 0xAA, (xxh_i64)(0U - seed64));
3653
3764
 
3654
- XXH_ALIGN(64) const __m512i* const src = (const __m512i*) XXH3_kSecret;
3655
- XXH_ALIGN(64) __m512i* const dest = ( __m512i*) customSecret;
3765
+ const __m512i* const src = (const __m512i*) ((const void*) XXH3_kSecret);
3766
+ __m512i* const dest = ( __m512i*) customSecret;
3656
3767
  int i;
3768
+ XXH_ASSERT(((size_t)src & 63) == 0); /* control alignment */
3769
+ XXH_ASSERT(((size_t)dest & 63) == 0);
3657
3770
  for (i=0; i < nbRounds; ++i) {
3658
3771
  /* GCC has a bug, _mm512_stream_load_si512 accepts 'void*', not 'void const*',
3659
- * this will warn "discards const qualifier". */
3772
+ * this will warn "discards 'const' qualifier". */
3660
3773
  union {
3661
- XXH_ALIGN(64) const __m512i* cp;
3662
- XXH_ALIGN(64) void* p;
3774
+ const __m512i* cp;
3775
+ void* p;
3663
3776
  } remote_const_void;
3664
3777
  remote_const_void.cp = src + i;
3665
3778
  dest[i] = _mm512_add_epi64(_mm512_stream_load_si512(remote_const_void.p), seed);
@@ -3745,10 +3858,10 @@ XXH_FORCE_INLINE XXH_TARGET_AVX2 void XXH3_initCustomSecret_avx2(void* XXH_RESTR
3745
3858
  XXH_STATIC_ASSERT(XXH_SEC_ALIGN <= 64);
3746
3859
  (void)(&XXH_writeLE64);
3747
3860
  XXH_PREFETCH(customSecret);
3748
- { __m256i const seed = _mm256_set_epi64x(-(xxh_i64)seed64, (xxh_i64)seed64, -(xxh_i64)seed64, (xxh_i64)seed64);
3861
+ { __m256i const seed = _mm256_set_epi64x((xxh_i64)(0U - seed64), (xxh_i64)seed64, (xxh_i64)(0U - seed64), (xxh_i64)seed64);
3749
3862
 
3750
- XXH_ALIGN(64) const __m256i* const src = (const __m256i*) XXH3_kSecret;
3751
- XXH_ALIGN(64) __m256i* dest = ( __m256i*) customSecret;
3863
+ const __m256i* const src = (const __m256i*) ((const void*) XXH3_kSecret);
3864
+ __m256i* dest = ( __m256i*) customSecret;
3752
3865
 
3753
3866
  # if defined(__GNUC__) || defined(__clang__)
3754
3867
  /*
@@ -3758,6 +3871,8 @@ XXH_FORCE_INLINE XXH_TARGET_AVX2 void XXH3_initCustomSecret_avx2(void* XXH_RESTR
3758
3871
  */
3759
3872
  XXH_COMPILER_GUARD(dest);
3760
3873
  # endif
3874
+ XXH_ASSERT(((size_t)src & 31) == 0); /* control alignment */
3875
+ XXH_ASSERT(((size_t)dest & 31) == 0);
3761
3876
 
3762
3877
  /* GCC -O2 need unroll loop manually */
3763
3878
  dest[0] = _mm256_add_epi64(_mm256_stream_load_si256(src+0), seed);
@@ -3849,27 +3964,29 @@ XXH_FORCE_INLINE XXH_TARGET_SSE2 void XXH3_initCustomSecret_sse2(void* XXH_RESTR
3849
3964
  { int const nbRounds = XXH_SECRET_DEFAULT_SIZE / sizeof(__m128i);
3850
3965
 
3851
3966
  # if defined(_MSC_VER) && defined(_M_IX86) && _MSC_VER < 1900
3852
- // MSVC 32bit mode does not support _mm_set_epi64x before 2015
3853
- XXH_ALIGN(16) const xxh_i64 seed64x2[2] = { (xxh_i64)seed64, -(xxh_i64)seed64 };
3967
+ /* MSVC 32bit mode does not support _mm_set_epi64x before 2015 */
3968
+ XXH_ALIGN(16) const xxh_i64 seed64x2[2] = { (xxh_i64)seed64, (xxh_i64)(0U - seed64) };
3854
3969
  __m128i const seed = _mm_load_si128((__m128i const*)seed64x2);
3855
3970
  # else
3856
- __m128i const seed = _mm_set_epi64x(-(xxh_i64)seed64, (xxh_i64)seed64);
3971
+ __m128i const seed = _mm_set_epi64x((xxh_i64)(0U - seed64), (xxh_i64)seed64);
3857
3972
  # endif
3858
3973
  int i;
3859
3974
 
3860
- XXH_ALIGN(64) const float* const src = (float const*) XXH3_kSecret;
3861
- XXH_ALIGN(XXH_SEC_ALIGN) __m128i* dest = (__m128i*) customSecret;
3975
+ const void* const src16 = XXH3_kSecret;
3976
+ __m128i* dst16 = (__m128i*) customSecret;
3862
3977
  # if defined(__GNUC__) || defined(__clang__)
3863
3978
  /*
3864
3979
  * On GCC & Clang, marking 'dest' as modified will cause the compiler:
3865
3980
  * - do not extract the secret from sse registers in the internal loop
3866
3981
  * - use less common registers, and avoid pushing these reg into stack
3867
3982
  */
3868
- XXH_COMPILER_GUARD(dest);
3983
+ XXH_COMPILER_GUARD(dst16);
3869
3984
  # endif
3985
+ XXH_ASSERT(((size_t)src16 & 15) == 0); /* control alignment */
3986
+ XXH_ASSERT(((size_t)dst16 & 15) == 0);
3870
3987
 
3871
3988
  for (i=0; i < nbRounds; ++i) {
3872
- dest[i] = _mm_add_epi64(_mm_castps_si128(_mm_load_ps(src+i*4)), seed);
3989
+ dst16[i] = _mm_add_epi64(_mm_load_si128((const __m128i *)src16+i), seed);
3873
3990
  } }
3874
3991
  }
3875
3992
 
@@ -4645,7 +4762,7 @@ XXH3_update(XXH3_state_t* state,
4645
4762
  XXH_ASSERT(input < bEnd);
4646
4763
 
4647
4764
  /* Consume input by a multiple of internal buffer size */
4648
- if (input+XXH3_INTERNALBUFFER_SIZE < bEnd) {
4765
+ if (bEnd - input > XXH3_INTERNALBUFFER_SIZE) {
4649
4766
  const xxh_u8* const limit = bEnd - XXH3_INTERNALBUFFER_SIZE;
4650
4767
  do {
4651
4768
  XXH3_consumeStripes(state->acc,
@@ -2,6 +2,6 @@ require 'digest'
2
2
 
3
3
  module Digest
4
4
  class XXHash < Digest::Class
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digest-xxhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - konsolebox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-13 00:00:00.000000000 Z
11
+ date: 2021-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake