-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.py
More file actions
73 lines (70 loc) · 2.16 KB
/
generator.py
File metadata and controls
73 lines (70 loc) · 2.16 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
rows=4
col=4
sys=open("generated.sv",'w')
str=""
for i in range(rows):
for j in range(col):
#for control signals flowing downward
if (i==0):
W_en=f"wfetch[{j}]"
W_ready=f"W_ready[{i}][{j}]"
W_in=f"i_wdata[{j}]"
W_out=f"W_data[{i}][{j}]"
P_in=f"bias"
P_out=f"P_data[{i}][{j}]"
elif (i==rows-1):
W_en=f"W_ready[{i-1}][{j}] & wfetch[{j}]"
W_ready=f""
W_in=f"W_data[{i-1}][{j}]"
W_out=""
P_in=f"P_data[{i-1}][{j}]"
P_out=f"of_data[{j}]"
else:
W_en=f"W_ready[{i-1}][{j}] & wfetch[{j}]"
W_ready=f"W_ready[{i}][{j}]"
W_in=f"W_data[{i-1}][{j}]"
W_out=f"W_data[{i}][{j}]"
P_in=f"P_data[{i-1}][{j}]"
P_out=f"P_data[{i}][{j}]"
#for control signals flowing rightward
if (j==0):
switch_in=f"W_switch[{i}][{j}]"
switch_out=f"W_switch[{i}][{j+1}]"
A_en=f"if_en[{i}]"
A_ready=f"A_ready[{i}][{j}]"
A_in=f"if_data[{i}]"
A_out=f"A_data[{i}][{j}]"
elif (j==col-1):
switch_in=f"W_switch[{i}][{j}]"
switch_out=f""
A_en=f"A_ready[{i}][{j-1}]"
A_ready=f""
A_in=f"A_data[{i}][{j-1}]"
A_out=f""
else:
switch_in=f"W_switch[{i}][{j}]"
switch_out=f"W_switch[{i}][{j+1}]"
A_en=f"A_ready[{i}][{j-1}]"
A_ready=f"A_ready[{i}][{j}]"
A_in=f"A_data[{i}][{j-1}]"
A_out=f"A_data[{i}][{j}]"
if (i==0 and j==0):
switch_in=f"switch"
str+=f"""mac mac_instance{i}{j} (
.clk(clk),
.rst(rst),
.switch_in({switch_in}),
.switch_out({switch_out}),
.A_en({A_en}),
.A_ready({A_ready}),
.A_in({A_in}),
.A_out({A_out}),
.W_en({W_en}),
.W_ready({W_ready}),
.W_in({W_in}),
.W_out({W_out}),
.P_in({P_in}),
.P_out({P_out})
);\n"""
sys.write(str)
sys.close()