cpu: lift ROL and ROR in cpu_switch_aot.py #778

Merged
Ammmae0x merged 1 commit from upstream-pr/784 into main 2026-11-23 03:45:57 +00:00
Ammmae0x commented 2026-11-23 03:09:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T03:09:19Z.


Change

Add ROL and ROR lifting in tools/cpu_switch_aot.py via a shared rotate_bits<T> helper in PRELUDE, register the cpu_switch_rotates MASM fixture and cpu_aot_switch_rotates CTest in CMakeLists.txt, and document the behavior and reproduction commands in docs/experiments.md.

  • tools/cpu_switch_aot.py:
    • Add ROTATES = {M.ROL: "true", M.ROR: "false"} and rotate_bits<T>(T value, word count, bool left) in PRELUDE, masking count to bits - 1 (with shift == 0 returning value unchanged to avoid undefined shifts) and preserving x64 32-bit zero-extension and 8-/16-bit upper-byte preservation via self.write(...).
    • Keep ROL and ROR out of FLAG_NEUTRAL and FLAG_PRODUCERS, and reject sets_flags=True with unsupported flag producer.
  • tests/cpu/switch_rotates.asm, tests/cpu/switch_rotates.def, tests/cpu/switch_rotates_check.py:
    • Source-owned MASM fixture and differential test covering 8-, 16-, 32-, and 64-bit register and memory operands, 1 / imm8 / CL counts, count 0, counts >= width * 8, upper-byte preservation, single load_always<T> memory read per instruction, a narrow 1-byte return, and 12 rejection controls (10 whole-PE controls + 2 direct Lifter().lower(..., sets_flags=True) checks).
  • CMakeLists.txt, docs/experiments.md:
    • Register cpu_switch_rotates and cpu_aot_switch_rotates and document the measured fixture counts and commands.

Verification

Commit tested: d5cc461 (clean rebuild and test runs on Windows x64, VS 2026 / MSVC 14.50).

  • Configure (& .\tools\dev.ps1):
    • cmake --preset dev -> configured cleanly
    • cmake --preset release -> configured cleanly
  • Clean rebuild of cpu_switch_rotates, cpu_switch_rotates_lifted, cpu_register_probe:
    • cmake --build --preset dev --target cpu_switch_rotates cpu_switch_rotates_lifted cpu_register_probe (after clearing cpu_switch_rotates* build outputs) -> 0 errors, 0 warnings
    • cmake --build --preset release --target cpu_switch_rotates cpu_switch_rotates_lifted cpu_register_probe (after clearing cpu_switch_rotates* build outputs) -> 0 errors, 0 warnings
  • CTest (dev and release presets):
    • ctest --preset dev --no-tests=error -R "^cpu_aot_(switch_.*|sse_.*)$" -V -> 3/3 passed (cpu_aot_switch_strings, cpu_aot_switch_addr32, cpu_aot_switch_rotates: 8,363 differential comparisons + 12 rejection controls passed, 0 skipped)
    • ctest --preset release --no-tests=error -R "^cpu_aot_(switch_.*|sse_.*)$" -V -> 3/3 passed (8,363 differential comparisons + 12 rejection controls passed, 0 skipped)
    • ctest --preset dev --no-tests=error -R "^cpu_aot_(switch_|sse)" -> 9/9 passed
    • ctest --preset release --no-tests=error -R "^cpu_aot_(switch_|sse)" -> 9/9 passed
    • ctest --preset dev --no-tests=error -R "rotate|flag_conditions" -> 4/4 passed (cpu_aot_flag_conditions, cpu_aot_switch_rotates, cpu_aot_carry_rotates, cpu_aot_rotates_shifts)
    • ctest --preset release --no-tests=error -R "rotate|flag_conditions" -> 4/4 passed
  • Pure-Python checks:
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py -> form coverage checks passed
    • .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py -> Checked 13 Markdown files and 146 links.
    • .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py -> Checked 631 tracked source, script and build/CI files: no bidirectional controls.

Evidence and follow-up

  • tests/cpu/switch_rotates.asm is an original source-owned MASM fixture in this repository (MIT License), annotated with ; coverage: source cpu_aot_switch_rotates.
  • Rotate flag production (CF/OF on ROL/ROR) and RCL/RCR remain out of scope for cpu_switch_aot.py; any flag consumer (Jcc, SETcc, CMOVcc) reading flags across or from ROL/ROR is rejected.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6551441467 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/784). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-23T03:09:19Z. --- ## Change Add `ROL` and `ROR` lifting in `tools/cpu_switch_aot.py` via a shared `rotate_bits<T>` helper in `PRELUDE`, register the `cpu_switch_rotates` MASM fixture and `cpu_aot_switch_rotates` CTest in `CMakeLists.txt`, and document the behavior and reproduction commands in `docs/experiments.md`. - `tools/cpu_switch_aot.py`: - Add `ROTATES = {M.ROL: "true", M.ROR: "false"}` and `rotate_bits<T>(T value, word count, bool left)` in `PRELUDE`, masking `count` to `bits - 1` (with `shift == 0` returning `value` unchanged to avoid undefined shifts) and preserving x64 32-bit zero-extension and 8-/16-bit upper-byte preservation via `self.write(...)`. - Keep `ROL` and `ROR` out of `FLAG_NEUTRAL` and `FLAG_PRODUCERS`, and reject `sets_flags=True` with `unsupported flag producer`. - `tests/cpu/switch_rotates.asm`, `tests/cpu/switch_rotates.def`, `tests/cpu/switch_rotates_check.py`: - Source-owned MASM fixture and differential test covering 8-, 16-, 32-, and 64-bit register and memory operands, `1` / `imm8` / `CL` counts, count `0`, counts `>= width * 8`, upper-byte preservation, single `load_always<T>` memory read per instruction, a narrow 1-byte return, and 12 rejection controls (10 whole-PE controls + 2 direct `Lifter().lower(..., sets_flags=True)` checks). - `CMakeLists.txt`, `docs/experiments.md`: - Register `cpu_switch_rotates` and `cpu_aot_switch_rotates` and document the measured fixture counts and commands. ## Verification Commit tested: `d5cc461` (clean rebuild and test runs on Windows x64, VS 2026 / MSVC 14.50). - Configure (`& .\tools\dev.ps1`): - `cmake --preset dev` -> configured cleanly - `cmake --preset release` -> configured cleanly - Clean rebuild of `cpu_switch_rotates`, `cpu_switch_rotates_lifted`, `cpu_register_probe`: - `cmake --build --preset dev --target cpu_switch_rotates cpu_switch_rotates_lifted cpu_register_probe` (after clearing `cpu_switch_rotates*` build outputs) -> 0 errors, 0 warnings - `cmake --build --preset release --target cpu_switch_rotates cpu_switch_rotates_lifted cpu_register_probe` (after clearing `cpu_switch_rotates*` build outputs) -> 0 errors, 0 warnings - CTest (`dev` and `release` presets): - `ctest --preset dev --no-tests=error -R "^cpu_aot_(switch_.*|sse_.*)$" -V` -> 3/3 passed (`cpu_aot_switch_strings`, `cpu_aot_switch_addr32`, `cpu_aot_switch_rotates`: 8,363 differential comparisons + 12 rejection controls passed, 0 skipped) - `ctest --preset release --no-tests=error -R "^cpu_aot_(switch_.*|sse_.*)$" -V` -> 3/3 passed (8,363 differential comparisons + 12 rejection controls passed, 0 skipped) - `ctest --preset dev --no-tests=error -R "^cpu_aot_(switch_|sse)"` -> 9/9 passed - `ctest --preset release --no-tests=error -R "^cpu_aot_(switch_|sse)"` -> 9/9 passed - `ctest --preset dev --no-tests=error -R "rotate|flag_conditions"` -> 4/4 passed (`cpu_aot_flag_conditions`, `cpu_aot_switch_rotates`, `cpu_aot_carry_rotates`, `cpu_aot_rotates_shifts`) - `ctest --preset release --no-tests=error -R "rotate|flag_conditions"` -> 4/4 passed - Pure-Python checks: - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py` -> `form coverage checks passed` - `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py` -> `Checked 13 Markdown files and 146 links.` - `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py` -> `Checked 631 tracked source, script and build/CI files: no bidirectional controls.` ## Evidence and follow-up - `tests/cpu/switch_rotates.asm` is an original source-owned MASM fixture in this repository (MIT License), annotated with `; coverage: source cpu_aot_switch_rotates`. - Rotate flag production (`CF`/`OF` on `ROL`/`ROR`) and `RCL`/`RCR` remain out of scope for `cpu_switch_aot.py`; any flag consumer (`Jcc`, `SETcc`, `CMOVcc`) reading flags across or from `ROL`/`ROR` is rejected. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:44:46 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!778
No description provided.