zstd-ruby 1.4.5.0 → 1.5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +8 -0
  3. data/.github/workflows/ruby.yml +35 -0
  4. data/README.md +2 -2
  5. data/ext/zstdruby/extconf.rb +2 -1
  6. data/ext/zstdruby/libzstd/BUCK +5 -7
  7. data/ext/zstdruby/libzstd/Makefile +225 -222
  8. data/ext/zstdruby/libzstd/README.md +43 -5
  9. data/ext/zstdruby/libzstd/common/bitstream.h +46 -22
  10. data/ext/zstdruby/libzstd/common/compiler.h +182 -22
  11. data/ext/zstdruby/libzstd/common/cpu.h +1 -3
  12. data/ext/zstdruby/libzstd/common/debug.c +1 -1
  13. data/ext/zstdruby/libzstd/common/debug.h +12 -19
  14. data/ext/zstdruby/libzstd/common/entropy_common.c +196 -44
  15. data/ext/zstdruby/libzstd/common/error_private.c +2 -1
  16. data/ext/zstdruby/libzstd/common/error_private.h +82 -3
  17. data/ext/zstdruby/libzstd/common/fse.h +41 -12
  18. data/ext/zstdruby/libzstd/common/fse_decompress.c +139 -22
  19. data/ext/zstdruby/libzstd/common/huf.h +47 -23
  20. data/ext/zstdruby/libzstd/common/mem.h +87 -98
  21. data/ext/zstdruby/libzstd/common/pool.c +23 -17
  22. data/ext/zstdruby/libzstd/common/pool.h +2 -2
  23. data/ext/zstdruby/libzstd/common/portability_macros.h +131 -0
  24. data/ext/zstdruby/libzstd/common/threading.c +6 -5
  25. data/ext/zstdruby/libzstd/common/xxhash.c +6 -846
  26. data/ext/zstdruby/libzstd/common/xxhash.h +5568 -167
  27. data/ext/zstdruby/libzstd/common/zstd_common.c +10 -10
  28. data/ext/zstdruby/libzstd/common/zstd_deps.h +111 -0
  29. data/ext/zstdruby/libzstd/common/zstd_internal.h +189 -142
  30. data/ext/zstdruby/libzstd/common/zstd_trace.h +163 -0
  31. data/ext/zstdruby/libzstd/compress/clevels.h +134 -0
  32. data/ext/zstdruby/libzstd/compress/fse_compress.c +89 -46
  33. data/ext/zstdruby/libzstd/compress/hist.c +27 -29
  34. data/ext/zstdruby/libzstd/compress/hist.h +2 -2
  35. data/ext/zstdruby/libzstd/compress/huf_compress.c +770 -198
  36. data/ext/zstdruby/libzstd/compress/zstd_compress.c +2894 -863
  37. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +390 -90
  38. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +12 -11
  39. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +4 -2
  40. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +31 -8
  41. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +1 -1
  42. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +25 -297
  43. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +1 -1
  44. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +206 -69
  45. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +307 -132
  46. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +1 -1
  47. data/ext/zstdruby/libzstd/compress/zstd_fast.c +322 -143
  48. data/ext/zstdruby/libzstd/compress/zstd_fast.h +1 -1
  49. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +1136 -174
  50. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +59 -1
  51. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +316 -213
  52. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +9 -2
  53. data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +106 -0
  54. data/ext/zstdruby/libzstd/compress/zstd_opt.c +373 -150
  55. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  56. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +152 -444
  57. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +31 -113
  58. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +1044 -403
  59. data/ext/zstdruby/libzstd/decompress/huf_decompress_amd64.S +571 -0
  60. data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +9 -9
  61. data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +2 -2
  62. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +450 -105
  63. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +913 -273
  64. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +14 -5
  65. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +59 -12
  66. data/ext/zstdruby/libzstd/deprecated/zbuff.h +1 -1
  67. data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +1 -1
  68. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +24 -4
  69. data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
  70. data/ext/zstdruby/libzstd/dictBuilder/cover.c +55 -38
  71. data/ext/zstdruby/libzstd/dictBuilder/cover.h +7 -6
  72. data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
  73. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +43 -34
  74. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +128 -58
  75. data/ext/zstdruby/libzstd/dll/example/Makefile +1 -1
  76. data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
  77. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +1 -1
  78. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +8 -8
  79. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
  80. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +9 -9
  81. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
  82. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +9 -9
  83. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
  84. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +10 -10
  85. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
  86. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +13 -13
  87. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +1 -1
  88. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +13 -13
  89. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
  90. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +13 -13
  91. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
  92. data/ext/zstdruby/libzstd/libzstd.mk +185 -0
  93. data/ext/zstdruby/libzstd/libzstd.pc.in +4 -3
  94. data/ext/zstdruby/libzstd/modulemap/module.modulemap +4 -0
  95. data/ext/zstdruby/libzstd/{dictBuilder/zdict.h → zdict.h} +154 -7
  96. data/ext/zstdruby/libzstd/zstd.h +699 -214
  97. data/ext/zstdruby/libzstd/{common/zstd_errors.h → zstd_errors.h} +2 -1
  98. data/ext/zstdruby/zstdruby.c +2 -2
  99. data/lib/zstd-ruby/version.rb +1 -1
  100. metadata +15 -6
  101. data/.travis.yml +0 -14
@@ -1,7 +1,7 @@
1
1
  /* ******************************************************************
2
2
  * bitstream
3
3
  * Part of FSE library
4
- * Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
4
+ * Copyright (c) Yann Collet, Facebook, Inc.
5
5
  *
6
6
  * You can contact the author at :
7
7
  * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -17,7 +17,6 @@
17
17
  #if defined (__cplusplus)
18
18
  extern "C" {
19
19
  #endif
20
-
21
20
  /*
22
21
  * This API consists of small unitary functions, which must be inlined for best performance.
23
22
  * Since link-time-optimization is not available for all compilers,
@@ -36,10 +35,12 @@ extern "C" {
36
35
  /*=========================================
37
36
  * Target specific
38
37
  =========================================*/
39
- #if defined(__BMI__) && defined(__GNUC__)
40
- # include <immintrin.h> /* support for bextr (experimental) */
41
- #elif defined(__ICCARM__)
42
- # include <intrinsics.h>
38
+ #ifndef ZSTD_NO_INTRINSICS
39
+ # if defined(__BMI__) && defined(__GNUC__)
40
+ # include <immintrin.h> /* support for bextr (experimental) */
41
+ # elif defined(__ICCARM__)
42
+ # include <intrinsics.h>
43
+ # endif
43
44
  #endif
44
45
 
45
46
  #define STREAM_ACCUMULATOR_MIN_32 25
@@ -141,8 +142,18 @@ MEM_STATIC unsigned BIT_highbit32 (U32 val)
141
142
  assert(val != 0);
142
143
  {
143
144
  # if defined(_MSC_VER) /* Visual */
144
- unsigned long r=0;
145
- return _BitScanReverse ( &r, val ) ? (unsigned)r : 0;
145
+ # if STATIC_BMI2 == 1
146
+ return _lzcnt_u32(val) ^ 31;
147
+ # else
148
+ if (val != 0) {
149
+ unsigned long r;
150
+ _BitScanReverse(&r, val);
151
+ return (unsigned)r;
152
+ } else {
153
+ /* Should not reach this code path */
154
+ __assume(0);
155
+ }
156
+ # endif
146
157
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
147
158
  return __builtin_clz (val) ^ 31;
148
159
  # elif defined(__ICCARM__) /* IAR Intrinsic */
@@ -198,7 +209,7 @@ MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
198
209
  MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
199
210
  size_t value, unsigned nbBits)
200
211
  {
201
- MEM_STATIC_ASSERT(BIT_MASK_SIZE == 32);
212
+ DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
202
213
  assert(nbBits < BIT_MASK_SIZE);
203
214
  assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
204
215
  bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos;
@@ -271,7 +282,7 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC)
271
282
  */
272
283
  MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize)
273
284
  {
274
- if (srcSize < 1) { memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
285
+ if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
275
286
 
276
287
  bitD->start = (const char*)srcBuffer;
277
288
  bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
@@ -288,22 +299,22 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
288
299
  switch(srcSize)
289
300
  {
290
301
  case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
291
- /* fall-through */
302
+ ZSTD_FALLTHROUGH;
292
303
 
293
304
  case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
294
- /* fall-through */
305
+ ZSTD_FALLTHROUGH;
295
306
 
296
307
  case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
297
- /* fall-through */
308
+ ZSTD_FALLTHROUGH;
298
309
 
299
310
  case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
300
- /* fall-through */
311
+ ZSTD_FALLTHROUGH;
301
312
 
302
313
  case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
303
- /* fall-through */
314
+ ZSTD_FALLTHROUGH;
304
315
 
305
316
  case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8;
306
- /* fall-through */
317
+ ZSTD_FALLTHROUGH;
307
318
 
308
319
  default: break;
309
320
  }
@@ -317,23 +328,36 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
317
328
  return srcSize;
318
329
  }
319
330
 
320
- MEM_STATIC size_t BIT_getUpperBits(size_t bitContainer, U32 const start)
331
+ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getUpperBits(size_t bitContainer, U32 const start)
321
332
  {
322
333
  return bitContainer >> start;
323
334
  }
324
335
 
325
- MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits)
336
+ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits)
326
337
  {
327
338
  U32 const regMask = sizeof(bitContainer)*8 - 1;
328
339
  /* if start > regMask, bitstream is corrupted, and result is undefined */
329
340
  assert(nbBits < BIT_MASK_SIZE);
341
+ /* x86 transform & ((1 << nbBits) - 1) to bzhi instruction, it is better
342
+ * than accessing memory. When bmi2 instruction is not present, we consider
343
+ * such cpus old (pre-Haswell, 2013) and their performance is not of that
344
+ * importance.
345
+ */
346
+ #if defined(__x86_64__) || defined(_M_X86)
347
+ return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
348
+ #else
330
349
  return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
350
+ #endif
331
351
  }
332
352
 
333
- MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
353
+ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
334
354
  {
355
+ #if defined(STATIC_BMI2) && STATIC_BMI2 == 1
356
+ return _bzhi_u64(bitContainer, nbBits);
357
+ #else
335
358
  assert(nbBits < BIT_MASK_SIZE);
336
359
  return bitContainer & BIT_mask[nbBits];
360
+ #endif
337
361
  }
338
362
 
339
363
  /*! BIT_lookBits() :
@@ -342,7 +366,7 @@ MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
342
366
  * On 32-bits, maxNbBits==24.
343
367
  * On 64-bits, maxNbBits==56.
344
368
  * @return : value extracted */
345
- MEM_STATIC size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits)
369
+ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits)
346
370
  {
347
371
  /* arbitrate between double-shift and shift+mask */
348
372
  #if 1
@@ -365,7 +389,7 @@ MEM_STATIC size_t BIT_lookBitsFast(const BIT_DStream_t* bitD, U32 nbBits)
365
389
  return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
366
390
  }
367
391
 
368
- MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
392
+ MEM_STATIC FORCE_INLINE_ATTR void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
369
393
  {
370
394
  bitD->bitsConsumed += nbBits;
371
395
  }
@@ -374,7 +398,7 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
374
398
  * Read (consume) next n bits from local register and update.
375
399
  * Pay attention to not read more than nbBits contained into local register.
376
400
  * @return : extracted value. */
377
- MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits)
401
+ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits)
378
402
  {
379
403
  size_t const value = BIT_lookBits(bitD, nbBits);
380
404
  BIT_skipBits(bitD, nbBits);
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -11,6 +11,8 @@
11
11
  #ifndef ZSTD_COMPILER_H
12
12
  #define ZSTD_COMPILER_H
13
13
 
14
+ #include "portability_macros.h"
15
+
14
16
  /*-*******************************************************
15
17
  * Compiler specifics
16
18
  *********************************************************/
@@ -38,6 +40,17 @@
38
40
 
39
41
  #endif
40
42
 
43
+ /**
44
+ On MSVC qsort requires that functions passed into it use the __cdecl calling conversion(CC).
45
+ This explicitly marks such functions as __cdecl so that the code will still compile
46
+ if a CC other than __cdecl has been made the default.
47
+ */
48
+ #if defined(_MSC_VER)
49
+ # define WIN_CDECL __cdecl
50
+ #else
51
+ # define WIN_CDECL
52
+ #endif
53
+
41
54
  /**
42
55
  * FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
43
56
  * parameters. They must be inlined for the compiler to eliminate the constant
@@ -79,30 +92,19 @@
79
92
  # endif
80
93
  #endif
81
94
 
95
+
82
96
  /* target attribute */
83
- #ifndef __has_attribute
84
- #define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
85
- #endif
86
97
  #if defined(__GNUC__) || defined(__ICCARM__)
87
98
  # define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
88
99
  #else
89
100
  # define TARGET_ATTRIBUTE(target)
90
101
  #endif
91
102
 
92
- /* Enable runtime BMI2 dispatch based on the CPU.
93
- * Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default.
103
+ /* Target attribute for BMI2 dynamic dispatch.
104
+ * Enable lzcnt, bmi, and bmi2.
105
+ * We test for bmi1 & bmi2. lzcnt is included in bmi1.
94
106
  */
95
- #ifndef DYNAMIC_BMI2
96
- #if ((defined(__clang__) && __has_attribute(__target__)) \
97
- || (defined(__GNUC__) \
98
- && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \
99
- && (defined(__x86_64__) || defined(_M_X86)) \
100
- && !defined(__BMI2__)
101
- # define DYNAMIC_BMI2 1
102
- #else
103
- # define DYNAMIC_BMI2 0
104
- #endif
105
- #endif
107
+ #define BMI2_TARGET_ATTRIBUTE TARGET_ATTRIBUTE("lzcnt,bmi,bmi2")
106
108
 
107
109
  /* prefetch
108
110
  * can be disabled, by declaring NO_PREFETCH build macro */
@@ -114,12 +116,12 @@
114
116
  # include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
115
117
  # define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
116
118
  # define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
117
- # elif defined(__aarch64__)
118
- # define PREFETCH_L1(ptr) __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr)))
119
- # define PREFETCH_L2(ptr) __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr)))
120
119
  # elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
121
120
  # define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
122
121
  # define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
122
+ # elif defined(__aarch64__)
123
+ # define PREFETCH_L1(ptr) __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr)))
124
+ # define PREFETCH_L2(ptr) __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr)))
123
125
  # else
124
126
  # define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
125
127
  # define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
@@ -138,8 +140,9 @@
138
140
  }
139
141
 
140
142
  /* vectorization
141
- * older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax */
142
- #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__)
143
+ * older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax,
144
+ * and some compilers, like Intel ICC and MCST LCC, do not support it at all. */
145
+ #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && !defined(__LCC__)
143
146
  # if (__GNUC__ == 4 && __GNUC_MINOR__ > 3) || (__GNUC__ >= 5)
144
147
  # define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
145
148
  # else
@@ -172,4 +175,161 @@
172
175
  # pragma warning(disable : 4324) /* disable: C4324: padded structure */
173
176
  #endif
174
177
 
178
+ /*Like DYNAMIC_BMI2 but for compile time determination of BMI2 support*/
179
+ #ifndef STATIC_BMI2
180
+ # if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86))
181
+ # ifdef __AVX2__ //MSVC does not have a BMI2 specific flag, but every CPU that supports AVX2 also supports BMI2
182
+ # define STATIC_BMI2 1
183
+ # endif
184
+ # endif
185
+ #endif
186
+
187
+ #ifndef STATIC_BMI2
188
+ #define STATIC_BMI2 0
189
+ #endif
190
+
191
+ /* compile time determination of SIMD support */
192
+ #if !defined(ZSTD_NO_INTRINSICS)
193
+ # if defined(__SSE2__) || defined(_M_AMD64) || (defined (_M_IX86) && defined(_M_IX86_FP) && (_M_IX86_FP >= 2))
194
+ # define ZSTD_ARCH_X86_SSE2
195
+ # endif
196
+ # if defined(__ARM_NEON) || defined(_M_ARM64)
197
+ # define ZSTD_ARCH_ARM_NEON
198
+ # endif
199
+ #
200
+ # if defined(ZSTD_ARCH_X86_SSE2)
201
+ # include <emmintrin.h>
202
+ # elif defined(ZSTD_ARCH_ARM_NEON)
203
+ # include <arm_neon.h>
204
+ # endif
205
+ #endif
206
+
207
+ /* C-language Attributes are added in C23. */
208
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) && defined(__has_c_attribute)
209
+ # define ZSTD_HAS_C_ATTRIBUTE(x) __has_c_attribute(x)
210
+ #else
211
+ # define ZSTD_HAS_C_ATTRIBUTE(x) 0
212
+ #endif
213
+
214
+ /* Only use C++ attributes in C++. Some compilers report support for C++
215
+ * attributes when compiling with C.
216
+ */
217
+ #if defined(__cplusplus) && defined(__has_cpp_attribute)
218
+ # define ZSTD_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
219
+ #else
220
+ # define ZSTD_HAS_CPP_ATTRIBUTE(x) 0
221
+ #endif
222
+
223
+ /* Define ZSTD_FALLTHROUGH macro for annotating switch case with the 'fallthrough' attribute.
224
+ * - C23: https://en.cppreference.com/w/c/language/attributes/fallthrough
225
+ * - CPP17: https://en.cppreference.com/w/cpp/language/attributes/fallthrough
226
+ * - Else: __attribute__((__fallthrough__))
227
+ */
228
+ #ifndef ZSTD_FALLTHROUGH
229
+ # if ZSTD_HAS_C_ATTRIBUTE(fallthrough)
230
+ # define ZSTD_FALLTHROUGH [[fallthrough]]
231
+ # elif ZSTD_HAS_CPP_ATTRIBUTE(fallthrough)
232
+ # define ZSTD_FALLTHROUGH [[fallthrough]]
233
+ # elif __has_attribute(__fallthrough__)
234
+ /* Leading semicolon is to satisfy gcc-11 with -pedantic. Without the semicolon
235
+ * gcc complains about: a label can only be part of a statement and a declaration is not a statement.
236
+ */
237
+ # define ZSTD_FALLTHROUGH ; __attribute__((__fallthrough__))
238
+ # else
239
+ # define ZSTD_FALLTHROUGH
240
+ # endif
241
+ #endif
242
+
243
+ /*-**************************************************************
244
+ * Alignment check
245
+ *****************************************************************/
246
+
247
+ /* this test was initially positioned in mem.h,
248
+ * but this file is removed (or replaced) for linux kernel
249
+ * so it's now hosted in compiler.h,
250
+ * which remains valid for both user & kernel spaces.
251
+ */
252
+
253
+ #ifndef ZSTD_ALIGNOF
254
+ # if defined(__GNUC__) || defined(_MSC_VER)
255
+ /* covers gcc, clang & MSVC */
256
+ /* note : this section must come first, before C11,
257
+ * due to a limitation in the kernel source generator */
258
+ # define ZSTD_ALIGNOF(T) __alignof(T)
259
+
260
+ # elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
261
+ /* C11 support */
262
+ # include <stdalign.h>
263
+ # define ZSTD_ALIGNOF(T) alignof(T)
264
+
265
+ # else
266
+ /* No known support for alignof() - imperfect backup */
267
+ # define ZSTD_ALIGNOF(T) (sizeof(void*) < sizeof(T) ? sizeof(void*) : sizeof(T))
268
+
269
+ # endif
270
+ #endif /* ZSTD_ALIGNOF */
271
+
272
+ /*-**************************************************************
273
+ * Sanitizer
274
+ *****************************************************************/
275
+
276
+ #if ZSTD_MEMORY_SANITIZER
277
+ /* Not all platforms that support msan provide sanitizers/msan_interface.h.
278
+ * We therefore declare the functions we need ourselves, rather than trying to
279
+ * include the header file... */
280
+ #include <stddef.h> /* size_t */
281
+ #define ZSTD_DEPS_NEED_STDINT
282
+ #include "zstd_deps.h" /* intptr_t */
283
+
284
+ /* Make memory region fully initialized (without changing its contents). */
285
+ void __msan_unpoison(const volatile void *a, size_t size);
286
+
287
+ /* Make memory region fully uninitialized (without changing its contents).
288
+ This is a legacy interface that does not update origin information. Use
289
+ __msan_allocated_memory() instead. */
290
+ void __msan_poison(const volatile void *a, size_t size);
291
+
292
+ /* Returns the offset of the first (at least partially) poisoned byte in the
293
+ memory range, or -1 if the whole range is good. */
294
+ intptr_t __msan_test_shadow(const volatile void *x, size_t size);
295
+ #endif
296
+
297
+ #if ZSTD_ADDRESS_SANITIZER
298
+ /* Not all platforms that support asan provide sanitizers/asan_interface.h.
299
+ * We therefore declare the functions we need ourselves, rather than trying to
300
+ * include the header file... */
301
+ #include <stddef.h> /* size_t */
302
+
303
+ /**
304
+ * Marks a memory region (<c>[addr, addr+size)</c>) as unaddressable.
305
+ *
306
+ * This memory must be previously allocated by your program. Instrumented
307
+ * code is forbidden from accessing addresses in this region until it is
308
+ * unpoisoned. This function is not guaranteed to poison the entire region -
309
+ * it could poison only a subregion of <c>[addr, addr+size)</c> due to ASan
310
+ * alignment restrictions.
311
+ *
312
+ * \note This function is not thread-safe because no two threads can poison or
313
+ * unpoison memory in the same memory region simultaneously.
314
+ *
315
+ * \param addr Start of memory region.
316
+ * \param size Size of memory region. */
317
+ void __asan_poison_memory_region(void const volatile *addr, size_t size);
318
+
319
+ /**
320
+ * Marks a memory region (<c>[addr, addr+size)</c>) as addressable.
321
+ *
322
+ * This memory must be previously allocated by your program. Accessing
323
+ * addresses in this region is allowed until this region is poisoned again.
324
+ * This function could unpoison a super-region of <c>[addr, addr+size)</c> due
325
+ * to ASan alignment restrictions.
326
+ *
327
+ * \note This function is not thread-safe because no two threads can
328
+ * poison or unpoison memory in the same memory region simultaneously.
329
+ *
330
+ * \param addr Start of memory region.
331
+ * \param size Size of memory region. */
332
+ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
333
+ #endif
334
+
175
335
  #endif /* ZSTD_COMPILER_H */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2018-2020, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -16,8 +16,6 @@
16
16
  * https://github.com/facebook/folly/blob/master/folly/CpuId.h
17
17
  */
18
18
 
19
- #include <string.h>
20
-
21
19
  #include "mem.h"
22
20
 
23
21
  #ifdef _MSC_VER
@@ -1,7 +1,7 @@
1
1
  /* ******************************************************************
2
2
  * debug
3
3
  * Part of FSE library
4
- * Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
4
+ * Copyright (c) Yann Collet, Facebook, Inc.
5
5
  *
6
6
  * You can contact the author at :
7
7
  * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -1,7 +1,7 @@
1
1
  /* ******************************************************************
2
2
  * debug
3
3
  * Part of FSE library
4
- * Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
4
+ * Copyright (c) Yann Collet, Facebook, Inc.
5
5
  *
6
6
  * You can contact the author at :
7
7
  * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -51,15 +51,6 @@ extern "C" {
51
51
  #endif
52
52
 
53
53
 
54
- /* DEBUGFILE can be defined externally,
55
- * typically through compiler command line.
56
- * note : currently useless.
57
- * Value must be stderr or stdout */
58
- #ifndef DEBUGFILE
59
- # define DEBUGFILE stderr
60
- #endif
61
-
62
-
63
54
  /* recommended values for DEBUGLEVEL :
64
55
  * 0 : release mode, no debug, all run-time checks disabled
65
56
  * 1 : enables assert() only, no display
@@ -76,7 +67,8 @@ extern "C" {
76
67
  */
77
68
 
78
69
  #if (DEBUGLEVEL>=1)
79
- # include <assert.h>
70
+ # define ZSTD_DEPS_NEED_ASSERT
71
+ # include "zstd_deps.h"
80
72
  #else
81
73
  # ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
82
74
  # define assert(condition) ((void)0) /* disable assert (default) */
@@ -84,7 +76,8 @@ extern "C" {
84
76
  #endif
85
77
 
86
78
  #if (DEBUGLEVEL>=2)
87
- # include <stdio.h>
79
+ # define ZSTD_DEPS_NEED_IO
80
+ # include "zstd_deps.h"
88
81
  extern int g_debuglevel; /* the variable is only declared,
89
82
  it actually lives in debug.c,
90
83
  and is shared by the whole process.
@@ -92,14 +85,14 @@ extern int g_debuglevel; /* the variable is only declared,
92
85
  It's useful when enabling very verbose levels
93
86
  on selective conditions (such as position in src) */
94
87
 
95
- # define RAWLOG(l, ...) { \
96
- if (l<=g_debuglevel) { \
97
- fprintf(stderr, __VA_ARGS__); \
88
+ # define RAWLOG(l, ...) { \
89
+ if (l<=g_debuglevel) { \
90
+ ZSTD_DEBUG_PRINT(__VA_ARGS__); \
98
91
  } }
99
- # define DEBUGLOG(l, ...) { \
100
- if (l<=g_debuglevel) { \
101
- fprintf(stderr, __FILE__ ": " __VA_ARGS__); \
102
- fprintf(stderr, " \n"); \
92
+ # define DEBUGLOG(l, ...) { \
93
+ if (l<=g_debuglevel) { \
94
+ ZSTD_DEBUG_PRINT(__FILE__ ": " __VA_ARGS__); \
95
+ ZSTD_DEBUG_PRINT(" \n"); \
103
96
  } }
104
97
  #else
105
98
  # define RAWLOG(l, ...) {} /* disabled */