Guidelines for using emms instruction, Guidelines for using emms instruction -4 – Intel ARCHITECTURE IA-32 User Manual

Page 224

Advertising
background image

IA-32 Intel® Architecture Optimization

4-4

Using

emms

clears all of the valid bits, effectively emptying the x87

floating-point stack and making it ready for new x87 floating-point
operations. The

emms

instruction ensures a clean transition between

using operations on the MMX registers and using operations on the x87
floating-point stack. On the Pentium 4 processor, there is a finite
overhead for using the

emms

instruction.

Failure to use the

emms

instruction (or the

_mm_empty()

intrinsic)

between operations on the MMX registers and operations on the x87
floating-point registers may lead to unexpected results.

Guidelines for Using EMMS Instruction

When developing code with both x87 floating-point and 64-bit SIMD
integer instructions, follow these steps:

1.

Always call the

emms

instruction at the end of 64-bit SIMD integer

code when the code transitions to x87 floating-point code.

2.

Insert the

emms

instruction at the end of all 64-bit SIMD integer

code segments to avoid an x87 floating-point stack overflow
exception when an x87 floating-point instruction is executed.

When writing an application that uses both floating-point and 64-bit
SIMD integer instructions, use the following guidelines to help you
determine when to use

emms

:

If next instruction is x87 FP: Use

_mm_empty()

after a 64-bit SIMD

integer instruction if the next instruction is an

x87 FP

instruction;

for example, before doing calculations on floats, doubles or long
doubles.

CAUTION.

Failure to reset the tag word for FP

instructions after using an MMX instruction can result
in faulty execution or poor performance.

Advertising