aboutsummaryrefslogtreecommitdiffstats
path: root/common/router1.cc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2018-07-22 02:16:03 +0200
committerClifford Wolf <clifford@clifford.at>2018-07-22 02:16:03 +0200
commitc6e4ad322745b478f0f289f4cc5f3668e05700ac (patch)
tree6fb6435880ba1ebaad9e016948961c5539475122 /common/router1.cc
parent1e96999863da24021c215a3706b5a442789ba3a7 (diff)
downloadnextpnr-c6e4ad322745b478f0f289f4cc5f3668e05700ac.tar.gz
nextpnr-c6e4ad322745b478f0f289f4cc5f3668e05700ac.tar.bz2
nextpnr-c6e4ad322745b478f0f289f4cc5f3668e05700ac.zip
Move common patterns from router1 to Context API
Signed-off-by: Clifford Wolf <clifford@clifford.at>
Diffstat (limited to 'common/router1.cc')
-rw-r--r--common/router1.cc214
1 files changed, 64 insertions, 150 deletions
diff --git a/common/router1.cc b/common/router1.cc
index f8d86a5b..dbe3a003 100644
--- a/common/router1.cc
+++ b/common/router1.cc
@@ -263,42 +263,26 @@ struct Router
if (ctx->debug)
log(" Source: %s.%s.\n", net_info->driver.cell->name.c_str(ctx), net_info->driver.port.c_str(ctx));
- auto src_bel = net_info->driver.cell->bel;
-
- if (src_bel == BelId())
- log_error("Source cell %s (%s) is not mapped to a bel.\n", net_info->driver.cell->name.c_str(ctx),
- net_info->driver.cell->type.c_str(ctx));
-
- if (ctx->debug)
- log(" Source bel: %s\n", ctx->getBelName(src_bel).c_str(ctx));
-
- IdString driver_port = net_info->driver.port;
-
- auto driver_port_it = net_info->driver.cell->pins.find(driver_port);
- if (driver_port_it != net_info->driver.cell->pins.end())
- driver_port = driver_port_it->second;
-
- auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port));
+ auto src_wire = ctx->getNetinfoSourceWire(net_info);
if (src_wire == WireId())
- log_error("No wire found for port %s (pin %s) on source cell %s "
- "(bel %s).\n",
- net_info->driver.port.c_str(ctx), driver_port.c_str(ctx), net_info->driver.cell->name.c_str(ctx),
- ctx->getBelName(src_bel).c_str(ctx));
+ log_error("No wire found for port %s on source cell %s.\n",
+ net_info->driver.port.c_str(ctx), net_info->driver.cell->name.c_str(ctx));
if (ctx->debug)
log(" Source wire: %s\n", ctx->getWireName(src_wire).c_str(ctx));
std::unordered_map<WireId, delay_t> src_wires;
- std::vector<PortRef> users_array;
+ std::vector<int> users_array;
if (user_idx < 0) {
// route all users
- users_array = net_info->users;
+ for (int user_idx = 0; user_idx < int(net_info->users.size()); user_idx++)
+ users_array.push_back(user_idx);
ctx->shuffle(users_array);
} else {
// route only the selected user
- users_array.push_back(net_info->users[user_idx]);
+ users_array.push_back(user_idx);
}
if (reroute) {
@@ -312,30 +296,12 @@ struct Router
ctx->bindWire(src_wire, net_name, STRENGTH_WEAK);
src_wires[src_wire] = ctx->getWireDelay(src_wire).maxDelay();
- for (auto &user_it : net_info->users) {
- auto dst_bel = user_it.cell->bel;
-
- if (dst_bel == BelId())
- log_error("Destination cell %s (%s) is not mapped to a bel.\n", user_it.cell->name.c_str(ctx),
- user_it.cell->type.c_str(ctx));
-
- if (ctx->debug)
- log(" Destination bel: %s\n", ctx->getBelName(dst_bel).c_str(ctx));
-
- IdString user_port = user_it.port;
-
- auto user_port_it = user_it.cell->pins.find(user_port);
-
- if (user_port_it != user_it.cell->pins.end())
- user_port = user_port_it->second;
-
- auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port));
+ for (int user_idx = 0; user_idx < int(net_info->users.size()); user_idx++) {
+ auto dst_wire = ctx->getNetinfoSinkWire(net_info, user_idx);
if (dst_wire == WireId())
- log_error("No wire found for port %s (pin %s) on destination "
- "cell %s (bel %s).\n",
- user_it.port.c_str(ctx), user_port.c_str(ctx), user_it.cell->name.c_str(ctx),
- ctx->getBelName(dst_bel).c_str(ctx));
+ log_error("No wire found for port %s on destination cell %s.\n",
+ net_info->users[user_idx].port.c_str(ctx), net_info->users[user_idx].cell->name.c_str(ctx));
std::function<delay_t(WireId)> register_existing_path =
[ctx, net_info, &src_wires, &register_existing_path](WireId wire) -> delay_t {
@@ -379,33 +345,15 @@ struct Router
}
}
- for (auto &user_it : users_array) {
- if (ctx->debug)
- log(" Route to: %s.%s.\n", user_it.cell->name.c_str(ctx), user_it.port.c_str(ctx));
-
- auto dst_bel = user_it.cell->bel;
-
- if (dst_bel == BelId())
- log_error("Destination cell %s (%s) is not mapped to a bel.\n", user_it.cell->name.c_str(ctx),
- user_it.cell->type.c_str(ctx));
-
+ for (int user_idx : users_array) {
if (ctx->debug)
- log(" Destination bel: %s\n", ctx->getBelName(dst_bel).c_str(ctx));
-
- IdString user_port = user_it.port;
+ log(" Route to: %s.%s.\n", net_info->users[user_idx].cell->name.c_str(ctx), net_info->users[user_idx].port.c_str(ctx));
- auto user_port_it = user_it.cell->pins.find(user_port);
-
- if (user_port_it != user_it.cell->pins.end())
- user_port = user_port_it->second;
-
- auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port));
+ auto dst_wire = ctx->getNetinfoSinkWire(net_info, user_idx);
if (dst_wire == WireId())
- log_error("No wire found for port %s (pin %s) on destination "
- "cell %s (bel %s).\n",
- user_it.port.c_str(ctx), user_port.c_str(ctx), user_it.cell->name.c_str(ctx),
- ctx->getBelName(dst_bel).c_str(ctx));
+ log_error("No wire found for port %s on destination cell %s.\n",
+ net_info->users[user_idx].port.c_str(ctx), net_info->users[user_idx].cell->name.c_str(ctx));
if (ctx->debug) {
log(" Destination wire: %s\n", ctx->getWireName(dst_wire).c_str(ctx));
@@ -509,25 +457,11 @@ void addFullNetRouteJob(Context *ctx, IdString net_name, std::unordered_map<IdSt
if (net_info->driver.cell == nullptr)
return;
- auto src_bel = net_info->driver.cell->bel;
-
- if (src_bel == BelId())
- log_error("Source cell %s (%s) is not mapped to a bel.\n", net_info->driver.cell->name.c_str(ctx),
- net_info->driver.cell->type.c_str(ctx));
-
- IdString driver_port = net_info->driver.port;
-
- auto driver_port_it = net_info->driver.cell->pins.find(driver_port);
- if (driver_port_it != net_info->driver.cell->pins.end())
- driver_port = driver_port_it->second;
-
- auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port));
+ auto src_wire = ctx->getNetinfoSourceWire(net_info);
if (src_wire == WireId())
- log_error("No wire found for port %s (pin %s) on source cell %s "
- "(bel %s).\n",
- net_info->driver.port.c_str(ctx), driver_port.c_str(ctx), net_info->driver.cell->name.c_str(ctx),
- ctx->getBelName(src_bel).c_str(ctx));
+ log_error("No wire found for port %s on source cell %s.\n",
+ net_info->driver.port.c_str(ctx), net_info->driver.cell->name.c_str(ctx));
auto &net_cache = cache[net_name];
@@ -546,41 +480,25 @@ void addFullNetRouteJob(Context *ctx, IdString net_name, std::unordered_map<IdSt
if (net_cache[user_idx])
continue;
- auto &user_info = net_info->users[user_idx];
- auto dst_bel = user_info.cell->bel;
-
- if (dst_bel == BelId())
- log_error("Destination cell %s (%s) is not mapped to a bel.\n", user_info.cell->name.c_str(ctx),
- user_info.cell->type.c_str(ctx));
-
- IdString user_port = user_info.port;
-
- auto user_port_it = user_info.cell->pins.find(user_port);
-
- if (user_port_it != user_info.cell->pins.end())
- user_port = user_port_it->second;
-
- auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port));
+ auto dst_wire = ctx->getNetinfoSinkWire(net_info, user_idx);
if (dst_wire == WireId())
- log_error("No wire found for port %s (pin %s) on destination "
- "cell %s (bel %s).\n",
- user_info.port.c_str(ctx), user_port.c_str(ctx), user_info.cell->name.c_str(ctx),
- ctx->getBelName(dst_bel).c_str(ctx));
+ log_error("No wire found for port %s on destination cell %s.\n",
+ net_info->users[user_idx].port.c_str(ctx), net_info->users[user_idx].cell->name.c_str(ctx));
if (user_idx == 0)
- job.slack = user_info.budget - ctx->estimateDelay(src_wire, dst_wire);
+ job.slack = net_info->users[user_idx].budget - ctx->estimateDelay(src_wire, dst_wire);
else
- job.slack = std::min(job.slack, user_info.budget - ctx->estimateDelay(src_wire, dst_wire));
+ job.slack = std::min(job.slack, net_info->users[user_idx].budget - ctx->estimateDelay(src_wire, dst_wire));
WireId cursor = dst_wire;
while (src_wire != cursor) {
auto it = net_info->wires.find(cursor);
if (it == net_info->wires.end()) {
if (!got_slack)
- job.slack = user_info.budget - ctx->estimateDelay(src_wire, dst_wire);
+ job.slack = net_info->users[user_idx].budget - ctx->estimateDelay(src_wire, dst_wire);
else
- job.slack = std::min(job.slack, user_info.budget - ctx->estimateDelay(src_wire, dst_wire));
+ job.slack = std::min(job.slack, net_info->users[user_idx].budget - ctx->estimateDelay(src_wire, dst_wire));
got_slack = true;
break;
}
@@ -603,25 +521,11 @@ void addNetRouteJobs(Context *ctx, IdString net_name, std::unordered_map<IdStrin
if (net_info->driver.cell == nullptr)
return;
- auto src_bel = net_info->driver.cell->bel;
-
- if (src_bel == BelId())
- log_error("Source cell %s (%s) is not mapped to a bel.\n", net_info->driver.cell->name.c_str(ctx),
- net_info->driver.cell->type.c_str(ctx));
-
- IdString driver_port = net_info->driver.port;
-
- auto driver_port_it = net_info->driver.cell->pins.find(driver_port);
- if (driver_port_it != net_info->driver.cell->pins.end())
- driver_port = driver_port_it->second;
-
- auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port));
+ auto src_wire = ctx->getNetinfoSourceWire(net_info);
if (src_wire == WireId())
- log_error("No wire found for port %s (pin %s) on source cell %s "
- "(bel %s).\n",
- net_info->driver.port.c_str(ctx), driver_port.c_str(ctx), net_info->driver.cell->name.c_str(ctx),
- ctx->getBelName(src_bel).c_str(ctx));
+ log_error("No wire found for port %s on source cell %s.\n",
+ net_info->driver.port.c_str(ctx), net_info->driver.cell->name.c_str(ctx));
auto &net_cache = cache[net_name];
@@ -632,41 +536,20 @@ void addNetRouteJobs(Context *ctx, IdString net_name, std::unordered_map<IdStrin
if (net_cache[user_idx])
continue;
- auto &user_info = net_info->users[user_idx];
- auto dst_bel = user_info.cell->bel;
-
- if (dst_bel == BelId())
- log_error("Destination cell %s (%s) is not mapped to a bel.\n", user_info.cell->name.c_str(ctx),
- user_info.cell->type.c_str(ctx));
-
- IdString user_port = user_info.port;
-
- auto user_port_it = user_info.cell->pins.find(user_port);
-
- if (user_port_it != user_info.cell->pins.end())
- user_port = user_port_it->second;
-
- auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port));
+ auto dst_wire = ctx->getNetinfoSinkWire(net_info, user_idx);
if (dst_wire == WireId())
- log_error("No wire found for port %s (pin %s) on destination "
- "cell %s (bel %s).\n",
- user_info.port.c_str(ctx), user_port.c_str(ctx), user_info.cell->name.c_str(ctx),
- ctx->getBelName(dst_bel).c_str(ctx));
+ log_error("No wire found for port %s on destination cell %s.\n",
+ net_info->users[user_idx].port.c_str(ctx), net_info->users[user_idx].cell->name.c_str(ctx));
WireId cursor = dst_wire;
while (src_wire != cursor) {
auto it = net_info->wires.find(cursor);
if (it == net_info->wires.end()) {
- if (ctx->debug)
- log("Adding job [%s %d]: %s %s (%s) -> %s %s (%s)\n", net_name.c_str(ctx), user_idx,
- ctx->getBelName(src_bel).c_str(ctx), driver_port.c_str(ctx),
- ctx->getWireName(src_wire).c_str(ctx), ctx->getBelName(dst_bel).c_str(ctx),
- user_port.c_str(ctx), ctx->getWireName(dst_wire).c_str(ctx));
RouteJob job;
job.net = net_name;
job.user_idx = user_idx;
- job.slack = user_info.budget - ctx->estimateDelay(src_wire, dst_wire);
+ job.slack = net_info->users[user_idx].budget - ctx->estimateDelay(src_wire, dst_wire);
job.randtag = ctx->rng();
queue.push(job);
net_cache[user_idx] = true;
@@ -870,6 +753,37 @@ bool router1(Context *ctx)
totalVisitCnt, (100.0 * totalRevisitCnt) / totalVisitCnt,
(100.0 * totalOvertimeRevisitCnt) / totalVisitCnt);
+ {
+ float tns = 0;
+ int tns_net_count = 0;
+ int tns_arc_count = 0;
+ for (auto &net_it : ctx->nets) {
+ bool got_negative_slack = false;
+ NetInfo *net_info = ctx->nets.at(net_it.first).get();
+ for (int user_idx = 0; user_idx < int(net_info->users.size()); user_idx++) {
+ delay_t arc_delay = ctx->getNetinfoRouteDelay(net_info, user_idx);
+ delay_t arc_budget = net_info->users[user_idx].budget;
+ delay_t arc_slack = arc_budget - arc_delay;
+ if (arc_slack < 0) {
+ if (!got_negative_slack) {
+ if (ctx->verbose)
+ log_info("net %s has negative slack arcs:\n", net_info->name.c_str(ctx));
+ tns_net_count++;
+ }
+ if (ctx->verbose)
+ log_info(" arc %s -> %s has %f ns slack (delay %f, budget %f)\n",
+ ctx->getWireName(ctx->getNetinfoSourceWire(net_info)).c_str(ctx),
+ ctx->getWireName(ctx->getNetinfoSinkWire(net_info, user_idx)).c_str(ctx),
+ ctx->getDelayNS(arc_slack), ctx->getDelayNS(arc_delay), ctx->getDelayNS(arc_budget));
+ tns += ctx->getDelayNS(arc_slack);
+ tns_arc_count++;
+ }
+ }
+ }
+ log_info("final tns with respect to arc budgets: %f ns (%d nets, %d arcs)\n",
+ tns, tns_net_count, tns_arc_count);
+ }
+
NPNR_ASSERT(jobQueue.empty());
jobCache.clear();