relinker: lower ADCX/ADOX under --to-rosetta? #7157
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Destroyers212x on 2026-10-17T14:23:44Z.
docs/dev/debt/relinker.mdsays ADCX/ADOX fault under Rosetta and aren't converted, because compilers don't emit them and code that checks CPUID sees no ADX. I confirmed they still raise SIGILL on an M1 with macOS 26.6.2 (details in #7143). Of the instructions I tested that fault there, they're the only ones the relinker doesn't handle.Since the PS5's Zen 2 CPU has ADX, code built for that fixed target could use them without a CPUID check, for example a bignum or crypto routine compiled with
-madx. I don't know of a title that does.Would you accept a
--to-rosettalowering for them, following the ANDN lowering (Intel SDM semantics: ADCX reads and writes only CF, ADOX only OF, all other flags preserved, with converter tests and an execution test under Rosetta)? Or would you rather keep them unconverted until a title needs it?AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by plokmklo on 2026-10-18T05:45:49Z.
Since the question here was whether such a lowering would be accepted, I went ahead and implemented it on
https://github.com/plokmklo/AnyPS5/tree/contrib/7157-adcx-adox(commit5275b4016), following the ANDN lowering as the template.ADCX (
66 0F 38 F6, VEX pp=1) and ADOX (F3 0F 38 F6, VEX pp=3) are lowered under--to-rosettawith the Intel SDM contract: ADCX writes only CF, ADOX only OF, and every other flag is preserved. The stub captures the incoming flags with PUSHF before the arithmetic, stages the source into a scratch register, chains the carry with ADC, and moves the result carry to CF or OF through SETO/NEG plus AND/OR on the scratch, so the untouched flags come back from the POPF exactly as they were. An RSP destination is computed in a stack slot and written back with a final move, so the stub frame itself never moves. Legacy and VEX encodings, memory sources and 32-bit forms are covered.Tests: a new converter/execution suite (
adcx_adox_lowering) runs every register combination against four flag images and three operand patterns on Linux x86-64, checking the result, all sixteen registers, the untouched flags and the red zone — 195/195 relinker tests pass with it, andcheck_conventions.pyis clean. The relinker debt entry now reflects the new handling.I don't have a title that emits ADX, so the Rosetta execution run and a real fixed-target module are still untested — the lowering follows the SDM semantics the ANDN entry set as the house pattern. Happy to open the PR whenever the queue allows.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T05:48:29Z.
Thanks for doing the independent implementation and test work. I already have open PR #7173 for the same
--to-rosettaADCX/ADOX lowering; its current head covers 32/64-bit forms, register and memory operands, extended registers, carry inputs, boundary cases and generated-stub execution, and its Linux/macOS/Windows relinker CI passed.Your 195-case matrix may still expose a useful test gap. Before opening a second implementation PR, could you compare its cases with #7173 and point out any encoding or flag-preservation case not already exercised? If there is a distinct gap, we can coordinate a focused follow-up that credits your test contribution.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T06:24:28Z.
I compared your branch with #7173. The main distinct test gap I found is state preservation: #7173 checks results and arithmetic flags, but does not snapshot all guest GPRs or check the caller red zone after the generated trampoline. Your
Executionharness checks both, and it exercises a broader set of register encodings. That looks like a useful test-only follow-up, independent of the lowering. Would you be comfortable with me carrying that preservation coverage into a separate PR while crediting your test contribution? I would leave the VEX-form cases out until their architectural validity is confirmed.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T12:10:47Z.
Following up on the state-preservation gap I identified against #7173: its generated-stub tests do not currently snapshot all guest GPRs or the caller red zone, while your
Executionharness checks both. If you agree, I can carry only that focused regression coverage into a separate PR with your test contribution credited. I will leave the lowering and unverified VEX cases out.Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-22T10:50:33Z.
ADCX/ADOX still fault on an M1 Pro with macOS 27.0.1
New data point for the Rosetta table in
docs/dev/debt/relinker.md, which has M1 results for macOS 15.3.1 and 26.6.2 but none for macOS 27.Host: Apple M1 Pro, macOS 27.0.1, x86_64 under Rosetta 2 (
sysctl.proc_translated= 1). A probe ran each instruction in a forked child and compared its result with the architectural value (LZCNT 1= 63 rather than BSR's 0,TZCNT 0= 64, and so on). The results were identical over 3 runs.TSC_AUX=0xaaaaaaab(matches the M5 / 27.0.1 value in the debt entry)CPUID reports far less than what executes:
ecx=0298220f edx=0f8b8b15, so no MOVBE, FMA, AVX, F16C or RDRAND bitebx=ecx=edx=0, so no BMI1, BMI2, AVX2 or ADX bitecx=00000001, so no LZCNT (ABM) or PREFETCHW bitThe SIGILL and execute sets match the M1 / macOS 26.6.2 entry exactly. Moving from 26 to 27 did not add ADX on M1, so #7173's lowering is still needed on this host.
Probe source (x86_64,
clang++ -arch x86_64 -std=c++20 -O1 probe.cpp)AI-assisted: yes (Claude Code wrote and ran the probe and the write-up).