cpu: lower VEX vaddsubps and vaddsubpd #1015

Manually merged
github merged 1 commit from gh-pr/1015/head into gh-pr/1015/base 2026-11-26 22:35:18 +00:00
Owner

@⁠zohaiblazuli on GitHub · 2026-11-23 21:17 UTC · original
zohaiblazuli:cpu/vex-addsub → main · +424 −3 · 7 files · 1 commits · merged 2026-11-23 21:39 UTC

Change

Lower the VEX.128 and VEX.256 alternating floating-point add/subtract forms vaddsubps and vaddsubpd in the shared lowering (tools/ffx_version_query.py). Both were observed_without_pass rows in the AVX group of docs/coverage/x64_zen2.tsv.

The forms go through the existing per-lane SSE3 path used for vhaddps/vhsubps (#926), with _mm_addsub_ps and _mm_addsub_pd. That path already accepts register and unaligned m128/m256 sources, zeroes bits 255:128 for 128-bit destinations, and rejects EVEX, untracked registers, segment prefixes and EIP-relative operands. So the lowering change is two table entries plus a docstring and diagnostic wording update.

Refs #387. Its original scope listed these two forms. They were dropped when it was narrowed to vminps/vmaxps, with the note that the other floating-point forms could be assessed with their own native evidence. This PR provides that evidence for vaddsubps/vaddsubpd only. No shared interface changes.

tests/cpu/sse34_fp.py had a rejection control expecting register-form vaddsubps xmm0, xmm1, xmm2 to be refused. That form is now accepted, so the control uses vaddsubps xmm0, xmm1, xmm3 instead (untracked source), which remains refused. The control still exercises the VEX addsub encoding.

Verification

Commit 5246da9 on main at 2067f54. Windows 11 build 26300.10075, MSVC 19.50.35728 x64, Intel Core i5-14600K (AVX).

cmake --build --preset dev --target cpu_avx_addsub_fp_lifted cpu_sse34_fp_lifted cpu_avx_horiz_fp_lifted
ctest --preset dev --no-tests=error -R '^cpu_aot_(avx_addsub_fp|sse34_fp|avx_horiz_fp)$' -V
  • cpu_aot_avx_addsub_fp: 400 cases across 14 exports and 7 MXCSR modes matched the native DLL and the IEEE-754 reference; 3 mutated controls mismatched.
  • cpu_aot_avx_horiz_fp: 632 cases, unchanged, passed.
  • cpu_aot_sse34_fp: 950 cases, passed with the retargeted control.

The same three tests passed 3/3 with the release preset (/O2). docs_links passed, and python -B tests/form_coverage_check.py reported "form coverage checks passed". Running tools/form_coverage.py --gaps x64_zen2 on a full non-hardware run of main listed vaddsubps and vaddsubpd as observed_without_pass. With this change, the fixture is classified pass and neither form appears in the gaps.

Evidence and follow-up

New fixture tests/cpu/avx_addsub_fp.asm is original MASM source (MIT), with 14 exports:

  • register and memory forms at both widths;
  • dst = src1, dst = src2, src1 = src2 and all-aliased register forms;
  • 128-bit forms preloading a nonzero destination, so the upper-byte clear is observed.

Inputs use distinct values per element and lane, so swapped elements, swapped add/sub positions, or a dropped upper lane all change the output. They cover:

  • QNaN/SNaN payloads in either operand and NaN-vs-NaN order;
  • signed-zero cancellation in both the add and the subtract positions;
  • inf - inf (invalid only in subtract positions);
  • overflow, subnormals and the FTZ boundary;
  • unaligned memory sources;
  • MXCSR RC 0–3, DAZ and FTZ.

The test reuses the IEEE-754 reference model, guarded buffers and AVX/MXCSR probes from tests/cpu/avx_horiz_fp.py rather than copying them. It exits 77 on hosts without AVX. The mutated controls are:

  • all-add for ps;
  • all-subtract for pd;
  • a missing upper-byte clear for the 128-bit form.

Reproduction steps are in docs/experiments.md, next to the horizontal FP entry. The legacy addsubps/addsubpd path in sse34_fp is unchanged.

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.
**@⁠zohaiblazuli** on GitHub · 2026-11-23 21:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1015) `zohaiblazuli:cpu/vex-addsub` → `main` · +424 −3 · 7 files · 1 commits · merged 2026-11-23 21:39 UTC ## Change Lower the VEX.128 and VEX.256 alternating floating-point add/subtract forms `vaddsubps` and `vaddsubpd` in the shared lowering (`tools/ffx_version_query.py`). Both were `observed_without_pass` rows in the `AVX` group of `docs/coverage/x64_zen2.tsv`. The forms go through the existing per-lane SSE3 path used for `vhaddps`/`vhsubps` (#926), with `_mm_addsub_ps` and `_mm_addsub_pd`. That path already accepts register and unaligned `m128`/`m256` sources, zeroes bits 255:128 for 128-bit destinations, and rejects EVEX, untracked registers, segment prefixes and EIP-relative operands. So the lowering change is two table entries plus a docstring and diagnostic wording update. Refs #387. Its original scope listed these two forms. They were dropped when it was narrowed to `vminps`/`vmaxps`, with the note that the other floating-point forms could be assessed with their own native evidence. This PR provides that evidence for `vaddsubps`/`vaddsubpd` only. No shared interface changes. `tests/cpu/sse34_fp.py` had a rejection control expecting register-form `vaddsubps xmm0, xmm1, xmm2` to be refused. That form is now accepted, so the control uses `vaddsubps xmm0, xmm1, xmm3` instead (untracked source), which remains refused. The control still exercises the VEX addsub encoding. ## Verification Commit `5246da9` on `main` at `2067f54`. Windows 11 build 26300.10075, MSVC 19.50.35728 x64, Intel Core i5-14600K (AVX). ```powershell cmake --build --preset dev --target cpu_avx_addsub_fp_lifted cpu_sse34_fp_lifted cpu_avx_horiz_fp_lifted ctest --preset dev --no-tests=error -R '^cpu_aot_(avx_addsub_fp|sse34_fp|avx_horiz_fp)$' -V ``` - `cpu_aot_avx_addsub_fp`: 400 cases across 14 exports and 7 MXCSR modes matched the native DLL and the IEEE-754 reference; 3 mutated controls mismatched. - `cpu_aot_avx_horiz_fp`: 632 cases, unchanged, passed. - `cpu_aot_sse34_fp`: 950 cases, passed with the retargeted control. The same three tests passed 3/3 with the `release` preset (/O2). `docs_links` passed, and `python -B tests/form_coverage_check.py` reported "form coverage checks passed". Running `tools/form_coverage.py --gaps x64_zen2` on a full non-hardware run of `main` listed `vaddsubps` and `vaddsubpd` as `observed_without_pass`. With this change, the fixture is classified `pass` and neither form appears in the gaps. ## Evidence and follow-up New fixture `tests/cpu/avx_addsub_fp.asm` is original MASM source (MIT), with 14 exports: - register and memory forms at both widths; - `dst = src1`, `dst = src2`, `src1 = src2` and all-aliased register forms; - 128-bit forms preloading a nonzero destination, so the upper-byte clear is observed. Inputs use distinct values per element and lane, so swapped elements, swapped add/sub positions, or a dropped upper lane all change the output. They cover: - QNaN/SNaN payloads in either operand and NaN-vs-NaN order; - signed-zero cancellation in both the add and the subtract positions; - `inf - inf` (invalid only in subtract positions); - overflow, subnormals and the FTZ boundary; - unaligned memory sources; - MXCSR RC 0–3, DAZ and FTZ. The test reuses the IEEE-754 reference model, guarded buffers and AVX/MXCSR probes from `tests/cpu/avx_horiz_fp.py` rather than copying them. It exits 77 on hosts without AVX. The mutated controls are: - all-add for `ps`; - all-subtract for `pd`; - a missing upper-byte clear for the 128-bit form. Reproduction steps are in `docs/experiments.md`, next to the horizontal FP entry. The legacy `addsubps`/`addsubpd` path in `sse34_fp` is unchanged. ## 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.
Route the VEX.128 and VEX.256 alternating add/subtract forms through the
existing per-lane SSE3 lowering used for vhaddps/vhsubps, with
_mm_addsub_ps and _mm_addsub_pd. 128-bit destinations zero bits 255:128.

Add cpu_aot_avx_addsub_fp: 14 source-built exports (register, memory and
aliased forms at both widths) compared against the native DLL and the
IEEE-754 reference model shared with avx_horiz_fp across 7 MXCSR modes,
with rejection and three mutated controls.

The sse34_fp control that expected register-form VEX vaddsubps to be
rejected now uses an untracked xmm3 source, which stays rejected.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:35:16 +00:00
github manually merged commit 5246da9b6f into gh-pr/1015/base 2026-11-26 22:35:18 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.