diff options
author | David Shah <davey1576@gmail.com> | 2018-06-13 14:01:42 +0200 |
---|---|---|
committer | David Shah <davey1576@gmail.com> | 2018-06-13 14:01:42 +0200 |
commit | 9374ef29bf24c6a9223e7b6742e3debd66a66bf9 (patch) | |
tree | 3e189679d0e6b1184699c058f78533467202db91 /ice40/pack.cc | |
parent | 991cf1979baaf12d83dc50c223160879d08bdd3a (diff) | |
download | nextpnr-9374ef29bf24c6a9223e7b6742e3debd66a66bf9.tar.gz nextpnr-9374ef29bf24c6a9223e7b6742e3debd66a66bf9.tar.bz2 nextpnr-9374ef29bf24c6a9223e7b6742e3debd66a66bf9.zip |
Fixing implementation of constants
Signed-off-by: David Shah <davey1576@gmail.com>
Diffstat (limited to 'ice40/pack.cc')
-rw-r--r-- | ice40/pack.cc | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/ice40/pack.cc b/ice40/pack.cc index 72dcadea..49c95ad6 100644 --- a/ice40/pack.cc +++ b/ice40/pack.cc @@ -110,28 +110,62 @@ static void pack_nonlut_ffs(Design *design) } } +// Merge a net into a constant net +static void set_net_constant(NetInfo *orig, NetInfo *constnet, bool constval) +{ + orig->driver.cell = nullptr; + for (auto user : orig->users) { + if (user.cell != nullptr) { + CellInfo *uc = user.cell; + log_info("%s user %s\n", orig->name.c_str(), uc->name.c_str()); + if (is_lut(uc) && (user.port.str().at(0) == 'I') && !constval) { + uc->ports[user.port].net = nullptr; + } else { + uc->ports[user.port].net = constnet; + constnet->users.push_back(user); + } + } + } + orig->users.clear(); +} + // Pack constants (simple implementation) static void pack_constants(Design *design) { CellInfo *gnd_cell = create_ice_cell(design, "ICESTORM_LC", "$PACKER_GND"); - gnd_cell->attrs["LUT_INIT"] = "0"; + gnd_cell->params["LUT_INIT"] = "0"; + NetInfo *gnd_net = new NetInfo; + gnd_net->name = "$PACKER_GND_NET"; + gnd_net->driver.cell = gnd_cell; + gnd_net->driver.port = "O"; CellInfo *vcc_cell = create_ice_cell(design, "ICESTORM_LC", "$PACKER_VCC"); - vcc_cell->attrs["LUT_INIT"] = "1"; + vcc_cell->params["LUT_INIT"] = "1"; + NetInfo *vcc_net = new NetInfo; + vcc_net->name = "$PACKER_VCC_NET"; + vcc_net->driver.cell = vcc_cell; + vcc_net->driver.port = "O"; + + std::vector<IdString> dead_nets; for (auto net : design->nets) { NetInfo *ni = net.second; if (ni->driver.cell != nullptr && ni->driver.cell->type == "GND") { - ni->driver.cell = gnd_cell; - ni->driver.port = "O"; + set_net_constant(ni, gnd_net, false); design->cells[gnd_cell->name] = gnd_cell; + design->nets[gnd_net->name] = gnd_net; + dead_nets.push_back(net.first); } else if (ni->driver.cell != nullptr && ni->driver.cell->type == "VCC") { - ni->driver.cell = vcc_cell; - ni->driver.port = "O"; + set_net_constant(ni, vcc_net, true); design->cells[vcc_cell->name] = vcc_cell; + design->nets[vcc_net->name] = vcc_net; + dead_nets.push_back(net.first); } } + + for (auto dn : dead_nets) + design->nets.erase(dn); } static bool is_nextpnr_iob(CellInfo *cell) |