mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:25:53 +01:00
[PR #1357] x64_recomp: add cmpxchg8b and cmpxchg16b emitters #1389
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#1389
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/1357
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:feat/x64-recomp-cmpxchg8b-16b📝 Commits (1)
750fcb6x64_recomp: add cmpxchg8b and cmpxchg16b emitters📊 Changes
2 files changed (+590 additions, -2 deletions)
View changed files
➕
tests/test_x64_recomp_cmpxchg16b.py(+488 -0)📝
tools/x64_recomp.py(+102 -2)📄 Description
Item ID:
X64-RECOMP-CMPXCHG8B-16BSummary
Adds decoding, classification, ARMv8.0 exclusive-pair assembler helpers, and code generation for x86-64 double-width compare-and-exchange instructions
cmpxchg8b(0F C7 /1) andcmpxchg16b(REX.W + 0F C7 /1) intools/x64_recomp.py:OF[0xC7]/_finish_groupgrp9):0F C7 /1withmod != 3ascmpxchg8b(m64, size 8) or, whenREX.Wis set,cmpxchg16b(m128, size 16).abstargets, ignoresREX.Rfor the/1opcode extension and ignores66operand-size prefix per Intel SDM, and marksmod == 3or non-/1group 9 forms (rdrand,rdseed,vmptrld, etc.) asunknownwith accurate instruction lengths."cmpxchg8b": "Z"and"cmpxchg16b": "Z"inFLAG_WRITERSand classifies them asins.kind = "cas2",ins.flags_w = "Z".Asm.ldaxp,Asm.stlxp,Asm.clrex):clang -arch arm64+otool -t:LDAXP(0x887F8000/0xC87F8000),STLXP(0x88208000/0xC8208000), andCLREX(0xD5033F5F), with register-constraint assertions (rt1 != rt2,rs not in (rt1, rt2, rn))._emit_cas2):RAX/RDX(safe when the base/index register aliasesRAX/RDX, e.g.,lock cmpxchg8b [rax]).LOCK-prefixed instructions, checks alignment via non-flag-settingand_i + cbnz(8-byte forcmpxchg8b, 16-byte forcmpxchg16b), runs an ARMv8.0LDAXP/STLXPretry loop (callingCLREXon mismatch), and falls back to non-exclusiveldr/strpairs on unaligned addresses to avoidSIGBUS. Unlocked instructions emit directldr/strpairs without LL/SC overhead.NZCV(eor_r + orr_r + cbnz). Forcmpxchg8b, compares low 32 bits (EDX:EAX), preserves upper 32 bits ofRAX/RDXon match, and zero-extendsRAX/RDXon mismatch.ZF: patches bit 30 of ARMNZCVviamrs_nzcv + bfi + msr_nzcvwhenZis live, and patches bit 6 (EF_ZF) ofctx.eflagswhen materialized — preservingCF,SF,OF,PF, andAF(including whenZFis dead).Tests (
tests/test_x64_recomp_cmpxchg16b.py)LDAXP/STLXP/CLREXencodings and constraint assertions, and LOCK vs unlocked LL/SC emission checks.cmpxchg8bmatch/mismatch/upper-32-bit zero-extension/unaligned+1/+4/[rax]aliasing,cmpxchg16b128-bit match/bit-63 mismatch/unaligned+8/Windows_InterlockedCompareExchange128retry loop, andCF/SF/OF/PFpreservation across same-block ARMNZCV, cross-block materializedctx.eflags, and dead-ZFpaths.Verification
python3 -I tests/test_x64_recomp_cmpxchg16b.py— 6 tests (3 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_cmpxchg16b.py— OKpython3 -I tests/test_ci_registration.py— 15/15 OKpython3 -I tests/test_text_write_line_endings.py— 3/3 OKtools/x64_recomp.pytoupstream/mainfails all static test methods (10 failures, 1 error).x64_recompPRs, 0 conflicts):tests/test_x64_recomp_cmpxchg16b.py: 6/6 passed (0 skipped)test_x64_recomp_*.pysuites combined: 108/108 passed (0 skipped)AI-assisted: yes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.