cpu: lower opt-in memory-operand AVX2 forms (--mem-ops) in cpu_avx2_aot #2120
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2128"
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:00:59Z.
Change
Add opt-in memory-operand lowering (
allow_memory=Falsedefault /--mem-opsCLI flag) for all 17 register-domain AVX2 forms intools/cpu_avx2_aot.py, and add a source-built differential fixture and CTest (cpu_aot_avx2_mem):allow_memory=False) socpu_aot_avx2_regscontinues rejecting all 17 memory forms unchanged.--mem-ops, lower memory forms forvpbroadcastb(m8),vpbroadcastw(m16),vpbroadcastd(m32), andvpbroadcastq(m64) across XMM/YMM (with upper-128 zeroing on XMM writes),vinserti128(m128),vextracti128(m128store enforcingR8destination viaflat_address(..., store=True)), andvperm2i128/vpermd/vpermpd/vpermps/vpermq/vpblendd/vpsllvd/vpsllvq/vpsravd/vpsrlvd/vpsrlvq(m128/m256sources)./O2viavolatile+__unaligned+std::atomic_signal_fence(std::memory_order_seq_cst)helpers (load8/load16/load32/load64/load128/load256andstore128/store256). All callers oftools/cpu_avx2_aot.pyintentionally share thePRELUDEunaligned/volatile/signal-fence load and fenced store helpers so/O2preserves unaligned reads and discarded-read fault ordering across both--mem-opsand non---mem-opspaths (re-verified acrosscpu_aot_avx2_regs,cpu_aot_avx2_mem,cpu_aot_avx2_shifts,cpu_aot_avx2_permutes, andcpu_aot_fma3on bothdevDebug andrelease/O2).host_has_avx2()(CPUID.01H:ECX[27:28],_xgetbv(0) & 6 == 6,CPUID.00H:EAX >= 7,CPUID.07H.0:EBX[5]) for clean exit-77 skipping on non-AVX2 hosts.tests/cpu/avx2_mem.asm(registered; coverage: source cpu_aot_avx2_mem),tests/cpu/avx2_mem.def, differential harnesstests/cpu/avx2_mem_check.py, and CMake targets/testcpu_aot_avx2_memwithSKIP_RETURN_CODE 77andFORM_COVERAGE_RECORD.Verification
Commit:
fdac8751(based onupstream/maina81beb55).cmake --preset dev && cmake --build --preset dev --target cpu_avx2_regs_original cpu_avx2_regs_original_lifted cpu_avx2_regs_altered_lifted cpu_avx2_mem_original cpu_avx2_mem_original_lifted cpu_avx2_mem_altered cpu_avx2_mem_altered_lifted cpu_avx2_permutes cpu_avx2_permutes_lifted cpu_avx2_shifts cpu_avx2_shifts_lifted-> exit0, 0 errors, 0 warnings.cmake --preset release && cmake --build --preset release --target ...(same 11 targets) -> exit0, 0 errors, 0 warnings.ctest --preset dev --no-tests=error -R "^cpu_aot_avx2" -E "cpu_native_archive_" -V->4/4 Passed(0 capability skips).ctest --preset release --no-tests=error -R "^cpu_aot_avx2" -E "cpu_native_archive_" -V->4/4 Passed(cpu_aot_avx2_regs0.44s,cpu_aot_avx2_mem0.37s,cpu_aot_avx2_shifts0.43s,cpu_aot_avx2_permutes0.43s; 0 capability skips).FORM_COVERAGE_RECORD(devandrelease) -> all 17 AVX2 mnemonics (vextracti128,vinserti128,vpblendd,vpbroadcastb/w/d/q,vperm2i128,vpermd,vpermpd,vpermps,vpermq,vpsllvd/q,vpsravd,vpsrlvd/q) 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 396 links.).out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py-> exit0(Checked 1432 tracked source, script and build/CI files: no bidirectional controls.).8): disablingallow_memory=Falsedefault rejection, relaxingvextracti128store=TrueR8check, replacingload_vec32volatile load with non-volatilememcpyonrelease/O2(caught by discarded-read fault test), and dropping upper-128 zeroing inop_vpbroadcastb.No capability skips (exit 77) observed on this AVX2-capable host.
Evidence and follow-up
tests/cpu/avx2_mem.asmandtests/cpu/avx2_mem.defare source-built MASM fixtures authored directly in this repository under the MIT license. The harness validates 32 exports across 622 native/lifted/reference cases (including unaligned displacements, XMM upper-128 zero-extension, discarded-read fault ordering, andALTER_IMMdifferential controls), 17 defaultallow_memory=Falserejections, and 12 unit + 4 patched-PE--mem-opsrejections.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:25:09Z.
Review: COMMENTED
Review of head
fdac8751f3cb8dc43649f35071d54d5a846bc093(comment only, no approval).Scope:
tools/cpu_avx2_aot.py(opt-in--mem-ops), newtests/cpu/avx2_mem.{asm,def},tests/cpu/avx2_mem_check.py,CMakeLists.txt(+30).Commands executed locally (Linux):
git diff --stat origin/main...HEAD: 5 files, +915/-51python3 tests/docs_links_check.py: pass (18 files, 396 links)python3 tests/bidi_controls_check.py: passgit diff --check origin/main...HEAD: cleanpython3 -m py_compile tools/cpu_avx2_aot.py tests/cpu/avx2_mem_check.py: passgh pr checks 2128: Linux Python checks, Windows build/test and gfx1013 fixtures pass. The /O2 job and the chart job are skipped.Not run locally:
cpu_aot_avx2_mem. It needs the MSVC-assembled fixture PE and a native DLL load, which this Linux host cannot build. For the same reason I could not run the required logic mutation here. I rely on the Windows CI job, and I could not read its log to confirm that this test ran and did not exit 77 (skip). Please confirm the job log showscpu_aot_avx2_memas Passed, not Skipped.Findings
P1: none.
P2
tools/cpu_avx2_aot.pyPRELUDE: the change is not limited to--mem-ops. Every lifted file now gets volatile, signal-fencedload128/load256/load32/load64and fencedstore128/store256. Existing fixtures and outputs change behavior (they cannot be elided or merged, and an unaligned type is used on MSVC). Please say in the PR body that this is intended for all callers, or gate it. Also check that existing differential suites were rerun on Win2025 for the non-mem path.host_has_avx2is only emitted under_MSC_VER. On other compilers the lifted DLL has no such export. If the test helper (host_has_avx2(lifted_lib)) is ever run against a non-MSVC build, it will fail at symbol lookup and not skip. Low risk today (CMake uses MSVC); a short comment would help.Nits
flat_address(store=True)allows onlyr8as store base while loads allowrcx/rdx/r8. That looks deliberate (output pointer convention), but add one line saying why.store128/store256still usememcpywhile loads use volatile. Fine, but the asymmetry deserves a comment.REGISTER_ONLY_AVX2whenallow_memoryis set. Unhandled mnemonics fall intoread_vec, which rejects memory operands. Good. Confirm a rejection case exists incheck_translator(the file says it has rejection checks).Semantics read (static): broadcast loaders read exactly 1/2/4/8 bytes; VEX.128 shift and blend memory forms read 16 bytes and 256-bit forms read 32; vpermq/vpermpd read 32; vinserti128 reads 16; vextracti128 stores 16. These match the ISA operand sizes. The
wideflag now comes from src1 and the destination width is used for the helper, which is consistent.Clean-room and title: neutral title, MIT only, no model names seen in the diff.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T11:36:44Z.
Updated PR #2128 (commit
7e8bc38a) to address the review findings:PRELUDEcomment and PR body that the volatile/unaligned/fenced helpers are intentional for all callers (including non---mem-opspaths). Re-ran allcpu_avx2_*+cpu_fma3_leaftargets andctest -R "^(cpu_aot_avx2|cpu_aot_fma3)"on Windows x64 for bothdev(Debug) andrelease(/O2): 5/5 Passed (cpu_aot_avx2_regs,cpu_aot_avx2_mem,cpu_aot_fma3,cpu_aot_avx2_shifts,cpu_aot_avx2_permutes), 0 capability skips (exit 77) —cpu_aot_avx2_memexecuted 622 differential cases + discarded-read + 13 unit / 4 PE rejections and passed._MSC_VERguard): Added comments at#if defined(_MSC_VER)(tools/cpu_avx2_aot.py) andhost_has_avx2()(tests/cpu/avx2_mem_check.py) noting that non-MSVC builds omit the export andhost_has_avx2()checkshasattr(lifted_lib, "host_has_avx2")before falling back.flat_address(store=True)restricts stores tor8(3-arg(rcx, rdx, r8)ABI output convention) and whystore*uses fencedmemcpywhileload*usesvolatile; addedunsupported_mem_op(VEX_VBROADCASTSS_YMM_M32) tomem_rejectsincheck_translator().store=TrueR8guard) killed bycpu_aot_avx2_mem(exit 8);form_coverage_check.py,docs_links_check.py, andbidi_controls_check.pyall exit 0.AI-assisted.