Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture
9-12 Vol. 1
PROGRAMMING WITH INTEL® MMX™ TECHNOLOGY
9.6.2 Transitions Between x87 FPU and MMX Code
Applications can contain both x87 FPU floating-point and MMX instructions. However,
because the MMX registers are aliased to the x87 FPU register stack, care must be
taken when making transitions between x87 FPU instructions and MMX instructions
to prevent incoherent or unexpected results.
When an MMX instruction (other than the EMMS instruction) is executed, the
processor changes the x87 FPU state as follows:
• The TOS (top of stack) value of the x87 FPU status word is set to 0.
• The entire x87 FPU tag word is set to the valid state (00B in all tag fields).
• When an MMX instruction writes to an MMX register, it writes ones (11B) to the
exponent part of the corresponding floating-point register (bits 64 through 79).
The net result of these actions is that any x87 FPU state prior to the execution of the
MMX instruction is essentially lost.
When an x87 FPU instruction is executed, the processor assumes that the current
state of the x87 FPU register stack and control registers is valid and executes the
instruction without any preparatory modifications to the x87 FPU state.
If the application contains both x87 FPU floating-point and MMX instructions, the
following guidelines are recommended:
• When transitioning between x87 FPU and MMX code, save the state of any x87
FPU data or control registers that need to be preserved for future use. The FSAVE
and FXSAVE instructions save the entire x87 FPU state.
• When transitioning between MMX and x87 FPU code, do the following:
— Save any data in the MMX registers that needs to be preserved for future use.
FSAVE and FXSAVE also save the state of MMX registers.
— Execute the EMMS instruction to clear the MMX state from the x87 data and
control registers.
The following sections describe the use of the EMMS instruction and give additional
guidelines for mixing x87 FPU and MMX code.
9.6.3 Using the EMMS Instruction
As described in Section 9.6.2, “Transitions Between x87 FPU and MMX Code,” when
an MMX instruction executes, the x87 FPU tag word is marked valid (00B). In this
state, the execution of subsequent x87 FPU instructions may produce unexpected
x87 FPU floating-point exceptions and/or incorrect results because the x87 FPU
register stack appears to contain valid data. The EMMS instruction is provided to
prevent this problem by marking the x87 FPU tag word as empty.
The EMMS instruction should be used in each of the following cases:
• When an application using the x87 FPU instructions calls an MMX technology
library/DLL (use the EMMS instruction at the end of the MMX code).