Move common patterns from router1 to Context API
Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
parent
1e96999863
commit
c6e4ad3227
@ -51,6 +51,62 @@ void IdString::initialize_add(const BaseCtx *ctx, const char *s, int idx)
|
||||
ctx->idstring_idx_to_str->push_back(&insert_rc.first->first);
|
||||
}
|
||||
|
||||
WireId Context::getNetinfoSourceWire(NetInfo *net_info) const
|
||||
{
|
||||
if (net_info->driver.cell == nullptr)
|
||||
return WireId();
|
||||
|
||||
auto src_bel = net_info->driver.cell->bel;
|
||||
|
||||
if (src_bel == BelId())
|
||||
return WireId();
|
||||
|
||||
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;
|
||||
|
||||
return getWireBelPin(src_bel, portPinFromId(driver_port));
|
||||
}
|
||||
|
||||
WireId Context::getNetinfoSinkWire(NetInfo *net_info, int user_idx) const
|
||||
{
|
||||
auto &user_info = net_info->users[user_idx];
|
||||
auto dst_bel = user_info.cell->bel;
|
||||
|
||||
if (dst_bel == BelId())
|
||||
return WireId();
|
||||
|
||||
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;
|
||||
|
||||
return getWireBelPin(dst_bel, portPinFromId(user_port));
|
||||
}
|
||||
|
||||
delay_t Context::getNetinfoRouteDelay(NetInfo *net_info, int user_idx) const
|
||||
{
|
||||
WireId src_wire = getNetinfoSourceWire(net_info);
|
||||
WireId cursor = getNetinfoSinkWire(net_info, user_idx);
|
||||
delay_t delay = getWireDelay(src_wire).maxDelay();
|
||||
|
||||
while (cursor != WireId() && cursor != src_wire) {
|
||||
auto it = net_info->wires.find(cursor);
|
||||
if (it == net_info->wires.end())
|
||||
break;
|
||||
PipId pip = it->second.pip;
|
||||
delay += getPipDelay(pip).maxDelay();
|
||||
delay += getWireDelay(cursor).maxDelay();
|
||||
cursor = getPipSrcWire(pip);
|
||||
}
|
||||
|
||||
return delay;
|
||||
}
|
||||
|
||||
static uint32_t xorshift32(uint32_t x)
|
||||
{
|
||||
x ^= x << 13;
|
||||
|
@ -460,6 +460,10 @@ struct Context : Arch, DeterministicRNG
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
WireId getNetinfoSourceWire(NetInfo *net_info) const;
|
||||
WireId getNetinfoSinkWire(NetInfo *net_info, int user_idx) const;
|
||||
delay_t getNetinfoRouteDelay(NetInfo *net_info, int user_idx) const;
|
||||
|
||||
// provided by router1.cc
|
||||
bool getActualRouteDelay(WireId src_wire, WireId dst_wire, delay_t &delay);
|
||||
|
||||
|
@ -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, ®ister_existing_path](WireId wire) -> delay_t {
|
||||
@ -379,33 +345,15 @@ struct Router
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &user_it : users_array) {
|
||||
for (int user_idx : users_array) {
|
||||
if (ctx->debug)
|
||||
log(" Route to: %s.%s.\n", user_it.cell->name.c_str(ctx), user_it.port.c_str(ctx));
|
||||
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 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));
|
||||
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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user