Unformatted text preview: 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). 9-12 Vol. 1 PROGRAMMING WITH INTEL MMXTM 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 generalpurpose registers (EAX, EBX, etc.)...
View Full Document
- Winter '11
- X86, Intel corporation, 64-bit mode, fpu floating-point exception, FPU Control Instructions