cpu: lower VEX vaddsubps and vaddsubpd #1008

Merged
zohaiblazuli merged 1 commit from upstream-pr/1015 into main 2026-11-23 21:39:47 +00:00
zohaiblazuli commented 2026-11-23 21:17:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by zohaiblazuli on 2026-11-23T21:17:50Z.


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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6569023080 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1015). Originally posted by [zohaiblazuli](https://github.com/zohaiblazuli) on 2026-11-23T21:17:50Z. --- ## 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.
upstream-sync closed this pull request 2026-11-24 06:45:51 +00:00
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!1008
No description provided.