background image

13-6 Vol. 3A

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR EXTENDED STATES

13.1.5.1   Numeric Error flag and IGNNE#

SSE extensions ignore the NE flag in control register CR0 (that is, they treat it as if it were always set) and the 
IGNNE# pin. When an unmasked SIMD floating-point exception is detected, it is always reported by generating a 
SIMD floating-point exception (#XM).

13.2 

EMULATION OF SSE EXTENSIONS 

The Intel 64 and IA-32 architectures do not support emulation of the SSE instructions, as they do for x87 FPU 
instructions.
The EM flag in control register CR0 (provided to invoke emulation of x87 FPU instructions) cannot be used to invoke 
emulation of SSE instructions. If an SSE instruction is executed when CR0.EM = 1, an invalid opcode exception 
(#UD) is generated. See Table 13-1.

13.3 

SAVING AND RESTORING SSE STATE

The SSE state consists of the state of the XMM and MXCSR registers. Intel recommends the following method for 
saving and restoring this state:

Execute the FXSAVE instruction to save the state of the XMM and MXCSR registers to memory.

Execute the FXRSTOR instruction to restore the state of the XMM and MXCSR registers from the image saved in 
memory earlier.

This save and restore method is required for all operating systems. XSAVE feature set can also be used to 
save/restore SSE state. See Section 13.5, “The XSAVE Feature Set and Processor Extended State Management,” 
for using the XSAVE feature set to save/restore SSE state.
In some cases, applications may choose to save only the XMM and MXCSR registers in the following manner:

Execute MOVDQ instructions to save the contents of the XMM registers to memory. 

Execute a STMXCSR instruction to save the state of the MXCSR register to memory.

Such applications must restore the XMM and MXCSR registers as follows:

Execute MOVDQ instructions to load the saved contents of the XMM registers from memory into the XMM 
registers.

Execute a LDMXCSR instruction to restore the state of the MXCSR register from memory.

13.4 

DESIGNING OS FACILITIES FOR SAVING X87 FPU, SSE AND EXTENDED 

STATES ON TASK OR CONTEXT SWITCHES

The x87 FPU and SSE state consist of the state of the x87 FPU, XMM, and MXCSR registers. The FXSAVE and 
FXRSTOR instructions provide a fast method for saving and restoring this state. The XSAVE feature set can also be 
used to save FP and SSE state along with other extended states (see Section 13.5).
Older operating systems may use FSAVE/FNSAVE and FRSTOR to save the x87 FPU state. These facilities can be 
extended to save and restore SSE state by substituting FXSAVE and FXRSTOR or the XSAVE feature set in place of 
FSAVE/FNSAVE and FRSTOR.
If task or context switching facilities are written from scratch, any of several approaches may be taken for using the 
FXSAVE and FXRSTOR instructions or the XSAVE feature set to save and restore x87 FPU and SSE state:

The operating system can require applications that are intended to be run as tasks take responsibility for saving 
the states prior to a task suspension during a task switch and for restoring the states when the task is resumed. 
This approach is appropriate for cooperative multitasking operating systems, where the application has control 
over (or is able to determine) when a task switch is about to occur and can save state prior to the task switch.