2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ランタイム時にSSEのサポート情報を確認しとく

Last updated at Posted at 2015-06-29
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

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?