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>
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>
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>
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)
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.