From 90086698679d8a3c5f9e58d619bc18a284ab17e1 Mon Sep 17 00:00:00 2001 From: David Shah Date: Tue, 19 Jun 2018 14:44:49 +0200 Subject: Major performance improvement to placement validity check Signed-off-by: David Shah --- ice40/arch.h | 8 ++++++-- ice40/arch_place.cc | 51 ++++++++++++++++++++++++++++++--------------------- ice40/arch_place.h | 26 ++++++++++++++++++++------ ice40/cells.cc | 7 ++++--- 4 files changed, 60 insertions(+), 32 deletions(-) (limited to 'ice40') diff --git a/ice40/arch.h b/ice40/arch.h index 0fdacfde..290bc9d3 100644 --- a/ice40/arch.h +++ b/ice40/arch.h @@ -279,8 +279,12 @@ template <> struct hash } }; -template <> struct hash : hash {}; -template <> struct hash : hash {}; +template <> struct hash : hash +{ +}; +template <> struct hash : hash +{ +}; } // namespace std NEXTPNR_NAMESPACE_BEGIN diff --git a/ice40/arch_place.cc b/ice40/arch_place.cc index c8806852..c607c9c6 100644 --- a/ice40/arch_place.cc +++ b/ice40/arch_place.cc @@ -24,6 +24,15 @@ NEXTPNR_NAMESPACE_BEGIN +PlaceValidityChecker::PlaceValidityChecker(Context *ctx) + : ctx(ctx), id_icestorm_lc(ctx, "ICESTORM_LC"), id_sb_io(ctx, "SB_IO"), + id_sb_gb(ctx, "SB_GB"), id_cen(ctx, "CEN"), id_clk(ctx, "CLK"), + id_sr(ctx, "SR"), id_i0(ctx, "I0"), id_i1(ctx, "I1"), + id_i2(ctx, "I2"), id_i3(ctx, "I3"), id_dff_en(ctx, "DFF_ENABLE"), + id_neg_clk(ctx, "NEG_CLK") +{ +} + static const NetInfo *get_net_or_empty(const CellInfo *cell, const IdString port) { @@ -34,20 +43,20 @@ static const NetInfo *get_net_or_empty(const CellInfo *cell, return nullptr; }; -static bool logicCellsCompatible(const Context *ctx, - const std::vector &cells) +bool PlaceValidityChecker::logicCellsCompatible( + const Context *ctx, const std::vector &cells) { bool dffs_exist = false, dffs_neg = false; const NetInfo *cen = nullptr, *clk = nullptr, *sr = nullptr; int locals_count = 0; for (auto cell : cells) { - if (bool_or_default(cell->params, "DFF_ENABLE")) { + if (bool_or_default(cell->params, id_dff_en)) { if (!dffs_exist) { dffs_exist = true; - cen = get_net_or_empty(cell, "CEN"); - clk = get_net_or_empty(cell, "CLK"); - sr = get_net_or_empty(cell, "SR"); + cen = get_net_or_empty(cell, id_cen); + clk = get_net_or_empty(cell, id_clk); + sr = get_net_or_empty(cell, id_sr); if (!is_global_net(ctx, cen) && cen != nullptr) locals_count++; @@ -56,25 +65,25 @@ static bool logicCellsCompatible(const Context *ctx, if (!is_global_net(ctx, sr) && sr != nullptr) locals_count++; - if (bool_or_default(cell->params, "NEG_CLK")) { + if (bool_or_default(cell->params, id_neg_clk)) { dffs_neg = true; } } else { - if (cen != get_net_or_empty(cell, "CEN")) + if (cen != get_net_or_empty(cell, id_cen)) return false; - if (clk != get_net_or_empty(cell, "CLK")) + if (clk != get_net_or_empty(cell, id_clk)) return false; - if (sr != get_net_or_empty(cell, "SR")) + if (sr != get_net_or_empty(cell, id_sr)) return false; - if (dffs_neg != bool_or_default(cell->params, "NEG_CLK")) + if (dffs_neg != bool_or_default(cell->params, id_neg_clk)) return false; } } - const NetInfo *i0 = get_net_or_empty(cell, "I0"), - *i1 = get_net_or_empty(cell, "I1"), - *i2 = get_net_or_empty(cell, "I2"), - *i3 = get_net_or_empty(cell, "I3"); + const NetInfo *i0 = get_net_or_empty(cell, id_i0), + *i1 = get_net_or_empty(cell, id_i1), + *i2 = get_net_or_empty(cell, id_i2), + *i3 = get_net_or_empty(cell, id_i3); if (i0 != nullptr) locals_count++; if (i1 != nullptr) @@ -88,7 +97,7 @@ static bool logicCellsCompatible(const Context *ctx, return locals_count <= 32; } -bool isBelLocationValid(Context *ctx, BelId bel) +bool PlaceValidityChecker::isBelLocationValid(BelId bel) { if (ctx->getBelType(bel) == TYPE_ICESTORM_LC) { std::vector cells; @@ -105,13 +114,13 @@ bool isBelLocationValid(Context *ctx, BelId bel) if (cellId == IdString()) return true; else - return isValidBelForCell(ctx, ctx->cells.at(cellId), bel); + return isValidBelForCell(ctx->cells.at(cellId), bel); } } -bool isValidBelForCell(Context *ctx, CellInfo *cell, BelId bel) +bool PlaceValidityChecker::isValidBelForCell(CellInfo *cell, BelId bel) { - if (cell->type == "ICESTORM_LC") { + if (cell->type == id_icestorm_lc) { assert(ctx->getBelType(bel) == TYPE_ICESTORM_LC); std::vector cells; @@ -126,9 +135,9 @@ bool isValidBelForCell(Context *ctx, CellInfo *cell, BelId bel) cells.push_back(cell); return logicCellsCompatible(ctx, cells); - } else if (cell->type == "SB_IO") { + } else if (cell->type == id_sb_io) { return ctx->getBelPackagePin(bel) != ""; - } else if (cell->type == "SB_GB") { + } else if (cell->type == id_sb_gb) { bool is_reset = false, is_cen = false; assert(cell->ports.at("GLOBAL_BUFFER_OUTPUT").net != nullptr); for (auto user : cell->ports.at("GLOBAL_BUFFER_OUTPUT").net->users) { diff --git a/ice40/arch_place.h b/ice40/arch_place.h index 3d05ed7a..d276b9c4 100644 --- a/ice40/arch_place.h +++ b/ice40/arch_place.h @@ -26,13 +26,27 @@ NEXTPNR_NAMESPACE_BEGIN -// Whether or not a given cell can be placed at a given Bel -// This is not intended for Bel type checks, but finer-grained constraints -// such as conflicting set/reset signals, etc -bool isValidBelForCell(Context *ctx, CellInfo *cell, BelId bel); +class PlaceValidityChecker +{ + public: + PlaceValidityChecker(Context *ctx); + // Whether or not a given cell can be placed at a given Bel + // This is not intended for Bel type checks, but finer-grained constraints + // such as conflicting set/reset signals, etc + bool isValidBelForCell(CellInfo *cell, BelId bel); -// Return true whether all Bels at a given location are valid -bool isBelLocationValid(Context *ctx, BelId bel); + // Return true whether all Bels at a given location are valid + bool isBelLocationValid(BelId bel); + + private: + bool logicCellsCompatible(const Context *ctx, + const std::vector &cells); + IdString id_icestorm_lc, id_sb_io, id_sb_gb; + IdString id_cen, id_clk, id_sr; + IdString id_i0, id_i1, id_i2, id_i3; + IdString id_dff_en, id_neg_clk; + Context *ctx; +}; NEXTPNR_NAMESPACE_END diff --git a/ice40/cells.cc b/ice40/cells.cc index 582e5c14..c2bc4609 100644 --- a/ice40/cells.cc +++ b/ice40/cells.cc @@ -211,9 +211,10 @@ void nxio_to_sb(Context *ctx, CellInfo *nxio, CellInfo *sbio) replace_port(tbuf, "E", sbio, "OUTPUT_ENABLE"); ctx->nets.erase(donet->name); if (!donet->users.empty()) - log_error("unsupported tristate IO pattern for IO buffer '%s', " - "instantiate SB_IO manually to ensure correct behaviour\n", - nxio->name.c_str(ctx)); + log_error( + "unsupported tristate IO pattern for IO buffer '%s', " + "instantiate SB_IO manually to ensure correct behaviour\n", + nxio->name.c_str(ctx)); ctx->cells.erase(tbuf->name); } } -- cgit v1.2.3