ArticleslgStudy

computer science

Barrel shifter

Barrel shifter is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Barrel shifter rather than just read about it. In short: 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.

Barrel shifter — main illustration
Barrel shifter — illustration

Key takeaways

  • Barrel shifter belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Barrel shifter to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Barrel shifter from memory before moving on to harder problems.

Reference excerpt

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 << 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 The number of multiplexers required for an n-bit word is nlog2n. Five common word sizes and the number of multiplexers needed are listed below:

128-bit — 128×log2128=128×7=896 64-bit — 64×log264=64×6=384 32-bit — 32×log232=32×5=160 16-bit — 16×log216=16×4=64 8-bit — 8×log28=8×3=24 Cost of critical path in FO4 (estimated, without wire delay):

32-bit: from 18 FO4 to 14 FO4

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.

See also Circular shift

References

Further reading Kroening, Daniel; Strichman, Ofer (2008). Decision Procedures. Springer. ISBN 978-3-540-74104-6.

External links Barrel-shifter (8 bit), University of Hamburg Implementing Barrel Shifters Using Multipliers (Paul Gigliotti, 2004-08-17)

Illustrations

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

Worked examples

Example 1 — a first encounter with Barrel shifter

Start with the simplest possible case. Write down what Barrel shifter claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Barrel shifter before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Barrel shifter ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Barrel shifter

In research
Barrel shifter appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Barrel shifter in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Barrel shifter is common in secondary-school and first-year university syllabi. It links to neighbouring topics Binary arithmetic, Binary operations, Computer arithmetic, so understanding it makes those chapters shorter.
In everyday life
Look for Barrel shifter outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Barrel shifter” →

How to study Barrel shifter in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Barrel shifter means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Barrel shifter out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Barrel shifter in simple terms?

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 rot…

Why does Barrel shifter matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Barrel shifter?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Barrel shifter.

Tags

  • Binary arithmetic
  • Binary operations
  • Computer arithmetic
  • Digital circuits
  • Unary operations

Keep exploring