From 72ff11fb9becb4209635a6e80612b05712f2ee7b Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Fri, 8 Nov 2024 16:43:52 -0800 Subject: [PATCH 1/4] remove output port bitblast index --- passes/cmds/splitnetlist.cc | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/passes/cmds/splitnetlist.cc b/passes/cmds/splitnetlist.cc index e5db7b5c2..3b9b76762 100644 --- a/passes/cmds/splitnetlist.cc +++ b/passes/cmds/splitnetlist.cc @@ -172,7 +172,33 @@ struct SplitNetlist : public ScriptPass { if (!wire->port_output) continue; std::string output_port_name = wire->name.c_str(); - std::string_view po_prefix = rtrim_until(std::string_view(output_port_name), '_'); + // We want to truncate the final __ part of the string + // Example: "add_Y_0_" + // Result: "add_Y" + bool bitblastedIndex = false; + std::string::iterator end = output_port_name.end()-1; + for (; end != output_port_name.begin(); end--) { + char c = (*end); + if ((end == output_port_name.end()-1) && (c == '_')) { + // bit blasted index + bitblastedIndex = true; + continue; + } + if (bitblastedIndex) { + if (c != '_') { + continue; + } else { + end--; + break; + } + } + } + if (!bitblastedIndex) + end = output_port_name.end()-1; + std::string no_bitblast_prefix; + std::copy(output_port_name.begin(), end, std::back_inserter(no_bitblast_prefix)); + // We then truncate the port name, Result: "add" + std::string_view po_prefix = rtrim_until(std::string_view(no_bitblast_prefix), '_'); std::set visitedCells; std::set visitedSigSpec; RTLIL::SigSpec actual = wire; From a8eb39f569f6699d263686271435894948553064 Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Sat, 9 Nov 2024 14:00:57 -0800 Subject: [PATCH 2/4] faster and simpler code --- passes/cmds/splitnetlist.cc | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/passes/cmds/splitnetlist.cc b/passes/cmds/splitnetlist.cc index 3b9b76762..bbf474459 100644 --- a/passes/cmds/splitnetlist.cc +++ b/passes/cmds/splitnetlist.cc @@ -172,29 +172,25 @@ struct SplitNetlist : public ScriptPass { if (!wire->port_output) continue; std::string output_port_name = wire->name.c_str(); + if (output_port_name.empty()) + continue; // We want to truncate the final __ part of the string // Example: "add_Y_0_" // Result: "add_Y" - bool bitblastedIndex = false; std::string::iterator end = output_port_name.end()-1; - for (; end != output_port_name.begin(); end--) { - char c = (*end); - if ((end == output_port_name.end()-1) && (c == '_')) { - // bit blasted index - bitblastedIndex = true; - continue; - } - if (bitblastedIndex) { - if (c != '_') { + if ((*end) == '_') { + // Last character is an _, it is a bit blasted index + end--; + for (; end != output_port_name.begin(); end--) { + if ((*end) != '_') { + // Truncate until the next _ continue; } else { - end--; + // Truncate the _ break; } } } - if (!bitblastedIndex) - end = output_port_name.end()-1; std::string no_bitblast_prefix; std::copy(output_port_name.begin(), end, std::back_inserter(no_bitblast_prefix)); // We then truncate the port name, Result: "add" From 21034a0b0a3be670174dd2e3b21bcc8042ab662b Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Sun, 10 Nov 2024 09:00:29 -0800 Subject: [PATCH 3/4] Support assign {a,b} = {c,d} with diff widths --- passes/cmds/splitnetlist.cc | 53 +++++++++++++++---------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/passes/cmds/splitnetlist.cc b/passes/cmds/splitnetlist.cc index bbf474459..ca84970f1 100644 --- a/passes/cmds/splitnetlist.cc +++ b/passes/cmds/splitnetlist.cc @@ -76,6 +76,16 @@ void sigCellDrivers(RTLIL::Design *design, dict sig2CellsInFanin[actual] = newSet; } newSet->insert(cell); + for (int i = 0; i < actual.size(); i++) { + SigSpec bit_sig = actual.extract(i, 1); + if (sig2CellsInFanin.count(bit_sig)) { + newSet = sig2CellsInFanin[bit_sig]; + } else { + newSet = new std::set; + sig2CellsInFanin[bit_sig] = newSet; + } + newSet->insert(cell); + } } } } @@ -92,38 +102,19 @@ void lhs2rhs(RTLIL::Design *design, dict &lhsSig continue; } if (!lhs.is_chunk()) { - if (lhs.chunks().size() != rhs.chunks().size()) { - auto rit = rhs.chunks().rbegin(); - long unsigned rhsSize = 0; - while (rit != rhs.chunks().rend()) { - RTLIL::SigSpec sub_rhs = *rit; - if (sub_rhs.is_fully_const()) { - rhsSize += (sub_rhs.as_chunk()).width; - } else { - rhsSize++; - } - rit++; - } - if (lhs.chunks().size() != rhsSize) { - continue; - } + std::vector lhsBits; + for (int i = 0; i < lhs.size(); i++) { + SigSpec bit_sig = lhs.extract(i, 1); + lhsBits.push_back(bit_sig); } - auto lit = lhs.chunks().rbegin(); - auto rit = rhs.chunks().rbegin(); - while (rit != rhs.chunks().rend()) { - RTLIL::SigSpec sub_lhs = *lit; - RTLIL::SigSpec sub_rhs = *rit; - if (sub_rhs.is_fully_const()) { - int constSize = (sub_rhs.as_chunk()).width; - while (constSize--) { - lit++; - } - rit++; - continue; - } - lhsSig2rhsSig[sub_lhs] = sub_rhs; - lit++; - rit++; + std::vector rhsBits; + for (int i = 0; i < rhs.size(); i++) { + SigSpec bit_sig = rhs.extract(i, 1); + rhsBits.push_back(bit_sig); + } + for (uint32_t i = 0; i < lhsBits.size(); i++) { + if (i < rhsBits.size()) + lhsSig2rhsSig[lhsBits[i]] = rhsBits[i]; } } else { lhsSig2rhsSig[lhs] = rhs; From ee8d9e74ac4ccc76131d547170a02018448e713b Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Sun, 10 Nov 2024 09:03:51 -0800 Subject: [PATCH 4/4] comment --- passes/cmds/splitnetlist.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/passes/cmds/splitnetlist.cc b/passes/cmds/splitnetlist.cc index ca84970f1..cd51ae250 100644 --- a/passes/cmds/splitnetlist.cc +++ b/passes/cmds/splitnetlist.cc @@ -102,6 +102,7 @@ void lhs2rhs(RTLIL::Design *design, dict &lhsSig continue; } if (!lhs.is_chunk()) { + // If lhs is not a chunk (leaf) ie: assign {a,b} = ..., then bitblast both lhs and rhs std::vector lhsBits; for (int i = 0; i < lhs.size(); i++) { SigSpec bit_sig = lhs.extract(i, 1);