background image

9-10 Vol. 1

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 Instructions 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 recommended, because they can degrade performance in some 
processor implementations. 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.

9.6.6 

Using MMX Code in a Multitasking Operating System Environment

An application needs to identify the nature of the multitasking operating system on which it runs. Each task retains 
its own state which must be saved when a task switch occurs. The processor state (context) consists of the 
general-purpose registers and the floating-point and MMX registers.
Operating systems can be classified into two types:

Cooperative multitasking operating system

Preemptive multitasking operating system

Cooperative multitasking operating systems do not save the FPU or MMX state when performing a context switch. 
Therefore, the application needs to save the relevant state before relinquishing direct or indirect control to the 
operating system.
Preemptive multitasking operating systems are responsible for saving and restoring the FPU and MMX state when 
performing a context switch. Therefore, the application does not have to save or restore the FPU and MMX state.