mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:45:54 +01:00
[PR #1306] x64_recomp: add cmpxchg, xadd, and atomic LL/SC memory xchg emitters (X64-RECOMP-ATOMICS) #1336
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#1336
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/1306
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:feat/x64-recomp-atomics📝 Commits (1)
c88ff19x64_recomp: add cmpxchg, xadd, and atomic LL/SC memory xchg emitters📊 Changes
2 files changed (+644 additions, -5 deletions)
View changed files
➕
tests/test_x64_recomp_atomics.py(+471 -0)📝
tools/x64_recomp.py(+173 -5)📄 Description
Item ID:
X64-RECOMP-ATOMICSAI-assisted: yes
Summary
Implements
cmpxchg,xadd, and ARMv8.0 LL/SC (ldaxr*/stlxr*/clrex) memory atomics intools/x64_recomp.py, replacing theUnhandledInsn("... needs atomics")stub in_emit_xchg:"cmpxchg": "NZCVPA"and"xadd": "NZCVPA"inFLAG_WRITERS, and added"cmpxchg"toSUB_KIND(socmpxchg'ssubs_rborrow polarity matchescmpacross_arm_cond,_maybe_mkflags,_emit_adcsbb, and_emit_flagctl).ins.flags_r = "NZCVPA"oncmpxchg/xaddin_classify(neither reads flags).Asm:ldaxr(rt, rn, size)(ldaxrb/ldaxrh/ldaxr w/ldaxr x),stlxr(rs, rt, rn, size)(stlxrb/stlxrh/stlxr w/stlxr x, assertingrs != rt and rs != rnper ARMv8CONSTRAINED UNPREDICTABLErules), andclrex(). Verified bit-exact againstclang -arch arm64/otool.xchg(implicitLOCK):ldaxr/stlxrretry loop for naturally aligned memory accesses (with an unalignedldr/strfallback forsize > 1usingand_i+cbnzsoNZCVflags are never disturbed).ADDR_Tand loads the source register before storing, keepingxchg [rax], raxsafe.cmpxchg(0F B0/0F B1) across 8/16/32/64-bit (reg, hi8, mem, unlocked &LOCK):srcintodstwhile leavingraxuntouched (preserving upper 32/48/56 bits).old_dstintoal/ax/eax/rax(zero-extendingraxon 32-bit), emitsclrexinLOCKLL/SC paths, and zero-extends 32-bit registerdstper Intel SDM (DEST := TEMP).SF, ZF, CF, OF, PF, AF) identically toCMP ACC, old_dstacross all 4 widths, includingCTX_RES/CTX_A/CTX_Bfor materialization.xadd(0F C0/0F C1) across 8/16/32/64-bit (reg, hi8, mem, unlocked &LOCK):old_dsttosrcbeforeold_dst + old_srctodst, soxadd reg, regyields2 * reg, and computesADDR_Tbefore updatingsrcsolock xadd [rax], raxworks cleanly.SF, ZF, CF, OF, PF, AF) identically toADD old_dst, old_srcacross all 4 widths.Merge compatibility
PRIMARY[0x90..0x97]anddecode_oneuntouched (zero overlap with#847,#1120,#1121,#1246).#1174,#1202,#1205,#1211,#1213,#1279, and#1296.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_atomics.py -v— 10 tests (6 static ok, 4 exec skipped without runner)tools/x64_recomp.pytoupstream/maincauses 6 failures/errors across all 6 static tests intests/test_x64_recomp_atomics.py.#1174,#1202,#1205,#1211,#1213,#1279,#1296— 0 merge conflicts):tests/test_x64_recomp_atomics.py— 10/10 OK (all 4 execution suites + 6 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 OKpython3 -m compileall -q tools/x64_recomp.py tests/test_x64_recomp_atomics.py— OKpython3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_atomics.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.