03.03.2013 Views

Intel® Architecture Instruction Set Extensions Programming Reference

Intel® Architecture Instruction Set Extensions Programming Reference

Intel® Architecture Instruction Set Extensions Programming Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

APPLICATION PROGRAMMING MODEL<br />

Prior to using AVX, the application must identify that the operating system supports the XGETBV instruction, the<br />

YMM register state, in addition to processor’s support for YMM state management using XSAVE/XRSTOR and AVX<br />

instructions. The following simplified sequence accomplishes both and is strongly recommended.<br />

1) Detect CPUID.1:ECX.OSXSAVE[bit 27] = 1 (XGETBV enabled for application use 1 )<br />

2) Issue XGETBV and verify that XFEATURE_ENABLED_MASK[2:1] = ‘11b’ (XMM state and YMM state are enabled<br />

by OS).<br />

3) detect CPUID.1:ECX.AVX[bit 28] = 1 (AVX instructions supported).<br />

(Step 3 can be done in any order relative to 1 and 2)<br />

The following pseudocode illustrates this recommended application AVX detection process:<br />

----------------------------------------------------------------------------------------<br />

INT supports_AVX()<br />

{ ; result in eax<br />

mov eax, 1<br />

cpuid<br />

and ecx, 018000000H<br />

cmp ecx, 018000000H; check both OSXSAVE and AVX feature flags<br />

jne not_supported<br />

; processor supports AVX instructions and XGETBV is enabled by OS<br />

mov ecx, 0; specify 0 for XFEATURE_ENABLED_MASK register<br />

XGETBV; result in EDX:EAX<br />

and eax, 06H<br />

cmp eax, 06H; check OS has enabled both XMM and YMM state support<br />

jne not_supported<br />

mov eax, 1<br />

jmp done<br />

NOT_SUPPORTED:<br />

mov eax, 0<br />

done:<br />

}<br />

-------------------------------------------------------------------------------<br />

Note: It is unwise for an application to rely exclusively on CPUID.1:ECX.AVX[bit 28] or at all on<br />

CPUID.1:ECX.XSAVE[bit 26]: These indicate hardware support but not operating system support. If YMM state<br />

management is not enabled by an operating systems, AVX instructions will #UD regardless of<br />

CPUID.1:ECX.AVX[bit 28]. “CPUID.1:ECX.XSAVE[bit 26] = 1” does not guarantee the OS actually uses the XSAVE<br />

process for state management.<br />

These steps above also apply to enhanced 128-bit SIMD floating-pointing instructions in AVX (using VEX prefixencoding)<br />

that operate on the YMM states. Application detection of VEX-encoded AES is described in Section 2.2.2.<br />

2.2.1 Detection of FMA<br />

Hardware support for FMA is indicated by CPUID.1:ECX.FMA[bit 12]=1.<br />

1. If CPUID.01H:ECX.OSXSAVE reports 1, it also indirectly implies the processor supports XSAVE, XRSTOR, XGETBV, processor<br />

extended state bit vector XFEATURE_ENALBED_MASK register. Thus an application may streamline the checking of CPUID feature<br />

flags for XSAVE and OSXSAVE. XSETBV is a privileged instruction.<br />

2-2 Ref. # 319433-014

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!