cpu: support NEG flags and SETcc/CMOVcc in cpu_sse_aot #747

Merged
Ammmae0x merged 2 commits from upstream-pr/753 into main 2026-11-23 01:40:32 +00:00
Ammmae0x commented 2026-11-23 00:53:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T00:53:48Z.


Change

Fixes #743

Update ScalarLifter and lift() in tools/cpu_sse_aot.py so the scalar-float leaf lifter handles NEG flag producers and SETcc/CMOVcc GPR instructions via the shared cpu_switch_aot helpers:

  • Import CMOVCC, FLAG_PRODUCERS, SETCC, and flag_producer from cpu_switch_aot.
  • Allow FLAG_PRODUCERS (including NEG) in condition() instead of hardcoding (*ALU, CMP, TEST, INC, DEC).
  • Resolve flag_producer(function, edges, ins) for SETcc/CMOVcc instructions in lift(), mark their flag producers in sets_flags, and pass sets_flags and producer through ScalarLifter.statement() to Lifter.statement().
  • Add neg_jcc, setcc_mix, and cmovcc_mix fixtures (tests/cpu/scalar_float.asm, tests/cpu/scalar_float.def, CMakeLists.txt) plus positive and negative controls in tests/cpu/scalar_float_check.py.

Verification

Tested at commit d766349 (on upstream/main cfb2600) with MSVC 19.50.35727 (ml64 14.50.35727.0), Windows SDK 10.0.26100.0, CMake 4.2.3-msvc3, Ninja 1.12.1, and Python 3.12.8 (out/pe-env):

  • ctest --preset dev -N: 324 tests (dev and release, unchanged).
  • Affected targets (cpu_float_original, cpu_float_original_lifted, cpu_float_swapped, cpu_float_swapped_lifted): built in both dev and release with 0 errors and 0 warnings.
  • ctest --preset dev --no-tests=error -R "^cpu_" -V: 132 passed, 0 skipped, 2 failed (#197 cpu_native_archive_reader, #198 cpu_native_archive_blast, unrelated missing ziglang); #121 cpu_aot_scalar_float passed (1.14 s).
  • ctest --preset release --no-tests=error -R "^cpu_" -V: 132 passed, 0 skipped, 2 failed (same ziglang tests); #121 cpu_aot_scalar_float passed (0.95 s).
  • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: exit 0.
  • .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py: exit 0 (11 Markdown files, 135 links).
  • .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py: exit 0 (616 tracked files).

Evidence and follow-up

All new fixtures (neg_jcc, setcc_mix, cmovcc_mix) are source-built in tests/cpu/scalar_float.asm and cross-checked differentially between original and swapped builds against fixed reference answers. Negative controls in tests/cpu/scalar_float_check.py verify rejection of SETcc/CMOVcc after UCOMISS, SETcc/CMOVcc across joins/branches, second jumps after NEG, SETcc partial writes to an undefined GPR (r9), and 16-bit CMOVcc.

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.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6550057255 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/753). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-23T00:53:48Z. --- ## Change Fixes #743 Update `ScalarLifter` and `lift()` in `tools/cpu_sse_aot.py` so the scalar-float leaf lifter handles `NEG` flag producers and `SETcc`/`CMOVcc` GPR instructions via the shared `cpu_switch_aot` helpers: - Import `CMOVCC`, `FLAG_PRODUCERS`, `SETCC`, and `flag_producer` from `cpu_switch_aot`. - Allow `FLAG_PRODUCERS` (including `NEG`) in `condition()` instead of hardcoding `(*ALU, CMP, TEST, INC, DEC)`. - Resolve `flag_producer(function, edges, ins)` for `SETcc`/`CMOVcc` instructions in `lift()`, mark their flag producers in `sets_flags`, and pass `sets_flags` and `producer` through `ScalarLifter.statement()` to `Lifter.statement()`. - Add `neg_jcc`, `setcc_mix`, and `cmovcc_mix` fixtures (`tests/cpu/scalar_float.asm`, `tests/cpu/scalar_float.def`, `CMakeLists.txt`) plus positive and negative controls in `tests/cpu/scalar_float_check.py`. ## Verification Tested at commit `d766349` (on `upstream/main` `cfb2600`) with MSVC `19.50.35727` (`ml64` `14.50.35727.0`), Windows SDK `10.0.26100.0`, CMake `4.2.3-msvc3`, Ninja `1.12.1`, and Python `3.12.8` (`out/pe-env`): - `ctest --preset dev -N`: `324` tests (`dev` and `release`, unchanged). - Affected targets (`cpu_float_original`, `cpu_float_original_lifted`, `cpu_float_swapped`, `cpu_float_swapped_lifted`): built in both `dev` and `release` with `0` errors and `0` warnings. - `ctest --preset dev --no-tests=error -R "^cpu_" -V`: `132` passed, `0` skipped, `2` failed (`#197 cpu_native_archive_reader`, `#198 cpu_native_archive_blast`, unrelated missing `ziglang`); `#121 cpu_aot_scalar_float` passed (`1.14 s`). - `ctest --preset release --no-tests=error -R "^cpu_" -V`: `132` passed, `0` skipped, `2` failed (same `ziglang` tests); `#121 cpu_aot_scalar_float` passed (`0.95 s`). - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: exit `0`. - `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py`: exit `0` (`11` Markdown files, `135` links). - `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py`: exit `0` (`616` tracked files). ## Evidence and follow-up All new fixtures (`neg_jcc`, `setcc_mix`, `cmovcc_mix`) are source-built in `tests/cpu/scalar_float.asm` and cross-checked differentially between `original` and `swapped` builds against fixed reference answers. Negative controls in `tests/cpu/scalar_float_check.py` verify rejection of `SETcc`/`CMOVcc` after `UCOMISS`, `SETcc`/`CMOVcc` across joins/branches, second jumps after `NEG`, `SETcc` partial writes to an undefined GPR (`r9`), and 16-bit `CMOVcc`. ## 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. AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:44:37 +00:00
R0Y00 commented 2026-11-24 06:48:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T01:22:55Z.


I synchronized #752 from main in 2018706 after confirming the earlier Windows runs failed in the shared predicate-rounding test. The new Windows jobs will now test the SSE leaf change without that unrelated NameError.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7089097465 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/753#issuecomment-7089097465). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T01:22:55Z. --- I synchronized #752 from main in `2018706` after confirming the earlier Windows runs failed in the shared predicate-rounding test. The new Windows jobs will now test the SSE leaf change without that unrelated NameError.
FZNull commented 2026-11-24 06:48:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by FZNull on 2026-11-23T01:23:03Z.


Reviewed the diff while verifying something else. The code change looks right — I reproduced the three crashes from #743 on 356a7be (NEG+JE → ValueError unsupported flag producer, CMP+SETE/CMP+CMOVE → AttributeError 'NoneType' object has no attribute 'op0_kind') and they are gone with this branch. One thing blocks the checklist:

docs/experiments.md is not updated, but the PR checklist marks it done. This PR makes a documented "not covered" statement false. In the x87/SSE section of docs/experiments.md on main:

  • L2167: Not covered: RIP-relative constants, packed operations, SQRT, MIN and MAX, the rounding conversions, SETcc and CMOVcc after a compare, stack frames and calls. — this PR covers SETcc/CMOVcc after a compare, and NEG as a flag producer.
  • L2163: The source fixture exports six functions — tests/cpu/scalar_float.def gains exports here.
  • L2165: the list of patched instructions the test expects to reject — the new negative controls belong there.

The project convention (CONTRIBUTING.md, "Submit and review a patch": update the README row or docs/experiments.md when a public capability changes) makes this part of the change rather than a follow-up.

Optional follow-up, not a request to change this PR: condition() in tools/cpu_sse_aot.py still resolves a Jcc producer through its own, more restrictive path than SETcc/CMOVcc now use. From a scratch copy of this branch, cpu_switch_aot.flag_producer accepts cmp ecx, edx; mov r9d, eax; je, while cpu_sse_aot.translate_pe rejects the same shape with unsupported flag producer. It is a clean rejection, not a miscompile, so it could be its own item in the coordination issue.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7089099044 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/753#issuecomment-7089099044). Originally posted by [FZNull](https://github.com/FZNull) on 2026-11-23T01:23:03Z. --- Reviewed the diff while verifying something else. The code change looks right — I reproduced the three crashes from #743 on `356a7be` (`NEG+JE` → `ValueError unsupported flag producer`, `CMP+SETE`/`CMP+CMOVE` → `AttributeError 'NoneType' object has no attribute 'op0_kind'`) and they are gone with this branch. One thing blocks the checklist: **`docs/experiments.md` is not updated, but the PR checklist marks it done.** This PR makes a documented "not covered" statement false. In the x87/SSE section of `docs/experiments.md` on `main`: - L2167: `Not covered: RIP-relative constants, packed operations, SQRT, MIN and MAX, the rounding conversions, SETcc and CMOVcc after a compare, stack frames and calls.` — this PR covers `SETcc`/`CMOVcc` after a compare, and `NEG` as a flag producer. - L2163: `The source fixture exports six functions` — `tests/cpu/scalar_float.def` gains exports here. - L2165: the list of patched instructions the test expects to reject — the new negative controls belong there. The project convention (CONTRIBUTING.md, "Submit and review a patch": update the README row or `docs/experiments.md` when a public capability changes) makes this part of the change rather than a follow-up. Optional follow-up, not a request to change this PR: `condition()` in `tools/cpu_sse_aot.py` still resolves a `Jcc` producer through its own, more restrictive path than `SETcc`/`CMOVcc` now use. From a scratch copy of this branch, `cpu_switch_aot.flag_producer` accepts `cmp ecx, edx; mov r9d, eax; je`, while `cpu_sse_aot.translate_pe` rejects the same shape with `unsupported flag producer`. It is a clean rejection, not a miscompile, so it could be its own item in the coordination issue.
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!747
No description provided.