我要做的是加载四个 char 值并将它们添加到 4 个浮点数的向量中。起初我所做的是这样的:
// char b[1024] is defined somewhere else
__declspec(align(16)) float d[3];
__declspec(align(16)) float a[4];
__m128* pSrcDst1 = (__m128*) d;
__m128* pSrc2 = (__m128*) a;
a[0] = b[i ];
a[1] = b[i+1];
a[2] = b[i+2];
a[3] = b[i+3];
*pSrcDst1 = _mm_add_ps(*pSrcDst1, *pSrc2);
我想利用类似的东西_mm_loadu_ps
,char*
所以我可以这样做:
// char b[1024] is defined somewhere else
__declspec(align(16)) float d[3];
__declspec(align(16)) float a[4];
__declspec(align(16)) char c[4];
__m128* pSrcDst1 = (__m128*) d;
__m128* pSrc2 = (__m128*) a;
__m64* pSrc3 = (__m64*) c;
*pSrc3 = _mm_loadu_ps(&b[i]);
*pSrc2 = _mm_cvtpu8_ps(*pSrc3);
*pSrcDst1 = _mm_add_ps(*pSrcDst1, *pSrc2);
这样做的正确和优化方法是什么?