Skip to content

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

Closed
jonesy827 wants to merge 2 commits into
boykopovar:mainfrom
jonesy827:feat/to-intel-rdpru-mcommit
Closed

jonesy827 wants to merge 2 commits into
boykopovar:mainfrom
jonesy827:feat/to-intel-rdpru-mcommit

Conversation

@jonesy827

Copy link
Copy Markdown

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

RDPRU reads the host time-stamp counter and returns zero for
unsupported ECX values, MCOMMIT runs as SFENCE with rFLAGS.CF forced
to one. Semantics from the AMD APM (24594, Rev 3.38, RDPRU and
MCOMMIT sections) and LLVM's RDPRU definition; remaining deltas are
recorded in the technical debt.
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants