diff options
author | Eddie Hung <eddie@fpgeh.com> | 2019-06-21 12:31:14 -0700 |
---|---|---|
committer | Eddie Hung <eddie@fpgeh.com> | 2019-06-21 12:31:14 -0700 |
commit | 545cfbbe0dcc36f18dce6429498f4d87112879e2 (patch) | |
tree | 640f7ef19cc7b86af29f384ee27fa88cfbccf097 /passes/opt | |
parent | 32f637ffdb0c0641b51227fad92bc80e284740d2 (diff) | |
download | yosys-545cfbbe0dcc36f18dce6429498f4d87112879e2.tar.gz yosys-545cfbbe0dcc36f18dce6429498f4d87112879e2.tar.bz2 yosys-545cfbbe0dcc36f18dce6429498f4d87112879e2.zip |
Cope with $reduce_or common in case
Diffstat (limited to 'passes/opt')
-rw-r--r-- | passes/opt/muxpack.cc | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/passes/opt/muxpack.cc b/passes/opt/muxpack.cc index 4468e8734..6697d6ca1 100644 --- a/passes/opt/muxpack.cc +++ b/passes/opt/muxpack.cc @@ -29,11 +29,13 @@ struct ExclusiveDatabase Module *module; const SigMap &sigmap; - dict<SigBit, std::pair<SigSpec,Const>> sig_cmp_prev; + dict<SigBit, std::pair<SigSpec,std::vector<Const>>> sig_cmp_prev; ExclusiveDatabase(Module *module, const SigMap &sigmap) : module(module), sigmap(sigmap) { - SigSpec const_sig, nonconst_sig, y_port; + SigSpec const_sig, nonconst_sig; + SigBit y_port; + pool<Cell*> reduce_or; for (auto cell : module->cells()) { if (cell->type == "$eq") { nonconst_sig = sigmap(cell->getPort("\\A")); @@ -50,11 +52,40 @@ struct ExclusiveDatabase const_sig = Const(RTLIL::S0, GetSize(nonconst_sig)); y_port = sigmap(cell->getPort("\\Y")); } + else if (cell->type == "$reduce_or") { + reduce_or.insert(cell); + continue; + } else continue; log_assert(!nonconst_sig.empty()); log_assert(!const_sig.empty()); - sig_cmp_prev[y_port] = std::make_pair(nonconst_sig,const_sig.as_const()); + sig_cmp_prev[y_port] = std::make_pair(nonconst_sig,std::vector<Const>{const_sig.as_const()}); + } + + for (auto cell : reduce_or) { + nonconst_sig = SigSpec(); + std::vector<Const> values; + SigSpec a_port = sigmap(cell->getPort("\\A")); + for (auto bit : a_port) { + auto it = sig_cmp_prev.find(bit); + if (it == sig_cmp_prev.end()) { + nonconst_sig = SigSpec(); + break; + } + if (nonconst_sig.empty()) + nonconst_sig = it->second.first; + else if (nonconst_sig != it->second.first) { + nonconst_sig = SigSpec(); + break; + } + for (auto value : it->second.second) + values.push_back(value); + } + if (nonconst_sig.empty()) + continue; + y_port = sigmap(cell->getPort("\\Y")); + sig_cmp_prev[y_port] = std::make_pair(nonconst_sig,std::move(values)); } } @@ -73,8 +104,9 @@ struct ExclusiveDatabase else if (nonconst_sig != it->second.first) return false; - if (!const_values.insert(it->second.second).second) - return false; + for (auto value : it->second.second) + if (!const_values.insert(value).second) + return false; } return true; |