Gcc __builtin_cpu_supports check OS support?

The GCC compiler provides a set of built-in functions for testing certain processor functions, such as the availability of specific instruction sets. But according to this thread, we can also know that some cpu functions may not be supported by the OS. So the question is: do __builtin_cpu_supports intrinsics also check if the OS allowed a specific processor function?

+7
c gcc simd intrinsics instruction-set
source share
1 answer

Not.

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) is no longer displayed, and when I run the code with the AVX instructions, it crashes. This tells me that the AV OS is disabled 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 if the AVX OS is disabled.

+4
source share

All Articles