Repository navigation
Conversation
Rosetta 2 runs VMASKMOVPS / PD and VPMASKMOVD / Q to memory an element at
a time and resumes a fault only on the first element; a fault on a later
one ends the process ("rosetta error: unexpectedly need to EmulateForward
on a synchronous exception"). Under Wine on macOS the write watch keeps
pages protected, so a title's masked store that crosses into a watched
page ends the run. The remedy (later commits) replaces each such store at
image load with a call to a helper that stores one element at a time.
This commit is the first part: `maskmov::insn_len`, the length of an
x86-64 instruction (to walk a function from its start to a candidate
site), and `maskmov::decode`, the four stores with any memory operand.
Nothing calls them yet.
Split out of mac-on-main-wip b51552b (xcl-dev#258).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The second part of the masked-store replacement for Rosetta 2. `maskmov::helper` writes position-independent code that does what one store does: it takes the address into R8 while every register still holds the title's value, spills source and mask to its stack, and stores each selected element with a plain `mov` (CDQ / JRCXZ on the mask's sign: no flag and no vector register written, a masked-out element not touched). A plain `mov` faults and resumes like any store, element by element. `call_site` is the `call` + NOPs that replaces a store; `UNWIND_INFO` is the unwind data all helpers share, so a fault in a helper unwinds into the title's function like one at the store. Tests: the helper's bytes, and under `exec` (Windows x86-64 only) each of 224 stores (4 kinds x XMM / YMM x 28 operand shapes) run against the instruction itself for every mask - registers, flags, YMM0-15, stack and memory identical; a masked-out tail at the end of a mapping; a fault on a later element in a write-watched page resumed. The ignored test runs the instruction itself across a watched page boundary: under Rosetta 2 it ends the process, which is the finding. Split out of mac-on-main-wip b51552b (xcl-dev#258). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Regression run of Against the limits in CONTRIBUTING.md: 100 % of AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, AI use: Claude Code (Claude Opus 5.5) built both trees and ran |
|
NVIDIA test report for
Lib tests only; no title run. AI-assisted (Claude Code, Claude Opus 5.5). |
|
Thanks @upipibi for the NVIDIA run. Each part of the masked-store stack now has a run from someone other than me; it waits for a maintainer review and merges cleanly into |
|
This is the second PR of a stack: it is stacked on #1303, and #1313 and #1344 sit on top of it. The shared lines are the stack, not a duplicate. No other open or merged PR adds masked-store helpers. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Stacked on #1303; only the top commit (
4b30c37) belongs here. Second of four PRs bringing @Ahmet-Dedeler's masked-store fix for Rosetta 2 frommac-on-main-wip(b51552b) tomain. Part of #258.Under Rosetta 2 a masked store (VMASKMOVPS / PD, VPMASKMOVD / Q to memory) that faults on any element but the first ends the process. This PR adds the code that replaces such a store: a helper that does the same store one element at a time with plain
movs, which fault and resume like any store. Nothing calls it yet; PR 3 finds the sites in an image, PR 4 applies them at load under Rosetta 2.Why this is over 800 lines: about 120 are the helper code, the rest is its proof. The
exectests are a harness (an assembly runner that loads and saves every register, the flags, YMM0–15 and the stack) that runs each helper and the real instruction from the same state and compares them. Splitting the helper from those tests would leave a PR whose code nothing checks.What is in it
maskmov.rs:helper(position-independent code: address into R8 first, source and mask spilled to its stack, one guardedmovper element using CDQ / JRCXZ, so no flag or vector register is written and a masked-out element is not touched),call_site(call helper+ NOPs over the store),UNWIND_INFO(shared by all helpers, so a fault in one unwinds into the title's function), andHELPER_MAX.a_helper_is_the_address_two_spills_and_a_store_per_element(the bytes);exec(Windows x86-64 only):a_helper_does_what_the_instruction_does(224 stores, 4 kinds × XMM / YMM × 28 operand shapes, every mask: 32,704 runs),a_masked_out_tail_may_end_where_the_mapping_ends,a_helper_resumes_after_a_fault_on_a_later_element(a write-watched page, as Wine's write watch makes it).the_instruction_itself_across_a_watched_page_boundaryis#[ignore]: it runs the real instruction across a watched page boundary, which ends the test process under Rosetta 2. It is the reproduction of the bug, not a test that is skipped to pass; run it with--ignored.Tested
x86_64-pc-windows-gnuwith mingw-w64 (GCC 16.2.0), Rust 1.100.0, debug; the lib test binary run under CrossOver'swine.maskmov::on this head: 6 passed, 0 failed, 1 ignored.--exact maskmov::exec::the_instruction_itself_across_a_watched_page_boundary --ignored: prints "a fault on the first element was resumed; now one on the fourth", thenrosetta error: unexpectedly need to EmulateForward on a synchronous exception … inst_index=18and the process ends, as on Ahmet's M5 Pro.Regression run
From @Toons29: AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, Windows 11 build 26300, release builds,
scripts/smoke.ps1, the same retail title for 60 s,main4178e88and this head: 100 % ofmain's frames, 100 % of its peak commit, no crash, no device removal.Nothing calls this code yet, so the pair shows only that the title runs as on
main.Not tested
exectests against the hardware's own masked stores, which is the comparison that matters most.cargo test --workspaceas a whole (it does not finish under CrossOver, see macOS (Apple Silicon, CrossOver + D3DMetal): the newer retail game reaches its first-run menus at 30 fps #258).AI use
claude-opus-5-5): split the commit, ran the tests above and wrote this description. The code and tests are Ahmet's.