cpu: lower legacy SSE/MMX packed unsigned integer ops (PAVGB, PAVGW, PMULHUW, PSADBW) in cpu_sse_mmx_aot #2087
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2094"
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-25T00:13:14Z.
Change
Lower legacy MMX and SSE2 packed unsigned integer operations (
pavgb,pavgw,pmulhuw,psadbw) intools/cpu_sse_mmx_aot.pyand add a source-built MASM fixture (tests/cpu/sse_mmx_int.asm,tests/cpu/sse_mmx_int.def), differential verification suite (tests/cpu/sse_mmx_int_check.py), and CTest registration (cpu_aot_sse_mmx_intinCMakeLists.txt):docs/coverage/x64_zen2.tsvgroupsSSE/SSE2):pavgb mm, mm/m64andpavgb xmm, xmm/m128— carry-safe unsigned byte average((uint16_t(a) + uint16_t(b) + 1u) >> 1).pavgw mm, mm/m64andpavgw xmm, xmm/m128— carry-safe unsigned 16-bit average((uint32_t(a) + uint32_t(b) + 1u) >> 1).pmulhuw mm, mm/m64andpmulhuw xmm, xmm/m128— unsigned high 16-bit product(uint32_t(a) * uint32_t(b)) >> 16.psadbw mm, mm/m64andpsadbw xmm, xmm/m128— sum of unsigned byte absolute differences zero-extended to 64 bits per independent 64-bit half (q[0],q[1]).m64([rdx+1]) and enforcemmx_active/ terminalemmsdiscipline.m128(flat_address(alignment=16)) and volatile loads so/O2never eliminates faulting discarded reads.emms, undefinedmm/xmmregisters, nonvolatile XMM/GPR registers, unaligned XMMm128, RIP-relative/SIB addressing, non-r8stores, and non-leaf branches.Verification
Tested on commit
f4b357b2(rebased ontoupstream/main3914e891, Windows x64, MSVC 14.50,devDebug andrelease/O2):cmake --build --preset dev --target cpu_sse_mmx_int_original cpu_sse_mmx_int_original_lifted cpu_sse_mmx_int_altered cpu_sse_mmx_int_altered_lifted cpu_sse_mmx_original cpu_sse_mmx_original_lifted cpu_sse_mmx_altered_liftedcmake --build --preset release --target ...(same targets)ctest --preset dev -R "^cpu_aot_sse_mmx" --output-on-failure -V2/2Passed (cpu_aot_sse_mmx_int,cpu_aot_sse_mmx).cpu_aot_sse_mmx_int: 1258 lifted + 1258/O2cases across 34 exports,/O2NULL read fault verified, 10ALTER_IMMdivergences, 4 software mutants killed, 5 VEX/EVEX + 22 IR + 3 raw + 6 PE-patched + CLI rejections passed. Capability skips: none.ctest --preset release -R "^cpu_aot_sse_mmx" --output-on-failure2/2Passed..\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.pyform coverage checks passed(exit 0)..\out\pe-env\Scripts\python.exe -B tests/docs_links_check.pySelf-test passed. Checked 18 Markdown files and 394 links.(exit 0)..\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.pySelf-test passed. Checked 1418 tracked source, script and build/CI files: no bidirectional controls.(exit 0).Evidence and follow-up
tests/cpu/sse_mmx_int.asm(; coverage: source cpu_aot_sse_mmx_int) andtests/cpu/sse_mmx_int.defare original, source-built synthetic MASM fixtures under the repository MIT license; no external binaries or game files are used.ALTER_IMMmutant exports, 4 software mutants (dropped+1rounding, signedpmulhw, mergedpsadbwhalves), aNULL-pointer discardedm128read fault check under Debug and/O2, and 5 VEX/EVEX + 22 IR + 3 raw + 6 PE-patched + CLI rejections.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:51:23Z.
Review: COMMENTED
Review of head
f4b357b25440a63be13b59a76bf98dfefad8318a(PAVGB/PAVGW/PMULHUW/PSADBW lowering incpu_sse_mmx_aot).Verdict: no P1, no P2. Looks correct.
Commands executed locally:
git diff --check origin/main...HEAD: cleangit merge-tree --write-tree --name-only origin/main HEAD: no conflictspython3 tests/bidi_controls_check.py: passpython3 tests/docs_links_check.py: passpython3 -I -m py_compile tests/cpu/sse_mmx_int_check.py tools/cpu_sse_mmx_aot.py: okgh pr checks 2094: Linux Python checks, Windows build/test and gfx1013 fixtures passdevand Release/O2,ctest -R '^(cpu_aot_sse_mmx|cpu_aot_sse_mmx_int)$'): 2/2 passed on each presetMutation: in
tools/cpu_sse_mmx_aot.py,op_pavgb64changed(ab + bb + 1u) >> 1uto(ab + bb) >> 1uand run on Win2025 through--patch.cpu_aot_sse_mmx_intFAILED (lifted op_pavgb_mm_reg case 1mismatch against the expected value). So the tests cover the change. Mutation reverted withgit checkout -- ..Code read (helper math, ALLOWED_CODES wiring, 16-byte alignment for xmm memory sources, unaligned m64 for mm):
tools/cpu_sse_mmx_aot.pyop_pmulhuw64:aw * bwisuint32_t, which is safe (max 0xFFFE0001). A short comment saying so would help the next reader. Optional.AI-assisted; commands listed were executed locally.