Skip to content
Surf Wiki
Save to docs
general/digital-circuits

From Surf Wiki (app.surf) — the open knowledge base

Barrel shifter

Digital circuit found in computers

Barrel shifter

Digital circuit found in computers

Schematic of a 4-bit crossbar barrel shifter. 'x' denotes input bits and ''y'' denotes output bits.

In computing, a barrel shifter is a combinational logic circuit that can shift a data word by a variable number of bit positions as specified by a binary input value. It may zero the vacated bits of the output word and thus perform a logical shift operation (e.g., logical shift left), or it may rotate all bits of the input word, either by design or as specified by one or more function select inputs.

A barrel shifter is often used to shift and rotate words in microprocessors, typically within a single clock cycle.

For example, consider a four-bit barrel shifter, with inputs A, B, C and D. The shifter can cycle the order of the bits ABCD as DABC, CDAB, or BCDA; in this case, no bits are lost. That is, it can shift all of the outputs up to three positions to the right (and thus make any cyclic combination of A, B, C and D). The barrel shifter has a variety of applications, including being a useful component in microprocessors (alongside the ALU).

Implementation

One way to implement a barrel shifter is as a sequence of multiplexers where the output of one multiplexer is connected to the input of the next multiplexer in a way that depends on the shift distance.

The fastest shifters are implemented as full crossbars, in a manner similar to the 4-bit shifter depicted above, only larger. These incur the least delay, with the output always a single gate delay behind the input to be shifted (after allowing the small time needed for the shift count decoder to settle; this penalty is only incurred when the shift count changes). These crossbar shifters require however n2 gates for n-bit shifts. Because of this, the barrel shifter is often implemented as a cascade of parallel 2×1 multiplexers instead, which allows a large reduction in gate count, now growing only with n log n; the propagation delay is larger, growing with log n (instead of being constant as with the crossbar shifter).

For an 8-bit barrel shifter, two intermediate signals are used which shifts by four and two bits, or passes the same data, based on the value of S[2] and S[1]. This signal is then shifted by another multiplexer, which is controlled by S[0]:

int1 = IN , if S[2] == 0 = IN
int2 = int1 , if S[1] == 0 = int1 OUT = int2 , if S[0] == 0 = int2

Larger barrel shifters have additional stages.

The cascaded shifter has the further advantage over the full crossbar shifter of not requiring any decoding logic for the shift count.

Cost

The number of multiplexers required for an n-bit word is n\log_2 n.{{cite book

  • 128-bit — 128 \times \log_2 128 = 128 \times 7 = 896
  • 64-bit — 64 \times \log_2 64 = 64 \times 6 = 384
  • 32-bit — 32 \times \log_2 32 = 32 \times 5 = 160
  • 16-bit — 16 \times \log_2 16 = 16 \times 4 = 64
  • 8-bit — 8 \times \log_2 8 = 8 \times 3 = 24

Cost of critical path in FO4 (estimated, without wire delay):

  • 32-bit: from 18 FO4 to 14 FO4{{cite web | access-date=2016-05-19}}

Uses

A common usage of a barrel shifter is in the hardware implementation of floating-point arithmetic. For a floating-point add or subtract operation, the significands of the two numbers must be aligned, which requires shifting the smaller number to the right, increasing its exponent, until it matches the exponent of the larger number. This is done by subtracting the exponents and using the barrel shifter to shift the smaller number to the right by the difference, in one cycle.

References

References

  1. (2015). "Proceedings of Second International Conference on Signal Processing, Image Processing and VLSI". Research Publishing Services.
Info: Wikipedia Source

This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.

Want to explore this topic further?

Ask Mako anything about Barrel shifter — get instant answers, deeper analysis, and related topics.

Research with Mako

Free with your Surf account

Content sourced from Wikipedia, available under CC BY-SA 4.0.

This content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.

Report