fix(relinker): lower ADCX and ADOX for Rosetta #7173

Open
MarcZX10 wants to merge 10 commits from upstream-pr/7173 into main
MarcZX10 commented 2026-10-17 14:53:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T14:53:15Z.


What

Lower ADCX and ADOX instructions in --to-rosetta output using baseline ADC while restoring unrelated arithmetic flags. ADCX maps ADC's carry-out to CF; ADOX maps that carry-out to OF, as required by the two independent carry chains. The lowering handles 32-bit and 64-bit register or memory sources, REX extensions, stack-relative operands, and RIP-relative relocation; it rejects RSP as the destination because the trampoline cannot safely change its own stack pointer. Adds decoder, converter, and generated-stub regression coverage, and records the unsupported RSP-destination case in relinker debt.

Tested

  • Linux relinker-only Release build completed.
  • Full CTest suite: 188/188 passed, including generated x86-64 stub execution across both instructions, widths, carry inputs, boundary operands, RSP-relative memory, RSP source, and extended registers.
  • The test includes a native ADX differential check gated by CPUID. This host lacks ADX, so that optional path was skipped.
  • check_conventions.py --base upstream/main passed.
  • pr_overlap.py --branch codex/rosetta-adx-flags-7157 reported no overlap with open PRs; unmergeable shared-file candidates were manually reviewed and no duplicate lowering was found.
  • Apple Silicon Rosetta runtime was not available in this Linux environment, so no claim is made for execution under Rosetta itself.
  • Rebase verification: the 188/188 CTest results and relinker-only build above were run on pre-rebase head b9f5cd818f35a4aa7424fedcebd6a3885ecfd8da. New head 65b4f1fc693e50ac8f14a32a7c7825479f31f40f is based on main 0e9dc7bc4c9755c3ce803f6bbdff9dc9f25d68bb; git diff --check and the merge preview passed. Both adx_lowering and guest_load_ranges remain registered in CMake. The conventions check had 0 errors and 1 debt-length warning. Build and CTest were not rerun after rebasing.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; silent stubs are listed under technical debt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: #7157
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4901083184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T14:53:15Z. --- ### What Lower ADCX and ADOX instructions in `--to-rosetta` output using baseline ADC while restoring unrelated arithmetic flags. ADCX maps ADC's carry-out to CF; ADOX maps that carry-out to OF, as required by the two independent carry chains. The lowering handles 32-bit and 64-bit register or memory sources, REX extensions, stack-relative operands, and RIP-relative relocation; it rejects RSP as the destination because the trampoline cannot safely change its own stack pointer. Adds decoder, converter, and generated-stub regression coverage, and records the unsupported RSP-destination case in relinker debt. ### Tested - Linux relinker-only Release build completed. - Full CTest suite: 188/188 passed, including generated x86-64 stub execution across both instructions, widths, carry inputs, boundary operands, RSP-relative memory, RSP source, and extended registers. - The test includes a native ADX differential check gated by CPUID. This host lacks ADX, so that optional path was skipped. - `check_conventions.py --base upstream/main` passed. - `pr_overlap.py --branch codex/rosetta-adx-flags-7157` reported no overlap with open PRs; unmergeable shared-file candidates were manually reviewed and no duplicate lowering was found. - Apple Silicon Rosetta runtime was not available in this Linux environment, so no claim is made for execution under Rosetta itself. - Rebase verification: the 188/188 CTest results and relinker-only build above were run on pre-rebase head `b9f5cd818f35a4aa7424fedcebd6a3885ecfd8da`. New head `65b4f1fc693e50ac8f14a32a7c7825479f31f40f` is based on `main` `0e9dc7bc4c9755c3ce803f6bbdff9dc9f25d68bb`; `git diff --check` and the merge preview passed. Both `adx_lowering` and `guest_load_ranges` remain registered in CMake. The conventions check had 0 errors and 1 debt-length warning. Build and CTest were not rerun after rebasing. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; silent stubs are listed under technical debt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: #7157 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
oneandonlydean commented 2026-10-17 15:03:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T15:03:37Z.


Thanks @MarcZX100. The Rosetta gating looks right: both hooks return early unless the target is Rosetta, so x86 codegen is unchanged. The decode, RSP handling and flag-preservation checks look good too, and ADCX is correct.

One blocker on ADOX:

ADOX writes the wrong OF. For ADOX, EmitAdx masks ADC's flags with 0x800, so the result OF is ADC's OF, which is signed overflow. ADOX's OF output is the unsigned carry-out (OF:DEST ← DEST + SRC + OF), and ADC leaves that in CF. Checked against native adox on an ADX host (gcc -madx):

input native ADOX lowering
0x7FFFFFFFFFFFFFFF + 0, OF=1 result 0x8000000000000000, OF=0 (CF preserved) OF=1
0xFFFFFFFFFFFFFFFF + 1, OF=0 result 0, OF=1 OF=0

So any ADOX carry chain (multi-precision add/multiply in bignum, crypto or hashing code) gets wrong sums from the second limb on, silently. A fix: for ADOX, take the carry from bit 0 and move it to bit 11, e.g. replace and scratch, 0x800 with and scratch, 1 + shl scratch, 11.

The test currently encodes the same mistake. AdxLoweringTests.cpp computes the expected ADOX flag as signed overflow (~(d^s) & (d^r) & sign). Its only execution input, 0x7FFF…F + 0 with carry 1, is exactly where signed overflow and unsigned carry differ, so it passes because of the bug. Could you:

  • expect the unsigned carry-out for both ADCX and ADOX;
  • add 0xFFFF…F + 1 and a no-carry case for each width;
  • ideally add a differential check against native adcx/adox when CPUID.(EAX=7,ECX=0):EBX[19] (ADX) is set, over a small grid of (dst, src, CF, OF). The Linux CI runners have ADX.

Once that's on a new head we'll re-review and run full CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235455238 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6235455238). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T15:03:37Z. --- Thanks @MarcZX100. The Rosetta gating looks right: both hooks return early unless the target is Rosetta, so x86 codegen is unchanged. The decode, RSP handling and flag-preservation checks look good too, and ADCX is correct. One blocker on ADOX: **ADOX writes the wrong OF.** For ADOX, `EmitAdx` masks ADC's flags with `0x800`, so the result OF is ADC's OF, which is *signed overflow*. ADOX's OF output is the *unsigned carry-out* (`OF:DEST ← DEST + SRC + OF`), and ADC leaves that in CF. Checked against native `adox` on an ADX host (`gcc -madx`): | input | native ADOX | lowering | |---|---|---| | `0x7FFFFFFFFFFFFFFF + 0`, OF=1 | result `0x8000000000000000`, **OF=0** (CF preserved) | OF=1 | | `0xFFFFFFFFFFFFFFFF + 1`, OF=0 | result `0`, **OF=1** | OF=0 | So any ADOX carry chain (multi-precision add/multiply in bignum, crypto or hashing code) gets wrong sums from the second limb on, silently. A fix: for ADOX, take the carry from bit 0 and move it to bit 11, e.g. replace `and scratch, 0x800` with `and scratch, 1` + `shl scratch, 11`. **The test currently encodes the same mistake.** `AdxLoweringTests.cpp` computes the expected ADOX flag as signed overflow (`~(d^s) & (d^r) & sign`). Its only execution input, `0x7FFF…F + 0` with carry 1, is exactly where signed overflow and unsigned carry differ, so it passes because of the bug. Could you: - expect the unsigned carry-out for both ADCX and ADOX; - add `0xFFFF…F + 1` and a no-carry case for each width; - ideally add a differential check against native `adcx`/`adox` when CPUID.(EAX=7,ECX=0):EBX[19] (ADX) is set, over a small grid of (dst, src, CF, OF). The Linux CI runners have ADX. Once that's on a new head we'll re-review and run full CI.
MarcZX10 commented 2026-10-17 15:05:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T15:05:13Z.


Follow-up manual overlap review after main advanced: the overlap tool reports unmergeable shared files in #5021, #6044, #6111 and #6314. #6111 changes RDTSCP handling in the same matcher but does not implement ADCX/ADOX; #6314 adds game-patch sources/tests to CMake; #6044 reorganizes CTest registration and its stale branch removes older ANDN entries, so the ADCX/ADOX registrations must be retained if it is integrated; #5021 is a broad AOT change with older CMake/debt edits. I found no duplicate ADCX/ADOX lowering. These are manual file reviews because the bot cannot compare those branches cleanly; a rebase/reconciliation may be needed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235470930 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6235470930). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T15:05:13Z. --- Follow-up manual overlap review after `main` advanced: the overlap tool reports unmergeable shared files in #5021, #6044, #6111 and #6314. #6111 changes RDTSCP handling in the same matcher but does not implement ADCX/ADOX; #6314 adds game-patch sources/tests to CMake; #6044 reorganizes CTest registration and its stale branch removes older ANDN entries, so the ADCX/ADOX registrations must be retained if it is integrated; #5021 is a broad AOT change with older CMake/debt edits. I found no duplicate ADCX/ADOX lowering. These are manual file reviews because the bot cannot compare those branches cleanly; a rebase/reconciliation may be needed.
Destroyers212x commented 2026-10-17 15:06:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Destroyers212x on 2026-10-17T15:06:32Z.


Rosetta results for this PR (63c454aa6), M1 with macOS 26.6.2, relinker-only Release build with -DCMAKE_OSX_ARCHITECTURES=x86_64, so the tests run under Rosetta: 179/179 passed, including adx_lowering (its execution part runs on macOS x86-64) and to_rosetta.

One semantic problem in ADOX's output flag, though. ADOX writes the unsigned carry-out of DEST + SRC + OF to OF: it is ADCX with OF in place of CF, which is what lets the two carry chains interleave. The lowering here writes the signed overflow of the ADC to OF instead, and the test encodes the same rule (AdxLoweringTests.cpp:146, overflow = ~(d ^ s) & (d ^ r) & sign), so both agree and the test passes.

Two 32-bit cases with OF clear on entry that show it:

ADOX carry out (expected OF) signed overflow (OF this PR produces)
0x56789000 + 0x5d4c306a 0 1
0xffffffff + 0xffffffff 1 0

I ran an independent execution test against this PR's EmitAdx under Rosetta. It covers every destination except RSP, sources 6, the destination itself, 11 and RSP, 32/64-bit, all-zero, all-one and mixed inputs, the memory forms ([rsi], [rsi+16], [rsp+0x40], [rdx+rcx*8], [rbp+16], RIP-relative), and entry flags 0x2, 0x8D7, CF only and OF only. The results and all other flags are right, and ADCX passes every case. ADOX fails 708 cases in both widths, all on OF only. The test is on Destroyers212x/AnyPS5 feat/rosetta-adx-lowering (check() computes the expected flags) if you want to reuse it. I won't open a competing PR.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235483649 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6235483649). Originally posted by [Destroyers212x](https://github.com/Destroyers212x) on 2026-10-17T15:06:32Z. --- Rosetta results for this PR (63c454aa6), M1 with macOS 26.6.2, relinker-only Release build with `-DCMAKE_OSX_ARCHITECTURES=x86_64`, so the tests run under Rosetta: 179/179 passed, including `adx_lowering` (its execution part runs on macOS x86-64) and `to_rosetta`. One semantic problem in ADOX's output flag, though. ADOX writes the **unsigned carry-out** of `DEST + SRC + OF` to OF: it is ADCX with OF in place of CF, which is what lets the two carry chains interleave. The lowering here writes the **signed overflow** of the ADC to OF instead, and the test encodes the same rule (`AdxLoweringTests.cpp:146`, `overflow = ~(d ^ s) & (d ^ r) & sign`), so both agree and the test passes. Two 32-bit cases with OF clear on entry that show it: | ADOX | carry out (expected OF) | signed overflow (OF this PR produces) | | --- | --- | --- | | `0x56789000 + 0x5d4c306a` | 0 | 1 | | `0xffffffff + 0xffffffff` | 1 | 0 | I ran an independent execution test against this PR's `EmitAdx` under Rosetta. It covers every destination except RSP, sources 6, the destination itself, 11 and RSP, 32/64-bit, all-zero, all-one and mixed inputs, the memory forms (`[rsi]`, `[rsi+16]`, `[rsp+0x40]`, `[rdx+rcx*8]`, `[rbp+16]`, RIP-relative), and entry flags `0x2`, `0x8D7`, CF only and OF only. The results and all other flags are right, and ADCX passes every case. ADOX fails 708 cases in both widths, all on OF only. The test is on [Destroyers212x/AnyPS5 `feat/rosetta-adx-lowering`](https://github.com/Destroyers212x/AnyPS5/blob/feat/rosetta-adx-lowering/core/relinker/codegen/tests/AdxLoweringTests.cpp) (`check()` computes the expected flags) if you want to reuse it. I won't open a competing PR. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-17 15:15:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T15:15:45Z.


Fixed in f5e857c48. The ADOX path now takes ADC’s unsigned carry-out from CF and maps it into OF; it no longer copies ADC’s signed overflow. The execution test now checks 32- and 64-bit cases across boundary operands and both carry-in values, and includes a native ADX differential check when CPUID reports ADX support. This host has no ADX, so that optional differential path was skipped here. adx_lowering_tests passes, the full Linux relinker-only CTest suite passes 188/188, git diff --check passes, and conventions pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235584204 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6235584204). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T15:15:45Z. --- Fixed in `f5e857c48`. The ADOX path now takes ADC’s unsigned carry-out from CF and maps it into OF; it no longer copies ADC’s signed overflow. The execution test now checks 32- and 64-bit cases across boundary operands and both carry-in values, and includes a native ADX differential check when CPUID reports ADX support. This host has no ADX, so that optional differential path was skipped here. `adx_lowering_tests` passes, the full Linux relinker-only CTest suite passes 188/188, `git diff --check` passes, and conventions pass.
Destroyers212x commented 2026-10-17 15:17:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Destroyers212x on 2026-10-17T15:17:57Z.


Re-ran f5e857c48 under Rosetta (M1, macOS 26.6.2, x86-64 relinker-only build): adx_lowering and to_rosetta pass, and the independent execution test that failed 708 ADOX cases on 63c454aa6 now passes every case for both instructions, both widths, all register pairs, the memory forms and CF/OF set and clear on entry.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235612221 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6235612221). Originally posted by [Destroyers212x](https://github.com/Destroyers212x) on 2026-10-17T15:17:57Z. --- Re-ran f5e857c48 under Rosetta (M1, macOS 26.6.2, x86-64 relinker-only build): `adx_lowering` and `to_rosetta` pass, and the independent execution test that failed 708 ADOX cases on 63c454aa6 now passes every case for both instructions, both widths, all register pairs, the memory forms and CF/OF set and clear on entry. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-17 15:18:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T15:18:44Z.


Follow-up: after the broader run, I made the carry-to-OF shift explicitly encode SHL r64, 11 (C1 /4) and reran the suite on the pushed head. The full Linux CTest suite again passes 188/188; the focused ADX test and conventions also pass. The native ADX differential path remains CPUID-gated and skipped on this host.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235622237 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6235622237). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T15:18:44Z. --- Follow-up: after the broader run, I made the carry-to-OF shift explicitly encode `SHL r64, 11` (`C1 /4`) and reran the suite on the pushed head. The full Linux CTest suite again passes 188/188; the focused ADX test and conventions also pass. The native ADX differential path remains CPUID-gated and skipped on this host.
MarcZX10 commented 2026-10-17 15:23:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T15:23:10Z.


Thanks for rerunning the independent Rosetta matrix. Your results on f5e857c48 confirm the ADOX carry mapping across the reported cases. I then made the one-bit extraction explicitly use SHL r64, 11 (instead of a rotate that produced the same single-bit result) in 8e83a61a2; the focused test and full Linux CTest suite pass again on that pushed head. Hosted cross-platform relinker jobs are still running.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235688306 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6235688306). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T15:23:10Z. --- Thanks for rerunning the independent Rosetta matrix. Your results on `f5e857c48` confirm the ADOX carry mapping across the reported cases. I then made the one-bit extraction explicitly use `SHL r64, 11` (instead of a rotate that produced the same single-bit result) in `8e83a61a2`; the focused test and full Linux CTest suite pass again on that pushed head. Hosted cross-platform relinker jobs are still running.
TheSovietWaffle commented 2026-10-17 15:23:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-17T15:23:51Z.


Windows data point: head 8e83a61a2 as-is, Release, Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, x86-64 host (no Rosetta). adx_lowering passes 5 of 5, including its generated-stub execution checks.

Not checked: the rest of the relinker suite, Rosetta.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235698531 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6235698531). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-17T15:23:51Z. --- Windows data point: head `8e83a61a2` as-is, Release, Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, x86-64 host (no Rosetta). `adx_lowering` passes 5 of 5, including its generated-stub execution checks. Not checked: the rest of the relinker suite, Rosetta. AI-assisted: yes (Claude Code).
MarcZX10 commented 2026-10-17 15:24:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T15:24:54Z.


Thanks for checking the final head on Windows. That confirms the generated-stub execution checks pass there as well; the Windows hosted relinker job is still pending, and your result covers the focused test rather than the full suite.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235714743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6235714743). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T15:24:54Z. --- Thanks for checking the final head on Windows. That confirms the generated-stub execution checks pass there as well; the Windows hosted relinker job is still pending, and your result covers the focused test rather than the full suite.
MarcZX10 commented 2026-10-17 15:26:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T15:26:43Z.


Hosted relinker CI has now completed on head 8e83a61a2: macOS, Linux and Windows jobs all pass, as do conventions and eligibility. The broader Linux/Windows/register-context/write-watch jobs were skipped by path filters; the separate local full Linux relinker-only suite passed 188/188.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235742699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6235742699). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T15:26:43Z. --- Hosted relinker CI has now completed on head `8e83a61a2`: macOS, Linux and Windows jobs all pass, as do conventions and eligibility. The broader Linux/Windows/register-context/write-watch jobs were skipped by path filters; the separate local full Linux relinker-only suite passed 188/188.
jotitadev commented 2026-10-18 02:33:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T02:33:41Z.

Review: COMMENTED


Native ADX run of the CPUID-gated differential, which no run here has exercised yet: the earlier hosts had no ADX (Ivy Bridge Xeon, Rosetta on M1).

Setup: head 8e83a61a2 (merges cleanly into main 195d0d08a), Linux x86-64, i7-8700 (adx in /proc/cpuinfo), GCC 15.2, relinker-only Release.

  • adx_lowering_tests: 3/3 pass, with the hasAdx branch taken. The relinker suite passes 188/188.
  • The native branch catches the bug from the first review on its own. I put AdxLowering.cpp from 63c454aa6 (ADOX OF = ADC signed overflow) back and kept the current test:
    • as is, it fails on the reference check, "ADX lowering produced the wrong carry flag or changed an unrelated arithmetic flag";
    • with that reference flag check also disabled, it fails with "ADX lowering differs from native ADX". So the native comparison runs on ADX hardware and covers ADOX's OF independently of the reference model.

One note on the Windows data point above: the execution section of AdxLoweringTests.cpp is under #if (defined(__linux__) || defined(__APPLE__)) && defined(__x86_64__). So on Windows only the decode and conversion checks run, not the generated-stub execution.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5561125246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#pullrequestreview-5561125246). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T02:33:41Z. **Review:** COMMENTED --- Native ADX run of the CPUID-gated differential, which no run here has exercised yet: the earlier hosts had no ADX (Ivy Bridge Xeon, Rosetta on M1). **Setup:** head `8e83a61a2` (merges cleanly into `main` `195d0d08a`), Linux x86-64, i7-8700 (`adx` in `/proc/cpuinfo`), GCC 15.2, relinker-only Release. - `adx_lowering_tests`: 3/3 pass, with the `hasAdx` branch taken. The relinker suite passes 188/188. - The native branch catches the bug from the first review on its own. I put `AdxLowering.cpp` from `63c454aa6` (ADOX OF = ADC signed overflow) back and kept the current test: - as is, it fails on the reference check, "ADX lowering produced the wrong carry flag or changed an unrelated arithmetic flag"; - with that reference flag check also disabled, it fails with "ADX lowering differs from native ADX". So the native comparison runs on ADX hardware and covers ADOX's OF independently of the reference model. One note on the Windows data point above: the execution section of `AdxLoweringTests.cpp` is under `#if (defined(__linux__) || defined(__APPLE__)) && defined(__x86_64__)`. So on Windows only the decode and conversion checks run, not the generated-stub execution. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-18 05:37:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T05:37:38Z.


Thanks for running the current head on native ADX hardware. This confirms both the reference-flag check and the native differential catch the ADOX carry regression; the Windows scope note is useful too. I have no further validation request.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6246169919 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6246169919). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T05:37:38Z. --- Thanks for running the current head on native ADX hardware. This confirms both the reference-flag check and the native differential catch the ADOX carry regression; the Windows scope note is useful too. I have no further validation request.
Destroyers212x commented 2026-10-18 11:09:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Destroyers212x on 2026-10-18T11:09:23Z.


Rosetta results for this PR (8e83a61), M1 with macOS 26.6.2, relinker-only Release build:

  • x86-64 under Rosetta (CMAKE_OSX_ARCHITECTURES=x86_64): 179/179 CTest passed. adx_lowering ran its execution checks: the (__linux__ || __APPLE__) && __x86_64__ guard is active, and the binary run directly prints "ADX lowering tests passed". Rosetta does not report ADX (CPUID.(EAX=7,ECX=0):EBX[19] = 0), so the native ADX differential path was skipped here too.
  • Native arm64: 179/179 CTest passed (adx_lowering runs only the decode and convert checks).

I also wrote a separate execution check under Rosetta, linked against build-x64/core/relinker/librelinker_core.a. Its reference model follows the ADCX/ADOX entries in Intel SDM Vol. 2A: dest + src + CF/OF, the carry-out goes only to CF/OF, and the 32-bit form zero-extends. It covered both instructions, both widths, every destination except RSP, every source register including RSP, and [rsp+8] and [rsp-8] memory sources (the second one is inside the red zone). Each case started with random values in all 16 registers and random CF/PF/AF/ZF/SF/OF. 6480 cases, 0 failures. In every case the destination, CF/PF/AF/ZF/SF/DF/OF and all the other GPRs matched, and the 128 bytes below the original RSP were unchanged.

A gap in the PR's test: in the 32-bit cases every destination value is ≤ 0xFFFFFFFF, so the test doesn't check that bits 63:32 of the destination get cleared. The lowering does clear them (my check started with random upper bits), but a destination like 0xDEADBEEF00000001 in values would cover it.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249149170 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6249149170). Originally posted by [Destroyers212x](https://github.com/Destroyers212x) on 2026-10-18T11:09:23Z. --- Rosetta results for this PR (8e83a61), M1 with macOS 26.6.2, relinker-only Release build: - x86-64 under Rosetta (`CMAKE_OSX_ARCHITECTURES=x86_64`): 179/179 CTest passed. `adx_lowering` ran its execution checks: the `(__linux__ || __APPLE__) && __x86_64__` guard is active, and the binary run directly prints "ADX lowering tests passed". Rosetta does not report ADX (CPUID.(EAX=7,ECX=0):EBX[19] = 0), so the native ADX differential path was skipped here too. - Native arm64: 179/179 CTest passed (`adx_lowering` runs only the decode and convert checks). I also wrote a separate execution check under Rosetta, linked against `build-x64/core/relinker/librelinker_core.a`. Its reference model follows the ADCX/ADOX entries in Intel SDM Vol. 2A: dest + src + CF/OF, the carry-out goes only to CF/OF, and the 32-bit form zero-extends. It covered both instructions, both widths, every destination except RSP, every source register including RSP, and `[rsp+8]` and `[rsp-8]` memory sources (the second one is inside the red zone). Each case started with random values in all 16 registers and random CF/PF/AF/ZF/SF/OF. 6480 cases, 0 failures. In every case the destination, CF/PF/AF/ZF/SF/DF/OF and all the other GPRs matched, and the 128 bytes below the original RSP were unchanged. A gap in the PR's test: in the 32-bit cases every destination value is ≤ 0xFFFFFFFF, so the test doesn't check that bits 63:32 of the destination get cleared. The lowering does clear them (my check started with random upper bits), but a destination like `0xDEADBEEF00000001` in `values` would cover it. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-18 12:24:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T12:24:50Z.


Added 0xDEADBEEF00000001 to both the generated-stub and CPUID-gated native differential operand matrices. In the 32-bit cases it supplies nonzero upper destination/source bits while the expected result remains zero-extended, so those checks now catch a failure to clear bits 63:32. The focused Linux test passes (1/1); conventions and git diff --check pass. Commit: 010ce9b02.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249883618 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6249883618). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T12:24:50Z. --- Added `0xDEADBEEF00000001` to both the generated-stub and CPUID-gated native differential operand matrices. In the 32-bit cases it supplies nonzero upper destination/source bits while the expected result remains zero-extended, so those checks now catch a failure to clear bits 63:32. The focused Linux test passes (1/1); conventions and `git diff --check` pass. Commit: `010ce9b02`.
MarcZX10 commented 2026-10-19 14:57:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T14:57:50Z.


Rebased on main at c92eb8da1e8d311c29a9de86ec5328f8a83d841c. The update preserves the remote-added upper-bits regression commit and combines the ADCX/ADOX lowering with the recent RDTSCP matcher change.

Validation on Linux x86-64 with GCC 12.2, Release, ANYPS5_RELINKER_ONLY=ON:

  • Full relinker-only build passed.
  • CTest passed 217/217, including adx_lowering and the amd64_only_converter regression suite.
  • check_conventions.py reported zero errors and one existing debt-length warning for the long --to-rosetta summary in docs/dev/debt/relinker.md.
  • No Rosetta runtime was available, so no execution under Rosetta is claimed.

The rebased head is fd7342a5109fdb2c3a80253a6c0c88b08f151719; GitHub checks are starting now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6270270153 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#issuecomment-6270270153). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T14:57:50Z. --- Rebased on `main` at `c92eb8da1e8d311c29a9de86ec5328f8a83d841c`. The update preserves the remote-added upper-bits regression commit and combines the ADCX/ADOX lowering with the recent RDTSCP matcher change. Validation on Linux x86-64 with GCC 12.2, Release, `ANYPS5_RELINKER_ONLY=ON`: - Full relinker-only build passed. - CTest passed 217/217, including `adx_lowering` and the `amd64_only_converter` regression suite. - `check_conventions.py` reported zero errors and one existing `debt-length` warning for the long `--to-rosetta` summary in `docs/dev/debt/relinker.md`. - No Rosetta runtime was available, so no execution under Rosetta is claimed. The rebased head is `fd7342a5109fdb2c3a80253a6c0c88b08f151719`; GitHub checks are starting now.
MarcZX10 commented 2026-11-02 04:56:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:56:52Z.

Review: COMMENTED


Replies checked — EIP-relative ADCX/ADOX bug still present, docs duplicate confirmed

The code at this head still drops the RIP-relative relocation for address-size-prefixed ADCX/ADOX, and the docs entry is duplicated after a merge with main.

What I ran

  • Live head 65b4f1fc693e50ac8f14a32a7c7825479f31f40f (OPEN).
  • gh api comments, review comments and reviews on #7173, newer than 2026-10-19T14:57:50Z, excluding MarcZX10 and bots.
  • gh pr view 7173 --json statusCheckRollup; git show 65b4f1fc:<path> for the three files below.
  • git merge-tree --write-tree upstream/main 65b4f1fc, then a grep count of the merged relinker.md.
  • Nothing built or run.

Results

Check Result Note
Live head matches batch OPEN
Merged docs entries (head + upstream/main) 2 upstream/main alone has 1
Hosted conventions, relinker (ubuntu, macOS, windows), relinker-asan SUCCESS windows aggregate, linux, register-context, write-watch SKIPPED

Findings

  • @oneandonlydean (2026-10-25, re-raised 2026-11-01 06:39 UTC): DecodeAdx clears RipRelative when the 0x67 prefix is present, and EmitAdx then copies the instruction without a relocation. Confirmed by reading: AdxLowering.cpp L168-L170 clears the flag, and L204-L206 relocate only when it is set. The test at L46 pins !RipRelative, so the current tests lock in the gap. Answer needed: fix it (preserve the target including 32-bit wrap) and add execution tests for ADCX and ADOX at a moved address. Not reproduced here.
  • @oneandonlydean (2026-11-01): drop the test that requires the RSP-destination form to throw. Confirmed at AdxLoweringTests.cpp L55-L62. Answer needed: remove it and keep the other checks.
  • @oneandonlydean (2026-10-28): the docs commit leaves two "--to-rosetta lowers what Rosetta lacks" entries after a merge with main. Confirmed: relinker.md L49-L50 at head, and two entries in the merged tree. Answer needed: keep one entry with the ADCX/ADOX wording on main's current line.
  • @AdnanKhan-ak47 (2026-10-25): merge-order proposal with #10970 and #10983. Not checked.

Sources

Not verified

  • The 5-versus-12 result from the reviewer's compile test. Not run.
  • The #10970 and #10983 registration overlaps.
  • Any build or test result.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732245943 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#pullrequestreview-5732245943). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T04:56:52Z. **Review:** COMMENTED --- # Replies checked — EIP-relative ADCX/ADOX bug still present, docs duplicate confirmed The code at this head still drops the RIP-relative relocation for address-size-prefixed ADCX/ADOX, and the docs entry is duplicated after a merge with main. ## What I ran - Live head `65b4f1fc693e50ac8f14a32a7c7825479f31f40f` (OPEN). - `gh api` comments, review comments and reviews on #7173, newer than 2026-10-19T14:57:50Z, excluding MarcZX10 and bots. - `gh pr view 7173 --json statusCheckRollup`; `git show 65b4f1fc:<path>` for the three files below. - `git merge-tree --write-tree upstream/main 65b4f1fc`, then a grep count of the merged `relinker.md`. - Nothing built or run. ## Results | Check | Result | Note | |---|---|---| | Live head | matches batch | OPEN | | Merged docs entries (head + upstream/main) | 2 | upstream/main alone has 1 | | Hosted `conventions`, `relinker` (ubuntu, macOS, windows), `relinker-asan` | SUCCESS | `windows` aggregate, `linux`, `register-context`, `write-watch` SKIPPED | ## Findings - @oneandonlydean (2026-10-25, re-raised 2026-11-01 06:39 UTC): `DecodeAdx` clears `RipRelative` when the 0x67 prefix is present, and `EmitAdx` then copies the instruction without a relocation. Confirmed by reading: `AdxLowering.cpp` L168-L170 clears the flag, and L204-L206 relocate only when it is set. The test at L46 pins `!RipRelative`, so the current tests lock in the gap. Answer needed: fix it (preserve the target including 32-bit wrap) and add execution tests for ADCX and ADOX at a moved address. Not reproduced here. - @oneandonlydean (2026-11-01): drop the test that requires the RSP-destination form to throw. Confirmed at `AdxLoweringTests.cpp` L55-L62. Answer needed: remove it and keep the other checks. - @oneandonlydean (2026-10-28): the docs commit leaves two "`--to-rosetta` lowers what Rosetta lacks" entries after a merge with main. Confirmed: `relinker.md` L49-L50 at head, and two entries in the merged tree. Answer needed: keep one entry with the ADCX/ADOX wording on main's current line. - @AdnanKhan-ak47 (2026-10-25): merge-order proposal with #10970 and #10983. Not checked. ## Sources - https://github.com/boykopovar/AnyPS5/blob/65b4f1fc693e50ac8f14a32a7c7825479f31f40f/core/relinker/codegen/src/x86/AdxLowering.cpp#L168-L170 - https://github.com/boykopovar/AnyPS5/blob/65b4f1fc693e50ac8f14a32a7c7825479f31f40f/core/relinker/codegen/src/x86/AdxLowering.cpp#L204-L206 - https://github.com/boykopovar/AnyPS5/blob/65b4f1fc693e50ac8f14a32a7c7825479f31f40f/core/relinker/codegen/tests/AdxLoweringTests.cpp#L46 - https://github.com/boykopovar/AnyPS5/blob/65b4f1fc693e50ac8f14a32a7c7825479f31f40f/core/relinker/codegen/tests/AdxLoweringTests.cpp#L55-L62 - https://github.com/boykopovar/AnyPS5/blob/65b4f1fc693e50ac8f14a32a7c7825479f31f40f/docs/dev/debt/relinker.md#L49-L50 ## Not verified - The 5-versus-12 result from the reviewer's compile test. Not run. - The #10970 and #10983 registration overlaps. - Any build or test result.
catminou4 commented 2026-11-25 05:48:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by catminou4 on 2026-11-25T05:48:51Z.

Review: CHANGES_REQUESTED


Reviewed merged into current main (61d110125e, merge is textually clean) on Ubuntu 22.04, GCC 11.4, relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON).

  • Builds; ctest -R 'adx|amd64_only|rosetta|converter' (adx_lowering, to_rosetta, ...) all pass. Full relinker-only ctest -j8: 1116/1117 pass; the one failure, tools_headers_manifest, is a Python tools test that does not touch these files.
  • I read EmitAdx: the 144-byte frame stays below the red zone, the saved RFLAGS at [rsp+8] gets only CF (ADCX) or OF (ADOX) replaced from the ADC result, the BT [rsp+8], 11 seeds CF from OF for ADOX, and RSP-based memory sources get +144. That matches the SDM semantics.

Changes requested, in the debt only:

  • The PR edits docs/dev/debt/relinker.md directly. CONTRIBUTING says debt entries are added and changed through a fragment in docs/dev/debt/changes/.
  • The rewritten --to-rosetta entry is an old copy of the line. Merged into main it drops text already on main: "ANDN, BLSI, BLSMSK, BLSR, SHLX, SHRX, SARX, RORX, BZHI, BEXTR and MULX are lowered" (it becomes "ANDN is lowered"), the 200,000-random-input BMI1/BMI2 result on the M5, and "SHA and AVX-512F" in the M5 fault list. It also leaves "The conversions are covered by the converter tests." twice.
  • check_conventions.py on the merge warns debt-length for that entry (1842 characters).

Please rebase, drop the edit of the existing line, and put the ADCX/ADOX change (remove "ADCX/ADOX fault under Rosetta and are not converted ..." and add the new entry) in a fragment. #7531 carries the same commits plus more tests; one of the two should be closed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6052482710 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#pullrequestreview-6052482710). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T05:48:51Z. **Review:** CHANGES_REQUESTED --- Reviewed merged into current `main` (61d110125e, merge is textually clean) on Ubuntu 22.04, GCC 11.4, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`). - Builds; `ctest -R 'adx|amd64_only|rosetta|converter'` (`adx_lowering`, `to_rosetta`, ...) all pass. Full relinker-only `ctest -j8`: 1116/1117 pass; the one failure, `tools_headers_manifest`, is a Python tools test that does not touch these files. - I read `EmitAdx`: the 144-byte frame stays below the red zone, the saved RFLAGS at `[rsp+8]` gets only CF (ADCX) or OF (ADOX) replaced from the `ADC` result, the `BT [rsp+8], 11` seeds CF from OF for ADOX, and RSP-based memory sources get +144. That matches the SDM semantics. Changes requested, in the debt only: - The PR edits `docs/dev/debt/relinker.md` directly. CONTRIBUTING says debt entries are added and changed through a fragment in `docs/dev/debt/changes/`. - The rewritten `--to-rosetta` entry is an old copy of the line. Merged into `main` it **drops text already on `main`**: "ANDN, BLSI, BLSMSK, BLSR, SHLX, SHRX, SARX, RORX, BZHI, BEXTR and MULX are lowered" (it becomes "ANDN is lowered"), the 200,000-random-input BMI1/BMI2 result on the M5, and "SHA and AVX-512F" in the M5 fault list. It also leaves "The conversions are covered by the converter tests." twice. - `check_conventions.py` on the merge warns `debt-length` for that entry (1842 characters). Please rebase, drop the edit of the existing line, and put the ADCX/ADOX change (remove "ADCX/ADOX fault under Rosetta and are not converted ..." and add the new entry) in a fragment. #7531 carries the same commits plus more tests; one of the two should be closed.
ligmaSec commented 2026-12-03 12:01:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:01:07Z.

Review: COMMENTED


Built this head with ANYPS5_RELINKER_ONLY=ON and ran adx_lowering on Linux x86-64. It passed the ADCX and ADOX lowering cases. Native Rosetta execution remains outside this run.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6169355979 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7173#pullrequestreview-6169355979). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T12:01:07Z. **Review:** COMMENTED --- Built this head with `ANYPS5_RELINKER_ONLY=ON` and ran `adx_lowering` on Linux x86-64. It passed the ADCX and ADOX lowering cases. Native Rosetta execution remains outside this run. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/7173:upstream-pr/7173'
git switch 'upstream-pr/7173'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/7173'
git switch 'upstream-pr/7173'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/7173'
git switch 'upstream-pr/7173'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/7173'
git switch 'main'
git merge --squash 'upstream-pr/7173'
git switch 'main'
git merge --ff-only 'upstream-pr/7173'
git switch 'main'
git merge 'upstream-pr/7173'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7173
No description provided.