Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture

Vol. 1 D-13
GUIDELINES FOR WRITING X87 FPU EXCEPTION HANDLERS
is masked (the corresponding mask bit in the control word = 1), the processor takes
an appropriate default action and continues with the computation.
The processor has a default fix-up activity for every possible exception condition it
may encounter. These masked-exception responses are designed to be safe and are
generally acceptable for most numeric applications.
For example, if the Inexact result (Precision) exception is masked, the system can
specify whether the x87 FPU should handle a result that cannot be represented
exactly by one of four modes of rounding: rounding it normally, chopping it toward
zero, always rounding it up, or always down. If the Underflow exception is masked,
the x87 FPU will store a number that is too small to be represented in normalized
form as a denormal (or zero if it’s smaller than the smallest denormal). Note that
when exceptions are masked, the x87 FPU may detect multiple exceptions in a single
instruction, because it continues executing the instruction after performing its
masked response. For example, the x87 FPU could detect a denormalized operand,
perform its masked response to this exception, and then detect an underflow.
As an example of how even severe exceptions can be handled safely and automati-
cally using the default exception responses, consider a calculation of the parallel
resistance of several values using only the standard formula (see Figure D-4). If R1
becomes zero, the circuit resistance becomes zero. With the divide-by-zero and
precision exceptions masked, the processor will produce the correct result. FDIV of
R1 into 1 gives infinity, and then FDIV of (infinity +R2 +R3) into 1 gives zero.
By masking or unmasking specific numeric exceptions in the x87 FPU control word,
programmers can delegate responsibility for most exceptions to the processor,
reserving the most severe exceptions for programmed exception handlers. Excep-
tion-handling software is often difficult to write, and the masked responses have
been tailored to deliver the most reasonable result for each condition. For the
majority of applications, masking all exceptions yields satisfactory results with the
Figure D-4. Arithmetic Example Using Infinity
Equivalent Resistance =
1
1
R
1
+
+
R
1
1
R
2
1
R
3
R
2
R
3