From 0eb5c72cc5b95a7fb6b848e8d09ea9b235bce9b3 Mon Sep 17 00:00:00 2001 From: David Shah Date: Tue, 13 Oct 2020 09:49:53 +0100 Subject: nexus: Refactor cell pin style db Signed-off-by: David Shah --- nexus/arch.cc | 1 + nexus/arch.h | 5 ++++- nexus/fasm.cc | 4 ---- nexus/pack.cc | 25 ++----------------------- nexus/pins.cc | 19 +++++++++++++++++-- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/nexus/arch.cc b/nexus/arch.cc index 352f789a..63977d6f 100644 --- a/nexus/arch.cc +++ b/nexus/arch.cc @@ -117,6 +117,7 @@ Arch::Arch(ArchArgs args) : args(args) for (size_t i = 0; i < chip_info->num_tiles; i++) { tileStatus[i].boundcells.resize(db->loctypes[chip_info->grid[i].loc_type].num_bels); } + init_cell_pin_data(); // Validate and set up package package_idx = -1; for (size_t i = 0; i < chip_info->num_packages; i++) { diff --git a/nexus/arch.h b/nexus/arch.h index 700df103..d2349162 100644 --- a/nexus/arch.h +++ b/nexus/arch.h @@ -1364,7 +1364,10 @@ struct Arch : BaseCtx typedef std::unordered_map CellPinsData; - void get_cell_pin_data(std::unordered_map &cell_pins) const; + std::unordered_map cell_pins_db; + CellPinStyle get_cell_pin_style(CellInfo *cell, IdString port) const; + + void init_cell_pin_data(); // ------------------------------------------------- diff --git a/nexus/fasm.cc b/nexus/fasm.cc index 71b4c5c2..7d25de58 100644 --- a/nexus/fasm.cc +++ b/nexus/fasm.cc @@ -30,8 +30,6 @@ struct NexusFasmWriter std::ostream &out; std::vector fasm_ctx; - std::unordered_map cell_pins_db; - NexusFasmWriter(const Context *ctx, std::ostream &out) : ctx(ctx), out(out) {} // Add a 'dot' prefix to the FASM context stack @@ -285,8 +283,6 @@ struct NexusFasmWriter // Write out FASM for the whole design void operator()() { - // Setup pin DB - ctx->get_cell_pin_data(cell_pins_db); // Write routing for (auto n : sorted(ctx->nets)) { write_net(n.second); diff --git a/nexus/pack.cc b/nexus/pack.cc index 386c5f4b..b9472ed1 100644 --- a/nexus/pack.cc +++ b/nexus/pack.cc @@ -99,8 +99,6 @@ struct NexusPacker { Context *ctx; - std::unordered_map cell_db; - // Generic cell transformation // Given cell name map and port map // If port name is not found in port map; it will be copied as-is but stripping [] @@ -319,30 +317,12 @@ struct NexusPacker return new_net; } - CellPinStyle get_pin_style(CellInfo *cell, IdString port) - { - // Look up the pin style in the cell database - auto fnd_cell = cell_db.find(cell->type); - if (fnd_cell == cell_db.end()) - return PINSTYLE_NONE; - auto fnd_port = fnd_cell->second.find(port); - if (fnd_port != fnd_cell->second.end()) - return fnd_port->second; - // If there isn't an exact port match, then the empty IdString - // represents a wildcard default match - auto fnd_default = fnd_cell->second.find({}); - if (fnd_default != fnd_cell->second.end()) - return fnd_default->second; - - return PINSTYLE_NONE; - } - CellPinMux get_pin_needed_muxval(CellInfo *cell, IdString port) { NetInfo *net = get_net_or_empty(cell, port); if (net == nullptr || net->driver.cell == nullptr) { // Pin is disconnected, return its default value - CellPinStyle pin_style = get_pin_style(cell, port); + CellPinStyle pin_style = ctx->get_cell_pin_style(cell, port); if ((pin_style & PINDEF_MASK) == PINDEF_0) return PINMUX_0; else if ((pin_style & PINDEF_MASK) == PINDEF_1) @@ -450,7 +430,7 @@ struct NexusPacker continue; } - CellPinStyle pin_style = get_pin_style(cell, port_name); + CellPinStyle pin_style = ctx->get_cell_pin_style(cell, port_name); if (req_mux == PINMUX_INV) { // Pin is inverted. If there is a hard inverter; then use it @@ -648,7 +628,6 @@ struct NexusPacker void operator()() { - ctx->get_cell_pin_data(cell_db); pack_ffs(); pack_luts(); pack_io(); diff --git a/nexus/pins.cc b/nexus/pins.cc index 6d449438..1f0ef363 100644 --- a/nexus/pins.cc +++ b/nexus/pins.cc @@ -74,9 +74,24 @@ static const std::unordered_map base_cell_pin_data }; } // namespace -void Arch::get_cell_pin_data(std::unordered_map &cell_pins) const +void Arch::init_cell_pin_data() { cell_pins_db = base_cell_pin_data; } + +CellPinStyle Arch::get_cell_pin_style(CellInfo *cell, IdString port) const { - cell_pins = base_cell_pin_data; + // Look up the pin style in the cell database + auto fnd_cell = cell_pins_db.find(cell->type); + if (fnd_cell == cell_pins_db.end()) + return PINSTYLE_NONE; + auto fnd_port = fnd_cell->second.find(port); + if (fnd_port != fnd_cell->second.end()) + return fnd_port->second; + // If there isn't an exact port match, then the empty IdString + // represents a wildcard default match + auto fnd_default = fnd_cell->second.find({}); + if (fnd_default != fnd_cell->second.end()) + return fnd_default->second; + + return PINSTYLE_NONE; } NEXTPNR_NAMESPACE_END -- cgit v1.2.3