feat(relinker): lower PDEP and PEXT under --to-rosetta and --to-avx #23781
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23781"
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 Urban225 on 2026-11-19T16:31:11Z.
What
Lowers PDEP and PEXT under
--to-rosettaand--to-avx, next to the existing BZHI/BEXTR lowering. Each becomes a stub that walks the mask one set bit per iteration (lowest bit through NEG and AND, cleared with XOR). RFLAGS is saved with PUSHFQ/POPFQ, since neither instruction writes it; scratch registers are saved in a 192-byte frame below the red zone. Register and memory masks, RSP as any operand, RIP-relative and stack-relative memory are handled as in the other BMI lowerings.The debt fragment also changes the
--to-avxentry that #23636 changes, so whichever merges second needs its fragment rebased.check_conventions.pyreports onedebt-lengthwarning: the--to-rosettaentry was already over 1000 characters and only gains "PDEP and PEXT" in its list.Tested
Ubuntu 24.04, GCC 13.3, x86-64 host with BMI2 (Intel Xeon), relinker-only build. No title or homebrew.
ctest: 1043/1043 pass.deposit_extract_loweringtest: decoding of every register combination, matcher for both targets, execution of 32- and 64-bit forms for every destination with aliased and RSP operands, memory masks (base, SIB, RIP-relative, stack-relative across the spill frame), result, other registers, RFLAGS and red zone checked against the SDM definition, and against the hardware instruction on 200,000 random inputs.to_rosettaPython test extended with PDEP and PEXT.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 PrivacyOnion on 2026-11-19T16:37:48Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d5a9169056:tools/check_conventions.pyfailed.deposit_extract_lowering_testsbuilt cleanly.deposit_extract_lowering):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T16:59:38Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d5a9169056:tools/check_conventions.pypassed.deposit_extract_lowering_testsbuilt cleanly.deposit_extract_lowering):core/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cpp,core/relinker/codegen/src/x86/DepositExtractLowering.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T17:24:10Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; I found no verified blocking defects in the files reviewed.
What I ran
Reviewed head
d5a916905639c895c63494725c2f08fb32f9367fusing the prepared diff andrepo_read.pysource reads. No commands or tests were run by me; test results below are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the CTest suite or inspect execution on Rosetta or a CPU without BMI2. The author's reported test results were not independently verified. All nine files listed as reviewed in the manifest were read; no files were excluded by the manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-20T08:17:42Z.
Review: COMMENTED
Ran it under Rosetta on Apple Silicon, which the Tested section lists as not tested.
Setup: Apple M4, macOS 27.0.1, Apple clang (Command Line Tools), x86_64 Release build under Rosetta 2. Head
d5a9169056merged ontomaine825fa1492with #17425 and #11049 (needed for the macOS build); clean merge.deposit_extract_loweringdeposit and extract lowering checks passed)to_rosetta--to-rosetta integration tests passed)pdep(0xff, 0xf0f0) = 0xf0f0andpext(0xabcd, 0xf0f0) = 0xac. SoHostExecutesis true here, and the stub-against-host comparison ran as well.Negative control: with the deposit loop's
SHRof the source changed toSHL(RegisterBytes(0xD1, wide, 5, source)→4),deposit_extract_loweringfails withPDEP 32 dst 0 source 6 mask 2 (source 1, mask value 1): register 0 is 0, wanted 1. With the change restored it passes.Not run on a CPU without BMI2.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T07:22:16Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
dc65c95564:tools/check_conventions.pypassed.deposit_extract_lowering_testsbuilt cleanly.deposit_extract_lowering):core/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cpp,core/relinker/codegen/src/x86/DepositExtractLowering.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T07:35:26Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review supports merging based on the source inspected, while runtime checks and some changed-file context were not available.
What I ran
Reviewed head
dc65c95564c003ba4c67c4a78009b2a835b6440d. Read the prepared description, commits, manifest and diff, plus the PDEP/PEXT lowering, its tests, matcher context and shared scalar-lowering helpers. No build or tests were run; author-reported test results were not independently verified.Results
Findings
Blocking
None in the source inspected.
Non-blocking
None.
Not verified
The
files.jsonexcluded-file list and whether every manifest entry was marked reviewed could not be checked. The full texts ofcore/relinker/CMakeLists.txt,core/relinker/codegen/include/codegen/x86/DepositExtractLowering.hpp,core/relinker/relinker/tests/test_to_rosetta.py,docs/dev/debt/changes/relinker-pdep-pext-lowering.md, anddocs/user/USAGE.mdwere not read. Build and runtime behavior were not tested; the reportedctestand hardware comparisons are author-reported.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:53:58Z.
Review: COMMENTED
Built this head with
ANYPS5_RELINKER_ONLY=ONand randeposit_extract_loweringandamd64_only_converteron Linux x86-64. Both passed. The Rosetta execution path 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.