cpu: add dedicated cpu_bmi1_aot lifter for BLSI, BLSMSK, and BLSR #2401
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2409"
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-25T15:37:20Z.
Change
Add a dedicated, portable C++ AOT lifter
tools/cpu_bmi1_aot.pyfor the three BMI1 bit-isolation/mask/reset instructions fromdocs/coverage/x64_zen2.tsvgroupBMI/ADX:BLSI(VEX_BLSI_R32_RM32,VEX_BLSI_R64_RM64):dst = (-src) & src,CF=(src!=0),ZF=(dst==0),SF=msb(dst),OF=0.BLSMSK(VEX_BLSMSK_R32_RM32,VEX_BLSMSK_R64_RM64):dst = (src-1) ^ src,CF=(src==0),ZF=0,SF=msb(dst),OF=0.BLSR(VEX_BLSR_R32_RM32,VEX_BLSR_R64_RM64):dst = (src-1) & src,CF=(src==0),ZF=(dst==0),SF=msb(dst),OF=0.[63:32]=0), flat[rcx|rdx|r8]memory reads viaload_always()(fault-preserving under/O2), volatile GPR glue (mov, xor, or, shl, movzx, setcc, flat[r8]stores,ret), andhost_has_bmi1()(CPUID.07H.00H:EBX[3]).PF/AFafterBLSI/BLSMSK/BLSRper Intel SDM so readingPF/AFrejects; rejects BMI2 (RORX/SARX/SHLX/SHRX/BZHI),TZCNT/ANDN/BEXTR, EVEX/XOP, nonvolatile GPRs, argument GPR writes, high-byte GPRs, undefined GPR/flag reads, displaced/indexed/non-flat memory, stores outside[r8], prefixes, branches, and missing/trailingret.tests/cpu/bmi1_aot.{asm,def,_check.py}(; coverage: record cpu_aot_bmi1_bit) and registercpu_aot_bmi1_bitinCMakeLists.txt.Verification
Verified on commit
1ab618a6(based onupstream/main7092683a) across bothdev(Debug) andrelease(/O2) presets:cmake --build --preset dev --target cpu_bmi1_aot_original cpu_bmi1_aot_original_lifted cpu_bmi1_aot_altered cpu_bmi1_aot_altered_lifted-> exit 0ctest --preset dev -R "^cpu_aot_bmi1_bit$" -E "cpu_native_archive_" --output-on-failure -V->100% tests passed, 0 tests failed out of 1(0 skipped, 0.68s):rejections passed: 3 alt + 37 IR + 4 raw + 10 PE-patched + CLIbmi1_aot passed: 2223 native + 2223 lifted + 2223 /O2 cases across 21 exports; ALTER_BMI1 diverged on 12 exports + 10 mutants caughtcmake --build --preset release --target cpu_bmi1_aot_original cpu_bmi1_aot_original_lifted cpu_bmi1_aot_altered cpu_bmi1_aot_altered_lifted-> exit 0ctest --preset release -R "^cpu_aot_bmi1_bit$" -E "cpu_native_archive_" --output-on-failure -V->100% tests passed, 0 tests failed out of 1(0 skipped, 0.84s)FORM_COVERAGE_RECORDverified in bothout/build/dev/form_coverage/cpu_aot_bmi1_bit.txtandout/build/release/form_coverage/cpu_aot_bmi1_bit.txt:blsi, blsmsk, blsr, mov, movzx, or, ret, setb, sete, seto, sets, shl, xorout/pe-env/Scripts/python.exe -B tests/form_coverage_check.py->form coverage checks passed(exit 0)out/pe-env/Scripts/python.exe -B tests/docs_links_check.py->Self-test passed. Checked 19 Markdown files and 464 links.(exit 0)out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py->Self-test passed. Checked 1727 tracked source, script and build/CI files: no bidirectional controls.(exit 0)Spot mutation checks against
tools/cpu_bmi1_aot.py(8/8 killed bytests/cpu/bmi1_aot_check.py, restored cleanly):BLSI32CF(/O2), setBLSMSK64ZF=(s==0)(/O2), setBLSR64ZF=(s==0)instead of(d==0)(/O2), preserve high 32 bits instead of zero-extending 32-bit BMI1 destination (/O2), dropSFinBLSI64(/O2), leavePFdefined after BMI1, allow writes to argument GPRs, and allow stores outside[r8](all returned exit 1).Evidence and follow-up
tests/cpu/bmi1_aot.{asm,def,_check.py}is a clean-room, source-built MASM fixture (MIT, repo-authored; no game files, dumps, or binaries).[r8]source-then-store, discarded faulting read,/O2build, mutants, andALTER_BMI1before anyhost_has_bmi1()exit-77 capability skip (0 skips on this BMI1-capable host).Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T15:51:13Z.
Review: PR #2409 —
cpu: add dedicated cpu_bmi1_aot lifter for BLSI, BLSMSK, and BLSRDecision: APPROVED
Summary
Adds
tools/cpu_bmi1_aot.py(584 lines) as a dedicated lifter for the three BMI1 bit-isolation/mask/reset instructions: BLSI, BLSMSK, and BLSR. Includes MASM fixture (tests/cpu/bmi1_aot.asm, 252 lines), DEF file, and 634-line test script.Correctness
dst = (~src + 1) & srcwith CF=(src!=0), ZF=(dst==0), SF=msb, OF=0 — correct per Intel SDMdst = (src-1) ^ srcwith CF=(src==0), ZF=false, SF=msb, OF=0 — correctdst = (src-1) & srcwith CF=(src==0), ZF=(dst==0), SF=msb, OF=0 — correctupdate_gpr_width(val, 32u) → val \& 0xFFFFFFFFull— correctTest Coverage
Consistency
cpu_leaf_aotpatterns exactly (load_always/store_always, PRELUDE, bounded_code, export_rva)No blocking issues found.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T16:25:45Z.
Review: COMMENTED
Review of head
1ab618a6(comment only).Checked:
git diff --stat origin/main...HEAD: 5 files, all new except a 24-line CMake block. Same shape as the sibling lifters (cpu_aot_bmi2_shiftand others), so it is small and additive.gh pr list --state all --search "cpu_bmi1_aot BLSI BLSR BLSMSK").tests/cpu/bmi1_aot_check.py:53match the instruction definitions: BLSI CF = (src != 0), ZF from result; BLSMSK CF = (src == 0), ZF = 0; BLSR CF = (src == 0), ZF from result; OF = 0, SF from result; 32-bit results zero-extend.invert_cf,drop_sf,no_zext32, ...) and an altered-binary check, so a wrong lowering would fail.python3 -I -m py_compile.No blocking findings. Win2025 WARP dev+release will be run next.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T16:29:40Z.
Win2025 WARP receipt for head
0804956fafter updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
0804956f3faa2cebb59d6583b786cd8d3e4e663b:--preset dev):cmake --build --preset dev --target cpu_bmi1_aot_altered cpu_bmi1_aot_altered_lifted cpu_bmi1_aot_original cpu_bmi1_aot_original_lifted -- -j 2):3.67s(configure1.65s)ctest --preset dev -R 'cpu_aot_bmi1_bit' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (1.06s:cpu_aot_bmi1_bit0.95s)/O2(--preset release):cmake --build --preset release --target cpu_bmi1_aot_altered cpu_bmi1_aot_altered_lifted cpu_bmi1_aot_original cpu_bmi1_aot_original_lifted -- -j 2):1.07s(configure1.73s)ctest --preset release -R 'cpu_aot_bmi1_bit' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (1.06s:cpu_aot_bmi1_bit0.96s)sccache: 0/4 hits; wall15.8sAI-assisted; commands listed were executed locally.