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

Merged
Vonsek merged 6 commits from upstream-pr/335 into main 2026-11-22 09:15:17 +00:00
Vonsek commented 2026-11-21 22:33:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T22:33:32Z.


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
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6535270623 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/335). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T22:33:32Z. --- ## 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
upstream-sync closed this pull request 2026-11-24 06:42:29 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:42:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T22:41:17Z.

Review: COMMENTED


💡 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6008658739 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/335#pullrequestreview-6008658739). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T22:41:17Z. **Review:** COMMENTED --- <!-- 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>
chatgpt-codex-connector[bot commented 2026-11-24 06:48:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T22:37:16Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070308995 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/335#issuecomment-7070308995). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T22:37:16Z. --- <!-- 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>
Vonsek commented 2026-11-24 06:48:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T22:46:15Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070414072 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/335#issuecomment-7070414072). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T22:46:15Z. --- 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`.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T22:41:17Z.

Code review location: tools/ffx_version_query.py; line 256

@@ -234,6 +252,8 @@ def write(expr):
             stmt = ";"
         elif op == M.SETE:
             stmt = write("zero")
+        elif op == M.SETO:
+            stmt = write("overflow")

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4655364444 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/335#discussion_r4655364444). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T22:41:17Z. **Code review location:** `tools/ffx_version_query.py`; line 256 ~~~~diff @@ -234,6 +252,8 @@ def write(expr): stmt = ";" elif op == M.SETE: stmt = write("zero") + elif op == M.SETO: + stmt = write("overflow") ~~~~ --- **<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 -->
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!330
No description provided.