cpu: complete NEG, ADD and INC/DEC flag conditions in switch lifter #725

Merged
Ammmae0x merged 1 commit from upstream-pr/731 into main 2026-11-22 23:58:35 +00:00
Ammmae0x commented 2026-11-22 23:46:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-22T23:46:50Z.


Change

Complete arithmetic flag condition lowering in tools/cpu_switch_aot.py and expand cpu_aot_flag_conditions and docs/experiments.md:

  • NEG flag production & all 16 conditions: Add M.NEG to FLAG_PRODUCERS and enable sets_flags in Lifter.lower() (fa = static_cast<uN>(0u - a); evaluated once before storing, reusing mem from load_always for memory operands). Lower all 16 conditions in Lifter.condition() (CF = (flag_result != 0), OF = (flag_result == sign_bit), be = "true", a = "false", plus e/ne/s/ns/l/ge/le/g/o/no/p/np).
  • ADD carry and signed conditions: Add b/ae/be/a (flag_result < a, etc.) and l/ge/le/g alongside existing e/ne/s/ns/o/no/p/np.
  • INC and DEC signed conditions: Add l/ge/le/g while preserving rejection of carry conditions (b/ae/be/a, unsupported condition after ...) because INC and DEC preserve CF.
  • Fixtures & negative controls: Expand tests/cpu/flag_conditions.{asm,def} and tests/cpu/flag_conditions_check.py from 160 to 289 exports (8/16/32/64-bit Jcc/SETcc/CMOVcc, flags_neg_mem_32_b single-read load_always verification, SHL RAX, CL, 12 INC/DEC CF-condition rejections, and NOT rejection controls). Update tests/cpu/switch_check.py dummy flag-clobbering patch from NEG EAX (f7 d8) to SHL EAX, 1 (d1 e0).

Verification

Commit: 4656a4216bbf55c12b61cdfe041bb9ed63e23ffc on Windows 11 (26100.7623), MSVC 19.50.35727 (x64), ML64 14.50.35727.0, Python 3.12.8:

  • Targeted CPU builds (dev Debug & release /O2): cmake --build --preset dev --target cpu_flag_conditions cpu_flag_conditions_lifted cpu_switch_original_lifted cpu_switch_swapped_lifted cpu_register_probe and cmake --build --preset release --target ... — 0 errors, 0 warnings.
  • dev targeted flag/jump-table tests: ctest --preset dev --no-tests=error -R "^(cpu_aot_flag_conditions|cpu_aot_jump_tables)$" -V — 2 passed, 0 skipped, 0 failed (289 exports, 532,140 native/AOT/reference comparisons + 1,860 NEG [mem] comparisons + rejection controls).
  • dev CPU AOT/lower/leaf/bink/shim-warp suite: ctest --preset dev --no-tests=error -R "^cpu_(aot_|lower_|leaf_|working_|bink_)|^cpu_shim_" -E "_hardware$" — 97 passed, 0 skipped, 0 failed.
  • release targeted flag/jump-table tests: ctest --preset release --no-tests=error -R "^(cpu_aot_flag_conditions|cpu_aot_jump_tables)$" -V — 2 passed, 0 skipped, 0 failed.
  • release CPU AOT/lower/leaf/bink/shim-warp suite: ctest --preset release --no-tests=error -R "^cpu_(aot_|lower_|leaf_|working_|bink_)|^cpu_shim_" -E "_hardware$" — 97 passed, 0 skipped, 0 failed.
  • Full non-hardware suite (-E "_hardware$") on both dev and release: 239 passed, 2 capability-skipped (exit 77: bvh_wave64_warp, wave_shuffle_warp), 2 failed (cpu_native_archive_reader, cpu_native_archive_blast — optional ziglang module not installed locally).
  • Pure-Python checks (.\out\pe-env\Scripts\python.exe -B): tests/form_coverage_check.py, tests/docs_links_check.py, and tests/bidi_controls_check.py — all passed.

Evidence and follow-up

  • All fixtures in tests/cpu/flag_conditions.asm and tests/cpu/switch.asm are original source-built MASM fixtures verified differentially against native DLL execution and an independent Python reference.
  • Negative controls verify rejection of SHL RAX, CL, INC/DEC followed by JB/JAE/JBE/JA/SETB/CMOVB, and NOT as a flag producer or without a preceding producer.
  • No CMakeLists.txt changes were needed (cpu_aot_flag_conditions runs all exports from tests/cpu/flag_conditions.def and emits FORM_COVERAGE_RECORD).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

This change was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6549381265 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/731). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-22T23:46:50Z. --- ## Change Complete arithmetic flag condition lowering in `tools/cpu_switch_aot.py` and expand `cpu_aot_flag_conditions` and `docs/experiments.md`: - **`NEG` flag production & all 16 conditions**: Add `M.NEG` to `FLAG_PRODUCERS` and enable `sets_flags` in `Lifter.lower()` (`fa = static_cast<uN>(0u - a);` evaluated once before storing, reusing `mem` from `load_always` for memory operands). Lower all 16 conditions in `Lifter.condition()` (`CF = (flag_result != 0)`, `OF = (flag_result == sign_bit)`, `be = "true"`, `a = "false"`, plus `e/ne/s/ns/l/ge/le/g/o/no/p/np`). - **`ADD` carry and signed conditions**: Add `b/ae/be/a` (`flag_result < a`, etc.) and `l/ge/le/g` alongside existing `e/ne/s/ns/o/no/p/np`. - **`INC` and `DEC` signed conditions**: Add `l/ge/le/g` while preserving rejection of carry conditions (`b/ae/be/a`, `unsupported condition after ...`) because `INC` and `DEC` preserve `CF`. - **Fixtures & negative controls**: Expand `tests/cpu/flag_conditions.{asm,def}` and `tests/cpu/flag_conditions_check.py` from 160 to 289 exports (8/16/32/64-bit `Jcc`/`SETcc`/`CMOVcc`, `flags_neg_mem_32_b` single-read `load_always` verification, `SHL RAX, CL`, 12 `INC`/`DEC` CF-condition rejections, and `NOT` rejection controls). Update `tests/cpu/switch_check.py` dummy flag-clobbering patch from `NEG EAX` (`f7 d8`) to `SHL EAX, 1` (`d1 e0`). ## Verification Commit: `4656a4216bbf55c12b61cdfe041bb9ed63e23ffc` on Windows 11 (`26100.7623`), MSVC `19.50.35727` (x64), ML64 `14.50.35727.0`, Python `3.12.8`: - **Targeted CPU builds (`dev` Debug & `release` /O2)**: `cmake --build --preset dev --target cpu_flag_conditions cpu_flag_conditions_lifted cpu_switch_original_lifted cpu_switch_swapped_lifted cpu_register_probe` and `cmake --build --preset release --target ...` — **0 errors, 0 warnings**. - **`dev` targeted flag/jump-table tests**: `ctest --preset dev --no-tests=error -R "^(cpu_aot_flag_conditions|cpu_aot_jump_tables)$" -V` — **2 passed, 0 skipped, 0 failed** (289 exports, 532,140 native/AOT/reference comparisons + 1,860 `NEG [mem]` comparisons + rejection controls). - **`dev` CPU AOT/lower/leaf/bink/shim-warp suite**: `ctest --preset dev --no-tests=error -R "^cpu_(aot_|lower_|leaf_|working_|bink_)|^cpu_shim_" -E "_hardware$"` — **97 passed, 0 skipped, 0 failed**. - **`release` targeted flag/jump-table tests**: `ctest --preset release --no-tests=error -R "^(cpu_aot_flag_conditions|cpu_aot_jump_tables)$" -V` — **2 passed, 0 skipped, 0 failed**. - **`release` CPU AOT/lower/leaf/bink/shim-warp suite**: `ctest --preset release --no-tests=error -R "^cpu_(aot_|lower_|leaf_|working_|bink_)|^cpu_shim_" -E "_hardware$"` — **97 passed, 0 skipped, 0 failed**. - **Full non-hardware suite (`-E "_hardware$"`) on both `dev` and `release`**: **239 passed, 2 capability-skipped** (exit 77: `bvh_wave64_warp`, `wave_shuffle_warp`), **2 failed** (`cpu_native_archive_reader`, `cpu_native_archive_blast` — optional `ziglang` module not installed locally). - **Pure-Python checks (`.\out\pe-env\Scripts\python.exe -B`)**: `tests/form_coverage_check.py`, `tests/docs_links_check.py`, and `tests/bidi_controls_check.py` — **all passed**. ## Evidence and follow-up - All fixtures in `tests/cpu/flag_conditions.asm` and `tests/cpu/switch.asm` are original source-built MASM fixtures verified differentially against native DLL execution and an independent Python reference. - Negative controls verify rejection of `SHL RAX, CL`, `INC`/`DEC` followed by `JB/JAE/JBE/JA/SETB/CMOVB`, and `NOT` as a flag producer or without a preceding producer. - No `CMakeLists.txt` changes were needed (`cpu_aot_flag_conditions` runs all exports from `tests/cpu/flag_conditions.def` and emits `FORM_COVERAGE_RECORD`). ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. This change was AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:44:32 +00:00
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
R0Y00/Xbox2Windows!725
No description provided.