feat(compress): move matchfinder policy to Rust
Move row matchfinder, block-splitter, LDM, chain-table, external-repcode, and tagged-dictionary policy leaves into Rust while preserving the existing C helper names and private parameter flow. Add boundary coverage for each policy decision. Test Plan: cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression; cargo clippy --manifest-path rust/Cargo.toml; cargo clippy --manifest-path rust/Cargo.toml --benches; cargo clippy --manifest-path rust/Cargo.toml --tests; make -B -C lib -j2 lib; make -B -C tests -j2 test-cli-tests; make -B -C tests -j2 test-zstream
This commit is contained in:
@@ -79,6 +79,17 @@ ZSTD_parameters ZSTD_rust_params_makeParams(ZSTD_compressionParameters cParams);
|
||||
size_t ZSTD_rust_params_maxNbSeq(size_t blockSize, U32 minMatch,
|
||||
int useSequenceProducer);
|
||||
size_t ZSTD_rust_params_resolveMaxBlockSize(size_t maxBlockSize);
|
||||
int ZSTD_rust_params_rowMatchFinderSupported(int strategy);
|
||||
int ZSTD_rust_params_rowMatchFinderUsed(int strategy, int mode);
|
||||
int ZSTD_rust_params_resolveRowMatchFinderMode(
|
||||
int mode, ZSTD_compressionParameters cParams);
|
||||
int ZSTD_rust_params_resolveBlockSplitterMode(
|
||||
int mode, ZSTD_compressionParameters cParams);
|
||||
int ZSTD_rust_params_allocateChainTable(int strategy, int mode, int forDDSDict);
|
||||
int ZSTD_rust_params_resolveEnableLdm(
|
||||
int mode, ZSTD_compressionParameters cParams);
|
||||
int ZSTD_rust_params_resolveExternalRepcodeSearch(int mode, int cLevel);
|
||||
int ZSTD_rust_params_cdictIndicesAreTagged(ZSTD_compressionParameters cParams);
|
||||
|
||||
/* CCtx parameter state is mirrored by rust/src/zstd_compress_params_api.rs.
|
||||
* Rust owns parameter bounds and clamping; C exposes only the
|
||||
@@ -437,7 +448,7 @@ const SeqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx) { return &(ctx->seqStor
|
||||
|
||||
/* Returns true if the strategy supports using a row based matchfinder */
|
||||
static int ZSTD_rowMatchFinderSupported(const ZSTD_strategy strategy) {
|
||||
return (strategy >= ZSTD_greedy && strategy <= ZSTD_lazy2);
|
||||
return ZSTD_rust_params_rowMatchFinderSupported((int)strategy);
|
||||
}
|
||||
|
||||
/* Returns true if the strategy and useRowMatchFinder mode indicate that we will use the row based matchfinder
|
||||
@@ -445,24 +456,21 @@ static int ZSTD_rowMatchFinderSupported(const ZSTD_strategy strategy) {
|
||||
*/
|
||||
static int ZSTD_rowMatchFinderUsed(const ZSTD_strategy strategy, const ZSTD_ParamSwitch_e mode) {
|
||||
assert(mode != ZSTD_ps_auto);
|
||||
return ZSTD_rowMatchFinderSupported(strategy) && (mode == ZSTD_ps_enable);
|
||||
return ZSTD_rust_params_rowMatchFinderUsed((int)strategy, (int)mode);
|
||||
}
|
||||
|
||||
/* Returns row matchfinder usage given an initial mode and cParams */
|
||||
static ZSTD_ParamSwitch_e ZSTD_resolveRowMatchFinderMode(ZSTD_ParamSwitch_e mode,
|
||||
const ZSTD_compressionParameters* const cParams) {
|
||||
if (mode != ZSTD_ps_auto) return mode; /* if requested enabled, but no SIMD, we still will use row matchfinder */
|
||||
mode = ZSTD_ps_disable;
|
||||
if (!ZSTD_rowMatchFinderSupported(cParams->strategy)) return mode;
|
||||
if (cParams->windowLog > 14) mode = ZSTD_ps_enable;
|
||||
return mode;
|
||||
return (ZSTD_ParamSwitch_e)ZSTD_rust_params_resolveRowMatchFinderMode(
|
||||
(int)mode, *cParams);
|
||||
}
|
||||
|
||||
/* Returns block splitter usage (generally speaking, when using slower/stronger compression modes) */
|
||||
static ZSTD_ParamSwitch_e ZSTD_resolveBlockSplitterMode(ZSTD_ParamSwitch_e mode,
|
||||
const ZSTD_compressionParameters* const cParams) {
|
||||
if (mode != ZSTD_ps_auto) return mode;
|
||||
return (cParams->strategy >= ZSTD_btopt && cParams->windowLog >= 17) ? ZSTD_ps_enable : ZSTD_ps_disable;
|
||||
return (ZSTD_ParamSwitch_e)ZSTD_rust_params_resolveBlockSplitterMode(
|
||||
(int)mode, *cParams);
|
||||
}
|
||||
|
||||
/* Returns 1 if the arguments indicate that we should allocate a chainTable, 0 otherwise */
|
||||
@@ -470,10 +478,8 @@ static int ZSTD_allocateChainTable(const ZSTD_strategy strategy,
|
||||
const ZSTD_ParamSwitch_e useRowMatchFinder,
|
||||
const U32 forDDSDict) {
|
||||
assert(useRowMatchFinder != ZSTD_ps_auto);
|
||||
/* We always should allocate a chaintable if we are allocating a matchstate for a DDS dictionary matchstate.
|
||||
* We do not allocate a chaintable if we are using ZSTD_fast, or are using the row-based matchfinder.
|
||||
*/
|
||||
return forDDSDict || ((strategy != ZSTD_fast) && !ZSTD_rowMatchFinderUsed(strategy, useRowMatchFinder));
|
||||
return ZSTD_rust_params_allocateChainTable(
|
||||
(int)strategy, (int)useRowMatchFinder, (int)forDDSDict);
|
||||
}
|
||||
|
||||
/* Returns ZSTD_ps_enable if compression parameters are such that we should
|
||||
@@ -482,8 +488,8 @@ static int ZSTD_allocateChainTable(const ZSTD_strategy strategy,
|
||||
*/
|
||||
static ZSTD_ParamSwitch_e ZSTD_resolveEnableLdm(ZSTD_ParamSwitch_e mode,
|
||||
const ZSTD_compressionParameters* const cParams) {
|
||||
if (mode != ZSTD_ps_auto) return mode;
|
||||
return (cParams->strategy >= ZSTD_btopt && cParams->windowLog >= 27) ? ZSTD_ps_enable : ZSTD_ps_disable;
|
||||
return (ZSTD_ParamSwitch_e)ZSTD_rust_params_resolveEnableLdm(
|
||||
(int)mode, *cParams);
|
||||
}
|
||||
|
||||
static int ZSTD_resolveExternalSequenceValidation(int mode) {
|
||||
@@ -496,18 +502,14 @@ static size_t ZSTD_resolveMaxBlockSize(size_t maxBlockSize) {
|
||||
}
|
||||
|
||||
static ZSTD_ParamSwitch_e ZSTD_resolveExternalRepcodeSearch(ZSTD_ParamSwitch_e value, int cLevel) {
|
||||
if (value != ZSTD_ps_auto) return value;
|
||||
if (cLevel < 10) {
|
||||
return ZSTD_ps_disable;
|
||||
} else {
|
||||
return ZSTD_ps_enable;
|
||||
}
|
||||
return (ZSTD_ParamSwitch_e)ZSTD_rust_params_resolveExternalRepcodeSearch(
|
||||
(int)value, cLevel);
|
||||
}
|
||||
|
||||
/* Returns 1 if compression parameters are such that CDict hashtable and chaintable indices are tagged.
|
||||
* If so, the tags need to be removed in ZSTD_resetCCtx_byCopyingCDict. */
|
||||
static int ZSTD_CDictIndicesAreTagged(const ZSTD_compressionParameters* const cParams) {
|
||||
return cParams->strategy == ZSTD_fast || cParams->strategy == ZSTD_dfast;
|
||||
return ZSTD_rust_params_cdictIndicesAreTagged(*cParams);
|
||||
}
|
||||
|
||||
static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams(
|
||||
|
||||
Reference in New Issue
Block a user