cpu: lift vector data moves in the control-flow lifter #905
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!905
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/905/head"
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?
@copycraft on GitHub · 2026-11-23 16:37 UTC · original
copycraft:cpu/switch-simd-moves→main· +1177 −31 · 8 files · 3 commits · closed without mergingChange
The control-flow CPU lifter (
tools/cpu_switch_aot.py) refused every function that named an XMM or YMM register. This PR lets it translate vector instructions that only move or zero data:Semantics:
STATUS_ACCESS_VIOLATIONbefore the access when a guest operand is misaligned. A RIP-relative operand is checked statically by its RVA. Frame accesses, through RSP or an RBP anchor, are proven aligned from their offset to entry RSP (8 mod 16). A 32-byte aligned frame access is refused, because the frame's alignment mod 32 is unknown.Why: in a local sample of 2,000 functions from an inspected Scarlett executable, vector register use was this lifter's most frequent first refusal. After this change, the most frequent first refusal in the same sample is taking the address of a stack slot (
lea reg,[rsp+N]), which this PR does not change. Those counts come from a local survey script that isn't part of this PR. They only explain the motivation; the public fixture verifies the behavior.Shared code: only the lifter's own output changes.
vec,vector_alignment,load_vector<N>,store_vector<N>and aRaiseExceptiondeclaration.prove_frameand the definedness pass now cover the vector registers as well as the general-purpose registers.Overlap: this branch is rebased onto #889 (RBP frame anchors).
stack_base, so an anchored access is measured from the anchor.anchored_vectorsexport and thebad_anchored_misalignedcontrol pin both. Their RSP and RBP differ by 8 mod 16, so measuring from RSP would refuse the first and accept the second.#895 also changes
tools/cpu_switch_aot.py. A test merge with this branch conflicts inprove_frame: #895 adds stack outputs where this branch builds the saved-register status over the vector registers. Whichever lands second needs a small rebase there.Verification
Branch head
6b82ce2, rebased onto279a7fb(main after #889). Windows 11 build 26300, MSVC/ML64 19.44.35207, Python 3.12.14,devpreset (Ninja, Debug; the fixture also builds an/O2translation).Passed:
/Odand/O2) and byte-reference comparisons matched, over 11 exports and source/destination offsets 0–31. Each comparison covers the whole destination with 32 guard bytes on each side, plus the return value./O2mutants fail, as they must: a legacy write that clears bytes 16–31, an aligned move without its check, and a store without its last-byte write-back.The check also reported
16 whole-PE refusal controls and 5 unsupported forms rejected.On the rebased branch:
100% tests passed, 0 tests failed out of 162. This includescpu_aot_switch_vectorsand #889'scpu_aot_stack_frames. All three Python checks passed: form coverage, no bidirectional controls in 725 files, and 180 links in 13 Markdown files.Full suite before the rebase (base
fc89b9e),ctest --preset dev --no-tests=error -j 6, 452 tests:_hardwareGPU tests on an Intel Arc 140V (driver 32.0.101.9028, debug layer unavailable):dxr_query,dxr_pipeline,dxr_update,dxr_update_pipeline,dxr_facing,dxr_facing_pipeline) hit the CTest timeout.gpu_alias_lookup_writes_hardwarereportedarray_atomics expected=64 actual=256,192,128,64, the InterlockedAdd adapter defect the docs already record for another adapter.Evidence and follow-up
Fixture: original MIT source.
tests/cpu/switch_vectors.asmis assembled with ML64, and the reference model intests/cpu/switch_vectors_check.pyis independent Python on source-built buffers. Its first line is; coverage: record cpu_aot_switch_vectors, so the forms of the compared functions reach the coverage dashboard.Negative controls:
/O2mutants.Assumptions: no vector register is defined at entry, since floating-point arguments are not supported. Entry RSP is 8 mod 16. Not modeled: nontemporal stores, memory ordering against other threads, exception resumption, and the physical state of XMM6–15 inside the translation.
Docs: Vector data moves in the control-flow CPU lifter has the full contract and reproduction command. The README CPU sentence links to it.
Follow-up: taking the address of a stack slot and passing it on (
lea rcx,[rsp+N]before a call) is now the most frequent first refusal in the local sample. This PR does not change it.Checklist
This change was AI-assisted: it was written with Claude Code.
🤖 Generated with Claude Code
@copycraft on GitHub · 2026-11-23 16:38 UTC · original
this was vibecoded... but it did follow all the rules. (this is the disclosure)
@R0Y00 on GitHub · 2026-11-23 16:49 UTC · original
Please keep any locally obtained executable or other game files private. Please do not send or upload them, including via a private message. For #905 review, a source-built fixture with a commit, exact command and the first differing output or diagnostic is enough. Thanks for offering to help verify the changes.
@R0Y00 on GitHub · 2026-11-23 16:54 UTC · original
The vector-store lowering introduces a volatile read and write-back of the last destination byte before the actual store. A native vector store does not read its destination. On a PAGE_NOACCESS second page, that extra read can report a read AV where the guest instruction reports a write AV. It also adds an observable write before the guest store. Please remove the write-back probe, preserve the single memory operation and its width/order, or explicitly refuse cases where that behavior cannot be established. Extend the guarded native/lifted comparison to check exception access type and target address, with a boundary-crossing write case in both builds. Please coordinate the shared Frame changes with #895 when refreshing.
@R0Y00 on GitHub · 2026-11-23 17:26 UTC · original
I integrated the single-width store and fault details from
d31c199with #895 ineeb5738. The shared frame analysis keeps explicit import output bytes and saved vector-register state. The AVX capability check runs before native vector comparisons, so a host lacking AVX can report a capability skip. Both Windows presets passed the vector, stack frame, stack output and archive regressions (4/4 each). Fresh CI is running.@R0Y00 on GitHub · 2026-11-23 17:37 UTC · original
I saw this was closed after the integration tests passed. Is there a successor PR or a reason we should leave the vector move slice out? If you are superseding it, please link the new PR here so its review can reuse the cross-page write-fault and saved-register checks.
@copycraft on GitHub · 2026-11-23 17:50 UTC · original
You can use the thing if you want.. i just feel like this isnt ready, and i personally thing i shouldhave started with a smaller change, just to get in the flow, and also like id like to understand the repo more before vibecoding some bs.
Pull request closed