Understanding Barrel Shifting in VHDL: A 16-bit Implementation

  • Thread starter Thread starter EvLer
  • Start date Start date
AI Thread Summary
A barrel shifter is a combinational logic device that shifts input data in stages, allowing for flexible bit manipulation. In this implementation, there are four stages, each capable of shifting by 1, 2, 4, or 8 bits, respectively. By enabling specific stages using multiplexers, any shift amount from 0 to 15 bits can be achieved. For example, to shift left by 10 bits, stages 2 and 4 would be activated, resulting in the input being shifted in two steps. The design primarily consists of multiplexers and interconnected shifters, confirming that the maximum shift is indeed 15 bits.
EvLer
Messages
454
Reaction score
0

Homework Statement


A, and B both are 16 bits wide; A is entity to shift and B is by how much;
we are supposed to implement a BARREL shifter. And here's the explanation (which does not make much sense to me, esp. the example) given in lab document:

A barrel shifter is a combinational logic device that incrementally shifts in stages. In our barrel shifter, we will have 4 stages. Each stage can choose to shift or not to shift, giving any total shift amount. For example, to shift an input by 9, stages one and four will shift 1 time and 8 times, respectively. Stages two and three will not shift. Notice that the binary number 9 is "1001". How convenient that the fourth bit and the first bit are 1 and the second and the third bits are 0.

The Attempt at a Solution


ok, I know how to write the shift register, a regular without the "barrel", and after some googling, I found that barrel basically shifts by the amounts of bits specified at once. If someone could explain how the description from the lab document makes sense that is all i need to understand... thanks in advance.
 
Physics news on Phys.org
I presume you have four shifters wired up in series, the output of one connected to the input of the next. Each shifter is also followed by a mux, so that you can bypass each shifter if you do not wish to use it.

The first shifter shifts only one bit position. If the value put into the first shifter is 10010010, you'll get out 00100100.

The second shifter shifts two bit positions. If you put in 10010010, you'll get out 01001000.

The third shifter shifts four bit positions, and the fourth shifter shifts eight bit positions.

By "enabling" some combination of these individual shifters (i.e. by not bypassing them with a mux), any total shift from zero bits to fifteen bits is possible. Note that this device is really nothing more than muxes and wires.

- Warren
 
Last edited:
ok, that makes a bit more sense...
so, just to make sure, let's say he wants us to shift left by 10, which is "1010" then shifter 2 and 4 are enabled, so I will shift by 2 first and then by 8, right?
So if the input is "1010 0111 0001"
then I will have after shifter 2: "1001 1100 0100"
then after shifter 4: "0100 0000 0000 0000"

edit: one more thing: it seems like I will be able to shift only 15 times is that how it's supposed to work out?:rolleyes:

thanks sooo much...
 
Last edited:
that looks correct to me :smile:
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...
Back
Top