| 118 | } |
| 119 | |
| 120 | bool feature_detect_avx_fma(int ftr) { |
| 121 | // see Detecting Availability and Support in |
| 122 | // https://software.intel.com/en-us/articles/introduction-to-intel-advanced-vector-extensions |
| 123 | |
| 124 | // check CPU support |
| 125 | if (!(bit(cpuid.ecx, 27) && bit(cpuid.ecx, ftr))) |
| 126 | return false; |
| 127 | |
| 128 | // check OS support |
| 129 | uint32_t edx, eax; |
| 130 | asm volatile("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0)); |
| 131 | |
| 132 | return (eax & 6) == 6; |
| 133 | } |
| 134 | |
| 135 | bool is_avx_supported = feature_detect_avx_fma(28); |
| 136 | bool is_fma_supported = feature_detect_avx_fma(12); |