如何修复支持 avx 的 Clion 错误

问题描述 投票:0回答:1

我在 Mac 中使用 Clion,通过 Clang 编译器编写 C++ 代码。我知道我的 CPU 支持 AVX1.0。但是,我认为在这个简单的代码中编译

AVX
的东西有问题。错误是:

always_inline function '_mm256_set_ps' requires target feature 'avx', but would be inlined into function 'main' that is compiled without support for 'avx'

和代码:

#include <immintrin.h>
#include <cstdio>

int main() {

    /* Initialize the two argument vectors */
    __m256 evens = _mm256_set_ps(2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0);
    __m256 odds = _mm256_set_ps(1.0, 3.0, 5.0, 7.0, 9.0, 11.0, 13.0, 15.0);

    /* Compute the difference between the two vectors */
    __m256 result = _mm256_sub_ps(evens, odds);

    /* Display the elements of the result vector */
    auto* f = (float*)&result;
    printf("%f %f %f %f %f %f %f %f\n",
           f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]);

    return 0;
}

我应该更改 Clion 中的某些内容吗?

c++ clang clion avx
1个回答
1
投票

我刚刚找到了解决方案。将其添加到您的 Cmake 文件中:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")

现在,它可以正常工作了。

© www.soinside.com 2019 - 2024. All rights reserved.