cpu: lower VEX.128/256 AVX horizontal and addsub FP ops in cpu_avx_horiz_fp_aot #2621

Merged
Ammmae0x merged 1 commit from upstream-pr/2629 into main 2026-11-25 23:43:35 +00:00
Ammmae0x commented 2026-11-25 23:37:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T23:37:21Z.


Change

Add a dedicated AVX horizontal and alternating add/sub floating-point AOT translator (tools/cpu_avx_horiz_fp_aot.py), MASM fixture (tests/cpu/avx_horiz_fp_aot.asm, tests/cpu/avx_horiz_fp_aot.def), and differential/refusal/coverage check (tests/cpu/avx_horiz_fp_aot_check.py), registered in CMakeLists.txt as cpu_aot_avx_horiz_fp_dedicated (SKIP_RETURN_CODE 77 + FORM_COVERAGE_RECORD).

  • Lower all 6 AVX horizontal/addsub FP mnemonics in VEX.128 (XMM) and VEX.256 (YMM) register and flat [rcx|rdx|r8] memory-source forms: VHADDPS, VHADDPD, VHSUBPS, VHSUBPD, VADDSUBPS, and VADDSUBPD, plus VMOVAPS/VMOVAPD/VMOVUPS/VMOVUPD glue, VZEROUPPER, and RET.
  • Model exact in-lane 128-bit pairing, even-sub/odd-add alternation, VEX.128 upper [255:128] zeroing, aliased dst/src1/src2 read-before-write semantics, unaligned memory loads/stores, and MXCSR rounding/FTZ/DAZ + -0.0/denormal/Inf/NaN behavior.
  • Refuse EVEX encodings, legacy SSE forms, nonvolatile vector registers (XMM6..15/YMM6..15/ZMM*), undefined vector reads, displaced/indexed/RIP-relative/non-argument memory operands, non-[r8] stores, instruction prefixes, and missing/trailing ret; use sibling-temp atomic .cpp writes.
  • Gate native differential execution via CPUID.01H:ECX[27:28] (OSXSAVE+AVX) + XGETBV(0)[2:1] (exit 77 when unsupported).

Verification

Commit: 93078265 (rebased on upstream/main b97bb64d) on Windows x64 (MSVC cl + Ninja via .\tools\dev.ps1):

  • cmake --preset dev + cmake --build --preset dev --target cpu_avx_horiz_fp_aot_original cpu_avx_horiz_fp_aot_original_lifted cpu_avx_horiz_fp_aot_altered cpu_avx_horiz_fp_aot_altered_lifted -> 0 errors, 0 warnings
  • ctest --preset dev -N -> lists cpu_aot_avx_horiz_fp_dedicated (no dropped tests)
  • ctest --preset dev --output-on-failure -R "^cpu_aot_avx_horiz_fp_dedicated$" -E "cpu_native_archive_" -V -> 1/1 Passed (48 accepted forms, 19 refusal controls, 910 differential cases across 31 exports and 7 MXCSR modes matched native DLL and IEEE-754 reference, 4 altered controls diverged; FORM_COVERAGE_RECORD recorded 12 mnemonics: ret, vaddsubpd, vaddsubps, vhaddpd, vhaddps, vhsubpd, vhsubps, vmovapd, vmovaps, vmovupd, vmovups, vzeroupper)
  • cmake --preset release + cmake --build --preset release --target cpu_avx_horiz_fp_aot_original cpu_avx_horiz_fp_aot_original_lifted cpu_avx_horiz_fp_aot_altered cpu_avx_horiz_fp_aot_altered_lifted -> 0 errors, 0 warnings (/O2)
  • ctest --preset release --output-on-failure -R "^cpu_aot_avx_horiz_fp_dedicated$" -E "cpu_native_archive_" -V -> 1/1 Passed (910 cases, 4 altered controls diverged, FORM_COVERAGE_RECORD 12 mnemonics)
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py -> exit 0
  • out\pe-env\Scripts\python.exe -B tests\docs_links_check.py -> exit 0 (19 Markdown files, 507 links)
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py -> exit 0 (1866 tracked files)
  • Spot-mutation check on tools/cpu_avx_horiz_fp_aot.py (nonvolatile vector guard, undefined vector guard, [r8]-only store guard, zero-displacement memory guard, VEX.128 width flag): 5/5 killed.

Evidence and follow-up

tests/cpu/avx_horiz_fp_aot.asm and tests/cpu/avx_horiz_fp_aot.def are source-built MASM fixtures authored for this repository (MIT License), assembled into original and altered (ALTER_AVX_HORIZ_FP) DLLs to provide both positive differential checks and diverging negative controls.

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:6616011062 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2629). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T23:37:21Z. --- ## Change Add a dedicated AVX horizontal and alternating add/sub floating-point AOT translator (`tools/cpu_avx_horiz_fp_aot.py`), MASM fixture (`tests/cpu/avx_horiz_fp_aot.asm`, `tests/cpu/avx_horiz_fp_aot.def`), and differential/refusal/coverage check (`tests/cpu/avx_horiz_fp_aot_check.py`), registered in `CMakeLists.txt` as `cpu_aot_avx_horiz_fp_dedicated` (`SKIP_RETURN_CODE 77` + `FORM_COVERAGE_RECORD`). - Lower all 6 AVX horizontal/addsub FP mnemonics in VEX.128 (XMM) and VEX.256 (YMM) register and flat `[rcx|rdx|r8]` memory-source forms: `VHADDPS`, `VHADDPD`, `VHSUBPS`, `VHSUBPD`, `VADDSUBPS`, and `VADDSUBPD`, plus `VMOVAPS`/`VMOVAPD`/`VMOVUPS`/`VMOVUPD` glue, `VZEROUPPER`, and `RET`. - Model exact in-lane 128-bit pairing, even-sub/odd-add alternation, VEX.128 upper `[255:128]` zeroing, aliased `dst`/`src1`/`src2` read-before-write semantics, unaligned memory loads/stores, and MXCSR rounding/FTZ/DAZ + `-0.0`/denormal/Inf/NaN behavior. - Refuse EVEX encodings, legacy SSE forms, nonvolatile vector registers (`XMM6..15`/`YMM6..15`/`ZMM*`), undefined vector reads, displaced/indexed/RIP-relative/non-argument memory operands, non-`[r8]` stores, instruction prefixes, and missing/trailing `ret`; use sibling-temp atomic `.cpp` writes. - Gate native differential execution via `CPUID.01H:ECX[27:28]` (OSXSAVE+AVX) + `XGETBV(0)[2:1]` (exit `77` when unsupported). ## Verification Commit: `93078265` (rebased on `upstream/main` `b97bb64d`) on Windows x64 (MSVC `cl` + Ninja via `.\tools\dev.ps1`): - `cmake --preset dev` + `cmake --build --preset dev --target cpu_avx_horiz_fp_aot_original cpu_avx_horiz_fp_aot_original_lifted cpu_avx_horiz_fp_aot_altered cpu_avx_horiz_fp_aot_altered_lifted` -> 0 errors, 0 warnings - `ctest --preset dev -N` -> lists `cpu_aot_avx_horiz_fp_dedicated` (no dropped tests) - `ctest --preset dev --output-on-failure -R "^cpu_aot_avx_horiz_fp_dedicated$" -E "cpu_native_archive_" -V` -> 1/1 Passed (48 accepted forms, 19 refusal controls, 910 differential cases across 31 exports and 7 MXCSR modes matched native DLL and IEEE-754 reference, 4 altered controls diverged; `FORM_COVERAGE_RECORD` recorded 12 mnemonics: `ret, vaddsubpd, vaddsubps, vhaddpd, vhaddps, vhsubpd, vhsubps, vmovapd, vmovaps, vmovupd, vmovups, vzeroupper`) - `cmake --preset release` + `cmake --build --preset release --target cpu_avx_horiz_fp_aot_original cpu_avx_horiz_fp_aot_original_lifted cpu_avx_horiz_fp_aot_altered cpu_avx_horiz_fp_aot_altered_lifted` -> 0 errors, 0 warnings (/O2) - `ctest --preset release --output-on-failure -R "^cpu_aot_avx_horiz_fp_dedicated$" -E "cpu_native_archive_" -V` -> 1/1 Passed (910 cases, 4 altered controls diverged, `FORM_COVERAGE_RECORD` 12 mnemonics) - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py` -> exit 0 - `out\pe-env\Scripts\python.exe -B tests\docs_links_check.py` -> exit 0 (19 Markdown files, 507 links) - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py` -> exit 0 (1866 tracked files) - Spot-mutation check on `tools/cpu_avx_horiz_fp_aot.py` (nonvolatile vector guard, undefined vector guard, `[r8]`-only store guard, zero-displacement memory guard, VEX.128 width flag): 5/5 killed. ## Evidence and follow-up `tests/cpu/avx_horiz_fp_aot.asm` and `tests/cpu/avx_horiz_fp_aot.def` are source-built MASM fixtures authored for this repository (MIT License), assembled into `original` and `altered` (`ALTER_AVX_HORIZ_FP`) DLLs to provide both positive differential checks and diverging negative controls. ## 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-26 00:01:05 +00:00
tedin7 commented 2026-11-26 00:01:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:41:49Z.

Review: COMMENTED


Review of head 93078265 against current main (6 commits behind, no overlap in files).

What I checked:

  • tools/cpu_avx_horiz_fp_aot.py: the six ops (VHADD/VHSUB/VADDSUB, PS and PD) are lowered per 128-bit lane with the matching SSE3 intrinsics, so the in-lane pairing of the 256-bit forms is right; VEX.128 forms zero bits [255:128]. Refusal list (EVEX, legacy SSE, XMM/YMM6..15, displaced/indexed memory, non-[r8] stores, prefixes, missing/trailing ret) matches the docstring.
  • Not a duplicate: earlier work (#926, #1015) covers these ops in the older lifter and in the older addsub fixture. This PR adds the dedicated AOT translator in the same family as cpu_avx_int_aot / cpu_avx_fp_move_aot. The latter explicitly refuses VADDSUB, so there is no overlap.
  • Test: cpu_aot_avx_horiz_fp_dedicated is a native-vs-lifted differential over 7 MXCSR modes, with refusal controls and 4 altered-DLL controls that must diverge, so it guards the behavior. It needs the MASM fixture, so it only runs on Windows; it exits 77 when AVX/OSXSAVE is missing.
  • CMake registration follows the sibling cpu_aot_* pattern (SKIP_RETURN_CODE 77, FORM_COVERAGE_RECORD).

Commands run (Linux):

  • git diff --check origin/main...HEAD -> clean
  • python3 tests/docs_links_check.py -> ok (19 files, 507 links)
  • python3 tests/bidi_controls_check.py -> ok
  • The differential check itself needs the MASM-built DLLs, so it was not run on Linux. Win2025 run follows.

No blocking findings.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066543025 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2629#pullrequestreview-6066543025). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:41:49Z. **Review:** COMMENTED --- Review of head 93078265 against current main (6 commits behind, no overlap in files). What I checked: - `tools/cpu_avx_horiz_fp_aot.py`: the six ops (VHADD/VHSUB/VADDSUB, PS and PD) are lowered per 128-bit lane with the matching SSE3 intrinsics, so the in-lane pairing of the 256-bit forms is right; VEX.128 forms zero bits [255:128]. Refusal list (EVEX, legacy SSE, XMM/YMM6..15, displaced/indexed memory, non-[r8] stores, prefixes, missing/trailing ret) matches the docstring. - Not a duplicate: earlier work (#926, #1015) covers these ops in the older lifter and in the older addsub fixture. This PR adds the dedicated AOT translator in the same family as `cpu_avx_int_aot` / `cpu_avx_fp_move_aot`. The latter explicitly refuses VADDSUB, so there is no overlap. - Test: `cpu_aot_avx_horiz_fp_dedicated` is a native-vs-lifted differential over 7 MXCSR modes, with refusal controls and 4 altered-DLL controls that must diverge, so it guards the behavior. It needs the MASM fixture, so it only runs on Windows; it exits 77 when AVX/OSXSAVE is missing. - CMake registration follows the sibling `cpu_aot_*` pattern (SKIP_RETURN_CODE 77, FORM_COVERAGE_RECORD). Commands run (Linux): - `git diff --check origin/main...HEAD` -> clean - `python3 tests/docs_links_check.py` -> ok (19 files, 507 links) - `python3 tests/bidi_controls_check.py` -> ok - The differential check itself needs the MASM-built DLLs, so it was not run on Linux. Win2025 run follows. No blocking findings. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 00:01:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:42:57Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 93078265b51066f03735d9b86c5fe5b64fcebd9e:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target cpu_avx_horiz_fp_aot_altered cpu_avx_horiz_fp_aot_altered_lifted cpu_avx_horiz_fp_aot_original cpu_avx_horiz_fp_aot_original_lifted -- -j 2): 0.84s (configure 0.00s)
    • Test (ctest --preset dev -R '^cpu_aot_avx_horiz_fp_dedicated$' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (0.65s: cpu_aot_avx_horiz_fp_dedicated 0.51s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target cpu_avx_horiz_fp_aot_altered cpu_avx_horiz_fp_aot_altered_lifted cpu_avx_horiz_fp_aot_original cpu_avx_horiz_fp_aot_original_lifted -- -j 2): 0.86s (configure 0.00s)
    • Test (ctest --preset release -R '^cpu_aot_avx_horiz_fp_dedicated$' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (0.58s: cpu_aot_avx_horiz_fp_dedicated 0.45s)
  • sccache: 4/17 hits; wall 8.5s
    AI-assisted; commands listed were executed locally.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7177948355 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2629#issuecomment-7177948355). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:42:57Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `93078265b51066f03735d9b86c5fe5b64fcebd9e`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target cpu_avx_horiz_fp_aot_altered cpu_avx_horiz_fp_aot_altered_lifted cpu_avx_horiz_fp_aot_original cpu_avx_horiz_fp_aot_original_lifted -- -j 2`): `0.84s` (configure `0.00s`) - Test (`ctest --preset dev -R '^cpu_aot_avx_horiz_fp_dedicated$' --parallel 6 --no-tests=error --output-on-failure`): **1/1 passed** (`0.65s`: `cpu_aot_avx_horiz_fp_dedicated` `0.51s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target cpu_avx_horiz_fp_aot_altered cpu_avx_horiz_fp_aot_altered_lifted cpu_avx_horiz_fp_aot_original cpu_avx_horiz_fp_aot_original_lifted -- -j 2`): `0.86s` (configure `0.00s`) - Test (`ctest --preset release -R '^cpu_aot_avx_horiz_fp_dedicated$' --parallel 6 --no-tests=error --output-on-failure`): **1/1 passed** (`0.58s`: `cpu_aot_avx_horiz_fp_dedicated` `0.45s`) - `sccache`: 4/17 hits; wall `8.5s` AI-assisted; commands listed were executed locally.
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!2621
No description provided.