Search code examples
c++x86simdavx512

Reverse the values in a __m512i register


I'd like to reverse the order of all values in a __m512i register. My main problem is that I am not finding an explanation of how to use all the different shuffle operations. I already tried _mm512_shuffle_epi32 but I don't find any explanation how the _MM_PERM_AAAA, _MM_PERM_AAAB, ... actually work and by just trying them I don't get exactly how to use them.


Solution

  • Found a solution:

    const __m512i reverseMask = _mm512_set_epi32 (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
    __m512i reversed = _mm512_permutevar_epi32(reverseMask,ObjectToReverse); 
    

    Note, that the "reverseMask" is no real mask and instead a register that holds the positions for each object in the register to reverse.