cpu: cover seven jump-table dispatch lowerings #669

Merged
Leyukaka merged 1 commit from upstream-pr/675 into main 2026-11-22 20:02:00 +00:00
Leyukaka commented 2026-11-22 19:22:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-22T19:22:50Z.


Change

This closes seven coverage gaps in the jump-table dispatch lowering of tools/cpu_switch_aot.py. Each was a one-line mutation that passed every cpu_ test on main. The switch fixture, its check, its export list in CMakeLists.txt and docs/experiments.md change; the translator does not.

tests/cpu/switch.asm gains select_rel_edges: a three-entry LLVM-layout table bounded by JAE, with the default placed before the guard, all three entries aliasing one target placed more than 32 KiB before the table, and a zero DWORD after the table. switch_check.py runs it on the source, translated and swapped-table builds, and adds three byte-patch rejection controls.

New case Mutation it covers
select_rva patched to cmp ecx, 7 + JGE, must be rejected signed JGE bound accepted
select_rel_edges builds and selector 3 takes the default JAE table counted one entry too many
REX.W added to the select_rva table load, must be rejected 64-bit table load accepted
select_rel_edges(0, x) reaches the far target entries sign-extended from 16 bits
select_rel_edges load base patched to R11, must be rejected load base not compared with the added base
select_rel_edges(3, x) takes the backward JAE backward default branch sent to the first case
select_rel_edges(2, x) reaches the third alias only the first two aliases labelled

Two of the mutations (JAE count, 16-bit entries) make the translator reject select_rel_edges, so they fail at build time. The 16-bit case needs the target more than 32 KiB away, hence the padding.

Verification

On d3b58ee (branch on ff7f68a), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14:

ctest --preset dev --no-tests=error -j 4

All 295 tests pass. tests/docs_links_check.py passes.

Each mutation was applied to tools/cpu_switch_aot.py one at a time, and all cpu_ tests were run. On main, all of them passed for each mutation. A control that dropped the + 1 for JA bounds was caught by cpu_aot_jump_tables and cpu_aot_image_data, so the run does detect a broken translator. On this branch, five mutations fail cpu_aot_jump_tables, and the other two fail the build because the translation of select_rel_edges is rejected (edge at RVA ... overlaps an instruction, edge outside owned ranges). With the third-alias mutation, the lifted function reaches abort(), which in a Debug build opens the CRT dialog, so that case ends only when the dialog closes.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6546665554 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/675). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-22T19:22:50Z. --- ## Change This closes seven coverage gaps in the jump-table dispatch lowering of `tools/cpu_switch_aot.py`. Each was a one-line mutation that passed every `cpu_` test on `main`. The switch fixture, its check, its export list in `CMakeLists.txt` and `docs/experiments.md` change; the translator does not. `tests/cpu/switch.asm` gains `select_rel_edges`: a three-entry LLVM-layout table bounded by `JAE`, with the default placed before the guard, all three entries aliasing one target placed more than 32 KiB before the table, and a zero DWORD after the table. `switch_check.py` runs it on the source, translated and swapped-table builds, and adds three byte-patch rejection controls. | New case | Mutation it covers | |---|---| | `select_rva` patched to `cmp ecx, 7` + `JGE`, must be rejected | signed `JGE` bound accepted | | `select_rel_edges` builds and selector 3 takes the default | `JAE` table counted one entry too many | | REX.W added to the `select_rva` table load, must be rejected | 64-bit table load accepted | | `select_rel_edges(0, x)` reaches the far target | entries sign-extended from 16 bits | | `select_rel_edges` load base patched to R11, must be rejected | load base not compared with the added base | | `select_rel_edges(3, x)` takes the backward `JAE` | backward default branch sent to the first case | | `select_rel_edges(2, x)` reaches the third alias | only the first two aliases labelled | Two of the mutations (`JAE` count, 16-bit entries) make the translator reject `select_rel_edges`, so they fail at build time. The 16-bit case needs the target more than 32 KiB away, hence the padding. ## Verification On `d3b58ee` (branch on `ff7f68a`), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14: ```text ctest --preset dev --no-tests=error -j 4 ``` All 295 tests pass. `tests/docs_links_check.py` passes. Each mutation was applied to `tools/cpu_switch_aot.py` one at a time, and all `cpu_` tests were run. On `main`, all of them passed for each mutation. A control that dropped the `+ 1` for `JA` bounds was caught by `cpu_aot_jump_tables` and `cpu_aot_image_data`, so the run does detect a broken translator. On this branch, five mutations fail `cpu_aot_jump_tables`, and the other two fail the build because the translation of `select_rel_edges` is rejected (`edge at RVA ... overlaps an instruction`, `edge outside owned ranges`). With the third-alias mutation, the lifted function reaches `abort()`, which in a Debug build opens the CRT dialog, so that case ends only when the dialog closes. ## 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.
upstream-sync closed this pull request 2026-11-24 06:44:15 +00:00
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!669
No description provided.