Repository navigation
Loader: clzero loops in one exception; rdpru (#34 rebased, with a fix) - #214
Conversation
Based on Marvisak#34 by ka1qux (commit faa0a9a), rebased over Marvisak#45, which added the same flag and register helpers for clwb loops; the duplicates are merged into gpr/cmp_flags/CMP_FLAGS. clzero: the two loops compilers build around it are done whole in one exception, leaving registers and flags as the last pass would. Anything else around it is one line and the next instruction. rdpru: returns the time-stamp counter for MPERF and APERF, 0 for other counters, and leaves the flags as they are: a Ryzen 7 5800X3D running it natively in user mode changes none, for known counters or not. Added over Marvisak#34: - loop 1 rejects cmp rax, rax (it fell into the loop and left wrong flags); - tests that go through the emulation on any CPU (both loop shapes, the rax-rax and wrong-neighbour fallbacks, rdpru with both flag states), since on an AMD host the native tests never enter the handler.
|
Ran Setup: Arch-based Linux, toolchain 1.98.1 (pinned), built with Host CPU: AMD Ryzen 5 5600 (Zen 3).
The 4 new tests pass under Wine:
Other checks:
Not tested: an Intel or non-AMD host where the handler really runs, and the title. |
…sed, with a fix) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Intel result for this PR's own code, through the real handler. i5-13400F (Raptor Lake, no
Not runtime-tested with game files. The timing test (in
|
Merges Marvisak#188 Marvisak#213 Marvisak#214 Marvisak#219 Marvisak#221 Marvisak#311 Marvisak#324 Marvisak#363 Marvisak#406 Marvisak#454 Marvisak#529 Marvisak#560 Marvisak#708 Marvisak#937 Marvisak#941 Marvisak#963 Marvisak#1111 Marvisak#1159 Marvisak#1304 Marvisak#1306 onto main (ffe310e), each head unchanged, no conflicts. One change of mine: the long-format import descriptor code Marvisak#963 adds nests `if size == 0` in an `if let`, which clippy::collapsible_if rejects under -D warnings; it is now one `if let ... && size == 0` (clippy --fix, no change of behaviour). cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (388 passed, 7 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
cb40900 to
514927d
Compare
…visak#34 rebased, with a fix)
…visak#34 rebased, with a fix)
…visak#34 rebased, with a fix)
This 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 Loader: clzero loops in one exception; rdpru #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.