Back to main page

Code generator for bit permutations


Back to main page


Please enter an index vector (0..31 or $0..$1f, or * for don't care):

origin base indexes refer

Options: Allow using cycles

Actual connections

Best method found: Bit group moving (about 43 cycles on superscalar processors):

x = (x & 0x00800000)
  | ((x & 0x08000000) << 1)
  | ((x & 0x00000840) << 3)
  | ((x & 0x00000080) << 4)
  | ((x & 0x00010000) << 5)
  | ((x & 0x20000000) >> 26)
  | ((x & 0x00020000) << 8)
  | ((x & 0x00004000) << 10)
  | ((x & 0x80200000) >> 21)
  | ((x & 0x01000000) >> 20)
  | ((x & 0x00002008) << 13)
  | ((x & 0x40000000) >> 18)
  | ((x & 0x00000020) << 15)
  | rol(x & 0x10400005, 17)
  | ((x & 0x00001000) << 18)
  | ((x & 0x00080000) >> 13)
  | ((x & 0x00000100) << 21)
  | ((x & 0x02048000) >> 10)
  | ((x & 0x00000010) << 23)
  | ((x & 0x00000600) >> 8)
  | ((x & 0x04000000) >> 4)
  | rol(x & 0x00100002, 30);

See documentation to bit_permute_step, bit_permute_step_simple, rol.
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.
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: info@sirrida.de


You may bookmark this page as http://programming.sirrida.de?calcperm.php.
Last change: 2014-07-06