Patch immediate-form SSE4a (extrq/insertq) in-place on Intel CPUs #461

Open
github-bot wants to merge 1 commit from github-bot/gh-461 into main AGit
Owner

@⁠HDFreitas on GitHub · 2026-12-02 12:59 UTC · original
HDFreitas:perf/sse4a-inplace-patch-v2 → main · +220 −19 · 1 files · 1 commits · open

Summary

  • Re-opens the SSE4a half of #367 / #386 rebased onto the rewritten \console_insn.rs\ module (after the \main\ history rewrite).
  • Replaces faulting immediate-form SSE4a \extrq\ and \insertq\ instructions (AMD-only, absent on Intel CPUs) on first fault with a 5-byte \jmp rel32\ to a register- and \RFLAGS-preserving native stub that clears bits 127:64 of the destination XMM register (matching \it_field).
  • Controlled by \VICTORY_PATCH_SSE4A\ (on by default; \VICTORY_PATCH_SSE4A=0\ keeps per-fault emulation), matching \VICTORY_PATCH_CLZERO\ / \VICTORY_PATCH_CLWB\ / \VICTORY_PATCH_WAITS.
  • Shares the \STUBS\ pool helper (\write_stub) with \patch_clzero\ and allows multiple 64 KiB pools when patched sites are more than 2 GiB apart. Uses \patch()\ so concurrent faults on the same site are handled by \REPLACED\ /
    eplaced_meanwhile.

Measured impact

On Intel i9-9900K (no SSE4a): reduces \extrq/\insertq\ exceptions from ~524k faults in a 6-minute run down to 1 fault on first execution.

Verification

  • \cargo clippy --locked -p victory-loader --tests -- -D warnings\ (0 warnings)
  • \cargo clippy --locked -p victory-loader --features diagnostics -- -D warnings\ (0 warnings)
  • \cargo test --release --locked -p victory-loader console_insn\ (23/23 passed, including \sse4a_immediate_becomes_native_stub\ executing patched \insertq/\extrq\ stubs natively, covering \len=0\ -> 64, \len+idx>64, \RFLAGS\ preservation, and high-qword zeroing)
**@⁠HDFreitas** on GitHub · 2026-12-02 12:59 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/461) `HDFreitas:perf/sse4a-inplace-patch-v2` → `main` · +220 −19 · 1 files · 1 commits · open ## Summary - Re-opens the SSE4a half of #367 / #386 rebased onto the rewritten \console_insn.rs\ module (after the \main\ history rewrite). - Replaces faulting immediate-form SSE4a \extrq\ and \insertq\ instructions (AMD-only, absent on Intel CPUs) on first fault with a 5-byte \jmp rel32\ to a register- and \RFLAGS\-preserving native stub that clears bits 127:64 of the destination XMM register (matching \it_field\). - Controlled by \VICTORY_PATCH_SSE4A\ (on by default; \VICTORY_PATCH_SSE4A=0\ keeps per-fault emulation), matching \VICTORY_PATCH_CLZERO\ / \VICTORY_PATCH_CLWB\ / \VICTORY_PATCH_WAITS\. - Shares the \STUBS\ pool helper (\write_stub\) with \patch_clzero\ and allows multiple 64 KiB pools when patched sites are more than 2 GiB apart. Uses \patch()\ so concurrent faults on the same site are handled by \REPLACED\ / \ eplaced_meanwhile\. ## Measured impact On Intel i9-9900K (no SSE4a): reduces \extrq\/\insertq\ exceptions from ~524k faults in a 6-minute run down to 1 fault on first execution. ## Verification - \cargo clippy --locked -p victory-loader --tests -- -D warnings\ (0 warnings) - \cargo clippy --locked -p victory-loader --features diagnostics -- -D warnings\ (0 warnings) - \cargo test --release --locked -p victory-loader console_insn\ (23/23 passed, including \sse4a_immediate_becomes_native_stub\ executing patched \insertq\/\extrq\ stubs natively, covering \len=0\ -> 64, \len+idx>64\, \RFLAGS\ preservation, and high-qword zeroing)
Replace faulting immediate-form SSE4a extrq/insertq instructions with a jmp rel32 trampoline to a register- and RFLAGS-preserving native stub in a nearby executable stub pool (controlled by VICTORY_PATCH_SSE4A, on by default).

Rebased onto the rewritten console_insn module, reusing its STUBS pool (extended to multiple pools when sites lie >2 GiB apart) and REPLACED race-tracking table. Adds unit tests executing patched insertq/extrq stubs natively.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 13:00:41 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/461/head:github-bot/gh-461'
git switch 'github-bot/gh-461'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-461'
git switch 'github-bot/gh-461'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-461'
git switch 'github-bot/gh-461'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-461'
git switch 'main'
git merge --squash 'github-bot/gh-461'
git switch 'main'
git merge --ff-only 'github-bot/gh-461'
git switch 'main'
git merge 'github-bot/gh-461'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.