Best method found: Bit group moving (about 38 cycles on superscalar processors):
x = ((x & 0x08000000) << 1) | ((x & 0x00000100) << 2) | ((x & 0x00210000) << 3) | ((x & 0x04000200) << 5) | ((x & 0x00100000) << 7) | rol(x & 0x40000080, 8) | ((x & 0x00000001) << 9) | ((x & 0x00800000) >> 21) | ((x & 0x00026050) << 12) | ((x & 0x00400000) >> 18) | ((x & 0x10000000) >> 15) | ((x & 0x02000000) >> 14) | rol(x & 0x00040008, 19) | ((x & 0x20080000) >> 12) | rol(x & 0x00001004, 21) | ((x & 0x80000400) >> 10) | ((x & 0x01000000) >> 4) | rol(x & 0x00008802, 29) | ((x & 0x00000020) >> 2);
See documentation to
pext and pdep can be emulated with compress_right and expand_right.
This result is not necessarily the best possible, but at least several methods have been challenged. The given cycles are only estimated and may vary significantly depending on the used processor. Thus, the selected method might not be the best one for your application. You can however influence the choice by using the options above.
See also some notes on the inner workings.
There is an even better calculator calcperm.* which is usable for various word sizes (Pascal and C++ sources).
Error reports, comments or questions? E-mail: email@example.com