cpu: lift memory-source forms of the AVX logical ops #1369

Merged
tedin7 merged 1 commit from upstream-pr/1376 into main 2026-11-24 10:10:58 +00:00
tedin7 commented 2026-11-24 09:42:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:42:18Z.


What

  • tools/cpu_avx_move_aot.py lifts the memory-source forms of vandpd, vandps, vandnpd, vandnps, vorpd, vorps, vxorpd and vxorps: (xmm, xmm, m128) and (ymm, ymm, m256) with the same flat [base + disp] operand the other memory forms accept (base rcx, rdx or r8). No new addressing mode: index/scale, RIP-relative, 32-bit address-size bases, segment prefixes and EVEX stay refused with the existing messages.
  • The memory operand is the last source: the result is op(register source, memory). vandn* inverts the register operand, never the memory one. The memory is read with the existing load128/load256 and combined by the existing LOGICAL_HELPERS on raw 64-bit words, so there is no NaN canonicalisation or float conversion. VEX.128 forms still zero bits 255:128.
  • The eight ops leave REGISTER_ONLY_AVX; the other 20 members are unchanged (vblend*, vextractf128, vinsertf128, vextractps, vinsertps, vperm2f128, vpermil*, vshuf*, vunpck*, vmovddup, vmovshdup, vmovsldup).
  • New fixture tests/cpu/avx_move_mem.asm/.def (16 exports) and tests/cpu/avx_move_mem_check.py, wired as cpu_aot_avx_move_mem (original and ALTER_MUT builds, exits 77 without AVX).
  • tests/cpu/avx_move_regs_check.py: the eight logical memory encodings were the "register-only with memory" negative controls; they are removed, and the PE-patched controls now use vshufps and vperm2f128 memory forms, which stay register-only. Counts drop from 30 to 22 unit memory controls.
  • tools/form_coverage.py maps the new fixture to the new test. docs/experiments.md is updated, including every sentence that listed the logical ops as register-only.

Why

The leaf translator refused vandps ymm0, ymm1, [rdx+disp] and the other seven ops with a memory source, so leaf functions that mask or merge straight from memory could not be lifted by it.

Tested

Windows (not run locally: MSVC/ML64 is not available here). Please run:

ctest --preset dev --no-tests=error -R '^cpu_aot_avx_move_(mem|regs)$' -V
ctest --preset release --no-tests=error -R '^cpu_aot_avx_move_(mem|regs)$' -V

Run on Linux:

  • The fixture was assembled with llvm-ml-19 (so the MASM syntax was accepted by an MASM-compatible assembler) and linked with lld-link-19, original and ALTER_MUT; the real translate() produced the C++; that was built with MinGW g++ at -O0 and -O2 and run under Wine next to the native DLL by a throwaway loader. The real check_differential ran on those results: 4,864 cases over 16 exports (all 256 pairs of 16 bit patterns including quiet and signaling NaNs, negative zero, all-ones, all-zero and differing upper lanes, plus 48 random cases per export, pointers shifted by 0, 1, 7 and 16 bytes) matched native, lifted and an independent bytewise model in both builds. The altered build matched its altered model and diverged from the unaltered result on all six mutated exports.
  • Mutated translations are caught: a lifted build with the vandn* operands swapped and one that keeps the register source's upper half in the VEX.128 result both failed the check.
  • The Linux-runnable part of the check passes on the built PE: 288 accepted memory forms, 19 unit rejection controls and 4 PE-patched rejection controls (EVEX masked and unmasked, index/scale, RIP-relative, 32-bit address-size base, rsp/rax/r9 bases, segment prefix, undefined source, nonvolatile destination, memory forms of five still register-only ops, vaddps memory).
  • avx_move_regs_check.py rejection part passes on a llvm-ml-19 build (71 unit and 11 PE-patched controls), and the C++ translated from all 150 existing avx_move_regs exports is byte-identical before and after this change.
  • py_compile on the touched Python, tests/form_coverage_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check pass.

Not run: the MSVC/ML64 build and the Windows ctest runs above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6578936101 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1376). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:42:18Z. --- ## What - `tools/cpu_avx_move_aot.py` lifts the memory-source forms of `vandpd`, `vandps`, `vandnpd`, `vandnps`, `vorpd`, `vorps`, `vxorpd` and `vxorps`: `(xmm, xmm, m128)` and `(ymm, ymm, m256)` with the same flat `[base + disp]` operand the other memory forms accept (base `rcx`, `rdx` or `r8`). No new addressing mode: index/scale, RIP-relative, 32-bit address-size bases, segment prefixes and EVEX stay refused with the existing messages. - The memory operand is the last source: the result is `op(register source, memory)`. `vandn*` inverts the register operand, never the memory one. The memory is read with the existing `load128`/`load256` and combined by the existing `LOGICAL_HELPERS` on raw 64-bit words, so there is no NaN canonicalisation or float conversion. VEX.128 forms still zero bits 255:128. - The eight ops leave `REGISTER_ONLY_AVX`; the other 20 members are unchanged (`vblend*`, `vextractf128`, `vinsertf128`, `vextractps`, `vinsertps`, `vperm2f128`, `vpermil*`, `vshuf*`, `vunpck*`, `vmovddup`, `vmovshdup`, `vmovsldup`). - New fixture `tests/cpu/avx_move_mem.asm`/`.def` (16 exports) and `tests/cpu/avx_move_mem_check.py`, wired as `cpu_aot_avx_move_mem` (original and `ALTER_MUT` builds, exits 77 without AVX). - `tests/cpu/avx_move_regs_check.py`: the eight logical memory encodings were the "register-only with memory" negative controls; they are removed, and the PE-patched controls now use `vshufps` and `vperm2f128` memory forms, which stay register-only. Counts drop from 30 to 22 unit memory controls. - `tools/form_coverage.py` maps the new fixture to the new test. `docs/experiments.md` is updated, including every sentence that listed the logical ops as register-only. ## Why The leaf translator refused `vandps ymm0, ymm1, [rdx+disp]` and the other seven ops with a memory source, so leaf functions that mask or merge straight from memory could not be lifted by it. ## Tested Windows (not run locally: MSVC/ML64 is not available here). Please run: ```powershell ctest --preset dev --no-tests=error -R '^cpu_aot_avx_move_(mem|regs)$' -V ctest --preset release --no-tests=error -R '^cpu_aot_avx_move_(mem|regs)$' -V ``` Run on Linux: - The fixture was assembled with `llvm-ml-19` (so the MASM syntax was accepted by an MASM-compatible assembler) and linked with `lld-link-19`, original and `ALTER_MUT`; the real `translate()` produced the C++; that was built with MinGW g++ at -O0 and -O2 and run under Wine next to the native DLL by a throwaway loader. The real `check_differential` ran on those results: 4,864 cases over 16 exports (all 256 pairs of 16 bit patterns including quiet and signaling NaNs, negative zero, all-ones, all-zero and differing upper lanes, plus 48 random cases per export, pointers shifted by 0, 1, 7 and 16 bytes) matched native, lifted and an independent bytewise model in both builds. The altered build matched its altered model and diverged from the unaltered result on all six mutated exports. - Mutated translations are caught: a lifted build with the `vandn*` operands swapped and one that keeps the register source's upper half in the VEX.128 result both failed the check. - The Linux-runnable part of the check passes on the built PE: 288 accepted memory forms, 19 unit rejection controls and 4 PE-patched rejection controls (EVEX masked and unmasked, index/scale, RIP-relative, 32-bit address-size base, `rsp`/`rax`/`r9` bases, segment prefix, undefined source, nonvolatile destination, memory forms of five still register-only ops, `vaddps` memory). - `avx_move_regs_check.py` rejection part passes on a `llvm-ml-19` build (71 unit and 11 PE-patched controls), and the C++ translated from all 150 existing `avx_move_regs` exports is byte-identical before and after this change. - `py_compile` on the touched Python, `tests/form_coverage_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` pass. Not run: the MSVC/ML64 build and the Windows ctest runs above.
tedin7 commented 2026-11-24 10:02:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:44:48Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit 028efdfe35c12ef6bfb7f3cf1a8c54927320847e:

  • Windows Python checks: tests/form_coverage_check.py ok (39.1s)
  • Debug (--preset dev):
    • Build (cpu_avx_move_mem_*, cpu_avx_move_regs_*): 3.49s (configure 1.61s)
    • Test (ctest --preset dev -R '^(cpu_aot_avx_move_mem|cpu_aot_avx_move_regs)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (cpu_aot_avx_move_regs 0.33s, cpu_aot_avx_move_mem 0.51s)
  • Release /O2 (--preset release):
    • Build (cpu_avx_move_mem_*, cpu_avx_move_regs_*): 1.39s (configure 1.60s)
    • Test (ctest --preset release -R '^(cpu_aot_avx_move_mem|cpu_aot_avx_move_regs)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (cpu_aot_avx_move_regs 0.30s, cpu_aot_avx_move_mem 0.54s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7127831600 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1376#issuecomment-7127831600). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:44:48Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit `028efdfe35c12ef6bfb7f3cf1a8c54927320847e`: - **Windows Python checks**: `tests/form_coverage_check.py` ok (`39.1s`) - **Debug (`--preset dev`)**: - Build (`cpu_avx_move_mem_*`, `cpu_avx_move_regs_*`): `3.49s` (configure `1.61s`) - Test (`ctest --preset dev -R '^(cpu_aot_avx_move_mem|cpu_aot_avx_move_regs)$' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`cpu_aot_avx_move_regs` `0.33s`, `cpu_aot_avx_move_mem` `0.51s`) - **Release `/O2` (`--preset release`)**: - Build (`cpu_avx_move_mem_*`, `cpu_avx_move_regs_*`): `1.39s` (configure `1.60s`) - Test (`ctest --preset release -R '^(cpu_aot_avx_move_mem|cpu_aot_avx_move_regs)$' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`cpu_aot_avx_move_regs` `0.30s`, `cpu_aot_avx_move_mem` `0.54s`)
chatgpt-codex-connector[bot commented 2026-11-24 10:02:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T09:44:56Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T09:48:09.503189Z 028efdf Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7127834450 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1376#issuecomment-7127834450). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T09:44:56Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"028efdfe35c12ef6bfb7f3cf1a8c54927320847e","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T09:48:09.503189Z">2026-11-24T09:48:09.503189Z</relative-time> | `028efdf` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
upstream-sync closed this pull request 2026-11-24 11:02:40 +00:00
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!1369
No description provided.