cpu: lower AVX conversions, compares, flag tests, and aligned/streaming moves #393

Manually merged
github merged 5 commits from gh-pr/393/head into gh-pr/393/base 2026-11-26 21:48:24 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-22 00:13 UTC · original
Vonsek:ag/cpu-lower-avx-cvt-cmp-test → main · +603 −11 · 8 files · 5 commits · merged 2026-11-23 19:07 UTC

Change

  • Lower 28 VEX 128-bit and 256-bit AVX conversion, compare, flag-test, and aligned/streaming move instructions in tools/ffx_version_query.py:
    • Packed conversions: vcvtdq2ps, vcvtdq2pd, vcvtps2dq, vcvtpd2dq, vcvttps2dq, vcvttpd2dq, vcvtps2pd, vcvtpd2ps
    • Scalar conversions: vcvtsi2ss, vcvtsi2sd, vcvtss2sd, vcvtsd2ss, vcvtss2si, vcvttss2si, vcvtsd2si, vcvttsd2si (with 32-bit and 64-bit integer-indefinite clamping)
    • Packed and scalar FP compares (all 32 AVX predicate encodings): vcmpps, vcmppd, vcmpss, vcmpsd
    • Vector flag tests (updating ZF and CF): vptest, vtestps, vtestpd
    • Aligned and streaming moves: vmovaps, vmovapd, vmovdqa, vlddqu, vmovntdqa
  • Restrict lowering to EncodingKind.VEX (rejecting EVEX encodings) and zero upper YMM bytes for 128-bit XMM destinations.
  • Probe CPUID leaf 1 ECX bits 27 (OSXSAVE) and 28 (AVX) plus XCR0 XMM/YMM state before invoking the native fixture (exiting 77 with SKIP_RETURN_CODE 77 on hosts without AVX).
  • Add source-built MASM differential fixture tests/cpu/avx_cvt_cmp_test.{asm,def,py}, CMake target cpu_avx_cvt_cmp_test_lifted, CTest cpu_aot_avx_cvt_cmp_test, coverage mapping in tools/form_coverage.py, and documentation in docs/experiments.md.

Verification

  • Confirmed pre-fix failure on cmake --build --preset dev --target cpu_avx_cvt_cmp_test_lifted:
    ValueError: unsupported query operation at 0x1000: vmovdqa ymm1,ymmword ptr [rcx]
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_avx_cvt_cmp_test_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_cvt_cmp_test|cpu_aot_bmi1)$" -V: 2/2 passed (33 AVX conversion/compare/test/move cases matched native and translated DLLs + EVEX vcvtdq2ps rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • Covers 28 AVX-grouped mnemonics in docs/coverage/x64_zen2.tsv using source-built fixtures, gated by a runtime CPUID/XCR0 check.
**@⁠Vonsek** on GitHub · 2026-11-22 00:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/393) `Vonsek:ag/cpu-lower-avx-cvt-cmp-test` → `main` · +603 −11 · 8 files · 5 commits · merged 2026-11-23 19:07 UTC ## Change - Lower 28 VEX 128-bit and 256-bit AVX conversion, compare, flag-test, and aligned/streaming move instructions in `tools/ffx_version_query.py`: - Packed conversions: `vcvtdq2ps`, `vcvtdq2pd`, `vcvtps2dq`, `vcvtpd2dq`, `vcvttps2dq`, `vcvttpd2dq`, `vcvtps2pd`, `vcvtpd2ps` - Scalar conversions: `vcvtsi2ss`, `vcvtsi2sd`, `vcvtss2sd`, `vcvtsd2ss`, `vcvtss2si`, `vcvttss2si`, `vcvtsd2si`, `vcvttsd2si` (with 32-bit and 64-bit integer-indefinite clamping) - Packed and scalar FP compares (all 32 AVX predicate encodings): `vcmpps`, `vcmppd`, `vcmpss`, `vcmpsd` - Vector flag tests (updating ZF and CF): `vptest`, `vtestps`, `vtestpd` - Aligned and streaming moves: `vmovaps`, `vmovapd`, `vmovdqa`, `vlddqu`, `vmovntdqa` - Restrict lowering to `EncodingKind.VEX` (rejecting EVEX encodings) and zero upper YMM bytes for 128-bit XMM destinations. - Probe CPUID leaf 1 ECX bits 27 (`OSXSAVE`) and 28 (`AVX`) plus XCR0 XMM/YMM state before invoking the native fixture (exiting 77 with `SKIP_RETURN_CODE 77` on hosts without AVX). - Add source-built MASM differential fixture `tests/cpu/avx_cvt_cmp_test.{asm,def,py}`, CMake target `cpu_avx_cvt_cmp_test_lifted`, CTest `cpu_aot_avx_cvt_cmp_test`, coverage mapping in `tools/form_coverage.py`, and documentation in `docs/experiments.md`. ## Verification - Confirmed pre-fix failure on `cmake --build --preset dev --target cpu_avx_cvt_cmp_test_lifted`: `ValueError: unsupported query operation at 0x1000: vmovdqa ymm1,ymmword ptr [rcx]` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_avx_cvt_cmp_test_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_cvt_cmp_test|cpu_aot_bmi1)$" -V`: 2/2 passed (`33 AVX conversion/compare/test/move cases matched native and translated DLLs` + EVEX `vcvtdq2ps` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - Covers 28 `AVX`-grouped mnemonics in `docs/coverage/x64_zen2.tsv` using source-built fixtures, gated by a runtime CPUID/XCR0 check.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:48:23 +00:00
github manually merged commit cc926a618a into gh-pr/393/base 2026-11-26 21:48:24 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:19 UTC · original · edited 2026-11-22 00:25 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-22T00:25:34.712146Z eb126f7 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-22 00:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/393#issuecomment-7071473656) · edited 2026-11-22 00:25 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"eb126f7db1e109b0050dbf59f0bd22ea4621a8bf","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-22T00:25:34.712146Z">2026-11-22T00:25:34.712146Z</relative-time> | `eb126f7` | 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

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

P2 Badge Honor MXCSR rounding for non-truncating conversions

When the caller selects a non-default MXCSR rounding mode, this helper still rounds every non-truncating conversion to nearest/even. In a standalone Linux/x64 check using this header, round-toward-zero made native vcvtsd2si convert 1.75 to 1, while cvt_to_i32 and cvt_to_i64 returned 2. The same helper backs vcvtps2dq, vcvtpd2dq, vcvtss2si, and vcvtsd2si, so these instructions silently produce incorrect numeric results outside the default rounding mode. Honor MXCSR.RC and add differential cases for the other rounding modes.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/393#discussion_r4655753312) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Honor MXCSR rounding for non-truncating conversions** When the caller selects a non-default MXCSR rounding mode, this helper still rounds every non-truncating conversion to nearest/even. In a standalone Linux/x64 check using this header, round-toward-zero made native `vcvtsd2si` convert `1.75` to `1`, while `cvt_to_i32` and `cvt_to_i64` returned `2`. The same helper backs `vcvtps2dq`, `vcvtpd2dq`, `vcvtss2si`, and `vcvtsd2si`, so these instructions silently produce incorrect numeric results outside the default rounding mode. Honor MXCSR.RC and add differential cases for the other rounding modes. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

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

P2 Badge Preserve the signaling distinction in AVX compare predicates

For NaN operands, predicate bit 4 distinguishes quiet and signaling comparisons even when their result masks are identical. For example, vcmpps with immediate 31 (TRUE_US) must set MXCSR's invalid-operation status and raise an exception if it is unmasked, but masking with 15 selects the literal true, so the generated code performs no floating-point comparison. A standalone Linux/x64 check with quiet NaNs produced native exception status 0x01 versus lowered status 0x00, despite matching result masks. Preserve the signaling behavior, or reject predicates whose exception semantics are not implemented.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/393#discussion_r4655753316) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve the signaling distinction in AVX compare predicates** For NaN operands, predicate bit 4 distinguishes quiet and signaling comparisons even when their result masks are identical. For example, `vcmpps` with immediate 31 (`TRUE_US`) must set MXCSR's invalid-operation status and raise an exception if it is unmasked, but masking with 15 selects the literal `true`, so the generated code performs no floating-point comparison. A standalone Linux/x64 check with quiet NaNs produced native exception status `0x01` versus lowered status `0x00`, despite matching result masks. Preserve the signaling behavior, or reject predicates whose exception semantics are not implemented. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 18:24 UTC · original

I updated this branch after #407 landed and kept both test fixtures. The conversion paths use Windows intrinsics for MXCSR-controlled rounding, and the compare path uses all five predicate bits. The original vs generated fixture exercises all four rounding modes and verifies that the signaling predicate sets the masked invalid flag. The streaming VMOVNTDQA form stays outside this patch; the VLDDQU case remains covered.

On Windows with MSVC 19.51, the Release AVX conversion/compare, scalar FP, and shuffle/blend CTests all ran and passed (3/3). The branch is ready for Windows CI.

**@⁠R0Y00** on GitHub · 2026-11-23 18:24 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/393#issuecomment-7110125751) I updated this branch after #407 landed and kept both test fixtures. The conversion paths use Windows intrinsics for MXCSR-controlled rounding, and the compare path uses all five predicate bits. The original vs generated fixture exercises all four rounding modes and verifies that the signaling predicate sets the masked invalid flag. The streaming VMOVNTDQA form stays outside this patch; the VLDDQU case remains covered. On Windows with MSVC 19.51, the Release AVX conversion/compare, scalar FP, and shuffle/blend CTests all ran and passed (3/3). The branch is ready for Windows CI.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 18:40 UTC · original

The Windows failures were two stale rejection assertions. The original VEX.128 store now checks that its misalignment branch precedes the write, and the conversion test rejects a masked EVEX form while the new AVX fixture still compares supported YMM conversions against native execution. The unsupported legacy cases are still tested. All three affected Windows Release CTests now pass locally. The new head needs both Windows jobs again.

**@⁠R0Y00** on GitHub · 2026-11-23 18:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/393#issuecomment-7110501061) The Windows failures were two stale rejection assertions. The original VEX.128 store now checks that its misalignment branch precedes the write, and the conversion test rejects a masked EVEX form while the new AVX fixture still compares supported YMM conversions against native execution. The unsupported legacy cases are still tested. All three affected Windows Release CTests now pass locally. The new head needs both Windows jobs again.
Author
Owner

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb126f7db1

ℹ️ 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-22 00:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/393#pullrequestreview-6009165215) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `eb126f7db1` <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.