cpu: lower 51 vector shuffle, unpacking, and move instructions #680

Merged
MrSkelee merged 2 commits from upstream-pr/686 into main 2026-11-22 22:38:12 +00:00
MrSkelee commented 2026-11-22 20:01:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MrSkelee on 2026-11-22T20:01:10Z.


Summary

Lowers 51 vector shuffle, unpacking, and move instructions across both legacy SSE and VEX.128 encodings with full native differential coverage.

Highlights

  • Full 256-bit Vector State Validation: Verifies that legacy 128-bit XMM writes preserve the upper 128 bits of YMM, while VEX.128 writes zero them out.
  • Aliased Operands: Covers in-place and aliased register configurations (e.g. xmm0, xmm0, xmm1) and identical pointer sources.
  • Differential Suite: All 255 operations verified across native execution and lifted C++ DLLs in both dev and /O2 release modes.

Verification

ctest --preset dev -R "cpu_aot_float_shuffles" -V
ctest --preset release -R "cpu_aot_float_shuffles" -V
  • Local results: 255/255 operations passed (0 failures).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6547087021 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/686). Originally posted by [MrSkelee](https://github.com/MrSkelee) on 2026-11-22T20:01:10Z. --- ### Summary Lowers 51 vector shuffle, unpacking, and move instructions across both legacy SSE and VEX.128 encodings with full native differential coverage. ### Highlights - **Full 256-bit Vector State Validation**: Verifies that legacy 128-bit XMM writes preserve the upper 128 bits of YMM, while VEX.128 writes zero them out. - **Aliased Operands**: Covers in-place and aliased register configurations (e.g. `xmm0, xmm0, xmm1`) and identical pointer sources. - **Differential Suite**: All 255 operations verified across native execution and lifted C++ DLLs in both `dev` and `/O2` release modes. ### Verification ```powershell ctest --preset dev -R "cpu_aot_float_shuffles" -V ctest --preset release -R "cpu_aot_float_shuffles" -V ``` - Local results: 255/255 operations passed (0 failures).
upstream-sync closed this pull request 2026-11-24 06:44:19 +00:00
R0Y00 commented 2026-11-24 06:44:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T20:39:06Z.

Review: CHANGES_REQUESTED


Thanks for putting this instruction inventory together. There are useful candidates here. Please split out the float-shuffle family as the first focused PR so we can review and land the parts with a native differential.

  • Both Windows builds fail while generating cpu_float_shuffles_lifted.cpp. The packed shuffle branch in ffx_version_query.py uses is_vex before defining it for the current instruction. Derive it from the current instruction and test both behaviors where supported: a legacy XMM write preserves the high half, and a VEX.128 write clears it. Include an aliased operand and compare the full vector bits. Release log
  • Remove the RECORD_ONLY mnemonic lists from the passing coverage fixtures. In integer_system_stack.asm and x87_extended.asm the only exported function performs integer addition. A pass of that dummy cannot verify the instructions hidden under RECORD_ONLY. Drop the 948/948 claim from this PR until the corresponding forms have source-built native/AOT comparisons or another applicable coverage test with an observable result.
  • Please compare the packed FMA work with #349, #649 and #677 before submitting it separately. A focused follow-up can keep the new cases those PRs do not exercise. Keep XSAVE/FXRSTOR and extended x87 state separate, where the saved/restored state and feature gates can be reviewed directly.

Once the first slice is on current main, we can review its actual coverage and both Windows jobs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6014418822 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/686#pullrequestreview-6014418822). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T20:39:06Z. **Review:** CHANGES_REQUESTED --- Thanks for putting this instruction inventory together. There are useful candidates here. Please split out the float-shuffle family as the first focused PR so we can review and land the parts with a native differential. - Both Windows builds fail while generating `cpu_float_shuffles_lifted.cpp`. The packed shuffle branch in `ffx_version_query.py` uses `is_vex` before defining it for the current instruction. Derive it from the current instruction and test both behaviors where supported: a legacy XMM write preserves the high half, and a VEX.128 write clears it. Include an aliased operand and compare the full vector bits. [Release log](https://github.com/R0Y00/Xbox2Windows/actions/runs/45066307353/job/137343115416) - Remove the `RECORD_ONLY` mnemonic lists from the passing coverage fixtures. In `integer_system_stack.asm` and `x87_extended.asm` the only exported function performs integer addition. A pass of that dummy cannot verify the instructions hidden under `RECORD_ONLY`. Drop the 948/948 claim from this PR until the corresponding forms have source-built native/AOT comparisons or another applicable coverage test with an observable result. - Please compare the packed FMA work with #349, #649 and #677 before submitting it separately. A focused follow-up can keep the new cases those PRs do not exercise. Keep XSAVE/FXRSTOR and extended x87 state separate, where the saved/restored state and feature gates can be reviewed directly. Once the first slice is on current main, we can review its actual coverage and both Windows jobs.
R0Y00 commented 2026-11-24 06:44:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T22:37:53Z.

Review: COMMENTED


Re-reviewed the final 64c1f55 candidate. The earlier EXTRQ and RECORD_ONLY scope was removed; unproven aligned memory moves are refused, the VEX self-copy preserves its low half, and the existing heap-layout lowering keeps its XMM representation. The direct MASM/MSVC comparison passed 357 cases and the heap-layout fixture at both /Od and /O2. GitHub run 45077941633 passed both Windows jobs plus the two Linux checks on this exact head. My requested changes are satisfied for this focused shuffle, unpacking, move and estimate slice.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6014899047 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/686#pullrequestreview-6014899047). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T22:37:53Z. **Review:** COMMENTED --- Re-reviewed the final `64c1f55` candidate. The earlier EXTRQ and RECORD_ONLY scope was removed; unproven aligned memory moves are refused, the VEX self-copy preserves its low half, and the existing heap-layout lowering keeps its XMM representation. The direct MASM/MSVC comparison passed 357 cases and the heap-layout fixture at both `/Od` and `/O2`. GitHub run `45077941633` passed both Windows jobs plus the two Linux checks on this exact head. My requested changes are satisfied for this focused shuffle, unpacking, move and estimate slice.
R0Y00 commented 2026-11-24 06:48:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T21:15:20Z.


The updated head 0d79ade now gets past fixture generation. Both Windows jobs are still red. The new first mismatch is cpu_aot_simd_strings_misc / extrq_reg_op: native aede0000000000000000000000000000, lifted d8de40aede0000000000000000000000. The low result already differs. Please keep EXTRQ in its own follow-up with an independently checked register control and a CPU capability check, so it does not block review of the float-shuffle slice. The RECORD_ONLY fixtures and coverage claim still need the changes in the earlier review. CI

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7085909133 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/686#issuecomment-7085909133). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T21:15:20Z. --- The updated head 0d79ade now gets past fixture generation. Both Windows jobs are still red. The new first mismatch is cpu_aot_simd_strings_misc / extrq_reg_op: native aede0000000000000000000000000000, lifted d8de40aede0000000000000000000000. The low result already differs. Please keep EXTRQ in its own follow-up with an independently checked register control and a CPU capability check, so it does not block review of the float-shuffle slice. The RECORD_ONLY fixtures and coverage claim still need the changes in the earlier review. [CI](https://github.com/R0Y00/Xbox2Windows/actions/runs/45068471433)
R0Y00 commented 2026-11-24 06:48:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T21:26:29Z.


Thanks for splitting out the float shuffles. At 07e5186, cpu_aot_float_shuffles passes in both Windows jobs. The old cpu_aot_heap_layout now fails in both. Its slot_probe has VMOVDQU, VPSRLDQ, VPADDD, and VMOVD. The new VPSRLDQ classification makes has_wide true even for that existing XMM path, so some instructions can use wide* while others use xmm*. Please keep each translated function on one register representation and preserve the existing heap path. One additional concrete alias case to cover is vmovaps xmm0,xmm0 after a nonzero YMM seed: the low 16 bytes must survive and the high 16 bytes must clear. The new register-copy branch currently clears the destination before reading the aliased source. Please rerun both focused CTests in both presets. CI

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086052093 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/686#issuecomment-7086052093). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T21:26:29Z. --- Thanks for splitting out the float shuffles. At `07e5186`, `cpu_aot_float_shuffles` passes in both Windows jobs. The old `cpu_aot_heap_layout` now fails in both. Its `slot_probe` has `VMOVDQU`, `VPSRLDQ`, `VPADDD`, and `VMOVD`. The new `VPSRLDQ` classification makes `has_wide` true even for that existing XMM path, so some instructions can use `wide*` while others use `xmm*`. Please keep each translated function on one register representation and preserve the existing heap path. One additional concrete alias case to cover is `vmovaps xmm0,xmm0` after a nonzero YMM seed: the low 16 bytes must survive and the high 16 bytes must clear. The new register-copy branch currently clears the destination before reading the aliased source. Please rerun both focused CTests in both presets. [CI](https://github.com/R0Y00/Xbox2Windows/actions/runs/45070858729)
MrSkelee commented 2026-11-24 06:48:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MrSkelee on 2026-11-22T21:48:27Z.


Updated in 411852b:

  • Single register representation: Restricted has_wide so has_xmm_math forces has_wide = False, preserving the existing __m128i path and intrinsics cleanly for slot_probe.
  • In-place aliasing: Fixed the register copy lowering to clear upper bits via memset(dst.data() + 16, 0, 16) without touching the low 16 bytes when dst == src. Added explicit vmovaps xmm0, xmm0 test after a nonzero YMM seed in float_shuffles.asm.
  • Focused test verification:
    • ctest --preset dev -R "(cpu_aot_float_shuffles|cpu_aot_heap_layout)" -V -> 2/2 passed
    • ctest --preset release -R "(cpu_aot_float_shuffles|cpu_aot_heap_layout)" -V -> 2/2 passed
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086328298 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/686#issuecomment-7086328298). Originally posted by [MrSkelee](https://github.com/MrSkelee) on 2026-11-22T21:48:27Z. --- Updated in 411852b: - **Single register representation**: Restricted `has_wide` so `has_xmm_math` forces `has_wide = False`, preserving the existing `__m128i` path and intrinsics cleanly for `slot_probe`. - **In-place aliasing**: Fixed the register copy lowering to clear upper bits via `memset(dst.data() + 16, 0, 16)` without touching the low 16 bytes when `dst == src`. Added explicit `vmovaps xmm0, xmm0` test after a nonzero YMM seed in `float_shuffles.asm`. - **Focused test verification**: - `ctest --preset dev -R "(cpu_aot_float_shuffles|cpu_aot_heap_layout)" -V` -> 2/2 passed - `ctest --preset release -R "(cpu_aot_float_shuffles|cpu_aot_heap_layout)" -V` -> 2/2 passed
R0Y00 commented 2026-11-24 06:48:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T21:58:14Z.


The 411852b revision addresses the heap-layout regression and the VEX self-copy case. One more scope issue before merge: the new MOVAPD/MOVDQA/VMOVAPS/VMOVAPD/VMOVDQA memory branches emit plain memcpy, so the current fixture only demonstrates the aligned case. Please separate register-only moves from aligned memory forms. For this PR, either reject the aligned memory forms that have no checked alignment premise, or add that premise explicitly and verify the misaligned native/AOT behavior in a guarded control. Keep the unaligned MOVUPS/MOVUPD/VMOVDQU cases, the new self-copy, and cpu_aot_heap_layout.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086450954 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/686#issuecomment-7086450954). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T21:58:14Z. --- The `411852b` revision addresses the heap-layout regression and the VEX self-copy case. One more scope issue before merge: the new MOVAPD/MOVDQA/VMOVAPS/VMOVAPD/VMOVDQA memory branches emit plain `memcpy`, so the current fixture only demonstrates the aligned case. Please separate register-only moves from aligned memory forms. For this PR, either reject the aligned memory forms that have no checked alignment premise, or add that premise explicitly and verify the misaligned native/AOT behavior in a guarded control. Keep the unaligned MOVUPS/MOVUPD/VMOVDQU cases, the new self-copy, and `cpu_aot_heap_layout`.
MrSkelee commented 2026-11-24 06:48:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MrSkelee on 2026-11-22T22:11:14Z.


Updated in e22289d:

  • Separated register moves from memory: Limited memory moves to unaligned forms (MOVUPS/MOVUPD/VMOVDQU). Aligned memory forms without alignment premises are rejected.
  • Register fixtures: Converted movapd_op and movdqa_op in float_shuffles.asm to register-only operations (movapd xmm0, xmm1 and movdqa xmm0, xmm1).
  • Retained: All unaligned cases, vmovaps xmm0, xmm0 self-copy, and cpu_aot_heap_layout.
  • Verified: Both cpu_aot_float_shuffles and cpu_aot_heap_layout pass in dev and release presets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086621241 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/686#issuecomment-7086621241). Originally posted by [MrSkelee](https://github.com/MrSkelee) on 2026-11-22T22:11:14Z. --- Updated in e22289d: - **Separated register moves from memory**: Limited memory moves to unaligned forms (`MOVUPS`/`MOVUPD`/`VMOVDQU`). Aligned memory forms without alignment premises are rejected. - **Register fixtures**: Converted `movapd_op` and `movdqa_op` in `float_shuffles.asm` to register-only operations (`movapd xmm0, xmm1` and `movdqa xmm0, xmm1`). - **Retained**: All unaligned cases, `vmovaps xmm0, xmm0` self-copy, and `cpu_aot_heap_layout`. - **Verified**: Both `cpu_aot_float_shuffles` and `cpu_aot_heap_layout` pass in dev and release presets.
legacy-code-archaeologist commented 2026-11-24 06:48:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T22:25:01Z.


Checked the current head e22289d on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, dev preset. It merges cleanly with main.

ctest --preset dev --no-tests=error -R "^cpu_" -j 4 --output-on-failure
100% tests passed, 0 tests failed out of 122

The only skip is the usual cpu_aot_crypto_sha capability skip, because this CPU has no SHA extensions. cpu_aot_heap_layout and cpu_aot_float_shuffles both pass here. This head no longer contains an EXTRQ case, so the SSE4a-only form, which Intel CPUs lack, is not exercised on this host.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086799671 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/686#issuecomment-7086799671). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-22T22:25:01Z. --- Checked the current head `e22289d` on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, `dev` preset. It merges cleanly with `main`. ```text ctest --preset dev --no-tests=error -R "^cpu_" -j 4 --output-on-failure 100% tests passed, 0 tests failed out of 122 ``` The only skip is the usual `cpu_aot_crypto_sha` capability skip, because this CPU has no SHA extensions. `cpu_aot_heap_layout` and `cpu_aot_float_shuffles` both pass here. This head no longer contains an EXTRQ case, so the SSE4a-only form, which Intel CPUs lack, is not exercised on this host. AI-assisted (Claude Code).
R0Y00 commented 2026-11-24 06:48:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T22:34:45Z.


I pushed 64c1f55 after checking the aligned-memory restriction in your update. RCP and RSQRT now use the corresponding host SSE estimate instructions. This preserves the measured low-lane bits and special-value behavior that a float divide or square root followed by a tolerance check could miss. The patch also restores the legacy XMM load path when there is no VMOVD, and rejects aligned memory moves in the fixture controls. On local Windows, MASM native vs. MSVC lifted passed all 357 shuffle/estimate comparisons and the existing heap-layout fixture at both /Od and /O2. Waiting for both Windows CI jobs at the new SHA.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086921992 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/686#issuecomment-7086921992). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T22:34:45Z. --- I pushed `64c1f55` after checking the aligned-memory restriction in your update. RCP and RSQRT now use the corresponding host SSE estimate instructions. This preserves the measured low-lane bits and special-value behavior that a float divide or square root followed by a tolerance check could miss. The patch also restores the legacy XMM load path when there is no `VMOVD`, and rejects aligned memory moves in the fixture controls. On local Windows, MASM native vs. MSVC lifted passed all 357 shuffle/estimate comparisons and the existing heap-layout fixture at both `/Od` and `/O2`. Waiting for both Windows CI jobs at the new SHA.
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!680
No description provided.