From c6e4ad322745b478f0f289f4cc5f3668e05700ac Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Sun, 22 Jul 2018 02:16:03 +0200 Subject: Move common patterns from router1 to Context API Signed-off-by: Clifford Wolf --- common/nextpnr.cc | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'common/nextpnr.cc') diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 3861e5fe..ac292e77 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -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; -- cgit v1.2.3 From 62b66e02085371c456dee95dc08d2cd41351c91f Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Sun, 22 Jul 2018 10:59:21 +0200 Subject: Rename getWireBelPin to getBelPinWire Signed-off-by: Clifford Wolf --- common/nextpnr.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'common/nextpnr.cc') diff --git a/common/nextpnr.cc b/common/nextpnr.cc index ac292e77..74747642 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -67,7 +67,7 @@ WireId Context::getNetinfoSourceWire(NetInfo *net_info) const if (driver_port_it != net_info->driver.cell->pins.end()) driver_port = driver_port_it->second; - return getWireBelPin(src_bel, portPinFromId(driver_port)); + return getBelPinWire(src_bel, portPinFromId(driver_port)); } WireId Context::getNetinfoSinkWire(NetInfo *net_info, int user_idx) const @@ -85,7 +85,7 @@ WireId Context::getNetinfoSinkWire(NetInfo *net_info, int user_idx) const if (user_port_it != user_info.cell->pins.end()) user_port = user_port_it->second; - return getWireBelPin(dst_bel, portPinFromId(user_port)); + return getBelPinWire(dst_bel, portPinFromId(user_port)); } delay_t Context::getNetinfoRouteDelay(NetInfo *net_info, int user_idx) const -- cgit v1.2.3 From a436facfd0a610c8b055e07d3a72e4122df677c6 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Mon, 23 Jul 2018 12:44:26 +0200 Subject: Add fallback to estimateDelay() in getNetinfoRouteDelay() Signed-off-by: Clifford Wolf --- common/nextpnr.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'common/nextpnr.cc') diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 74747642..2c50c9a1 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -92,7 +92,7 @@ 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(); + delay_t delay = 0; while (cursor != WireId() && cursor != src_wire) { auto it = net_info->wires.find(cursor); @@ -104,6 +104,11 @@ delay_t Context::getNetinfoRouteDelay(NetInfo *net_info, int user_idx) const cursor = getPipSrcWire(pip); } + if (cursor == src_wire) + delay += getWireDelay(src_wire).maxDelay(); + else + delay += estimateDelay(src_wire, cursor); + return delay; } -- cgit v1.2.3