cpu: lower 34 packed, scalar, and half-precision float conversion instructions (SSE, SSE2, AVX) #735

Merged
MrSkelee merged 2 commits from upstream-pr/741 into main 2026-11-23 01:14:40 +00:00
MrSkelee commented 2026-11-23 00:14:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MrSkelee on 2026-11-23T00:14:42Z.


Lowers 34 Zen 2 float, double, integer, and F16C conversion instructions across SSE, SSE2, and AVX (VEX.128) encodings with full native differential coverage.

Highlights

  • Instructions Lowered:
    • Packed XMM-to-XMM: cvtdq2ps, vcvtdq2ps, cvtdq2pd, vcvtdq2pd, cvtps2dq, vcvtps2dq, cvttps2dq, vcvttps2dq, cvtps2pd, vcvtps2pd, cvtpd2ps, vcvtpd2ps, cvtpd2dq, vcvtpd2dq, cvttpd2dq, vcvttpd2dq
    • Scalar XMM-to-XMM: cvtss2sd, vcvtss2sd, cvtsd2ss, vcvtsd2ss
    • Scalar GPR-to-XMM (32-bit & 64-bit): cvtsi2ss, vcvtsi2ss, cvtsi2sd, vcvtsi2sd
    • Scalar XMM-to-GPR (32-bit & 64-bit): cvtss2si, vcvtss2si, cvttss2si, vcvttss2si, cvtsd2si, vcvtsd2si, cvttsd2si, vcvttsd2si
    • Half-Precision F16C: vcvtph2ps, vcvtps2ph
  • Operand & Encoding Validation: Rejects invalid memory forms, 256-bit YMM width, and untracked registers with ValueError before register indexing.
  • Full 256-bit Vector State Validation: Verifies that legacy 128-bit XMM operations preserve the upper 128 bits of YMM, while VEX.128 writes zero them out.
  • GPR Return Verification: Validates 32-bit and 64-bit integer outputs directly against host Windows ABI returns.
  • Differential Suite: All 354 operations verified across native MASM execution and lifted C++ DLLs in both dev (/Od) and release (/O2) presets.

Verification

ctest --preset dev -R "cpu_aot_float_conversions" -V
ctest --preset release -R "cpu_aot_float_conversions" -V

Local results: 354/354 operations passed (0 failures).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6549652053 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/741). Originally posted by [MrSkelee](https://github.com/MrSkelee) on 2026-11-23T00:14:42Z. --- Lowers 34 Zen 2 float, double, integer, and F16C conversion instructions across SSE, SSE2, and AVX (VEX.128) encodings with full native differential coverage. ### Highlights - **Instructions Lowered**: - Packed XMM-to-XMM: `cvtdq2ps`, `vcvtdq2ps`, `cvtdq2pd`, `vcvtdq2pd`, `cvtps2dq`, `vcvtps2dq`, `cvttps2dq`, `vcvttps2dq`, `cvtps2pd`, `vcvtps2pd`, `cvtpd2ps`, `vcvtpd2ps`, `cvtpd2dq`, `vcvtpd2dq`, `cvttpd2dq`, `vcvttpd2dq` - Scalar XMM-to-XMM: `cvtss2sd`, `vcvtss2sd`, `cvtsd2ss`, `vcvtsd2ss` - Scalar GPR-to-XMM (32-bit & 64-bit): `cvtsi2ss`, `vcvtsi2ss`, `cvtsi2sd`, `vcvtsi2sd` - Scalar XMM-to-GPR (32-bit & 64-bit): `cvtss2si`, `vcvtss2si`, `cvttss2si`, `vcvttss2si`, `cvtsd2si`, `vcvtsd2si`, `cvttsd2si`, `vcvttsd2si` - Half-Precision F16C: `vcvtph2ps`, `vcvtps2ph` - **Operand & Encoding Validation**: Rejects invalid memory forms, 256-bit YMM width, and untracked registers with `ValueError` before register indexing. - **Full 256-bit Vector State Validation**: Verifies that legacy 128-bit XMM operations preserve the upper 128 bits of YMM, while VEX.128 writes zero them out. - **GPR Return Verification**: Validates 32-bit and 64-bit integer outputs directly against host Windows ABI returns. - **Differential Suite**: All 354 operations verified across native MASM execution and lifted C++ DLLs in both `dev` (/Od) and `release` (/O2) presets. ### Verification ```powershell ctest --preset dev -R "cpu_aot_float_conversions" -V ctest --preset release -R "cpu_aot_float_conversions" -V ``` Local results: 354/354 operations passed (0 failures).
upstream-sync closed this pull request 2026-11-24 06:44:34 +00:00
R0Y00 commented 2026-11-24 06:44:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T01:14:03Z.

Review: COMMENTED


Re-reviewed 2f4d918. The native AVX harness checks OS-enabled XMM/YMM state, F16C is gated separately, and VCVTPS2PH rejects immediates other than zero. Immediate 0 specifies round-to-nearest-even directly. The encoding that selects MXCSR is outside this profile. Both Windows jobs and Linux passed at this SHA. My requested changes are satisfied.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6015562908 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/741#pullrequestreview-6015562908). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T01:14:03Z. **Review:** COMMENTED --- Re-reviewed `2f4d918`. The native AVX harness checks OS-enabled XMM/YMM state, F16C is gated separately, and VCVTPS2PH rejects immediates other than zero. Immediate 0 specifies round-to-nearest-even directly. The encoding that selects MXCSR is outside this profile. Both Windows jobs and Linux passed at this SHA. My requested changes are satisfied.
R0Y00 commented 2026-11-24 06:48:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T00:30:44Z.


The decoded-operand checks cover the intended register forms. Two verification gaps remain. The test harness itself uses YMM instructions to seed and read the upper half, so check AVX plus OS-enabled XMM/YMM state before calling it. Gate the F16C exports separately so AVX-capable hosts without F16C still test the other conversions. VCVTPS2PH currently accepts every decoded immediate, but its native fixture exercises only immediate 0. Please limit the first profile to that rounding form or demonstrate the directed and MXCSR-controlled forms with a halfway input that distinguishes them.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7088409580 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/741#issuecomment-7088409580). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T00:30:44Z. --- The decoded-operand checks cover the intended register forms. Two verification gaps remain. The test harness itself uses YMM instructions to seed and read the upper half, so check AVX plus OS-enabled XMM/YMM state before calling it. Gate the F16C exports separately so AVX-capable hosts without F16C still test the other conversions. `VCVTPS2PH` currently accepts every decoded immediate, but its native fixture exercises only immediate 0. Please limit the first profile to that rounding form or demonstrate the directed and MXCSR-controlled forms with a halfway input that distinguishes them.
MrSkelee commented 2026-11-24 06:48:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MrSkelee on 2026-11-23T00:45:10Z.


Updated in 2f4d918:

  • AVX and OS state check: Added host_has_avx() verifying CPUID leaf 1 ECX bit 28, OSXSAVE bit 27, and _xgetbv(0) & 6ull == 6ull, returning CTest skip code 77 if unavailable.
  • F16C gating: Added host_has_f16c() check (CPUID leaf 1 ECX bit 29) to gate vcvtph2ps_op and vcvtps2ph_op so AVX hosts lacking F16C still execute and verify the other 44 conversions.
  • VCVTPS2PH immediate limit: Constrained vcvtps2ph to immediate8 == 0 (MXCSR rounding), rejecting non-zero rounding mode immediates with ValueError.
  • Rejection controls: Added rejection verification for vcvtps2ph xmm0, xmm1, 1 (c4 e3 79 1d c8 01).
  • All 354 operations verified passing locally on both dev (/Od) and release (/O2) presets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7088604706 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/741#issuecomment-7088604706). Originally posted by [MrSkelee](https://github.com/MrSkelee) on 2026-11-23T00:45:10Z. --- Updated in `2f4d918`: - **AVX and OS state check**: Added `host_has_avx()` verifying CPUID leaf 1 ECX bit 28, OSXSAVE bit 27, and `_xgetbv(0) & 6ull == 6ull`, returning CTest skip code 77 if unavailable. - **F16C gating**: Added `host_has_f16c()` check (CPUID leaf 1 ECX bit 29) to gate `vcvtph2ps_op` and `vcvtps2ph_op` so AVX hosts lacking F16C still execute and verify the other 44 conversions. - **VCVTPS2PH immediate limit**: Constrained `vcvtps2ph` to `immediate8 == 0` (MXCSR rounding), rejecting non-zero rounding mode immediates with `ValueError`. - **Rejection controls**: Added rejection verification for `vcvtps2ph xmm0, xmm1, 1` (`c4 e3 79 1d c8 01`). - All 354 operations verified passing locally on both `dev` (/Od) and `release` (/O2) presets.
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!735
No description provided.