memory_dff: Recognize read ports with reset / initial value.
authorMarcelina Kościelnicka <mwk@0x04.net>
Thu, 27 May 2021 19:08:11 +0000 (21:08 +0200)
committerMarcelina Kościelnicka <mwk@0x04.net>
Wed, 11 Aug 2021 12:17:48 +0000 (14:17 +0200)
passes/memory/memory_dff.cc
tests/memories/read_arst.v [new file with mode: 0644]
tests/memories/read_two_mux.v
tests/memories/run-test.sh

index e6b4b2400dc73b965165b593546bbd082a80eeff..8ad131c7c1685b07cdc912b8611d5f3a175a2b81 100644 (file)
@@ -60,11 +60,6 @@ struct MemoryDffWorker
                        log("output FF has both set and reset, not supported.\n");
                        return;
                }
-               if (ff.has_srst || ff.has_arst || !ff.val_init.is_fully_undef()) {
-                       // TODO: not supported yet
-                       log("output FF has reset and/or init value, not supported yet.\n");
-                       return;
-               }
                merger.remove_output_ff(bits);
                if (ff.has_en && !ff.pol_en)
                        ff.sig_en = module->LogicNot(NEW_ID, ff.sig_en);
@@ -79,7 +74,6 @@ struct MemoryDffWorker
                        port.en = ff.sig_en;
                else
                        port.en = State::S1;
-#if 0
                if (ff.has_arst) {
                        port.arst = ff.sig_arst;
                        port.arst_value = ff.val_arst;
@@ -94,7 +88,6 @@ struct MemoryDffWorker
                        port.srst = State::S0;
                }
                port.init_value = ff.val_init;
-#endif
                port.data = ff.sig_q;
                mem.emit();
                log("merged output FF to cell.\n");
diff --git a/tests/memories/read_arst.v b/tests/memories/read_arst.v
new file mode 100644 (file)
index 0000000..6100cc4
--- /dev/null
@@ -0,0 +1,27 @@
+// expect-wr-ports 1
+// expect-rd-ports 1
+// expect-rd-clk \clk
+// expect-rd-en \re
+// expect-rd-arst-sig \reset
+// expect-rd-arst-val 8'01011010
+// expect-rd-init-val 8'00111100
+
+module top(input clk, input we, re, reset, input [7:0] addr, wdata, output reg [7:0] rdata);
+
+reg [7:0] bram[0:255];
+initial rdata = 8'h3c;
+
+always @(posedge clk) begin
+       if (we)
+               bram[addr] <= wdata;
+end
+
+always @(posedge clk, posedge reset) begin
+       if (reset)
+               rdata <= 8'h5a;
+       else if (re)
+               rdata <= bram[addr];
+end
+
+endmodule
+
index 4f2e7e1cd7b92664cb9476b8fdf65c688c58e810..8b609c5521d8d622e1d90d6ea97d5b2d7246ebd9 100644 (file)
@@ -1,6 +1,9 @@
 // expect-wr-ports 1
 // expect-rd-ports 1
-// expect-no-rd-clk
+// expect-rd-clk \clk
+// expect-rd-en \re
+// expect-rd-srst-sig \reset
+// expect-rd-srst-val 8'00000000
 
 module top(input clk, input we, re, reset, input [7:0] addr, wdata, output reg [7:0] rdata);
 
index cded3eb40a537a413dacfb3d320a844d0174d99d..49922e3da8ff841123a95886f9963d3a8ea18ef5 100755 (executable)
@@ -31,6 +31,30 @@ for f in `egrep -l 'expect-(wr-ports|rd-ports|rd-clk)' *.v`; do
                grep -q "connect \\\\RD_CLK \\$(gawk '/expect-rd-clk/ { print $3; }' $f)\$" ${f%.v}.dmp ||
                                { echo " ERROR: Unexpected read clock."; false; }
        fi
+       if grep -q expect-rd-en $f; then
+               grep -q "connect \\\\RD_EN \\$(gawk '/expect-rd-en/ { print $3; }' $f)\$" ${f%.v}.dmp ||
+                               { echo " ERROR: Unexpected read enable."; false; }
+       fi
+       if grep -q expect-rd-srst-sig $f; then
+               grep -q "connect \\\\RD_SRST \\$(gawk '/expect-rd-srst-sig/ { print $3; }' $f)\$" ${f%.v}.dmp ||
+                               { echo " ERROR: Unexpected read sync reset."; false; }
+       fi
+       if grep -q expect-rd-srst-val $f; then
+               grep -q "parameter \\\\RD_SRST_VALUE $(gawk '/expect-rd-srst-val/ { print $3; }' $f)\$" ${f%.v}.dmp ||
+                               { echo " ERROR: Unexpected read sync reset value."; false; }
+       fi
+       if grep -q expect-rd-arst-sig $f; then
+               grep -q "connect \\\\RD_ARST \\$(gawk '/expect-rd-arst-sig/ { print $3; }' $f)\$" ${f%.v}.dmp ||
+                               { echo " ERROR: Unexpected read async reset."; false; }
+       fi
+       if grep -q expect-rd-arst-val $f; then
+               grep -q "parameter \\\\RD_ARST_VALUE $(gawk '/expect-rd-arst-val/ { print $3; }' $f)\$" ${f%.v}.dmp ||
+                               { echo " ERROR: Unexpected read async reset value."; false; }
+       fi
+       if grep -q expect-rd-init-val $f; then
+               grep -q "parameter \\\\RD_INIT_VALUE $(gawk '/expect-rd-init-val/ { print $3; }' $f)\$" ${f%.v}.dmp ||
+                               { echo " ERROR: Unexpected read init value."; false; }
+       fi
        if grep -q expect-no-rd-clk $f; then
                grep -q "connect \\\\RD_CLK 1'x\$" ${f%.v}.dmp ||
                                { echo " ERROR: Expected no read clock."; false; }