Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture
Vol. 1 8-33
PROGRAMMING WITH THE X87 FPU
control and status words, respectively, in memory (or for an FSTSW/FNSTSW
instruction in a general-purpose register).
The FSTENV/FNSTENV and FSAVE/FNSAVE instructions save the x87 FPU environ-
ment and state, respectively, in memory. The x87 FPU environment includes all the
x87 FPU’s control and status registers; the x87 FPU state includes the x87 FPU envi-
ronment and the data registers in the x87 FPU register stack. (The FSAVE/FNSAVE
instruction also initializes the x87 FPU to default values, like the FINIT/FNINIT
instruction, after it saves the original state of the x87 FPU.)
The FLDENV and FRSTOR instructions load the x87 FPU environment and state,
respectively, from memory into the x87 FPU. These instructions are commonly used
when switching tasks or contexts.
The WAIT/FWAIT instructions are synchronization instructions. (They are actually
mnemonics for the same opcode.) These instructions check the x87 FPU status word
for pending unmasked x87 FPU exceptions. If any pending unmasked x87 FPU excep-
tions are found, they are handled before the processor resumes execution of the
instructions (integer, floating-point, or system instruction) in the instruction stream.
The WAIT/FWAIT instructions are provided to allow synchronization of instruction
execution between the x87 FPU and the processor’s integer unit. See Section 8.6,
“x87 FPU Exception Synchronization,” for more information on the use of the
WAIT/FWAIT instructions.
8.3.12 Waiting vs. Non-waiting Instructions
All of the x87 FPU instructions except a few special control instructions perform a wait
operation (similar to the WAIT/FWAIT instructions), to check for and handle pending
unmasked x87 FPU floating-point exceptions, before they perform their primary
operation (such as adding two floating-point numbers). These instructions are called
waiting instructions. Some of the x87 FPU control instructions, such as
FSTSW/FNSTSW, have both a waiting and a non-waiting version. The waiting version
(with the “F” prefix) executes a wait operation before it performs its primary opera-
tion; whereas, the non-waiting version (with the “FN” prefix) ignores pending
unmasked exceptions.
Non-waiting instructions allow software to save the current x87 FPU state without
first handling pending exceptions or to reset or reinitialize the x87 FPU without
regard for pending exceptions.
NOTES
When operating a Pentium or Intel486 processor in MS-DOS compat-
ibility mode, it is possible (under unusual circumstances) for a non-
waiting instruction to be interrupted prior to being executed to
handle a pending x87 FPU exception. The circumstances where this
can happen and the resulting action of the processor are described in