diff options
author | David Shah <davey1576@gmail.com> | 2018-06-13 15:10:42 +0200 |
---|---|---|
committer | David Shah <davey1576@gmail.com> | 2018-06-13 15:10:42 +0200 |
commit | 14b5e46b5df76973dccd26bb07dc12c26e5d6efc (patch) | |
tree | dfdef863b1e195fc0dd660663ca9d0088081f723 /ice40/pack.cc | |
parent | d80e60cce210b58c036003f6812eb876c632d19e (diff) | |
download | nextpnr-14b5e46b5df76973dccd26bb07dc12c26e5d6efc.tar.gz nextpnr-14b5e46b5df76973dccd26bb07dc12c26e5d6efc.tar.bz2 nextpnr-14b5e46b5df76973dccd26bb07dc12c26e5d6efc.zip |
ice40: Promote one clock to a global buffer
Signed-off-by: David Shah <davey1576@gmail.com>
Diffstat (limited to 'ice40/pack.cc')
-rw-r--r-- | ice40/pack.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/ice40/pack.cc b/ice40/pack.cc index 49c95ad6..e8876283 100644 --- a/ice40/pack.cc +++ b/ice40/pack.cc @@ -222,10 +222,58 @@ static void pack_io(Design *design) } } +// Simple global promoter (clock only) +static void promote_globals(Design *design) +{ + std::unordered_map<IdString, int> clock_count; + for (auto net : design->nets) { + NetInfo *ni = net.second; + if (ni->driver.cell != nullptr && !is_global_net(ni)) { + clock_count[net.first] = 0; + for (auto user : ni->users) { + if (user.cell != nullptr && is_ff(user.cell) && user.port == "C") + clock_count[net.first]++; + } + } + } + auto global_clock = std::max_element(clock_count.begin(), clock_count.end(), []( + const std::pair<IdString, int> &a, const std::pair<IdString, int> &b) { + return a.second < b.second; + }); + if (global_clock->second > 0) { + NetInfo *clknet = design->nets[global_clock->first]; + CellInfo *gb = create_ice_cell(design, "SB_GB"); + gb->ports["USER_SIGNAL_TO_GLOBAL_BUFFER"].net = clknet; + PortRef pr; + pr.cell = gb; + pr.port = "USER_SIGNAL_TO_GLOBAL_BUFFER"; + clknet->users.push_back(pr); + + pr.cell = gb; + pr.port = "GLOBAL_BUFFER_OUTPUT"; + NetInfo *glbnet = new NetInfo(); + glbnet->name = clknet->name.str() + "_glb"; + glbnet->driver = pr; + design->nets[glbnet->name] = glbnet; + std::vector<PortRef> keep_users; + for (auto user : clknet->users) { + if (user.cell != nullptr && is_ff(user.cell) && user.port == "C") { + user.cell->ports[user.port].net = glbnet; + glbnet->users.push_back(user); + } else { + keep_users.push_back(user); + } + } + clknet->users = keep_users; + design->cells[gb->name] = gb; + } +} + // Main pack function void pack_design(Design *design) { pack_constants(design); + promote_globals(design); pack_io(design); pack_lut_lutffs(design); pack_nonlut_ffs(design); |