floating-pointarmnannegationabsolute-value

Rationale for default NaN is never returned from FABS, FMAX*, FMIN*, and FNEG instructions


Arm Architecture Reference Manual for A-profile architecture (issue I.a) (emphases added):

DN, bit [25]

Default NaN use for NaN propagation.

0b0 NaN operands propagate through to the output of a floating-point operation.

0b1 Any operation involving one or more NaNs returns the Default NaN.

This bit has no effect on the output of FABS, FMAX*, FMIN*, and FNEG instructions, and a default NaN is never returned as a result of these instructions.

A simple question: what is the rationale for the emphasized text?

What are the obstacles to return a default NaN from these instructions?


Solution

  • FNEG normally has a very simple implementation: just flip the sign bit. In order to provide "default NaN" behavior, it would have to include a test for NaN to trigger special handling, making it possibly less efficient. Most other instructions already need special handling for NaN to get correct mathematical results, in which case it isn't so bad to change that handling when DN is set.

    FABS is similar, in that it can be implemented by unconditionally clearing the sign bit.

    For FMAX/FMIN, they are usually defined to have behavior like x > y ? x : y, where the result is always one of the two inputs, and this property is considered rather fundamental. Replacing a NaN result with a default NaN would break it.