cpu: lower AVX horizontal floating-point add and subtract instructions #926

Manually merged
github merged 2 commits from gh-pr/926/head into gh-pr/926/base 2026-11-26 22:28:52 +00:00
Owner

@⁠Ammmae0x on GitHub · 2026-11-23 17:23 UTC · original
Ammmae0x:cpu/avx-horiz-fp → main · +782 −0 · 6 files · 2 commits · merged 2026-11-23 17:50 UTC

Change

Lower the four VEX-encoded AVX horizontal floating-point add/subtract instructions (vhaddps, vhaddpd, vhsubps, vhsubpd) in tools/ffx_version_query.py using a shared helper (lower_avx_horiz_fp + avx_horiz_fp_ops):

  • Supports 128-bit XMM0–XMM2 (zeroing destination bytes [16:32] per VEX semantics) and 256-bit YMM0–YMM2 (independent 128-bit lanes), with both register and unaligned m128/m256 memory src2 operands.
  • Reuses 128-bit SSE3 intrinsics (_mm_hadd_ps, _mm_hadd_pd, _mm_hsub_ps, _mm_hsub_pd) per 128-bit lane to preserve hardware NaN payloads, signed zeros, rounding modes, DAZ, and FTZ semantics.
  • Rejects EVEX, non-VEX, untracked registers (xmm3+/ymm3+), segment prefixes, EIP-relative addressing, and mismatched operand shapes with ValueError.
  • Adds source-built MASM differential fixture tests/cpu/avx_horiz_fp.{asm,def,py}, registers cpu_avx_horiz_fp, cpu_avx_horiz_fp_lifted, and cpu_aot_avx_horiz_fp (SKIP_RETURN_CODE 77) in CMakeLists.txt, and documents the fixture in docs/experiments.md.

Verification

  • cmake --build --preset dev --target cpu_avx_horiz_fp cpu_avx_horiz_fp_lifted and cmake --build --preset release --target cpu_avx_horiz_fp cpu_avx_horiz_fp_lifted: 0 errors, 0 warnings in both Debug (dev) and /O2 (release).
  • ctest --preset dev --no-tests=error -R "^cpu_aot_(avx_horiz_fp|avx2_regs|avx_int_regs|avx_move_regs|float_packed|sse41_42_misc)$" -V: 6/6 passed (cpu_aot_avx_horiz_fp: 632 VEX AVX horizontal FP cases across 22 exports and 7 MXCSR modes matched native DLL and IEEE-754 reference; 2 mutated controls mismatched, plus 16 rejection controls).
  • ctest --preset release --no-tests=error -R "^cpu_aot_(avx_horiz_fp|avx2_regs|avx_int_regs|avx_move_regs|float_packed|sse41_42_misc)$" -V: 6/6 passed (cpu_aot_avx_horiz_fp: 632 cases + 2 mutated controls).
  • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed / Self-test passed.
  • .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py: Checked 13 Markdown files and 178 links. Self-test passed.
  • .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py: Checked 725 tracked source, script and build/CI files: no bidirectional controls.
  • tools/form_coverage.py against ctest --preset dev -R "^cpu_" JUnit output: vhaddps, vhaddpd, vhsubps, vhsubpd are covered (+4 net new covered x64 Zen 2 AVX forms, 799 of 948 total).

Evidence and follow-up

  • tests/cpu/avx_horiz_fp.{asm,def,py} are original source-built MASM and Python fixtures contributed under the MIT License.
  • Differential checks compare the native MASM DLL, translated C++ DLL, and an independent Python IEEE-754 Fraction reference across aliasing (dst == src1, dst == src2, src1 == src2, dst == src1 == src2), unaligned m128/m256 loads, upper-16-byte zeroing, QNaN/SNaN payloads, signed zeros, infinities, subnormals, and 7 MXCSR rounding/DAZ/FTZ modes, alongside 16 rejection controls and 2 mutated negative controls.
  • Passing this fixture verifies lowering of these four VEX instructions in the leaf profile; it does not establish full-game startup.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-11-23 17:23 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/926) `Ammmae0x:cpu/avx-horiz-fp` → `main` · +782 −0 · 6 files · 2 commits · merged 2026-11-23 17:50 UTC ## Change Lower the four VEX-encoded AVX horizontal floating-point add/subtract instructions (`vhaddps`, `vhaddpd`, `vhsubps`, `vhsubpd`) in `tools/ffx_version_query.py` using a shared helper (`lower_avx_horiz_fp` + `avx_horiz_fp_ops`): - Supports 128-bit `XMM0`–`XMM2` (zeroing destination bytes `[16:32]` per VEX semantics) and 256-bit `YMM0`–`YMM2` (independent 128-bit lanes), with both register and unaligned `m128`/`m256` memory `src2` operands. - Reuses 128-bit SSE3 intrinsics (`_mm_hadd_ps`, `_mm_hadd_pd`, `_mm_hsub_ps`, `_mm_hsub_pd`) per 128-bit lane to preserve hardware NaN payloads, signed zeros, rounding modes, DAZ, and FTZ semantics. - Rejects EVEX, non-VEX, untracked registers (`xmm3+`/`ymm3+`), segment prefixes, EIP-relative addressing, and mismatched operand shapes with `ValueError`. - Adds source-built MASM differential fixture `tests/cpu/avx_horiz_fp.{asm,def,py}`, registers `cpu_avx_horiz_fp`, `cpu_avx_horiz_fp_lifted`, and `cpu_aot_avx_horiz_fp` (`SKIP_RETURN_CODE 77`) in `CMakeLists.txt`, and documents the fixture in `docs/experiments.md`. ## Verification - `cmake --build --preset dev --target cpu_avx_horiz_fp cpu_avx_horiz_fp_lifted` and `cmake --build --preset release --target cpu_avx_horiz_fp cpu_avx_horiz_fp_lifted`: 0 errors, 0 warnings in both Debug (`dev`) and `/O2` (`release`). - `ctest --preset dev --no-tests=error -R "^cpu_aot_(avx_horiz_fp|avx2_regs|avx_int_regs|avx_move_regs|float_packed|sse41_42_misc)$" -V`: `6/6` passed (`cpu_aot_avx_horiz_fp`: `632 VEX AVX horizontal FP cases across 22 exports and 7 MXCSR modes matched native DLL and IEEE-754 reference; 2 mutated controls mismatched`, plus 16 rejection controls). - `ctest --preset release --no-tests=error -R "^cpu_aot_(avx_horiz_fp|avx2_regs|avx_int_regs|avx_move_regs|float_packed|sse41_42_misc)$" -V`: `6/6` passed (`cpu_aot_avx_horiz_fp`: `632` cases + `2` mutated controls). - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` / `Self-test passed.` - `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py`: `Checked 13 Markdown files and 178 links. Self-test passed.` - `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py`: `Checked 725 tracked source, script and build/CI files: no bidirectional controls.` - `tools/form_coverage.py` against `ctest --preset dev -R "^cpu_"` JUnit output: `vhaddps`, `vhaddpd`, `vhsubps`, `vhsubpd` are covered (+4 net new covered x64 Zen 2 `AVX` forms, `799 of 948` total). ## Evidence and follow-up - `tests/cpu/avx_horiz_fp.{asm,def,py}` are original source-built MASM and Python fixtures contributed under the MIT License. - Differential checks compare the native MASM DLL, translated C++ DLL, and an independent Python IEEE-754 `Fraction` reference across aliasing (`dst == src1`, `dst == src2`, `src1 == src2`, `dst == src1 == src2`), unaligned `m128`/`m256` loads, upper-16-byte zeroing, QNaN/SNaN payloads, signed zeros, infinities, subnormals, and 7 MXCSR rounding/DAZ/FTZ modes, alongside 16 rejection controls and 2 mutated negative controls. - Passing this fixture verifies lowering of these four VEX instructions in the leaf profile; it does not establish full-game startup. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:28:51 +00:00
github manually merged commit 56ef0bfc08 into gh-pr/926/base 2026-11-26 22:28:52 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 17:33 UTC · original

I independently built and tested 4673aee with MSVC 19.51 x64 Release. cpu_aot_avx_horiz_fp passed all 632 cases across 22 exports and seven MXCSR modes, with both mutants detected. I will check the full GitHub run and current mergeability before merging.

**@⁠R0Y00** on GitHub · 2026-11-23 17:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/926#issuecomment-7108833496) I independently built and tested 4673aee with MSVC 19.51 x64 Release. cpu_aot_avx_horiz_fp passed all 632 cases across 22 exports and seven MXCSR modes, with both mutants detected. I will check the full GitHub run and current mergeability before merging.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 17:36 UTC · original

I integrated the branch with current main at 56ef0bf and retained the adjacent integer and shuffle fixtures. Windows x64 Release passed all four focused AVX tests. The horizontal case still matched 632 cases and caught both mutations; the existing guard-page and VZEROALL ABI controls also passed. Waiting for CI on the combined head.

**@⁠R0Y00** on GitHub · 2026-11-23 17:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/926#issuecomment-7108902513) I integrated the branch with current main at 56ef0bf and retained the adjacent integer and shuffle fixtures. Windows x64 Release passed all four focused AVX tests. The horizontal case still matched 632 cases and caught both mutations; the existing guard-page and VZEROALL ABI controls also passed. Waiting for CI on the combined head.
This discussion has been locked. Commenting is limited to contributors.
No description provided.