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 mathematical ...
that can shift a
data word In computing, a word is the natural unit of data used by a particular processor design. 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 si ...
by a specified number of
bit The bit is the most basic unit of information in computing and digital communications. 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 represente ...
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 or combinatorial logic) is a type of digital logic which is implemented by Boolean circuits, where the output is a pure function of the present input only. This i ...
, 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, an internal binary op ...
. It can however in theory also be used to implement
unary operation In mathematics, an 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 on ...
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 calculation ...
). 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 or digital input signals and forwards the selected input to a single output line. 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'') oscillates between a high and a low state and is used like a metronome to coordinate actions of digital circuits. A clock sig ...
. 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 where the data processing logic and control is included on a single integrated circuit, or a small number of integrated circuits. The microprocessor contains the arithmetic, logic, and control circu ...
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, 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 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 the natural unit of data used by a particular processor design. 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 si ...
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 In digital electronics, Fan-out of 4 is a measure of time used in digital CMOS technologies: the gate delay of a component with a fan-out of 4. Fan out = Cload / Cin, where :Cload = total MOS gate capacitance driven by the logic gate under con ...
(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 that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can be ...
. For a floating-point add or subtract operation, the
significand The significand (also mantissa or coefficient, sometimes also argument, or ambiguously fraction or characteristic) is part of a number in scientific notation or in floating-point representation, consisting of its significant digits. Depending on ...
s of the two numbers must be aligned, which requires shifting the smaller number to the right, increasing its
exponent Exponentiation is a mathematical operation, written as , involving two numbers, the '' base'' and the ''exponent'' or ''power'' , and pronounced as " (raised) to the (power of) ". When is a positive integer, exponentiation corresponds to re ...
, 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 oper ...


References


Further reading

*


External links


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

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