c++ - 当我尝试使用 AVX 功能时 Clang 生成错误

标签 c++ c clang

我在 Windows 10 上使用 Clang 版本 5(最近安装)。当我编译以下内容时

#define __AVX__
#define __AVX2__
#include <immintrin.h>

int main(void) {
    __m256i a, b, result;
    result = _mm256_add_epi64(a, b);
    return 0;
}

我收到以下错误:

 error: always_inline function '_mm256_add_epi64' requires target 
 feature 'avx2', but would be inlined into function 'main' that is 
 compiled without support for 'avx2'
    result = _mm256_add_epi64(a, b);
             ^

MSVC 可以很好地编译它。为了让 Clang 编译它,我需​​要使用什么编译器选项?还是有其他事情发生?

最佳答案

如果你是本地编译(主机和目标是同一台机器,不是交叉编译),那么考虑将 -march=native 传递给 clang

另见 user manual of the Clang compiler .

注意 Clang 编译器是 open source .您可以下载其源代码并对其进行改进。

关于c++ - 当我尝试使用 AVX 功能时 Clang 生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47207637/

相关文章:

c - 如何用标准C实现消息队列

gcc - Clang 3.4 stdlib.h 编译错误

c++ - 模板替换和 SFINAE 中的私有(private)成员访问

c++ - 地址 sanitizer : "SEGV on unknown adress" when using throw-catch and printf

c# - C++/Cx for C# 中的 Directx 包装器

c++ - 为我的程序设置一个 exe 图标

c++ - 计算球形多边形面积?

c - 将多维数组传递给 C 中的函数

c++ - 在 C++ 中使用链表作为类中的对象

c - 查找不可打印的字符并在 C 中打印出它们的十六进制形式