Skip to content

Commit f680e2a

Browse files
committed
ql-qlf: k6n10f: add tests for RAM with asymmetric port widths
Signed-off-by: Paweł Czarnecki <[email protected]>
1 parent 9ef6779 commit f680e2a

File tree

9 files changed

+772
-1
lines changed

9 files changed

+772
-1
lines changed

ql-qlf-plugin/tests/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ POST_SYNTH_SIM_TESTS = \
5454
qlf_k6n10f/bram_tdp_split \
5555
qlf_k6n10f/bram_sdp_split \
5656
qlf_k6n10f/dsp_mult_post_synth_sim \
57-
qlf_k6n10f/dsp_simd_post_synth_sim
57+
qlf_k6n10f/dsp_simd_post_synth_sim \
58+
qlf_k6n10f/bram_asymmetric_wider_write \
59+
qlf_k6n10f/bram_asymmetric_wider_read
5860

5961
include $(shell pwd)/../../Makefile_test.common
6062

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
yosys -import
2+
3+
if { [info procs ql-qlf-k6n10f] == {} } { plugin -i ql-qlf }
4+
yosys -import ;
5+
6+
read_verilog $::env(DESIGN_TOP).v
7+
design -save bram_tdp
8+
9+
select spram_16x2048_32x1024
10+
select *
11+
synth_quicklogic -family qlf_k6n10f -top spram_16x2048_32x1024
12+
opt_expr -undriven
13+
opt_clean
14+
stat
15+
write_verilog sim/spram_16x2048_32x1024_post_synth.v
16+
select -assert-count 1 t:TDP36K
17+
18+
select -clear
19+
design -load bram_tdp
20+
select spram_8x4096_16x2048
21+
select *
22+
synth_quicklogic -family qlf_k6n10f -top spram_8x4096_16x2048
23+
opt_expr -undriven
24+
opt_clean
25+
stat
26+
write_verilog sim/spram_8x4096_16x2048_post_synth.v
27+
select -assert-count 1 t:TDP36K
28+
29+
select -clear
30+
design -load bram_tdp
31+
select spram_8x2048_16x1024
32+
select *
33+
synth_quicklogic -family qlf_k6n10f -top spram_8x2048_16x1024
34+
opt_expr -undriven
35+
opt_clean
36+
stat
37+
write_verilog sim/spram_8x2048_16x1024_post_synth.v
38+
select -assert-count 1 t:TDP36K
39+
40+
select -clear
41+
design -load bram_tdp
42+
select spram_8x4096_32x1024
43+
select *
44+
synth_quicklogic -family qlf_k6n10f -top spram_8x4096_32x1024
45+
opt_expr -undriven
46+
opt_clean
47+
stat
48+
write_verilog sim/spram_8x4096_32x1024_post_synth.v
49+
select -assert-count 1 t:TDP36K
50+
51+
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Copyright 2020-2022 F4PGA Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
17+
module spram_16x2048_32x1024 (
18+
clk,
19+
rce,
20+
ra,
21+
rq,
22+
wce,
23+
wa,
24+
wd
25+
);
26+
input clk;
27+
input rce;
28+
input [9:0] ra;
29+
output reg [31:0] rq;
30+
input wce;
31+
input [10:0] wa;
32+
input [15:0] wd;
33+
reg [31:0] memory [0:1023];
34+
always @(posedge clk) begin
35+
if (rce)
36+
rq <= memory[ra];
37+
if (wce)
38+
memory[wa / 2][(wa % 2) * 16+:16] <= wd;
39+
end
40+
integer i;
41+
initial for (i = 0; i < 1024; i = i + 1)
42+
memory[i] = 0;
43+
endmodule
44+
45+
module spram_8x2048_16x1024 (
46+
clk,
47+
rce,
48+
ra,
49+
rq,
50+
wce,
51+
wa,
52+
wd
53+
);
54+
input clk;
55+
input rce;
56+
input [9:0] ra;
57+
output reg [15:0] rq;
58+
input wce;
59+
input [10:0] wa;
60+
input [7:0] wd;
61+
reg [15:0] memory [0:1023];
62+
always @(posedge clk) begin
63+
if (rce)
64+
rq <= memory[ra];
65+
if (wce)
66+
memory[wa / 2][(wa % 2) * 8+:8] <= wd;
67+
end
68+
integer i;
69+
initial for (i = 0; i < 1024; i = i + 1)
70+
memory[i] = 0;
71+
endmodule
72+
73+
module spram_8x4096_16x2048 (
74+
clk,
75+
rce,
76+
ra,
77+
rq,
78+
wce,
79+
wa,
80+
wd
81+
);
82+
input clk;
83+
input rce;
84+
input [10:0] ra;
85+
output reg [15:0] rq;
86+
input wce;
87+
input [11:0] wa;
88+
input [7:0] wd;
89+
reg [15:0] memory [0:2047];
90+
always @(posedge clk) begin
91+
if (rce)
92+
rq <= memory[ra];
93+
if (wce)
94+
memory[wa / 2][(wa % 2) * 8+:8] <= wd;
95+
end
96+
integer i;
97+
initial for (i = 0; i < 2048; i = i + 1)
98+
memory[i] = 0;
99+
endmodule
100+
101+
module spram_8x4096_32x1024 (
102+
clk,
103+
rce,
104+
ra,
105+
rq,
106+
wce,
107+
wa,
108+
wd
109+
);
110+
input clk;
111+
input rce;
112+
input [9:0] ra;
113+
output reg [31:0] rq;
114+
input wce;
115+
input [11:0] wa;
116+
input [7:0] wd;
117+
reg [31:0] memory [0:1023];
118+
always @(posedge clk) begin
119+
if (rce)
120+
rq <= memory[ra];
121+
if (wce)
122+
memory[wa / 4][(wa % 4) * 8+:8] <= wd;
123+
end
124+
integer i;
125+
initial for (i = 0; i < 1024; i = i + 1)
126+
memory[i] = 0;
127+
endmodule
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2020-2022 F4PGA Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
TESTBENCH = bram_asymmetric_wider_read_tb.v
18+
POST_SYNTH = spram_16x2048_32x1024_post_synth spram_8x4096_16x2048_post_synth spram_8x2048_16x1024_post_synth spram_8x4096_32x1024_post_synth
19+
READ_ADDR_WIDTH = 10 11 10 10
20+
WRITE_ADDR_WIDTH = 11 12 11 12
21+
READ_DATA_WIDTH = 32 16 16 32
22+
WRITE_DATA_WIDTH = 16 8 8 8
23+
TOP = spram_16x2048_32x1024 spram_8x4096_16x2048 spram_8x2048_16x1024 spram_8x4096_32x1024
24+
READ_ADDR_DEFINES = $(foreach awidth, $(READ_ADDR_WIDTH),-DREAD_ADDR_WIDTH="$(awidth)")
25+
WRITE_ADDR_DEFINES = $(foreach awidth, $(WRITE_ADDR_WIDTH),-DWRITE_ADDR_WIDTH="$(awidth)")
26+
READ_DATA_DEFINES = $(foreach dwidth, $(READ_DATA_WIDTH),-DREAD_DATA_WIDTH="$(dwidth)")
27+
WRITE_DATA_DEFINES = $(foreach dwidth, $(WRITE_DATA_WIDTH),-DWRITE_DATA_WIDTH="$(dwidth)")
28+
TOP_DEFINES = $(foreach top, $(TOP),-DTOP="$(top)")
29+
VCD_DEFINES = $(foreach vcd, $(POST_SYNTH),-DVCD="$(vcd).vcd")
30+
31+
SIM_LIBS = $(shell find ../../../../qlf_k6n10f -name "*.v" -not -name "*_map.v")
32+
33+
define simulate_post_synth
34+
@iverilog -vvvv -g2005 $(word $(1),$(READ_ADDR_DEFINES)) $(word $(1),$(WRITE_ADDR_DEFINES)) $(word $(1),$(READ_DATA_DEFINES)) $(word $(1),$(WRITE_DATA_DEFINES)) $(word $(1),$(TOP_DEFINES)) $(word $(1),$(VCD_DEFINES)) -o $(word $(1),$(POST_SYNTH)).vvp $(word $(1),$(POST_SYNTH)).v $(SIM_LIBS) $(TESTBENCH) > $(word $(1),$(POST_SYNTH)).vvp.log 2>&1
35+
@vvp -vvvv $(word $(1),$(POST_SYNTH)).vvp > $(word $(1),$(POST_SYNTH)).vcd.log 2>&1
36+
endef
37+
38+
define clean_post_synth_sim
39+
@rm -rf $(word $(1),$(POST_SYNTH)).vcd $(word $(1),$(POST_SYNTH)).vvp $(word $(1),$(POST_SYNTH)).vvp.log $(word $(1),$(POST_SYNTH)).vcd.log
40+
endef
41+
42+
sim:
43+
$(call simulate_post_synth,1)
44+
$(call simulate_post_synth,2)
45+
$(call simulate_post_synth,3)
46+
$(call simulate_post_synth,4)
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// Copyright 2020-2022 F4PGA Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
17+
`timescale 1ns/1ps
18+
19+
`define STRINGIFY(x) `"x`"
20+
21+
module TB;
22+
localparam PERIOD = 50;
23+
localparam ADDR_INCR = 1;
24+
25+
reg clk;
26+
reg rce;
27+
reg [`READ_ADDR_WIDTH-1:0] ra;
28+
wire [`READ_DATA_WIDTH-1:0] rq;
29+
reg wce;
30+
reg [`WRITE_ADDR_WIDTH-1:0] wa;
31+
reg [`WRITE_DATA_WIDTH-1:0] wd;
32+
33+
initial clk = 0;
34+
initial ra = 0;
35+
initial rce = 0;
36+
initial forever #(PERIOD / 2.0) clk = ~clk;
37+
initial begin
38+
$dumpfile(`STRINGIFY(`VCD));
39+
$dumpvars;
40+
end
41+
42+
integer a;
43+
44+
reg done;
45+
initial done = 1'b0;
46+
47+
reg [`READ_DATA_WIDTH-1:0] expected;
48+
49+
always @(posedge clk) begin
50+
case (`READ_DATA_WIDTH / `WRITE_DATA_WIDTH)
51+
1: expected <= (a | (a << 20) | 20'h55000) & {`WRITE_DATA_WIDTH{1'b1}};
52+
2: expected <= ((((2*a+1) | ((2*a+1) << 20) | 20'h55000) & {`WRITE_DATA_WIDTH{1'b1}}) << `WRITE_DATA_WIDTH) |
53+
(((2*a) | ((2*a) << 20) | 20'h55000) & {`WRITE_DATA_WIDTH{1'b1}});
54+
4: expected <= (((4*a) | ((4*a) << 20) | 20'h55000) & {`WRITE_DATA_WIDTH{1'b1}}) |
55+
((((4*a+1) | ((4*a+1) << 20) | 20'h55000) & {`WRITE_DATA_WIDTH{1'b1}}) << `WRITE_DATA_WIDTH) |
56+
((((4*a+2) | ((4*a+2) << 20) | 20'h55000) & {`WRITE_DATA_WIDTH{1'b1}}) << (2 * `WRITE_DATA_WIDTH)) |
57+
((((4*a+3) | ((4*a+3) << 20) | 20'h55000) & {`WRITE_DATA_WIDTH{1'b1}}) << (3 * `WRITE_DATA_WIDTH));
58+
default: expected <= ((a) | ((a) << 20) | 20'h55000) & {`WRITE_DATA_WIDTH{1'b1}};
59+
endcase
60+
end
61+
62+
wire error = ((a != 0) && read_test) ? rq !== expected : 0;
63+
64+
integer error_cnt = 0;
65+
always @ (posedge clk)
66+
begin
67+
if (error)
68+
error_cnt <= error_cnt + 1'b1;
69+
end
70+
71+
reg read_test;
72+
initial read_test = 0;
73+
74+
initial #(1) begin
75+
// Write data
76+
for (a = 0; a < (1<<`WRITE_ADDR_WIDTH); a = a + ADDR_INCR) begin
77+
@(negedge clk) begin
78+
wa = a;
79+
wd = a | (a << 20) | 20'h55000;
80+
wce = 1;
81+
end
82+
@(posedge clk) begin
83+
#(PERIOD/10) wce = 0;
84+
end
85+
end
86+
// Read data
87+
read_test = 1;
88+
for (a = 0; a < (1<<`READ_ADDR_WIDTH); a = a + ADDR_INCR) begin
89+
@(negedge clk) begin
90+
ra = a;
91+
rce = 1;
92+
end
93+
@(posedge clk) begin
94+
#(PERIOD/10) rce = 0;
95+
if ( rq !== expected) begin
96+
$display("%d: FAIL: mismatch act=%x exp=%x at %x", $time, rq, expected, a);
97+
end else begin
98+
$display("%d: OK: act=%x exp=%x at %x", $time, rq, expected, a);
99+
end
100+
end
101+
end
102+
done = 1'b1;
103+
end
104+
105+
// Scan for simulation finish
106+
always @(posedge clk) begin
107+
if (done)
108+
$finish_and_return( (error_cnt == 0) ? 0 : -1 );
109+
end
110+
111+
case (`STRINGIFY(`TOP))
112+
"spram_16x2048_32x1024": begin
113+
spram_16x2048_32x1024 #() simple (
114+
.clk(clk),
115+
.rce(rce),
116+
.ra(ra),
117+
.rq(rq),
118+
.wce(wce),
119+
.wa(wa),
120+
.wd(wd)
121+
);
122+
end
123+
"spram_8x4096_16x2048": begin
124+
spram_8x4096_16x2048 #() simple (
125+
.clk(clk),
126+
.rce(rce),
127+
.ra(ra),
128+
.rq(rq),
129+
.wce(wce),
130+
.wa(wa),
131+
.wd(wd)
132+
);
133+
end
134+
"spram_8x2048_16x1024": begin
135+
spram_8x2048_16x1024 #() simple (
136+
.clk(clk),
137+
.rce(rce),
138+
.ra(ra),
139+
.rq(rq),
140+
.wce(wce),
141+
.wa(wa),
142+
.wd(wd)
143+
);
144+
end
145+
"spram_8x4096_32x1024": begin
146+
spram_8x4096_32x1024 #() simple (
147+
.clk(clk),
148+
.rce(rce),
149+
.ra(ra),
150+
.rq(rq),
151+
.wce(wce),
152+
.wa(wa),
153+
.wd(wd)
154+
);
155+
end
156+
endcase
157+
endmodule

0 commit comments

Comments
 (0)