1212#include "zstd_double_fast.h"
1313
1414
15- void ZSTD_fillDoubleHashTable (ZSTD_CCtx * cctx , const void * end , const U32 mls )
15+ void ZSTD_fillDoubleHashTable (ZSTD_matchState_t * ms ,
16+ ZSTD_compressionParameters const * cParams ,
17+ void const * end )
1618{
17- U32 * const hashLarge = cctx -> hashTable ;
18- U32 const hBitsL = cctx -> appliedParams .cParams .hashLog ;
19- U32 * const hashSmall = cctx -> chainTable ;
20- U32 const hBitsS = cctx -> appliedParams .cParams .chainLog ;
21- const BYTE * const base = cctx -> base ;
22- const BYTE * ip = base + cctx -> nextToUpdate ;
19+ U32 * const hashLarge = ms -> hashTable ;
20+ U32 const hBitsL = cParams -> hashLog ;
21+ U32 const mls = cParams -> searchLength ;
22+ U32 * const hashSmall = ms -> chainTable ;
23+ U32 const hBitsS = cParams -> chainLog ;
24+ const BYTE * const base = ms -> base ;
25+ const BYTE * ip = base + ms -> nextToUpdate ;
2326 const BYTE * const iend = ((const BYTE * )end ) - HASH_READ_SIZE ;
2427 const U32 fastHashFillStep = 3 ;
2528
@@ -43,24 +46,24 @@ void ZSTD_fillDoubleHashTable(ZSTD_CCtx* cctx, const void* end, const U32 mls)
4346
4447
4548FORCE_INLINE_TEMPLATE
46- size_t ZSTD_compressBlock_doubleFast_generic (ZSTD_CCtx * cctx ,
47- const void * src , size_t srcSize ,
48- const U32 mls )
49+ size_t ZSTD_compressBlock_doubleFast_generic (
50+ ZSTD_matchState_t * ms , seqStore_t * seqStore , U32 rep [ZSTD_REP_NUM ],
51+ ZSTD_compressionParameters const * cParams , void const * src , size_t srcSize ,
52+ U32 const mls /* template */ )
4953{
50- U32 * const hashLong = cctx -> hashTable ;
51- const U32 hBitsL = cctx -> appliedParams .cParams .hashLog ;
52- U32 * const hashSmall = cctx -> chainTable ;
53- const U32 hBitsS = cctx -> appliedParams .cParams .chainLog ;
54- seqStore_t * seqStorePtr = & (cctx -> seqStore );
55- const BYTE * const base = cctx -> base ;
54+ U32 * const hashLong = ms -> hashTable ;
55+ const U32 hBitsL = cParams -> hashLog ;
56+ U32 * const hashSmall = ms -> chainTable ;
57+ const U32 hBitsS = cParams -> chainLog ;
58+ const BYTE * const base = ms -> base ;
5659 const BYTE * const istart = (const BYTE * )src ;
5760 const BYTE * ip = istart ;
5861 const BYTE * anchor = istart ;
59- const U32 lowestIndex = cctx -> dictLimit ;
62+ const U32 lowestIndex = ms -> dictLimit ;
6063 const BYTE * const lowest = base + lowestIndex ;
6164 const BYTE * const iend = istart + srcSize ;
6265 const BYTE * const ilimit = iend - HASH_READ_SIZE ;
63- U32 offset_1 = seqStorePtr -> rep [0 ], offset_2 = seqStorePtr -> rep [1 ];
66+ U32 offset_1 = rep [0 ], offset_2 = rep [1 ];
6467 U32 offsetSaved = 0 ;
6568
6669 /* init */
@@ -87,7 +90,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(ZSTD_CCtx* cctx,
8790 /* favor repcode */
8891 mLength = ZSTD_count (ip + 1 + 4 , ip + 1 + 4 - offset_1 , iend ) + 4 ;
8992 ip ++ ;
90- ZSTD_storeSeq (seqStorePtr , ip - anchor , anchor , 0 , mLength - MINMATCH );
93+ ZSTD_storeSeq (seqStore , ip - anchor , anchor , 0 , mLength - MINMATCH );
9194 } else {
9295 U32 offset ;
9396 if ( (matchIndexL > lowestIndex ) && (MEM_read64 (matchLong ) == MEM_read64 (ip )) ) {
@@ -117,7 +120,7 @@ size_t ZSTD_compressBlock_doubleFast_generic(ZSTD_CCtx* cctx,
117120 offset_2 = offset_1 ;
118121 offset_1 = offset ;
119122
120- ZSTD_storeSeq (seqStorePtr , ip - anchor , anchor , offset + ZSTD_REP_MOVE , mLength - MINMATCH );
123+ ZSTD_storeSeq (seqStore , ip - anchor , anchor , offset + ZSTD_REP_MOVE , mLength - MINMATCH );
121124 }
122125
123126 /* match found */
@@ -140,61 +143,63 @@ size_t ZSTD_compressBlock_doubleFast_generic(ZSTD_CCtx* cctx,
140143 { U32 const tmpOff = offset_2 ; offset_2 = offset_1 ; offset_1 = tmpOff ; } /* swap offset_2 <=> offset_1 */
141144 hashSmall [ZSTD_hashPtr (ip , hBitsS , mls )] = (U32 )(ip - base );
142145 hashLong [ZSTD_hashPtr (ip , hBitsL , 8 )] = (U32 )(ip - base );
143- ZSTD_storeSeq (seqStorePtr , 0 , anchor , 0 , rLength - MINMATCH );
146+ ZSTD_storeSeq (seqStore , 0 , anchor , 0 , rLength - MINMATCH );
144147 ip += rLength ;
145148 anchor = ip ;
146149 continue ; /* faster when present ... (?) */
147150 } } }
148151
149152 /* save reps for next block */
150- seqStorePtr -> repToConfirm [0 ] = offset_1 ? offset_1 : offsetSaved ;
151- seqStorePtr -> repToConfirm [1 ] = offset_2 ? offset_2 : offsetSaved ;
153+ rep [0 ] = offset_1 ? offset_1 : offsetSaved ;
154+ rep [1 ] = offset_2 ? offset_2 : offsetSaved ;
152155
153156 /* Return the last literals size */
154157 return iend - anchor ;
155158}
156159
157160
158- size_t ZSTD_compressBlock_doubleFast (ZSTD_CCtx * ctx , const void * src , size_t srcSize )
161+ size_t ZSTD_compressBlock_doubleFast (
162+ ZSTD_matchState_t * ms , seqStore_t * seqStore , U32 rep [ZSTD_REP_NUM ],
163+ ZSTD_compressionParameters const * cParams , void const * src , size_t srcSize )
159164{
160- const U32 mls = ctx -> appliedParams . cParams . searchLength ;
165+ const U32 mls = cParams -> searchLength ;
161166 switch (mls )
162167 {
163168 default : /* includes case 3 */
164169 case 4 :
165- return ZSTD_compressBlock_doubleFast_generic (ctx , src , srcSize , 4 );
170+ return ZSTD_compressBlock_doubleFast_generic (ms , seqStore , rep , cParams , src , srcSize , 4 );
166171 case 5 :
167- return ZSTD_compressBlock_doubleFast_generic (ctx , src , srcSize , 5 );
172+ return ZSTD_compressBlock_doubleFast_generic (ms , seqStore , rep , cParams , src , srcSize , 5 );
168173 case 6 :
169- return ZSTD_compressBlock_doubleFast_generic (ctx , src , srcSize , 6 );
174+ return ZSTD_compressBlock_doubleFast_generic (ms , seqStore , rep , cParams , src , srcSize , 6 );
170175 case 7 :
171- return ZSTD_compressBlock_doubleFast_generic (ctx , src , srcSize , 7 );
176+ return ZSTD_compressBlock_doubleFast_generic (ms , seqStore , rep , cParams , src , srcSize , 7 );
172177 }
173178}
174179
175180
176- static size_t ZSTD_compressBlock_doubleFast_extDict_generic (ZSTD_CCtx * ctx ,
177- const void * src , size_t srcSize ,
178- const U32 mls )
181+ static size_t ZSTD_compressBlock_doubleFast_extDict_generic (
182+ ZSTD_matchState_t * ms , seqStore_t * seqStore , U32 rep [ZSTD_REP_NUM ],
183+ ZSTD_compressionParameters const * cParams , void const * src , size_t srcSize ,
184+ U32 const mls /* template */ )
179185{
180- U32 * const hashLong = ctx -> hashTable ;
181- U32 const hBitsL = ctx -> appliedParams .cParams .hashLog ;
182- U32 * const hashSmall = ctx -> chainTable ;
183- U32 const hBitsS = ctx -> appliedParams .cParams .chainLog ;
184- seqStore_t * seqStorePtr = & (ctx -> seqStore );
185- const BYTE * const base = ctx -> base ;
186- const BYTE * const dictBase = ctx -> dictBase ;
186+ U32 * const hashLong = ms -> hashTable ;
187+ U32 const hBitsL = cParams -> hashLog ;
188+ U32 * const hashSmall = ms -> chainTable ;
189+ U32 const hBitsS = cParams -> chainLog ;
190+ const BYTE * const base = ms -> base ;
191+ const BYTE * const dictBase = ms -> dictBase ;
187192 const BYTE * const istart = (const BYTE * )src ;
188193 const BYTE * ip = istart ;
189194 const BYTE * anchor = istart ;
190- const U32 lowestIndex = ctx -> lowLimit ;
195+ const U32 lowestIndex = ms -> lowLimit ;
191196 const BYTE * const dictStart = dictBase + lowestIndex ;
192- const U32 dictLimit = ctx -> dictLimit ;
197+ const U32 dictLimit = ms -> dictLimit ;
193198 const BYTE * const lowPrefixPtr = base + dictLimit ;
194199 const BYTE * const dictEnd = dictBase + dictLimit ;
195200 const BYTE * const iend = istart + srcSize ;
196201 const BYTE * const ilimit = iend - 8 ;
197- U32 offset_1 = seqStorePtr -> rep [0 ], offset_2 = seqStorePtr -> rep [1 ];
202+ U32 offset_1 = rep [0 ], offset_2 = rep [1 ];
198203
199204 /* Search Loop */
200205 while (ip < ilimit ) { /* < instead of <=, because (ip+1) */
@@ -220,7 +225,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(ZSTD_CCtx* ctx,
220225 const BYTE * repMatchEnd = repIndex < dictLimit ? dictEnd : iend ;
221226 mLength = ZSTD_count_2segments (ip + 1 + 4 , repMatch + 4 , iend , repMatchEnd , lowPrefixPtr ) + 4 ;
222227 ip ++ ;
223- ZSTD_storeSeq (seqStorePtr , ip - anchor , anchor , 0 , mLength - MINMATCH );
228+ ZSTD_storeSeq (seqStore , ip - anchor , anchor , 0 , mLength - MINMATCH );
224229 } else {
225230 if ((matchLongIndex > lowestIndex ) && (MEM_read64 (matchLong ) == MEM_read64 (ip ))) {
226231 const BYTE * matchEnd = matchLongIndex < dictLimit ? dictEnd : iend ;
@@ -231,7 +236,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(ZSTD_CCtx* ctx,
231236 while (((ip > anchor ) & (matchLong > lowMatchPtr )) && (ip [-1 ] == matchLong [-1 ])) { ip -- ; matchLong -- ; mLength ++ ; } /* catch up */
232237 offset_2 = offset_1 ;
233238 offset_1 = offset ;
234- ZSTD_storeSeq (seqStorePtr , ip - anchor , anchor , offset + ZSTD_REP_MOVE , mLength - MINMATCH );
239+ ZSTD_storeSeq (seqStore , ip - anchor , anchor , offset + ZSTD_REP_MOVE , mLength - MINMATCH );
235240
236241 } else if ((matchIndex > lowestIndex ) && (MEM_read32 (match ) == MEM_read32 (ip ))) {
237242 size_t const h3 = ZSTD_hashPtr (ip + 1 , hBitsL , 8 );
@@ -256,7 +261,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(ZSTD_CCtx* ctx,
256261 }
257262 offset_2 = offset_1 ;
258263 offset_1 = offset ;
259- ZSTD_storeSeq (seqStorePtr , ip - anchor , anchor , offset + ZSTD_REP_MOVE , mLength - MINMATCH );
264+ ZSTD_storeSeq (seqStore , ip - anchor , anchor , offset + ZSTD_REP_MOVE , mLength - MINMATCH );
260265
261266 } else {
262267 ip += ((ip - anchor ) >> g_searchStrength ) + 1 ;
@@ -283,7 +288,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(ZSTD_CCtx* ctx,
283288 const BYTE * const repEnd2 = repIndex2 < dictLimit ? dictEnd : iend ;
284289 size_t const repLength2 = ZSTD_count_2segments (ip + 4 , repMatch2 + 4 , iend , repEnd2 , lowPrefixPtr ) + 4 ;
285290 U32 tmpOffset = offset_2 ; offset_2 = offset_1 ; offset_1 = tmpOffset ; /* swap offset_2 <=> offset_1 */
286- ZSTD_storeSeq (seqStorePtr , 0 , anchor , 0 , repLength2 - MINMATCH );
291+ ZSTD_storeSeq (seqStore , 0 , anchor , 0 , repLength2 - MINMATCH );
287292 hashSmall [ZSTD_hashPtr (ip , hBitsS , mls )] = current2 ;
288293 hashLong [ZSTD_hashPtr (ip , hBitsL , 8 )] = current2 ;
289294 ip += repLength2 ;
@@ -294,27 +299,29 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(ZSTD_CCtx* ctx,
294299 } } }
295300
296301 /* save reps for next block */
297- seqStorePtr -> repToConfirm [0 ] = offset_1 ; seqStorePtr -> repToConfirm [1 ] = offset_2 ;
302+ rep [0 ] = offset_1 ;
303+ rep [1 ] = offset_2 ;
298304
299305 /* Return the last literals size */
300306 return iend - anchor ;
301307}
302308
303309
304- size_t ZSTD_compressBlock_doubleFast_extDict (ZSTD_CCtx * ctx ,
305- const void * src , size_t srcSize )
310+ size_t ZSTD_compressBlock_doubleFast_extDict (
311+ ZSTD_matchState_t * ms , seqStore_t * seqStore , U32 rep [ZSTD_REP_NUM ],
312+ ZSTD_compressionParameters const * cParams , void const * src , size_t srcSize )
306313{
307- U32 const mls = ctx -> appliedParams . cParams . searchLength ;
314+ U32 const mls = cParams -> searchLength ;
308315 switch (mls )
309316 {
310317 default : /* includes case 3 */
311318 case 4 :
312- return ZSTD_compressBlock_doubleFast_extDict_generic (ctx , src , srcSize , 4 );
319+ return ZSTD_compressBlock_doubleFast_extDict_generic (ms , seqStore , rep , cParams , src , srcSize , 4 );
313320 case 5 :
314- return ZSTD_compressBlock_doubleFast_extDict_generic (ctx , src , srcSize , 5 );
321+ return ZSTD_compressBlock_doubleFast_extDict_generic (ms , seqStore , rep , cParams , src , srcSize , 5 );
315322 case 6 :
316- return ZSTD_compressBlock_doubleFast_extDict_generic (ctx , src , srcSize , 6 );
323+ return ZSTD_compressBlock_doubleFast_extDict_generic (ms , seqStore , rep , cParams , src , srcSize , 6 );
317324 case 7 :
318- return ZSTD_compressBlock_doubleFast_extDict_generic (ctx , src , srcSize , 7 );
325+ return ZSTD_compressBlock_doubleFast_extDict_generic (ms , seqStore , rep , cParams , src , srcSize , 7 );
319326 }
320327}
0 commit comments