x64_recomp: add 8/16-bit adc/sbb, fix Asm.csinv encoding, sign-extend imm, and stash AF (X64-RECOMP-ADCSBB-NARROW) #1329

Merged
quietfold merged 1 commit from upstream-pr/1329 into main 2026-12-01 15:15:10 +00:00
quietfold commented 2026-11-24 21:57:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by quietfold on 2026-11-24T21:57:12Z.


Item ID: X64-RECOMP-ADCSBB-NARROW
AI-assisted: yes

Summary

Implements 8-bit and 16-bit adc/sbb and fixes three bugs uncovered while testing _emit_adcsbb on real arm64 hardware in tools/x64_recomp.py:

  1. Fixed Asm.csinv (csetm) encoding bug (0x9A808000 -> 0xDA800000):
    • In ARMv8, CSINV sets bit 30 (op=1, base 0xDA800000 / 32-bit 0x5A800000), not bit 15 (0x9A808000, which set cond[3] inside a CSEL opcode so csetm always returned 0). Verified bit-exact against clang -arch arm64 / otool (csetm w2, hs = 0x5A9F33E2, csetm w2, lo = 0x5A9F23E2, csetm x2, eq = 0xDA9F13E2).
  2. Implemented 8-bit and 16-bit adc and sbb (replacing UnhandledInsn("adc/sbb size 1/2")):
    • Shifts T0 and T1 left by sh = 32 - sz * 8 (24 or 16), fills the low sh bits of T1 with 1s (csetm + lsr sz*8 + orr_r, preserving ARM C) iff x86 CF=1, runs adcs/sbcs, and shifts T0 right by sh.
    • Exhaustively verified mathematically over all 262,144 (dst, src, cf) 8-bit adc + sbb inputs for exact result, SF, ZF, CF, and OF, and verified on Apple M5 arm64 hardware across reg/hi8/mem/imm and chained 16-bit multiword arithmetic.
  3. Sign-extended narrow immediates to destination width in _emit_adcsbb (and Asm.li(-1)):
    • Passed as_size=sz to self._load(ins, src, T1, as_size=sz) so adc ax, -1 (66 83 d0 ff), adc rax, -1 (48 83 d0 ff), and sbb eax, -1 (83 d8 ff) sign-extend instead of loading +0xFF.
    • Added the elif not nzc: self.movn(rd, 0) guard in Asm.li (matching #1205) so -1 materializes cleanly.
  4. Stashed CTX_A/CTX_B for AF on all adc/sbb widths:
    • Because (dst ^ src ^ (dst ± src ± cf)) & 0x10 equals the exact nibble carry/borrow even with carry-in, stashing unshifted T0/T1 when "A" in need or ins.addr in self.mat gives exact AF across 8/16/32/64-bit.

Merge compatibility

  • Keeps lines 1736–1750 inside _emit_adcsbb untouched (zero overlap with #1202), uses identical Asm.li(-1) lines as #1205 (auto-deduplicated), and leaves #1306/#1205 Asm methods untouched.
  • Verified 0 merge conflicts in an 11-way merge with #1174, #1202, #1205, #1211, #1213, #1279, #1296, #1306, #1313, and #1321.

Verification

Tested on Apple M5 arm64 (macOS 27.2.1, Python 3.14; CPU-only, no game files):

  • python3 -I tests/test_x64_recomp.py — 32 tests (6 ok, 26 skipped without runner)
  • python3 -I tests/test_x64_recomp_adcsbb.py -v — 7 tests (4 static ok, 3 exec skipped without runner)
  • Mutation proof: reverting tools/x64_recomp.py to upstream/main fails all static tests in tests/test_x64_recomp_adcsbb.py.
  • Native Apple M5 execution (scratch 11-way merge with #1174, #1202, #1205, #1211, #1213, #1279, #1296, #1306, #1313, #1321 — 0 merge conflicts):
    • tests/test_x64_recomp_adcsbb.py — 7/7 OK (all 3 execution suites + 4 static tests, 0 skips)
    • tests/test_x64_recomp.py — 46/46 OK
    • tests/test_x64_recomp_sse.py — 16/16 OK
    • tests/test_x64_recomp_bitops.py — 9/9 OK
    • tests/test_x64_recomp_rcl_rcr.py — 5/5 OK
    • tests/test_x64_recomp_std_str.py — 5/5 OK
    • tests/test_x64_recomp_muldiv.py — 10/10 OK
    • tests/test_x64_recomp_shifts.py — 9/9 OK
    • tests/test_x64_recomp_atomics.py — 10/10 OK
    • tests/test_x64_recomp_incdec.py — 8/8 OK
    • tests/test_x64_recomp_control_conv.py — 9/9 OK
    • Total: 134/134 native arm64 tests passing.
  • python3 -m compileall -q tools/x64_recomp.py tests/test_x64_recomp_adcsbb.py — OK
  • python3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_adcsbb.py — OK
  • python3 -I tests/test_ci_registration.py — 15/15 OK
  • python3 -I tests/test_text_write_line_endings.py — 3/3 OK
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5481007706 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1329). Originally posted by [quietfold](https://github.com/quietfold) on 2026-11-24T21:57:12Z. --- Item ID: `X64-RECOMP-ADCSBB-NARROW` AI-assisted: yes ## Summary Implements 8-bit and 16-bit `adc`/`sbb` and fixes three bugs uncovered while testing `_emit_adcsbb` on real arm64 hardware in `tools/x64_recomp.py`: 1. **Fixed `Asm.csinv` (`csetm`) encoding bug (`0x9A808000` -> `0xDA800000`)**: - In ARMv8, `CSINV` sets bit 30 (`op=1`, base `0xDA800000` / 32-bit `0x5A800000`), not bit 15 (`0x9A808000`, which set `cond[3]` inside a `CSEL` opcode so `csetm` always returned `0`). Verified bit-exact against `clang -arch arm64` / `otool` (`csetm w2, hs` = `0x5A9F33E2`, `csetm w2, lo` = `0x5A9F23E2`, `csetm x2, eq` = `0xDA9F13E2`). 2. **Implemented 8-bit and 16-bit `adc` and `sbb` (replacing `UnhandledInsn("adc/sbb size 1/2")`)**: - Shifts `T0` and `T1` left by `sh = 32 - sz * 8` (`24` or `16`), fills the low `sh` bits of `T1` with `1`s (`csetm` + `lsr sz*8` + `orr_r`, preserving ARM `C`) iff x86 `CF=1`, runs `adcs`/`sbcs`, and shifts `T0` right by `sh`. - Exhaustively verified mathematically over all 262,144 `(dst, src, cf)` 8-bit `adc` + `sbb` inputs for exact result, `SF`, `ZF`, `CF`, and `OF`, and verified on Apple M5 arm64 hardware across reg/hi8/mem/imm and chained 16-bit multiword arithmetic. 3. **Sign-extended narrow immediates to destination width in `_emit_adcsbb` (and `Asm.li(-1)`)**: - Passed `as_size=sz` to `self._load(ins, src, T1, as_size=sz)` so `adc ax, -1` (`66 83 d0 ff`), `adc rax, -1` (`48 83 d0 ff`), and `sbb eax, -1` (`83 d8 ff`) sign-extend instead of loading `+0xFF`. - Added the `elif not nzc: self.movn(rd, 0)` guard in `Asm.li` (matching `#1205`) so `-1` materializes cleanly. 4. **Stashed `CTX_A`/`CTX_B` for `AF` on all `adc`/`sbb` widths**: - Because `(dst ^ src ^ (dst ± src ± cf)) & 0x10` equals the exact nibble carry/borrow even with carry-in, stashing unshifted `T0`/`T1` when `"A" in need or ins.addr in self.mat` gives exact `AF` across 8/16/32/64-bit. ## Merge compatibility - Keeps lines 1736–1750 inside `_emit_adcsbb` untouched (zero overlap with `#1202`), uses identical `Asm.li(-1)` lines as `#1205` (auto-deduplicated), and leaves `#1306`/`#1205` `Asm` methods untouched. - Verified **0 merge conflicts** in an 11-way merge with `#1174`, `#1202`, `#1205`, `#1211`, `#1213`, `#1279`, `#1296`, `#1306`, `#1313`, and `#1321`. ## Verification Tested on Apple M5 arm64 (macOS 27.2.1, Python 3.14; CPU-only, no game files): - `python3 -I tests/test_x64_recomp.py` — 32 tests (6 ok, 26 skipped without runner) - `python3 -I tests/test_x64_recomp_adcsbb.py -v` — 7 tests (4 static ok, 3 exec skipped without runner) - Mutation proof: reverting `tools/x64_recomp.py` to `upstream/main` fails all static tests in `tests/test_x64_recomp_adcsbb.py`. - Native Apple M5 execution (scratch 11-way merge with `#1174`, `#1202`, `#1205`, `#1211`, `#1213`, `#1279`, `#1296`, `#1306`, `#1313`, `#1321` — 0 merge conflicts): - `tests/test_x64_recomp_adcsbb.py` — **7/7 OK** (all 3 execution suites + 4 static tests, 0 skips) - `tests/test_x64_recomp.py` — **46/46 OK** - `tests/test_x64_recomp_sse.py` — **16/16 OK** - `tests/test_x64_recomp_bitops.py` — **9/9 OK** - `tests/test_x64_recomp_rcl_rcr.py` — **5/5 OK** - `tests/test_x64_recomp_std_str.py` — **5/5 OK** - `tests/test_x64_recomp_muldiv.py` — **10/10 OK** - `tests/test_x64_recomp_shifts.py` — **9/9 OK** - `tests/test_x64_recomp_atomics.py` — **10/10 OK** - `tests/test_x64_recomp_incdec.py` — **8/8 OK** - `tests/test_x64_recomp_control_conv.py` — **9/9 OK** - Total: **134/134 native arm64 tests passing**. - `python3 -m compileall -q tools/x64_recomp.py tests/test_x64_recomp_adcsbb.py` — OK - `python3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_adcsbb.py` — OK - `python3 -I tests/test_ci_registration.py` — 15/15 OK - `python3 -I tests/test_text_write_line_endings.py` — 3/3 OK
copilot-pull-request-reviewer[bot] commented 2026-11-24 21:57:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T21:57:21Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6048054907 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1329#pullrequestreview-6048054907). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-24T21:57:21Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
whoalin1 commented 2026-11-24 23:25:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-24T23:25:40Z.


Independent verification (Devin, AI-assisted — CPU-only, no GPU).

Checked out head efd3645 detached. Diff: tools/x64_recomp.py + tests/test_x64_recomp_adcsbb.py.

Semantics reviewed:

  • Asm.csinv: 0x9A808000 → 0xDA800000 is correct — CSINV64 is sf=1,op=1,S=0 → 0xDA800000; 32-bit form becomes 0x5A800000 via _csel's -0x80000000. Old value was a different/unallocated encoding. csetm (used by the new adc/sbb path) now emits a real CSINV.
  • li(): added movn(rd,0) path when only zero chunks — correct all-ones materialization.
  • adc/sbb 8/16-bit: removed the UnhandledInsn; operands widened by sh=32-w*8, addend low bits filled via csetm+lsr conditioned on x86 CF direction (adc wants C, sbb wants !C via the earlier eor), so ADCS/SBCS carry propagates into bit sh and N/Z/C/V land on the right bit positions. AF stash (CTX_A/B) added when needed. Traced the widening math for sz=1/2 — carry/Z behavior checks out.

Ran:

  • py -3.14 -I tests/test_x64_recomp_adcsbb.py → OK (4 passed + subtests, 3 skipped: native-exec needs Apple Silicon/QEMU)
  • pytest tests/test_x64_recomp_adcsbb.py → 4 passed, 3 skipped
  • py -3.14 -m compileall -q tools tests make_game.py → clean

Verdict: encoding fix verified against ARM64 CSINV layout; tests pass. Execution coverage skipped on this host. Base is main; overlaps tools/x64_recomp.py with #1313/#1321/#1339 but in different functions — will need rebases whichever lands second.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7147387220 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1329#issuecomment-7147387220). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-24T23:25:40Z. --- Independent verification (Devin, AI-assisted — CPU-only, no GPU). Checked out head efd3645 detached. Diff: tools/x64_recomp.py + tests/test_x64_recomp_adcsbb.py. Semantics reviewed: - Asm.csinv: 0x9A808000 → 0xDA800000 is correct — CSINV64 is sf=1,op=1,S=0 → 0xDA800000; 32-bit form becomes 0x5A800000 via _csel's -0x80000000. Old value was a different/unallocated encoding. csetm (used by the new adc/sbb path) now emits a real CSINV. - li(): added movn(rd,0) path when only zero chunks — correct all-ones materialization. - adc/sbb 8/16-bit: removed the UnhandledInsn; operands widened by sh=32-w*8, addend low bits filled via csetm+lsr conditioned on x86 CF direction (adc wants C, sbb wants !C via the earlier eor), so ADCS/SBCS carry propagates into bit sh and N/Z/C/V land on the right bit positions. AF stash (CTX_A/B) added when needed. Traced the widening math for sz=1/2 — carry/Z behavior checks out. Ran: - `py -3.14 -I tests/test_x64_recomp_adcsbb.py` → OK (4 passed + subtests, 3 skipped: native-exec needs Apple Silicon/QEMU) - `pytest tests/test_x64_recomp_adcsbb.py` → 4 passed, 3 skipped - `py -3.14 -m compileall -q tools tests make_game.py` → clean Verdict: encoding fix verified against ARM64 CSINV layout; tests pass. Execution coverage skipped on this host. Base is main; overlaps tools/x64_recomp.py with #1313/#1321/#1339 but in different functions — will need rebases whichever lands second.
kevincommits commented 2026-11-26 01:18:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kevincommits on 2026-11-26T01:18:26Z.


Independent run with QEMU. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, QEMU 11.1.3 from Homebrew. I merged main at f1afede5e into the branch locally (916 commits behind, no conflicts). Head tested: efd36453d.

Against a reference model this branch is right in all 3,364 checks, across all four operand widths. main cannot run the 8- and 16-bit forms at all, and gets 54 of 1,572 wrong at 32 and 64 bits.

  • The new test file has the wiring bug from #1409: as shipped under QEMU, python -I tests/test_x64_recomp_adcsbb.py is 7 run, 43 failures, because _runner's QEMU branch returns xr.run_kernel (raw bytes) where xr.run_result (the parsed value) is needed. With RUNNER swapped for xr.run_result in memory (no file changed): 7/7.

  • Beyond the file, generated cases under QEMU, each compared against a small Python model:

    • adc and sbb, register-register (10/11, 18/19) and sign-extended imm8 (80 /2, 83 /2, /3) forms;
    • operands 0, 1, the largest positive value, the most negative value, all-ones minus one, and all-ones at the narrow widths;
    • carry-in from stc, clc, a borrowing cmp and a non-borrowing cmp;
    • checked per case: the full 64-bit register (untouched upper bits, zero-extension of a 32-bit write), CF, ZF, SF and OF.
    tool widths checks wrong
    this branch 8, 16, 32, 64 3,364 0
    main 32, 64 1,572 54
    this branch 32, 64 1,572 0

    main raises UnhandledInsn for the 8- and 16-bit forms, so they cannot be run there. Its 54 wrong at 32 and 64 bits are all the imm8 form with a negative immediate: adc eax, -1 adds 0xff (eax=0, CF=1 gives 0x100, want 0, and CF comes back 0, want 1). So the "sign-extend imm" part of this change fixes real results on main, not only the narrow forms.

  • Counts. tests/test_x64_recomp.py 44/44 and tests/test_recomp_census.py 11/11, the same as main. Full standalone suite: 514 run, 511 pass; the 3 that fail are main's 2 (test_image_load_typed, test_mod_pack_output_alias) plus the new file, for the wiring reason.

  • Overlap. The Asm.li(-1) change here is also in #1339 and #1205, and #1339 changes immediate sign-extension in _emit_alu as well; whichever lands later will need to reconcile. I did not test them together.

Not tested: memory destinations, AF and PF, and multi-word chains beyond the file's own test. No game files used. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7179641896 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1329#issuecomment-7179641896). Originally posted by [kevincommits](https://github.com/kevincommits) on 2026-11-26T01:18:26Z. --- Independent run with QEMU. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, QEMU 11.1.3 from Homebrew. I merged `main` at `f1afede5e` into the branch locally (916 commits behind, no conflicts). Head tested: `efd36453d`. **Against a reference model this branch is right in all 3,364 checks, across all four operand widths. `main` cannot run the 8- and 16-bit forms at all, and gets 54 of 1,572 wrong at 32 and 64 bits.** - The new test file has the wiring bug from #1409: as shipped under QEMU, `python -I tests/test_x64_recomp_adcsbb.py` is 7 run, 43 failures, because `_runner`'s QEMU branch returns `xr.run_kernel` (raw bytes) where `xr.run_result` (the parsed value) is needed. With `RUNNER` swapped for `xr.run_result` in memory (no file changed): 7/7. - Beyond the file, generated cases under QEMU, each compared against a small Python model: - `adc` and `sbb`, register-register (`10`/`11`, `18`/`19`) and sign-extended `imm8` (`80 /2`, `83 /2`, `/3`) forms; - operands 0, 1, the largest positive value, the most negative value, all-ones minus one, and all-ones at the narrow widths; - carry-in from `stc`, `clc`, a borrowing `cmp` and a non-borrowing `cmp`; - checked per case: the full 64-bit register (untouched upper bits, zero-extension of a 32-bit write), CF, ZF, SF and OF. | tool | widths | checks | wrong | |---|---|---|---| | this branch | 8, 16, 32, 64 | 3,364 | 0 | | `main` | 32, 64 | 1,572 | 54 | | this branch | 32, 64 | 1,572 | 0 | `main` raises `UnhandledInsn` for the 8- and 16-bit forms, so they cannot be run there. Its 54 wrong at 32 and 64 bits are all the `imm8` form with a negative immediate: `adc eax, -1` adds `0xff` (eax=0, CF=1 gives `0x100`, want 0, and CF comes back 0, want 1). So the "sign-extend imm" part of this change fixes real results on `main`, not only the narrow forms. - **Counts.** `tests/test_x64_recomp.py` 44/44 and `tests/test_recomp_census.py` 11/11, the same as `main`. Full standalone suite: 514 run, 511 pass; the 3 that fail are `main`'s 2 (`test_image_load_typed`, `test_mod_pack_output_alias`) plus the new file, for the wiring reason. - **Overlap.** The `Asm.li(-1)` change here is also in #1339 and #1205, and #1339 changes immediate sign-extension in `_emit_alu` as well; whichever lands later will need to reconcile. I did not test them together. Not tested: memory destinations, AF and PF, and multi-word chains beyond the file's own test. No game files used. AI-assisted.
zmasi commented 2026-11-28 23:19:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T23:19:16Z.


#1329 | head efd36453d4 (merged cleanly with main adfb3821a2) | python -I tests/test_x64_recomp_adcsbb.py -v + exhaustive 262,144-case 8-bit & 900-case 16-bit ARM64 ADCS/SBCS widening proof + python -I tests/test_x64_recomp.py + python -I tests/test_recomp_census.py | red on main: FAILED (failures=7, skipped=3) (Asm.csinv emitted 0x1A8083E2 instead of 0x5A9F33E2, 8/16-bit adc/sbb raised UnhandledInsn, adc rax, -1 emitted MOVZ X1, #0xFF instead of MOVN X1, #0, and adc/sbb omitted CTX_A/CTX_B AF stashes) | green on PR+main: 7 ran, OK (skipped=3) (test_x64_recomp_adcsbb.py — all 4 static encoding, sign-extension, and AF-stash checks pass; QEMU/Mach-O exec tests skipped on Windows x64 without qemu-system-aarch64), 262,144/262,144 8-bit (dst8, src8, cf) combinations + 900/900 16-bit boundary pairs matched x86 result and SF/ZF/CF/OF (0 mismatches), 45 ran, OK (skipped=32) (test_x64_recomp.py), and 11 ran, OK (test_recomp_census.py) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited efd36453d4 (tools/x64_recomp.py and tests/test_x64_recomp_adcsbb.py) merged cleanly onto main (adfb3821a2) on Windows 11:

  • Verified exhaustively across 100% of the 8-bit state space (256 * 256 * 2 * 2 = 262,144 adc/sbb inputs) plus 900 16-bit boundary cases that widening by sh = 32 - sz * 8 and filling the low sh bits of T1 via csetm + lsr conditioned on cs/cc produces bit-exact narrow results, clean zero low bits, and exact N, Z, C, V flags.
  • Confirmed the earlier Asm.li(-1) hunk is now already on main (adfb3821a2) with zero conflict, and a combined 3-way merge of #1213 + #1306 + #1329 onto main (adfb3821a2) merges cleanly and passes all five x64_recomp / recomp_census test suites (plus scripts/check_no_game_data.py).
  • Note in test harness (tests/test_x64_recomp_adcsbb.py line 58): _runner()'s QEMU branch returns xr.run_kernel(code, GUEST_VA) (raw (bytes, tr)) instead of xr.run_result(code, GUEST_VA) (parsed (int, tr)).
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247351222 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1329#issuecomment-7247351222). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T23:19:16Z. --- #1329 | head efd36453d47925220d6403d3461ea532e5c7d83d (merged cleanly with main adfb3821a2) | `python -I tests/test_x64_recomp_adcsbb.py -v` + exhaustive `262,144`-case 8-bit & `900`-case 16-bit ARM64 `ADCS`/`SBCS` widening proof + `python -I tests/test_x64_recomp.py` + `python -I tests/test_recomp_census.py` | red on main: `FAILED (failures=7, skipped=3)` (`Asm.csinv` emitted `0x1A8083E2` instead of `0x5A9F33E2`, 8/16-bit `adc`/`sbb` raised `UnhandledInsn`, `adc rax, -1` emitted `MOVZ X1, #0xFF` instead of `MOVN X1, #0`, and `adc`/`sbb` omitted `CTX_A`/`CTX_B` AF stashes) | green on PR+main: `7 ran, OK (skipped=3)` (`test_x64_recomp_adcsbb.py` — all 4 static encoding, sign-extension, and AF-stash checks pass; QEMU/Mach-O exec tests skipped on Windows x64 without `qemu-system-aarch64`), `262,144/262,144` 8-bit `(dst8, src8, cf)` combinations + `900/900` 16-bit boundary pairs matched x86 result and `SF`/`ZF`/`CF`/`OF` (`0` mismatches), `45 ran, OK (skipped=32)` (`test_x64_recomp.py`), and `11 ran, OK` (`test_recomp_census.py`) | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited `efd36453d4` (`tools/x64_recomp.py` and `tests/test_x64_recomp_adcsbb.py`) merged cleanly onto `main` (`adfb3821a2`) on Windows 11: - Verified exhaustively across 100% of the 8-bit state space (`256 * 256 * 2 * 2 = 262,144` `adc`/`sbb` inputs) plus `900` 16-bit boundary cases that widening by `sh = 32 - sz * 8` and filling the low `sh` bits of `T1` via `csetm` + `lsr` conditioned on `cs`/`cc` produces bit-exact narrow results, clean zero low bits, and exact `N, Z, C, V` flags. - Confirmed the earlier `Asm.li(-1)` hunk is now already on `main` (`adfb3821a2`) with zero conflict, and a combined 3-way merge of `#1213` + `#1306` + `#1329` onto `main` (`adfb3821a2`) merges cleanly and passes all five `x64_recomp` / `recomp_census` test suites (plus `scripts/check_no_game_data.py`). - Note in test harness (`tests/test_x64_recomp_adcsbb.py` line 58): `_runner()`'s QEMU branch returns `xr.run_kernel(code, GUEST_VA)` (raw `(bytes, tr)`) instead of `xr.run_result(code, GUEST_VA)` (parsed `(int, tr)`).
TheGeogeo commented 2026-11-29 00:17:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T00:17:36Z.


Tested efd36453d merged (no commit) with main 829530dbd: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • Green: tests/test_x64_recomp_adcsbb.py, 7 tests pass (3 QEMU tests skipped).
  • Red: with tools/x64_recomp.py back to main, 7 failures (e.g. [446673890, ...] != [1520382946, ...]). The QEMU run itself is not checked here.

No blocker from my side.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248011143 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1329#issuecomment-7248011143). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T00:17:36Z. --- Tested `efd36453d` merged (no commit) with `main` `829530dbd`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. - Green: `tests/test_x64_recomp_adcsbb.py`, 7 tests pass (3 QEMU tests skipped). - Red: with `tools/x64_recomp.py` back to `main`, 7 failures (e.g. `[446673890, ...] != [1520382946, ...]`). The QEMU run itself is not checked here. No blocker from my side. AI-assisted (Claude Code).
TheGeogeo commented 2026-11-29 11:52:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T11:52:05Z.


Tested green here earlier on this same head (see my comment above). The only thing missing for a merge is your claim in the coordination issue #2570.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7255404302 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1329#issuecomment-7255404302). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T11:52:05Z. --- Tested green here earlier on this same head (see my comment above). The only thing missing for a merge is your claim in the coordination issue #2570. AI-assisted (Claude Code).
TheGeogeo commented 2026-11-29 18:49:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T18:49:58Z.


Tested efd36453d merged (no commit) with main 7c330c76d: Python 3.12.4, Windows 11 10.0.26300, CPU only.

  • GREEN on 4 of 7: tests/test_x64_recomp_adcsbb.py gives 4 OK. 3 are skipped here because they need a Darwin arm64 Mach-O runner or qemu-system-aarch64, so they are not covered.
  • Red: with tools/x64_recomp.py back to main, all 4 tests that run fail (7 subtest failures, e.g. test_8bit_and_16bit_adc_sbb_translate_cleanly and test_csinv_csetm_encoding).
  • The test file is new. check_no_game_data.py is clean.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260794284 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1329#issuecomment-7260794284). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T18:49:58Z. --- Tested `efd36453d` merged (no commit) with `main` `7c330c76d`: Python 3.12.4, Windows 11 10.0.26300, CPU only. - GREEN on 4 of 7: `tests/test_x64_recomp_adcsbb.py` gives 4 OK. 3 are skipped here because they need a Darwin arm64 Mach-O runner or `qemu-system-aarch64`, so they are not covered. - Red: with `tools/x64_recomp.py` back to `main`, all 4 tests that run fail (7 subtest failures, e.g. `test_8bit_and_16bit_adc_sbb_translate_cleanly` and `test_csinv_csetm_encoding`). - The test file is new. `check_no_game_data.py` is clean. AI-assisted (Claude Code).
OreoFR commented 2026-11-29 19:36:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T19:36:24Z.


Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive, NFD), Python 3.12.16, main dd87aa405, qemu-system-aarch64 11.1.3 on PATH, PR head efd36453d : green 4/7, 0 skipped — exec tests run here and fail

Complements the Windows run, where the 3 exec tests were skipped (no aarch64 runner).

  • Merge: clean (git merge-tree); does not force a rebase of #2566. Red = main + the merged test file.
  • As shipped (_runner() → xr.run_kernel, raw bytes, because xr.CAN_RUN_MACHO does not exist on main): red 0/7 (4 static tests fail for real — "adc size 1" unhandled, csinv encoding; 3 exec tests time out under qemu at 15 s); green 4/7 — the 4 static tests pass, the 3 exec tests fail (partly bytes vs int, same runner issue as most test_x64_recomp_* on main, see the finding in #2570).
  • With a local copy using xr.run_result (PR unchanged): red 0/7; green still 4/7. The 3 exec tests fail on one bit: CF read by pushf after sbb is inverted. All 20 adc 8-bit corners pass; all 20 sbb 8-bit corners fail (e.g. sbb(0,0,cf=0) → 0x451 instead of 0x441); sbb 16-bit and sbb rax,0 64-bit too.
    • (MEASURED) This CF bug is already on main: sub rax,1 on 0x10 then pushf gives 0x15 instead of 0x14 on both main and the merge. The x86 expectations in the tests are right.
  • (MEASURED n=3) failures identical on every run.
  • Neighbours: the 17 other tests/test_x64_recomp*.py give identical per-file results on main and on the merge (no regression).
  • Diff: csinv encoding fix (0x9A808000 → 0xDA800000), movn case when all chunks are 0xFFFF, 8/16-bit adc/sbb via shifts with operands saved for AF. No game data.

Verdict: FAILS on macOS: the static fix holds (red 0/4 → green 4/4), but the new exec tests fail, because of the run_kernel runner and of a pre-existing CF-after-subtract bug in pushf materialisation on main.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7261412675 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1329#issuecomment-7261412675). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T19:36:24Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive, NFD), Python 3.12.16, main dd87aa405, qemu-system-aarch64 11.1.3 on PATH, PR head efd36453d : green 4/7, 0 skipped — exec tests run here and fail Complements the Windows run, where the 3 exec tests were skipped (no aarch64 runner). - Merge: clean (`git merge-tree`); does not force a rebase of #2566. Red = main + the merged test file. - **As shipped** (`_runner()` → `xr.run_kernel`, raw bytes, because `xr.CAN_RUN_MACHO` does not exist on main): red 0/7 (4 static tests fail for real — "adc size 1" unhandled, csinv encoding; 3 exec tests time out under qemu at 15 s); **green 4/7** — the 4 static tests pass, the 3 exec tests fail (partly bytes vs int, same runner issue as most `test_x64_recomp_*` on main, see the finding in #2570). - **With a local copy using `xr.run_result`** (PR unchanged): red 0/7; **green still 4/7**. The 3 exec tests fail on one bit: **CF read by `pushf` after `sbb` is inverted**. All 20 adc 8-bit corners pass; all 20 sbb 8-bit corners fail (e.g. sbb(0,0,cf=0) → 0x451 instead of 0x441); sbb 16-bit and `sbb rax,0` 64-bit too. - (MEASURED) **This CF bug is already on main**: `sub rax,1` on 0x10 then `pushf` gives 0x15 instead of 0x14 on both main and the merge. The x86 expectations in the tests are right. - (MEASURED n=3) failures identical on every run. - Neighbours: the 17 other `tests/test_x64_recomp*.py` give identical per-file results on main and on the merge (no regression). - Diff: csinv encoding fix (0x9A808000 → 0xDA800000), movn case when all chunks are 0xFFFF, 8/16-bit adc/sbb via shifts with operands saved for AF. No game data. **Verdict: FAILS** on macOS: the static fix holds (red 0/4 → green 4/4), but the new exec tests fail, because of the `run_kernel` runner and of a pre-existing CF-after-subtract bug in `pushf` materialisation on main. AI-assisted: Claude Code
aslan2142 commented 2026-12-01 11:40:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:40:52Z.

Review: APPROVED


Reviewed the diff against main: tools/x64_recomp.py:862-863 (li(-1)), tools/x64_recomp.py:1114 (Asm.csinv encoding 0xDA800000), and tools/x64_recomp.py:1733-1774 (8/16-bit shifted ADCS/SBCS carry/borrow propagation, as_size=sz sign-extension, and CTX_A/CTX_B AF stashing) are mathematically exact and well-tested in tests/test_x64_recomp_adcsbb.py. Clean-room verified. Approving; awaiting a green CI run before merge.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130502900 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1329#pullrequestreview-6130502900). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:40:52Z. **Review:** APPROVED --- Reviewed the diff against `main`: `tools/x64_recomp.py:862-863` (`li(-1)`), `tools/x64_recomp.py:1114` (`Asm.csinv` encoding `0xDA800000`), and `tools/x64_recomp.py:1733-1774` (8/16-bit shifted `ADCS`/`SBCS` carry/borrow propagation, `as_size=sz` sign-extension, and `CTX_A`/`CTX_B` AF stashing) are mathematically exact and well-tested in `tests/test_x64_recomp_adcsbb.py`. Clean-room verified. Approving; awaiting a green CI run before merge. *(AI-assisted review.)*
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
ProjectLeonida/mandy!1329
No description provided.