loader: replace SSE4a extrq/insertq with SSE2 stubs on first fault #1653
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!1653
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1653"
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?
@JeremRuiz on GitHub · 2026-11-28 23:05 UTC · original
JeremRuiz:loader-sse4a-stubs→main· +210 −0 · 1 files · 1 commits · merged 2026-11-29 08:16 UTCRelated: #1603
What it changes
extrqandinsertqare AMD-only (SSE4a). On an Intel CPU each one raises an illegal-instruction exception, andconsole_insn::emulatesteps over it every time. The title has one hot site,insertq xmm0, xmm1, 16, 16(6 bytes,F2 0F 78 C1 10 10), the only SSE4a form seen in seven logs on an i5-9600K. #1603 reports about 1,200 of these a second on an i7-13700K.This replaces the immediate forms at their first fault, as clzero loops already are: the instruction becomes a
jmp rel32(plus NOPs to its length) to a stub in the existingSTUBSregions, and the stub jumps back past it.extrq xmm, len, idx:psrlqthenpandwith the field mask.insertq xmm1, xmm2, len, idx: a third XMM register is borrowed and kept on the stack (lea rsp, so the flags are untouched);pandandpsllqon the source,pandwith the hole mask on the destination, thenpor.decode::extrq/decode::insertqgive; the high quadword is zeroed, as the emulation already does.pandfrom memory needs the alignment).patchalready requires.VICTORY_PATCH_SSE4A=0keeps the old path.The new
put_stubhelper writes a stub into aSTUBSregion within reach of the site. It reserves a new region when none reaches, aspatch_clzerodoes.patch_clzeroitself is unchanged.How it was tested
victory play's default switches.an_sse4a_instruction_becomes_sse2: six forms (insertq with distinct registers, with destination equal to source, length 0 and length 4 at index 60; extrq on xmm0 and xmm1) are faulted once throughemulateand then run natively. The results are checked againstdecode::insertq/decode::extrq, and the borrowed register is checked unchanged. It fails when the stub's shift is broken on purpose.cargo testpassed for the crates it touches: yes.cargo test -p victory-loaderond4b5d51: 47 passed.cargo clippy -p victory-loader --all-targetswith and without--all-features,-D warnings: clean. The full workspace tests ran on the v2026.11.28.03 base, not on main.Checked for overlap
STUBSinto a list of regions (no conflict left; this builds on it).