All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
instrset.h File Reference
#include <stdlib.h>
Include dependency graph for instrset.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Const_int_t< n >
 
class  Const_uint_t< n >
 
class  Static_error_check< bool >
 
class  Static_error_check< false >
 

Macros

#define INSTRSET_H   116
 
#define INSTRSET   0
 
#define const_int(n)   (Const_int_t <n>())
 
#define const_uint(n)   (Const_uint_t<n>())
 

Typedefs

typedef signed char int8_t
 
typedef unsigned char uint8_t
 
typedef signed short int int16_t
 
typedef unsigned short int uint16_t
 
typedef signed int int32_t
 
typedef unsigned int uint32_t
 
typedef long long int64_t
 
typedef unsigned long long uint64_t
 
typedef int32_t intptr_t
 

Functions

int instrset_detect (void)
 
bool hasFMA3 (void)
 
bool hasFMA4 (void)
 
bool hasXOP (void)
 

Macro Definition Documentation

#define const_int (   n)    (Const_int_t <n>())

Definition at line 191 of file instrset.h.

#define const_uint (   n)    (Const_uint_t<n>())

Definition at line 192 of file instrset.h.

#define INSTRSET   0

Definition at line 52 of file instrset.h.

#define INSTRSET_H   116

Definition at line 21 of file instrset.h.

Typedef Documentation

typedef signed short int int16_t

Definition at line 139 of file instrset.h.

typedef signed int int32_t

Definition at line 141 of file instrset.h.

typedef long long int64_t

Definition at line 143 of file instrset.h.

typedef signed char int8_t

Definition at line 137 of file instrset.h.

typedef int32_t intptr_t

Definition at line 148 of file instrset.h.

typedef unsigned short int uint16_t

Definition at line 140 of file instrset.h.

typedef unsigned int uint32_t

Definition at line 142 of file instrset.h.

typedef unsigned long long uint64_t

Definition at line 144 of file instrset.h.

typedef unsigned char uint8_t

Definition at line 138 of file instrset.h.

Function Documentation

bool hasFMA3 ( void  )

Definition at line 132 of file instrset_detect.cpp.

{
if (instrset_detect() < 7) return false; // must have AVX
int abcd[4]; // cpuid results
cpuid(abcd, 1); // call cpuid function 1
return ((abcd[2] & (1 << 12)) != 0); // ecx bit 12 indicates FMA3
}
bool hasFMA4 ( void  )

Definition at line 140 of file instrset_detect.cpp.

{
if (instrset_detect() < 7) return false; // must have AVX
int abcd[4]; // cpuid results
cpuid(abcd, 0x80000001); // call cpuid function 0x80000001
return ((abcd[2] & (1 << 16)) != 0); // ecx bit 16 indicates FMA4
}
bool hasXOP ( void  )

Definition at line 148 of file instrset_detect.cpp.

{
if (instrset_detect() < 7) return false; // must have AVX
int abcd[4]; // cpuid results
cpuid(abcd, 0x80000001); // call cpuid function 0x80000001
return ((abcd[2] & (1 << 11)) != 0); // ecx bit 11 indicates XOP
}
int instrset_detect ( void  )

Definition at line 90 of file instrset_detect.cpp.

{
static int iset = -1; // remember value for next call
if (iset >= 0) {
return iset; // called before
}
iset = 0; // default value
int abcd[4] = {0,0,0,0}; // cpuid results
cpuid(abcd, 0); // call cpuid function 0
if (abcd[0] == 0) return iset; // no further cpuid function supported
cpuid(abcd, 1); // call cpuid function 1 for feature flags
if ((abcd[3] & (1 << 0)) == 0) return iset; // no floating point
if ((abcd[3] & (1 << 23)) == 0) return iset; // no MMX
if ((abcd[3] & (1 << 15)) == 0) return iset; // no conditional move
if ((abcd[3] & (1 << 24)) == 0) return iset; // no FXSAVE
if ((abcd[3] & (1 << 25)) == 0) return iset; // no SSE
iset = 1; // 1: SSE supported
if ((abcd[3] & (1 << 26)) == 0) return iset; // no SSE2
iset = 2; // 2: SSE2 supported
if ((abcd[2] & (1 << 0)) == 0) return iset; // no SSE3
iset = 3; // 3: SSE3 supported
if ((abcd[2] & (1 << 9)) == 0) return iset; // no SSSE3
iset = 4; // 4: SSSE3 supported
if ((abcd[2] & (1 << 19)) == 0) return iset; // no SSE4.1
iset = 5; // 5: SSE4.1 supported
if ((abcd[2] & (1 << 23)) == 0) return iset; // no POPCNT
if ((abcd[2] & (1 << 20)) == 0) return iset; // no SSE4.2
iset = 6; // 6: SSE4.2 supported
if ((abcd[2] & (1 << 27)) == 0) return iset; // no OSXSAVE
if ((xgetbv(0) & 6) != 6) return iset; // AVX not enabled in O.S.
if ((abcd[2] & (1 << 28)) == 0) return iset; // no AVX
iset = 7; // 7: AVX supported
cpuid(abcd, 7); // call cpuid leaf 7 for feature flags
if ((abcd[1] & (1 << 5)) == 0) return iset; // no AVX2
iset = 8; // 8: AVX2 supported
cpuid(abcd, 0xD); // call cpuid leaf 0xD for feature flags
if ((abcd[0] & 0x60) != 0x60) return iset; // no AVX512
iset = 9; // 8: AVX512F supported
return iset;
}