8-10
PROGRAMMING WITH THE INTEL MMX TECHNOLOGY
8.5.1.Detecting Support for MMX Technology Using the
CPUID Instruction
Use the CPUID instruction to determine whether the processor supports the MMX instruction
set (refer to Section 3.2., Instruction Reference in Section 3, Instruction Set Reference of
the Intel Architecture Software Developers Manual, Volume 2, for a detailed description of the
CPUID instruction). When the support for MMX technology is detected by the CPUID
instruction, it is signaled by setting bit 23 (MMX technology bit) in the feature flags to 1. In
general, two versions of the routine can be created: one with scalar instructions and one with
MMX instructions. The application will call the appropriate routine depending on the results
of the CPUID instruction. If support for MMX technology is detected, then the MMX
routine is called; if no support for the MMX technology exists, the application calls the scalar
routine.
NOTE
The CPUID instruction will continue to report the existence of the MMX
technology if the CR0.EM bit is set (which signifies that the CPU is
configured to generate exception interrupt 7 that can be used to emulate
floating-point instructions). In this case, executing an MMX instruction
results in an invalid opcode exception.
Example 8-1 illustrates how to use the CPUID instruction. This example does not represent the
entire CPUID sequence, but shows the portion used for detection of MMX technology.
Example 8-1. Partial Routine for Detecting MMX Technology with the CPUID Instruction
; identify existence of CPUID instruction
; identify Intel processor
movEAX, 1; request for feature flags
CPUID; 0Fh, 0A2h CPUID instruction
testEDX, 00800000h; Is IA MMX technology bit (Bit 23 of EDX)
; in feature flags set?
jnzMMX_Technology_Found
8.5.2.Using the EMMS Instruction
When integrating an MMX routine into an application running under an existing operating
system, programmers need to take special precautions, similar to those when writing floating-
point code.
When an MMX instruction executes, the floating-point tag word is marked valid (00s). Subse-
quent floating-point instructions that will be executed may produce unexpected results because
the floating-point stack seems to contain valid data. The EMMS instruction marks the floating-