cpu: lower signed 32-bit comparison branches in cpu_leaf_aot #258

Merged
Vonsek merged 2 commits from upstream-pr/261 into main 2026-11-22 03:40:54 +00:00
Vonsek commented 2026-11-21 19:38:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:38:05Z.


Change

  • Add signed 32-bit comparison short jumps (jl 0x7c, jge 0x7d, jle 0x7e, jg 0x7f) after cmp eax, imm8 / cmp eax, imm32 in tools/cpu_leaf_aot.py, emitting static_cast<std::int32_t> comparisons.
  • Extend tests/cpu/branch.asm with two signed stages — cmp eax, -12 (jl/jge, sign-extended imm8) and cmp eax, -300 (jle/jg, imm32) — in both the normal and INVERT_BRANCH builds.
  • Update tests/cpu/branches.py to model the signed stages and verify native, translated, and inverted outputs across 367 inputs hitting <, ==, and > at every threshold (including 0x7fffffff and 0x80000000).

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, building cpu_leaf_original_lifted failed with:
    unsupported or incomplete instruction at RVA 0x1056
    
  • After the change:
    • cmake --build --preset dev --target cpu_leaf_original_lifted cpu_leaf_inverted_lifted succeeded.
    • ctest --preset dev --no-tests=error -R "^cpu_leaf_aot_branches$" -V: passed (367 native/translated matches and 367 inverted-branch differences across jb/jae, je/jne, jbe/ja, jl/jge, jle/jg, 32-bit immediates and sign-extended imm8).

Evidence and follow-up

  • tools/cpu_leaf_aot.py previously lowered the six unsigned/equality short conditional jumps (0x72..0x77) after cmp eax, imm8/imm32 but rejected the four signed counterparts (0x7c..0x7f).
  • All fixtures 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:6533495602 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/261). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:38:05Z. --- ## Change - Add signed 32-bit comparison short jumps (`jl` `0x7c`, `jge` `0x7d`, `jle` `0x7e`, `jg` `0x7f`) after `cmp eax, imm8` / `cmp eax, imm32` in `tools/cpu_leaf_aot.py`, emitting `static_cast<std::int32_t>` comparisons. - Extend `tests/cpu/branch.asm` with two signed stages — `cmp eax, -12` (`jl`/`jge`, sign-extended `imm8`) and `cmp eax, -300` (`jle`/`jg`, `imm32`) — in both the normal and `INVERT_BRANCH` builds. - Update `tests/cpu/branches.py` to model the signed stages and verify native, translated, and inverted outputs across 367 inputs hitting `<`, `==`, and `>` at every threshold (including `0x7fffffff` and `0x80000000`). ## 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, building `cpu_leaf_original_lifted` failed with: ```text unsupported or incomplete instruction at RVA 0x1056 ``` - After the change: - `cmake --build --preset dev --target cpu_leaf_original_lifted cpu_leaf_inverted_lifted` succeeded. - `ctest --preset dev --no-tests=error -R "^cpu_leaf_aot_branches$" -V`: passed (`367 native/translated matches and 367 inverted-branch differences across jb/jae, je/jne, jbe/ja, jl/jge, jle/jg, 32-bit immediates and sign-extended imm8`). ## Evidence and follow-up - `tools/cpu_leaf_aot.py` previously lowered the six unsigned/equality short conditional jumps (`0x72..0x77`) after `cmp eax, imm8/imm32` but rejected the four signed counterparts (`0x7c..0x7f`). - All fixtures 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:06 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:42:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:44:20Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4dc7c97c97

ℹ️ 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:6007744918 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/261#pullrequestreview-6007744918). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:44:20Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `4dc7c97c97` <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:47:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:40:49Z.


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-21T19:44:22.319834Z 4dc7c97 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:7068198174 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/261#issuecomment-7068198174). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:40:49Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"4dc7c97c97ceae1d1916fd1a1e1f5022baa64b74","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-21T19:44:22.319834Z">2026-11-21T19:44:22.319834Z</relative-time> | `4dc7c97` | 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:47:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:47:54Z.


Updated the leaf-recompilation section in docs/experiments.md to document jl/jge and jle/jg, both imm8 and imm32 compare encodings, and the 367-input signed-boundary and inverted-branch coverage.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068285246 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/261#issuecomment-7068285246). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:47:54Z. --- Updated the leaf-recompilation section in `docs/experiments.md` to document `jl`/`jge` and `jle`/`jg`, both `imm8` and `imm32` compare encodings, and the 367-input signed-boundary and inverted-branch coverage.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:44:20Z.

Code review location: tools/cpu_leaf_aot.py; line 50

@@ -38,12 +38,16 @@ def function_bytes(image, name):
 
 
 CONDITIONS = {
-    0x72: "<",
-    0x73: ">=",
-    0x74: "==",
-    0x75: "!=",
-    0x76: "<=",
-    0x77: ">",
+    0x72: ("<", False),
+    0x73: (">=", False),
+    0x74: ("==", False),
+    0x75: ("!=", False),
+    0x76: ("<=", False),
+    0x77: (">", False),
+    0x7c: ("<", True),
+    0x7d: (">=", True),
+    0x7e: ("<=", True),
+    0x7f: (">", True),

P1 Badge Document the new signed-branch capability

Adding these signed jump forms changes the public capability of the leaf translator, but neither the README nor the experiment notes are updated: docs/experiments.md:71–73 still describes unsigned JB/JAE support and unsigned-only fixture validation. Root AGENTS.md explicitly requires a documentation update when a public capability changes. Update the leaf-recompilation section to describe jl/jge, jle/jg, both immediate encodings, and the signed-boundary/inverted-control coverage so contributors can discover and reproduce the newly supported behavior.

AGENTS.md reference: AGENTS.md:L145-L146

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4654641904 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/261#discussion_r4654641904). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:44:20Z. **Code review location:** `tools/cpu_leaf_aot.py`; line 50 ~~~~diff @@ -38,12 +38,16 @@ def function_bytes(image, name): CONDITIONS = { - 0x72: "<", - 0x73: ">=", - 0x74: "==", - 0x75: "!=", - 0x76: "<=", - 0x77: ">", + 0x72: ("<", False), + 0x73: (">=", False), + 0x74: ("==", False), + 0x75: ("!=", False), + 0x76: ("<=", False), + 0x77: (">", False), + 0x7c: ("<", True), + 0x7d: (">=", True), + 0x7e: ("<=", True), + 0x7f: (">", True), ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new signed-branch capability** Adding these signed jump forms changes the public capability of the leaf translator, but neither the README nor the experiment notes are updated: `docs/experiments.md:71–73` still describes unsigned JB/JAE support and unsigned-only fixture validation. Root `AGENTS.md` explicitly requires a documentation update when a public capability changes. Update the leaf-recompilation section to describe `jl/jge`, `jle/jg`, both immediate encodings, and the signed-boundary/inverted-control coverage so contributors can discover and reproduce the newly supported behavior. AGENTS.md reference: [AGENTS.md:L145-L146](https://github.com/R0Y00/Xbox2Windows/blob/4dc7c97c97ceae1d1916fd1a1e1f5022baa64b74/AGENTS.md#L145-L146) 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!258
No description provided.