cpu: recompile a caller with two different direct callees #220

Merged
denn0x merged 1 commit from upstream-pr/223 into main 2026-11-21 18:58:52 +00:00
denn0x commented 2026-11-21 18:35:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-21T18:35:48Z.


Change

Advances: an independent problem in the CPU call profile. It follows #177, which left "two calls to different callees" open. There is no prerequisite PR: #219, which this was reconciled with as requested in review, is now merged, so the branch is a single commit on current main.

In cpu_call_aot with this change, a caller may:

  • Direct calls: make direct calls to any number of distinct targets, each lifted once in call order. The first keeps the name lifted_callee, and later ones are lifted_callee2, lifted_callee3 and so on.
  • Overlap rule: each direct target's function interval must overlap neither the caller nor another callee.
  • Import calls: repeat one import call through the same IAT slot, bound once (#219).

Still rejected, in either order:

  • a direct call mixed with an import call ("mixed import and direct calls");
  • import calls through two different IAT slots ("call to a second IAT slot").

The new source-built fixture tests/cpu/call_pair.asm has a caller call_pair that calls mix_args (a - b + 11) and then mix_other ((a ^ b) + 29). The XOR keeps the two callees from commuting, so swapping the calls changes the result. repeat_call.asm with #219's IMPORT_MIX build and direct.asm are unchanged by this PR.

Changed expectations in cpu_aot_repeated_call. All of these cases are still rejected:

  • A call redirected into the callee interior used to fail as "call to a second target". It now reaches the interval lookup and fails as "no unique function interval".
  • The three hand-built sequences from #219 are kept. The two mixed orders now report "mixed import and direct calls", and the two-slot case reports "call to a second IAT slot".

Verification

Head 971ae91 on 6254a96 (the #219 merge). The full suite ran on fad2d42, which has an identical tree; the five tests below were rerun on 971ae91. Windows 11 build 26200, MSVC 19.50.35720 with ML64, Windows SDK 10.0.26100.0, Python 3.13.

ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import)$' -V
78: 249 input pairs each for caller and callee: arguments, guarded writes, RBX, RSI and returns match; all altered returns and the register clobber detected
79: 249 input pairs: caller, swapped caller and all four lifted callees match arguments, guarded writes, RBX, RSI and returns; swapping the calls changes 249 results; each altered callee changes every caller return
79: one rel32 to each callee; 3 redirected calls and overlapping callee intervals are rejected
80: 249 input pairs each for caller and callee: arguments, guarded writes, RBX, RSI and returns match; every altered callee changes the caller's return and trace; the register clobber is detected
80: both call sites and trace-pointer moves found; opcode 89 moves translate identically; 4 redirected calls, the omitted R8 reload and an R8 reload from RBX are rejected
80: mixed direct/import calls and two distinct IAT slots are rejected
80: 249 repeated-import input pairs match native execution, guarded trace, RBX and RSI
100% tests passed, 0 tests failed out of 5
  • Both native differential cases are retained: the repeated direct call (cpu_repeat_original) and #219's repeated import (cpu_repeat_import), 249 pairs each against native execution.
  • #219's output unchanged: the generated cpu_repeat_import source is byte-identical to what #219's translator, as merged, produces for the same DLL.
  • Existing outputs unchanged: the generated cpu_call_original, cpu_call_altered, cpu_import_original, cpu_ordinal_original, cpu_repeat_original and cpu_repeat_altered sources are byte-identical to main before #219 and this change.
  • Two callees:
    • The swapped-order copy follows its own reference, changes all 249 results, and names mix_other as lifted_callee.
    • Altering only mix_args, or only mix_other, changes the caller's return on every pair.
    • Each caller has exactly one rel32 to each callee.
    • Translation rejects three redirected calls: either one into the other callee's interior, or the second one back to the caller. A copy whose mix_args runtime-function entry is extended into mix_other is refused by the range reader as an invalid runtime-function interval.
  • Before: the translator on main rejects call_pair with "call to a second target".
  • Full suite: ctest --preset dev --no-tests=error gives 116 tests, 0 failed. bvh_wave64_warp and wave_shuffle_warp reported capability skips.

Not exercised:

  • more than two distinct direct callees;
  • a caller that returns to an earlier callee after calling another (A, B, A);
  • the translator's own callee-against-callee overlap check. The range reader refuses overlapping runtime-function entries first, so this check is a second guard.

Evidence and follow-up

The new fixture is original MASM written for this test (MIT). The README CPU row and the direct-call section of docs/experiments.md are updated with the commands and rejection reasons.

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:6532820232 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/223). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-21T18:35:48Z. --- ## Change Advances: an independent problem in the CPU call profile. It follows #177, which left "two calls to different callees" open. There is no prerequisite PR: #219, which this was reconciled with as requested in review, is now merged, so the branch is a single commit on current `main`. In `cpu_call_aot` with this change, a caller may: - **Direct calls:** make direct calls to any number of distinct targets, each lifted once in call order. The first keeps the name `lifted_callee`, and later ones are `lifted_callee2`, `lifted_callee3` and so on. - **Overlap rule:** each direct target's function interval must overlap neither the caller nor another callee. - **Import calls:** repeat one import call through the same IAT slot, bound once (#219). Still rejected, in either order: - a direct call mixed with an import call ("mixed import and direct calls"); - import calls through two different IAT slots ("call to a second IAT slot"). The new source-built fixture `tests/cpu/call_pair.asm` has a caller `call_pair` that calls `mix_args` (`a - b + 11`) and then `mix_other` (`(a ^ b) + 29`). The XOR keeps the two callees from commuting, so swapping the calls changes the result. `repeat_call.asm` with #219's `IMPORT_MIX` build and `direct.asm` are unchanged by this PR. **Changed expectations in `cpu_aot_repeated_call`.** All of these cases are still rejected: - A call redirected into the callee interior used to fail as "call to a second target". It now reaches the interval lookup and fails as "no unique function interval". - The three hand-built sequences from #219 are kept. The two mixed orders now report "mixed import and direct calls", and the two-slot case reports "call to a second IAT slot". ## Verification Head `971ae91` on `6254a96` (the #219 merge). The full suite ran on `fad2d42`, which has an identical tree; the five tests below were rerun on `971ae91`. Windows 11 build 26200, MSVC 19.50.35720 with ML64, Windows SDK 10.0.26100.0, Python 3.13. ```powershell ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import)$' -V ``` ```text 78: 249 input pairs each for caller and callee: arguments, guarded writes, RBX, RSI and returns match; all altered returns and the register clobber detected 79: 249 input pairs: caller, swapped caller and all four lifted callees match arguments, guarded writes, RBX, RSI and returns; swapping the calls changes 249 results; each altered callee changes every caller return 79: one rel32 to each callee; 3 redirected calls and overlapping callee intervals are rejected 80: 249 input pairs each for caller and callee: arguments, guarded writes, RBX, RSI and returns match; every altered callee changes the caller's return and trace; the register clobber is detected 80: both call sites and trace-pointer moves found; opcode 89 moves translate identically; 4 redirected calls, the omitted R8 reload and an R8 reload from RBX are rejected 80: mixed direct/import calls and two distinct IAT slots are rejected 80: 249 repeated-import input pairs match native execution, guarded trace, RBX and RSI 100% tests passed, 0 tests failed out of 5 ``` - **Both native differential cases are retained:** the repeated direct call (`cpu_repeat_original`) and #219's repeated import (`cpu_repeat_import`), 249 pairs each against native execution. - **#219's output unchanged:** the generated `cpu_repeat_import` source is byte-identical to what #219's translator, as merged, produces for the same DLL. - **Existing outputs unchanged:** the generated `cpu_call_original`, `cpu_call_altered`, `cpu_import_original`, `cpu_ordinal_original`, `cpu_repeat_original` and `cpu_repeat_altered` sources are byte-identical to `main` before #219 and this change. - **Two callees:** - The swapped-order copy follows its own reference, changes all 249 results, and names `mix_other` as `lifted_callee`. - Altering only `mix_args`, or only `mix_other`, changes the caller's return on every pair. - Each caller has exactly one rel32 to each callee. - Translation rejects three redirected calls: either one into the other callee's interior, or the second one back to the caller. A copy whose `mix_args` runtime-function entry is extended into `mix_other` is refused by the range reader as an invalid runtime-function interval. - **Before:** the translator on `main` rejects `call_pair` with "call to a second target". - **Full suite:** `ctest --preset dev --no-tests=error` gives 116 tests, 0 failed. `bvh_wave64_warp` and `wave_shuffle_warp` reported capability skips. Not exercised: - more than two distinct direct callees; - a caller that returns to an earlier callee after calling another (A, B, A); - the translator's own callee-against-callee overlap check. The range reader refuses overlapping runtime-function entries first, so this check is a second guard. ## Evidence and follow-up The new fixture is original MASM written for this test (MIT). The README CPU row and the direct-call section of `docs/experiments.md` are updated with the commands and rejection reasons. ## 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:41:53 +00:00
R0Y00 commented 2026-11-24 06:47:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T18:39:47Z.


Reviewed b7967799 alongside #219. This head rejects a second IAT call before checking its slot, while #219 verifies two calls to the same slot against native execution. Please reconcile with #219 so the caller can use multiple direct targets or repeat one import slot. Keep rejection of distinct IAT slots and mixed direct/import calls in either order. For the combined head, please run ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import)$' -V and retain both native differential cases.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067419020 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/223#issuecomment-7067419020). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T18:39:47Z. --- Reviewed `b7967799` alongside #219. This head rejects a second IAT call before checking its slot, while #219 verifies two calls to the same slot against native execution. Please reconcile with #219 so the caller can use multiple direct targets or repeat one import slot. Keep rejection of distinct IAT slots and mixed direct/import calls in either order. For the combined head, please run `ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import)$' -V` and retain both native differential cases.
denn0x commented 2026-11-24 06:47:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-21T18:46:53Z.


Reconciled with #219. The head is now 90ec8f8 on 6941bf6: #219's commit (4e820ab, Vonsek's, rebased onto current main) with this change on top.

Combined behavior:

  • Allowed: direct calls to several distinct targets, each lifted once in call order, and repeated calls through one IAT slot, bound once.
  • Rejected in either order: mixed direct/import calls ("mixed import and direct calls") and two distinct IAT slots ("call to a second IAT slot").
ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import)$' -V

All 5 pass on Windows 11 build 26200 with MSVC 19.50.35720. Both native differential cases are retained: 249 pairs each for the repeated direct call and for #219's repeated import (249 repeated-import input pairs match native execution, guarded trace, RBX and RSI).

The generated cpu_repeat_import source is byte-identical to what #219's own translator produces. The six earlier generated sources are byte-identical to main. The full suite gives 115 tests, 0 failed, with capability skips for bvh_wave64_warp and wave_shuffle_warp. The PR description lists the changed rejection messages. If #219 merges first, this branch reduces to its second commit.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067507919 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/223#issuecomment-7067507919). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-21T18:46:53Z. --- Reconciled with #219. The head is now `90ec8f8` on `6941bf6`: #219's commit (`4e820ab`, Vonsek's, rebased onto current `main`) with this change on top. Combined behavior: - **Allowed:** direct calls to several distinct targets, each lifted once in call order, and repeated calls through one IAT slot, bound once. - **Rejected in either order:** mixed direct/import calls ("mixed import and direct calls") and two distinct IAT slots ("call to a second IAT slot"). ```powershell ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import)$' -V ``` All 5 pass on Windows 11 build 26200 with MSVC 19.50.35720. Both native differential cases are retained: 249 pairs each for the repeated direct call and for #219's repeated import (`249 repeated-import input pairs match native execution, guarded trace, RBX and RSI`). The generated `cpu_repeat_import` source is byte-identical to what #219's own translator produces. The six earlier generated sources are byte-identical to `main`. The full suite gives 115 tests, 0 failed, with capability skips for `bvh_wave64_warp` and `wave_shuffle_warp`. The PR description lists the changed rejection messages. If #219 merges first, this branch reduces to its second commit. AI-assisted (Claude Code).
RonLogic commented 2026-11-24 06:47:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-21T18:52:57Z.


I independently tested the combined #223 head (90ec8f8) on Windows x64 and
extended its source-built MASM fixture to cover the A -> B -> A sequence
listed in the PR's verification notes.

Across 249 input pairs, the native and recompiled callers matched the
independent arithmetic, including the return value, guarded final trace
and RBX/RSI sentinels. I also checked the linked call sites in both builds.
The first and third instructions call the same target, with a call to the
other target between them. Swapping the first two calls in the native
control (B -> A -> A) changed 244 return values.

After configuring with the dev preset in out/build/mixed-call-review
and building the fixtures, I ran this CTest selection:

ctest --test-dir out/build/mixed-call-review --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import)

Result: 5 passed, 0 failed, 0 skipped. The A -> B -> A fixture runs as
part of cpu_aot_call_pair. I can share the source-only test patch if
you'd like to fold it into #223. -V

Result: 5 passed, 0 failed, 0 skipped. The A -> B -> A fixture runs as
part of cpu_aot_call_pair. I can share the source-only test patch if
you'd like to fold it into #223.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067584141 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/223#issuecomment-7067584141). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-21T18:52:57Z. --- I independently tested the combined #223 head (`90ec8f8`) on Windows x64 and extended its source-built MASM fixture to cover the A -> B -> A sequence listed in the PR's verification notes. Across 249 input pairs, the native and recompiled callers matched the independent arithmetic, including the return value, guarded final trace and RBX/RSI sentinels. I also checked the linked call sites in both builds. The first and third instructions call the same target, with a call to the other target between them. Swapping the first two calls in the native control (B -> A -> A) changed 244 return values. After configuring with the dev preset in `out/build/mixed-call-review` and building the fixtures, I ran this CTest selection: ```powershell ctest --test-dir out/build/mixed-call-review --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import) Result: 5 passed, 0 failed, 0 skipped. The A -> B -> A fixture runs as part of cpu_aot_call_pair. I can share the source-only test patch if you'd like to fold it into #223. -V ``` Result: 5 passed, 0 failed, 0 skipped. The A -> B -> A fixture runs as part of cpu_aot_call_pair. I can share the source-only test patch if you'd like to fold it into #223.
R0Y00 commented 2026-11-24 06:47:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T18:55:19Z.


Thanks for retaining both contributors’ work in 90ec8f8. #219 is now on main at 6254a96. A three-way merge against that exact commit still reports five conflicts. Since Vonsek’s change is on main, one route is to replay denn0x’s 90ec8f8 on 6254a96, preserving authorship.

In tools/cpu_call_aot.py, reconcile the call-kind check, repeated IAT slot identity and callee declarations. In tests/cpu/repeat_call_check.py, keep the mixed-call controls in both orders and the distinct-IAT-slot rejection. In CMakeLists.txt, keep both the call-pair and EXE-entry tests, and combine the CPU row in README.md and the repeated-call paragraph in docs/experiments.md.

Please push the reconciled head. We’ll verify that exact candidate on Windows with ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import|exe_entry)$' -V. The separate A→B→A report is useful additional evidence.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067615238 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/223#issuecomment-7067615238). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T18:55:19Z. --- Thanks for retaining both contributors’ work in `90ec8f8`. #219 is now on main at `6254a96`. A three-way merge against that exact commit still reports five conflicts. Since Vonsek’s change is on main, one route is to replay denn0x’s `90ec8f8` on `6254a96`, preserving authorship. In `tools/cpu_call_aot.py`, reconcile the call-kind check, repeated IAT slot identity and callee declarations. In `tests/cpu/repeat_call_check.py`, keep the mixed-call controls in both orders and the distinct-IAT-slot rejection. In `CMakeLists.txt`, keep both the call-pair and EXE-entry tests, and combine the CPU row in `README.md` and the repeated-call paragraph in `docs/experiments.md`. Please push the reconciled head. We’ll verify that exact candidate on Windows with `ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import|exe_entry)$' -V`. The separate A→B→A report is useful additional evidence.
denn0x commented 2026-11-24 06:47:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-21T19:01:58Z.


Thanks for merging. After the merge I ran the requested selection on main at f85723e, on Windows 11 build 26200 with MSVC 19.50.35720:

ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import|exe_entry)$' -V

Result: 6 passed, 0 failed, 0 skipped.

@RonLogic, thanks for the independent run and the A -> B -> A extension. This closes the second "not exercised" item in the PR body. Since #223 is merged, the fixture would fit best as its own small PR, with the B -> A -> A swap as its negative control.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067707069 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/223#issuecomment-7067707069). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-21T19:01:58Z. --- Thanks for merging. After the merge I ran the requested selection on `main` at `f85723e`, on Windows 11 build 26200 with MSVC 19.50.35720: ```powershell ctest --preset dev --no-tests=error -R '^cpu_aot_(call_pair|repeated_call|direct_call|import_call|ordinal_import|exe_entry)$' -V ``` Result: 6 passed, 0 failed, 0 skipped. @RonLogic, thanks for the independent run and the A -> B -> A extension. This closes the second "not exercised" item in the PR body. Since #223 is merged, the fixture would fit best as its own small PR, with the B -> A -> A swap as its negative control. AI-assisted (Claude Code).
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!220
No description provided.