我已经用 g++ 编写和调试了一些 AVX 代码,现在我正试图让它与 MSVC 一起工作,但我不断得到 p>
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)
引用的代码是
...
#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);
}
...
- 我启用了
/arch:AVX
,但没有任何区别。 - 我的机器绝对支持 AVX - 它与我用于原始 Linux 项目的机器相同。
- 另外,http://msdn.microsoft.com/en-us/library/hh977022.aspx在可用的内部函数中列出
_mm256_setr_epi64x
。
如有任何帮助,我们将不胜感激。
最佳答案
看起来这可能实际上是一个 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);
}
哪个可能更有效率。
关于c++ - 未解析的外部符号 __mm256_setr_epi64x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27258261/