Expand description
FPU arithmetic (T-13-002).
Pure functions over IEEE-754 values, with the VR4300’s FCSR semantics
layered on top. Kept separate from crate::fpr (the register file) and
crate::cop1 (the control registers) so each can be tested without the
others.
§Rounding
FCSR.RM selects the mode (UM §7.2.4): 0 nearest-even, 1 toward zero,
2 toward +∞, 3 toward −∞.
Every operation here honors it, arithmetic included. The four
arithmetic operations are adapters over crate::softfloat, which takes
the mode as a parameter and rounds exactly once; the conversions take a
Rounding directly.
This paragraph has been wrong in both directions and is worth reading
carefully before it is edited again. It first claimed the modes applied
throughout while the arithmetic ignored them; it was then corrected to say
the arithmetic could not honor them, which became false when the soft-float
path landed. See docs/engineering-lessons.md §3.3c — the rule is that a
comment asserting what the code does goes stale silently, because no test
fails when it is wrong.
§What is deliberately absent
The FP multiplication erratum is not here. It is a property of specific
early console revisions (n64brew_wiki/markdown/VR4300.md) and belongs with
the revision model, not with the arithmetic; implementing it inline would
make every multiply on every console wrong.
Structs§
- Flags
- The
FCSRcause/flag bits an operation can raise (UM §7.2.2). - Outcome
- A result plus the flags producing it raised.
Enums§
- Relation
- The outcome of an ordered comparison: which of the three mutually exclusive relations holds.
- Rounding
- The rounding mode from
FCSR.RM(UM §7.2.4). - Stepping
- Which VR4300 stepping a console carries.
Constants§
- CAUSE_
MASK FCSR.Cause— bits 17:12, the field an operation replaces wholesale.- CAUSE_
UNIMPLEMENTED - The
Unimplemented Operationcause bit (FCSRbit 17). - FMT_D
fmtfor double precision.- FMT_L
fmtfor 64-bit fixed point (L).- FMT_S
fmtfor single precision, as the COP1 encoding gives it.- FMT_W
fmtfor 32-bit fixed point (W), the source format ofCVT.fmt.W.
Functions§
- abs_d
ABS.D.- abs_s
ABS.S— clears the sign bit.- add_d
ADD.D.- add_s
ADD.S.- arith_
unimplemented_ d - See
arith_unimplemented_s. - arith_
unimplemented_ s - Do these arithmetic operands force unimplemented operation before the operation is even attempted?
- compare_
d C.cond.fmt— compare two double-precision values.- compare_
s C.cond.fmt— compare two single-precision values.- cvt_d_s
CVT.D.S— single to double. Always exact: everyf32is anf64.- cvt_s_d
CVT.S.D— double to single. Can overflow, underflow or lose precision.- delay_
cycles - Pipeline cycles for a COP1 arithmetic instruction — UM Table 7-14.
- div_d
DIV.D.- div_s
DIV.S.- flush_
subnormal_ f32 - Flush a subnormal result to zero or to the smallest normal, per
FCSR.FS. - flush_
subnormal_ f64 - See
flush_subnormal_f32. - is_
snan_ f32 - Is this
f32a signaling NaN as the VR4300 classifies one? - is_
snan_ f64 - Is this
f64a signaling NaN as the VR4300 classifies one? - is_
subnormal_ f32 - Is this a subnormal — a non-zero value with a zero exponent field?
- is_
subnormal_ f64 - Is this
f64a subnormal? Seeis_subnormal_f32. - is_
unimplemented_ nan_ f32 - Is this a NaN the VR4300’s arithmetic cannot handle?
- is_
unimplemented_ nan_ f64 - See
is_unimplemented_nan_f32. - long_
convertible - Does a 64-bit integer satisfy
CVT.[S,D].L’s range restriction? - mul_d
MUL.D.- mul_
erratum_ triggers - Would the erratum’s trigger condition fire for this multiply?
- mul_s
MUL.S.- neg_d
NEG.D.- neg_s
NEG.S— flips the sign bit.- round_
f64 - Round a float to an integer under an explicit
Roundingmode. - stall_
cycles - The stall a COP1 arithmetic instruction adds, in
PCycles. - sub_d
SUB.D.- sub_s
SUB.S.- to_i32
- Convert a float to a 32-bit integer under
mode. - to_i64
- Convert a float to a 64-bit integer under
mode.