Checking if SSE is supported at runtime [duplicate]

感情迁移 提交于 2019-12-20 10:21:15

问题


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.


回答1:


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

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




回答2:


On MSVC, extern int __isa_available has information about the CPU support on a MSVC build.

It is used by the vectorizer in MSVC 2013 to pick what assembly to run.



来源:https://stackoverflow.com/questions/29177785/checking-if-sse-is-supported-at-runtime

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