Loader/TLS: use memchr::memmem SIMD scan in tls::patch #2954
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2956"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T01:30:07Z.
Replace the byte-by-byte
.textscan incrates/victory-loader/src/tls.rs::patchformov r64, gs:[0x58]withmemchr::memmem::Findertargeting the 5-byte[0x25, 0x58, 0, 0, 0]suffix, using the existing workspacememchrdependency.Output is bit-identical to the bytewise scanner (verified by
memmem_patch_matches_bytewise_oracleacross mixed encodings, prefixes, false-positive suffixes, and boundary offsets).Measured (
--release, median of 3 runs)bench_tls_patch_64mb(64 MiB buffer with 32,768mov r64, gs:[0x58]sites): 39.79 ms → 5.51 ms (7.22×, -86.2%)Verification
--locked, default +--tests+--features diagnosticsclippy,xtask policy, full workspace tests): RVZO6/VIctory CI run #45734072839 (green, combined Wave 7 check on63bcca4).AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:50:58Z.
Review: COMMENTED
Reviewed and verified against
main(63bcca43) on Windows 11 — clean, mathematically equivalent to the byte-by-byte scan, and ready to merge (note: functionally overlaps with #188's SSE2 scanner, and based onmainwithout #1192's short/empty-section guard):memchr = "2.8.3"already present inCargo.lock(passes--lockedwith zero new external crates).crates/victory-loader/src/tls.rs:78-115searches for the 5-byte invariant tail[0x25, 0x58, 0, 0, 0]starting atpos = 4, recoversi = hit - 4, checks the exact same 9-byte pattern (LOAD_LEN = 9), and advancespos = i + LOAD_LEN + 4on match orhit + 1on mismatch — matching the previous scan byte-for-byte.Local verification:
cargo test --locked -p victory-loader: 40/40 passed (36unit +crash_log+load_probe+title_dlls)cargo test --locked --release -p victory-loader --lib bench_tls_patch_64mb -- --ignored --nocapture:2.20 mscargo clippy --locked -p victory-loader --tests -- -D warnings: 0 warningscargo xtask policy: 191 files okImported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:24:18Z.
Review: COMMENTED
Verified the scan equivalence: needle starts at pos>=4 so hit-4 can't underflow; the loop bound pos+5<=len preserves the old i+9<=len check; on-match pos=i+13 aligns with the next instruction's needle field, and non-match pos=hit+1 keeps overlapping-needle coverage identical to the bytewise oracle — which the test diffs byte-for-byte including the patched output. The len<LOAD_LEN early-out covers the code[pos..] slice.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:47:14Z.
Automated triage for the maintainers.
Needs the maintainer's decision. Thanks for
47880d3. The benchmark and its figures from the title's binary are gone, andmemmem_patch_matches_bytewise_oracleremains. I re-readtls::patch(crates/victory-loader/src/tls.rs): it is still equivalent to the byte-by-byte scan, and thecode.len() < LOAD_LENearly return matches the old loop bound.What's left is not a code issue. The PR adds
memchras a new dependency ofvictory-loader(Cargo.toml,Cargo.lock) to save about 35 ms once per launch, and whether that trade is worth it is the maintainer's call.CI: passing (
check).Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T06:56:41Z.
Addressed triage feedback in
47880d3:#[ignore]bench_tls_patch_64mbbenchmark test and its comment referencing binary sizes/hit counts (docs/asset-policy.md), keepingmemmem_patch_matches_bytewise_oracle.victory-loader, both clippy profiles, andxtask policy. Not run: the title; any hardware GPU.Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T20:30:19Z.
NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head
47880d3(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.memmem_patch_matches_bytewise_oracle.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T23:37:10Z.
Independent Windows verification of PR #2956 (Loader/TLS: use memchr::memmem SIMD scan in tls::patch).
47880d3, basemain, merge-base63bcca4. OPEN, MERGEABLE/CLEAN, non-draft, no formal approval, no prior comment from me.cargo test --locked, worktree-localCARGO_TARGET_DIR,CARGO_BUILD_JOBS=2(repo pins 1.98.1; no clippy/rustup). No game data, synthetic byte patterns only, GPU/driver N/A.cargo test --locked -p victory-loader --lib -- tls::tests::memmem_patch_matches_bytewise_oracle --exact --quiettest result: ok. 1 passed; 0 failed; 0 ignored; 35 filtered out.git diff --checkagainst merge-base63bcca4: clean (exit 0).origin/main(0 hits).Note: I am aware of the existing
triage: needs the maintainer's decisionverdict; this comment reports only the local CPU test result and does not contest that verdict. Real title.textsections were not exercised.AI-assisted (Hy4 flash). No game assets, extracted shaders, keys or DRM content used or uploaded.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.