zstdlib 0.2.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +30 -1
  3. data/README.md +2 -2
  4. data/Rakefile +1 -1
  5. data/ext/zstdlib/extconf.rb +3 -3
  6. data/ext/zstdlib/ruby/zlib-2.7/zstdlib.c +4895 -0
  7. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/bitstream.h +38 -39
  8. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/compiler.h +40 -5
  9. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/cpu.h +1 -1
  10. data/ext/zstdlib/zstd-1.4.5/lib/common/debug.c +24 -0
  11. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/debug.h +11 -31
  12. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/entropy_common.c +13 -33
  13. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/error_private.c +2 -1
  14. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/error_private.h +6 -2
  15. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/fse.h +12 -32
  16. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/fse_decompress.c +12 -35
  17. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/huf.h +15 -33
  18. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/mem.h +75 -2
  19. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/pool.c +8 -4
  20. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/pool.h +2 -2
  21. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/threading.c +50 -4
  22. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/threading.h +36 -4
  23. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/xxhash.c +23 -35
  24. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/xxhash.h +11 -31
  25. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/zstd_common.c +1 -1
  26. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/zstd_errors.h +2 -1
  27. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/common/zstd_internal.h +154 -26
  28. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/fse_compress.c +17 -40
  29. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/hist.c +15 -35
  30. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/hist.h +12 -32
  31. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/huf_compress.c +92 -92
  32. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_compress.c +1191 -1330
  33. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_compress_internal.h +317 -55
  34. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_literals.c +158 -0
  35. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_literals.h +29 -0
  36. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_sequences.c +419 -0
  37. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_sequences.h +54 -0
  38. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_superblock.c +845 -0
  39. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_compress_superblock.h +32 -0
  40. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_cwksp.h +525 -0
  41. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_double_fast.c +65 -43
  42. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_double_fast.h +2 -2
  43. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_fast.c +92 -66
  44. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_fast.h +2 -2
  45. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_lazy.c +74 -42
  46. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_lazy.h +1 -1
  47. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_ldm.c +32 -10
  48. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_ldm.h +7 -2
  49. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_opt.c +81 -114
  50. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstd_opt.h +1 -1
  51. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstdmt_compress.c +95 -51
  52. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/compress/zstdmt_compress.h +3 -2
  53. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/huf_decompress.c +76 -60
  54. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_ddict.c +12 -8
  55. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_ddict.h +2 -2
  56. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_decompress.c +292 -172
  57. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_decompress_block.c +459 -338
  58. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_decompress_block.h +3 -3
  59. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/decompress/zstd_decompress_internal.h +18 -4
  60. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/lib/zstd.h +265 -88
  61. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzclose.c +1 -1
  62. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzcompatibility.h +1 -1
  63. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzguts.h +0 -0
  64. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzlib.c +9 -9
  65. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzread.c +16 -8
  66. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/gzwrite.c +8 -8
  67. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/zstd_zlibwrapper.c +16 -12
  68. data/ext/zstdlib/{zstd-1.4.0 → zstd-1.4.5}/zlibWrapper/zstd_zlibwrapper.h +1 -1
  69. metadata +69 -62
  70. data/ext/zstdlib/zstd-1.4.0/lib/common/debug.c +0 -44
@@ -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
@@ -43,8 +43,7 @@ void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
43
43
  /* Only load extra positions for ZSTD_dtlm_full */
44
44
  if (dtlm == ZSTD_dtlm_fast)
45
45
  break;
46
- }
47
- }
46
+ } }
48
47
  }
49
48
 
50
49
 
@@ -63,7 +62,9 @@ size_t ZSTD_compressBlock_doubleFast_generic(
63
62
  const BYTE* const istart = (const BYTE*)src;
64
63
  const BYTE* ip = istart;
65
64
  const BYTE* anchor = istart;
66
- const U32 prefixLowestIndex = ms->window.dictLimit;
65
+ const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
66
+ /* presumes that, if there is a dictionary, it must be using Attach mode */
67
+ const U32 prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, cParams->windowLog);
67
68
  const BYTE* const prefixLowest = base + prefixLowestIndex;
68
69
  const BYTE* const iend = istart + srcSize;
69
70
  const BYTE* const ilimit = iend - HASH_READ_SIZE;
@@ -93,14 +94,23 @@ size_t ZSTD_compressBlock_doubleFast_generic(
93
94
  dictCParams->hashLog : hBitsL;
94
95
  const U32 dictHBitsS = dictMode == ZSTD_dictMatchState ?
95
96
  dictCParams->chainLog : hBitsS;
96
- const U32 dictAndPrefixLength = (U32)(ip - prefixLowest + dictEnd - dictStart);
97
+ const U32 dictAndPrefixLength = (U32)((ip - prefixLowest) + (dictEnd - dictStart));
98
+
99
+ DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_generic");
97
100
 
98
101
  assert(dictMode == ZSTD_noDict || dictMode == ZSTD_dictMatchState);
99
102
 
103
+ /* if a dictionary is attached, it must be within window range */
104
+ if (dictMode == ZSTD_dictMatchState) {
105
+ assert(ms->window.dictLimit + (1U << cParams->windowLog) >= endIndex);
106
+ }
107
+
100
108
  /* init */
101
109
  ip += (dictAndPrefixLength == 0);
102
110
  if (dictMode == ZSTD_noDict) {
103
- U32 const maxRep = (U32)(ip - prefixLowest);
111
+ U32 const current = (U32)(ip - base);
112
+ U32 const windowLow = ZSTD_getLowestPrefixIndex(ms, current, cParams->windowLog);
113
+ U32 const maxRep = current - windowLow;
104
114
  if (offset_2 > maxRep) offsetSaved = offset_2, offset_2 = 0;
105
115
  if (offset_1 > maxRep) offsetSaved = offset_1, offset_1 = 0;
106
116
  }
@@ -138,7 +148,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
138
148
  const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
139
149
  mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
140
150
  ip++;
141
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
151
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
142
152
  goto _match_stored;
143
153
  }
144
154
 
@@ -147,7 +157,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
147
157
  && ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1)))) {
148
158
  mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
149
159
  ip++;
150
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
160
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
151
161
  goto _match_stored;
152
162
  }
153
163
 
@@ -170,8 +180,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
170
180
  offset = (U32)(current - dictMatchIndexL - dictIndexDelta);
171
181
  while (((ip>anchor) & (dictMatchL>dictStart)) && (ip[-1] == dictMatchL[-1])) { ip--; dictMatchL--; mLength++; } /* catch up */
172
182
  goto _match_found;
173
- }
174
- }
183
+ } }
175
184
 
176
185
  if (matchIndexS > prefixLowestIndex) {
177
186
  /* check prefix short match */
@@ -186,16 +195,17 @@ size_t ZSTD_compressBlock_doubleFast_generic(
186
195
 
187
196
  if (match > dictStart && MEM_read32(match) == MEM_read32(ip)) {
188
197
  goto _search_next_long;
189
- }
190
- }
198
+ } }
191
199
 
192
200
  ip += ((ip-anchor) >> kSearchStrength) + 1;
201
+ #if defined(__aarch64__)
202
+ PREFETCH_L1(ip+256);
203
+ #endif
193
204
  continue;
194
205
 
195
206
  _search_next_long:
196
207
 
197
- {
198
- size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
208
+ { size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
199
209
  size_t const dictHLNext = ZSTD_hashPtr(ip+1, dictHBitsL, 8);
200
210
  U32 const matchIndexL3 = hashLong[hl3];
201
211
  const BYTE* matchL3 = base + matchIndexL3;
@@ -221,9 +231,7 @@ _search_next_long:
221
231
  offset = (U32)(current + 1 - dictMatchIndexL3 - dictIndexDelta);
222
232
  while (((ip>anchor) & (dictMatchL3>dictStart)) && (ip[-1] == dictMatchL3[-1])) { ip--; dictMatchL3--; mLength++; } /* catch up */
223
233
  goto _match_found;
224
- }
225
- }
226
- }
234
+ } } }
227
235
 
228
236
  /* if no long +1 match, explore the short match we found */
229
237
  if (dictMode == ZSTD_dictMatchState && matchIndexS < prefixLowestIndex) {
@@ -242,7 +250,7 @@ _match_found:
242
250
  offset_2 = offset_1;
243
251
  offset_1 = offset;
244
252
 
245
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
253
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
246
254
 
247
255
  _match_stored:
248
256
  /* match found */
@@ -250,11 +258,14 @@ _match_stored:
250
258
  anchor = ip;
251
259
 
252
260
  if (ip <= ilimit) {
253
- /* Fill Table */
254
- hashLong[ZSTD_hashPtr(base+current+2, hBitsL, 8)] =
255
- hashSmall[ZSTD_hashPtr(base+current+2, hBitsS, mls)] = current+2; /* here because current+2 could be > iend-8 */
256
- hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] =
257
- hashSmall[ZSTD_hashPtr(ip-2, hBitsS, mls)] = (U32)(ip-2-base);
261
+ /* Complementary insertion */
262
+ /* done after iLimit test, as candidates could be > iend-8 */
263
+ { U32 const indexToInsert = current+2;
264
+ hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
265
+ hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
266
+ hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
267
+ hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
268
+ }
258
269
 
259
270
  /* check immediate repcode */
260
271
  if (dictMode == ZSTD_dictMatchState) {
@@ -263,14 +274,14 @@ _match_stored:
263
274
  U32 const repIndex2 = current2 - offset_2;
264
275
  const BYTE* repMatch2 = dictMode == ZSTD_dictMatchState
265
276
  && repIndex2 < prefixLowestIndex ?
266
- dictBase - dictIndexDelta + repIndex2 :
277
+ dictBase + repIndex2 - dictIndexDelta :
267
278
  base + repIndex2;
268
279
  if ( ((U32)((prefixLowestIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
269
280
  && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
270
281
  const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
271
282
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
272
283
  U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
273
- ZSTD_storeSeq(seqStore, 0, anchor, 0, repLength2-MINMATCH);
284
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
274
285
  hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
275
286
  hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
276
287
  ip += repLength2;
@@ -278,8 +289,7 @@ _match_stored:
278
289
  continue;
279
290
  }
280
291
  break;
281
- }
282
- }
292
+ } }
283
293
 
284
294
  if (dictMode == ZSTD_noDict) {
285
295
  while ( (ip <= ilimit)
@@ -290,18 +300,19 @@ _match_stored:
290
300
  U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; /* swap offset_2 <=> offset_1 */
291
301
  hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip-base);
292
302
  hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip-base);
293
- ZSTD_storeSeq(seqStore, 0, anchor, 0, rLength-MINMATCH);
303
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, rLength-MINMATCH);
294
304
  ip += rLength;
295
305
  anchor = ip;
296
306
  continue; /* faster when present ... (?) */
297
- } } } }
307
+ } } }
308
+ } /* while (ip < ilimit) */
298
309
 
299
310
  /* save reps for next block */
300
311
  rep[0] = offset_1 ? offset_1 : offsetSaved;
301
312
  rep[1] = offset_2 ? offset_2 : offsetSaved;
302
313
 
303
314
  /* Return the last literals size */
304
- return iend - anchor;
315
+ return (size_t)(iend - anchor);
305
316
  }
306
317
 
307
318
 
@@ -360,10 +371,13 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
360
371
  const BYTE* anchor = istart;
361
372
  const BYTE* const iend = istart + srcSize;
362
373
  const BYTE* const ilimit = iend - 8;
363
- const U32 prefixStartIndex = ms->window.dictLimit;
364
374
  const BYTE* const base = ms->window.base;
375
+ const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
376
+ const U32 lowLimit = ZSTD_getLowestMatchIndex(ms, endIndex, cParams->windowLog);
377
+ const U32 dictStartIndex = lowLimit;
378
+ const U32 dictLimit = ms->window.dictLimit;
379
+ const U32 prefixStartIndex = (dictLimit > lowLimit) ? dictLimit : lowLimit;
365
380
  const BYTE* const prefixStart = base + prefixStartIndex;
366
- const U32 dictStartIndex = ms->window.lowLimit;
367
381
  const BYTE* const dictBase = ms->window.dictBase;
368
382
  const BYTE* const dictStart = dictBase + dictStartIndex;
369
383
  const BYTE* const dictEnd = dictBase + prefixStartIndex;
@@ -371,6 +385,10 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
371
385
 
372
386
  DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_extDict_generic (srcSize=%zu)", srcSize);
373
387
 
388
+ /* if extDict is invalidated due to maxDistance, switch to "regular" variant */
389
+ if (prefixStartIndex == dictStartIndex)
390
+ return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, mls, ZSTD_noDict);
391
+
374
392
  /* Search Loop */
375
393
  while (ip < ilimit) { /* < instead of <=, because (ip+1) */
376
394
  const size_t hSmall = ZSTD_hashPtr(ip, hBitsS, mls);
@@ -396,7 +414,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
396
414
  const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
397
415
  mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
398
416
  ip++;
399
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
417
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
400
418
  } else {
401
419
  if ((matchLongIndex > dictStartIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
402
420
  const BYTE* const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
@@ -407,7 +425,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
407
425
  while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
408
426
  offset_2 = offset_1;
409
427
  offset_1 = offset;
410
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
428
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
411
429
 
412
430
  } else if ((matchIndex > dictStartIndex) && (MEM_read32(match) == MEM_read32(ip))) {
413
431
  size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
@@ -432,23 +450,27 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
432
450
  }
433
451
  offset_2 = offset_1;
434
452
  offset_1 = offset;
435
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
453
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
436
454
 
437
455
  } else {
438
456
  ip += ((ip-anchor) >> kSearchStrength) + 1;
439
457
  continue;
440
458
  } }
441
459
 
442
- /* found a match : store it */
460
+ /* move to next sequence start */
443
461
  ip += mLength;
444
462
  anchor = ip;
445
463
 
446
464
  if (ip <= ilimit) {
447
- /* Fill Table */
448
- hashSmall[ZSTD_hashPtr(base+current+2, hBitsS, mls)] = current+2;
449
- hashLong[ZSTD_hashPtr(base+current+2, hBitsL, 8)] = current+2;
450
- hashSmall[ZSTD_hashPtr(ip-2, hBitsS, mls)] = (U32)(ip-2-base);
451
- hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
465
+ /* Complementary insertion */
466
+ /* done after iLimit test, as candidates could be > iend-8 */
467
+ { U32 const indexToInsert = current+2;
468
+ hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
469
+ hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
470
+ hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
471
+ hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
472
+ }
473
+
452
474
  /* check immediate repcode */
453
475
  while (ip <= ilimit) {
454
476
  U32 const current2 = (U32)(ip-base);
@@ -460,7 +482,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
460
482
  const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
461
483
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
462
484
  U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
463
- ZSTD_storeSeq(seqStore, 0, anchor, 0, repLength2-MINMATCH);
485
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
464
486
  hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
465
487
  hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
466
488
  ip += repLength2;
@@ -475,7 +497,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
475
497
  rep[1] = offset_2;
476
498
 
477
499
  /* Return the last literals size */
478
- return iend - anchor;
500
+ return (size_t)(iend - anchor);
479
501
  }
480
502
 
481
503
 
@@ -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
@@ -15,7 +15,7 @@
15
15
  extern "C" {
16
16
  #endif
17
17
 
18
- #include "mem.h" /* U32 */
18
+ #include "../common/mem.h" /* U32 */
19
19
  #include "zstd_compress_internal.h" /* ZSTD_CCtx, size_t */
20
20
 
21
21
  void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
@@ -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
@@ -8,12 +8,13 @@
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
 
15
15
  void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
16
- void const* end, ZSTD_dictTableLoadMethod_e dtlm)
16
+ const void* const end,
17
+ ZSTD_dictTableLoadMethod_e dtlm)
17
18
  {
18
19
  const ZSTD_compressionParameters* const cParams = &ms->cParams;
19
20
  U32* const hashTable = ms->hashTable;
@@ -41,8 +42,9 @@ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
41
42
  } } } }
42
43
  }
43
44
 
44
- FORCE_INLINE_TEMPLATE
45
- size_t ZSTD_compressBlock_fast_generic(
45
+
46
+ FORCE_INLINE_TEMPLATE size_t
47
+ ZSTD_compressBlock_fast_generic(
46
48
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
47
49
  void const* src, size_t srcSize,
48
50
  U32 const mls)
@@ -58,7 +60,8 @@ size_t ZSTD_compressBlock_fast_generic(
58
60
  const BYTE* ip0 = istart;
59
61
  const BYTE* ip1;
60
62
  const BYTE* anchor = istart;
61
- const U32 prefixStartIndex = ms->window.dictLimit;
63
+ const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
64
+ const U32 prefixStartIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, cParams->windowLog);
62
65
  const BYTE* const prefixStart = base + prefixStartIndex;
63
66
  const BYTE* const iend = istart + srcSize;
64
67
  const BYTE* const ilimit = iend - HASH_READ_SIZE;
@@ -66,15 +69,24 @@ size_t ZSTD_compressBlock_fast_generic(
66
69
  U32 offsetSaved = 0;
67
70
 
68
71
  /* init */
72
+ DEBUGLOG(5, "ZSTD_compressBlock_fast_generic");
69
73
  ip0 += (ip0 == prefixStart);
70
74
  ip1 = ip0 + 1;
71
- {
72
- U32 const maxRep = (U32)(ip0 - prefixStart);
75
+ { U32 const current = (U32)(ip0 - base);
76
+ U32 const windowLow = ZSTD_getLowestPrefixIndex(ms, current, cParams->windowLog);
77
+ U32 const maxRep = current - windowLow;
73
78
  if (offset_2 > maxRep) offsetSaved = offset_2, offset_2 = 0;
74
79
  if (offset_1 > maxRep) offsetSaved = offset_1, offset_1 = 0;
75
80
  }
76
81
 
77
82
  /* Main Search Loop */
83
+ #ifdef __INTEL_COMPILER
84
+ /* From intel 'The vector pragma indicates that the loop should be
85
+ * vectorized if it is legal to do so'. Can be used together with
86
+ * #pragma ivdep (but have opted to exclude that because intel
87
+ * warns against using it).*/
88
+ #pragma vector always
89
+ #endif
78
90
  while (ip1 < ilimit) { /* < instead of <=, because check at ip0+2 */
79
91
  size_t mLength;
80
92
  BYTE const* ip2 = ip0 + 2;
@@ -86,19 +98,25 @@ size_t ZSTD_compressBlock_fast_generic(
86
98
  U32 const current1 = (U32)(ip1-base);
87
99
  U32 const matchIndex0 = hashTable[h0];
88
100
  U32 const matchIndex1 = hashTable[h1];
89
- BYTE const* repMatch = ip2-offset_1;
101
+ BYTE const* repMatch = ip2 - offset_1;
90
102
  const BYTE* match0 = base + matchIndex0;
91
103
  const BYTE* match1 = base + matchIndex1;
92
104
  U32 offcode;
105
+
106
+ #if defined(__aarch64__)
107
+ PREFETCH_L1(ip0+256);
108
+ #endif
109
+
93
110
  hashTable[h0] = current0; /* update hash table */
94
111
  hashTable[h1] = current1; /* update hash table */
95
112
 
96
113
  assert(ip0 + 1 == ip1);
97
114
 
98
115
  if ((offset_1 > 0) & (MEM_read32(repMatch) == MEM_read32(ip2))) {
99
- mLength = ip2[-1] == repMatch[-1] ? 1 : 0;
116
+ mLength = (ip2[-1] == repMatch[-1]) ? 1 : 0;
100
117
  ip0 = ip2 - mLength;
101
118
  match0 = repMatch - mLength;
119
+ mLength += 4;
102
120
  offcode = 0;
103
121
  goto _match;
104
122
  }
@@ -112,8 +130,7 @@ size_t ZSTD_compressBlock_fast_generic(
112
130
  match0 = match1;
113
131
  goto _offset;
114
132
  }
115
- {
116
- size_t const step = ((ip0-anchor) >> (kSearchStrength - 1)) + stepSize;
133
+ { size_t const step = ((size_t)(ip0-anchor) >> (kSearchStrength - 1)) + stepSize;
117
134
  assert(step >= 2);
118
135
  ip0 += step;
119
136
  ip1 += step;
@@ -124,19 +141,18 @@ _offset: /* Requires: ip0, match0 */
124
141
  offset_2 = offset_1;
125
142
  offset_1 = (U32)(ip0-match0);
126
143
  offcode = offset_1 + ZSTD_REP_MOVE;
127
- mLength = 0;
144
+ mLength = 4;
128
145
  /* Count the backwards match length */
129
146
  while (((ip0>anchor) & (match0>prefixStart))
130
147
  && (ip0[-1] == match0[-1])) { ip0--; match0--; mLength++; } /* catch up */
131
148
 
132
149
  _match: /* Requires: ip0, match0, offcode */
133
150
  /* Count the forward length */
134
- mLength += ZSTD_count(ip0+mLength+4, match0+mLength+4, iend) + 4;
135
- ZSTD_storeSeq(seqStore, ip0-anchor, anchor, offcode, mLength-MINMATCH);
151
+ mLength += ZSTD_count(ip0+mLength, match0+mLength, iend);
152
+ ZSTD_storeSeq(seqStore, (size_t)(ip0-anchor), anchor, iend, offcode, mLength-MINMATCH);
136
153
  /* match found */
137
154
  ip0 += mLength;
138
155
  anchor = ip0;
139
- ip1 = ip0 + 1;
140
156
 
141
157
  if (ip0 <= ilimit) {
142
158
  /* Fill Table */
@@ -144,20 +160,18 @@ _match: /* Requires: ip0, match0, offcode */
144
160
  hashTable[ZSTD_hashPtr(base+current0+2, hlog, mls)] = current0+2; /* here because current+2 could be > iend-8 */
145
161
  hashTable[ZSTD_hashPtr(ip0-2, hlog, mls)] = (U32)(ip0-2-base);
146
162
 
147
- while ( (ip0 <= ilimit)
148
- && ( (offset_2>0)
149
- & (MEM_read32(ip0) == MEM_read32(ip0 - offset_2)) )) {
150
- /* store sequence */
151
- size_t const rLength = ZSTD_count(ip0+4, ip0+4-offset_2, iend) + 4;
152
- U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; /* swap offset_2 <=> offset_1 */
153
- hashTable[ZSTD_hashPtr(ip0, hlog, mls)] = (U32)(ip0-base);
154
- ip0 += rLength;
155
- ip1 = ip0 + 1;
156
- ZSTD_storeSeq(seqStore, 0, anchor, 0, rLength-MINMATCH);
157
- anchor = ip0;
158
- continue; /* faster when present (confirmed on gcc-8) ... (?) */
159
- }
160
- }
163
+ if (offset_2 > 0) { /* offset_2==0 means offset_2 is invalidated */
164
+ while ( (ip0 <= ilimit) && (MEM_read32(ip0) == MEM_read32(ip0 - offset_2)) ) {
165
+ /* store sequence */
166
+ size_t const rLength = ZSTD_count(ip0+4, ip0+4-offset_2, iend) + 4;
167
+ { U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; } /* swap offset_2 <=> offset_1 */
168
+ hashTable[ZSTD_hashPtr(ip0, hlog, mls)] = (U32)(ip0-base);
169
+ ip0 += rLength;
170
+ ZSTD_storeSeq(seqStore, 0 /*litLen*/, anchor, iend, 0 /*offCode*/, rLength-MINMATCH);
171
+ anchor = ip0;
172
+ continue; /* faster when present (confirmed on gcc-8) ... (?) */
173
+ } } }
174
+ ip1 = ip0 + 1;
161
175
  }
162
176
 
163
177
  /* save reps for next block */
@@ -165,7 +179,7 @@ _match: /* Requires: ip0, match0, offcode */
165
179
  rep[1] = offset_2 ? offset_2 : offsetSaved;
166
180
 
167
181
  /* Return the last literals size */
168
- return iend - anchor;
182
+ return (size_t)(iend - anchor);
169
183
  }
170
184
 
171
185
 
@@ -173,8 +187,7 @@ size_t ZSTD_compressBlock_fast(
173
187
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
174
188
  void const* src, size_t srcSize)
175
189
  {
176
- ZSTD_compressionParameters const* cParams = &ms->cParams;
177
- U32 const mls = cParams->minMatch;
190
+ U32 const mls = ms->cParams.minMatch;
178
191
  assert(ms->dictMatchState == NULL);
179
192
  switch(mls)
180
193
  {
@@ -222,11 +235,19 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
222
235
  const U32 dictAndPrefixLength = (U32)(ip - prefixStart + dictEnd - dictStart);
223
236
  const U32 dictHLog = dictCParams->hashLog;
224
237
 
225
- /* otherwise, we would get index underflow when translating a dict index
226
- * into a local index */
238
+ /* if a dictionary is still attached, it necessarily means that
239
+ * it is within window size. So we just check it. */
240
+ const U32 maxDistance = 1U << cParams->windowLog;
241
+ const U32 endIndex = (U32)((size_t)(ip - base) + srcSize);
242
+ assert(endIndex - prefixStartIndex <= maxDistance);
243
+ (void)maxDistance; (void)endIndex; /* these variables are not used when assert() is disabled */
244
+
245
+ /* ensure there will be no no underflow
246
+ * when translating a dict index into a local index */
227
247
  assert(prefixStartIndex >= (U32)(dictEnd - dictBase));
228
248
 
229
249
  /* init */
250
+ DEBUGLOG(5, "ZSTD_compressBlock_fast_dictMatchState_generic");
230
251
  ip += (dictAndPrefixLength == 0);
231
252
  /* dictMatchState repCode checks don't currently handle repCode == 0
232
253
  * disabling. */
@@ -251,7 +272,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
251
272
  const BYTE* const repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
252
273
  mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
253
274
  ip++;
254
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
275
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
255
276
  } else if ( (matchIndex <= prefixStartIndex) ) {
256
277
  size_t const dictHash = ZSTD_hashPtr(ip, dictHLog, mls);
257
278
  U32 const dictMatchIndex = dictHashTable[dictHash];
@@ -271,7 +292,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
271
292
  } /* catch up */
272
293
  offset_2 = offset_1;
273
294
  offset_1 = offset;
274
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
295
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
275
296
  }
276
297
  } else if (MEM_read32(match) != MEM_read32(ip)) {
277
298
  /* it's not a match, and we're not going to check the dictionary */
@@ -286,7 +307,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
286
307
  && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
287
308
  offset_2 = offset_1;
288
309
  offset_1 = offset;
289
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
310
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
290
311
  }
291
312
 
292
313
  /* match found */
@@ -311,7 +332,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
311
332
  const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
312
333
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
313
334
  U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
314
- ZSTD_storeSeq(seqStore, 0, anchor, 0, repLength2-MINMATCH);
335
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
315
336
  hashTable[ZSTD_hashPtr(ip, hlog, mls)] = current2;
316
337
  ip += repLength2;
317
338
  anchor = ip;
@@ -327,15 +348,14 @@ size_t ZSTD_compressBlock_fast_dictMatchState_generic(
327
348
  rep[1] = offset_2 ? offset_2 : offsetSaved;
328
349
 
329
350
  /* Return the last literals size */
330
- return iend - anchor;
351
+ return (size_t)(iend - anchor);
331
352
  }
332
353
 
333
354
  size_t ZSTD_compressBlock_fast_dictMatchState(
334
355
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
335
356
  void const* src, size_t srcSize)
336
357
  {
337
- ZSTD_compressionParameters const* cParams = &ms->cParams;
338
- U32 const mls = cParams->minMatch;
358
+ U32 const mls = ms->cParams.minMatch;
339
359
  assert(ms->dictMatchState != NULL);
340
360
  switch(mls)
341
361
  {
@@ -366,15 +386,24 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
366
386
  const BYTE* const istart = (const BYTE*)src;
367
387
  const BYTE* ip = istart;
368
388
  const BYTE* anchor = istart;
369
- const U32 dictStartIndex = ms->window.lowLimit;
389
+ const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
390
+ const U32 lowLimit = ZSTD_getLowestMatchIndex(ms, endIndex, cParams->windowLog);
391
+ const U32 dictStartIndex = lowLimit;
370
392
  const BYTE* const dictStart = dictBase + dictStartIndex;
371
- const U32 prefixStartIndex = ms->window.dictLimit;
393
+ const U32 dictLimit = ms->window.dictLimit;
394
+ const U32 prefixStartIndex = dictLimit < lowLimit ? lowLimit : dictLimit;
372
395
  const BYTE* const prefixStart = base + prefixStartIndex;
373
396
  const BYTE* const dictEnd = dictBase + prefixStartIndex;
374
397
  const BYTE* const iend = istart + srcSize;
375
398
  const BYTE* const ilimit = iend - 8;
376
399
  U32 offset_1=rep[0], offset_2=rep[1];
377
400
 
401
+ DEBUGLOG(5, "ZSTD_compressBlock_fast_extDict_generic (offset_1=%u)", offset_1);
402
+
403
+ /* switch to "regular" variant if extDict is invalidated due to maxDistance */
404
+ if (prefixStartIndex == dictStartIndex)
405
+ return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, mls);
406
+
378
407
  /* Search Loop */
379
408
  while (ip < ilimit) { /* < instead of <=, because (ip+1) */
380
409
  const size_t h = ZSTD_hashPtr(ip, hlog, mls);
@@ -385,16 +414,18 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
385
414
  const U32 repIndex = current + 1 - offset_1;
386
415
  const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
387
416
  const BYTE* const repMatch = repBase + repIndex;
388
- size_t mLength;
389
417
  hashTable[h] = current; /* update hash table */
418
+ DEBUGLOG(7, "offset_1 = %u , current = %u", offset_1, current);
390
419
  assert(offset_1 <= current +1); /* check repIndex */
391
420
 
392
421
  if ( (((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow */ & (repIndex > dictStartIndex))
393
422
  && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
394
- const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
395
- mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
423
+ const BYTE* const repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
424
+ size_t const rLength = ZSTD_count_2segments(ip+1 +4, repMatch +4, iend, repMatchEnd, prefixStart) + 4;
396
425
  ip++;
397
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
426
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, rLength-MINMATCH);
427
+ ip += rLength;
428
+ anchor = ip;
398
429
  } else {
399
430
  if ( (matchIndex < dictStartIndex) ||
400
431
  (MEM_read32(match) != MEM_read32(ip)) ) {
@@ -402,21 +433,17 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
402
433
  ip += ((ip-anchor) >> kSearchStrength) + stepSize;
403
434
  continue;
404
435
  }
405
- { const BYTE* matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
406
- const BYTE* lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
407
- U32 offset;
408
- mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
436
+ { const BYTE* const matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
437
+ const BYTE* const lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
438
+ U32 const offset = current - matchIndex;
439
+ size_t mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
409
440
  while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
410
- offset = current - matchIndex;
411
- offset_2 = offset_1;
412
- offset_1 = offset;
413
- ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
441
+ offset_2 = offset_1; offset_1 = offset; /* update offset history */
442
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
443
+ ip += mLength;
444
+ anchor = ip;
414
445
  } }
415
446
 
416
- /* found a match : store it */
417
- ip += mLength;
418
- anchor = ip;
419
-
420
447
  if (ip <= ilimit) {
421
448
  /* Fill Table */
422
449
  hashTable[ZSTD_hashPtr(base+current+2, hlog, mls)] = current+2;
@@ -425,13 +452,13 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
425
452
  while (ip <= ilimit) {
426
453
  U32 const current2 = (U32)(ip-base);
427
454
  U32 const repIndex2 = current2 - offset_2;
428
- const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
455
+ const BYTE* const repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
429
456
  if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) & (repIndex2 > dictStartIndex)) /* intentional overflow */
430
457
  && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
431
458
  const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
432
459
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
433
- U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
434
- ZSTD_storeSeq(seqStore, 0, anchor, 0, repLength2-MINMATCH);
460
+ { U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; } /* swap offset_2 <=> offset_1 */
461
+ ZSTD_storeSeq(seqStore, 0 /*litlen*/, anchor, iend, 0 /*offcode*/, repLength2-MINMATCH);
435
462
  hashTable[ZSTD_hashPtr(ip, hlog, mls)] = current2;
436
463
  ip += repLength2;
437
464
  anchor = ip;
@@ -445,7 +472,7 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
445
472
  rep[1] = offset_2;
446
473
 
447
474
  /* Return the last literals size */
448
- return iend - anchor;
475
+ return (size_t)(iend - anchor);
449
476
  }
450
477
 
451
478
 
@@ -453,8 +480,7 @@ size_t ZSTD_compressBlock_fast_extDict(
453
480
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
454
481
  void const* src, size_t srcSize)
455
482
  {
456
- ZSTD_compressionParameters const* cParams = &ms->cParams;
457
- U32 const mls = cParams->minMatch;
483
+ U32 const mls = ms->cParams.minMatch;
458
484
  switch(mls)
459
485
  {
460
486
  default: /* includes case 3 */