zstdlib 0.6.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +20 -0
  3. data/README.md +7 -1
  4. data/Rakefile +38 -8
  5. data/ext/{zstdlib → zstdlib_c}/extconf.rb +10 -5
  6. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.2/zstdlib.c +2 -2
  7. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.3/zstdlib.c +2 -2
  8. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.4/zstdlib.c +2 -2
  9. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.5/zstdlib.c +2 -2
  10. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.6/zstdlib.c +2 -2
  11. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.7/zstdlib.c +2 -2
  12. data/ext/zstdlib_c/ruby/zlib-3.0/zstdlib.c +4994 -0
  13. data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
  14. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/adler32.c +0 -0
  15. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/compress.c +0 -0
  16. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/crc32.c +0 -0
  17. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/crc32.h +0 -0
  18. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/deflate.c +0 -0
  19. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/deflate.h +0 -0
  20. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzclose.c +0 -0
  21. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzguts.h +0 -0
  22. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzlib.c +0 -0
  23. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzread.c +0 -0
  24. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzwrite.c +0 -0
  25. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/infback.c +0 -0
  26. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffast.c +0 -0
  27. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffast.h +0 -0
  28. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffixed.h +0 -0
  29. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inflate.c +0 -0
  30. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inflate.h +0 -0
  31. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inftrees.c +0 -0
  32. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inftrees.h +0 -0
  33. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/trees.c +0 -0
  34. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/trees.h +0 -0
  35. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/uncompr.c +0 -0
  36. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zconf.h +0 -0
  37. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zlib.h +0 -0
  38. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zutil.c +0 -0
  39. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zutil.h +0 -0
  40. data/ext/{zstdlib → zstdlib_c}/zlib.mk +0 -0
  41. data/ext/{zstdlib → zstdlib_c}/zlibwrapper/zlibwrapper.c +1 -5
  42. data/ext/{zstdlib → zstdlib_c}/zlibwrapper.mk +0 -0
  43. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/bitstream.h +75 -57
  44. data/ext/zstdlib_c/zstd-1.5.2/lib/common/compiler.h +335 -0
  45. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/cpu.h +1 -3
  46. data/ext/zstdlib_c/zstd-1.5.2/lib/common/debug.c +24 -0
  47. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/debug.h +22 -49
  48. data/ext/zstdlib_c/zstd-1.5.2/lib/common/entropy_common.c +368 -0
  49. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/error_private.c +3 -1
  50. data/ext/zstdlib_c/zstd-1.5.2/lib/common/error_private.h +159 -0
  51. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/fse.h +51 -42
  52. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/fse_decompress.c +149 -57
  53. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/huf.h +60 -54
  54. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/mem.h +87 -98
  55. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/pool.c +34 -23
  56. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/pool.h +5 -5
  57. data/ext/zstdlib_c/zstd-1.5.2/lib/common/portability_macros.h +137 -0
  58. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/threading.c +10 -8
  59. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/threading.h +4 -3
  60. data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.c +24 -0
  61. data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.h +5686 -0
  62. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_common.c +10 -10
  63. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_deps.h +111 -0
  64. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_internal.h +493 -0
  65. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_trace.h +163 -0
  66. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/clevels.h +134 -0
  67. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/fse_compress.c +105 -85
  68. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.c +41 -63
  69. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.h +13 -33
  70. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/huf_compress.c +1370 -0
  71. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress.c +6327 -0
  72. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_internal.h +537 -82
  73. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.c +21 -16
  74. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.h +4 -2
  75. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.c +61 -34
  76. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.h +10 -3
  77. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_superblock.c +573 -0
  78. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_superblock.h +32 -0
  79. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_cwksp.h +236 -95
  80. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.c +321 -143
  81. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.h +2 -2
  82. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.c +328 -137
  83. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.h +2 -2
  84. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.c +2104 -0
  85. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.h +125 -0
  86. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.c +336 -209
  87. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.h +15 -3
  88. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_ldm_geartab.h +106 -0
  89. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.c +439 -239
  90. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.h +1 -1
  91. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/compress/zstdmt_compress.c +205 -462
  92. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstdmt_compress.h +113 -0
  93. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress.c +1889 -0
  94. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress_amd64.S +585 -0
  95. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.c +20 -16
  96. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.h +3 -3
  97. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress.c +691 -230
  98. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/zstd_decompress_block.c +2072 -0
  99. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.h +16 -7
  100. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_internal.h +71 -10
  101. data/ext/zstdlib_c/zstd-1.5.2/lib/zdict.h +452 -0
  102. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/lib/zstd.h +760 -234
  103. data/ext/{zstdlib/zstd-1.4.4/lib/common → zstdlib_c/zstd-1.5.2/lib}/zstd_errors.h +3 -1
  104. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzclose.c +0 -0
  105. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzcompatibility.h +1 -1
  106. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzguts.h +0 -0
  107. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzlib.c +0 -0
  108. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzread.c +0 -0
  109. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzwrite.c +0 -0
  110. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.c +133 -44
  111. data/ext/{zstdlib/zstd-1.4.4 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.h +1 -1
  112. data/ext/zstdlib_c/zstd.mk +15 -0
  113. data/lib/zstdlib.rb +2 -2
  114. metadata +118 -107
  115. data/ext/zstdlib/zstd-1.4.4/lib/common/compiler.h +0 -159
  116. data/ext/zstdlib/zstd-1.4.4/lib/common/debug.c +0 -44
  117. data/ext/zstdlib/zstd-1.4.4/lib/common/entropy_common.c +0 -236
  118. data/ext/zstdlib/zstd-1.4.4/lib/common/error_private.h +0 -76
  119. data/ext/zstdlib/zstd-1.4.4/lib/common/xxhash.c +0 -882
  120. data/ext/zstdlib/zstd-1.4.4/lib/common/xxhash.h +0 -305
  121. data/ext/zstdlib/zstd-1.4.4/lib/common/zstd_internal.h +0 -350
  122. data/ext/zstdlib/zstd-1.4.4/lib/compress/huf_compress.c +0 -798
  123. data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_compress.c +0 -4103
  124. data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_lazy.c +0 -1115
  125. data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_lazy.h +0 -67
  126. data/ext/zstdlib/zstd-1.4.4/lib/compress/zstdmt_compress.h +0 -192
  127. data/ext/zstdlib/zstd-1.4.4/lib/decompress/huf_decompress.c +0 -1234
  128. data/ext/zstdlib/zstd-1.4.4/lib/decompress/zstd_decompress_block.c +0 -1323
  129. data/ext/zstdlib/zstd.mk +0 -14
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -31,15 +31,15 @@ void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
31
31
  * is empty.
32
32
  */
33
33
  for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
34
- U32 const current = (U32)(ip - base);
34
+ U32 const curr = (U32)(ip - base);
35
35
  U32 i;
36
36
  for (i = 0; i < fastHashFillStep; ++i) {
37
37
  size_t const smHash = ZSTD_hashPtr(ip + i, hBitsS, mls);
38
38
  size_t const lgHash = ZSTD_hashPtr(ip + i, hBitsL, 8);
39
39
  if (i == 0)
40
- hashSmall[smHash] = current + i;
40
+ hashSmall[smHash] = curr + i;
41
41
  if (i == 0 || hashLarge[lgHash] == 0)
42
- hashLarge[lgHash] = current + i;
42
+ hashLarge[lgHash] = curr + i;
43
43
  /* Only load extra positions for ZSTD_dtlm_full */
44
44
  if (dtlm == ZSTD_dtlm_fast)
45
45
  break;
@@ -48,10 +48,216 @@ void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
48
48
 
49
49
 
50
50
  FORCE_INLINE_TEMPLATE
51
- size_t ZSTD_compressBlock_doubleFast_generic(
51
+ size_t ZSTD_compressBlock_doubleFast_noDict_generic(
52
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
53
+ void const* src, size_t srcSize, U32 const mls /* template */)
54
+ {
55
+ ZSTD_compressionParameters const* cParams = &ms->cParams;
56
+ U32* const hashLong = ms->hashTable;
57
+ const U32 hBitsL = cParams->hashLog;
58
+ U32* const hashSmall = ms->chainTable;
59
+ const U32 hBitsS = cParams->chainLog;
60
+ const BYTE* const base = ms->window.base;
61
+ const BYTE* const istart = (const BYTE*)src;
62
+ const BYTE* anchor = istart;
63
+ const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
64
+ /* presumes that, if there is a dictionary, it must be using Attach mode */
65
+ const U32 prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, cParams->windowLog);
66
+ const BYTE* const prefixLowest = base + prefixLowestIndex;
67
+ const BYTE* const iend = istart + srcSize;
68
+ const BYTE* const ilimit = iend - HASH_READ_SIZE;
69
+ U32 offset_1=rep[0], offset_2=rep[1];
70
+ U32 offsetSaved = 0;
71
+
72
+ size_t mLength;
73
+ U32 offset;
74
+ U32 curr;
75
+
76
+ /* how many positions to search before increasing step size */
77
+ const size_t kStepIncr = 1 << kSearchStrength;
78
+ /* the position at which to increment the step size if no match is found */
79
+ const BYTE* nextStep;
80
+ size_t step; /* the current step size */
81
+
82
+ size_t hl0; /* the long hash at ip */
83
+ size_t hl1; /* the long hash at ip1 */
84
+
85
+ U32 idxl0; /* the long match index for ip */
86
+ U32 idxl1; /* the long match index for ip1 */
87
+
88
+ const BYTE* matchl0; /* the long match for ip */
89
+ const BYTE* matchs0; /* the short match for ip */
90
+ const BYTE* matchl1; /* the long match for ip1 */
91
+
92
+ const BYTE* ip = istart; /* the current position */
93
+ const BYTE* ip1; /* the next position */
94
+
95
+ DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_noDict_generic");
96
+
97
+ /* init */
98
+ ip += ((ip - prefixLowest) == 0);
99
+ {
100
+ U32 const current = (U32)(ip - base);
101
+ U32 const windowLow = ZSTD_getLowestPrefixIndex(ms, current, cParams->windowLog);
102
+ U32 const maxRep = current - windowLow;
103
+ if (offset_2 > maxRep) offsetSaved = offset_2, offset_2 = 0;
104
+ if (offset_1 > maxRep) offsetSaved = offset_1, offset_1 = 0;
105
+ }
106
+
107
+ /* Outer Loop: one iteration per match found and stored */
108
+ while (1) {
109
+ step = 1;
110
+ nextStep = ip + kStepIncr;
111
+ ip1 = ip + step;
112
+
113
+ if (ip1 > ilimit) {
114
+ goto _cleanup;
115
+ }
116
+
117
+ hl0 = ZSTD_hashPtr(ip, hBitsL, 8);
118
+ idxl0 = hashLong[hl0];
119
+ matchl0 = base + idxl0;
120
+
121
+ /* Inner Loop: one iteration per search / position */
122
+ do {
123
+ const size_t hs0 = ZSTD_hashPtr(ip, hBitsS, mls);
124
+ const U32 idxs0 = hashSmall[hs0];
125
+ curr = (U32)(ip-base);
126
+ matchs0 = base + idxs0;
127
+
128
+ hashLong[hl0] = hashSmall[hs0] = curr; /* update hash tables */
129
+
130
+ /* check noDict repcode */
131
+ if ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1))) {
132
+ mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
133
+ ip++;
134
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_REPCODE_1, mLength);
135
+ goto _match_stored;
136
+ }
137
+
138
+ hl1 = ZSTD_hashPtr(ip1, hBitsL, 8);
139
+
140
+ if (idxl0 > prefixLowestIndex) {
141
+ /* check prefix long match */
142
+ if (MEM_read64(matchl0) == MEM_read64(ip)) {
143
+ mLength = ZSTD_count(ip+8, matchl0+8, iend) + 8;
144
+ offset = (U32)(ip-matchl0);
145
+ while (((ip>anchor) & (matchl0>prefixLowest)) && (ip[-1] == matchl0[-1])) { ip--; matchl0--; mLength++; } /* catch up */
146
+ goto _match_found;
147
+ }
148
+ }
149
+
150
+ idxl1 = hashLong[hl1];
151
+ matchl1 = base + idxl1;
152
+
153
+ if (idxs0 > prefixLowestIndex) {
154
+ /* check prefix short match */
155
+ if (MEM_read32(matchs0) == MEM_read32(ip)) {
156
+ goto _search_next_long;
157
+ }
158
+ }
159
+
160
+ if (ip1 >= nextStep) {
161
+ PREFETCH_L1(ip1 + 64);
162
+ PREFETCH_L1(ip1 + 128);
163
+ step++;
164
+ nextStep += kStepIncr;
165
+ }
166
+ ip = ip1;
167
+ ip1 += step;
168
+
169
+ hl0 = hl1;
170
+ idxl0 = idxl1;
171
+ matchl0 = matchl1;
172
+ #if defined(__aarch64__)
173
+ PREFETCH_L1(ip+256);
174
+ #endif
175
+ } while (ip1 <= ilimit);
176
+
177
+ _cleanup:
178
+ /* save reps for next block */
179
+ rep[0] = offset_1 ? offset_1 : offsetSaved;
180
+ rep[1] = offset_2 ? offset_2 : offsetSaved;
181
+
182
+ /* Return the last literals size */
183
+ return (size_t)(iend - anchor);
184
+
185
+ _search_next_long:
186
+
187
+ /* check prefix long +1 match */
188
+ if (idxl1 > prefixLowestIndex) {
189
+ if (MEM_read64(matchl1) == MEM_read64(ip1)) {
190
+ ip = ip1;
191
+ mLength = ZSTD_count(ip+8, matchl1+8, iend) + 8;
192
+ offset = (U32)(ip-matchl1);
193
+ while (((ip>anchor) & (matchl1>prefixLowest)) && (ip[-1] == matchl1[-1])) { ip--; matchl1--; mLength++; } /* catch up */
194
+ goto _match_found;
195
+ }
196
+ }
197
+
198
+ /* if no long +1 match, explore the short match we found */
199
+ mLength = ZSTD_count(ip+4, matchs0+4, iend) + 4;
200
+ offset = (U32)(ip - matchs0);
201
+ while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* catch up */
202
+
203
+ /* fall-through */
204
+
205
+ _match_found: /* requires ip, offset, mLength */
206
+ offset_2 = offset_1;
207
+ offset_1 = offset;
208
+
209
+ if (step < 4) {
210
+ /* It is unsafe to write this value back to the hashtable when ip1 is
211
+ * greater than or equal to the new ip we will have after we're done
212
+ * processing this match. Rather than perform that test directly
213
+ * (ip1 >= ip + mLength), which costs speed in practice, we do a simpler
214
+ * more predictable test. The minmatch even if we take a short match is
215
+ * 4 bytes, so as long as step, the distance between ip and ip1
216
+ * (initially) is less than 4, we know ip1 < new ip. */
217
+ hashLong[hl1] = (U32)(ip1 - base);
218
+ }
219
+
220
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_OFFSET(offset), mLength);
221
+
222
+ _match_stored:
223
+ /* match found */
224
+ ip += mLength;
225
+ anchor = ip;
226
+
227
+ if (ip <= ilimit) {
228
+ /* Complementary insertion */
229
+ /* done after iLimit test, as candidates could be > iend-8 */
230
+ { U32 const indexToInsert = curr+2;
231
+ hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
232
+ hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
233
+ hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
234
+ hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
235
+ }
236
+
237
+ /* check immediate repcode */
238
+ while ( (ip <= ilimit)
239
+ && ( (offset_2>0)
240
+ & (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) {
241
+ /* store sequence */
242
+ size_t const rLength = ZSTD_count(ip+4, ip+4-offset_2, iend) + 4;
243
+ U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; /* swap offset_2 <=> offset_1 */
244
+ hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip-base);
245
+ hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip-base);
246
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, STORE_REPCODE_1, rLength);
247
+ ip += rLength;
248
+ anchor = ip;
249
+ continue; /* faster when present ... (?) */
250
+ }
251
+ }
252
+ }
253
+ }
254
+
255
+
256
+ FORCE_INLINE_TEMPLATE
257
+ size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
52
258
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
53
259
  void const* src, size_t srcSize,
54
- U32 const mls /* template */, ZSTD_dictMode_e const dictMode)
260
+ U32 const mls /* template */)
55
261
  {
56
262
  ZSTD_compressionParameters const* cParams = &ms->cParams;
57
263
  U32* const hashLong = ms->hashTable;
@@ -63,10 +269,8 @@ size_t ZSTD_compressBlock_doubleFast_generic(
63
269
  const BYTE* ip = istart;
64
270
  const BYTE* anchor = istart;
65
271
  const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
66
- const U32 lowestValid = ms->window.dictLimit;
67
- const U32 maxDistance = 1U << cParams->windowLog;
68
272
  /* presumes that, if there is a dictionary, it must be using Attach mode */
69
- const U32 prefixLowestIndex = (endIndex - lowestValid > maxDistance) ? endIndex - maxDistance : lowestValid;
273
+ const U32 prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, cParams->windowLog);
70
274
  const BYTE* const prefixLowest = base + prefixLowestIndex;
71
275
  const BYTE* const iend = istart + srcSize;
72
276
  const BYTE* const ilimit = iend - HASH_READ_SIZE;
@@ -74,52 +278,30 @@ size_t ZSTD_compressBlock_doubleFast_generic(
74
278
  U32 offsetSaved = 0;
75
279
 
76
280
  const ZSTD_matchState_t* const dms = ms->dictMatchState;
77
- const ZSTD_compressionParameters* const dictCParams =
78
- dictMode == ZSTD_dictMatchState ?
79
- &dms->cParams : NULL;
80
- const U32* const dictHashLong = dictMode == ZSTD_dictMatchState ?
81
- dms->hashTable : NULL;
82
- const U32* const dictHashSmall = dictMode == ZSTD_dictMatchState ?
83
- dms->chainTable : NULL;
84
- const U32 dictStartIndex = dictMode == ZSTD_dictMatchState ?
85
- dms->window.dictLimit : 0;
86
- const BYTE* const dictBase = dictMode == ZSTD_dictMatchState ?
87
- dms->window.base : NULL;
88
- const BYTE* const dictStart = dictMode == ZSTD_dictMatchState ?
89
- dictBase + dictStartIndex : NULL;
90
- const BYTE* const dictEnd = dictMode == ZSTD_dictMatchState ?
91
- dms->window.nextSrc : NULL;
92
- const U32 dictIndexDelta = dictMode == ZSTD_dictMatchState ?
93
- prefixLowestIndex - (U32)(dictEnd - dictBase) :
94
- 0;
95
- const U32 dictHBitsL = dictMode == ZSTD_dictMatchState ?
96
- dictCParams->hashLog : hBitsL;
97
- const U32 dictHBitsS = dictMode == ZSTD_dictMatchState ?
98
- dictCParams->chainLog : hBitsS;
99
- const U32 dictAndPrefixLength = (U32)(ip - prefixLowest + dictEnd - dictStart);
100
-
101
- DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_generic");
102
-
103
- assert(dictMode == ZSTD_noDict || dictMode == ZSTD_dictMatchState);
281
+ const ZSTD_compressionParameters* const dictCParams = &dms->cParams;
282
+ const U32* const dictHashLong = dms->hashTable;
283
+ const U32* const dictHashSmall = dms->chainTable;
284
+ const U32 dictStartIndex = dms->window.dictLimit;
285
+ const BYTE* const dictBase = dms->window.base;
286
+ const BYTE* const dictStart = dictBase + dictStartIndex;
287
+ const BYTE* const dictEnd = dms->window.nextSrc;
288
+ const U32 dictIndexDelta = prefixLowestIndex - (U32)(dictEnd - dictBase);
289
+ const U32 dictHBitsL = dictCParams->hashLog;
290
+ const U32 dictHBitsS = dictCParams->chainLog;
291
+ const U32 dictAndPrefixLength = (U32)((ip - prefixLowest) + (dictEnd - dictStart));
292
+
293
+ DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_dictMatchState_generic");
104
294
 
105
295
  /* if a dictionary is attached, it must be within window range */
106
- if (dictMode == ZSTD_dictMatchState) {
107
- assert(lowestValid + maxDistance >= endIndex);
108
- }
296
+ assert(ms->window.dictLimit + (1U << cParams->windowLog) >= endIndex);
109
297
 
110
298
  /* init */
111
299
  ip += (dictAndPrefixLength == 0);
112
- if (dictMode == ZSTD_noDict) {
113
- U32 const maxRep = (U32)(ip - prefixLowest);
114
- if (offset_2 > maxRep) offsetSaved = offset_2, offset_2 = 0;
115
- if (offset_1 > maxRep) offsetSaved = offset_1, offset_1 = 0;
116
- }
117
- if (dictMode == ZSTD_dictMatchState) {
118
- /* dictMatchState repCode checks don't currently handle repCode == 0
119
- * disabling. */
120
- assert(offset_1 <= dictAndPrefixLength);
121
- assert(offset_2 <= dictAndPrefixLength);
122
- }
300
+
301
+ /* dictMatchState repCode checks don't currently handle repCode == 0
302
+ * disabling. */
303
+ assert(offset_1 <= dictAndPrefixLength);
304
+ assert(offset_2 <= dictAndPrefixLength);
123
305
 
124
306
  /* Main Search Loop */
125
307
  while (ip < ilimit) { /* < instead of <=, because repcode check at (ip+1) */
@@ -129,35 +311,24 @@ size_t ZSTD_compressBlock_doubleFast_generic(
129
311
  size_t const h = ZSTD_hashPtr(ip, hBitsS, mls);
130
312
  size_t const dictHL = ZSTD_hashPtr(ip, dictHBitsL, 8);
131
313
  size_t const dictHS = ZSTD_hashPtr(ip, dictHBitsS, mls);
132
- U32 const current = (U32)(ip-base);
314
+ U32 const curr = (U32)(ip-base);
133
315
  U32 const matchIndexL = hashLong[h2];
134
316
  U32 matchIndexS = hashSmall[h];
135
317
  const BYTE* matchLong = base + matchIndexL;
136
318
  const BYTE* match = base + matchIndexS;
137
- const U32 repIndex = current + 1 - offset_1;
138
- const BYTE* repMatch = (dictMode == ZSTD_dictMatchState
139
- && repIndex < prefixLowestIndex) ?
319
+ const U32 repIndex = curr + 1 - offset_1;
320
+ const BYTE* repMatch = (repIndex < prefixLowestIndex) ?
140
321
  dictBase + (repIndex - dictIndexDelta) :
141
322
  base + repIndex;
142
- hashLong[h2] = hashSmall[h] = current; /* update hash tables */
323
+ hashLong[h2] = hashSmall[h] = curr; /* update hash tables */
143
324
 
144
- /* check dictMatchState repcode */
145
- if (dictMode == ZSTD_dictMatchState
146
- && ((U32)((prefixLowestIndex-1) - repIndex) >= 3 /* intentional underflow */)
325
+ /* check repcode */
326
+ if (((U32)((prefixLowestIndex-1) - repIndex) >= 3 /* intentional underflow */)
147
327
  && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
148
328
  const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
149
329
  mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
150
330
  ip++;
151
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
152
- goto _match_stored;
153
- }
154
-
155
- /* check noDict repcode */
156
- if ( dictMode == ZSTD_noDict
157
- && ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1)))) {
158
- mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
159
- ip++;
160
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
331
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_REPCODE_1, mLength);
161
332
  goto _match_stored;
162
333
  }
163
334
 
@@ -169,7 +340,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
169
340
  while (((ip>anchor) & (matchLong>prefixLowest)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
170
341
  goto _match_found;
171
342
  }
172
- } else if (dictMode == ZSTD_dictMatchState) {
343
+ } else {
173
344
  /* check dictMatchState long match */
174
345
  U32 const dictMatchIndexL = dictHashLong[dictHL];
175
346
  const BYTE* dictMatchL = dictBase + dictMatchIndexL;
@@ -177,7 +348,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
177
348
 
178
349
  if (dictMatchL > dictStart && MEM_read64(dictMatchL) == MEM_read64(ip)) {
179
350
  mLength = ZSTD_count_2segments(ip+8, dictMatchL+8, iend, dictEnd, prefixLowest) + 8;
180
- offset = (U32)(current - dictMatchIndexL - dictIndexDelta);
351
+ offset = (U32)(curr - dictMatchIndexL - dictIndexDelta);
181
352
  while (((ip>anchor) & (dictMatchL>dictStart)) && (ip[-1] == dictMatchL[-1])) { ip--; dictMatchL--; mLength++; } /* catch up */
182
353
  goto _match_found;
183
354
  } }
@@ -187,7 +358,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(
187
358
  if (MEM_read32(match) == MEM_read32(ip)) {
188
359
  goto _search_next_long;
189
360
  }
190
- } else if (dictMode == ZSTD_dictMatchState) {
361
+ } else {
191
362
  /* check dictMatchState short match */
192
363
  U32 const dictMatchIndexS = dictHashSmall[dictHS];
193
364
  match = dictBase + dictMatchIndexS;
@@ -198,6 +369,9 @@ size_t ZSTD_compressBlock_doubleFast_generic(
198
369
  } }
199
370
 
200
371
  ip += ((ip-anchor) >> kSearchStrength) + 1;
372
+ #if defined(__aarch64__)
373
+ PREFETCH_L1(ip+256);
374
+ #endif
201
375
  continue;
202
376
 
203
377
  _search_next_long:
@@ -206,7 +380,7 @@ _search_next_long:
206
380
  size_t const dictHLNext = ZSTD_hashPtr(ip+1, dictHBitsL, 8);
207
381
  U32 const matchIndexL3 = hashLong[hl3];
208
382
  const BYTE* matchL3 = base + matchIndexL3;
209
- hashLong[hl3] = current + 1;
383
+ hashLong[hl3] = curr + 1;
210
384
 
211
385
  /* check prefix long +1 match */
212
386
  if (matchIndexL3 > prefixLowestIndex) {
@@ -217,7 +391,7 @@ _search_next_long:
217
391
  while (((ip>anchor) & (matchL3>prefixLowest)) && (ip[-1] == matchL3[-1])) { ip--; matchL3--; mLength++; } /* catch up */
218
392
  goto _match_found;
219
393
  }
220
- } else if (dictMode == ZSTD_dictMatchState) {
394
+ } else {
221
395
  /* check dict long +1 match */
222
396
  U32 const dictMatchIndexL3 = dictHashLong[dictHLNext];
223
397
  const BYTE* dictMatchL3 = dictBase + dictMatchIndexL3;
@@ -225,15 +399,15 @@ _search_next_long:
225
399
  if (dictMatchL3 > dictStart && MEM_read64(dictMatchL3) == MEM_read64(ip+1)) {
226
400
  mLength = ZSTD_count_2segments(ip+1+8, dictMatchL3+8, iend, dictEnd, prefixLowest) + 8;
227
401
  ip++;
228
- offset = (U32)(current + 1 - dictMatchIndexL3 - dictIndexDelta);
402
+ offset = (U32)(curr + 1 - dictMatchIndexL3 - dictIndexDelta);
229
403
  while (((ip>anchor) & (dictMatchL3>dictStart)) && (ip[-1] == dictMatchL3[-1])) { ip--; dictMatchL3--; mLength++; } /* catch up */
230
404
  goto _match_found;
231
405
  } } }
232
406
 
233
407
  /* if no long +1 match, explore the short match we found */
234
- if (dictMode == ZSTD_dictMatchState && matchIndexS < prefixLowestIndex) {
408
+ if (matchIndexS < prefixLowestIndex) {
235
409
  mLength = ZSTD_count_2segments(ip+4, match+4, iend, dictEnd, prefixLowest) + 4;
236
- offset = (U32)(current - matchIndexS);
410
+ offset = (U32)(curr - matchIndexS);
237
411
  while (((ip>anchor) & (match>dictStart)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
238
412
  } else {
239
413
  mLength = ZSTD_count(ip+4, match+4, iend) + 4;
@@ -241,13 +415,11 @@ _search_next_long:
241
415
  while (((ip>anchor) & (match>prefixLowest)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
242
416
  }
243
417
 
244
- /* fall-through */
245
-
246
418
  _match_found:
247
419
  offset_2 = offset_1;
248
420
  offset_1 = offset;
249
421
 
250
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
422
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_OFFSET(offset), mLength);
251
423
 
252
424
  _match_stored:
253
425
  /* match found */
@@ -257,7 +429,7 @@ _match_stored:
257
429
  if (ip <= ilimit) {
258
430
  /* Complementary insertion */
259
431
  /* done after iLimit test, as candidates could be > iend-8 */
260
- { U32 const indexToInsert = current+2;
432
+ { U32 const indexToInsert = curr+2;
261
433
  hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
262
434
  hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
263
435
  hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
@@ -265,43 +437,27 @@ _match_stored:
265
437
  }
266
438
 
267
439
  /* check immediate repcode */
268
- if (dictMode == ZSTD_dictMatchState) {
269
- while (ip <= ilimit) {
270
- U32 const current2 = (U32)(ip-base);
271
- U32 const repIndex2 = current2 - offset_2;
272
- const BYTE* repMatch2 = dictMode == ZSTD_dictMatchState
273
- && repIndex2 < prefixLowestIndex ?
274
- dictBase - dictIndexDelta + repIndex2 :
275
- base + repIndex2;
276
- if ( ((U32)((prefixLowestIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
277
- && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
278
- const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
279
- size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
280
- U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
281
- ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
282
- hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
283
- hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
284
- ip += repLength2;
285
- anchor = ip;
286
- continue;
287
- }
288
- break;
289
- } }
290
-
291
- if (dictMode == ZSTD_noDict) {
292
- while ( (ip <= ilimit)
293
- && ( (offset_2>0)
294
- & (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) {
295
- /* store sequence */
296
- size_t const rLength = ZSTD_count(ip+4, ip+4-offset_2, iend) + 4;
297
- U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; /* swap offset_2 <=> offset_1 */
298
- hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip-base);
299
- hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip-base);
300
- ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, rLength-MINMATCH);
301
- ip += rLength;
440
+ while (ip <= ilimit) {
441
+ U32 const current2 = (U32)(ip-base);
442
+ U32 const repIndex2 = current2 - offset_2;
443
+ const BYTE* repMatch2 = repIndex2 < prefixLowestIndex ?
444
+ dictBase + repIndex2 - dictIndexDelta :
445
+ base + repIndex2;
446
+ if ( ((U32)((prefixLowestIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
447
+ && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
448
+ const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
449
+ size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
450
+ U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
451
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, STORE_REPCODE_1, repLength2);
452
+ hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
453
+ hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
454
+ ip += repLength2;
302
455
  anchor = ip;
303
- continue; /* faster when present ... (?) */
304
- } } }
456
+ continue;
457
+ }
458
+ break;
459
+ }
460
+ }
305
461
  } /* while (ip < ilimit) */
306
462
 
307
463
  /* save reps for next block */
@@ -312,6 +468,24 @@ _match_stored:
312
468
  return (size_t)(iend - anchor);
313
469
  }
314
470
 
471
+ #define ZSTD_GEN_DFAST_FN(dictMode, mls) \
472
+ static size_t ZSTD_compressBlock_doubleFast_##dictMode##_##mls( \
473
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], \
474
+ void const* src, size_t srcSize) \
475
+ { \
476
+ return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
477
+ }
478
+
479
+ ZSTD_GEN_DFAST_FN(noDict, 4)
480
+ ZSTD_GEN_DFAST_FN(noDict, 5)
481
+ ZSTD_GEN_DFAST_FN(noDict, 6)
482
+ ZSTD_GEN_DFAST_FN(noDict, 7)
483
+
484
+ ZSTD_GEN_DFAST_FN(dictMatchState, 4)
485
+ ZSTD_GEN_DFAST_FN(dictMatchState, 5)
486
+ ZSTD_GEN_DFAST_FN(dictMatchState, 6)
487
+ ZSTD_GEN_DFAST_FN(dictMatchState, 7)
488
+
315
489
 
316
490
  size_t ZSTD_compressBlock_doubleFast(
317
491
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
@@ -322,13 +496,13 @@ size_t ZSTD_compressBlock_doubleFast(
322
496
  {
323
497
  default: /* includes case 3 */
324
498
  case 4 :
325
- return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 4, ZSTD_noDict);
499
+ return ZSTD_compressBlock_doubleFast_noDict_4(ms, seqStore, rep, src, srcSize);
326
500
  case 5 :
327
- return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 5, ZSTD_noDict);
501
+ return ZSTD_compressBlock_doubleFast_noDict_5(ms, seqStore, rep, src, srcSize);
328
502
  case 6 :
329
- return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 6, ZSTD_noDict);
503
+ return ZSTD_compressBlock_doubleFast_noDict_6(ms, seqStore, rep, src, srcSize);
330
504
  case 7 :
331
- return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 7, ZSTD_noDict);
505
+ return ZSTD_compressBlock_doubleFast_noDict_7(ms, seqStore, rep, src, srcSize);
332
506
  }
333
507
  }
334
508
 
@@ -342,13 +516,13 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState(
342
516
  {
343
517
  default: /* includes case 3 */
344
518
  case 4 :
345
- return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 4, ZSTD_dictMatchState);
519
+ return ZSTD_compressBlock_doubleFast_dictMatchState_4(ms, seqStore, rep, src, srcSize);
346
520
  case 5 :
347
- return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 5, ZSTD_dictMatchState);
521
+ return ZSTD_compressBlock_doubleFast_dictMatchState_5(ms, seqStore, rep, src, srcSize);
348
522
  case 6 :
349
- return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 6, ZSTD_dictMatchState);
523
+ return ZSTD_compressBlock_doubleFast_dictMatchState_6(ms, seqStore, rep, src, srcSize);
350
524
  case 7 :
351
- return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 7, ZSTD_dictMatchState);
525
+ return ZSTD_compressBlock_doubleFast_dictMatchState_7(ms, seqStore, rep, src, srcSize);
352
526
  }
353
527
  }
354
528
 
@@ -384,7 +558,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
384
558
 
385
559
  /* if extDict is invalidated due to maxDistance, switch to "regular" variant */
386
560
  if (prefixStartIndex == dictStartIndex)
387
- return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, mls, ZSTD_noDict);
561
+ return ZSTD_compressBlock_doubleFast(ms, seqStore, rep, src, srcSize);
388
562
 
389
563
  /* Search Loop */
390
564
  while (ip < ilimit) { /* < instead of <=, because (ip+1) */
@@ -398,31 +572,31 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
398
572
  const BYTE* const matchLongBase = matchLongIndex < prefixStartIndex ? dictBase : base;
399
573
  const BYTE* matchLong = matchLongBase + matchLongIndex;
400
574
 
401
- const U32 current = (U32)(ip-base);
402
- const U32 repIndex = current + 1 - offset_1; /* offset_1 expected <= current +1 */
575
+ const U32 curr = (U32)(ip-base);
576
+ const U32 repIndex = curr + 1 - offset_1; /* offset_1 expected <= curr +1 */
403
577
  const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
404
578
  const BYTE* const repMatch = repBase + repIndex;
405
579
  size_t mLength;
406
- hashSmall[hSmall] = hashLong[hLong] = current; /* update hash table */
580
+ hashSmall[hSmall] = hashLong[hLong] = curr; /* update hash table */
407
581
 
408
582
  if ((((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow : ensure repIndex doesn't overlap dict + prefix */
409
- & (repIndex > dictStartIndex))
583
+ & (offset_1 <= curr+1 - dictStartIndex)) /* note: we are searching at curr+1 */
410
584
  && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
411
585
  const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
412
586
  mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
413
587
  ip++;
414
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
588
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_REPCODE_1, mLength);
415
589
  } else {
416
590
  if ((matchLongIndex > dictStartIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
417
591
  const BYTE* const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
418
592
  const BYTE* const lowMatchPtr = matchLongIndex < prefixStartIndex ? dictStart : prefixStart;
419
593
  U32 offset;
420
594
  mLength = ZSTD_count_2segments(ip+8, matchLong+8, iend, matchEnd, prefixStart) + 8;
421
- offset = current - matchLongIndex;
595
+ offset = curr - matchLongIndex;
422
596
  while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
423
597
  offset_2 = offset_1;
424
598
  offset_1 = offset;
425
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
599
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_OFFSET(offset), mLength);
426
600
 
427
601
  } else if ((matchIndex > dictStartIndex) && (MEM_read32(match) == MEM_read32(ip))) {
428
602
  size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
@@ -430,24 +604,24 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
430
604
  const BYTE* const match3Base = matchIndex3 < prefixStartIndex ? dictBase : base;
431
605
  const BYTE* match3 = match3Base + matchIndex3;
432
606
  U32 offset;
433
- hashLong[h3] = current + 1;
607
+ hashLong[h3] = curr + 1;
434
608
  if ( (matchIndex3 > dictStartIndex) && (MEM_read64(match3) == MEM_read64(ip+1)) ) {
435
609
  const BYTE* const matchEnd = matchIndex3 < prefixStartIndex ? dictEnd : iend;
436
610
  const BYTE* const lowMatchPtr = matchIndex3 < prefixStartIndex ? dictStart : prefixStart;
437
611
  mLength = ZSTD_count_2segments(ip+9, match3+8, iend, matchEnd, prefixStart) + 8;
438
612
  ip++;
439
- offset = current+1 - matchIndex3;
613
+ offset = curr+1 - matchIndex3;
440
614
  while (((ip>anchor) & (match3>lowMatchPtr)) && (ip[-1] == match3[-1])) { ip--; match3--; mLength++; } /* catch up */
441
615
  } else {
442
616
  const BYTE* const matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
443
617
  const BYTE* const lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
444
618
  mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
445
- offset = current - matchIndex;
619
+ offset = curr - matchIndex;
446
620
  while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
447
621
  }
448
622
  offset_2 = offset_1;
449
623
  offset_1 = offset;
450
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
624
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_OFFSET(offset), mLength);
451
625
 
452
626
  } else {
453
627
  ip += ((ip-anchor) >> kSearchStrength) + 1;
@@ -461,7 +635,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
461
635
  if (ip <= ilimit) {
462
636
  /* Complementary insertion */
463
637
  /* done after iLimit test, as candidates could be > iend-8 */
464
- { U32 const indexToInsert = current+2;
638
+ { U32 const indexToInsert = curr+2;
465
639
  hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
466
640
  hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
467
641
  hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
@@ -474,12 +648,12 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
474
648
  U32 const repIndex2 = current2 - offset_2;
475
649
  const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
476
650
  if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) /* intentional overflow : ensure repIndex2 doesn't overlap dict + prefix */
477
- & (repIndex2 > dictStartIndex))
651
+ & (offset_2 <= current2 - dictStartIndex))
478
652
  && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
479
653
  const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
480
654
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
481
655
  U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
482
- ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
656
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, STORE_REPCODE_1, repLength2);
483
657
  hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
484
658
  hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
485
659
  ip += repLength2;
@@ -497,6 +671,10 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
497
671
  return (size_t)(iend - anchor);
498
672
  }
499
673
 
674
+ ZSTD_GEN_DFAST_FN(extDict, 4)
675
+ ZSTD_GEN_DFAST_FN(extDict, 5)
676
+ ZSTD_GEN_DFAST_FN(extDict, 6)
677
+ ZSTD_GEN_DFAST_FN(extDict, 7)
500
678
 
501
679
  size_t ZSTD_compressBlock_doubleFast_extDict(
502
680
  ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
@@ -507,12 +685,12 @@ size_t ZSTD_compressBlock_doubleFast_extDict(
507
685
  {
508
686
  default: /* includes case 3 */
509
687
  case 4 :
510
- return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 4);
688
+ return ZSTD_compressBlock_doubleFast_extDict_4(ms, seqStore, rep, src, srcSize);
511
689
  case 5 :
512
- return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 5);
690
+ return ZSTD_compressBlock_doubleFast_extDict_5(ms, seqStore, rep, src, srcSize);
513
691
  case 6 :
514
- return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 6);
692
+ return ZSTD_compressBlock_doubleFast_extDict_6(ms, seqStore, rep, src, srcSize);
515
693
  case 7 :
516
- return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 7);
694
+ return ZSTD_compressBlock_doubleFast_extDict_7(ms, seqStore, rep, src, srcSize);
517
695
  }
518
696
  }