[PR #1485] x64_recomp: the 0F SIMD ranges skip eight ModRM opcodes (X64-RECOMP-SIMD-TABLE) #1517

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

📋 Pull Request Information

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

Base: main ← Head: x64-recomp-simd-table


📝 Commits (1)

  • d6e8cbd x64_recomp: the 0F SIMD ranges skip eight ModRM opcodes (X64-RECOMP-SIMD-TABLE)

📊 Changes

3 files changed (+39 additions, -3 deletions)

View changed files

📝 docs/mobile.md (+12 -0)
📝 tests/test_x64_recomp.py (+21 -0)
📝 tools/x64_recomp.py (+6 -3)

📄 Description

The 0F SIMD opcode list in tools/x64_recomp.py is generated from opcode ranges, and the
ranges left out eight opcodes that take a ModRM byte:

  • 7C / 7D, HADDPD/HADDPS and HSUBPD/HSUBPS (66 and F2 forms)
  • D0, ADDSUBPD/ADDSUBPS
  • D7, PMOVMSKB (66 form; the MMX form has no prefix)
  • E6, CVTDQ2PD, CVTTPD2DQ, CVTPD2DQ
  • E7, MOVNTDQ
  • F0, LDDQU
  • F7, MASKMOVDQU

With no table entry each decoded as the unknown op0f_XX of its two opcode bytes, so the byte
after them was read as the next instruction and the rest of the function was decoded from the
wrong offset.

Measurement

The image is game_scarlett_master.exe, SHA-256
e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993. REA measured the section
ranges with gnu.objdump section_headers, evidence
ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90: .text VMA
0x140001000, file 0x400, size 0x5f3f966; .pdata VMA 0x14abcf000, file 0x6e03a00.

  1. Walking every .pdata function (299,257) with the unfixed decoder, 6 functions stop on one of
    these opcodes. The first unknown in each is op0f_7d (RVA 0x17e1060), op0f_e6
    (0x277a710, 0x3137ab0, 0x562bc40), op0f_e7 (0x3081860) and op0f_f7 (0x3e2aad0).
    With the fix they decode 852 instructions further and 3 reach the end of the function with no
    unknown left.
  2. A per-instruction differential against GNU objdump over .text: objdump's linear walk and the
    decoder's walk read the same bytes and the instruction lengths are compared (26,674,180
    objdump instructions). It drops 6 length mismatches, 4 F3 0F E6 (CVTDQ2PD, RVAs 0x562ad45,
    0x562ad6e, 0x562e320, 0x562e395) and 2 66 REX.W 0F D7 (PMOVMSKB, RVAs 0x564df78,
    0x565191f), and adds none. The totals are 52,638 before and 52,632 after.

Enumerating the 0F opcodes against the set of legacy SSE/MMX instructions that take a ModRM
byte leaves none out after the change; movnti (0F C3) is already its own entry.

Test

tests/test_x64_recomp.py::DecodeTests::test_simd_opcodes_outside_the_ranges_carry_modrm covers
the eight opcodes in the register and memory forms. Against the unfixed decoder the first case
(f3 0f e6 c9) decodes as unknown; with the fix each keeps its ModRM/SIB/displacement length.

python -I tests/test_x64_recomp.py: 33 tests OK, 26 skipped (this host has no
qemu-system-aarch64). python -I tests/test_recomp_census.py: 11 tests OK.
python3 -m compileall -q make_game.py tools tests exits 0. python -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py docs/mobile.md exits
0 with no output.

docs/mobile.md records both counts and the evidence ID. The differential is local analysis of
the shipped file; nothing was executed. No game files, no GPU, nothing online. Tested on Linux
(openSUSE Tumbleweed, Python 3.13.18, binutils 2.47), 12 cores.

AI-assisted (DeepSeek V4.1 Flash).


🔄 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/1485 **Author:** [@kett1m](https://github.com/kett1m) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `x64-recomp-simd-table` --- ### 📝 Commits (1) - [`d6e8cbd`](https://github.com/ubiquitarianism/leonida/commit/d6e8cbda66b55b9c998a8b278eb43a15258fdbfa) x64_recomp: the 0F SIMD ranges skip eight ModRM opcodes (X64-RECOMP-SIMD-TABLE) ### 📊 Changes **3 files changed** (+39 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/mobile.md` (+12 -0) 📝 `tests/test_x64_recomp.py` (+21 -0) 📝 `tools/x64_recomp.py` (+6 -3) </details> ### 📄 Description The `0F` SIMD opcode list in `tools/x64_recomp.py` is generated from opcode ranges, and the ranges left out eight opcodes that take a ModRM byte: - `7C` / `7D`, HADDPD/HADDPS and HSUBPD/HSUBPS (`66` and `F2` forms) - `D0`, ADDSUBPD/ADDSUBPS - `D7`, PMOVMSKB (`66` form; the MMX form has no prefix) - `E6`, CVTDQ2PD, CVTTPD2DQ, CVTPD2DQ - `E7`, MOVNTDQ - `F0`, LDDQU - `F7`, MASKMOVDQU With no table entry each decoded as the unknown `op0f_XX` of its two opcode bytes, so the byte after them was read as the next instruction and the rest of the function was decoded from the wrong offset. ## Measurement The image is `game_scarlett_master.exe`, SHA-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`. REA measured the section ranges with `gnu.objdump` `section_headers`, evidence `ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90`: `.text` VMA `0x140001000`, file `0x400`, size `0x5f3f966`; `.pdata` VMA `0x14abcf000`, file `0x6e03a00`. 1. Walking every `.pdata` function (299,257) with the unfixed decoder, 6 functions stop on one of these opcodes. The first unknown in each is `op0f_7d` (RVA `0x17e1060`), `op0f_e6` (`0x277a710`, `0x3137ab0`, `0x562bc40`), `op0f_e7` (`0x3081860`) and `op0f_f7` (`0x3e2aad0`). With the fix they decode 852 instructions further and 3 reach the end of the function with no unknown left. 2. A per-instruction differential against GNU objdump over `.text`: objdump's linear walk and the decoder's walk read the same bytes and the instruction lengths are compared (26,674,180 objdump instructions). It drops 6 length mismatches, 4 `F3 0F E6` (CVTDQ2PD, RVAs `0x562ad45`, `0x562ad6e`, `0x562e320`, `0x562e395`) and 2 `66 REX.W 0F D7` (PMOVMSKB, RVAs `0x564df78`, `0x565191f`), and adds none. The totals are 52,638 before and 52,632 after. Enumerating the `0F` opcodes against the set of legacy SSE/MMX instructions that take a ModRM byte leaves none out after the change; `movnti` (`0F C3`) is already its own entry. ## Test `tests/test_x64_recomp.py::DecodeTests::test_simd_opcodes_outside_the_ranges_carry_modrm` covers the eight opcodes in the register and memory forms. Against the unfixed decoder the first case (`f3 0f e6 c9`) decodes as `unknown`; with the fix each keeps its ModRM/SIB/displacement length. `python -I tests/test_x64_recomp.py`: 33 tests OK, 26 skipped (this host has no qemu-system-aarch64). `python -I tests/test_recomp_census.py`: 11 tests OK. `python3 -m compileall -q make_game.py tools tests` exits 0. `python -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py docs/mobile.md` exits 0 with no output. `docs/mobile.md` records both counts and the evidence ID. The differential is local analysis of the shipped file; nothing was executed. No game files, no GPU, nothing online. Tested on Linux (openSUSE Tumbleweed, Python 3.13.18, binutils 2.47), 12 cores. AI-assisted (DeepSeek V4.1 Flash). --- <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#1517
No description provided.