mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:50:52 +01:00
[PR #1313] x64_recomp: fix 8/16-bit inc/dec, CF preservation, and inc/dec/neg AF (X64-RECOMP-INCDEC-WIDTH-CF) #1343
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#1343
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/1313
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:fix/x64-recomp-incdec-width-cf📝 Commits (1)
7e38867x64_recomp: fix 8/16-bit inc/dec, CF preservation, and inc/dec/neg AF📊 Changes
2 files changed (+340 additions, -18 deletions)
View changed files
➕
tests/test_x64_recomp_incdec.py(+294 -0)📝
tools/x64_recomp.py(+46 -18)📄 Description
Item ID:
X64-RECOMP-INCDEC-WIDTH-CFAI-assisted: yes
Summary
Fixes five correctness bugs in
tools/x64_recomp.py(_emit_incdecand_emit_negnot):inc/decadded/subtracted1after shiftingT0left by 24/16:_emit_incdecshiftedT0left bysh = 32 - sz * 8, then emittedadds/subswith immediate1and shifted right bysh.inc aland 16-bitinc axcomplete no-ops (((v << 24) + 1) >> 24 == v) and brokeZFon 8/16-bitdec((1 << 24) - 1 == 0x00FFFFFF, leavingZ=0).1 << sh(movz T1, 1 << (sh - 16), hw=1, sf=0->0x01000000/0x00010000) when flags are live, and using plainadd/sub+uxtb/uxthwhen flags are dead.inc/decdestroyedCFviabfi(T3, GTMP, 29, 1)copying bit 0 instead of bit 29:BFIinserts the lowest bits (bit 0, always0inMRS NZCV) ofGTMPinto bit 29 ofT3, unconditionally zeroingCFwheneverkeep_cran.a.ubfx(GTMP, GTMP, 29, 1)beforea.bfi(T3, GTMP, 29, 1).keep_c = "C" in needwas alwaysFalseon same-blockCFconsumers:"C"is not inFLAG_WRITERS["inc"]/FLAG_WRITERS["dec"]("NZVPA"),self.needed[ins.addr]never contained"C", sostc; inc eax; jcoradd; inc; adcclobbered ARMC.add/subwhennot flaggyand always preserving ARMCaroundadds/subswhenflaggy.decinverted survivingCFviaSUB_KIND:_maybe_mkflagsflipped ARM bit 29 for everySUB_KINDinstruction includingdec, even thoughdecdoes not writeCF(inverting an upstreamstc/clc/cmpcarry bit)._emit_incdecby callingself._mkflags(0)directly onins.addr in self.matwhile saving/restoring bit 0 (EF_CF) ofctx.eflagsinGTMP(preserved acrossrt_mkflags).AFoperand stashing oninc/dec/neg, andnotrunning_stash_res/_maybe_mkflags:CTX_A/CTX_Bforinc/dec(orig,1) andneg(0,orig) whenever"A" in need or ins.addr in self.matsort_mkflagscomputes exactAF.notreturn immediately after_storeso it never touches flags or context flag slots.Merge compatibility
_emit_incdecand_emit_negnot(lines 1655–1698 onmain).#1174,#1202,#1205,#1211,#1213,#1279,#1296, and#1306.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_incdec.py -v— 8 tests (5 static ok, 3 exec skipped without runner)tools/x64_recomp.pytoupstream/maincauses 5/5 static test failures intests/test_x64_recomp_incdec.py.#1174,#1202,#1205,#1211,#1213,#1279,#1296,#1306— 0 merge conflicts):tests/test_x64_recomp_incdec.py— 8/8 OK (all 3 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 OKpython3 -m compileall -q tools/x64_recomp.py tests/test_x64_recomp_incdec.py— OKpython3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_incdec.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.