
Chapter 6: x87 Floating-Point Programming
351
24593—Rev. 3.09—September 2003
AMD 64-Bit Technology
6.10
State-Saving
In general, system software should save and restore x87 state
between task switches or other interventions in the execution
of x87 floating-point procedures. Virtually all modern operating
systems running on x86 processors—like Windows NT, UNIX,
and OS/2—are preemptive multitasking operating systems that
handle such saving and restoring of state properly across task
switches, independently of hardware task-switch support.
However, application procedures are also free to save and
restore x87 state at any time they deem useful.
6.10.1
State-Saving
Instructions
FSAVE/FNSAVE and FRSTOR Instructions.
Application software can
save and restore the x87 state by executing the FSAVE (or
FNSAVE) and FRSTOR instructions. Alternatively, software
may use multiple F
x
ST
x
(floating-point store stack top)
instructions for saving only the contents of the x87 data
registers, rather than the complete x87 state.
The FSAVE instruction stores the state, but only after handling
any pending unmasked x87 floating-point exceptions, whereas
the FNSAVE instruction skips the handling of these exceptions.
The state of all x87 data registers is saved, as well as all x87
environment state (the x87 control word register, status word
register, tag word, instruction pointer, data pointer, and last
opcode register). After saving this state, the tag bits for all x87
registers are changed to
empty
and thus available for a new
procedure.
FXSAVE and FXRSTOR Instructions.
Application software can save
and restore the 128-bit media state, 64-bit media state, and x87
floating-point state by executing the FXSAVE and FXRSTOR
instructions. The FXSAVE and FXRSTOR instructions execute
faster than FSAVE/FNSAVE and FRSTOR because they do not
save and restore the x87 pointers (last instruction pointer, last
data pointer, and last opcode, described in “Pointers and
Opcode State” on page 297) except in the relatively rare cases
in which the exception-summary (ES) bit in the x87 status word
(the ES register image for FXSAVE, or the ES memory image
for FXRSTOR) is set to 1, indicating that an unmasked x87
exception has occurred.
Unlike FSAVE and FNSAVE, however, FXSAVE does not alter
the tag bits. The state of the saved x87 data registers is
retained, thus indicating that the registers may still be valid (or