Left and right shifts are often used for fast multiplication/division (by 2) and bit manipulation. Since they can be done so quickly in hardware, compliers will perform strength reduction to optimize code to take advantage of shifts.

Note that there are two types of right shifts:

  1. Logical right shift puts 0 in the MSB.
  2. Arithmetic right shift puts whatever the original MSB is. This preserves the sign of the integer value.

A simple shifter that moves by a constant bits can be implemented using just wires, but this is slow if we want to shift by bits (since we would need to run a 1-bit simple shifter times).

Barrel Shifter

The barrel shifter provides a faster way to shift by bits. We create multiple simple shifters with . Then, we use muxes to select the shifters that have bit in , effectively shifting by the powers of 2 that make up .