feat(compress): move dictionary mode selection to Rust
The block-compressor dispatch already selected its strategy and row-mode index in Rust, but C still classified the match state into no-dictionary, ext-dictionary, attached-dictionary, or dedicated-dictionary mode. Project the window and match-state scalars into Rust so that four-way policy is centralized with compressor dispatch while C retains private match-state access. Test Plan: - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo check --tests (rust) - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --tests -- -A clippy::manual-bits -D warnings (rust) - ulimit -v 41943040; make -j1 - ulimit -v 41943040; make -j1 -C tests test
This commit is contained in:
@@ -1326,6 +1326,10 @@ type BlockCompressorFn =
|
||||
const ZSTD_RUST_BLOCK_COMPRESSOR_TABLE_WIDTH: usize = 10;
|
||||
const ZSTD_RUST_ROW_BLOCK_COMPRESSOR_TABLE_WIDTH: usize = 3;
|
||||
const ZSTD_RUST_DICT_MODE_COUNT: c_int = 4;
|
||||
const ZSTD_RUST_DICT_MODE_NO_DICT: c_int = 0;
|
||||
const ZSTD_RUST_DICT_MODE_EXT_DICT: c_int = 1;
|
||||
const ZSTD_RUST_DICT_MODE_MATCH_STATE: c_int = 2;
|
||||
const ZSTD_RUST_DICT_MODE_DEDICATED: c_int = 3;
|
||||
const ZSTD_RUST_BLOCK_COMPRESSOR_MAX_STRATEGY: c_int =
|
||||
ZSTD_RUST_BLOCK_COMPRESSOR_TABLE_WIDTH as c_int - 1;
|
||||
|
||||
@@ -10945,6 +10949,28 @@ pub extern "C" fn ZSTD_rust_windowHasExtDict(dict_limit: u32, low_limit: u32) ->
|
||||
(low_limit < dict_limit) as c_uint
|
||||
}
|
||||
|
||||
/// Select the compressor dictionary mode from the C-owned window scalars.
|
||||
/// Rust owns the four-way policy; C retains only private match-state access.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ZSTD_rust_matchStateDictMode(
|
||||
dict_limit: u32,
|
||||
low_limit: u32,
|
||||
has_dict_match_state: c_int,
|
||||
dedicated_dict_search: c_int,
|
||||
) -> c_int {
|
||||
if low_limit < dict_limit {
|
||||
ZSTD_RUST_DICT_MODE_EXT_DICT
|
||||
} else if has_dict_match_state != 0 {
|
||||
if dedicated_dict_search != 0 {
|
||||
ZSTD_RUST_DICT_MODE_DEDICATED
|
||||
} else {
|
||||
ZSTD_RUST_DICT_MODE_MATCH_STATE
|
||||
}
|
||||
} else {
|
||||
ZSTD_RUST_DICT_MODE_NO_DICT
|
||||
}
|
||||
}
|
||||
|
||||
/// Project the dictionary/window limit policy while C retains pointer-owned
|
||||
/// match-state invalidation and the private window layout.
|
||||
#[repr(C)]
|
||||
@@ -19417,6 +19443,15 @@ mod tests {
|
||||
assert_eq!(ZSTD_rust_windowCheckDictValidity(70, 64, 8, 10), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_state_dictionary_mode_uses_window_before_match_state_policy() {
|
||||
assert_eq!(ZSTD_rust_matchStateDictMode(10, 2, 0, 0), 1);
|
||||
assert_eq!(ZSTD_rust_matchStateDictMode(10, 10, 0, 0), 0);
|
||||
assert_eq!(ZSTD_rust_matchStateDictMode(10, 10, 1, 0), 2);
|
||||
assert_eq!(ZSTD_rust_matchStateDictMode(10, 10, 1, 1), 3);
|
||||
assert_eq!(ZSTD_rust_matchStateDictMode(10, 2, 1, 1), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn window_dictionary_pointer_projection_applies_invalidation_side_effects() {
|
||||
let mut low_limit = 2;
|
||||
|
||||
Reference in New Issue
Block a user