Repository navigation
x64_recomp: clear logic OF & high eflags in rt_mkflags, fix parity/ctx_jcc NZCV & T0 clobber (X64-RECOMP-PARITY-LOGIC-EFLAGS) - #1401
Merged
MoonEyes merged 1 commit intoNov 28, 2026
Conversation
…x_jcc NZCV & T0 clobber
Collaborator
|
Red/green: classified READY by dada-lotF (red on main, green on head merged with main); head df07ec2 unchanged since 2026-11-24, before that run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)