GCC compiler provides a set of builtins to test some processor features, like availability of certain instruction sets. But, according to this thread we also may know certain cpu features may be not enabled by OS. So the question is: do __builtin_cpu_supports
intrinsics also check if OS has enabled certain processor feature?
No.
I disabled AVX on my Skylake system by adding noxsave
to the Linux kernel boot options. When I do cat /proc/cpuinfo
AVX (and AVX2) no longer appear and when I run code with AVX instructions it crashes. This tells me that AVX has been disabled by the OS.
However, when I compile and run the following code
#include <stdio.h>
int main(void) {
__builtin_cpu_init();
printf("%d\n", __builtin_cpu_supports ("sse"));
printf("%d\n", __builtin_cpu_supports ("avx"));
}
it returns 8 and 512. This means that __builtin_cpu_supports
does not check to see if AVX was disabled by the OS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With