I am trying to rewrite this piece of code with simd:
int16_t v;
int32_t a[16];
int8_t b[32];
...
((int16_t *)a[i])[0] = b[i]==1? -v:v;
((int16_t *)a[i])[1] = b[i]==1? -v:v;
I thought to use _mm256_cmpeq_epi8to generate a vector mask, after which I can use _mm256_and_si256and _mm256_andnot_si256to execute the selection values.
The problem is that b [i] is an 8-bit integer and v is a 16-bit one.
If the mask vector is similar to {0xff, 0x00, 0xff, 0x00...}, it must be expanded to {0xffff, 0x0000, 0xffff, 0x0000...}to select a 16-bit value.
How can i do this? (Sorry for my English)
edit:
I found a solution with inspiration for this question .
_mm256_shuffle_epi256can only perform in 128-bit band. So I broke the mask _mm256i into registers 2 _mm128i. Then with _mm256_broadcastsi128_si256and _mm256_shuffle_epi256I got the result.
source
share