COP1

Overview
The COP1 is the FPU of the main CPU. It operates on floats (either 32 bit singles or 64 bit doubles).

Just like the main CPU, the COP1 has 32 registers which are each 64 bit wide. Unlike the main CPU registers, all registers are equal (there is no zero register).

Getting data to/from the COP1
Numbers can be passed from main registers to FPU registers via MTC1 (32 bit) and DMTC1 (64 bit). For the way back, use MFC1/DMFC1. Alternatively, numbers can be loaded from RAM via LWC1/LDC1 and stored via SWC1/SDC1.

Supported formats and conversions
The instructions above simply transfer bits. In order to actually calculate, they need to be interpreted correctly. The COP1 understands four formats:

The COP1 can only perform calculations on singles and doubles; word and long are temporary formats merely used for conversion.

Example: The following snippet puts 6 into V0, which is then moved to the COP1 into F0. It then converts that number to a double and puts it into F2. At the end, F2 will have the value 6.0:

The COP1 supports almost all conversions:

Rounding modes and inexact results
The conversions mentioned above, but also most regular instructions can be lossy. When that happens, the COP1 has to perform some sort of rounding to fit the result in the destination. It provides four modes:
 * ROUND: Round towards nearest number (e.g. 4.4 => 4 and 4.6 => 5),
 * TRUNC: Round towards zero (e.g. 4.9 => 4 and -4.9 => 4),
 * CEIL: Round towards larger number (e.g. 4.1 => 5 and -4.1 => -4),
 * FLOOR: Round towards smaller number (e.g. 4.9 => 4 and -4.9 => -5).

The COP1 has a configurable rounding mode in FCSR (see below), which is applied for most instructions where its applicable. For the specific case of float->int conversions, it provides specialized instructions that overwrite the global rounding mode: ROUND.x.y, TRUNC.x.y, CEIL.x.y, FLOOR.x.y (where x is either W or L and y is either S or D; all 16 combinations are supported).

When rounding happens, inexact is signaled (see exceptions below).

FCSR
In addition to the data registers, the COP1 also provides the Floating Point Status Register, is read via CFC1 and written through CTC1 (both using index 31). It provides the following bits:

Exceptions Overview
The COP1 supports 6 exceptions:
 * Inexact: The destination can't hold the full result, so some data loss occurred and rounding was performed.
 * Underflow: The resulting number was so small it was rounded down to 0. This is always in combination with inexact. (The COP1 has a quirk here: Unlike other CPUs like x64 and arm64, the rounding modes FLOOR/CEIL are taken literally even on underflow; if the result is smaller than the smallest possible float, it might not be rounded to 0 but to the minimum regular float).
 * Overflow: The resulting number was so large it couldn't be represented as a regular number and was instead "rounded up to infinity" (which is a special floating point value). This is always in combination with inexact.
 * Division By Zero: This just happens for DIV.S and DIV.D when the divisor is 0.
 * Invalid Operation: This happens in a bunch of special cases (see "special cases" below).
 * Unimplemented Operation: This happens in a bunch of special cases (see "special cases" below).

For instructions that can fire exceptions (e.g. ADD.S, CVT.S.W) the process is roughly as follows (in this example, Inexact is being signaled):
 * Clear all Cause bits
 * Perform operation
 * Set Inexact Cause
 * If Inexact is Enabled, fire exception. Otherwise, set Inexact Flag

This means that after several instructions, Flags are cumulative: They are true if any previous instruction signaled that exception (assuming it was disabled). Cause on the other hand exclusively has information on the preceding instruction.

Unimplemented Operation is special as it can't be disabled - if it happens, it will always fire.

Floating Point Numbers
Before going into details about Invalid Operation and Unimplemented Operation, it makes sense to take a quick look at what floats actually are. This is the definition of a single (doubles work exactly the same, but have more bits in the exponent and the mantissa):

If the sign bit is 0, the number is positive. If it is 1, the number is negative (because of this, a floating point number is easily negated - just XOR with 0x80000000).

There are some special cases for the exponent and mantissa:
 * Exponent=0 and Mantissa=0: The number is 0.0 (if sign is 0) or -0.0 (negative zero if sign is 1). Note that for all intents and purposes, -0 is considered equal to 0.
 * Exponent=0 and Mantissa!=0: The number is a denormal or subnormal. If a number like this is given to an calculating instruction, an Unimplemented Operation is signaled.
 * Exponent=0xFF and Mantissa==0: The number is INFINITY (if sign is 0) or -INFINITY (if sign is 1).
 * Exponent=0xFF and Mantissa!=0: The number is a NAN (Not a Number), which indicates an incorrect result (this is for example the result of 0.0/0.0 or sqrt(-2). There are two varieties of NAN, which are differented by the most significant bit of the mantissa: msb=1 is qNAN (quiet) and msb=0 is sNAN (signaling). Any sNAN that is given to a calculating instruction will immediately trigger an UnimplementedOperation. qNAN as input will cause the output of the instruction to be qNAN (though with a different payload) and no exception will be signaled.
 * Anything else: This is a regular floating point number.