
Chapter 6: x87 Floating-Point Programming
289
24593—Rev. 3.09—September 2003
AMD 64-Bit Technology
stack pointer and then copy the operand (often with conversion
to the double-extended-precision format) from memory into the
decremented top-of-stack register. Instructions that store
operands from an x87 register to memory copy the operand
(often with conversion from the double-extended-precision
format) in the top-of-stack register to memory and then
increment the stack pointer.
Figure 6-2 shows the mapping between stack registers and
physical registers when the TOP has the value 2. Modulo-8
wraparound addressing is used. Pushing a new element onto
this stack—for example with the FLDZ (floating-point load
+0.0) instruction—decrements the TOP to 1, so that ST(0) refers
to FPR1, and the new top-of-stack is loaded with +0.0.
The architecture provides alternative versions of many
instructions that either modify or do not modify the TOP as a
side effect. For example, FADDP (floating-point add and pop)
behaves exactly like FADD (floating-point add), except that it
pops the stack after completion. Programs that use the x87
registers as a flat register file rather than as a stack would use
non-popping versions of instructions to ensure that the TOP
remains unchanged. However, loads (pushes) without
corresponding pops can cause the stack to overflow, which
occurs when a value is pushed or loaded into an x87 register
that is not empty (as indicated by the register’s tag bits). To
prevent overflow, the FXCH (floating-point exchange)
instruction can be used to access stack registers, giving the
appearance of a flat register file, but all x87 programs must be
aware of the register file’s stack organization.
The FINCSTP and FDECSTP instructions can be used to
increment and decrement, respectively, the TOP, modulo-8,
allowing the stack top to wrap around to the bottom of the
eight-register file when incremented beyond the top of the file,
or to wrap around to the top of the register file when
decremented beyond the bottom of the file. Neither the x87 tag
word nor the contents of the floating-point stack itself is
updated when these instructions are used.
6.3.2
x87 Status Word
Register
The 16-bit x87 status word register contains information about
the state of the floating-point unit, including the top-of-stack
pointer (TOP), four condition-code bits, exception-summary
flag, stack-fault flag, and six x87 floating-point exception flags.
Figure 6-3 on page 290 shows the format of this register. All bits