aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ice40/chains.cc109
1 files changed, 78 insertions, 31 deletions
diff --git a/ice40/chains.cc b/ice40/chains.cc
index fb361d2d..b3b54d6b 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;
@@ -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,75 @@ 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<CellInfo> 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<NetInfo> 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<NetInfo> 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;
+ 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;
+ 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()) {
+ 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);
@@ -163,29 +208,31 @@ class ChainConstrainer
void process_carries()
{
- std::vector<CellChain> 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;
- });
+ std::vector<CellChain> 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;
+ });
std::unordered_set<IdString> chained;
for (auto &base_chain : carry_chains) {
for (auto c : base_chain.cells)