8-11
PROGRAMMING WITH THE INTEL MMX TECHNOLOGY
point tag word as empty. Therefore, it is imperative to use the EMMS instruction at the end of
every MMX routine, if the next routine may contain FPU code.
The EMMS instruction must be used in each of the following cases:
When an application using the floating-point instructions calls an MMX technology
library/DLL. (Use the EMMS instruction at the end of the MMX code.)
When an application using MMX instructions calls a floating-point library/DLL. (Use
the EMMS instruction before calling the floating-point code.)
When a switch is made between MMX code in a task/thread and other tasks/threads in
cooperative operating systems, unless it is certain that more MMX instructions will be
executed before any FPU code.
If the EMMS instruction is not used when trying to execute a floating-point instruction, the
following may occur:
Depending on the exception mask bits of the floating-point control word, a floating- point
exception event may be generated.
A soft exception may occur. In this case floating-point code continues to execute, but
generates incorrect results. This happens when the floating-point exceptions are masked
and no visible exceptions occur. The internal exception handler (microcode, not user
visible) loads a NaN (Not a Number) with an exponent of 11..11B onto the floating-point
stack. The NaN is used for further calculations, yielding incorrect results.
A potential error may occur only if the operating system does NOT manage floating-point
context across task switches. These operating systems are usually cooperative operating
systems. It is imperative that the EMMS instruction execute at the end of all the MMX
routines that may enable a task switch immediately after they end execution (explicit yield
API or implicit yield API).
The EMMS instruction is not returned when mixing MMX technology instructions and
Streaming SIMD Extensions. Refer to Section 9.4., Compatibility with FPU Archi-
tecture in Chapter 9.4., Compatibility with FPU Architecture, of the Intel Architecture
Software Developers Manual, Volume 3, for more detailed information.
8.5.3.Interfacing with MMX Code
The MMX technology enables direct access to all the MMX registers. This means that all
existing interface conventions that apply to the use of the processors general-purpose registers
(EAX, EBX, etc.) also apply to use of MMX register.
An efficient interface to MMX routines might pass parameters and return values through the
MMX registers or through a combination of memory locations (via the stack) and MMX
registers. Such an interface would have to be written in assembly language since passing param-
eters through MMX registers is not currently supported by any existing C compilers. Do not
use the EMMS instruction when the interface to the MMX code has been defined to retain
values in the MMX register.