Dynamic bit shuffle using AVX-512

Suppose you want to rearrange the bits in a 64-bit word. This question was raised on Twitter, and the author provides a code snippet that reverses the bit order using a straightforward approach. However, there is a more efficient way to do it using AVX-512 instructions on recent Intel and AMD processors. By converting the word to a mask register, then to a 512-bit AVX-512 register, applying a shuffle, and converting back, the bit order can be reversed with fewer instructions. The author also suggests an even faster method using a dedicated instruction for bit shuffling. The code snippets and additional optimizations are provided.

https://lemire.me/blog/2023/06/29/dynamic-bit-shuffle-using-avx-512/

To top