Repository navigation
cpu_emulation: the executable's CLZERO zeroing loop is finished in one trap (retail frame loop on Intel: about 2.4 to 46 frames a second; depends on #7111) - #8783
Conversation
… desktop CPU may lack The runtime runs the Xbox Series (Zen 2) executable natively, so an instruction the host CPU lacks raises #UD where it is reached. tools/cpu_feature_scan.py streams dumpbin /disasm like inline_scan.py, maps each instruction to its CPUID feature or privilege class (AMD-only, newer-Intel-only, not on Zen 2, privileged, kernel call, host query, baseline), and splits the counts by .pdata range. docs/cpu_features.md records the 1.0.2.1 result (counts only): 19 SSE4a, 10 CLZERO and 4 MONITORX/MWAITX sites (AMD only) and 8 CLWB sites, all real code; the privileged hits are jump-table data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the first Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Q/EXTRQ, CLZERO, MONITORX/MWAITX, CLWB) The executable uses SSE4a INSERTQ, CLZERO and MONITORX/MWAITX (AMD only) and CLWB (Intel since Ice Lake) without asking CPUID (docs/cpu_features.md). A host without one raises #UD there. src/cpu_emulation.h adds a vectored handler that recognises those encodings at the faulting RIP, does the same work on the CONTEXT and steps past the instruction; gta6rt installs it before any image code runs, after the startup trace's handler so it runs first. One [rt] line names what the host lacks, one more per instruction on first use. cpu_emulation_test checks the decoder on hand-written encodings, the bit-field helpers and apply() on a synthetic CONTEXT, then runs every form for real from an executable buffer: natively on a Zen host, through the handler on an Intel one, with the same expected values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ult; accept 66 on 0F 01 FC/FA/FB A line CLZERO cannot write now reaches the next handlers as the access violation (or guard-page violation) the instruction raises, with the write flag and the line address, instead of the #UD. The 66 prefix and segment overrides are accepted on CLZERO/MONITORX/MWAITX; F2/F3 (other instructions there, F3 0F 01 FA is MCOMMIT) and LOCK stay #UD. Points raised by SirKingg on ItsNotRexed#7055. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… xmm1[127:64]; AMD prefix forms; no SEH - INSERTQ xmm, xmm took the length and index from swapped fields. The APM (vol. 4) has the length in xmm2[69:64] and the index in xmm2[77:72]; a Ryzen 9800X3D and a Ryzen 5700X agree (TheHoracio, Mayzkl on ItsNotRexed#7111). The measured 0x0810 case is a unit check now. - INSERTQ/EXTRQ zero xmm1[127:64], as the Zen 3 measured in the same review does in all four forms. - Decode REX bytes among the legacy prefixes (a non-final REX is ignored) and accept F2/F3 on CLZERO, as Zen 3 runs them (ItsNotRexed#7055's reviews); F2/F3 stay #UD on MONITORX/MWAITX. - Check the CLZERO line's page and the instruction bytes' readability with VirtualQuery instead of catching a fault in a local __try, which clang-cl without /EHa does not cover for inline stores (venetanji on ItsNotRexed#7111). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on and xg_xs test targets) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e trap (retail frame loop on Intel: about 2.4 to 46 frames a second)
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Verified on Windows 11.
- Massive performance optimization for Intel CPUs: recognizes the hot memory-zeroing loop tail (\clzero; add rax, 64; cmp rax, limit; jb) in the #UD exception filter and finishes remaining iterations in a single trap via \memset.
- Accurately reconstructs CPU flags (CF, PF, AF, ZF, SF, OF) matching the final \cmp rax, limit\ instruction.
- Safe page boundary protection: halts early and steps back to the \clzero\ instruction if encountering uncommitted, read-only, or guard pages so the kernel raises the authentic access/guard violation.
- \ ools/cpu_feature_scan.py\ passes compileall and cleanly lists Zen 2 instructions.
- Clean-room check and \git diff --check\ pass on all changed files.
LGTM!
|
Tested
|
|
Checked Pass
Needs changes
Not checked here: Intel timings, retail reachability (including #8537), the samples, presentation rates. That needs AI-assisted: Codex GPT-6.2 Sol ran the checks, Claude Opus 5.5 reviewed the report. The executable was read in place (SHA-256 |
|
checked: #878358f7d1c (the last commit, on top of #7111) | with: the same cross-build as my #7111 check | on: Linux 6.18, Proton-CachyOS 11.0 (wine-11.0), Intel Core i5-12400F (no CLZERO), RTX 4060, driver 620.70.06 | result: pass under Wine. The retail frame loop runs with PresentX called about 200 times a second (the frames are still black, as reported on #8851), and a 330 s run ended without an exception. Base as in my #7111 check. No A/B against #7111 alone. |
… docs: three hosts and the frame loop --bench timed CLWB on every host and called the native instruction "the emulation cost" where CLWB is native (towade, fiestorra, SpaghettiMaster545 on ItsNotRexed#8537). It now times each of CLWB, CLZERO and EXTRQ that the host lacks, against a NOP of the same length, and says there is nothing to time on a host that has all three. cpu_features.md: the Raptor Lake and Zen 4/5 rows from the reviews, the measured scope (up to the slot 41 assert), the CLZERO sites a boot that reaches the frame loop adds, and ItsNotRexed#8783 for the hot CLZERO loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
checked: #878358f7d1c (last commit, stacked on #711139b757a) | base:
agent: yes |
Claimed in the coordination issue as: new RT item (RT-500 follow-up), #8683 (comment)
Depends on: #7111 (this branch is on its head
39b757a6d; review only the last commit,58f7d1ca6)What and why
#7111 emulates CLZERO from the #UD handler, one instruction per trap. The executable's 10 CLZERO sites are one routine that zeroes memory a line at a time with the same four instructions:
so every 64 bytes cost one exception round trip, about 1.9 us here. A boot reaches this loop, and the title's frame loop runs it all the time: on a retail boot one title thread sat at 100 % of a core with its RIP on the CLZERO (4 of 24 stack samples), and the title presented about 2.4 frames a second.
finish_clzero_loop(runtime/src/cpu_emulation.h): after a CLZERO has been emulated, when the bytes at RIP are exactly that tail, the handler zeroes every further line the loop would, sets RAX, the arithmetic flags (those of the lastcmp) and RIP as the loop leaves them, and continues after the branch. A line that is not committed, is guarded or cannot be written ends it early with RIP back at the CLZERO and RAX in that line, so that iteration traps again and raises its access violation as before (a page that is committed on first touch still gets its fault this way). Any other code after a CLZERO is emulated as before. Nothing is patched in the image.Measured
Intel Core i9-14900KF (no SSE4a, CLZERO, MONITORX), NVIDIA RTX 5070 (driver 32.0.16.2124), Windows 11, MSVC 14.51 RelWithDebInfo,
LEONIDA_D3D12=vulkan, own 1.0.2.1 copy.cpu_emulation_test(16,376 lines)The retail numbers are from a local integration stack (tibzejoker's
rt5-integrationplus the open boot-chain pull requests up to a frame loop that presents, with #7111 and this change), not from this branch alone. The first loop the boot ran through it zeroed 229 lines in one trap. It does not change what the title draws: the frames were black before and after. Counts only, nothing from the executable.For #8537's table: its boot stopped about 4 s in, before the loop is reached, so it saw no CLZERO. A boot that reaches the frame loop spends its time there.
Tested
cpu_emulation_test: all checks pass on the i9-14900KF (every form through the handler). New:test_clzero_loop(the lines zeroed, RAX/RIP/flags for a limit on and inside a line,cmp rax, rcx, nothing left to do, another instruction after the CLZERO, a branch that does not go back to the CLZERO, a read-only page) and, live, the whole loop over 1 MiB and into a read-only page (access violation, with the lines before it zeroed). The live cases run natively on a host with CLZERO, so there they check the instruction itself; I have no such host.gta6rtbuilds; the retail run above.python -I scripts/check_no_game_data.pyon the four changed files: clean.tests/test_docs_*.py: the same three fail as on RT-500: gta6rt emulates the Zen 2 instructions an Intel CPU lacks (INSERTQ/EXTRQ, CLZERO, MONITORX/MWAITX, CLWB) #7111's head (test_docs_cli_flags,test_docs_design_rows,test_docs_links); the others pass.Not shown
AI-assisted: yes (Claude, in OpenCode).