mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:30:53 +01:00
[PR #1339] x64_recomp: sign-extend ALU/CMP/TEST/MOV immediates, fix Asm.li(-1), and handle movnti (X64-RECOMP-SIGNEXT-IMM) #1369
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#1369
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/1339
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:fix/x64-recomp-signext-imm📝 Commits (1)
c641b98x64_recomp: sign-extend ALU/CMP/TEST/MOV immediates, fix Asm.li(-1), and handle movnti📊 Changes
2 files changed (+203 additions, -12 deletions)
View changed files
➕
tests/test_x64_recomp_signext_imm.py(+195 -0)📝
tools/x64_recomp.py(+8 -12)📄 Description
Item ID:
X64-RECOMP-SIGNEXT-IMMAI-assisted: yes
Summary
Fixes silent zero-extension of negative immediates across
_emit_alu,_emit_cmp, and_emit_mov, fixesAsm.li(-1)crash, and handlesmovntiintools/x64_recomp.py:imm8/imm32to the immediate's encoded width:_finishand_finish_groupalready decode83 /r ib,81 /r id,05..3D id,F7 /0 id, andA9 idas signed Python integers, but_emit_aluand_emit_cmpcalledself._load(ins, src, T1)withoutas_size=sz._loadmaskedop[1]with(1 << (src[2] * 8)) - 1, so:and rsp, -16(48 83 e4 f0, standard stack alignment) loaded+0xF0instead of0xFFFFFFFFFFFFFFF0, zeroing bits 8..63 ofrsp.cmp rax, -1(48 83 f8 ff/48 81 f8 ff ff ff ff/48 3d ff ff ff ff) compared against+0xFFor+0xFFFFFFFFinstead of-1.test rax, -1(48 f7 c0 ff ff ff ff/48 a9 ff ff ff ff) masked out bits 32..63.add/sub/or/xorwith negativeimm8/imm32added/subtracted+0xFFor+0xFFFFFFFF.as_size=sztoself._load(ins, src, T1, as_size=sz)in_emit_aluand_emit_cmp, and stashingCTX_A/CTX_Bwhenins.addr in self.matas well as"A" in need.mov qword ptr [mem], imm32(48 C7 /0) andmovnti(0F C3):_emit_mov's special case forC7 /0sign-extension only checkeddst[0] == "r", somov qword ptr [rsp], -1stored0x00000000FFFFFFFFinstead of0xFFFFFFFFFFFFFFFF. Passingas_size=self._op_size(dst)to_loadfixes both register and memory destinations and removes the redundant branch."movnti"alongside"mov"so 32/64-bit non-temporal stores translate cleanly instead of raisingUnhandledInsn("movnti").Asm.li(rd, -1):elif not nzc: self.movn(rd, 0)(identical to#1205and#1329) so materializing0xFFFFFFFFFFFFFFFF(forcmp rax, -1,mov [rsp], -1,push -1, etc.) emitsMOVNinstead of crashing withIndexError.Merge compatibility
#1174,#1202,#1205,#1211,#1213,#1279,#1296,#1306,#1313,#1321, and#1329.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_signext_imm.py -v— 8 tests (4 static ok, 4 exec skipped without runner)tools/x64_recomp.pytoupstream/maincauses 8 failures across all 4 static tests intests/test_x64_recomp_signext_imm.py.#1174,#1202,#1205,#1211,#1213,#1279,#1296,#1306,#1313,#1321,#1329— 0 merge conflicts):tests/test_x64_recomp_signext_imm.py— 8/8 OK (all 4 execution suites + 4 static tests, 0 skips)test_x64_recomp*.pysuites — 134/134 OKpython3 -m compileall -q tools/x64_recomp.py tests/test_x64_recomp_signext_imm.py— OKpython3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_signext_imm.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.