mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:20:53 +01:00
[PR #1401] x64_recomp: clear logic OF & high eflags in rt_mkflags, fix parity/ctx_jcc NZCV & T0 clobber (X64-RECOMP-PARITY-LOGIC-EFLAGS) #1430
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#1430
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/1401
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/x64-recomp-parity-logic-eflags📝 Commits (1)
df07ec2x64_recomp: clear logic OF & high eflags in rt_mkflags, fix parity/ctx_jcc NZCV & T0 clobber📊 Changes
2 files changed (+300 additions, -15 deletions)
View changed files
➕
tests/test_x64_recomp_parity_logic_eflags.py(+279 -0)📝
tools/x64_recomp.py(+21 -15)📄 Description
Item ID:
X64-RECOMP-PARITY-LOGIC-EFLAGSSummary
Fixes four flag-materialization and condition-testing bugs in
tools/x64_recomp.py:rt_mkflags(kind == 2,LOGIC_KIND) leaked staleOF: ARM64ands/tstleavesNZCV.Vunchanged from prior arithmetic, andrt_mkflagscopiedNZCV.VintoEF_OF(bit 11) even whenkind == 2(and/or/xor/test), corrupting cross-blockjo/jno/jl/jge/jle/jg. Now clearsOF = 0forkind == 2, matchingCF = 0.rt_mkflagswrote only 32 bits ofCTX_EFLAGS:a.str(2, CTX_REG, CTX_EFLAGS, size=4)left stale upper 32 bits written bypopfq(size=8), leaking them into subsequentpushfq. Changed tosize=8._parity_jccignoredCTX_EFLAGSafterpopf/sahf/materialized paths and clobbered ARMNZCV: previously always folded staleCTX_RESand rantst_i(T0, 1), corruptingjp/setp/cmovpafterpopf/cross-block paths AND destroying live ARMNZCVfor any subsequent same-blocksetcc/cmov/jcc. Now readsEF_PF(bit 2) fromCTX_EFLAGSwhenprod is None,prod.mnem in ("popf", "sahf"), orprod.addr in self.mat, and usestbz/tbnz(never modifyingNZCV)._parity_jccand_ctx_jccclobberedT0(holding_emit_cmov's loaded source operand) and_ctx_jcc_regclobberedNZCV: everycmovp/cmovnpand every cross-blockcmovccloadedsrcintoT0, then called_parity_jcc/_ctx_jccwhich overwroteT0withctx.eflagsor foldedctx.resbeforea.mov(g, T0, sf). Switching_parity_jcc/_ctx_jccto scratchT2and usingtbz/tbnzfor single-bit conditions in_ctx_jcc_regpreserves bothT0and live ARMNZCV.Tests & Verification
python3 -m compileall -q make_game.py tools tests— OKpython3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_parity_logic_eflags.py— OKpython3 -I tests/test_x64_recomp_parity_logic_eflags.py -v— 2 static OK (5 exec skip cleanly without#1174runner)python3 -I tests/test_x64_recomp.py— 6 static OK (26 exec skipped)python3 -I tests/test_text_write_line_endings.py— 3/3 OKtests/test_x64_recomp_parity_logic_eflags.pyon unpatchedupstream/main+#1174): 5 failures (FAILED (failures=5)).upstream/maincdb003ea1with#1174+ all 19 other openx64_recompPR branches):tests/test_x64_recomp_parity_logic_eflags.py: 7/7 OK (0 skipped) on native Apple M5 arm64tests/test_x64_recomp_*.pysuites combined: 145/145 OK (0 skipped)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.