cpu: add AVX2 leaf AOT translator covering all 28 forms #318
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/323"
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 MarlomMedeiros on 2026-11-21T22:07:02Z.
Summary
Adds a standalone CPU AOT translator (
tools/cpu_avx2_aot.py) that lifts bounded straight-line Windows x64 leaf functions covering all 28 of 28 forms indocs/coverage/x64_zen2.tsvgroupAVX2, with a source-built MASM fixture, three-way differential test suite (native MASM DLL / lifted C++ / independent Python ISA reference),PAGE_NOACCESSfault-suppression controls, and form coverage assertions.Scope
vbroadcasti128(m128source),vextracti128,vinserti128,vperm2i128vpbroadcastb,vpbroadcastw,vpbroadcastd,vpbroadcastqvpermd,vpermpd,vpermps,vpermqvpblendd(XMM and YMM)vpsllvd,vpsllvq,vpsravd,vpsrlvd,vpsrlvqvgatherdps,vgatherdpd,vgatherqps,vgatherqpd,vpgatherdd,vpgatherdq,vpgatherqd,vpgatherqqacrossvm32x/vm32y/vm64x/vm64yvpmaskmovd,vpmaskmovqload and store formsvmovdqu(128/256-bit flat load, store, register copy),vzeroupper, terminalretState model and memory semantics
ymm0..ymm5modeled as a portablestruct Vec256 { std::uint64_t q[4]; }value type rather than MSVC AVX2 intrinsics: generated C++ builds with default x64 flags (no/arch:AVX2) and avoids C++ UB on shift counts>= 32/>= 64.if-guarded loads (fault suppression), sign-extended 32-bit indices, SIB scales{1,2,4,8}, masked-off lanes preserve prior destination value, upper destination bits zeroed beyond the gathered element count, and the 256-bit mask register reads as zero afterwards.vpmaskmovloads zero masked-off lanes (unlike gathers) and leave the mask register unchanged; stores write only MSB-set lanes.#UD), illegal VSIB scales, non-argument/32-bit/rspbases, RIP-relative or GPR-indexed operands, undefined vector register reads, memory operands on the 17 register-only forms, EVEX encodings, prefixes, nonvolatilexmm6..xmm15, branches and out-of-scope instructions.Measured results
Tested at commit
0c4cc3eon Windows 11 (10.0.26300.0), AMD Ryzen 7 5800X3D, MSVCcl19.52.37029 x64,ml6414.52.37029.0, Python 3.14.10:cpu_aot_avx2_regs: passed. 1,120 differential cases (772 register-domain + 348 memory-domain across 68 exports, guarded source/output buffers) plus 34VirtualAlloc/PAGE_NOACCESSguard-page fault-suppression cases matched native MASM, lifted C++ and independent Python reference bit-for-bit.ALTER_IMMbuilds diverge onop_perm2i128_mix(14),op_permq(14),op_pblendd_ymm(16),op_gatherdps_ymm(12),op_pmaskmovd_load_ymm(10); output-mutation control caught; 59 unit rejection controls, 4 invalid-scale checks (0/3/5/16) and 9 PE-patched end-to-end rejections pass.ctest --preset dev --no-tests=error -R '^cpu_' -E '_hardware$'-> 40/40 passed, 0 skipped.tests/form_coverage_check.pypassed:avx2_regs.asmaccounts for all 28/28AVX2forms.tests/docs_links_check.pyandtests/bidi_controls_check.pypassed.Not covered
Memory operands on the 17 register-only AVX2 forms, control flow or calls mixed with AVX2 state, nonvolatile
XMM6..XMM15save/restore prologues, and title CPU code execution remain outside this change.Imported from R0Y00/Xbox2Windows. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-21T22:07:16Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T22:35:27Z.
A coverage note from reading the diff at
0c4cc3e, without building it.op_movdqu_copy128is the only XMM register-to-register copy in the fixture. It cannot tell a correct VEX.128 copy, which zeroes bits 128–255 ofymm1, from two wrong lowerings:xmm0was just loaded by a VEX.128vmovdqu, so its upper half is already zero.ymm1has no prior write, and the generatedVec256 ymm1{}starts at zero.Both would pass. Loading both registers first, with
vmovdqu ymm0, YMMWORD PTR [rcx]andvmovdqu ymm1, YMMWORD PTR [rdx], then runningvmovdqu xmm1, xmm0and the existingymm1store would expose either one. The expected value,a[:16]followed by zeros, stays the same.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-21T22:37:16Z.
Good catch — with both regs pre-zeroed, the three lowerings really do produce identical output. Fixed in
36cacde: ymm0 and ymm1 now load the full 256 bits before the xmm copy, so a full-ymm lowering leaks a[16:32] into the high half and a merge-only-lowering leaks b[16:32]. Expected output is unchanged, and the test still passes on the correct lowering.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T03:08:07Z.
For the AVX2 and AVX leaf fixtures, please focus the next update on #323, including the outstanding upper-lane control discussed here. Hold the #373 rebase until #323 lands so the CMake and coverage registrations can be reconciled against that base.