zstd-ruby 1.3.8.0 → 1.4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -5
  3. data/README.md +1 -1
  4. data/ext/zstdruby/libzstd/Makefile +133 -61
  5. data/ext/zstdruby/libzstd/README.md +51 -18
  6. data/ext/zstdruby/libzstd/common/bitstream.h +38 -39
  7. data/ext/zstdruby/libzstd/common/compiler.h +41 -6
  8. data/ext/zstdruby/libzstd/common/cpu.h +1 -1
  9. data/ext/zstdruby/libzstd/common/debug.c +11 -31
  10. data/ext/zstdruby/libzstd/common/debug.h +11 -31
  11. data/ext/zstdruby/libzstd/common/entropy_common.c +13 -33
  12. data/ext/zstdruby/libzstd/common/error_private.c +2 -1
  13. data/ext/zstdruby/libzstd/common/error_private.h +6 -2
  14. data/ext/zstdruby/libzstd/common/fse.h +13 -33
  15. data/ext/zstdruby/libzstd/common/fse_decompress.c +12 -35
  16. data/ext/zstdruby/libzstd/common/huf.h +15 -33
  17. data/ext/zstdruby/libzstd/common/mem.h +75 -2
  18. data/ext/zstdruby/libzstd/common/pool.c +8 -4
  19. data/ext/zstdruby/libzstd/common/pool.h +2 -2
  20. data/ext/zstdruby/libzstd/common/threading.c +52 -6
  21. data/ext/zstdruby/libzstd/common/threading.h +36 -4
  22. data/ext/zstdruby/libzstd/common/xxhash.c +25 -37
  23. data/ext/zstdruby/libzstd/common/xxhash.h +11 -31
  24. data/ext/zstdruby/libzstd/common/zstd_common.c +1 -1
  25. data/ext/zstdruby/libzstd/common/zstd_errors.h +2 -1
  26. data/ext/zstdruby/libzstd/common/zstd_internal.h +203 -22
  27. data/ext/zstdruby/libzstd/compress/fse_compress.c +19 -42
  28. data/ext/zstdruby/libzstd/compress/hist.c +15 -35
  29. data/ext/zstdruby/libzstd/compress/hist.h +12 -32
  30. data/ext/zstdruby/libzstd/compress/huf_compress.c +92 -92
  31. data/ext/zstdruby/libzstd/compress/zstd_compress.c +1460 -1472
  32. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +330 -65
  33. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +158 -0
  34. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +29 -0
  35. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +419 -0
  36. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +54 -0
  37. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +845 -0
  38. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +32 -0
  39. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +525 -0
  40. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +65 -43
  41. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +2 -2
  42. data/ext/zstdruby/libzstd/compress/zstd_fast.c +264 -159
  43. data/ext/zstdruby/libzstd/compress/zstd_fast.h +2 -2
  44. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +74 -42
  45. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +2 -2
  46. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +33 -11
  47. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +7 -2
  48. data/ext/zstdruby/libzstd/compress/zstd_opt.c +108 -125
  49. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  50. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +129 -93
  51. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +46 -28
  52. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +76 -60
  53. data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +14 -10
  54. data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +2 -2
  55. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +471 -258
  56. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +471 -346
  57. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +3 -3
  58. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +25 -4
  59. data/ext/zstdruby/libzstd/deprecated/zbuff.h +9 -8
  60. data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +2 -2
  61. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -1
  62. data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
  63. data/ext/zstdruby/libzstd/dictBuilder/cover.c +220 -65
  64. data/ext/zstdruby/libzstd/dictBuilder/cover.h +81 -7
  65. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +85 -56
  66. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +43 -19
  67. data/ext/zstdruby/libzstd/dictBuilder/zdict.h +73 -35
  68. data/ext/zstdruby/libzstd/dll/example/Makefile +2 -1
  69. data/ext/zstdruby/libzstd/dll/example/build_package.bat +3 -2
  70. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +49 -15
  71. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +142 -117
  72. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +13 -8
  73. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +54 -25
  74. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +13 -8
  75. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +55 -25
  76. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +13 -8
  77. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +62 -29
  78. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +13 -8
  79. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +145 -109
  80. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +14 -9
  81. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +56 -26
  82. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +11 -6
  83. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +65 -28
  84. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +11 -6
  85. data/ext/zstdruby/libzstd/libzstd.pc.in +3 -2
  86. data/ext/zstdruby/libzstd/zstd.h +921 -597
  87. data/lib/zstd-ruby/version.rb +1 -1
  88. data/zstd-ruby.gemspec +2 -2
  89. metadata +19 -14
  90. data/ext/zstdruby/libzstd/dll/libzstd.def +0 -87
@@ -1,35 +1,15 @@
1
1
  /*
2
- xxHash - Extremely Fast Hash algorithm
3
- Header File
4
- Copyright (C) 2012-2016, 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
- - xxHash source repository : https://github.com/Cyan4973/xxHash
2
+ * xxHash - Extremely Fast Hash algorithm
3
+ * Header File
4
+ * Copyright (c) 2012-2020, Yann Collet, Facebook, Inc.
5
+ *
6
+ * You can contact the author at :
7
+ * - xxHash source repository : https://github.com/Cyan4973/xxHash
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
33
13
  */
34
14
 
35
15
  /* Notice extracted from xxHash homepage :
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, 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
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, 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
@@ -76,6 +76,7 @@ typedef enum {
76
76
  /* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
77
77
  ZSTD_error_frameIndex_tooLarge = 100,
78
78
  ZSTD_error_seekableIO = 102,
79
+ ZSTD_error_dstBuffer_wrong = 104,
79
80
  ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
80
81
  } ZSTD_ErrorCode;
81
82
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, 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
@@ -19,12 +19,15 @@
19
19
  /*-*************************************
20
20
  * Dependencies
21
21
  ***************************************/
22
+ #ifdef __aarch64__
23
+ #include <arm_neon.h>
24
+ #endif
22
25
  #include "compiler.h"
23
26
  #include "mem.h"
24
27
  #include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
25
28
  #include "error_private.h"
26
29
  #define ZSTD_STATIC_LINKING_ONLY
27
- #include "zstd.h"
30
+ #include "../zstd.h"
28
31
  #define FSE_STATIC_LINKING_ONLY
29
32
  #include "fse.h"
30
33
  #define HUF_STATIC_LINKING_ONLY
@@ -34,7 +37,6 @@
34
37
  #endif
35
38
  #include "xxhash.h" /* XXH_reset, update, digest */
36
39
 
37
-
38
40
  #if defined (__cplusplus)
39
41
  extern "C" {
40
42
  #endif
@@ -53,8 +55,81 @@ extern "C" {
53
55
  #undef MAX
54
56
  #define MIN(a,b) ((a)<(b) ? (a) : (b))
55
57
  #define MAX(a,b) ((a)>(b) ? (a) : (b))
56
- #define CHECK_F(f) { size_t const errcod = f; if (ERR_isError(errcod)) return errcod; } /* check and Forward error code */
57
- #define CHECK_E(f, e) { size_t const errcod = f; if (ERR_isError(errcod)) return ERROR(e); } /* check and send Error code */
58
+
59
+ /**
60
+ * Ignore: this is an internal helper.
61
+ *
62
+ * This is a helper function to help force C99-correctness during compilation.
63
+ * Under strict compilation modes, variadic macro arguments can't be empty.
64
+ * However, variadic function arguments can be. Using a function therefore lets
65
+ * us statically check that at least one (string) argument was passed,
66
+ * independent of the compilation flags.
67
+ */
68
+ static INLINE_KEYWORD UNUSED_ATTR
69
+ void _force_has_format_string(const char *format, ...) {
70
+ (void)format;
71
+ }
72
+
73
+ /**
74
+ * Ignore: this is an internal helper.
75
+ *
76
+ * We want to force this function invocation to be syntactically correct, but
77
+ * we don't want to force runtime evaluation of its arguments.
78
+ */
79
+ #define _FORCE_HAS_FORMAT_STRING(...) \
80
+ if (0) { \
81
+ _force_has_format_string(__VA_ARGS__); \
82
+ }
83
+
84
+ /**
85
+ * Return the specified error if the condition evaluates to true.
86
+ *
87
+ * In debug modes, prints additional information.
88
+ * In order to do that (particularly, printing the conditional that failed),
89
+ * this can't just wrap RETURN_ERROR().
90
+ */
91
+ #define RETURN_ERROR_IF(cond, err, ...) \
92
+ if (cond) { \
93
+ RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
94
+ __FILE__, __LINE__, ZSTD_QUOTE(cond), ZSTD_QUOTE(ERROR(err))); \
95
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
96
+ RAWLOG(3, ": " __VA_ARGS__); \
97
+ RAWLOG(3, "\n"); \
98
+ return ERROR(err); \
99
+ }
100
+
101
+ /**
102
+ * Unconditionally return the specified error.
103
+ *
104
+ * In debug modes, prints additional information.
105
+ */
106
+ #define RETURN_ERROR(err, ...) \
107
+ do { \
108
+ RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
109
+ __FILE__, __LINE__, ZSTD_QUOTE(ERROR(err))); \
110
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
111
+ RAWLOG(3, ": " __VA_ARGS__); \
112
+ RAWLOG(3, "\n"); \
113
+ return ERROR(err); \
114
+ } while(0);
115
+
116
+ /**
117
+ * If the provided expression evaluates to an error code, returns that error code.
118
+ *
119
+ * In debug modes, prints additional information.
120
+ */
121
+ #define FORWARD_IF_ERROR(err, ...) \
122
+ do { \
123
+ size_t const err_code = (err); \
124
+ if (ERR_isError(err_code)) { \
125
+ RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
126
+ __FILE__, __LINE__, ZSTD_QUOTE(err), ERR_getErrorName(err_code)); \
127
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
128
+ RAWLOG(3, ": " __VA_ARGS__); \
129
+ RAWLOG(3, "\n"); \
130
+ return err_code; \
131
+ } \
132
+ } while(0);
58
133
 
59
134
 
60
135
  /*-*************************************
@@ -87,6 +162,8 @@ static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
87
162
  static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
88
163
  typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
89
164
 
165
+ #define ZSTD_FRAMECHECKSUMSIZE 4
166
+
90
167
  #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
91
168
  #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
92
169
 
@@ -150,32 +227,99 @@ static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
150
227
  /*-*******************************************
151
228
  * Shared functions to include for inlining
152
229
  *********************************************/
153
- static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
230
+ static void ZSTD_copy8(void* dst, const void* src) {
231
+ #ifdef __aarch64__
232
+ vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
233
+ #else
234
+ memcpy(dst, src, 8);
235
+ #endif
236
+ }
237
+
154
238
  #define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
239
+ static void ZSTD_copy16(void* dst, const void* src) {
240
+ #ifdef __aarch64__
241
+ vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
242
+ #else
243
+ memcpy(dst, src, 16);
244
+ #endif
245
+ }
246
+ #define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
247
+
248
+ #define WILDCOPY_OVERLENGTH 32
249
+ #define WILDCOPY_VECLEN 16
250
+
251
+ typedef enum {
252
+ ZSTD_no_overlap,
253
+ ZSTD_overlap_src_before_dst
254
+ /* ZSTD_overlap_dst_before_src, */
255
+ } ZSTD_overlap_e;
155
256
 
156
257
  /*! ZSTD_wildcopy() :
157
- * custom version of memcpy(), can overwrite up to WILDCOPY_OVERLENGTH bytes (if length==0) */
158
- #define WILDCOPY_OVERLENGTH 8
159
- MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length)
258
+ * Custom version of memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)
259
+ * @param ovtype controls the overlap detection
260
+ * - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
261
+ * - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart.
262
+ * The src buffer must be before the dst buffer.
263
+ */
264
+ MEM_STATIC FORCE_INLINE_ATTR
265
+ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
160
266
  {
267
+ ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
161
268
  const BYTE* ip = (const BYTE*)src;
162
269
  BYTE* op = (BYTE*)dst;
163
270
  BYTE* const oend = op + length;
164
- do
165
- COPY8(op, ip)
166
- while (op < oend);
271
+
272
+ assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff <= -WILDCOPY_VECLEN));
273
+
274
+ if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
275
+ /* Handle short offset copies. */
276
+ do {
277
+ COPY8(op, ip)
278
+ } while (op < oend);
279
+ } else {
280
+ assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
281
+ /* Separate out the first COPY16() call because the copy length is
282
+ * almost certain to be short, so the branches have different
283
+ * probabilities. Since it is almost certain to be short, only do
284
+ * one COPY16() in the first call. Then, do two calls per loop since
285
+ * at that point it is more likely to have a high trip count.
286
+ */
287
+ #ifndef __aarch64__
288
+ do {
289
+ COPY16(op, ip);
290
+ }
291
+ while (op < oend);
292
+ #else
293
+ COPY16(op, ip);
294
+ if (op >= oend) return;
295
+ do {
296
+ COPY16(op, ip);
297
+ COPY16(op, ip);
298
+ }
299
+ while (op < oend);
300
+ #endif
301
+ }
167
302
  }
168
303
 
169
- MEM_STATIC void ZSTD_wildcopy_e(void* dst, const void* src, void* dstEnd) /* should be faster for decoding, but strangely, not verified on all platform */
304
+ MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
170
305
  {
171
- const BYTE* ip = (const BYTE*)src;
172
- BYTE* op = (BYTE*)dst;
173
- BYTE* const oend = (BYTE*)dstEnd;
174
- do
175
- COPY8(op, ip)
176
- while (op < oend);
306
+ size_t const length = MIN(dstCapacity, srcSize);
307
+ if (length > 0) {
308
+ memcpy(dst, src, length);
309
+ }
310
+ return length;
177
311
  }
178
312
 
313
+ /* define "workspace is too large" as this number of times larger than needed */
314
+ #define ZSTD_WORKSPACETOOLARGE_FACTOR 3
315
+
316
+ /* when workspace is continuously too large
317
+ * during at least this number of times,
318
+ * context's memory usage is considered wasteful,
319
+ * because it's sized to handle a worst case scenario which rarely happens.
320
+ * In which case, resize it down to free some memory */
321
+ #define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128
322
+
179
323
 
180
324
  /*-*******************************************
181
325
  * Private declarations
@@ -200,6 +344,42 @@ typedef struct {
200
344
  U32 longLengthPos;
201
345
  } seqStore_t;
202
346
 
347
+ typedef struct {
348
+ U32 litLength;
349
+ U32 matchLength;
350
+ } ZSTD_sequenceLength;
351
+
352
+ /**
353
+ * Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
354
+ * indicated by longLengthPos and longLengthID, and adds MINMATCH back to matchLength.
355
+ */
356
+ MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
357
+ {
358
+ ZSTD_sequenceLength seqLen;
359
+ seqLen.litLength = seq->litLength;
360
+ seqLen.matchLength = seq->matchLength + MINMATCH;
361
+ if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
362
+ if (seqStore->longLengthID == 1) {
363
+ seqLen.litLength += 0xFFFF;
364
+ }
365
+ if (seqStore->longLengthID == 2) {
366
+ seqLen.matchLength += 0xFFFF;
367
+ }
368
+ }
369
+ return seqLen;
370
+ }
371
+
372
+ /**
373
+ * Contains the compressed frame size and an upper-bound for the decompressed frame size.
374
+ * Note: before using `compressedSize`, check for errors using ZSTD_isError().
375
+ * similarly, before using `decompressedBound`, check for errors using:
376
+ * `decompressedBound != ZSTD_CONTENTSIZE_ERROR`
377
+ */
378
+ typedef struct {
379
+ size_t compressedSize;
380
+ unsigned long long decompressedBound;
381
+ } ZSTD_frameSizeInfo; /* decompress & legacy */
382
+
203
383
  const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
204
384
  void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
205
385
 
@@ -215,10 +395,11 @@ MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus
215
395
  {
216
396
  # if defined(_MSC_VER) /* Visual */
217
397
  unsigned long r=0;
218
- _BitScanReverse(&r, val);
219
- return (unsigned)r;
398
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
220
399
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
221
- return 31 - __builtin_clz(val);
400
+ return __builtin_clz (val) ^ 31;
401
+ # elif defined(__ICCARM__) /* IAR Intrinsic */
402
+ return 31 - __CLZ(val);
222
403
  # else /* Software version */
223
404
  static const U32 DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
224
405
  U32 v = val;
@@ -1,35 +1,15 @@
1
1
  /* ******************************************************************
2
- FSE : Finite State Entropy encoder
3
- Copyright (C) 2013-present, 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
- - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
32
- - Public forum : https://groups.google.com/forum/#!forum/lz4c
2
+ * FSE : Finite State Entropy encoder
3
+ * Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
4
+ *
5
+ * You can contact the author at :
6
+ * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
7
+ * - Public forum : https://groups.google.com/forum/#!forum/lz4c
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
33
13
  ****************************************************************** */
34
14
 
35
15
  /* **************************************************************
@@ -37,14 +17,14 @@
37
17
  ****************************************************************/
38
18
  #include <stdlib.h> /* malloc, free, qsort */
39
19
  #include <string.h> /* memcpy, memset */
40
- #include "compiler.h"
41
- #include "mem.h" /* U32, U16, etc. */
42
- #include "debug.h" /* assert, DEBUGLOG */
20
+ #include "../common/compiler.h"
21
+ #include "../common/mem.h" /* U32, U16, etc. */
22
+ #include "../common/debug.h" /* assert, DEBUGLOG */
43
23
  #include "hist.h" /* HIST_count_wksp */
44
- #include "bitstream.h"
24
+ #include "../common/bitstream.h"
45
25
  #define FSE_STATIC_LINKING_ONLY
46
- #include "fse.h"
47
- #include "error_private.h"
26
+ #include "../common/fse.h"
27
+ #include "../common/error_private.h"
48
28
 
49
29
 
50
30
  /* **************************************************************
@@ -129,9 +109,9 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
129
109
  { U32 position = 0;
130
110
  U32 symbol;
131
111
  for (symbol=0; symbol<=maxSymbolValue; symbol++) {
132
- int nbOccurences;
112
+ int nbOccurrences;
133
113
  int const freq = normalizedCounter[symbol];
134
- for (nbOccurences=0; nbOccurences<freq; nbOccurences++) {
114
+ for (nbOccurrences=0; nbOccurrences<freq; nbOccurrences++) {
135
115
  tableSymbol[position] = (FSE_FUNCTION_TYPE)symbol;
136
116
  position = (position + step) & tableMask;
137
117
  while (position > highThreshold)
@@ -645,9 +625,6 @@ size_t FSE_compress_usingCTable (void* dst, size_t dstSize,
645
625
 
646
626
  size_t FSE_compressBound(size_t size) { return FSE_COMPRESSBOUND(size); }
647
627
 
648
- #define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
649
- #define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
650
-
651
628
  /* FSE_compress_wksp() :
652
629
  * Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
653
630
  * `wkspSize` size must be `(1<<tableLog)`.