cpu: lower VEX AVX F16C, masked FP load/store, and non-temporal store instructions #403

Open
Vonsek wants to merge 1 commit from upstream-pr/409 into main
Vonsek commented 2026-11-22 00:40:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-22T00:40:07Z.


Change

  • Lower 7 VEX AVX F16C, masked FP load/store, and non-temporal aligned store instructions in tools/ffx_version_query.py:
    • F16C half-precision conversions: vcvtph2ps, vcvtps2ph (exact IEEE 754 binary16 <-> binary32 for all 4 explicit rounding modes, rejecting MXCSR mode imm8 & 4 != 0)
    • Masked FP load/store: vmaskmovps, vmaskmovpd (leaving unmasked memory untouched on stores and zeroing unmasked lanes on loads)
    • Non-temporal aligned stores: vmovntps, vmovntpd, vmovntdq
  • Restrict lowering to EncodingKind.VEX (rejecting EVEX encodings).
  • Probe CPUID leaf 1 ECX bits 27 (OSXSAVE), 28 (AVX), and 29 (F16C) plus XCR0 XMM/YMM state before invoking the native fixture (exiting 77 with SKIP_RETURN_CODE 77 on hosts without AVX/F16C).
  • Add source-built MASM differential fixture tests/cpu/avx_f16c_maskmov.{asm,def,py}, CMake target cpu_avx_f16c_maskmov_lifted, CTest cpu_aot_avx_f16c_maskmov, coverage mapping in tools/form_coverage.py, and documentation in docs/experiments.md.

Verification

  • Confirmed pre-fix failure on cmake --build --preset dev --target cpu_avx_f16c_maskmov_lifted:
    ValueError: unsupported query operation at 0x1004: vcvtph2ps ymm0,xmm1
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_avx_f16c_maskmov_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_f16c_maskmov|cpu_aot_bmi1)$" -V: 2/2 passed (10 AVX F16C/maskmov/movnt cases matched native and translated DLLs + MXCSR-mode vcvtps2ph rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • Covers 7 AVX-grouped mnemonics in docs/coverage/x64_zen2.tsv using source-built fixtures, gated by a runtime CPUID/XCR0 check.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536426749 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/409). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-22T00:40:07Z. --- ## Change - Lower 7 VEX AVX F16C, masked FP load/store, and non-temporal aligned store instructions in `tools/ffx_version_query.py`: - F16C half-precision conversions: `vcvtph2ps`, `vcvtps2ph` (exact IEEE 754 binary16 <-> binary32 for all 4 explicit rounding modes, rejecting MXCSR mode imm8 & 4 != 0) - Masked FP load/store: `vmaskmovps`, `vmaskmovpd` (leaving unmasked memory untouched on stores and zeroing unmasked lanes on loads) - Non-temporal aligned stores: `vmovntps`, `vmovntpd`, `vmovntdq` - Restrict lowering to `EncodingKind.VEX` (rejecting EVEX encodings). - Probe CPUID leaf 1 ECX bits 27 (`OSXSAVE`), 28 (`AVX`), and 29 (`F16C`) plus XCR0 XMM/YMM state before invoking the native fixture (exiting 77 with `SKIP_RETURN_CODE 77` on hosts without AVX/F16C). - Add source-built MASM differential fixture `tests/cpu/avx_f16c_maskmov.{asm,def,py}`, CMake target `cpu_avx_f16c_maskmov_lifted`, CTest `cpu_aot_avx_f16c_maskmov`, coverage mapping in `tools/form_coverage.py`, and documentation in `docs/experiments.md`. ## Verification - Confirmed pre-fix failure on `cmake --build --preset dev --target cpu_avx_f16c_maskmov_lifted`: `ValueError: unsupported query operation at 0x1004: vcvtph2ps ymm0,xmm1` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_avx_f16c_maskmov_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_f16c_maskmov|cpu_aot_bmi1)$" -V`: 2/2 passed (`10 AVX F16C/maskmov/movnt cases matched native and translated DLLs` + MXCSR-mode `vcvtps2ph` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - Covers 7 `AVX`-grouped mnemonics in `docs/coverage/x64_zen2.tsv` using source-built fixtures, gated by a runtime CPUID/XCR0 check.
legacy-code-archaeologist commented 2026-11-24 06:48:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T14:46:39Z.


Verification of 5d120e3 on an Intel Core i7-6820HQ (Skylake; AVX2 and F16C, no AVX-512). Windows 11 26100.9168, MSVC 19.52.37029, dev preset:

ctest --preset dev --no-tests=error -R cpu_aot_avx_f16c_maskmov -V
10 AVX F16C/maskmov/movnt cases matched native and translated DLLs
1/1 Test #95: cpu_aot_avx_f16c_maskmov .........   Passed    0.24 sec

The fixture does not cover one property of vmaskmov: masked-off lanes must not fault. I checked it with a local probe, using the built cpu_avx_f16c_maskmov.dll and cpu_avx_f16c_maskmov_lifted.dll unchanged:

  • Each call runs in a child process.
  • The 32-byte operand starts 16 bytes before a PAGE_NOACCESS page, so its upper half lies on that page.
  • The mask enables only the lanes in the lower 16 bytes.

Native and translated runs match for all four exports. None faulted, and the outputs are identical:

Export Native Translated
vmaskmovps_load_op no fault, lanes 0–3 loaded, 4–7 zero same bytes
vmaskmovpd_load_op no fault, lanes 0–1 loaded, 2–3 zero same bytes
vmaskmovps_store_op no fault, only the enabled bytes written same bytes
vmaskmovpd_store_op no fault, only the enabled bytes written same bytes

Adding such a guard-page case to tests/cpu/avx_f16c_maskmov.py would pin that behavior. A translation that loads all 32 bytes and then blends would pass the current sentinel check but fault there.

Separately, 5d120e3 no longer merges cleanly with main at f8d11ad. git merge-tree reports conflicts in CMakeLists.txt, tools/ffx_version_query.py and tools/form_coverage.py.

AI-assisted: run and summarized with Claude Code; outputs copied from the local runs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7080797573 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/409#issuecomment-7080797573). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-22T14:46:39Z. --- Verification of `5d120e3` on an Intel Core i7-6820HQ (Skylake; AVX2 and F16C, no AVX-512). Windows 11 26100.9168, MSVC 19.52.37029, `dev` preset: ```text ctest --preset dev --no-tests=error -R cpu_aot_avx_f16c_maskmov -V 10 AVX F16C/maskmov/movnt cases matched native and translated DLLs 1/1 Test #95: cpu_aot_avx_f16c_maskmov ......... Passed 0.24 sec ``` The fixture does not cover one property of `vmaskmov`: masked-off lanes must not fault. I checked it with a local probe, using the built `cpu_avx_f16c_maskmov.dll` and `cpu_avx_f16c_maskmov_lifted.dll` unchanged: - Each call runs in a child process. - The 32-byte operand starts 16 bytes before a `PAGE_NOACCESS` page, so its upper half lies on that page. - The mask enables only the lanes in the lower 16 bytes. Native and translated runs match for all four exports. None faulted, and the outputs are identical: | Export | Native | Translated | |---|---|---| | `vmaskmovps_load_op` | no fault, lanes 0–3 loaded, 4–7 zero | same bytes | | `vmaskmovpd_load_op` | no fault, lanes 0–1 loaded, 2–3 zero | same bytes | | `vmaskmovps_store_op` | no fault, only the enabled bytes written | same bytes | | `vmaskmovpd_store_op` | no fault, only the enabled bytes written | same bytes | Adding such a guard-page case to `tests/cpu/avx_f16c_maskmov.py` would pin that behavior. A translation that loads all 32 bytes and then blends would pass the current sentinel check but fault there. Separately, `5d120e3` no longer merges cleanly with `main` at `f8d11ad`. `git merge-tree` reports conflicts in `CMakeLists.txt`, `tools/ffx_version_query.py` and `tools/form_coverage.py`. AI-assisted: run and summarized with Claude Code; outputs copied from the local runs.
tedin7 commented 2026-11-27 09:37:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T09:37:29Z.


This PR now conflicts with main. Conflicting files:

  • CMakeLists.txt
  • tools/ffx_version_query.py
  • tools/form_coverage.py

Could you merge main into your branch (a merge commit, no force push needed) and resolve these? Thank you.

AI-assisted; commands listed were executed locally. (git merge-tree origin/main <head>)

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7214900468 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/409#issuecomment-7214900468). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T09:37:29Z. --- This PR now conflicts with `main`. Conflicting files: - `CMakeLists.txt` - `tools/ffx_version_query.py` - `tools/form_coverage.py` Could you merge `main` into your branch (a merge commit, no force push needed) and resolve these? Thank you. AI-assisted; commands listed were executed locally. (`git merge-tree origin/main <head>`)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/409:upstream-pr/409'
git switch 'upstream-pr/409'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/409'
git switch 'upstream-pr/409'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/409'
git switch 'upstream-pr/409'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/409'
git switch 'main'
git merge --squash 'upstream-pr/409'
git switch 'main'
git merge --ff-only 'upstream-pr/409'
git switch 'main'
git merge 'upstream-pr/409'
git push origin 'main'
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!403
No description provided.