我正在学习使用内部函数而不是 asm 内联。昨天,他们还在工作,但我今天总是出错。什么都没改变。
#include <iostream>
#include <intrin.h> // immintrin.h, smmintrin.h ... tried all, never worked
using namespace std;
int main()
{
_m256_zeroupper(); // __mm256_zeroupper(); does not work too
_mm128 x; // __mm128 x; does not work too
_mm256 y; // __mm256 y; does not work too
_m256_zeroupper(); // __mm256_zeroupper(); does not work too
cout << "Hello world!" << endl;
return 0;
}
这是错误。我尝试了不同内在函数的所有头文件,但错误是相同的。还重新安装了 gcc,但没有用。
我哪里错了?我需要添加什么才能实际声明这些内部变量和函数?
C:\indirmeDenemesi\hello_intrin\main.cpp||In function 'int main()':|
C:\indirmeDenemesi\hello_intrin\main.cpp|8|error: '_mm256_zeroupper' was not declared in this scope|
C:\indirmeDenemesi\hello_intrin\main.cpp|9|error: '_mm128' was not declared in this scope|
C:\indirmeDenemesi\hello_intrin\main.cpp|9|error: expected ';' before 'x'|
C:\indirmeDenemesi\hello_intrin\main.cpp|10|error: '_mm256' was not declared in this scope|
C:\indirmeDenemesi\hello_intrin\main.cpp|10|error: expected ';' before 'y'|
||=== Build finished: 5 errors, 0 warnings (0 minutes, 0 seconds) ===|
在具有 64 位 Windows 的 64 位 CPU 上使用 64 位最新版本的 gcc。 CPU是FX8150。 尝试了 -march=bdver1 -mtune=bdver1 并产生了数百个垃圾错误。
所有这些是否意味着我的 CPU 快要死了?
编辑:一些其他项目现在正在运行,但我没有做任何更改。这一定是一个项目特定的东西。 使用 code::blocks 并且当我右键单击标题并选择“打开”时,它会出现“找不到”错误,但在编译时不会出现任何与此相关的错误,只是 intrinsinc 命令的错误。工作项目也是如此(他们编译一切并工作,但右键单击并单击打开时找不到头文件)。也许其他一些 Windows 服务正在干扰?我不知道,但编译器错误会时不时地消失并再次出现。重新安装代码块也没有解决。只有一些项目可以使用内部函数,而其他项目不能(即使所有项目都有相同的 header 。)
下面这段代码也不起作用。
#include <iostream>
#include <immintrin.h>
using namespace std;
int main()
{
_m256_zeroupper();
__mm128 x;
__mm256 y;
_m256_zeroupper();
cout << "Hello world!" << endl;
return 0;
}
最佳答案
三件事应该让你的代码工作:
确保您使用的是 -mavx 编译标志。
您的变量应声明为
__m256
而不是_mm256
。确保包含
immintrin.h
关于C++ 内部未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17549630/