feat(compress): move Double-Fast dictionary fill to Rust

Replace the dictionary-content Double-Fast callback with a live-field
projection and call the existing Rust table-fill leaf directly. The
projection keeps hash tables, window base, match-state index, and parameters
live through the window/publication callbacks, preserving the timing behavior
of the former C adapter. Preserve the excluded-DFast assertion path and the
34-word dictionary bridge layout.

Test Plan:
- git diff --check
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo check --manifest-path rust/Cargo.toml --tests
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -A clippy::manual-bits -D warnings
- ulimit -v 41943040; make -j1
- capped strategy-2 compress/decompress round trip with cmp
- Full original suite deferred to the next serialized verification step
This commit is contained in:
2026-07-21 21:33:37 +02:00
parent de6c837d7f
commit f89ae75898
2 changed files with 195 additions and 29 deletions
+59 -19
View File
@@ -2805,8 +2805,45 @@ typedef char ZSTD_rust_load_dictionary_fast_table_layout[
&& sizeof(ZSTD_rust_loadDictionaryContentFastTableState)
== 5 * sizeof(void*) + 2 * sizeof(int))
? 1 : -1];
typedef void (*ZSTD_rust_loadDictionaryContent_fillTable_f)(
void* context, const void* iend, int dtlm, int tfp);
/* The Double-Fast dictionary-table leaf is also implemented in Rust. Keep
* pointers to the live match-state fields because window/publish callbacks
* run before the Rust orchestrator selects this branch. */
typedef struct {
U32** hashLong;
U32** hashSmall;
const BYTE** base;
const U32* nextToUpdate;
const U32* hashLog;
const U32* chainLog;
const U32* minMatch;
int fullTableLoad;
int forCDict;
int available;
} ZSTD_rust_loadDictionaryContentDoubleFastTableState;
typedef char ZSTD_rust_load_dictionary_double_fast_table_layout[
(offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, hashLong) == 0
&& offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, hashSmall)
== sizeof(void*)
&& offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, base)
== 2 * sizeof(void*)
&& offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, nextToUpdate)
== 3 * sizeof(void*)
&& offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, hashLog)
== 4 * sizeof(void*)
&& offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, chainLog)
== 5 * sizeof(void*)
&& offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, minMatch)
== 6 * sizeof(void*)
&& offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, fullTableLoad)
== 7 * sizeof(void*)
&& offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, forCDict)
== 7 * sizeof(void*) + sizeof(int)
&& offsetof(ZSTD_rust_loadDictionaryContentDoubleFastTableState, available)
== 7 * sizeof(void*) + 2 * sizeof(int)
&& sizeof(ZSTD_rust_loadDictionaryContentDoubleFastTableState)
== ((7 * sizeof(void*) + 3 * sizeof(int) + sizeof(void*) - 1)
/ sizeof(void*) * sizeof(void*)))
? 1 : -1];
typedef void (*ZSTD_rust_loadDictionaryContent_loadMatch_f)(
void* context, const void* ip);
typedef void (*ZSTD_rust_loadDictionaryContent_loadTree_f)(
@@ -2841,7 +2878,7 @@ typedef struct {
ZSTD_rust_loadDictionaryContent_fillLdm_f fillLdm;
ZSTD_rust_loadDictionaryContent_overflowCorrect_f overflowCorrect;
const ZSTD_rust_loadDictionaryContentFastTableState* fastTable;
ZSTD_rust_loadDictionaryContent_fillTable_f fillDoubleHashTable;
const ZSTD_rust_loadDictionaryContentDoubleFastTableState* doubleFastTable;
ZSTD_rust_loadDictionaryContent_loadMatch_f loadDedicated;
ZSTD_rust_loadDictionaryContent_loadMatch_f loadRow;
ZSTD_rust_loadDictionaryContent_loadMatch_f loadChain;
@@ -2865,6 +2902,9 @@ ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_callback_offset,
ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_fast_table_offset,
offsetof(ZSTD_rust_loadDictionaryContentState,
fastTable) == 25 * sizeof(void*));
ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_double_fast_table_offset,
offsetof(ZSTD_rust_loadDictionaryContentState,
doubleFastTable) == 26 * sizeof(void*));
ZSTD_RUST_LOAD_DICT_ASSERT(ZSTD_rust_load_dict_final_callback_offset,
offsetof(ZSTD_rust_loadDictionaryContentState,
publishFinalIndex) == 31 * sizeof(void*));
@@ -6891,21 +6931,6 @@ static void ZSTD_loadDictionaryContent_overflowCorrect(
context->params, ip, iend);
}
static void ZSTD_loadDictionaryContent_fillDoubleHashTable(
void* opaque, const void* iend, int dtlm, int tfp)
{
ZSTD_loadDictionaryContent_context const* const context =
(const ZSTD_loadDictionaryContent_context*)opaque;
#ifndef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR
ZSTD_fillDoubleHashTable(context->matchState, (const BYTE*)iend,
(ZSTD_dictTableLoadMethod_e)dtlm,
(ZSTD_tableFillPurpose_e)tfp);
#else
(void)context; (void)iend; (void)dtlm; (void)tfp;
assert(0); /* shouldn't be called: cparams should've been adjusted. */
#endif
}
static void ZSTD_loadDictionaryContent_loadDedicated(void* opaque, const void* ip)
{
ZSTD_loadDictionaryContent_context const* const context =
@@ -7002,6 +7027,7 @@ static size_t ZSTD_loadDictionaryContent_callback(
{
ZSTD_loadDictionaryContent_context context;
ZSTD_rust_loadDictionaryContentFastTableState fastTable;
ZSTD_rust_loadDictionaryContentDoubleFastTableState doubleFastTable;
ZSTD_rust_loadDictionaryContentState state;
ZSTD_MatchState_t* const ms = (ZSTD_MatchState_t*)matchState;
ldmState_t* const ls = (ldmState_t*)ldmState;
@@ -7025,6 +7051,20 @@ static size_t ZSTD_loadDictionaryContent_callback(
fastTable.minMatch = &ms->cParams.minMatch;
fastTable.fullTableLoad = dtlm == ZSTD_dtlm_full;
fastTable.forCDict = tfp == ZSTD_tfp_forCDict;
doubleFastTable.hashLong = &ms->hashTable;
doubleFastTable.hashSmall = &ms->chainTable;
doubleFastTable.base = &ms->window.base;
doubleFastTable.nextToUpdate = &ms->nextToUpdate;
doubleFastTable.hashLog = &ms->cParams.hashLog;
doubleFastTable.chainLog = &ms->cParams.chainLog;
doubleFastTable.minMatch = &ms->cParams.minMatch;
doubleFastTable.fullTableLoad = dtlm == ZSTD_dtlm_full;
doubleFastTable.forCDict = tfp == ZSTD_tfp_forCDict;
#ifndef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR
doubleFastTable.available = 1;
#else
doubleFastTable.available = 0;
#endif
state.callbackContext = &context;
state.currentMax = ZSTD_CURRENT_MAX;
@@ -7052,7 +7092,7 @@ static size_t ZSTD_loadDictionaryContent_callback(
state.fillLdm = ZSTD_loadDictionaryContent_fillLdm;
state.overflowCorrect = ZSTD_loadDictionaryContent_overflowCorrect;
state.fastTable = &fastTable;
state.fillDoubleHashTable = ZSTD_loadDictionaryContent_fillDoubleHashTable;
state.doubleFastTable = &doubleFastTable;
state.loadDedicated = ZSTD_loadDictionaryContent_loadDedicated;
state.loadRow = ZSTD_loadDictionaryContent_loadRow;
state.loadChain = ZSTD_loadDictionaryContent_loadChain;