From 2895a667844f91c64917ff2815e32d780f38a4f8 Mon Sep 17 00:00:00 2001 From: Claire Xenia Wolf Date: Tue, 6 Dec 2022 16:00:48 +0100 Subject: Bugfix in splitcells pass Signed-off-by: Claire Xenia Wolf --- passes/cmds/splitcells.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/passes/cmds/splitcells.cc b/passes/cmds/splitcells.cc index eb04380fe..de6df6142 100644 --- a/passes/cmds/splitcells.cc +++ b/passes/cmds/splitcells.cc @@ -76,9 +76,14 @@ struct SplitcellsWorker std::vector slices; slices.push_back(0); - for (int i = 1; i < GetSize(outsig); i++) { - auto &last_users = bit_users_db.at(outsig[slices.back()]); - auto &this_users = bit_users_db.at(outsig[i]); + int width = GetSize(outsig); + width = std::min(width, GetSize(cell->getPort(ID::A))); + if (cell->hasPort(ID::B)) + width = std::min(width, GetSize(cell->getPort(ID::B))); + + for (int i = 1; i < width; i++) { + auto &last_users = bit_users_db[outsig[slices.back()]]; + auto &this_users = bit_users_db[outsig[i]]; if (last_users != this_users) slices.push_back(i); } if (GetSize(slices) <= 1) return 0; @@ -98,8 +103,11 @@ struct SplitcellsWorker auto slice_signal = [&](SigSpec old_sig) -> SigSpec { SigSpec new_sig; - for (int i = 0; i < GetSize(old_sig); i += GetSize(outsig)) - new_sig.append(old_sig.extract(i+slice_lsb, slice_msb-slice_lsb+1)); + for (int i = 0; i < GetSize(old_sig); i += GetSize(outsig)) { + int offset = i+slice_lsb; + int length = std::min(GetSize(old_sig)-offset, slice_msb-slice_lsb+1); + new_sig.append(old_sig.extract(offset, length)); + } return new_sig; }; -- cgit v1.2.3