cpu: lower AVX VEX FP compare instructions #966

Closed
Ammmae0x wants to merge 1 commit from upstream-pr/973 into main
Ammmae0x commented 2026-11-23 19:22:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T19:22:36Z.


Change

Add VEX AVX floating-point compare lowering (tools/ffx_version_query.py) and differential fixture coverage (tests/cpu/avx_cmp_fp.{asm,def,py}, CMakeLists.txt, docs/experiments.md) for four uncovered x64 Zen 2 AVX mnemonics:

  • vcmpps (VEX.128 and VEX.256, register and unaligned m128/m256 operands)
  • vcmppd (VEX.128 and VEX.256, register and unaligned m128/m256 operands)
  • vcmpss (VEX.128, register and unaligned m32 operands)
  • vcmpsd (VEX.128, register and unaligned m64 operands)

The lowering (avx_cmp_pred, avx_cmp_f32, avx_cmp_f64 in INTEGER_HEADER plus lower_avx_cmp_fp) implements all 32 AVX predicate immediates (imm8 & 0x1f) using portable SSE2 _mm_comi*/_mm_ucomi* intrinsics and bit-level NaN checks (compatible with non-/arch:AVX MSVC builds), preserving ordered/unordered NaN semantics, quiet vs. signaling MXCSR #I, DAZ handling, upper-lane preservation (4..15 on vcmpss, 8..15 on vcmpsd), and upper-128-bit zeroing on XMM destinations. EVEX encodings, legacy SSE encodings, untracked vector registers (xmm3/ymm3), segment prefixes, EIP-relative operands, mixed XMM/YMM widths, mismatched memory operand sizes, and non-imm8 predicates are rejected.

Verification

Tested on commit 75dd03f (branch cpu/avx-cmp-fp, x64 Windows host with AVX):

  • ctest --preset dev -N: 503 total tests (cpu_aot_avx_cmp_fp registered as Test #216 with SKIP_RETURN_CODE 77; no test drops or regressions).
  • cmake --preset dev + cmake --build --preset dev --clean-first --target cpu_avx_cmp_fp_lifted cpu_avx_horiz_fp_lifted cpu_avx_scalar_fp_lifted cpu_version_query_lifted: succeeded with 0 errors, 0 warnings.
  • cmake --preset release + cmake --build --preset release --target cpu_avx_cmp_fp_lifted cpu_avx_horiz_fp_lifted cpu_avx_scalar_fp_lifted cpu_version_query_lifted: succeeded with 0 errors, 0 warnings.
  • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_cmp_fp|cpu_aot_avx_horiz_fp|cpu_aot_avx_scalar_fp|cpu_aot_version_query)$" -V: 4/4 passed (cpu_aot_avx_cmp_fp: 1760 VEX AVX FP compare cases across 217 exports and 2 MXCSR modes + guard-page bounds + 18 byte-decoded & 11 synthetic rejections + 4 mutated controls; cpu_aot_avx_horiz_fp: 632 cases + 2 mutated controls; cpu_aot_avx_scalar_fp: 39 cases; cpu_aot_version_query: passed).
  • ctest --preset release --no-tests=error -R "^(cpu_aot_avx_cmp_fp|cpu_aot_avx_horiz_fp|cpu_aot_avx_scalar_fp|cpu_aot_version_query)$" -V: 4/4 passed with matching counts.
  • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py: all passed (13 Markdown files / 195 links; 796 tracked files).
  • tools/form_coverage.py on cpu_aot_avx_cmp_fp JUnit XML: vcmpps, vcmppd, vcmpss, vcmpsd all counted as covered in AVX.

Evidence and follow-up

  • Source-built MASM fixture (tests/cpu/avx_cmp_fp.asm) and Python differential check (tests/cpu/avx_cmp_fp.py) with an independent IEEE-754 comparison reference model, unaligned memory offsets, VirtualAlloc guard-page bounds checks, 18 byte-decoded + 11 synthetic rejection controls, and 4 mutated C++ negative controls.
  • Remaining uncovered AVX forms in docs/coverage/x64_zen2.tsv (vaddsubps/pd, vptest, vtestps/pd, vldmxcsr, vstmxcsr, vmovq, vmaskmovdqu) are out of scope for this PR.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6567041102 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/973). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-23T19:22:36Z. --- ## Change Add VEX AVX floating-point compare lowering (`tools/ffx_version_query.py`) and differential fixture coverage (`tests/cpu/avx_cmp_fp.{asm,def,py}`, `CMakeLists.txt`, `docs/experiments.md`) for four uncovered x64 Zen 2 `AVX` mnemonics: - `vcmpps` (VEX.128 and VEX.256, register and unaligned `m128`/`m256` operands) - `vcmppd` (VEX.128 and VEX.256, register and unaligned `m128`/`m256` operands) - `vcmpss` (VEX.128, register and unaligned `m32` operands) - `vcmpsd` (VEX.128, register and unaligned `m64` operands) The lowering (`avx_cmp_pred`, `avx_cmp_f32`, `avx_cmp_f64` in `INTEGER_HEADER` plus `lower_avx_cmp_fp`) implements all 32 AVX predicate immediates (`imm8 & 0x1f`) using portable SSE2 `_mm_comi*`/`_mm_ucomi*` intrinsics and bit-level NaN checks (compatible with non-`/arch:AVX` MSVC builds), preserving ordered/unordered NaN semantics, quiet vs. signaling MXCSR `#I`, DAZ handling, upper-lane preservation (`4..15` on `vcmpss`, `8..15` on `vcmpsd`), and upper-128-bit zeroing on XMM destinations. EVEX encodings, legacy SSE encodings, untracked vector registers (`xmm3`/`ymm3`), segment prefixes, EIP-relative operands, mixed XMM/YMM widths, mismatched memory operand sizes, and non-`imm8` predicates are rejected. ## Verification Tested on commit `75dd03f` (branch `cpu/avx-cmp-fp`, x64 Windows host with AVX): - `ctest --preset dev -N`: 503 total tests (`cpu_aot_avx_cmp_fp` registered as Test #216 with `SKIP_RETURN_CODE 77`; no test drops or regressions). - `cmake --preset dev` + `cmake --build --preset dev --clean-first --target cpu_avx_cmp_fp_lifted cpu_avx_horiz_fp_lifted cpu_avx_scalar_fp_lifted cpu_version_query_lifted`: succeeded with 0 errors, 0 warnings. - `cmake --preset release` + `cmake --build --preset release --target cpu_avx_cmp_fp_lifted cpu_avx_horiz_fp_lifted cpu_avx_scalar_fp_lifted cpu_version_query_lifted`: succeeded with 0 errors, 0 warnings. - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_cmp_fp|cpu_aot_avx_horiz_fp|cpu_aot_avx_scalar_fp|cpu_aot_version_query)$" -V`: 4/4 passed (`cpu_aot_avx_cmp_fp`: 1760 VEX AVX FP compare cases across 217 exports and 2 MXCSR modes + guard-page bounds + 18 byte-decoded & 11 synthetic rejections + 4 mutated controls; `cpu_aot_avx_horiz_fp`: 632 cases + 2 mutated controls; `cpu_aot_avx_scalar_fp`: 39 cases; `cpu_aot_version_query`: passed). - `ctest --preset release --no-tests=error -R "^(cpu_aot_avx_cmp_fp|cpu_aot_avx_horiz_fp|cpu_aot_avx_scalar_fp|cpu_aot_version_query)$" -V`: 4/4 passed with matching counts. - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`: all passed (13 Markdown files / 195 links; 796 tracked files). - `tools/form_coverage.py` on `cpu_aot_avx_cmp_fp` JUnit XML: `vcmpps`, `vcmppd`, `vcmpss`, `vcmpsd` all counted as covered in `AVX`. ## Evidence and follow-up - Source-built MASM fixture (`tests/cpu/avx_cmp_fp.asm`) and Python differential check (`tests/cpu/avx_cmp_fp.py`) with an independent IEEE-754 comparison reference model, unaligned memory offsets, VirtualAlloc guard-page bounds checks, 18 byte-decoded + 11 synthetic rejection controls, and 4 mutated C++ negative controls. - Remaining uncovered `AVX` forms in `docs/coverage/x64_zen2.tsv` (`vaddsubps`/`pd`, `vptest`, `vtestps`/`pd`, `vldmxcsr`, `vstmxcsr`, `vmovq`, `vmaskmovdqu`) are out of scope for this PR. ## 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.
upstream-sync closed this pull request 2026-11-24 06:45:39 +00:00
R0Y00 commented 2026-11-24 06:49:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T19:36:34Z.


Both Windows jobs stop while generating the lifted fixture: mutated control vcmpps_flipped_ord_unord_control changed nothing. The standalone head builds locally. In GitHub's merge candidate, main's existing elif op in avx_compare handles all four mnemonics before the added branch, so the generated body uses the existing compare intrinsic and the mutation never matches. Please keep the stronger all-predicate, guard-page and MXCSR comparisons as a fixture on current main. Make the controls change the actual emitted instruction path, keep their failure assertions, and report any native-versus-main mismatch separately before replacing that lowering.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7111844449 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/973#issuecomment-7111844449). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T19:36:34Z. --- Both Windows jobs stop while generating the lifted fixture: `mutated control vcmpps_flipped_ord_unord_control changed nothing`. The standalone head builds locally. In GitHub's merge candidate, main's existing `elif op in avx_compare` handles all four mnemonics before the added branch, so the generated body uses the existing compare intrinsic and the mutation never matches. Please keep the stronger all-predicate, guard-page and MXCSR comparisons as a fixture on current main. Make the controls change the actual emitted instruction path, keep their failure assertions, and report any native-versus-main mismatch separately before replacing that lowering.
Ammmae0x commented 2026-11-24 06:49:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T19:43:35Z.


Closing as superseded by merged #393, which already covers vcmpps, vcmppd, vcmpss, and vcmpsd. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7112013708 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/973#issuecomment-7112013708). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-23T19:43:35Z. --- Closing as superseded by merged #393, which already covers `vcmpps`, `vcmppd`, `vcmpss`, and `vcmpsd`. AI-assisted.

Pull request closed

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!966
No description provided.