cpu: lift BMI1 ANDN, BEXTR, and TZCNT leaf functions to C++ #2660
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2668"
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-26T01:36:10Z.
Change
Add a bounded x64-to-C++ leaf lifter (
tools/cpu_bmi1_logic_aot.py) and source-built MASM/CTest differential suite (tests/cpu/bmi1_logic_aot.{asm,def,_check.py}, CTestcpu_aot_bmi1_logic) covering 32-bit and 64-bit register and flat[rcx|rdx|r8]memory-source forms of BMI1ANDN,BEXTR, andTZCNT.ANDN((~src1) & src2, updating SF/ZF, clearing CF/OF, refusing PF/AF reads);BEXTR(start = op2[7:0],len = op2[15:8],len == 0orstart >= widthyielding 0 with ZF=1, CF=OF=0, refusing SF/PF/AF reads);TZCNT(src == 0yielding width with CF=1/ZF=0 else trailing-zero count with CF=0/ZF=(dst==0), refusing SF/OF/PF/AF reads).load_always()/store_always()withatomic_signal_fenceand volatile observation so/O2preserves faulting memory reads (verified byop_bmi1_logic_discarded_read).BLSI/BLSMSK/BLSR, BMI2, EVEX/XOP, 16-bitTZCNT,BSF/LZCNT, nonvolatile GPRs, writes to argument GPRs, high-byte GPRs, undefined GPR/flag reads, displaced/indexed/RIP-relative memory operands, non-[r8]stores, prefixes, branches, and missing/trailing instructions afterret.cpu_aot_bmi1_logicwithSKIP_RETURN_CODE 77(CPUID.7.0:EBX[3] BMI1 gate) andFORM_COVERAGE_RECORD(; coverage: record cpu_aot_bmi1_logic).Verification
77b79c7f(based onupstream/main31bcd9ad)cmake --preset dev+cmake --build --preset dev --target cpu_bmi1_logic_aot_original cpu_bmi1_logic_aot_original_lifted cpu_bmi1_logic_aot_altered cpu_bmi1_logic_aot_altered_lifted-> 0 errors, 0 warningsctest --preset dev -N->Total Tests: 2165(cpu_aot_bmi1_logicregistered)ctest --preset dev --output-on-failure -R "^cpu_aot_bmi1_logic$" -E "cpu_native_archive_"->1/1 Passed(1.32s);out\build\dev\form_coverage\cpu_aot_bmi1_logic.txtrecorded 13 forms (includingandn,bextr,tzcnt)cmake --preset release+cmake --build --preset release --target cpu_bmi1_logic_aot_original cpu_bmi1_logic_aot_original_lifted cpu_bmi1_logic_aot_altered cpu_bmi1_logic_aot_altered_lifted-> 0 errors, 0 warningsctest --preset release --output-on-failure -R "^cpu_aot_bmi1_logic$" -E "cpu_native_archive_"->1/1 Passed(1.32s);out\build\release\form_coverage\cpu_aot_bmi1_logic.txtrecorded 13 formsout\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 510 links.(exit 0)out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py->Self-test passed. Checked 1893 tracked source, script and build/CI files: no bidirectional controls.(exit 0)op_andn32operand swap,op_tzcnt64CF inversion, undefined-flag read guard bypass).ALTER_BMI1_LOGICdiverging exports, 17 SDM edge-case mutant models, 45 IR rejections + 5 raw-byte rejections + 12 PE-patched rejections + CLI error-exit/zero-temp checks, and discarded NULL-read fault preservation under/O2.Evidence and follow-up
All assembly fixtures in
tests/cpu/bmi1_logic_aot.asmare source-built MASM x64 routines authored under the repository MIT license. Portable lifted, mutant, rejection, and/O2 /W4 /WXcompilation checks run unconditionally before the CPUID.07H.00H:EBX[3] native differential gate (exit 77 on hosts without BMI1).Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:00:52Z.
Review: COMMENTED
Review of head
e41d90f5(main merged in), comment only.Checked:
tools/cpu_bmi1_logic_aot.pyagainst the SDM: ANDN (SF/ZF set, CF/OF cleared), BEXTR (start/len from op2[7:0]/[15:8], len==0 or start>=width gives 0 with ZF=1), TZCNT (src==0 gives width with CF=1/ZF=0). All correct, 32-bit results zero-extend.cpu_bmi1_aotlifter, so no overlap. No other open or merged PR covers ANDN/BEXTR/TZCNT.check_altered_and_mutants) that must diverge, plus a discarded-read test for/O2.cpu_aot_bmi1_logic.Commands run locally:
git diff --check origin/main...HEADpython3 tests/docs_links_check.pypython3 tests/bidi_controls_check.pyThe helper semantics were reviewed by reading; the differential check needs MSVC and ran on Win2025 only.
No blocking findings.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:00:53Z.
Win2025 WARP receipt for head
e41d90f5after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
e41d90f519a5c8d58a00bbac7950d33e102331f8:--preset dev):cmake --build --preset dev --target cpu_bmi1_logic_aot_altered cpu_bmi1_logic_aot_altered_lifted cpu_bmi1_logic_aot_original cpu_bmi1_logic_aot_original_lifted -- -j 2):1.82s(configure3.77s)ctest --preset dev -R 'bmi1' --parallel 2 --no-tests=error --output-on-failure): 3/3 passed (2.61s:cpu_aot_bmi10.44s,cpu_aot_bmi1_bit1.54s,cpu_aot_bmi1_logic1.98s)/O2(--preset release):cmake --build --preset release --target cpu_bmi1_logic_aot_altered cpu_bmi1_logic_aot_altered_lifted cpu_bmi1_logic_aot_original cpu_bmi1_logic_aot_original_lifted -- -j 2):2.63s(configure3.45s)ctest --preset release -R 'bmi1' --parallel 2 --no-tests=error --output-on-failure): 3/3 passed (2.91s:cpu_aot_bmi10.52s,cpu_aot_bmi1_bit1.62s,cpu_aot_bmi1_logic2.14s)sccache: 11/29 hits; wall22.5sAI-assisted; commands listed were executed locally.