Skip to content

Recompiler: build the wide unsigned multiply without UMul on a Mac - #3525

Draft
vakaobr wants to merge 2 commits into
xcl-dev:mainfrom
vakaobr:recompiler/mac-wide-multiply-without-umul
Draft

vakaobr wants to merge 2 commits into
xcl-dev:mainfrom
vakaobr:recompiler/mac-wide-multiply-without-umul

Conversation

@vakaobr

@vakaobr vakaobr commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Stacked on #2361; only the top commit belongs here. Part of #258.

Apple's metal-shaderconverter, which D3DMetal runs on every pipeline, does not handle DXIL UMul (binaryWithTwoOuts, opcode 42) in every program: on some it overflows its stack and the compile never returns. The direct translator emits UMul for the stride * index term of a windowed buffer address, so on a Mac those pipelines can stop there. On a Mac (util::mac_host), umul_wide now builds the high half from 16-bit parts, as the HLSL kernel's mul_hi_u32 does, so the window code still needs no Int64Ops. Windows keeps UMul. #2172 would use umul_wide in more places; on a Mac those go through the same halves.

What is in it

  • crates/xcl/src/gpu/dxil/ops.rs: umul_wide takes umul_wide_halves on a Mac.
  • crates/xcl/src/gpu/dxil/ops_tests.rs: new umul_wide_without_umul_matches_cpu.
  • crates/xcl/src/gpu/dxil/core_tests.rs: window_at_lowers_to_32bit_carry_without_int64 expects no UMul on a Mac and UMul elsewhere.

Tested

  • M5 Pro, macOS 27.2.1, CrossOver 26.3 (Wine) with D3DMetal, Rust 1.100, x86_64-pc-windows-gnu, debug; this branch on main 9dfbe3e with Memory: detect a macOS host under Wine (mac_host) #2361.
  • gpu_memory_windows_above_4_gib, gpu_memory_windows_reject_out_of_uma_aliasing, gpu_sparse_vram_descriptors_buffers_and_xmem: on main each reports "has overflowed its stack" and hangs; with this PR all three pass.
  • umul_wide_without_umul_matches_cpu (new), window_at_lowers_to_32bit_carry_without_int64, gpu_window_at_32bit_carry_edge_cases, a_mac_host_is_darwin_under_wine_unless_forced: pass. With XCL_MAC_HOST=0 the window_at test still finds UMul.

Regression run

  • None yet: I have no Windows machine for scripts/smoke.ps1. On Windows mac_host() is false, so the code path there is unchanged.

Not tested

  • Windows (any GPU), the whole suite, a retail title. IMul's high half is also wrong on D3DMetal (1 * 0x9e377939 gives 0); the runtime does not emit IMul today, and this PR does not change it.

AI use

  • Claude Code with Claude Opus 5.5: found the converter's stack overflow, wrote the change and the tests, ran them on my Mac, and drafted this description. I checked it before opening.

util::mac_host(): the process runs under Wine on a Mac (CrossOver or the
Game Porting Toolkit), where D3D12 is Apple's D3DMetal and the title's
code runs through Rosetta 2. ntdll's wine_get_host_version names the
host's system; "Darwin" is a Mac. XCL_MAC_HOST=1 / 0 overrides it.

Nothing calls it yet. The Mac changes that need to know they run there
(the barrier default, title textures on shared pages) build on it; until
now only Ahmet-Dedeler's mac7 branch had it. Part of xcl-dev#258.
Apple's metal-shaderconverter, which D3DMetal runs on every pipeline,
does not handle DXIL UMul (binaryWithTwoOuts, opcode 42) in every
program: on some it overflows its stack and the compile never returns.
The direct translator emits UMul for the stride * index term of a
windowed buffer address (lower_window.rs), so on a Mac every test and
title pipeline with such an address can stop there.

On a Mac (util::mac_host), umul_wide now builds the high half from
16-bit parts, as the HLSL kernel's mul_hi_u32 does, so the window code
still needs no Int64Ops. Windows keeps UMul.

Measured on an M5 Pro, macOS 27.2.1, CrossOver 26.3 + D3DMetal, on main
9dfbe3e with xcl-dev#2361:
- gpu_memory_windows_above_4_gib,
  gpu_memory_windows_reject_out_of_uma_aliasing and
  gpu_sparse_vram_descriptors_buffers_and_xmem: on main each reports
  "has overflowed its stack" and hangs; with this change all three pass.
- umul_wide_without_umul_matches_cpu (new): passes on 32 lanes; its
  kernel has no binaryWithTwoOuts and no Int64Ops.
- window_at_lowers_to_32bit_carry_without_int64 now expects no UMul on
  a Mac: it passes, and with XCL_MAC_HOST=0 it still finds UMul, as
  before (with the Mac branch disabled it failed, measured on my Mac
  branch on 27 Nov).
- gpu_window_at_32bit_carry_edge_cases: passes.
@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 3ebde06, diff read, not a merge-check; draft with PR description red, so not built or run):

  • No xcl-smoke blocks (main or this head), which is why PR description fails, and the full suite hasn't been run anywhere. It's stacked on Memory: detect a macOS host under Wine (mac_host) #2361 (open draft), which provides util::mac_host().
  • The test pairs each value with a derived one, so the largest-carry case (0xFFFFFFFF x 0xFFFFFFFF) isn't covered; worth adding.

Fine: umul_wide_halves is correct for all inputs (the middle sum stays below 2^18, and since the true high word fits in 32 bits no addition wraps). It's gated on mac_host() (ops.rs ~444), so Windows still emits UMul and the existing Windows test still asserts it; the only caller is lower_window.rs ~130. The new GPU test skips correctly without a GPU, and AI use names the model.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 3ebde06

Stacked on #2361: the first commit (69c0b04, util::mac_host) is #2361's; only 3ebde06 belongs here. No other open or merged PR avoids UMul in umul_wide; #2363, #2402 and #2492 use mac_host for other changes.
No problems found in the diff: ops.rs::umul_wide_halves sums the two cross products' low halves with the carry out of ll before shifting, which gives the exact high word, and umul_wide_without_umul_matches_cpu checks it against the CPU product. On Windows mac_host() is false, so the emitted DXIL is unchanged there.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants