检查运行时是否支持SSE [英] Checking if SSE is supported at runtime
问题描述
我想在运行时检查是否支持SSE4或AVX,以便我的程序可以利用特定于处理器的指令,而无需为每个处理器创建二进制文件.
I would like to check if SSE4 or AVX is supported at runtime, so that my program may take advantage of processor specific instructions without creating a binary for each processor.
如果我可以在运行时确定它,则可以使用一个接口并在不同的指令集之间进行切换.
If I could determine it at runtime, I could use an interface and switch between different instruction sets.
推荐答案
GCC有一种方法,首先调用__builtin_cpu_init
,然后调用__builtin_cpu_is
和__builtin_cpu_supports
来检查功能. https://gcc.gnu.org/onlinedocs/gcc- 4.8.2/gcc/X86-Built-in-Functions.html
GCC has a way of doing this that starts by calling __builtin_cpu_init
then calling __builtin_cpu_is
and __builtin_cpu_supports
to check features. https://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/X86-Built-in-Functions.html
在x86上,当使用C ++前端时,GCC支持功能多版本",该功能允许您编写该功能的多个版本,指定应在其上使用的目标,并让GCC负责确保调用该功能. . https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Function-Multiversioning.html
On x86, when using the C++ frontend, GCC supports "function multiversioning", which allows you to write multiple versions of the function, specify the target it should be used on, and let GCC take care of making sure it is called. https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Function-Multiversioning.html
这篇关于检查运行时是否支持SSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!