
222
Chapter 4: 128-Bit Media and Scientific Programming
AMD 64-Bit Technology
24593—Rev. 3.09—September 2003
of the invalid-operation exception (IE), software can use
signaling NaNs to invoke an exception handler. Within the
constraints imposed by the encoding of SNaNs and QNaNs,
software may freely assign the bits in the significand of a NaN.
See “Not a Number (NaN)” on page 155 for format details.
For example, software can pre-load each element of an array
with a signaling NaN that encodes the array index. When an
application accesses an uninitialized array element, the invalid-
operation exception is invoked and the service routine can
identify that element. A service routine can store debug
information in memory as the exceptions occur. The routine can
create a QNaN that references its associated debug area in
memory. As the program runs, the service routine can create a
different QNaN for each error condition, so that a single test-
run can identify a collection of errors.
4.11
Saving, Clearing, and Passing State
4.11.1
Saving and
Restoring State
In general, system software should save and restore 128-bit
media state between task switches or other interventions in the
execution of 128-bit media procedures. Virtually all modern
operating systems running on x86 processors—like
Windows NT, UNIX, and OS/2—are preemptive multitasking
operating systems that handle such saving and restoring of
state properly across task switches, independently of hardware
task-switch support. However, application procedures are also
free to save and restore 128-bit media state at any time they
deem useful.
Software running at any privilege level may save and restore
128-bit media state by executing the FXSAVE instruction,
which saves not only 128-bit media state but also x87 floating-
point state. Alternatively, software may use multiple move
instructions for saving only the contents of selected 128-bit
media data registers, or the STMXCSR instruction for saving
the MXCSR register state. For details, see “Save and Restore
State” on page 186.
4.11.2
Parameter
Passing
128-bit media procedures can use MOV
x
instructions to pass
data to other such procedures. This can be done directly, via the
XMM registers, or indirectly by storing data on the procedure
stack. When storing to the stack, software should use the rSP
register for the memory address and, after the save, explicitly