[PR #1383] x64_recomp: add xlat/xlatb and enter emitters (X64-RECOMP-XLAT-ENTER) #1413

Open
opened 2026-11-26 20:21:10 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1383
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: feat/x64-recomp-xlat-enter


📝 Commits (1)

  • 2193b80 x64_recomp: add xlat/xlatb and enter emitters

📊 Changes

2 files changed (+268 additions, -1 deletions)

View changed files

➕ tests/test_x64_recomp_xlat_enter.py (+226 -0)
📝 tools/x64_recomp.py (+42 -1)

📄 Description

Item ID: X64-RECOMP-XLAT-ENTER

Summary

Adds AArch64 emitters for xlat/xlatb (0xD7) and enter (0xC8) in tools/x64_recomp.py:

  • xlat / xlatb (0xD7):
    • Updated PRIMARY[0xD7] from ("xlat", "sys") to ("xlat", "") and classified "xlat" as "misc" so decode_one and _emit_one handle it directly instead of rejecting it as an unhandled system instruction.
    • Emits AL := *(uint8_t *)(base + zero_extend(AL)) where base is RBX (or zero-extended EBX under 67 address-size override, ins.addrsize == 1), inserting only the low 8 bits into RAX via bfi so the upper 56 bits of RAX and all flags are preserved.
  • enter imm16, imm8 (0xC8):
    • Classified "enter" as "misc" (was already decoded by PRIMARY[0xC8] = ("enter", "iw,ib")) and added _emit_enter.
    • Pushes RBP, snapshots frame_temp = RSP, copies nesting - 1 lexical display frame pointers from [RBP - 8*i] and pushes frame_temp when (imm8 & 31) > 0, sets RBP = frame_temp, and subtracts unsigned alloc = imm16 & 0xFFFF from RSP (supporting alloc >= 4096 without overflowing ARM SUB (immediate)). Preserves all flags.

Tests & Verification

  • AI-assisted: yes
  • Host / hardware: macOS (Apple M5, arm64)
  • Standalone checks on this branch (upstream/main 28a32e190):
    • python3 -m compileall -q make_game.py tools tests — OK
    • python3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_xlat_enter.py — OK
    • python3 -I tests/test_x64_recomp_xlat_enter.py — 1 static test OK (3 exec tests skip cleanly without #1174 runner)
    • python3 -I tests/test_x64_recomp.py — 6 static OK (26 exec skipped)
    • python3 -I tests/test_text_write_line_endings.py — 3/3 OK
  • Mutation proof: running tests/test_x64_recomp_xlat_enter.py against unpatched upstream/main fails with 8 assertion failures.
  • Native Apple M5 execution (19-way scratch merge with #1174 + all 17 other open x64_recomp PR branches):
    • 0 merge conflicts across all 19 branches
    • tests/test_x64_recomp_xlat_enter.py: 4/4 OK (0 skipped) on native Apple M5 arm64
    • All 18 tests/test_x64_recomp_*.py suites combined: 132/132 OK (0 skipped)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1383 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/x64-recomp-xlat-enter` --- ### 📝 Commits (1) - [`2193b80`](https://github.com/ubiquitarianism/leonida/commit/2193b80d0553ddb0ff7552b42a96a83e237a40b3) x64_recomp: add xlat/xlatb and enter emitters ### 📊 Changes **2 files changed** (+268 additions, -1 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_x64_recomp_xlat_enter.py` (+226 -0) 📝 `tools/x64_recomp.py` (+42 -1) </details> ### 📄 Description Item ID: `X64-RECOMP-XLAT-ENTER` ## Summary Adds AArch64 emitters for `xlat`/`xlatb` (`0xD7`) and `enter` (`0xC8`) in `tools/x64_recomp.py`: - **`xlat` / `xlatb` (`0xD7`)**: - Updated `PRIMARY[0xD7]` from `("xlat", "sys")` to `("xlat", "")` and classified `"xlat"` as `"misc"` so `decode_one` and `_emit_one` handle it directly instead of rejecting it as an unhandled system instruction. - Emits `AL := *(uint8_t *)(base + zero_extend(AL))` where `base` is `RBX` (or zero-extended `EBX` under `67` address-size override, `ins.addrsize == 1`), inserting only the low 8 bits into `RAX` via `bfi` so the upper 56 bits of `RAX` and all flags are preserved. - **`enter imm16, imm8` (`0xC8`)**: - Classified `"enter"` as `"misc"` (was already decoded by `PRIMARY[0xC8] = ("enter", "iw,ib")`) and added `_emit_enter`. - Pushes `RBP`, snapshots `frame_temp = RSP`, copies `nesting - 1` lexical display frame pointers from `[RBP - 8*i]` and pushes `frame_temp` when `(imm8 & 31) > 0`, sets `RBP = frame_temp`, and subtracts unsigned `alloc = imm16 & 0xFFFF` from `RSP` (supporting `alloc >= 4096` without overflowing ARM `SUB (immediate)`). Preserves all flags. ## Tests & Verification - **AI-assisted**: yes - **Host / hardware**: macOS (Apple M5, arm64) - Standalone checks on this branch (`upstream/main` `28a32e190`): - `python3 -m compileall -q make_game.py tools tests` — OK - `python3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_xlat_enter.py` — OK - `python3 -I tests/test_x64_recomp_xlat_enter.py` — 1 static test OK (3 exec tests skip cleanly without `#1174` runner) - `python3 -I tests/test_x64_recomp.py` — 6 static OK (26 exec skipped) - `python3 -I tests/test_text_write_line_endings.py` — 3/3 OK - **Mutation proof**: running `tests/test_x64_recomp_xlat_enter.py` against unpatched `upstream/main` fails with 8 assertion failures. - **Native Apple M5 execution (19-way scratch merge with `#1174` + all 17 other open `x64_recomp` PR branches)**: - 0 merge conflicts across all 19 branches - `tests/test_x64_recomp_xlat_enter.py`: **4/4 OK (0 skipped)** on native Apple M5 arm64 - All 18 `tests/test_x64_recomp_*.py` suites combined: **132/132 OK (0 skipped)** --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1413
No description provided.