File: opt_mem_priority.ys

package info (click to toggle)
yosys 0.52-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 69,796 kB
  • sloc: ansic: 696,955; cpp: 239,736; python: 14,617; yacc: 3,529; sh: 2,175; makefile: 1,945; lex: 697; perl: 445; javascript: 323; tcl: 162; vhdl: 115
file content (209 lines) | stat: -rw-r--r-- 3,283 bytes parent folder | download | duplicates (2)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Bad case: independent write ports.

read_verilog << EOT

module top(
	input [3:0] wa1, wa2, ra, wd1, wd2,
	input clk, we1, we2,
	output [3:0] rd);

reg [3:0] mem[0:15];
assign rd = mem[ra];

always @(posedge clk) begin
	if (we1)
		mem[wa1] <= wd1;
	if (we2)
		mem[wa2] <= wd2;
end

endmodule

EOT

hierarchy -auto-top
proc
opt
memory -nomap
select -assert-count 1 t:$mem_v2
select -assert-count 1 t:$mem_v2 r:WR_PRIORITY_MASK=4'b0100 %i


design -reset

# Good case: write ports with definitely different addresses.

read_verilog << EOT

module top(
	input [3:0] wa, ra, wd1, wd2,
	input clk, we1, we2,
	output [3:0] rd);

reg [3:0] mem[0:15];
assign rd = mem[ra];

always @(posedge clk) begin
	if (we1)
		mem[wa] <= wd1;
	if (we2)
		mem[wa ^ 1] <= wd2;
end

endmodule

EOT

hierarchy -auto-top
proc
opt
memory -nomap
select -assert-count 1 t:$mem_v2
select -assert-count 1 t:$mem_v2 r:WR_PRIORITY_MASK=4'b0000 %i


design -reset

# Bad case 2: the above, but broken.

read_verilog << EOT

module top(
	input [3:0] wa, ra, wd1, wd2,
	input clk, we1, we2,
	output [3:0] rd);

reg [3:0] mem[0:15];
assign rd = mem[ra];

always @(posedge clk) begin
	if (we1)
		mem[wa] <= wd1;
	if (we2)
		mem[wa | 1] <= wd2;
end

endmodule

EOT

hierarchy -auto-top
proc
opt
memory -nomap
select -assert-count 1 t:$mem_v2
select -assert-count 1 t:$mem_v2 r:WR_PRIORITY_MASK=4'b0100 %i


design -reset

# Good case 2: write ports with disjoint bit enables.

read_verilog << EOT

module top(
	input [3:0] wa1, wa2, ra,
	input [1:0] wd1, wd2,
	input clk, we1, we2,
	output [3:0] rd);

reg [3:0] mem[0:15];
assign rd = mem[ra];

always @(posedge clk) begin
	if (we1)
		mem[wa1][1:0] <= wd1;
	if (we2)
		mem[wa2][3:2] <= wd2;
end

endmodule

EOT

hierarchy -auto-top
proc
opt
memory -nomap
select -assert-count 1 t:$mem_v2
select -assert-count 1 t:$mem_v2 r:WR_PRIORITY_MASK=4'b0000 %i


design -reset

# Good case 3: write ports with soft priority logic already

read_verilog << EOT

module top(
	input [3:0] wa1, wa2, ra, wd1, wd2,
	input clk, we1, we2,
	output [3:0] rd);

reg [3:0] mem[0:15];
assign rd = mem[ra];

always @(posedge clk) begin
	if (we1)
		mem[wa1] <= wd1;
	if (we2 && wa1 != wa2)
		mem[wa2] <= wd2;
end

endmodule

EOT

hierarchy -auto-top
proc
opt
memory -nomap
select -assert-count 1 t:$mem_v2
select -assert-count 1 t:$mem_v2 r:WR_PRIORITY_MASK=4'b0000 %i


design -reset

# Good case 4: two wide write ports

read_verilog << EOT

module top(
	input [5:0] wa1, wa2,
	input [7:0] ra,
	input [31:0] wd1, wd2,
	input clk, we1, we2,
	output [7:0] rd);

reg [7:0] mem[0:255];
assign rd = mem[ra];

always @(posedge clk) begin
	if (we1) begin
		mem[{wa1, 2'b00}] <= wd1[7:0];
		mem[{wa1, 2'b01}] <= wd1[15:8];
		mem[{wa1, 2'b10}] <= wd1[23:16];
		mem[{wa1, 2'b11}] <= wd1[31:24];
	end
	if (we2) begin
		mem[{wa2, 2'b00}] <= wd2[7:0];
		mem[{wa2, 2'b01}] <= wd2[15:8];
		mem[{wa2, 2'b10}] <= wd2[23:16];
		mem[{wa2, 2'b11}] <= wd2[31:24];
	end
end

endmodule

EOT

hierarchy -auto-top
proc
opt
opt_mem_priority
memory_collect
select -assert-count 1 t:$mem_v2
select -assert-count 1 t:$mem_v2 r:WR_PRIORITY_MASK=64'h0804020100000000 %i
memory_share
select -assert-count 1 t:$mem_v2 r:WR_PRIORITY_MASK=64'h0f0f0f0f00000000 %i
select -assert-count 1 t:$mem_v2 r:WR_WIDE_CONTINUATION=8'hee %i