feat(relinker): lower RDPRU and MCOMMIT for --to-intel #1756

Closed
jonesy827 wants to merge 2 commits from upstream-pr/1756 into main
jonesy827 commented 2026-10-08 18:34:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jonesy827 on 2026-10-08T18:34:01Z.


What

--to-intel lowers the two remaining AMD-only system instructions instead of failing the relink:

  • RDPRU (0F 01 FD) reads the host time-stamp counter and returns zero for unsupported ECX values, with every rFLAGS bit preserved (RdpruLowering.cpp).
  • MCOMMIT (F3 0F 01 FA) runs as SFENCE with CF set to one and OF, SF, ZF, AF and PF cleared (McommitLowering.cpp).
  • Both stubs move the stack pointer below the red zone before any push, as the other stubs do.
  • Both lowerings are required, not optional: RDPRU and MCOMMIT raise #UD on Intel hosts, so an unlowerable site (a site too short for the return jump whose following instruction cannot move into the stub, for example mcommit before a conditional branch) fails the relink. Prefixed forms (66, F2, F3 on RDPRU; LOCK, 66, F2 on MCOMMIT and other 0F 01 FA forms) are reported as unsupported; other prefixed 0F 01 FA forms report as MONITORX.
  • The short-site absorption in the converter now reports an unsupported follower at its own file offset with its instruction name, instead of throwing the sequence failure at the first site's offset.

Sources: RDPRU and MCOMMIT sections of the AMD64 Architecture Programmer's Manual Volume 3 (24594, Rev 3.38, July 2026); MCOMMIT's SFENCE ordering and rFLAGS table, RDPRU's ECX register selection and zero result for unsupported values. LLVM's RDPRU definition (Uses=[ECX], Defs=[EAX,EDX], no EFLAGS) agrees. The APM rFLAGS table for RDPRU shows the arithmetic flags cleared and CF modified, but RDPRU measured on hardware leaves every flag unchanged, so the stub preserves the flags and the difference is recorded in the technical debt with the measurement. The remaining deltas (TSC values instead of MPERF/MAPERF, no host mechanism for MCOMMIT's delayed store errors, unmeasured prefixed forms) are recorded in TechnicalDebt.md.

Tested

Arch Linux, Ryzen 9 5900XT (Zen 3). Relinker-only build, Release and Debug configurations: full ctest suite (38/38), including new converter, matcher, golden-encoding and hardware-execution tests (the RDPRU stub runs against the host RDTSC; flag preservation, unsupported-ECX zeroing, ECX preservation, upper-half zeroing and red-zone sentinels are checked on real execution; golden stub bytes verified against GNU as). tools/check_conventions.py --base origin/main passes. No title run: no title in the compatibility list is known to use RDPRU or MCOMMIT.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4791201247 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1756). Originally posted by [jonesy827](https://github.com/jonesy827) on 2026-10-08T18:34:01Z. --- ### What `--to-intel` lowers the two remaining AMD-only system instructions instead of failing the relink: - RDPRU (`0F 01 FD`) reads the host time-stamp counter and returns zero for unsupported ECX values, with every rFLAGS bit preserved ([RdpruLowering.cpp](https://github.com/jonesy827/AnyPS5/blob/feat/to-intel-rdpru-mcommit/core/relinker/codegen/src/x86/RdpruLowering.cpp)). - MCOMMIT (`F3 0F 01 FA`) runs as SFENCE with CF set to one and OF, SF, ZF, AF and PF cleared ([McommitLowering.cpp](https://github.com/jonesy827/AnyPS5/blob/feat/to-intel-rdpru-mcommit/core/relinker/codegen/src/x86/McommitLowering.cpp)). - Both stubs move the stack pointer below the red zone before any push, as the other stubs do. - Both lowerings are required, not optional: RDPRU and MCOMMIT raise #UD on Intel hosts, so an unlowerable site (a site too short for the return jump whose following instruction cannot move into the stub, for example `mcommit` before a conditional branch) fails the relink. Prefixed forms (66, F2, F3 on RDPRU; LOCK, 66, F2 on MCOMMIT and other `0F 01 FA` forms) are reported as unsupported; other prefixed `0F 01 FA` forms report as MONITORX. - The short-site absorption in the converter now reports an unsupported follower at its own file offset with its instruction name, instead of throwing the sequence failure at the first site's offset. Sources: RDPRU and MCOMMIT sections of the AMD64 Architecture Programmer's Manual Volume 3 (24594, Rev 3.38, July 2026); MCOMMIT's SFENCE ordering and rFLAGS table, RDPRU's ECX register selection and zero result for unsupported values. LLVM's `RDPRU` definition (`Uses=[ECX]`, `Defs=[EAX,EDX]`, no EFLAGS) agrees. The APM rFLAGS table for RDPRU shows the arithmetic flags cleared and CF modified, but RDPRU measured on hardware leaves every flag unchanged, so the stub preserves the flags and the difference is recorded in the technical debt with the measurement. The remaining deltas (TSC values instead of MPERF/MAPERF, no host mechanism for MCOMMIT's delayed store errors, unmeasured prefixed forms) are recorded in [TechnicalDebt.md](https://github.com/jonesy827/AnyPS5/blob/feat/to-intel-rdpru-mcommit/docs/dev/TechnicalDebt.md). ### Tested Arch Linux, Ryzen 9 5900XT (Zen 3). Relinker-only build, Release and Debug configurations: full `ctest` suite (38/38), including new converter, matcher, golden-encoding and hardware-execution tests (the RDPRU stub runs against the host RDTSC; flag preservation, unsupported-ECX zeroing, ECX preservation, upper-half zeroing and red-zone sentinels are checked on real execution; golden stub bytes verified against GNU as). `tools/check_conventions.py --base origin/main` passes. No title run: no title in the compatibility list is known to use RDPRU or MCOMMIT. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-09 05:32:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T05:32:11Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2001 docs/dev/TechnicalDebt.md L300-306
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074953654 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1756#issuecomment-6074953654). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T05:32:11Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2001 | `docs/dev/TechnicalDebt.md` [L300-306](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/docs/dev/TechnicalDebt.md#L300-L306) | | |
oneandonlydean commented 2026-10-09 08:55:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T08:55:26Z.


Closing: no title is known to reach RDPRU or MCOMMIT, and the lowering isn't exact (TSC instead of MPERF/APERF). Reopen when a title stops on one of them under --to-intel.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077715406 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1756#issuecomment-6077715406). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T08:55:26Z. --- Closing: no title is known to reach RDPRU or MCOMMIT, and the lowering isn't exact (TSC instead of MPERF/APERF). Reopen when a title stops on one of them under `--to-intel`.

Pull request closed

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!1756
No description provided.