mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:30:53 +01:00
[PR #1321] x64_recomp: fix cwd/REX.W conv, ret imm16, indirect call [rsp], and jrcxz/loop (X64-RECOMP-CONV-CALL-RET-LOOP) #1352
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#1352
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/1321
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:fix/x64-recomp-conv-call-ret-loop📝 Commits (2)
fa76977x64_recomp: fix cwd/REX.W conv, ret imm16, indirect call [rsp], and jrcxz/loop082b42dtests: match any scratch register loading ctx.eflags in cross-block loope check📊 Changes
2 files changed (+301 additions, -16 deletions)
View changed files
➕
tests/test_x64_recomp_control_conv.py(+271 -0)📝
tools/x64_recomp.py(+30 -16)📄 Description
Item ID:
X64-RECOMP-CONV-CALL-RET-LOOPAI-assisted: yes
Summary
Fixes five correctness and crash bugs in
tools/x64_recomp.py(_emit_conv,_emit_branch,_emit_call,_emit_ret):_emit_conv(66 99cwdcopiedAXintoDXinstead of sign-extendingAX):a.sxth(T0, GMAP[0], sf=0); a.bfi(GMAP[2], T0, 0, 16)wrote the low 16 bits ofAXdirectly intoDXinstead of its sign bit (0x0000/0xFFFF). Fixed by insertinga.asr(T0, T0, 16, sf=0)beforebfi.REX.Wtakes priority over0x66(66 48 98->cdqe,66 48 99->cqo)._emit_ret(C2 iwret imm16crashed withIndexErrorand failed forimm16 >= 4096):ins.ops[1]instead ofins.ops[0][1], raisingIndexError: tuple index out of rangeon everyret imm16.imm16directly to ARM64ADD imm12(0..4095), raisingAssertionErrorforimm16 >= 4096. Fixed usinga.li(T0, imm); a.add_r(GMAP[4], GMAP[4], T0)whenimm >= 4096._emit_call(indirectcall [rsp+disp]/call rspdecrementedrspbefore loading the target):str_pre(T0, GMAP[4], -8)) beforeself._load(ins, op, ADDR_T)causedcall [rsp]to read the pushed return address andcall [rsp+8]to read 8 bytes too low.ADDR_Tbefore pushing the return address._emit_branch(jrcxzvs67 jecxzandloop/loope/loopne):E3(jrcxz) hardcodedsf=0, ignoring the upper 32 bits ofrcxin 64-bit mode; fixed tosf = 0 if ins.addrsize else 1.loop/loope/loopnenow respect0x67(ins.addrsize) for 32-bitecxvs 64-bitrcx, andloope/loopnecheckself.arm_pathso cross-blockZFreadsctx.eflagsvia_ctx_jccinstead of stale ARMZ.Merge compatibility
_emit_conv(lines 1855–1872) and_emit_branch/_emit_call/_emit_ret(lines 2140–2175 onmain).#1174,#1202,#1205,#1211,#1213,#1279,#1296,#1306, and#1313.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_control_conv.py -v— 9 tests (5 static ok, 4 exec skipped without runner)tools/x64_recomp.pytoupstream/maincauses 8 failures across all 5 static tests intests/test_x64_recomp_control_conv.py.#1174,#1202,#1205,#1211,#1213,#1279,#1296,#1306,#1313— 0 merge conflicts):tests/test_x64_recomp_control_conv.py— 9/9 OK (all 4 execution suites + 5 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 OKpython3 -m compileall -q tools/x64_recomp.py tests/test_x64_recomp_control_conv.py— OKpython3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_control_conv.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.