background image

Vol. 1 8-31

PROGRAMMING WITH THE X87 FPU

When using the FSCALE instruction, massive underflow can occur, where the magnitude of the result is too 
small to be represented, even with a bias-adjusted exponent. Here, if underflow occurs again after the result 
has been biased, a properly signed 0 is stored in the destination operand.

8.5.6 

Inexact-Result (Precision) Exception (#P)

The inexact-result exception (also called the precision exception) occurs if the result of an operation is not exactly 
representable in the destination format. (See Section 4.9.1.6, “Inexact-Result (Precision) Exception (#P),” for 
additional information about the numeric overflow exception.) Note that the transcendental instructions (FSIN, 
FCOS, FSINCOS, FPTAN, FPATAN, F2XM1, FYL2X, and FYL2XP1) by nature produce inexact results.
The inexact-result exception flag (PE) is bit 5 of the x87 FPU status word, and the mask bit (PM) is bit 5 of the x87 
FPU control word. 
If the inexact-result exception is masked when an inexact-result condition occurs and a numeric overflow or under-
flow condition has not occurred, the x87 FPU handles the exception as describe in Section 4.9.1.6, “Inexact-Result 
(Precision) Exception (#P),”
 with one additional action. The C1 (round-up) bit in the x87 FPU status word is set to 
indicate whether the inexact result was rounded up (C1 is set) or “not rounded up” (C1 is cleared). In the “not 
rounded up” case, the least-significant bits of the inexact result are truncated so that the result fits in the destina-
tion format.
If the inexact-result exception is not masked when an inexact result occurs and numeric overflow or underflow has 
not occurred, the x87 FPU handles the exception as described in the previous paragraph and, in addition, invokes 
a software exception handler.
If an inexact result occurs in conjunction with numeric overflow or underflow, the x87 FPU carries out one of the 
following operations:

If an inexact result occurs in conjunction with masked overflow or underflow, the OE or UE flag and the PE flag 
are set and the result is stored as described for the overflow or underflow exceptions (see Section 8.5.4, 
“Numeric Overflow Exception (#O),” or S
ection 8.5.5, “Numeric Underflow Exception (#U)”). If the inexact 
result exception is unmasked, the x87 FPU also invokes a software exception handler.

If an inexact result occurs in conjunction with unmasked overflow or underflow and the destination operand is 
a register, the OE or UE flag and the PE flag are set, the result is stored as described for the overflow or 
underflow exceptions (see Section 8.5.4, “Numeric Overflow Exception (#O),” or Section 8.5.5, “Numeric 
Underflow Exception (#U)”) 
and a software exception handler is invoked.

If an unmasked numeric overflow or underflow exception occurs and the destination operand is a memory location 
(which can happen only for a floating-point store), the inexact-result condition is not reported and the C1 flag is 
cleared.

8.6 

X87 FPU EXCEPTION SYNCHRONIZATION

Because the integer unit and x87 FPU are separate execution units, it is possible for the processor to execute 
floating-point, integer, and system instructions concurrently. No special programming techniques are required to 
gain the advantages of concurrent execution. (Floating-point instructions are placed in the instruction stream 
along with the integer and system instructions.) However, concurrent execution can cause problems for floating-
point exception handlers. 
This problem is related to the way the x87 FPU signals the existence of unmasked floating-point exceptions. 
(Special exception synchronization is not required for masked floating-point exceptions, because the x87 FPU 
always returns a masked result to the destination operand.) 
When a floating-point exception is unmasked and the exception condition occurs, the x87 FPU stops further execu-
tion of the floating-point instruction and signals the exception event. On the next occurrence of a floating-point 
instruction or a WAIT/FWAIT instruction in the instruction stream, the processor checks the ES flag in the x87 FPU 
status word for pending floating-point exceptions. If floating-point exceptions are pending, the x87 FPU makes an 
implicit call (traps) to the floating-point software exception handler. The exception handler can then execute 
recovery procedures for selected or all floating-point exceptions.