cpu: lift VEX.128 16-bit packed-integer leaf functions #320
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/325"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T22:15:19Z.
Change
Fixes #314 within the scope approved there.
tools/cpu_vex_aot.pytranslates Windows x64 leaf functions that use VEX.128 16-bit packed-integer forms into per-lane C++:vpaddw,vpsubw,vpmaxsw,vpminsw,vpmulhwandvpavgw;vpsraw,vpsllwandvpsrlwwith an immediate count;vpackuswb;vmovdqu/vmovdqa,vpxor/vpand/vporandvzeroupper.The 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 defined. Memory operands must be exactly
[RCX],[RDX]or[R8]with a 16-byte access, and stores go only to[R8]. Only VEX encodings and the volatile XMM0-XMM5 are accepted. Unmodelled forms, EVEX forms such as a maskedvpaddw, legacy SSE encodings, XMM6-XMM15, VEX.256 operands and other operand shapes are rejected with their RVA. Decoding uses iced-x86, and function bounds come fromcpu_leaf_aot.bounded_code.The module docstring and the new
docs/experiments.mdsection document alignment and aliases:vmovdqutakes any address.vmovdqaneeds 16-byte alignment, a precondition the generated C++ does not check.Registration points shared with #269, #323 (AVX2) and #286, #287, #289, #291 and #309: one
CPU_FIXTURESentry intools/form_coverage.pyand one block inCMakeLists.txtnext tocpu_heap_layout. I will rebase around whichever lands first.Verification
On
2ff1c14(branch on6ee2406), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14:The full suite passes 145 of 145 tests.
Hand-encoded rejections. Eight bodies are each checked against their iced disassembly before translation, so a wrong encoding fails the test instead of passing it:
vpaddw xmm0{k1};paddw;xmm6as destination and as source;[rcx+10h]and[rax];[rcx];vpsrawwith an XMM count.Inputs. Each call runs in one 16-byte-aligned arena where the inputs and the output are separated by 0xcc guard zones. The whole arena is compared. The 4096 pairs are:
Arithmetic shifts use counts 1, 15 and 16, left shifts 1, 2 and 16, and logical right shifts 0, 15 (in the control build) and 16.
Mutations. Sixteen translator mutations each fail the test:
vpavgwwithout rounding;vpmulhwkeeping bit 15;vpsrawcounts above 15 not clamped;vpsllwandvpsrlwcounts above 15 not cleared;vpackuswbwithout saturation;vpunpckhbwandvpunpckhwdreading the low half;vpmaxswcomparing unsigned;Only the alias checks catch the last two.
Evidence and follow-up
The fixture is source-built MASM. The fixture uses only XMM0-XMM5, so it never touches the nonvolatile XMM registers of the calling process. The shift-count form with an XMM count operand and the other AVX word forms, such as
vpaddsw,vpmulhuwandvpcmpeqw, are rejected and left for follow-ups.Checklist
AI-assisted.