Microprocessor Design
Back To Introduction
The Barrel Shifter
by
James Adrian
      Important operations and corresponding instructions are made possible by the barrel shifter. It facilitates shift instructions and roll instructions.

      A roll instruction which might be called roll left 3 moves the bits of a word or byte three bit locations to the left. Instead of letting three bits disappear from the word or byte off the left end, it moves those bits in order into the right side of the word or byte. A roll right 1 instruction would call for moving each the bits one bit location to the right except that the rightmost bit is moved to the left end of the word or byte. Instead making these shifts of location 1 bit at a time, the barrel shifter takes the same amount of time for rolling any bit distance.

      For data words four bits wide (often called a nibble), the barrel shifter is comprised of 16 tri-state buffers arranged in a four-by-four matrix. The figure below shows this, but does not show all of the enable connections.


750


      Each of the four bits of data are entered at the head of a column of inputs. They each provide the inputs to four tri-state buffers that are arranged in a vertical column.

      Each row produces an output on the right. Since four tri-state buffer outputs are connected together in any give row, only one of those four outputs can be on (producing an output) at any given time.

      The enable inputs are on the left. During any roll instruction, only one of the enable inputs is active. The active enable input is selected by a two-to-four decoder (not shown).

      The E3 input has a signal path that is shown in green. This input enables four of the sixteen tri-state buffers in such a way as to select one buffer from each column and, at the same time, one buffer from each row. It enables input bit In0 to be connected to Out3, In1 to be connected to Out0, In2 to be connected to Out 1, and In3 to be connected to Out2.

      Here is the effect of that enable signal:

E3 Green
          In Bits       0   1   2   3
          Out Bits      3   0   1   2

      The figure below shows the path enabled by E2 in red.


750


      Here is the effect of that enable signal:

E2 Red
          In Bits       0   1   2   3
          Out Bits      2   3   0   1

      The figure below shows the path enabled by E1 in blue.


750


      Here is the effect of that enable signal:

E1 Blue
          In Bits       0   1   2   3
          Out Bits      1   2   3   0

      The figure below shows the path enabled by E0 in purple.


750


      Here is the effect of that enable signal:

E0 Purple
          In Bits       0   1   2   3
          Out Bits      0   1   2   3

      The connections are combined to show the complete barrel shifter in the figure below.


750


      E0 does not transform the order of bits. There is such an enable result in any barrel shifter regardless of data width. It may be used to pass data from the ALU output through the barrel shifter unmodified. This makes it convenient to use a barrel shifter in series with the ALU.

      The number of tri-state buffers in a barrel shifter is the square of the data width. Eight-bit data requires 64 buffers. If the data is 64 bits wide, the number of tri-state buffer required 4096.

      Shift operations are somewhat different from roll operations. Here is an illustration of a shift right by two bits:

          In Bits       1   1   1   1
          Out Bits      0   0   1   1

      Two bits disappear on the right as zeros are filled in on the left. (The data in this case was 1111. Earlier, base ten numbers indicated the bit locations rather than the value of the bits.) Shifting left would have an opposite effect. If 0011 were shifted two bits to the left, the result would be 1100.

      One way that a barrel shifter can be made to produce this kind of result is to anticipate which and how many bits will be lost and where the new zeroes will appear. This information can be surmised from the direction and magnitude of the shift. If a left shift is to relocate the bits by three bit locations, it is known that three bits on the left will be lost. If they are replaced by zeroes before going into the barrel shifter, those zeroes will be rolled into the right-hand bit locations. To do this only requires a logical AND of the original data with a number appropriate to the instruction. The barrel shifter is very often placed at the output of the ALU.

      In your investigations concerning alternate designs it is important to compare them for their total propagation delay.


Contact

      https://www.futurebeacon.com/jamesadrian.htm