cpu: lower 32-bit and 64-bit BMI1 bit-manipulation instructions #286

Manually merged
github merged 2 commits from gh-pr/286/head into gh-pr/286/base 2026-11-26 21:40:10 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 20:50 UTC · original
Vonsek:ag/cpu-lower-bmi1 → main · +425 −0 · 7 files · 2 commits · merged 2026-11-21 22:25 UTC

Change

  • Lower 32-bit and 64-bit BMI1 bit-manipulation instructions (andn, bextr, blsi, blsmsk, blsr, tzcnt) in tools/ffx_version_query.py, preserving zero-extending 32-bit writes and exact ZF/CF flag updates.
  • Add a source-built MASM fixture (tests/cpu/bmi1.asm, tests/cpu/bmi1.def) and differential test (tests/cpu/bmi1.py) wired into CMakeLists.txt as cpu_aot_bmi1, checking all 12 exports (32-bit and 64-bit) for both values and observed ZF/CF flags plus a 16-bit tzcnt rejection control.
  • Classify bmi1 -> cpu_aot_bmi1 in tools/form_coverage.py (raising BMI/ADX x64 Zen 2 form coverage from 0/16 to 6/16) 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_bmi1_lifted failed with:
    ValueError: unsupported query operation at 0x1007: andn eax,ecx,edx
    
  • After the change:
    • cmake --build --preset dev --target cpu_bmi1_lifted succeeded.
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_bmi1|cpu_aot_shift_count|cpu_aot_version_query|cpu_aot_address_size)$" -V: 4/4 passed (1054 binary and 136 unary BMI1 cases (values + ZF/CF) matched native and translated DLLs).
    • python -B tests/form_coverage_check.py: form coverage checks passed.

Evidence and follow-up

  • Covers all six BMI1 mnemonics (andn, bextr, blsi, blsmsk, blsr, tzcnt) in docs/coverage/x64_zen2.tsv; BMI2 (bzhi, mulx, pdep, pext, rorx, sarx, shlx, shrx) and ADX (adcx, adox) can follow in separate focused PRs.
  • 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:50 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/286) `Vonsek:ag/cpu-lower-bmi1` → `main` · +425 −0 · 7 files · 2 commits · merged 2026-11-21 22:25 UTC ## Change - Lower 32-bit and 64-bit BMI1 bit-manipulation instructions (`andn`, `bextr`, `blsi`, `blsmsk`, `blsr`, `tzcnt`) in `tools/ffx_version_query.py`, preserving zero-extending 32-bit writes and exact ZF/CF flag updates. - Add a source-built MASM fixture (`tests/cpu/bmi1.asm`, `tests/cpu/bmi1.def`) and differential test (`tests/cpu/bmi1.py`) wired into `CMakeLists.txt` as `cpu_aot_bmi1`, checking all 12 exports (32-bit and 64-bit) for both values and observed ZF/CF flags plus a 16-bit `tzcnt` rejection control. - Classify `bmi1` -> `cpu_aot_bmi1` in `tools/form_coverage.py` (raising BMI/ADX x64 Zen 2 form coverage from 0/16 to 6/16) 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_bmi1_lifted` failed with: ```text ValueError: unsupported query operation at 0x1007: andn eax,ecx,edx ``` - After the change: - `cmake --build --preset dev --target cpu_bmi1_lifted` succeeded. - `ctest --preset dev --no-tests=error -R "^(cpu_aot_bmi1|cpu_aot_shift_count|cpu_aot_version_query|cpu_aot_address_size)$" -V`: 4/4 passed (`1054 binary and 136 unary BMI1 cases (values + ZF/CF) matched native and translated DLLs`). - `python -B tests/form_coverage_check.py`: `form coverage checks passed`. ## Evidence and follow-up - Covers all six BMI1 mnemonics (`andn`, `bextr`, `blsi`, `blsmsk`, `blsr`, `tzcnt`) in `docs/coverage/x64_zen2.tsv`; BMI2 (`bzhi`, `mulx`, `pdep`, `pext`, `rorx`, `sarx`, `shlx`, `shrx`) and ADX (`adcx`, `adox`) can follow in separate focused PRs. - 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 the six BMI1 instructions (andn,
bextr, blsi, blsmsk, blsr, tzcnt) in tools/ffx_version_query.py,
including zero-extending 32-bit writes and ZF/CF flag semantics.

Add a source-built MASM differential fixture (tests/cpu/bmi1.asm,
tests/cpu/bmi1.def, tests/cpu/bmi1.py) registered as cpu_aot_bmi1 in
CMakeLists.txt and classified in tools/form_coverage.py, and document
it in docs/experiments.md.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:40:08 +00:00
github manually merged commit 1473e1eb91 into gh-pr/286/base 2026-11-26 21:40:10 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 20:53 UTC · original · edited 2026-11-21 20:56 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-21T20:56:44.672313Z 1c2755c 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 20:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/286#issuecomment-7069082617) · edited 2026-11-21 20:56 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"1c2755c6f55cd82b41b0bc98065ffea762bd85d3","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-21T20:56:44.672313Z">2026-11-21T20:56:44.672313Z</relative-time> | `1c2755c` | 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

@⁠R0Y00 on GitHub · 2026-11-21 20:56 UTC · original

The new CTest invokes native BMI1 exports unconditionally. BMI1 is optional on supported x64 Windows hosts, so an older CPU can fault before producing a comparison. Please check CPUID BMI1 before calling the native fixture and register a capability skip for unsupported hosts. Preserve the differential and 16-bit rejection controls on BMI1-capable machines.

**@⁠R0Y00** on GitHub · 2026-11-21 20:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/286#issuecomment-7069112833) The new CTest invokes native BMI1 exports unconditionally. BMI1 is optional on supported x64 Windows hosts, so an older CPU can fault before producing a comparison. Please check CPUID BMI1 before calling the native fixture and register a capability skip for unsupported hosts. Preserve the differential and 16-bit rejection controls on BMI1-capable machines.
Author
Owner

@⁠Vonsek on GitHub · 2026-11-21 22:12 UTC · original

Added a host_has_bmi1() CPUID leaf 7 EBX bit 3 check in the portable lifted DLL before loading/invoking the native BMI1 fixture, exiting 77 when BMI1 is absent, and registered SKIP_RETURN_CODE 77 on cpu_aot_bmi1 in CMakeLists.txt. Differential and 16-bit rejection controls remain unchanged on BMI1-capable hosts.

**@⁠Vonsek** on GitHub · 2026-11-21 22:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/286#issuecomment-7070022071) Added a `host_has_bmi1()` CPUID leaf 7 EBX bit 3 check in the portable lifted DLL before loading/invoking the native BMI1 fixture, exiting 77 when BMI1 is absent, and registered `SKIP_RETURN_CODE 77` on `cpu_aot_bmi1` in `CMakeLists.txt`. Differential and 16-bit rejection controls remain unchanged on BMI1-capable hosts.
This discussion has been locked. Commenting is limited to contributors.
No description provided.