mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:20:53 +01:00
[PR #1373] x64_recomp: emit ARMv8.0 LL/SC atomics for LOCK ALU memory ops #1403
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#1403
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/1373
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:feat/x64-recomp-lock-alu📝 Commits (1)
e8b1173x64_recomp: emit ARMv8.0 LL/SC atomics for LOCK ALU memory ops📊 Changes
2 files changed (+547 additions, -0 deletions)
View changed files
➕
tests/test_x64_recomp_lock_alu.py(+340 -0)📝
tools/x64_recomp.py(+207 -0)📄 Description
Item ID:
X64-RECOMP-LOCK-ALUSummary
tools/x64_recomp.pypreviously ignored theLOCKprefix on memory ALU instructions (lock inc,lock dec,lock add,lock sub,lock and,lock or,lock xor,lock neg,lock not,lock adc,lock sbb— what MSVC_InterlockedIncrement/Decrement/Add/And/Or/Xorcompile to), emitting non-atomic load-modify-store sequences.This PR adds atomic ARMv8.0 LL/SC lowering (
_emit_lock_alu) for all 11 LOCK-valid memory ALU operations across 8/16/32/64-bit operands:Asm.ldaxr,Asm.stlxr): 8/16/32/64-bit acquire-load / release-store exclusives with register-constraint assertions (rs != rt and rs != rn)._emit_lock_alu):-1) and computes the effective address before entering the loop.lock adc/lock sbb, captures incoming x86CF(0or1, handlingADD_KIND,SUB_KIND,LOGIC_KIND, andctx.eflags) intoGTMPbefore the loop so store-exclusive retries always re-read the original incoming carry.LDAXR-> compute ->STLXR->CBNZretry loop using exclusively non-flag-setting instructions, with a non-flag-setting alignment check (and_i + cbnz) and plainldr/strfallback on unaligned 16/32/64-bit addresses so unalignedLOCKops never raiseSIGBUS.lock notpreserves all flags (NZCVandctx.eflags).lock inc/lock decwiden narrow 8/16-bit operands (1 << sh) for exactSF/ZF/OFwhile preserving both live ARMCand materializedctx.eflagsbit 0 (CF).lock adc/lock sbbhandle 8/16-bit flags via widenedADCS/SBCSwith low-bit fill whenCF == 1(using non-csetmarithmetic so it works standalone onmain).lock add/sub/and/or/xor/negemit exact widenedSF/ZF/CF/OF/PF/AFacross 8/16/32/64-bit.LDAXR/STLXRoverhead.Tests (
tests/test_x64_recomp_lock_alu.py)LDAXR/STLXRemission across all 4 widths (8/16/32/64-bit) and all 11LOCKALU ops (including negative immediatelock add qword [rdi], -1), plus confirming unlocked memory ALU ops do not emitLDAXR/STLXR.lock add/sub/and/or/xor/neg, negative sign-extended immediates, adjacent sentinel-byte isolation, and unaligned[rsp+1]fallback.lock inc/lock decCFpreservation (both same-blockSUB_KIND/clcand cross-blockctx.eflags) andlock notfull flag preservation.lock adc/lock sbbacross 8/16/32/64-bit (from bothSUB_KINDandstc) plus chained 128-bit atomiclock add+lock adc.Verification
python3 -I tests/test_x64_recomp_lock_alu.py— 4 tests (1 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_lock_alu.py— OKpython3 -I tests/test_text_write_line_endings.py— 3/3 OKtools/x64_recomp.pytoupstream/mainfails the static test across all 15LOCKsubtests (15 failures).x64_recompPRs, 0 conflicts):tests/test_x64_recomp_lock_alu.py: 4/4 passed (0 skipped)test_x64_recomp_*.pysuites combined: 123/123 passed (0 skipped)AI-assisted: yes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.