From 7b16c63101d46274cb3b93907489c8403e5d9bc5 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Sun, 14 Sep 2014 11:21:37 +0200 Subject: Merge $macc cells in alumacc pass --- passes/techmap/alumacc.cc | 60 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'passes') diff --git a/passes/techmap/alumacc.cc b/passes/techmap/alumacc.cc index 757dc7cf..5a15e825 100644 --- a/passes/techmap/alumacc.cc +++ b/passes/techmap/alumacc.cc @@ -57,6 +57,8 @@ struct AlumaccWorker if (!cell->type.in("$pos", "$neg", "$add", "$sub", "$mul")) continue; + log(" creating $macc model for %s (%s).\n", log_id(cell), log_id(cell->type)); + maccnode_t *n = new maccnode_t; Macc::port_t new_port; @@ -67,7 +69,6 @@ struct AlumaccWorker for (auto bit : n->y) n->users = std::max(n->users, bit_users.at(bit) - 1); - if (cell->type.in("$pos", "$neg")) { new_port.in_a = sigmap(cell->getPort("\\A")); @@ -103,6 +104,60 @@ struct AlumaccWorker } } + void merge_macc() + { + while (1) + { + std::set delete_nodes; + + for (auto &it : sig_macc) + { + auto n = it.second; + + if (delete_nodes.count(n)) + continue; + + for (int i = 0; i < SIZE(n->macc.ports); i++) + { + auto &port = n->macc.ports[i]; + + if (SIZE(port.in_b) > 0 || sig_macc.count(port.in_a) == 0) + continue; + + auto other_n = sig_macc.at(port.in_a); + + if (other_n->users > 1) + continue; + + if (SIZE(other_n->y) != SIZE(n->y)) + continue; + + log(" merging $macc model for %s into %s.\n", log_id(other_n->cell), log_id(n->cell)); + + bool do_subtract = port.do_subtract; + for (int j = 0; j < SIZE(other_n->macc.ports); j++) { + if (do_subtract) + other_n->macc.ports[j].do_subtract = !other_n->macc.ports[j].do_subtract; + if (j == 0) + n->macc.ports[i--] = other_n->macc.ports[j]; + else + n->macc.ports.push_back(other_n->macc.ports[j]); + } + + delete_nodes.insert(other_n); + } + } + + if (delete_nodes.empty()) + break; + + for (auto n : delete_nodes) { + sig_macc.erase(n->y); + delete n; + } + } + } + void replace_macc() { for (auto &it : sig_macc) @@ -121,8 +176,11 @@ struct AlumaccWorker void run() { + log("Extracting $alu and $macc cells in module %s:\n", log_id(module)); + count_bit_users(); extract_macc(); + merge_macc(); replace_macc(); } }; -- cgit v1.2.3