mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:55:52 +01:00
[PR #1368] x64_recomp: add VEX BMI1 and BMI2 emitters #1398
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1398
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1368
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:feat/x64-recomp-bmi1-bmi2📝 Commits (1)
6204164x64_recomp: add VEX BMI1 and BMI2 emitters📊 Changes
2 files changed (+737 additions, -0 deletions)
View changed files
➕
tests/test_x64_recomp_bmi1_bmi2.py(+475 -0)📝
tools/x64_recomp.py(+262 -0)📄 Description
Item ID:
X64-RECOMP-BMI1-BMI2Summary
tools/x64_recomp.pypreviously decoded all map-2 (0F 38) and map-3 (0F 3A) VEX instructions as generic("simd", "V W")/("simd", "V W Ib"), which misdecoded every Zen 2 / AVX2 BMI1 and BMI2 integer instruction with XMM operands and failed translation.This PR adds decoding, flag tracking, and ARM64 lowering for all 13 VEX.LZ BMI1 and BMI2 instructions across 32-bit (
VEX.W=0) and 64-bit (VEX.W=1) register and memory operands:_decode_vex_bmi, dispatched fromdecode_onefor non-EVEXmap in (2, 3)withVEX.L == 0):andn(0F38 F2),blsr(0F38 F3 /1),blsmsk(0F38 F3 /2),blsi(0F38 F3 /3),bextr(0F38 F7,pp=0).bzhi(0F38 F5,pp=0),pext(F3 0F38 F5),pdep(F2 0F38 F5),mulx(F2 0F38 F6),shlx(66 0F38 F7),sarx(F3 0F38 F7),shrx(F2 0F38 F7),rorx(F2 0F3A F0 /r ibwithvvvv == 0).VEX.R,VEX.X, andVEX.Binto_modrmsor8..r15work acrossreg,vvvv, andr/moperands, resolves RIP-relativeabstargets pastimm8forrorx, leavesVEX.L == 1untouched, and marks invalid0F38 F3/regextensions asunknownwith exact length.FLAG_WRITERS&_emit_bmi):andn,blsr,blsmsk,blsi,bextr,bzhiinFLAG_WRITERS("NZCV"), setting exactSF,ZF,CF(src == 0forblsr/blsmsk,src != 0forblsi,index >= Wforbzhi,0forandn/bextr), andOF = 0on both ARMNZCVand materializedctx.eflags.shlx,sarx,shrx,rorx,mulx,pdep,pext) using strictly non-flag-setting ARMv8.0 instructions:LSLV/ASRV/LSRV,ROR,UMADDL/MUL+UMULH(writinglobeforehisohi == loyields the high half per Intel SDM), and lowest-set-bitpdep/pextloops — preserving all flags (CF/ZF/SF/OF/PF/AF).Tests (
tests/test_x64_recomp_bmi1_bmi2.py)clang -arch x86_64 -mbmi -mbmi2) decode/extended-reg/RIP-relative/rejection checks and full 13-instruction 32/64-bit translation verification.andn,blsr,blsmsk,blsi,bextr) across 32/64-bit, boundary counts/lengths, and ARMNZCV+ cross-blockctx.eflags.bzhi,shlx,sarx,shrx,rorx,mulx) including index wrapping (0x104),index >= WCF=1, count masking mod 32/64, 128-bit unsigned product, andmulx rdx, rdx, rcx(hi == lo == rdx).pdep/pextacross zero/all-ones/Morton/64-bit sparse masks + sequential flag-preservation check across all 7 flag-preserving BMI2 ops on both ARMNZCVand cross-blockctx.eflags.Verification
python3 -I tests/test_x64_recomp_bmi1_bmi2.py— 5 tests (2 static OK, 3 exec skipped without runner)python3 -I tests/test_x64_recomp.py— OKpython3 -m compileall -q make_game.py tools tests— OKpython3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_bmi1_bmi2.py— OKpython3 -I tests/test_text_write_line_endings.py— 3/3 OKtools/x64_recomp.pytoupstream/mainfails all static test methods (19 failures, 1 error).x64_recompPRs, 0 conflicts):tests/test_x64_recomp_bmi1_bmi2.py: 5/5 passed (0 skipped)test_x64_recomp_*.pysuites combined: 119/119 passed (0 skipped)AI-assisted: yes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.