zstdlib 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +6 -1
  3. data/README.md +1 -1
  4. data/ext/zstdlib/extconf.rb +2 -2
  5. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/bitstream.h +3 -2
  6. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/compiler.h +14 -2
  7. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/cpu.h +0 -0
  8. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/debug.c +0 -0
  9. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/debug.h +0 -0
  10. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/entropy_common.c +0 -0
  11. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/error_private.c +0 -0
  12. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/error_private.h +0 -0
  13. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/fse.h +1 -1
  14. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/fse_decompress.c +2 -0
  15. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/huf.h +0 -0
  16. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/mem.h +73 -0
  17. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/pool.c +7 -3
  18. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/pool.h +0 -0
  19. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/threading.c +46 -1
  20. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/threading.h +32 -1
  21. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/xxhash.c +0 -0
  22. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/xxhash.h +0 -0
  23. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/zstd_common.c +0 -0
  24. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/zstd_errors.h +0 -0
  25. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/zstd_internal.h +32 -55
  26. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/fse_compress.c +0 -0
  27. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/hist.c +0 -0
  28. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/hist.h +0 -0
  29. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/huf_compress.c +0 -0
  30. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress.c +633 -436
  31. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress_internal.h +54 -12
  32. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress_literals.c +10 -5
  33. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress_literals.h +1 -1
  34. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress_sequences.c +3 -3
  35. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress_sequences.h +1 -1
  36. data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_cwksp.h +535 -0
  37. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_double_fast.c +9 -9
  38. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_double_fast.h +0 -0
  39. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_fast.c +30 -39
  40. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_fast.h +0 -0
  41. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_lazy.c +5 -5
  42. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_lazy.h +0 -0
  43. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_ldm.c +4 -4
  44. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_ldm.h +0 -0
  45. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_opt.c +1 -1
  46. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_opt.h +0 -0
  47. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstdmt_compress.c +32 -26
  48. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstdmt_compress.h +0 -0
  49. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/huf_decompress.c +2 -0
  50. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_ddict.c +0 -0
  51. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_ddict.h +0 -0
  52. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_decompress.c +14 -16
  53. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_decompress_block.c +144 -146
  54. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_decompress_block.h +0 -0
  55. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_decompress_internal.h +0 -0
  56. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/zstd.h +161 -59
  57. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzclose.c +1 -1
  58. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzcompatibility.h +0 -0
  59. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzguts.h +0 -0
  60. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzlib.c +9 -9
  61. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzread.c +16 -8
  62. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzwrite.c +8 -8
  63. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/zstd_zlibwrapper.c +15 -11
  64. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/zstd_zlibwrapper.h +0 -0
  65. metadata +62 -61
@@ -148,7 +148,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
148
148
  const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
149
149
  mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
150
150
  ip++;
151
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, 0, mLength-MINMATCH);
151
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
152
152
  goto _match_stored;
153
153
  }
154
154
 
@@ -157,7 +157,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
157
157
  && ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1)))) {
158
158
  mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
159
159
  ip++;
160
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, 0, mLength-MINMATCH);
160
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
161
161
  goto _match_stored;
162
162
  }
163
163
 
@@ -247,7 +247,7 @@ _match_found:
247
247
  offset_2 = offset_1;
248
248
  offset_1 = offset;
249
249
 
250
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
250
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
251
251
 
252
252
  _match_stored:
253
253
  /* match found */
@@ -278,7 +278,7 @@ _match_stored:
278
278
  const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
279
279
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
280
280
  U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
281
- ZSTD_storeSeq(seqStore, 0, anchor, 0, repLength2-MINMATCH);
281
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
282
282
  hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
283
283
  hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
284
284
  ip += repLength2;
@@ -297,7 +297,7 @@ _match_stored:
297
297
  U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; /* swap offset_2 <=> offset_1 */
298
298
  hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip-base);
299
299
  hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip-base);
300
- ZSTD_storeSeq(seqStore, 0, anchor, 0, rLength-MINMATCH);
300
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, rLength-MINMATCH);
301
301
  ip += rLength;
302
302
  anchor = ip;
303
303
  continue; /* faster when present ... (?) */
@@ -411,7 +411,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
411
411
  const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
412
412
  mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
413
413
  ip++;
414
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, 0, mLength-MINMATCH);
414
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
415
415
  } else {
416
416
  if ((matchLongIndex > dictStartIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
417
417
  const BYTE* const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
@@ -422,7 +422,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
422
422
  while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
423
423
  offset_2 = offset_1;
424
424
  offset_1 = offset;
425
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
425
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
426
426
 
427
427
  } else if ((matchIndex > dictStartIndex) && (MEM_read32(match) == MEM_read32(ip))) {
428
428
  size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
@@ -447,7 +447,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
447
447
  }
448
448
  offset_2 = offset_1;
449
449
  offset_1 = offset;
450
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
450
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
451
451
 
452
452
  } else {
453
453
  ip += ((ip-anchor) >> kSearchStrength) + 1;
@@ -479,7 +479,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
479
479
  const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
480
480
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
481
481
  U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
482
- ZSTD_storeSeq(seqStore, 0, anchor, 0, repLength2-MINMATCH);
482
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
483
483
  hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
484
484
  hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
485
485
  ip += repLength2;
@@ -8,7 +8,7 @@
8
8
  * You may select, at your option, one of the above-listed licenses.
9
9
  */
10
10
 
11
- #include "zstd_compress_internal.h"
11
+ #include "zstd_compress_internal.h" /* ZSTD_hashPtr, ZSTD_count, ZSTD_storeSeq */
12
12
  #include "zstd_fast.h"
13
13
 
14
14
 
@@ -43,8 +43,8 @@ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
43
43
  }
44
44
 
45
45
 
46
- FORCE_INLINE_TEMPLATE
47
- size_t ZSTD_compressBlock_fast_generic(
46
+ FORCE_INLINE_TEMPLATE size_t
47
+ ZSTD_compressBlock_fast_generic(
48
48
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
49
49
  void const* src, size_t srcSize,
50
50
  U32 const mls)
@@ -74,8 +74,7 @@ size_t ZSTD_compressBlock_fast_generic(
74
74
  DEBUGLOG(5, "ZSTD_compressBlock_fast_generic");
75
75
  ip0 += (ip0 == prefixStart);
76
76
  ip1 = ip0 + 1;
77
- {
78
- U32 const maxRep = (U32)(ip0 - prefixStart);
77
+ { U32 const maxRep = (U32)(ip0 - prefixStart);
79
78
  if (offset_2 > maxRep) offsetSaved = offset_2, offset_2 = 0;
80
79
  if (offset_1 > maxRep) offsetSaved = offset_1, offset_1 = 0;
81
80
  }
@@ -118,8 +117,7 @@ size_t ZSTD_compressBlock_fast_generic(
118
117
  match0 = match1;
119
118
  goto _offset;
120
119
  }
121
- {
122
- size_t const step = ((ip0-anchor) >> (kSearchStrength - 1)) + stepSize;
120
+ { size_t const step = ((size_t)(ip0-anchor) >> (kSearchStrength - 1)) + stepSize;
123
121
  assert(step >= 2);
124
122
  ip0 += step;
125
123
  ip1 += step;
@@ -138,7 +136,7 @@ _offset: /* Requires: ip0, match0 */
138
136
  _match: /* Requires: ip0, match0, offcode */
139
137
  /* Count the forward length */
140
138
  mLength += ZSTD_count(ip0+mLength+4, match0+mLength+4, iend) + 4;
141
- ZSTD_storeSeq(seqStore, ip0-anchor, anchor, offcode, mLength-MINMATCH);
139
+ ZSTD_storeSeq(seqStore, (size_t)(ip0-anchor), anchor, iend, offcode, mLength-MINMATCH);
142
140
  /* match found */
143
141
  ip0 += mLength;
144
142
  anchor = ip0;
@@ -150,16 +148,15 @@ _match: /* Requires: ip0, match0, offcode */
150
148
  hashTable[ZSTD_hashPtr(base+current0+2, hlog, mls)] = current0+2; /* here because current+2 could be > iend-8 */
151
149
  hashTable[ZSTD_hashPtr(ip0-2, hlog, mls)] = (U32)(ip0-2-base);
152
150
 
153
- while ( (ip0 <= ilimit)
154
- && ( (offset_2>0)
155
- & (MEM_read32(ip0) == MEM_read32(ip0 - offset_2)) )) {
151
+ while ( ((ip0 <= ilimit) & (offset_2>0)) /* offset_2==0 means offset_2 is invalidated */
152
+ && (MEM_read32(ip0) == MEM_read32(ip0 - offset_2)) ) {
156
153
  /* store sequence */
157
154
  size_t const rLength = ZSTD_count(ip0+4, ip0+4-offset_2, iend) + 4;
158
- U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; /* swap offset_2 <=> offset_1 */
155
+ { U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; } /* swap offset_2 <=> offset_1 */
159
156
  hashTable[ZSTD_hashPtr(ip0, hlog, mls)] = (U32)(ip0-base);
160
157
  ip0 += rLength;
161
158
  ip1 = ip0 + 1;
162
- ZSTD_storeSeq(seqStore, 0, anchor, 0, rLength-MINMATCH);
159
+ ZSTD_storeSeq(seqStore, 0 /*litLen*/, anchor, iend, 0 /*offCode*/, rLength-MINMATCH);
163
160
  anchor = ip0;
164
161
  continue; /* faster when present (confirmed on gcc-8) ... (?) */
165
162
  }
@@ -179,8 +176,7 @@ size_t ZSTD_compressBlock_fast(
179
176
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
180
177
  void const* src, size_t srcSize)
181
178
  {
182
- ZSTD_compressionParameters const* cParams = &ms->cParams;
183
- U32 const mls = cParams->minMatch;
179
+ U32 const mls = ms->cParams.minMatch;
184
180
  assert(ms->dictMatchState == NULL);
185
181
  switch(mls)
186
182
  {
@@ -265,7 +261,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
265
261
  const BYTE* const repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
266
262
  mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
267
263
  ip++;
268
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, 0, mLength-MINMATCH);
264
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
269
265
  } else if ( (matchIndex <= prefixStartIndex) ) {
270
266
  size_t const dictHash = ZSTD_hashPtr(ip, dictHLog, mls);
271
267
  U32 const dictMatchIndex = dictHashTable[dictHash];
@@ -285,7 +281,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
285
281
  } /* catch up */
286
282
  offset_2 = offset_1;
287
283
  offset_1 = offset;
288
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
284
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
289
285
  }
290
286
  } else if (MEM_read32(match) != MEM_read32(ip)) {
291
287
  /* it's not a match, and we're not going to check the dictionary */
@@ -300,7 +296,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
300
296
  && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
301
297
  offset_2 = offset_1;
302
298
  offset_1 = offset;
303
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
299
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
304
300
  }
305
301
 
306
302
  /* match found */
@@ -325,7 +321,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
325
321
  const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
326
322
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
327
323
  U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
328
- ZSTD_storeSeq(seqStore, 0, anchor, 0, repLength2-MINMATCH);
324
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
329
325
  hashTable[ZSTD_hashPtr(ip, hlog, mls)] = current2;
330
326
  ip += repLength2;
331
327
  anchor = ip;
@@ -348,8 +344,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState(
348
344
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
349
345
  void const* src, size_t srcSize)
350
346
  {
351
- ZSTD_compressionParameters const* cParams = &ms->cParams;
352
- U32 const mls = cParams->minMatch;
347
+ U32 const mls = ms->cParams.minMatch;
353
348
  assert(ms->dictMatchState != NULL);
354
349
  switch(mls)
355
350
  {
@@ -408,16 +403,17 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
408
403
  const U32 repIndex = current + 1 - offset_1;
409
404
  const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
410
405
  const BYTE* const repMatch = repBase + repIndex;
411
- size_t mLength;
412
406
  hashTable[h] = current; /* update hash table */
413
407
  assert(offset_1 <= current +1); /* check repIndex */
414
408
 
415
409
  if ( (((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow */ & (repIndex > dictStartIndex))
416
410
  && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
417
411
  const BYTE* const repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
418
- mLength = ZSTD_count_2segments(ip+1 +4, repMatch +4, iend, repMatchEnd, prefixStart) + 4;
412
+ size_t const rLength = ZSTD_count_2segments(ip+1 +4, repMatch +4, iend, repMatchEnd, prefixStart) + 4;
419
413
  ip++;
420
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, 0, mLength-MINMATCH);
414
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, rLength-MINMATCH);
415
+ ip += rLength;
416
+ anchor = ip;
421
417
  } else {
422
418
  if ( (matchIndex < dictStartIndex) ||
423
419
  (MEM_read32(match) != MEM_read32(ip)) ) {
@@ -427,19 +423,15 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
427
423
  }
428
424
  { const BYTE* const matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
429
425
  const BYTE* const lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
430
- U32 offset;
431
- mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
426
+ U32 const offset = current - matchIndex;
427
+ size_t mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
432
428
  while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
433
- offset = current - matchIndex;
434
- offset_2 = offset_1;
435
- offset_1 = offset;
436
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
429
+ offset_2 = offset_1; offset_1 = offset; /* update offset history */
430
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
431
+ ip += mLength;
432
+ anchor = ip;
437
433
  } }
438
434
 
439
- /* found a match : store it */
440
- ip += mLength;
441
- anchor = ip;
442
-
443
435
  if (ip <= ilimit) {
444
436
  /* Fill Table */
445
437
  hashTable[ZSTD_hashPtr(base+current+2, hlog, mls)] = current+2;
@@ -448,13 +440,13 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
448
440
  while (ip <= ilimit) {
449
441
  U32 const current2 = (U32)(ip-base);
450
442
  U32 const repIndex2 = current2 - offset_2;
451
- const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
443
+ const BYTE* const repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
452
444
  if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) & (repIndex2 > dictStartIndex)) /* intentional overflow */
453
445
  && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
454
446
  const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
455
447
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
456
- U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
457
- ZSTD_storeSeq(seqStore, 0, anchor, 0, repLength2-MINMATCH);
448
+ { U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; } /* swap offset_2 <=> offset_1 */
449
+ ZSTD_storeSeq(seqStore, 0 /*litlen*/, anchor, iend, 0 /*offcode*/, repLength2-MINMATCH);
458
450
  hashTable[ZSTD_hashPtr(ip, hlog, mls)] = current2;
459
451
  ip += repLength2;
460
452
  anchor = ip;
@@ -476,8 +468,7 @@ size_t ZSTD_compressBlock_fast_extDict(
476
468
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
477
469
  void const* src, size_t srcSize)
478
470
  {
479
- ZSTD_compressionParameters const* cParams = &ms->cParams;
480
- U32 const mls = cParams->minMatch;
471
+ U32 const mls = ms->cParams.minMatch;
481
472
  switch(mls)
482
473
  {
483
474
  default: /* includes case 3 */
@@ -810,7 +810,7 @@ ZSTD_compressBlock_lazy_generic(
810
810
  /* store sequence */
811
811
  _storeSequence:
812
812
  { size_t const litLength = start - anchor;
813
- ZSTD_storeSeq(seqStore, litLength, anchor, (U32)offset, matchLength-MINMATCH);
813
+ ZSTD_storeSeq(seqStore, litLength, anchor, iend, (U32)offset, matchLength-MINMATCH);
814
814
  anchor = ip = start + matchLength;
815
815
  }
816
816
 
@@ -828,7 +828,7 @@ _storeSequence:
828
828
  const BYTE* const repEnd2 = repIndex < prefixLowestIndex ? dictEnd : iend;
829
829
  matchLength = ZSTD_count_2segments(ip+4, repMatch+4, iend, repEnd2, prefixLowest) + 4;
830
830
  offset = offset_2; offset_2 = offset_1; offset_1 = (U32)offset; /* swap offset_2 <=> offset_1 */
831
- ZSTD_storeSeq(seqStore, 0, anchor, 0, matchLength-MINMATCH);
831
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, matchLength-MINMATCH);
832
832
  ip += matchLength;
833
833
  anchor = ip;
834
834
  continue;
@@ -843,7 +843,7 @@ _storeSequence:
843
843
  /* store sequence */
844
844
  matchLength = ZSTD_count(ip+4, ip+4-offset_2, iend) + 4;
845
845
  offset = offset_2; offset_2 = offset_1; offset_1 = (U32)offset; /* swap repcodes */
846
- ZSTD_storeSeq(seqStore, 0, anchor, 0, matchLength-MINMATCH);
846
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, matchLength-MINMATCH);
847
847
  ip += matchLength;
848
848
  anchor = ip;
849
849
  continue; /* faster when present ... (?) */
@@ -1051,7 +1051,7 @@ size_t ZSTD_compressBlock_lazy_extDict_generic(
1051
1051
  /* store sequence */
1052
1052
  _storeSequence:
1053
1053
  { size_t const litLength = start - anchor;
1054
- ZSTD_storeSeq(seqStore, litLength, anchor, (U32)offset, matchLength-MINMATCH);
1054
+ ZSTD_storeSeq(seqStore, litLength, anchor, iend, (U32)offset, matchLength-MINMATCH);
1055
1055
  anchor = ip = start + matchLength;
1056
1056
  }
1057
1057
 
@@ -1066,7 +1066,7 @@ _storeSequence:
1066
1066
  const BYTE* const repEnd = repIndex < dictLimit ? dictEnd : iend;
1067
1067
  matchLength = ZSTD_count_2segments(ip+4, repMatch+4, iend, repEnd, prefixStart) + 4;
1068
1068
  offset = offset_2; offset_2 = offset_1; offset_1 = (U32)offset; /* swap offset history */
1069
- ZSTD_storeSeq(seqStore, 0, anchor, 0, matchLength-MINMATCH);
1069
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, matchLength-MINMATCH);
1070
1070
  ip += matchLength;
1071
1071
  anchor = ip;
1072
1072
  continue; /* faster when present ... (?) */
@@ -49,9 +49,9 @@ size_t ZSTD_ldm_getTableSize(ldmParams_t params)
49
49
  {
50
50
  size_t const ldmHSize = ((size_t)1) << params.hashLog;
51
51
  size_t const ldmBucketSizeLog = MIN(params.bucketSizeLog, params.hashLog);
52
- size_t const ldmBucketSize =
53
- ((size_t)1) << (params.hashLog - ldmBucketSizeLog);
54
- size_t const totalSize = ldmBucketSize + ldmHSize * sizeof(ldmEntry_t);
52
+ size_t const ldmBucketSize = ((size_t)1) << (params.hashLog - ldmBucketSizeLog);
53
+ size_t const totalSize = ZSTD_cwksp_alloc_size(ldmBucketSize)
54
+ + ZSTD_cwksp_alloc_size(ldmHSize * sizeof(ldmEntry_t));
55
55
  return params.enableLdm ? totalSize : 0;
56
56
  }
57
57
 
@@ -583,7 +583,7 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
583
583
  rep[i] = rep[i-1];
584
584
  rep[0] = sequence.offset;
585
585
  /* Store the sequence */
586
- ZSTD_storeSeq(seqStore, newLitLength, ip - newLitLength,
586
+ ZSTD_storeSeq(seqStore, newLitLength, ip - newLitLength, iend,
587
587
  sequence.offset + ZSTD_REP_MOVE,
588
588
  sequence.matchLength - MINMATCH);
589
589
  ip += sequence.matchLength;
@@ -1098,7 +1098,7 @@ _shortestPath: /* cur, last_pos, best_mlen, best_off have to be set */
1098
1098
 
1099
1099
  assert(anchor + llen <= iend);
1100
1100
  ZSTD_updateStats(optStatePtr, llen, anchor, offCode, mlen);
1101
- ZSTD_storeSeq(seqStore, llen, anchor, offCode, mlen-MINMATCH);
1101
+ ZSTD_storeSeq(seqStore, llen, anchor, iend, offCode, mlen-MINMATCH);
1102
1102
  anchor += advance;
1103
1103
  ip = anchor;
1104
1104
  } }
@@ -668,7 +668,7 @@ static void ZSTDMT_compressionJob(void* jobDescription)
668
668
 
669
669
  /* init */
670
670
  if (job->cdict) {
671
- size_t const initError = ZSTD_compressBegin_advanced_internal(cctx, NULL, 0, ZSTD_dct_auto, ZSTD_dtlm_fast, job->cdict, jobParams, job->fullFrameSize);
671
+ size_t const initError = ZSTD_compressBegin_advanced_internal(cctx, NULL, 0, ZSTD_dct_auto, ZSTD_dtlm_fast, job->cdict, &jobParams, job->fullFrameSize);
672
672
  assert(job->firstJob); /* only allowed for first job */
673
673
  if (ZSTD_isError(initError)) JOB_ERROR(initError);
674
674
  } else { /* srcStart points at reloaded section */
@@ -680,7 +680,7 @@ static void ZSTDMT_compressionJob(void* jobDescription)
680
680
  job->prefix.start, job->prefix.size, ZSTD_dct_rawContent, /* load dictionary in "content-only" mode (no header analysis) */
681
681
  ZSTD_dtlm_fast,
682
682
  NULL, /*cdict*/
683
- jobParams, pledgedSrcSize);
683
+ &jobParams, pledgedSrcSize);
684
684
  if (ZSTD_isError(initError)) JOB_ERROR(initError);
685
685
  } }
686
686
 
@@ -927,12 +927,18 @@ static void ZSTDMT_releaseAllJobResources(ZSTDMT_CCtx* mtctx)
927
927
  unsigned jobID;
928
928
  DEBUGLOG(3, "ZSTDMT_releaseAllJobResources");
929
929
  for (jobID=0; jobID <= mtctx->jobIDMask; jobID++) {
930
+ /* Copy the mutex/cond out */
931
+ ZSTD_pthread_mutex_t const mutex = mtctx->jobs[jobID].job_mutex;
932
+ ZSTD_pthread_cond_t const cond = mtctx->jobs[jobID].job_cond;
933
+
930
934
  DEBUGLOG(4, "job%02u: release dst address %08X", jobID, (U32)(size_t)mtctx->jobs[jobID].dstBuff.start);
931
935
  ZSTDMT_releaseBuffer(mtctx->bufPool, mtctx->jobs[jobID].dstBuff);
932
- mtctx->jobs[jobID].dstBuff = g_nullBuffer;
933
- mtctx->jobs[jobID].cSize = 0;
936
+
937
+ /* Clear the job description, but keep the mutex/cond */
938
+ memset(&mtctx->jobs[jobID], 0, sizeof(mtctx->jobs[jobID]));
939
+ mtctx->jobs[jobID].job_mutex = mutex;
940
+ mtctx->jobs[jobID].job_cond = cond;
934
941
  }
935
- memset(mtctx->jobs, 0, (mtctx->jobIDMask+1)*sizeof(ZSTDMT_jobDescription));
936
942
  mtctx->inBuff.buffer = g_nullBuffer;
937
943
  mtctx->inBuff.filled = 0;
938
944
  mtctx->allJobsCompleted = 1;
@@ -1028,9 +1034,9 @@ size_t ZSTDMT_getMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSTDMT_parameter parameter,
1028
1034
 
1029
1035
  /* Sets parameters relevant to the compression job,
1030
1036
  * initializing others to default values. */
1031
- static ZSTD_CCtx_params ZSTDMT_initJobCCtxParams(ZSTD_CCtx_params const params)
1037
+ static ZSTD_CCtx_params ZSTDMT_initJobCCtxParams(const ZSTD_CCtx_params* params)
1032
1038
  {
1033
- ZSTD_CCtx_params jobParams = params;
1039
+ ZSTD_CCtx_params jobParams = *params;
1034
1040
  /* Clear parameters related to multithreading */
1035
1041
  jobParams.forceWindow = 0;
1036
1042
  jobParams.nbWorkers = 0;
@@ -1151,16 +1157,16 @@ size_t ZSTDMT_toFlushNow(ZSTDMT_CCtx* mtctx)
1151
1157
  /* ===== Multi-threaded compression ===== */
1152
1158
  /* ------------------------------------------ */
1153
1159
 
1154
- static unsigned ZSTDMT_computeTargetJobLog(ZSTD_CCtx_params const params)
1160
+ static unsigned ZSTDMT_computeTargetJobLog(const ZSTD_CCtx_params* params)
1155
1161
  {
1156
1162
  unsigned jobLog;
1157
- if (params.ldmParams.enableLdm) {
1163
+ if (params->ldmParams.enableLdm) {
1158
1164
  /* In Long Range Mode, the windowLog is typically oversized.
1159
1165
  * In which case, it's preferable to determine the jobSize
1160
1166
  * based on chainLog instead. */
1161
- jobLog = MAX(21, params.cParams.chainLog + 4);
1167
+ jobLog = MAX(21, params->cParams.chainLog + 4);
1162
1168
  } else {
1163
- jobLog = MAX(20, params.cParams.windowLog + 2);
1169
+ jobLog = MAX(20, params->cParams.windowLog + 2);
1164
1170
  }
1165
1171
  return MIN(jobLog, (unsigned)ZSTDMT_JOBLOG_MAX);
1166
1172
  }
@@ -1193,27 +1199,27 @@ static int ZSTDMT_overlapLog(int ovlog, ZSTD_strategy strat)
1193
1199
  return ovlog;
1194
1200
  }
1195
1201
 
1196
- static size_t ZSTDMT_computeOverlapSize(ZSTD_CCtx_params const params)
1202
+ static size_t ZSTDMT_computeOverlapSize(const ZSTD_CCtx_params* params)
1197
1203
  {
1198
- int const overlapRLog = 9 - ZSTDMT_overlapLog(params.overlapLog, params.cParams.strategy);
1199
- int ovLog = (overlapRLog >= 8) ? 0 : (params.cParams.windowLog - overlapRLog);
1204
+ int const overlapRLog = 9 - ZSTDMT_overlapLog(params->overlapLog, params->cParams.strategy);
1205
+ int ovLog = (overlapRLog >= 8) ? 0 : (params->cParams.windowLog - overlapRLog);
1200
1206
  assert(0 <= overlapRLog && overlapRLog <= 8);
1201
- if (params.ldmParams.enableLdm) {
1207
+ if (params->ldmParams.enableLdm) {
1202
1208
  /* In Long Range Mode, the windowLog is typically oversized.
1203
1209
  * In which case, it's preferable to determine the jobSize
1204
1210
  * based on chainLog instead.
1205
1211
  * Then, ovLog becomes a fraction of the jobSize, rather than windowSize */
1206
- ovLog = MIN(params.cParams.windowLog, ZSTDMT_computeTargetJobLog(params) - 2)
1212
+ ovLog = MIN(params->cParams.windowLog, ZSTDMT_computeTargetJobLog(params) - 2)
1207
1213
  - overlapRLog;
1208
1214
  }
1209
1215
  assert(0 <= ovLog && ovLog <= ZSTD_WINDOWLOG_MAX);
1210
- DEBUGLOG(4, "overlapLog : %i", params.overlapLog);
1216
+ DEBUGLOG(4, "overlapLog : %i", params->overlapLog);
1211
1217
  DEBUGLOG(4, "overlap size : %i", 1 << ovLog);
1212
1218
  return (ovLog==0) ? 0 : (size_t)1 << ovLog;
1213
1219
  }
1214
1220
 
1215
1221
  static unsigned
1216
- ZSTDMT_computeNbJobs(ZSTD_CCtx_params params, size_t srcSize, unsigned nbWorkers)
1222
+ ZSTDMT_computeNbJobs(const ZSTD_CCtx_params* params, size_t srcSize, unsigned nbWorkers)
1217
1223
  {
1218
1224
  assert(nbWorkers>0);
1219
1225
  { size_t const jobSizeTarget = (size_t)1 << ZSTDMT_computeTargetJobLog(params);
@@ -1236,9 +1242,9 @@ static size_t ZSTDMT_compress_advanced_internal(
1236
1242
  const ZSTD_CDict* cdict,
1237
1243
  ZSTD_CCtx_params params)
1238
1244
  {
1239
- ZSTD_CCtx_params const jobParams = ZSTDMT_initJobCCtxParams(params);
1240
- size_t const overlapSize = ZSTDMT_computeOverlapSize(params);
1241
- unsigned const nbJobs = ZSTDMT_computeNbJobs(params, srcSize, params.nbWorkers);
1245
+ ZSTD_CCtx_params const jobParams = ZSTDMT_initJobCCtxParams(&params);
1246
+ size_t const overlapSize = ZSTDMT_computeOverlapSize(&params);
1247
+ unsigned const nbJobs = ZSTDMT_computeNbJobs(&params, srcSize, params.nbWorkers);
1242
1248
  size_t const proposedJobSize = (srcSize + (nbJobs-1)) / nbJobs;
1243
1249
  size_t const avgJobSize = (((proposedJobSize-1) & 0x1FFFF) < 0x7FFF) ? proposedJobSize + 0xFFFF : proposedJobSize; /* avoid too small last block */
1244
1250
  const char* const srcStart = (const char*)src;
@@ -1256,7 +1262,7 @@ static size_t ZSTDMT_compress_advanced_internal(
1256
1262
  ZSTD_CCtx* const cctx = mtctx->cctxPool->cctx[0];
1257
1263
  DEBUGLOG(4, "ZSTDMT_compress_advanced_internal: fallback to single-thread mode");
1258
1264
  if (cdict) return ZSTD_compress_usingCDict_advanced(cctx, dst, dstCapacity, src, srcSize, cdict, jobParams.fParams);
1259
- return ZSTD_compress_advanced_internal(cctx, dst, dstCapacity, src, srcSize, NULL, 0, jobParams);
1265
+ return ZSTD_compress_advanced_internal(cctx, dst, dstCapacity, src, srcSize, NULL, 0, &jobParams);
1260
1266
  }
1261
1267
 
1262
1268
  assert(avgJobSize >= 256 KB); /* condition for ZSTD_compressBound(A) + ZSTD_compressBound(B) <= ZSTD_compressBound(A+B), required to compress directly into Dst (no additional buffer) */
@@ -1404,12 +1410,12 @@ size_t ZSTDMT_initCStream_internal(
1404
1410
 
1405
1411
  mtctx->singleBlockingThread = (pledgedSrcSize <= ZSTDMT_JOBSIZE_MIN); /* do not trigger multi-threading when srcSize is too small */
1406
1412
  if (mtctx->singleBlockingThread) {
1407
- ZSTD_CCtx_params const singleThreadParams = ZSTDMT_initJobCCtxParams(params);
1413
+ ZSTD_CCtx_params const singleThreadParams = ZSTDMT_initJobCCtxParams(&params);
1408
1414
  DEBUGLOG(5, "ZSTDMT_initCStream_internal: switch to single blocking thread mode");
1409
1415
  assert(singleThreadParams.nbWorkers == 0);
1410
1416
  return ZSTD_initCStream_internal(mtctx->cctxPool->cctx[0],
1411
1417
  dict, dictSize, cdict,
1412
- singleThreadParams, pledgedSrcSize);
1418
+ &singleThreadParams, pledgedSrcSize);
1413
1419
  }
1414
1420
 
1415
1421
  DEBUGLOG(4, "ZSTDMT_initCStream_internal: %u workers", params.nbWorkers);
@@ -1435,11 +1441,11 @@ size_t ZSTDMT_initCStream_internal(
1435
1441
  mtctx->cdict = cdict;
1436
1442
  }
1437
1443
 
1438
- mtctx->targetPrefixSize = ZSTDMT_computeOverlapSize(params);
1444
+ mtctx->targetPrefixSize = ZSTDMT_computeOverlapSize(&params);
1439
1445
  DEBUGLOG(4, "overlapLog=%i => %u KB", params.overlapLog, (U32)(mtctx->targetPrefixSize>>10));
1440
1446
  mtctx->targetSectionSize = params.jobSize;
1441
1447
  if (mtctx->targetSectionSize == 0) {
1442
- mtctx->targetSectionSize = 1ULL << ZSTDMT_computeTargetJobLog(params);
1448
+ mtctx->targetSectionSize = 1ULL << ZSTDMT_computeTargetJobLog(&params);
1443
1449
  }
1444
1450
  assert(mtctx->targetSectionSize <= (size_t)ZSTDMT_JOBSIZE_MAX);
1445
1451