# Intrinsics for Saving and Restoring the Extended Processor States

To use any of these intrinsics, include the immintrin.h file as follows:

    #include <immintrin.h>

## Intrinsics that map to FXSAVE[64] and FXRSTOR[64] instructions

This group of intrinsics includes four intrinsics to save and restore the current state of the x87 FPU, MMX, XMM, and MXCSR registers.

These intrinsics accept a memory reference to a 16-byte aligned 512-byte memory chunk. The layout of the memory is shown below in Table 1.

Table 1 - `FXSAVE` save area layout.

## Intrinsics that map to XSAVE[64], XSAVEOPT[64], and XRSTOR[64] instructions

This group of intrinsics includes six intrinsics to fully or partially save and restore the current state of the x87 FPU, MMX, XMM, YMM, and MXCSR registers.

These intrinsics accept a memory reference to a 64-byte aligned memory. The layout of the register fields for the first 512 bytes is the same as the `FXSAVE` save area layout. The intrinsics saving the states do not write to bytes 464:511. The save area layout is shown in Tables 2a and 2b below.

The second operand is a save/restore mask specifying the saved/restored extended states. The value of the mask is `AND`ed with `XFEATURE_ENABLED_MASK(XCR0)`. A particular extended state is saved/restored only if the corresponding bit of both save/restore mask and `XFEATURE_ENABLED_MASK` is set to '1'.

Table 2a - `XSAVE` save area layout (first 512 bytes)

Table 2b - `XSAVE` save area layout for YMM registers

Parent topic: Intrinsics for Managing Extended Processor States and Registers

- _fxsave()
  Saves the states of x87 FPU, MMX, XMM, and MXCSR registers to memory.
- _fxsave64()
  Saves the states of x87 FPU, MMX, XMM, and MXCSR registers to memory.
- _fxrstor()
  Restores the states of x87 FPU, MMX, XMM, and MXCSR registers from memory.
- _fxrstor64()
  Restores the states of x87 FPU, MMX, XMM, and MXCSR registers from memory.
- _xsave()/_xsavec()/_xsaves()
  Saves the states of x87 FPU, MMX, XMM, YMM, and MXCSR registers to memory.
- _xsave64()/ _xsavec64()/ _xsaves64()
  Saves the states of x87 FPU, MMX, XMM, YMM, and MXCSR registers to memory.
- _xsaveopt()
  Saves the states of x87 FPU, MMX, XMM, YMM, and MXCSR registers to memory, optimizing the save operation if possible.
- _xsaveopt64()
  Saves the states of x87 FPU, MMX, XMM, YMM, and MXCSR registers to memory, optimizing the save operation if possible.
- _xrstor()/xrstors()
  Restores the states of x87 FPU, MMX, XMM, YMM, and MXCSR registers from memory.
- _xrstor64()/xrstors64()
  Restores the states of x87 FPU, MMX, XMM, YMM, and MXCSR registers from memory.