Barrel Shifter
   HOME

TheInfoList



OR:

A barrel shifter is a
digital circuit In theoretical computer science, a circuit is a model of computation in which input values proceed through a sequence of gates, each of which computes a function. Circuits of this kind provide a generalization of Boolean circuits and a mathematica ...
that can shift a data word by a specified number of
bit The bit is the most basic unit of information in computing and digital communication. The name is a portmanteau of binary digit. The bit represents a logical state with one of two possible values. These values are most commonly represented as ...
s without the use of any
sequential logic In automata theory, sequential logic is a type of logic circuit whose output depends on the present value of its input signals and on the sequence of past inputs, the input history. This is in contrast to '' combinational logic'', whose output i ...
, only pure
combinational logic In automata theory, combinational logic (also referred to as time-independent logic) is a type of digital logic that is implemented by Boolean circuits, where the output is a pure function of the present input only. This is in contrast to sequ ...
, i.e. it inherently provides a
binary operation In mathematics, a binary operation or dyadic operation is a rule for combining two elements (called operands) to produce another element. More formally, a binary operation is an operation of arity two. More specifically, a binary operation ...
. It can however in theory also be used to implement
unary operation In mathematics, a unary operation is an operation with only one operand, i.e. a single input. This is in contrast to ''binary operations'', which use two operands. An example is any function , where is a set; the function is a unary operation ...
s, such as logical shift left, in cases where limited by a fixed amount (e.g. for
address generation unit The address generation unit (AGU), sometimes also called address computation unit (ACU), is an execution unit inside central processing units (CPUs) that calculates addresses used by the CPU to access main memory. By having address calculations ...
). One way to implement a barrel shifter is as a sequence of
multiplexer In electronics, a multiplexer (or mux; spelled sometimes as multiplexor), also known as a data selector, is a device that selects between several Analog signal, analog or Digital signal (electronics), digital input signals and forwards the sel ...
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, typically within a single
clock cycle In electronics and especially synchronous digital circuits, a clock signal (historically also known as ''logic beat'') is an electronic logic signal (voltage or current) which oscillates between a high and a low state at a constant frequency and ...
. 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 A microprocessor is a computer processor (computing), processor for which the data processing logic and control is included on a single integrated circuit (IC), or a small number of ICs. The microprocessor contains the arithmetic, logic, a ...
s (alongside the ALU).


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 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 and S This signal is then shifted by another multiplexer, which is controlled by S int1 = IN , if S

0 = IN << 4, if S

1 int2 = int1 , if S

0 = int1 << 2, if S

1 OUT = int2 , if S

0 = int2 << 1, if S

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 n\log_2 n. Five common
word size In computing, a word is any processor design's natural unit of data. A word is a fixed-sized datum handled as a unit by the instruction set or the hardware of the processor. The number of bits or digits in a word (the ''word size'', ''word wid ...
s and the number of multiplexers needed are listed below: * 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


Uses

A common usage of a barrel shifter is in the hardware implementation of
floating-point arithmetic In computing, floating-point arithmetic (FP) is arithmetic on subsets of real numbers formed by a ''significand'' (a Sign (mathematics), signed sequence of a fixed number of digits in some Radix, base) multiplied by an integer power of that ba ...
. For a floating-point add or subtract operation, the
significand The significand (also coefficient, sometimes argument, or more ambiguously mantissa, fraction, or characteristic) is the first (left) part of a number in scientific notation or related concepts in floating-point representation, consisting of its s ...
s of the two numbers must be aligned, which requires shifting the smaller number to the right, increasing its
exponent In mathematics, exponentiation, denoted , is an operation involving two numbers: the ''base'', , and the ''exponent'' or ''power'', . When is a positive integer, exponentiation corresponds to repeated multiplication of the base: that is, i ...
, 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 In combinatorial mathematics, a circular shift is the operation of rearranging the entries in a tuple, either by moving the final entry to the first position, while shifting all other entries to the next position, or by performing the inverse ope ...


References


Further reading

*


External links


Barrel-shifter (8 bit)
University of Hamburg The University of Hamburg (, also referred to as UHH) is a public university, public research university in Hamburg, Germany. It was founded on 28 March 1919 by combining the previous General Lecture System ('':de:Allgemeines Vorlesungswesen, ...

Implementing Barrel Shifters Using Multipliers
(Paul Gigliotti, 2004-08-17) {{CPU technologies Digital circuits Binary arithmetic Computer arithmetic Unary operations Binary operations