C++ 内部未声明

标签 c++ gcc compiler-errors intrinsics

我正在学习使用内部函数而不是 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;
}

最佳答案

三件事应该让你的代码工作:

  1. 确保您使用的是 -mavx 编译标志。

  2. 您的变量应声明为 __m256 而不是 _mm256

  3. 确保包含 immintrin.h

关于C++ 内部未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17549630/

相关文章:

c++ - gcc 编译错误,对象初始化解释为函数指针?

c++ - std::auto_ptr 和 boost::shared_ptr 的语义

c++ - 具有非模板基的模板化类给我一个 LNK2005 错误

c++ - 编译 gtk3 应用程序时出现 fatal error : glib. h 未找到

c++ - 无法在 Solaris 10 上使用 GCC 5.5 包含 cmath

java - 来自 == 运算符的 "Invalid assignment"错误

c++ - 我可以像 C++ 中的数组一样迭代类成员吗?

c++ - 允许编译器优化堆内存分配吗?

c++ - Sr 编程语言安装在 Ubuntu 14.04 编译器错误

c++ - 由于 Visual Studio 2012 中缺少 std::isnan,Qt 构建失败