cpu: lower VEX.256 packed single-precision min and max #387

Manually merged
github merged 6 commits from gh-pr/387/head into gh-pr/387/base 2026-11-26 21:47:54 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-22 00:04 UTC · original
Vonsek:ag/cpu-lower-avx-packed-fp → main · +178 −0 · 6 files · 6 commits · merged 2026-11-23 15:42 UTC

Change

  • Lower 31 VEX 128-bit and 256-bit AVX packed floating-point instructions in tools/ffx_version_query.py:
    • Move: vmovupd
    • Arithmetic and square root: vaddps, vsubps, vmulps, vdivps, vsqrtps, vminps, vmaxps, vaddpd, vsubpd, vmulpd, vdivpd, vsqrtpd, vminpd, vmaxpd
    • Bitwise: vandps, vandnps, vorps, vxorps, vandpd, vandnpd, vorpd, vxorpd
    • Horizontal / alternating: vaddsubps, vhaddps, vhsubps, vaddsubpd, vhaddpd, vhsubpd
    • Sign masks: vmovmskps, vmovmskpd
  • 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_packed_fp.{asm,def,py}, CMake target cpu_avx_packed_fp_lifted, CTest cpu_aot_avx_packed_fp, 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_packed_fp_lifted:
    ValueError: unsupported query operation at 0x1008: vaddps ymm0,ymm1,ymm2
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_avx_packed_fp_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_packed_fp|cpu_aot_bmi1)$" -V: 2/2 passed (30 AVX 256-bit packed FP cases matched native and translated DLLs + EVEX vaddps rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • Covers 31 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:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/387) `Vonsek:ag/cpu-lower-avx-packed-fp` → `main` · +178 −0 · 6 files · 6 commits · merged 2026-11-23 15:42 UTC ## Change - Lower 31 VEX 128-bit and 256-bit AVX packed floating-point instructions in `tools/ffx_version_query.py`: - Move: `vmovupd` - Arithmetic and square root: `vaddps`, `vsubps`, `vmulps`, `vdivps`, `vsqrtps`, `vminps`, `vmaxps`, `vaddpd`, `vsubpd`, `vmulpd`, `vdivpd`, `vsqrtpd`, `vminpd`, `vmaxpd` - Bitwise: `vandps`, `vandnps`, `vorps`, `vxorps`, `vandpd`, `vandnpd`, `vorpd`, `vxorpd` - Horizontal / alternating: `vaddsubps`, `vhaddps`, `vhsubps`, `vaddsubpd`, `vhaddpd`, `vhsubpd` - Sign masks: `vmovmskps`, `vmovmskpd` - 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_packed_fp.{asm,def,py}`, CMake target `cpu_avx_packed_fp_lifted`, CTest `cpu_aot_avx_packed_fp`, 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_packed_fp_lifted`: `ValueError: unsupported query operation at 0x1008: vaddps ymm0,ymm1,ymm2` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_avx_packed_fp_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_packed_fp|cpu_aot_bmi1)$" -V`: 2/2 passed (`30 AVX 256-bit packed FP cases matched native and translated DLLs` + EVEX `vaddps` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - Covers 31 `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:47:53 +00:00
github manually merged commit cedf64fe07 into gh-pr/387/base 2026-11-26 21:47:54 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:07 UTC · original · edited 2026-11-22 00:15 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:15:19.462489Z adbc413 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:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/387#issuecomment-7071331111) · edited 2026-11-22 00:15 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"adbc413a36376099f6d311b69d738ae44aaf05aa","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:15:19.462489Z">2026-11-22T00:15:19.462489Z</relative-time> | `adbc413` | 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:15 UTC · original

P2 Badge Honor DAZ when lowering packed min/max

When the caller enables MXCSR.DAZ, these comparisons treat subnormal inputs as zero, but the subsequent selection and memcpy retain the original subnormal bits. Native VMIN/VMAX also apply DAZ to the returned operand: with MXCSR 0x1fc0, lhs +0.0f, and rhs bits 0x00000001, native vminps returns 0x00000000, while the generated loop returns 0x00000001. This mismatch reproduces with the emitted lowering compiled unoptimized using GCC 13 and Clang 17 on x86-64 Linux, and affects both PS/PD and both vector widths. Use min/max intrinsics that preserve the instruction semantics, or explicitly normalize operands according to MXCSR, and add a DAZ-enabled differential case.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/387#discussion_r4655716347) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Honor DAZ when lowering packed min/max** When the caller enables MXCSR.DAZ, these comparisons treat subnormal inputs as zero, but the subsequent selection and `memcpy` retain the original subnormal bits. Native VMIN/VMAX also apply DAZ to the returned operand: with MXCSR `0x1fc0`, lhs `+0.0f`, and rhs bits `0x00000001`, native `vminps` returns `0x00000000`, while the generated loop returns `0x00000001`. This mismatch reproduces with the emitted lowering compiled unoptimized using GCC 13 and Clang 17 on x86-64 Linux, and affects both PS/PD and both vector widths. Use min/max intrinsics that preserve the instruction semantics, or explicitly normalize operands according to MXCSR, and add a DAZ-enabled differential case. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 08:20 UTC · original

I assembled the original MASM fixtures from this PR and #382 and tested their exports through cpu_switch_aot.translate_pe at d2ac415. The shared entry rejected all 30 exports here and all 22 in #382. That leaves both sets of fixtures useful. Please start this queue with a narrow packed-min/max slice for #387, using the shared lowering and a native bit comparison for one width. Include the DAZ-on subnormal second-operand case from the existing review and both operand orders. The aligned SSE moves and the broader #382 conversion set can keep their own review.

**@⁠R0Y00** on GitHub · 2026-11-23 08:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/387#issuecomment-7095326054) I assembled the original MASM fixtures from this PR and #382 and tested their exports through `cpu_switch_aot.translate_pe` at `d2ac415`. The shared entry rejected all 30 exports here and all 22 in #382. That leaves both sets of fixtures useful. Please start this queue with a narrow packed-min/max slice for #387, using the shared lowering and a native bit comparison for one width. Include the DAZ-on subnormal second-operand case from the existing review and both operand orders. The aligned SSE moves and the broader #382 conversion set can keep their own review.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 14:45 UTC · original

Independent Windows result on an i9-14900HX with MSVC 19.51 /Od and /O2: the source-built 256-bit VMINPS/VMAXPS returned 0x00000000 for (+0, 0x00000001) with MXCSR 0x1fc0, while the scalar conditional returned 0x00000001. Reversing the operands returned zero in both. Across 64 output words per build (both operations, both orders, DAZ on/off, signed subnormals, zeros and distinct qNaNs), the conditional differed in 10 words. Two 128-bit MINPS/MAXPS intrinsics applied in source order matched all 64. That gives us a Windows oracle for the packed single-precision min/max slice.

**@⁠R0Y00** on GitHub · 2026-11-23 14:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/387#issuecomment-7104479281) Independent Windows result on an i9-14900HX with MSVC 19.51 /Od and /O2: the source-built 256-bit VMINPS/VMAXPS returned 0x00000000 for (+0, 0x00000001) with MXCSR 0x1fc0, while the scalar conditional returned 0x00000001. Reversing the operands returned zero in both. Across 64 output words per build (both operations, both orders, DAZ on/off, signed subnormals, zeros and distinct qNaNs), the conditional differed in 10 words. Two 128-bit MINPS/MAXPS intrinsics applied in source order matched all 64. That gives us a Windows oracle for the packed single-precision min/max slice.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 15:29 UTC · original

Maintainer update at cedf64f: resolved the conflict with the now-merged #395 and kept this slice to register-form VEX.256 VMINPS and VMAXPS. The original MASM comparison remains in place. Two SSE halves preserve source order, including when DAZ is enabled. The fixture checks 64 exact word observations covering signed subnormals, signed zero, NaN and both operand orders, and rejects the unsupported memory form.

ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_(avx_packed_fp|avx_packed_int|float_packed|sse34_fp)$' passed 4/4 in each preset. Windows CI is now running on the updated branch. The other floating-point forms can be assessed with their own native evidence.

**@⁠R0Y00** on GitHub · 2026-11-23 15:29 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/387#issuecomment-7105648586) Maintainer update at `cedf64f`: resolved the conflict with the now-merged #395 and kept this slice to register-form VEX.256 `VMINPS` and `VMAXPS`. The original MASM comparison remains in place. Two SSE halves preserve source order, including when DAZ is enabled. The fixture checks 64 exact word observations covering signed subnormals, signed zero, NaN and both operand orders, and rejects the unsupported memory form. `ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_(avx_packed_fp|avx_packed_int|float_packed|sse34_fp)$'` passed 4/4 in each preset. Windows CI is now running on the updated branch. The other floating-point forms can be assessed with their own native evidence.
Author
Owner

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adbc413a36

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