background image

Vol. 1 4-23

DATA TYPES

4.9.2 

Floating-Point Exception Priority

The processor handles exceptions according to a predetermined precedence. When an instruction generates two or 
more exception conditions, the exception precedence sometimes results in the higher-priority exception being 
handled and the lower-priority exceptions being ignored. For example, dividing an SNaN by zero can potentially 
signal an invalid-operation exception (due to the SNaN operand) and a divide-by-zero exception. Here, if both 
exceptions are masked, the processor handles the higher-priority exception only (the invalid-operation exception), 
returning a QNaN to the destination. Alternately, a denormal-operand or inexact-result exception can accompany 
a numeric underflow or overflow exception with both exceptions being handled.
The precedence for floating-point exceptions is as follows:
1. Invalid-operation exception, subdivided as follows:

a. stack underflow (occurs with x87 FPU only)
b. stack overflow (occurs with x87 FPU only)
c. operand of unsupported format (occurs with x87 FPU only when using the double extended-precision 

floating-point format)

d. SNaN operand

2. QNaN operand. Though this is not an exception, the handling of a QNaN operand has precedence over lower-

priority exceptions. For example, a QNaN divided by zero results in a QNaN, not a zero-divide exception.

3. Any other invalid-operation exception not mentioned above or a divide-by-zero exception.
4. Denormal-operand exception. If masked, then instruction execution continues and a lower-priority exception 

can occur as well.

5. Numeric overflow and underflow exceptions; possibly in conjunction with the inexact-result exception.
6. Inexact-result exception.
Invalid operation, zero divide, and denormal operand exceptions are detected before a floating-point operation 
begins. Overflow, underflow, and precision exceptions are not detected until a true result has been computed. 
When an unmasked pre-operation exception is detected, the destination operand has not yet been updated, and 
appears as if the offending instruction has not been executed. When an unmasked post-operation exception is 
detected, the destination operand may be updated with a result, depending on the nature of the exception (except 
for SSE/SSE2/SSE3 instructions, which do not update their destination operands in such cases).

4.9.3 

Typical Actions of a Floating-Point Exception Handler

After the floating-point exception handler is invoked, the processor handles the exception in the same manner that 
it handles non-floating-point exceptions. The floating-point exception handler is normally part of the operating 
system or executive software, and it usually invokes a user-registered floating-point exception handle. 
A typical action of the exception handler is to store state information in memory. Other typical exception handler 
actions include:

•

Examining the stored state information to determine the nature of the error

•

Taking actions to correct the condition that caused the error

•

Clearing the exception flags

•

Returning to the interrupted program and resuming normal execution

In lieu of writing recovery procedures, the exception handler can do the following:

•

Increment in software an exception counter for later display or printing

•

Print or display diagnostic information (such as the state information)

•

Halt further program execution