Skip to content

Commit

Permalink
Use new paramSwitch enum for row matchfinder and block splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
senhuang42 committed Sep 20, 2021
1 parent 6392c38 commit 4e4ad30
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 183 deletions.
169 changes: 81 additions & 88 deletions lib/compress/zstd_compress.c

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions lib/compress/zstd_compress_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ typedef struct {
U32 offCodeSumBasePrice; /* to compare to log2(offreq) */
ZSTD_OptPrice_e priceType; /* prices can be determined dynamically, or follow a pre-defined cost structure */
const ZSTD_entropyCTables_t* symbolCosts; /* pre-calculated dictionary statistics */
ZSTD_literalCompressionMode_e literalCompressionMode;
ZSTD_paramSwitch_e literalCompressionMode;
} optState_t;

typedef struct {
Expand Down Expand Up @@ -297,7 +297,7 @@ struct ZSTD_CCtx_params_s {
* There is no guarantee that hint is close to actual source size */

ZSTD_dictAttachPref_e attachDictPref;
ZSTD_literalCompressionMode_e literalCompressionMode;
ZSTD_paramSwitch_e literalCompressionMode;

/* Multithreading: used to pass parameters to mtctx */
int nbWorkers;
Expand All @@ -320,10 +320,10 @@ struct ZSTD_CCtx_params_s {
int validateSequences;

/* Block splitting */
int splitBlocks;
ZSTD_paramSwitch_e useBlockSplitter;

/* Param for deciding whether to use row-based matchfinder */
ZSTD_useRowMatchFinderMode_e useRowMatchFinder;
ZSTD_paramSwitch_e useRowMatchFinder;

/* Always load a dictionary in ext-dict mode (not prefix mode)? */
int deterministicRefPrefix;
Expand Down Expand Up @@ -444,7 +444,7 @@ typedef enum {
typedef size_t (*ZSTD_blockCompressor) (
ZSTD_matchState_t* bs, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
void const* src, size_t srcSize);
ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_useRowMatchFinderMode_e rowMatchfinderMode, ZSTD_dictMode_e dictMode);
ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_paramSwitch_e rowMatchfinderMode, ZSTD_dictMode_e dictMode);


MEM_STATIC U32 ZSTD_LLcode(U32 litLength)
Expand Down Expand Up @@ -551,17 +551,17 @@ MEM_STATIC size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
return (srcSize >> minlog) + 2;
}

MEM_STATIC int ZSTD_disableLiteralsCompression(const ZSTD_CCtx_params* cctxParams)
MEM_STATIC int ZSTD_literalsCompressionIsDisabled(const ZSTD_CCtx_params* cctxParams)
{
switch (cctxParams->literalCompressionMode) {
case ZSTD_lcm_huffman:
case ZSTD_ps_enable:
return 0;
case ZSTD_lcm_uncompressed:
case ZSTD_ps_disable:
return 1;
default:
assert(0 /* impossible: pre-validated */);
/* fall-through */
case ZSTD_lcm_auto:
case ZSTD_ps_auto:
return (cctxParams->cParams.strategy == ZSTD_fast) && (cctxParams->cParams.targetLength > 0);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/compress/zstd_ldm.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes) {

size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
ZSTD_useRowMatchFinderMode_e useRowMatchFinder,
ZSTD_paramSwitch_e useRowMatchFinder,
void const* src, size_t srcSize)
{
const ZSTD_compressionParameters* const cParams = &ms->cParams;
Expand Down
2 changes: 1 addition & 1 deletion lib/compress/zstd_ldm.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ size_t ZSTD_ldm_generateSequences(
*/
size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
ZSTD_useRowMatchFinderMode_e useRowMatchFinder,
ZSTD_paramSwitch_e useRowMatchFinder,
void const* src, size_t srcSize);

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/compress/zstd_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ MEM_STATIC double ZSTD_fCost(U32 price)

static int ZSTD_compressedLiterals(optState_t const* const optPtr)
{
return optPtr->literalCompressionMode != ZSTD_lcm_uncompressed;
return optPtr->literalCompressionMode != ZSTD_ps_disable;
}

static void ZSTD_setBasePrices(optState_t* optPtr, int optLevel)
Expand Down
64 changes: 34 additions & 30 deletions lib/zstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ typedef enum {
* ZSTD_c_stableOutBuffer
* ZSTD_c_blockDelimiters
* ZSTD_c_validateSequences
* ZSTD_c_splitBlocks
* ZSTD_c_useBlockSplitter
* ZSTD_c_useRowMatchFinder
* Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
* note : never ever use experimentalParam? names directly;
Expand Down Expand Up @@ -1290,19 +1290,14 @@ typedef enum {
} ZSTD_dictAttachPref_e;

typedef enum {
ZSTD_lcm_auto = 0, /**< Automatically determine the compression mode based on the compression level.
* Negative compression levels will be uncompressed, and positive compression
* levels will be compressed. */
ZSTD_lcm_huffman = 1, /**< Always attempt Huffman compression. Uncompressed literals will still be
* emitted if Huffman compression is not profitable. */
ZSTD_lcm_uncompressed = 2 /**< Always emit uncompressed literals. */
} ZSTD_literalCompressionMode_e;

typedef enum {
ZSTD_urm_auto = 0, /* Automatically determine whether or not we use row matchfinder */
ZSTD_urm_disableRowMatchFinder = 1, /* Never use row matchfinder */
ZSTD_urm_enableRowMatchFinder = 2 /* Always use row matchfinder when applicable */
} ZSTD_useRowMatchFinderMode_e;
/* Note: This enum controls features which are conditionally beneficial. Zstd typically will make a final
* decision on whether or not to enable the feature (ZSTD_ps_auto), but setting the switch to ZSTD_ps_enable
* or ZSTD_ps_disable allow for a force enable/disable the feature.
*/
ZSTD_ps_auto = 0, /* Let the library automatically determine whether the feature shall be enabled */
ZSTD_ps_disable = 1, /* Do not use the feature */
ZSTD_ps_enable = 2 /* Force-enable the feature */
} ZSTD_paramSwitch_e;

/***************************************
* Frame size functions
Expand Down Expand Up @@ -1729,9 +1724,15 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre
* See the comments on that enum for an explanation of the feature. */
#define ZSTD_c_forceAttachDict ZSTD_c_experimentalParam4

/* Controls how the literals are compressed (default is auto).
* The value must be of type ZSTD_literalCompressionMode_e.
* See ZSTD_literalCompressionMode_e enum definition for details.
/* Controlled with ZSTD_paramSwitch_e enum.
* Default is ZSTD_ps_auto.
* Set to ZSTD_ps_disable to never compress literals.
* Set to ZSTD_ps_enable to always compress literals. (Note: uncompressed literals
* may still be emitted if huffman is not beneficial to use.)
*
* By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
* literals compression based on the compression parameters - specifically,
* negative compression levels do not use literal compression.
*/
#define ZSTD_c_literalCompressionMode ZSTD_c_experimentalParam5

Expand Down Expand Up @@ -1883,23 +1884,26 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre
*/
#define ZSTD_c_validateSequences ZSTD_c_experimentalParam12

/* ZSTD_c_splitBlocks
* Default is 0 == disabled. Set to 1 to enable block splitting.
/* ZSTD_c_useBlockSplitter
* Controlled with ZSTD_paramSwitch_e enum.
* Default is ZSTD_ps_auto.
* Set to ZSTD_ps_disable to never use block splitter.
* Set to ZSTD_ps_enable to always use block splitter.
*
* Will attempt to split blocks in order to improve compression ratio at the cost of speed.
* By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
* block splitting based on the compression parameters.
*/
#define ZSTD_c_splitBlocks ZSTD_c_experimentalParam13
#define ZSTD_c_useBlockSplitter ZSTD_c_experimentalParam13

/* ZSTD_c_useRowMatchFinder
* Default is ZSTD_urm_auto.
* Controlled with ZSTD_useRowMatchFinderMode_e enum.
*
* By default, in ZSTD_urm_auto, when finalizing the compression parameters, the library
* will decide at runtime whether to use the row-based matchfinder based on support for SIMD
* instructions as well as the windowLog.
*
* Set to ZSTD_urm_disableRowMatchFinder to never use row-based matchfinder.
* Set to ZSTD_urm_enableRowMatchFinder to force usage of row-based matchfinder.
* Controlled with ZSTD_paramSwitch_e enum.
* Default is ZSTD_ps_auto.
* Set to ZSTD_ps_disable to never use row-based matchfinder.
* Set to ZSTD_ps_enable to force usage of row-based matchfinder.
*
* By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
* the row-based matchfinder based on support for SIMD instructions and the window log.
* Note that this only pertains to compression strategies: greedy, lazy, and lazy2
*/
#define ZSTD_c_useRowMatchFinder ZSTD_c_experimentalParam14

Expand Down
2 changes: 1 addition & 1 deletion programs/benchzstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ BMK_advancedParams_t BMK_initAdvancedParams(void) {
0, /* ldmHashLog */
0, /* ldmBuckSizeLog */
0, /* ldmHashRateLog */
ZSTD_lcm_auto, /* literalCompressionMode */
ZSTD_ps_auto, /* literalCompressionMode */
0 /* useRowMatchFinder */
};
return res;
Expand Down
2 changes: 1 addition & 1 deletion programs/benchzstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ typedef struct {
int ldmHashLog;
int ldmBucketSizeLog;
int ldmHashRateLog;
ZSTD_literalCompressionMode_e literalCompressionMode;
ZSTD_paramSwitch_e literalCompressionMode;
int useRowMatchFinder; /* use row-based matchfinder if possible */
} BMK_advancedParams_t;

Expand Down
6 changes: 3 additions & 3 deletions programs/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ struct FIO_prefs_s {
size_t targetCBlockSize;
int srcSizeHint;
int testMode;
ZSTD_literalCompressionMode_e literalCompressionMode;
ZSTD_paramSwitch_e literalCompressionMode;

/* IO preferences */
U32 removeSrcFile;
Expand Down Expand Up @@ -392,7 +392,7 @@ FIO_prefs_t* FIO_createPreferences(void)
ret->targetCBlockSize = 0;
ret->srcSizeHint = 0;
ret->testMode = 0;
ret->literalCompressionMode = ZSTD_lcm_auto;
ret->literalCompressionMode = ZSTD_ps_auto;
ret->excludeCompressedFiles = 0;
ret->allowBlockDevices = 0;
return ret;
Expand Down Expand Up @@ -510,7 +510,7 @@ void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode) {

void FIO_setLiteralCompressionMode(
FIO_prefs_t* const prefs,
ZSTD_literalCompressionMode_e mode) {
ZSTD_paramSwitch_e mode) {
prefs->literalCompressionMode = mode;
}

Expand Down
2 changes: 1 addition & 1 deletion programs/fileio.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint);
void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode);
void FIO_setLiteralCompressionMode(
FIO_prefs_t* const prefs,
ZSTD_literalCompressionMode_e mode);
ZSTD_paramSwitch_e mode);

void FIO_setProgressSetting(FIO_progressSetting_e progressSetting);
void FIO_setNotificationLevel(int level);
Expand Down
6 changes: 3 additions & 3 deletions programs/zstdcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ int main(int argCount, const char* argv[])
#ifndef ZSTD_NOBENCH
BMK_advancedParams_t benchParams = BMK_initAdvancedParams();
#endif
ZSTD_literalCompressionMode_e literalCompressionMode = ZSTD_lcm_auto;
ZSTD_paramSwitch_e literalCompressionMode = ZSTD_ps_auto;


/* init */
Expand Down Expand Up @@ -900,8 +900,8 @@ int main(int argCount, const char* argv[])
if (!strcmp(argument, "--format=lz4")) { suffix = LZ4_EXTENSION; FIO_setCompressionType(prefs, FIO_lz4Compression); continue; }
#endif
if (!strcmp(argument, "--rsyncable")) { rsyncable = 1; continue; }
if (!strcmp(argument, "--compress-literals")) { literalCompressionMode = ZSTD_lcm_huffman; continue; }
if (!strcmp(argument, "--no-compress-literals")) { literalCompressionMode = ZSTD_lcm_uncompressed; continue; }
if (!strcmp(argument, "--compress-literals")) { literalCompressionMode = ZSTD_ps_enable; continue; }
if (!strcmp(argument, "--no-compress-literals")) { literalCompressionMode = ZSTD_ps_disable; continue; }
if (!strcmp(argument, "--no-progress")) { FIO_setProgressSetting(FIO_ps_never); continue; }
if (!strcmp(argument, "--progress")) { FIO_setProgressSetting(FIO_ps_always); continue; }
if (!strcmp(argument, "--exclude-compressed")) { FIO_setExcludeCompressedFile(prefs, 1); continue; }
Expand Down
2 changes: 1 addition & 1 deletion tests/fuzz/zstd_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void FUZZ_setRandomParameters(ZSTD_CCtx *cctx, size_t srcSize, FUZZ_dataProducer
setRand(cctx, ZSTD_c_forceMaxWindow, 0, 1, producer);
setRand(cctx, ZSTD_c_literalCompressionMode, 0, 2, producer);
setRand(cctx, ZSTD_c_forceAttachDict, 0, 2, producer);
setRand(cctx, ZSTD_c_splitBlocks, 0, 1, producer);
setRand(cctx, ZSTD_c_useBlockSplitter, 0, 2, producer);
setRand(cctx, ZSTD_c_deterministicRefPrefix, 0, 1, producer);
if (FUZZ_dataProducer_uint32Range(producer, 0, 1) == 0) {
setRand(cctx, ZSTD_c_srcSizeHint, ZSTD_SRCSIZEHINT_MIN, 2 * srcSize, producer);
Expand Down
6 changes: 3 additions & 3 deletions tests/fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ static int basicUnitTests(U32 const seed, double compressibility)

DISPLAYLEVEL(3, "test%3i : compress with block splitting : ", testNb++)
{ ZSTD_CCtx* cctx = ZSTD_createCCtx();
CHECK( ZSTD_CCtx_setParameter(cctx, ZSTD_c_splitBlocks, 1) );
CHECK( ZSTD_CCtx_setParameter(cctx, ZSTD_c_useBlockSplitter, ZSTD_ps_enable) );
cSize = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize, CNBuffer, CNBuffSize);
CHECK(cSize);
ZSTD_freeCCtx(cctx);
Expand All @@ -1732,7 +1732,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
CHECK( ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, 2) );
cSize1 = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize, CNBuffer, CNBuffSize);
CHECK(cSize1);
CHECK( ZSTD_CCtx_setParameter(cctx, ZSTD_c_literalCompressionMode, ZSTD_lcm_uncompressed) );
CHECK( ZSTD_CCtx_setParameter(cctx, ZSTD_c_literalCompressionMode, ZSTD_ps_disable) );
cSize2 = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize, CNBuffer, CNBuffSize);
CHECK(cSize2);
CHECK_LT(cSize1, cSize2);
Expand Down Expand Up @@ -2019,7 +2019,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
ZSTD_CCtx* const cctx = ZSTD_createCCtx();
size_t nodict_cSize;
ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, l);
ZSTD_CCtx_setParameter(cctx, ZSTD_c_useRowMatchFinder, ZSTD_urm_enableRowMatchFinder);
ZSTD_CCtx_setParameter(cctx, ZSTD_c_useRowMatchFinder, ZSTD_ps_enable);
nodict_cSize = ZSTD_compress2(cctx, compressedBuffer, compressedBufferSize,
contentStart, contentSize);
if (nodict_cSize > target_nodict_cSize[l]) {
Expand Down
8 changes: 4 additions & 4 deletions tests/regression/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static config_t mt_ldm = {

static param_value_t mt_advanced_param_values[] = {
{.param = ZSTD_c_nbWorkers, .value = 2},
{.param = ZSTD_c_literalCompressionMode, .value = ZSTD_lcm_uncompressed},
{.param = ZSTD_c_literalCompressionMode, .value = ZSTD_ps_disable},
};

static config_t mt_advanced = {
Expand Down Expand Up @@ -258,7 +258,7 @@ static config_t small_clog = {

static param_value_t const uncompressed_literals_param_values[] = {
{.param = ZSTD_c_compressionLevel, .value = 3},
{.param = ZSTD_c_literalCompressionMode, .value = ZSTD_lcm_uncompressed},
{.param = ZSTD_c_literalCompressionMode, .value = ZSTD_ps_disable},
};

static config_t uncompressed_literals = {
Expand All @@ -269,7 +269,7 @@ static config_t uncompressed_literals = {

static param_value_t const uncompressed_literals_opt_param_values[] = {
{.param = ZSTD_c_compressionLevel, .value = 19},
{.param = ZSTD_c_literalCompressionMode, .value = ZSTD_lcm_uncompressed},
{.param = ZSTD_c_literalCompressionMode, .value = ZSTD_ps_disable},
};

static config_t uncompressed_literals_opt = {
Expand All @@ -280,7 +280,7 @@ static config_t uncompressed_literals_opt = {

static param_value_t const huffman_literals_param_values[] = {
{.param = ZSTD_c_compressionLevel, .value = -1},
{.param = ZSTD_c_literalCompressionMode, .value = ZSTD_lcm_huffman},
{.param = ZSTD_c_literalCompressionMode, .value = ZSTD_ps_disable},
};

static config_t huffman_literals = {
Expand Down
Loading

0 comments on commit 4e4ad30

Please sign in to comment.