From ff6c9446c038bc23baffedb81178a6af3935ef32 Mon Sep 17 00:00:00 2001 From: George Rennie Date: Tue, 12 Nov 2024 01:05:15 +0100 Subject: [PATCH] bufnorm: preserve constant bits when mapping back to connections --- passes/techmap/bufnorm.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/passes/techmap/bufnorm.cc b/passes/techmap/bufnorm.cc index 163e42c0f70..a4552c71bd4 100644 --- a/passes/techmap/bufnorm.cc +++ b/passes/techmap/bufnorm.cc @@ -404,6 +404,17 @@ struct BufnormPass : public Pass { pool added_buffers; + const auto lookup_mapping = [&mapped_bits](const SigBit bit, bool default_sx = false) + { + if (!bit.is_wire()) + return bit; + + if (default_sx) + return mapped_bits.at(bit, State::Sx); + + return mapped_bits.at(bit); + }; + auto make_buffer_f = [&](const IdString &type, const SigSpec &src, const SigSpec &dst) { auto it = old_buffers.find(pair(type, dst)); @@ -438,12 +449,8 @@ struct BufnormPass : public Pass { bool chain_this_wire = chain_this_wire_f(wire); SigSpec keysig = sigmap(wire), insig = wire, outsig = wire; - for (int i = 0; i < GetSize(insig); i++) { - if (keysig[i].is_wire()) - insig[i] = mapped_bits.at(keysig[i], State::Sx); - else - insig[i] = keysig[i]; - } + for (int i = 0; i < GetSize(insig); i++) + insig[i] = lookup_mapping(keysig[i], true); if (chain_this_wire) { for (int i = 0; i < GetSize(outsig); i++) @@ -491,7 +498,7 @@ struct BufnormPass : public Pass { SigSpec newsig = conn.second; for (auto &bit : newsig) - bit = mapped_bits[sigmap(bit)]; + bit = lookup_mapping(sigmap(bit)); if (conn.second != newsig) { log(" fixing input signal on cell %s port %s: %s\n",