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

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

@⁠kett1m on GitHub · 2026-11-25 01:27 UTC · original
kett1m:x64-recomp-simd-table → main · +39 −3 · 3 files · 1 commits · open

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).

**@⁠kett1m** on GitHub · 2026-11-25 01:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1485) `kett1m:x64-recomp-simd-table` → `main` · +39 −3 · 3 files · 1 commits · open 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).
The `0F` SIMD opcode list is built from opcode ranges, and the ranges left out
`7C`/`7D` (haddp*/hsubp* and their F2 forms), `D0` (addsubp*), `D7` (pmovmskb),
`E6` (cvtdq2pd/cvttpd2dq/cvtpd2dq), `E7` (movntdq), `F0` (lddqu) and `F7`
(maskmovdqu). Each of them takes a ModRM byte, but with no table entry it 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.

Two measurements on `game_scarlett_master.exe` (SHA-256
`e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`). Walking
every `.pdata` function (299,257) with the unfixed decoder, 6 stop on one of these
opcodes; with the fix they decode 852 instructions further and 3 reach the end of
the function with no unknown left. A per-instruction differential against objdump
over `.text` (objdump's walk and the decoder's walk, lengths compared, 26,674,180
instructions) goes from 52,638 to 52,632 mismatches: the 6 removed are 4 `F3 0F E6`
and 2 `66 REX.W 0F D7`, and no signature is added. `docs/mobile.md` records both
counts and the REA `gnu.objdump` section-header evidence.

Test: tests/test_x64_recomp.py::DecodeTests::test_simd_opcodes_outside_the_ranges_carry_modrm
fails before the fix (the first case is `unknown`) and passes after, covering the
eight opcodes in both the register and memory forms.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:53:40 +00:00
Author
Owner

@⁠ytsodacan on GitHub · 2026-11-25 03:36 UTC · original · edited 2026-11-25 03:43 UTC

[KEEP]

  • The table fix looks correct and scoped: _OF_SIMD_NORM in tools/x64_recomp.py gains 7C/7D, D0, D7, E6, E7, F0 and F7, with a 12-case decode test and a measured differential recorded in docs/mobile.md.
  • CI has not finished: change-scope and no-game-data are still QUEUED, so there is no green result yet.
  • Likely textual conflicts with #1488 and #1483 (same test insertion point in tests/test_x64_recomp.py, same docs/mobile.md). #1428 also edits tools/x64_recomp.py. A maintainer should pick a merge order, then rebase the rest.
  • Suggest merging once CI is green and the stack is ordered.
**@⁠ytsodacan** on GitHub · 2026-11-25 03:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1485#issuecomment-7152066329) · edited 2026-11-25 03:43 UTC **[KEEP]** - The table fix looks correct and scoped: `_OF_SIMD_NORM` in `tools/x64_recomp.py` gains 7C/7D, D0, D7, E6, E7, F0 and F7, with a 12-case decode test and a measured differential recorded in `docs/mobile.md`. - CI has not finished: `change-scope` and `no-game-data` are still QUEUED, so there is no green result yet. - Likely textual conflicts with #1488 and #1483 (same test insertion point in `tests/test_x64_recomp.py`, same `docs/mobile.md`). #1428 also edits `tools/x64_recomp.py`. A maintainer should pick a merge order, then rebase the rest. - Suggest merging once CI is green and the stack is ordered.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 03:53 UTC · original · approved these changes

Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). The eight added opcodes are all ModRM forms in the 0F map: 7C/7D haddp*/hsubp*, D0 addsubp*, D7 pmovmskb, E6 cvt*dq2pd/pd2dq, E7 movntdq/movntq, F0 lddqu, F7 maskmovdqu/maskmovq.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 03:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1485#pullrequestreview-6051621342) · **approved these changes** Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). The eight added opcodes are all ModRM forms in the 0F map: 7C/7D haddp*/hsubp*, D0 addsubp*, D7 pmovmskb, E6 cvt*dq2pd/pd2dq, E7 movntdq/movntq, F0 lddqu, F7 maskmovdqu/maskmovq. AI-assisted (Claude).
Author
Owner

@⁠kevincommits on GitHub · 2026-11-25 22:04 UTC · original

Independent run. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, QEMU 11.1.3 from Homebrew, so the 26 exec tests ran rather than skipped. I merged main at d3b8251bc into the branch locally (635 commits behind, no conflicts).

  • main alone decodes f3 0f e6 c9 as unknown op0f_e6, size 3, and 66 48 0f d7 d0 as unknown op0f_d7, size 4. This branch gives simd at sizes 4 and 5.
  • tests/test_x64_recomp.py: 34/34 (33 on main), so the new test fails on main and passes here. tests/test_recomp_census.py: 11/11.
  • Every standalone tests/test_*.py under python -I: 510 run, 506 pass; the 4 that fail are the same 4 that fail on plain main.

I only ran the synthetic byte fixtures. I did not reproduce the retail-image counts in the docs/mobile.md paragraph. No game files used. AI-assisted.

**@⁠kevincommits** on GitHub · 2026-11-25 22:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1485#issuecomment-7175902521) Independent run. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, QEMU 11.1.3 from Homebrew, so the 26 exec tests ran rather than skipped. I merged `main` at `d3b8251bc` into the branch locally (635 commits behind, no conflicts). - `main` alone decodes `f3 0f e6 c9` as unknown `op0f_e6`, size 3, and `66 48 0f d7 d0` as unknown `op0f_d7`, size 4. This branch gives `simd` at sizes 4 and 5. - `tests/test_x64_recomp.py`: 34/34 (33 on `main`), so the new test fails on `main` and passes here. `tests/test_recomp_census.py`: 11/11. - Every standalone `tests/test_*.py` under `python -I`: 510 run, 506 pass; the 4 that fail are the same 4 that fail on plain `main`. I only ran the synthetic byte fixtures. I did not reproduce the retail-image counts in the `docs/mobile.md` paragraph. 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/1485/head:github-bot/gh-1485'
git switch 'github-bot/gh-1485'

Merge

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