mem/extract_rdff: Fix "no FF made" edge case.
authorMarcelina Kościelnicka <mwk@0x04.net>
Tue, 25 May 2021 20:39:50 +0000 (22:39 +0200)
committerMarcelina Kościelnicka <mwk@0x04.net>
Tue, 25 May 2021 21:42:31 +0000 (23:42 +0200)
When converting a sync transparent read port with const address to async
read port, nothing at all needs to be done other than clk_enable change,
and thus we have no FF cell to return.  Handle this case correctly in
the helper and in its users.

kernel/mem.cc
passes/memory/memory_nordff.cc

index 5d0a01dd2c66a098bcb0c17862712138cd40a02e..fe88be5d7bc0c46b2817467f19d870bc94af9186 100644 (file)
@@ -579,7 +579,8 @@ Cell *Mem::extract_rdff(int idx, FfInitVals *initvals) {
                        if (port.addr[i].wire)
                                width++;
 
-               if (width) {
+               if (width)
+               {
                        SigSpec sig_q = module->addWire(stringf("$%s$rdreg[%d]$q", memid.c_str(), idx), width);
                        SigSpec sig_d;
 
@@ -591,6 +592,8 @@ Cell *Mem::extract_rdff(int idx, FfInitVals *initvals) {
                                }
 
                        c = module->addDff(stringf("$%s$rdreg[%d]", memid.c_str(), idx), port.clk, sig_d, sig_q, port.clk_polarity);
+               } else {
+                       c = nullptr;
                }
        }
        else
index 665efceb202bb754b0e86128c74e836ec28fb1ae..80f78ca77ae3e21164b160d93160afad23d8d3db 100644 (file)
@@ -57,9 +57,12 @@ struct MemoryNordffPass : public Pass {
                        for (auto &mem : Mem::get_selected_memories(module))
                        {
                                bool changed = false;
-                               for (int i = 0; i < GetSize(mem.rd_ports); i++)
-                                       if (mem.extract_rdff(i, &initvals))
+                               for (int i = 0; i < GetSize(mem.rd_ports); i++) {
+                                       if (mem.rd_ports[i].clk_enable) {
+                                               mem.extract_rdff(i, &initvals);
                                                changed = true;
+                                       }
+                               }
 
                                if (changed)
                                        mem.emit();