Digital Design: A Systems Approach Lecture 3: Combinational Building Blocks
Digital Design: A Systems Approach Lecture 3: Combinational Building Blocks
Readings
L3: Chapters 8 & 9
L4: Chapter 10 & 11
Review
Lecture 1 Introduction to digital design:
Representations, noise margins, Boolean algebra, Verilog
Todays Lecture
Combinational building blocks the idioms of digital design
Decoder (binary to one-hot)
Encoder (one-hot to binary)
Muliplexer (select one of N)
Arbiter (pick first of N)
Comparators
Read-only memories
One-hot representation
Represent a set of N elements with N bits
Exactly one bit is set
Example encode numbers 0-7
Binary
000
001
010
110
111
One-hot
00000001
00000010
00000100
01000000
10000000
Decoder
b[i] = 1 if a = i
b = 1<<a
Decoder
m
n
m2
6
Example of a Decoder
4 Decoder
a1
a0
a1 a0 b3 b2 b1 b0
0 0 0 0 0 1
0 1 0 0 1 0
1 0 0 1 0 0
1 1 1 0 0 0
b3
b2
b1
b0
a4
0
1
0
1
z3
0
0
0
1
z2
0
0
1
0
z1
0
1
0
0
z0
1
0
0
0
a3
0
0
1
1
a2
0
1
0
1
y3
0
0
0
1
y2
0
0
1
0
y1
0
1
0
0
y0
1
0
0
0
a1
0
0
1
1
a0
0
1
0
1
x3
0
0
0
1
x2
0
0
1
0
x1
0
1
0
0
x0
1
0
0
0
a[5:0]
2
a[3:2]
2
2:4
2:4
2:4
4
x[3]
4
y[3]
y[3]
y[3:0]
x[3:0]
x[3]
a[1:0]
x[0]
y[0]
z[3]
z[2]
b63
b62
z[3:0]
a[5:4]
z[0]
b0
10
Decoder
m
n
m2
11
Synthesizes to
module dec (
input [1:0]
output [3:0]
wire n2,
NO210 U2
NO210 U3
NO210 U4
NO210 U5
IV110 U6
IV110 U7
endmodule
in, out );
in;
out;
n3;
( .A(n2), .B(n3), .Y(out[3]) );
( .A(in[0]), .B(n2), .Y(out[2]) );
( .A(in[1]), .B(n3), .Y(out[1]) );
( .A(in[0]), .B(in[1]), .Y(out[0]) );
( .A(in[1]), .Y(n2) );
( .A(in[0]), .Y(n3) );
12
3:8
in [2 :0 ]
3
b [7 ]
b [5 ]
i sp ri me
b [3 ]
b [2 ]
b [1 ]
13
Encoder
a0
a1
a3 a2 a1 a0 b1 b0
0 0 0 1 0 0
0 0 1 0 0 1
0 1 0 0 1 0
1 0 0 0 1 1
a2
2 encoder.
a3
Example: a 4
b1
b0
b0 = a3 a1
b1 = a3 a2
(c) 2005-2012 W. J. Dally
14
One hot
a[7:4]
a[3:0]
4
b[3:2]
2
2
b[1:0]
4:2
High bits
Low bits
4:2
a[11:8]
4:2
4:2
a[15:12]
4:2
Repeat as needed
2
(c) 2005-2012 W. J. Dally
2
15
16
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
0000000000000001
0000000000000010
0000000000000100
0000000000001000
0000000000010000
0000000000100000
0000000001000000
0000000010000000
0000000100000000
0000001000000000
0000010000000000
0000100000000000
0001000000000000
0010000000000000
0100000000000000
1000000000000000
0000000000000000
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
0000
17
Multiplexer
Multiplexer:
n k-bit inputs
n-bit one-hot select signal s
Multiplexers are commonly used as data selectors
a0
an-1
b=a[i] if s [i] = 1
n
(c) 2005-2012 W. J. Dally
18
Multiplexer Implementation
a0
a0
s0
s0
a1
s1
a2
a1
b
s1
a2
s2
s2
a3
a3
s3
s3
19
f
0001
0010
0100
1000
h
00
01
10
11
20
21
a0
an-1
k
s
n
Selects one of n k-bit inputs
s must be one-hot
b=a[i] if s [i] = 1
(c) 2005-2012 W. J. Dally
22
s1
s0
a0
k
b
k
an-1
a3
Decoder
a2
a1
a0
23
b
k
an-1
k
Decoder
n
24
sb
sb
isprime
0
1
sb[2]
1
Muxb
Muxb
0
1
1
1
0
1
0
1
isprime
2
Arbiter
Arbiter
26
No_one_yet[i]
r[i]
No_one_yet[i+1]
g[i]
27
Using Bit-Cell
r0
Using Look-Ahead
g0
r0
r1
g0
g1
g1
r1
r2
g2
g2
r2
g3
r3
r3
g3
28
r[i]
g[i]
No_one_yet[i+1]
No_one_yet[i]
29
Priority Encoder
Priority Encoder:
n-bit input signal a
m-bit output signal b
b indicates the position of the first 1 bit in a
Encoder
Arbiter
m=
Priority
Encoder
log2n
30
31
32
Encode
Arbiter
OR
Decode
Equality Comparator
Comparator
a3
b3
a2
eq
b2
a1
b1
// equality comparator
module EqComp(a, b, eq) ;
parameter k=8;
input [k-1:0] a,b;
output eq ;
wire
eq;
a0
b0
eq3
eq2
eq
eq1
eq0
assign eq = (a==b) ;
endmodule
(c) 2005-2012 W. J. Dally
33
gtbi+1
Magnitude Comparator
Magnitude
Comparator
gt
ai
bi
gti
eqi
gtbi
// magnitude comparator
module MagComp(a, b, gt) ;
parameter k=8 ;
input [k-1:0] a, b ;
output gt ;
wire
[k-1:0] eqi = a ~^ b ;
wire
[k-1:0] gti = a & ~b ;
wire
[k:0]
gtb {((eqi[k-1:0] & gtb[k-1:0]) | gti[k-1:0]), 1b0} ;
wire
gt = gtb[k] ;
endmodule
34
eqi
gtai-1
bi
gti
eqai-1
ai
gtai
eqai
35
36
b
n
Magnitude
Comparator
gt
Mux
ma x
n
a>b
37
a
n
ROM d
d
m
38
a
n
D ecoder
m
w 2 n 1
d 2 n 1
39
2 5 6 w o rd x
1 6 b it/w o r d R O M
6 4 r o w s x 6 4 c o lu m n s
7 :2
D ecoder
a
8
63
252
16
a
1 :0
253
16
16
M u lt ip le x e r
(c) 2005-2012 W. J. Dally
254
40
16
255
16
Summary
Assemble combinational circuits from pre-defined building blocks
Decoder converts codes (e.g., binary to one-hot)
Encoder encodes one-hot to binary
Multiplexer select an input (one-hot select)
Arbiter pick first true bit
Comparators equality and magnitude
ROMs
Divide and conquer to build large units from small units
Decoder, encoder, multiplexer
Logic with multiplexers or decoders
Bit-slice coding style
41
Coming in L4
Numbers and Arithmetic
42