In many cases most designs only need simple shift registers that shift the
input one bit every clock cycle. But what if one wants to shift or rotate data an arbitrary number of bits in a combinatorial design? To shift data an arbitrary number of bits a barrel shifter is used.
This document gives a brief overview of an efficient generic barrel shift implementation that rotates input data to the left. VHDL code is provided for the barrel shifter package declaration, implementation and test bench.
After putting some thought into the design of a barrel shifter it is clear that some sort of multiplexer circuitry is required to select how the input bits route to the output bits. A naive method of implementing a barrel shifter would be to use N (where N is the number of input bits) parallel N-to-1 multiplexers, one multiplexer that multiplexes all inputs into one of the outputs. This would create an equivalent N*N to N multiplexer, which would use significant hardware resources (multiplexer input grows in O(N2).
A more efficient implementation is possible by creating a hierarchy of multiplexers. For an 8 bit rotate component the multiplexers would be constructed as follows:
Using this approach input data can be shifted an arbitrary number of bits. The number of multiplexers used for an 8 bit rotate component is as follows:
Note that this design has only been tested with the Xilinx ISE and Modelsim tools.
Package declaration: barrel_shift_pkg.vhd
Implementation: barrel_shift.vhd
Test bench: barrel_shift_tb.vhd
Last updated: March 25, 2003