Académique Documents
Professionnel Documents
Culture Documents
Sequential Circuits
Amey Karkare
karkare@cse.iitk.ac.in
Department of CSE, IIT Kanpur
CS220, CO
Volunteers
External
Comb Ckts
CS220, CO
Content
Introduce sequential circuits as a way of
saving area
Seq Ckts
state elements
rules and actions for describing dynamic behavior
modules and methods
CS220, CO
Multiplication by repeated
addition
b Multiplicand 1101
a Muliplier * 1011
1101
+
1101
+ 0000
+ 1101
10001111
a0
(13)
(11)
a1
m0
m1
0
add4
(143)
a2
m2
add4
mi = (a[i]==0)? 0 : b;
a3
m3
add4
Seq Ckts
CS220, CO
Seq Ckts
CS220, CO
Seq Ckts
CS220, CO
Seq Ckts
CS220, CO
Combinational circuits
Sel
..
.
Mux
An-1
lg(n)
Demux
A0
A1
Sel
lg(n)
..
.
O0
O1
On-1
A
lg(n)
Decoder
OpSelect
..
.
O0
O1
ALU
On-1
Result
Comp?
CS220, CO
ff
C
D
Q
Metastability
CS220, CO
ff
EN
C
ff
ff
dangerous!
EN
C
EN
D
D
C
0
1
CS220, CO
10
Registers
En
C
ff
ff
ff
ff
ff
ff
ff
ff
Seq Ckts
CS220, CO
11
Seq Ckts
CS220, CO
12
+1
s0
sel
en
sel
en
< 32
notDone
Seq Ckts
CS220, CO
13
Expressing sequential
circuits in BSV
Seq Ckts
make a 32-bit
register which is
uninitialized
CS220, CO
14
Rule Execution
When a rule executes:
+1
sel
en
i
< 32
notDone
Seq Ckts
s0
CS220, CO
sel
en
sel = start
en = start | notDone
15
CS220, CO
16
No
Sequential multiply
Reg#(Bit#(32))
Reg#(Bit#(32))
Reg#(Bit#(32))
Reg#(Bit#(32))
Reg#(Bit#(6))
a <- mkRegU();
b <- mkRegU();
prod <-mkRegU();
tp <- mkRegU();
i <- mkReg(32);
state
elements
a rule to
describe
the
dynamic
behavior
17
Dynamic selection
requires a mux
i
a[i]
>>
a
0
Seq Ckts
CS220, CO
a[0],a[1],a[2],
18
Replacing repeated
selections by shifts
Reg#(Bit#(32))
Reg#(Bit#(32))
Reg#(Bit#(32))
Reg#(Bit#(32))
Reg#(Bit#(6))
a <- mkRegU();
b <- mkRegU();
prod <-mkRegU();
tp <- mkRegU();
i <- mkReg(32);
Seq Ckts
CS220, CO
19
aIn
s1
0
0
<<
s1
<<
+1
add
s1
s2
s1
s2
a
31:0
32:1
s2
tp
31
s2
[30:0]
prod
== 32
done
result (high)
result (low)
s1 = start_en
s2 = start_en | !done
Seq Ckts
CS220, CO
20
Circuit analysis
Number of add32 circuits has been reduced
from 31 to one, though some registers and
muxes have been added
The longest combinational path has been
reduced from 31 serial add32s to one add32
plus a few muxes
The sequential circuit will take 31 clock cycles
to compute an answer
Seq Ckts
CS220, CO
21
Modules
We often package sequential
circuits into modules to hide
the details
Seq Ckts
CS220, CO
22
Bit#(64)
rdy
Multiply
module
en
rdy
result
interface Multiply;
method Action start
(Bit#(32) a, Bit#(32) b);
method Bit#(64) result();
endinterface
Bit#(32)
Bit#(32)
start
Multiply Module
CS220, CO
23
External
interface
Multiply Module
module mkMultiply32 (Multiply);
Reg#(Bit#(32)) a <- mkRegU();
Reg#(Bit#(32)) b <- mkRegU();
State
Reg#(Bit#(32)) prod <-mkRegU();
Reg#(Bit#(32)) tp <- mkRegU();
Reg#(Bit#(6)) i <- mkReg(32);
rule mulStep if (i != 32);
Bit#(32) m = (a[0]==0)? 0 : b;
Internal
Bit#(33) sum = add32(m,tp,0);
behavior
prod <= {sum[0], (prod >> 1)[30:0]};
tp <= truncateLSB(sum); a <= a >> 1; i <= i+1;
endrule
method Action start(Bit#(32) aIn, Bit#(32) bIn)
if (i == 32);
a <= aIn; b <= bIn; i <= 0; tp <= 0; prod <= 0;
endmethod
method
method Bit#(64) result() if (i == 32);
guards
return {tp,prod};
Why is it initiated we have set it to
endmethod endmodule
Seq Ckts
CS220, CO
24
aIn
s1
0
s1
<<
+1
<<
aIn
bIn
en
rdy
start
bIn
add
result
rdy
result
s1
s2
s1
s2
== 32
a
31:0
32:1
s2
tp
result (high)
[30:0]
31
s2
prod
result (low)
done
s1
Seq Ckts
OR
s1 = start_en
s2 = start_en | !done
s2
CS220, CO
25
Polymorphic Multiply
Module
Tadd(n,n)
Bit#(64)
rdy
#(Numeric type n)
result
implicit
conditions
n could be
Multiply
module
en
rdy
start
Bit#(32)n
Bit#(32)
Bit#(32),
Bit#(13), ...
interface Multiply;
n
n
method Action start (Bit#(32) a, Bit#(32) b);
TAdd#(n,n)
method Bit#(64) result();
endinterface
The module can easily be made polymorphic
Seq Ckts
CS220, CO
26
Seq Ckts
CS220, CO
27
Multiply Module
interface Multiply;
method Action start (Bit#(32) a, Bit#(32) b);
method Bit#(64) result();
endinterface
The same interface can be implemented in many
different ways: What??
module mkMultiply (Multiply)
module mkBlockMultiply (Multiply)
module mkBoothMultiply (Multiply)
Seq Ckts
CS220, CO
28