cpu: lower unsigned and equality CMOVcc and SETcc forms #328

Manually merged
github merged 4 commits from gh-pr/328/head into gh-pr/328/base 2026-11-26 21:43:21 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 22:19 UTC · original
Vonsek:ag/cpu-lower-cmov-setcc → main · +265 −8 · 6 files · 4 commits · merged 2026-11-22 09:04 UTC

Change

  • Extend tools/ffx_version_query.py to lower all six unsigned/equality CMOVcc (cmove, cmovne, cmova, cmovae, cmovb, cmovbe) and SETcc (sete, setne, seta, setae, setb, setbe) instructions using the existing zero and carry flags, unconditionally zero-extending 32-bit CMOVcc destinations and preserving upper bytes on SETcc.
  • Add a source-built MASM fixture (tests/cpu/cmov_setcc.asm, tests/cpu/cmov_setcc.def) and differential test (tests/cpu/cmov_setcc.py) wired into CMakeLists.txt as cpu_aot_cmov_setcc, verifying all 13 exports across 1,300 cases against both the native DLL and a reference model.
  • Classify cmov_setcc -> cpu_aot_cmov_setcc in tools/form_coverage.py (+9 uncovered Integer mnemonics in docs/coverage/x64_zen2.tsv) and document the test in docs/experiments.md.

Verification

Tested on Windows 11 (VS 2022 Build Tools 17.14, MSVC 19.44, ML64 14.44, Windows SDK 10.0.26100, Python 3.12):

  • Before the change, cmake --build --preset dev --target cpu_cmov_setcc_lifted failed with:
    ValueError: unsupported query operation at 0x100c: cmova eax,r8d
    
  • After the change:
    • cmake --build --preset dev --target cpu_cmov_setcc_lifted succeeded.
    • ctest --preset dev --no-tests=error -R "^cpu_aot_cmov_setcc$" -V: passed (1300 CMOVcc and SETcc cases (cmova/ae/b/e, seta/ae/b/be/ne) matched native and translated DLLs).
    • python -B tests/form_coverage_check.py: form coverage checks passed.

Evidence and follow-up

  • Adds nine uncovered baseline x64 Integer mnemonics (cmova, cmovae, cmovb, cmove, seta, setae, setb, setbe, setne) to docs/coverage/x64_zen2.tsv coverage; all are part of baseline x86-64 and require no optional CPUID gate.
  • All binaries are source-built via MASM and CMake; no game files or external dumps are included.

Checklist

  • Focused, single-purpose change
  • Source-built test that fails without the change and passes with it
  • Verified locally on Windows
**@⁠Vonsek** on GitHub · 2026-11-21 22:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/328) `Vonsek:ag/cpu-lower-cmov-setcc` → `main` · +265 −8 · 6 files · 4 commits · merged 2026-11-22 09:04 UTC ## Change - Extend `tools/ffx_version_query.py` to lower all six unsigned/equality `CMOVcc` (`cmove`, `cmovne`, `cmova`, `cmovae`, `cmovb`, `cmovbe`) and `SETcc` (`sete`, `setne`, `seta`, `setae`, `setb`, `setbe`) instructions using the existing `zero` and `carry` flags, unconditionally zero-extending 32-bit `CMOVcc` destinations and preserving upper bytes on `SETcc`. - Add a source-built MASM fixture (`tests/cpu/cmov_setcc.asm`, `tests/cpu/cmov_setcc.def`) and differential test (`tests/cpu/cmov_setcc.py`) wired into `CMakeLists.txt` as `cpu_aot_cmov_setcc`, verifying all 13 exports across 1,300 cases against both the native DLL and a reference model. - Classify `cmov_setcc` -> `cpu_aot_cmov_setcc` in `tools/form_coverage.py` (+9 uncovered Integer mnemonics in `docs/coverage/x64_zen2.tsv`) and document the test in `docs/experiments.md`. ## Verification Tested on Windows 11 (VS 2022 Build Tools 17.14, MSVC 19.44, ML64 14.44, Windows SDK 10.0.26100, Python 3.12): - Before the change, `cmake --build --preset dev --target cpu_cmov_setcc_lifted` failed with: ```text ValueError: unsupported query operation at 0x100c: cmova eax,r8d ``` - After the change: - `cmake --build --preset dev --target cpu_cmov_setcc_lifted` succeeded. - `ctest --preset dev --no-tests=error -R "^cpu_aot_cmov_setcc$" -V`: passed (`1300 CMOVcc and SETcc cases (cmova/ae/b/e, seta/ae/b/be/ne) matched native and translated DLLs`). - `python -B tests/form_coverage_check.py`: `form coverage checks passed`. ## Evidence and follow-up - Adds nine uncovered baseline x64 Integer mnemonics (`cmova`, `cmovae`, `cmovb`, `cmove`, `seta`, `setae`, `setb`, `setbe`, `setne`) to `docs/coverage/x64_zen2.tsv` coverage; all are part of baseline x86-64 and require no optional CPUID gate. - All binaries are source-built via MASM and CMake; no game files or external dumps are included. ## Checklist - [x] Focused, single-purpose change - [x] Source-built test that fails without the change and passes with it - [x] Verified locally on Windows
Extend tools/ffx_version_query.py to lower all six unsigned/equality
CMOVcc (cmove, cmovne, cmova, cmovae, cmovb, cmovbe) and SETcc (sete,
setne, seta, setae, setb, setbe) instructions using the existing zero
and carry flag state.

Add a source-built MASM differential fixture (tests/cpu/cmov_setcc.asm,
tests/cpu/cmov_setcc.def, tests/cpu/cmov_setcc.py) registered as
cpu_aot_cmov_setcc in CMakeLists.txt, classified in
tools/form_coverage.py, and documented in docs/experiments.md.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:43:20 +00:00
github manually merged commit e4da0e3531 into gh-pr/328/base 2026-11-26 21:43:21 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 22:22 UTC · original · edited 2026-11-21 22:26 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T22:26:20.935176Z 3ca133f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 22:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/328#issuecomment-7070132481) · edited 2026-11-21 22:26 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"3ca133fd7541e41c8236934e20356a1863666b1f","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T22:26:20.935176Z">2026-11-21T22:26:20.935176Z</relative-time> | `3ca133f` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 22:26 UTC · original

P2 Badge Read CMOV memory sources unconditionally

For the newly accepted cmova/cmovae/cmovb memory-source forms, putting operand(1) inside ?: skips its load when the predicate is false. x86 reads a CMOV memory source regardless of the predicate: cmp ecx, ecx; cmova eax, [r8] must fault with null r8, but the emitted code returns normally. A Linux x64 probe confirmed this difference between native code and the generated C++. These forms previously failed translation, whereas they now silently suppress faults and corresponding exception handling. Use an unconditional, optimization-proof memory read, as tools/cpu_switch_aot.py already does, or continue rejecting memory-source forms.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 22:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/328#discussion_r4655311648) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Read CMOV memory sources unconditionally** For the newly accepted `cmova`/`cmovae`/`cmovb` memory-source forms, putting `operand(1)` inside `?:` skips its load when the predicate is false. x86 reads a CMOV memory source regardless of the predicate: `cmp ecx, ecx; cmova eax, [r8]` must fault with null `r8`, but the emitted code returns normally. A Linux x64 probe confirmed this difference between native code and the generated C++. These forms previously failed translation, whereas they now silently suppress faults and corresponding exception handling. Use an unconditional, optimization-proof memory read, as `tools/cpu_switch_aot.py` already does, or continue rejecting memory-source forms. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠Vonsek on GitHub · 2026-11-21 22:30 UTC · original

Rebased onto main and added an unconditional volatile load_always<T> read for CMOVcc memory sources so the memory operand is always read regardless of the predicate, plus a check in tests/cpu/cmov_setcc.py.

**@⁠Vonsek** on GitHub · 2026-11-21 22:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/328#issuecomment-7070227168) Rebased onto `main` and added an unconditional volatile `load_always<T>` read for `CMOVcc` memory sources so the memory operand is always read regardless of the predicate, plus a check in `tests/cpu/cmov_setcc.py`.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 22:26 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ca133fd75

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 22:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/328#pullrequestreview-6008602065) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `3ca133fd75` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.