2021年4月25日星期日

AVX512 - How to move all set bits to the right?

How can I move all set bits of mask register to right? (To the bottom, least-significant position).

For example:

__mmask16 mask = _mm512_cmpeq_epi32_mask(vload, vlimit); // mask = 1101110111011101  

If we move all set bits to the right, we will get: 1101110111011101 -> 0000111111111111

How can I achieve this efficiently?

Below you can see how I tried to get the same result, but it's inefficient:

__mmask16 mask = 56797;  // mask: 1101110111011101  __m512i vbrdcast = _mm512_maskz_broadcastd_epi32(mask, _mm_set1_epi32(~0));  // vbrdcast: -1 0 -1 -1 -1 0 -1 -1 -1 0 -1 -1 -1 0 -1 -1  __m512i vcompress = _mm512_maskz_compress_epi32(mask, vbrdcast);  // vcompress:-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0   __mmask16 right_packed_mask =   _mm512_movepi32_mask(vcompress);     // right_packed_mask: 0000111111111111                           

What is the best way to do this?

https://stackoverflow.com/questions/67256047/avx512-how-to-move-all-set-bits-to-the-right April 26, 2021 at 12:59AM

没有评论:

发表评论