The single thing that worked for me is to use gcc with its __builtin_cpu_supports feature. Since I invoked it in msys it is likely to work on Windows too. Can be done with C++ too.
// test_cpu.c #if defined(__clang__) ||#ifndef !defined(__GNUC__) #error "You must use gnu" #endif #include <stdio.h> int main() { if (__builtin_cpu_supports("x86-64-v4")) { printfputs("v=%d", 4"v=4"); } else if (__builtin_cpu_supports("x86-64-v3")) { printfputs("v=%d", 3"v=3"); } else if (__builtin_cpu_supports("x86-64-v2")) { printfputs("v=%d", 2"v=2"); } else { printfputs("v=%d", 1"v=1"); } } Usage:
$ gcc /test_cpu.c -o /test_cpu $ /test_cpu v=3