Jump to content

Barrel shifter: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
AnomieBOT (talk | contribs)
m Dating maintenance tags: {{Refimprove}} {{Cn}}
Is it incorrectly in the Category:Unary operations? In comment with it "bits.shiftLeftByOneBit()". A barrel shifter is inherently unary, and I believe there are simpler structures for shift by always 1 (or e.g. always 4?), but this logic could still implement it. So I clarify in text. This is likely never done for AGU in practice, but could in theory. A better example might be old CPUs such as 6502 with only shift amounts with no count, for unary operations, but I very much doubt they used.
Line 2: Line 2:
{{Refimprove|date=November 2020}}
{{Refimprove|date=November 2020}}


A ''' barrel shifter''' is a [[digital circuit]] that can [[Bit shift|shift]] a [[Word (data type)|data word]] by a specified number of [[bit]]s without the use of any [[sequential logic]], only pure [[combinational logic]]. One way to implement it is as a sequence of [[multiplexer]]s where the output of one multiplexer is connected to the input of the next multiplexer in a way that depends on the shift distance. A barrel shifter is often used to shift and rotate n-bits in modern microprocessors,{{cn|date=November 2020}} typically within a single [[clock cycle]].
A '''barrel shifter''' is a [[digital circuit]] that can [[bit shift|shift]] a [[word (data type)|data word]] by a specified number of [[bit]]s without the use of any [[sequential logic]], only pure [[combinational logic]], i.e. it inherently provides a [[binary operation]]. It can however also be used to implement [[unary operation]]s, such as [[logical shift left]] (e.g. for [[address generation unit]]), by a fixed amount. One way to implement a barrel shifter is as a sequence of [[multiplexer]]s where the output of one multiplexer is connected to the input of the next multiplexer in a way that depends on the shift distance. A barrel shifter is often used to shift and rotate n-bits in modern microprocessors,{{cn|date=November 2020}} typically within a single [[clock cycle]].


For example, take 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 [[microprocessor]]s (alongside the [[Arithmetic logic unit|ALU]]).
For example, take 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 [[microprocessor]]s (alongside the [[Arithmetic logic unit|ALU]]).
Line 51: Line 51:


==See also==
==See also==
*[[Circular shift]]
* [[Circular shift]]


==References==
==References==

Revision as of 15:52, 17 December 2020

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

A barrel shifter is a digital circuit that can shift a data word by a specified number of bits without the use of any sequential logic, only pure combinational logic, i.e. it inherently provides a binary operation. It can however also be used to implement unary operations, such as logical shift left (e.g. for address generation unit), by a fixed amount. 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. A barrel shifter is often used to shift and rotate n-bits in modern microprocessors,[citation needed] typically within a single clock cycle.

For example, take 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

A barrel shifter is often implemented as a cascade of parallel 2×1 multiplexers. 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   << 4, if S[2] == 1
 int2  = int1     , if S[1] == 0
       = int1 << 2, if S[1] == 1
 OUT   = int2     , if S[0] == 0
       = int2 << 1, if S[0] == 1

Larger barrel shifters have additional stages.

Cost

The number of multiplexers required for an n-bit word is .[1] Five common word sizes and the number of multiplexers needed are listed below:

  • 128-bit —
  • 64-bit —
  • 32-bit —
  • 16-bit —
  • 8-bit —

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

  • 32-bit: from 18 FO4 to 14 FO4[2]

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. If a simple shifter were used, shifting by n bit positions would require n clock cycles.[citation needed]

See also

References

  1. ^ Kroening, Daniel; Strichman, Ofer (2008). Decision Procedures. Springer. p. 159. ISBN 978-3-540-74104-6.
  2. ^ Wang, David T. (2002-08-15). "Revisiting the FO4 Metric". Retrieved 2016-05-19.

Further reading

This article is based on material taken from the Free On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the "relicensing" terms of the GFDL, version 1.3 or later.