Barrel shifter (source code)

= Barrel shifter

A <barrel shifter> moves a <machine word> by a variable number of <bit> positions through a bounded-depth <combinational logic> circuit. For a $2^k$-bit <machine word>, cascade $k$ banks of <multiplexers> selecting optional shifts of $1,2,\ldots,2^{k-1}$. The binary shift-amount <bits> select the stages; the chosen distances add. Logical shifts fill vacated positions with zero, whereas <bit rotations> reconnect the discarded positions. A 32-bit logical <barrel shifter> can use five banks of 32 two-input <multiplexers>.