Expand description
The one sanctioned wide-arithmetic type for guest code.
The R3000 has mult and multu, which write a 64-bit product to the
HI:LO pair in one instruction. A 64-bit add or subtract is a few 32-bit
instructions with a carry, a compare is two word compares, and a shift is
a few word shifts. None of that calls a compiler helper. The expensive
half of 64-bit arithmetic is division and remainder (__divdi3,
__udivdi3, __moddi3, __umoddi3, with u64_div_rem behind them),
and the 128-bit and soft-float routines; the project’s guest symbol gate
(tools/guest_symbol_gate.sh) fails a link that contains any of them.
Game and engine code that has a quantity this wide (a dot product of two
world-sized vectors, a squared distance, the cross product of two screen
edges, a CORDIC accumulator) holds a Wide or a WideU and never
names i64 or u64, so a per-project source guard can fail the build on
every i64/u64 token outside this file. This file is where the rule is
enforced: its 64-bit tokens carry psx-numeric-allow markers.
§What exists, and what deliberately does not
Only operations that compile to native R3000 instructions exist:
- full products of two 32-bit words (
Wide::mul,WideU::mul), and multiply-accumulate forms of them; - 64-bit add, subtract, negate, absolute value, compare;
- shifts, with the count taken modulo 64;
- the low 64 bits of a 64-by-64 product (
Wide::mul_w) and of a 64-by-32 product (Wide::times), which LLVM expands to a fewmultu/muland adds; - extraction to 32 bits in three explicit flavours: truncating
(
low,shr_i32), checked (to_i32,to_u32) and saturating (saturate_i32,saturate_u32); - a square root (
Wide::isqrt,WideU::isqrt), which iscrate::int32::isqrt_u64and usesmultuonly.
This module has no division and no remainder, and no way to ask for
one. Dividing a wide value is crate::wide_div: exact, in 32-bit
instructions only, with explicit rounding and clamping. To divide a product
of two words by a word use crate::int32::mul_div_i32 /
crate::int32::mul_div_u32 (a native multu then divu), which is
cheaper than building the Wide first.
Arithmetic wraps like the release-mode i64 / u64 it stands in for.
Every function is #[inline(always)] (or const), so a call site
compiles to the same instructions as the bare 64-bit expression.
The representation is private. Outside tests the only 64-bit tokens in
this module are the handful in the private widen* / raw helpers, each
with a marker.