cpu: lift VEX.128 16-bit packed-integer leaf functions #314

Closed
opened 2026-11-26 21:42:21 +00:00 by github-bot · 5 comments
Owner

@⁠Leyukaka on GitHub · 2026-11-21 21:47 UTC · original

Problem

docs/coverage/x64_zen2.tsv lists 256 AVX forms. The only VEX forms in a fixture with a translation test are the seven in tests/cpu/heap_layout.asm: vmovd, vmovdqu, vmovups, vpaddd, vpsrldq, vpxor and vzeroupper. tools/ffx_version_query.py lowers them. No translator or open PR handles the 16-bit packed-integer forms:

  • vpaddw, vpsubw;
  • vpsraw, vpsllw;
  • vpunpcklbw, vpunpckhbw, vpunpcklwd, vpunpckhwd;
  • vpackuswb;
  • vpmaxsw, vpminsw;
  • vpmulhw, vpavgw.

Proposal

I'd like to take this group, as a new translator tools/cpu_vex_aot.py for Windows x64 leaf functions that use VEX.128 packed-integer forms on 16-byte buffers. The signature is fixed: RCX and RDX point to two 16-byte inputs, R8 to a 16-byte output, and there is no return value.

  • Generated C++. Each XMM register is a 16-byte lane array. Each form becomes an explicit per-lane loop with the ISA's wraparound, saturation, arithmetic-shift and rounding rules. ffx_version_query.py emits SSE intrinsics for its dword forms; this translator avoids them, so that the reference spells out the lane semantics instead of relying on the host compiler's mapping.
  • Supported forms: the word forms above with register or memory sources, vmovdqu/vmovdqa loads and stores, vpxor/vpand/vpor and vzeroupper. Any other instruction, a VEX.256 form or another operand kind is rejected with its RVA, as the existing translators do.
  • Fixture. A source-built MASM fixture with a few functions that chain these forms, for example unpack, multiply-high, average, then saturating pack. It is registered in CPU_FIXTURES.

Interfaces touched: a new tool and a new fixture, plus the registration points in CMakeLists.txt and tools/form_coverage.py, a docs/experiments.md section and a README.md row. The registration points are shared with:

I'll rebase around whichever lands first. No translator code is shared with any of them.

Alternatives

  • Extend ffx_version_query.py. Its vector model is three fixed registers with dword lanes, which suits its call site and the integer fixtures that reuse lower. Word lanes, saturation and unpack/pack would widen that model for every caller.
  • Use intrinsics in the generated code. That would test the compiler's mapping rather than the lane semantics.

Verification

The CTest test calls the native and lifted DLLs on the same 4096 input pairs. These include:

  • every pairing of the saturation edges 0x7fff, 0x8000, 0x0000, 0xffff, 0x00ff and 0xff00;
  • shift counts 0, 1, 15 and 16;
  • rounding ties for vpavgw;
  • random lanes.

It compares the 16 output bytes and the guard bytes around them. A rebuilt fixture with vpsraw turned into vpsrlw must fail the comparison. Translation must reject a VEX.256 form and an unsupported mnemonic.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-21 21:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/314) ### Problem `docs/coverage/x64_zen2.tsv` lists 256 AVX forms. The only VEX forms in a fixture with a translation test are the seven in `tests/cpu/heap_layout.asm`: `vmovd`, `vmovdqu`, `vmovups`, `vpaddd`, `vpsrldq`, `vpxor` and `vzeroupper`. `tools/ffx_version_query.py` lowers them. No translator or open PR handles the 16-bit packed-integer forms: - `vpaddw`, `vpsubw`; - `vpsraw`, `vpsllw`; - `vpunpcklbw`, `vpunpckhbw`, `vpunpcklwd`, `vpunpckhwd`; - `vpackuswb`; - `vpmaxsw`, `vpminsw`; - `vpmulhw`, `vpavgw`. ### Proposal I'd like to take this group, as a new translator `tools/cpu_vex_aot.py` for Windows x64 leaf functions that use VEX.128 packed-integer forms on 16-byte buffers. The signature is fixed: RCX and RDX point to two 16-byte inputs, R8 to a 16-byte output, and there is no return value. - **Generated C++.** Each XMM register is a 16-byte lane array. Each form becomes an explicit per-lane loop with the ISA's wraparound, saturation, arithmetic-shift and rounding rules. `ffx_version_query.py` emits SSE intrinsics for its dword forms; this translator avoids them, so that the reference spells out the lane semantics instead of relying on the host compiler's mapping. - **Supported forms:** the word forms above with register or memory sources, `vmovdqu`/`vmovdqa` loads and stores, `vpxor`/`vpand`/`vpor` and `vzeroupper`. Any other instruction, a VEX.256 form or another operand kind is rejected with its RVA, as the existing translators do. - **Fixture.** A source-built MASM fixture with a few functions that chain these forms, for example unpack, multiply-high, average, then saturating pack. It is registered in `CPU_FIXTURES`. Interfaces touched: a new tool and a new fixture, plus the registration points in `CMakeLists.txt` and `tools/form_coverage.py`, a `docs/experiments.md` section and a `README.md` row. The registration points are shared with: - #269 (scalar SSE/SSE2); - #286, #287, #289, #291 and #309 (integer lowering); - the AVX2 register-domain work announced in a comment on #269. I'll rebase around whichever lands first. No translator code is shared with any of them. ### Alternatives - **Extend `ffx_version_query.py`.** Its vector model is three fixed registers with dword lanes, which suits its call site and the integer fixtures that reuse `lower`. Word lanes, saturation and unpack/pack would widen that model for every caller. - **Use intrinsics in the generated code.** That would test the compiler's mapping rather than the lane semantics. ### Verification The CTest test calls the native and lifted DLLs on the same 4096 input pairs. These include: - every pairing of the saturation edges 0x7fff, 0x8000, 0x0000, 0xffff, 0x00ff and 0xff00; - shift counts 0, 1, 15 and 16; - rounding ties for `vpavgw`; - random lanes. It compares the 16 output bytes and the guard bytes around them. A rebuilt fixture with `vpsraw` turned into `vpsrlw` must fail the comparison. Translation must reject a VEX.256 form and an unsupported mnemonic. _AI-assisted._
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:42:21 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 21:57 UTC · original

The separate bounded VEX.128 integer leaf fixture is approved. Its ABI is specific to this profile: RCX and RDX point to 16-byte inputs, R8 points to a 16-byte output, and no return bits are guaranteed. Document alignment and allowed aliases; cover read-before-write order for supported alias cases and test vmovdqa under its alignment precondition. Reject unmodeled forms and widths. Verify lane-boundary values, guard bytes and mutation controls bit-for-bit. Reuse existing decoding/range-reading logic where appropriate and coordinate the registration sites with #269.

**@⁠R0Y00** on GitHub · 2026-11-21 21:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/314#issuecomment-7069836093) The separate bounded VEX.128 integer leaf fixture is approved. Its ABI is specific to this profile: RCX and RDX point to 16-byte inputs, R8 points to a 16-byte output, and no return bits are guaranteed. Document alignment and allowed aliases; cover read-before-write order for supported alias cases and test `vmovdqa` under its alignment precondition. Reject unmodeled forms and widths. Verify lane-boundary values, guard bytes and mutation controls bit-for-bit. Reuse existing decoding/range-reading logic where appropriate and coordinate the registration sites with #269.
Author
Owner

@⁠MarlomMedeiros on GitHub · 2026-11-21 22:17 UTC · original

Coordination note: working the broader AVX packed-integer slice now — all ~118 VEX.128 vp* forms plus vmpsadbw/vzeroall/vzeroupper in a dedicated tools/cpu_avx_int_aot.py (same leaf ABI and Vec256 model as the AVX2 translator in #323, disjoint file from cpu_sse_aot.py so #269 registration is unaffected). This issue's approved 16-bit profile lands inside that coverage; will cite #314 in the PR and keep the alias/alignment and read-before-write order guidance.

**@⁠MarlomMedeiros** on GitHub · 2026-11-21 22:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/314#issuecomment-7070071642) Coordination note: working the broader AVX packed-integer slice now — all ~118 VEX.128 vp* forms plus vmpsadbw/vzeroall/vzeroupper in a dedicated tools/cpu_avx_int_aot.py (same leaf ABI and Vec256 model as the AVX2 translator in #323, disjoint file from cpu_sse_aot.py so #269 registration is unaffected). This issue's approved 16-bit profile lands inside that coverage; will cite #314 in the PR and keep the alias/alignment and read-before-write order guidance.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-21 22:27 UTC · original

@⁠MarlomMedeiros, thanks for the note. Here is where this issue stands:

  • #325 is open, with the scope approved above: tools/cpu_vex_aot.py and the cpu_aot_vex_words fixture for the 16-bit forms.
  • A follow-up is ready locally, on the same tool and fixture, and not opened yet. It covers:
    • vpavgb, vpshufb and vpmaddubsw;
    • vpaddsw, vpmullw and vpandn;
    • vpsrad, vpsrldq, vpslldq and vpshufd;
    • vmovups/vmovaps;
    • vmovq/vmovd, with 8- and 4-byte loads and stores.

To avoid two translators for the same forms, could cpu_avx_int_aot.py leave these out and take the remaining vp* forms? If you would rather cover everything in one tool, say so, and I'll hold the follow-up until we agree which lands first.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-21 22:27 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/314#issuecomment-7070193077) @⁠MarlomMedeiros, thanks for the note. Here is where this issue stands: - **#325 is open**, with the scope approved above: `tools/cpu_vex_aot.py` and the `cpu_aot_vex_words` fixture for the 16-bit forms. - **A follow-up is ready locally**, on the same tool and fixture, and not opened yet. It covers: - `vpavgb`, `vpshufb` and `vpmaddubsw`; - `vpaddsw`, `vpmullw` and `vpandn`; - `vpsrad`, `vpsrldq`, `vpslldq` and `vpshufd`; - `vmovups`/`vmovaps`; - `vmovq`/`vmovd`, with 8- and 4-byte loads and stores. To avoid two translators for the same forms, could `cpu_avx_int_aot.py` leave these out and take the remaining `vp*` forms? If you would rather cover everything in one tool, say so, and I'll hold the follow-up until we agree which lands first. _AI-assisted._
Author
Owner

@⁠MarlomMedeiros on GitHub · 2026-11-21 22:32 UTC · original

Agreed on the split — you were in the VEX.128 space first. cpu_avx_int_aot.py and cpu_avx_move_aot.py will leave the whole #325 scope plus your listed follow-up to cpu_vex_aot.py:

#325 already covers: vmovdqa, vmovdqu, vpackuswb, vpaddd, vpaddw, vpand, vpor, vpxor, vpavgw, vpmaxsw, vpminsw, vpmulhw, vpsllw, vpsraw, vpsrlw, vpsubw, vpunpckhbw, vpunpckhwd, vpunpcklbw, vpunpcklwd, vzeroupper
Follow-up adds: vpavgb, vpshufb, vpmaddubsw, vpaddsw, vpmullw, vpandn, vpsrad, vpsrldq, vpslldq, vpshufd, vmovups, vmovaps, vmovq, vmovd

Our tools take the remaining vp* and AVX bit-move forms (~139) and will explicitly reject the carved-out set so there is exactly one translator per form and no double-counted coverage rows. If your follow-up scope changes, ping the thread and I will adjust the exclusion list before opening.

**@⁠MarlomMedeiros** on GitHub · 2026-11-21 22:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/314#issuecomment-7070251950) Agreed on the split — you were in the VEX.128 space first. cpu_avx_int_aot.py and cpu_avx_move_aot.py will leave the whole #325 scope plus your listed follow-up to cpu_vex_aot.py: #325 already covers: vmovdqa, vmovdqu, vpackuswb, vpaddd, vpaddw, vpand, vpor, vpxor, vpavgw, vpmaxsw, vpminsw, vpmulhw, vpsllw, vpsraw, vpsrlw, vpsubw, vpunpckhbw, vpunpckhwd, vpunpcklbw, vpunpcklwd, vzeroupper Follow-up adds: vpavgb, vpshufb, vpmaddubsw, vpaddsw, vpmullw, vpandn, vpsrad, vpsrldq, vpslldq, vpshufd, vmovups, vmovaps, vmovq, vmovd Our tools take the remaining vp* and AVX bit-move forms (~139) and will explicitly reject the carved-out set so there is exactly one translator per form and no double-counted coverage rows. If your follow-up scope changes, ping the thread and I will adjust the exclusion list before opening.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-21 22:36 UTC · original

Thanks, that split works. One correction to the list: vpaddd is not in #325. cpu_vex_aot.py rejects it, and the test uses a vpaddw patched into vpaddd as a rejection control, so please keep vpaddd in your tools. Everything else in both lists matches. I'll open the follow-up after #325 lands, and ping here if its scope changes.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-21 22:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/314#issuecomment-7070301064) Thanks, that split works. One correction to the list: `vpaddd` is not in #325. `cpu_vex_aot.py` rejects it, and the test uses a `vpaddw` patched into `vpaddd` as a rejection control, so please keep `vpaddd` in your tools. Everything else in both lists matches. I'll open the follow-up after #325 lands, and ping here if its scope changes. _AI-assisted._
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/R0Y00--Xbox2Windows#314
No description provided.