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

Vol. 1 8-13
PROGRAMMING WITH THE X87 FPU
.
Each tag in the x87 FPU tag word corresponds to a physical register (numbers 0
through 7). The current top-of-stack (TOP) pointer stored in the x87 FPU status word
can be used to associate tags with registers relative to ST(0).
The x87 FPU uses the tag values to detect stack overflow and underflow conditions
(see Section 8.5.1.1, “Stack Overflow or Underflow Exception (#IS)”).
Application programs and exception handlers can use this tag information to check
the contents of an x87 FPU data register without performing complex decoding of the
actual data in the register. To read the tag register, it must be stored in memory using
either the FSTENV/FNSTENV or FSAVE/FNSAVE instructions. The location of the tag
word in memory after being saved with one of these instructions is shown in Figures
8-9 through 8-12.
Software cannot directly load or modify the tags in the tag register. The FLDENV and
FRSTOR instructions load an image of the tag register into the x87 FPU; however,
the x87 FPU uses those tag values only to determine if the data registers are empty
(11B) or non-empty (00B, 01B, or 10B).
If the tag register image indicates that a data register is empty, the tag in the tag
register for that data register is marked empty (11B); if the tag register image indi-
cates that the data register is non-empty, the x87 FPU reads the actual value in the
data register and sets the tag for the register accordingly. This action prevents a
program from setting the values in the tag register to incorrectly represent the actual
contents of non-empty data registers.
8.1.8 x87 FPU Instruction and Data (Operand) Pointers
The x87 FPU stores pointers to the instruction and data (operand) for the last non-
control instruction executed. These pointers are stored in two 48-bit registers: the
x87 FPU instruction pointer and x87 FPU operand (data) pointer registers (see
Figure 8-1). (These pointers are saved to provide state information for exception
handlers.)
Figure 8-7. x87 FPU Tag Word
015
TAG Values
TAG(7) TAG(5)TAG(6) TAG(4) TAG(3) TAG(2) TAG(1) TAG(0)
00 — Valid
01 — Zero
10 — Special: invalid (NaN, unsupported), infinity, or denormal
11 Empty