ZSTD_lazy2=5,
ZSTD_btlazy2=6,
ZSTD_btopt=7,
- ZSTD_btultra=8
- </b>/* note : new strategies might be added in the future.<b>
- Only the order (from fast to strong) is guaranteed, not the exact position.
- new strategy names might be introduced, pushing the maximum number upward */
+ ZSTD_btultra=8,
+ ZSTD_btultra2=9
+ </b>/* note : new strategies _might_ be added in the future.<b>
+ Only the order (from fast to strong) is guaranteed */
} ZSTD_strategy;
</b></pre><BR>
<pre><b>typedef enum {
* Distance between match sampling.
* Larger values make compression faster, and weaker.
* Special: value 0 means "use default targetLength". */
- ZSTD_c_compressionStrategy=107, </b>/* See ZSTD_strategy enum definition.<b>
+ ZSTD_c_strategy=107, </b>/* See ZSTD_strategy enum definition.<b>
* The higher the value of selected strategy, the more complex it is,
* resulting in stronger and slower compression.
* Special: value 0 means "use default strategy". */
bounds.upperBound = ZSTD_TARGETLENGTH_MAX;
return bounds;
- case ZSTD_c_compressionStrategy:
+ case ZSTD_c_strategy:
bounds.lowerBound = (int)ZSTD_fast;
bounds.upperBound = (int)ZSTD_btultra2; /* note : how to ensure at compile time that this is the highest value strategy ? */
return bounds;
case ZSTD_c_format:
ZSTD_STATIC_ASSERT((int)ZSTD_f_zstd1 < (int)ZSTD_f_zstd1_magicless);
bounds.lowerBound = (int)ZSTD_f_zstd1;
- bounds.upperBound = (int)ZSTD_f_zstd1_magicless;
+ bounds.upperBound = (int)ZSTD_f_zstd1_magicless; /* note : how to ensure at compile time that this is the highest value enum ? */
return bounds;
case ZSTD_c_forceAttachDict:
- bounds.lowerBound = 0;
- bounds.upperBound = 1;
+ ZSTD_STATIC_ASSERT((int)ZSTD_dictDefaultAttach < (int)ZSTD_dictForceCopy);
+ bounds.lowerBound = ZSTD_dictDefaultAttach;
+ bounds.upperBound = ZSTD_dictForceCopy; /* note : how to ensure at compile time that this is the highest value enum ? */
return bounds;
default:
case ZSTD_c_searchLog:
case ZSTD_c_minMatch:
case ZSTD_c_targetLength:
- case ZSTD_c_compressionStrategy:
+ case ZSTD_c_strategy:
return 1;
case ZSTD_c_format:
case ZSTD_c_searchLog:
case ZSTD_c_minMatch:
case ZSTD_c_targetLength:
- case ZSTD_c_compressionStrategy:
+ case ZSTD_c_strategy:
if (cctx->cdict) return ERROR(stage_wrong);
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
return CCtxParams->cParams.minMatch;
case ZSTD_c_targetLength :
- /* all values are valid. 0 => use default */
+ CLAMPCHECK(ZSTD_c_targetLength, value);
CCtxParams->cParams.targetLength = value;
return CCtxParams->cParams.targetLength;
- case ZSTD_c_compressionStrategy :
+ case ZSTD_c_strategy :
if (value!=0) /* 0 => use default */
- CLAMPCHECK(ZSTD_c_compressionStrategy, value);
+ CLAMPCHECK(ZSTD_c_strategy, value);
CCtxParams->cParams.strategy = (ZSTD_strategy)value;
return (size_t)CCtxParams->cParams.strategy;
case ZSTD_c_targetLength :
*value = CCtxParams->cParams.targetLength;
break;
- case ZSTD_c_compressionStrategy :
+ case ZSTD_c_strategy :
*value = (unsigned)CCtxParams->cParams.strategy;
break;
case ZSTD_c_contentSizeFlag :
CLAMPCHECK(ZSTD_c_hashLog, cParams.hashLog);
CLAMPCHECK(ZSTD_c_searchLog, cParams.searchLog);
CLAMPCHECK(ZSTD_c_minMatch, cParams.minMatch);
- ZSTD_STATIC_ASSERT(ZSTD_TARGETLENGTH_MIN == 0);
- if (cParams.targetLength > ZSTD_TARGETLENGTH_MAX)
- return ERROR(parameter_outOfBound);
- CLAMPCHECK(ZSTD_c_compressionStrategy, cParams.strategy);
+ CLAMPCHECK(ZSTD_c_targetLength,cParams.targetLength);
+ CLAMPCHECK(ZSTD_c_strategy, cParams.strategy);
return 0;
}
static ZSTD_compressionParameters
ZSTD_clampCParams(ZSTD_compressionParameters cParams)
{
-# define CLAMP(cParam, val) { \
- ZSTD_bounds const bounds = ZSTD_cParam_getBounds(cParam); \
- if (val<bounds.lowerBound) val=bounds.lowerBound; \
- else if (val>bounds.upperBound) val=bounds.upperBound; \
+# define CLAMP(cParam, val) { \
+ ZSTD_bounds const bounds = ZSTD_cParam_getBounds(cParam); \
+ if ((int)val<bounds.lowerBound) val=bounds.lowerBound; \
+ else if ((int)val>bounds.upperBound) val=bounds.upperBound; \
}
CLAMP(ZSTD_c_windowLog, cParams.windowLog);
CLAMP(ZSTD_c_chainLog, cParams.chainLog);
CLAMP(ZSTD_c_hashLog, cParams.hashLog);
CLAMP(ZSTD_c_searchLog, cParams.searchLog);
CLAMP(ZSTD_c_minMatch, cParams.minMatch);
- ZSTD_STATIC_ASSERT(ZSTD_TARGETLENGTH_MIN == 0);
- if (cParams.targetLength > ZSTD_TARGETLENGTH_MAX)
- cParams.targetLength = ZSTD_TARGETLENGTH_MAX;
- CLAMP(ZSTD_c_compressionStrategy, cParams.strategy);
+ CLAMP(ZSTD_c_targetLength,cParams.targetLength);
+ CLAMP(ZSTD_c_strategy, cParams.strategy);
return cParams;
}
* note : use same formula for both situations */
static size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
{
- U32 const minlog = (U32)strat - 1;
- ZSTD_STATIC_ASSERT(ZSTD_btopt == 7);
- assert(strat >= ZSTD_btopt);
- return (srcSize >> minlog) + 2;
-}
+ U32 const minlog = (strat>=ZSTD_btultra) ? (U32)(strat) - 1 : 6;
+ ZSTD_STATIC_ASSERT(ZSTD_btultra == 8);
+ return (srcSize >> minlog) + 2;}
static size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
ZSTD_hufCTables_t* nextHuf,
ZSTD_blockCompressor selectedCompressor;
ZSTD_STATIC_ASSERT((unsigned)ZSTD_fast == 1);
- assert(ZSTD_cParam_withinBounds(ZSTD_c_compressionStrategy, strat));
+ assert(ZSTD_cParam_withinBounds(ZSTD_c_strategy, strat));
selectedCompressor = blockCompressor[(int)dictMode][(int)strat];
assert(selectedCompressor != NULL);
return selectedCompressor;
case ZSTD_btlazy2:
case ZSTD_btopt:
case ZSTD_btultra:
+ case ZSTD_btultra2:
break;
default:
assert(0); /* not possible : not a valid strategy id */
}
/* note : no btultra2 variant for extDict nor dictMatchState,
- * tbecause btultra2 is not meant to work with dictionaries
+ * because btultra2 is not meant to work with dictionaries
* and is only specific for the first block (no prefix) */
size_t ZSTD_compressBlock_btultra(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
void const* src, size_t srcSize);
+size_t ZSTD_compressBlock_btultra2(
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
+ void const* src, size_t srcSize);
+
size_t ZSTD_compressBlock_btopt_dictMatchState(
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
void const* src, size_t srcSize);
+ /* note : no btultra2 variant for extDict nor dictMatchState,
+ * because btultra2 is not meant to work with dictionaries
+ * and is only specific for the first block (no prefix) */
+
#if defined (__cplusplus)
}
#endif
ZSTD_btopt=7,
ZSTD_btultra=8,
ZSTD_btultra2=9
- /* note : new strategies might be added in the future.
- Only the order (from fast to strong) is guaranteed, not the exact position.
- new strategy names might be introduced, pushing the maximum number upward */
+ /* note : new strategies _might_ be added in the future.
+ Only the order (from fast to strong) is guaranteed */
} ZSTD_strategy;
* Distance between match sampling.
* Larger values make compression faster, and weaker.
* Special: value 0 means "use default targetLength". */
- ZSTD_c_compressionStrategy=107, /* See ZSTD_strategy enum definition.
+ ZSTD_c_strategy=107, /* See ZSTD_strategy enum definition.
* The higher the value of selected strategy, the more complex it is,
* resulting in stronger and slower compression.
* Special: value 0 means "use default strategy". */
ZSTD_CCtx_setParameter(ctx, ZSTD_c_searchLog, comprParams->searchLog);
ZSTD_CCtx_setParameter(ctx, ZSTD_c_minMatch, comprParams->minMatch);
ZSTD_CCtx_setParameter(ctx, ZSTD_c_targetLength, comprParams->targetLength);
- ZSTD_CCtx_setParameter(ctx, ZSTD_c_compressionStrategy, comprParams->strategy);
+ ZSTD_CCtx_setParameter(ctx, ZSTD_c_strategy, comprParams->strategy);
ZSTD_CCtx_loadDictionary(ctx, dictBuffer, dictBufferSize);
}
CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_searchLog, comprParams.searchLog) );
CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_minMatch, comprParams.minMatch) );
CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_targetLength, comprParams.targetLength) );
- CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_compressionStrategy, comprParams.strategy) );
+ CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_strategy, comprParams.strategy) );
/* multi-threading */
#ifdef ZSTD_MULTITHREAD
DISPLAYLEVEL(5,"set nb workers = %u \n", g_nbWorkers);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_c_searchLog, cparams.searchLog);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_c_minMatch, cparams.minMatch);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_c_targetLength, cparams.targetLength);
- ZSTD_CCtx_setParameter(g_zcc, ZSTD_c_compressionStrategy, cparams.strategy);
+ ZSTD_CCtx_setParameter(g_zcc, ZSTD_c_strategy, cparams.strategy);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_c_compressionLevel, cLevel);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_c_searchLog, cparams.searchLog);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_c_minMatch, cparams.minMatch);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_c_targetLength, cparams.targetLength);
- ZSTD_CCtx_setParameter(g_cstream, ZSTD_c_compressionStrategy, cparams.strategy);
+ ZSTD_CCtx_setParameter(g_cstream, ZSTD_c_strategy, cparams.strategy);
/* Preparation */
switch(benchNb)
#include "fuzz_helpers.h"
#include "zstd.h"
-static void set(ZSTD_CCtx *cctx, ZSTD_cParameter param, unsigned value)
+static void set(ZSTD_CCtx *cctx, ZSTD_cParameter param, int value)
{
FUZZ_ZASSERT(ZSTD_CCtx_setParameter(cctx, param, value));
}
cParams.minMatch = FUZZ_rand32(state, ZSTD_MINMATCH_MIN,
ZSTD_MINMATCH_MAX);
cParams.targetLength = FUZZ_rand32(state, 0, 512);
- cParams.strategy = FUZZ_rand32(state, ZSTD_fast, ZSTD_btultra);
+ cParams.strategy = FUZZ_rand32(state, ZSTD_fast, ZSTD_btultra2);
return ZSTD_adjustCParams(cParams, srcSize, 0);
}
set(cctx, ZSTD_c_searchLog, cParams.searchLog);
set(cctx, ZSTD_c_minMatch, cParams.minMatch);
set(cctx, ZSTD_c_targetLength, cParams.targetLength);
- set(cctx, ZSTD_c_compressionStrategy, cParams.strategy);
+ set(cctx, ZSTD_c_strategy, cParams.strategy);
/* Select frame parameters */
setRand(cctx, ZSTD_c_contentSizeFlag, 0, 1, state);
setRand(cctx, ZSTD_c_checksumFlag, 0, 1, state);
#define CLOG_RANGE (ZSTD_CHAINLOG_MAX - ZSTD_CHAINLOG_MIN + 1)
#define HLOG_RANGE (ZSTD_HASHLOG_MAX - ZSTD_HASHLOG_MIN + 1)
#define SLOG_RANGE (ZSTD_SEARCHLOG_MAX - ZSTD_SEARCHLOG_MIN + 1)
-#define MML_RANGE (ZSTD_MINMATCH_MAX - ZSTD_MINMATCH_MIN + 1)
-#define TLEN_RANGE 17
-#define STRT_RANGE (ZSTD_btultra - ZSTD_fast + 1)
-#define FADT_RANGE 3
+#define MML_RANGE (ZSTD_MINMATCH_MAX - ZSTD_MINMATCH_MIN + 1)
+#define TLEN_RANGE 17
+#define STRT_RANGE (ZSTD_btultra2 - ZSTD_fast + 1)
+#define FADT_RANGE 3
#define CHECKTIME(r) { if(BMK_timeSpan(g_time) > g_timeLimit_s) { DEBUGOUTPUT("Time Limit Reached\n"); return r; } }
#define CHECKTIMEGT(ret, val, _gototag) {if(BMK_timeSpan(g_time) > g_timeLimit_s) { DEBUGOUTPUT("Time Limit Reached\n"); ret = val; goto _gototag; } }
#define PARAM_UNSET ((U32)-2) /* can't be -1 b/c fadt uses -1 */
-static const char* g_stratName[ZSTD_btultra+1] = {
+static const char* g_stratName[ZSTD_btultra2+1] = {
"(none) ", "ZSTD_fast ", "ZSTD_dfast ",
"ZSTD_greedy ", "ZSTD_lazy ", "ZSTD_lazy2 ",
- "ZSTD_btlazy2 ", "ZSTD_btopt ", "ZSTD_btultra "};
+ "ZSTD_btlazy2 ", "ZSTD_btopt ", "ZSTD_btultra ",
+ "ZSTD_btultra2"};
static const U32 tlen_table[TLEN_RANGE] = { 0, 1, 2, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 256, 512, 999 };
U32 vals[NUM_PARAMS];
} paramValues_t;
-/* maximum value of parameters */
+/* minimum value of parameters */
static const U32 mintable[NUM_PARAMS] =
{ ZSTD_WINDOWLOG_MIN, ZSTD_CHAINLOG_MIN, ZSTD_HASHLOG_MIN, ZSTD_SEARCHLOG_MIN, ZSTD_MINMATCH_MIN, ZSTD_TARGETLENGTH_MIN, ZSTD_fast, FADT_MIN };
-/* minimum value of parameters */
+/* maximum value of parameters */
static const U32 maxtable[NUM_PARAMS] =
- { ZSTD_WINDOWLOG_MAX, ZSTD_CHAINLOG_MAX, ZSTD_HASHLOG_MAX, ZSTD_SEARCHLOG_MAX, ZSTD_MINMATCH_MAX, ZSTD_TARGETLENGTH_MAX, ZSTD_btultra, FADT_MAX };
+ { ZSTD_WINDOWLOG_MAX, ZSTD_CHAINLOG_MAX, ZSTD_HASHLOG_MAX, ZSTD_SEARCHLOG_MAX, ZSTD_MINMATCH_MAX, ZSTD_TARGETLENGTH_MAX, ZSTD_btultra2, FADT_MAX };
/* # of values parameters can take on */
static const U32 rangetable[NUM_PARAMS] =
/* ZSTD_cctxSetParameter() index to set */
static const ZSTD_cParameter cctxSetParamTable[NUM_PARAMS] =
- { ZSTD_c_windowLog, ZSTD_c_chainLog, ZSTD_c_hashLog, ZSTD_c_searchLog, ZSTD_c_minMatch, ZSTD_c_targetLength, ZSTD_c_compressionStrategy, ZSTD_c_forceAttachDict };
+ { ZSTD_c_windowLog, ZSTD_c_chainLog, ZSTD_c_hashLog, ZSTD_c_searchLog, ZSTD_c_minMatch, ZSTD_c_targetLength, ZSTD_c_strategy, ZSTD_c_forceAttachDict };
/* names of parameters */
static const char* g_paramNames[NUM_PARAMS] =
params.vals[clog_ind] = 0, params.vals[slog_ind] = 0;
if (params.vals[strt_ind] == ZSTD_dfast)
params.vals[slog_ind] = 0;
- if (params.vals[strt_ind] != ZSTD_btopt && params.vals[strt_ind] != ZSTD_btultra && params.vals[strt_ind] != ZSTD_fast)
+ if ( (params.vals[strt_ind] < ZSTD_btopt) && (params.vals[strt_ind] != ZSTD_fast) )
params.vals[tlen_ind] = 0;
return params;
if( !((varArray[i] == clog_ind && strat == ZSTD_fast)
|| (varArray[i] == slog_ind && strat == ZSTD_fast)
|| (varArray[i] == slog_ind && strat == ZSTD_dfast)
- || (varArray[i] == tlen_ind && strat != ZSTD_btopt && strat != ZSTD_btultra && strat != ZSTD_fast))) {
+ || (varArray[i] == tlen_ind && strat < ZSTD_btopt && strat != ZSTD_fast))) {
varNew[j] = varArray[i];
j++;
}
}
/* frees all allocated memotables */
+/* secret contract :
+ * mtAll is a table of (ZSTD_btultra2+1) memoTable_t */
static void freeMemoTableArray(memoTable_t* const mtAll) {
int i;
if(mtAll == NULL) { return; }
- for(i = 1; i <= (int)ZSTD_btultra; i++) {
+ for(i = 1; i <= (int)ZSTD_btultra2; i++) {
free(mtAll[i].table);
}
free(mtAll);
/* inits memotables for all (including mallocs), all strategies */
/* takes unsanitized varyParams */
-static memoTable_t* createMemoTableArray(const paramValues_t p, const varInds_t* const varyParams, const size_t varyLen, const U32 memoTableLog) {
- memoTable_t* mtAll = (memoTable_t*)calloc(sizeof(memoTable_t),(ZSTD_btultra + 1));
- ZSTD_strategy i, stratMin = ZSTD_fast, stratMax = ZSTD_btultra;
+static memoTable_t*
+createMemoTableArray(const paramValues_t p,
+ const varInds_t* const varyParams,
+ const size_t varyLen,
+ const U32 memoTableLog)
+{
+ memoTable_t* const mtAll = (memoTable_t*)calloc(sizeof(memoTable_t),(ZSTD_btultra2 + 1));
+ ZSTD_strategy i, stratMin = ZSTD_fast, stratMax = ZSTD_btultra2;
if(mtAll == NULL) {
return NULL;
}
- for(i = 1; i <= (int)ZSTD_btultra; i++) {
+ for(i = 1; i <= (int)ZSTD_btultra2; i++) {
mtAll[i].varLen = sanitizeVarArray(mtAll[i].varArray, varyLen, varyParams, i);
}
/* no memoization */
if(memoTableLog == 0) {
- for(i = 1; i <= (int)ZSTD_btultra; i++) {
+ for(i = 1; i <= (int)ZSTD_btultra2; i++) {
mtAll[i].tableType = noMemo;
mtAll[i].table = NULL;
mtAll[i].tableLen = 0;
g_level_constraint[l].cSpeed_min = (g_level_constraint[l-1].cSpeed_min * 49) / 64;
g_level_constraint[l].dSpeed_min = 0.;
g_level_constraint[l].windowLog_max = (l<20) ? 23 : l+5; /* only --ultra levels >= 20 can use windowlog > 23 */
- g_level_constraint[l].strategy_max = (l<19) ? ZSTD_btopt : ZSTD_btultra; /* level 19 is allowed to use btultra */
+ g_level_constraint[l].strategy_max = ZSTD_btultra2; /* level 19 is allowed to use btultra */
} }
}
int candidate = 2 * bestStrategy - currentStrategy - 1;
if(candidate < 1) {
candidate = currentStrategy + 1;
- if(candidate > (int)ZSTD_btultra) {
+ if(candidate > (int)ZSTD_btultra2) {
return 0;
} else {
return candidate;
}
} else { /* bestStrategy >= currentStrategy */
int candidate = 2 * bestStrategy - currentStrategy;
- if(candidate > (int)ZSTD_btultra) {
+ if(candidate > (int)ZSTD_btultra2) {
candidate = currentStrategy - 1;
if(candidate < 1) {
return 0;
CHECK_RET_Z(ZSTD_CCtx_getParameter(zc, ZSTD_c_searchLog, (int*)&savedParams->cParams.searchLog));
CHECK_RET_Z(ZSTD_CCtx_getParameter(zc, ZSTD_c_minMatch, (int*)&savedParams->cParams.minMatch));
CHECK_RET_Z(ZSTD_CCtx_getParameter(zc, ZSTD_c_targetLength, (int*)&savedParams->cParams.targetLength));
- CHECK_RET_Z(ZSTD_CCtx_getParameter(zc, ZSTD_c_compressionStrategy, &value));
+ CHECK_RET_Z(ZSTD_CCtx_getParameter(zc, ZSTD_c_strategy, &value));
savedParams->cParams.strategy = value;
CHECK_RET_Z(ZSTD_CCtx_getParameter(zc, ZSTD_c_checksumFlag, &savedParams->fParams.checksumFlag));