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

Manually merged
github merged 1 commit from gh-pr/1171/head into gh-pr/1171/base 2026-11-26 22:46:01 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 02:24 UTC · original
tedin7:x2w-cpu-switch-aot-inverted-unsigned-bound → main · +427 −5 · 6 files · 1 commits · merged 2026-11-24 03:25 UTC

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).

**@⁠tedin7** on GitHub · 2026-11-24 02:24 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1171) `tedin7:x2w-cpu-switch-aot-inverted-unsigned-bound` → `main` · +427 −5 · 6 files · 1 commits · merged 2026-11-24 03:25 UTC ## 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).
A compiler may branch to the dispatch block when the index is in range
(cmp reg, limit; jbe or jb to the block) and put a jmp to the default in
front of the block. The translator accepted only the fallthrough form
(ja or jae to the default) and refused this one as an unbounded index.

In the inverted form only JB and JBE enter the table, with limit and
limit + 1 entries. The jmp must sit directly in front of the block, and the
branch must target its first instruction and be the only edge that does.

The new fixture switch_inverted.asm exports three functions (MSVC and LLVM
layouts, 32- and 64-bit compares, a default before the check, a default that
does not store). The test compares native, translated and exchanged-table
builds with a Python reference, checks the guard words around the stored
word, and rejects 19 byte-patched copies.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:45:58 +00:00
github manually merged commit 1ced906547 into gh-pr/1171/base 2026-11-26 22:46:01 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 03:06 UTC · original · edited 2026-11-24 03:10 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-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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 03:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1171#issuecomment-7120772760) · edited 2026-11-24 03:10 UTC <!-- 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>
This discussion has been locked. Commenting is limited to contributors.
No description provided.