我试图用 gcc(g++) 编译一个 AVX2 程序。但它没有正常工作。
#include<immintrin.h>
....
__m256i _vector256 = _mm256_loadu_si256((__m256i*)pin);
__m256i _vectorMask = _mm256_loadu_si256((__m256i*)mask_hbits);
_vector256 = _mm256_slli_epi32 (_vector256, AVX_LOGDESC); // AVX_LOGDESC == 4
__m256i _vectorRes = _mm256_and_si256(_vector256, _vectorMask);
....
我的编译命令是(作为 Makefile 中的一行):
g++ avx_shift.cpp -c -mavx2
我也试过这个:
g++ avx_shift.cpp -c -march=native
但错误信息是一样的:
/tmp/ccSFs6U0.s: Assembler messages:
/tmp/ccSFs6U0.s:1083: Error: suffix or operands invalid for `vpslld'
/tmp/ccSFs6U0.s:1091: Error: suffix or operands invalid for `vpand'
....
汇编代码(添加行号):
vmovdqa 988(%rsp), %ymm0 # __A, D.48219
movl 984(%rsp), %eax # __B, tmp205
movl %eax, -120(%rsp) # tmp205, %sfp
vmovd -120(%rsp), %xmm6 # %sfp, tmp205
vpslld %xmm6, %ymm0, %ymm0 # tmp205, D.48219, D.48220 // 1083
....
vmovdqa 668(%rsp), %ymm0 # __B, tmp220
vmovdqa 700(%rsp), %ymm1 # __A, tmp221
vpand %ymm0, %ymm1, %ymm0 # tmp220, tmp221, D.48215 // 1091
....
我的 gcc(g++) 版本是 4.8.0。我的操作系统版本是 Centos6.5 X86_64。我已经确认我的 CPU 支持 AVX2 指令。那么谁能帮我找出错误呢?