
Chapter 5: 64-Bit Media Programming
279
24593—Rev. 3.09—September 2003
AMD 64-Bit Technology
procedure—or a 128-bit media procedure that accesses an
MMX register—to an x87 procedure, or to software that may
eventually branch to an x87 procedure, software should clear
the MMX state, as described immediately below.
5.13.2
Clearing MMX
State
Software should separate 64-bit media procedures, 128-bit
media procedures, or dynamic link libraries (DLLs) that access
MMX registers from x87 floating-point procedures or DLLs by
clearing the MMX state with the EMMS or FEMMS instruction
before leaving a 64-bit media procedure, as described in “Exit
Media State” on page 247.
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 the 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—including such
systems as 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.
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.