[PR #1409] x64_recomp: give REX.W precedence over 0x66 operand-size override (X64-RECOMP-REXW-OVER-66) #1439

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/1409
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/x64-recomp-rexw-over-66


📝 Commits (1)

  • d35c866 x64_recomp: give REX.W precedence over 0x66 operand-size override

📊 Changes

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

View changed files

➕ tests/test_x64_recomp_rexw_66.py (+134 -0)
📝 tools/x64_recomp.py (+4 -4)

📄 Description

Item ID: X64-RECOMP-REXW-OVER-66

Summary

Fixes REX.W vs 0x66 operand-size override precedence in tools/x64_recomp.py:

  • _vsize(opsize, rexw): checks if rexw: return 8 before if opsize: return 2 per Intel SDM Vol. 2A §2.2.1.2. Previously 66 48 ... decoded as 16-bit instead of 64-bit, causing 66 48 B8 <imm64> (movabs) to read only 2 immediate bytes and desynchronize subsequent instructions.
  • decode_one state["opsize"]: sets state["opsize"] = 0 if rexw else opsize while leaving ins.opsize = opsize intact for mandatory-66 prefix decoders (e.g. SSE2). This ensures Iz immediates (66 48 81, 66 48 68, 66 48 69, etc.) read 4 bytes instead of 2 and string ops (66 48 A5) use 8-byte element width.

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_rexw_66.py — OK
    • python3 -I tests/test_x64_recomp_rexw_66.py -v — 2 static OK (1 exec skips 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_rexw_66.py on unpatched upstream/main + #1174): 2 failures, 1 error.
  • Native Apple M5 execution (23-way scratch merge on upstream/main 3a0af1f15 with #1174 + all 21 other open x64_recomp PR branches):
    • 0 merge conflicts across all 23 branches
    • tests/test_x64_recomp_rexw_66.py: 3/3 OK (0 skipped) on native Apple M5 arm64
    • All 22 tests/test_x64_recomp_*.py suites combined: 151/151 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/1409 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/x64-recomp-rexw-over-66` --- ### 📝 Commits (1) - [`d35c866`](https://github.com/ubiquitarianism/leonida/commit/d35c8665dffdee59a366cdfb70e6aa8aa2023fa2) x64_recomp: give REX.W precedence over 0x66 operand-size override ### 📊 Changes **2 files changed** (+138 additions, -4 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_x64_recomp_rexw_66.py` (+134 -0) 📝 `tools/x64_recomp.py` (+4 -4) </details> ### 📄 Description Item ID: `X64-RECOMP-REXW-OVER-66` ## Summary Fixes `REX.W` vs `0x66` operand-size override precedence in `tools/x64_recomp.py`: - **`_vsize(opsize, rexw)`**: checks `if rexw: return 8` before `if opsize: return 2` per Intel SDM Vol. 2A §2.2.1.2. Previously `66 48 ...` decoded as 16-bit instead of 64-bit, causing `66 48 B8 <imm64>` (`movabs`) to read only 2 immediate bytes and desynchronize subsequent instructions. - **`decode_one` `state["opsize"]`**: sets `state["opsize"] = 0 if rexw else opsize` while leaving `ins.opsize = opsize` intact for mandatory-`66` prefix decoders (e.g. SSE2). This ensures `Iz` immediates (`66 48 81`, `66 48 68`, `66 48 69`, etc.) read 4 bytes instead of 2 and string ops (`66 48 A5`) use 8-byte element width. ## 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_rexw_66.py` — OK - `python3 -I tests/test_x64_recomp_rexw_66.py -v` — 2 static OK (1 exec skips 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_rexw_66.py` on unpatched `upstream/main` + `#1174`): **2 failures, 1 error**. - **Native Apple M5 execution (23-way scratch merge on `upstream/main` `3a0af1f15` with `#1174` + all 21 other open `x64_recomp` PR branches)**: - 0 merge conflicts across all 23 branches - `tests/test_x64_recomp_rexw_66.py`: **3/3 OK (0 skipped)** on native Apple M5 arm64 - All 22 `tests/test_x64_recomp_*.py` suites combined: **151/151 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#1439
No description provided.