cpu: lower CVTPI2PD MMX and memory forms in cpu_mmx_sse2_aot #2137
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2145"
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:34:45Z.
Change
Lower legacy SSE2
CVTPI2PD(Code.CVTPI2PD_XMM_MMM64) for bothMM0..MM7register sources and unaligned flat[rcx|rdx|r8 + disp]m64memory sources intools/cpu_mmx_sse2_aot.py, extendingtests/cpu/mmx_sse2.asm,tests/cpu/mmx_sse2.def,tests/cpu/mmx_sse2_check.py, andCMakeLists.txt:tools/cpu_mmx_sse2_aot.py:Code.CVTPI2PD_XMM_MMM64toALLOWED_CODESand lower viaop_cvtpi2pd(src), converting the low and high signedint32_tlanes of the 64-bit source into packed IEEE-754 binary64 lanes (Vec128) in volatileXMM0..XMM5.mm_src64()helper shared withMOVQ_MM_MMM64:MM0..MM7register sources route throughread_mm()(enforcing definition tracking and settingmmx_active = True), whilem64memory sources route throughload64(flat_address(ins))(allowing unaligned byte displacements and not settingmmx_active, matching x86-64 semantics).volatileaccess andstd::atomic_signal_fence(std::memory_order_seq_cst)barriers inload64()/load128()so discarded guest reads retain fault ordering across surrounding stores under/O2.tests/cpu/mmx_sse2.asm,tests/cpu/mmx_sse2.def,CMakeLists.txt:op_cvtpi2pd_reg,op_cvtpi2pd_mem,op_cvtpi2pd_mem_disp,op_cvtpi2pd_discarded_read,op_cvtpi2pd_bridge) withALTER_IMMcontrols and; coverage: source cpu_aot_mmx_sse2discovery forcvtpi2pd.tests/cpu/mmx_sse2_check.py:unsupported_cvtpi2pdrefusal with bit-for-bit native/lifted/reference differential checks acrossINT32_MIN,-1,0,1,INT32_MAX,+/-(2^24+1), and unalignedm64offsets;ALTER_IMMdivergence checks; discarded-read fault-ordering checks; signedness/lane-order mutation controls; and unit + PE-patched rejection controls (missingemmsformmregister source or prior active MMX state, undefinedmm, nonvolatilexmm6, VEXvcvtdq2pd, non-argument memory base).Verification
Verified on commit
953c9417(rebased onupstream/main8e8b0621):cmake --build --preset dev --target cpu_mmx_sse2_original cpu_mmx_sse2_original_lifted cpu_mmx_sse2_altered cpu_mmx_sse2_altered_lifted-> exit0(0 errors, 0 warnings)cmake --build --preset release --target cpu_mmx_sse2_original cpu_mmx_sse2_original_lifted cpu_mmx_sse2_altered cpu_mmx_sse2_altered_lifted-> exit0(0 errors, 0 warnings)ctest --preset dev -N->Total Tests: 1341(cpu_aot_mmx_sse2present, no dropped tests)ctest --preset dev -R "^cpu_aot_mmx_sse2$" --output-on-failure -V-> exit0(100% tests passed,285 native/lifted/reference MMX/SSE2 cases across 17 exports matched bit-for-bit,12 alternate-encoding lift checks, 53 unit rejection controls and 13 PE-patched rejection controls passed)ctest --preset release -R "^cpu_aot_mmx_sse2$" --output-on-failure -V-> exit0(100% tests passed, same counts including discarded-read fault ordering under/O2)./out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py-> exit0(form coverage checks passed;form_coverage.masm_mnemonicsincludescvtpi2pdfromtests/cpu/mmx_sse2.asm)./out/pe-env/Scripts/python.exe -B tests/docs_links_check.py-> exit0(Self-test passed. Checked 18 Markdown files and 398 links.)./out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py-> exit0(Self-test passed. Checked 1439 tracked source, script and build/CI files: no bidirectional controls.)tools/cpu_mmx_sse2_aot.py(CVTPI2PD_XMM_MMM64lowering branch,mm_src64memory-operand dispatch, andmm_src64read_mmdef/state check); all 3 mutations were killed bytests/cpu/mmx_sse2_check.py(exit1) and cleanly restored.Evidence and follow-up
All fixtures in
tests/cpu/mmx_sse2.asmare source-built synthetic MASM leaf functions (MIT License) assembled withml64and translated viatools/cpu_mmx_sse2_aot.py. Negative controls coverALTER_IMMdivergence, output/signedness/lane-order mutations, faulting discardedm64reads, and unit + PE-patched translator rejections.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:05:53Z.
Review: COMMENTED
Review of head
953c9417fdd021a8c8eb8d9347966b8d3e489293(comment only).Summary: No P1 or P2 findings. The CVTPI2PD lowering matches the ISA: the low and high signed int32 lanes become two binary64 lanes, in order. The memory form is an unaligned m64 read that does not set
mmx_active, which is correct. The register form goes throughread_mm(), so it is subject to the definition check and theemms-before-retrule.Commands run locally (Linux, worktree of the PR head):
git diff --stat origin/main...HEAD-> 5 files, +281/-19git diff --check origin/main...HEAD-> cleanpython3 tests/docs_links_check.py-> self-test passed, 18 Markdown files and 398 links checkedpython3 tests/bidi_controls_check.py-> self-test passed, 1439 files, no bidirectional controlsgh pr checks 2145-> Linux Python checks, Windows build/test and gfx1013 fixtures pass.Build and test on Windows at /O2is "skipping". See the first nit.iced-x86on hand-encoded bytes:cvtpi2pd xmm0,[rcx+5]lifts toxmm0 = op_cvtpi2pd(load64((rcx + 0x5ull)));.cvtpi2pd xmm5,mm7withmm7undefined is rejected with "undefined MMX register mm7".op_cvtpi2pdlane math on0x80000001FFFFFFFF: lo = -1.0 (bits0xBFF0000000000000), hi = -2147483647.0. Signedness and lane order are correct.mm_src64memory path toload64(1+...). The emitted C++ then differs from the string the check expects attests/cpu/mmx_sse2_check.py:465, so that test should kill it. I reverted it withgit checkout -- ..tests/cpu/mmx_sse2_check.pyneeds the Windows-built DLLs (MSVC and the exports). I did not run it on Linux, and I did not runwin2025. The PR's Windows CI job covers it, and this change is not a gfx2hlsl or shader change.Nits (non-blocking):
load64/load128now usevolatileand signal fences for every translated guest read, not just the discardedcvtpi2pdread. This is intended and the PR body says so. The/O2Windows job is "skipping", though. Please confirm the discarded-read test (op_cvtpi2pd_discarded_read) was exercised at/O2before marking Ready.load128thememcpyinto a local followed by avolatilecopy is a slightly roundabout way to force the read. A directvolatile128-bit access is not portable in MSVC, so I think it is fine, but a one-line comment on why would help.__unalignedqualifier inload64is MSVC-specific. That fits the Windows-only toolchain, but it will not compile with a non-MSVC host compiler.Clean-room: no external code or AI-model names seen in the diff or the title. The title is neutral. Mergeable state was reported as UNKNOWN at review time.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:47:33Z.
Review: COMMENTED
Re-review of head
be2dbe830520a2b4de895d6045495dd3793c3945(previous review was on953c9417).Delta since the last review: one commit, docs only (
docs/experiments.md, +4/-2). It addscvtpi2pdto the op list, narrows "Not covered" to "outside this profile", and adds a paragraph describing the extension. The code and tests are unchanged from the previously reviewed head.Checks run locally (Linux):
git diff --stat 953c941 HEAD: 1 file, docs only.python3 tests/docs_links_check.py: self-test passed, 18 Markdown files and 398 links OK.python3 tests/bidi_controls_check.py: self-test passed, 1439 files, no bidirectional controls.git diff --check origin/main...HEAD: clean.tools/cpu_mmx_sse2_aot.pylowering (op_cvtpi2pd,mm_src64,read_mm): lanes are signed int32 to exact binary64, low word in lane 0. A register source setsmmx_active, soemmsis required beforeret. A memory source goes throughload64and does not setmmx_active. This matches the doc text.2147483648.0where the signed form gives-2147483648.0. The signedness and lane-order controls attests/cpu/mmx_sse2_check.py:372-379would catch that, by reading.tests/cpu/mmx_sse2_check.pyand thecpu_aot_mmx_sse2CTest. They needpefile,iced_x86and MASM, which this Linux host does not have. No Win2025 run was queued from this review.CI: the Linux, Windows and gfx1013 jobs were still pending when I looked. Please wait for them to go green before Ready.
Findings: P1=0, P2=0.
AI-assisted; commands listed were executed locally.