Repository navigation
PE loader: a title's CLZERO loops run as native code on a CPU without CLZERO (port of #2892) - #3082
AngeloMaiale wants to merge 1 commit into
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>
72a141c to
dd883f2
Compare
|
A second loop shape this PR may want to cover, read from both projects and not run (I don't run the title): xcl's decoder knows one That is 15 bytes, with the counter in AI-assisted (Claude Code, Claude Opus 5.5 read both handlers). |
|
Good catch — I scanned the executable sections of title There are 11 byte matches in total (all in the main
None of the 4 15-byte loops fired during the 60 s menu smoke run ( To keep #3082 as a verbatim cherry-pick of #2892 from AI use: Antigravity (Gemini 4 Carbon) scanned the PE sections for |
|
A second candidate for this patch-at-load approach, with numbers, in case it's useful for a follow-up (read from other trees' threads, not run): xcl emulates SSE4a That is the same kind of site as the 12-byte AI-assisted (Claude Code, Claude Opus 5.5 read VIctory#3042 and ScarlettPort#377). |
|
Ran the clzero tests on both Linux/Wine lanes at head
So on both vendors, under Wine, the thunk patch and the register preservation hold on the machine that actually takes the illegal-instruction path (rig2) and on the machine that skips it (rig1). Tested: the 3 clzero-matching tests, x3 per lane at |
|
Closing as a duplicate of #2892: #2892's change (CLZERO loops patched on a CPU without CLZERO, AI use: Claude Code (Claude Opus 5.5) checked the pair and wrote this; part of the duplicate sweep announced on #3041. |
Port of #2892 (
f9362ed3onnvidia-dev, by @Prime1997) tomain.On CPUs without native
CLZERO(all Intel CPUs), each run of a title's 12-byteclzero; add rax, 0x40; cmp rax, <reg>; jb -12loop raisesSTATUS_ILLEGAL_INSTRUCTIONintoeh::emulate_console_only. At PE image load on a CPU withoutCLZERO, replace each 12-byteClzeroLoop(end_reg != rsp) with acallto a near-imagerep stosbstand-in that zeroes the same whole 64-byte lines and leavesrax, flags, and all other registers as the loop does (XCL_CLZERO_PATCH=0keeps trap emulation; loneclzerostays emulated).Note:
HANDOFF.md("Console CPU instructions the PC lacks") describesclzeroas always emulated byeh::emulate_console_only; 12-byteClzeroLoopsites in mapped title images now run natively.Fixes #2497
What is in it
crates/xcl/src/eh.rs:cpu_has_clzero,patch_clzero_loops(withclzero_loop_thunkandcode_near), and unit testa_patched_clzero_loop_zeroes_whole_lines_and_keeps_registers, cherry-picked verbatim from PE loader: a title's CLZERO loops run as native code on a CPU without CLZERO #2892.crates/xcl/src/loader.rs: callseh::patch_clzero_loopson executable sections of mapped title images when!eh::cpu_has_clzero().Tested
rustc 1.100.0(stable-x86_64-pc-windows-msvc), debug (workspace test suite) and release (smoke.ps1)..\scripts\test.ps1(cargo build --workspace && cargo test --workspace -- --test-threads=4): 1467 passed, 0 failed, 47 ignored (28SKIPPEDlines: 20no wave64, 3#1426wave32 per-lane f16/f32 refusals, 1no heap windows, 1no D3D12 debug layer, 3e2edebug-layer/sample skips).419239bf(60 s run on Intel Core i7-12650H): logged6 CLZERO loops run as native code on this CPU, which has no CLZEROat image load and zeroClzeroLoopemulation traps thereafter (versusClzeroLooptrap emulation onmain).Regression run
main:
PR:
Not tested
cpu_has_clzero()is true andpatch_clzero_loopsis skipped).XCL_CLZERO_PATCH=0on a live title.AI use
dd883f27is cherry-picked verbatim from PE loader: a title's CLZERO loops run as native code on a CPU without CLZERO #2892 by @Prime1997 (Co-Authored-By: Claude Fable 5.2). Antigravity (Gemini 4 Carbon) cherry-picked the commit ontomain, ran the test suite and paired regression smoke runs, and wrote this PR description.