这个错误实际上可能不会出现在所有机器上,但在我的机器上我运行了下面的代码并得到了输出(注意值-1.#IND00
)?
values int:: 4 2
shifts:: 4 2
result: : 64 32
input 1 HADDPD:: 10.000000 -1.#IND00
input 2 HADDPD:: 13.000000 10.000000
result of HADDPD:: -1.#IND00 23.000000
如果我注释掉
__m64 PSLLDm64_IN = _mm_set_pi32(2,4);
__m64 PSLLDm64_C = _mm_set_pi32(2,4);//could this be the culprit?
__m64 PSLLDm64_r = PSLLD(PSLLDm64_IN, PSLLDm64_C);
print_2_32_bit_int("values int:" , PSLLDm64_IN);
print_2_32_bit_int("shifts:", PSLLDm64_C);
print_2_32_bit_int("result: ", PSLLDm64_r);
我得到...
input 1 HADDPD:: 10.000000 100.000000
input 2 HADDPD:: 13.000000 10.000000
result of HADDPD:: 110.000000 23.000000
我想知道第32行__m64 PSLLDm64_C = _mm_set_pi32(2,4);
是否可以搞砸?
继承人完整的代码(它-msse3 -mmmx
使用 g++ 运行)虽然并不是所有的标题都是真正必要的。
#include <xmmintrin.h>
#include <emmintrin.h>
#include <pmmintrin.h>
#include <stdio.h>
#include <stdint.h>
#include <iostream>
void print_2_64_bit_doubles(const char * label, __m128d m64_r)
{
double *val = (double *) &m64_r;
printf("%s: %f %f\n",
label, val[0], val[1]);
}
void print_2_32_bit_int(const char * label, __m64 m32_r)
{
int *val = (int *) &m32_r;
printf("%s: %d %d\n",
label, val[0], val[1]);
}
__m128d HADDPD(__m128d __X, __m128d __Y)
{
return _mm_hadd_pd ( __X, __Y);
}
__m64 PSLLD(__m64 __m, __m64 __count)
{
return _mm_sll_pi32 ( __m, __count);
}
int main()
{
//PSLLD-------------------------------------------------------------------
__m64 PSLLDm64_IN = _mm_set_pi32(2,4);
__m64 PSLLDm64_C = _mm_set_pi32(2,4);
__m64 PSLLDm64_r = PSLLD(PSLLDm64_IN, PSLLDm64_C);
print_2_32_bit_int("values int:" , PSLLDm64_IN);
print_2_32_bit_int("shifts:", PSLLDm64_C);
print_2_32_bit_int("result: ", PSLLDm64_r);
//HADDPD------------------------------------------------------------------
double C1 = 10;
double D = C1*C1;
double x = 10;
double y = 13;
__m128d HADDPDm64_1 = _mm_set_pd(D,C1);
__m128d HADDPDm64_2 = _mm_set_pd(x,y);
__m128d HADDPDm64_r = HADDPD( HADDPDm64_1, HADDPDm64_2);
print_2_64_bit_doubles("input 1 HADDPD:", HADDPDm64_1);
print_2_64_bit_doubles("input 2 HADDPD:", HADDPDm64_2);
print_2_64_bit_doubles("result of HADDPD:", HADDPDm64_r);
return 0;
}
编辑:这是使用 g++ 4.4.1 编译的新移位指令的更新代码-msse -msse2 -msse3 -msse4
#include <xmmintrin.h>
#include <emmintrin.h>
#include <pmmintrin.h>
#include <mmintrin.h>
#include <stdio.h>
#include <stdint.h>
void print_2_64_bit_doubles(const char * label, __m128d m64_r)
{
double *val = (double *) &m64_r;
printf("%s: %f %f\n",
label, val[0], val[1]);
}
void print_2_32_bit_int(const char * label, __m64 m32_r)
{
int *val = (int *) &m32_r;
printf("%s: %d %d\n",
label, val[0], val[1]);
}
void print_1_32_bit_int(const char * label, __m64 m32_r)
{
int *val = (int *) &m32_r;
printf("%s: %d \n",
label, val[0]);
}
__m128d HADDPD(__m128d __X, __m128d __Y)
{
return _mm_hadd_pd ( __X, __Y);
}
__m64 PSLLD(__m64 __m, __m64 __count)
{
return _mm_sll_pi32 ( __m, __count);
}
int main()
{
//PSLLD-------------------------------------------------------------------
__m64 PSLLDm64_IN = _mm_set_pi32(2,4);
long long __i = 2;
__m64 PSLLDm64_C = (__m64)(__i);
__m64 PSLLDm64_r = PSLLD(PSLLDm64_IN, PSLLDm64_C);
_mm_empty();
print_2_32_bit_int("values int:" , PSLLDm64_IN);
print_1_32_bit_int("shifts:", PSLLDm64_C);
print_2_32_bit_int("result: ", PSLLDm64_r);
//HADDPD------------------------------------------------------------------
double C1 = 10;
double D = C1*C1;
double x = 10;
double y = 13;
__m128d HADDPDm64_1 = _mm_set_pd(D,C1);
__m128d HADDPDm64_2 = _mm_set_pd(x,y);
__m128d HADDPDm64_r = HADDPD( HADDPDm64_1, HADDPDm64_2);
print_2_64_bit_doubles("input 1 HADDPD:", HADDPDm64_1);
print_2_64_bit_doubles("input 2 HADDPD:", HADDPDm64_2);
print_2_64_bit_doubles("result of HADDPD:", HADDPDm64_r);
return 0;
}
和输出
values int:: 4 2
shifts:: 2
result: : 16 8
input 1 HADDPD:: 10.000000 -1.#IND00
input 2 HADDPD:: 13.000000 10.000000
result of HADDPD:: -1.#IND00 23.000000