From 7d48acff52cfa31cf7873d7462a3a4e6395ee520 Mon Sep 17 00:00:00 2001 From: David Shah Date: Sun, 29 Jul 2018 10:07:58 +0200 Subject: ecp5: Clock usage counter function Signed-off-by: David Shah --- ecp5/globals.cc | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'ecp5') diff --git a/ecp5/globals.cc b/ecp5/globals.cc index d435ca93..770eb7e2 100644 --- a/ecp5/globals.cc +++ b/ecp5/globals.cc @@ -18,6 +18,7 @@ */ #include "nextpnr.h" +#include NEXTPNR_NAMESPACE_BEGIN @@ -25,6 +26,39 @@ class Ecp5GlobalRouter { public: Ecp5GlobalRouter(Context *ctx) : ctx(ctx){}; + private: + + bool is_clock_port(const PortRef &user) { + if (user.cell->type == ctx->id("TRELLIS_LC") && user.port == ctx->id("CLK")) + return true; + return false; + } + + std::vector get_clocks() + { + std::unordered_map clockCount; + for (auto &net : ctx->nets) { + NetInfo *ni = net.second.get(); + clockCount[ni->name] = 0; + for (const auto &user : ni->users) { + if (is_clock_port(user)) + clockCount[ni->name]++; + } + } + std::vector clocks; + while (clocks.size() < 16) { + auto max = std::max_element(clockCount.begin(), clockCount.end(), []( + const decltype(clockCount)::value_type &a, const decltype(clockCount)::value_type &b + ) { + return a.second < b.second; + }); + if (max == clockCount.end() || max->second < 3) + break; + clocks.push_back(ctx->nets.at(max->first).get()); + clockCount.erase(max->first); + } + return clocks; + } PipId find_tap_pip(WireId tile_glb) { @@ -43,7 +77,6 @@ class Ecp5GlobalRouter return *(ctx->getPipsUphill(tap_wire).begin()); } - private: Context *ctx; }; -- cgit v1.2.3