6.6.8.9.1 Compare Status and Predicates

IEEE 754-2008/2019 standards specify Quiet and Signaling Compare Predicates (equations) as shown in Table 6-46. A “signaling” predicate signals (i.e., attempts to generate an exception) when a Quiet NaN or Signaling NaN (qNaN or sNaN) operand is detected.

A “quiet” predicate will not signal when a qNaN operand is detected.

An sNaN will always signal an exception when detected as an operand for all instructions except those that do not generate any exceptions (FMOV, FMOVC, FABS, FNEG and FTST).

The FPU coprocessor macro implements Signaling and Quiet predicates by supporting two floating-point compare options, one signaling (FCPS), one quiet FCPQ), and a set of floating-point branch operations that test for the required predicates. Each compare instruction will set one of the four mutually exclusive ordering relations (GT, LT, EQ, UN status bits) located in the FSR to indicate the result of the comparison.

  • FCPS (signaling compare):
    • qNaN or sNaN: If either or both operands are a qNaN or sNaN value, the compare is considered unordered which will cause the FSR.UN bit to be set. In addition, the FSR.INVAL bit will be set, causing the CPU to be signaled via the Invalid exception (assuming that the exception is not masked).
  • FCPQ (quiet compare):
    • qNaN: If one or more operands contain a qNaN value, the compare is considered unordered which will cause the FSR.UN bit to be set. A qNaN will not set the FSR.INVAL bit, so no signaling will occur.
    • sNaN: If either or both operands are a sNaN value, the compare is considered unordered which will cause the FSR.UN bit to be set. In addition, the FSR.INVAL bit will be set, causing the CPU to be signaled via the Invalid exception (assuming that the exception is not masked).

The compare operation subtracts Fs (subtrahend) from Fb (minuend). The EQ, GT and LT status bits are set as follows:

  • If the minuend is equal to the subtrahend (Fb = Fs) the EQ status bit is set.
  • If the minuend is greater than the subtrahend (Fb > Fs) the GT status bit is set.
  • If the minuend is less than the subtrahend (Fb < Fs) the LT status bit is set.

In addition, the UN status bit is set if one or both operands is a NaN. If this is the case, no other compare status is set (i.e., UN and EQ, GT, LT are mutually exclusive).

Note: The FCPS/FCPQ instructions consider -0 and +0 as equivalent.
Note: Comparing a value to itself should produce an equivalence result. However, UN has precedence over EQ such that, should two values be identical but both NaN, the UN bit will be set but the EQ bit will be cleared.