main.cpp
#include <stdio.h>
#include <string.h>
#if defined(_MSC_VER)
#include <intrin.h>
#define CALL_CPUID( dst, paramID ) __cpuidex( dst, paramID, 0 )
#else
#define CALL_CPUID( dst, paramID ) XXX::cpuid( dst, paramID )
namespace XXX
{
void cpuid( int dst[4], int paramID )
{
__asm__ __volatile__
(
"cpuid"
: "=a" (dst[0]), "=b" (dst[1]), "=c" (dst[2]), "=d" (dst[3])
: "a" (paramID), "c" (0)
);
}
}
#endif
int main()
{
int cpuInfo[4];
CALL_CPUID( cpuInfo, 0 );
const int highestValidInfoID = cpuInfo[0];
int info1_ECX = 0;
int info1_EDX = 0;
int info7_EBX = 0;
if( highestValidInfoID >= 1 )
{
CALL_CPUID( cpuInfo, 1 );
info1_ECX = cpuInfo[2];
info1_EDX = cpuInfo[3];
}
if( highestValidInfoID >= 7 )
{
CALL_CPUID( cpuInfo, 7 );
info7_EBX = cpuInfo[1];
}
if( (info1_EDX & (1 << 25)) != 0 ) printf( "SSE supported\n" );
if( (info1_EDX & (1 << 26)) != 0 ) printf( "SSE2 supported\n" );
if( (info1_ECX & (1 << 0)) != 0 ) printf( "SSE3 supported\n" );
if( (info1_ECX & (1 << 19)) != 0 ) printf( "SSE41 supported\n" );
if( (info1_ECX & (1 << 20)) != 0 ) printf( "SSE42 supported\n" );
if( (info1_ECX & (1 << 28)) != 0 ) printf( "AVX supported\n" );
if( (info7_EBX & (1 << 5)) != 0 ) printf( "AVX2 supported\n" );
}
参照:
https://msdn.microsoft.com/ja-jp/library/vstudio/hskdteyh%28v=vs.120%29.aspx
http://www.intel.co.jp/content/dam/www/public/ijkk/jp/ja/documents/developer/Processor_Identification_071405_i.pdf