feat(relinker): lower register-form EXTRQ and relocate following instructions for short sites #54

Merged
oneandonlydean merged 1 commit from upstream-pr/54 into main 2026-09-28 06:35:28 +00:00
oneandonlydean commented 2026-09-28 03:37:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-28T03:37:37Z.


What

Addresses an item from docs/TechnicalDebt.md: --to-intel failed the relink on register-form EXTRQ (66 0F 79), which is 4 or 5 bytes and too short for a jump to a stub. A retail title hits this. With this change all 97 of its AMD-only instructions are lowered (94 through stubs).

How

  • Lowering: register-form EXTRQ is emitted out of line with SSE2 only. Two scratch XMM registers (distinct from both operands) are spilled; one gets the index (src >> 8 & 63), the other (64 - length) & 63 (length masked to 6 bits, so 0 means 64). The destination is shifted right by the index, then left and right by the complement, which keeps the low length bits. INSERTQ register form is still reported as unsupported.
  • Short sites: when a site is shorter than a jmp rel32, the converter extends it over the instructions that follow it until it's 5 bytes long:
    • following EXTRQ/INSERTQ instructions (before any other instruction) are lowered into the same stub, via a new MatchSequence;
    • other instructions are copied after the lowered body (LowerOutOfLine's new trailing bytes), but only if they're sequential, have no RIP-relative operand and no branch target;
    • anything else (a return, a branch, RIP-relative code, the segment ending) still fails the relink, as does a branch target inside the extended site.
  • docs/TechnicalDebt.md now lists only the INSERTQ register form, MONITORX/MWAITX/CLZERO/RDPRU/MCOMMIT and SHA-NI.

Testing

amd64_only_converter:

  • The matcher lowers register-form EXTRQ through a stub and still rejects register-form INSERTQ.
  • The converter rejects a short EXTRQ followed by a ret. When a nop follows instead, the site grows to 5 bytes and the nop runs before the return jump.
  • On x86-64 Linux the stub is run, with distinct and with equal operands, for several length/index pairs (including length 0 and index + length = 64). Each result is checked against a reference, and the check confirms the spilled scratch register is restored.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4658944835 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/54). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-09-28T03:37:37Z. --- ### What Addresses an item from `docs/TechnicalDebt.md`: `--to-intel` failed the relink on register-form EXTRQ (`66 0F 79`), which is 4 or 5 bytes and too short for a jump to a stub. A retail title hits this. With this change all 97 of its AMD-only instructions are lowered (94 through stubs). ### How - **Lowering:** register-form EXTRQ is emitted out of line with SSE2 only. Two scratch XMM registers (distinct from both operands) are spilled; one gets the index (`src >> 8 & 63`), the other `(64 - length) & 63` (`length` masked to 6 bits, so 0 means 64). The destination is shifted right by the index, then left and right by the complement, which keeps the low `length` bits. INSERTQ register form is still reported as unsupported. - **Short sites:** when a site is shorter than a `jmp rel32`, the converter extends it over the instructions that follow it until it's 5 bytes long: - following EXTRQ/INSERTQ instructions (before any other instruction) are lowered into the same stub, via a new `MatchSequence`; - other instructions are copied after the lowered body (`LowerOutOfLine`'s new `trailing` bytes), but only if they're sequential, have no RIP-relative operand and no branch target; - anything else (a return, a branch, RIP-relative code, the segment ending) still fails the relink, as does a branch target inside the extended site. - `docs/TechnicalDebt.md` now lists only the INSERTQ register form, MONITORX/MWAITX/CLZERO/RDPRU/MCOMMIT and SHA-NI. ### Testing `amd64_only_converter`: - The matcher lowers register-form EXTRQ through a stub and still rejects register-form INSERTQ. - The converter rejects a short EXTRQ followed by a `ret`. When a `nop` follows instead, the site grows to 5 bytes and the `nop` runs before the return jump. - On x86-64 Linux the stub is run, with distinct and with equal operands, for several length/index pairs (including length 0 and index + length = 64). Each result is checked against a reference, and the check confirms the spilled scratch register is restored.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!54
No description provided.