gcc的__builtin_cpu_supports是否检查操作系统支持? [英] does gcc's __builtin_cpu_supports check for OS support?
问题描述
GCC编译器提供了一组内置来测试某些处理器功能,例如某些指令集的可用性.但是,根据此线程我们也可能知道某些操作系统可能未启用某些cpu功能.所以问题是:__builtin_cpu_supports
内部函数是否还会检查OS是否已启用某些处理器功能?
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?
推荐答案
否.
我通过在Linux内核引导选项中添加noxsave
来禁用Skylake系统上的AVX.当我执行cat /proc/cpuinfo
AVX(和AVX2)时,不再出现,并且当我使用AVX指令运行代码时,它崩溃了.这告诉我AVX已被操作系统禁用.
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"));
}
它返回8和512.这意味着__builtin_cpu_supports
不会检查是否OS禁用了AVX.
it returns 8 and 512. This means that __builtin_cpu_supports
does not check to see if AVX was disabled by the OS.
这篇关于gcc的__builtin_cpu_supports是否检查操作系统支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!