Jump to content

Barrel shifter: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Revert vandalism from 39.32.234.244
Citation bot (talk | contribs)
Alter: title, template type. Add: isbn, chapter-url, pages, chapter, authors 1-1. Removed or converted URL. Removed parameters. Some additions/deletions were parameter name changes. | Use this bot. Report bugs. | Suggested by Dominic3203 | Category:Binary arithmetic | #UCB_Category 98/100
 
(37 intermediate revisions by 29 users not shown)
Line 1: Line 1:
{{Short description|Digital circuit found in computers}}
[[File:crossbar barrel shifter.svg|thumb|250px|Schematic of a 4-bit crossbar barrel shifter. ''x'' denotes input bits and ''y'' denotes output bits.]]
[[File:crossbar barrel shifter.svg|thumb|250px|Schematic of a 4-bit crossbar barrel shifter. 'x' denotes input bits and ''y'' denotes output bits.]]
{{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 in one [[clock cycle]]. It can be implemented as a sequence of [[multiplexer]]s (mux.), and in such an implementation the output of one mux is connected to the input of the next mux in a way that depends on the shift distance.
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 in theory also be used to implement [[unary operation]]s, such as [[logical shift left]], in cases where limited by a fixed amount (e.g. for [[address generation unit]]). 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,<ref>{{Cite book |last1=Abhilasha |last2=Sudharshan |last3=Anusha |first3=S.L. |chapter=Design and FPGA Implementation of High Performance 8-BIT Vedic Multiplier Using Reversible Logic Based Barrel Shifter |date=2015 |pages=991–999 |title=Proceedings of Second International Conference on Signal Processing, Image Processing and VLSI |chapter-url=http://dx.doi.org/10.3850/978-981-09-6200-5_vlsi-74 |location=Singapore |publisher=Research Publishing Services |doi=10.3850/978-981-09-6200-5_vlsi-74|isbn=978-981-09-6200-5 }}</ref> 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 7: Line 9:
== Implementation ==
== Implementation ==


The very 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, however, is only incurred when the shift count changes). These crossbar shifters require however ''n<sup>2</sup>'' 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'' x log ''n''; the propagation delay is however larger, growing with log ''n'' (instead of being constant as with the crossbar shifter).
A barrel shifter is often implemented as a cascade of parallel 2×1 multiplexers. For a 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]:

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
int1 = IN , if S[2] == 0
Line 17: Line 21:


Larger barrel shifters have additional stages.
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 ==
== Cost ==


The number of multiplexers required for an ''n''-bit word is <math>\scriptstyle n\log_2n</math>.<ref>{{cite book |last=Kroening |first=D. | last2=Strichman |first2=Ofer |year=2008 |title=Decision Procedures |publisher=Springer |quote=p.159.}}</ref> Five common [[word size]]s and the number of multiplexers needed are listed below:
The number of multiplexers required for an ''n''-bit word is <math>n\log_2 n</math>.<ref>{{cite book
| title=Decision Procedures

| first1=Daniel
* 128-bit &mdash; <math>\scriptstyle 128\times\log_2(128) = 128\times7 = 896</math>
| last1=Kroening
* 64-bit &mdash; <math>\scriptstyle 64\times\log_2(64) = 64\times6 = 384</math>
| first2=Ofer
* 32-bit &mdash; <math>\scriptstyle 32\times\log_2(32) = 32\times5 = 160</math>
| last2=Strichman
* 16-bit &mdash; <math>\scriptstyle 16\times\log_2(16) = 16\times4 = 64</math>
| publisher=[[Springer Science+Business Media|Springer]]
* 8-bit &mdash; <math>\scriptstyle 8\times\log_2(8) = 8\times3 = 24</math>
| year=2008
| page=159
| isbn=978-3-540-74104-6}}</ref> Five common [[word size]]s and the number of multiplexers needed are listed below:
* 128-bit <math>128 \times \log_2 128 = 128 \times 7 = 896</math>
* 64-bit <math>64 \times \log_2 64 = 64 \times 6 = 384</math>
* 32-bit <math>32 \times \log_2 32 = 32 \times 5 = 160</math>
* 16-bit <math>16 \times \log_2 16 = 16 \times 4 = 64</math>
* 8-bit <math>8 \times \log_2 8 = 8 \times 3 = 24</math>


Cost of critical path in [[FO4]] (estimated, without wire delay):
Cost of critical path in [[FO4]] (estimated, without wire delay):
* 32-bit: from 18 FO4 to 14 FO4<ref>http://www.realworldtech.com/page.cfm?ArticleID=RWT081502231107&p=4</ref>
* 32-bit: from 18 FO4 to 14 FO4<ref>{{cite web
| url=http://www.realworldtech.com/fo4-metric/4/
| title=Revisiting the FO4 Metric
| first=David T.
| last=Wang
| date=2002-08-15
| access-date=2016-05-19}}</ref>


== Uses ==
== 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 [[significand]]s 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.
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 [[significand]]s 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.


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


==References==
==References==

{{reflist}}
{{reflist}}

==External links==
<!--*[http://answers.google.com/answers/threadview?id=388350 Google Answers] has a good explanation, and collection of links-->
*[http://tams-www.informatik.uni-hamburg.de/applets/hades/webdemos/10-gates/60-barrel/shifter8.html University of Hamburg] for a useful Java Barrel shifter.
*[http://www.xilinx.com/support/documentation/application_notes/xapp195.pdf Xilinx Application Note] Implementation of Barrel shifter using Xilinx FPGAs.


==Further reading==
==Further reading==
* {{cite book
*{{cite book |first=Daniel |last=Kroening |first2=Ofer |last2=Strichman |title=Decision Procedures |location= |publisher=Springer |year=2008 |isbn=978-3-540-74104-6 }}
| title=Decision Procedures
| first1=Daniel
| last1=Kroening
| first2=Ofer
| last2=Strichman
| publisher=[[Springer Science+Business Media|Springer]]
| year=2008
| isbn=978-3-540-74104-6}}


==External links==
{{FOLDOC}}
* [https://tams.informatik.uni-hamburg.de/applets/hades/webdemos/10-gates/60-barrel/shifter8.html Barrel-shifter (8 bit)], [[University of Hamburg]]
* [http://www.xilinx.com/support/documentation/application_notes/xapp195.pdf Implementing Barrel Shifters Using Multipliers] (Paul Gigliotti, 2004-08-17)


{{CPU technologies}}
{{CPU technologies}}
Line 57: Line 81:
[[Category:Binary arithmetic]]
[[Category:Binary arithmetic]]
[[Category:Computer arithmetic]]
[[Category:Computer arithmetic]]
[[Category:Unary operations]]<!-- bits.shiftLeftByOneBit() -->
[[Category:Binary operations]]<!-- bits.shiftLeftBy(n bits) -->

Latest revision as of 05:04, 2 November 2024

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 in theory also be used to implement unary operations, such as logical shift left, in cases where limited by a fixed amount (e.g. for address generation unit). 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,[1] 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

[edit]

The very 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, however, 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 x log n; the propagation delay is however 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   << 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.

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

Cost

[edit]

The number of multiplexers required for an n-bit word is .[2] 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[3]

Uses

[edit]

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.

See also

[edit]

References

[edit]
  1. ^ Abhilasha; Sudharshan; Anusha, S.L. (2015). "Design and FPGA Implementation of High Performance 8-BIT Vedic Multiplier Using Reversible Logic Based Barrel Shifter". Proceedings of Second International Conference on Signal Processing, Image Processing and VLSI. Singapore: Research Publishing Services. pp. 991–999. doi:10.3850/978-981-09-6200-5_vlsi-74. ISBN 978-981-09-6200-5.
  2. ^ Kroening, Daniel; Strichman, Ofer (2008). Decision Procedures. Springer. p. 159. ISBN 978-3-540-74104-6.
  3. ^ Wang, David T. (2002-08-15). "Revisiting the FO4 Metric". Retrieved 2016-05-19.

Further reading

[edit]
[edit]