User Guide

x87 Floating-Point Programming 275
24592—Rev. 3.15—November 2009 AMD64 Technology
Assemblers issue FSTCW as an FWAIT instruction followed by an FNSTCW instruction. Thus,
FSTCW (but not FNSTCW) reports pending unmasked x87 floating-point exceptions before storing
the control word.
The FSTCW instruction should be used when pending x87 floating-point exceptions are being
reported (unmasked). The no-wait instruction, FNSTCW, should be used when pending x87 floating-
point exceptions are not being reported (masked).
Save x87 Status Word
FSTSW—Floating-Point Store Status Word
FNSTSW—Floating-Point No-Wait Store Status Word
These instructions store the x87 status word either at a specified 2-byte memory location or in the AX
register. The second form, FxSTSW AX, is used in older code to copy condition codes through the AX
register to the r FLAGS register, where they can be used for conditional branching using general-
purpose instructions. However, the combination of FCOMI and FCMOVcc provides a faster method of
conditional branching.
Assemblers issue FSTSW as an FWAIT instruction followed by an FNSTSW instruction. Thus,
FSTSW (but not FNSTSW) reports pending unmasked x87 floating-point exceptions before storing
the status word.
The FSTSW instruction should be used when pending x87 floating-point exceptions are being
reported (unmasked). The no-wait instruction, FNSTSW, should be used when pending x87 floating-
point exceptions are not being reported (masked).
Save and Restore x87 Environment
FLDENV—Floating-Point Load x87 Environment
FNSTENV—Floating-Point No-Wait Store Environment
FSTENV—Floating-Point Store Environment
These instructions load or store the entire x87 environment (non-data processor state) as a 14-byte or
28-byte block, depending on effective operand size, from or to memory.
When executing FLDENV, any exception flags are set in the new status word, and these exceptions are
unmasked in the control word, a floating-point exception occurs when the next non-control x87 or 64-
bit media instruction is executed.
Assemblers issue FSTENV as an FWAIT instruction followed by an FNSTENV instruction. Thus,
FSTENV (but not FNSTENV) reports pending unmasked x87 floating-point exceptions before storing
the status word.
The x87 environment includes the x87 control word register, x87 status word register, x87 tag word,
last x87 instruction pointer, last x87 data pointer, and last x87 opcode. See “Media and x87 Processor
State” in Volume 2 for details on how the x87 environment is stored in memory.