1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-29 11:21:22 +03:00

changed ZSTD_c_compressionStrategy into ZSTD_c_strategy

also : fixed paramgrill, and limit conditions
This commit is contained in:
Yann Collet
2018-12-06 15:00:52 -08:00
parent e9448cdf4c
commit be9e561da4
12 changed files with 78 additions and 67 deletions

View File

@ -399,10 +399,10 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
ZSTD_lazy2=5, ZSTD_lazy2=5,
ZSTD_btlazy2=6, ZSTD_btlazy2=6,
ZSTD_btopt=7, ZSTD_btopt=7,
ZSTD_btultra=8 ZSTD_btultra=8,
</b>/* note : new strategies might be added in the future.<b> ZSTD_btultra2=9
Only the order (from fast to strong) is guaranteed, not the exact position. </b>/* note : new strategies _might_ be added in the future.<b>
new strategy names might be introduced, pushing the maximum number upward */ Only the order (from fast to strong) is guaranteed */
} ZSTD_strategy; } ZSTD_strategy;
</b></pre><BR> </b></pre><BR>
<pre><b>typedef enum { <pre><b>typedef enum {
@ -452,7 +452,7 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
* Distance between match sampling. * Distance between match sampling.
* Larger values make compression faster, and weaker. * Larger values make compression faster, and weaker.
* Special: value 0 means "use default targetLength". */ * 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, * The higher the value of selected strategy, the more complex it is,
* resulting in stronger and slower compression. * resulting in stronger and slower compression.
* Special: value 0 means "use default strategy". */ * Special: value 0 means "use default strategy". */

View File

@ -267,7 +267,7 @@ ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param)
bounds.upperBound = ZSTD_TARGETLENGTH_MAX; bounds.upperBound = ZSTD_TARGETLENGTH_MAX;
return bounds; return bounds;
case ZSTD_c_compressionStrategy: case ZSTD_c_strategy:
bounds.lowerBound = (int)ZSTD_fast; bounds.lowerBound = (int)ZSTD_fast;
bounds.upperBound = (int)ZSTD_btultra2; /* note : how to ensure at compile time that this is the highest value strategy ? */ bounds.upperBound = (int)ZSTD_btultra2; /* note : how to ensure at compile time that this is the highest value strategy ? */
return bounds; return bounds;
@ -349,12 +349,13 @@ ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param)
case ZSTD_c_format: case ZSTD_c_format:
ZSTD_STATIC_ASSERT((int)ZSTD_f_zstd1 < (int)ZSTD_f_zstd1_magicless); ZSTD_STATIC_ASSERT((int)ZSTD_f_zstd1 < (int)ZSTD_f_zstd1_magicless);
bounds.lowerBound = (int)ZSTD_f_zstd1; 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; return bounds;
case ZSTD_c_forceAttachDict: case ZSTD_c_forceAttachDict:
bounds.lowerBound = 0; ZSTD_STATIC_ASSERT((int)ZSTD_dictDefaultAttach < (int)ZSTD_dictForceCopy);
bounds.upperBound = 1; bounds.lowerBound = ZSTD_dictDefaultAttach;
bounds.upperBound = ZSTD_dictForceCopy; /* note : how to ensure at compile time that this is the highest value enum ? */
return bounds; return bounds;
default: default:
@ -392,7 +393,7 @@ static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
case ZSTD_c_searchLog: case ZSTD_c_searchLog:
case ZSTD_c_minMatch: case ZSTD_c_minMatch:
case ZSTD_c_targetLength: case ZSTD_c_targetLength:
case ZSTD_c_compressionStrategy: case ZSTD_c_strategy:
return 1; return 1;
case ZSTD_c_format: case ZSTD_c_format:
@ -441,7 +442,7 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
case ZSTD_c_searchLog: case ZSTD_c_searchLog:
case ZSTD_c_minMatch: case ZSTD_c_minMatch:
case ZSTD_c_targetLength: case ZSTD_c_targetLength:
case ZSTD_c_compressionStrategy: case ZSTD_c_strategy:
if (cctx->cdict) return ERROR(stage_wrong); if (cctx->cdict) return ERROR(stage_wrong);
return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
@ -534,13 +535,13 @@ size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* CCtxParams,
return CCtxParams->cParams.minMatch; return CCtxParams->cParams.minMatch;
case ZSTD_c_targetLength : case ZSTD_c_targetLength :
/* all values are valid. 0 => use default */ CLAMPCHECK(ZSTD_c_targetLength, value);
CCtxParams->cParams.targetLength = value; CCtxParams->cParams.targetLength = value;
return CCtxParams->cParams.targetLength; return CCtxParams->cParams.targetLength;
case ZSTD_c_compressionStrategy : case ZSTD_c_strategy :
if (value!=0) /* 0 => use default */ if (value!=0) /* 0 => use default */
CLAMPCHECK(ZSTD_c_compressionStrategy, value); CLAMPCHECK(ZSTD_c_strategy, value);
CCtxParams->cParams.strategy = (ZSTD_strategy)value; CCtxParams->cParams.strategy = (ZSTD_strategy)value;
return (size_t)CCtxParams->cParams.strategy; return (size_t)CCtxParams->cParams.strategy;
@ -666,7 +667,7 @@ size_t ZSTD_CCtxParam_getParameter(
case ZSTD_c_targetLength : case ZSTD_c_targetLength :
*value = CCtxParams->cParams.targetLength; *value = CCtxParams->cParams.targetLength;
break; break;
case ZSTD_c_compressionStrategy : case ZSTD_c_strategy :
*value = (unsigned)CCtxParams->cParams.strategy; *value = (unsigned)CCtxParams->cParams.strategy;
break; break;
case ZSTD_c_contentSizeFlag : case ZSTD_c_contentSizeFlag :
@ -849,10 +850,8 @@ size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
CLAMPCHECK(ZSTD_c_hashLog, cParams.hashLog); CLAMPCHECK(ZSTD_c_hashLog, cParams.hashLog);
CLAMPCHECK(ZSTD_c_searchLog, cParams.searchLog); CLAMPCHECK(ZSTD_c_searchLog, cParams.searchLog);
CLAMPCHECK(ZSTD_c_minMatch, cParams.minMatch); CLAMPCHECK(ZSTD_c_minMatch, cParams.minMatch);
ZSTD_STATIC_ASSERT(ZSTD_TARGETLENGTH_MIN == 0); CLAMPCHECK(ZSTD_c_targetLength,cParams.targetLength);
if (cParams.targetLength > ZSTD_TARGETLENGTH_MAX) CLAMPCHECK(ZSTD_c_strategy, cParams.strategy);
return ERROR(parameter_outOfBound);
CLAMPCHECK(ZSTD_c_compressionStrategy, cParams.strategy);
return 0; return 0;
} }
@ -862,20 +861,18 @@ size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
static ZSTD_compressionParameters static ZSTD_compressionParameters
ZSTD_clampCParams(ZSTD_compressionParameters cParams) ZSTD_clampCParams(ZSTD_compressionParameters cParams)
{ {
# define CLAMP(cParam, val) { \ # define CLAMP(cParam, val) { \
ZSTD_bounds const bounds = ZSTD_cParam_getBounds(cParam); \ ZSTD_bounds const bounds = ZSTD_cParam_getBounds(cParam); \
if (val<bounds.lowerBound) val=bounds.lowerBound; \ if ((int)val<bounds.lowerBound) val=bounds.lowerBound; \
else if (val>bounds.upperBound) val=bounds.upperBound; \ else if ((int)val>bounds.upperBound) val=bounds.upperBound; \
} }
CLAMP(ZSTD_c_windowLog, cParams.windowLog); CLAMP(ZSTD_c_windowLog, cParams.windowLog);
CLAMP(ZSTD_c_chainLog, cParams.chainLog); CLAMP(ZSTD_c_chainLog, cParams.chainLog);
CLAMP(ZSTD_c_hashLog, cParams.hashLog); CLAMP(ZSTD_c_hashLog, cParams.hashLog);
CLAMP(ZSTD_c_searchLog, cParams.searchLog); CLAMP(ZSTD_c_searchLog, cParams.searchLog);
CLAMP(ZSTD_c_minMatch, cParams.minMatch); CLAMP(ZSTD_c_minMatch, cParams.minMatch);
ZSTD_STATIC_ASSERT(ZSTD_TARGETLENGTH_MIN == 0); CLAMP(ZSTD_c_targetLength,cParams.targetLength);
if (cParams.targetLength > ZSTD_TARGETLENGTH_MAX) CLAMP(ZSTD_c_strategy, cParams.strategy);
cParams.targetLength = ZSTD_TARGETLENGTH_MAX;
CLAMP(ZSTD_c_compressionStrategy, cParams.strategy);
return cParams; return cParams;
} }
@ -1841,11 +1838,9 @@ static size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, cons
* note : use same formula for both situations */ * note : use same formula for both situations */
static size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat) static size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
{ {
U32 const minlog = (U32)strat - 1; U32 const minlog = (strat>=ZSTD_btultra) ? (U32)(strat) - 1 : 6;
ZSTD_STATIC_ASSERT(ZSTD_btopt == 7); ZSTD_STATIC_ASSERT(ZSTD_btultra == 8);
assert(strat >= ZSTD_btopt); return (srcSize >> minlog) + 2;}
return (srcSize >> minlog) + 2;
}
static size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf, static size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
ZSTD_hufCTables_t* nextHuf, ZSTD_hufCTables_t* nextHuf,
@ -2585,7 +2580,7 @@ ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMo
ZSTD_blockCompressor selectedCompressor; ZSTD_blockCompressor selectedCompressor;
ZSTD_STATIC_ASSERT((unsigned)ZSTD_fast == 1); 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]; selectedCompressor = blockCompressor[(int)dictMode][(int)strat];
assert(selectedCompressor != NULL); assert(selectedCompressor != NULL);
return selectedCompressor; return selectedCompressor;

View File

@ -188,6 +188,7 @@ static size_t ZSTD_ldm_fillFastTables(ZSTD_matchState_t* ms,
case ZSTD_btlazy2: case ZSTD_btlazy2:
case ZSTD_btopt: case ZSTD_btopt:
case ZSTD_btultra: case ZSTD_btultra:
case ZSTD_btultra2:
break; break;
default: default:
assert(0); /* not possible : not a valid strategy id */ assert(0); /* not possible : not a valid strategy id */

View File

@ -1162,5 +1162,5 @@ size_t ZSTD_compressBlock_btultra_extDict(
} }
/* note : no btultra2 variant for extDict nor dictMatchState, /* 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) */ * and is only specific for the first block (no prefix) */

View File

@ -26,6 +26,10 @@ size_t ZSTD_compressBlock_btopt(
size_t ZSTD_compressBlock_btultra( size_t ZSTD_compressBlock_btultra(
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); 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( 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],
@ -41,6 +45,10 @@ size_t ZSTD_compressBlock_btultra_extDict(
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); 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) #if defined (__cplusplus)
} }
#endif #endif

View File

@ -496,9 +496,8 @@ typedef enum { ZSTD_fast=1,
ZSTD_btopt=7, ZSTD_btopt=7,
ZSTD_btultra=8, ZSTD_btultra=8,
ZSTD_btultra2=9 ZSTD_btultra2=9
/* note : new strategies might be added in the future. /* note : new strategies _might_ be added in the future.
Only the order (from fast to strong) is guaranteed, not the exact position. Only the order (from fast to strong) is guaranteed */
new strategy names might be introduced, pushing the maximum number upward */
} ZSTD_strategy; } ZSTD_strategy;
@ -549,7 +548,7 @@ typedef enum {
* Distance between match sampling. * Distance between match sampling.
* Larger values make compression faster, and weaker. * Larger values make compression faster, and weaker.
* Special: value 0 means "use default targetLength". */ * 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, * The higher the value of selected strategy, the more complex it is,
* resulting in stronger and slower compression. * resulting in stronger and slower compression.
* Special: value 0 means "use default strategy". */ * Special: value 0 means "use default strategy". */

View File

@ -178,7 +178,7 @@ static void BMK_initCCtx(ZSTD_CCtx* ctx,
ZSTD_CCtx_setParameter(ctx, ZSTD_c_searchLog, comprParams->searchLog); ZSTD_CCtx_setParameter(ctx, ZSTD_c_searchLog, comprParams->searchLog);
ZSTD_CCtx_setParameter(ctx, ZSTD_c_minMatch, comprParams->minMatch); ZSTD_CCtx_setParameter(ctx, ZSTD_c_minMatch, comprParams->minMatch);
ZSTD_CCtx_setParameter(ctx, ZSTD_c_targetLength, comprParams->targetLength); 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); ZSTD_CCtx_loadDictionary(ctx, dictBuffer, dictBufferSize);
} }

View File

@ -551,7 +551,7 @@ static cRess_t FIO_createCResources(const char* dictFileName, int cLevel,
CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_searchLog, comprParams.searchLog) ); 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_minMatch, comprParams.minMatch) );
CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_targetLength, comprParams.targetLength) ); 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 */ /* multi-threading */
#ifdef ZSTD_MULTITHREAD #ifdef ZSTD_MULTITHREAD
DISPLAYLEVEL(5,"set nb workers = %u \n", g_nbWorkers); DISPLAYLEVEL(5,"set nb workers = %u \n", g_nbWorkers);

View File

@ -401,7 +401,7 @@ static size_t benchMem(U32 benchNb,
ZSTD_CCtx_setParameter(g_zcc, ZSTD_c_searchLog, cparams.searchLog); 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_minMatch, cparams.minMatch);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_c_targetLength, cparams.targetLength); 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_compressionLevel, cLevel);
@ -411,7 +411,7 @@ static size_t benchMem(U32 benchNb,
ZSTD_CCtx_setParameter(g_cstream, ZSTD_c_searchLog, cparams.searchLog); 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_minMatch, cparams.minMatch);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_c_targetLength, cparams.targetLength); 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 */ /* Preparation */
switch(benchNb) switch(benchNb)

View File

@ -13,7 +13,7 @@
#include "fuzz_helpers.h" #include "fuzz_helpers.h"
#include "zstd.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)); FUZZ_ZASSERT(ZSTD_CCtx_setParameter(cctx, param, value));
} }
@ -35,7 +35,7 @@ ZSTD_compressionParameters FUZZ_randomCParams(size_t srcSize, uint32_t *state)
cParams.minMatch = FUZZ_rand32(state, ZSTD_MINMATCH_MIN, cParams.minMatch = FUZZ_rand32(state, ZSTD_MINMATCH_MIN,
ZSTD_MINMATCH_MAX); ZSTD_MINMATCH_MAX);
cParams.targetLength = FUZZ_rand32(state, 0, 512); 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); return ZSTD_adjustCParams(cParams, srcSize, 0);
} }
@ -66,7 +66,7 @@ void FUZZ_setRandomParameters(ZSTD_CCtx *cctx, size_t srcSize, uint32_t *state)
set(cctx, ZSTD_c_searchLog, cParams.searchLog); set(cctx, ZSTD_c_searchLog, cParams.searchLog);
set(cctx, ZSTD_c_minMatch, cParams.minMatch); set(cctx, ZSTD_c_minMatch, cParams.minMatch);
set(cctx, ZSTD_c_targetLength, cParams.targetLength); set(cctx, ZSTD_c_targetLength, cParams.targetLength);
set(cctx, ZSTD_c_compressionStrategy, cParams.strategy); set(cctx, ZSTD_c_strategy, cParams.strategy);
/* Select frame parameters */ /* Select frame parameters */
setRand(cctx, ZSTD_c_contentSizeFlag, 0, 1, state); setRand(cctx, ZSTD_c_contentSizeFlag, 0, 1, state);
setRand(cctx, ZSTD_c_checksumFlag, 0, 1, state); setRand(cctx, ZSTD_c_checksumFlag, 0, 1, state);

View File

@ -75,20 +75,21 @@ static const int g_maxNbVariations = 64;
#define CLOG_RANGE (ZSTD_CHAINLOG_MAX - ZSTD_CHAINLOG_MIN + 1) #define CLOG_RANGE (ZSTD_CHAINLOG_MAX - ZSTD_CHAINLOG_MIN + 1)
#define HLOG_RANGE (ZSTD_HASHLOG_MAX - ZSTD_HASHLOG_MIN + 1) #define HLOG_RANGE (ZSTD_HASHLOG_MAX - ZSTD_HASHLOG_MIN + 1)
#define SLOG_RANGE (ZSTD_SEARCHLOG_MAX - ZSTD_SEARCHLOG_MIN + 1) #define SLOG_RANGE (ZSTD_SEARCHLOG_MAX - ZSTD_SEARCHLOG_MIN + 1)
#define MML_RANGE (ZSTD_MINMATCH_MAX - ZSTD_MINMATCH_MIN + 1) #define MML_RANGE (ZSTD_MINMATCH_MAX - ZSTD_MINMATCH_MIN + 1)
#define TLEN_RANGE 17 #define TLEN_RANGE 17
#define STRT_RANGE (ZSTD_btultra - ZSTD_fast + 1) #define STRT_RANGE (ZSTD_btultra2 - ZSTD_fast + 1)
#define FADT_RANGE 3 #define FADT_RANGE 3
#define CHECKTIME(r) { if(BMK_timeSpan(g_time) > g_timeLimit_s) { DEBUGOUTPUT("Time Limit Reached\n"); return r; } } #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 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 */ #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 ", "(none) ", "ZSTD_fast ", "ZSTD_dfast ",
"ZSTD_greedy ", "ZSTD_lazy ", "ZSTD_lazy2 ", "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 }; static const U32 tlen_table[TLEN_RANGE] = { 0, 1, 2, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 256, 512, 999 };
@ -114,13 +115,13 @@ typedef struct {
U32 vals[NUM_PARAMS]; U32 vals[NUM_PARAMS];
} paramValues_t; } paramValues_t;
/* maximum value of parameters */ /* minimum value of parameters */
static const U32 mintable[NUM_PARAMS] = 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 }; { 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] = 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 */ /* # of values parameters can take on */
static const U32 rangetable[NUM_PARAMS] = static const U32 rangetable[NUM_PARAMS] =
@ -128,7 +129,7 @@ static const U32 rangetable[NUM_PARAMS] =
/* ZSTD_cctxSetParameter() index to set */ /* ZSTD_cctxSetParameter() index to set */
static const ZSTD_cParameter cctxSetParamTable[NUM_PARAMS] = 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 */ /* names of parameters */
static const char* g_paramNames[NUM_PARAMS] = static const char* g_paramNames[NUM_PARAMS] =
@ -298,7 +299,7 @@ static paramValues_t sanitizeParams(paramValues_t params)
params.vals[clog_ind] = 0, params.vals[slog_ind] = 0; params.vals[clog_ind] = 0, params.vals[slog_ind] = 0;
if (params.vals[strt_ind] == ZSTD_dfast) if (params.vals[strt_ind] == ZSTD_dfast)
params.vals[slog_ind] = 0; 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; params.vals[tlen_ind] = 0;
return params; return params;
@ -1218,7 +1219,7 @@ static size_t sanitizeVarArray(varInds_t* varNew, const size_t varLength, const
if( !((varArray[i] == clog_ind && strat == ZSTD_fast) if( !((varArray[i] == clog_ind && strat == ZSTD_fast)
|| (varArray[i] == slog_ind && strat == ZSTD_fast) || (varArray[i] == slog_ind && strat == ZSTD_fast)
|| (varArray[i] == slog_ind && strat == ZSTD_dfast) || (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]; varNew[j] = varArray[i];
j++; j++;
} }
@ -1290,10 +1291,12 @@ static void memoTableSet(const memoTable_t* memoTableArray, const paramValues_t
} }
/* frees all allocated memotables */ /* frees all allocated memotables */
/* secret contract :
* mtAll is a table of (ZSTD_btultra2+1) memoTable_t */
static void freeMemoTableArray(memoTable_t* const mtAll) { static void freeMemoTableArray(memoTable_t* const mtAll) {
int i; int i;
if(mtAll == NULL) { return; } 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[i].table);
} }
free(mtAll); free(mtAll);
@ -1301,21 +1304,26 @@ static void freeMemoTableArray(memoTable_t* const mtAll) {
/* inits memotables for all (including mallocs), all strategies */ /* inits memotables for all (including mallocs), all strategies */
/* takes unsanitized varyParams */ /* takes unsanitized varyParams */
static memoTable_t* createMemoTableArray(const paramValues_t p, const varInds_t* const varyParams, const size_t varyLen, const U32 memoTableLog) { static memoTable_t*
memoTable_t* mtAll = (memoTable_t*)calloc(sizeof(memoTable_t),(ZSTD_btultra + 1)); createMemoTableArray(const paramValues_t p,
ZSTD_strategy i, stratMin = ZSTD_fast, stratMax = ZSTD_btultra; 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) { if(mtAll == NULL) {
return 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); mtAll[i].varLen = sanitizeVarArray(mtAll[i].varArray, varyLen, varyParams, i);
} }
/* no memoization */ /* no memoization */
if(memoTableLog == 0) { 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].tableType = noMemo;
mtAll[i].table = NULL; mtAll[i].table = NULL;
mtAll[i].tableLen = 0; mtAll[i].tableLen = 0;
@ -1661,7 +1669,7 @@ static void BMK_init_level_constraints(int bytePerSec_level1)
g_level_constraint[l].cSpeed_min = (g_level_constraint[l-1].cSpeed_min * 49) / 64; 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].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].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 */
} } } }
} }
@ -2134,7 +2142,7 @@ static int nextStrategy(const int currentStrategy, const int bestStrategy) {
int candidate = 2 * bestStrategy - currentStrategy - 1; int candidate = 2 * bestStrategy - currentStrategy - 1;
if(candidate < 1) { if(candidate < 1) {
candidate = currentStrategy + 1; candidate = currentStrategy + 1;
if(candidate > (int)ZSTD_btultra) { if(candidate > (int)ZSTD_btultra2) {
return 0; return 0;
} else { } else {
return candidate; return candidate;
@ -2144,7 +2152,7 @@ static int nextStrategy(const int currentStrategy, const int bestStrategy) {
} }
} else { /* bestStrategy >= currentStrategy */ } else { /* bestStrategy >= currentStrategy */
int candidate = 2 * bestStrategy - currentStrategy; int candidate = 2 * bestStrategy - currentStrategy;
if(candidate > (int)ZSTD_btultra) { if(candidate > (int)ZSTD_btultra2) {
candidate = currentStrategy - 1; candidate = currentStrategy - 1;
if(candidate < 1) { if(candidate < 1) {
return 0; return 0;

View File

@ -230,7 +230,7 @@ static size_t getCCtxParams(ZSTD_CCtx* zc, ZSTD_parameters* savedParams)
CHECK_RET_Z(ZSTD_CCtx_getParameter(zc, ZSTD_c_searchLog, (int*)&savedParams->cParams.searchLog)); 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_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_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; savedParams->cParams.strategy = value;
CHECK_RET_Z(ZSTD_CCtx_getParameter(zc, ZSTD_c_checksumFlag, &savedParams->fParams.checksumFlag)); CHECK_RET_Z(ZSTD_CCtx_getParameter(zc, ZSTD_c_checksumFlag, &savedParams->fParams.checksumFlag));