cpu: decisions needed before the jump-table translator handles calls, RIP-relative data and stack frames #312
Open
opened 2026-11-21 21:54:33 +00:00 by bosseurdinternet
·
9 comments
No Branch/Tag specified
main
codex/indirect-large-backed-views
codex/word3-preflight-check
codex/vertex-table-two-records
codex/live-index-alias
codex/copied-vertex-buffer-srv
codex/windows-stage-test-output
codex/preserve-live-srv-retirement
codex/share-render-target-tracking
codex/sgd5-negative-offset-fixture
coverage-dashboard
codex/mesh-loose-root
codex/mesh86-cache-padding
codex/xmem-scatter-preflight
codex/mesh-depth-ps
codex/indirect-dispatch-refresh
codex/compute-container-index
codex/startup-compute-formatted-load
codex/compute-indirect-producer
codex/compute-atomic-soffset
codex/mesh-dual-handoff
codex/startup-run-sh-watcher-control
codex/queue31-page-alias
codex/indexed-indirect-compute-root
codex/typed-buffer-view-metadata
codex/translated-indexed-address-alias
codex/fixed-mesh-create-result
codex/xmem-section-lease
codex/startup-slot86-mesh-cache
codex/restore-mesh-barrier-iteration
codex/translated-indirect-upload-index
codex/xapu-completion-opt-in
codex/translated-indexed-rect
codex/translated-indexed-indirect
codex/startup-mesh-lds-integration
codex/startup-console-ms24
codex/startup-slot57-mesh-request
codex/indirect-copy-provenance
codex/present-color-producer-trace
codex/compute-dispatch-binding-trace
codex/translated-indirect-table-buffers
codex/indirect-copy-provenance-base
codex/mix-half-literal-source
codex/translated-indirect-draw
codex/xmem-scatter-diagnostics
codex/slot148-recording-upload
codex/slot70-loading-art-verified
codex/command-list-upload-arena
codex/recover-failed-command-list
codex/startup-heap-timing-notes
codex/align-audio-input-timeline
codex/synthetic-depth-export-control
codex/startup-texture1d-on-windows
codex/1629-packed-position-fixture
codex/cpu-srv-refresh
codex/stream-root-srv-draw
codex/audio-mixer-timer
codex/startup-reload-published-shader
codex/priority-integrate-1284
codex/guest-sixteen-page-record
codex/aot-placed-dxr-batch
codex/guest-directory-selection
codex/gamesave-enumerate-read
codex/readme-archive-to-pixels
codex/pe-placed-view-draw
codex/archive-directory-gpu
codex/slot133-dxr-build
codex/materialize-placed-vertex-view
codex/dstorage-directory-offsets
codex/xg-nine-bc-copy
codex/xg-slot10-bc64-arrays
codex/dxr-guest-address-readback
codex/gpu-va-high-bits
codex/clarify-diagnostic-startup-scope
codex/xg-six-levels
codex/typed-derived-blend
codex/english-legal-text-progress
codex/address-bc-4ks
codex/dstorage-bounded-file-read
codex/wide-srv-offsets-menu
codex/startup-memory-srv
codex/bound-view-tail
codex/language-selector-readback
codex/setup-menu-progress
codex/cpu-plane-refresh
codex/startup-ubyte-vertex
codex/presenter-window-selection
codex/startup-uniform-buffer-lane
codex/intro-loop-timing
codex/static-clzero-loops
codex/document-rtx-intro
codex/startup-insertq
codex/nv12-startup-texture
codex/stream-stage-draw
codex/startup-null-uav-format
codex/startup-draw-capture
codex/shorten-windows-checks
codex/dstorage-rfc1950
codex/startup-dump-fence
codex/pr1135-review-base
codex/startup-stream-requests
codex/startup-chroma-view
codex/readme-graphics-pipeline-streams
codex/static-crt-free-tls
codex/arc-140t-rtx-5080-laptop-gpu-reports
codex/main-startup-progress-entry
codex/signed-dxil-catalogue
codex/reloc-free-preferred-base
codex/quad-dpp-bit-mask
codex/raw-srv-bounds
codex/rx9070-31044-hardware-report
codex/gpu-page-source-provenance
codex/runtime-placeholder-interior
codex/gpu-copy-queue-tile-order
codex/pe-pin-external-providers
codex/xmem-placeholder-reservations
codex/xmem-shared-physical-pages
codex/pe-package-startup
codex/xmem-tools-memory-query
codex/cpu-stack-output-import
codex/pe-load-security-cookie
codex/record-three-bvh-retests
codex/cpu-rbp-frame-anchor
codex/xmem-default-startup
codex/record-rtx-3050-ti-9597
codex/docs-readme-start-here
codex/check-compute-mad24-truncation
codex/docs-discord-community
codex/bound-rcx-branch-mutants
codex/rtx5060ti-bvh-62114
codex/837-neutral-readme-disclaimer
codex/record-rtx-3070-ti
codex/title-neutral-public-wording
codex/exe-shadow-frame-submissions
codex/exe-shadow-runtime-chain
codex/readme-polish
codex/gpu-coverage-nov23
codex/spirv-minlod
codex/shadow-shim-device
codex/exe-two-shadow-frames
codex/shim-dispatch-cleanup
codex/fix-spirv-cache-probe
codex/sampler-use
codex/ballot-bit-extract
codex/packed-fma-release
codex/cpu-packed-fma-o2
codex/publish-coverage-dashboard
codex/mesh-cbv-binding-order
codex/spirv-window-fixture
codex/ps-e32-float-uint
codex/ps-cbuffer-reads
codex/fixed-profile-rescan
codex/shim-compute-integration
codex/readme-visible-coverage
codex/readme-research-navigation
codex/integrate-pr-256
codex/indexed-mesh
codex/sampled-coverage
codex/first-ms
codex/dual-ps
codex/ps-attribute
codex/compute-first
codex/ps-export
codex/readme-research-status
codex/ps-layout
codex/blast-window
codex/chart-caption
codex/reviewer-roles
codex/blast-aot
codex/archive-program
codex/crc-stream-program
codex/exe-image-data-chain
codex/local-cpu-fixture-coverage
codex/exe-bound-frame-chain
codex/exe-mapped-comparison
codex/contribution-dependencies
codex/exe-entry-aot
codex/bink-frame-heap-integration
docs/hardware-seven-reports
codex/bink-custom-heap
codex/bink-heap-callers
codex/discussions-entry-points
codex/gpu-community-batch-64
codex/ffx-scratch-writers
codex/generic-project-documentation
codex/ffx-dispatch-rcas
codex/four-windows-gpu-reports
codex/title-neutral-project-wording
codex/community-coverage-provenance
codex/rcas-packed-texels
codex/community-gpu-retests
codex/community-build-and-gpu-reports
codex/ffx-provider-loop
codex/ffx-recurrent-views
codex/ffx-recurrent-resource
codex/amd-wave64-reports
codex/ffx-backend-slots
codex/upscaler-device-init
codex/ffx-context-lifecycle
codex/ffx-version-query
codex/ffx-provider-contract
codex/typed-object-callback
codex/cpu-ordinal-import
codex/chained-cpu-ranges
codex/cpu-import-call
codex/cpu-direct-call
codex/cpu-leaf-aot
codex/community-project-status
codex/script-state-path-replay
codex/script-state-evidence
codex/bc7-resident-tail
codex/bcpack-mip-tail
codex/bc7-texture-draw
codex/asset-ranges
codex/pixel-constants
codex/pixel-aot
codex/pre-exe-workloads
codex/root-signature-device-coverage
engineering/packed-bvh-leaves
engineering/bvh-build-and-update
engineering/intake-root-roundtrip
community/gpu-check-release
community/english-contributor-entry
gpu-check-v0.1.0
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
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#312
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-21T21:54:33Z.
Problem
After #282, #285 and #309 (open),
tools/cpu_switch_aot.pytranslates 651 of 1,119 functions of an MSVC 14.52/O2build of this repository's own C++ sources (plus one plain C++ file). What refuses the other 468 is mostly not an instruction: it is a transfer to other code, or an address.call rel32jmp qword ptr [rip+slot], a tail jump through the import tablecall qword ptr [rip+slot]Limits of these numbers: 831 of the 1,119 functions are MSVC STL instantiations; only the first refusal of each function is counted, so a function refused for a call usually also needs a stack frame; and this is desktop code, not a title.
Each of these needs a contract that the machine code of one function does not supply. I would rather ask than pick one and have several PRs built on it. Four questions follow, each with the option I would take.
Proposal
1. Imports (call or tail jump through an import slot). Translate only through an explicit binding, with
cpu_call_aot.resolve_importand its--bind PROVIDER SYMBOLconvention. The callee's code is not in the image, so the number of low RAX bytes it defines is unknown to the translator.return_widthas aRETsite contributes its own; after a call, RAX has that many defined bytes.I am preparing the tail-jump case this way now. It is small and I will change it to match your answer.
2. Direct calls and direct jumps to other functions in the same image. Translate the callee by RVA into the same generated source, starting from the requested exports and following calls, with internal functions named by RVA. The caller is refused if any callee is refused. After a call, RAX has the callee's
return_widthdefined bytes, and volatile registers are undefined.return_widthas a fixed point over the call graph starting from the lower bound.3. RIP-relative data. Today a RIP-relative
LEAresult is a guest address and may only feed a jump table. Three models:pe_map), and a RIP-relative operand becomesimage_base + RVA. A RIP-relativeLEAthen yields a real address, so it can be stored, compared and returned. The translation then depends on the original image being mapped, which the existing differential tests already do.ffx_version_query.lower()does with its globals.Proposed: (a). It needs no per-function input and keeps one copy of the data, shared with the native run it is compared against.
4. Stack frames. A non-leaf function saves nonvolatile registers, allocates with
sub rsp, Nand addresses[rsp+disp].[rsp+disp]an offset into it, so a slot's address is a real address that can be passed to a callee. Refused at first: a function whose RSP is not a constant offset from entry at every instruction,alloca, a callee that reads stack arguments (fifth and later), and any read of a slot that no path wrote.ffx_version_query.lower().SSE/AVX is not part of this question; #314 covers a first case.
Alternatives
Keep the translator to leaf functions and count the rest as out of scope. That is a valid answer too: it would stop this line of PRs at integer mnemonics.
Verification
Each step would come as its own PR with a source-built MASM or C++ fixture, a differential check through the register probe, rejection controls printed by the test, and before and after counts on the corpus above with a check that no translated function is lost and that the generated C++ of functions already translated is unchanged. For calls, the corpus functions can also be executed beside their originals on generated inputs, as described in #282 and #285.
Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:56:53Z.
Start with the IAT tail jump. Bind the module and slot explicitly by symbol name or ordinal, with the input ABI and the number of guaranteed low RAX bytes (0, 1, 2 or 8). Zero denotes a normal return with no guaranteed result bits. Take the conservative minimum across tail jumps and other reachable normal returns. For ordinary calls apply volatile-register and flag clobbers.
For internal edges, validate function-entry RVAs and emit each target once. Start with acyclic graphs and diagnose self- and mutual recursion. For RIP-relative data, accept an explicitly supplied live mapping matching the input image and a checked RVA. Preserve aliases and shared writes; compare writable data under identical initial state using separate mappings or restoration, and compare cross-mapping addresses by RVA. Keep the existing ABI available and limit pointer validity to the binding lifetime.
For frames, use a bounded byte array per invocation with checked size and alignment. Track stack offsets, save/restore and bytewise definition before reads on each path. Allow only known bounded pointer uses across calls; reject escapes, dynamic frames, unsupported stack arguments and unproved effects. Separate source-built fixtures are appropriate for each step. Report corpus figures for the measured desktop inputs.
Imported from R0Y00/Xbox2Windows. Originally posted by grahamster2 on 2026-11-21T23:37:42Z.
I'd like to take step 4 (stack frames) in
tools/cpu_switch_aot.py, following the decision above. @bosseurdinternet, if you already have frames underway, say so and I'll verify or review yours instead.First PR: call-free functions with a fixed frame. Calls stay refused until step 2 lands, so no frame pointer crosses a call yet.
sub rsp, regand any other RSP write.push/popof a register,sub rsp, immandadd rsp, imm, and[rsp+disp]loads and stores with no index. Every RET must see offset 0.alignas(16)byte array per invocation, sized at translation time to the deepest offset plus the caller's 32-byte home area.[rsp+disp]becomes a checked offset into it. The return-address slot and anything above the home area (stack arguments) are refused.pushof RBX, RBP, RSI, RDI or R12–R15 before any write saves the caller's value, and every RET must see that register restored by the matchingpop. A nonvolatile write without such a save, or a read of a save slot other than its restore, is refused.lea r, [rsp+d]or any other way a frame address reaches a register, RSP as an index, andenter/leave.Verification: a source-built MASM fixture with push/pop of nonvolatiles,
sub rspspills and reloads, home-area spills of RCX and RDX, and a frame value that crosses a join. Differential checks throughcpu_register_probe(return, trace, RBX, RSI) against the original, and printed rejection controls for an unbalanced pop, a read before write, mismatched offsets at a join, a return-address read, a stack-argument read, an RSP write from a register and a frame-address escape. I'll report before/after counts on the MSVC/O2corpus at the top of this issue. @bosseurdinternet, could you share how you built and walked it, so the figures are comparable?I'll base on current
mainand rebase after #343, #321 and #330, which also editcpu_switch_aot.py. Environment: Windows 11 build 26200, MSVC 19.50, Python 3.12.Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-21T23:51:19Z.
Hey, thanks for the detailed plan! I've already implemented most of step 4 and am wrapping up the remaining tests and verification. I'm planning to open a PR within the next couple of hours.
It would probably make sense to review and build on that rather than duplicate the work. I'll share the PR here as soon as it's ready, along with the testing details and corpus results.
Imported from R0Y00/Xbox2Windows. Originally posted by grahamster2 on 2026-11-21T23:53:31Z.
Thanks, @bosseurdinternet. I'll review and verify yours rather than open a second PR.
I had already built an independent version while waiting, so it can serve as a cross-check:
cpu/switch-stack-frameson my fork (be4784f, not a PR). The fixture and controls don't depend on my translator, so once your PR is up I'll run them against your branch on Windows 11 build 26200 (MSVC 19.50) and report what each one does:tests/cpu/frames.asm: five exports covering PUSH/POP of RBX and RSI used as scratch, qword/dword/word/byte stores combined by a wider reload, home-area spills of RCX and RDX with no allocation, the same slots written differently on two paths before a join, and a frame-resident counter across a loop back edge. Throughcpu_register_probe, 545 inputs per export against a Python reference.[rsp],[rsp+28h]and[rsp-8]at entry, LEA and MOV copies of RSP, an unsaved write to RDI,mov rsp, raxandsub rsp, rcx.Corpus method, in case it helps make figures comparable: a Release (
/O2) build of the repo at9bdbb20, every.pdataentry of the 81 non-_liftedimages, deduplicated by function bytes, each translated by RVA with four arguments. That gave 1,406 unique functions. Two observations from it: three CRT-free fixtures (cpu_startup_a,cpu_startup_a_alt,cpu_life_sink) fail to link at/O2with an unresolvedmemcpy, and once frames are accepted the most common new first refusal is a RIP-relative operand (28 functions), followed by XMM/YMM registers (8).Imported from R0Y00/Xbox2Windows. Originally posted by grahamster2 on 2026-11-22T01:08:50Z.
@bosseurdinternet, I see #343 (step 1) and #416 (step 3), with frames coming from you as well. Is step 2, direct calls and direct jumps to other functions in the same image, also on your list?
If not, I'd like to take it, following the decision above: validate function-entry RVAs, emit each callee once, start with acyclic call graphs, diagnose self- and mutual recursion, and apply volatile-register and flag clobbers after a call. Every non-leaf callee needs a frame, so I'd build on your frames PR once it's up and prototype against my frames branch until then. If you already have it underway, say so and I'll review and verify it instead, as with frames.
Imported from R0Y00/Xbox2Windows. Originally posted by grahamster2 on 2026-11-22T01:35:19Z.
I've opened step 2 (direct calls and tail jumps to other functions in the same image) as draft #425. It is stacked on #420 and I'll rebase once #420 lands. It follows the decision above: function-entry RVAs are validated, each callee is emitted once, self- and mutual recursion are refused, and volatile-register and flag clobbers apply after a call. The PR lists the points the decision left open for review, the main one being callees that have no
.pdataentry. @bosseurdinternet, if you already have step 2 underway, say so and I'll close mine and review yours.Imported from R0Y00/Xbox2Windows. Originally posted by grahamster2 on 2026-11-22T02:50:52Z.
A design question for the next step after #425, before any code is written for it: frame addresses passed to callees.
With frames (#420) and direct calls (#425), the most common first refusal at
/Odin @bosseurdinternet's corpus is a frame address that escapes or is passed to a callee (about 190 functions). In mine (/O2) it's 41. The typical shape islea rcx, [rsp+20h]; call fwherefwrites or reads through RCX, i.e. an out-parameter or a small struct passed by pointer. The decision above says: "Allow only known bounded pointer uses across calls; reject escapes, dynamic frames, unsupported stack arguments and unproved effects."Proposed reading, for you to accept, narrow or reject:
lea reg, [rsp+d]immediately feeding the call, never stored to memory, returned, or kept in a register after the call.[0, n)from the pointer: constant offsets only, and no further escape (not stored, not passed on, not returned).nand the bytes the callee reads before writing and writes are recorded as the callee's effect summary.[d, d+n)must lie inside its frame and not overlap the callee's home space or the return address. Bytes the callee reads must be defined in the caller. After the call, bytes the callee may write become written (defined if written on every callee path, otherwise undefined). Nothing else in the frame changes.load/storereach it directly. Pointer validity is limited to the call, matching "pointer validity to the binding lifetime".[0, n), a pointer to the caller's home space or save slots, frame addresses passed to imports (unknown effects), and recursion through such calls.Is that the boundary you want, or would you prefer something narrower first, e.g. read-only or write-only callee windows, or a single pointer argument per call? I'd do it as one PR stacked on #425 with fixtures for each rule and the usual controls.
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T02:23:48Z.
Claiming one narrow addition to
tools/cpu_switch_aot.py: the inverted unsigned bound check,cmp reg, limit; jb/jbe dispatch_block; jmp default. JB and JBE enter the table, withlimitandlimit + 1entries. It touchesdispatch()andprove()only, not the ABI, frames, calls or data binding, so it does not overlap steps 1 to 4 or any open PR I could find.Planned files:
tools/cpu_switch_aot.py, a new source-built fixturetests/cpu/switch_inverted.asmwith its check,CMakeLists.txtanddocs/experiments.md. The check runs native, translated and exchanged-table builds against a Python reference and adds byte-patched rejection controls.Environment: Linux, LLVM 19 (
llvm-mc,lld-link), mingw-w64 g++ with Wine 10 for the native-versus-translated run. ML64 and MSVC are not available to me, so the MASM source and the/O2build are only exercised by the Windows CI jobs.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by dicnunz on 2026-11-25T05:11:27Z.
Claiming two stacked follow-ups to step 2 on
tools/cpu_switch_aot.py, after the acyclic-call work already on main.Recursion through direct
CALLs: allow a call to close a call cycle and settlereturn_widthand argument demands by iterating to a fixed point, the method proposed in this issue. A tail jump that closes a cycle stays refused. Branch: https://github.com/dicnunz/Xbox2Windows/tree/cpu/switch-recursion (9e8d909)Stack arguments (5th to 12th) of internal callees: each caller must have written the bytes the callee reads. A tail jump to such a callee, and stack arguments of exported functions, stay refused. This branch contains the recursion commits, so it should land second: https://github.com/dicnunz/Xbox2Windows/tree/cpu/switch-stack-arguments (
172c07f)Both use new source-built MASM fixtures with differential checks and refusal controls. They were developed in Claude Code (Opus 5.5). On the fork's full Windows CI (
windows-2025, Debug and /O2),cpu_aot_recursionandcpu_aot_stack_argumentspassed. The one failing test,call_evidence_check, is unchanged by these branches and fails the same way on upstream main.These do not overlap the remaining questions on this issue (frame addresses passed to callees, RIP-relative data, imports) or the open
cpu:PRs I could find. They editcpu_switch_aot.py,CMakeLists.txtanddocs/experiments.md.AI-assisted (Claude Code, Opus 5.5).