diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/nextpnr.h | 5 | ||||
-rw-r--r-- | common/placer1.cc | 13 | ||||
-rw-r--r-- | common/router1.cc | 2 | ||||
-rw-r--r-- | common/timing.cc | 96 | ||||
-rw-r--r-- | common/timing.h | 4 |
5 files changed, 52 insertions, 68 deletions
diff --git a/common/nextpnr.h b/common/nextpnr.h index c4c05ae0..38a313fd 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -204,6 +204,11 @@ struct DecalXY { DecalId decal; float x = 0, y = 0; + + bool operator==(const DecalXY &other) const + { + return (decal == other.decal && x == other.x && y == other.y); + } }; struct BelPin diff --git a/common/placer1.cc b/common/placer1.cc index 264f1eba..d0771e5c 100644 --- a/common/placer1.cc +++ b/common/placer1.cc @@ -75,10 +75,10 @@ class SAPlacer bool place() { log_break(); + ctx->lock(); size_t placed_cells = 0; // Initial constraints placer - ctx->lock(); for (auto &cell_entry : ctx->cells) { CellInfo *cell = cell_entry.second.get(); auto loc = cell->attrs.find(ctx->id("BEL")); @@ -112,6 +112,7 @@ class SAPlacer } int constr_placed_cells = placed_cells; log_info("Placed %d cells based on constraints.\n", int(placed_cells)); + ctx->yield(); // Sort to-place cells for deterministic initial placement std::vector<CellInfo *> autoplaced; @@ -123,28 +124,25 @@ class SAPlacer } std::sort(autoplaced.begin(), autoplaced.end(), [](CellInfo *a, CellInfo *b) { return a->name < b->name; }); ctx->shuffle(autoplaced); - ctx->unlock(); // Place cells randomly initially log_info("Creating initial placement for remaining %d cells.\n", int(autoplaced.size())); for (auto cell : autoplaced) { - ctx->lock(); place_initial(cell); placed_cells++; if ((placed_cells - constr_placed_cells) % 500 == 0) log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), int(autoplaced.size())); - ctx->unlock(); } if ((placed_cells - constr_placed_cells) % 500 != 0) log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), int(autoplaced.size())); + ctx->yield(); log_info("Running simulated annealing placer.\n"); // Calculate metric after initial placement - ctx->lock(); curr_metric = 0; curr_tns = 0; for (auto &net : ctx->nets) { @@ -152,7 +150,6 @@ class SAPlacer metrics[net.first] = wl; curr_metric += wl; } - ctx->unlock(); int n_no_progress = 0; wirelen_t min_metric = curr_metric; @@ -257,7 +254,7 @@ class SAPlacer ctx->yield(); } // Final post-pacement validitiy check - ctx->lock(); + ctx->yield(); for (auto bel : ctx->getBels()) { IdString cell = ctx->getBoundBelCell(bel); if (!ctx->isBelLocationValid(bel)) { @@ -275,7 +272,7 @@ class SAPlacer } } } - compute_fmax(ctx, true /* print_fmax */); + timing_analysis(ctx, true /* print_fmax */); ctx->unlock(); return true; } diff --git a/common/router1.cc b/common/router1.cc index 2ae54245..d1551363 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -814,7 +814,7 @@ bool router1(Context *ctx) #ifndef NDEBUG ctx->check(); #endif - compute_fmax(ctx, true /* print_fmax */, true /* print_path */); + timing_analysis(ctx, true /* print_fmax */, true /* print_path */); ctx->unlock(); return true; } catch (log_execution_error_exception) { diff --git a/common/timing.cc b/common/timing.cc index f720b772..20cfd1b5 100644 --- a/common/timing.cc +++ b/common/timing.cc @@ -26,14 +26,13 @@ NEXTPNR_NAMESPACE_BEGIN -typedef std::unordered_map<const PortInfo *, delay_t> UpdateMap; typedef std::list<const PortRef *> PortRefList; -static delay_t follow_net(Context *ctx, NetInfo *net, int path_length, delay_t slack, UpdateMap *updates, +static delay_t follow_net(Context *ctx, NetInfo *net, int path_length, delay_t slack, bool update, delay_t &min_slack, PortRefList *current_path, PortRefList *crit_path); // Follow a path, returning budget to annotate -static delay_t follow_user_port(Context *ctx, PortRef &user, int path_length, delay_t slack, UpdateMap *updates, +static delay_t follow_user_port(Context *ctx, PortRef &user, int path_length, delay_t slack, bool update, delay_t &min_slack, PortRefList *current_path, PortRefList *crit_path) { delay_t value; @@ -58,7 +57,7 @@ static delay_t follow_user_port(Context *ctx, PortRef &user, int path_length, de if (is_path) { NetInfo *net = port.second.net; if (net) { - delay_t path_budget = follow_net(ctx, net, path_length, slack - comb_delay, updates, min_slack, + delay_t path_budget = follow_net(ctx, net, path_length, slack - comb_delay, update, min_slack, current_path, crit_path); value = std::min(value, path_budget); } @@ -66,16 +65,10 @@ static delay_t follow_user_port(Context *ctx, PortRef &user, int path_length, de } } } - - if (updates) { - auto ret = updates->emplace(&user.cell->ports.at(user.port), value); - if (!ret.second) - ret.first->second = std::min(value, ret.first->second); - } return value; } -static delay_t follow_net(Context *ctx, NetInfo *net, int path_length, delay_t slack, UpdateMap *updates, +static delay_t follow_net(Context *ctx, NetInfo *net, int path_length, delay_t slack, bool update, delay_t &min_slack, PortRefList *current_path, PortRefList *crit_path) { delay_t net_budget = slack / (path_length + 1); @@ -92,14 +85,16 @@ static delay_t follow_net(Context *ctx, NetInfo *net, int path_length, delay_t s } net_budget = std::min(net_budget, follow_user_port(ctx, usr, pl, slack - ctx->getNetinfoRouteDelay(net, i), - updates, min_slack, current_path, crit_path)); + update, min_slack, current_path, crit_path)); + if (update) + usr.budget = std::min(usr.budget, net_budget); if (crit_path) current_path->pop_back(); } return net_budget; } -static delay_t compute_min_slack(Context *ctx, UpdateMap *updates, PortRefList *crit_path) +static delay_t walk_paths(Context *ctx, bool update, PortRefList *crit_path) { delay_t default_slack = delay_t(1.0e12 / ctx->target_freq); delay_t min_slack = default_slack; @@ -119,7 +114,7 @@ static delay_t compute_min_slack(Context *ctx, UpdateMap *updates, PortRefList * if (ctx->getCellDelay(cell.second.get(), clock_domain, port.first, clkToQ)) slack -= clkToQ; if (port.second.net) - follow_net(ctx, port.second.net, 0, slack, updates, min_slack, ¤t_path, crit_path); + follow_net(ctx, port.second.net, 0, slack, update, min_slack, ¤t_path, crit_path); } } } @@ -140,32 +135,10 @@ void assign_budget(Context *ctx) } } - UpdateMap updates; - delay_t min_slack = compute_min_slack(ctx, &updates, nullptr); + delay_t min_slack = walk_paths(ctx, true, nullptr); - // If user has not specified a frequency, adjust the target frequency dynamically - // TODO(eddieh): Tune these factors - if (!ctx->user_freq) { - if (min_slack < 0) - ctx->target_freq = 1e12 / (default_slack - 0.95 * min_slack); - else - ctx->target_freq = 1e12 / (default_slack - 1.2 * min_slack); - if (ctx->verbose) - log_info("minimum slack for this assign = %d, target Fmax for next update = %.2f MHz\n", min_slack, - ctx->target_freq / 1e6); - } - - // Update the budgets for (auto &net : ctx->nets) { - for (size_t i = 0; i < net.second->users.size(); ++i) { - auto &user = net.second->users[i]; - auto pi = &user.cell->ports.at(user.port); - auto budget = ctx->getNetinfoRouteDelay(net.second.get(), i); - auto it = updates.find(pi); - if (it != updates.end()) - budget += it->second; - user.budget = ctx->getBudgetOverride(net.second.get(), i, budget); - + for (auto &user : net.second->users) { // Post-update check if (ctx->user_freq && user.budget < 0) log_warning("port %s.%s, connected to net '%s', has negative " @@ -180,27 +153,29 @@ void assign_budget(Context *ctx) } } + // If user has not specified a frequency, adjust the target frequency dynamically + // TODO(eddieh): Tune these factors + if (!ctx->user_freq) { + if (min_slack < 0) + ctx->target_freq = 1e12 / (default_slack - 0.95 * min_slack); + else + ctx->target_freq = 1e12 / (default_slack - 1.2 * min_slack); + if (ctx->verbose) + log_info("minimum slack for this assign = %d, target Fmax for next update = %.2f MHz\n", min_slack, + ctx->target_freq / 1e6); + } + log_info("Checksum: 0x%08x\n", ctx->checksum()); } void update_budget(Context *ctx) { - UpdateMap updates; - delay_t min_slack = compute_min_slack(ctx, &updates, nullptr); - - // Update the budgets - for (auto &net : ctx->nets) { - for (size_t i = 0; i < net.second->users.size(); ++i) { - auto &user = net.second->users[i]; - auto pi = &user.cell->ports.at(user.port); - auto budget = ctx->getNetinfoRouteDelay(net.second.get(), i); - auto it = updates.find(pi); - if (it != updates.end()) - budget += it->second; - user.budget = ctx->getBudgetOverride(net.second.get(), i, budget); + delay_t min_slack = walk_paths(ctx, true, nullptr); - // Post-update check - if (ctx->verbose) { + if (ctx->verbose) { + for (auto &net : ctx->nets) { + for (auto &user : net.second->users) { + // Post-update check if (ctx->user_freq && user.budget < 0) log_warning("port %s.%s, connected to net '%s', has negative " "timing budget of %fns\n", @@ -215,21 +190,25 @@ void update_budget(Context *ctx) } } - // If user has not specified a frequency, adjust the frequency dynamically: + // If user has not specified a frequency, adjust the target frequency dynamically + // TODO(eddieh): Tune these factors if (!ctx->user_freq) { delay_t default_slack = delay_t(1.0e12 / ctx->target_freq); - ctx->target_freq = 1e12 / (default_slack - min_slack); + if (min_slack < 0) + ctx->target_freq = 1e12 / (default_slack - 0.95 * min_slack); + else + ctx->target_freq = 1e12 / (default_slack - 1.2 * min_slack); if (ctx->verbose) - log_info("minimum slack for this update = %d, target Fmax for next update = %.2f MHz\n", min_slack, + log_info("minimum slack for this assign = %d, target Fmax for next update = %.2f MHz\n", min_slack, ctx->target_freq / 1e6); } } -void compute_fmax(Context *ctx, bool print_fmax, bool print_path) +delay_t timing_analysis(Context *ctx, bool print_fmax, bool print_path) { delay_t default_slack = delay_t(1.0e12 / ctx->target_freq); PortRefList crit_path; - delay_t min_slack = compute_min_slack(ctx, nullptr, &crit_path); + delay_t min_slack = walk_paths(ctx, false, &crit_path); if (print_path) { delay_t total = 0; log_break(); @@ -267,6 +246,7 @@ void compute_fmax(Context *ctx, bool print_fmax, bool print_path) } if (print_fmax) log_info("estimated Fmax = %.2f MHz\n", 1e6 / (default_slack - min_slack)); + return min_slack; } NEXTPNR_NAMESPACE_END diff --git a/common/timing.h b/common/timing.h index a1e12ab3..de4f7bbe 100644 --- a/common/timing.h +++ b/common/timing.h @@ -30,7 +30,9 @@ void assign_budget(Context *ctx); // Evenly redistribute the total path slack amongst all sinks on each path void update_budget(Context *ctx); -void compute_fmax(Context *ctx, bool print_fmax = false, bool print_path = false); +// Perform timing analysis and return the minimum path slack, +// optionally, print out the fmax and critical path +delay_t timing_analysis(Context *ctx, bool print_fmax = false, bool print_path = false); NEXTPNR_NAMESPACE_END |