From 0c93b55650a8a8919f2697cd6d6dbd373bf5ff19 Mon Sep 17 00:00:00 2001 From: David Shah Date: Tue, 4 Dec 2018 12:02:26 +0000 Subject: [PATCH 1/4] ice40: Include I3 connectivity in chain Thanks @smunaut Signed-off-by: David Shah --- ice40/chains.cc | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/ice40/chains.cc b/ice40/chains.cc index fb361d2d..07eb100b 100644 --- a/ice40/chains.cc +++ b/ice40/chains.cc @@ -163,29 +163,31 @@ class ChainConstrainer void process_carries() { - std::vector carry_chains = - find_chains(ctx, [](const Context *ctx, const CellInfo *cell) { return is_lc(ctx, cell); }, - [](const Context *ctx, const + std::vector carry_chains = find_chains( + ctx, [](const Context *ctx, const CellInfo *cell) { return is_lc(ctx, cell); }, + [](const Context *ctx, const - CellInfo *cell) { - CellInfo *carry_prev = - net_driven_by(ctx, cell->ports.at(ctx->id("CIN")).net, is_lc, ctx->id("COUT")); - if (carry_prev != nullptr) - return carry_prev; - /*CellInfo *i3_prev = net_driven_by(ctx, cell->ports.at(ctx->id("I3")).net, is_lc, - ctx->id("COUT")); if (i3_prev != nullptr) return i3_prev;*/ - return (CellInfo *)nullptr; - }, - [](const Context *ctx, const CellInfo *cell) { - CellInfo *carry_next = net_only_drives(ctx, cell->ports.at(ctx->id("COUT")).net, is_lc, - ctx->id("CIN"), false); - if (carry_next != nullptr) - return carry_next; - /*CellInfo *i3_next = - net_only_drives(ctx, cell->ports.at(ctx->id("COUT")).net, is_lc, ctx->id("I3"), - false); if (i3_next != nullptr) return i3_next;*/ - return (CellInfo *)nullptr; - }); + CellInfo *cell) { + CellInfo *carry_prev = + net_driven_by(ctx, cell->ports.at(ctx->id("CIN")).net, is_lc, ctx->id("COUT")); + if (carry_prev != nullptr) + return carry_prev; + CellInfo *i3_prev = net_driven_by(ctx, cell->ports.at(ctx->id("I3")).net, is_lc, ctx->id("COUT")); + if (i3_prev != nullptr) + return i3_prev; + return (CellInfo *)nullptr; + }, + [](const Context *ctx, const CellInfo *cell) { + CellInfo *carry_next = + net_only_drives(ctx, cell->ports.at(ctx->id("COUT")).net, is_lc, ctx->id("CIN"), false); + if (carry_next != nullptr) + return carry_next; + CellInfo *i3_next = + net_only_drives(ctx, cell->ports.at(ctx->id("COUT")).net, is_lc, ctx->id("I3"), false); + if (i3_next != nullptr) + return i3_next; + return (CellInfo *)nullptr; + }); std::unordered_set chained; for (auto &base_chain : carry_chains) { for (auto c : base_chain.cells) From 51cda136b185730afa9e058e5b8e998cdb8c1d08 Mon Sep 17 00:00:00 2001 From: David Shah Date: Tue, 4 Dec 2018 12:31:32 +0000 Subject: [PATCH 2/4] ice40: Don't split carry chain in simple feed-out cases Signed-off-by: David Shah --- ice40/chains.cc | 57 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/ice40/chains.cc b/ice40/chains.cc index 07eb100b..b8fbee0f 100644 --- a/ice40/chains.cc +++ b/ice40/chains.cc @@ -74,10 +74,10 @@ class ChainConstrainer (net_only_drives(ctx, carry_net, is_lc, ctx->id("I3"), false) != net_only_drives(ctx, carry_net, is_lc, ctx->id("CIN"), false)) || (at_end && !net_only_drives(ctx, carry_net, is_lc, ctx->id("I3"), true))) { - CellInfo *passout = make_carry_pass_out(cell->ports.at(ctx->id("COUT"))); + CellInfo *passout = make_carry_pass_out(cell->ports.at(ctx->id("COUT")), + at_end ? nullptr : *(curr_cell + 1)); chains.back().cells.push_back(passout); tile.push_back(passout); - start_of_chain = true; } } ++curr_cell; @@ -87,30 +87,73 @@ class ChainConstrainer } // Insert a logic cell to legalise a COUT->fabric connection - CellInfo *make_carry_pass_out(PortInfo &cout_port) + CellInfo *make_carry_pass_out(PortInfo &cout_port, CellInfo *cin_cell = nullptr) { NPNR_ASSERT(cout_port.net != nullptr); std::unique_ptr lc = create_ice_cell(ctx, ctx->id("ICESTORM_LC")); lc->params[ctx->id("LUT_INIT")] = "65280"; // 0xff00: O = I3 lc->params[ctx->id("CARRY_ENABLE")] = "1"; - lc->ports.at(ctx->id("O")).net = cout_port.net; + lc->ports.at(id_O).net = cout_port.net; std::unique_ptr co_i3_net(new NetInfo()); co_i3_net->name = ctx->id(lc->name.str(ctx) + "$I3"); co_i3_net->driver = cout_port.net->driver; PortRef i3_r; - i3_r.port = ctx->id("I3"); + i3_r.port = id_I3; i3_r.cell = lc.get(); co_i3_net->users.push_back(i3_r); PortRef o_r; - o_r.port = ctx->id("O"); + o_r.port = id_O; o_r.cell = lc.get(); cout_port.net->driver = o_r; - lc->ports.at(ctx->id("I3")).net = co_i3_net.get(); + lc->ports.at(id_I3).net = co_i3_net.get(); cout_port.net = co_i3_net.get(); IdString co_i3_name = co_i3_net->name; NPNR_ASSERT(ctx->nets.find(co_i3_name) == ctx->nets.end()); ctx->nets[co_i3_name] = std::move(co_i3_net); + + // If COUT also connects to a CIN; preserve the carry chain + if (cin_cell) { + std::unique_ptr co_cin_net(new NetInfo()); + co_cin_net->name = ctx->id(lc->name.str(ctx) + "$COUT"); + + // Connect I1 to 1 to preserve carry chain + NetInfo *vcc = ctx->nets.at(ctx->id("$PACKER_VCC_NET")).get(); + lc->ports.at(id_I1).net = vcc; + PortRef i1_r; + i1_r.port = id_I1; + i1_r.cell = lc.get(); + vcc->users.push_back(i1_r); + + // Connect co_cin_net to the COUT of the LC + PortRef co_r; + co_r.port = id_COUT; + co_r.cell = lc.get(); + co_cin_net->driver = co_r; + lc->ports.at(id_COUT).net = co_cin_net.get(); + + // Find the user corresponding to the next CIN + int replaced_ports = 0; + log_info("cell: %s\n", cin_cell->name.c_str(ctx)); + for (auto port : {id_CIN, id_I3}) { + auto &usr = lc->ports.at(id_O).net->users; + for (auto user : usr) + log_info("%s.%s\n", user.cell->name.c_str(ctx), user.port.c_str(ctx)); + auto fnd_user = std::find_if(usr.begin(), usr.end(), + [&](const PortRef &pr) { return pr.cell == cin_cell && pr.port == port; }); + if (fnd_user != usr.end()) { + co_cin_net->users.push_back(*fnd_user); + usr.erase(fnd_user); + cin_cell->ports.at(port).net = co_cin_net.get(); + ++replaced_ports; + } + } + NPNR_ASSERT(replaced_ports > 0); + IdString co_cin_name = co_cin_net->name; + NPNR_ASSERT(ctx->nets.find(co_cin_name) == ctx->nets.end()); + ctx->nets[co_cin_name] = std::move(co_cin_net); + } + IdString name = lc->name; ctx->assignCellInfo(lc.get()); ctx->cells[lc->name] = std::move(lc); From d298687dc2472e3afd2b19979719658b5eba3132 Mon Sep 17 00:00:00 2001 From: David Shah Date: Wed, 5 Dec 2018 10:12:23 +0000 Subject: [PATCH 3/4] ice40: Fix carry chain splitting Signed-off-by: David Shah --- ice40/chains.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ice40/chains.cc b/ice40/chains.cc index b8fbee0f..3ef367f1 100644 --- a/ice40/chains.cc +++ b/ice40/chains.cc @@ -62,7 +62,7 @@ class ChainConstrainer bool split_chain = (!ctx->logicCellsCompatible(tile.data(), tile.size())) || (int(chains.back().cells.size()) > max_length); if (split_chain) { - CellInfo *passout = make_carry_pass_out(cell->ports.at(ctx->id("COUT"))); + CellInfo *passout = make_carry_pass_out((*(curr_cell - 1))->ports.at(ctx->id("COUT"))); tile.pop_back(); chains.back().cells.back() = passout; start_of_chain = true; From dbaabae23594dc3ac058abeb9f3de2db756a4636 Mon Sep 17 00:00:00 2001 From: David Shah Date: Thu, 6 Dec 2018 10:51:17 +0000 Subject: [PATCH 4/4] ice40: Put debug logging behind ctx->debug Signed-off-by: David Shah --- ice40/chains.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ice40/chains.cc b/ice40/chains.cc index 3ef367f1..b3b54d6b 100644 --- a/ice40/chains.cc +++ b/ice40/chains.cc @@ -134,11 +134,13 @@ class ChainConstrainer // Find the user corresponding to the next CIN int replaced_ports = 0; - log_info("cell: %s\n", cin_cell->name.c_str(ctx)); + if (ctx->debug) + log_info("cell: %s\n", cin_cell->name.c_str(ctx)); for (auto port : {id_CIN, id_I3}) { auto &usr = lc->ports.at(id_O).net->users; - for (auto user : usr) - log_info("%s.%s\n", user.cell->name.c_str(ctx), user.port.c_str(ctx)); + if (ctx->debug) + for (auto user : usr) + log_info("%s.%s\n", user.cell->name.c_str(ctx), user.port.c_str(ctx)); auto fnd_user = std::find_if(usr.begin(), usr.end(), [&](const PortRef &pr) { return pr.cell == cin_cell && pr.port == port; }); if (fnd_user != usr.end()) {