okay I implemented a function that can shift left up to 16 byte.
template <unsigned int N> __m256i _mm256_shift_left(__m256i a)
{
__m256i mask = _mm256_srli_si256(
_mm256_permute2x128_si256(a, a, _MM_SHUFFLE(0,0,3,0))
, 16-N);
return _mm256_or_si256(_mm256_slli_si256(a,N),mask);
}
Example:
int main(int argc, char* argv[]) {
__m256i reg = _mm256_set_epi8(32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,
14,13,12,11,10,9,8,7,6,5,4,3,2,1);
__m256i result = _mm256_shift_left<1>(reg);
for(int i = 0; i < 32; i++)
printf("%2d ",((unsigned char *)&result)[i]);
printf("
");
}
The output is
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Edit: New version with new alignr instruction.
Thanks for the hint @Evgney Kluev
template <unsigned int N> __m256i _mm256_shift_left(__m256i a)
{
__m256i mask = _mm256_permute2x128_si256(a, a, _MM_SHUFFLE(0,0,3,0) );
return _mm256_alignr_epi8(a,mask,16-N);
}