cpu: lower CLZERO in counted x64 loops #1223
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1230"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T04:32:20Z.
Refs #870.
Teach the shared x64 static lifter to lower the plain three-byte CLZERO through its normal exported-function entry. It requires a defined 64-bit RAX, rounds down to a 64-byte cache line, emits observable stores, and leaves the cursor and flags unchanged. Existing arithmetic and control flow implement the surrounding counted loop. The code uses no fixed executable addresses, image rewriter, profile lookup or exception handler.
The Windows Release test compares six range and alignment cases with an independently assembled integer-store reference and literal expected bytes. The 24 compact loop comparisons rotate the bound through RDX, R8, R9 and R10. Six additional instrumented comparisons check CF before/after CLZERO, the final equality/above results and the returned cursor. Negative controls reject address-size overrides and uninitialized RAX. The measured domain is single-threaded, writable ordinary memory.
Windows x64, Intel Core i9-14900HX, MSVC 19.51.36244, Release: 1/1 passed, zero skips. This fixture measures architectural results, not application frame rate.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:38:46Z.
Review: COMMENTED
Reviewed commit
f39021c6on Linux (x86_64, Python 3.12 withiced-x86andpefile). Windows build/tests (cpu_clzero_lifted,ctest --preset release --no-tests=error -R '^cpu_counted_clzero$' -V) were not run locally.Code & Spec Audit
tools/cpu_switch_aot.py: addsMnemonic.CLZEROtoFLAG_NEUTRAL, rejectsins.len != 3(address-size override67h/ prefixes), requires defined 64-bitRAX(self.reg(R.RAX)with{R.RAX: 8}read,{}write), aligns down with({address} & ~63ull), and emits a 64-bytevolatile unsigned char*zeroing loop without modifyingRAXor flags.tests/cpu/counted_clzero.{asm,def,py}: tests 6 aligned/unaligned/equal/reversed/multi-line bounds againstreference_countedand literal expected bytes/RAX/flags, 4 compact loop variants (loop_dx,loop_r8,loop_r9,loop_r10), and negative controls (prefix_addr32,unknown_rax).README.mdanddocs/experiments.mdare title-neutral and match the test scope.Checks Run Locally (Linux)
/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (self-test passed; 16 Markdown files, 278 links)/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (self-test passed; 1037 tracked files)/root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py: passed/root/.local/share/x2w-rev-venv/bin/python -B tests/hardware_reports_check.py: 12/12 passed, 0 skipped, 0 failed/root/.local/share/x2w-rev-venv/bin/python -B tests/gpu_report_format_check.py: 10/10 passed, 0 skipped, 0 failedtools/cpu_switch_aot.py+iced_x86check (0f 01 fclen 3,67 0f 01 fclen 4,Mnemonic.CLZERO in FLAG_NEUTRAL): passedgit diff --check HEAD~1..HEAD: passed