VR4300: Difference between revisions

372 bytes added ,  2 years ago
m
→‎Known Bugs: Added a clearer example of the MUL/MUL CPU bug
mNo edit summary
m (→‎Known Bugs: Added a clearer example of the MUL/MUL CPU bug)
Line 5:
= Known Bugs =
 
Some VR4300 CPUs contain the “VR4300 multiplication bug”. This causes incorrect results to be generated, under certain circumstances, after computing a floating-point multiplication. The bug was fixed in later processor [https://en.wikipedia.org/wiki/Stepping_level steppings], and affects someearly but not allmodel Nintendo 64 consoles. Theregenerally isNUS-01 a(Japan ROMOnly), whichNUS-02 tests(Japan ifOnly), yourNUS-03 hardware(First isUS affectedRevision). by this bug (where?)
 
GCC accepts the <code>-mfix4300</code> flag, which tells GCC to generate code with a workaround for this bug—two <code>nop</code> instructions are inserted after every <code>mul.s (fp),</code> or <code>mul.d (fp) or mult (integer)</code>. For example, consider this function:
 
For example, consider this function:
float mul(float x, float y) { return x * y; }
 
<code>float mul(float x, float y) { return x * y; }</code>
If the fix is disabled, GCC will generate the following assembly (for the n32 ABI):
Without the fix it may generate this code:
 
<code>
# Does not contain workaround, may cause problems.
jal mul:
jr $31nop
mul.s $f0f1,$f12f13,$f14f15
mul:
 
jr $31
With the setting enabled, GCC will append <code>nop</code> instructions. Note that in this case, the second one goes into the branch delay slot.
mul.s $f0,$f12,$f14
 
</code>
# Contains workaround for CPU bug.
The mul.s after the nop (red) may produce unexpected results, if the operands in the mul.s after the jr (yellow) include NaN, Zero or Infinity.
mul:
mul.s $f0,$f12,$f14
nop
jr $31
nop
 
With the fix it may generate this code:
<code>
mul.s $f1,$f13,$f15
nop
jal mul
nop
nop
mul:
mul.s $f0,$f12,$f14
jr $31
nop
</code>
Depending on the other instructions that can be reordered the nops could be other instructions that perform work, so this is a worst case scenario.
There may be a ROM which tests if your hardware is affected by this bug, but determining based on the Motherboard revision is easier.
[[Category:Motherboard components]]
autoeditors, Administrators
76

edits