‫Welcome to the barrel shifter explained lecture in this lecture I'll explain what Abair software is
‫and how we can implement one in VHDL barrel shift register Bearse a regular shift register a regular
‫shift register only shifts one bit per clock cycle and a center shift register will only shift left
‫or right.
‫You can also make a universal shift register where you can shift left or right based upon the input
‫and you can also have like a parallel load shift register where you can load all the bits at once or
‫a serial load shift register where you shift all the bits in.
‫The main thing to note with a standard shift register is that you can only every clock cycle you'll
‫make one shift whether it's left or right.
‫Now if we compare that to a barrel shifter Barish after allows you to shift an number of bits on a single
‫clock cycle and this end means that it's a configurable input on one clock cycle.
‫I can shift one bit.
‫I can shift two I can shift three for any arbitrary number of bits as long as However wide my register
‫is.
‫And this will happen on one clock cycle and you can also like to shift to the left or right just the
‫same.
‫Now the downside of the barrel shifter versus the regular shift register is that it will require slightly
‫more resources that moment however what you will gain is a speed factor if you want to shift say 8 bits
‫to the right with a center shift register.
‫It's going to take you eight clock cycles to get there with the barrel shift or you can do it in a single
‫clock cycle.
‫So in theory here and in reality are eight times faster.
‫And so that's where the advantage of the barrel shifter is a standard shift register comes in.
‫Now eight minutes you probably might not notice that.
‫But if you have a really large register a 64 bit 128 that registers even larger and you can perform
‫a 128 bit shift on one single clock cycle.
‫And so that's greatly useful and this is very powerful Let's take a look at an example of we have an
‫8 bit barrel shifter.
‫You'll see that we have our input which is seven down is zero meaning that it's eight minutes wide.
‫We have our select one down to zero two bits wide.
‫And then we have our shift to down to zero reset and clock line and then we have output.
‫So we look at a table we have the different time steps.
‫So if we want to go our time zero we have our input.
‫A certain bit.
‫8 bits wide and our select is equal to 3 which means that we want to do a load operation.
‫So we're going to take the bits that are on our input and put them in the register.
‫And these are register is what we're going to see on the output of our shift register.
‫And if we keep A.M.A. the time steps you can see that will do different operations on our on our select
‫input.
‫So our select is a zero.
‫That is a hold.
‫So on the whole we're not going to do anything we're just going to keep the same same there so you can
‫say a register doesn't change it just now has a value that was on our template and then our select becomes
‫a 2.
‫Now our register is shifted left to the value whatever shift value is which is the value of three minute
‫shift left three three bits and if you just follow through you'll see our next one we're going to shift
‫right.
‫The amount that is on our shift input which is a 4.
‫So we're going to shift right for bits and you'll see that the register on the next step has that implementation
‫has been shifted right for bits and if he falls the time steps are we have a shift right by one bit
‫shift left by two bits and then our select is a zero.
‫And our shift is zero which is once a zero we know the hold.
‫So now we're just holding that output.
‫And that's kind of the huge thing with the barrel shifter is that if I wanted to do any one of these
‫other operations where on time to I have a shift of three it's going to take three clock cycles to do
‫that.
‫We're on the barrel shifter one clock cycle.
‫I now have that output.
‫And so you gain a lot of speed but the con is that it takes a few more resources to implement but you
‫do gain a lot more in speed.
‫So let's take a look at how would you design the barrel shifter.
‫If we take a block diagram just to show kind of how the barrel shifter could be design you would have
‫a process we would call a shift left and a process will of course shift right.
‫And then our process would point output.
‫So every time the shift amount changes you are going to shift left and shift right that amount and that
‫process is going to continue to be happening so soon that changed my shift about my shift left and my
‫shift right.
‫We're going to change.
‫And then my output when I see a clock based on my select if I'm selecting my shift right or shift left
‫I'm just going to select the output that s r red or s l Reg value.
‫And so in theory what we're doing every single clock cycle before that clock cycle occurs.
‫We're shifting left and shifting right at the same exact time based upon the shift amount input and
‫then the clock cycle occurs.
‫We're going to make the decision with the mux inside of our process or out the process and decide am
‫my -- the shift left register or the shift right register and that's how we can make it happen
‫on a single clock cycle before that clock cycle occurs.
‫We're already doing the left shifting and the right shifting and based on the input we're giving it
‫we're going to say OK we're selecting a shift left or shift right because both those outputs have already
‫been shifted left or right the number of bits that we have selected.
‫Now the understanding of how the barracks filter works let's get started implementing one on your development
‫board.