Skip to content

fix(recomp): give the MMI HI/LO family both pipelines' registers - #322

Open
abilliontokens wants to merge 1 commit into
ran-j:mainfrom
abilliontokens:fix/mmi-hilo-dual-pipeline
Open

abilliontokens wants to merge 1 commit into
ran-j:mainfrom
abilliontokens:fix/mmi-hilo-dual-pipeline

Conversation

@abilliontokens

@abilliontokens abilliontokens commented Oct 16, 2026 •

Copy link
Copy Markdown

Defect

The R5900's MMI multiply/divide family feeds two HI/LO pipeline register pairs — hi/lo (pipeline 0) and hi1/lo1 (pipeline 1) — and R5900Context already carries hi1/lo1 for MULT1/DIV1. The MMI translation ignored the second pair and collapsed everything into one 64-bit accumulator with the wrong lanes:

  • PMULTW/PMULTUW summed all four 32×32 products into one 64-bit HI:LO (hardware: lo/hi = product of words 0, lo1/hi1 = product of words 2; rd gets both 64-bit products).
  • PMADDW/PMSUBW/PMADDUW accumulated into that same single pair; hardware accumulates pipeline 0 from HI:LO and pipeline 1 from HI1:LO1 (PCSX2's MMI.cpp includes its documented high-word temp2 / 4294967295 rounding and, for PMADDW pipeline 0, the "division voodoo" +0x70000000 term).
  • PDIVW/PDIVUW/PDIVBW divided only word 0 (PDIVBW: only one divisor); hardware divides both word pairs (PDIVBW: every word by rt.h0, quotient in LO/LO1, remainder in HI/HI1).
  • PMFHI/PMFLO returned only the pipeline-0 register.
  • PMFHL.* was built from one pair with wrong unpack/packs orders (SLW did not clamp the 64-bit pairs, LH/SH took the wrong halfwords); PMTHL handled only sa=0 and clobbered both 32-bit halves of each HI/LO.
  • PMULTH/PMADDH/PMSUBH/PHMADH/PHMSBH routed halfword products into the wrong slots (PHMSBH missed the documented ~second-temp upper-word quirk).

Any title using the MMI integer DSP idioms (audio mixing, geometry setup, fixed-point filters) gets wrong data on every one of these.

Fix

A ps2_mmi_* helper family in ps2_runtime_macros.h, semantics taken from PCSX2's interpreter (pcsx2/MMI.cpp) quirk-for-quirk, using both hi/lo and hi1/lo1; the translator emits one call per instruction. ps2_u64_to_epi64_pair and the old PS2_PMFHL_* macros are removed. No permutation instruction is touched here (see #291 for those).

Generated code must be regenerated to pick this up.

Evidence

  • New PS2MmiHiLo suite, 45 cases: every helper against known answers derived from PCSX2's code with a distinct pattern in every lane (both pipelines, both sa forms, 0x80000000 / -1, divide-by-zero results, the PMADDW rounding/voodoo terms, PHMSBH's inverted upper word, rd suppression for PDIV*, $0 destinations). All fail on main.
  • ps2x_tests: Correction (2026-10-16): an earlier version of this description said EE scheduler selects absolute priority then FIFO also fails on pristine main. That was wrong. Our local MSVC build was configured with -DCMAKE_CXX_FLAGS=-msse4.1, which replaces CMake's default flags and so drops /EHsc, and that test failed only in that build. With default flags the suite passes on main: upstream CI is green on eb8688b (run 38574762065). The ps2x_tests totals measured in that build are withdrawn until re-run; every comparison above used the same build on both sides. TestSuiteRepair found the misconfiguration.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant