cpu: lower opt-in memory-operand AVX move, shuffle, and blend forms (--mem-ops) in cpu_avx_move_aot #2122
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2130"
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 Ammmae0x on 2026-11-25T01:11:36Z.
Change
Add opt-in memory-operand lowering (
allow_memory=Falsedefault /--mem-opsCLI flag) for all 20 register-domain AVX move, shuffle, permute, unpack, blend, and lane forms intools/cpu_avx_move_aot.py, and add a source-built differential fixture and CTest (cpu_aot_avx_move_ext_mem):allow_memory=Falseregister-only rejections unchanged socpu_aot_avx_move_regsandcpu_aot_avx_move_memretain their exact existing contracts.--mem-ops, lower memory operands forvblendpd/vblendps/vblendvpd/vblendvps,vperm2f128,vpermilpd/vpermilps(imm8 and variable forms),vshufpd/vshufps,vunpcklpd/vunpcklps/vunpckhpd/vunpckhps,vmovshdup/vmovsldup(m128/m256),vmovddup(exactm64for XMM viaload_vec64vsm256for YMM),vinsertf128(m128),vinsertps(exactm32viaload_vec32withimm8 & 0x3fignoringCOUNT_Sfor memory operands), and memory storesvextractf128(m128) /vextractps(m32) enforcingR8destination viaflat_address(..., store=True)./O2viavolatile+__unaligned+std::atomic_signal_fence(std::memory_order_seq_cst)helpers.host_has_avx()(CPUID.01H:ECX[27:28]+_xgetbv(0) & 6 == 6) for clean exit-77 skipping on non-AVX hosts.tests/cpu/avx_move_ext_mem.asm(registered; coverage: source cpu_aot_avx_move_ext_mem),tests/cpu/avx_move_ext_mem.def, differential harnesstests/cpu/avx_move_ext_mem_check.py, and CMake targets/testcpu_aot_avx_move_ext_memwithSKIP_RETURN_CODE 77andFORM_COVERAGE_RECORD.Verification
Commit:
30303f42(based onupstream/main6921dcfd).cmake --preset dev && cmake --build --preset dev --target cpu_avx_move_ext_mem_altered cpu_avx_move_ext_mem_altered_lifted cpu_avx_move_ext_mem_original cpu_avx_move_ext_mem_original_lifted cpu_avx_move_mem_altered cpu_avx_move_mem_altered_lifted cpu_avx_move_mem_original cpu_avx_move_mem_original_lifted cpu_avx_move_regs_altered cpu_avx_move_regs_altered_lifted cpu_avx_move_regs_original cpu_avx_move_regs_original_lifted-> exit0, 0 errors, 0 warnings.cmake --preset release && cmake --build --preset release --target ...(same 12 targets) -> exit0, 0 errors, 0 warnings.ctest --preset dev --no-tests=error -R "^cpu_aot_avx_move" -E "cpu_native_archive_" -V->3/3 Passed(0 capability skips).ctest --preset release --no-tests=error -R "^cpu_aot_avx_move" -E "cpu_native_archive_" -V->3/3 Passed(cpu_aot_avx_move_regs0.77s,cpu_aot_avx_move_mem0.78s,cpu_aot_avx_move_ext_mem0.67s; 0 capability skips).FORM_COVERAGE_RECORD(devandrelease) -> all 20 AVX mnemonics (vblendpd/ps/vpd/vps,vextractf128,vextractps,vinsertf128,vinsertps,vmovddup,vmovshdup,vmovsldup,vperm2f128,vpermilpd/ps,vshufpd/ps,vunpckhpd/hps/lpd/lps) plusret,vmovdqu,vzeroupper.out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py-> exit0(form coverage checks passed).out/pe-env/Scripts/python.exe -B tests/docs_links_check.py-> exit0(Checked 18 Markdown files and 398 links.).out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py-> exit0(Checked 1433 tracked source, script and build/CI files: no bidirectional controls.).8): disablingallow_memory=Falsedefault rejection, relaxingvextractpsstore=TrueR8check, droppingvinsertpsm32imm8 & 0x3fmask, widening XMMvmovddupfromload_vec64toload128, and replacingload_vec32volatile load with non-volatilememcpyonrelease/O2(caught by discarded-read fault test).No capability skips (exit 77) observed on this AVX-capable host.
Evidence and follow-up
tests/cpu/avx_move_ext_mem.asmandtests/cpu/avx_move_ext_mem.defare source-built MASM fixtures authored directly in this repository under the MIT license. The harness validates 41 exports across 1312 native/lifted/reference cases (including IEEE-754 NaN/inf/-0 raw bit preservation, unaligned displacements, XMM upper-128 zeroing,VirtualAlloc/PAGE_NOACCESSpage-edgem32/m64no-overread tests, discarded-read fault ordering, andALTER_IMMdifferential controls), 20 defaultallow_memory=Falserejections, and 14 unit + 4 patched-PE--mem-opsrejections.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:20:50Z.
Review: COMMENTED
Review of head
30303f423cf8635695bcd7308fc5c886cfa09437Scope:
tools/cpu_avx_move_aot.py(--mem-ops/allow_memory), new fixturetests/cpu/avx_move_ext_mem.{asm,def}+avx_move_ext_mem_check.py, CMake testcpu_aot_avx_move_ext_mem.Result: no P1, no P2. Two nits.
What I checked (Linux, locally)
git diff --stat origin/main...HEAD: 5 files, +1152/-43. Title is neutral, PR is MERGEABLE.gh pr checks 2130: Windows build/test, gfx1013 fixtures, and Linux Python checks all pass. The /O2 job and the coverage chart job were skipped.python3 tests/docs_links_check.py: pass (18 files, 398 links).python3 tests/bidi_controls_check.py: pass.git diff --check origin/main...HEAD: clean.ctypes.wintypes, loads the MASM-built PE, and needsml64. I could not run it on Linux, so I did not runwin2025. The native differential result rests on the CI Windows job. I did not see the test name in the logs I fetched, so please confirm thatcpu_aot_avx_move_ext_memactually ran and did not exit 77.lift_codedirectly with iced-x86 encodings (venv, local):vinsertps xmm,xmm,[rcx+8],0FFhwithallow_memory=Truelifts toload_vec32(...)with imm0x3fu. The default (allow_memory=False) still rejects it.vextractps [r8+8],xmm,2lifts tostore32.[rcx+8]is rejected, so only R8 is allowed for stores.vextractf128 [r8+8],ymm,1lifts tostore128.vmovddupmemory form: XMM usesload_vec64(exact m64), YMM usesload256.immediate8 & 0x3fto& 0xfffor the memoryvinsertps. The lifted code changed to0xffu. The fixture uses imm0D2h/0D4h(bits 7:6 set), so the native differential should kill this mutation. I only confirmed that the generated source changes. I could not run the native kill. I reverted withgit checkout -- ..Findings
read_vec_or_memalways callsflat_address(ins), so memory sources must be rooted in an argument GPR. That matches the existing contract. A one-line note in the docstring or--mem-opshelp would make this clear.store32/store64/store128/store256gained signal fences but are notvolatile. This is fine for ordering against the loads. Say so in a comment if the intent is "fault ordering of discarded reads only".Correctness notes (no action)
write_vecbefore the memory read keeps the "defined register" bookkeeping consistent. Operand order in the emitted statements is unchanged.cpu_aot_avx_move_regsandcpu_aot_avx_move_memkeep their contracts.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T11:37:30Z.
Confirmed at head
30303f42on Windows x64 (AVX-capable host; CIprpreset only runs the 30-test smoke subset):ctest --preset dev --no-tests=error -R "^cpu_aot_avx_move_ext_mem$" -V-> 1/1 Passed (exit 0, not skipped with exit 77).ctest --preset release --no-tests=error -R "^cpu_aot_avx_move_ext_mem$" -V(/O2) -> 1/1 Passed (exit 0, not skipped with exit 77).AI-assisted.