Intel 253668-032US User Manual

Page of 806
Vol. 3   13-9
SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND 
Execute a LDMXCSR instruction to restore the state of the MXCSR register from 
memory.
13.4 
SAVING THE SSE/SSE2/SSE3/SSSE3/SSE4 STATE ON 
TASK OR CONTEXT SWITCHES
When switching from one task or context to another, it is often necessary to save the 
SSE/SSE2/SSE3/SSSE3/SSE4 state. FXSAVE and FXRSTOR instructions provide a 
simple method for saving and restoring this state. See Section 13.3, “Saving and 
Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 State.”
 These instructions offer the 
added benefit of saving x87 FPU and MMX state as well. 
Guidelines for writing such procedures are in Section 13.5, “Designing OS Facilities 
for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state 
on Task or Context Switches.”
13.5 
DESIGNING OS FACILITIES FOR AUTOMATICALLY 
SAVING X87 FPU, MMX, AND 
SSE/SSE2/SSE3/SSSE3/SSE4 STATE ON TASK OR 
CONTEXT SWITCHES
The x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state consist of the state of the x87 
FPU, MMX, XMM, and MXCSR registers. The FXSAVE and FXRSTOR instructions 
provide a fast method for saving ad restoring this state. If task or context switching 
facilities are already implemented in an operating system or executive and they use 
FSAVE/FNSAVE and FRSTOR to save the x87 FPU and MMX state, these facilities can 
be extended to save and restore SSE/SSE2/SSE3/SSSE3/SSE4 state by substituting 
FXSAVE/FXRSTOR for FSAVE/FNSAVE and FRSTOR. 
Where task or content switching facilities must be written from scratch, several 
approaches can be taken for using the FXSAVE and FXRSTOR instructions to save and 
restore x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state:
The operating system can require applications that are intended be run as tasks 
take responsibility for saving the state of the x87 FPU, MMX, XMM, and MXCSR 
registers prior to a task suspension during a task switch and for restoring the 
registers 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.
The operating system can take the responsibility for automatically saving the x87 
FPU, MMX, XMM, and MXCSR registers as part of the task switch process (using 
an FXSAVE instruction) and automatically restoring the state of the registers