| 60 | } |
| 61 | |
| 62 | bool feature_detect_avx2() { |
| 63 | uint32_t eax, ebx, ecx, edx; |
| 64 | |
| 65 | // check cpu support |
| 66 | #if defined(_WIN32) |
| 67 | int cpuInfo[4]; |
| 68 | __cpuid(cpuInfo, 7); |
| 69 | eax = cpuInfo[0]; |
| 70 | ebx = cpuInfo[1]; |
| 71 | ecx = cpuInfo[2]; |
| 72 | edx = cpuInfo[3]; |
| 73 | #else |
| 74 | asm volatile("cpuid\n" |
| 75 | : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) |
| 76 | : "a"(7), "c"(0) |
| 77 | : "cc"); |
| 78 | #endif |
| 79 | |
| 80 | if (!(bit(ebx, 3) && bit(ebx, 5) && bit(ebx, 8))) |
| 81 | return false; |
| 82 | |
| 83 | // check os support |
| 84 | asm volatile("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0)); |
| 85 | |
| 86 | return (eax & 6) == 6; |
| 87 | } |
| 88 | |
| 89 | bool feature_detect_vnni() { |
| 90 | uint32_t eax, ebx, ecx, edx; |