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

Merged
Vonsek merged 4 commits from upstream-pr/328 into main 2026-11-22 09:04:43 +00:00
Vonsek commented 2026-11-21 22:19:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T22:19:03Z.


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
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6535138112 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/328). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T22:19:03Z. --- ## 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
upstream-sync closed this pull request 2026-11-24 06:42:26 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:42:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T22:26:18Z.

Review: COMMENTED


💡 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6008602065 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/328#pullrequestreview-6008602065). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T22:26:18Z. **Review:** COMMENTED --- <!-- 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>
chatgpt-codex-connector[bot commented 2026-11-24 06:48:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T22:22:12Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070132481 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/328#issuecomment-7070132481). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T22:22:12Z. --- <!-- 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>
Vonsek commented 2026-11-24 06:48:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T22:30:16Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070227168 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/328#issuecomment-7070227168). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T22:30:16Z. --- 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`.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T22:26:19Z.

Code review location: tools/ffx_version_query.py; line 130

@@ -124,12 +124,10 @@ def write(expr):
             stmt = write(operand(1))
         elif op == M.MOVSXD:
             stmt = write(f"int64_t(int32_t({operand(1)}))")
-        elif op == M.CMOVNE:
-            stmt = write(f"zero ? {operand(0)} : {operand(1)}")
-        elif op == M.CMOVE:
-            stmt = write(f"zero ? {operand(1)} : {operand(0)}")
-        elif op == M.CMOVBE:
-            stmt = write(f"(carry || zero) ? {operand(1)} : {operand(0)}")
+        elif op in (M.CMOVE, M.CMOVNE, M.CMOVA, M.CMOVAE, M.CMOVB, M.CMOVBE):
+            cond = {M.CMOVE: "zero", M.CMOVNE: "!zero", M.CMOVA: "!carry && !zero",
+                    M.CMOVAE: "!carry", M.CMOVB: "carry", M.CMOVBE: "carry || zero"}[op]
+            stmt = write(f"({cond}) ? {operand(1)} : {operand(0)}")

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4655311648 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/328#discussion_r4655311648). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T22:26:19Z. **Code review location:** `tools/ffx_version_query.py`; line 130 ~~~~diff @@ -124,12 +124,10 @@ def write(expr): stmt = write(operand(1)) elif op == M.MOVSXD: stmt = write(f"int64_t(int32_t({operand(1)}))") - elif op == M.CMOVNE: - stmt = write(f"zero ? {operand(0)} : {operand(1)}") - elif op == M.CMOVE: - stmt = write(f"zero ? {operand(1)} : {operand(0)}") - elif op == M.CMOVBE: - stmt = write(f"(carry || zero) ? {operand(1)} : {operand(0)}") + elif op in (M.CMOVE, M.CMOVNE, M.CMOVA, M.CMOVAE, M.CMOVB, M.CMOVBE): + cond = {M.CMOVE: "zero", M.CMOVNE: "!zero", M.CMOVA: "!carry && !zero", + M.CMOVAE: "!carry", M.CMOVB: "carry", M.CMOVBE: "carry || zero"}[op] + stmt = write(f"({cond}) ? {operand(1)} : {operand(0)}") ~~~~ --- **<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 -->
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!323
No description provided.