Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
812 views
in Technique[技术] by (71.8m points)

gcc - C++ Intrinsic not declared

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;
    }

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) ===|

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.

Does all these mean my CPU is dying?

Edit: 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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Three things should make your code work:

  1. Make sure you're using the -mavx compile flag.

  2. Your variable should be declared as __m256 not _mm256.

  3. Make sure you're including immintrin.h


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...