Console CPU instructions: a CLZERO loop traps once per run; rewrite it to a stub once #2497
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#2497
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@voiceovarian1-max on GitHub · 2026-11-25 20:39 UTC · original
On a CPU without CLZERO, a retail title's small clearing loops cost one illegal-instruction exception per run. Plan: the first time such a loop faults, rewrite it once to jump to a small stub that clears the same lines with plain stores.
#217 made a whole
clzero; add rax,0x40; cmp rax,r; jbloop one exception (ConsoleOnly::ClzeroLoop) and hot-patches CLWB to NOPs; #647 makes each exception'sis_writablecheaper. This title runs 5 such loops (0.9–7 KB each) in one function thousands of times a second. In a thread-dump sample of its world, title threads were inemulate_console_onlyin 17 of 344 samples. Exceptions are slow under Wine; on Windows they cost less, but are not free.Plan (about 110 lines in
eh.rswith a test,XCL_CLZERO_PATCH=0to turn it off): only for a loop right after the 10-byte NOP compilers pad loops with (66 2E 0F 1F 84 00…).cmpbytes, and jumps back after the loop.jmp stub, then the loop's first 4 tojmp short. These are aligned stores, so another thread always sees code it can run.Loops without the pad, not 8-byte aligned, or ending at rcx/rdi/rax/rsp stay emulated.
Measured so far: Linux, Proton's Wine, i7-14700K, RTX 4070 Ti. 4 of the 5 loops were rewritten and the title ran to the end of each run. The frame rate did not change measurably, because the main limits are elsewhere. A test runs a rewritten loop and checks the cleared lines and rax.
This extends #217's hot-patching from CLWB to these loops. Would a PR for it be welcome?
AI use: found, written and tested with Claude Code (Claude Opus 5.5).