cpu: lower VEX.128 16-bit word abs, sign, rounding mul-high, and hadd #2104
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2111"
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:35:57Z.
Change
Extend
tools/cpu_vex_aot.pyto lower four additional VEX.128 16-bit packed-word instructions (vpabsw,vpsignw,vpmulhrsw,vphaddw) for volatileXMM0..XMM5registers and[rcx]/[rdx]/[r8]16-byte memory operands, and add a source-built differential fixture and CTest (cpu_aot_vex_words_ext):UNARYdispatch (M.VPABSW -> pabsw) and register-definition tracking inlift()so 2-operand VEX.128 unary forms enforce the same defined-source and volatile-XMM rules asBINARY/SHIFTS.M.VPSIGNW -> psignw,M.VPMULHRSW -> pmulhrsw, andM.VPHADDW -> phaddwinBINARY, with explicit per-lane C++ helpers inPRELUDEavoiding signed-negation UB onINT16_MIN(0x8000) and spelling out rounding((int32(a) * b) + 0x4000) >> 15and pairwise horizontal addition.host_has_avx()(CPUID.01H:ECX[27:28]+XGETBV(0) & 6 == 6) inPRELUDEso differential harnesses can gate native AVX execution cleanly (exiting 77 if unsupported while still running AOT lowering/rejection checks).tests/cpu/vex_words_ext.asm(registered; coverage: source cpu_aot_vex_words_ext),tests/cpu/vex_words_ext.def, differential harnesstests/cpu/vex_words_ext_check.py, and CMake targets/testcpu_aot_vex_words_extwithSKIP_RETURN_CODE 77andFORM_COVERAGE_RECORD.Verification
Commit:
25ae80d0(rebased ontoupstream/main30888b67).cmake --preset dev && cmake --build --preset dev --target cpu_vex_words_original cpu_vex_words_original_lifted cpu_vex_words_altered cpu_vex_words_altered_lifted cpu_vex_words_ext_original cpu_vex_words_ext_original_lifted cpu_vex_words_ext_altered cpu_vex_words_ext_altered_lifted-> exit0, 0 errors, 0 warnings.cmake --preset release && cmake --build --preset release --target cpu_vex_words_original cpu_vex_words_original_lifted cpu_vex_words_altered cpu_vex_words_altered_lifted cpu_vex_words_ext_original cpu_vex_words_ext_original_lifted cpu_vex_words_ext_altered cpu_vex_words_ext_altered_lifted-> exit0, 0 errors, 0 warnings.ctest --preset dev -N->Total Tests: 1319(includescpu_aot_vex_wordsandcpu_aot_vex_words_ext).ctest --preset dev --no-tests=error -R "^cpu_aot_vex_words" -E "cpu_native_archive_" -V->2/2 Passed(0 capability skips).ctest --preset release --no-tests=error -R "^cpu_aot_vex_words" -E "cpu_native_archive_" -V->2/2 Passed(0 capability skips).FORM_COVERAGE_RECORD(devandrelease) ->ret,vmovdqa,vmovdqu,vpabsw,vphaddw,vpmulhrsw,vpsignw,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.out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py-> exit0.UNARYdefined-register tracking inlift(),pmulhrswrounding bias (+ 0x4000 -> + 0), andpsignwzero-mask branch (0 -> word(a, i)) each causedctest --preset dev -R "^cpu_aot_vex_words_ext$"to fail (exit8).No capability skips (exit 77) observed on this AVX-capable host.
Evidence and follow-up
tests/cpu/vex_words_ext.asmandtests/cpu/vex_words_ext.defare source-built MASM fixtures authored directly in this repository under the MIT license. The harness checks 10 exports across 1024 input pairs (including edge pairings,INT16_MIN, exact output aliases,RCX == RDX, and 8-byte misalignment onvmovdqu-only exports), 29 rejected encodings (VEX.256, EVEX, legacy SSSE3, nonvolatileXMM6..XMM15, undefined sources, displaced/indexed/invalid memory operands, invalid stores), 3 patched-PE rejections, 4 faulty reference mutants, and 3ALTER_EXTbuild controls.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:05:39Z.
Review: COMMENTED
Review of head
25ae80d0a9Result: no P1, no P2. Two nits.
Commands run locally (Linux worktree of the PR head):
git diff --stat origin/main...HEAD: 5 files, +610/-1 (CMakeLists.txt, tools/cpu_vex_aot.py, 3 new files under tests/cpu/)python3 tests/docs_links_check.py: Self-test passed. Checked 18 Markdown files and 395 links.python3 tests/bidi_controls_check.py: Self-test passed. 1425 files, no bidirectional controls.git diff --check origin/main...HEAD: cleangh pr checks 2111: Windows build and test pass, gfx1013 fixtures pass, Linux Python checks pass (the /O2 job was skipped)Semantics checked by hand against the ISA text (tools/cpu_vex_aot.py PRELUDE):
pabsw: 0x8000 stays 0x8000 through the unsigned negate. Correct, and there is no signed-overflow UB.psignw: negative b gives -a, zero b gives 0, positive b gives a. Matches. The -0x8000 case wraps correctly.pmulhrsw:(a*b + 0x4000) >> 15is identical to the Intel form((a*b >> 14) + 1) >> 1, because floor((floor(x/2^14)+1)/2) = floor((x+2^14)/2^15). The 0x8000*0x8000 case gives 0x8000 after the 16-bit truncation, which is also what the hardware returns.phaddw: pairwise sums, a lanes in the low half and b lanes in the high half. The wrap-around goes through set_word. Matches.lift(): UNARY is added to the defined-source check and the destination tracking. The undefined-XMM-source rule applies to vpabsw as it does to BINARY.Not run:
ctest -R cpu_aot_vex_words_extand the fixture need MASM, MSVC and iced_x86, so they cannot run on this Linux box (the check script fails to import iced_x86 here). I did not run the fixture or any mutation of the new lowering. I am relying on the green Windows CI job for that. No Win2025 run was started, since the change is CPU lowering and not shader or C++ GPU work.Nits:
host_has_avx):<intrin.h>,__cpuidand_xgetbvare MSVC-specific. That fits the existing__declspec(dllexport)use, but a short comment saying the lifted output targets MSVC only would help.AI-assisted; commands listed were executed locally.