mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:20:53 +01:00
[PR #1329] x64_recomp: add 8/16-bit adc/sbb, fix Asm.csinv encoding, sign-extend imm, and stash AF (X64-RECOMP-ADCSBB-NARROW) #1359
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#1359
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/1329
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:feat/x64-recomp-adcsbb-narrow📝 Commits (1)
efd3645x64_recomp: add 8/16-bit adc/sbb, fix Asm.csinv encoding, sign-extend imm, and stash AF📊 Changes
2 files changed (+280 additions, -5 deletions)
View changed files
➕
tests/test_x64_recomp_adcsbb.py(+260 -0)📝
tools/x64_recomp.py(+20 -5)📄 Description
Item ID:
X64-RECOMP-ADCSBB-NARROWAI-assisted: yes
Summary
Implements 8-bit and 16-bit
adc/sbband fixes three bugs uncovered while testing_emit_adcsbbon real arm64 hardware intools/x64_recomp.py:Asm.csinv(csetm) encoding bug (0x9A808000->0xDA800000):CSINVsets bit 30 (op=1, base0xDA800000/ 32-bit0x5A800000), not bit 15 (0x9A808000, which setcond[3]inside aCSELopcode socsetmalways returned0). Verified bit-exact againstclang -arch arm64/otool(csetm w2, hs=0x5A9F33E2,csetm w2, lo=0x5A9F23E2,csetm x2, eq=0xDA9F13E2).adcandsbb(replacingUnhandledInsn("adc/sbb size 1/2")):T0andT1left bysh = 32 - sz * 8(24or16), fills the lowshbits ofT1with1s (csetm+lsr sz*8+orr_r, preserving ARMC) iff x86CF=1, runsadcs/sbcs, and shiftsT0right bysh.(dst, src, cf)8-bitadc+sbbinputs for exact result,SF,ZF,CF, andOF, and verified on Apple M5 arm64 hardware across reg/hi8/mem/imm and chained 16-bit multiword arithmetic._emit_adcsbb(andAsm.li(-1)):as_size=sztoself._load(ins, src, T1, as_size=sz)soadc ax, -1(66 83 d0 ff),adc rax, -1(48 83 d0 ff), andsbb eax, -1(83 d8 ff) sign-extend instead of loading+0xFF.elif not nzc: self.movn(rd, 0)guard inAsm.li(matching#1205) so-1materializes cleanly.CTX_A/CTX_BforAFon alladc/sbbwidths:(dst ^ src ^ (dst ± src ± cf)) & 0x10equals the exact nibble carry/borrow even with carry-in, stashing unshiftedT0/T1when"A" in need or ins.addr in self.matgives exactAFacross 8/16/32/64-bit.Merge compatibility
_emit_adcsbbuntouched (zero overlap with#1202), uses identicalAsm.li(-1)lines as#1205(auto-deduplicated), and leaves#1306/#1205Asmmethods untouched.#1174,#1202,#1205,#1211,#1213,#1279,#1296,#1306,#1313, and#1321.Verification
Tested on Apple M5 arm64 (macOS 27.2.1, Python 3.14; CPU-only, no game files):
python3 -I tests/test_x64_recomp.py— 32 tests (6 ok, 26 skipped without runner)python3 -I tests/test_x64_recomp_adcsbb.py -v— 7 tests (4 static ok, 3 exec skipped without runner)tools/x64_recomp.pytoupstream/mainfails all static tests intests/test_x64_recomp_adcsbb.py.#1174,#1202,#1205,#1211,#1213,#1279,#1296,#1306,#1313,#1321— 0 merge conflicts):tests/test_x64_recomp_adcsbb.py— 7/7 OK (all 3 execution suites + 4 static tests, 0 skips)tests/test_x64_recomp.py— 46/46 OKtests/test_x64_recomp_sse.py— 16/16 OKtests/test_x64_recomp_bitops.py— 9/9 OKtests/test_x64_recomp_rcl_rcr.py— 5/5 OKtests/test_x64_recomp_std_str.py— 5/5 OKtests/test_x64_recomp_muldiv.py— 10/10 OKtests/test_x64_recomp_shifts.py— 9/9 OKtests/test_x64_recomp_atomics.py— 10/10 OKtests/test_x64_recomp_incdec.py— 8/8 OKtests/test_x64_recomp_control_conv.py— 9/9 OKpython3 -m compileall -q tools/x64_recomp.py tests/test_x64_recomp_adcsbb.py— OKpython3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_adcsbb.py— OKpython3 -I tests/test_ci_registration.py— 15/15 OKpython3 -I tests/test_text_write_line_endings.py— 3/3 OK🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.