2014-12-02 78 views
4

我已經寫和調試一些AVX代碼G ++,現在我試圖讓它與MSVC的工作,但我不斷收到解析的外部符號__mm256_setr_epi64x

錯誤LNK2019:解析外部符號__mm256_setr_epi64x中引用功能 「私人:工會__m256i __thiscall avx_matrix :: avx_bit_mask(無符號整數)常量」(avx_bit_mask @ avx_matrix @@ ABE AT__m256i @@我@ Z?)

的代碼引用的部分是

... 

#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); 
    } 
... 

任何幫助將不勝感激。

回答

3

看起來這實際上可能是known bug-某些AVX內在函數顯然在32位模式下不可用。嘗試構建64位和/或升級到Visual Studio 2013 Update 2,現在已經解決了這個問題。

或者,如果你只是上面使用的是這種內在的其中一個實例,那麼你可以在你的功能更改爲:

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

甚或:

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

威力會更高效一點。

+0

您的鏈接說「此連接不受信任」。 – 2014-12-03 08:53:59

+2

嘿 - 看起來像微軟忘了更新他們的證書。 – 2014-12-03 09:03:24

+1

爲了發現這個已經被修復的問題+1。然而,現在是2014年。誰在使用32位模式? OS X現在只有64位。 Ubuntu在一年內逐步淘汰32位。 8年前,MSFT應該已經修復了這個問題。 – 2014-12-03 09:06:44

4

在32位模式下MSVC不支持

  • _mm_set_epi64x
  • _mm_setr_epi64x
  • _mm_set1_epi64x
  • _mm256_set_epi64x
  • _mm256_setr_epi64x
  • _mm256_set1_epi64x

在32位模式下你的情況,你可以這樣做:

union { 
     int64_t q[4]; 
     int32_t r[8]; 
    } u; 
    u.q[0] = a; u.q[1] = b; u.q[2] = c; u.q[3] = d; 
    return _mm256_setr_epi32(u.r[0], u.r[1], u.r[2], u.r[3], u.r[4], u.r[5], u.r[6], u.r[7]);