Ver 4
Ver 4
elements
in Digital Circuits
Debdeep Mukhopadhyay
Associate Professor
Dept of Computer Science and Engineering
NYU Shanghai and IIT Kharagpur
1
What is datapath?
• Suppose we want to design a Full Adder
(FA):
– Sum=A ^ B ^ CIN = Parity(A,B,CIN)
– COUT=AB+ACIN+BCIN=MAJ(A,B,CIN)
• Combine the two functions to a single FA
logic cell:
ADD(A[i],B[i],CIN,S[i],COUT)
• How do we build a 4-bit ripple carry
adder?
A 4 bit Adder
The layout of buswide logic that operates on data signals is called a Datapath.
The module ADD is called a Datapath element.
What is the difference between
datapath and standard cells?
• Standard Cell Based Design: Cells are placed
together in rows but there is no generally no
regularity to the arrangement of the cells within
the rows—we let software arrange the cells and
complete the interconnect.
• Datapath layout automatically takes care of most
of the interconnect between the cells with the
following advantages:
– Regular layout produces predictable and equal delay
for each bit.
– Interconnect between cells can be built into each cell.
Digital Device Components
0 0 Y<-A No shift
0 1 Y<-shlA Shift left
1 0 Y<-shrA Shift right
1 1 Y<-0 Zero
outputs
0
A[1]
A[0] Y[1]
MUX
A[2]
A[0]
A[1] Y[0]
MUX
0
Verilog Code
module shifter(Con,A,Y);
input [1:0] Con;
input[2:0] A;
output[2:0] Y;
reg [2:0] Y;
always @(A or Con)
begin
case(Con)
0: Y=A;
1: Y=A<<1;
2: Y=A>>1;
default: Y=3’b0;
endcase
end
endmodule
Combinational logic shifters with
shiftin and shiftout
Sel Operation Function
0 Y<=A No shift
1 Y<-A rol 1 Rotate once
2 Y<-A rol 2 Rotate twice
3 Y<- A rol 3 Rotate Thrice
4 Y<-A rol 4 Rotate four times
5 Y<-A rol 5 Rotate five times
Verilog Coding
• function [2:0] rotate_left;
input [5:0] A;
input [2:0] NumberShifts;
reg [5:0] Shifting;
integer N;
begin
Shifting = A;
for(N=1;N<=NumberShifts;N=N+1)
begin
Shifting={Shifting[4:0],Shifting[5])};
end
rotate_left=Shifting;
end
endfunction
Verilog
• always @(Rotate or A)
begin
case(Rotate)
0: Y=A;
1: Y=rotate_left(A,1);
2: Y=rotate_left(A,2);
3: Y=rotate_left(A,3);
4: Y=rotate_left(A,4);
5: Y=rotate_left(A,5);
default: Y=6’bx;
endcase
end
Another Way
.
data 1
n bits
output
data 2 n bits
n bits
Cout S Cout C
S
S Cout
Cout S
A B C Co S
A B Co S 0 0 0
0 0 0 0 1
0 1 0 1 0
1 0 0 1 1
1 1 1 0 0
1 0 1
1 1 0
1 1 1
Single-Bit Addition
Half Adder A B
Full Adder A B
S A B Cout S A B C
Cout C
Cout AB Cout MAJ ( A, B, C )
S S
A B Co S A B C Co S
0 0 0 0 0 0 0 0 0
0 1 0 1 0 0 1 0 1
1 0 0 1 0 1 0 0 1
1 1 1 0 0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
Carry-Ripple Adder
• Simplest design: cascade full adders
– Critical path goes from Cin to Cout
– Design full adder to have fast carry delay
A4 B4 A3 B3 A2 B2 A1 B1
Cout Cin
C3 C2 C1
S4 S3 S2 S1
Full adder
• Computes one-bit sum, carry:
– si = ai XOR bi XOR ci
– ci+1 = aibi + aici + bici
• Half adder computes two-bit sum.
• Ripple-carry adder: n-bit adder built from
full adders.
• Delay of ripple-carry adder goes through
all carry bits.
Verilog for full adder
module fulladd(a,b,carryin,sum,carryout);
input a, b, carryin; /* add these bits*/
output sum, carryout; /* results */
fulladd a0(a[0],b[0],carryin,sum[0],carry[1]);
fulladd a1(a[1],b[1],carry[1],sum[1],carry[2]);
…
fulladd a7(a[7],b[7],carry[7],sum[7],carryout]);
endmodule
Generate and Propagate
• endmodule
Verilog for carry-lookahead sum
unit
module sum(a,b,carryin,result);
input a, b, carryin; /* add these bits*/
output result; /* sum */
( j i)2
j i 1
( j i)
( j i )2 ( j i ) (k i )2 ( k 1 i )
j i 1
k 1 i
l 2 l (k i )2 ( k 1 i ) 2 (k i 1)2 ( k 1 i ) ( k i )2 ( k 1 i )
l 1
2 2 ( k 1 i )
p
[Using, l
l 1
2 l
2 ( p 2)2 p
]
Carry completion sensing adder
A=011101101101101 A=011101101101101
B=100111000010101 B=100111000010101
------------------------------ ------------------------------
C=000000000000000 C=000101000000101
N=000000000000000 N=000000010000010
------------------------------ ------------------------------
C=000101000000101 C=001111000001101
N=000000010000010 N=000000110000010
Carry completion sensing adder
A=011101101101101 A=011101101101101
B=100111000010101 B=100111000010101
------------------------------ ------------------------------
C=001111000001101 C=011111000011101
N=000000110000010 N=000000110000010
------------------------------ ------------------------------
C=011111000011101 C=111111000111101
N=000000110000010 N=000000110000010
Carry completion sensing adder
A=011101101101101
B=100111000010101
------------------------------
C=111111000111101
N=000000110000010
------------------------------
C=111111001111101
N=000000110000010
Carry completion sensing adder
• (A[i],B[i])=(0,0)=>(Ci,Ni)=(0,1)
• (A[i],B[i])=(1,1)=>(Ci,Ni)=(1,0)
• (A[i],B[i])=(0,1)=>(Ci,Ni)=(Ci-1,Ni-1)
• (A[i],B[i])=(0,0)=>(Ci,Ni)=(Ci-1,Ni-1)
• Stop, when for all I, Ci V Ni = 1
Justification
• Ci and Ni together is a coding for the
carry.
• When Ci=1, carry can be computed. Make
Ni=0
• When Ci=0 is the final carry, then indicate
by Ni=1
• The carry can be surely stated when both
Ai and Bi are 1’s or 0’s.
Carry-skip adder
• Looks for cases in which carry out of a set
of bits is identical to carry in.
• Typically organized into b-bit stages.
• Can bypass carry through all stages in a
group when all propagates are true: Pi Pi+1
… Pi+b-1.
– Carry out of group when carry out of last bit in
group or carry is bypassed.
Carry-skip structure
ci
Pi
Pi+1 AND
…
Pi+b-1
OR
Ci+b-1
Carry-skip structure
fulladd_p a0(a[0],b[0],carryin,sum[0],carry[1],p[0]);
fulladd_p a1(a[1],b[1],carry[1],sum[1],carry[2],p[1]);
fulladd_p a2(a[2],b[2],carry[2],sum[2],carry[3],p[2]);
fulladd_p a3(a[3],b[3],carry[3],sum[3],carry[4],p[3]);
assign cs4 = carry[4] | (p[0] & p[1] & p[2] & p[3] & carryin);
fulladd_p a4(a[4],b[4],cs4, sum[4],carry[5],p[4]);
…
assign carryout = carry[8] | (p[4] & p[5] & p[6] & p[7] & cs4);
endmodule
Delay analysis
• Assume that skip delay = 1 bit carry delay.
• Delay of k-bit adder with block size b:
– T = (b-1) + 0.5 + (k/b –2) + (b-1)
block 0 OR gate skips last block
• For equal sized blocks, optimal block size
is sqrt(k/2).
Delay of Carry-Skip Adder
tp
ripple adder
bypass adder
N
t d 2k 1t RCA 2 t SKIP
2k
4..8
N
Carry-select adder
• Computes two results in parallel, each for
different carry input assumptions.
• Uses actual carry in to select correct
result.
• Reduces delay to multiplexer.
Carry-select structure
Carry-save adder
• Useful in multiplication.
• Input: 3 n-bit operands.
• Output: n-bit partial sum, n-bit carry.
– Use carry propagate adder for final sum.
• Operations:
– s = (x + y + z) mod 2.
– c = [(x + y + z) –2] / 2.
Adder comparison
• Ripple-carry adder has highest
performance/cost.
• Optimized adders are most effective in
very long bit widths (> 48 bits).
ALUs
• ALU computes a variety of logical and
arithmetic functions based on opcode.
• May offer complete set of functions of two
variables or a subset.
• ALU built around adder, since carry chain
determines delay.
ALU as multiplexer
• Compute functions then select desired one:
opcode
AND
OR
NOT
SUM