The Gaudi Framework  master (37c0b60a)
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)
 
bool hasF16C (void)
 
bool hasAVX512ER (void)
 
bool hasAVX512VBMI (void)
 
bool hasAVX512VBMI2 (void)
 

Function Documentation

◆ hasAVX512ER()

bool hasAVX512ER ( void  )

Definition at line 142 of file instrset_detect.cpp.

142  {
143  if ( instrset_detect() < 9 ) return false; // must have AVX512F
144  int abcd[4]; // cpuid results
145  cpuid( abcd, 7 ); // call cpuid function 7
146  return ( ( abcd[1] & ( 1 << 27 ) ) != 0 ); // ebx bit 27 indicates AVX512ER
147  }

◆ hasAVX512VBMI()

bool hasAVX512VBMI ( void  )

Definition at line 150 of file instrset_detect.cpp.

150  {
151  if ( instrset_detect() < 10 ) return false; // must have AVX512BW
152  int abcd[4]; // cpuid results
153  cpuid( abcd, 7 ); // call cpuid function 7
154  return ( ( abcd[2] & ( 1 << 1 ) ) != 0 ); // ecx bit 1 indicates AVX512VBMI
155  }

◆ hasAVX512VBMI2()

bool hasAVX512VBMI2 ( void  )

Definition at line 158 of file instrset_detect.cpp.

158  {
159  if ( instrset_detect() < 10 ) return false; // must have AVX512BW
160  int abcd[4]; // cpuid results
161  cpuid( abcd, 7 ); // call cpuid function 7
162  return ( ( abcd[2] & ( 1 << 6 ) ) != 0 ); // ecx bit 6 indicates AVX512VBMI2
163  }

◆ hasF16C()

bool hasF16C ( void  )

Definition at line 134 of file instrset_detect.cpp.

134  {
135  if ( instrset_detect() < 7 ) return false; // must have AVX
136  int abcd[4]; // cpuid results
137  cpuid( abcd, 1 ); // call cpuid function 1
138  return ( ( abcd[2] & ( 1 << 29 ) ) != 0 ); // ecx bit 29 indicates F16C
139  }

◆ hasFMA3()

bool hasFMA3 ( void  )

Definition at line 110 of file instrset_detect.cpp.

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

◆ hasFMA4()

bool hasFMA4 ( void  )

Definition at line 118 of file instrset_detect.cpp.

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

◆ hasXOP()

bool hasXOP ( void  )

Definition at line 126 of file instrset_detect.cpp.

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

◆ instrset_detect()

int instrset_detect ( void  )

Definition at line 63 of file instrset_detect.cpp.

63  {
64 
65  static int iset = -1; // remember value for next call
66  if ( iset >= 0 ) {
67  return iset; // called before
68  }
69  iset = 0; // default value
70  int abcd[4] = { 0, 0, 0, 0 }; // cpuid results
71  cpuid( abcd, 0 ); // call cpuid function 0
72  if ( abcd[0] == 0 ) return iset; // no further cpuid function supported
73  cpuid( abcd, 1 ); // call cpuid function 1 for feature flags
74  if ( ( abcd[3] & ( 1 << 0 ) ) == 0 ) return iset; // no floating point
75  if ( ( abcd[3] & ( 1 << 23 ) ) == 0 ) return iset; // no MMX
76  if ( ( abcd[3] & ( 1 << 15 ) ) == 0 ) return iset; // no conditional move
77  if ( ( abcd[3] & ( 1 << 24 ) ) == 0 ) return iset; // no FXSAVE
78  if ( ( abcd[3] & ( 1 << 25 ) ) == 0 ) return iset; // no SSE
79  iset = 1; // 1: SSE supported
80  if ( ( abcd[3] & ( 1 << 26 ) ) == 0 ) return iset; // no SSE2
81  iset = 2; // 2: SSE2 supported
82  if ( ( abcd[2] & ( 1 << 0 ) ) == 0 ) return iset; // no SSE3
83  iset = 3; // 3: SSE3 supported
84  if ( ( abcd[2] & ( 1 << 9 ) ) == 0 ) return iset; // no SSSE3
85  iset = 4; // 4: SSSE3 supported
86  if ( ( abcd[2] & ( 1 << 19 ) ) == 0 ) return iset; // no SSE4.1
87  iset = 5; // 5: SSE4.1 supported
88  if ( ( abcd[2] & ( 1 << 23 ) ) == 0 ) return iset; // no POPCNT
89  if ( ( abcd[2] & ( 1 << 20 ) ) == 0 ) return iset; // no SSE4.2
90  iset = 6; // 6: SSE4.2 supported
91  if ( ( abcd[2] & ( 1 << 27 ) ) == 0 ) return iset; // no OSXSAVE
92  if ( ( xgetbv( 0 ) & 6 ) != 6 ) return iset; // AVX not enabled in O.S.
93  if ( ( abcd[2] & ( 1 << 28 ) ) == 0 ) return iset; // no AVX
94  iset = 7; // 7: AVX supported
95  cpuid( abcd, 7 ); // call cpuid leaf 7 for feature flags
96  if ( ( abcd[1] & ( 1 << 5 ) ) == 0 ) return iset; // no AVX2
97  iset = 8;
98  if ( ( abcd[1] & ( 1 << 16 ) ) == 0 ) return iset; // no AVX512
99  cpuid( abcd, 0xD ); // call cpuid leaf 0xD for feature flags
100  if ( ( abcd[0] & 0x60 ) != 0x60 ) return iset; // no AVX512
101  iset = 9;
102  cpuid( abcd, 7 ); // call cpuid leaf 7 for feature flags
103  if ( ( abcd[1] & ( 1 << 31 ) ) == 0 ) return iset; // no AVX512VL
104  if ( ( abcd[1] & 0x40020000 ) != 0x40020000 ) return iset; // no AVX512BW, AVX512DQ
105  iset = 10;
106  return iset;
107  }
instrset_detect
int instrset_detect(void)
Definition: instrset_detect.cpp:63
cpuid
#define cpuid(func, ax, bx, cx, dx)
Definition: PerfMonAuditor.cpp:83