feat(relinker): add --to-avx to lower TZCNT, LZCNT and MOVBE for hosts without BMI #17084
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17084"
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 ycbuzi on 2026-11-08T09:48:20Z.
What
Adds
--to-avx, a relinker target for hosts that have AVX but not AVX2, BMI1, BMI2, LZCNT or MOVBE, such as the Sandy Bridge and Ivy Bridge CPUs of 2011 and 2012 Macs. It applies the BMI1 and BMI2 lowerings that--to-rosettaalready has (ANDN, BLSI/BLSMSK/BLSR, SHLX/SHRX/SARX/RORX, BZHI/BEXTR, MULX) plus CLWB and RDPID, which Sandy Bridge also lacks, and adds two more:It leaves out the Rosetta-only workarounds: 256-bit store splits, masked stores, scalar compares, RDTSCP, XSAVEOPT and RDSEED. A Sandy Bridge runs the first five natively, and it has no RDRAND for the RDSEED rewrite to target.
Both new stubs use relocatable-window placement. A 4-byte
tzcnt eax, ecxfollowed by ajbin Celeste Classic's eboot failed with "too short for a jump" until the window could take the branch.--to-avxrequires--macos, because only the macOS runtime starts without the host CPU check. Not lowered yet, and listed indocs/dev/debt/relinker.md:Tested
count_lowering,movbe_lowering,cli_args,andn_lowering,bls_lowering,shift_lowering,bitfield_loweringandmulx_loweringpass. The two new execution tests run their stubs on a CPU that lacks the instructions and compare result and flags against an SDM model.amd64_only_converterstops with SIGILL on this host onmainas well: it runs host AVX2 code, as #16236 describes.amd64_only_converter(including the newconverterAvxShortSites),count_lowering,movbe_loweringandcli_argspass. The execution parts are skipped on Windows.--macos --to-avx --skip-sce-module. The--to-rosettaoutput still holds 1,674 TZCNT, 1,108 LZCNT and 111 MOVBE; the--to-avxoutput holds none of them, and at 31.4 MB it is smaller than the--to-rosettaoutput (31.7 MB) because it skips the store splits. The title does not run on this Mac yet, because it also uses AVX2.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T11:56:03Z.
Review: COMMENTED
Windows run of this head as part of #17132's head
a7614d3fcf, which contains32ccea1fd0unchanged, merged ontomain105c9e4d91. Setup: Windows 11, i7-12800H (BMI1/2, LZCNT, MOVBE), WinLibs GCC 15.2, Release, relinker-only.count_lowering,movbe_lowering,cli_args,amd64_only_converter, and the existing ANDN, BLS, shift, bitfield and MULX lowering tests. The execution parts are compiled out on Windows._WIN32branch inLoweringExecution.hpp(VirtualAlloc/VirtualProtectand asysv_abicall; details on #17132), the execution parts ofcount_loweringandmovbe_loweringrun here and pass against your SDM model.count_lowering's execution also ran each site as the original instruction, using the same wrapper with the site bytes emitted raw. I compared all 16 GPRs, CF and ZF, and the red zone against the stub. That covers every register case and every memory form in the test, both flag inputs each time: 13,272 runs, all identical. So the BSF/BSR + CMOVZ stubs match real TZCNT/LZCNT on these inputs, including the zero source, the 16-bit forms keeping bits 63:16, and RIP-relative memory.MOVBE was checked only against the SDM model, not natively.