Console CPU instructions: fix ClzeroLoop ModRM check and loop semantics #290
No reviewers
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!290
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/290/head"
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?
@AlpPesen on GitHub · 2026-11-23 22:28 UTC · original
AlpPesen:fix/clzero-loop-semantics→main· +140 −13 · 2 files · 1 commits · merged 2026-11-23 23:20 UTCFixes items 1 and 2 of #278 (
ClzeroLoopdecoder false-positive and loop emulation semantics).insn::decodepreviously matched[48|4C] 39 <modrm> 72 F4without checking(modrm & 0xC7) == 0xC0, allowing non-raxor memorycmpforms to decode asClzeroLoop. Ineh::emulate_console_only,ClzeroLoopalso skipped 64-byte cache-line alignment, zeroed partial bytes instead of full 64-byte steps whenend - startwas not a multiple of 64, skipped the firstclzerowhenend <= startwhile still overwritingctx.Rax = end, and leftctx.EFlagsstale.Overlap note: touches
crates/xcl/src/insn.rsandcrates/xcl/src/eh.rs(same files as #234, disjoint hunks).What is in it
crates/xcl/src/insn.rs: require(modrm & 0xC7) == 0xC0andend_reg != 0forClzeroLoop, with negative decoder tests (cmp rdx, rcx,cmp [rax], rdx,cmp rax, rax).crates/xcl/src/eh.rs: alignClzeroLoopto 64-byte lines, advanceRaxin 64-byte steps, update arithmeticEFlagsviacmp_eflags, and fall back to stepping the singleclzero(len - 9) whenend <= startor the full span cannot be fast-forwarded; adds unit tests forcmp_eflagsand aligned/unaligned/end <= startClzeroLoopcases.Tested
26300), Intel Core i9-9900K (Coffee Lake, pre-Ice Lake — noCLZERO/CLWB), AMD Radeon RX 6800 (16337 MiB VRAM, driver32.0.21045.29003; notesmoke.ps1's WMI query prints the first non-Basic adapterParsec Virtual Display Adapter, while XCL renders on the RX 6800),rustc 1.100.0, DXC1.9.2602.17(debugfor tests,releasefor smoke runs).XCL_REQUIRE_GPU=wave64,mesh+.\scripts\test.ps1: 653 passed, 0 failed, 40 ignored, 0 GPU skipped (xcllib: 613 passed / 20 ignored; integration/e2e: 40 passed / 20 ignored;XCL_SAMPLE_*unset).YouKnowWho): confirmedClzeroLoop { end_reg: 10 }ran on i9-9900K inxcl.logwith 0 crashes and 0 device removals.Regression run
Both runs below used the same warmed shader cache on
YouKnowWho(60 s):main(9ab7d763197c):PR head (
9e9551b0ec19):Not tested
XCL_SAMPLE_*unset).AI use
@PHeitor1 on GitHub · 2026-11-23 22:47 UTC · original
Tested
9e9551bmerged ontomain9ab7d76on RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X (Zen 3), Windows 11 Pro 26300 (native), rustc 1.100.0 MSVC, debug,cargo test --workspace --no-fail-fast -- --test-threads=4, noXCL_SAMPLE_*. Baselinemain9ab7d76: 651 passed, 0 failed, 40 ignored.Pass: 653 passed, 0 failed, 40 ignored. GPU skips: the same 2 as on
main(no wave64).Run and written with Claude Code (Claude Opus 5.5).
@mastrr9 on GitHub · 2026-11-23 22:52 UTC · original
Independent static code & x86-64 ISA audit of
9e9551b0e(code inspection only —cargo testnot run on macOS; no game files):Summary: Looks clean
(Note: overlaps with #295, which also addresses #278.)
cmp_eflags(eh.rs:269-293): Verified all 6 arithmetic flags (CF,PF,AF,ZF,SF,OF) match x86-64cmp lhs, rhswhile preserving non-arithmeticEFLAGSbits.insn.rs:125-134,eh.rs:351-376):(modrm & 0xC7) == 0xC0+reg_idx != 0cleanly rejects non-raxr/m, memory operands, andcmp rax, rax. Stepping the singleclzero(step = len - 9) on fallback cleanly lets the CPU runadd / cmp / jbnatively forend <= start, wrapping, and cross-region spans.insn.rs:125): Requiringi == 0(no prefixes at all before0F 01 FC) forClzeroLoopis slightly stricter than!code[..i].contains(&0x67)sincejb -12(72 F4) targetsrip + i.(AI-assisted)