C++ 内在未声明
我正在学习使用内在函数而不是 asm 内联.昨天,他们正在工作,但我今天总是出错.什么都没变.
Im learning to use intrinsics instead of asm-inlining. Yesterday, they were working but I always get error today. Changed nothing.
#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 但没有用.
Here are the errors. I tried all header files for different intrinsics but errors were same. Also reinstalled gcc but did not work.
我哪里错了?我需要添加什么才能实际声明这些内在变量和函数?
Where am I wrong? What do I need to add to actually declare these intrinsic variables and functions?
C:indirmeDenemesihello_intrinmain.cpp||In function 'int main()':|
C:indirmeDenemesihello_intrinmain.cpp|8|error: '_mm256_zeroupper' was not declared in this scope|
C:indirmeDenemesihello_intrinmain.cpp|9|error: '_mm128' was not declared in this scope|
C:indirmeDenemesihello_intrinmain.cpp|9|error: expected ';' before 'x'|
C:indirmeDenemesihello_intrinmain.cpp|10|error: '_mm256' was not declared in this scope|
C:indirmeDenemesihello_intrinmain.cpp|10|error: expected ';' before 'y'|
||=== Build finished: 5 errors, 0 warnings (0 minutes, 0 seconds) ===|
在 64 位 cpu 和 64 位 windows 上使用 64 位最新版本的 gcc.CPU是FX8150.试过 -march=bdver1 -mtune=bdver1 并产生了数百个垃圾错误.
Using 64-bit latest version of gcc on 64bit cpu with 64 bit windows. CPU is FX8150. Tried -march=bdver1 -mtune=bdver1 and it produced hundreds of junk error.
所有这些是否意味着我的 CPU 快要死了?
Does all these mean my CPU is dying?
其他一些项目现在正在运行,但我没有做任何改变.这必须是特定于项目的事情.使用 code::blocks 并且当我右键单击标题并选择打开"时,它会给出错误找不到",但在编译时不会给出任何错误,只是内在命令的错误.对于工作项目也是如此(它们编译所有内容并工作,但在右键单击并单击打开时找不到头文件).也许其他一些 Windows 服务正在干扰?我不知道,但编译器错误正在消失并时不时地再次出现.重新安装代码块也没有解决.只有一些项目可以使用内部函数,而其他项目则不能(即使所有项目都具有相同的标头.)
some other projects are working now, but I did not change anything. This must be a project-specific thing. Using code::blocks and when I right-click on a header and select "open", it gives error "could not find" but does not give any error when compiling related to that, just error for intrinsinc commands. Same for working projects(they compile everything and work, but does not find header files when right click and click open). Maybe some other windows services were interfering? I dont know but compiler errors are vanishing and coming again, time to time. Reinstalling also codeblocks did not solve. Only some projects can use intrinsics while other projects cannot(even if all projects have same headers.)
下面的代码也不起作用.
This code below does not work too.
#include <iostream>
#include <immintrin.h>
using namespace std;
int main()
{
_m256_zeroupper();
__mm128 x;
__mm256 y;
_m256_zeroupper();
cout << "Hello world!" << endl;
return 0;
}
推荐答案
让你的代码正常工作的三件事:
Three things should make your code work:
确保您使用的是 -mavx 编译标志.
Make sure you're using the -mavx compile flag.
你的变量应该声明为 __m256
而不是 _mm256
.
Your variable should be declared as __m256
not _mm256
.
确保包含 immintrin.h
相关文章