pub const fn div(dividend: u64, divisor: u64) -> HiLoExpand description
DIV — 32-bit signed divide. Reproduces the VR4300 sign-extension erratum.
Acts as a 32-bit by 35-bit signed division: the dividend is sign-extended on bit 31, the divisor on bit 34, before a 64-bit division.
§The unknown case
When bits 63 and 31 of the divisor differ, the quotient written to LO is
documented as incorrect and “it is currently unclear how the outputs of this
last case are arrived at” — unknown even to N64brew. HI is at least
well-defined: remainder = (int32_t)(dividend - quotient * divisor), computed
in 64-bit.
This implementation performs the 32×35 division in that case too, which is a
guess, and it is recorded as such in docs/accuracy-ledger.md. It must be
characterized against hardware rather than left to look authoritative.
Divide-by-zero is architecturally undefined on MIPS; the values below follow the conventional interpretation and also need hardware confirmation.