This preview shows page 1. Sign up to view the full content.
Unformatted text preview: techniques given in Section 10.5., “Saving and Restoring the Streaming SIMD Extensions state”. This approach to saving the SIMD floating-point state 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 SIMD floating-point state as part of the task switch process (using an FXSAVE instruction) and automatically restoring the SIMD floating-point state when a suspended task is resumed (using an FXRSTOR instruction). Here, the SIMD floating-point state must be saved as part of the task state. This approach is appropriate for preemptive multitasking operating systems, where the application cannot know when it is going to be preempted and cannot prepare in advance for task switching. The operating system is responsible for saving and restoring the task and SIMD floating-point state when necessary. The operating system can take the responsibility for saving the SIMD floating-point state as part of the task switch process, but delay the saving of the SIMD floating-point state until a Streaming SIMD Extensions instruction is actually executed by the new task. Using this approach, the SIMD floating-point state is saved only if a Streaming SIMD Extensions instruction needs to be executed in the new task. (See Section 10.6.1., “Using the TS Flag in Control Register CR0 to Control SIMD Floating-Point State Saving”, for more information on this SIMD floating-point state saving technique.) • • 11.6.1. Using the TS Flag in Control Register CR0 to Control SIMD Floating-Point State Saving Saving the SIMD floating-point state using the FXSAVE instruction is not as high-overhead operation as FSAVE. However an operating system may choose to wait to save the SIMD floating-point state to avoid this overhead. If a task being switched to will not access the SIMD floating-point registers (by executing a Streaming SIMD Extensions instruction), this overhead can be avoided by not automatically saving the SIMD floating-point state on a task switch. 11-8 STREAMING SIMD EXTENSIONS SYSTEM PROGRAMMING The TS flag in control register CR0 is provided to allow the operating system to delay saving the SIMD floating-point state until the SIMD floating-point registers are actually accessed in the new task. When this flag is set, the processor monitors the instruction stream for Streaming SIMD Extensions instructions. When the processor detects a Streaming SIMD Extensions instruction, it raises a device-not-available exception (#NM) prior to executing the instruction. The device-not-available exception handler can then be used to save the SIMD floating-point state for the previous task (using an FXSAVE instruction) and load the SIMD floating-point state for the current task (using an FXRSTOR instruction). If the task never encounters a Streaming SIMD Extensions instruction, the device-not-available exception will not be raised and the SIMD floating-point state will not be saved unnecessarily. The TS flag can be set either explicitly (by executing a MOV instruction to control register CR0) or implicitly (using the processor’s native task switching mechanism). When the native task switching mechanism is used, the processor automatically sets the TS flag on a task switch. After the device-not-available handler has saved the SIMD floating-point state, it should execute the CLTS instruction to clear the TS flag in CR0. Figure 10-2 gives an example of an operating system that implements SIMD floating-point state saving using the TS flag. In this example, task A is the currently running task and task B is the task being switched to. Task A Application Operating System Task A SIMD floating-point State Save Area Operating System Task Switching Code Device-Not-Available Exception Handler SIMD floating-point State Owner Task B CR0.TS=1 and extensions instruction is encountered. Task B SIMD floating-point State Save Area Saves Task A SIMD floating-point State Loads Task B SIMD floating-point State Figure 11-2. Example of SIMD Floating-Point State Saving During an Operating SystemControlled Task Switch The operating system maintains a SIMD floating-point save area for each task and defines a variable (SIMD-fpStateOwner) that indicates which task “owns” the SIMD floating-point state. In this example, task A is the current SIMD floating-point state owner. On a task switch, the operating system task switching code must execute the following pseudocode to set the TS flag according to the current SIMD floating-point state owner. If the new task 11-9 STREAMING SIMD EXTENSIONS SYSTEM PROGRAMMING (task B in this example) is not the current SIMD floating-point state owner, the TS flag is set to 1; otherwise, it is set to 0.
IF Task_Being_Switched_To ≠ SIMD-fpStateOwner THEN CR0.TS ← 1; ELSE CR0.TS ← 0; FI; If a new task attempts to use a Streaming SIMD Extensions instruct...
View Full Document
This note was uploaded on 06/07/2013 for the course ECE 1234 taught by Professor Kwhon during the Spring '10 term at University of California, Berkeley.
- Spring '10