Repository navigation
PE loader: a title's CLZERO loops run as native code on a CPU without CLZERO - #2892
Conversation
… CLZERO CLZERO is AMD's; on an Intel CPU each clzero raises an illegal-instruction exception that XCL answers by emulating the loop it starts (insn::ConsoleOnly::ClzeroLoop): one exception for every run of the loop. A retail title's memset is such a loop. While its world loaded on an Intel CPU one of its threads was in that exception at every thread dump (300, 360 and 400 s of several runs), and XCL_GPU_TIMES measured 0.17 to 0.51 s of GPU work in world frames that took 17 to 43 s: the card stood idle while the CPU side crawled. When an image is mapped on a CPU without CLZERO, each such loop (12 bytes) becomes a call of a stand-in next to the image that zeroes the same whole lines with rep stosb and leaves rax, the flags and every other register as the loop does. XCL_CLZERO_PATCH=0 keeps the emulation. A lone clzero is still emulated. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Tested and reviewed commit Tested
Review notes
Not tested
AI use
|
…SKIP, probe past xcl-dev#2891)
|
Focused Intel/Wine verification of exact head Tested: Intel Core i7-13620H, 16 GiB system RAM, Linux 6.17 / Wine 11.0 / Rust 1.98.1, Windows MSVC target. This is CPU execution, not a GPU fixture; the laptop has an RTX 4060 but no rendering claim is made. Existing external 9 GiB/512 MiB scope and RAM/GPU/disk safety guards retained.
Passing owner fixtures:
Evidence: Not tested: full suite, every possible end register, retail loader patch-site discovery, opt-out integration, matched-main title regression, loading time/FPS, or gameplay. No title was launched. This clears the selected native-loop/emulator correctness checks here; it does not establish that this fixes our separate Game-Init stalled-fence watchdog, nor certify the complete nvidia-dev integration. The useful next comparison is a controlled title main/head run after the independent Wine synchronization/safety blockers are cleared, not an unchanged crashing launch. AI-assisted verification/report: omp, OpenAI GPT-6 Astra; results above are from executed local commands. |
…st and version Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Requested by Prime · project thread
On a CPU without CLZERO (every Intel CPU), each run of a title's
clzero; add rax, 0x40; cmp rax, <reg>; jbloop raises an illegal-instruction exception thateh::emulate_console_onlyanswers: one exception for every run of the loop. A retail title's memset is such a loop. This patches those loops once, when the image is mapped, into a call of a native stand-in next to the image that zeroes the same whole lines and leaves rax, the flags and every other register as the loop does.Part of #2688.
Why
On an Intel i5-10400, while a retail title's world loaded, one of its threads stood in the exception path (
eh::cpp_exception_logger/is_writable) at every thread dump (XCL_THREAD_DUMP_AT, 300, 360 and 400 s, several runs), andXCL_GPU_TIMESmeasured 0.17 to 0.51 s of GPU work in world frames that took 17 to 43 s: the GPU stood idle while the CPU side crawled. With the loops patched (6 in that title) the same run's world frames took 1.05 to 1.81 s and it issued 102,739 dispatches where it had issued 12,000 to 24,000. In the 60 s regression run below the title shows 1393 frames against the base's 459.What is in it
crates/xcl/src/eh.rs:cpu_has_clzero(CPUID 8000_0008h EBX bit 0),clzero_loop_thunk(the stand-in for one end register: zero[rax & !63 ..)in whole lines up to it withrep stosb, at least one line as the loop's first pass, rax and the flags as the loop's lastadd/cmpleave them, no other register changed),code_near(64 KiB acall rel32reaches),patch_clzero_loops(finds the 12-byte loops withinsn::decode, leaves an0x67-prefixed CLZERO and a loop against rsp alone, writescall+ a 7-byte nop).XCL_CLZERO_PATCH=0keeps the emulation; a lone CLZERO is still emulated.crates/xcl/src/loader.rs: step 9 of mapping an image, after the stack-cookie hook, on a CPU without CLZERO only.eh::tests::a_patched_clzero_loop_zeroes_whole_lines_and_keeps_registers: patches a real loop in executable memory and runs it (lines zeroed, bytes around them kept, rax where the loop leaves it, rcx/rdi/rdx unchanged, end at or before the start zeroing one line).Tested
cargo test --locked --workspace --no-fail-fast -- --test-threads=4withXCL_DXC_DIRset to DXC 1.9.2609.5: 1817 passed, 9 failed, 48 ignored. The 9 failures are the same tests that fail onnvidia-deveae01502itself (1816passed,9failed,48ignored there, same command):async_compute_pso_registers_real_pso_and_not_standin,console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly,gpu::recomp::tests::gpu_compute_thread_limits_leave_the_lanes_past_them_out,hle::d3d12x::texture_upload::tests::gpu_parts_of_a_texture_go_up_and_the_rest_stays,hle::d3d12x::texture_upload::tests::pieces_hold_the_texels_of_their_levels,split_compute_prefers_the_offline_whole_pipeline,two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs.Build and test (Windows, no GPU)fails here onhle::d3d12x::sparse::tests::a_gpu_write_into_a_gpu_view_lands_in_its_cpu_view(the WARP device is removed, 0x887a0005). That test passes on the card above, on this branch and oneae01502, and fails the same way on the other open pull requests againstnvidia-dev(kernelx: physical page homes in window 0 first, from the top, keeping 64 MB free (#2867) #2905, for one).Regression run
A commit of
main(b49be183, the last one before the shader preparation screen of #2555, which prepares every record before the title and so does not fit a 60 s run):The base of this PR,
nvidia-deveae01502:This PR's head:
Not tested
AI use
Claude Code (Claude Fable 5.2 and Claude Opus 5.5) wrote the code, ran the suite and the regression runs on the hardware above, and wrote this description; Prime asked for it and owns the account. We coordinate the 8 GB work on the XCL Discord too: https://discord.gg/gK3y7WRRY
🤖 Generated with Claude Code