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

Open
github-bot wants to merge 1 commit from github-bot/gh-1383 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-24 23:01 UTC · original
IlyassRS3:feat/x64-recomp-xlat-enter → main · +268 −1 · 2 files · 1 commits · open

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)
**@⁠IlyassRS3** on GitHub · 2026-11-24 23:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1383) `IlyassRS3:feat/x64-recomp-xlat-enter` → `main` · +268 −1 · 2 files · 1 commits · open 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)**
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:49:32 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-24 23:02 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-24 23:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1383#pullrequestreview-6048783711) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠kevincommits on GitHub · 2026-11-25 23:24 UTC · original

Independent run with QEMU. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, QEMU 11.1.3 from Homebrew. I merged main at cb1d5f57f into the branch locally (826 commits behind, no conflicts). Head tested: 2193b80d0.

The emitters pass every case in the file under QEMU. The file as shipped fails for the wiring reason in #1409.

  • As shipped: python -I tests/test_x64_recomp_xlat_enter.py is 4 run, 6 failures. _runner's QEMU branch returns xr.run_kernel (raw bytes) where xr.run_result (parsed value) is needed. Suggested fix: xr.run_result in both branches.
  • With RUNNER swapped for xr.run_result in memory (no file changed): 4/4 pass on this branch, including enter at nesting 0 to 3 with the large allocation, xlat with high indices and the upper bits of rax kept, and the flag-preservation cases.
  • The same tests against main's tools/x64_recomp.py: the six exec cases error (both instructions are unhandled there) and the three static checks fail, so the tests do fail before and pass after.

Counts. tests/test_x64_recomp.py 33/33 and tests/test_recomp_census.py 11/11, the same as main. Full standalone suite: 512 run, 507 pass; the 5 that fail are main's 4 plus the new file, for the wiring reason.

I ran the pull request's own cases and wrote no extra ones. No game files used. AI-assisted.

**@⁠kevincommits** on GitHub · 2026-11-25 23:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1383#issuecomment-7177526397) Independent run with QEMU. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, QEMU 11.1.3 from Homebrew. I merged `main` at `cb1d5f57f` into the branch locally (826 commits behind, no conflicts). Head tested: `2193b80d0`. **The emitters pass every case in the file under QEMU. The file as shipped fails for the wiring reason in #1409.** - As shipped: `python -I tests/test_x64_recomp_xlat_enter.py` is 4 run, 6 failures. `_runner`'s QEMU branch returns `xr.run_kernel` (raw bytes) where `xr.run_result` (parsed value) is needed. Suggested fix: `xr.run_result` in both branches. - With `RUNNER` swapped for `xr.run_result` in memory (no file changed): **4/4 pass on this branch**, including `enter` at nesting 0 to 3 with the large allocation, `xlat` with high indices and the upper bits of rax kept, and the flag-preservation cases. - The same tests against `main`'s `tools/x64_recomp.py`: the six exec cases error (both instructions are unhandled there) and the three static checks fail, so the tests do fail before and pass after. **Counts.** `tests/test_x64_recomp.py` 33/33 and `tests/test_recomp_census.py` 11/11, the same as `main`. Full standalone suite: 512 run, 507 pass; the 5 that fail are `main`'s 4 plus the new file, for the wiring reason. I ran the pull request's own cases and wrote no extra ones. No game files used. AI-assisted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1383/head:github-bot/gh-1383'
git switch 'github-bot/gh-1383'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1383'
git switch 'github-bot/gh-1383'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1383'
git switch 'github-bot/gh-1383'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1383'
git switch 'main'
git merge --squash 'github-bot/gh-1383'
git switch 'main'
git merge --ff-only 'github-bot/gh-1383'
git switch 'main'
git merge 'github-bot/gh-1383'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.