A barrel shifter is a digital circuit that can shift a data word by a specified number of bits without the use of any sequential logic, only pure combinational logic. One way to implement it 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. A barrel shifter is often used to shift and rotate n-bits in modern microprocessors, typically within a single clock cycle.
For example, take 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 (and thus make any cyclic combination of A, B, C and D). The barrel shifter has a variety of applications, including being a useful component in microprocessors (alongside the ALU).
A barrel shifter is often implemented as a cascade of parallel 2×1 multiplexers. 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 number of multiplexers required for an n-bit word is [math]n\log_2 n[/math]. Five common word sizes and the number of multiplexers needed are listed below:
- 128-bit — [math]128 \times \log_2 128 = 128 \times 7 = 896[/math]
- 64-bit — [math]64 \times \log_2 64 = 64 \times 6 = 384[/math]
- 32-bit — [math]32 \times \log_2 32 = 32 \times 5 = 160[/math]
- 16-bit — [math]16 \times \log_2 16 = 16 \times 4 = 64[/math]
- 8-bit — [math]8 \times \log_2 8 = 8 \times 3 = 24[/math]
Cost of critical path in FO4 (estimated, without wire delay):
- 32-bit: from 18 FO4 to 14 FO4
A common usage of a barrel shifter is in the hardware implementation of floating-point arithmetic. For a floating-point add or subtract operation, the significands of the two numbers must be aligned, which requires shifting the smaller number to the right, increasing its exponent, until it matches the exponent of the larger number. This is done by subtracting the exponents and using the barrel shifter to shift the smaller number to the right by the difference, in one cycle. If a simple shifter were used, shifting by n bit positions would require n clock cycles.
- Barrel-shifter (8 bit), University of Hamburg
- Implementing Barrel Shifters Using Multipliers (Paul Gigliotti, 2004-08-17)
Original source: https://en.wikipedia.org/wiki/ Barrel shifter. Read more