Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

c++ - unresolved external symbol __mm256_setr_epi64x

I have written and debugged some AVX code with g++ and now I'm trying to get it to work with MSVC, but I keep getting

error LNK2019: unresolved external symbol __mm256_setr_epi64x referenced in function "private: union __m256i __thiscall avx_matrix::avx_bit_mask(unsigned int)const " (?avx_bit_mask@avx_matrix@@ABE?AT__m256i@@I@Z)

The referenced piece of code is

...

#include <immintrin.h>

...

    /* All zeros except for pos-th position (0..255) */
    __m256i avx_matrix::avx_bit_mask(const std::size_t pos) const
    {
        int64_t a = (pos >= 0 && pos < 64) ? 1LL << (pos - 0) : 0;
        int64_t b = (pos >= 64 && pos < 128) ? 1LL << (pos - 64) : 0;
        int64_t c = (pos >= 128 && pos < 192) ? 1LL << (pos - 128) : 0;
        int64_t d = (pos >= 192 && pos < 256) ? 1LL << (pos - 256) : 0;
        return _mm256_setr_epi64x(a, b, c, d);
    }
...
  • I have enabled /arch:AVX, but it doesn't make any difference.
  • My machine definitely supports AVX - it is the same one I used for the original Linux project.
  • Also, http://msdn.microsoft.com/en-us/library/hh977022.aspx lists _mm256_setr_epi64x among the available intrinsics.

Any help would be much appreciated.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

It looks this might actually be a known bug - certain AVX intrinsics are apparently not available in 32-bit mode. Try building for 64 bit and/or upgrading to Visual Studio 2013 Update 2, where this has supposedly now been fixed.

Alternatively, if you just have the one instance above where you are using this intrinsic, then you could change your function to:

__m256i avx_matrix::avx_bit_mask(const std::size_t pos) const
{
    int64_t a[4] = { (pos >=   0 && pos <  64) ? 1LL << (pos -   0) : 0,
                     (pos >=  64 && pos < 128) ? 1LL << (pos -  64) : 0,
                     (pos >= 128 && pos < 192) ? 1LL << (pos - 128) : 0,
                     (pos >= 192 && pos < 256) ? 1LL << (pos - 256) : 0 };
    return _mm256_loadu_si256((__m256i *)a);
}

or perhaps even:

__m256i avx_matrix::avx_bit_mask(const std::size_t pos) const
{
    int64_t a[4] = { 0 };
    a[pos >> 6] = 1LL << (pos & 63ULL);
    return _mm256_loadu_si256((__m256i *)a);
}

which might be a little more efficient.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...