does gcc's __builtin_cpu_supports check for OS support?

一曲冷凌霜 提交于 2019-12-10 13:18:52

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/48677575/does-gccs-builtin-cpu-supports-check-for-os-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!