cpu: bind two ordinary import slots in one jump-table translation #779

Merged
lukaslw-lab merged 3 commits from upstream-pr/785 into main 2026-11-23 04:12:39 +00:00
lukaslw-lab commented 2026-11-23 03:10:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T03:10:25Z.


Change

tools/cpu_switch_aot.py binds two ordinary IAT slots in one translation. --bind PROVIDER SYMBOL is repeatable; with several, the --link-name, --import-arguments and --return-bytes after each --bind belong to it. Each binding names a distinct ordinary import of the image and binds the slot that holds it, with its own argument count and guaranteed return bytes. A single --bind parses and translates as before: all 15 single-binding translations in the build (13 named, 2 ordinal) are byte-identical to the output of the translator at 761e323. cpu_translation() forwards a second binding from SECOND_*. Fixes #767. Refs #317, #572, #655.

  • Rejected: a reached slot that no binding names, two bindings of one import, a binding that names no import of the image, an unused binding, and two bindings that would declare the same C name.
  • Imports are declared in IAT slot order, so reordering the --bind groups does not change the source.
  • Command line: an option before the first of several --bind, an option given twice for one --bind, and a --bind without its numbers are errors.

Verification

Full runs at commit a61fe79 (on upstream/main a4c6c06), on Windows 10 Pro 22H2 (build 19045.7846), Visual Studio 2026 18.12 (MSVC 19.52.37029), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7, both presets configured with DXC_EXECUTABLE set to DXC 1.9.2609.

cmake --build --preset dev
ctest --preset dev --no-tests=error
99% tests passed, 1 tests failed out of 345
     76 - gpu_alias_lookup_writes_warp (Failed)

cmake --preset release && cmake --build --preset release
ctest --preset release --no-tests=error -R '^cpu_'
100% tests passed, 0 tests failed out of 136

dev: 304 passed, 40 skipped (exit 77), 1 failed. release: 130 passed, 6 skipped.

After rebasing onto 81cf1e3 (shader and tooling commits only, no overlap with the translator or its fixtures), commit 522e0a4 was rebuilt and the import tests and the link check rerun:

ctest --preset dev --no-tests=error -R '^cpu_aot_(two_slots|import)|docs_links'
100% tests passed, 0 tests failed out of 5

cpu_aot_two_slots, cpu_aot_import_call, cpu_aot_import_calls and cpu_aot_import_tail_jump pass in both presets. Skips are capability skips of this machine (Windows 10 in-box runtime without SM 6.5/6.6 or DXR, a 32-lane GPU without native wave64, and CPU features such as SHA, ADX, CLWB and CLFLUSHOPT). gpu_alias_lookup_writes_warp fails on main too: Windows 10 in-box WARP applies InterlockedAdd through a dynamically indexed buffer array four times (#332).

A local git merge-tree (at a61fe79) against the heads of the 52 open PRs that also edit CMakeLists.txt or docs/experiments.md gave the same conflicting files and hunk counts with and without this commit, so it adds no conflict to them. No open PR touches cpu_switch_aot.py, cpu_call_aot.py or the import fixtures.

Evidence and follow-up

New source-built fixture (MIT): two_slots.asm and slot_provider.cpp (fold4, four arguments, 16-bit result), reusing the mix3 providers of cpu_aot_import_tail_jump. Callers: named, mix3 altered, fold4 altered, and mix3 by ordinal #3 (link name mix3). route2 reaches mix3 by an ordinary call and fold4 by a tail jump after the epilogue and by a thunk call; call_both calls both on one path.

Requirement (#767 and the review comment) Evidence in cpu_aot_two_slots
Native and AOT match the argument trace, published result and returned bytes on both paths 3 exports × 249 pairs per caller: native = translated = Python reference on RAX, guarded trace (incl. fold4's R9) and RBX/RSI
Distinguishable provider results; each import site uses its own slot altered mix3 changes only the mix3 path, altered fold4 only the two fold4 paths; ordinal caller = named caller
Own argument count and return width per binding, including the tail jump mix3(rcx, rdx, r8) and fold4(rcx, rdx, r8, r9); route2 width 2 (8 when fold4 states 8) from the tail jump; too few bytes stated for either binding, or four arguments for mix3, are rejected
Each binding by name or ordinal #3 with link name mix3 next to named fold4; #3 without its link name rejected
Second slot with only the first binding rejected call or tail jump through a second IAT slot RVA 0x2000
Conflicting binding for the same slot rejected two bindings of …!mix3 (read as two bindings of one import, here with 8 and 1 bytes)
Provider or symbol mismatch rejected binding …!fold4 names no ordinary import of the image (wrong provider), same for fold3 (wrong symbol)
Existing single-binding positive and malformed controls still pass cpu_aot_import_call, cpu_aot_import_calls, cpu_aot_import_tail_jump unchanged and passing in dev and release; their generated sources are byte-identical to the previous translator's
Repeatable --bind, single-binding command unchanged a single --bind after its options translates as before
Argument-order check reversed groups give the same source; options swapped between groups, an option before the first group, an option twice, a missing --return-bytes are refused
Focused CTest, dev and release, first diagnostic cpu_aot_two_slots; results above; before the change the two-group command failed with unbound import cpu_tail_named_provider.dll!mix3 at IAT slot RVA 0x2010 (only the last --bind counted)
  • 10 rejection and 4 command-line controls in total; also an unused binding and two bindings declaring the same C name.
  • Delay imports and dynamically selected targets stay outside the fixture. The providers' contracts are known from source, as in the existing import tests.

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: prepared with Claude Code; the commands and results above were run on the author's PC.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6551453370 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/785). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-23T03:10:25Z. --- ## Change `tools/cpu_switch_aot.py` binds two ordinary IAT slots in one translation. `--bind PROVIDER SYMBOL` is repeatable; with several, the `--link-name`, `--import-arguments` and `--return-bytes` after each `--bind` belong to it. Each binding names a distinct ordinary import of the image and binds the slot that holds it, with its own argument count and guaranteed return bytes. A single `--bind` parses and translates as before: all 15 single-binding translations in the build (13 named, 2 ordinal) are byte-identical to the output of the translator at `761e323`. `cpu_translation()` forwards a second binding from `SECOND_*`. Fixes #767. Refs #317, #572, #655. - Rejected: a reached slot that no binding names, two bindings of one import, a binding that names no import of the image, an unused binding, and two bindings that would declare the same C name. - Imports are declared in IAT slot order, so reordering the `--bind` groups does not change the source. - Command line: an option before the first of several `--bind`, an option given twice for one `--bind`, and a `--bind` without its numbers are errors. ## Verification Full runs at commit `a61fe79` (on `upstream/main` `a4c6c06`), on Windows 10 Pro 22H2 (build 19045.7846), Visual Studio 2026 18.12 (MSVC 19.52.37029), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7, both presets configured with `DXC_EXECUTABLE` set to DXC 1.9.2609. cmake --build --preset dev ctest --preset dev --no-tests=error 99% tests passed, 1 tests failed out of 345 76 - gpu_alias_lookup_writes_warp (Failed) cmake --preset release && cmake --build --preset release ctest --preset release --no-tests=error -R '^cpu_' 100% tests passed, 0 tests failed out of 136 `dev`: 304 passed, 40 skipped (exit 77), 1 failed. `release`: 130 passed, 6 skipped. After rebasing onto `81cf1e3` (shader and tooling commits only, no overlap with the translator or its fixtures), commit `522e0a4` was rebuilt and the import tests and the link check rerun: ctest --preset dev --no-tests=error -R '^cpu_aot_(two_slots|import)|docs_links' 100% tests passed, 0 tests failed out of 5 `cpu_aot_two_slots`, `cpu_aot_import_call`, `cpu_aot_import_calls` and `cpu_aot_import_tail_jump` pass in both presets. Skips are capability skips of this machine (Windows 10 in-box runtime without SM 6.5/6.6 or DXR, a 32-lane GPU without native wave64, and CPU features such as SHA, ADX, CLWB and CLFLUSHOPT). `gpu_alias_lookup_writes_warp` fails on main too: Windows 10 in-box WARP applies `InterlockedAdd` through a dynamically indexed buffer array four times (#332). A local `git merge-tree` (at `a61fe79`) against the heads of the 52 open PRs that also edit `CMakeLists.txt` or `docs/experiments.md` gave the same conflicting files and hunk counts with and without this commit, so it adds no conflict to them. No open PR touches `cpu_switch_aot.py`, `cpu_call_aot.py` or the import fixtures. ## Evidence and follow-up New source-built fixture (MIT): `two_slots.asm` and `slot_provider.cpp` (`fold4`, four arguments, 16-bit result), reusing the `mix3` providers of `cpu_aot_import_tail_jump`. Callers: named, `mix3` altered, `fold4` altered, and `mix3` by ordinal `#3` (link name `mix3`). `route2` reaches `mix3` by an ordinary call and `fold4` by a tail jump after the epilogue and by a thunk call; `call_both` calls both on one path. | Requirement (#767 and the review comment) | Evidence in `cpu_aot_two_slots` | |---|---| | Native and AOT match the argument trace, published result and returned bytes on both paths | 3 exports × 249 pairs per caller: native = translated = Python reference on RAX, guarded trace (incl. `fold4`'s R9) and RBX/RSI | | Distinguishable provider results; each import site uses its own slot | altered `mix3` changes only the `mix3` path, altered `fold4` only the two `fold4` paths; ordinal caller = named caller | | Own argument count and return width per binding, including the tail jump | `mix3(rcx, rdx, r8)` and `fold4(rcx, rdx, r8, r9)`; `route2` width 2 (8 when `fold4` states 8) from the tail jump; too few bytes stated for either binding, or four arguments for `mix3`, are rejected | | Each binding by name or ordinal | `#3` with link name `mix3` next to named `fold4`; `#3` without its link name rejected | | Second slot with only the first binding rejected | `call or tail jump through a second IAT slot RVA 0x2000` | | Conflicting binding for the same slot rejected | `two bindings of …!mix3` (read as two bindings of one import, here with 8 and 1 bytes) | | Provider or symbol mismatch rejected | `binding …!fold4 names no ordinary import of the image` (wrong provider), same for `fold3` (wrong symbol) | | Existing single-binding positive and malformed controls still pass | `cpu_aot_import_call`, `cpu_aot_import_calls`, `cpu_aot_import_tail_jump` unchanged and passing in `dev` and `release`; their generated sources are byte-identical to the previous translator's | | Repeatable `--bind`, single-binding command unchanged | a single `--bind` after its options translates as before | | Argument-order check | reversed groups give the same source; options swapped between groups, an option before the first group, an option twice, a missing `--return-bytes` are refused | | Focused CTest, `dev` and `release`, first diagnostic | `cpu_aot_two_slots`; results above; before the change the two-group command failed with `unbound import cpu_tail_named_provider.dll!mix3 at IAT slot RVA 0x2010` (only the last `--bind` counted) | - 10 rejection and 4 command-line controls in total; also an unused binding and two bindings declaring the same C name. - Delay imports and dynamically selected targets stay outside the fixture. The providers' contracts are known from source, as in the existing import tests. ## 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: prepared with Claude Code; the commands and results above were run on the author's PC._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:44:46 +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!779
No description provided.