Using values from `__m256i` to access an array efficiently - SIMD

Viewed 1144

Let's say, for example, that I have 2 variables __m256i called rows and cols, the values inside them are:

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

Now, these values represent the x and y positions for 8 points, so, in this case I would have these points:

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 called lut that will have values of int type:

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

What I want to do, is to use these positions values from rows and cols variables, access the lut array with it and create a new __m256i value with the lut accessed values.

The way I know of how to do that would be to store rows and cols values in two int arrays of size 8, then read the values from lut array one at a time and then use _mm256_set_epi32() to create the new _m256i value.

This works, but it seems to me to be very inefficient.. So my question is if there is some way to do it faster.

Note that these values are just for a more concrete example, and lut doesn't need to have ordered values or size 64.

thanks!

1 Answers
Related