wreduce for $sub
authorEddie Hung <eddie@fpgeh.com>
Fri, 19 Jul 2019 19:50:21 +0000 (12:50 -0700)
committerEddie Hung <eddie@fpgeh.com>
Fri, 19 Jul 2019 19:50:21 +0000 (12:50 -0700)
passes/opt/wreduce.cc

index 1fbc4108264618c0f5aa288e1cec6ee970afbad8..e8c2cb7265363575a7c2baeac306938cf432a6c7 100644 (file)
@@ -365,6 +365,29 @@ struct WreduceWorker
                        }
                }
 
+               if (cell->type.in("$add", "$sub")) {
+                       SigSpec A = cell->getPort("\\A");
+                       SigSpec B = cell->getPort("\\B");
+                       bool sub = cell->type == "$sub";
+
+                       int i;
+                       for (i = 0; i < GetSize(sig); i++) {
+                               if (B[i] != S0 && (sub || A[i] != S0))
+                                       break;
+                               if (B[i] == S0)
+                                       module->connect(sig[i], A[i]);
+                               else if (A[i] == S0)
+                                       module->connect(sig[i], B[i]);
+                               else log_abort();
+                       }
+                       if (i > 0) {
+                               cell->setPort("\\A", A.extract(i, -1));
+                               cell->setPort("\\B", B.extract(i, -1));
+                               sig.remove(0, i);
+                               bits_removed += i;
+                       }
+               }
+
                if (GetSize(sig) == 0) {
                        log("Removed cell %s.%s (%s).\n", log_id(module), log_id(cell), log_id(cell->type));
                        module->remove(cell);