x64_recomp: SHLD and SHRD (0F A4/A5/AC/AD) decode with their ModRM and imm8 (X64-RECOMP-SHLD-SHRD-DECODE) #3148
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3148"
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 Kal0s-design on 2026-12-02T14:10:48Z.
Claimed in the coordination issue as: X64-RECOMP-SHLD-SHRD-DECODE (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7348110712)
What and why
tools/x64_recomp.pyhad no0Ftable entry for the double-precision shifts, so0F A4,0F A5,0F ACand0F AD(shld/shrdr/m, reg, imm8 or CL) decoded as the unknownop0f_XXafter the two opcode bytes. Their ModRM byte, any SIB/displacement and the imm8 of theA4/ACforms were then read as the next instructions. Example:48 0F A4 C2 05 C3came out asop0f_a4(3 bytes) followed by a bogusret 0xc305, and the census stopped the function at the decode error. Compilers emit these for 128-bit shifts.The fix adds four table entries using the specs the table already has:
Ev Gv IbforA4/AC(ModRM + imm8) andEv Gv cforA5/AD(ModRM, count in CL).66and REX go through the shared operand parser like every otherEv Gventry.Scope is decoding only. There is no emitter, so the translator reports them as unhandled
shld/shrdand leaves abrk, the same way it handles other instructions it cannot translate yet; the census now names them instead of losing the rest of the function. An emitter (flags, count 0, the 16-bit forms) can follow in its own pull request.The same item was taken earlier by #1349, which also added an emitter; it went stale on a conflict with
mainand its author closed it on 1 December. This one only carries the decode part.Tested
tests/test_x64_recomp.py: newtest_shld_shrd_carry_modrm_and_imm8(register and memory forms, SIB + disp8, RIP + disp32, with and without REX.W and66, and where the next instruction starts) andtest_shld_shrd_are_reported_unhandled_by_the_translator.main(69cd4106c):AssertionError: Tuples differ: ('op0f_a4', 3, True) != ('shld', 5, False)andAssertionError: Lists differ: [] != ['shld'], soFAILED (failures=2, skipped=34)over 53 tests.tests/test_x64_recomp.py53 testsOK (skipped=34),tests/test_recomp_census.py13 testsOK. The othertests/test_x64_recomp_*.pysuites andtests/test_gdk_runtime_calls.pyalso pass (their QEMU cases skip here).scripts/check_no_game_data.pypasses.objdump -D -b binary -m i386:x86-64), reference only.0Ftable, in other lines;git merge-treeof this branch with its head1ca3e4a98is clean.GPUs tested: n/a (CPU-only tests)
AI-assisted: yes
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-02T14:44:11Z.
Verified PR #3148 (
1f158fe57) merged cleanly ontomain(acc350745) on Windows 10 x64 (Pythontests/test_x64_recomp.py):python -I scripts/check_no_game_data.pyPASS.1f158fe57ontoacc350745):python -I tests/test_x64_recomp.py--Ran 19 tests in 2.162s -- OK (skipped=34)(both newSHLD/SHRDtests pass).maintools/x64_recomp.py+ PRtests/test_x64_recomp.py): both new tests fail as expected:test_shld_shrd_carry_modrm_and_imm8:('op0f_a4', 3, True) != ('shld', 5, False)test_shld_shrd_are_reported_unhandled_by_the_translator:[] != ['shld']OF(0xA4/0xA5shld,0xAC/0xADshrdwith"Ev Gv Ib"/"Ev Gv c"), matching the Intel SDM ModRM/SIB/disp/imm8 encodings and leaving translation cleanly marked unhandled until an emitter is added. No issues found.Verdict: PASS (CPU/unit tests only; no game launch).
AI-assisted: yes (Antigravity).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T15:11:12Z.
Merging. Head
1f158fe57merges cleanly withmain83046a713and does not force a rebase of #2566. Third-party verification by lixonik (https://github.com/ProjectLeonida/mandy/pull/3148#issuecomment-7349050422): new SHLD/SHRD tests red on main and green on head1f158fe577; CI green incl. no-game-data; no open review or question. Merged by MoonEyes.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T15:21:30Z.
Verified on this machine with the repository's own checker:
red then green, and nothing else moved.What that says: the two new tests fail on
mainand pass with the change - the decoder really was losing the instruction - and the other 17 in that file are untouched by it.git merge-treeagainstmain69cd4106cis clean.What I looked at in the diff: the four opcodes with their two forms (imm8 and
CL), the 66 and REX prefixes, and the memory form keeping SIB, displacement and immediate (4c 0f a4 44 24 08 03-> 7 bytes, base 4, disp 8). Those are the cases where a decoder that stops at the opcode silently loses the rest of a function, which is what the test's own comment says.What this does not cover, so nobody reads more into it than it says:
--no-cargo, and there is nothing Rust in the change;AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.