x64_recomp: give REX.W precedence over 0x66 operand-size override (X64-RECOMP-REXW-OVER-66) #1409
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1409
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/x64-recomp-rexw-over-66"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Item ID:
X64-RECOMP-REXW-OVER-66Summary
Fixes
REX.Wvs0x66operand-size override precedence intools/x64_recomp.py:_vsize(opsize, rexw): checksif rexw: return 8beforeif opsize: return 2per Intel SDM Vol. 2A §2.2.1.2. Previously66 48 ...decoded as 16-bit instead of 64-bit, causing66 48 B8 <imm64>(movabs) to read only 2 immediate bytes and desynchronize subsequent instructions.decode_onestate["opsize"]: setsstate["opsize"] = 0 if rexw else opsizewhile leavingins.opsize = opsizeintact for mandatory-66prefix decoders (e.g. SSE2). This ensuresIzimmediates (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
upstream/main(3a0af1f15):python3 -m compileall -q make_game.py tools tests— OKpython3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_rexw_66.py— OKpython3 -I tests/test_x64_recomp_rexw_66.py -v— 2 static OK (1 exec skips cleanly without#1174runner)python3 -I tests/test_x64_recomp.py— 6 static OK (26 exec skipped)python3 -I tests/test_text_write_line_endings.py— 3/3 OKpython3 -I tests/test_ci_registration.py— 16/16 OKtests/test_x64_recomp_rexw_66.pyon unpatchedupstream/main+#1174): 2 failures, 1 error.upstream/main3a0af1f15with#1174+ all 21 other openx64_recompPR branches):tests/test_x64_recomp_rexw_66.py: 3/3 OK (0 skipped) on native Apple M5 arm64tests/test_x64_recomp_*.pysuites combined: 151/151 OK (0 skipped)Independent run with QEMU. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, QEMU 11.1.3 from Homebrew. I merged
mainat392dda8f0into the branch locally (674 commits behind, no conflicts). Head tested:d35c8665d.The decoder change does what it says, but two things need fixing.
1. The new exec test errors wherever QEMU is installed.
python -I tests/test_x64_recomp_rexw_66.py: 3 run, 1 error._find_runner's QEMU branch returnsxr.run_kernel, which gives back(raw output bytes, translator), not the parsed value.xr.run_resultis the one that parsesR=xxxxxxxx. On this branchCAN_RUN_MACHOdoes not exist (it comes with #1174), so the QEMU branch is the only one that can be taken: the test is skipped without QEMU and errors with it. Suggested fix: usexr.run_resultin both branches.With that one substitution made locally, all four cases in the test give the asserted values under QEMU (
1122334412345679,0000000400000001,0807060504030201,ffffffffffedcbaa), so the assertions themselves are right.2.
66 48 98and66 48 99still take the 16-bit path._emit_convtestsins.opsizebeforeins.rexw, andins.opsizedeliberately stays 1.48 98(cdqe), eax=80000000ffffffff80000000ffffffff8000000066 48 98000000008000000048 99(cqo), rax=8000000000000000ffffffffffffffffffffffffffffffff66 48 990000000000000000Suggested fix: test
ins.rexwfirst in both arms of_emit_conv.What does work. These gave the wrong value on
mainand the right one here, each run under QEMU:66 48 ff c0(inc carries past bit 32),66 48 f7 d8(neg),66 48 c1 e0 24(shl by 36),66 48 0f af c1(imul),66 48 05 imm32,66 48 29 c8(sub with borrow),66 48 8d 04 08(lea),66 48 63 c1(movsxd). Lengths now match for66 48 c7 /0,66 48 a9,66 48 69,66 48 05(8, 7, 8, 7 bytes;mainread a 2-byte immediate).66 48 0f 6e,0f 7e,0f 3a 16,0f 3a 22decode the same as onmain, so the mandatory-prefix forms were not disturbed.Counts.
tests/test_x64_recomp.py33/33 andtests/test_recomp_census.py11/11, the same asmain. Full standalone suite: 511 run, 506 pass; the 5 that fail aremain's 4 plus this new file.Not this pull request, seen on
maintoo:48 c7 c0 01 00 00 80givesfffffffe80000001and48 91does not exchange. #1339 and #1428 look like the owners of those.No game files used. AI-assisted.
Red/green: classified READY by dada-lotF (red on main, green on head merged with main); head d35c8665dffd unchanged since 2026-11-24, before that run.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)