Salta al contenuto
Note per Studenti Adders Report

Adders

In questa pagina 5
In questa pagina 4

The adder is the fundamental circuit 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 →): subtraction, comparison and address computation all reuse it (Binary ArithmeticBinary addition and two's complement subtraction, overflow for unsigned (carry) and signed (sign change) numbers, the N Z C V flags, multiplication by shifts and additions, Booth's algorithm with a worked example, division, and logical, arithmetic and rotate shifts.Binary Arithmetic →).

Half adder and full adder

The sum of two bits gives a sum bit SS and a carry CC: 0+0=000+0=00, 0+1=010+1=01, 1+1=101+1=10. A half adder has S=A⊕BS=A\oplus B, C=ABC=AB. To add multi-bit numbers each position must also add the carry from the previous one: three bits AA, BB, CinC_{in} give SS and CoutC_{out}.

AA BB CinC_{in} SS CoutC_{out}
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1

Formula (full adder). S=A⊕B⊕Cin,Cout=AB+BCin+ACin=AB+Cin(A⊕B).S=A\oplus B\oplus C_{in},\qquad C_{out}=AB+BC_{in}+AC_{in}=AB+C_{in}(A\oplus B).

The carry is the majority function: it is 11 when at least two inputs are 11. Example: A=B=Cin=1A=B=C_{in}=1 gives S=1S=1, Cout=1C_{out}=1.

Definition (generate, propagate, delete).

  • generate G=ABG=AB: the stage produces a carry of 11 regardless of CinC_{in};
  • propagate P=A⊕BP=A\oplus B (or A+BA+B for the carry): the stage passes CinC_{in} on;
  • delete D=A‾ B‾D=\overline A\,\overline B: the stage kills the carry (output 00 whatever CinC_{in}).

Then Cout=G+P⋅Cin,S=P⊕Cin.C_{out}=G+P\cdot C_{in},\qquad S=P\oplus C_{in}.

GG and PP depend only on AA, BB (set-up phase); only CoutC_{out} and SS depend on CinC_{in} (carry/sum phase).

Ripple-carry adder

Formula (ripple-carry delay, worst case). NN full adders in cascade, Cout,i=Cin,i+1C_{out,i}=C_{in,i+1}. With tct_c the carry delay (Cin→CoutC_{in}\to C_{out}) and tst_s the sum delay (Cin→SC_{in}\to S) of one full adder, and Cin,0=0C_{in,0}=0: in the worst case (all P=1P=1, the carry crosses all stages) the last bit waits N−1N-1 carry delays: tadd=(N−1) tc+ts(linear in N),\boxed{t_{add}=(N-1)\,t_c+t_s}\qquad(\text{linear in }N), and tadd=tsetup+(N−1)tc+tst_{add}=t_{setup}+(N-1)t_c+t_s if set-up is counted.

Numerical example. tc=100t_c=100 ps, ts=150t_s=150 ps: N=4N=4: 450450 ps; N=16N=16: 16501650 ps; N=32N=32: 32503250 ps. Doubling NN roughly doubles the delay. It is the simplest and most compact adder, but slow.

Data-dependent delay. The carry out of stage ii is available after tct_c if the stage is generate or delete, and after tct_c plus the previous stage's time if it is propagate. A generate or delete breaks the chain; the total delay is tst_s plus tct_c times the longest chain (a generate or delete followed by consecutive propagates).

Example. Stages 0…30\ldots3 with (Ai,Bi)=(1,0),(0,1),(1,1),(0,0)(A_i,B_i)=(1,0),(0,1),(1,1),(0,0): P, P, G, D. Stage 22 resets the chain, so tadd=2tc+tst_{add}=2t_c+t_s. If Ai=BiA_i=B_i everywhere, every stage is G or D and tadd=tc+tst_{add}=t_c+t_s.

Adding two NN-bit numbers needs N+1N+1 bits (the final carry). In two's complement overflow is V=CN−1⊕CNV=C_{N-1}\oplus C_N (carry into and out of the last stage).

Adder-subtractor

Property (adder-subtractor). One adder also subtracts in two's complement: each bit of BB goes through an XOR with a signal SUB\text{SUB}, which is also the initial carry c0c_0.

  • SUB=0\text{SUB}=0: B⊕0=BB\oplus0=B, c0=0c_0=0, result A+BA+B.
  • SUB=1\text{SUB}=1: B⊕1=B‾B\oplus1=\overline B, c0=1c_0=1, result A+B‾+1=A−BA+\overline B+1=A-B.

Example (4 bits, SUB=1\text{SUB}=1): 0110−0011=0110+1100+1=(1) 0011=30110-0011=0110+1100+1=(1)\,0011=3.

Fast adders

Fast structures keep the same full adder but shorten the critical carry path with extra logic. Notation: tsetupt_{setup}, tcarryt_{carry} (per stage), tmuxt_{mux}, tsumt_{sum}.

Carry-lookahead

Definition (carry lookahead). With gi=AiBig_i=A_iB_i and pi=Ai+Bip_i=A_i+B_i the carries are computed directly from the inputs: c1=g0+p0c0,c2=g1+p1g0+p1p0c0, …c_1=g_0+p_0c_0,\qquad c_2=g_1+p_1g_0+p_1p_0c_0,\ \dots

More gates, but delay growing roughly as log⁡N\log N (prefix adders such as Kogge-Stone combine G and P of bit groups in O(log⁡N)O(\log N)). In FPGAs a dedicated carry chain does the same job with a fast physical path.

Carry-bypass (carry-skip)

The NN bits are divided into blocks of MM. In each block compute BP=P0P1⋯PM−1BP=P_0P_1\cdots P_{M-1}. If all propagates are 11, the block's carry out equals its carry in: a multiplexer driven by BPBP makes the carry skip the block.

Formula (carry-bypass delay and optimal block size). Worst case: the carry is generated at the first stage of the first block and crosses it (M tcarryM\,t_{carry}), skips the following blocks through N/M−1N/M-1 multiplexers, then crosses M−1M-1 stages of the last block: tadd=tsetup+M tcarry+(NM−1)tmux+(M−1) tcarry+tsum,Mopt=N tmux2 tcarry.t_{add}=t_{setup}+M\,t_{carry}+\Big(\frac NM-1\Big)t_{mux}+(M-1)\,t_{carry}+t_{sum},\qquad M_{opt}=\sqrt{\frac{N\,t_{mux}}{2\,t_{carry}}}.

Example. N=32N=32, all delays TT: Mopt=32/2=4M_{opt}=\sqrt{32/2}=4 and tadd=T+4T+7T+3T+T=16Tt_{add}=T+4T+7T+3T+T=16T. The delay is dominated by the carry time (tcarryt_{carry}), since set-up and sum appear once.

Carry-select

In each block (except the first) sums and carries are computed twice, assuming carry in 00 and 11. When the true carry from the previous block arrives, a multiplexer selects the right result. Both computations run in parallel with the previous block's carry.

Formula (linear carry-select). Blocks of MM bits, N/MN/M blocks: tadd=tsetup+M tcarry+NM tmux+tsum,Mopt=N tmuxtcarry.t_{add}=t_{setup}+M\,t_{carry}+\frac NM\,t_{mux}+t_{sum},\qquad M_{opt}=\sqrt{\frac{N\,t_{mux}}{t_{carry}}}.

Example. N=32N=32, M=8M=8, all delays TT: tadd=T+8T+4T+T=14Tt_{add}=T+8T+4T+T=14T. Cost: about twice the full adders, plus multiplexers.

Square-root carry-select

In the linear version, block jj waits for the carry of block j−1j-1, which arrives one multiplexer later: meanwhile it has already finished its two alternatives. So each block can have one more bit than the previous one. Blocks of M,M+1,…,M+K−1M,M+1,\dots,M+K-1 bits:

Formula (square-root carry-select). N=∑j=0K−1(M+j)≈K22⇒K≈2N,tadd≈tsetup+M tcarry+2N tmux+tsum.N=\sum_{j=0}^{K-1}(M+j)\approx\frac{K^2}2\Rightarrow K\approx\sqrt{2N},\qquad t_{add}\approx t_{setup}+M\,t_{carry}+\sqrt{2N}\,t_{mux}+t_{sum}.

Example. N=32N=32, M=3M=3: blocks 3,4,5,6,7,83,4,5,6,7,8 (3333 bits), K=6K=6, tadd=T+3T+6T+T=11Tt_{add}=T+3T+6T+T=11T. Delay grows as N\sqrt N. If tmux≠tcarryt_{mux}\ne t_{carry} the blocks grow by tmux/tcarryt_{mux}/t_{carry} bits at a time.

Comparison

With tsetup=tcarry=tmux=tsum=Tt_{setup}=t_{carry}=t_{mux}=t_{sum}=T:

NN ripple carry-bypass linear select square-root select
16 17T17T 12T12T 10T10T 9T9T
32 33T33T 16T16T 14T14T 11T11T
64 65T65T 24T24T 18T18T 14T14T

The advantage of variable-block structures grows with NN; the price is area (select structures duplicate full adders) and routing complexity.

Common mistakes

  • Using N tcN\,t_c or N(tc+ts)N(t_c+t_s) instead of (N−1)tc+ts(N-1)t_c+t_s: the sum is computed once, at the end.
  • Treating the worst-case delay as valid for every pair of operands.
  • Forgetting that a generate or delete stage interrupts the carry chain; confusing propagate (A⊕BA\oplus B) with generate (ABAB).
  • Counting multiplexers wrongly: N/M−1N/M-1 for bypass, N/MN/M for select.
  • Using the bypass MoptM_{opt} (with the factor 22) for carry-select, or equal blocks in the square-root select.
  • Forgetting +1+1 in subtraction (A+B‾A+\overline B alone is wrong).

Versione ripasso

Full adder

S=A⊕B⊕CinS=A\oplus B\oplus C_{in}, Cout=AB+BCin+ACinC_{out}=AB+BC_{in}+AC_{in} (majority). Half adder: S=A⊕BS=A\oplus B, C=ABC=AB. With generate G=ABG=AB, propagate P=A⊕BP=A\oplus B, delete D=A‾ B‾D=\overline A\,\overline B: Cout=G+P CinC_{out}=G+P\,C_{in}, S=P⊕CinS=P\oplus C_{in}. GG, PP do not depend on CinC_{in} (set-up).

Ripple-carry

NN full adders in cascade. Worst case (all P=1P=1): tadd=(N−1)tc+tst_{add}=(N-1)t_c+t_s, linear in NN. Example tc=100t_c=100, ts=150t_s=150 ps: N=16N=16 gives 16501650 ps. A G or D stage cuts the chain; delay =ts+tc⋅=t_s+t_c\cdot(longest G/D-then-P chain). Equal operands: tc+tst_c+t_s. Result needs N+1N+1 bits; overflow V=CN−1⊕CNV=C_{N-1}\oplus C_N.

Adder-subtractor

XOR on each BiB_i driven by SUB, SUB also c0c_0: A+B‾+1=A−BA+\overline B+1=A-B. Example: 0110−0011=00110110-0011=0011.

Fast adders

  • Lookahead: c1=g0+p0c0c_1=g_0+p_0c_0, c2=g1+p1g0+p1p0c0c_2=g_1+p_1g_0+p_1p_0c_0; delay about log⁡N\log N.
  • Carry-bypass: blocks of MM, BP=∏PiBP=\prod P_i skips the block through a mux. t=tsetup+Mtcarry+(N/M−1)tmux+(M−1)tcarry+tsumt=t_{setup}+Mt_{carry}+(N/M-1)t_{mux}+(M-1)t_{carry}+t_{sum}, Mopt=Ntmux/(2tcarry)M_{opt}=\sqrt{Nt_{mux}/(2t_{carry})}. N=32N=32: 16T16T.
  • Linear carry-select: two results per block (carry in 0 and 1), mux selects. t=tsetup+Mtcarry+(N/M)tmux+tsumt=t_{setup}+Mt_{carry}+(N/M)t_{mux}+t_{sum}, Mopt=Ntmux/tcarryM_{opt}=\sqrt{Nt_{mux}/t_{carry}}. N=32N=32, M=8M=8: 14T14T.
  • Square-root select: blocks M,M+1,…M,M+1,\dots; K≈2NK\approx\sqrt{2N}, t≈tsetup+Mtcarry+2N tmux+tsumt\approx t_{setup}+Mt_{carry}+\sqrt{2N}\,t_{mux}+t_{sum}. N=32N=32, M=3M=3: 11T11T.
NN ripple bypass select sqrt
16 17T17T 12T12T 10T10T 9T9T
32 33T33T 16T16T 14T14T 11T11T
64 65T65T 24T24T 18T18T 14T14T

Common mistakes: NtcN t_c instead of (N−1)tc+ts(N-1)t_c+t_s; worst case taken as typical; forgetting that G/D break the chain; A+B‾A+\overline B without +1+1; bypass MoptM_{opt} used for select.

Teoria collegata