cpu: lower 32-bit and 64-bit ADX instructions (ADCX, ADOX) and SETO #335

Manually merged
github merged 6 commits from gh-pr/335/head into gh-pr/335/base 2026-11-26 21:43:57 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 22:33 UTC · original
Vonsek:ag/cpu-lower-adx → main · +469 −34 · 6 files · 6 commits · merged 2026-11-22 09:15 UTC

Change

  • Track the overflow flag (OF) alongside ZF and CF in tools/ffx_version_query.py and lower 32-bit and 64-bit adcx, adox, and seto, preserving OF across adcx and CF across adox with zero-extending 32-bit writes.
  • Add a source-built MASM fixture (tests/cpu/adx.asm, tests/cpu/adx.def) and differential test (tests/cpu/adx.py) wired into CMakeLists.txt as cpu_aot_adx with a host_has_adx() CPUID leaf 7 EBX bit 19 check and SKIP_RETURN_CODE 77 for hosts without ADX.
  • Verify all five exports (adcx32_op, adcx64_op, adox32_op, adox64_op, and interleaved dual-carry adx_dual64) across 1,093 cases against both the native DLL and a reference model.
  • Classify adx -> cpu_aot_adx in tools/form_coverage.py (+2 BMI/ADX mnemonics adcx/adox + seto) 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_adx_lifted failed with:
    ValueError: unsupported query operation at 0x100c: adcx eax,edx
    
  • After the change:
    • cmake --build --preset dev --target cpu_adx_lifted succeeded.
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_adx|cpu_aot_bmi1|cpu_aot_shift_count|cpu_aot_version_query|cpu_aot_address_size)$" -V: 5/5 passed (1093 ADX cases (ADCX, ADOX, and interleaved dual-carry chains) matched native and translated DLLs).
    • python -B tests/form_coverage_check.py: form coverage checks passed.

Evidence and follow-up

  • Completes the remaining two mnemonics (adcx, adox) of the 16-entry BMI/ADX group in docs/coverage/x64_zen2.tsv alongside #286 (BMI1, merged) and #287 (BMI2).
  • 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 22:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/335) `Vonsek:ag/cpu-lower-adx` → `main` · +469 −34 · 6 files · 6 commits · merged 2026-11-22 09:15 UTC ## Change - Track the overflow flag (`OF`) alongside `ZF` and `CF` in `tools/ffx_version_query.py` and lower 32-bit and 64-bit `adcx`, `adox`, and `seto`, preserving `OF` across `adcx` and `CF` across `adox` with zero-extending 32-bit writes. - Add a source-built MASM fixture (`tests/cpu/adx.asm`, `tests/cpu/adx.def`) and differential test (`tests/cpu/adx.py`) wired into `CMakeLists.txt` as `cpu_aot_adx` with a `host_has_adx()` CPUID leaf 7 EBX bit 19 check and `SKIP_RETURN_CODE 77` for hosts without ADX. - Verify all five exports (`adcx32_op`, `adcx64_op`, `adox32_op`, `adox64_op`, and interleaved dual-carry `adx_dual64`) across 1,093 cases against both the native DLL and a reference model. - Classify `adx` -> `cpu_aot_adx` in `tools/form_coverage.py` (+2 BMI/ADX mnemonics `adcx`/`adox` + `seto`) 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_adx_lifted` failed with: ```text ValueError: unsupported query operation at 0x100c: adcx eax,edx ``` - After the change: - `cmake --build --preset dev --target cpu_adx_lifted` succeeded. - `ctest --preset dev --no-tests=error -R "^(cpu_aot_adx|cpu_aot_bmi1|cpu_aot_shift_count|cpu_aot_version_query|cpu_aot_address_size)$" -V`: 5/5 passed (`1093 ADX cases (ADCX, ADOX, and interleaved dual-carry chains) matched native and translated DLLs`). - `python -B tests/form_coverage_check.py`: `form coverage checks passed`. ## Evidence and follow-up - Completes the remaining two mnemonics (`adcx`, `adox`) of the 16-entry `BMI/ADX` group in `docs/coverage/x64_zen2.tsv` alongside #286 (BMI1, merged) and #287 (BMI2). - 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
Track the overflow flag (OF) alongside ZF and CF in
tools/ffx_version_query.py and lower 32-bit and 64-bit adcx, adox, and
seto, preserving OF across adcx and CF across adox.

Add a source-built MASM differential fixture (tests/cpu/adx.asm,
tests/cpu/adx.def, tests/cpu/adx.py) with a CPUID leaf 7 EBX bit 19
(ADX) gate and SKIP_RETURN_CODE 77 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:43:56 +00:00
github manually merged commit 8b1243214e into gh-pr/335/base 2026-11-26 21:43:57 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 22:37 UTC · original · edited 2026-11-21 22:41 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:41:19.638028Z 9a45134 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:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/335#issuecomment-7070308995) · edited 2026-11-21 22:41 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"9a4513446170b56d97cf1164f58eeacedb8e90fd","has_any_findings":true,"has_unresolved_findings":true,"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:41:19.638028Z">2026-11-21T22:41:19.638028Z</relative-time> | `9a45134` | 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>
@ -629,2 +658,4 @@
M.SETAE: "!carry", M.SETB: "carry", M.SETBE: "carry || zero"}[op]
stmt = write(f"({cond})")
elif op == M.SETO:
stmt = write("overflow")
Author
Owner

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

P1 Badge Update OF in every supported instruction that defines it

When seto or adox follows an existing OF-writing instruction, it can consume stale overflow: the IMUL, one-bit shift, and BMI1 handlers never update that variable. A Linux x64 native-versus-generated-C++ check of mov eax, 0x40000000; shl eax, 1; seto al produced native AL=1 but lowered AL=0; feeding the same flag into adox also changed the sum. Update OF for IMUL, count-one shifts, and BMI1 forms that clear it, or reject those compositions rather than silently generating incorrect results. Add composition cases to the differential fixture so these producers are checked alongside the new consumers.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 22:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/335#discussion_r4655364444) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Update OF in every supported instruction that defines it** When `seto` or `adox` follows an existing OF-writing instruction, it can consume stale `overflow`: the `IMUL`, one-bit shift, and BMI1 handlers never update that variable. A Linux x64 native-versus-generated-C++ check of `mov eax, 0x40000000; shl eax, 1; seto al` produced native AL=1 but lowered AL=0; feeding the same flag into `adox` also changed the sum. Update OF for IMUL, count-one shifts, and BMI1 forms that clear it, or reject those compositions rather than silently generating incorrect results. Add composition cases to the differential fixture so these producers are checked alongside the new consumers. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

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

Updated overflow in IMUL, count-1 SHL/SHR/SAR, and the five OF-clearing BMI1 forms (ANDN, BEXTR, BLSI, BLSMSK, BLSR), and added shl1_adox32, imul_seto32, and andn_clears_of32 composition checks to tests/cpu/adx.asm and tests/cpu/adx.py.

**@⁠Vonsek** on GitHub · 2026-11-21 22:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/335#issuecomment-7070414072) Updated `overflow` in `IMUL`, count-1 `SHL`/`SHR`/`SAR`, and the five OF-clearing BMI1 forms (`ANDN`, `BEXTR`, `BLSI`, `BLSMSK`, `BLSR`), and added `shl1_adox32`, `imul_seto32`, and `andn_clears_of32` composition checks to `tests/cpu/adx.asm` and `tests/cpu/adx.py`.
Author
Owner

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a45134461

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 22:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/335#pullrequestreview-6008658739) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `9a45134461` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.