如何使用英特尔内部函数检查是否AVX扩展是由CPU的支持? [英] How to check with Intel intrinsics if AVX extensions is supported by the CPU?

查看:641
本文介绍了如何使用英特尔内部函数检查是否AVX扩展是由CPU的支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写采用英特尔内部函数的程序。我想用 _mm_permute_pd 内在的,这是唯一与AVX的CPU可用。对于没有AVX的CPU我可以使用 _mm_shuffle_pd 但根据规格它比 _mm_permute_pd 慢得多。做英特尔内部函数头文件定义常量,让我分辨AVX是否支持,让我可以写某事像这样:

I'm writing a program using Intel intrinsics. I want to use _mm_permute_pd intrinsic, which is only available on CPUs with AVX. For CPUs without AVX I can use _mm_shuffle_pd but according to the specs it is much slower than _mm_permute_pd. Do the header files for Intel intrinsics define constants that allow me to distinguish whether AVX is supported so that I can write sth like this:

#ifdef __IS_AVX_SUPPORTED__  // is there sth like this defined?
// use _mm_permute_pd
# else
// use _mm_shuffle_pd
#endif

?我发现<一个href=\"https://software.intel.com/en-us/articles/introduction-to-intel-advanced-vector-extensions/\">this教程,它展示了如何执行运行时检查,但我需要做一个静态,编译时检查当前计算机。

? I have found this tutorial, which shows how to perform a runtime check but I need to do a static, compile-time check for the current machine.

推荐答案

我假设你使用的是英特尔C ++编译器。在这种情况下 - 是的,有这样的宏:英特尔C ++编译器参考指南 __ __ AVX __ __ AVX2

I assume you are using Intel C++ Compiler. In this case - yes, there are such macros: Intel C++ Compiler Reference Guide: __AVX__, __AVX2__.

P.S。请注意,如果您编译您AVX指令集的应用程序启用它将在失败的CPU不支持AVX。如果你要分发软件的源$ C ​​$ C封装和汇编目标机器上 - 这是可能是一个可行的解决方案。否则,你应该检查AVX动态。

P.S. Be aware that if you compile you application with AVX instruction set enabled it will fail on CPUs not supporting AVX. If you are going to distribute your software as source code package and compile on target machine - this is may be a viable solution. Otherwise you should check for AVX dynamically.

P.P.S。有对国际刑事法院的几个选项。看看在下列编译器选项从中其他还引用。

P.P.S. There are several options for ICC. Take a look at the following compiler options and also references from it to other.

这篇关于如何使用英特尔内部函数检查是否AVX扩展是由CPU的支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆