Safe copy: copies under 1 KiB by SSE2 moves, 3-4x faster small copies on Zen 2 (VICTORY_SMALL_COPY) #2116
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2116"
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 trustno1-coder/VIctory-NVIDIA. Originally posted by OGShotz on 2026-11-29T09:37:19Z.
What it changes
safecopy::copy(the fault-safe copy of title memory) was onerep movsbat any length.rep movsbstarts slowly on Zen 2, which has no fast shortrep movsb, so small copies cost several times what a plain copy does.Copies under
VICTORY_SMALL_COPYbytes (1024 by default;0keepsrep movsbfor every length, as before) now use 16-byte SSE2 moves, then 8-byte moves, then single bytes. All of these sit betweenvictory_safe_copy_atandvictory_safe_copy_after, so a fault in them is handled as one inrep movsbis: the watch handler opens a block we guard and the copy goes on, or the copy leaves throughvictory_safe_copy_failed. The path is SSE2 only, with no AVX state to clear. The limit is passed inr9, so the switch is read once in Rust (small_copy()), not in the assembly.How it was tested
-C target-cpu=znver2.safecopy::tests::copy_costs(ignored test,--nocapture). It now also measures 64 B and 1 KiB pieces, scattered over 128 MiB. These are the column forcopy(labelled "rep movsb" in the test output), in GB/s:VICTORY_SMALL_COPY=0(before)Pieces of 4 KiB and up are memory-bound and unchanged; they still take
rep movsb.cargo test -p victory-gpu --lib safecopy: 8 passed.copies_every_length_and_alignmentcovers more lengths now (7-9, 15-17, 31-33, 63-65, 100, 513, 1023-1025).faults_are_failuresadds small copies that run into a forbidden page (a + 4096 - 20, 40 bytes;a + 4096 - 3, 8 bytes), which must fail, and one that ends just before it, which must succeed.victory-gpusuite passed (920) on a branch with this change on main829188e9. On the previous main (e1f2eb60) the gpu, shader and hle suites all passed with it (625 / 395 / 204; the gpu suite has the same rare failures as main without it:watch::many_askers_tests2 of 1,000 runs either way, anddescriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes).Checked for overlap
vzeroupperon both exits. This one is that part on its own, against the current main, switch-gated, with Zen 2 numbers and fault tests at the edges. If #1298 lands first, this can be closed.🤖 Generated with Claude Code