| 193 | #include <intrin.h> // for __cpuid |
| 194 | #endif |
| 195 | bool cpu_has_speculation() { |
| 196 | #if __TBB_TSX_AVAILABLE |
| 197 | #if (__INTEL_COMPILER || __GNUC__ || _MSC_VER || __SUNPRO_CC) |
| 198 | bool result = false; |
| 199 | const int hle_ebx_mask = 1<<4; |
| 200 | #if _MSC_VER |
| 201 | int info[4] = {0,0,0,0}; |
| 202 | const int reg_ebx = 1; |
| 203 | __cpuidex(info, 7, 0); |
| 204 | result = (info[reg_ebx] & hle_ebx_mask)!=0; |
| 205 | #elif __GNUC__ || __SUNPRO_CC |
| 206 | int32_t reg_ebx = 0; |
| 207 | int32_t reg_eax = 7; |
| 208 | int32_t reg_ecx = 0; |
| 209 | __asm__ __volatile__ ( "movl %%ebx, %%esi\n" |
| 210 | "cpuid\n" |
| 211 | "movl %%ebx, %0\n" |
| 212 | "movl %%esi, %%ebx\n" |
| 213 | : "=a"(reg_ebx) : "0" (reg_eax), "c" (reg_ecx) : "esi", |
| 214 | #if __TBB_x86_64 |
| 215 | "ebx", |
| 216 | #endif |
| 217 | "edx" |
| 218 | ); |
| 219 | result = (reg_ebx & hle_ebx_mask)!=0 ; |
| 220 | #endif |
| 221 | return result; |
| 222 | #else |
| 223 | #error Speculation detection not enabled for compiler |
| 224 | #endif /* __INTEL_COMPILER || __GNUC__ || _MSC_VER */ |
| 225 | #else /* __TBB_TSX_AVAILABLE */ |
| 226 | return false; |
| 227 | #endif /* __TBB_TSX_AVAILABLE */ |
| 228 | } |
| 229 | |
| 230 | } // namespace internal |
| 231 | |