简体   繁体   中英

C++ error: intrinsic function was not declared in scope

I want to compile code that uses the intrinsic function _mm256_undefined_si256() (returns a vector of 8 packed double word integers). Here is the reduced snipped of the affected function from the header file:

// test.hpp
#include "immintrin.h"

namespace {
    inline __m256i foo(__m256i a, __m256i b) {
        __m256i res = _mm256_undefined_si256();
        // some inline asm stuff
        // __asm__(...);
        return res;
    }
}

Compiling via gcc -march=native -mavx2 -O3 -std=c++11 test.cpp -o app throws the following error >>_mm256_undefined_si256<< was not declared in this scope.

I can not explain why this intrinsic function is not defined, since there are other intrinsics used in the header file which work properly.

Your code works in GCC4.9 and newer ( https://godbolt.org/z/bajMsKvK9 ). GCC4.9 was released in April 2014, close to a decade ago, and the most recent release of GCC4.8.5 was in June 2015. So it's about time to upgrade your compiler!

GCC4.8 was missing that intrinsic, and didn't even know about -march=sandybridge (let alone tuning options for Haswell which had AVX2), although it did know about the less meaningful -march=corei7-avx .


It does happen that GCC misses some of the more obscure intrinsics that Intel adds along with support for a new instruction set, so support for _mm256_add_epi32 won't always imply _mm256_undefined_si256() .

eg it took until GCC11 for them to add _mm_load_si32(void*) unaligned aliasing-safe movd (which I think Intel introduced around the same time as AVX-512 stuff), so that's multiple years late. (And until GCC12 / 11.3 for GCC to implement it correctly, Bug 99754 , and still not aliasing-safe for _mm_load_ss(float*) ( Bug 84508 ).

But fortunately for the _mm256_undefined_si256 , it's supported by non-ancient versions of all the mainstream compilers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM