Patch immediate-form SSE4a (insertq/extrq) in-place on Intel CPUs #386
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/readmet3xt-lab--foxhound!386
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-386"
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?
@HDFreitas on GitHub · 2026-12-01 21:13 UTC · original
HDFreitas:perf/sse4a-inplace-patch→main· +200 −15 · 1 files · 72 commits · closed without mergingSummary
Split out from #367 (SSE4a half only, targeting
mainuntil the console-instruction rewrite is pushed — happy to rebase once it lands).On Intel CPUs (which lack AMD's SSE4a extension), immediate-form
insertq/extrqinstructions (>= 6bytes, e.g.,insertq xmm0, xmm1, 16, 16) currently raiseSTATUS_ILLEGAL_INSTRUCTIONon every execution — reaching 524,288+ kernel exceptions in ~6 minutes (~1,800–2,200 faults/s) during gameplay on an Intel i9-9900K.Changes (
crates/victory-loader/src/console_insn.rs)clzeroloop trampoline mechanism: replaces the first 5 bytes of faulting immediate-forminsertq/extrqinstructions (len >= 5, not crossing a 16-byte boundary) atomically viacmpxchg16bwith ajmp rel32to a small native stub in a nearby executable page.RFLAGS(pushfq/popfq), and zeroes the destination XMM's high quadword viamovq xmm, rax(matching emulation / Zen 5).STUBSto a multi-page pool (Vec<(usize, usize)>) so modules >2 GiB apart can each allocate a reachable stub page.VICTORY_PATCH_SSE4A(on by default; setVICTORY_PATCH_SSE4A=0to fall back to per-fault emulation).Measurements (Intel i9-9900K @ 5 GHz, Windows 11)
console_insn): dropped from 524,288 faults in 6 min to 1 single fault at startup (patched on first hit, 0 subsequent faults).Verification
cargo clippy --locked -p victory-loader --tests -- -D warnings: clean (0 warnings).cargo test --release --locked -p victory-loader console_insn: 6/6 passed, includingsse4a_immediate_becomes_native_stubwhich executes patchedinsertqandextrqinstructions natively and verifies low/high quadwords andRFLAGSpreservation.Pull request closed