Академический Документы
Профессиональный Документы
Культура Документы
design a multiplier
design a divider
Combinational Logic
CLK
D
always @ (CLK)
Q <= D;
endmodule
module ff(D, Q, CLK);
input D, CLK;
output Q;
reg Q;
always @ (posedge CLK)
Q <= D;
endmodule
Correct ?
CLK
R
(red)
Y
Change
Rst
If Change == 1 on
positive CLK
edge
traffic light
changes
(yellow)
G
(green)
RYG
100
If Rst == 1 on
positive CLK
edge
RYG=100
Rst == 1
RYG
100
Change == 1
Change == 1
RYG
001
Change == 1
RYG
010
10
Rst == 1
Change == 1
RYG
100
Change == 1
RYG
001
Change == 1
RYG
010
Change
RYG
100
00
1
010
100
11
Rst == 1
Change == 1
RYG
100
Change == 1
RYG
001
Change == 1
RYG
010
One-Hot Encoding
D
12
Rst == 1
RYG
100
Change == 1
Change == 1
RYG
001
Change == 1
Rst
RYG
010
Change
D Q
13
wire
next_R, next_Y, next_G;
output R, Y, G;
???
14
CLK
input D, CLK;
output Q;
reg Q;
always @ (posedge CLK)
Q <= D;
endmodule
15
wire
next_R, next_Y, next_G;
output R, Y, G;
ff ff_R(R, next_R, CLK);
ff ff_Y(Y, next_Y, CLK);
ff ff_G(G, next_G, CLK);
16
Rst
Change
wire
next_G
next_Y
17
wire
next_R, next_Y, next_G;
output R, Y, G;
assign next_R = rst ? 1b1 : (change ? G : R);
assign next_Y = rst ? 1b0 : (change ? R : Y);
assign next_G = rst ? 1b0 : (change ? Y : G);
ff ff_R(R, next_R, CLK);
ff ff_Y(Y, next_Y, CLK);
ff ff_G(G, next_G, CLK);
18
Change == 1
RYG
100
Change == 1
RYG
001
Change == 1
RYG
010
19
20
21
22
23
24
set-on-less-than
slt $1, $2, $3; if $2 < $3 then $1 = 1, else $1 = 0
; if MSB of $2 - $3 is 1, then $1 = 1
; 2s comp. MSB of a negative no. is 1
25
Overflow
=Carryin XOR Carryout
26
A 32-bit ALU
constructed from
32 1-bit ALUs
27
A 32-bit ALU
with zero detector
28
29
30
CLA
a b cout
0 0
0
nothing happen
0 1
cin
propagate cin
1 0
cin
propagate cin
1 1
1
generate
propagate = a + b;
generate = ab
31
32
Design Process
Divide and Conquer
using simple components
glue simple components together
work on the things you know how to do. The unknown
will become obvious as you make progress
Successive Refinement
multiplier design
divider design
33
Multiplier
paper and pencil method
multiplicand
multiplier
0110
1001
0110
0000
0000
0110
0110110
product
n bits x m bits = m+n bits
binary : 0
place 0
1
place a copy of multiplicand
34
multiplicand
64 bits
64-bit ALU
product
shift left
shift right
multiplier
ADD
write
control
64 bits
Control provides
four control
signals
35
36
2
3
step
initial
1.a
2
3
2
3
1.a
2
3
2
3
multiplier
0101
0101
0101
0010
0010
0001
0001
0001
0000
0000
0000
multiplicand
0000 0010
0000 0010
0000 0100
0000 0100
0000 1000
0000 1000
0000 1000
0001 0000
0001 0000
0010 0000
0010 0000
product
0000 0000
0000 0010
0000 0010
0000 0010
0000 0010
0000 0010
0000 1010
0000 1010
0000 1010
0000 1010
0000 1010
37
38
32-bit ALU
product
32 bits
32 bits
ADD
shift right
multiplier
shift right
control
write
Check the right
Write into the
most bit of Mr
left half of the
to decide to add 0
product register
or multiplicand
39
40
3
4
step
initial
1.a
2
3
1.a
2
3
2
3
2
3
multiplier
0011
0011
0011
0001
0001
0001
0000
0000
0000
0000
0000
multiplicand
0010
0010
0010
0010
0010
0010
0010
0010
0010
0010
0010
product
0000 0000
0010 0000
0001 0000
0001 0000
0011 0000
0001 1000
0001 1000
0000 1100
0000 1100
0000 0110
0000 0110
41
Multiply Version 2
Observations
product reg. wastes space that exactly matches the size
of multiplier
3 steps per bit
combine multiplier register and product register
42
multiplicand
32 bit ALU
ADD
write into
left half
control
product (multiplier)
shift right
43
44
iter.
0
1
2
3
4
step
initial
1.a
2
1.a
2
2
1.a
2
multiplicand
1110
1110
1110
1110
1110
1110
1110
1110
need to save the carry
product
0000 1011
1110 1011
0111 0101
10101 0101
1010 1010
0101 0101
10011 0101
1001 1010
45
46
Booths Algorithm
Motivation for Booths Algorithm is speed
example 2 x 6 = 0010 x 0110
normal approach
0010
0110
Booths approach
0010
0110
47
Booths Algorithm
end of run
middle of run
beginning of run
011111111111111111110
explanation
action
beginning of a run of 1s
middle of a run
no arithmetic oper.
end of a run
middle of a run of 0s
48
multiplicand
1110
1110
1110
1110
1110
1110
1110
product
0000 0111
0010 0111
0001 0011
0000 1001
0000 0100
1110 0100
1111 0010
previous
bit
0
0
1
1
1
1
0
49
Divide Algorithm
Paper and pencil
divisor 1011
1010101010
quotient
dividend
remainder (modulo )
50
shift right
64-bit ALU
remainder
quotient
write
shift left
control
51
quotient
divisor
0000 0010 0000
0000 0111
0010 0000
1110 0111
0010 0000
0000 0111
0001 0000
0000 0111
0001 0000
1111 0111
0001 0000
0000 0111
0000 1000
0000 0111
0000 1000
1111 1111
0000 1000
0000 0111
0000 0100
0000 0111
0000 0100
0000 0011
0000 0100
0000 0011
0000 0010
0000 0011
0000 0010
0000 0001
0000 0010
0000 0001
0000 0001
0000 0001
remainder
52
53
Possible improvement
instead of shifting divisor to right, shifting remainder to
left ?
first step can not produce a 1 in quotient, so switch order
to shift first and then subtract. This can save one
iteration
54
divisor
quotient
32-bit ALU
shift left
remainder
shift left
control
55
56
0000
0011
0011
0011
0011
0011
0011
0011
0011
0011
0011
0011
0011
quotient
divisor
0011 0000 1111
0001 1110
1110 1110
0001 1110
0011 1100
0000 1100
0000 1100
0001 1000
1110 1000
0001 1000
0011 0000
0000 0000
0000 0000
remainder
57
58
write
control
59
60
step
initial
1
2
3b
2
3b
2
3a
2
3b
divisor
0101
0101
0101
0101
0101
0101
0101
0101
0101
0101
remainder
0000 1110
0001 1100
1
1100 1100
0011 1000
2
1110 1000
0111 0000
3
0010 0000
0100 0001
4
1111 0001
1000 0010
0100 0010
correction step: shift remainder right 1bit.
quotient
61
62
-2N-1+ 1 <---------------------->2N-1 - 1
0 <-----------------------> 10N/4 - 1
How about
very small numbers, very large numbers
rationals, such as 2/3; irrationals such as 2;
transcendentals, such as , .
63
1.Mx2 E127
IEEE standard F.P.
single precision S(1bit), E(8 bits), M(23 bits)
mantissa = sign + magnitude; magnitude is normalized with
hidden integer bit: 1.M
exponent = E -127 (excess 127), 0 < E < 255
a FP number N = (-1)S 2(E-127) (1.M)
0 = 0 00000000 00000000000000000000000
-1.5 = 1 01111111 10000000000000000000000
64
E=126
-5.0 = -101.0b=-1.01 x 22
E=129
7 = 111b = 1.11 x 22
E=129
1 01111110 10000.......0
65
66
67
68
69
Addition Example
4-bit significand
1.0110 x 23 + 1.1000 x 22
70
71