Commit Graph

56 Commits

Author SHA1 Message Date
9b7674d643 Fix post-merge CI regressions in wave_diff, x64_recomp, and piecewise_parse 2026-12-01 10:54:03 -05:00
a11c4fbf34 Merge pull request #1428 from IlyassRS3/fix/x64-recomp-short-xchg-movnti
x64_recomp: fix short-form xchg (0x91..0x97) and movnti (0F C3) widths/emission (X64-RECOMP-SHORT-XCHG-MOVNTI)
2026-12-01 16:15:43 +01:00
bc7f99f2b3 Merge pull request #1329 from IlyassRS3/feat/x64-recomp-adcsbb-narrow
x64_recomp: add 8/16-bit adc/sbb, fix Asm.csinv encoding, sign-extend imm, and stash AF (X64-RECOMP-ADCSBB-NARROW)
2026-12-01 16:15:10 +01:00
52e1c837b2 Merge pull request #1120 from kett1m/x64-recomp-vzeroupper
x64_recomp: vzeroupper is three bytes, not four (X64-RECOMP-VZEROUPPER-NO-MODRM)
2026-12-01 15:53:31 +01:00
d762b13973 Merge pull request #950 from barkodr/fix/x64-recomp-qemu-path
x64_recomp: find qemu through QEMU_AARCH64 or PATH, not a contributor's home folder
2026-11-30 09:13:23 +01:00
dd60cba733 Merge remote-tracking branch 'origin/main' into x64-recomp-vzeroupper
# Conflicts:
#	tests/test_x64_recomp.py
2026-11-29 20:30:08 +01:00
04f484006e Merge pull request #2143 from kevincommits/x64-recomp-qemu-unaligned
x64_recomp: the QEMU harness maps guest RAM as Normal memory, so unaligned accesses work (X64-RECOMP-QEMU-UNALIGNED)
2026-11-29 03:16:40 +01:00
7100865c42 Merge pull request #1211 from IlyassRS3/feat/x64-recomp-rcl-rcr
x64_recomp: rcl and rcr rotate-through-carry emitters (X64-RECOMP-RCL-RCR)
2026-11-29 01:54:27 +01:00
d63e0b94d4 Merge pull request #1213 from IlyassRS3/feat/x64-recomp-std-str
x64_recomp: std/cld direction flag, reverse string ops, and lods emitter (X64-RECOMP-STD-STR)
2026-11-29 01:54:11 +01:00
c7753ed98a Merge pull request #1205 from IlyassRS3/feat/x64-recomp-bitops
x64_recomp: bt/bts/btr/btc, bsf/bsr, tzcnt/lzcnt, and popcnt emitters (X64-RECOMP-BITOPS)
2026-11-28 22:52:58 +01:00
d2bac15bee Merge pull request #1339 from IlyassRS3/fix/x64-recomp-signext-imm
x64_recomp: sign-extend ALU/CMP/TEST/MOV immediates, fix Asm.li(-1), and handle movnti (X64-RECOMP-SIGNEXT-IMM)
2026-11-28 20:39:29 +01:00
c80db3dc1c Merge pull request #1321 from IlyassRS3/fix/x64-recomp-conv-call-ret-loop
x64_recomp: fix cwd/REX.W conv, ret imm16, indirect call [rsp], and jrcxz/loop (X64-RECOMP-CONV-CALL-RET-LOOP)
2026-11-28 20:39:05 +01:00
fa5a65df07 Merge pull request #1313 from IlyassRS3/fix/x64-recomp-incdec-width-cf
x64_recomp: fix 8/16-bit inc/dec, CF preservation, and inc/dec/neg AF (X64-RECOMP-INCDEC-WIDTH-CF)
2026-11-28 20:38:42 +01:00
2662987988 Merge pull request #1296 from IlyassRS3/fix/x64-recomp-shift-width-cf
x64_recomp: fix 64-bit shift CF and narrow shift/rotate semantics (X64-RECOMP-SHIFT-WIDTH-CF)
2026-11-28 20:38:15 +01:00
23ff0b91c4 Merge pull request #1279 from IlyassRS3/feat/x64-recomp-muldiv
x64_recomp: fix mul/imul CF/OF bugs and add 8/16/64-bit mul/div/idiv emitters (X64-RECOMP-MULDIV)
2026-11-28 20:37:39 +01:00
de3e5d5482 Merge pull request #1409 from IlyassRS3/fix/x64-recomp-rexw-over-66
x64_recomp: give REX.W precedence over 0x66 operand-size override (X64-RECOMP-REXW-OVER-66)
2026-11-28 15:41:07 +01:00
cb7a239cc1 Merge pull request #1408 from IlyassRS3/fix/x64-recomp-push-pop-16
x64_recomp: handle 16-bit operand-size override (66) in push and pop (X64-RECOMP-PUSH-POP-16)
2026-11-28 15:40:39 +01:00
17829743ad Merge pull request #1401 from IlyassRS3/fix/x64-recomp-parity-logic-eflags
x64_recomp: clear logic OF & high eflags in rt_mkflags, fix parity/ctx_jcc NZCV & T0 clobber (X64-RECOMP-PARITY-LOGIC-EFLAGS)
2026-11-28 15:37:08 +01:00
2953aca5f5 Merge pull request #1392 from IlyassRS3/fix/x64-recomp-addrsize-67
x64_recomp: handle 0x67 address-size override in memory and moffs operands (X64-RECOMP-ADDRSIZE-67)
2026-11-28 15:35:34 +01:00
e208709dd4 Merge pull request #1383 from IlyassRS3/feat/x64-recomp-xlat-enter
x64_recomp: add xlat/xlatb and enter emitters (X64-RECOMP-XLAT-ENTER)
2026-11-28 15:34:55 +01:00
08f1b98ac1 Merge pull request #1379 from IlyassRS3/fix/x64-recomp-flagctl-preserve
x64_recomp: preserve ARM NZCV in _maybe_mkflags and ctx.eflags in _emit_flagctl
2026-11-28 15:34:14 +01:00
4ee8a3f4a3 Merge pull request #1373 from IlyassRS3/feat/x64-recomp-lock-alu
x64_recomp: emit ARMv8.0 LL/SC atomics for LOCK ALU memory ops
2026-11-28 15:33:40 +01:00
05a04c2ebb Merge pull request #1368 from IlyassRS3/feat/x64-recomp-bmi1-bmi2
x64_recomp: add VEX BMI1 and BMI2 emitters
2026-11-28 15:32:50 +01:00
1e69611027 Merge pull request #1362 from IlyassRS3/feat/x64-recomp-movbe-crc32
x64_recomp: add movbe and SSE4.2 crc32 emitters
2026-11-28 15:31:51 +01:00
4ecb057499 Merge pull request #1483 from kett1m/x64-recomp-grp7
x64_recomp: 0F 01 /r needs its ModRM byte (X64-RECOMP-GROUP7)
2026-11-28 11:19:55 +01:00
00131bb85e main keeps its own runtime, tools and tests; the branch's variants stay on port/d3d12-nvidia
After the merge the tree held this branch's older states of files main maintains. Run against main's code,
tests/test_acphal_abi.py and 11 of the 15 translator tests that differed failed, and the C++ runtime would have
been built from two generations of its sources. So that the merge cannot break what main builds and tests:

- runtime/ is main's, file for file (68 files only this branch had are not carried over);
- every file under tools/, tests/ and docs/ that both sides have is main's (80 files);
- ten translator tests only this branch has, which test rules main's translator does not have, and their
  fixtures are left out.

What main gains: d3d12/ (the Rust D3D12 runtime), its launchers and helpers (Launcher.bat, scripts/play*.ps1,
play-linux.sh, port_ctl.py, smooth-motion.ps1, fetch_vkd3d_proton.py, sync_victory.py), mods/example_lua, eleven
notes under docs/, seven tools and the tests that pass with main's code, the README's sections and credits, and
the "Runtime traps" section of AGENTS.md. Everything left out here is on the branch port/d3d12-nvidia.

Checked: compileall; make_game.py --help; check_no_game_data.py over every file this adds to main; the
line-ending, docs-encoding, CI-registration and docs tests; each test file that differs from main, on its own.
Not run: the whole translator suite, the C++ build, cargo over d3d12/ after the merge (d3d12/ is byte for byte the
branch's), CI.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 17:58:38 -05:00
b87abdef57 Merge mandy's main into port/d3d12-nvidia
Brings the D3D12 runtime branch (d3d12/, its launcher scripts and notes, and the pull requests reviewed and applied
on it) together with mandy's main.

Conflicts (67 files, none under d3d12/): docs/, make_game.py, runtime/, scripts/build_runtime.ps1, tests/ and
tools/. Every one takes main's side: main is where that code is maintained, and this branch's copies were older
states of the same files or the same pull requests in another form. tests/test_fspx_unpack.py is main's too, as it
tests main's tools/fspx_unpack.py. Nothing under d3d12/ is changed by the merge.

Checked before pushing: python -m compileall over make_game.py, tools and tests; make_game.py --help;
scripts/check_no_game_data.py over the files this adds to main; tests/test_text_write_line_endings.py. The
translator suite, the C++ runtime build and CI have not run on the result.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 17:50:37 -05:00
15c668fb64 PR #950: x64_recomp: find qemu through QEMU_AARCH64 or PATH, not a contributor's home folder
From https://github.com/ProjectLeonida/mandy/pull/950 (head 16452e785f), applied as a reviewed patch.

Co-authored-by: barkodr <barkodr@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 15:42:19 -05:00
cd536c403a fix: x64_recomp QEMU harness maps guest RAM as Normal memory so unaligned accesses work 2026-11-26 21:27:48 -05:00
4a1c850a7a x64_recomp: treat a shift by cl as a writer that may leave the flags alone (#2150 review)
x86 changes no flag for a shift or rotate whose masked count is 0. The
first version patched ARM's carry when cl is 0, taking CF from ctx when no
carry writer came before the shift in its block. But flag liveness treated
the shift as always writing, so a writer in an earlier block never stored
its word, and ctx held a stale CF: cmp r8d, 2 (r8d = 1); jmp; mov cl, 0;
shl eax, cl; setc read 0 instead of 1.

_flag_analysis now treats a shift by cl as a conditional writer: liveness
does not kill the flags it writes, the writer before it stores its word as
well, and a consumer behind it reads the ctx word. With cl = 0 the shift
is skipped whole, its flag store included, so ctx keeps the earlier word.
The ARM-carry patching and shift_prev_c go; the immediate-count-0 change
stays.

Tests: the analysis checks of the patching are replaced by checks of the
new rule, and three execution cases are added (a carry from an earlier
block with cl = 0 and cl = 1, and one a logic op cleared). The first one
fails on the previous head.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 19:37:25 -05:00
5ce5769d48 x64_recomp: preserve carry flag across zero-count shifts (X64-RECOMP-SHIFT-ZERO-COUNT-CARRY)
In x86-64, shifts and rotates (shl, shr, sar, rol, ror) leave all flags
untouched when the count is zero.

In tools/x64_recomp.py:
1. Immediate count 0 shifts were classified with flags_w = FLAG_WRITERS[mnem],
   causing FunctionTranslator to treat them as flag producers in arm_path,
   while emitting 0 instructions. Subsequent condition checks (e.g. setc/jcc)
   therefore checked ADD_KIND condition 'cs' against the preceding SUB_KIND
   instruction (which set C == 0 on borrow), inverting the carry flag.
2. Variable count shifts (cl) skipped execution on cbz(T1, skip) when cl == 0,
   leaving ARM NZCV in the preceding SUB_KIND instruction's polarity
   (C == 0 for borrow), while downstream consumers expected ADD_KIND polarity
   (C == 1 for borrow), inverting the carry flag.

Fix:
1. In _classify(), mark shifts and rotates with immediate count 0 (including
   masked mod 32/64 zero counts) with flags_w = '' and flags_r = '' so they
   are not treated as flag writers.
2. In _flag_analysis(), track the nearest reaching carry writer before variable
   shifts in the basic block (shift_prev_c).
3. In _emit_shift(), on the cl == 0 path when carry is needed:
   - If the preceding carry producer was in SUB_KIND, invert NZCV bit 29
     (C := !C) to convert subtraction borrow polarity into ADD_KIND carry
     polarity.
   - If there was no preceding carry producer in the block, restore CF from
     CTX_EFLAGS into NZCV bit 29.
4. Move _maybe_mkflags(ins) after the skip label so that materialized flag
   blocks preserve valid flags on both zero and non-zero count paths.
5. Add unit tests in tests/test_x64_recomp.py.

AI-assisted (Claude Code)
2026-11-26 02:54:28 +03:00
c1df54c119 x64_recomp: 0F 01 /r is a ModRM group, so the walk stops one byte late (X64-RECOMP-GROUP7)
The `0F` table had no entry for opcode `0x01`, so the whole system-instruction
group decoded as the unknown `op0f_01` and its two opcode bytes. Every form of
`0F 01 /r` carries a ModRM byte: the memory forms are SGDT/SIDT/LGDT/LIDT/SMSW/
LMSW/INVLPG, and the register forms are whole ModRM bytes (MONITOR, MWAIT,
XGETBV, XSETBV, CLZERO, MONITORX, MWAITX, RDTSCP, SWAPGS, the VMX/SVM
instructions). Stopping after the two opcode bytes made every following
instruction in the function the wrong one.

A per-instruction differential against objdump over the retail image's `.text`
(26,674,180 instructions) shows the group decoded one byte short at all 16 sites
the image uses (10 clzero, 2 xgetbv, 2 monitorx, 2 mwaitx); with the group back,
9 `.pdata` functions decode 638 instructions further and 7 of them have no
unknown instruction left. `docs/mobile.md` records the measurement and the REA
section-header evidence.

Test: tests/test_x64_recomp.py::DecodeTests::test_group7_0f01_carries_modrm
fails before the fix (`0f 01 fc` decodes to size 2) and passes after.
2026-11-25 02:09:36 +01:00
41db945135 x64_recomp: fix short-form xchg (0x91..0x97) and movnti (0F C3) widths/emission (X64-RECOMP-SHORT-XCHG-MOVNTI) 2026-11-25 01:02:21 +01:00
d35c8665df x64_recomp: give REX.W precedence over 0x66 operand-size override 2026-11-25 00:36:09 +01:00
c6d1639d45 x64_recomp: handle 16-bit operand-size override (66) in push and pop 2026-11-25 00:32:32 +01:00
df07ec2bd0 x64_recomp: clear logic OF & high eflags in rt_mkflags, fix parity/ctx_jcc NZCV & T0 clobber 2026-11-25 00:24:22 +01:00
442ef0a663 x64_recomp: handle 0x67 address-size override in memory and moffs operands 2026-11-25 00:09:40 +01:00
2193b80d05 x64_recomp: add xlat/xlatb and enter emitters 2026-11-24 23:58:59 +01:00
5d91014825 x64_recomp: preserve ARM NZCV in _maybe_mkflags and ctx.eflags in _emit_flagctl 2026-11-24 23:54:04 +01:00
e8b1173e75 x64_recomp: emit ARMv8.0 LL/SC atomics for LOCK ALU memory ops 2026-11-24 23:46:09 +01:00
6204164491 x64_recomp: add VEX BMI1 and BMI2 emitters 2026-11-24 23:39:48 +01:00
7014994d41 x64_recomp: add movbe and SSE4.2 crc32 emitters 2026-11-24 23:29:52 +01:00
c641b98321 x64_recomp: sign-extend ALU/CMP/TEST/MOV immediates, fix Asm.li(-1), and handle movnti 2026-11-24 22:58:55 +01:00
efd36453d4 x64_recomp: add 8/16-bit adc/sbb, fix Asm.csinv encoding, sign-extend imm, and stash AF 2026-11-24 22:55:21 +01:00
fa7697749f x64_recomp: fix cwd/REX.W conv, ret imm16, indirect call [rsp], and jrcxz/loop 2026-11-24 22:48:57 +01:00
7e38867514 x64_recomp: fix 8/16-bit inc/dec, CF preservation, and inc/dec/neg AF 2026-11-24 22:41:41 +01:00
75d6d34691 x64_recomp: fix 64-bit shift CF and narrow shift/rotate semantics 2026-11-24 22:23:14 +01:00
fbba8eebd2 x64_recomp: fix mul/imul CF/OF bugs and add 8/16/64-bit mul/div/idiv emitters 2026-11-24 22:12:51 +01:00
944e675b66 x64_recomp: std/cld direction flag, reverse string ops, and lods emitter (X64-RECOMP-STD-STR) 2026-11-24 21:24:29 +01:00
621aaeefc1 x64_recomp: rcl and rcr rotate-through-carry emitters (X64-RECOMP-RCL-RCR) 2026-11-24 21:20:12 +01:00