Salta al contenuto
Note per Studenti Shift Registers, Shifters and Multipliers Report

Shift Registers, Shifters and Multipliers

In questa pagina 4
In questa pagina 3

Together with the adder (AddersHalf adder and full adder, generate-propagate-delete decomposition, the ripple-carry adder and its linear worst-case delay, the adder-subtractor, and the fast structures carry-lookahead, carry-bypass, carry-select and square-root carry-select with their delay formulas and optimal block sizes.Adders →), these are the other basic circuits of an arithmetic-logic unit (Arithmetic Logic UnitRole of the ALU, its inputs and the N Z C V flags, the 1-bit ALU built from AND, OR, a full adder and a multiplexer, the N-bit ALU with subtraction, NOR, set-less-than, zero and overflow detection, comparators, bus sharing with tri-state outputs, and the other computation units.Arithmetic Logic Unit →).

Shift register

Definition (shift register). A cascade of NN D registers with the same clock: the output of each is the input of the next, so at every clock edge the data advances by one position. The first register receives the serial input; the last gives the serial output.

Example. 4 bits, starting at 00000000, serial input 1,0,1,11,0,1,1 entering from the right (shift left): 0000→0001→0010→0101→10110000\to0001\to0010\to0101\to1011. (Entering from the left and shifting right: 0000→1000→0100→1010→11010000\to1000\to0100\to1010\to1101.)

Hold constraint. Two registers are directly connected (tcd,logic=0t_{cd,logic}=0), so tc-q>tholdt_{c\text{-}q}>t_{hold} (also in the presence of clock skew) is critical: registers are built to satisfy it, or delays are inserted. In FPGAs shift registers up to 32 bits are built directly in the LUTs.

Shifters

Definition (shift and rotate). A shifter moves the bits of a word by kk positions. For a word aN−1…a0a_{N-1}\dots a_0:

  • logical shift left (LSL): bits move toward the MSB, 00 enters from the right: multiplies by 2k2^k (without overflow);
  • logical shift right (LSR): 00 enters from the left: divides an unsigned number by 2k2^k;
  • arithmetic shift right (ASR): the sign bit is replicated from the left: divides a two's complement number by 2k2^k (rounding toward −∞-\infty);
  • rotation (ROL, ROR): bits leaving one side re-enter from the other.

Examples (8 bits). 0001 0110 (22)0001\,0110\ (22), LSL by 22: 0101 1000 (88)=22⋅40101\,1000\ (88)=22\cdot4. 1110 0100 (−28)1110\,0100\ (-28), ASR by 11: 1111 0010 (−14)1111\,0010\ (-14); LSR by 11 would give 0111 0010 (114)0111\,0010\ (114), wrong for a signed number. Rotate right of 0001 01100001\,0110 by 22: 1000 01011000\,0101. 1111 0000≫11111\,0000\gg1: logical 0111 10000111\,1000 (240→120240\to120), arithmetic 1111 10001111\,1000 (−16→−8-16\to-8).

Barrel shifter. A shifter by one position (a 2→12\to1 multiplexer per bit) is not enough for variable shifts. The barrel shifter uses log⁡2N\log_2N levels of 2→12\to1 multiplexers: level jj shifts by 2j2^j positions if bit jj of the shift amount ss is 11. For N=8N=8: three levels (shifts of 11, 22, 44) cover every ss from 00 to 77; for s=5=1012s=5=101_2 levels 11 and 44 are active. Cost: Nlog⁡2NN\log_2N multiplexers; delay: log⁡2N\log_2N multiplexer delays, independent of ss. In ARM the barrel shifter sits in front of the second ALU input, so a shift costs no extra cycle.

Multipliers

Definition (product as a sum of shifted partial products). The product of two unsigned NN-bit numbers has 2N2N bits. For each bit BjB_j of the multiplier form a partial product PPj=A⋅BjPP_j=A\cdot B_j (one AND per bit), shifted by jj positions, and add them all.

Example (4×44\times4 bits), A=1011 (11)A=1011\ (11), B=1101 (13)B=1101\ (13):

        1011   A  (11)
      x 1101   B  (13)
      ------
        1011   bit B0 = 1: A
       0000    bit B1 = 0: zero, shifted by 1
      1011     bit B2 = 1: A shifted by 2
     1011      bit B3 = 1: A shifted by 3
     --------
     10001111  = 143

Formula (array multiplier: cells and delay). N2N^2 AND gates generate the partial products and a matrix of N(N−1)N(N-1) full adders sums the rows (the carry of each row propagates to the next). For N=4N=4: 1616 AND gates and 1212 full adders. The critical path crosses about 2N2N cells: tmult≈(2N−2) tcarry+tsum,t_{mult}\approx(2N-2)\,t_{carry}+t_{sum}, linear in NN with area O(N2)O(N^2).

Example. N=4N=4, tcarry=100t_{carry}=100 ps, tsum=150t_{sum}=150 ps: about 750750 ps.

Alternatives.

Common mistakes

  • Using logical right shift on a signed number (the sign is lost): use arithmetic shift.
  • Forgetting that an NN-bit by NN-bit product needs 2N2N bits.
  • Saying the array multiplier is O(log⁡N)O(\log N): that is the Wallace tree (with a fast final adder).
  • Forgetting the hold constraint tc-q>tholdt_{c\text{-}q}>t_{hold} between directly connected registers.

Versione ripasso

Shift register

NN D registers in cascade; each edge the data advances one position. Example: 0000→0001→0010→0101→10110000\to0001\to0010\to0101\to1011 with serial input 1,0,1,11,0,1,1. Serial-parallel conversion; parallel-serial with a load/shift multiplexer; delay lines, FIFOs. Direct connection: need tc-q>tholdt_{c\text{-}q}>t_{hold}.

Shifters

  • LSL multiplies by 2k2^k; LSR divides unsigned (0 enters); ASR divides two's complement (sign replicated); rotation re-inserts the bits.
  • 1110 0100 (−28)1110\,0100\ (-28) ASR 1 =1111 0010 (−14)=1111\,0010\ (-14); LSR would give 114114 (wrong).
  • Barrel shifter: log⁡2N\log_2N levels of 2→12\to1 multiplexers, level jj shifts by 2j2^j if bit jj of ss is 1; Nlog⁡2NN\log_2N multiplexers; delay independent of ss (s=5s=5: levels 11 and 44). In ARM it precedes the second ALU input.

Multipliers

Common mistakes: LSR on signed numbers; forgetting the 2N2N-bit product; array multiplier is not O(log⁡N)O(\log N).

Teoria collegata