From 0daffec2a0efdbea36201eeb5666d208a10d0226 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Mon, 30 Jul 2018 15:35:40 +0200 Subject: [PATCH 1/3] Add predictDelay Arch API Signed-off-by: Clifford Wolf --- common/nextpnr.cc | 10 +++++----- ecp5/arch.cc | 5 +++++ ecp5/arch.h | 1 + generic/arch.cc | 9 +++++++++ generic/arch.h | 1 + ice40/arch.cc | 16 ++++++++++++++++ ice40/arch.h | 1 + 7 files changed, 38 insertions(+), 5 deletions(-) diff --git a/common/nextpnr.cc b/common/nextpnr.cc index cf1b5982..5b0a45ed 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -93,7 +93,9 @@ delay_t Context::getNetinfoRouteDelay(NetInfo *net_info, int user_idx) const WireId src_wire = getNetinfoSourceWire(net_info); if (src_wire == WireId()) return 0; - WireId cursor = getNetinfoSinkWire(net_info, user_idx); + + WireId dst_wire = getNetinfoSinkWire(net_info, user_idx); + WireId cursor = dst_wire; delay_t delay = 0; while (cursor != WireId() && cursor != src_wire) { @@ -107,11 +109,9 @@ delay_t Context::getNetinfoRouteDelay(NetInfo *net_info, int user_idx) const } if (cursor == src_wire) - delay += getWireDelay(src_wire).maxDelay(); - else - delay += estimateDelay(src_wire, cursor); + return delay + getWireDelay(src_wire).maxDelay(); - return delay; + return predictDelay(src_wire, dst_wire); } static uint32_t xorshift32(uint32_t x) diff --git a/ecp5/arch.cc b/ecp5/arch.cc index 55fe5704..88b5e4d4 100644 --- a/ecp5/arch.cc +++ b/ecp5/arch.cc @@ -413,6 +413,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::predictDelay(WireId src, WireId dst) const +{ + return 200 * (abs(src.location.x - dst.location.x) + abs(src.location.y - dst.location.y)); +} + // ----------------------------------------------------------------------- bool Arch::place() { return placer1(getCtx()); } diff --git a/ecp5/arch.h b/ecp5/arch.h index b6aac9cf..13f2db1f 100644 --- a/ecp5/arch.h +++ b/ecp5/arch.h @@ -776,6 +776,7 @@ struct Arch : BaseCtx // ------------------------------------------------- delay_t estimateDelay(WireId src, WireId dst) const; + delay_t predictDelay(WireId src, WireId dst) const; delay_t getDelayEpsilon() const { return 20; } delay_t getRipupDelayPenalty() const { return 200; } float getDelayNS(delay_t v) const { return v * 0.001; } diff --git a/generic/arch.cc b/generic/arch.cc index 5c9864ab..8ef37716 100644 --- a/generic/arch.cc +++ b/generic/arch.cc @@ -403,6 +403,15 @@ delay_t Arch::estimateDelay(WireId src, WireId dst) const return (dx + dy) * grid_distance_to_delay; } +delay_t Arch::predictDelay(WireId src, WireId dst) const +{ + const WireInfo &s = wires.at(src); + const WireInfo &d = wires.at(dst); + int dx = abs(s.x - d.x); + int dy = abs(s.y - d.y); + return (dx + dy) * grid_distance_to_delay; +} + // --------------------------------------------------------------- bool Arch::place() { return placer1(getCtx()); } diff --git a/generic/arch.h b/generic/arch.h index 01a90ee1..60220fbe 100644 --- a/generic/arch.h +++ b/generic/arch.h @@ -194,6 +194,7 @@ struct Arch : BaseCtx const std::vector &getGroupGroups(GroupId group) const; delay_t estimateDelay(WireId src, WireId dst) const; + delay_t predictDelay(WireId src, WireId dst) const; delay_t getDelayEpsilon() const { return 0.01; } delay_t getRipupDelayPenalty() const { return 1.0; } float getDelayNS(delay_t v) const { return v; } diff --git a/ice40/arch.cc b/ice40/arch.cc index 3803f842..91c20b42 100644 --- a/ice40/arch.cc +++ b/ice40/arch.cc @@ -579,6 +579,22 @@ delay_t Arch::estimateDelay(WireId src, WireId dst) const int xd = x2 - x1, yd = y2 - y1; int xscale = 120, yscale = 120, offset = 0; + return xscale * abs(xd) + yscale * abs(yd) + offset; +} + +delay_t Arch::predictDelay(WireId src, WireId dst) const +{ + NPNR_ASSERT(src != WireId()); + int x1 = chip_info->wire_data[src.index].x; + int y1 = chip_info->wire_data[src.index].y; + + NPNR_ASSERT(dst != WireId()); + int x2 = chip_info->wire_data[dst.index].x; + int y2 = chip_info->wire_data[dst.index].y; + + int xd = x2 - x1, yd = y2 - y1; + int xscale = 120, yscale = 120, offset = 0; + // if (chip_info->wire_data[src.index].type == WIRE_TYPE_SP4_VERT) { // yd = yd < -4 ? yd + 4 : (yd < 0 ? 0 : yd); // offset = 500; diff --git a/ice40/arch.h b/ice40/arch.h index 51cbe725..1725d181 100644 --- a/ice40/arch.h +++ b/ice40/arch.h @@ -684,6 +684,7 @@ struct Arch : BaseCtx // ------------------------------------------------- delay_t estimateDelay(WireId src, WireId dst) const; + delay_t predictDelay(WireId src, WireId dst) const; delay_t getDelayEpsilon() const { return 20; } delay_t getRipupDelayPenalty() const { return 200; } float getDelayNS(delay_t v) const { return v * 0.001; } From e4b044da52ce7d8fed2e461bec09c86cb293566d Mon Sep 17 00:00:00 2001 From: Eddie Hung Date: Mon, 30 Jul 2018 19:39:44 -0700 Subject: [PATCH 2/3] Fix tns --- common/place_common.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/common/place_common.cc b/common/place_common.cc index 5673c847..b7ea84f8 100644 --- a/common/place_common.cc +++ b/common/place_common.cc @@ -72,6 +72,7 @@ wirelen_t get_net_metric(const Context *ctx, const NetInfo *net, MetricType type wirelength = wirelen_t((ymax - ymin) + (xmax - xmin)); } + tns = ctx->getDelayNS(tns); return wirelength; } From a82f6f410595de26e82eaf4818e41036f0bc2f9c Mon Sep 17 00:00:00 2001 From: Eddie Hung Date: Mon, 30 Jul 2018 19:19:30 -0700 Subject: [PATCH 3/3] Modify predictDelay signature --- common/nextpnr.cc | 2 +- common/place_common.cc | 8 +++----- ecp5/arch.cc | 8 ++++++-- ecp5/arch.h | 2 +- generic/arch.cc | 12 +++++++----- generic/arch.h | 2 +- ice40/arch.cc | 21 +++++++++++++-------- ice40/arch.h | 2 +- 8 files changed, 33 insertions(+), 24 deletions(-) diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 5b0a45ed..4a97bd93 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -111,7 +111,7 @@ delay_t Context::getNetinfoRouteDelay(NetInfo *net_info, int user_idx) const if (cursor == src_wire) return delay + getWireDelay(src_wire).maxDelay(); - return predictDelay(src_wire, dst_wire); + return predictDelay(net_info, net_info->users[user_idx]); } static uint32_t xorshift32(uint32_t x) diff --git a/common/place_common.cc b/common/place_common.cc index b7ea84f8..3c19a733 100644 --- a/common/place_common.cc +++ b/common/place_common.cc @@ -37,10 +37,9 @@ wirelen_t get_net_metric(const Context *ctx, const NetInfo *net, MetricType type return 0; driver_gb = ctx->getBelGlobalBuf(driver_cell->bel); driver_loc = ctx->getBelLocation(driver_cell->bel); - WireId drv_wire = ctx->getBelPinWire(driver_cell->bel, ctx->portPinFromId(net->driver.port)); if (driver_gb) return 0; - float worst_slack = 1000; + delay_t worst_slack = std::numeric_limits::max(); int xmin = driver_loc.x, xmax = driver_loc.x, ymin = driver_loc.y, ymax = driver_loc.y; for (auto load : net->users) { if (load.cell == nullptr) @@ -49,9 +48,8 @@ wirelen_t get_net_metric(const Context *ctx, const NetInfo *net, MetricType type if (load_cell->bel == BelId()) continue; if (ctx->timing_driven && type == MetricType::COST) { - WireId user_wire = ctx->getBelPinWire(load_cell->bel, ctx->portPinFromId(load.port)); - delay_t raw_wl = ctx->estimateDelay(drv_wire, user_wire); - float slack = ctx->getDelayNS(load.budget) - ctx->getDelayNS(raw_wl); + delay_t net_delay = ctx->predictDelay(net, load); + auto slack = load.budget - net_delay; if (slack < 0) tns += slack; worst_slack = std::min(slack, worst_slack); diff --git a/ecp5/arch.cc b/ecp5/arch.cc index 88b5e4d4..23105df2 100644 --- a/ecp5/arch.cc +++ b/ecp5/arch.cc @@ -413,9 +413,13 @@ 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::predictDelay(WireId src, WireId dst) const +delay_t Arch::predictDelay(const NetInfo *net_info, const PortRef &sink) const; { - return 200 * (abs(src.location.x - dst.location.x) + abs(src.location.y - dst.location.y)); + const auto& driver = net_info->driver; + auto driver_loc = getBelLocation(driver.cell->bel); + auto sink_loc = getBelLocation(sink.cell->bel); + + return 200 * (abs(driver_loc.x - sink_loc.x) + abs(driver_loc.y - sink_loc.y)); } // ----------------------------------------------------------------------- diff --git a/ecp5/arch.h b/ecp5/arch.h index 13f2db1f..400d6e55 100644 --- a/ecp5/arch.h +++ b/ecp5/arch.h @@ -776,7 +776,7 @@ struct Arch : BaseCtx // ------------------------------------------------- delay_t estimateDelay(WireId src, WireId dst) const; - delay_t predictDelay(WireId src, WireId dst) const; + delay_t predictDelay(const NetInfo *net_info, const PortRef &sink) const; delay_t getDelayEpsilon() const { return 20; } delay_t getRipupDelayPenalty() const { return 200; } float getDelayNS(delay_t v) const { return v * 0.001; } diff --git a/generic/arch.cc b/generic/arch.cc index 8ef37716..4469a828 100644 --- a/generic/arch.cc +++ b/generic/arch.cc @@ -403,12 +403,14 @@ delay_t Arch::estimateDelay(WireId src, WireId dst) const return (dx + dy) * grid_distance_to_delay; } -delay_t Arch::predictDelay(WireId src, WireId dst) const +delay_t Arch::predictDelay(const NetInfo *net_info, const PortRef &sink) const; { - const WireInfo &s = wires.at(src); - const WireInfo &d = wires.at(dst); - int dx = abs(s.x - d.x); - int dy = abs(s.y - d.y); + const auto& driver = net_info->driver; + auto driver_loc = getBelLocation(driver.cell->bel); + auto sink_loc = getBelLocation(sink.cell->bel); + + int dx = abs(driver_loc.x - driver_loc.x); + int dy = abs(sink_loc.y - sink_locy); return (dx + dy) * grid_distance_to_delay; } diff --git a/generic/arch.h b/generic/arch.h index 60220fbe..f02649f6 100644 --- a/generic/arch.h +++ b/generic/arch.h @@ -194,7 +194,7 @@ struct Arch : BaseCtx const std::vector &getGroupGroups(GroupId group) const; delay_t estimateDelay(WireId src, WireId dst) const; - delay_t predictDelay(WireId src, WireId dst) const; + delay_t predictDelay(const NetInfo *net_info, const PortRef &sink) const; delay_t getDelayEpsilon() const { return 0.01; } delay_t getRipupDelayPenalty() const { return 1.0; } float getDelayNS(delay_t v) const { return v; } diff --git a/ice40/arch.cc b/ice40/arch.cc index 91c20b42..107bf56a 100644 --- a/ice40/arch.cc +++ b/ice40/arch.cc @@ -582,17 +582,19 @@ delay_t Arch::estimateDelay(WireId src, WireId dst) const return xscale * abs(xd) + yscale * abs(yd) + offset; } -delay_t Arch::predictDelay(WireId src, WireId dst) const +delay_t Arch::predictDelay(const NetInfo *net_info, const PortRef &sink) const { - NPNR_ASSERT(src != WireId()); - int x1 = chip_info->wire_data[src.index].x; - int y1 = chip_info->wire_data[src.index].y; + const auto& driver = net_info->driver; + auto driver_loc = getBelLocation(driver.cell->bel); + auto sink_loc = getBelLocation(sink.cell->bel); - NPNR_ASSERT(dst != WireId()); - int x2 = chip_info->wire_data[dst.index].x; - int y2 = chip_info->wire_data[dst.index].y; + if (driver.port == id_cout) { + if (driver_loc.y == sink_loc.y) + return 0; + return 250; + } - int xd = x2 - x1, yd = y2 - y1; + int xd = sink_loc.x - driver_loc.x, yd = sink_loc.y - driver_loc.y; int xscale = 120, yscale = 120, offset = 0; // if (chip_info->wire_data[src.index].type == WIRE_TYPE_SP4_VERT) { @@ -600,6 +602,9 @@ delay_t Arch::predictDelay(WireId src, WireId dst) const // offset = 500; // } + if (driver.port == id_o) offset += 330; + if (sink.port == id_i0 || sink.port == id_i1 || sink.port == id_i2 || sink.port == id_i3) offset += 260; + return xscale * abs(xd) + yscale * abs(yd) + offset; } diff --git a/ice40/arch.h b/ice40/arch.h index 1725d181..57089ed7 100644 --- a/ice40/arch.h +++ b/ice40/arch.h @@ -684,7 +684,7 @@ struct Arch : BaseCtx // ------------------------------------------------- delay_t estimateDelay(WireId src, WireId dst) const; - delay_t predictDelay(WireId src, WireId dst) const; + delay_t predictDelay(const NetInfo *net_info, const PortRef &sink) const; delay_t getDelayEpsilon() const { return 20; } delay_t getRipupDelayPenalty() const { return 200; } float getDelayNS(delay_t v) const { return v * 0.001; }