Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture
Vol. 1 9-13
PROGRAMMING WITH INTEL® MMX™ TECHNOLOGY
• When an application using MMX instructions calls a x87 FPU floating-point
library/DLL (use the EMMS instruction before calling the x87 FPU code).
• When a switch is made between MMX code in a task or thread and other tasks or
threads in cooperative operating systems, unless it is certain that more MMX
instructions will be executed before any x87 FPU code.
EMMS is not required when mixing MMX technology instructions with
SSE/SSE2/SSE3 instructions (see Section 11.6.7, “Interaction of SSE/SSE2 Instruc-
tions with x87 FPU and MMX Instructions”).
9.6.4 Mixing MMX and x87 FPU Instructions
An application can contain both x87 FPU floating-point and MMX instructions.
However, frequent transitions between MMX and x87 FPU instructions are not recom-
mended, because they can degrade performance in some processor implementa-
tions. When mixing MMX code with x87 FPU code, follow these guidelines:
• Keep the code in separate modules, procedures, or routines.
• Do not rely on register contents across transitions between x87 FPU and MMX
code modules.
• When transitioning between MMX code and x87 FPU code, save the MMX register
state (if it will be needed in the future) and execute an EMMS instruction to empty
the MMX state.
• When transitioning between x87 FPU code and MMX code, save the x87 FPU state
if it will be needed in the future.
9.6.5 Interfacing with MMX Code
MMX technology enables direct access to all the MMX registers. This means that all
existing interface conventions that apply to the use of the processor’s general-
purpose registers (EAX, EBX, etc.) also apply to the use of MMX registers.
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. Do not use the EMMS instruction or mix MMX and x87 FPU
code when using to the MMX registers to pass parameters.
If a high-level language that does not support the MMX data types directly is used,
the MMX data types can be defined as a 64-bit structure containing packed data
types.
When implementing MMX instructions in high-level languages, other approaches can
be taken, such as:
• Passing parameters to an MMX routine by passing a pointer to a structure via the
stack.
• Returning a value from a function by returning a pointer to a structure.