cpu: lower CLZERO in counted x64 loops #1230

Manually merged
github merged 1 commit from gh-pr/1230/head into gh-pr/1230/base 2026-11-26 22:50:45 +00:00
Owner

@⁠R0Y00 on GitHub · 2026-11-24 04:32 UTC · original
R0Y00:codex/static-clzero-loops → main · +134 −1 · 7 files · 1 commits · merged 2026-11-24 04:40 UTC

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.

. ./tools/dev.ps1
cmake --preset release -DCMAKE_TRY_COMPILE_CONFIGURATION=Release
cmake --build --preset release --target cpu_clzero_lifted
ctest --preset release --no-tests=error -R '^cpu_counted_clzero$' -V

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.

**@⁠R0Y00** on GitHub · 2026-11-24 04:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1230) `R0Y00:codex/static-clzero-loops` → `main` · +134 −1 · 7 files · 1 commits · merged 2026-11-24 04:40 UTC 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. ```powershell . ./tools/dev.ps1 cmake --preset release -DCMAKE_TRY_COMPILE_CONFIGURATION=Release cmake --build --preset release --target cpu_clzero_lifted ctest --preset release --no-tests=error -R '^cpu_counted_clzero$' -V ``` 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:50:44 +00:00
github manually merged commit f39021c6c2 into gh-pr/1230/base 2026-11-26 22:50:45 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 04:38 UTC · original · reviewed

Reviewed commit f39021c6 on Linux (x86_64, Python 3.12 with iced-x86 and pefile). 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: adds Mnemonic.CLZERO to FLAG_NEUTRAL, rejects ins.len != 3 (address-size override 67h / prefixes), requires defined 64-bit RAX (self.reg(R.RAX) with {R.RAX: 8} read, {} write), aligns down with ({address} & ~63ull), and emits a 64-byte volatile unsigned char* zeroing loop without modifying RAX or flags.
  • tests/cpu/counted_clzero.{asm,def,py}: tests 6 aligned/unaligned/equal/reversed/multi-line bounds against reference_counted and 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.md and docs/experiments.md are 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 failed
  • Inline tools/cpu_switch_aot.py + iced_x86 check (0f 01 fc len 3, 67 0f 01 fc len 4, Mnemonic.CLZERO in FLAG_NEUTRAL): passed
  • git diff --check HEAD~1..HEAD: passed
**@⁠tedin7** on GitHub · 2026-11-24 04:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1230#pullrequestreview-6033725304) · **reviewed** Reviewed commit `f39021c6` on Linux (`x86_64`, Python 3.12 with `iced-x86` and `pefile`). 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`: adds `Mnemonic.CLZERO` to `FLAG_NEUTRAL`, rejects `ins.len != 3` (address-size override `67h` / prefixes), requires defined 64-bit `RAX` (`self.reg(R.RAX)` with `{R.RAX: 8}` read, `{}` write), aligns down with `({address} & ~63ull)`, and emits a 64-byte `volatile unsigned char*` zeroing loop without modifying `RAX` or flags. - `tests/cpu/counted_clzero.{asm,def,py}`: tests 6 aligned/unaligned/equal/reversed/multi-line bounds against `reference_counted` and 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.md` and `docs/experiments.md` are 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 failed - Inline `tools/cpu_switch_aot.py` + `iced_x86` check (`0f 01 fc` len 3, `67 0f 01 fc` len 4, `Mnemonic.CLZERO in FLAG_NEUTRAL`): passed - `git diff --check HEAD~1..HEAD`: passed
This discussion has been locked. Commenting is limited to contributors.
No description provided.