mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:30:53 +01:00
[PR #1379] x64_recomp: preserve ARM NZCV in _maybe_mkflags and ctx.eflags in _emit_flagctl #1409
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#1409
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/1379
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:fix/x64-recomp-flagctl-preserve📝 Commits (1)
5d91014x64_recomp: preserve ARM NZCV in _maybe_mkflags and ctx.eflags in _emit_flagctl📊 Changes
2 files changed (+240 additions, -9 deletions)
View changed files
➕
tests/test_x64_recomp_flagctl_mat.py(+229 -0)📝
tools/x64_recomp.py(+11 -9)📄 Description
Item ID:
X64-RECOMP-SUB-MAT-FLAGCTLSummary
Fixes two flag-materialization bugs in
tools/x64_recomp.py:_maybe_mkflagsinverted live ARMNZCV.Cin-place for materializedSUB_KINDinstructions:_maybe_mkflagsflipped bit 29 of ARMNZCV(eor_i(GTMP, GTMP, 0x20000000); msr_nzcv(GTMP)) before callingrt_mkflags(0)and never restored it — even thoughrt_mkflagsalready implementskind == 1(SUB_KIND) to invert ARM borrow intoctx.eflagswhile preservingNZCVinx5.SUB_KINDinstruction (cmp,sub,sbb,neg,cmps,scas) materialized flags for a downstream block and also fed a same-block carry consumer viaarm_path, the same-block consumer assumedSUB_KINDARM polarity (!CF) and got the inverted carry flag.cmp a, b; jb less; je equal), wherejein the fallthrough block forcescmpintoself.mat: onmain,(3 < 5)jumped togreaterand(9 > 5)jumped toless.kind = 2 if ins.mnem in LOGIC_KIND else (1 if ins.mnem in SUB_KIND else 0)toself._mkflags(kind)without touching ARMNZCV._emit_flagctl(clc,stc,cmc) overwrote the entirectx.eflagsword:_emit_flagctlended withself._maybe_mkflags(ins), callingrt_mkflags(0)and rewritingSF,ZF,OF,PF, andAFinctx.eflagsfrom currentNZCVandCTX_RES/CTX_A/CTX_Binstead of updating onlyCF.ins.addr in self.mat, extract bit 29 (C) from ARMNZCVand patch only bit 0 (EF_CF) ofctx.eflagsviabfi.Tests (
tests/test_x64_recomp_flagctl_mat.py)_maybe_mkflagspasseskind = 1(movz w0, #1) without invertingGTMP/NZCV, and verifies materializedclc/stc/cmcpatchEF_CFwithout emitting a secondbl rt_mkflags.cmp; jb; jeacross 7(a, b)pairs (small, equal, signed-boundary0x7FFFFFFFvs0x80000000).subwith same-blocksetc+ cross-blocksets, andsub; cmc; jmp +0flag checks.clc/stc/cmcpreservingOF/SF/ZFaftersub,popf, andxor(LOGIC_KIND).Verification
python3 -I tests/test_x64_recomp_flagctl_mat.py— 5 tests (2 static OK, 3 exec skipped without runner)python3 -I tests/test_x64_recomp.py— OKpython3 -m compileall -q make_game.py tools tests— OKpython3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_flagctl_mat.py— OKpython3 -I tests/test_text_write_line_endings.py— 3/3 OKupstream/main(0f98d193c+ #1174 runner without this fix):cmp; jb; je,sub; setc; jmp; sets,sub; cmc, and static assertion failed onmain).x64_recompPRs, 0 conflicts):tests/test_x64_recomp_flagctl_mat.py: 5/5 passed (0 skipped)test_x64_recomp_*.pysuites combined: 128/128 passed (0 skipped)AI-assisted: yes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.