feat(cli): move patch-from window policy to Rust

Keep patch-from orchestration in C while extracting only the bounded window
selection and automatic-LDM decision into the Rust CLI leaf. The C caller
still computes the raw file window with FIO_highbit64, obtains cParams,
updates the memory limit, emits warnings and optimal-parser notes, and writes
comprParams->windowLog and prefs->ldmFlag. Rust receives only scalar policy
inputs and two output pointers, clamps the selected window to the target's
10..30/31 bounds, and compares the unclamped value strictly against cycleLog.
This preserves equality as no-LDM and keeps values above the maximum eligible
to trigger LDM. Focused unit tests cover both clamps and each comparison edge.

Test Plan:
- `cargo clippy --manifest-path rust/Cargo.toml --no-default-features
  --features compression` with library, `--benches`, and `--tests`, before and
  after formatting -- passed
- `cargo +nightly fmt --manifest-path rust/Cargo.toml --
  --config skip_children=true` and nightly rustfmt on the owned file -- passed
- `cargo test --manifest-path rust/cli/Cargo.toml --no-default-features
  --features cli,compression,decompression,benchmark fileio_prefs` -- 36 passed
- `make -C programs -j2 zstd` -- passed
- `make -C tests -j2 test-cli-tests` -- 41 passed
- Focused patch-from round trip and automatic long-mode trigger -- passed
This commit is contained in:
2026-07-18 15:19:30 +02:00
parent 98e99f08b0
commit a9b11394ce
2 changed files with 75 additions and 2 deletions
+12 -2
View File
@@ -329,6 +329,10 @@ int FIO_rust_checkFilenameCollisions(const char** filenameTable, unsigned nbFile
unsigned FIO_rust_highbit64(unsigned long long v);
unsigned long long FIO_rust_getLargestFileSize(const char** inFileNames, unsigned nbFiles);
unsigned FIO_rust_cycleLog(unsigned hashLog, int strategy);
void FIO_rust_patchFromWindowPolicy(unsigned fileWindowLog,
unsigned cycleLog,
unsigned* windowLog,
int* enableLdm);
void FIO_rust_setInBuffer(ZSTD_inBuffer* output, const void* buf, size_t s, size_t pos);
void FIO_rust_setOutBuffer(ZSTD_outBuffer* output, void* buf, size_t s, size_t pos);
const char* FIO_rust_determineCompressedName(const char* srcFileName, const char* outDirName, const char* suffix);
@@ -877,11 +881,17 @@ static void FIO_adjustParamsForPatchFromMode(FIO_prefs_t* const prefs,
{
unsigned const fileWindowLog = FIO_highbit64(maxSrcFileSize) + 1;
ZSTD_compressionParameters const cParams = ZSTD_getCParams(cLevel, (size_t)maxSrcFileSize, (size_t)dictSize);
unsigned windowLog;
int enableLdm;
FIO_adjustMemLimitForPatchFromMode(prefs, dictSize, maxSrcFileSize);
FIO_rust_patchFromWindowPolicy(fileWindowLog,
ZSTD_cycleLog(cParams.chainLog, cParams.strategy),
&windowLog,
&enableLdm);
if (fileWindowLog > ZSTD_WINDOWLOG_MAX)
DISPLAYLEVEL(1, "Max window log exceeded by file (compression ratio will suffer)\n");
comprParams->windowLog = MAX(ZSTD_WINDOWLOG_MIN, MIN(ZSTD_WINDOWLOG_MAX, fileWindowLog));
if (fileWindowLog > ZSTD_cycleLog(cParams.chainLog, cParams.strategy)) {
comprParams->windowLog = windowLog;
if (enableLdm) {
if (!prefs->ldmFlag)
DISPLAYLEVEL(2, "long mode automatically triggered\n");
FIO_setLdmFlag(prefs, 1);