Skip to content

Instantly share code, notes, and snippets.

@jniemann66
Created October 3, 2016 22:10
Show Gist options
  • Save jniemann66/6ec11257fc94e3d3a9614fe62b152f0c to your computer and use it in GitHub Desktop.
Save jniemann66/6ec11257fc94e3d3a9614fe62b152f0c to your computer and use it in GitHub Desktop.
runtime check of CPU AVX capabilities
#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