我需要在 __m128i 变量的特定位置加载连续存储在数组中的 4 个字节,即能够一次进行 4 个 int32_t 求和,存储所有部分结果。
例如:
const unsigned int SIZE = 2000000;
const unsigned int STEP = 100;
unsigned char* inBuffer = new char[SIZE];
//Fill inBuffer
const unsigned char* a = inBuffer;
int32_t* outBuffer = new int32_t[SIZE/STEP*4];
int32_t* result = outBuffer;
__m128i sum = _mm_setzero_si128 ()
for (int i = 0; i < SIZE; i+=STEP) {
__m128i value = _mm_set_epi32 (a[3],a[2],a[1],a[0]);
sum = __mm_add_epi32(sum,value);
_mm_storeu_si128 ((__m128i*)result,sum);
a+=STEP;
result+=4;
}
//Print outBuffer
delete[] inBuffer;
delete[] outBuffer;
我想知道是否有更有效的方法来做到这一点