cpu: lower 32/64-bit BMI2 BZHI, MULX, PDEP, and PEXT in cpu_bmi2_bit_aot #2613
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2621"
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-25T23:29:32Z.
Change
Add a dedicated BMI2 bit-manipulation AOT lifter
tools/cpu_bmi2_bit_aot.pylowering 32-bit and 64-bit register and flat zero-displacement[rcx|rdx|r8]memory-source forms ofBZHI,MULX,PDEP, andPEXTplus MASM differential/refusal/mutation coverage intests/cpu/bmi2_bit_aot.{asm,def,_check.py}(registered ascpu_aot_bmi2_bitinCMakeLists.txtwithSKIP_RETURN_CODE 77andFORM_COVERAGE_RECORD):[63:32];BZHI8-bit index masking (index >= widthpreserves source withCF=1;index == 0yields0withCF=0; updatesCF/ZF/SF/OF=0and invalidatesPF/AF);MULXimplicitEDX/RDXoperand read before writingdst_lothendst_hi(soop0 == op1receives the high half) with all flags preserved;PDEP/PEXTflagless bit deposit/extract; unconditionalload_always()so/O2preserves faulting discarded reads.[r8]stores, undefined GPR/flag reads (includingPF/AFafterBZHI), instruction prefixes, branches/calls, and missing/trailingret.AI-assisted.
Verification
Tested on commit
d9536df4(rebased onupstream/main) with MSVC 19.50 + ML64 14.50 andout\pe-env\Scripts\python.exe -B:ctest --preset dev -N/ctest --preset release -N: Total Tests: 2085 (no dropped tests).cmake --build --preset dev --target cpu_bmi2_bit_original cpu_bmi2_bit_original_lifted cpu_bmi2_bit_altered cpu_bmi2_bit_altered_lifted: 0 errors, 0 warnings.ctest --preset dev --output-on-failure --no-tests=error -R "^cpu_aot_bmi2_bit$" -E "cpu_native_archive_" -V: 1/1 passed (5 alt + 52 unit + 3 raw + 10 PE-patched + CLI rejections; 3,006 lifted + 3,006/O2 /W4 /WXcases across 26 exports matched bit for bit;ALTER_BMI2_BITdiverged on all 10 altered exports; 0 capability skips on BMI2 host).cmake --build --preset release --target cpu_bmi2_bit_original cpu_bmi2_bit_original_lifted cpu_bmi2_bit_altered cpu_bmi2_bit_altered_lifted(/O2): 0 errors, 0 warnings;ctest --preset release -R "^cpu_aot_bmi2_bit$" -V: 1/1 passed.FORM_COVERAGE_RECORDin bothdevandrelease(15 mnemonics:bzhi,cmp,mov,movzx,mulx,or,pdep,pext,ret,setb,sete,seto,setp,sets,xor).tools/cpu_bmi2_bit_aot.py(BZHIPFinvalidation, displaced-memory rejection, argument-GPR write rejection, non-[r8]store rejection); 4/4 mutations killed bycheck_rejections()and restored cleanly.out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py: passed (exit 0).out\pe-env\Scripts\python.exe -B tests\docs_links_check.py: passed (exit 0).out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py: passed (exit 0).Evidence and follow-up
All fixtures in
tests/cpu/bmi2_bit_aot.{asm,def}are source-built synthetic MASM routines (MIT License). Native execution is CPUID leaf 7 subleaf 0 EBX[8] BMI2 gated (exit 77 on non-BMI2 hosts). Remaining BMI1/ADX forms remain follow-ups.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:32:01Z.
Review: COMMENTED
Review of head
d9536df4(comment only).Checked:
tools/cpu_bmi2_bit_aot.pyhelpers against the Intel SDM: BZHI (index masked to 8 bits,index >= widthkeeps the source with CF=1,index == 0gives 0 with CF=0, ZF/SF from result, OF=0, PF/AF not defined and refused on read), MULX (hi/lo operand order, implicit EDX/RDX, lo written before hi so op0 == op1 gets the high half, flags untouched), PDEP and PEXT (flagless, 32-bit results zero-extended). Operand order in the lifter (src/index/mask) matches the SDM forms.cpu_bmi2_shift_aot(#2367) and are refused here, so there is no overlap.tests/cpu/bmi2_bit_aot_check.pycovers differential, refusal and mutation cases, and CMake registerscpu_aot_bmi2_bitwithSKIP_RETURN_CODE 77like the sibling suite.Commands run (Linux):
python3 tests/docs_links_check.py: okpython3 tests/bidi_controls_check.py: okgit diff --check origin/main...HEAD: cleanNot run on Linux: the new CTest needs MSVC/ML64 and the Windows Python environment, so it will be exercised on Windows only. No concerns found in the code.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:32:58Z.
Win2025 WARP receipt for head
d9536df4.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
d9536df46656e4156e059c79fdd4ffe3c22db2c1:--preset dev):cmake --build --preset dev --target cpu_bmi2_bit_altered cpu_bmi2_bit_altered_lifted cpu_bmi2_bit_original cpu_bmi2_bit_original_lifted -- -j 2):1.11s(configure0.00s)ctest --preset dev -R 'cpu_aot_bmi2_bit' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (1.73s:cpu_aot_bmi2_bit1.53s)/O2(--preset release):cmake --build --preset release --target cpu_bmi2_bit_altered cpu_bmi2_bit_altered_lifted cpu_bmi2_bit_original cpu_bmi2_bit_original_lifted -- -j 2):1.75s(configure0.00s)ctest --preset release -R 'cpu_aot_bmi2_bit' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (1.67s:cpu_aot_bmi2_bit1.48s)sccache: 4/6 hits; wall20.0sAI-assisted; commands listed were executed locally.