Using values ​​from `__m256i` for efficient array access - SIMD

Say, for example, that I have 2 variables __m256i, called rowsand cols, the values ​​inside them:

rows: 0, 2, 7, 5, 7, 2, 3, 0
cols: 1, 2, 7, 5, 7, 2, 2, 6

Now, these values represent the positions xand y8 points, so in this case I would have the following terms:

p0: [0, 1], p1: [2, 2], p2: [7, 7], p3: [5, 5]
p4: [7, 7], p5: [2, 2], p6: [3, 2], p7: [0, 6]

I also have an array with a name lutthat will have inttype values :

lut: [0, 1, 2, 3, ..., 60, 61, 62, 63]

I want to use these position values ​​from variables rowsand cols, access it with an array lutand create a new value __m256iwith lutavailable values.

, , , - rows cols int 8, lut , _mm256_set_epi32(), _m256i.

, , . , .

, , lut 64.

!

+4
1

, avx2,

// index = (rows << 3) + cols;
const __m256i index = _mm256_add_epi32( _mm256_slli_epi32(rows, 3), cols);
// result = lut[index];
const __m256i result = _mm256_i32gather_epi32(lut, index, 4);

, , , result, .

4: scale

__m256i _mm256_i32gather_epi32 (int const* base_addr, __m256i vindex, const int scale)

, :

*(const int*)((const char*) base_addr + scale*index)

, (, LUT 1 2 ( )). , , 4 , 1/4 1/2 ( , - ).

+5

Source: https://habr.com/ru/post/1683193/


All Articles