From 8613ee17c8a673c81a9c38ac37671d50b77b9d8c Mon Sep 17 00:00:00 2001 From: Lofty Date: Tue, 10 Feb 2026 14:08:59 +0000 Subject: [PATCH] verify inversion before/after assigning bridges --- himbaechel/uarch/gatemate/bitstream.cc | 7 +++++++ himbaechel/uarch/gatemate/gatemate.cc | 29 +++++++++++++++++++++++++- himbaechel/uarch/gatemate/gatemate.h | 3 ++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/himbaechel/uarch/gatemate/bitstream.cc b/himbaechel/uarch/gatemate/bitstream.cc index d4c215f5..915f0d68 100644 --- a/himbaechel/uarch/gatemate/bitstream.cc +++ b/himbaechel/uarch/gatemate/bitstream.cc @@ -523,4 +523,11 @@ void GateMateImpl::write_bitstream(const std::string &device, const std::string be.write_bitstream(); } +bool GateMateImpl::need_inversion_remove_me_later(CellInfo *cell, IdString port) +{ + std::ofstream out("/dev/null"); + BitstreamBackend be(ctx, this, "", out); + return be.need_inversion(cell, port); +} + NEXTPNR_NAMESPACE_END diff --git a/himbaechel/uarch/gatemate/gatemate.cc b/himbaechel/uarch/gatemate/gatemate.cc index 361fe656..662dfba6 100644 --- a/himbaechel/uarch/gatemate/gatemate.cc +++ b/himbaechel/uarch/gatemate/gatemate.cc @@ -23,6 +23,7 @@ #include "idstringlist.h" #include "log.h" #include "nextpnr_assertions.h" +#include "nextpnr_types.h" #include "placer_heap.h" #define GEN_INIT_CONSTIDS @@ -373,7 +374,8 @@ bool GateMateImpl::checkPipAvail(PipId pip) const if (extra_data.value == 1 && IdString(extra_data.name).in(id_C_CLKSEL, id_C_ENSEL)) return false; } - if (!use_cp_for_cpe && extra_data.type == PipExtra::PIP_EXTRA_MUX && extra_data.resource !=0 && extra_data.resource <= PipMask::C_PY2_I) { + if (!use_cp_for_cpe && extra_data.type == PipExtra::PIP_EXTRA_MUX && extra_data.resource != 0 && + extra_data.resource <= PipMask::C_PY2_I) { return false; } if (!use_bridges && extra_data.type == PipExtra::PIP_EXTRA_MUX && @@ -593,6 +595,18 @@ void GateMateImpl::postRoute() { int num = 0; + dict, bool> inversion_before_bridges; + + for (auto &pair : ctx->cells) { + auto *cell = pair.second.get(); + for (auto &port : cell->ports) { + if (port.second.type != PORT_IN) + continue; + inversion_before_bridges.insert( + {std::make_pair(cell->name, port.first), need_inversion_remove_me_later(cell, port.first)}); + } + } + pool nets_with_bridges; pool nets_with_cplines; @@ -704,6 +718,19 @@ void GateMateImpl::postRoute() } } + for (auto &pair : inversion_before_bridges) { + auto cell_name = pair.first.first; + auto port = pair.first.second; + auto inversion_before = pair.second; + auto *cell = ctx->cells.at(cell_name).get(); + auto inversion_after = need_inversion_remove_me_later(cell, port); + + if (inversion_before != inversion_after) { + log_error("cell '%s.%s' of type '%s' differs in inversion!\n", cell_name.c_str(ctx), port.c_str(ctx), + cell->type.c_str(ctx)); + } + } + dict cfg; dict port_mapping; auto add_input = [&](IdString orig_port, IdString port, bool merged) -> bool { diff --git a/himbaechel/uarch/gatemate/gatemate.h b/himbaechel/uarch/gatemate/gatemate.h index 2d2d55e6..990a0b56 100644 --- a/himbaechel/uarch/gatemate/gatemate.h +++ b/himbaechel/uarch/gatemate/gatemate.h @@ -114,13 +114,14 @@ struct GateMateImpl : HimbaechelAPI MultiDieStrategy strategy; dict index_to_die; dict die_to_index; - dict> pass_backtrace; + dict> pass_backtrace; private: bool getChildPlacement(const BaseClusterInfo *cluster, Loc root_loc, std::vector> &placement) const; void write_bitstream(const std::string &device, const std::string &filename); + bool need_inversion_remove_me_later(CellInfo *cell, IdString port); void parse_ccf(const std::string &filename);