|
本帖最后由 chiannet 于 2013-6-8 15:12 编辑
应用程序如何检测AVX2
在《Intel® Architecture Instruction Set Extensions Programming Reference》的“2.2.3 Detection of AVX2”中介绍了AVX2指令集的检测方法和汇编伪代码,摘录如下——
Hardware support for AVX2 is indicated by CPUID.(EAX=07H,ECX=0H):EBX.AVX2[bit 5]=1.
Application Software must identify that hardware supports AVX as explained in Section 2.2, after that it must also detect support for AVX2 by checking
CPUID.(EAX=07H, ECX=0H):EBX.AVX2[bit 5]. The recommended pseudocode sequence for detection of AVX2 is:
----------------------------------------------------------------------------------------- INT supports_avx2()
- { ; result in eax
- mov eax, 1
- cpuid
- and ecx, 018000000H
- cmp ecx, 018000000H; check both OSXSAVE and AVX feature flags
- jne not_supported
- ; processor supports AVX instructions and XGETBV is enabled by OS
- mov eax, 7
- mov ecx, 0
- cpuid
- and ebx, 20H
- cmp ebx, 20H; check AVX2 feature flags
- jne not_supported
- mov ecx, 0; specify 0 for XFEATURE_ENABLED_MASK register
- XGETBV; result in EDX:EAX
- and eax, 06H
- cmp eax, 06H; check OS has enabled both XMM and YMM state support
- jne not_supported
- mov eax, 1
- jmp done
- NOT_SUPPORTED:
- mov eax, 0
- done:
- }
复制代码 上面这个代码是intel官方提供的,先检测CPU是否具备AVX2支持能力,还检测了操作系统是否开启用了这个支持,我仅需要检测CPU是否具备AVX2支持就可以了,欲转化为如下delphi 7代码,能通过编译,但不知结果,因为手上木有Haswell 内核的CPU,估计暂时坛子里也没有几个人有此神器,请大家比照看看,代码是否正确。谢谢。
- function IsAVX2Support: Boolean; assembler;
- asm
- cpuid
- mov @Result, True
- and ecx, 018000000H
- cmp ecx, 018000000H // check both OSXSAVE and AVX feature flags
- jbe @not_supported // processor supports AVX instructions and XGETBV is enabled by OS
- mov eax, 7
- mov ecx, 0
- cpuid
- and ebx, 20H
- cmp ebx, 20H // check AVX2 feature flags
- jbe @not_supported
- // mov ecx, 0 // specify 0 for XFEATURE_ENABLED_MASK register
- // XGETBV // result in EDX:EAX
- // and eax, 06H
- // cmp eax, 06H // check OS has enabled both XMM and YMM state support
- // jbe @not_supported
- // mov eax, 1
- jnz @EXIT
- @not_supported:
- mov @Result, False
- @EXIT:
- end;
复制代码 |
|