Early revisions of the VR4300 have a hardware bug where two consecutive multiplications can produce an incorrect result in the second multiply.
This revision adds the -mfix4300 flag to llvm (and clang) which, when passed, provides a software fix for this issue.
More precise description of the "mulmul" bug:
1: mul.[s,d] fd,fs,ft 2: mul.[s,d] fd,fs,ft or [D]MULT[U] rs,rt
When the above sequence is executed by the CPU, if at least one of the source operands of the first mul instruction happens to be sNaN, 0 or Infinity, then the second mul instruction may produce an incorrect result.
This can happen both if the two mul instructions are next to each other and if the first one is in a delay slot and the second is the first instruction of the branch target.
Description of the fix:
This fix adds a backend pass to llvm which scans for mul instructions in each basic block and inserts a nop whenever the following conditions are met:
- The current instruction is a single or double-precision floating-point mul instruction.
- The next instruction is either a mul instruction (any kind) or a branch instruction.
Note:
I chose -mfix4300 as a name for the flag to follow the GCC nomenclature but I don't know if this is a good name.
We can move this option to the MipsTargetMachine.cpp and just do not add the pass when it is not necessary.