-
Notifications
You must be signed in to change notification settings - Fork 0
/
RippleCarryAdderGL.py
49 lines (36 loc) · 1.09 KB
/
RippleCarryAdderGL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#=========================================================================
# RippleCarryAdderGL
#=========================================================================
from pymtl3 import *
from FullAdderGL import FullAdderGL
class RippleCarryAdderGL( Component ):
def construct( s, nbits=4 ):
s.in0 = InPort (nbits)
s.in1 = InPort (nbits)
s.out = OutPort(nbits)
s.fas = [ FullAdderGL() for _ in range(nbits) ]
for i in range(nbits):
s.in0[i] //= s.fas[i].a
s.in1[i] //= s.fas[i].b
s.out[i] //= s.fas[i].sum
s.fas[0].cin //= 0
for i in range(nbits-1):
s.fas[i].cout //= s.fas[i+1].cin
#-------------------------------------------------------------------------
# main
#-------------------------------------------------------------------------
if __name__ == "__main__":
dut = RippleCarryAdderGL()
dut.apply( DefaultPassGroup(textwave=True) )
dut.sim_reset()
dut.in0 @= 6
dut.in1 @= 3
dut.sim_tick()
dut.in0 @= 4
dut.in1 @= 4
dut.sim_tick()
dut.in0 @= 0xf
dut.in1 @= 0x1
dut.sim_tick()
dut.sim_tick()
dut.print_textwave()