cpu: accept an inverted unsigned bound check in the jump-table translator #1164

Merged
tedin7 merged 1 commit from upstream-pr/1171 into main 2026-11-24 03:25:08 +00:00
tedin7 commented 2026-11-24 02:24:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T02:24:20Z.


Change

Refs #317. tools/cpu_switch_aot.py now accepts the inverted unsigned bound check in front of a jump-table dispatch: cmp reg, limit; jb/jbe dispatch_block; jmp default. Before, only the fallthrough form (ja/jae to the default) was recognized, and this shape was refused as unbounded jump-table index.

  • Only JB and JBE enter the table in this form, with limit and limit + 1 entries.
  • A JMP must sit directly in front of the dispatch block. The branch must target the first instruction of the block and be the only edge that does.
  • Rejected: second entry into the block, JA/JAE or a signed condition, a missing JMP, a branch past the top of the block, an index that is not the compared value.
  • Touches dispatch() and prove() only. No change to the ABI, frames, calls or data binding.

Shared interface: none beyond cpu_switch_aot.py. No open PR touches that file.

Verification

Not run on Windows (no ML64 or MSVC here). The new CTest cpu_aot_switch_inverted runs in the Windows jobs, including /O2.

Linux (LLVM 19 llvm-mc and lld-link from a GNU-syntax copy of the MASM source, mingw-w64 g++ -O0 and -O2 for the translation, Wine 10 for the run):

  • python3 -B tests/cpu/switch_inverted_check.py rejections <dll>: 19 rejection controls passed. On origin/main the same command fails at the first translation (unbounded jump-table index).
  • Native vs translated vs exchanged-table build, 540, 585 and 630 inputs for the three exports (1,755 in total), at -O0 and -O2: all match the Python reference on return value and the three output words; the exchanged build changed only its two selectors (1/4, 1/5, 0/5). RBX/RSI are checked only by the Windows register probe.
  • Mutants of the translator all fail: JBE counted as limit entries aborts at selector 4; no single-entry check accepts the two second-entry controls; JA accepted in the inverted form accepts the JA control.
  • The seven existing jump-table fixtures (built the same way) translate to byte-identical C++ with and without the change, and switch_check.py rejections passes on both (16 + 3 controls).
  • tests/docs_links_check.py, tests/form_coverage_check.py, tests/bidi_controls_check.py: pass.

Evidence and follow-up

tests/cpu/switch_inverted.asm is original MASM written for this test. It exports inv_rva_jbe (MSVC layout, 32-bit JBE, 5 entries), inv_rel_jb (LLVM layout, 64-bit JB, 6 entries, one shared target; the default returns all ones and does not store) and inv_rel_window_jbe (LLVM layout, JBE, 7 entries, default in front of the check, zero-extending copy inside the block). Guard words on both sides of the stored word must not change, including for selectors past the table and selectors with upper bits set.

Assumption: the MASM source assembles with ML64 as the existing fixtures do; I could only check an equivalent copy with LLVM. docs/experiments.md has the new paragraph and the exact commands.

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 (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6573195119 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1171). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T02:24:20Z. --- ## Change Refs #317. `tools/cpu_switch_aot.py` now accepts the inverted unsigned bound check in front of a jump-table dispatch: `cmp reg, limit; jb/jbe dispatch_block; jmp default`. Before, only the fallthrough form (`ja`/`jae` to the default) was recognized, and this shape was refused as `unbounded jump-table index`. - Only `JB` and `JBE` enter the table in this form, with `limit` and `limit + 1` entries. - A `JMP` must sit directly in front of the dispatch block. The branch must target the first instruction of the block and be the only edge that does. - Rejected: second entry into the block, `JA`/`JAE` or a signed condition, a missing `JMP`, a branch past the top of the block, an index that is not the compared value. - Touches `dispatch()` and `prove()` only. No change to the ABI, frames, calls or data binding. Shared interface: none beyond `cpu_switch_aot.py`. No open PR touches that file. ## Verification Not run on Windows (no ML64 or MSVC here). The new CTest `cpu_aot_switch_inverted` runs in the Windows jobs, including `/O2`. Linux (LLVM 19 `llvm-mc` and `lld-link` from a GNU-syntax copy of the MASM source, mingw-w64 g++ `-O0` and `-O2` for the translation, Wine 10 for the run): - `python3 -B tests/cpu/switch_inverted_check.py rejections <dll>`: 19 rejection controls passed. On `origin/main` the same command fails at the first translation (`unbounded jump-table index`). - Native vs translated vs exchanged-table build, 540, 585 and 630 inputs for the three exports (1,755 in total), at `-O0` and `-O2`: all match the Python reference on return value and the three output words; the exchanged build changed only its two selectors (1/4, 1/5, 0/5). RBX/RSI are checked only by the Windows register probe. - Mutants of the translator all fail: JBE counted as `limit` entries aborts at selector 4; no single-entry check accepts the two second-entry controls; JA accepted in the inverted form accepts the JA control. - The seven existing jump-table fixtures (built the same way) translate to byte-identical C++ with and without the change, and `switch_check.py rejections` passes on both (16 + 3 controls). - `tests/docs_links_check.py`, `tests/form_coverage_check.py`, `tests/bidi_controls_check.py`: pass. ## Evidence and follow-up `tests/cpu/switch_inverted.asm` is original MASM written for this test. It exports `inv_rva_jbe` (MSVC layout, 32-bit JBE, 5 entries), `inv_rel_jb` (LLVM layout, 64-bit JB, 6 entries, one shared target; the default returns all ones and does not store) and `inv_rel_window_jbe` (LLVM layout, JBE, 7 entries, default in front of the check, zero-extending copy inside the block). Guard words on both sides of the stored word must not change, including for selectors past the table and selectors with upper bits set. Assumption: the MASM source assembles with ML64 as the existing fixtures do; I could only check an equivalent copy with LLVM. `docs/experiments.md` has the new paragraph and the exact commands. ## 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 (Claude Code).
upstream-sync closed this pull request 2026-11-24 06:46:40 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:50:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:06:10Z.


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-24T03:10:43.829402Z 1ced906 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:7120772760 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1171#issuecomment-7120772760). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T03:06:10Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"1ced90654712e02d566d99029b297ae699d7fad9","has_any_findings":false,"has_unresolved_findings":false,"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-24T03:10:43.829402Z">2026-11-24T03:10:43.829402Z</relative-time> | `1ced906` | 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>
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!1164
No description provided.