The Gaudi Framework  v28r3 (cc1cf868)
instrset_detect.cpp File Reference
#include "instrset.h"
Include dependency graph for instrset_detect.cpp:

Go to the source code of this file.

Functions

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

Function Documentation

bool hasFMA3 ( void  )

Definition at line 135 of file instrset_detect.cpp.

135  {
136  if (instrset_detect() < 7) return false; // must have AVX
137  int abcd[4]; // cpuid results
138  cpuid(abcd, 1); // call cpuid function 1
139  return ((abcd[2] & (1 << 12)) != 0); // ecx bit 12 indicates FMA3
140 }
int instrset_detect(void)
#define cpuid(func, eax, ebx, ecx, edx)
bool hasFMA4 ( void  )

Definition at line 143 of file instrset_detect.cpp.

143  {
144  if (instrset_detect() < 7) return false; // must have AVX
145  int abcd[4]; // cpuid results
146  cpuid(abcd, 0x80000001); // call cpuid function 0x80000001
147  return ((abcd[2] & (1 << 16)) != 0); // ecx bit 16 indicates FMA4
148 }
int instrset_detect(void)
#define cpuid(func, eax, ebx, ecx, edx)
bool hasXOP ( void  )

Definition at line 151 of file instrset_detect.cpp.

151  {
152  if (instrset_detect() < 7) return false; // must have AVX
153  int abcd[4]; // cpuid results
154  cpuid(abcd, 0x80000001); // call cpuid function 0x80000001
155  return ((abcd[2] & (1 << 11)) != 0); // ecx bit 11 indicates XOP
156 }
int instrset_detect(void)
#define cpuid(func, eax, ebx, ecx, edx)
int instrset_detect ( void  )

Definition at line 93 of file instrset_detect.cpp.

93  {
94 
95  static int iset = -1; // remember value for next call
96  if (iset >= 0) {
97  return iset; // called before
98  }
99  iset = 0; // default value
100  int abcd[4] = {0,0,0,0}; // cpuid results
101  cpuid(abcd, 0); // call cpuid function 0
102  if (abcd[0] == 0) return iset; // no further cpuid function supported
103  cpuid(abcd, 1); // call cpuid function 1 for feature flags
104  if ((abcd[3] & (1 << 0)) == 0) return iset; // no floating point
105  if ((abcd[3] & (1 << 23)) == 0) return iset; // no MMX
106  if ((abcd[3] & (1 << 15)) == 0) return iset; // no conditional move
107  if ((abcd[3] & (1 << 24)) == 0) return iset; // no FXSAVE
108  if ((abcd[3] & (1 << 25)) == 0) return iset; // no SSE
109  iset = 1; // 1: SSE supported
110  if ((abcd[3] & (1 << 26)) == 0) return iset; // no SSE2
111  iset = 2; // 2: SSE2 supported
112  if ((abcd[2] & (1 << 0)) == 0) return iset; // no SSE3
113  iset = 3; // 3: SSE3 supported
114  if ((abcd[2] & (1 << 9)) == 0) return iset; // no SSSE3
115  iset = 4; // 4: SSSE3 supported
116  if ((abcd[2] & (1 << 19)) == 0) return iset; // no SSE4.1
117  iset = 5; // 5: SSE4.1 supported
118  if ((abcd[2] & (1 << 23)) == 0) return iset; // no POPCNT
119  if ((abcd[2] & (1 << 20)) == 0) return iset; // no SSE4.2
120  iset = 6; // 6: SSE4.2 supported
121  if ((abcd[2] & (1 << 27)) == 0) return iset; // no OSXSAVE
122  if ((xgetbv(0) & 6) != 6) return iset; // AVX not enabled in O.S.
123  if ((abcd[2] & (1 << 28)) == 0) return iset; // no AVX
124  iset = 7; // 7: AVX supported
125  cpuid(abcd, 7); // call cpuid leaf 7 for feature flags
126  if ((abcd[1] & (1 << 5)) == 0) return iset; // no AVX2
127  iset = 8; // 8: AVX2 supported
128  cpuid(abcd, 0xD); // call cpuid leaf 0xD for feature flags
129  if ((abcd[0] & 0x60) != 0x60) return iset; // no AVX512
130  iset = 9; // 8: AVX512F supported
131  return iset;
132 }
#define cpuid(func, eax, ebx, ecx, edx)