feat(relinker): add opt-in PEXT and PDEP lowering for Rosetta #12678
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12678"
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-29T01:35:32Z.
What
Add the explicit
--lower-bit-permutationoption for scalar 32/64-bit PEXT/PDEP lowering with--to-rosetta. Default Rosetta output keeps the native instructions. Register masks and eligible RSP-relative masks are lowered; unsupported memory forms remain native. Both executable and bundled-module conversion receive the option.The older-host motivation has published probe evidence: kiaramaldonado's merged #7953 includes raw
PDEP Illegal instruction: 4andPEXT Illegal instruction: 4results from an Apple M2 running macOS 14.8.9, using isolated x86-64 processes built with Apple clang 15.0.0. Modern M1/M5 reports execute the instructions, which is why this remains opt-in. This is an independent measurement, not a new run on my Windows host; no converted title or performance gain is claimed.Resolved current-main conflicts while preserving
--omit-unavailable-dependenciesalongside the lowering option. Merge-order dependencies: #11525 first, as requested by its author, and #15032 before this PR to avoid competing edits to guest-builder option propagation. This PR waits behind both. On the later rebase, retain #11525's data-range argument toConvert, #15032's function-symbol-root option, and this PR's lowering option; these implement separate behavior.Tested
Head
72bd72605c, merged with main04a9eb4fa2. Windows x64, MinGW GCC 13.2.0, Python 3.13.15, Ninja Release,ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON.andn_lowering,masked_store_lowering,relinker_conversion,amd64_only_windows,bit_permutation_lowering,cli_args,amd64_only_converter.guest_intel_trampolines,to_rosetta,bit_permutation_conversionwere blocked when Windows Application Control refused the compiled relinker (WinError 4551). Hosted CI subsequently passed on this head: Linux, Windows (686/686 tests), macOS arm64, macOS x86-64 and Linux ASan. Build run. No Windows security setting was changed.upstream/mainandgit diff --check upstream/main...HEADpassed. The required comparison against the fork's outdatedorigin/mainalso ran and reports six unrelated upstream commit-subject errors plus existing debt-length warnings.Independent earlier execution coverage: rooklz's review ran 65,856 generated-stub cases under Rosetta on an M5 with macOS 26.2 and killed 25 mutants. That review predates this integration update. No local Mac/Rosetta run, old-M2 retest, retail-title test or full product build.
Independent update on this exact head: TechLevelZero's AMD run merged
72bd726onto main5b1d381and reports 1,076 passed, seven skipped and four failures already present or unstable on main, with no new Vulkan validation IDs. Host: AMD Radeon RX 6300, Mesa 25.2.8, Ubuntu 26.04.1. This is contributor-reported coverage, not a local run.Review audit on 2026-11-05, exact head
72bd72605cd2760a3fbf0df015e84d096c8d6c4b: all four hosted relinker configurations (Linux, Windows, macOS arm64 and macOS x86-64), relinker ASan, eligibility, conventions and labels have successful completed checks; full product jobs were skipped by workflow policy. The published older-host evidence and the Usage-column correction are present in this head. The requested review changes are ready for reassessment.Current overlap #15032 is option plumbing in
CliArgs.cpp,GuestImage.hpp,GuestModuleBuilder.cppandConversion.cpp; it implements function-symbol roots, not PEXT/PDEP. Its merge order is recorded on the checklist. Manually inspected the newly listed base-conflicting #6149 (module-args test source), #13486 (zero finalizers/stub-window safety), #15245 (executable exports), #14001 (program-header-table bounds) and #15651 (section links/entry sizes); these do not implement this lowering or TLS image comparison. Older manual checks remain historical evidence, not a claim that base-conflicting PRs merge cleanly.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-29T01:50:36Z.
Review: APPROVED
Reviewed @
80dbfb4093on macOS 26.2, Apple M5 (arm64), AppleClang, Release,ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON, Python 3.13. Main is3a2b919816andgit merge-treeagainst it is clean.arm64 build: relinker-only build plus
ctest -j 8: 482/482 pass, includingbit_permutation_loweringandbit_permutation_conversion. On arm64 the test printsPEXT/PDEP execution checks require an x86-64 build, so the macOS CI lane only covers decoding and the matcher.Execution under Rosetta 2: I built the same tree with
-DCMAKE_OSX_ARCHITECTURES=x86_64and ranbit_permutation_lowering_testsunder Rosetta 2. It printedExecuted 65856 PEXT/PDEP cases with register, flag and red-zone checksand passed in 0.8 s. This is the first time the generated stubs ran under Rosetta, which the debt entry lists as unverified. Caveat: this Rosetta version runspextq/pdepqnatively (a probe returned the SDM results). So the older-Rosetta SIGILL that motivates the PR can't be reproduced here, and this run proves the stub is correct under Rosetta, not that it was needed. You could narrow the debt sentence to "precise fault delivery inside the spill sequence".Independent oracle: in a scratch copy of the test, I replaced
expectedResultwith inlinepext/pdep(32- and 64-bit) executed by the host. All 65,856 cases still pass, so the bit-loop model and the lowering agree with the instruction itself, not only with each other.Mutants: run against the x86_64 binary under Rosetta. 25/25 killed:
<=,56 -,>=, width fixed at 8 and at 4>=and+1pushfqxor ecx,ecx→movnullopt0x67skipGates:
check_conventions --base upstream/mainis clean.pr_overlaplists only the uncomparable, base-conflicting PRs already named in the body (#9345, #9508, #9793, #10193, #10861, #11192, …).Optional, not blocking: the macOS lane could also build this one test for x86_64 and run it under Rosetta, so the execution half runs in CI on Apple Silicon.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T02:02:05Z.
Review: CHANGES_REQUESTED
The lowering itself checks out (spill frame, red zone, flags, RSP aliases, 32-bit zero-extension), and @rooklz's Rosetta run and mutants cover it well. What blocks the merge is the same question @oneandonlydean raised, still unanswered:
docs/dev/debt/relinker.mdonmainrecords both executing (M1 macOS 26.6.2, M5 macOS 26.4) and only ANDN/RDRAND faulting (macOS 15.3.1), and @rooklz could not reproduce a fault either. Please give the version and a probe result, and name the version split in the debt entry.core/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cpp: every--to-rosettaconversion now replaces a working native PEXT/PDEP with an out-of-line loop. Please scope it to the hosts that need it, or make it opt-in.[rsp+disp](e.g. RIP-relative, 8 of your 96 CLI cases) now fail the conversion, though those titles convert and run today. Keep those forms native instead of failing, or lower them too.Welcome to push an update with these addressed.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T04:55:50Z.
Review: CHANGES_REQUESTED
Checked the head against current
main(52c09d567): the merge is clean and the opt-in works as described (--lower-bit-permutationneeds--to-rosetta, default output keeps PEXT/PDEP native). The lowering itself checks out: spill frame, red zone, flags, RSP aliases and 32-bit zero-extension are covered by the tests.Still open before merge:
docs/dev/debt/relinker.md) or name a title or report that needs the lowering. Without one of those we won't merge 600 lines of translation for an optional path.--lower-bit-permutationline in theUsagetext inCliArgs.cppis one space out of column with the other entries.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T06:29:22Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the opt-in PEXT/PDEP lowering and its propagation through executable and guest-module conversion are supported by the inspected code and tests.
What I ran
Reviewed head
72bd72605cd2760a3fbf0df015e84d096c8d6c4busing the prepared diff andrepo_read.py. No commands or tests were run locally.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No local build, tests, or console execution were performed. The PR-reported hosted CI and independent Rosetta/AMD runs were not independently verified. Read all 16 changed files listed as included in the manifest; no excluded files were identified there.
files.jsonwas unavailable through the reader, so any exclusions it may list are not verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:58:21Z.
Review: COMMENTED
Built this head with
ANYPS5_RELINKER_ONLY=ONand ranbit_permutation_lowering,cli_args, andbit_permutation_conversionon Linux. All passed, including 128 conversion cases spanning Linux and macOS output formats. Native Rosetta execution remains outside this run.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.