macOS: the safe copies' masked stores as plain stores under Rosetta 2 (KLBF_SAFE_PLAIN_STORES) #436
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/436"
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 PastiiJay/klbf-lab. Originally posted by vakaobr on 2026-12-01T15:19:58Z.
What this changes
victory_safe_putandvictory_safe_merge(crates/victory-gpu/src/safecopy.rs) each store the dwords that change with one AVX2 masked store (vpmaskmovdto memory). This adds a twin of each,victory_safe_put_plainandvictory_safe_merge_plain, that stores the same dwords with plainmovs, and uses the twins whenKLBF_SAFE_PLAIN_STORESsays so:wine_get_host_versionsaysDarwin), off everywhere else;1forces the twins anywhere,0keeps the masked stores even on macOS.The masked routines are untouched, so nothing changes on Windows or Linux unless the option is set.
Details:
r10/ymm0in put;eax,ymm1,ymm2in merge) and do not touch the stack, as the originals._atand_afterlabels, andfailing_exitknows the two new ranges, so the handler inwatch.rstreats a fault in a twin as it treats one in the original.watch::wine_hostbecomespub(crate)sosafecopycan ask it.docs/klbf/launch-options.jsonhas the new option (risk: experimental), andLAUNCH-OPTIONS.mdis regenerated from it withscripts/launch-options-doc.ps1.Why (issue, mission or report)
#435 (macOS test report). Under Rosetta 2 a masked store that faults cannot be resumed:
rosetta error: unexpectedly need to EmulateForward on a synchronous exception, and the process hangs. On an M5 Pro with fault tracking on, a run stopped about 68 s in atvictory.exe+0x57e2b2, bytesc4 e2 5d 8e 19=vpmaskmovd [rcx], ymm4, ymm3: the store ofvictory_safe_merge.KLBF_NO_FAULT_TRACKINGremoves the faults the layer makes itself, but title memory can still fault under these two routines (pages the title made read-only or unmapped: the reason they have a failing exit), so I think the twins are wanted with the Mac mode as well.How it was tested
v26123at065ee66. The run on the Mac was onstableat4c79ac5, with the same plain stores put in place of the masked ones without a switch.What was checked off the Mac:
safecopy.rs, assembled and run side by side on an x86-64 CPU (Linux,extern "win64"): 200,000 randomized runs each of put and merge, with the title winning on every other merge. Return values, the three counts, title memory and the held copy were equal every time.failing_exitdoes: 127,346 faults opened and resumed with the same result, 7,660 sent to the failing exit with nothing stored, and none outside the twins' labels.cargo clippy -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings: clean for these files (cross-checked from Linux with a newer toolchain, so with-A deprecatedforfetch_updatein files this does not touch).tests/launch-options.ps1: all passed (616 options).cargo test -p xtask(repository_passes_policy): passed.What was not done, so you know what to look at:
safecopy.rs(plain_stores_are_for_macos_unless_asked,the_twins_of_plain_stores_do_as_the_masked_ones,faults_in_the_twins_of_plain_stores_are_failures) are compiled but have not been run: they need Windows. CI will be their first run.Checklist
KLBF_...launch option, off by default (unless it's a plain fix) — off everywhere except under macOS, where the masked stores cannot workView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.