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

Vol. 1 8-41
PROGRAMMING WITH THE X87 FPU
The action that the x87 FPU takes when numeric overflow occurs and the numeric-
overflow exception is not masked, depends on whether the instruction is supposed to
store the result in memory or on the register stack.
Destination is a memory location — The OE flag is set and a software
exception handler is invoked (see Section 8.7, “Handling x87 FPU Exceptions in
Software”). The top-of-stack pointer (TOP) and source and destination operands
remain unchanged. Because the data in the stack is in double extended-precision
format, the exception handler has the option either of re-executing the store
instruction after proper adjustment of the operand or of rounding the significand
on the stack to the destination's precision as the standard requires. The
exception handler should ultimately store a value into the destination location in
memory if the program is to continue.
Destination is the register stack — The significand of the result is rounded
according to current settings of the precision and rounding control bits in the x87
FPU control word and the exponent of the result is adjusted by dividing it by
2
24576
. (For instructions not affected by the precision field, the significand is
rounded to double-extended precision.) The resulting value is stored in the
destination operand. Condition code bit C1 in the x87 FPU status word (called in
this situation the “round-up bit”) is set if the significand was rounded upward and
cleared if the result was rounded toward 0. After the result is stored, the OE flag
is set and a software exception handler is invoked. The scaling bias value 24,576
is equal to 3 2
13
. Biasing the exponent by 24,576 normally translates the
number as nearly as possible to the middle of the double extended-precision
floating-point exponent range so that, if desired, it can be used in subsequent
scaled operations with less risk of causing further exceptions.
When using the FSCALE instruction, massive overflow can occur, where the
result is too large to be represented, even with a bias-adjusted exponent. Here,
if overflow occurs again, after the result has been biased, a properly signed is
stored in the destination operand.
8.5.5 Numeric Underflow Exception (#U)
The x87 FPU detects a floating-point numeric underflow condition whenever the
rounded result of an arithmetic instruction is tiny; that is, less than the smallest
possible normalized, finite value that will fit into the floating-point format of the
destination operand. (See Section 4.9.1.5, “Numeric Underflow Exception (#U),” for
additional information about the numeric underflow exception.)
Like numeric overflow, numeric underflow can occur on arithmetic operations where
the result is stored in an x87 FPU data register. It can also occur on store floating-
point operations (with the FST and FSTP instructions), where a within-range value in
a data register is stored in memory in the smaller single-precision or double-preci-
sion floating-point formats. A numeric underflow exception cannot occur when
storing values in an integer or BCD integer format, because a tiny value is always
rounded to an integral value of 0 or 1, depending on the rounding mode in effect.