Loader: clzero loops in one exception; rdpru (#34 rebased, with a fix) #214
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!214
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/214/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?
@Makto94 on GitHub · 2026-11-24 01:29 UTC · original
Makto94:fix/clzero-loops→main· +395 −3 · 1 files · 3 commits · merged 2026-11-25 00:16 UTCThis is #34 by @ka1qux rebased over #45, with a fix and tests added. #34 conflicts with
mainsince #45 added the same flag and register helpers forclwbloops; the duplicates are merged intogpr/cmp_flags/CMP_FLAGS.From #34
clzero: the two loops compilers build around it are done whole in one exception, leaving registers and flags as the last pass would. ka1qux measured one 28 KiB clear at 448 exceptions / 0.40 ms onmainvs 1 exception / 4 µs with this (i5-13600KF, see #34).rdpru: the time-stamp counter for MPERF and APERF, 0 for other counters.Added here
cmp rax, rax. It was taken for the loop and leftZF=0where the CPU leavesZF=1. Now it is one line, as with any other neighbours.emulate_amd_onlywith a synthetic context: both loop shapes, therax-raxand wrong-neighbour fallbacks, andrdpruwith flags all set and all clear.On the #34 review (rdpru and CF)
The review asked for
rdpruto set CF on success and clear the other status flags. Measured natively in user mode on a Ryzen 7 5800X3D (Zen 3),rdpruchanges no flags, from starts of0x202,0x8d5and0xad7, forecx0, 1, 2 and 0x40 (counts for 0 and 1, zero for 2 and 0x40). So the emulation leaves the flags alone, and a test pins that. This is one CPU, not the console's Zen 2, and I did not check the AMD manual's RDPRU entry.Testing
cargo test -p victory-loaderon Windows 11 with the pinned 1.98.1 toolchain: 22 passed, 0 failed; clippy clean.Ripand the zeroed lines: 1,008 cases for loop 1 and 14,112 for loop 2 (r8–r15 included, limits reached on entry or below the start, unaligned starts), plus wrong neighbours and code at page edges between no-access pages. All pass on this version; it found thecmp rax, raxcase above, whose test fails before the fix.u64::MAX,rspas an operand.🤖 Generated with Claude Code
Update: main merged in (
ffe310e) so CI runs; the patch itself is unchanged.Update: three tests added for the loop edge cases (limit on a line boundary, r9-r15 with REX.R/REX.B, rax as the limit); the handler is unchanged.
@SkippySteve on GitHub · 2026-11-24 01:32 UTC · original
Ran
cargo test -p victory-loaderforx86_64-pc-windows-msvcunder Wine on Linux to compare this PR withmain.Setup: Arch-based Linux, toolchain 1.98.1 (pinned), built with
cargo xwin test, tests run by UMU-Proton 11.0 (wine-11.0) in a new prefix.Host CPU: AMD Ryzen 5 5600 (Zen 3).
clzeroandrdpruare both in/proc/cpuinfo, so the nativeclzero_loops_end_like_their_last_passtest runs the instructions directly and never reaches the handler. That makes this a second Zen 3 result, not the Intel check the PR lists as untested. Theemulated_*tests feed the bytes toemulate_amd_onlydirectly, so they are a real check of the emulation on any CPU.main(d2a4bae)9de712f)tests/load_probe.rsThe 4 new tests pass under Wine:
compare_sets_flags_like_the_cpu,clzero_loops_end_like_their_last_pass,emulated_clzero_loops_end_like_their_last_passandemulated_rdpru_reads_known_counters_and_keeps_flags. All 18 existing tests also pass.load_probe::loads_binds_and_calls_probefails the same way onmainand on the PR: it spawns hostcargofrom inside the Wine process (running cargo: ... Invalid handle, then a mixed\..\..\fixture path). That is a problem with how this setup runs the test, not with the PR.Other checks:
cargo xwin clippy -p victory-loader --all-targets -- -D warnings: clean.git merge-treeagainst currentmain(which now includes #129): no conflicts.Not tested: an Intel or non-AMD host where the handler really runs, and the title.
@wwwwwwww3333333 on GitHub · 2026-11-24 14:41 UTC · original
Intel result for this PR's own code, through the real handler. i5-13400F (Raptor Lake, no
clzero: CPUID8000_0008EBX[0] = 0), Windows 11, Rust 1.98.1 MSVC, this PR (9de712f) merged ontod2a4bae:cargo test -p victory-loader --lib -- --test-threads=1: 22 passed, 0 failed. That includesclzero_loops_end_like_their_last_passandclzero_zeroes_its_line_on_any_cpu, which on this CPU fault for real and go throughemulate_amd_only, so they cover the handler path the description lists as untested on Intel.Timing, with a local ignored test that is not part of this PR (below). It runs the title's loop from #7 (
0f 01 fc 48 83 c0 40 4c 39 d0 72 f4) over 16 MiB, release build, best of 3, and checks every byte is zero afterwards:d2a4bae: 484.6 ms (33 MiB/s; 262,144 faults, about 1.85 µs each)That is about 350× on this CPU, consistent with ka1qux's 0.40 ms → 4 µs for 28 KiB on an i5-13600KF.
Not runtime-tested with game files.
The timing test (in
crash.rs'smod tests; run withcargo test --release -p victory-loader --lib clzero_loop_speed -- --ignored --nocapture)AI-assisted (Claude wrote the timing test and did the analysis; I ran it on my machine).