feat(relinker): lower MULX under --to-rosetta #12255
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12255"
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?
Imported from boykopovar/AnyPS5. Originally posted by Mherberts on 2026-10-28T05:31:00Z.
What
--to-rosettacurrently leaves VEX MULX native, so conversion still depends on the host implementing this BMI2 instruction. This adds a scalar lowering for its 32- and 64-bit register and memory forms, including extended registers, SIB addressing, RSP operands and RIP-relative sources. It is registered for both single-instruction and combined stubs. Plain conversion and--to-intelkeep MULX native.The semantics follow Intel SDM volume 2B, MULX, section 4-153: unsigned multiplication by EDX/RDX, low and high results in the second and first destinations, high result winning when the destinations coincide, and unchanged arithmetic flags. The stub saves RAX, RDX and RFLAGS below the guest red zone, uses scalar MUL, then restores state and commits the two outputs, deferring an RSP destination until last.
Stack-displacement overflow and direct RSP reads overlapping the saved inputs are refused. Precise exception delivery, aliases of spill slots through other registers, and execution of a converted title under Rosetta remain unverified or unsupported as recorded in
docs/dev/debt/relinker.md. This PR does not establish that a retail title is unblocked.Tested
Review follow-up on head
77a4c6f0660453829c5abb77dafc84b31a11bbfb:rooklzindependently built the original implementation head46f658e8ddon Apple M5, macOS 26.2, and reported 372/372 relinker-only CTests passing in the native arm64 build. An x86-64 build under Rosetta executed all 73,868 MULX cases successfully. This verifies the lowering test on that Rosetta host, not a converted title or exception delivery.upstream/main. Merge previews againstmain3a40945e62and #12068 headb10f3d89150919c0ff730ebfc07959773d0d4929exit 0.The following results were obtained on the original head before the documentation-only follow-up:
Windows 11 x86-64 (10.0.26200), WinLibs GCC 15.2.0, Python 3.13, Release with
ANYPS5_RELINKER_ONLY=ONandBUILD_TESTING=ON. Head46f658e8dd9748c0912b06259012b251c83b3a29, based onmain895ead67f7c11a46a7a29378c802d11864bed37a.cmake --build build-verify --parallel 2.mulx_lowering,mulx_conversion,to_rosetta,andn_lowering,masked_store_lowering,amd64_only_converter,amd64_only_windows,guest_intel_trampolines,red_zone_framerandred_zone_framer_execution.mulx_loweringexecuted 73,868 emitted-body cases on Windows: every register triple at both widths, shared destinations, RAX/RDX/RSP aliases, deterministic random and boundary inputs, all arithmetic-flag combinations, memory base registers, SIB, RIP-relative addressing, and red-zone preservation. It also checks invalid encodings, spill overlap boundaries, converter reports and relocation metadata. The final native test rerun passed in 0.26 seconds.mulx_conversionpassed 48 CLI conversions: executable and guest-module paths, Linux ELF and macOS Mach-O output, 32/64-bit register and memory sites, with plain/Intel/Rosetta mode controls. These checks inspect files; they do not execute Linux or macOS output on Windows.main's unchanged instruction-matcher source (blobecbe487147281a1e852ea874e32168b16345a48b) instead of the changed matcher. It exits 1 withRosetta mode did not require a MULX trampoline; the changed matcher passes. This is a focused control, not a full baseline build.git diff --checkandcheck_conventions.py --base upstream/mainpass. The required--base origin/mainwas also run: the fork's old main includes unrelated upstream differences, yielding 47 debt-length warnings and the existing non-Conventional upstream revert97f1d41a2c; none belongs to this PR's commits.tools/pr_overlap.py --branch codex/feat-rosetta-mulxlogic ran against a fresh public inventory of 1,358 open PRs through a local read-only GitHub-CLI adapter. No implementation overlap was found after moving registrations away from other pending additions. Manually inspected the uncomparable shared files in #5021, #6713, #7173, #7531, #9793, #10861 and #11192: they add unrelated macOS/Windows/SCE tests, ADX lowering or scalar reciprocal handling; the MULX source lists, registration, matcher sites and separate debt entry are disjoint.No native macOS/Rosetta or Linux execution, full product suite, GPU run, or retail title run was performed locally; the Rosetta test above was independently run by the reviewer. No performance claim.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T05:51:51Z.
Review: APPROVED
Reviewed
46f658e8dd: approve.I ran it on macOS 26.2, Apple M5 (arm64 host), with Homebrew Python 3.13 and Apple clang:
main0cd07dc4ab, arm64 relinker-only Release build: full build passed, ctest 372/372. On arm64,mulx_loweringruns only the encoding checks, because the execution block is gated on__x86_64__.-DCMAKE_OSX_ARCHITECTURES=x86_64) run under Rosetta 2 (arch -x86_64):mulx_lowering_testsprintedExecuted 73,868 MULX cases with register, flag and red-zone checksand exited 0. So the emitted stub bodies do run correctly under Rosetta on this host. That covers part of the new debt line ("Execution ... under Rosetta ... not been verified"). It does not cover a converted title or fault delivery inside the spill sequence. Whether to narrow the debt line is your call.check_conventions.py --base upstream/mainpassed;git merge-treeagainstmainclean.pr_overlap.pylists only the shared files (CMakeLists.txt,Amd64OnlyInstructionMatcher.cpp,debt/relinker.md) with #7531/#9793/#10861/#11192, no shared hunks.On inspection, the frame stays below the 128-byte red zone (192 > 128 + 24 spill bytes), and an RSP destination is committed last, after the frame is released. The semantics match the SDM text cited in the description: high result wins on equal destinations, flags are preserved.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T09:00:12Z.
Review: APPROVED
I reviewed the decoder and lowering path, including VEX register extensions, memory operands, RSP-relative adjustment, and spill-frame overlap refusal. The emitted stub preserves RAX/RDX/RFLAGS, defers an RSP destination, and leaves normal conversion paths unchanged. The reported 73,868 executed lowering cases plus CLI conversions cover register aliases, memory/SIB/RIP-relative forms, flags, red-zone preservation and invalid encodings; the current cross-platform relinker/ASan CI matrix passes. Remaining unsupported alias/exception/Rosetta cases are recorded in debt and the PR makes no retail-title claim. No blocking issue found.