zstd-ruby 1.3.7.0 → 1.3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/zstdruby/libzstd/BUCK +15 -2
- data/ext/zstdruby/libzstd/Makefile +37 -2
- data/ext/zstdruby/libzstd/README.md +67 -41
- data/ext/zstdruby/libzstd/common/bitstream.h +2 -2
- data/ext/zstdruby/libzstd/common/compiler.h +19 -12
- data/ext/zstdruby/libzstd/common/cpu.h +1 -1
- data/ext/zstdruby/libzstd/common/debug.h +22 -11
- data/ext/zstdruby/libzstd/common/error_private.c +6 -0
- data/ext/zstdruby/libzstd/common/fse.h +2 -2
- data/ext/zstdruby/libzstd/common/huf.h +25 -1
- data/ext/zstdruby/libzstd/common/pool.c +1 -1
- data/ext/zstdruby/libzstd/common/zstd_common.c +3 -1
- data/ext/zstdruby/libzstd/common/zstd_errors.h +1 -0
- data/ext/zstdruby/libzstd/common/zstd_internal.h +11 -2
- data/ext/zstdruby/libzstd/compress/fse_compress.c +3 -3
- data/ext/zstdruby/libzstd/compress/hist.c +19 -11
- data/ext/zstdruby/libzstd/compress/hist.h +11 -8
- data/ext/zstdruby/libzstd/compress/huf_compress.c +33 -31
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +621 -371
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +90 -28
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +4 -4
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +15 -15
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +25 -18
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +18 -67
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +2 -6
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +133 -48
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +8 -0
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +229 -73
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +18 -10
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +178 -42
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +240 -0
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +44 -0
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +244 -1680
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +1307 -0
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +59 -0
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +168 -0
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +13 -11
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +15 -15
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +28 -28
- data/ext/zstdruby/libzstd/dll/libzstd.def +0 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +0 -10
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +15 -15
- data/ext/zstdruby/libzstd/zstd.h +1208 -968
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +7 -2
@@ -11,6 +11,7 @@
|
|
11
11
|
/*-*************************************
|
12
12
|
* Dependencies
|
13
13
|
***************************************/
|
14
|
+
#include <limits.h> /* INT_MAX */
|
14
15
|
#include <string.h> /* memset */
|
15
16
|
#include "cpu.h"
|
16
17
|
#include "mem.h"
|
@@ -61,7 +62,7 @@ static void ZSTD_initCCtx(ZSTD_CCtx* cctx, ZSTD_customMem memManager)
|
|
61
62
|
memset(cctx, 0, sizeof(*cctx));
|
62
63
|
cctx->customMem = memManager;
|
63
64
|
cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
|
64
|
-
{ size_t const err =
|
65
|
+
{ size_t const err = ZSTD_CCtx_reset(cctx, ZSTD_reset_parameters);
|
65
66
|
assert(!ZSTD_isError(err));
|
66
67
|
(void)err;
|
67
68
|
}
|
@@ -128,7 +129,7 @@ static size_t ZSTD_sizeof_mtctx(const ZSTD_CCtx* cctx)
|
|
128
129
|
#ifdef ZSTD_MULTITHREAD
|
129
130
|
return ZSTDMT_sizeof_CCtx(cctx->mtctx);
|
130
131
|
#else
|
131
|
-
(void)
|
132
|
+
(void)cctx;
|
132
133
|
return 0;
|
133
134
|
#endif
|
134
135
|
}
|
@@ -226,9 +227,160 @@ static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams(
|
|
226
227
|
return ret;
|
227
228
|
}
|
228
229
|
|
229
|
-
|
230
|
-
|
231
|
-
|
230
|
+
ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param)
|
231
|
+
{
|
232
|
+
ZSTD_bounds bounds = { 0, 0, 0 };
|
233
|
+
|
234
|
+
switch(param)
|
235
|
+
{
|
236
|
+
case ZSTD_c_compressionLevel:
|
237
|
+
bounds.lowerBound = ZSTD_minCLevel();
|
238
|
+
bounds.upperBound = ZSTD_maxCLevel();
|
239
|
+
return bounds;
|
240
|
+
|
241
|
+
case ZSTD_c_windowLog:
|
242
|
+
bounds.lowerBound = ZSTD_WINDOWLOG_MIN;
|
243
|
+
bounds.upperBound = ZSTD_WINDOWLOG_MAX;
|
244
|
+
return bounds;
|
245
|
+
|
246
|
+
case ZSTD_c_hashLog:
|
247
|
+
bounds.lowerBound = ZSTD_HASHLOG_MIN;
|
248
|
+
bounds.upperBound = ZSTD_HASHLOG_MAX;
|
249
|
+
return bounds;
|
250
|
+
|
251
|
+
case ZSTD_c_chainLog:
|
252
|
+
bounds.lowerBound = ZSTD_CHAINLOG_MIN;
|
253
|
+
bounds.upperBound = ZSTD_CHAINLOG_MAX;
|
254
|
+
return bounds;
|
255
|
+
|
256
|
+
case ZSTD_c_searchLog:
|
257
|
+
bounds.lowerBound = ZSTD_SEARCHLOG_MIN;
|
258
|
+
bounds.upperBound = ZSTD_SEARCHLOG_MAX;
|
259
|
+
return bounds;
|
260
|
+
|
261
|
+
case ZSTD_c_minMatch:
|
262
|
+
bounds.lowerBound = ZSTD_MINMATCH_MIN;
|
263
|
+
bounds.upperBound = ZSTD_MINMATCH_MAX;
|
264
|
+
return bounds;
|
265
|
+
|
266
|
+
case ZSTD_c_targetLength:
|
267
|
+
bounds.lowerBound = ZSTD_TARGETLENGTH_MIN;
|
268
|
+
bounds.upperBound = ZSTD_TARGETLENGTH_MAX;
|
269
|
+
return bounds;
|
270
|
+
|
271
|
+
case ZSTD_c_strategy:
|
272
|
+
bounds.lowerBound = ZSTD_STRATEGY_MIN;
|
273
|
+
bounds.upperBound = ZSTD_STRATEGY_MAX;
|
274
|
+
return bounds;
|
275
|
+
|
276
|
+
case ZSTD_c_contentSizeFlag:
|
277
|
+
bounds.lowerBound = 0;
|
278
|
+
bounds.upperBound = 1;
|
279
|
+
return bounds;
|
280
|
+
|
281
|
+
case ZSTD_c_checksumFlag:
|
282
|
+
bounds.lowerBound = 0;
|
283
|
+
bounds.upperBound = 1;
|
284
|
+
return bounds;
|
285
|
+
|
286
|
+
case ZSTD_c_dictIDFlag:
|
287
|
+
bounds.lowerBound = 0;
|
288
|
+
bounds.upperBound = 1;
|
289
|
+
return bounds;
|
290
|
+
|
291
|
+
case ZSTD_c_nbWorkers:
|
292
|
+
bounds.lowerBound = 0;
|
293
|
+
#ifdef ZSTD_MULTITHREAD
|
294
|
+
bounds.upperBound = ZSTDMT_NBWORKERS_MAX;
|
295
|
+
#else
|
296
|
+
bounds.upperBound = 0;
|
297
|
+
#endif
|
298
|
+
return bounds;
|
299
|
+
|
300
|
+
case ZSTD_c_jobSize:
|
301
|
+
bounds.lowerBound = 0;
|
302
|
+
#ifdef ZSTD_MULTITHREAD
|
303
|
+
bounds.upperBound = ZSTDMT_JOBSIZE_MAX;
|
304
|
+
#else
|
305
|
+
bounds.upperBound = 0;
|
306
|
+
#endif
|
307
|
+
return bounds;
|
308
|
+
|
309
|
+
case ZSTD_c_overlapLog:
|
310
|
+
bounds.lowerBound = ZSTD_OVERLAPLOG_MIN;
|
311
|
+
bounds.upperBound = ZSTD_OVERLAPLOG_MAX;
|
312
|
+
return bounds;
|
313
|
+
|
314
|
+
case ZSTD_c_enableLongDistanceMatching:
|
315
|
+
bounds.lowerBound = 0;
|
316
|
+
bounds.upperBound = 1;
|
317
|
+
return bounds;
|
318
|
+
|
319
|
+
case ZSTD_c_ldmHashLog:
|
320
|
+
bounds.lowerBound = ZSTD_LDM_HASHLOG_MIN;
|
321
|
+
bounds.upperBound = ZSTD_LDM_HASHLOG_MAX;
|
322
|
+
return bounds;
|
323
|
+
|
324
|
+
case ZSTD_c_ldmMinMatch:
|
325
|
+
bounds.lowerBound = ZSTD_LDM_MINMATCH_MIN;
|
326
|
+
bounds.upperBound = ZSTD_LDM_MINMATCH_MAX;
|
327
|
+
return bounds;
|
328
|
+
|
329
|
+
case ZSTD_c_ldmBucketSizeLog:
|
330
|
+
bounds.lowerBound = ZSTD_LDM_BUCKETSIZELOG_MIN;
|
331
|
+
bounds.upperBound = ZSTD_LDM_BUCKETSIZELOG_MAX;
|
332
|
+
return bounds;
|
333
|
+
|
334
|
+
case ZSTD_c_ldmHashRateLog:
|
335
|
+
bounds.lowerBound = ZSTD_LDM_HASHRATELOG_MIN;
|
336
|
+
bounds.upperBound = ZSTD_LDM_HASHRATELOG_MAX;
|
337
|
+
return bounds;
|
338
|
+
|
339
|
+
/* experimental parameters */
|
340
|
+
case ZSTD_c_rsyncable:
|
341
|
+
bounds.lowerBound = 0;
|
342
|
+
bounds.upperBound = 1;
|
343
|
+
return bounds;
|
344
|
+
|
345
|
+
case ZSTD_c_forceMaxWindow :
|
346
|
+
bounds.lowerBound = 0;
|
347
|
+
bounds.upperBound = 1;
|
348
|
+
return bounds;
|
349
|
+
|
350
|
+
case ZSTD_c_format:
|
351
|
+
ZSTD_STATIC_ASSERT(ZSTD_f_zstd1 < ZSTD_f_zstd1_magicless);
|
352
|
+
bounds.lowerBound = ZSTD_f_zstd1;
|
353
|
+
bounds.upperBound = ZSTD_f_zstd1_magicless; /* note : how to ensure at compile time that this is the highest value enum ? */
|
354
|
+
return bounds;
|
355
|
+
|
356
|
+
case ZSTD_c_forceAttachDict:
|
357
|
+
ZSTD_STATIC_ASSERT(ZSTD_dictDefaultAttach < ZSTD_dictForceCopy);
|
358
|
+
bounds.lowerBound = ZSTD_dictDefaultAttach;
|
359
|
+
bounds.upperBound = ZSTD_dictForceCopy; /* note : how to ensure at compile time that this is the highest value enum ? */
|
360
|
+
return bounds;
|
361
|
+
|
362
|
+
default:
|
363
|
+
{ ZSTD_bounds const boundError = { ERROR(parameter_unsupported), 0, 0 };
|
364
|
+
return boundError;
|
365
|
+
}
|
366
|
+
}
|
367
|
+
}
|
368
|
+
|
369
|
+
/* ZSTD_cParam_withinBounds:
|
370
|
+
* @return 1 if value is within cParam bounds,
|
371
|
+
* 0 otherwise */
|
372
|
+
static int ZSTD_cParam_withinBounds(ZSTD_cParameter cParam, int value)
|
373
|
+
{
|
374
|
+
ZSTD_bounds const bounds = ZSTD_cParam_getBounds(cParam);
|
375
|
+
if (ZSTD_isError(bounds.error)) return 0;
|
376
|
+
if (value < bounds.lowerBound) return 0;
|
377
|
+
if (value > bounds.upperBound) return 0;
|
378
|
+
return 1;
|
379
|
+
}
|
380
|
+
|
381
|
+
#define BOUNDCHECK(cParam, val) { \
|
382
|
+
if (!ZSTD_cParam_withinBounds(cParam,val)) { \
|
383
|
+
return ERROR(parameter_outOfBound); \
|
232
384
|
} }
|
233
385
|
|
234
386
|
|
@@ -236,38 +388,39 @@ static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
|
|
236
388
|
{
|
237
389
|
switch(param)
|
238
390
|
{
|
239
|
-
case
|
240
|
-
case
|
241
|
-
case
|
242
|
-
case
|
243
|
-
case
|
244
|
-
case
|
245
|
-
case
|
391
|
+
case ZSTD_c_compressionLevel:
|
392
|
+
case ZSTD_c_hashLog:
|
393
|
+
case ZSTD_c_chainLog:
|
394
|
+
case ZSTD_c_searchLog:
|
395
|
+
case ZSTD_c_minMatch:
|
396
|
+
case ZSTD_c_targetLength:
|
397
|
+
case ZSTD_c_strategy:
|
246
398
|
return 1;
|
247
399
|
|
248
|
-
case
|
249
|
-
case
|
250
|
-
case
|
251
|
-
case
|
252
|
-
case
|
253
|
-
case
|
254
|
-
case
|
255
|
-
case
|
256
|
-
case
|
257
|
-
case
|
258
|
-
case
|
259
|
-
case
|
260
|
-
case
|
261
|
-
case
|
262
|
-
case
|
400
|
+
case ZSTD_c_format:
|
401
|
+
case ZSTD_c_windowLog:
|
402
|
+
case ZSTD_c_contentSizeFlag:
|
403
|
+
case ZSTD_c_checksumFlag:
|
404
|
+
case ZSTD_c_dictIDFlag:
|
405
|
+
case ZSTD_c_forceMaxWindow :
|
406
|
+
case ZSTD_c_nbWorkers:
|
407
|
+
case ZSTD_c_jobSize:
|
408
|
+
case ZSTD_c_overlapLog:
|
409
|
+
case ZSTD_c_rsyncable:
|
410
|
+
case ZSTD_c_enableLongDistanceMatching:
|
411
|
+
case ZSTD_c_ldmHashLog:
|
412
|
+
case ZSTD_c_ldmMinMatch:
|
413
|
+
case ZSTD_c_ldmBucketSizeLog:
|
414
|
+
case ZSTD_c_ldmHashRateLog:
|
415
|
+
case ZSTD_c_forceAttachDict:
|
263
416
|
default:
|
264
417
|
return 0;
|
265
418
|
}
|
266
419
|
}
|
267
420
|
|
268
|
-
size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param,
|
421
|
+
size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
|
269
422
|
{
|
270
|
-
DEBUGLOG(4, "ZSTD_CCtx_setParameter (%
|
423
|
+
DEBUGLOG(4, "ZSTD_CCtx_setParameter (%i, %i)", (int)param, value);
|
271
424
|
if (cctx->streamStage != zcss_init) {
|
272
425
|
if (ZSTD_isUpdateAuthorized(param)) {
|
273
426
|
cctx->cParamsChanged = 1;
|
@@ -277,51 +430,52 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned v
|
|
277
430
|
|
278
431
|
switch(param)
|
279
432
|
{
|
280
|
-
case
|
433
|
+
case ZSTD_c_format :
|
281
434
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
282
435
|
|
283
|
-
case
|
436
|
+
case ZSTD_c_compressionLevel:
|
284
437
|
if (cctx->cdict) return ERROR(stage_wrong);
|
285
438
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
286
439
|
|
287
|
-
case
|
288
|
-
case
|
289
|
-
case
|
290
|
-
case
|
291
|
-
case
|
292
|
-
case
|
293
|
-
case
|
440
|
+
case ZSTD_c_windowLog:
|
441
|
+
case ZSTD_c_hashLog:
|
442
|
+
case ZSTD_c_chainLog:
|
443
|
+
case ZSTD_c_searchLog:
|
444
|
+
case ZSTD_c_minMatch:
|
445
|
+
case ZSTD_c_targetLength:
|
446
|
+
case ZSTD_c_strategy:
|
294
447
|
if (cctx->cdict) return ERROR(stage_wrong);
|
295
448
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
296
449
|
|
297
|
-
case
|
298
|
-
case
|
299
|
-
case
|
450
|
+
case ZSTD_c_contentSizeFlag:
|
451
|
+
case ZSTD_c_checksumFlag:
|
452
|
+
case ZSTD_c_dictIDFlag:
|
300
453
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
301
454
|
|
302
|
-
case
|
455
|
+
case ZSTD_c_forceMaxWindow : /* Force back-references to remain < windowSize,
|
303
456
|
* even when referencing into Dictionary content.
|
304
457
|
* default : 0 when using a CDict, 1 when using a Prefix */
|
305
458
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
306
459
|
|
307
|
-
case
|
460
|
+
case ZSTD_c_forceAttachDict:
|
308
461
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
309
462
|
|
310
|
-
case
|
311
|
-
if ((value
|
463
|
+
case ZSTD_c_nbWorkers:
|
464
|
+
if ((value!=0) && cctx->staticSize) {
|
312
465
|
return ERROR(parameter_unsupported); /* MT not compatible with static alloc */
|
313
466
|
}
|
314
467
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
315
468
|
|
316
|
-
case
|
317
|
-
case
|
469
|
+
case ZSTD_c_jobSize:
|
470
|
+
case ZSTD_c_overlapLog:
|
471
|
+
case ZSTD_c_rsyncable:
|
318
472
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
319
473
|
|
320
|
-
case
|
321
|
-
case
|
322
|
-
case
|
323
|
-
case
|
324
|
-
case
|
474
|
+
case ZSTD_c_enableLongDistanceMatching:
|
475
|
+
case ZSTD_c_ldmHashLog:
|
476
|
+
case ZSTD_c_ldmMinMatch:
|
477
|
+
case ZSTD_c_ldmBucketSizeLog:
|
478
|
+
case ZSTD_c_ldmHashRateLog:
|
325
479
|
if (cctx->cdict) return ERROR(stage_wrong);
|
326
480
|
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
|
327
481
|
|
@@ -329,21 +483,21 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned v
|
|
329
483
|
}
|
330
484
|
}
|
331
485
|
|
332
|
-
size_t ZSTD_CCtxParam_setParameter(
|
333
|
-
|
486
|
+
size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* CCtxParams,
|
487
|
+
ZSTD_cParameter param, int value)
|
334
488
|
{
|
335
|
-
DEBUGLOG(4, "ZSTD_CCtxParam_setParameter (%
|
489
|
+
DEBUGLOG(4, "ZSTD_CCtxParam_setParameter (%i, %i)", (int)param, value);
|
336
490
|
switch(param)
|
337
491
|
{
|
338
|
-
case
|
339
|
-
|
340
|
-
return ERROR(parameter_unsupported);
|
492
|
+
case ZSTD_c_format :
|
493
|
+
BOUNDCHECK(ZSTD_c_format, value);
|
341
494
|
CCtxParams->format = (ZSTD_format_e)value;
|
342
495
|
return (size_t)CCtxParams->format;
|
343
496
|
|
344
|
-
case
|
345
|
-
int cLevel =
|
497
|
+
case ZSTD_c_compressionLevel : {
|
498
|
+
int cLevel = value;
|
346
499
|
if (cLevel > ZSTD_maxCLevel()) cLevel = ZSTD_maxCLevel();
|
500
|
+
if (cLevel < ZSTD_minCLevel()) cLevel = ZSTD_minCLevel();
|
347
501
|
if (cLevel) { /* 0 : does not change current level */
|
348
502
|
CCtxParams->compressionLevel = cLevel;
|
349
503
|
}
|
@@ -351,213 +505,229 @@ size_t ZSTD_CCtxParam_setParameter(
|
|
351
505
|
return 0; /* return type (size_t) cannot represent negative values */
|
352
506
|
}
|
353
507
|
|
354
|
-
case
|
355
|
-
if (value
|
356
|
-
|
508
|
+
case ZSTD_c_windowLog :
|
509
|
+
if (value!=0) /* 0 => use default */
|
510
|
+
BOUNDCHECK(ZSTD_c_windowLog, value);
|
357
511
|
CCtxParams->cParams.windowLog = value;
|
358
512
|
return CCtxParams->cParams.windowLog;
|
359
513
|
|
360
|
-
case
|
361
|
-
if (value
|
362
|
-
|
514
|
+
case ZSTD_c_hashLog :
|
515
|
+
if (value!=0) /* 0 => use default */
|
516
|
+
BOUNDCHECK(ZSTD_c_hashLog, value);
|
363
517
|
CCtxParams->cParams.hashLog = value;
|
364
518
|
return CCtxParams->cParams.hashLog;
|
365
519
|
|
366
|
-
case
|
367
|
-
if (value
|
368
|
-
|
520
|
+
case ZSTD_c_chainLog :
|
521
|
+
if (value!=0) /* 0 => use default */
|
522
|
+
BOUNDCHECK(ZSTD_c_chainLog, value);
|
369
523
|
CCtxParams->cParams.chainLog = value;
|
370
524
|
return CCtxParams->cParams.chainLog;
|
371
525
|
|
372
|
-
case
|
373
|
-
if (value
|
374
|
-
|
526
|
+
case ZSTD_c_searchLog :
|
527
|
+
if (value!=0) /* 0 => use default */
|
528
|
+
BOUNDCHECK(ZSTD_c_searchLog, value);
|
375
529
|
CCtxParams->cParams.searchLog = value;
|
376
530
|
return value;
|
377
531
|
|
378
|
-
case
|
379
|
-
if (value
|
380
|
-
|
381
|
-
CCtxParams->cParams.
|
382
|
-
return CCtxParams->cParams.
|
532
|
+
case ZSTD_c_minMatch :
|
533
|
+
if (value!=0) /* 0 => use default */
|
534
|
+
BOUNDCHECK(ZSTD_c_minMatch, value);
|
535
|
+
CCtxParams->cParams.minMatch = value;
|
536
|
+
return CCtxParams->cParams.minMatch;
|
383
537
|
|
384
|
-
case
|
385
|
-
|
538
|
+
case ZSTD_c_targetLength :
|
539
|
+
BOUNDCHECK(ZSTD_c_targetLength, value);
|
386
540
|
CCtxParams->cParams.targetLength = value;
|
387
541
|
return CCtxParams->cParams.targetLength;
|
388
542
|
|
389
|
-
case
|
390
|
-
if (value
|
391
|
-
|
543
|
+
case ZSTD_c_strategy :
|
544
|
+
if (value!=0) /* 0 => use default */
|
545
|
+
BOUNDCHECK(ZSTD_c_strategy, value);
|
392
546
|
CCtxParams->cParams.strategy = (ZSTD_strategy)value;
|
393
547
|
return (size_t)CCtxParams->cParams.strategy;
|
394
548
|
|
395
|
-
case
|
549
|
+
case ZSTD_c_contentSizeFlag :
|
396
550
|
/* Content size written in frame header _when known_ (default:1) */
|
397
|
-
DEBUGLOG(4, "set content size flag = %u", (value
|
398
|
-
CCtxParams->fParams.contentSizeFlag = value
|
551
|
+
DEBUGLOG(4, "set content size flag = %u", (value!=0));
|
552
|
+
CCtxParams->fParams.contentSizeFlag = value != 0;
|
399
553
|
return CCtxParams->fParams.contentSizeFlag;
|
400
554
|
|
401
|
-
case
|
555
|
+
case ZSTD_c_checksumFlag :
|
402
556
|
/* A 32-bits content checksum will be calculated and written at end of frame (default:0) */
|
403
|
-
CCtxParams->fParams.checksumFlag = value
|
557
|
+
CCtxParams->fParams.checksumFlag = value != 0;
|
404
558
|
return CCtxParams->fParams.checksumFlag;
|
405
559
|
|
406
|
-
case
|
407
|
-
DEBUGLOG(4, "set dictIDFlag = %u", (value
|
560
|
+
case ZSTD_c_dictIDFlag : /* When applicable, dictionary's dictID is provided in frame header (default:1) */
|
561
|
+
DEBUGLOG(4, "set dictIDFlag = %u", (value!=0));
|
408
562
|
CCtxParams->fParams.noDictIDFlag = !value;
|
409
563
|
return !CCtxParams->fParams.noDictIDFlag;
|
410
564
|
|
411
|
-
case
|
412
|
-
CCtxParams->forceWindow = (value
|
565
|
+
case ZSTD_c_forceMaxWindow :
|
566
|
+
CCtxParams->forceWindow = (value != 0);
|
413
567
|
return CCtxParams->forceWindow;
|
414
568
|
|
415
|
-
case
|
416
|
-
|
417
|
-
|
418
|
-
|
569
|
+
case ZSTD_c_forceAttachDict : {
|
570
|
+
const ZSTD_dictAttachPref_e pref = (ZSTD_dictAttachPref_e)value;
|
571
|
+
BOUNDCHECK(ZSTD_c_forceAttachDict, pref);
|
572
|
+
CCtxParams->attachDictPref = pref;
|
419
573
|
return CCtxParams->attachDictPref;
|
574
|
+
}
|
420
575
|
|
421
|
-
case
|
576
|
+
case ZSTD_c_nbWorkers :
|
422
577
|
#ifndef ZSTD_MULTITHREAD
|
423
|
-
if (value
|
578
|
+
if (value!=0) return ERROR(parameter_unsupported);
|
424
579
|
return 0;
|
425
580
|
#else
|
426
581
|
return ZSTDMT_CCtxParam_setNbWorkers(CCtxParams, value);
|
427
582
|
#endif
|
428
583
|
|
429
|
-
case
|
584
|
+
case ZSTD_c_jobSize :
|
430
585
|
#ifndef ZSTD_MULTITHREAD
|
431
586
|
return ERROR(parameter_unsupported);
|
432
587
|
#else
|
433
588
|
return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_jobSize, value);
|
434
589
|
#endif
|
435
590
|
|
436
|
-
case
|
591
|
+
case ZSTD_c_overlapLog :
|
437
592
|
#ifndef ZSTD_MULTITHREAD
|
438
593
|
return ERROR(parameter_unsupported);
|
439
594
|
#else
|
440
|
-
return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams,
|
595
|
+
return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_overlapLog, value);
|
441
596
|
#endif
|
442
597
|
|
443
|
-
case
|
444
|
-
|
598
|
+
case ZSTD_c_rsyncable :
|
599
|
+
#ifndef ZSTD_MULTITHREAD
|
600
|
+
return ERROR(parameter_unsupported);
|
601
|
+
#else
|
602
|
+
return ZSTDMT_CCtxParam_setMTCtxParameter(CCtxParams, ZSTDMT_p_rsyncable, value);
|
603
|
+
#endif
|
604
|
+
|
605
|
+
case ZSTD_c_enableLongDistanceMatching :
|
606
|
+
CCtxParams->ldmParams.enableLdm = (value!=0);
|
445
607
|
return CCtxParams->ldmParams.enableLdm;
|
446
608
|
|
447
|
-
case
|
448
|
-
if (value
|
449
|
-
|
609
|
+
case ZSTD_c_ldmHashLog :
|
610
|
+
if (value!=0) /* 0 ==> auto */
|
611
|
+
BOUNDCHECK(ZSTD_c_ldmHashLog, value);
|
450
612
|
CCtxParams->ldmParams.hashLog = value;
|
451
613
|
return CCtxParams->ldmParams.hashLog;
|
452
614
|
|
453
|
-
case
|
454
|
-
if (value
|
455
|
-
|
615
|
+
case ZSTD_c_ldmMinMatch :
|
616
|
+
if (value!=0) /* 0 ==> default */
|
617
|
+
BOUNDCHECK(ZSTD_c_ldmMinMatch, value);
|
456
618
|
CCtxParams->ldmParams.minMatchLength = value;
|
457
619
|
return CCtxParams->ldmParams.minMatchLength;
|
458
620
|
|
459
|
-
case
|
460
|
-
if (value
|
461
|
-
|
621
|
+
case ZSTD_c_ldmBucketSizeLog :
|
622
|
+
if (value!=0) /* 0 ==> default */
|
623
|
+
BOUNDCHECK(ZSTD_c_ldmBucketSizeLog, value);
|
462
624
|
CCtxParams->ldmParams.bucketSizeLog = value;
|
463
625
|
return CCtxParams->ldmParams.bucketSizeLog;
|
464
626
|
|
465
|
-
case
|
627
|
+
case ZSTD_c_ldmHashRateLog :
|
466
628
|
if (value > ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
|
467
629
|
return ERROR(parameter_outOfBound);
|
468
|
-
CCtxParams->ldmParams.
|
469
|
-
return CCtxParams->ldmParams.
|
630
|
+
CCtxParams->ldmParams.hashRateLog = value;
|
631
|
+
return CCtxParams->ldmParams.hashRateLog;
|
470
632
|
|
471
633
|
default: return ERROR(parameter_unsupported);
|
472
634
|
}
|
473
635
|
}
|
474
636
|
|
475
|
-
size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param,
|
637
|
+
size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int* value)
|
476
638
|
{
|
477
639
|
return ZSTD_CCtxParam_getParameter(&cctx->requestedParams, param, value);
|
478
640
|
}
|
479
641
|
|
480
642
|
size_t ZSTD_CCtxParam_getParameter(
|
481
|
-
ZSTD_CCtx_params* CCtxParams, ZSTD_cParameter param,
|
643
|
+
ZSTD_CCtx_params* CCtxParams, ZSTD_cParameter param, int* value)
|
482
644
|
{
|
483
645
|
switch(param)
|
484
646
|
{
|
485
|
-
case
|
647
|
+
case ZSTD_c_format :
|
486
648
|
*value = CCtxParams->format;
|
487
649
|
break;
|
488
|
-
case
|
650
|
+
case ZSTD_c_compressionLevel :
|
489
651
|
*value = CCtxParams->compressionLevel;
|
490
652
|
break;
|
491
|
-
case
|
653
|
+
case ZSTD_c_windowLog :
|
492
654
|
*value = CCtxParams->cParams.windowLog;
|
493
655
|
break;
|
494
|
-
case
|
656
|
+
case ZSTD_c_hashLog :
|
495
657
|
*value = CCtxParams->cParams.hashLog;
|
496
658
|
break;
|
497
|
-
case
|
659
|
+
case ZSTD_c_chainLog :
|
498
660
|
*value = CCtxParams->cParams.chainLog;
|
499
661
|
break;
|
500
|
-
case
|
662
|
+
case ZSTD_c_searchLog :
|
501
663
|
*value = CCtxParams->cParams.searchLog;
|
502
664
|
break;
|
503
|
-
case
|
504
|
-
*value = CCtxParams->cParams.
|
665
|
+
case ZSTD_c_minMatch :
|
666
|
+
*value = CCtxParams->cParams.minMatch;
|
505
667
|
break;
|
506
|
-
case
|
668
|
+
case ZSTD_c_targetLength :
|
507
669
|
*value = CCtxParams->cParams.targetLength;
|
508
670
|
break;
|
509
|
-
case
|
671
|
+
case ZSTD_c_strategy :
|
510
672
|
*value = (unsigned)CCtxParams->cParams.strategy;
|
511
673
|
break;
|
512
|
-
case
|
674
|
+
case ZSTD_c_contentSizeFlag :
|
513
675
|
*value = CCtxParams->fParams.contentSizeFlag;
|
514
676
|
break;
|
515
|
-
case
|
677
|
+
case ZSTD_c_checksumFlag :
|
516
678
|
*value = CCtxParams->fParams.checksumFlag;
|
517
679
|
break;
|
518
|
-
case
|
680
|
+
case ZSTD_c_dictIDFlag :
|
519
681
|
*value = !CCtxParams->fParams.noDictIDFlag;
|
520
682
|
break;
|
521
|
-
case
|
683
|
+
case ZSTD_c_forceMaxWindow :
|
522
684
|
*value = CCtxParams->forceWindow;
|
523
685
|
break;
|
524
|
-
case
|
686
|
+
case ZSTD_c_forceAttachDict :
|
525
687
|
*value = CCtxParams->attachDictPref;
|
526
688
|
break;
|
527
|
-
case
|
689
|
+
case ZSTD_c_nbWorkers :
|
528
690
|
#ifndef ZSTD_MULTITHREAD
|
529
691
|
assert(CCtxParams->nbWorkers == 0);
|
530
692
|
#endif
|
531
693
|
*value = CCtxParams->nbWorkers;
|
532
694
|
break;
|
533
|
-
case
|
695
|
+
case ZSTD_c_jobSize :
|
696
|
+
#ifndef ZSTD_MULTITHREAD
|
697
|
+
return ERROR(parameter_unsupported);
|
698
|
+
#else
|
699
|
+
assert(CCtxParams->jobSize <= INT_MAX);
|
700
|
+
*value = (int)CCtxParams->jobSize;
|
701
|
+
break;
|
702
|
+
#endif
|
703
|
+
case ZSTD_c_overlapLog :
|
534
704
|
#ifndef ZSTD_MULTITHREAD
|
535
705
|
return ERROR(parameter_unsupported);
|
536
706
|
#else
|
537
|
-
*value = CCtxParams->
|
707
|
+
*value = CCtxParams->overlapLog;
|
538
708
|
break;
|
539
709
|
#endif
|
540
|
-
case
|
710
|
+
case ZSTD_c_rsyncable :
|
541
711
|
#ifndef ZSTD_MULTITHREAD
|
542
712
|
return ERROR(parameter_unsupported);
|
543
713
|
#else
|
544
|
-
*value = CCtxParams->
|
714
|
+
*value = CCtxParams->rsyncable;
|
545
715
|
break;
|
546
716
|
#endif
|
547
|
-
case
|
717
|
+
case ZSTD_c_enableLongDistanceMatching :
|
548
718
|
*value = CCtxParams->ldmParams.enableLdm;
|
549
719
|
break;
|
550
|
-
case
|
720
|
+
case ZSTD_c_ldmHashLog :
|
551
721
|
*value = CCtxParams->ldmParams.hashLog;
|
552
722
|
break;
|
553
|
-
case
|
723
|
+
case ZSTD_c_ldmMinMatch :
|
554
724
|
*value = CCtxParams->ldmParams.minMatchLength;
|
555
725
|
break;
|
556
|
-
case
|
726
|
+
case ZSTD_c_ldmBucketSizeLog :
|
557
727
|
*value = CCtxParams->ldmParams.bucketSizeLog;
|
558
728
|
break;
|
559
|
-
case
|
560
|
-
*value = CCtxParams->ldmParams.
|
729
|
+
case ZSTD_c_ldmHashRateLog :
|
730
|
+
*value = CCtxParams->ldmParams.hashRateLog;
|
561
731
|
break;
|
562
732
|
default: return ERROR(parameter_unsupported);
|
563
733
|
}
|
@@ -655,34 +825,35 @@ size_t ZSTD_CCtx_refPrefix_advanced(
|
|
655
825
|
|
656
826
|
/*! ZSTD_CCtx_reset() :
|
657
827
|
* Also dumps dictionary */
|
658
|
-
|
828
|
+
size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset)
|
659
829
|
{
|
660
|
-
|
661
|
-
|
830
|
+
if ( (reset == ZSTD_reset_session_only)
|
831
|
+
|| (reset == ZSTD_reset_session_and_parameters) ) {
|
832
|
+
cctx->streamStage = zcss_init;
|
833
|
+
cctx->pledgedSrcSizePlusOne = 0;
|
834
|
+
}
|
835
|
+
if ( (reset == ZSTD_reset_parameters)
|
836
|
+
|| (reset == ZSTD_reset_session_and_parameters) ) {
|
837
|
+
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
838
|
+
cctx->cdict = NULL;
|
839
|
+
return ZSTD_CCtxParams_reset(&cctx->requestedParams);
|
840
|
+
}
|
841
|
+
return 0;
|
662
842
|
}
|
663
843
|
|
664
|
-
size_t ZSTD_CCtx_resetParameters(ZSTD_CCtx* cctx)
|
665
|
-
{
|
666
|
-
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
667
|
-
cctx->cdict = NULL;
|
668
|
-
return ZSTD_CCtxParams_reset(&cctx->requestedParams);
|
669
|
-
}
|
670
844
|
|
671
845
|
/** ZSTD_checkCParams() :
|
672
846
|
control CParam values remain within authorized range.
|
673
847
|
@return : 0, or an error code if one value is beyond authorized range */
|
674
848
|
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
|
675
849
|
{
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
return ERROR(parameter_outOfBound);
|
684
|
-
if ((U32)(cParams.strategy) > (U32)ZSTD_btultra)
|
685
|
-
return ERROR(parameter_unsupported);
|
850
|
+
BOUNDCHECK(ZSTD_c_windowLog, cParams.windowLog);
|
851
|
+
BOUNDCHECK(ZSTD_c_chainLog, cParams.chainLog);
|
852
|
+
BOUNDCHECK(ZSTD_c_hashLog, cParams.hashLog);
|
853
|
+
BOUNDCHECK(ZSTD_c_searchLog, cParams.searchLog);
|
854
|
+
BOUNDCHECK(ZSTD_c_minMatch, cParams.minMatch);
|
855
|
+
BOUNDCHECK(ZSTD_c_targetLength,cParams.targetLength);
|
856
|
+
BOUNDCHECK(ZSTD_c_strategy, cParams.strategy);
|
686
857
|
return 0;
|
687
858
|
}
|
688
859
|
|
@@ -692,19 +863,19 @@ size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
|
|
692
863
|
static ZSTD_compressionParameters
|
693
864
|
ZSTD_clampCParams(ZSTD_compressionParameters cParams)
|
694
865
|
{
|
695
|
-
# define
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
CLAMP(cParams.
|
702
|
-
CLAMP(cParams.
|
703
|
-
CLAMP(cParams.
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
866
|
+
# define CLAMP_TYPE(cParam, val, type) { \
|
867
|
+
ZSTD_bounds const bounds = ZSTD_cParam_getBounds(cParam); \
|
868
|
+
if ((int)val<bounds.lowerBound) val=(type)bounds.lowerBound; \
|
869
|
+
else if ((int)val>bounds.upperBound) val=(type)bounds.upperBound; \
|
870
|
+
}
|
871
|
+
# define CLAMP(cParam, val) CLAMP_TYPE(cParam, val, int)
|
872
|
+
CLAMP(ZSTD_c_windowLog, cParams.windowLog);
|
873
|
+
CLAMP(ZSTD_c_chainLog, cParams.chainLog);
|
874
|
+
CLAMP(ZSTD_c_hashLog, cParams.hashLog);
|
875
|
+
CLAMP(ZSTD_c_searchLog, cParams.searchLog);
|
876
|
+
CLAMP(ZSTD_c_minMatch, cParams.minMatch);
|
877
|
+
CLAMP(ZSTD_c_targetLength,cParams.targetLength);
|
878
|
+
CLAMP_TYPE(ZSTD_c_strategy,cParams.strategy, ZSTD_strategy);
|
708
879
|
return cParams;
|
709
880
|
}
|
710
881
|
|
@@ -774,7 +945,7 @@ ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(
|
|
774
945
|
if (CCtxParams->cParams.hashLog) cParams.hashLog = CCtxParams->cParams.hashLog;
|
775
946
|
if (CCtxParams->cParams.chainLog) cParams.chainLog = CCtxParams->cParams.chainLog;
|
776
947
|
if (CCtxParams->cParams.searchLog) cParams.searchLog = CCtxParams->cParams.searchLog;
|
777
|
-
if (CCtxParams->cParams.
|
948
|
+
if (CCtxParams->cParams.minMatch) cParams.minMatch = CCtxParams->cParams.minMatch;
|
778
949
|
if (CCtxParams->cParams.targetLength) cParams.targetLength = CCtxParams->cParams.targetLength;
|
779
950
|
if (CCtxParams->cParams.strategy) cParams.strategy = CCtxParams->cParams.strategy;
|
780
951
|
assert(!ZSTD_checkCParams(cParams));
|
@@ -787,13 +958,12 @@ ZSTD_sizeof_matchState(const ZSTD_compressionParameters* const cParams,
|
|
787
958
|
{
|
788
959
|
size_t const chainSize = (cParams->strategy == ZSTD_fast) ? 0 : ((size_t)1 << cParams->chainLog);
|
789
960
|
size_t const hSize = ((size_t)1) << cParams->hashLog;
|
790
|
-
U32 const hashLog3 = (forCCtx && cParams->
|
961
|
+
U32 const hashLog3 = (forCCtx && cParams->minMatch==3) ? MIN(ZSTD_HASHLOG3_MAX, cParams->windowLog) : 0;
|
791
962
|
size_t const h3Size = ((size_t)1) << hashLog3;
|
792
963
|
size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32);
|
793
964
|
size_t const optPotentialSpace = ((MaxML+1) + (MaxLL+1) + (MaxOff+1) + (1<<Litbits)) * sizeof(U32)
|
794
965
|
+ (ZSTD_OPT_NUM+1) * (sizeof(ZSTD_match_t)+sizeof(ZSTD_optimal_t));
|
795
|
-
size_t const optSpace = (forCCtx && (
|
796
|
-
(cParams->strategy == ZSTD_btultra)))
|
966
|
+
size_t const optSpace = (forCCtx && (cParams->strategy >= ZSTD_btopt))
|
797
967
|
? optPotentialSpace
|
798
968
|
: 0;
|
799
969
|
DEBUGLOG(4, "chainSize: %u - hSize: %u - h3Size: %u",
|
@@ -808,7 +978,7 @@ size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params)
|
|
808
978
|
{ ZSTD_compressionParameters const cParams =
|
809
979
|
ZSTD_getCParamsFromCCtxParams(params, 0, 0);
|
810
980
|
size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << cParams.windowLog);
|
811
|
-
U32 const divider = (cParams.
|
981
|
+
U32 const divider = (cParams.minMatch==3) ? 3 : 4;
|
812
982
|
size_t const maxNbSeq = blockSize / divider;
|
813
983
|
size_t const tokenSpace = WILDCOPY_OVERLENGTH + blockSize + 11*maxNbSeq;
|
814
984
|
size_t const entropySpace = HUF_WORKSPACE_SIZE;
|
@@ -843,7 +1013,7 @@ size_t ZSTD_estimateCCtxSize(int compressionLevel)
|
|
843
1013
|
{
|
844
1014
|
int level;
|
845
1015
|
size_t memBudget = 0;
|
846
|
-
for (level=1; level<=compressionLevel; level++) {
|
1016
|
+
for (level=MIN(compressionLevel, 1); level<=compressionLevel; level++) {
|
847
1017
|
size_t const newMB = ZSTD_estimateCCtxSize_internal(level);
|
848
1018
|
if (newMB > memBudget) memBudget = newMB;
|
849
1019
|
}
|
@@ -879,7 +1049,7 @@ size_t ZSTD_estimateCStreamSize(int compressionLevel)
|
|
879
1049
|
{
|
880
1050
|
int level;
|
881
1051
|
size_t memBudget = 0;
|
882
|
-
for (level=1; level<=compressionLevel; level++) {
|
1052
|
+
for (level=MIN(compressionLevel, 1); level<=compressionLevel; level++) {
|
883
1053
|
size_t const newMB = ZSTD_estimateCStreamSize_internal(level);
|
884
1054
|
if (newMB > memBudget) memBudget = newMB;
|
885
1055
|
}
|
@@ -933,7 +1103,7 @@ static U32 ZSTD_equivalentCParams(ZSTD_compressionParameters cParams1,
|
|
933
1103
|
return (cParams1.hashLog == cParams2.hashLog)
|
934
1104
|
& (cParams1.chainLog == cParams2.chainLog)
|
935
1105
|
& (cParams1.strategy == cParams2.strategy) /* opt parser space */
|
936
|
-
& ((cParams1.
|
1106
|
+
& ((cParams1.minMatch==3) == (cParams2.minMatch==3)); /* hashlog3 space */
|
937
1107
|
}
|
938
1108
|
|
939
1109
|
static void ZSTD_assertEqualCParams(ZSTD_compressionParameters cParams1,
|
@@ -945,7 +1115,7 @@ static void ZSTD_assertEqualCParams(ZSTD_compressionParameters cParams1,
|
|
945
1115
|
assert(cParams1.chainLog == cParams2.chainLog);
|
946
1116
|
assert(cParams1.hashLog == cParams2.hashLog);
|
947
1117
|
assert(cParams1.searchLog == cParams2.searchLog);
|
948
|
-
assert(cParams1.
|
1118
|
+
assert(cParams1.minMatch == cParams2.minMatch);
|
949
1119
|
assert(cParams1.targetLength == cParams2.targetLength);
|
950
1120
|
assert(cParams1.strategy == cParams2.strategy);
|
951
1121
|
}
|
@@ -960,7 +1130,7 @@ static U32 ZSTD_equivalentLdmParams(ldmParams_t ldmParams1,
|
|
960
1130
|
ldmParams1.hashLog == ldmParams2.hashLog &&
|
961
1131
|
ldmParams1.bucketSizeLog == ldmParams2.bucketSizeLog &&
|
962
1132
|
ldmParams1.minMatchLength == ldmParams2.minMatchLength &&
|
963
|
-
ldmParams1.
|
1133
|
+
ldmParams1.hashRateLog == ldmParams2.hashRateLog);
|
964
1134
|
}
|
965
1135
|
|
966
1136
|
typedef enum { ZSTDb_not_buffered, ZSTDb_buffered } ZSTD_buffered_policy_e;
|
@@ -976,7 +1146,7 @@ static U32 ZSTD_sufficientBuff(size_t bufferSize1, size_t maxNbSeq1,
|
|
976
1146
|
{
|
977
1147
|
size_t const windowSize2 = MAX(1, (size_t)MIN(((U64)1 << cParams2.windowLog), pledgedSrcSize));
|
978
1148
|
size_t const blockSize2 = MIN(ZSTD_BLOCKSIZE_MAX, windowSize2);
|
979
|
-
size_t const maxNbSeq2 = blockSize2 / ((cParams2.
|
1149
|
+
size_t const maxNbSeq2 = blockSize2 / ((cParams2.minMatch == 3) ? 3 : 4);
|
980
1150
|
size_t const maxNbLit2 = blockSize2;
|
981
1151
|
size_t const neededBufferSize2 = (buffPol2==ZSTDb_buffered) ? windowSize2 + blockSize2 : 0;
|
982
1152
|
DEBUGLOG(4, "ZSTD_sufficientBuff: is neededBufferSize2=%u <= bufferSize1=%u",
|
@@ -1034,8 +1204,8 @@ static void ZSTD_invalidateMatchState(ZSTD_matchState_t* ms)
|
|
1034
1204
|
{
|
1035
1205
|
ZSTD_window_clear(&ms->window);
|
1036
1206
|
|
1037
|
-
ms->nextToUpdate = ms->window.dictLimit
|
1038
|
-
ms->nextToUpdate3 = ms->window.dictLimit
|
1207
|
+
ms->nextToUpdate = ms->window.dictLimit;
|
1208
|
+
ms->nextToUpdate3 = ms->window.dictLimit;
|
1039
1209
|
ms->loadedDictEnd = 0;
|
1040
1210
|
ms->opt.litLengthSum = 0; /* force reset of btopt stats */
|
1041
1211
|
ms->dictMatchState = NULL;
|
@@ -1080,7 +1250,7 @@ ZSTD_reset_matchState(ZSTD_matchState_t* ms,
|
|
1080
1250
|
{
|
1081
1251
|
size_t const chainSize = (cParams->strategy == ZSTD_fast) ? 0 : ((size_t)1 << cParams->chainLog);
|
1082
1252
|
size_t const hSize = ((size_t)1) << cParams->hashLog;
|
1083
|
-
U32 const hashLog3 = (forCCtx && cParams->
|
1253
|
+
U32 const hashLog3 = (forCCtx && cParams->minMatch==3) ? MIN(ZSTD_HASHLOG3_MAX, cParams->windowLog) : 0;
|
1084
1254
|
size_t const h3Size = ((size_t)1) << hashLog3;
|
1085
1255
|
size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32);
|
1086
1256
|
|
@@ -1094,9 +1264,9 @@ ZSTD_reset_matchState(ZSTD_matchState_t* ms,
|
|
1094
1264
|
ZSTD_invalidateMatchState(ms);
|
1095
1265
|
|
1096
1266
|
/* opt parser space */
|
1097
|
-
if (forCCtx && (
|
1267
|
+
if (forCCtx && (cParams->strategy >= ZSTD_btopt)) {
|
1098
1268
|
DEBUGLOG(4, "reserving optimal parser space");
|
1099
|
-
ms->opt.litFreq = (
|
1269
|
+
ms->opt.litFreq = (unsigned*)ptr;
|
1100
1270
|
ms->opt.litLengthFreq = ms->opt.litFreq + (1<<Litbits);
|
1101
1271
|
ms->opt.matchLengthFreq = ms->opt.litLengthFreq + (MaxLL+1);
|
1102
1272
|
ms->opt.offCodeFreq = ms->opt.matchLengthFreq + (MaxML+1);
|
@@ -1158,13 +1328,13 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
|
|
1158
1328
|
/* Adjust long distance matching parameters */
|
1159
1329
|
ZSTD_ldm_adjustParameters(¶ms.ldmParams, ¶ms.cParams);
|
1160
1330
|
assert(params.ldmParams.hashLog >= params.ldmParams.bucketSizeLog);
|
1161
|
-
assert(params.ldmParams.
|
1162
|
-
zc->ldmState.hashPower =
|
1331
|
+
assert(params.ldmParams.hashRateLog < 32);
|
1332
|
+
zc->ldmState.hashPower = ZSTD_rollingHash_primePower(params.ldmParams.minMatchLength);
|
1163
1333
|
}
|
1164
1334
|
|
1165
1335
|
{ size_t const windowSize = MAX(1, (size_t)MIN(((U64)1 << params.cParams.windowLog), pledgedSrcSize));
|
1166
1336
|
size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, windowSize);
|
1167
|
-
U32 const divider = (params.cParams.
|
1337
|
+
U32 const divider = (params.cParams.minMatch==3) ? 3 : 4;
|
1168
1338
|
size_t const maxNbSeq = blockSize / divider;
|
1169
1339
|
size_t const tokenSpace = WILDCOPY_OVERLENGTH + blockSize + 11*maxNbSeq;
|
1170
1340
|
size_t const buffOutSize = (zbuff==ZSTDb_buffered) ? ZSTD_compressBound(blockSize)+1 : 0;
|
@@ -1227,7 +1397,7 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
|
|
1227
1397
|
if (pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN)
|
1228
1398
|
zc->appliedParams.fParams.contentSizeFlag = 0;
|
1229
1399
|
DEBUGLOG(4, "pledged content size : %u ; flag : %u",
|
1230
|
-
(
|
1400
|
+
(unsigned)pledgedSrcSize, zc->appliedParams.fParams.contentSizeFlag);
|
1231
1401
|
zc->blockSize = blockSize;
|
1232
1402
|
|
1233
1403
|
XXH64_reset(&zc->xxhState, 0);
|
@@ -1306,16 +1476,17 @@ void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx) {
|
|
1306
1476
|
* dictionary tables into the working context is faster than using them
|
1307
1477
|
* in-place.
|
1308
1478
|
*/
|
1309
|
-
static const size_t attachDictSizeCutoffs[
|
1310
|
-
8 KB,
|
1311
|
-
8 KB,
|
1479
|
+
static const size_t attachDictSizeCutoffs[ZSTD_STRATEGY_MAX+1] = {
|
1480
|
+
8 KB, /* unused */
|
1481
|
+
8 KB, /* ZSTD_fast */
|
1312
1482
|
16 KB, /* ZSTD_dfast */
|
1313
1483
|
32 KB, /* ZSTD_greedy */
|
1314
1484
|
32 KB, /* ZSTD_lazy */
|
1315
1485
|
32 KB, /* ZSTD_lazy2 */
|
1316
1486
|
32 KB, /* ZSTD_btlazy2 */
|
1317
1487
|
32 KB, /* ZSTD_btopt */
|
1318
|
-
8 KB
|
1488
|
+
8 KB, /* ZSTD_btultra */
|
1489
|
+
8 KB /* ZSTD_btultra2 */
|
1319
1490
|
};
|
1320
1491
|
|
1321
1492
|
static int ZSTD_shouldAttachDict(const ZSTD_CDict* cdict,
|
@@ -1447,7 +1618,8 @@ static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
|
|
1447
1618
|
ZSTD_buffered_policy_e zbuff)
|
1448
1619
|
{
|
1449
1620
|
|
1450
|
-
DEBUGLOG(4, "ZSTD_resetCCtx_usingCDict (pledgedSrcSize=%u)",
|
1621
|
+
DEBUGLOG(4, "ZSTD_resetCCtx_usingCDict (pledgedSrcSize=%u)",
|
1622
|
+
(unsigned)pledgedSrcSize);
|
1451
1623
|
|
1452
1624
|
if (ZSTD_shouldAttachDict(cdict, params, pledgedSrcSize)) {
|
1453
1625
|
return ZSTD_resetCCtx_byAttachingCDict(
|
@@ -1670,7 +1842,9 @@ static size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, cons
|
|
1670
1842
|
* note : use same formula for both situations */
|
1671
1843
|
static size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
|
1672
1844
|
{
|
1673
|
-
U32 const minlog = (strat
|
1845
|
+
U32 const minlog = (strat>=ZSTD_btultra) ? (U32)(strat) - 1 : 6;
|
1846
|
+
ZSTD_STATIC_ASSERT(ZSTD_btultra == 8);
|
1847
|
+
assert(ZSTD_cParam_withinBounds(ZSTD_c_strategy, strat));
|
1674
1848
|
return (srcSize >> minlog) + 2;
|
1675
1849
|
}
|
1676
1850
|
|
@@ -1679,7 +1853,8 @@ static size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
|
1679
1853
|
ZSTD_strategy strategy, int disableLiteralCompression,
|
1680
1854
|
void* dst, size_t dstCapacity,
|
1681
1855
|
const void* src, size_t srcSize,
|
1682
|
-
|
1856
|
+
void* workspace, size_t wkspSize,
|
1857
|
+
const int bmi2)
|
1683
1858
|
{
|
1684
1859
|
size_t const minGain = ZSTD_minGain(srcSize, strategy);
|
1685
1860
|
size_t const lhSize = 3 + (srcSize >= 1 KB) + (srcSize >= 16 KB);
|
@@ -1708,9 +1883,9 @@ static size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
|
1708
1883
|
int const preferRepeat = strategy < ZSTD_lazy ? srcSize <= 1024 : 0;
|
1709
1884
|
if (repeat == HUF_repeat_valid && lhSize == 3) singleStream = 1;
|
1710
1885
|
cLitSize = singleStream ? HUF_compress1X_repeat(ostart+lhSize, dstCapacity-lhSize, src, srcSize, 255, 11,
|
1711
|
-
workspace,
|
1886
|
+
workspace, wkspSize, (HUF_CElt*)nextHuf->CTable, &repeat, preferRepeat, bmi2)
|
1712
1887
|
: HUF_compress4X_repeat(ostart+lhSize, dstCapacity-lhSize, src, srcSize, 255, 11,
|
1713
|
-
workspace,
|
1888
|
+
workspace, wkspSize, (HUF_CElt*)nextHuf->CTable, &repeat, preferRepeat, bmi2);
|
1714
1889
|
if (repeat != HUF_repeat_none) {
|
1715
1890
|
/* reused the existing table */
|
1716
1891
|
hType = set_repeat;
|
@@ -1977,7 +2152,7 @@ ZSTD_selectEncodingType(
|
|
1977
2152
|
assert(!ZSTD_isError(NCountCost));
|
1978
2153
|
assert(compressedCost < ERROR(maxCode));
|
1979
2154
|
DEBUGLOG(5, "Estimated bit costs: basic=%u\trepeat=%u\tcompressed=%u",
|
1980
|
-
(
|
2155
|
+
(unsigned)basicCost, (unsigned)repeatCost, (unsigned)compressedCost);
|
1981
2156
|
if (basicCost <= repeatCost && basicCost <= compressedCost) {
|
1982
2157
|
DEBUGLOG(5, "Selected set_basic");
|
1983
2158
|
assert(isDefaultAllowed);
|
@@ -1999,7 +2174,7 @@ ZSTD_selectEncodingType(
|
|
1999
2174
|
MEM_STATIC size_t
|
2000
2175
|
ZSTD_buildCTable(void* dst, size_t dstCapacity,
|
2001
2176
|
FSE_CTable* nextCTable, U32 FSELog, symbolEncodingType_e type,
|
2002
|
-
|
2177
|
+
unsigned* count, U32 max,
|
2003
2178
|
const BYTE* codeTable, size_t nbSeq,
|
2004
2179
|
const S16* defaultNorm, U32 defaultNormLog, U32 defaultMax,
|
2005
2180
|
const FSE_CTable* prevCTable, size_t prevCTableSize,
|
@@ -2007,11 +2182,13 @@ ZSTD_buildCTable(void* dst, size_t dstCapacity,
|
|
2007
2182
|
{
|
2008
2183
|
BYTE* op = (BYTE*)dst;
|
2009
2184
|
const BYTE* const oend = op + dstCapacity;
|
2185
|
+
DEBUGLOG(6, "ZSTD_buildCTable (dstCapacity=%u)", (unsigned)dstCapacity);
|
2010
2186
|
|
2011
2187
|
switch (type) {
|
2012
2188
|
case set_rle:
|
2013
|
-
*op = codeTable[0];
|
2014
2189
|
CHECK_F(FSE_buildCTable_rle(nextCTable, (BYTE)max));
|
2190
|
+
if (dstCapacity==0) return ERROR(dstSize_tooSmall);
|
2191
|
+
*op = codeTable[0];
|
2015
2192
|
return 1;
|
2016
2193
|
case set_repeat:
|
2017
2194
|
memcpy(nextCTable, prevCTable, prevCTableSize);
|
@@ -2053,6 +2230,9 @@ ZSTD_encodeSequences_body(
|
|
2053
2230
|
FSE_CState_t stateLitLength;
|
2054
2231
|
|
2055
2232
|
CHECK_E(BIT_initCStream(&blockStream, dst, dstCapacity), dstSize_tooSmall); /* not enough space remaining */
|
2233
|
+
DEBUGLOG(6, "available space for bitstream : %i (dstCapacity=%u)",
|
2234
|
+
(int)(blockStream.endPtr - blockStream.startPtr),
|
2235
|
+
(unsigned)dstCapacity);
|
2056
2236
|
|
2057
2237
|
/* first symbols */
|
2058
2238
|
FSE_initCState2(&stateMatchLength, CTable_MatchLength, mlCodeTable[nbSeq-1]);
|
@@ -2085,9 +2265,9 @@ ZSTD_encodeSequences_body(
|
|
2085
2265
|
U32 const ofBits = ofCode;
|
2086
2266
|
U32 const mlBits = ML_bits[mlCode];
|
2087
2267
|
DEBUGLOG(6, "encoding: litlen:%2u - matchlen:%2u - offCode:%7u",
|
2088
|
-
sequences[n].litLength,
|
2089
|
-
sequences[n].matchLength + MINMATCH,
|
2090
|
-
sequences[n].offset);
|
2268
|
+
(unsigned)sequences[n].litLength,
|
2269
|
+
(unsigned)sequences[n].matchLength + MINMATCH,
|
2270
|
+
(unsigned)sequences[n].offset);
|
2091
2271
|
/* 32b*/ /* 64b*/
|
2092
2272
|
/* (7)*/ /* (7)*/
|
2093
2273
|
FSE_encodeSymbol(&blockStream, &stateOffsetBits, ofCode); /* 15 */ /* 15 */
|
@@ -2112,6 +2292,7 @@ ZSTD_encodeSequences_body(
|
|
2112
2292
|
BIT_addBits(&blockStream, sequences[n].offset, ofBits); /* 31 */
|
2113
2293
|
}
|
2114
2294
|
BIT_flushBits(&blockStream); /* (7)*/
|
2295
|
+
DEBUGLOG(7, "remaining space : %i", (int)(blockStream.endPtr - blockStream.ptr));
|
2115
2296
|
} }
|
2116
2297
|
|
2117
2298
|
DEBUGLOG(6, "ZSTD_encodeSequences: flushing ML state with %u bits", stateMatchLength.stateLog);
|
@@ -2169,6 +2350,7 @@ static size_t ZSTD_encodeSequences(
|
|
2169
2350
|
FSE_CTable const* CTable_LitLength, BYTE const* llCodeTable,
|
2170
2351
|
seqDef const* sequences, size_t nbSeq, int longOffsets, int bmi2)
|
2171
2352
|
{
|
2353
|
+
DEBUGLOG(5, "ZSTD_encodeSequences: dstCapacity = %u", (unsigned)dstCapacity);
|
2172
2354
|
#if DYNAMIC_BMI2
|
2173
2355
|
if (bmi2) {
|
2174
2356
|
return ZSTD_encodeSequences_bmi2(dst, dstCapacity,
|
@@ -2186,16 +2368,20 @@ static size_t ZSTD_encodeSequences(
|
|
2186
2368
|
sequences, nbSeq, longOffsets);
|
2187
2369
|
}
|
2188
2370
|
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2371
|
+
/* ZSTD_compressSequences_internal():
|
2372
|
+
* actually compresses both literals and sequences */
|
2373
|
+
MEM_STATIC size_t
|
2374
|
+
ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
|
2375
|
+
const ZSTD_entropyCTables_t* prevEntropy,
|
2376
|
+
ZSTD_entropyCTables_t* nextEntropy,
|
2377
|
+
const ZSTD_CCtx_params* cctxParams,
|
2378
|
+
void* dst, size_t dstCapacity,
|
2379
|
+
void* workspace, size_t wkspSize,
|
2380
|
+
const int bmi2)
|
2195
2381
|
{
|
2196
2382
|
const int longOffsets = cctxParams->cParams.windowLog > STREAM_ACCUMULATOR_MIN;
|
2197
2383
|
ZSTD_strategy const strategy = cctxParams->cParams.strategy;
|
2198
|
-
|
2384
|
+
unsigned count[MaxSeq+1];
|
2199
2385
|
FSE_CTable* CTable_LitLength = nextEntropy->fse.litlengthCTable;
|
2200
2386
|
FSE_CTable* CTable_OffsetBits = nextEntropy->fse.offcodeCTable;
|
2201
2387
|
FSE_CTable* CTable_MatchLength = nextEntropy->fse.matchlengthCTable;
|
@@ -2212,6 +2398,7 @@ MEM_STATIC size_t ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
|
|
2212
2398
|
BYTE* lastNCount = NULL;
|
2213
2399
|
|
2214
2400
|
ZSTD_STATIC_ASSERT(HUF_WORKSPACE_SIZE >= (1<<MAX(MLFSELog,LLFSELog)));
|
2401
|
+
DEBUGLOG(5, "ZSTD_compressSequences_internal");
|
2215
2402
|
|
2216
2403
|
/* Compress literals */
|
2217
2404
|
{ const BYTE* const literals = seqStorePtr->litStart;
|
@@ -2222,7 +2409,8 @@ MEM_STATIC size_t ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
|
|
2222
2409
|
cctxParams->cParams.strategy, disableLiteralCompression,
|
2223
2410
|
op, dstCapacity,
|
2224
2411
|
literals, litSize,
|
2225
|
-
workspace,
|
2412
|
+
workspace, wkspSize,
|
2413
|
+
bmi2);
|
2226
2414
|
if (ZSTD_isError(cSize))
|
2227
2415
|
return cSize;
|
2228
2416
|
assert(cSize <= dstCapacity);
|
@@ -2249,51 +2437,63 @@ MEM_STATIC size_t ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
|
|
2249
2437
|
/* convert length/distances into codes */
|
2250
2438
|
ZSTD_seqToCodes(seqStorePtr);
|
2251
2439
|
/* build CTable for Literal Lengths */
|
2252
|
-
{
|
2253
|
-
size_t const mostFrequent = HIST_countFast_wksp(count, &max, llCodeTable, nbSeq, workspace); /* can't fail */
|
2440
|
+
{ unsigned max = MaxLL;
|
2441
|
+
size_t const mostFrequent = HIST_countFast_wksp(count, &max, llCodeTable, nbSeq, workspace, wkspSize); /* can't fail */
|
2254
2442
|
DEBUGLOG(5, "Building LL table");
|
2255
2443
|
nextEntropy->fse.litlength_repeatMode = prevEntropy->fse.litlength_repeatMode;
|
2256
|
-
LLtype = ZSTD_selectEncodingType(&nextEntropy->fse.litlength_repeatMode,
|
2444
|
+
LLtype = ZSTD_selectEncodingType(&nextEntropy->fse.litlength_repeatMode,
|
2445
|
+
count, max, mostFrequent, nbSeq,
|
2446
|
+
LLFSELog, prevEntropy->fse.litlengthCTable,
|
2447
|
+
LL_defaultNorm, LL_defaultNormLog,
|
2448
|
+
ZSTD_defaultAllowed, strategy);
|
2257
2449
|
assert(set_basic < set_compressed && set_rle < set_compressed);
|
2258
2450
|
assert(!(LLtype < set_compressed && nextEntropy->fse.litlength_repeatMode != FSE_repeat_none)); /* We don't copy tables */
|
2259
2451
|
{ size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_LitLength, LLFSELog, (symbolEncodingType_e)LLtype,
|
2260
2452
|
count, max, llCodeTable, nbSeq, LL_defaultNorm, LL_defaultNormLog, MaxLL,
|
2261
2453
|
prevEntropy->fse.litlengthCTable, sizeof(prevEntropy->fse.litlengthCTable),
|
2262
|
-
workspace,
|
2454
|
+
workspace, wkspSize);
|
2263
2455
|
if (ZSTD_isError(countSize)) return countSize;
|
2264
2456
|
if (LLtype == set_compressed)
|
2265
2457
|
lastNCount = op;
|
2266
2458
|
op += countSize;
|
2267
2459
|
} }
|
2268
2460
|
/* build CTable for Offsets */
|
2269
|
-
{
|
2270
|
-
size_t const mostFrequent = HIST_countFast_wksp(count, &max, ofCodeTable, nbSeq, workspace); /* can't fail */
|
2461
|
+
{ unsigned max = MaxOff;
|
2462
|
+
size_t const mostFrequent = HIST_countFast_wksp(count, &max, ofCodeTable, nbSeq, workspace, wkspSize); /* can't fail */
|
2271
2463
|
/* We can only use the basic table if max <= DefaultMaxOff, otherwise the offsets are too large */
|
2272
2464
|
ZSTD_defaultPolicy_e const defaultPolicy = (max <= DefaultMaxOff) ? ZSTD_defaultAllowed : ZSTD_defaultDisallowed;
|
2273
2465
|
DEBUGLOG(5, "Building OF table");
|
2274
2466
|
nextEntropy->fse.offcode_repeatMode = prevEntropy->fse.offcode_repeatMode;
|
2275
|
-
Offtype = ZSTD_selectEncodingType(&nextEntropy->fse.offcode_repeatMode,
|
2467
|
+
Offtype = ZSTD_selectEncodingType(&nextEntropy->fse.offcode_repeatMode,
|
2468
|
+
count, max, mostFrequent, nbSeq,
|
2469
|
+
OffFSELog, prevEntropy->fse.offcodeCTable,
|
2470
|
+
OF_defaultNorm, OF_defaultNormLog,
|
2471
|
+
defaultPolicy, strategy);
|
2276
2472
|
assert(!(Offtype < set_compressed && nextEntropy->fse.offcode_repeatMode != FSE_repeat_none)); /* We don't copy tables */
|
2277
2473
|
{ size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_OffsetBits, OffFSELog, (symbolEncodingType_e)Offtype,
|
2278
2474
|
count, max, ofCodeTable, nbSeq, OF_defaultNorm, OF_defaultNormLog, DefaultMaxOff,
|
2279
2475
|
prevEntropy->fse.offcodeCTable, sizeof(prevEntropy->fse.offcodeCTable),
|
2280
|
-
workspace,
|
2476
|
+
workspace, wkspSize);
|
2281
2477
|
if (ZSTD_isError(countSize)) return countSize;
|
2282
2478
|
if (Offtype == set_compressed)
|
2283
2479
|
lastNCount = op;
|
2284
2480
|
op += countSize;
|
2285
2481
|
} }
|
2286
2482
|
/* build CTable for MatchLengths */
|
2287
|
-
{
|
2288
|
-
size_t const mostFrequent = HIST_countFast_wksp(count, &max, mlCodeTable, nbSeq, workspace); /* can't fail */
|
2289
|
-
DEBUGLOG(5, "Building ML table");
|
2483
|
+
{ unsigned max = MaxML;
|
2484
|
+
size_t const mostFrequent = HIST_countFast_wksp(count, &max, mlCodeTable, nbSeq, workspace, wkspSize); /* can't fail */
|
2485
|
+
DEBUGLOG(5, "Building ML table (remaining space : %i)", (int)(oend-op));
|
2290
2486
|
nextEntropy->fse.matchlength_repeatMode = prevEntropy->fse.matchlength_repeatMode;
|
2291
|
-
MLtype = ZSTD_selectEncodingType(&nextEntropy->fse.matchlength_repeatMode,
|
2487
|
+
MLtype = ZSTD_selectEncodingType(&nextEntropy->fse.matchlength_repeatMode,
|
2488
|
+
count, max, mostFrequent, nbSeq,
|
2489
|
+
MLFSELog, prevEntropy->fse.matchlengthCTable,
|
2490
|
+
ML_defaultNorm, ML_defaultNormLog,
|
2491
|
+
ZSTD_defaultAllowed, strategy);
|
2292
2492
|
assert(!(MLtype < set_compressed && nextEntropy->fse.matchlength_repeatMode != FSE_repeat_none)); /* We don't copy tables */
|
2293
2493
|
{ size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_MatchLength, MLFSELog, (symbolEncodingType_e)MLtype,
|
2294
2494
|
count, max, mlCodeTable, nbSeq, ML_defaultNorm, ML_defaultNormLog, MaxML,
|
2295
2495
|
prevEntropy->fse.matchlengthCTable, sizeof(prevEntropy->fse.matchlengthCTable),
|
2296
|
-
workspace,
|
2496
|
+
workspace, wkspSize);
|
2297
2497
|
if (ZSTD_isError(countSize)) return countSize;
|
2298
2498
|
if (MLtype == set_compressed)
|
2299
2499
|
lastNCount = op;
|
@@ -2328,19 +2528,24 @@ MEM_STATIC size_t ZSTD_compressSequences_internal(seqStore_t* seqStorePtr,
|
|
2328
2528
|
}
|
2329
2529
|
}
|
2330
2530
|
|
2531
|
+
DEBUGLOG(5, "compressed block size : %u", (unsigned)(op - ostart));
|
2331
2532
|
return op - ostart;
|
2332
2533
|
}
|
2333
2534
|
|
2334
|
-
MEM_STATIC size_t
|
2335
|
-
|
2336
|
-
|
2337
|
-
|
2338
|
-
|
2339
|
-
|
2535
|
+
MEM_STATIC size_t
|
2536
|
+
ZSTD_compressSequences(seqStore_t* seqStorePtr,
|
2537
|
+
const ZSTD_entropyCTables_t* prevEntropy,
|
2538
|
+
ZSTD_entropyCTables_t* nextEntropy,
|
2539
|
+
const ZSTD_CCtx_params* cctxParams,
|
2540
|
+
void* dst, size_t dstCapacity,
|
2541
|
+
size_t srcSize,
|
2542
|
+
void* workspace, size_t wkspSize,
|
2543
|
+
int bmi2)
|
2340
2544
|
{
|
2341
2545
|
size_t const cSize = ZSTD_compressSequences_internal(
|
2342
|
-
|
2343
|
-
|
2546
|
+
seqStorePtr, prevEntropy, nextEntropy, cctxParams,
|
2547
|
+
dst, dstCapacity,
|
2548
|
+
workspace, wkspSize, bmi2);
|
2344
2549
|
if (cSize == 0) return 0;
|
2345
2550
|
/* When srcSize <= dstCapacity, there is enough space to write a raw uncompressed block.
|
2346
2551
|
* Since we ran out of space, block must be not compressible, so fall back to raw uncompressed block.
|
@@ -2362,7 +2567,7 @@ MEM_STATIC size_t ZSTD_compressSequences(seqStore_t* seqStorePtr,
|
|
2362
2567
|
* assumption : strat is a valid strategy */
|
2363
2568
|
ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMode_e dictMode)
|
2364
2569
|
{
|
2365
|
-
static const ZSTD_blockCompressor blockCompressor[3][
|
2570
|
+
static const ZSTD_blockCompressor blockCompressor[3][ZSTD_STRATEGY_MAX+1] = {
|
2366
2571
|
{ ZSTD_compressBlock_fast /* default for 0 */,
|
2367
2572
|
ZSTD_compressBlock_fast,
|
2368
2573
|
ZSTD_compressBlock_doubleFast,
|
@@ -2371,7 +2576,8 @@ ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMo
|
|
2371
2576
|
ZSTD_compressBlock_lazy2,
|
2372
2577
|
ZSTD_compressBlock_btlazy2,
|
2373
2578
|
ZSTD_compressBlock_btopt,
|
2374
|
-
ZSTD_compressBlock_btultra
|
2579
|
+
ZSTD_compressBlock_btultra,
|
2580
|
+
ZSTD_compressBlock_btultra2 },
|
2375
2581
|
{ ZSTD_compressBlock_fast_extDict /* default for 0 */,
|
2376
2582
|
ZSTD_compressBlock_fast_extDict,
|
2377
2583
|
ZSTD_compressBlock_doubleFast_extDict,
|
@@ -2380,6 +2586,7 @@ ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMo
|
|
2380
2586
|
ZSTD_compressBlock_lazy2_extDict,
|
2381
2587
|
ZSTD_compressBlock_btlazy2_extDict,
|
2382
2588
|
ZSTD_compressBlock_btopt_extDict,
|
2589
|
+
ZSTD_compressBlock_btultra_extDict,
|
2383
2590
|
ZSTD_compressBlock_btultra_extDict },
|
2384
2591
|
{ ZSTD_compressBlock_fast_dictMatchState /* default for 0 */,
|
2385
2592
|
ZSTD_compressBlock_fast_dictMatchState,
|
@@ -2389,14 +2596,14 @@ ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMo
|
|
2389
2596
|
ZSTD_compressBlock_lazy2_dictMatchState,
|
2390
2597
|
ZSTD_compressBlock_btlazy2_dictMatchState,
|
2391
2598
|
ZSTD_compressBlock_btopt_dictMatchState,
|
2599
|
+
ZSTD_compressBlock_btultra_dictMatchState,
|
2392
2600
|
ZSTD_compressBlock_btultra_dictMatchState }
|
2393
2601
|
};
|
2394
2602
|
ZSTD_blockCompressor selectedCompressor;
|
2395
2603
|
ZSTD_STATIC_ASSERT((unsigned)ZSTD_fast == 1);
|
2396
2604
|
|
2397
|
-
assert((
|
2398
|
-
|
2399
|
-
selectedCompressor = blockCompressor[(int)dictMode][(U32)strat];
|
2605
|
+
assert(ZSTD_cParam_withinBounds(ZSTD_c_strategy, strat));
|
2606
|
+
selectedCompressor = blockCompressor[(int)dictMode][(int)strat];
|
2400
2607
|
assert(selectedCompressor != NULL);
|
2401
2608
|
return selectedCompressor;
|
2402
2609
|
}
|
@@ -2421,15 +2628,15 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
|
|
2421
2628
|
{
|
2422
2629
|
ZSTD_matchState_t* const ms = &zc->blockState.matchState;
|
2423
2630
|
size_t cSize;
|
2424
|
-
DEBUGLOG(5, "ZSTD_compressBlock_internal (dstCapacity=%
|
2425
|
-
dstCapacity, ms->window.dictLimit, ms->nextToUpdate);
|
2631
|
+
DEBUGLOG(5, "ZSTD_compressBlock_internal (dstCapacity=%u, dictLimit=%u, nextToUpdate=%u)",
|
2632
|
+
(unsigned)dstCapacity, (unsigned)ms->window.dictLimit, (unsigned)ms->nextToUpdate);
|
2426
2633
|
assert(srcSize <= ZSTD_BLOCKSIZE_MAX);
|
2427
2634
|
|
2428
2635
|
/* Assert that we have correctly flushed the ctx params into the ms's copy */
|
2429
2636
|
ZSTD_assertEqualCParams(zc->appliedParams.cParams, ms->cParams);
|
2430
2637
|
|
2431
2638
|
if (srcSize < MIN_CBLOCK_SIZE+ZSTD_blockHeaderSize+1) {
|
2432
|
-
ZSTD_ldm_skipSequences(&zc->externSeqStore, srcSize, zc->appliedParams.cParams.
|
2639
|
+
ZSTD_ldm_skipSequences(&zc->externSeqStore, srcSize, zc->appliedParams.cParams.minMatch);
|
2433
2640
|
cSize = 0;
|
2434
2641
|
goto out; /* don't even attempt compression below a certain srcSize */
|
2435
2642
|
}
|
@@ -2437,8 +2644,8 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
|
|
2437
2644
|
ms->opt.symbolCosts = &zc->blockState.prevCBlock->entropy; /* required for optimal parser to read stats from dictionary */
|
2438
2645
|
|
2439
2646
|
/* a gap between an attached dict and the current window is not safe,
|
2440
|
-
* they must remain adjacent,
|
2441
|
-
* must be unset */
|
2647
|
+
* they must remain adjacent,
|
2648
|
+
* and when that stops being the case, the dict must be unset */
|
2442
2649
|
assert(ms->dictMatchState == NULL || ms->loadedDictEnd == ms->window.dictLimit);
|
2443
2650
|
|
2444
2651
|
/* limited update after a very long match */
|
@@ -2495,7 +2702,9 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
|
|
2495
2702
|
&zc->blockState.prevCBlock->entropy, &zc->blockState.nextCBlock->entropy,
|
2496
2703
|
&zc->appliedParams,
|
2497
2704
|
dst, dstCapacity,
|
2498
|
-
srcSize,
|
2705
|
+
srcSize,
|
2706
|
+
zc->entropyWorkspace, HUF_WORKSPACE_SIZE /* statically allocated in resetCCtx */,
|
2707
|
+
zc->bmi2);
|
2499
2708
|
|
2500
2709
|
out:
|
2501
2710
|
if (!ZSTD_isError(cSize) && cSize != 0) {
|
@@ -2535,7 +2744,7 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx,
|
|
2535
2744
|
U32 const maxDist = (U32)1 << cctx->appliedParams.cParams.windowLog;
|
2536
2745
|
assert(cctx->appliedParams.cParams.windowLog <= 31);
|
2537
2746
|
|
2538
|
-
DEBUGLOG(5, "ZSTD_compress_frameChunk (blockSize=%u)", (
|
2747
|
+
DEBUGLOG(5, "ZSTD_compress_frameChunk (blockSize=%u)", (unsigned)blockSize);
|
2539
2748
|
if (cctx->appliedParams.fParams.checksumFlag && srcSize)
|
2540
2749
|
XXH64_update(&cctx->xxhState, src, srcSize);
|
2541
2750
|
|
@@ -2583,7 +2792,7 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx,
|
|
2583
2792
|
assert(dstCapacity >= cSize);
|
2584
2793
|
dstCapacity -= cSize;
|
2585
2794
|
DEBUGLOG(5, "ZSTD_compress_frameChunk: adding a block of size %u",
|
2586
|
-
(
|
2795
|
+
(unsigned)cSize);
|
2587
2796
|
} }
|
2588
2797
|
|
2589
2798
|
if (lastFrameChunk && (op>ostart)) cctx->stage = ZSTDcs_ending;
|
@@ -2606,9 +2815,9 @@ static size_t ZSTD_writeFrameHeader(void* dst, size_t dstCapacity,
|
|
2606
2815
|
size_t pos=0;
|
2607
2816
|
|
2608
2817
|
assert(!(params.fParams.contentSizeFlag && pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN));
|
2609
|
-
if (dstCapacity <
|
2818
|
+
if (dstCapacity < ZSTD_FRAMEHEADERSIZE_MAX) return ERROR(dstSize_tooSmall);
|
2610
2819
|
DEBUGLOG(4, "ZSTD_writeFrameHeader : dictIDFlag : %u ; dictID : %u ; dictIDSizeCode : %u",
|
2611
|
-
!params.fParams.noDictIDFlag, dictID,
|
2820
|
+
!params.fParams.noDictIDFlag, (unsigned)dictID, (unsigned)dictIDSizeCode);
|
2612
2821
|
|
2613
2822
|
if (params.format == ZSTD_f_zstd1) {
|
2614
2823
|
MEM_writeLE32(dst, ZSTD_MAGICNUMBER);
|
@@ -2672,7 +2881,7 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx,
|
|
2672
2881
|
size_t fhSize = 0;
|
2673
2882
|
|
2674
2883
|
DEBUGLOG(5, "ZSTD_compressContinue_internal, stage: %u, srcSize: %u",
|
2675
|
-
cctx->stage, (
|
2884
|
+
cctx->stage, (unsigned)srcSize);
|
2676
2885
|
if (cctx->stage==ZSTDcs_created) return ERROR(stage_wrong); /* missing init (ZSTD_compressBegin) */
|
2677
2886
|
|
2678
2887
|
if (frame && (cctx->stage==ZSTDcs_init)) {
|
@@ -2709,7 +2918,7 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx,
|
|
2709
2918
|
}
|
2710
2919
|
}
|
2711
2920
|
|
2712
|
-
DEBUGLOG(5, "ZSTD_compressContinue_internal (blockSize=%u)", (
|
2921
|
+
DEBUGLOG(5, "ZSTD_compressContinue_internal (blockSize=%u)", (unsigned)cctx->blockSize);
|
2713
2922
|
{ size_t const cSize = frame ?
|
2714
2923
|
ZSTD_compress_frameChunk (cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) :
|
2715
2924
|
ZSTD_compressBlock_internal (cctx, dst, dstCapacity, src, srcSize);
|
@@ -2721,7 +2930,7 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx,
|
|
2721
2930
|
ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN == (unsigned long long)-1);
|
2722
2931
|
if (cctx->consumedSrcSize+1 > cctx->pledgedSrcSizePlusOne) {
|
2723
2932
|
DEBUGLOG(4, "error : pledgedSrcSize = %u, while realSrcSize >= %u",
|
2724
|
-
(
|
2933
|
+
(unsigned)cctx->pledgedSrcSizePlusOne-1, (unsigned)cctx->consumedSrcSize);
|
2725
2934
|
return ERROR(srcSize_wrong);
|
2726
2935
|
}
|
2727
2936
|
}
|
@@ -2733,7 +2942,7 @@ size_t ZSTD_compressContinue (ZSTD_CCtx* cctx,
|
|
2733
2942
|
void* dst, size_t dstCapacity,
|
2734
2943
|
const void* src, size_t srcSize)
|
2735
2944
|
{
|
2736
|
-
DEBUGLOG(5, "ZSTD_compressContinue (srcSize=%u)", (
|
2945
|
+
DEBUGLOG(5, "ZSTD_compressContinue (srcSize=%u)", (unsigned)srcSize);
|
2737
2946
|
return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 1 /* frame mode */, 0 /* last chunk */);
|
2738
2947
|
}
|
2739
2948
|
|
@@ -2791,6 +3000,7 @@ static size_t ZSTD_loadDictionaryContent(ZSTD_matchState_t* ms,
|
|
2791
3000
|
case ZSTD_btlazy2: /* we want the dictionary table fully sorted */
|
2792
3001
|
case ZSTD_btopt:
|
2793
3002
|
case ZSTD_btultra:
|
3003
|
+
case ZSTD_btultra2:
|
2794
3004
|
if (srcSize >= HASH_READ_SIZE)
|
2795
3005
|
ZSTD_updateTree(ms, iend-HASH_READ_SIZE, iend);
|
2796
3006
|
break;
|
@@ -2861,7 +3071,9 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|
2861
3071
|
if (offcodeLog > OffFSELog) return ERROR(dictionary_corrupted);
|
2862
3072
|
/* Defer checking offcodeMaxValue because we need to know the size of the dictionary content */
|
2863
3073
|
/* fill all offset symbols to avoid garbage at end of table */
|
2864
|
-
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.offcodeCTable,
|
3074
|
+
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.offcodeCTable,
|
3075
|
+
offcodeNCount, MaxOff, offcodeLog,
|
3076
|
+
workspace, HUF_WORKSPACE_SIZE),
|
2865
3077
|
dictionary_corrupted);
|
2866
3078
|
dictPtr += offcodeHeaderSize;
|
2867
3079
|
}
|
@@ -2873,7 +3085,9 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|
2873
3085
|
if (matchlengthLog > MLFSELog) return ERROR(dictionary_corrupted);
|
2874
3086
|
/* Every match length code must have non-zero probability */
|
2875
3087
|
CHECK_F( ZSTD_checkDictNCount(matchlengthNCount, matchlengthMaxValue, MaxML));
|
2876
|
-
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.matchlengthCTable,
|
3088
|
+
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.matchlengthCTable,
|
3089
|
+
matchlengthNCount, matchlengthMaxValue, matchlengthLog,
|
3090
|
+
workspace, HUF_WORKSPACE_SIZE),
|
2877
3091
|
dictionary_corrupted);
|
2878
3092
|
dictPtr += matchlengthHeaderSize;
|
2879
3093
|
}
|
@@ -2885,7 +3099,9 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|
2885
3099
|
if (litlengthLog > LLFSELog) return ERROR(dictionary_corrupted);
|
2886
3100
|
/* Every literal length code must have non-zero probability */
|
2887
3101
|
CHECK_F( ZSTD_checkDictNCount(litlengthNCount, litlengthMaxValue, MaxLL));
|
2888
|
-
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.litlengthCTable,
|
3102
|
+
CHECK_E( FSE_buildCTable_wksp(bs->entropy.fse.litlengthCTable,
|
3103
|
+
litlengthNCount, litlengthMaxValue, litlengthLog,
|
3104
|
+
workspace, HUF_WORKSPACE_SIZE),
|
2889
3105
|
dictionary_corrupted);
|
2890
3106
|
dictPtr += litlengthHeaderSize;
|
2891
3107
|
}
|
@@ -3023,7 +3239,7 @@ size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t di
|
|
3023
3239
|
ZSTD_parameters const params = ZSTD_getParams(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize);
|
3024
3240
|
ZSTD_CCtx_params const cctxParams =
|
3025
3241
|
ZSTD_assignParamsToCCtxParams(cctx->requestedParams, params);
|
3026
|
-
DEBUGLOG(4, "ZSTD_compressBegin_usingDict (dictSize=%u)", (
|
3242
|
+
DEBUGLOG(4, "ZSTD_compressBegin_usingDict (dictSize=%u)", (unsigned)dictSize);
|
3027
3243
|
return ZSTD_compressBegin_internal(cctx, dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL,
|
3028
3244
|
cctxParams, ZSTD_CONTENTSIZE_UNKNOWN, ZSTDb_not_buffered);
|
3029
3245
|
}
|
@@ -3067,7 +3283,7 @@ static size_t ZSTD_writeEpilogue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity)
|
|
3067
3283
|
if (cctx->appliedParams.fParams.checksumFlag) {
|
3068
3284
|
U32 const checksum = (U32) XXH64_digest(&cctx->xxhState);
|
3069
3285
|
if (dstCapacity<4) return ERROR(dstSize_tooSmall);
|
3070
|
-
DEBUGLOG(4, "ZSTD_writeEpilogue: write checksum : %08X", checksum);
|
3286
|
+
DEBUGLOG(4, "ZSTD_writeEpilogue: write checksum : %08X", (unsigned)checksum);
|
3071
3287
|
MEM_writeLE32(op, checksum);
|
3072
3288
|
op += 4;
|
3073
3289
|
}
|
@@ -3093,7 +3309,7 @@ size_t ZSTD_compressEnd (ZSTD_CCtx* cctx,
|
|
3093
3309
|
DEBUGLOG(4, "end of frame : controlling src size");
|
3094
3310
|
if (cctx->pledgedSrcSizePlusOne != cctx->consumedSrcSize+1) {
|
3095
3311
|
DEBUGLOG(4, "error : pledgedSrcSize = %u, while realSrcSize = %u",
|
3096
|
-
(
|
3312
|
+
(unsigned)cctx->pledgedSrcSizePlusOne-1, (unsigned)cctx->consumedSrcSize);
|
3097
3313
|
return ERROR(srcSize_wrong);
|
3098
3314
|
} }
|
3099
3315
|
return cSize + endResult;
|
@@ -3139,7 +3355,7 @@ size_t ZSTD_compress_advanced_internal(
|
|
3139
3355
|
const void* dict,size_t dictSize,
|
3140
3356
|
ZSTD_CCtx_params params)
|
3141
3357
|
{
|
3142
|
-
DEBUGLOG(4, "ZSTD_compress_advanced_internal (srcSize:%u)", (
|
3358
|
+
DEBUGLOG(4, "ZSTD_compress_advanced_internal (srcSize:%u)", (unsigned)srcSize);
|
3143
3359
|
CHECK_F( ZSTD_compressBegin_internal(cctx,
|
3144
3360
|
dict, dictSize, ZSTD_dct_auto, ZSTD_dtlm_fast, NULL,
|
3145
3361
|
params, srcSize, ZSTDb_not_buffered) );
|
@@ -3163,7 +3379,7 @@ size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
|
|
3163
3379
|
const void* src, size_t srcSize,
|
3164
3380
|
int compressionLevel)
|
3165
3381
|
{
|
3166
|
-
DEBUGLOG(4, "ZSTD_compressCCtx (srcSize=%u)", (
|
3382
|
+
DEBUGLOG(4, "ZSTD_compressCCtx (srcSize=%u)", (unsigned)srcSize);
|
3167
3383
|
assert(cctx != NULL);
|
3168
3384
|
return ZSTD_compress_usingDict(cctx, dst, dstCapacity, src, srcSize, NULL, 0, compressionLevel);
|
3169
3385
|
}
|
@@ -3189,7 +3405,7 @@ size_t ZSTD_estimateCDictSize_advanced(
|
|
3189
3405
|
size_t dictSize, ZSTD_compressionParameters cParams,
|
3190
3406
|
ZSTD_dictLoadMethod_e dictLoadMethod)
|
3191
3407
|
{
|
3192
|
-
DEBUGLOG(5, "sizeof(ZSTD_CDict) : %u", (
|
3408
|
+
DEBUGLOG(5, "sizeof(ZSTD_CDict) : %u", (unsigned)sizeof(ZSTD_CDict));
|
3193
3409
|
return sizeof(ZSTD_CDict) + HUF_WORKSPACE_SIZE + ZSTD_sizeof_matchState(&cParams, /* forCCtx */ 0)
|
3194
3410
|
+ (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize);
|
3195
3411
|
}
|
@@ -3203,7 +3419,7 @@ size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel)
|
|
3203
3419
|
size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict)
|
3204
3420
|
{
|
3205
3421
|
if (cdict==NULL) return 0; /* support sizeof on NULL */
|
3206
|
-
DEBUGLOG(5, "sizeof(*cdict) : %u", (
|
3422
|
+
DEBUGLOG(5, "sizeof(*cdict) : %u", (unsigned)sizeof(*cdict));
|
3207
3423
|
return cdict->workspaceSize + (cdict->dictBuffer ? cdict->dictContentSize : 0) + sizeof(*cdict);
|
3208
3424
|
}
|
3209
3425
|
|
@@ -3214,7 +3430,7 @@ static size_t ZSTD_initCDict_internal(
|
|
3214
3430
|
ZSTD_dictContentType_e dictContentType,
|
3215
3431
|
ZSTD_compressionParameters cParams)
|
3216
3432
|
{
|
3217
|
-
DEBUGLOG(3, "ZSTD_initCDict_internal (dictContentType:%u)", (
|
3433
|
+
DEBUGLOG(3, "ZSTD_initCDict_internal (dictContentType:%u)", (unsigned)dictContentType);
|
3218
3434
|
assert(!ZSTD_checkCParams(cParams));
|
3219
3435
|
cdict->matchState.cParams = cParams;
|
3220
3436
|
if ((dictLoadMethod == ZSTD_dlm_byRef) || (!dictBuffer) || (!dictSize)) {
|
@@ -3264,7 +3480,7 @@ ZSTD_CDict* ZSTD_createCDict_advanced(const void* dictBuffer, size_t dictSize,
|
|
3264
3480
|
ZSTD_dictContentType_e dictContentType,
|
3265
3481
|
ZSTD_compressionParameters cParams, ZSTD_customMem customMem)
|
3266
3482
|
{
|
3267
|
-
DEBUGLOG(3, "ZSTD_createCDict_advanced, mode %u", (
|
3483
|
+
DEBUGLOG(3, "ZSTD_createCDict_advanced, mode %u", (unsigned)dictContentType);
|
3268
3484
|
if (!customMem.customAlloc ^ !customMem.customFree) return NULL;
|
3269
3485
|
|
3270
3486
|
{ ZSTD_CDict* const cdict = (ZSTD_CDict*)ZSTD_malloc(sizeof(ZSTD_CDict), customMem);
|
@@ -3345,7 +3561,7 @@ const ZSTD_CDict* ZSTD_initStaticCDict(
|
|
3345
3561
|
void* ptr;
|
3346
3562
|
if ((size_t)workspace & 7) return NULL; /* 8-aligned */
|
3347
3563
|
DEBUGLOG(4, "(workspaceSize < neededSize) : (%u < %u) => %u",
|
3348
|
-
(
|
3564
|
+
(unsigned)workspaceSize, (unsigned)neededSize, (unsigned)(workspaceSize < neededSize));
|
3349
3565
|
if (workspaceSize < neededSize) return NULL;
|
3350
3566
|
|
3351
3567
|
if (dictLoadMethod == ZSTD_dlm_byCopy) {
|
@@ -3505,7 +3721,7 @@ static size_t ZSTD_resetCStream_internal(ZSTD_CStream* cctx,
|
|
3505
3721
|
size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize)
|
3506
3722
|
{
|
3507
3723
|
ZSTD_CCtx_params params = zcs->requestedParams;
|
3508
|
-
DEBUGLOG(4, "ZSTD_resetCStream: pledgedSrcSize = %u", (
|
3724
|
+
DEBUGLOG(4, "ZSTD_resetCStream: pledgedSrcSize = %u", (unsigned)pledgedSrcSize);
|
3509
3725
|
if (pledgedSrcSize==0) pledgedSrcSize = ZSTD_CONTENTSIZE_UNKNOWN;
|
3510
3726
|
params.fParams.contentSizeFlag = 1;
|
3511
3727
|
return ZSTD_resetCStream_internal(zcs, NULL, 0, ZSTD_dct_auto, zcs->cdict, params, pledgedSrcSize);
|
@@ -3525,7 +3741,7 @@ size_t ZSTD_initCStream_internal(ZSTD_CStream* zcs,
|
|
3525
3741
|
assert(!((dict) && (cdict))); /* either dict or cdict, not both */
|
3526
3742
|
|
3527
3743
|
if (dict && dictSize >= 8) {
|
3528
|
-
DEBUGLOG(4, "loading dictionary of size %u", (
|
3744
|
+
DEBUGLOG(4, "loading dictionary of size %u", (unsigned)dictSize);
|
3529
3745
|
if (zcs->staticSize) { /* static CCtx : never uses malloc */
|
3530
3746
|
/* incompatible with internal cdict creation */
|
3531
3747
|
return ERROR(memory_allocation);
|
@@ -3584,7 +3800,7 @@ size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
|
|
3584
3800
|
ZSTD_parameters params, unsigned long long pledgedSrcSize)
|
3585
3801
|
{
|
3586
3802
|
DEBUGLOG(4, "ZSTD_initCStream_advanced: pledgedSrcSize=%u, flag=%u",
|
3587
|
-
(
|
3803
|
+
(unsigned)pledgedSrcSize, params.fParams.contentSizeFlag);
|
3588
3804
|
CHECK_F( ZSTD_checkCParams(params.cParams) );
|
3589
3805
|
if ((pledgedSrcSize==0) && (params.fParams.contentSizeFlag==0)) pledgedSrcSize = ZSTD_CONTENTSIZE_UNKNOWN; /* for compatibility with older programs relying on this behavior. Users should now specify ZSTD_CONTENTSIZE_UNKNOWN. This line will be removed in the future. */
|
3590
3806
|
zcs->requestedParams = ZSTD_assignParamsToCCtxParams(zcs->requestedParams, params);
|
@@ -3612,8 +3828,15 @@ size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel)
|
|
3612
3828
|
|
3613
3829
|
/*====== Compression ======*/
|
3614
3830
|
|
3615
|
-
|
3616
|
-
|
3831
|
+
static size_t ZSTD_nextInputSizeHint(const ZSTD_CCtx* cctx)
|
3832
|
+
{
|
3833
|
+
size_t hintInSize = cctx->inBuffTarget - cctx->inBuffPos;
|
3834
|
+
if (hintInSize==0) hintInSize = cctx->blockSize;
|
3835
|
+
return hintInSize;
|
3836
|
+
}
|
3837
|
+
|
3838
|
+
static size_t ZSTD_limitCopy(void* dst, size_t dstCapacity,
|
3839
|
+
const void* src, size_t srcSize)
|
3617
3840
|
{
|
3618
3841
|
size_t const length = MIN(dstCapacity, srcSize);
|
3619
3842
|
if (length) memcpy(dst, src, length);
|
@@ -3621,7 +3844,7 @@ MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity,
|
|
3621
3844
|
}
|
3622
3845
|
|
3623
3846
|
/** ZSTD_compressStream_generic():
|
3624
|
-
* internal function for all *compressStream*() variants
|
3847
|
+
* internal function for all *compressStream*() variants
|
3625
3848
|
* non-static, because can be called from zstdmt_compress.c
|
3626
3849
|
* @return : hint size for next input */
|
3627
3850
|
size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
@@ -3638,7 +3861,7 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|
3638
3861
|
U32 someMoreWork = 1;
|
3639
3862
|
|
3640
3863
|
/* check expectations */
|
3641
|
-
DEBUGLOG(5, "ZSTD_compressStream_generic, flush=%u", (
|
3864
|
+
DEBUGLOG(5, "ZSTD_compressStream_generic, flush=%u", (unsigned)flushMode);
|
3642
3865
|
assert(zcs->inBuff != NULL);
|
3643
3866
|
assert(zcs->inBuffSize > 0);
|
3644
3867
|
assert(zcs->outBuff != NULL);
|
@@ -3660,12 +3883,12 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|
3660
3883
|
/* shortcut to compression pass directly into output buffer */
|
3661
3884
|
size_t const cSize = ZSTD_compressEnd(zcs,
|
3662
3885
|
op, oend-op, ip, iend-ip);
|
3663
|
-
DEBUGLOG(4, "ZSTD_compressEnd :
|
3886
|
+
DEBUGLOG(4, "ZSTD_compressEnd : cSize=%u", (unsigned)cSize);
|
3664
3887
|
if (ZSTD_isError(cSize)) return cSize;
|
3665
3888
|
ip = iend;
|
3666
3889
|
op += cSize;
|
3667
3890
|
zcs->frameEnded = 1;
|
3668
|
-
ZSTD_CCtx_reset(zcs);
|
3891
|
+
ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
|
3669
3892
|
someMoreWork = 0; break;
|
3670
3893
|
}
|
3671
3894
|
/* complete loading into inBuffer */
|
@@ -3709,7 +3932,7 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|
3709
3932
|
if (zcs->inBuffTarget > zcs->inBuffSize)
|
3710
3933
|
zcs->inBuffPos = 0, zcs->inBuffTarget = zcs->blockSize;
|
3711
3934
|
DEBUGLOG(5, "inBuffTarget:%u / inBuffSize:%u",
|
3712
|
-
(
|
3935
|
+
(unsigned)zcs->inBuffTarget, (unsigned)zcs->inBuffSize);
|
3713
3936
|
if (!lastBlock)
|
3714
3937
|
assert(zcs->inBuffTarget <= zcs->inBuffSize);
|
3715
3938
|
zcs->inToCompress = zcs->inBuffPos;
|
@@ -3718,7 +3941,7 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|
3718
3941
|
if (zcs->frameEnded) {
|
3719
3942
|
DEBUGLOG(5, "Frame completed directly in outBuffer");
|
3720
3943
|
someMoreWork = 0;
|
3721
|
-
ZSTD_CCtx_reset(zcs);
|
3944
|
+
ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
|
3722
3945
|
}
|
3723
3946
|
break;
|
3724
3947
|
}
|
@@ -3733,7 +3956,7 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|
3733
3956
|
size_t const flushed = ZSTD_limitCopy(op, oend-op,
|
3734
3957
|
zcs->outBuff + zcs->outBuffFlushedSize, toFlush);
|
3735
3958
|
DEBUGLOG(5, "toFlush: %u into %u ==> flushed: %u",
|
3736
|
-
(
|
3959
|
+
(unsigned)toFlush, (unsigned)(oend-op), (unsigned)flushed);
|
3737
3960
|
op += flushed;
|
3738
3961
|
zcs->outBuffFlushedSize += flushed;
|
3739
3962
|
if (toFlush!=flushed) {
|
@@ -3746,7 +3969,7 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|
3746
3969
|
if (zcs->frameEnded) {
|
3747
3970
|
DEBUGLOG(5, "Frame completed on flush");
|
3748
3971
|
someMoreWork = 0;
|
3749
|
-
ZSTD_CCtx_reset(zcs);
|
3972
|
+
ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
|
3750
3973
|
break;
|
3751
3974
|
}
|
3752
3975
|
zcs->streamStage = zcss_load;
|
@@ -3761,28 +3984,34 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|
3761
3984
|
input->pos = ip - istart;
|
3762
3985
|
output->pos = op - ostart;
|
3763
3986
|
if (zcs->frameEnded) return 0;
|
3764
|
-
|
3765
|
-
|
3766
|
-
|
3987
|
+
return ZSTD_nextInputSizeHint(zcs);
|
3988
|
+
}
|
3989
|
+
|
3990
|
+
static size_t ZSTD_nextInputSizeHint_MTorST(const ZSTD_CCtx* cctx)
|
3991
|
+
{
|
3992
|
+
#ifdef ZSTD_MULTITHREAD
|
3993
|
+
if (cctx->appliedParams.nbWorkers >= 1) {
|
3994
|
+
assert(cctx->mtctx != NULL);
|
3995
|
+
return ZSTDMT_nextInputSizeHint(cctx->mtctx);
|
3767
3996
|
}
|
3997
|
+
#endif
|
3998
|
+
return ZSTD_nextInputSizeHint(cctx);
|
3999
|
+
|
3768
4000
|
}
|
3769
4001
|
|
3770
4002
|
size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input)
|
3771
4003
|
{
|
3772
|
-
|
3773
|
-
|
3774
|
-
if (input->pos > input->size) return ERROR(GENERIC);
|
3775
|
-
|
3776
|
-
return ZSTD_compressStream_generic(zcs, output, input, ZSTD_e_continue);
|
4004
|
+
CHECK_F( ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue) );
|
4005
|
+
return ZSTD_nextInputSizeHint_MTorST(zcs);
|
3777
4006
|
}
|
3778
4007
|
|
3779
4008
|
|
3780
|
-
size_t
|
3781
|
-
|
3782
|
-
|
3783
|
-
|
4009
|
+
size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
4010
|
+
ZSTD_outBuffer* output,
|
4011
|
+
ZSTD_inBuffer* input,
|
4012
|
+
ZSTD_EndDirective endOp)
|
3784
4013
|
{
|
3785
|
-
DEBUGLOG(5, "
|
4014
|
+
DEBUGLOG(5, "ZSTD_compressStream2, endOp=%u ", (unsigned)endOp);
|
3786
4015
|
/* check conditions */
|
3787
4016
|
if (output->pos > output->size) return ERROR(GENERIC);
|
3788
4017
|
if (input->pos > input->size) return ERROR(GENERIC);
|
@@ -3792,9 +4021,9 @@ size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
|
|
3792
4021
|
if (cctx->streamStage == zcss_init) {
|
3793
4022
|
ZSTD_CCtx_params params = cctx->requestedParams;
|
3794
4023
|
ZSTD_prefixDict const prefixDict = cctx->prefixDict;
|
3795
|
-
memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict));
|
3796
|
-
assert(prefixDict.dict==NULL || cctx->cdict==NULL);
|
3797
|
-
DEBUGLOG(4, "
|
4024
|
+
memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* single usage */
|
4025
|
+
assert(prefixDict.dict==NULL || cctx->cdict==NULL); /* only one can be set */
|
4026
|
+
DEBUGLOG(4, "ZSTD_compressStream2 : transparent init stage");
|
3798
4027
|
if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = input->size + 1; /* auto-fix pledgedSrcSize */
|
3799
4028
|
params.cParams = ZSTD_getCParamsFromCCtxParams(
|
3800
4029
|
&cctx->requestedParams, cctx->pledgedSrcSizePlusOne-1, 0 /*dictSize*/);
|
@@ -3807,7 +4036,7 @@ size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
|
|
3807
4036
|
if (params.nbWorkers > 0) {
|
3808
4037
|
/* mt context creation */
|
3809
4038
|
if (cctx->mtctx == NULL) {
|
3810
|
-
DEBUGLOG(4, "
|
4039
|
+
DEBUGLOG(4, "ZSTD_compressStream2: creating new mtctx for nbWorkers=%u",
|
3811
4040
|
params.nbWorkers);
|
3812
4041
|
cctx->mtctx = ZSTDMT_createCCtx_advanced(params.nbWorkers, cctx->customMem);
|
3813
4042
|
if (cctx->mtctx == NULL) return ERROR(memory_allocation);
|
@@ -3829,6 +4058,7 @@ size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
|
|
3829
4058
|
assert(cctx->streamStage == zcss_load);
|
3830
4059
|
assert(cctx->appliedParams.nbWorkers == 0);
|
3831
4060
|
} }
|
4061
|
+
/* end of transparent initialization stage */
|
3832
4062
|
|
3833
4063
|
/* compression stage */
|
3834
4064
|
#ifdef ZSTD_MULTITHREAD
|
@@ -3840,18 +4070,18 @@ size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
|
|
3840
4070
|
{ size_t const flushMin = ZSTDMT_compressStream_generic(cctx->mtctx, output, input, endOp);
|
3841
4071
|
if ( ZSTD_isError(flushMin)
|
3842
4072
|
|| (endOp == ZSTD_e_end && flushMin == 0) ) { /* compression completed */
|
3843
|
-
ZSTD_CCtx_reset(cctx);
|
4073
|
+
ZSTD_CCtx_reset(cctx, ZSTD_reset_session_only);
|
3844
4074
|
}
|
3845
|
-
DEBUGLOG(5, "completed
|
4075
|
+
DEBUGLOG(5, "completed ZSTD_compressStream2 delegating to ZSTDMT_compressStream_generic");
|
3846
4076
|
return flushMin;
|
3847
4077
|
} }
|
3848
4078
|
#endif
|
3849
4079
|
CHECK_F( ZSTD_compressStream_generic(cctx, output, input, endOp) );
|
3850
|
-
DEBUGLOG(5, "completed
|
4080
|
+
DEBUGLOG(5, "completed ZSTD_compressStream2");
|
3851
4081
|
return cctx->outBuffContentSize - cctx->outBuffFlushedSize; /* remaining to flush */
|
3852
4082
|
}
|
3853
4083
|
|
3854
|
-
size_t
|
4084
|
+
size_t ZSTD_compressStream2_simpleArgs (
|
3855
4085
|
ZSTD_CCtx* cctx,
|
3856
4086
|
void* dst, size_t dstCapacity, size_t* dstPos,
|
3857
4087
|
const void* src, size_t srcSize, size_t* srcPos,
|
@@ -3859,13 +4089,33 @@ size_t ZSTD_compress_generic_simpleArgs (
|
|
3859
4089
|
{
|
3860
4090
|
ZSTD_outBuffer output = { dst, dstCapacity, *dstPos };
|
3861
4091
|
ZSTD_inBuffer input = { src, srcSize, *srcPos };
|
3862
|
-
/*
|
3863
|
-
size_t const cErr =
|
4092
|
+
/* ZSTD_compressStream2() will check validity of dstPos and srcPos */
|
4093
|
+
size_t const cErr = ZSTD_compressStream2(cctx, &output, &input, endOp);
|
3864
4094
|
*dstPos = output.pos;
|
3865
4095
|
*srcPos = input.pos;
|
3866
4096
|
return cErr;
|
3867
4097
|
}
|
3868
4098
|
|
4099
|
+
size_t ZSTD_compress2(ZSTD_CCtx* cctx,
|
4100
|
+
void* dst, size_t dstCapacity,
|
4101
|
+
const void* src, size_t srcSize)
|
4102
|
+
{
|
4103
|
+
ZSTD_CCtx_reset(cctx, ZSTD_reset_session_only);
|
4104
|
+
{ size_t oPos = 0;
|
4105
|
+
size_t iPos = 0;
|
4106
|
+
size_t const result = ZSTD_compressStream2_simpleArgs(cctx,
|
4107
|
+
dst, dstCapacity, &oPos,
|
4108
|
+
src, srcSize, &iPos,
|
4109
|
+
ZSTD_e_end);
|
4110
|
+
if (ZSTD_isError(result)) return result;
|
4111
|
+
if (result != 0) { /* compression not completed, due to lack of output space */
|
4112
|
+
assert(oPos == dstCapacity);
|
4113
|
+
return ERROR(dstSize_tooSmall);
|
4114
|
+
}
|
4115
|
+
assert(iPos == srcSize); /* all input is expected consumed */
|
4116
|
+
return oPos;
|
4117
|
+
}
|
4118
|
+
}
|
3869
4119
|
|
3870
4120
|
/*====== Finalize ======*/
|
3871
4121
|
|
@@ -3874,21 +4124,21 @@ size_t ZSTD_compress_generic_simpleArgs (
|
|
3874
4124
|
size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output)
|
3875
4125
|
{
|
3876
4126
|
ZSTD_inBuffer input = { NULL, 0, 0 };
|
3877
|
-
|
3878
|
-
CHECK_F( ZSTD_compressStream_generic(zcs, output, &input, ZSTD_e_flush) );
|
3879
|
-
return zcs->outBuffContentSize - zcs->outBuffFlushedSize; /* remaining to flush */
|
4127
|
+
return ZSTD_compressStream2(zcs, output, &input, ZSTD_e_flush);
|
3880
4128
|
}
|
3881
4129
|
|
3882
4130
|
|
3883
4131
|
size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output)
|
3884
4132
|
{
|
3885
4133
|
ZSTD_inBuffer input = { NULL, 0, 0 };
|
3886
|
-
|
3887
|
-
CHECK_F(
|
4134
|
+
size_t const remainingToFlush = ZSTD_compressStream2(zcs, output, &input, ZSTD_e_end);
|
4135
|
+
CHECK_F( remainingToFlush );
|
4136
|
+
if (zcs->appliedParams.nbWorkers > 0) return remainingToFlush; /* minimal estimation */
|
4137
|
+
/* single thread mode : attempt to calculate remaining to flush more precisely */
|
3888
4138
|
{ size_t const lastBlockSize = zcs->frameEnded ? 0 : ZSTD_BLOCKHEADERSIZE;
|
3889
4139
|
size_t const checksumSize = zcs->frameEnded ? 0 : zcs->appliedParams.fParams.checksumFlag * 4;
|
3890
|
-
size_t const toFlush =
|
3891
|
-
DEBUGLOG(4, "ZSTD_endStream : remaining to flush : %u", (
|
4140
|
+
size_t const toFlush = remainingToFlush + lastBlockSize + checksumSize;
|
4141
|
+
DEBUGLOG(4, "ZSTD_endStream : remaining to flush : %u", (unsigned)toFlush);
|
3892
4142
|
return toFlush;
|
3893
4143
|
}
|
3894
4144
|
}
|
@@ -3905,27 +4155,27 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV
|
|
3905
4155
|
/* W, C, H, S, L, TL, strat */
|
3906
4156
|
{ 19, 12, 13, 1, 6, 1, ZSTD_fast }, /* base for negative levels */
|
3907
4157
|
{ 19, 13, 14, 1, 7, 0, ZSTD_fast }, /* level 1 */
|
3908
|
-
{
|
3909
|
-
{
|
3910
|
-
{
|
3911
|
-
{
|
3912
|
-
{ 21,
|
3913
|
-
{ 21,
|
4158
|
+
{ 20, 15, 16, 1, 6, 0, ZSTD_fast }, /* level 2 */
|
4159
|
+
{ 21, 16, 17, 1, 5, 1, ZSTD_dfast }, /* level 3 */
|
4160
|
+
{ 21, 18, 18, 1, 5, 1, ZSTD_dfast }, /* level 4 */
|
4161
|
+
{ 21, 18, 19, 2, 5, 2, ZSTD_greedy }, /* level 5 */
|
4162
|
+
{ 21, 19, 19, 3, 5, 4, ZSTD_greedy }, /* level 6 */
|
4163
|
+
{ 21, 19, 19, 3, 5, 8, ZSTD_lazy }, /* level 7 */
|
3914
4164
|
{ 21, 19, 19, 3, 5, 16, ZSTD_lazy2 }, /* level 8 */
|
3915
4165
|
{ 21, 19, 20, 4, 5, 16, ZSTD_lazy2 }, /* level 9 */
|
3916
|
-
{
|
3917
|
-
{
|
3918
|
-
{ 22,
|
3919
|
-
{ 22, 21, 22,
|
3920
|
-
{ 22,
|
3921
|
-
{ 22,
|
3922
|
-
{ 22,
|
3923
|
-
{ 23,
|
3924
|
-
{ 23, 23, 22, 6, 3,
|
3925
|
-
{ 23, 24, 22, 7, 3,256,
|
3926
|
-
{ 25, 25, 23, 7, 3,256,
|
3927
|
-
{ 26, 26, 24, 7, 3,512,
|
3928
|
-
{ 27, 27, 25, 9, 3,999,
|
4166
|
+
{ 22, 20, 21, 4, 5, 16, ZSTD_lazy2 }, /* level 10 */
|
4167
|
+
{ 22, 21, 22, 4, 5, 16, ZSTD_lazy2 }, /* level 11 */
|
4168
|
+
{ 22, 21, 22, 5, 5, 16, ZSTD_lazy2 }, /* level 12 */
|
4169
|
+
{ 22, 21, 22, 5, 5, 32, ZSTD_btlazy2 }, /* level 13 */
|
4170
|
+
{ 22, 22, 23, 5, 5, 32, ZSTD_btlazy2 }, /* level 14 */
|
4171
|
+
{ 22, 23, 23, 6, 5, 32, ZSTD_btlazy2 }, /* level 15 */
|
4172
|
+
{ 22, 22, 22, 5, 5, 48, ZSTD_btopt }, /* level 16 */
|
4173
|
+
{ 23, 23, 22, 5, 4, 64, ZSTD_btopt }, /* level 17 */
|
4174
|
+
{ 23, 23, 22, 6, 3, 64, ZSTD_btultra }, /* level 18 */
|
4175
|
+
{ 23, 24, 22, 7, 3,256, ZSTD_btultra2}, /* level 19 */
|
4176
|
+
{ 25, 25, 23, 7, 3,256, ZSTD_btultra2}, /* level 20 */
|
4177
|
+
{ 26, 26, 24, 7, 3,512, ZSTD_btultra2}, /* level 21 */
|
4178
|
+
{ 27, 27, 25, 9, 3,999, ZSTD_btultra2}, /* level 22 */
|
3929
4179
|
},
|
3930
4180
|
{ /* for srcSize <= 256 KB */
|
3931
4181
|
/* W, C, H, S, L, T, strat */
|
@@ -3940,18 +4190,18 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV
|
|
3940
4190
|
{ 18, 18, 19, 4, 4, 8, ZSTD_lazy2 }, /* level 8 */
|
3941
4191
|
{ 18, 18, 19, 5, 4, 8, ZSTD_lazy2 }, /* level 9 */
|
3942
4192
|
{ 18, 18, 19, 6, 4, 8, ZSTD_lazy2 }, /* level 10 */
|
3943
|
-
{ 18, 18, 19, 5, 4,
|
3944
|
-
{ 18, 19, 19,
|
3945
|
-
{ 18,
|
3946
|
-
{ 18, 18, 19, 4,
|
3947
|
-
{ 18, 18, 19,
|
3948
|
-
{ 18, 19, 19, 6, 3,
|
3949
|
-
{ 18, 19, 19, 8, 3,
|
3950
|
-
{ 18, 19, 19,
|
3951
|
-
{ 18, 19, 19,
|
3952
|
-
{ 18, 19, 19,
|
3953
|
-
{ 18, 19, 19, 12, 3,512,
|
3954
|
-
{ 18, 19, 19, 13, 3,999,
|
4193
|
+
{ 18, 18, 19, 5, 4, 12, ZSTD_btlazy2 }, /* level 11.*/
|
4194
|
+
{ 18, 19, 19, 7, 4, 12, ZSTD_btlazy2 }, /* level 12.*/
|
4195
|
+
{ 18, 18, 19, 4, 4, 16, ZSTD_btopt }, /* level 13 */
|
4196
|
+
{ 18, 18, 19, 4, 3, 32, ZSTD_btopt }, /* level 14.*/
|
4197
|
+
{ 18, 18, 19, 6, 3,128, ZSTD_btopt }, /* level 15.*/
|
4198
|
+
{ 18, 19, 19, 6, 3,128, ZSTD_btultra }, /* level 16.*/
|
4199
|
+
{ 18, 19, 19, 8, 3,256, ZSTD_btultra }, /* level 17.*/
|
4200
|
+
{ 18, 19, 19, 6, 3,128, ZSTD_btultra2}, /* level 18.*/
|
4201
|
+
{ 18, 19, 19, 8, 3,256, ZSTD_btultra2}, /* level 19.*/
|
4202
|
+
{ 18, 19, 19, 10, 3,512, ZSTD_btultra2}, /* level 20.*/
|
4203
|
+
{ 18, 19, 19, 12, 3,512, ZSTD_btultra2}, /* level 21.*/
|
4204
|
+
{ 18, 19, 19, 13, 3,999, ZSTD_btultra2}, /* level 22.*/
|
3955
4205
|
},
|
3956
4206
|
{ /* for srcSize <= 128 KB */
|
3957
4207
|
/* W, C, H, S, L, T, strat */
|
@@ -3966,26 +4216,26 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV
|
|
3966
4216
|
{ 17, 17, 17, 4, 4, 8, ZSTD_lazy2 }, /* level 8 */
|
3967
4217
|
{ 17, 17, 17, 5, 4, 8, ZSTD_lazy2 }, /* level 9 */
|
3968
4218
|
{ 17, 17, 17, 6, 4, 8, ZSTD_lazy2 }, /* level 10 */
|
3969
|
-
{ 17, 17, 17,
|
3970
|
-
{ 17, 18, 17,
|
3971
|
-
{ 17, 18, 17,
|
3972
|
-
{ 17, 18, 17, 4,
|
3973
|
-
{ 17, 18, 17, 6, 3,
|
3974
|
-
{ 17, 18, 17,
|
3975
|
-
{ 17, 18, 17,
|
3976
|
-
{ 17, 18, 17,
|
3977
|
-
{ 17, 18, 17,
|
3978
|
-
{ 17, 18, 17,
|
3979
|
-
{ 17, 18, 17,
|
3980
|
-
{ 17, 18, 17, 11, 3,
|
4219
|
+
{ 17, 17, 17, 5, 4, 8, ZSTD_btlazy2 }, /* level 11 */
|
4220
|
+
{ 17, 18, 17, 7, 4, 12, ZSTD_btlazy2 }, /* level 12 */
|
4221
|
+
{ 17, 18, 17, 3, 4, 12, ZSTD_btopt }, /* level 13.*/
|
4222
|
+
{ 17, 18, 17, 4, 3, 32, ZSTD_btopt }, /* level 14.*/
|
4223
|
+
{ 17, 18, 17, 6, 3,256, ZSTD_btopt }, /* level 15.*/
|
4224
|
+
{ 17, 18, 17, 6, 3,128, ZSTD_btultra }, /* level 16.*/
|
4225
|
+
{ 17, 18, 17, 8, 3,256, ZSTD_btultra }, /* level 17.*/
|
4226
|
+
{ 17, 18, 17, 10, 3,512, ZSTD_btultra }, /* level 18.*/
|
4227
|
+
{ 17, 18, 17, 5, 3,256, ZSTD_btultra2}, /* level 19.*/
|
4228
|
+
{ 17, 18, 17, 7, 3,512, ZSTD_btultra2}, /* level 20.*/
|
4229
|
+
{ 17, 18, 17, 9, 3,512, ZSTD_btultra2}, /* level 21.*/
|
4230
|
+
{ 17, 18, 17, 11, 3,999, ZSTD_btultra2}, /* level 22.*/
|
3981
4231
|
},
|
3982
4232
|
{ /* for srcSize <= 16 KB */
|
3983
4233
|
/* W, C, H, S, L, T, strat */
|
3984
4234
|
{ 14, 12, 13, 1, 5, 1, ZSTD_fast }, /* base for negative levels */
|
3985
4235
|
{ 14, 14, 15, 1, 5, 0, ZSTD_fast }, /* level 1 */
|
3986
4236
|
{ 14, 14, 15, 1, 4, 0, ZSTD_fast }, /* level 2 */
|
3987
|
-
{ 14, 14,
|
3988
|
-
{ 14, 14, 14, 4, 4, 2, ZSTD_greedy }, /* level 4
|
4237
|
+
{ 14, 14, 15, 2, 4, 1, ZSTD_dfast }, /* level 3 */
|
4238
|
+
{ 14, 14, 14, 4, 4, 2, ZSTD_greedy }, /* level 4 */
|
3989
4239
|
{ 14, 14, 14, 3, 4, 4, ZSTD_lazy }, /* level 5.*/
|
3990
4240
|
{ 14, 14, 14, 4, 4, 8, ZSTD_lazy2 }, /* level 6 */
|
3991
4241
|
{ 14, 14, 14, 6, 4, 8, ZSTD_lazy2 }, /* level 7 */
|
@@ -3993,17 +4243,17 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV
|
|
3993
4243
|
{ 14, 15, 14, 5, 4, 8, ZSTD_btlazy2 }, /* level 9.*/
|
3994
4244
|
{ 14, 15, 14, 9, 4, 8, ZSTD_btlazy2 }, /* level 10.*/
|
3995
4245
|
{ 14, 15, 14, 3, 4, 12, ZSTD_btopt }, /* level 11.*/
|
3996
|
-
{ 14, 15, 14,
|
3997
|
-
{ 14, 15, 14,
|
3998
|
-
{ 14, 15, 15, 6, 3,
|
3999
|
-
{ 14, 15, 15,
|
4000
|
-
{ 14, 15, 15,
|
4001
|
-
{ 14, 15, 15, 6, 3,128,
|
4002
|
-
{ 14, 15, 15,
|
4003
|
-
{ 14, 15, 15,
|
4004
|
-
{ 14, 15, 15, 8, 3,
|
4005
|
-
{ 14, 15, 15, 9, 3,
|
4006
|
-
{ 14, 15, 15, 10, 3,
|
4246
|
+
{ 14, 15, 14, 4, 3, 24, ZSTD_btopt }, /* level 12.*/
|
4247
|
+
{ 14, 15, 14, 5, 3, 32, ZSTD_btultra }, /* level 13.*/
|
4248
|
+
{ 14, 15, 15, 6, 3, 64, ZSTD_btultra }, /* level 14.*/
|
4249
|
+
{ 14, 15, 15, 7, 3,256, ZSTD_btultra }, /* level 15.*/
|
4250
|
+
{ 14, 15, 15, 5, 3, 48, ZSTD_btultra2}, /* level 16.*/
|
4251
|
+
{ 14, 15, 15, 6, 3,128, ZSTD_btultra2}, /* level 17.*/
|
4252
|
+
{ 14, 15, 15, 7, 3,256, ZSTD_btultra2}, /* level 18.*/
|
4253
|
+
{ 14, 15, 15, 8, 3,256, ZSTD_btultra2}, /* level 19.*/
|
4254
|
+
{ 14, 15, 15, 8, 3,512, ZSTD_btultra2}, /* level 20.*/
|
4255
|
+
{ 14, 15, 15, 9, 3,512, ZSTD_btultra2}, /* level 21.*/
|
4256
|
+
{ 14, 15, 15, 10, 3,999, ZSTD_btultra2}, /* level 22.*/
|
4007
4257
|
},
|
4008
4258
|
};
|
4009
4259
|
|
@@ -4022,8 +4272,8 @@ ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long l
|
|
4022
4272
|
if (compressionLevel > ZSTD_MAX_CLEVEL) row = ZSTD_MAX_CLEVEL;
|
4023
4273
|
{ ZSTD_compressionParameters cp = ZSTD_defaultCParameters[tableID][row];
|
4024
4274
|
if (compressionLevel < 0) cp.targetLength = (unsigned)(-compressionLevel); /* acceleration factor */
|
4025
|
-
return ZSTD_adjustCParams_internal(cp, srcSizeHint, dictSize);
|
4026
|
-
|
4275
|
+
return ZSTD_adjustCParams_internal(cp, srcSizeHint, dictSize);
|
4276
|
+
}
|
4027
4277
|
}
|
4028
4278
|
|
4029
4279
|
/*! ZSTD_getParams() :
|