x64_recomp: in/out immediate ports need their imm8 byte (X64-RECOMP-IN-IMM8) #1488
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!1488
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/1488"
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
Claimed in the coordination issue as: X64-RECOMP-IN-IMM8
Depends on: #1485 (conflicts with in
tests/test_x64_recomp.py; whichever lands second needs a rebase)The primary table in
tools/x64_recomp.pygivesE4,E5,E6andE7the operand shapesys, so the decoder consumed only the opcode and the instruction came out one byte long. Theseare the immediate-port forms of
inandout:E4 ib=in al, imm8E5 ib=in eax, imm8E6 ib=out imm8, alE7 ib=out imm8, eaxEach takes one immediate byte, so the instruction is two bytes; the walk read the port number as
the next opcode and the rest of the function came out at the wrong offset. The
EC-EFDX-portforms take no immediate and are unchanged.
Measurement
The image is
game_scarlett_master.exe, SHA-256e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993. REA measured the sectionranges with
gnu.objdumpsection_headers, evidenceev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90:.textVMA0x140001000, file0x400, size0x5f3f966.A per-instruction differential against GNU objdump over
.text: objdump's linear walk and thedecoder's walk read the same bytes and the instruction lengths are compared (26,674,180 objdump
instructions). On
main(b4b7756) it reports 52,638 mismatching instructions; the form is usedtwice, at RVA
0x55f2ed4(in $0x3d,%al) and RVA0x564652c(in $0x73,%al), each one byteshort of objdump's two. With this change the count is 52,636, both of those are gone, and no new
mismatch signature appears. Both sites sit inside
.pdatafunctions (RVAs0x55f2ed0and0x5646250).outwith an immediate port does not occur anywhere in.text, so it is covered bythe unit test rather than by a retail count.
Test
tests/test_x64_recomp.py::DecodeTests::test_in_out_immediate_port_consumes_imm8:E4 3d,E5 73,E6 40andE7 40are two bytes with the operand shapein al, imm8and its three siblings, andEC/ED/EE/EFstay one byte. Against the unfixed decoder the first case decodes to size 1.python -I tests/test_x64_recomp.py: 33 tests OK, 26 skipped (this host has noqemu-system-aarch64).
python -I tests/test_recomp_census.py: 11 tests OK.python3 -m compileall -q make_game.py tools testsexits 0.python -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py docs/mobile.mdexits0 with no output.
The per-function
.pdatawalk is noisy for this change, because the other length defects still onmainleave most functions misaligned, so it is not quoted as an impact figure.docs/mobile.mdrecords the measurement, the two offsets and the evidence ID. No game files, noGPU, nothing online. Tested on Linux (openSUSE Tumbleweed, Python 3.13.18, binutils 2.47), 12
cores.
GPUs tested: n/a (decoder and census are CPU-only)
AI-assisted: yes (DeepSeek V4.1 Flash)
Checklist
mainand merges cleanly.docs/design.mdcontract row.[KEEP]
tools/x64_recomp.pyE4-E7 go fromsystoAb Ib/Av Ib/Ib Ab/Ib Av, with a decode test covering all four plus the unchanged EC-EF forms.change-scopeandno-game-dataare still QUEUED, so there is no green result yet.tests/test_x64_recomp.pyneartest_prefixes) and docs indocs/mobile.md. A maintainer should pick a merge order, then rebase the rest.Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). E4/E5 are
in AL/eAX, imm8and E6/E7out imm8, AL/eAX, so each carries an imm8 port byte; treating them as baresysended the instruction one byte early.AI-assisted (Claude).
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
mainat6b843a4adinto the branch locally (633 commits behind, no conflicts).mainalone decodese4 3das('in', size 1); this branch gives('in', size 2).tests/test_x64_recomp.py: 34/34 (33 onmain), so the new test fails onmainand passes here.tests/test_recomp_census.py: 11/11.tests/test_*.pyunderpython -I: 510 run, 506 pass; the 4 that fail are the same 4 that fail on plainmain.I only ran the synthetic byte fixtures. I did not reproduce the retail-image counts in the
docs/mobile.mdparagraph. No game files used. AI-assisted.Hi @kett1m, thanks for this pull request. It currently conflicts with
main(conflicting file(s):tests/test_x64_recomp.py), so it carries theneeds rebaselabel. CONTRIBUTING.md asks authors to rebase their branch onmain; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.AI-assisted (Claude Code, Claude Opus 5.5).
#1488 | head 6cace7d7c3dbf074546e79078f3f597a9a3132ce (merged cleanly with main adfb3821a2) |
python -I tests/test_x64_recomp.py -v+python -I tests/test_recomp_census.py+python -I tests/test_docs_links.py+python -I tests/test_docs_repo_paths.py| red on main:FAILED (failures=1, skipped=32)(AssertionError: Tuples differ: ('in', 1) != ('in', 2)— opcodes0xE4..0xE7decoded as 1-bytesysinstead of consuming theirimm8port byte) | green on PR+main:46 ran, OK (skipped=32)(test_x64_recomp.py),11 ran, OK(test_recomp_census.py),17 ran, OK(test_docs_links.py), and5 ran, OK(test_docs_repo_paths.py) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yesAudited
6cace7d7c3(tools/x64_recomp.py,tests/test_x64_recomp.py, anddocs/mobile.md) on Windows 11, confirming0xE4..0xE7decode as 2-byteAb Ib/Av Ib/Ib Ab/Ib Avimmediate-port forms while0xEC..0xEFremain 1-byte DX-port forms. Also verifiedtests/test_docs_cli_flags.py,tests/test_docs_encoding.py,tests/test_ci_registration.py, andscripts/check_no_game_data.py.Tested
6cace7d7cmerged (no commit) withmain829530dbd: Python 3.12.4, Windows 11 10.0.26300, CPU only.check_no_game_data.pyis clean.tests/test_x64_recomp.py, 46 tests pass (32 skipped:qemu-system-aarch64 not installed).tools/x64_recomp.pyback tomain, 1 failure (('in', 1) != ('in', 2)).tests/test_x64_recomp.py(git merge-tree), so the second to land needs a rebase.No blocker from my side.
AI-assisted (Claude Code).
Tested green here earlier on this same head (see my comment above). Two things before a merge: your claim in the coordination issue #2570 is missing, and this PR conflicts with #1485 in
tests/test_x64_recomp.py, so whichever lands second needs a rebase.AI-assisted (Claude Code).
Ready for testing: merges cleanly with
main3535eb5c4. Not inmainyet:git cherryfinds 1 commit(s) not there, and 1 of the 26 lines it adds are already present. No duplicate found: its claimX64-RECOMP-IN-IMM8appears in no other open pull request and in nomaincommit.AI-assisted (Claude Code).
RUN of #1488 (red/green,
python -I, no build, no game, no GPU)Heads tested: PR head
6cace7d7c3db, origin/mainbd643e46e784; merged = main + PR head,git merge --no-ff, local only (merged cleanly, merge commit1abe3635b408).Commands, one process each, from the worktree root:
python -I tests/test_x64_recomp.py -vRelated (every test file that imports
tools/x64_recomp.py,tools/bcpack_tool.pyortools/recomp_census.py, 17 files):tests/test_x64_recomp.py,test_x64_recomp_*.py(14 files),test_recomp_census.py,test_bcpack_tool.py.tools/x64_recomp.pywith the PR's tests; no new API, so this is a behavioural red, not a build failure):FAILED (failures=1),test_in_out_immediate_port_consumes_imm8:AssertionError: Tuples differ: ('in', 1) != ('in', 2). On mainE4 3Ddecodes as a one-bytein; with the PR it is two bytes with the immediate operand.test_x64_recomp.pyRan 46, OK (skipped=32); the new test runs (not skipped). All 17 related files exit 0.test_x64_recomp.pyRan 48 (main added two), OK (skipped=34); all 17 related files exit 0. Nothing fails merged that passes on main.qemu-system-aarch64 not installedon this machine); the changed decode test is a pure decode test and ran. The retail-image differential quoted in the docs paragraph cannot be re-checked here (no game data in this test); the red/green covers the decoder change only.Machine: NVIDIA GeForce RTX 3090 (not used), Windows 11 Pro 10.0.26300, CPython 3.13.12.
Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, qemu-system-aarch64 11.1.3 on PATH, main 4755667f5, PR head 6cace7d7c : red 1 failure / green 48 OK
python3.12 -I tests/test_x64_recomp.py:test_in_out_immediate_port_consumes_imm8. Green: 48/48 OK.git merge-tree). main changedtests/test_x64_recomp.py(+36) andtools/x64_recomp.pysince the PR base 30fc2d68c, so red = the merged test file against main's code.tests/test_x64_recomp_*.pygive identical results per file on main and on the merge (14 of them already fail on main under qemu because ofrun_kernelvsrun_result, see the finding in #2570).tests/test_x64_recomp.py/tools/x64_recomp.py; whichever lands second needs a rebase. It does not force a rebase of #2566.else, so translation is unchanged.objdumpdiff on the retail image's.text(RVA, instruction counts). Worth a check against the "no game data" rule; I did not use any game file.Verdict: READY (code); see the docs note above.
AI-assisted: Claude Code
"No game data" review by OreoFR (requested for maintainers), PR head b144b06a2, merged locally on main 720bd3b4e. Note: the head moved since my earlier verification (6cace7d7c), so that verdict is stale.
scripts/check_no_game_data.pyon the merge: rc 0; theno-game-data.ymlextension filter: 0 files. The code (tools/x64_recomp.py, E4–E7) and the test fixtures (tests/test_x64_recomp.py:175,:178, hand-written standard x86 encodings) are synthetic.docs/mobile.md(PR-side line numbers) cites the retail image:.text, which are fine);Review: please remove the RVAs and the two disassembled instructions (docs/mobile.md:40, 44–45), keeping only "two sites" and the counts; the REA proof identifier is for a maintainer to decide. I am not quoting the values here on purpose.
AI-assisted: Claude Code
Maintainer decision: the
tools/x64_recomp.pychange and its test look fine, but this cannot merge as it is.docs/mobile.md(lines 40 and 44-45 on the current head) quotes addresses from the retail executable and two instructions disassembled from it. That is game data under the repository's first hard rule (AGENTS.md: no game data in commits, including quotes of it). Please remove those lines; describing the encoding rule itself (theimm8byte ofin/out) without values from the retail image is fine.AI-assisted (Claude Code), posted for MoonEyes.
Fixed the doc quotes MoonEyes flagged (861ca5f2). The paragraph now describes the imm8-byte rule itself: the encoding rule, the two-line
objdumpcomparison and the counts stay, but the retail addresses (0x55f2ed4/0x564652c) and the two disassembled instructions are gone. Docs tests pass;check_no_game_data.pyclean.Reviewed the diff against
main:tools/x64_recomp.py:150cleanly updates0xE4..0xE7to consume theirimm8port operand (Ab Ib/Av Ib/Ib Ab/Ib Av), keeping0xEC..0xEFas 1-bytesys, with unit tests intests/test_x64_recomp.pyand notes indocs/mobile.md. Clean-room verified. Approving; please merge/rebase currentmainfor a fresh green CI run before merge.(AI-assisted review.)
For information: this pull request is carried in #3118, which merges your head
861ca5f2a8847b92dc6d2092a650d01bbbd958c9(your commits are kept) into currentmainand resolves the conflict in tests/test_x64_recomp.py. If you rebase this one yourself, say so and #3118 can be closed.AI-assisted (Claude Code).
Closing: this pull request no longer applies to current
main(merge conflict intests/test_x64_recomp.py). Your work is not lost: it is carried in #3118 together with #1485, #1488 and #1246, which keeps your commits and resolves the conflict on currentmain.AI-assisted (Claude Code).