When to use it
When you need to shift or rotate by a runtime amount in one clock, a normalizer, a float aligner, a bit extractor, you can't ripple one place at a time. A barrel shifter does the whole shift combinationally.
How it works
Build it from log2(W) stages, each controlled by one bit of the shift amount: stage i
either passes its input through or shifts it by 2^i. Chain them and any shift 0 to W-1
falls out in a single (deep but fast) cone of logic. Writing x >> amt in Verilog
synthesizes to exactly this, the recipe just shows the structure.
Gotchas
- This one shifts right, logical (zeros in). For arithmetic shift, feed the sign bit in; for rotate, OR the two directions together.
- It's all combinational, so it can become your critical path. Register the output (or pipeline the stages) if the shift is wide.