Created
October 3, 2016 22:10
-
-
Save jniemann66/6ec11257fc94e3d3a9614fe62b152f0c to your computer and use it in GitHub Desktop.
runtime check of CPU AVX capabilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <immintrin.h> | |
// Verify CPU capabilities: | |
bool bAVXok = false; | |
int cpuInfo[4] = { 0,0,0,0 }; | |
__cpuid(cpuInfo, 0); | |
if (cpuInfo[0] != 0) { | |
__cpuid(cpuInfo, 1); | |
if (cpuInfo[2] & (1 << 28)) { | |
bAVXok = true; // Note: this test only confirms CPU AVX capability, and does not check OS capability. | |
// to-do: check for AVX2 ... | |
} | |
} | |
if (bAVXok) | |
std::cout << "CPU supports AVX (ok)"; | |
else { | |
std::cout << "Your CPU doesn't support AVX - please try a non-AVX build on this machine" << std::endl; | |
exit(EXIT_FAILURE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment