每次偏移 int索引*scale 个字节,每次取4字节。注意int索引是倒序的,如__m128i vindex有4个int索引,先取最后一个索引。
举例:
__m128i _mm_i32gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
int int_array[8] = { 100,200,300,400,500,600,700,800 }; //4字节元素 __m128i vindex = _mm_set_epi32(0, 1, 2, 3); //4个int索引 __m128i result1 = _mm_i32gather_epi32(int_array, vindex, 4);//每次取4字节,第一个从偏移3*4字节处开始取,即400 int* int_res = (int*)&result1; for (int i = 0; i < 4; i++) { std::cout << int_res[i] << "\n"; //400,300,200,100 } //案例二 uint8_t uint8_array[8] = { 10,11,12,13,14,15,16,17 }; //1字节元素 __m128i result = _mm_i32gather_epi32((int*)uint8_array, vindex, 1);//每次取4字节,第一个从偏移3*1字节处开始取,即13 14 15 16 uint8_t* uint8_res = (uint8_t*)&result; for (int i = 0; i < 8; i++) { std::cout << (int)uint8_res[i] << "\n"; //13 14 15 16 12 13 14 15 }
标签:__,vindex,字节,int,gather,索引,m128i,指令集,CPU From: https://www.cnblogs.com/xixixing/p/18246414