[PR #1408] x64_recomp: handle 16-bit operand-size override (66) in push and pop (X64-RECOMP-PUSH-POP-16) #1438

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

📋 Pull Request Information

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

Base: main ← Head: fix/x64-recomp-push-pop-16


📝 Commits (1)

  • c6d1639 x64_recomp: handle 16-bit operand-size override (66) in push and pop

📊 Changes

2 files changed (+189 additions, -4 deletions)

View changed files

➕ tests/test_x64_recomp_push_pop_16.py (+173 -0)
📝 tools/x64_recomp.py (+16 -4)

📄 Description

Item ID: X64-RECOMP-PUSH-POP-16

Summary

Fixes 16-bit operand-size override (66 prefix without REX.W) in _emit_pushpop in tools/x64_recomp.py:

  • push (66 50..57, 66 41 50..57, 66 68 iw, 66 6A ib, 66 FF /6): loads 2 bytes (or sign-extended imm8 masked to 16 bits) and emits str_pre(T0, rsp, -2, size=2) (STRH W0, [X23, #-2]!) instead of always decrementing RSP by 8 and writing 8 bytes.
  • pop (66 58..5F, 66 41 58..5F, 66 8F /0): emits ldr_post(T0, rsp, 2, size=2) (LDRH W0, [X23], #2), inserts only the low 16 bits via bfi(..., 0, 16) for register destinations (preserving upper 48 bits), and stores exactly 2 bytes via str(..., size=2) for memory destinations (after the post-increment of RSP, matching Intel SDM for pop word ptr [rsp+disp]).
  • 66 + REX.W precedence (66 48 50, 66 48 58): REX.W overrides 66, preserving full 64-bit push/pop (±8).

Tests & Verification

  • AI-assisted: yes
  • Host / hardware: macOS (Apple M5, arm64)
  • Standalone checks on upstream/main (3a0af1f15):
    • 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_push_pop_16.py — OK
    • python3 -I tests/test_x64_recomp_push_pop_16.py -v — 1 static OK (2 exec 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
    • python3 -I tests/test_ci_registration.py — 16/16 OK
  • Live Apple M5 mutation proof (tests/test_x64_recomp_push_pop_16.py on unpatched upstream/main + #1174): 2 failures, 1 error.
  • Native Apple M5 execution (22-way scratch merge on upstream/main 3a0af1f15 with #1174 + all 20 other open x64_recomp PR branches):
    • 0 merge conflicts across all 22 branches
    • tests/test_x64_recomp_push_pop_16.py: 3/3 OK (0 skipped) on native Apple M5 arm64
    • All 21 tests/test_x64_recomp_*.py suites combined: 148/148 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/1408 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/x64-recomp-push-pop-16` --- ### 📝 Commits (1) - [`c6d1639`](https://github.com/ubiquitarianism/leonida/commit/c6d1639d4531405604bfe3ff4c820176ba982314) x64_recomp: handle 16-bit operand-size override (66) in push and pop ### 📊 Changes **2 files changed** (+189 additions, -4 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_x64_recomp_push_pop_16.py` (+173 -0) 📝 `tools/x64_recomp.py` (+16 -4) </details> ### 📄 Description Item ID: `X64-RECOMP-PUSH-POP-16` ## Summary Fixes 16-bit operand-size override (`66` prefix without `REX.W`) in `_emit_pushpop` in `tools/x64_recomp.py`: - **`push` (`66 50..57`, `66 41 50..57`, `66 68 iw`, `66 6A ib`, `66 FF /6`)**: loads 2 bytes (or sign-extended `imm8` masked to 16 bits) and emits `str_pre(T0, rsp, -2, size=2)` (`STRH W0, [X23, #-2]!`) instead of always decrementing `RSP` by 8 and writing 8 bytes. - **`pop` (`66 58..5F`, `66 41 58..5F`, `66 8F /0`)**: emits `ldr_post(T0, rsp, 2, size=2)` (`LDRH W0, [X23], #2`), inserts only the low 16 bits via `bfi(..., 0, 16)` for register destinations (preserving upper 48 bits), and stores exactly 2 bytes via `str(..., size=2)` for memory destinations (after the post-increment of `RSP`, matching Intel SDM for `pop word ptr [rsp+disp]`). - **`66` + `REX.W` precedence (`66 48 50`, `66 48 58`)**: `REX.W` overrides `66`, preserving full 64-bit `push`/`pop` (`±8`). ## Tests & Verification - **AI-assisted**: yes - **Host / hardware**: macOS (Apple M5, arm64) - Standalone checks on `upstream/main` (`3a0af1f15`): - `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_push_pop_16.py` — OK - `python3 -I tests/test_x64_recomp_push_pop_16.py -v` — 1 static OK (2 exec 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 - `python3 -I tests/test_ci_registration.py` — 16/16 OK - **Live Apple M5 mutation proof** (`tests/test_x64_recomp_push_pop_16.py` on unpatched `upstream/main` + `#1174`): **2 failures, 1 error**. - **Native Apple M5 execution (22-way scratch merge on `upstream/main` `3a0af1f15` with `#1174` + all 20 other open `x64_recomp` PR branches)**: - 0 merge conflicts across all 22 branches - `tests/test_x64_recomp_push_pop_16.py`: **3/3 OK (0 skipped)** on native Apple M5 arm64 - All 21 `tests/test_x64_recomp_*.py` suites combined: **148/148 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#1438
No description provided.