Barrel shifter


A Barrel Shifter is a logic component that perform shift or rotate operations. Barrel shifters are applicable for digital signal processors and processors. This component design is for a natural size (4,8,16…) barrel shifters that perform shift right logical, rotate right, shift left logical, and rotate left operations depending on the instantiation parameters. The left and right operation is implemented through inversion of the input and output vectors, so the basic multiplexing function can perform both operations. The number of multiplexing stages is relative to the width of the input vector.

Block diagram



barrel shifter block diagram

  • shift right logical, rotate right, shift left logical, and rotate left operations
  • Multiplexor (mux) based logarithmic barrel shifter implementation
  • Number of mux stages relative to input vector size
  • Combinational logic only, no sampling stages
  • Parameterized data input width on natural size (4,8,16,32…)
  • Parameterized operation type, selecting Rotate or shift
  • Parameterized direction, selecting left or write rotation


  • Verified RTL code
  • Access to detailed design documentation
  • 1 year support and customization service.


parameters table


Valid values




Barrel shifter natural size width



Rotation enable:

0 – for logic shift

1 – for rotate



Rotation/shift direction:

0 – left rotation/shift

1 – right rotation/shift

interface table

Signal name




Input [DATA_SIZE-1:0]

Data in vector


Input [log2(DATA_SIZE)-1:0]

Selects the number of shift/rotate bits. The maximal shift is width of the input vector – 1


Output [DATA_SIZE-1:0]

Data out vector

Barrel shifter functionality

The Barrel shifter component is applicable for cases where an efficient logical shift or rotate with a selectable shift amount is required. The component supports either shift or rotate operations depending on the ROTATION parameter. When the ROTATION parameter is set to 1, the barrel shifter performs rotation and when it is set to 0, a logical shift operation is performed, shifting logical 0 in. the DIRECTION parameter determines if the barrel shifter performs a left or right shift. Setting the DIRECTION parameter to 0 would result in a left shift and setting it to 2 would result in a right shift.

The following table summarizes the operation modes of the barrel shifter:





shift left logical



Logic shift left, 0 is shifted through the rightmost (LSB) bit.

rotate left



Left rotate, the rightmost bit is shifted back in from the right.

shift right logical



Logical shift right, 0 is shifted through the leftmost (MSB) bit

rotate right



Right rotate, the rightmost bit is shifted back in from the left.

Logarithmic shift and rotate

The shift or rotate operation is done in stages where each stage performs a shift or rotate operation of a different size. For example, a 5 bits shift operation would result in a shift of 4 and a shift of 1 where the stage that performs the shift of 2 would not do any shift. The select vector binary encoding is actually to enable the different stages of the barrel shifter.

barrel shifter stages

rotate and shift example


Logical shift operation

The logical shift operation inserts 0 value for each shift operation. The input vector is shifted in the selected direction according to the number of bits in the select indication.

Rotate operation

The rotate operation is a shift where the bit which is shifted out of the vector MSB  is inserted at its LSB.


Rotate and shift direction

The direction of the rotate and shift operation is implemented by reversing the input and output vector. Using this method allows for the shift or rotate logic to be kept simple, performing only right shift. For a left shift, the input vector is reversed at the input, goes through the shift logic which performs a right shift according to the select input and at the output stage, it is reversed again, resulting in a left shift of the vector.


Test Items

the below table summarizes the test items that were checked for the barrel shifter

some of the items are relevant only for specific parameter setting.

Item name


Overflow shift operation

Shift left where the MSB bits are shifted out.

Underflow shift operation

Shift right where the LSB bits are shifted out.

All shift options

Shift right and left through all select options

Shift 0

Test that shift of 0 does not impact the output vector

Overflow rotate operation

Rotate left where the MSB bits are shifted out and inserted from the LSB.

Underflow rotate operation

Rotate right where the LSB bits are shifted out and inserted from the MSB.

All rotate options

Rotate right and left through all select options

Rotate 0

Test that rotate of 0 does not impact the output vector




Adding a sampling stage

The barrel shifter can be integrated into a pipeline or sampled for timing within the design. The natural locations for added sampling are at the output of the bit reversal logic and the output of the shift and rotate logic.