Barrel shifter
In computing, a barrel shifter is a combinational logic circuit that can shift a data word by a variable number of bit positions as specified by a binary input value. It may zero the vacated bits of the output word and thus perform a logical shift operation, or it may rotate all bits of the input word, either by design or as specified by one or more function select inputs.
A barrel shifter is often used to shift and rotate words in microprocessors, typically within a single clock cycle.
For example, consider a four-bit barrel shifter, with inputs A, B, C and D. The shifter can cycle the order of the bits ABCD as DABC, CDAB, or BCDA; in this case, no bits are lost. That is, it can shift all of the outputs up to three positions to the right. The barrel shifter has a variety of applications, including being a useful component in microprocessors.
Implementation
One way to implement a barrel shifter is as a sequence of multiplexers where the output of one multiplexer is connected to the input of the next multiplexer in a way that depends on the shift distance.The fastest shifters are implemented as full crossbars, in a manner similar to the 4-bit shifter depicted above, only larger. These incur the least delay, with the output always a single gate delay behind the input to be shifted. These crossbar shifters require however n2 gates for n-bit shifts. Because of this, the barrel shifter is often implemented as a cascade of parallel 2×1 multiplexers instead, which allows a large reduction in gate count, now growing only with n log n; the propagation delay is larger, growing with log n.
For an 8-bit barrel shifter, two intermediate signals are used which shifts by four and two bits, or passes the same data, based on the value of S and S. This signal is then shifted by another multiplexer, which is controlled by S:
int1 = IN , if S 0
= IN << 4, if S 1
int2 = int1 , if S 0
= int1 << 2, if S 1
OUT = int2 , if S 0
= int2 << 1, if S 1
Larger barrel shifters have additional stages.
The cascaded shifter has the further advantage over the full crossbar shifter of not requiring any decoding logic for the shift count.
Cost
The number of multiplexers required for an n-bit word is. Five common word sizes and the number of multiplexers needed are listed below:- 128-bit —
- 64-bit —
- 32-bit —
- 16-bit —
- 8-bit —
- 32-bit: from 18 FO4 to 14 FO4
Uses