aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/placer1.cc13
-rw-r--r--common/router1.cc35
-rw-r--r--common/timing.cc121
-rw-r--r--common/timing.h2
-rw-r--r--ecp5/arch.cc5
-rw-r--r--ecp5/arch.h1
-rw-r--r--generic/arch.cc5
-rw-r--r--generic/arch.h1
-rw-r--r--ice40/arch.cc6
-rw-r--r--ice40/arch.h1
10 files changed, 186 insertions, 4 deletions
diff --git a/common/placer1.cc b/common/placer1.cc
index 025c7c15..461fc4e8 100644
--- a/common/placer1.cc
+++ b/common/placer1.cc
@@ -151,6 +151,7 @@ class SAPlacer
ctx->unlock();
int n_no_progress = 0;
+ wirelen_t min_metric = curr_metric;
double avg_metric = curr_metric;
temp = 10000;
@@ -176,6 +177,11 @@ class SAPlacer
}
}
+ if (curr_metric < min_metric) {
+ min_metric = curr_metric;
+ improved = true;
+ }
+
// Heuristic to improve placement on the 8k
if (improved)
n_no_progress = 0;
@@ -230,6 +236,9 @@ class SAPlacer
ctx->shuffle(autoplaced);
assign_budget(ctx);
}
+ else {
+ update_budget(ctx);
+ }
// Recalculate total metric entirely to avoid rounding errors
// accumulating over time
@@ -378,8 +387,8 @@ class SAPlacer
// SA acceptance criterea
if (delta < 0 || (temp > 1e-6 && (ctx->rng() / float(0x3fffffff)) <= std::exp(-delta / temp))) {
n_accept++;
- if (delta < 2)
- improved = true;
+ //if (delta < 2)
+ // improved = true;
} else {
if (other != IdString())
ctx->unbindBel(oldBel);
diff --git a/common/router1.cc b/common/router1.cc
index fbf3c467..431770da 100644
--- a/common/router1.cc
+++ b/common/router1.cc
@@ -22,6 +22,7 @@
#include "log.h"
#include "router1.h"
+#include "timing.h"
namespace {
@@ -612,8 +613,38 @@ bool router1(Context *ctx)
std::unordered_set<IdString> normalRouteNets, ripupQueue;
- if (ctx->verbose || iterCnt == 1)
- log_info("routing queue contains %d jobs.\n", int(jobQueue.size()));
+ if (iterCnt == 1) {
+ if (ctx->verbose)
+ log_info("routing queue contains %d jobs.\n", int(jobQueue.size()));
+ } else {
+ static auto actual_delay = [](Context *ctx, WireId src, WireId dst) {
+ delay_t total_delay = 0;
+ WireId last = dst;
+ auto net_name = ctx->getBoundWireNet(src);
+ if (net_name != IdString()) {
+ auto net = ctx->nets.at(net_name).get();
+ while (last != src) {
+ total_delay += ctx->getWireDelay(last).maxDelay();
+ auto pip = net->wires.at(last).pip;
+ NPNR_ASSERT(ctx->getBoundPipNet(pip) == net_name);
+ total_delay += ctx->getPipDelay(pip).maxDelay();
+ last = ctx->getPipSrcWire(pip);
+ if (ctx->getBoundWireNet(last) != net_name) {
+ log_warning("Wire %s bound to %s not %s!\n", ctx->getWireName(last).c_str(ctx), ctx->getBoundWireNet(last).c_str(ctx), net_name.c_str(ctx));
+ break;
+ }
+ NPNR_ASSERT(ctx->getBoundWireNet(last) == net_name);
+ }
+ NPNR_ASSERT(last != WireId());
+ }
+ if (last != src)
+ total_delay += ctx->estimateDelay(src, last);
+ else
+ total_delay += ctx->getWireDelay(last).maxDelay();
+ return total_delay;
+ };
+ update_budget(ctx, actual_delay);
+ }
bool printNets = ctx->verbose && (jobQueue.size() < 10);
diff --git a/common/timing.cc b/common/timing.cc
index 3a48935f..0e84dded 100644
--- a/common/timing.cc
+++ b/common/timing.cc
@@ -22,6 +22,7 @@
#include <unordered_map>
#include <utility>
#include "log.h"
+#include "util.h"
NEXTPNR_NAMESPACE_BEGIN
@@ -114,4 +115,124 @@ void assign_budget(Context *ctx)
log_info("Checksum: 0x%08x\n", ctx->checksum());
}
+typedef std::unordered_map<const PortInfo*, delay_t> updates_t;
+typedef std::unordered_map<const PortInfo*, delay_t> delays_t;
+
+static delay_t follow_net_update(Context *ctx, NetInfo *net, int path_length, delay_t slack, const delays_t& delays, updates_t& updates);
+
+// Follow a path, returning budget to annotate
+static delay_t follow_user_port_update(Context *ctx, PortRef &user, int path_length, delay_t slack, const delays_t& delays, updates_t& updates)
+{
+ delay_t value;
+ if (ctx->getPortClock(user.cell, user.port) != IdString()) {
+ // At the end of a timing path (arguably, should check setup time
+ // here too)
+ value = slack / path_length;
+ } else {
+ // Default to the path ending here, if no further paths found
+ value = slack / path_length;
+ // Follow outputs of the user
+ for (auto& port : user.cell->ports) {
+ if (port.second.type == PORT_OUT) {
+ delay_t comb_delay;
+ // Look up delay through this path
+ bool is_path = ctx->getCellDelay(user.cell, user.port, port.first, comb_delay);
+ if (is_path) {
+ NetInfo *net = port.second.net;
+ if (net) {
+ delay_t path_budget = follow_net_update(ctx, net, path_length, slack - comb_delay, delays, updates);
+ value = std::min(value, path_budget);
+ }
+ }
+ }
+ }
+ }
+
+ auto ret = updates.emplace(&user.cell->ports.at(user.port), value);
+ if (!ret.second && value < ret.first->second) {
+ ret.first->second = value;
+ }
+ return value;
+}
+
+static delay_t follow_net_update(Context *ctx, NetInfo *net, int path_length, delay_t slack, const delays_t& delays,updates_t& updates)
+{
+ delay_t net_budget = slack / (path_length + 1);
+ for (auto& usr : net->users) {
+ net_budget = std::min(net_budget, follow_user_port_update(ctx, usr, path_length + 1, slack - get_or_default(delays, &usr.cell->ports.at(usr.port), 0.), delays, updates));
+ }
+ return net_budget;
+}
+
+void update_budget(Context *ctx, std::function<delay_t(Context*,WireId,WireId)> delay_fn)
+{
+ delays_t delays;
+ updates_t updates;
+
+ // Compute the delay for every pin on every net
+ for (auto &n : ctx->nets) {
+ auto net = n.second.get();
+
+ int driver_x, driver_y;
+ bool driver_gb;
+ CellInfo *driver_cell = net->driver.cell;
+ if (!driver_cell)
+ continue;
+ if (driver_cell->bel == BelId())
+ continue;
+ ctx->estimatePosition(driver_cell->bel, driver_x, driver_y, driver_gb);
+ WireId drv_wire = ctx->getWireBelPin(driver_cell->bel, ctx->portPinFromId(net->driver.port));
+ if (driver_gb)
+ continue;
+ for (auto& load : net->users) {
+ if (load.cell == nullptr)
+ continue;
+ CellInfo *load_cell = load.cell;
+ if (load_cell->bel == BelId())
+ continue;
+ WireId user_wire = ctx->getWireBelPin(load_cell->bel, ctx->portPinFromId(load.port));
+ delay_t raw_wl = delay_fn(ctx, drv_wire, user_wire);
+ delays.emplace(&load_cell->ports.at(load.port), raw_wl);
+ }
+ }
+
+ // Go through all clocked drivers and distribute the available path slack evenly into every budget
+ for (auto &cell : ctx->cells) {
+ for (auto& port : cell.second->ports) {
+ if (port.second.type == PORT_OUT) {
+ IdString clock_domain = ctx->getPortClock(cell.second.get(), port.first);
+ if (clock_domain != IdString()) {
+ if (port.second.net)
+ follow_net_update(ctx, port.second.net, 0, delay_t(1.0e12 / ctx->target_freq) - get_or_default(delays, &port.second, 0.), delays, updates);
+ }
+ }
+ }
+ }
+
+ // Update the budgets
+ for (auto &net : ctx->nets) {
+ for (auto& user : net.second->users) {
+ auto pi = &user.cell->ports.at(user.port);
+ auto it = updates.find(pi);
+ if (it == updates.end()) continue;
+ auto budget = delays.at(pi) + it->second;
+ user.budget = ctx->getBudgetOverride(net.second->driver, budget);
+
+ // Post-update check
+ if (ctx->verbose) {
+ if (user.budget < 0)
+ log_warning("port %s.%s, connected to net '%s', has negative "
+ "timing budget of %fns\n",
+ user.cell->name.c_str(ctx), user.port.c_str(ctx), net.first.c_str(ctx),
+ ctx->getDelayNS(user.budget));
+ else
+ log_info("port %s.%s, connected to net '%s', has "
+ "timing budget of %fns\n",
+ user.cell->name.c_str(ctx), user.port.c_str(ctx), net.first.c_str(ctx),
+ ctx->getDelayNS(user.budget));
+ }
+ }
+ }
+}
+
NEXTPNR_NAMESPACE_END
diff --git a/common/timing.h b/common/timing.h
index 025e4a76..8c098963 100644
--- a/common/timing.h
+++ b/common/timing.h
@@ -27,6 +27,8 @@ NEXTPNR_NAMESPACE_BEGIN
// Assign "budget" values for all user ports in the design
void assign_budget(Context *ctx);
+void update_budget(Context *ctx, std::function<delay_t(Context*,WireId,WireId)> delay_fn=&Context::estimateDelay);
+
NEXTPNR_NAMESPACE_END
#endif
diff --git a/ecp5/arch.cc b/ecp5/arch.cc
index 7d67dd0c..371dbb12 100644
--- a/ecp5/arch.cc
+++ b/ecp5/arch.cc
@@ -434,6 +434,11 @@ delay_t Arch::estimateDelay(WireId src, WireId dst) const
return 200 * (abs(src.location.x - dst.location.x) + abs(src.location.y - dst.location.y));
}
+delay_t Arch::getBudgetOverride(const PortRef& pr, delay_t v) const
+{
+ return v;
+}
+
// -----------------------------------------------------------------------
bool Arch::place() { return placer1(getCtx()); }
diff --git a/ecp5/arch.h b/ecp5/arch.h
index ce2b90c3..c2efb2bd 100644
--- a/ecp5/arch.h
+++ b/ecp5/arch.h
@@ -758,6 +758,7 @@ struct Arch : BaseCtx
delay_t getRipupDelayPenalty() const { return 200; }
float getDelayNS(delay_t v) const { return v * 0.001; }
uint32_t getDelayChecksum(delay_t v) const { return v; }
+ delay_t getBudgetOverride(const PortRef& pr, delay_t v) const;
// -------------------------------------------------
diff --git a/generic/arch.cc b/generic/arch.cc
index 0fff2e4c..f5e94778 100644
--- a/generic/arch.cc
+++ b/generic/arch.cc
@@ -384,6 +384,11 @@ delay_t Arch::estimateDelay(WireId src, WireId dst) const
return (dx + dy) * grid_distance_to_delay;
}
+delay_t Arch::getBudgetOverride(const PortRef& pr, delay_t v) const
+{
+ return v;
+}
+
// ---------------------------------------------------------------
bool Arch::place() { return placer1(getCtx()); }
diff --git a/generic/arch.h b/generic/arch.h
index 61e6b033..2b952da6 100644
--- a/generic/arch.h
+++ b/generic/arch.h
@@ -197,6 +197,7 @@ struct Arch : BaseCtx
delay_t getRipupDelayPenalty() const { return 1.0; }
float getDelayNS(delay_t v) const { return v; }
uint32_t getDelayChecksum(delay_t v) const { return 0; }
+ delay_t getBudgetOverride(const PortRef& pr, delay_t v) const;
bool pack() { return true; }
bool place();
diff --git a/ice40/arch.cc b/ice40/arch.cc
index 65b21afd..51fa6472 100644
--- a/ice40/arch.cc
+++ b/ice40/arch.cc
@@ -511,6 +511,12 @@ delay_t Arch::estimateDelay(WireId src, WireId dst) const
return xscale * abs(xd) + yscale * abs(yd) + offset;
}
+delay_t Arch::getBudgetOverride(const PortRef& pr, delay_t v) const
+{
+ if (pr.port == id("COUT")) return 0;
+ return v;
+}
+
// -----------------------------------------------------------------------
bool Arch::place() { return placer1(getCtx()); }
diff --git a/ice40/arch.h b/ice40/arch.h
index d4d71cfc..697d4142 100644
--- a/ice40/arch.h
+++ b/ice40/arch.h
@@ -691,6 +691,7 @@ struct Arch : BaseCtx
delay_t getRipupDelayPenalty() const { return 200; }
float getDelayNS(delay_t v) const { return v * 0.001; }
uint32_t getDelayChecksum(delay_t v) const { return v; }
+ delay_t getBudgetOverride(const PortRef& pr, delay_t v) const;
// -------------------------------------------------