cpu: lower 32-bit and 64-bit ROL, ROR, SHLD, and SHRD instructions #291

Manually merged
github merged 3 commits from gh-pr/291/head into gh-pr/291/base 2026-11-26 21:40:36 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 20:58 UTC · original
Vonsek:ag/cpu-lower-rotates-shifts → main · +514 −0 · 7 files · 3 commits · merged 2026-11-22 02:38 UTC

Change

  • Lower 32-bit and 64-bit rol, ror, shld, and shrd with both immediate and cl counts in tools/ffx_version_query.py, preserving ZF/CF on zero masked counts while zero-extending 32-bit destinations.
  • Add a source-built MASM fixture (tests/cpu/rotates_shifts.asm, tests/cpu/rotates_shifts.def) and differential test (tests/cpu/rotates_shifts.py) wired into CMakeLists.txt as cpu_aot_rotates_shifts, verifying all 12 exports (values, 32-bit zero-extension, and ZF/CF flags) against both the native DLL and a reference model.
  • Classify rotates_shifts -> cpu_aot_rotates_shifts in tools/form_coverage.py (+4 Integer mnemonics in docs/coverage/x64_zen2.tsv) and document the test in docs/experiments.md.

Verification

Tested on Windows 11 (VS 2022 Build Tools 17.14, MSVC 19.44, ML64 14.44, Windows SDK 10.0.26100, Python 3.12):

  • Before the change, cmake --build --preset dev --target cpu_rotates_shifts_lifted failed with:
    ValueError: unsupported query operation at 0x1010: rol eax,cl
    
  • After the change:
    • cmake --build --preset dev --target cpu_rotates_shifts_lifted succeeded.
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_rotates_shifts|cpu_aot_shift_count|cpu_aot_version_query|cpu_aot_address_size)$" -V: 4/4 passed (2244 rotate and double-precision shift cases (ROL, ROR, SHLD, SHRD) matched native and translated DLLs).
    • python -B tests/form_coverage_check.py: form coverage checks passed.

Evidence and follow-up

  • Adds four uncovered x64 Integer mnemonics (rol, ror, shld, shrd) to docs/coverage/x64_zen2.tsv coverage.
  • All binaries are source-built via MASM and CMake; no game files or external dumps are included.

Checklist

  • Focused, single-purpose change
  • Source-built test that fails without the change and passes with it
  • Verified locally on Windows
**@⁠Vonsek** on GitHub · 2026-11-21 20:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/291) `Vonsek:ag/cpu-lower-rotates-shifts` → `main` · +514 −0 · 7 files · 3 commits · merged 2026-11-22 02:38 UTC ## Change - Lower 32-bit and 64-bit `rol`, `ror`, `shld`, and `shrd` with both immediate and `cl` counts in `tools/ffx_version_query.py`, preserving ZF/CF on zero masked counts while zero-extending 32-bit destinations. - Add a source-built MASM fixture (`tests/cpu/rotates_shifts.asm`, `tests/cpu/rotates_shifts.def`) and differential test (`tests/cpu/rotates_shifts.py`) wired into `CMakeLists.txt` as `cpu_aot_rotates_shifts`, verifying all 12 exports (values, 32-bit zero-extension, and ZF/CF flags) against both the native DLL and a reference model. - Classify `rotates_shifts` -> `cpu_aot_rotates_shifts` in `tools/form_coverage.py` (+4 Integer mnemonics in `docs/coverage/x64_zen2.tsv`) and document the test in `docs/experiments.md`. ## Verification Tested on Windows 11 (VS 2022 Build Tools 17.14, MSVC 19.44, ML64 14.44, Windows SDK 10.0.26100, Python 3.12): - Before the change, `cmake --build --preset dev --target cpu_rotates_shifts_lifted` failed with: ```text ValueError: unsupported query operation at 0x1010: rol eax,cl ``` - After the change: - `cmake --build --preset dev --target cpu_rotates_shifts_lifted` succeeded. - `ctest --preset dev --no-tests=error -R "^(cpu_aot_rotates_shifts|cpu_aot_shift_count|cpu_aot_version_query|cpu_aot_address_size)$" -V`: 4/4 passed (`2244 rotate and double-precision shift cases (ROL, ROR, SHLD, SHRD) matched native and translated DLLs`). - `python -B tests/form_coverage_check.py`: `form coverage checks passed`. ## Evidence and follow-up - Adds four uncovered x64 Integer mnemonics (`rol`, `ror`, `shld`, `shrd`) to `docs/coverage/x64_zen2.tsv` coverage. - All binaries are source-built via MASM and CMake; no game files or external dumps are included. ## Checklist - [x] Focused, single-purpose change - [x] Source-built test that fails without the change and passes with it - [x] Verified locally on Windows
Add 32-bit and 64-bit lowering for rol, ror, shld, and shrd with both
immediate and CL counts in tools/ffx_version_query.py, preserving flags
on zero masked counts while still zero-extending 32-bit destinations.

Add a source-built MASM differential fixture
(tests/cpu/rotates_shifts.asm, tests/cpu/rotates_shifts.def,
tests/cpu/rotates_shifts.py) registered as cpu_aot_rotates_shifts in
CMakeLists.txt, classified in tools/form_coverage.py, and documented in
docs/experiments.md.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:40:35 +00:00
github manually merged commit 44ef4d0e99 into gh-pr/291/base 2026-11-26 21:40:36 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 22:11 UTC · original · edited 2026-11-21 22:16 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T22:16:27.360042Z 302a100 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 22:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/291#issuecomment-7070008639) · edited 2026-11-21 22:16 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"302a10033934afe054d865eb2e9ef9b32afe84ef","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T22:16:27.360042Z">2026-11-21T22:16:27.360042Z</relative-time> | `302a100` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-21 23:01 UTC · original

A coverage note from reading the diff at d903b2c, without building it.

The description says a zero masked count preserves ZF and CF. Two gaps:

  • Immediate counts. The fixtures use 7, 19, 13 and 21 only, so no immediate masks to zero. shld eax, edx, 32 (0F A4 D0 20, which iced decodes with an 8-bit immediate) after cmp r10d, r10d would cover it: ZF = 1 and CF = 0 must survive, and RAX should match what the CL cases already expect for a zero count, the zero-extended EAX.
  • CL counts. All eight CL fixtures seed CF = 1, ZF = 0 with cmp r10d, 1. A lowering that forced those values on a zero masked count would still pass. A second seed, cmp r10d, r10d (ZF = 1, CF = 0), over the existing counts 0, 32 and 64 would separate the two.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-21 23:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/291#issuecomment-7070583630) A coverage note from reading the diff at `d903b2c`, without building it. The description says a zero masked count preserves ZF and CF. Two gaps: - **Immediate counts.** The fixtures use 7, 19, 13 and 21 only, so no immediate masks to zero. `shld eax, edx, 32` (`0F A4 D0 20`, which iced decodes with an 8-bit immediate) after `cmp r10d, r10d` would cover it: ZF = 1 and CF = 0 must survive, and RAX should match what the CL cases already expect for a zero count, the zero-extended EAX. - **CL counts.** All eight CL fixtures seed CF = 1, ZF = 0 with `cmp r10d, 1`. A lowering that forced those values on a zero masked count would still pass. A second seed, `cmp r10d, r10d` (ZF = 1, CF = 0), over the existing counts 0, 32 and 64 would separate the two. _AI-assisted._
Author
Owner

@⁠Vonsek on GitHub · 2026-11-21 23:07 UTC · original

Good catch — added shld32_imm32 (shld eax, edx, 32 after cmp r10d, r10d) plus rol32_cl_zf and shld32_cl_zf (seeded with ZF=1, CF=0 over counts 0, 32, and 64) to tests/cpu/rotates_shifts.asm and tests/cpu/rotates_shifts.py.

**@⁠Vonsek** on GitHub · 2026-11-21 23:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/291#issuecomment-7070655777) Good catch — added `shld32_imm32` (`shld eax, edx, 32` after `cmp r10d, r10d`) plus `rol32_cl_zf` and `shld32_cl_zf` (seeded with `ZF=1, CF=0` over counts 0, 32, and 64) to `tests/cpu/rotates_shifts.asm` and `tests/cpu/rotates_shifts.py`.
This discussion has been locked. Commenting is limited to contributors.
No description provided.