mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:15:51 +01:00
[PR #1205] x64_recomp: bt/bts/btr/btc, bsf/bsr, tzcnt/lzcnt, and popcnt emitters (X64-RECOMP-BITOPS) #1236
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#1236
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/1205
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:feat/x64-recomp-bitops📝 Commits (2)
fad93a5x64_recomp: bt/bts/btr/btc, bsf/bsr, tzcnt/lzcnt, and popcnt emitters (X64-RECOMP-BITOPS)a491079tests: encode xor eax, 0x80 with imm32 (35 80 00 00 00) instead of sign-extended imm8📊 Changes
2 files changed (+481 additions, -3 deletions)
View changed files
➕
tests/test_x64_recomp_bitops.py(+311 -0)📝
tools/x64_recomp.py(+170 -3)📄 Description
Claimed in the coordination issue as: X64-RECOMP-BITOPS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143260452)
What and why
Implements the remaining decoded-but-unemitted bit-manipulation instructions in
tools/x64_recomp.py(independent of#1174and#1202, and conflict-free with all openx64_recompPRs):Asm.rbit/Asm.clz: adds 32-bit and 64-bit bit-reverse and count-leading-zeros encodings (verified against Apple Clang / LLVM 21).bt/bts/btr/btc(_emit_bt):16/32/64), updateCFvia_set_cfwithout clobberingN/Z/V, and preserve upper bits on 16-bit writes.0F BA /4../7) mask the immediate modulo operand width; memory register forms (0F A3/AB/B3/BB) sign-extend the bit index from operand width (sxth/sxtw/64-bit) to index bytes before or after the base address (base + (idx >>s 3), bitidx & 7).flags_r = "C"dependency onbts/btr/btcin_classify.bsf/bsr: setsZF = (src == 0)and leavesdstunmodified whensrc == 0(matching x86-64 hardware); computes LSB/MSB index viarbit/clzfor 16/32/64-bit operands.tzcnt(F3 0F BC) /lzcnt(F3 0F BD): decodesF3-prefixed0F BC/0F BDseparately frombsf/bsr, returns operand width (16/32/64) whensrc == 0, and setsCF = (src == 0)andZF = (result == 0).popcnt(F3 0F B8): mapsF3-prefixedpopcnt_jmpetopopcnt(leaving unprefixed0F B8unhandled assys), computes 16/32/64-bit Hamming weight with pure-GPR SWAR (no FP/SIMD dependency), and setsZF = (src == 0)(N=C=V=0).Asm.li(rd, -1): when all four 16-bit chunks are0xFFFF,nzcwas empty andchunks[nzc[0]]raisedIndexError; now emitsmovn rd, #0.tests/test_x64_recomp_bitops.py): 9 tests covering decoding, LLVM 21–verified encodings, translation, and 5 end-to-end execution tests (BitopsExecTests).Tested
main:tests/test_x64_recomp_bitops.py(4 cross-platform passed, 5 exec cleanly skipped without QEMU),tests/test_x64_recomp.py,tests/test_recomp_census.py,tests/test_ci_registration.py,tests/test_text_write_line_endings.py,compileall,make_game.py --help,check_no_game_data.py: all passed.#1174and#1202in a scratch checkout):tests/test_x64_recomp_bitops.py9/9 passed,tests/test_x64_recomp_sse.py16/16 passed,tests/test_x64_recomp.py46/46 passed (71/71 total).git apply --check) against openx64_recompPRs#847,#950,#1120,#1121,#1174, and#1202.GPUs tested: n/a (CPU x86-64 -> arm64 recompiler; tested natively on Apple M5 arm64, macOS 27.2.1)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.