x64_recomp: handle 0x67 address-size override in memory and moffs operands (X64-RECOMP-ADDRSIZE-67) #1392
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1392"
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?
Imported from ubiquitarianism/leonida. Originally posted by quietfold on 2026-11-24T23:11:29Z.
Item ID:
X64-RECOMP-ADDRSIZE-67Summary
Fixes handling of the
0x67address-size override prefix (32-bit effective addressing in 64-bit mode) intools/x64_recomp.py:moffs(A0..A3, tokenQ) in_finish: reads a 4-byte unsignedmoffs32whenins.addrsizeis set instead of always reading 8 bytes (which previously consumed subsequent instruction bytes or raisedDecodeError("truncated imm"))._finishand_finish_group: tags memory operands withaddrsize = 4whenins.addrsizeis set, and truncates RIP-relative effective addresses to 32 bits ((ins.addr + ins.size + disp) & 0xFFFFFFFF) per Intel SDM Vol. 2A §2.2.1.6._mem_addr: emitssf=0(W-register) ARM64 arithmetic/moves/shifts (MOV,ADD,SUB,ADD (shifted reg),LSL) and masks immediate/absolute/disp32-only addresses to 32 bits whenm.get("addrsize") == 4, wrapping modulo2^32and zero-extending to 64 bits (includingdisp == 0withbase == rd,[disp32]zero-extension vs 64-bit sign-extension, and large displacements>= 4096/<= -4096).Tests & Verification
upstream/main28a32e190):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_addrsize67.py— OKpython3 -I tests/test_x64_recomp_addrsize67.py -v— 3 static decode/codegen tests OK (3 exec tests skip 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 OKtests/test_x64_recomp_addrsize67.pyon unpatchedupstream/main+#1174): 19 failures (FAILED (failures=19)).#1174+ all 18 other openx64_recompPR branches):tests/test_x64_recomp_addrsize67.py: 6/6 OK (0 skipped) on native Apple M5 arm64tests/test_x64_recomp_*.pysuites combined: 138/138 OK (0 skipped)Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T23:11:47Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from ubiquitarianism/leonida. Originally posted by kevincommits on 2026-11-26T04:29:37Z.
Independent run with QEMU. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, QEMU 11.1.3 from Homebrew. I merged
mainata73a57e13into the branch locally (913 commits behind, no conflicts). Head tested:442ef0a66.Against a reference model this branch is right in all 432 checks.
maingets 167 wrong, every one a67-prefixed form; the un-prefixed half is identical on both, so the_mem_addrrewrite changes nothing for ordinary 64-bit addressing.Test file. As shipped under QEMU,
python -I tests/test_x64_recomp_addrsize67.pyis 6 run, 16 errors, from the wiring bug in #1409 (xr.run_kernelwherexr.run_resultis needed; here the raw bytes reachhi & 0xFFFFFFFF). WithRUNNERswapped forxr.run_resultin memory (no file changed): 6/6.Beyond the file, generated cases under QEMU against a small Python model. Each address form is run twice, as
lea rax, [...]with and without the67prefix, and the full 64-bitraxis compared (the effective address, or its low 32 bits zero-extended):[rcx + disp]with no displacement,disp8anddisp32encodings, 14 displacements from-0x80000000to0x7fffffff, four base values including ones that wrap at 32 bits and ones with junk above bit 31;[rax]and[rax+1]where the destination is also the base;[rcx + rdx*s],[rcx + rdx*s + disp8],[rcx + rdx*s + disp32]for all four scales;[rdx*s + disp32]for all four scales, and[disp32]alone;67-prefixed memory reads (mov eax, [ecx],mov eax, [ecx+4]) with junk in the upper half ofrcx.main67forms: the prefix is ignored, so the address is computed at 64 bits (67 lea rax,[rcx+1]withrcx=0xffffffffgives0x100000000, want 0); the two memory reads time outCounts.
tests/test_x64_recomp.py44/44 andtests/test_recomp_census.py11/11, the same asmain. Full standalone suite: 514 run, 512 pass; the 2 that fail aremain'stest_mod_pack_output_aliasand the new file, for the wiring reason.Not tested:
moffsforms (67 a0–a3) and EIP-relative addressing beyond the file's own cases,67on stores and on string instructions, and segment-prefixed operands. No game files used. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:35:29Z.
Red/green: classified READY by dada-lotF (red on main, green on head merged with main); head
442ef0a663unchanged since 2026-11-24, before that run.Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main
d48a957bbin GitHub Actions: no new failure.AI-assisted (Claude Code, Claude Opus 5.5)