User Guide
234 64-Bit Media Programming
AMD64 Technology 24592—Rev. 3.15—November 2009
The 64-bit media instructions and x87 floating-point instructions interpret the contents of their aliased
MMX and x87 registers differently. Because of this, software should not exchange register data
between 64-bit media and x87 floating-point procedures, or use conditional branches at t he end of
loops that might jump to code of the other type. Software must not rely on the contents of the aliased
MMX and x87 registers across such code-type transitions. If a transition to an x87 procedure occurs
from a 64-bit media procedure that does not clear the MMX state, the x87 stack may overflow.
5.14 State-Saving
5.14.1 Saving and Restoring State
In general, system software should save and restore MMX™ and x87 state between task switches or
other interventions in the execution of 64-bit media procedures. Virtually all modern operating
systems running on x86 processors implement preemptive multitasking that handle saving and
restoring of state across task switches, independent of hardware task-switch support.
No changes are needed to the x87 register-saving performed by 32-bit operating systems, exception
handlers, or device drivers. The same support provided in a 32-bit operating system’s device-not-
available (#NM) exception handler by any of the x87-register save/restore instructions described
below also supports saving and restoring the MMX registers.
However, application procedures are also free to save and restore MMX and x87 state at any time they
deem useful.
5.14.2 State-Saving Instructions
Software running at any privilege level may save and restore 64-bit media and x87 state by executing
the FSAVE, FNSAVE, or FXSAVE instruction. Alternatively, software may use move instructions for
saving only the contents of the MMX registers, rather than the complete 64-bit media and x87 state.
For example, when saving MMX register values, use eight MOVQ instructions.
FSAVE/FNSAVE and FRSTOR Instructions. The FSAVE, FNSAVE, and FRSTOR instructions are
described in “Save and Restore 64-Bit Media and x87 State” on page 223. After saving state with
FSAVE or FNSAVE, the tag bits for all MMX and x87 registers are changed to empty and thus
available for a new procedure. Thus, FSAVE and FNSAVE also perform the state-clearing function of
EMMS or FEMMS.
FXSAVE and FXRSTOR Instructions. The FSAVE, FNSAVE, and FRSTOR instructions are
described in “Save and Restore 128-Bit, 64-Bit, and x87 State” on page 223. The FXSAVE and
FXRSTOR instructions execute faster than FSAVE/FNSAVE and FRSTOR because they do not save
and restore the x87 error pointers (described in “Pointers and Opcode State” on page 247) except in the
relatively rare cases in which the exception-summary (ES) bit in the x87 status word (register image
for FXSAVE, memory image for FXRSTOR) is set to 1, indicating that an unmasked x87 exception
has occurred.