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

Closed
opened 2026-11-21 21:47:57 +00:00 by Leyukaka · 5 comments
Leyukaka commented 2026-11-21 21:47:57 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T21:47:57Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6534813042 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/314). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-21T21:47:57Z. --- ### 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._
R0Y00 commented 2026-11-24 06:48:05 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:57:18Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069836093 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/314#issuecomment-7069836093). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T21:57:18Z. --- 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.
MarlomMedeiros commented 2026-11-24 06:48:08 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-21T22:17:08Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070071642 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/314#issuecomment-7070071642). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-21T22:17:08Z. --- 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.
Leyukaka commented 2026-11-24 06:48:09 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T22:27:22Z.


@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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070193077 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/314#issuecomment-7070193077). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-21T22:27:22Z. --- @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._
MarlomMedeiros commented 2026-11-24 06:48:09 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-21T22:32:23Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070251950 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/314#issuecomment-7070251950). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-21T22:32:23Z. --- 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.
Leyukaka commented 2026-11-24 06:48:09 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T22:36:35Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070301064 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/314#issuecomment-7070301064). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-21T22:36:35Z. --- 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._
Sign in to join this conversation.
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#309
No description provided.