Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture
4-22 Vol. 1
DATA TYPES
4.8.3.6 Using SNaNs and QNaNs in Applications
Except for the rules given at the beginning of Section 4.8.3.4, “NaNs,” for encoding
SNaNs and QNaNs, software is free to use the bits in the significand of a NaN for any
purpose. Both SNaNs and QNaNs can be encoded to carry and store data, such as
diagnostic information.
By unmasking the invalid operation exception, the programmer can use signaling
NaNs to trap to the exception handler. The generality of this approach and the large
number of NaN values that are available provide the sophisticated programmer with
a tool that can be applied to a variety of special situations.
For example, a compiler can use signaling NaNs as references to uninitialized (real)
array elements. The compiler can preinitialize each array element with a signaling
NaN whose significand contained the index (relative position) of the element. Then,
if an application program attempts to access an element that it had not initialized, it
can use the NaN placed there by the compiler. If the invalid operation exception is
unmasked, an interrupt will occur, and the exception handler will be invoked. The
exception handler can determine which element has been accessed, since the
Table 4-7. Rules for Handling NaNs
Source Operands Result
1
SNaN and QNaN x87 FPU — QNaN source operand.
SSE/SSE2/SSE3 — First operand (if this operand is
an SNaN, it is converted to a QNaN)
Two SNaNs x87 FPU—SNaN source operand with the larger
significand, converted into a QNaN
SSE/SSE2/SSE3 — First operand converted to a
QNaN
Two QNaNs x87 FPU — QNaN source operand with the larger
significand
SSE/SSE2/SSE3 — First operand
SNaN and a floating-point value SNaN source operand, converted into a QNaN
QNaN and a floating-point value QNaN source operand
SNaN (for instructions that take only one
operand)
SNaN source operand, converted into a QNaN
QNaN (for instructions that take only one
operand)
QNaN source operand
NOTE:
1. For SSE/SSE2/SSE3 instructions, the first operand is generally a source operand that becomes
the destination operand. Within the Result column, the x87 FPU notation also applies to the
FISTTP instruction in SSE3; the SSE3 notation applies to the SIMD floating-point instructions.