【问题标题】:How to detect AVX2 support using gcc如何使用 gcc 检测 AVX2 支持
【发布时间】:2021-08-05 22:47:55
【问题描述】:

我需要在我的代码中检测到 AVX2 支持并做出相应的决定。
我知道两种方法 - __builtin_cpu_supports("avx2")#if defined(__AVX2__)。现在的问题是一个返回真,另一个返回假。 测试代码如下-

int main(){
    if(__builtin_cpu_supports("avx2")){
        std::cout<< "Builtin methods supports" << std::endl;
    }
    
    
#if defined(__AVX2__)
    std::cout<<"Builtin symbol present"<<std::endl;
#endif
return 0;
}

而输出如下-

Builtin methods supports

我正在运行 i7 - 9750h。而且我的处理器确实支持AVX2 指令集。

什么是正确的识别方法。我在 9.3.1 中的 GCC 版本

【问题讨论】:

    标签: gcc g++ avx instruction-set avx2


    【解决方案1】:

    我认为你搞错了。您可以在编译时使用宏检查您是否已将 gcc 配置为使用 AVX2 支持进行编译。内置程序可以在运行时检查它当前运行的 CPU 是否支持 AVX2 扩展。

    【讨论】:

    猜你喜欢
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    • 1970-01-01
    • 2012-01-12
    相关资源
    最近更新 更多