2018-07-08 18:56:43 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 David Shah <david@symbioticeda.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <algorithm>
|
2018-09-30 23:29:26 +08:00
|
|
|
#include <boost/optional.hpp>
|
2018-07-08 18:56:43 +08:00
|
|
|
#include <iterator>
|
|
|
|
#include <unordered_set>
|
2018-07-17 19:19:27 +08:00
|
|
|
#include "cells.h"
|
2018-09-30 23:58:02 +08:00
|
|
|
#include "chain_utils.h"
|
2018-07-08 18:56:43 +08:00
|
|
|
#include "design_utils.h"
|
2018-11-01 00:22:34 +08:00
|
|
|
#include "globals.h"
|
2018-07-08 18:56:43 +08:00
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
static bool is_nextpnr_iob(Context *ctx, CellInfo *cell)
|
|
|
|
{
|
|
|
|
return cell->type == ctx->id("$nextpnr_ibuf") || cell->type == ctx->id("$nextpnr_obuf") ||
|
|
|
|
cell->type == ctx->id("$nextpnr_iobuf");
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:19:27 +08:00
|
|
|
class Ecp5Packer
|
2018-07-08 18:56:43 +08:00
|
|
|
{
|
2018-07-17 19:19:27 +08:00
|
|
|
public:
|
|
|
|
Ecp5Packer(Context *ctx) : ctx(ctx){};
|
2018-07-08 18:56:43 +08:00
|
|
|
|
2018-07-17 19:19:27 +08:00
|
|
|
private:
|
2018-07-17 19:41:33 +08:00
|
|
|
// Process the contents of packed_cells and new_cells
|
|
|
|
void flush_cells()
|
|
|
|
{
|
|
|
|
for (auto pcell : packed_cells) {
|
|
|
|
ctx->cells.erase(pcell);
|
|
|
|
}
|
|
|
|
for (auto &ncell : new_cells) {
|
|
|
|
ctx->cells[ncell->name] = std::move(ncell);
|
|
|
|
}
|
|
|
|
packed_cells.clear();
|
|
|
|
new_cells.clear();
|
|
|
|
}
|
|
|
|
|
2018-07-17 20:19:21 +08:00
|
|
|
// Find FFs associated with LUTs, or LUT expansion muxes
|
|
|
|
void find_lutff_pairs()
|
|
|
|
{
|
2018-07-17 21:44:36 +08:00
|
|
|
log_info("Finding LUTFF pairs...\n");
|
2018-07-17 20:19:21 +08:00
|
|
|
for (auto cell : sorted(ctx->cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (is_lut(ctx, ci) || is_pfumx(ctx, ci) || is_l6mux(ctx, ci)) {
|
|
|
|
NetInfo *znet = ci->ports.at(ctx->id("Z")).net;
|
|
|
|
if (znet != nullptr) {
|
|
|
|
CellInfo *ff = net_only_drives(ctx, znet, is_ff, ctx->id("DI"), false);
|
|
|
|
if (ff != nullptr) {
|
|
|
|
lutffPairs[ci->name] = ff->name;
|
2018-07-17 21:25:10 +08:00
|
|
|
fflutPairs[ff->name] = ci->name;
|
2018-07-17 20:19:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 15:52:53 +08:00
|
|
|
const NetInfo *net_or_nullptr(CellInfo *cell, IdString port)
|
|
|
|
{
|
|
|
|
auto fnd = cell->ports.find(port);
|
|
|
|
if (fnd == cell->ports.end())
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return fnd->second.net;
|
|
|
|
}
|
|
|
|
|
2018-07-17 21:25:10 +08:00
|
|
|
// Return whether two FFs can be packed together in the same slice
|
|
|
|
bool can_pack_ffs(CellInfo *ff0, CellInfo *ff1)
|
|
|
|
{
|
|
|
|
if (str_or_default(ff0->params, ctx->id("GSR"), "DISABLED") !=
|
|
|
|
str_or_default(ff1->params, ctx->id("GSR"), "DISABLED"))
|
|
|
|
return false;
|
|
|
|
if (str_or_default(ff0->params, ctx->id("SRMODE"), "LSR_OVER_CE") !=
|
|
|
|
str_or_default(ff1->params, ctx->id("SRMODE"), "LSR_OVER_CE"))
|
|
|
|
return false;
|
|
|
|
if (str_or_default(ff0->params, ctx->id("CEMUX"), "1") != str_or_default(ff1->params, ctx->id("CEMUX"), "1"))
|
|
|
|
return false;
|
|
|
|
if (str_or_default(ff0->params, ctx->id("LSRMUX"), "LSR") !=
|
|
|
|
str_or_default(ff1->params, ctx->id("LSRMUX"), "LSR"))
|
|
|
|
return false;
|
|
|
|
if (str_or_default(ff0->params, ctx->id("CLKMUX"), "CLK") !=
|
|
|
|
str_or_default(ff1->params, ctx->id("CLKMUX"), "CLK"))
|
|
|
|
return false;
|
2018-07-18 15:52:53 +08:00
|
|
|
if (net_or_nullptr(ff0, ctx->id("CLK")) != net_or_nullptr(ff1, ctx->id("CLK")))
|
2018-07-17 21:25:10 +08:00
|
|
|
return false;
|
2018-07-18 15:52:53 +08:00
|
|
|
if (net_or_nullptr(ff0, ctx->id("CE")) != net_or_nullptr(ff1, ctx->id("CE")))
|
2018-07-17 21:25:10 +08:00
|
|
|
return false;
|
2018-07-18 15:52:53 +08:00
|
|
|
if (net_or_nullptr(ff0, ctx->id("LSR")) != net_or_nullptr(ff1, ctx->id("LSR")))
|
2018-07-17 21:25:10 +08:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-30 23:58:02 +08:00
|
|
|
// Return whether or not an FF can be added to a tile (pairing checks must also be done using the fn above)
|
2018-10-02 00:45:35 +08:00
|
|
|
bool can_add_ff_to_tile(const std::vector<CellInfo *> &tile_ffs, CellInfo *ff0)
|
2018-10-01 00:05:42 +08:00
|
|
|
{
|
2018-09-30 23:58:02 +08:00
|
|
|
for (const auto &existing : tile_ffs) {
|
|
|
|
if (net_or_nullptr(existing, ctx->id("CLK")) != net_or_nullptr(ff0, ctx->id("CLK")))
|
|
|
|
return false;
|
|
|
|
if (net_or_nullptr(existing, ctx->id("LSR")) != net_or_nullptr(ff0, ctx->id("LSR")))
|
|
|
|
return false;
|
|
|
|
if (str_or_default(existing->params, ctx->id("CLKMUX"), "CLK") !=
|
|
|
|
str_or_default(ff0->params, ctx->id("CLKMUX"), "CLK"))
|
|
|
|
return false;
|
|
|
|
if (str_or_default(existing->params, ctx->id("LSRMUX"), "LSR") !=
|
|
|
|
str_or_default(ff0->params, ctx->id("LSRMUX"), "LSR"))
|
|
|
|
return false;
|
2018-10-01 01:10:20 +08:00
|
|
|
if (str_or_default(existing->params, ctx->id("SRMODE"), "LSR_OVER_CE") !=
|
|
|
|
str_or_default(ff0->params, ctx->id("SRMODE"), "LSR_OVER_CE"))
|
2018-09-30 23:58:02 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-02 22:50:45 +08:00
|
|
|
// Return true if a FF can be added to a DPRAM slice
|
|
|
|
bool can_pack_ff_dram(CellInfo *dpram, CellInfo *ff)
|
|
|
|
{
|
|
|
|
std::string wckmux = str_or_default(dpram->params, ctx->id("WCKMUX"), "WCK");
|
|
|
|
std::string clkmux = str_or_default(ff->params, ctx->id("CLKMUX"), "CLK");
|
|
|
|
if (wckmux != clkmux && !(wckmux == "WCK" && clkmux == "CLK"))
|
|
|
|
return false;
|
|
|
|
std::string wremux = str_or_default(dpram->params, ctx->id("WREMUX"), "WRE");
|
|
|
|
std::string lsrmux = str_or_default(ff->params, ctx->id("LSRMUX"), "LSR");
|
|
|
|
if (wremux != lsrmux && !(wremux == "WRE" && lsrmux == "LSR"))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-17 21:25:10 +08:00
|
|
|
// Return true if two LUTs can be paired considering FF compatibility
|
|
|
|
bool can_pack_lutff(IdString lut0, IdString lut1)
|
|
|
|
{
|
|
|
|
auto ff0 = lutffPairs.find(lut0), ff1 = lutffPairs.find(lut1);
|
|
|
|
if (ff0 != lutffPairs.end() && ff1 != lutffPairs.end()) {
|
|
|
|
return can_pack_ffs(ctx->cells.at(ff0->second).get(), ctx->cells.at(ff1->second).get());
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find "closely connected" LUTs and pair them together
|
2018-07-17 21:44:36 +08:00
|
|
|
void pair_luts()
|
2018-07-17 21:25:10 +08:00
|
|
|
{
|
2018-07-17 21:44:36 +08:00
|
|
|
log_info("Finding LUT-LUT pairs...\n");
|
2018-07-17 21:25:10 +08:00
|
|
|
std::unordered_set<IdString> procdLuts;
|
|
|
|
for (auto cell : sorted(ctx->cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (is_lut(ctx, ci) && procdLuts.find(cell.first) == procdLuts.end()) {
|
|
|
|
NetInfo *znet = ci->ports.at(ctx->id("Z")).net;
|
|
|
|
if (znet != nullptr) {
|
|
|
|
for (auto user : znet->users) {
|
2018-07-17 22:45:39 +08:00
|
|
|
if (is_lut(ctx, user.cell) && user.cell != ci &&
|
|
|
|
procdLuts.find(user.cell->name) == procdLuts.end()) {
|
2018-07-17 21:25:10 +08:00
|
|
|
if (can_pack_lutff(ci->name, user.cell->name)) {
|
|
|
|
procdLuts.insert(ci->name);
|
|
|
|
procdLuts.insert(user.cell->name);
|
|
|
|
lutPairs[ci->name] = user.cell->name;
|
|
|
|
goto paired;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (false) {
|
|
|
|
paired:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lutffPairs.find(ci->name) != lutffPairs.end()) {
|
|
|
|
NetInfo *qnet = ctx->cells.at(lutffPairs[ci->name])->ports.at(ctx->id("Q")).net;
|
|
|
|
if (qnet != nullptr) {
|
|
|
|
for (auto user : qnet->users) {
|
2018-07-17 22:45:39 +08:00
|
|
|
if (is_lut(ctx, user.cell) && user.cell != ci &&
|
|
|
|
procdLuts.find(user.cell->name) == procdLuts.end()) {
|
2018-07-17 21:25:10 +08:00
|
|
|
if (can_pack_lutff(ci->name, user.cell->name)) {
|
|
|
|
procdLuts.insert(ci->name);
|
|
|
|
procdLuts.insert(user.cell->name);
|
|
|
|
lutPairs[ci->name] = user.cell->name;
|
|
|
|
goto paired_ff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (false) {
|
|
|
|
paired_ff:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-17 22:45:39 +08:00
|
|
|
for (const char *inp : {"A", "B", "C", "D"}) {
|
|
|
|
NetInfo *innet = ci->ports.at(ctx->id(inp)).net;
|
2018-07-17 21:25:10 +08:00
|
|
|
if (innet != nullptr && innet->driver.cell != nullptr) {
|
|
|
|
CellInfo *drv = innet->driver.cell;
|
2018-07-17 22:45:39 +08:00
|
|
|
if (is_lut(ctx, drv) && drv != ci && innet->driver.port == ctx->id("Z")) {
|
2018-07-17 21:25:10 +08:00
|
|
|
if (procdLuts.find(drv->name) == procdLuts.end()) {
|
|
|
|
if (can_pack_lutff(ci->name, drv->name)) {
|
|
|
|
procdLuts.insert(ci->name);
|
|
|
|
procdLuts.insert(drv->name);
|
|
|
|
lutPairs[ci->name] = drv->name;
|
|
|
|
goto paired_inlut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (is_ff(ctx, drv) && innet->driver.port == ctx->id("Q")) {
|
|
|
|
auto fflut = fflutPairs.find(drv->name);
|
2018-07-17 22:45:39 +08:00
|
|
|
if (fflut != fflutPairs.end() && fflut->second != ci->name &&
|
|
|
|
procdLuts.find(fflut->second) == procdLuts.end()) {
|
2018-07-17 21:25:10 +08:00
|
|
|
if (can_pack_lutff(ci->name, fflut->second)) {
|
|
|
|
procdLuts.insert(ci->name);
|
|
|
|
procdLuts.insert(fflut->second);
|
|
|
|
lutPairs[ci->name] = fflut->second;
|
|
|
|
goto paired_inlut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (false) {
|
|
|
|
paired_inlut:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-09 23:17:26 +08:00
|
|
|
// Return true if an port is a top level port that provides its own IOBUF
|
2018-11-09 23:17:37 +08:00
|
|
|
bool is_top_port(PortRef &port)
|
|
|
|
{
|
2018-11-09 23:17:26 +08:00
|
|
|
if (port.cell == nullptr)
|
|
|
|
return false;
|
|
|
|
if (port.cell->type == id_DCUA) {
|
|
|
|
return port.port == id_CH0_HDINP || port.port == id_CH0_HDINN || port.port == id_CH0_HDOUTP ||
|
2018-11-09 23:17:37 +08:00
|
|
|
port.port == id_CH0_HDOUTN || port.port == id_CH1_HDINP || port.port == id_CH1_HDINN ||
|
|
|
|
port.port == id_CH1_HDOUTP || port.port == id_CH1_HDOUTN;
|
2018-11-09 23:17:26 +08:00
|
|
|
} else if (port.cell->type == id_EXTREFB) {
|
|
|
|
return port.port == id_REFCLKP || port.port == id_REFCLKN;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if a net only drives a top port
|
2018-11-09 23:17:37 +08:00
|
|
|
bool drives_top_port(NetInfo *net, PortRef &tp)
|
|
|
|
{
|
2018-11-09 23:17:26 +08:00
|
|
|
if (net == nullptr)
|
|
|
|
return false;
|
|
|
|
for (auto user : net->users) {
|
|
|
|
if (is_top_port(user)) {
|
|
|
|
if (net->users.size() > 1)
|
2018-11-09 23:17:37 +08:00
|
|
|
log_error(" port %s.%s must be connected to (and only to) a top level pin\n",
|
|
|
|
user.cell->name.c_str(ctx), user.port.c_str(ctx));
|
2018-11-09 23:17:26 +08:00
|
|
|
tp = user;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (net->driver.cell != nullptr && is_top_port(net->driver)) {
|
|
|
|
if (net->users.size() > 1)
|
2018-11-09 23:17:37 +08:00
|
|
|
log_error(" port %s.%s must be connected to (and only to) a top level pin\n",
|
|
|
|
net->driver.cell->name.c_str(ctx), net->driver.port.c_str(ctx));
|
2018-11-09 23:17:26 +08:00
|
|
|
tp = net->driver;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:19:27 +08:00
|
|
|
// Simple "packer" to remove nextpnr IOBUFs, this assumes IOBUFs are manually instantiated
|
2018-07-17 19:41:33 +08:00
|
|
|
void pack_io()
|
2018-07-17 19:19:27 +08:00
|
|
|
{
|
|
|
|
log_info("Packing IOs..\n");
|
2018-07-08 18:56:43 +08:00
|
|
|
|
2018-07-17 19:19:27 +08:00
|
|
|
for (auto cell : sorted(ctx->cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (is_nextpnr_iob(ctx, ci)) {
|
|
|
|
CellInfo *trio = nullptr;
|
2018-11-09 23:17:26 +08:00
|
|
|
NetInfo *ionet = nullptr;
|
|
|
|
PortRef tp;
|
2018-07-17 19:19:27 +08:00
|
|
|
if (ci->type == ctx->id("$nextpnr_ibuf") || ci->type == ctx->id("$nextpnr_iobuf")) {
|
2018-11-09 23:17:26 +08:00
|
|
|
ionet = ci->ports.at(ctx->id("O")).net;
|
|
|
|
trio = net_only_drives(ctx, ionet, is_trellis_io, ctx->id("B"), true, ci);
|
2018-07-17 19:19:27 +08:00
|
|
|
|
|
|
|
} else if (ci->type == ctx->id("$nextpnr_obuf")) {
|
2018-11-09 23:17:26 +08:00
|
|
|
ionet = ci->ports.at(ctx->id("I")).net;
|
2018-07-17 19:19:27 +08:00
|
|
|
trio = net_only_drives(ctx, ci->ports.at(ctx->id("I")).net, is_trellis_io, ctx->id("B"), true, ci);
|
2018-07-08 18:56:43 +08:00
|
|
|
}
|
2018-07-17 19:19:27 +08:00
|
|
|
if (trio != nullptr) {
|
|
|
|
// Trivial case, TRELLIS_IO used. Just destroy the net and the
|
|
|
|
// iobuf
|
|
|
|
log_info("%s feeds TRELLIS_IO %s, removing %s %s.\n", ci->name.c_str(ctx), trio->name.c_str(ctx),
|
|
|
|
ci->type.c_str(ctx), ci->name.c_str(ctx));
|
|
|
|
NetInfo *net = trio->ports.at(ctx->id("B")).net;
|
|
|
|
if (net != nullptr) {
|
|
|
|
ctx->nets.erase(net->name);
|
|
|
|
trio->ports.at(ctx->id("B")).net = nullptr;
|
2018-07-08 18:56:43 +08:00
|
|
|
}
|
2018-07-17 19:19:27 +08:00
|
|
|
if (ci->type == ctx->id("$nextpnr_iobuf")) {
|
|
|
|
NetInfo *net2 = ci->ports.at(ctx->id("I")).net;
|
|
|
|
if (net2 != nullptr) {
|
|
|
|
ctx->nets.erase(net2->name);
|
|
|
|
}
|
|
|
|
}
|
2018-11-09 23:17:26 +08:00
|
|
|
} else if (drives_top_port(ionet, tp)) {
|
2018-11-09 23:17:37 +08:00
|
|
|
log_info("%s feeds %s %s.%s, removing %s %s.\n", ci->name.c_str(ctx), tp.cell->type.c_str(ctx),
|
|
|
|
tp.cell->name.c_str(ctx), tp.port.c_str(ctx), ci->type.c_str(ctx), ci->name.c_str(ctx));
|
2018-11-09 23:17:26 +08:00
|
|
|
if (ionet != nullptr) {
|
|
|
|
ctx->nets.erase(ionet->name);
|
|
|
|
tp.cell->ports.at(tp.port).net = nullptr;
|
|
|
|
}
|
|
|
|
if (ci->type == ctx->id("$nextpnr_iobuf")) {
|
|
|
|
NetInfo *net2 = ci->ports.at(ctx->id("I")).net;
|
|
|
|
if (net2 != nullptr) {
|
|
|
|
ctx->nets.erase(net2->name);
|
|
|
|
}
|
|
|
|
}
|
2018-07-17 19:19:27 +08:00
|
|
|
} else {
|
2018-10-31 19:30:09 +08:00
|
|
|
// Create a TRELLIS_IO buffer
|
|
|
|
std::unique_ptr<CellInfo> tr_cell =
|
|
|
|
create_ecp5_cell(ctx, ctx->id("TRELLIS_IO"), ci->name.str(ctx) + "$tr_io");
|
|
|
|
nxio_to_tr(ctx, ci, tr_cell.get(), new_cells, packed_cells);
|
|
|
|
new_cells.push_back(std::move(tr_cell));
|
|
|
|
trio = new_cells.back().get();
|
2018-07-08 18:56:43 +08:00
|
|
|
}
|
2018-07-18 22:01:53 +08:00
|
|
|
|
2018-07-17 19:19:27 +08:00
|
|
|
packed_cells.insert(ci->name);
|
2018-11-09 23:17:26 +08:00
|
|
|
if (trio != nullptr) {
|
|
|
|
for (const auto &attr : ci->attrs)
|
|
|
|
trio->attrs[attr.first] = attr.second;
|
2018-07-18 22:01:53 +08:00
|
|
|
|
2018-11-09 23:17:26 +08:00
|
|
|
auto loc_attr = trio->attrs.find(ctx->id("LOC"));
|
|
|
|
if (loc_attr != trio->attrs.end()) {
|
|
|
|
std::string pin = loc_attr->second;
|
|
|
|
BelId pinBel = ctx->getPackagePinBel(pin);
|
|
|
|
if (pinBel == BelId()) {
|
|
|
|
log_error("IO pin '%s' constrained to pin '%s', which does not exist for package '%s'.\n",
|
|
|
|
trio->name.c_str(ctx), pin.c_str(), ctx->args.package.c_str());
|
|
|
|
} else {
|
|
|
|
log_info("pin '%s' constrained to Bel '%s'.\n", trio->name.c_str(ctx),
|
|
|
|
ctx->getBelName(pinBel).c_str(ctx));
|
|
|
|
}
|
|
|
|
trio->attrs[ctx->id("BEL")] = ctx->getBelName(pinBel).str(ctx);
|
2018-07-18 22:01:53 +08:00
|
|
|
}
|
|
|
|
}
|
2018-07-08 18:56:43 +08:00
|
|
|
}
|
2018-07-17 19:19:27 +08:00
|
|
|
}
|
2018-07-17 19:41:33 +08:00
|
|
|
flush_cells();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass to pack LUT5s into a newly created slice
|
|
|
|
void pack_lut5s()
|
|
|
|
{
|
|
|
|
log_info("Packing LUT5s...\n");
|
|
|
|
for (auto cell : sorted(ctx->cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (is_pfumx(ctx, ci)) {
|
|
|
|
std::unique_ptr<CellInfo> packed =
|
|
|
|
create_ecp5_cell(ctx, ctx->id("TRELLIS_SLICE"), ci->name.str(ctx) + "_SLICE");
|
|
|
|
NetInfo *f0 = ci->ports.at(ctx->id("BLUT")).net;
|
|
|
|
if (f0 == nullptr)
|
|
|
|
log_error("PFUMX '%s' has disconnected port 'BLUT'\n", ci->name.c_str(ctx));
|
|
|
|
NetInfo *f1 = ci->ports.at(ctx->id("ALUT")).net;
|
|
|
|
if (f1 == nullptr)
|
|
|
|
log_error("PFUMX '%s' has disconnected port 'ALUT'\n", ci->name.c_str(ctx));
|
2018-07-17 21:44:36 +08:00
|
|
|
CellInfo *lut0 = net_driven_by(ctx, f0, is_lut, ctx->id("Z"));
|
|
|
|
CellInfo *lut1 = net_driven_by(ctx, f1, is_lut, ctx->id("Z"));
|
|
|
|
if (lut0 == nullptr)
|
2018-07-17 19:41:33 +08:00
|
|
|
log_error("PFUMX '%s' has BLUT driven by cell other than a LUT\n", ci->name.c_str(ctx));
|
2018-07-17 21:44:36 +08:00
|
|
|
if (lut1 == nullptr)
|
2018-07-17 19:41:33 +08:00
|
|
|
log_error("PFUMX '%s' has ALUT driven by cell other than a LUT\n", ci->name.c_str(ctx));
|
2018-07-17 21:44:36 +08:00
|
|
|
replace_port(lut0, ctx->id("A"), packed.get(), ctx->id("A0"));
|
|
|
|
replace_port(lut0, ctx->id("B"), packed.get(), ctx->id("B0"));
|
|
|
|
replace_port(lut0, ctx->id("C"), packed.get(), ctx->id("C0"));
|
|
|
|
replace_port(lut0, ctx->id("D"), packed.get(), ctx->id("D0"));
|
|
|
|
replace_port(lut1, ctx->id("A"), packed.get(), ctx->id("A1"));
|
|
|
|
replace_port(lut1, ctx->id("B"), packed.get(), ctx->id("B1"));
|
|
|
|
replace_port(lut1, ctx->id("C"), packed.get(), ctx->id("C1"));
|
|
|
|
replace_port(lut1, ctx->id("D"), packed.get(), ctx->id("D1"));
|
2018-07-17 19:41:33 +08:00
|
|
|
replace_port(ci, ctx->id("C0"), packed.get(), ctx->id("M0"));
|
|
|
|
replace_port(ci, ctx->id("Z"), packed.get(), ctx->id("OFX0"));
|
2018-07-17 21:44:36 +08:00
|
|
|
packed->params[ctx->id("LUT0_INITVAL")] = str_or_default(lut0->params, ctx->id("INIT"), "0");
|
|
|
|
packed->params[ctx->id("LUT1_INITVAL")] = str_or_default(lut1->params, ctx->id("INIT"), "0");
|
|
|
|
|
2018-07-17 19:41:33 +08:00
|
|
|
ctx->nets.erase(f0->name);
|
|
|
|
ctx->nets.erase(f1->name);
|
2018-07-17 21:25:10 +08:00
|
|
|
sliceUsage[packed->name].lut0_used = true;
|
|
|
|
sliceUsage[packed->name].lut1_used = true;
|
|
|
|
sliceUsage[packed->name].mux5_used = true;
|
2018-07-17 20:19:21 +08:00
|
|
|
|
|
|
|
if (lutffPairs.find(ci->name) != lutffPairs.end()) {
|
|
|
|
CellInfo *ff = ctx->cells.at(lutffPairs[ci->name]).get();
|
2018-07-17 21:44:36 +08:00
|
|
|
ff_to_slice(ctx, ff, packed.get(), 0, true);
|
2018-07-17 20:19:21 +08:00
|
|
|
packed_cells.insert(ff->name);
|
2018-07-17 21:25:10 +08:00
|
|
|
sliceUsage[packed->name].ff0_used = true;
|
2018-07-18 15:52:53 +08:00
|
|
|
lutffPairs.erase(ci->name);
|
|
|
|
fflutPairs.erase(ff->name);
|
2018-07-17 20:19:21 +08:00
|
|
|
}
|
|
|
|
|
2018-07-17 19:41:33 +08:00
|
|
|
new_cells.push_back(std::move(packed));
|
2018-07-17 21:44:36 +08:00
|
|
|
packed_cells.insert(lut0->name);
|
|
|
|
packed_cells.insert(lut1->name);
|
|
|
|
packed_cells.insert(ci->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flush_cells();
|
|
|
|
}
|
|
|
|
|
2018-09-30 22:12:06 +08:00
|
|
|
// Create a feed in to the carry chain
|
2018-09-30 23:29:26 +08:00
|
|
|
CellInfo *make_carry_feed_in(NetInfo *carry, PortRef chain_in)
|
|
|
|
{
|
2018-09-30 23:58:02 +08:00
|
|
|
std::unique_ptr<CellInfo> feedin = create_ecp5_cell(ctx, ctx->id("CCU2C"));
|
2018-09-30 22:12:06 +08:00
|
|
|
|
2018-09-30 23:58:02 +08:00
|
|
|
feedin->params[ctx->id("INIT0")] = "10"; // LUT4 = 0; LUT2 = A
|
|
|
|
feedin->params[ctx->id("INIT1")] = "65535";
|
2018-09-30 22:12:06 +08:00
|
|
|
feedin->params[ctx->id("INJECT1_0")] = "NO";
|
|
|
|
feedin->params[ctx->id("INJECT1_1")] = "YES";
|
|
|
|
|
2018-09-30 23:29:26 +08:00
|
|
|
carry->users.erase(std::remove_if(carry->users.begin(), carry->users.end(),
|
|
|
|
[chain_in](const PortRef &user) {
|
|
|
|
return user.port == chain_in.port && user.cell == chain_in.cell;
|
|
|
|
}),
|
|
|
|
carry->users.end());
|
2018-09-30 22:12:06 +08:00
|
|
|
connect_port(ctx, carry, feedin.get(), id_A0);
|
|
|
|
|
|
|
|
std::unique_ptr<NetInfo> new_carry(new NetInfo());
|
2018-09-30 23:58:02 +08:00
|
|
|
new_carry->name = ctx->id(feedin->name.str(ctx) + "$COUT");
|
|
|
|
connect_port(ctx, new_carry.get(), feedin.get(), ctx->id("COUT"));
|
2018-10-01 01:10:20 +08:00
|
|
|
chain_in.cell->ports[chain_in.port].net = nullptr;
|
2018-09-30 22:12:06 +08:00
|
|
|
connect_port(ctx, new_carry.get(), chain_in.cell, chain_in.port);
|
|
|
|
|
|
|
|
CellInfo *feedin_ptr = feedin.get();
|
2018-10-01 00:18:30 +08:00
|
|
|
IdString feedin_name = feedin->name;
|
|
|
|
ctx->cells[feedin_name] = std::move(feedin);
|
2018-09-30 22:12:06 +08:00
|
|
|
IdString new_carry_name = new_carry->name;
|
|
|
|
ctx->nets[new_carry_name] = std::move(new_carry);
|
|
|
|
return feedin_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a feed out and loop through from the carry chain
|
2018-09-30 23:58:02 +08:00
|
|
|
CellInfo *make_carry_feed_out(NetInfo *carry, boost::optional<PortRef> chain_next = boost::optional<PortRef>())
|
2018-09-30 23:29:26 +08:00
|
|
|
{
|
2018-09-30 23:58:02 +08:00
|
|
|
std::unique_ptr<CellInfo> feedout = create_ecp5_cell(ctx, ctx->id("CCU2C"));
|
|
|
|
feedout->params[ctx->id("INIT0")] = "0";
|
|
|
|
feedout->params[ctx->id("INIT1")] = "10"; // LUT4 = 0; LUT2 = A
|
2018-10-01 02:27:06 +08:00
|
|
|
feedout->params[ctx->id("INJECT1_0")] = "NO";
|
2018-09-30 22:12:06 +08:00
|
|
|
feedout->params[ctx->id("INJECT1_1")] = "NO";
|
|
|
|
|
|
|
|
PortRef carry_drv = carry->driver;
|
|
|
|
carry->driver.cell = nullptr;
|
2018-09-30 23:58:02 +08:00
|
|
|
connect_port(ctx, carry, feedout.get(), ctx->id("S0"));
|
2018-09-30 22:12:06 +08:00
|
|
|
|
|
|
|
std::unique_ptr<NetInfo> new_cin(new NetInfo());
|
2018-09-30 23:58:02 +08:00
|
|
|
new_cin->name = ctx->id(feedout->name.str(ctx) + "$CIN");
|
2018-09-30 22:12:06 +08:00
|
|
|
new_cin->driver = carry_drv;
|
|
|
|
carry_drv.cell->ports.at(carry_drv.port).net = new_cin.get();
|
2018-09-30 23:58:02 +08:00
|
|
|
connect_port(ctx, new_cin.get(), feedout.get(), ctx->id("CIN"));
|
2018-09-30 22:12:06 +08:00
|
|
|
|
|
|
|
if (chain_next) {
|
|
|
|
// Loop back into LUT4_1 for feedthrough
|
|
|
|
connect_port(ctx, carry, feedout.get(), id_A1);
|
|
|
|
|
2018-09-30 23:29:26 +08:00
|
|
|
carry->users.erase(std::remove_if(carry->users.begin(), carry->users.end(),
|
|
|
|
[chain_next](const PortRef &user) {
|
|
|
|
return user.port == chain_next->port && user.cell == chain_next->cell;
|
|
|
|
}),
|
|
|
|
carry->users.end());
|
2018-09-30 22:12:06 +08:00
|
|
|
|
|
|
|
std::unique_ptr<NetInfo> new_cout(new NetInfo());
|
2018-09-30 23:58:02 +08:00
|
|
|
new_cout->name = ctx->id(feedout->name.str(ctx) + "$COUT");
|
|
|
|
connect_port(ctx, new_cout.get(), feedout.get(), ctx->id("COUT"));
|
2018-09-30 22:12:06 +08:00
|
|
|
|
|
|
|
chain_next->cell->ports[chain_next->port].net = nullptr;
|
|
|
|
connect_port(ctx, new_cout.get(), chain_next->cell, chain_next->port);
|
|
|
|
|
|
|
|
IdString new_cout_name = new_cout->name;
|
|
|
|
ctx->nets[new_cout_name] = std::move(new_cout);
|
2018-09-30 23:29:26 +08:00
|
|
|
}
|
2018-09-30 22:12:06 +08:00
|
|
|
|
|
|
|
CellInfo *feedout_ptr = feedout.get();
|
2018-10-01 00:18:30 +08:00
|
|
|
IdString feedout_name = feedout->name;
|
|
|
|
ctx->cells[feedout_name] = std::move(feedout);
|
2018-09-30 22:12:06 +08:00
|
|
|
|
|
|
|
IdString new_cin_name = new_cin->name;
|
|
|
|
ctx->nets[new_cin_name] = std::move(new_cin);
|
|
|
|
|
|
|
|
return feedout_ptr;
|
|
|
|
}
|
|
|
|
|
2018-09-30 23:58:02 +08:00
|
|
|
// Split a carry chain into multiple legal chains
|
|
|
|
std::vector<CellChain> split_carry_chain(CellChain &carryc)
|
|
|
|
{
|
|
|
|
bool start_of_chain = true;
|
|
|
|
std::vector<CellChain> chains;
|
|
|
|
const int max_length = (ctx->chip_info->width - 4) * 4 - 2;
|
|
|
|
auto curr_cell = carryc.cells.begin();
|
|
|
|
while (curr_cell != carryc.cells.end()) {
|
|
|
|
CellInfo *cell = *curr_cell;
|
|
|
|
if (start_of_chain) {
|
|
|
|
chains.emplace_back();
|
|
|
|
start_of_chain = false;
|
|
|
|
if (cell->ports.at(ctx->id("CIN")).net) {
|
|
|
|
// CIN is not constant and not part of a chain. Must feed in from fabric
|
|
|
|
PortRef inport;
|
|
|
|
inport.cell = cell;
|
|
|
|
inport.port = ctx->id("CIN");
|
|
|
|
CellInfo *feedin = make_carry_feed_in(cell->ports.at(ctx->id("CIN")).net, inport);
|
|
|
|
chains.back().cells.push_back(feedin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chains.back().cells.push_back(cell);
|
|
|
|
bool split_chain = int(chains.back().cells.size()) > max_length;
|
|
|
|
if (split_chain) {
|
|
|
|
CellInfo *passout = make_carry_feed_out(cell->ports.at(ctx->id("COUT")).net);
|
|
|
|
chains.back().cells.back() = passout;
|
|
|
|
start_of_chain = true;
|
|
|
|
} else {
|
|
|
|
NetInfo *carry_net = cell->ports.at(ctx->id("COUT")).net;
|
|
|
|
bool at_end = (curr_cell == carryc.cells.end() - 1);
|
|
|
|
if (carry_net != nullptr && (carry_net->users.size() > 1 || at_end)) {
|
|
|
|
boost::optional<PortRef> nextport;
|
|
|
|
if (!at_end) {
|
|
|
|
auto next_cell = *(curr_cell + 1);
|
|
|
|
PortRef nextpr;
|
|
|
|
nextpr.cell = next_cell;
|
|
|
|
nextpr.port = ctx->id("CIN");
|
|
|
|
nextport = nextpr;
|
|
|
|
}
|
|
|
|
CellInfo *passout = make_carry_feed_out(cell->ports.at(ctx->id("COUT")).net, nextport);
|
|
|
|
chains.back().cells.push_back(passout);
|
|
|
|
}
|
|
|
|
++curr_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return chains;
|
|
|
|
}
|
|
|
|
|
2018-09-30 22:12:06 +08:00
|
|
|
// Pack carries and set up appropriate relative constraints
|
2018-10-01 00:05:42 +08:00
|
|
|
void pack_carries()
|
|
|
|
{
|
2018-09-30 23:58:02 +08:00
|
|
|
log_info("Packing carries...\n");
|
2018-10-01 00:18:30 +08:00
|
|
|
// Find all chains (including single carry cells)
|
|
|
|
auto carry_chains = find_chains(
|
2018-10-01 00:05:42 +08:00
|
|
|
ctx, [](const Context *ctx, const CellInfo *cell) { return is_carry(ctx, cell); },
|
|
|
|
[](const Context *ctx, const CellInfo *cell) {
|
|
|
|
return net_driven_by(ctx, cell->ports.at(ctx->id("CIN")).net, is_carry, ctx->id("COUT"));
|
|
|
|
},
|
|
|
|
[](const Context *ctx, const CellInfo *cell) {
|
|
|
|
return net_only_drives(ctx, cell->ports.at(ctx->id("COUT")).net, is_carry, ctx->id("CIN"), false);
|
|
|
|
},
|
|
|
|
1);
|
2018-10-01 00:18:30 +08:00
|
|
|
std::vector<CellChain> all_chains;
|
|
|
|
|
|
|
|
// Chain splitting
|
|
|
|
for (auto &base_chain : carry_chains) {
|
|
|
|
if (ctx->verbose) {
|
|
|
|
log_info("Found carry chain: \n");
|
|
|
|
for (auto entry : base_chain.cells)
|
|
|
|
log_info(" %s\n", entry->name.c_str(ctx));
|
|
|
|
log_info("\n");
|
|
|
|
}
|
|
|
|
std::vector<CellChain> split_chains = split_carry_chain(base_chain);
|
|
|
|
for (auto &chain : split_chains) {
|
|
|
|
all_chains.push_back(chain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-01 01:39:49 +08:00
|
|
|
std::vector<std::vector<CellInfo *>> packed_chains;
|
2018-10-01 01:10:20 +08:00
|
|
|
|
2018-10-01 00:18:30 +08:00
|
|
|
// Chain packing
|
2018-10-02 01:19:56 +08:00
|
|
|
std::vector<std::tuple<CellInfo *, CellInfo *, int>> ff_packing;
|
2018-10-01 00:18:30 +08:00
|
|
|
for (auto &chain : all_chains) {
|
|
|
|
int cell_count = 0;
|
|
|
|
std::vector<CellInfo *> tile_ffs;
|
2018-10-01 01:10:20 +08:00
|
|
|
std::vector<CellInfo *> packed_chain;
|
2018-10-01 00:18:30 +08:00
|
|
|
for (auto &cell : chain.cells) {
|
|
|
|
if (cell_count % 4 == 0)
|
|
|
|
tile_ffs.clear();
|
|
|
|
std::unique_ptr<CellInfo> slice =
|
|
|
|
create_ecp5_cell(ctx, ctx->id("TRELLIS_SLICE"), cell->name.str(ctx) + "$CCU2_SLICE");
|
|
|
|
|
|
|
|
ccu2c_to_slice(ctx, cell, slice.get());
|
|
|
|
|
|
|
|
CellInfo *ff0 = nullptr;
|
|
|
|
NetInfo *f0net = slice->ports.at(ctx->id("F0")).net;
|
|
|
|
if (f0net != nullptr) {
|
|
|
|
ff0 = net_only_drives(ctx, f0net, is_ff, ctx->id("DI"), false);
|
2018-10-02 00:45:35 +08:00
|
|
|
if (ff0 != nullptr && can_add_ff_to_tile(tile_ffs, ff0)) {
|
2018-10-02 01:19:56 +08:00
|
|
|
ff_packing.push_back(std::make_tuple(ff0, slice.get(), 0));
|
2018-10-01 00:18:30 +08:00
|
|
|
tile_ffs.push_back(ff0);
|
|
|
|
packed_cells.insert(ff0->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CellInfo *ff1 = nullptr;
|
|
|
|
NetInfo *f1net = slice->ports.at(ctx->id("F1")).net;
|
|
|
|
if (f1net != nullptr) {
|
|
|
|
ff1 = net_only_drives(ctx, f1net, is_ff, ctx->id("DI"), false);
|
|
|
|
if (ff1 != nullptr && (ff0 == nullptr || can_pack_ffs(ff0, ff1)) &&
|
2018-10-02 01:20:14 +08:00
|
|
|
can_add_ff_to_tile(tile_ffs, ff1)) {
|
2018-10-02 01:19:56 +08:00
|
|
|
ff_packing.push_back(std::make_tuple(ff1, slice.get(), 1));
|
2018-10-01 00:18:30 +08:00
|
|
|
tile_ffs.push_back(ff1);
|
|
|
|
packed_cells.insert(ff1->name);
|
|
|
|
}
|
|
|
|
}
|
2018-10-01 01:10:20 +08:00
|
|
|
packed_chain.push_back(slice.get());
|
2018-10-01 00:18:30 +08:00
|
|
|
new_cells.push_back(std::move(slice));
|
|
|
|
packed_cells.insert(cell->name);
|
|
|
|
cell_count++;
|
|
|
|
}
|
2018-10-01 01:10:20 +08:00
|
|
|
packed_chains.push_back(packed_chain);
|
2018-10-01 00:18:30 +08:00
|
|
|
}
|
2018-10-01 00:42:47 +08:00
|
|
|
|
2018-10-02 01:19:56 +08:00
|
|
|
for (auto ff : ff_packing)
|
|
|
|
ff_to_slice(ctx, std::get<0>(ff), std::get<1>(ff), std::get<2>(ff), true);
|
|
|
|
|
2018-10-01 00:42:47 +08:00
|
|
|
// Relative chain placement
|
2018-10-01 01:10:20 +08:00
|
|
|
for (auto &chain : packed_chains) {
|
|
|
|
chain.at(0)->constr_abs_z = true;
|
|
|
|
chain.at(0)->constr_z = 0;
|
|
|
|
for (int i = 1; i < int(chain.size()); i++) {
|
|
|
|
chain.at(i)->constr_x = (i / 4);
|
|
|
|
chain.at(i)->constr_y = 0;
|
|
|
|
chain.at(i)->constr_z = i % 4;
|
|
|
|
chain.at(i)->constr_abs_z = true;
|
|
|
|
chain.at(i)->constr_parent = chain.at(0);
|
|
|
|
chain.at(0)->constr_children.push_back(chain.at(i));
|
2018-10-01 00:42:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-01 00:18:30 +08:00
|
|
|
flush_cells();
|
2018-09-30 23:58:02 +08:00
|
|
|
}
|
2018-09-30 22:12:06 +08:00
|
|
|
|
2018-10-01 22:23:12 +08:00
|
|
|
// Pack distributed RAM
|
|
|
|
void pack_dram()
|
|
|
|
{
|
|
|
|
for (auto cell : sorted(ctx->cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (is_dpram(ctx, ci)) {
|
2018-10-02 00:05:02 +08:00
|
|
|
|
|
|
|
// Create RAMW slice
|
2018-10-01 22:23:12 +08:00
|
|
|
std::unique_ptr<CellInfo> ramw_slice =
|
|
|
|
create_ecp5_cell(ctx, ctx->id("TRELLIS_SLICE"), ci->name.str(ctx) + "$RAMW_SLICE");
|
|
|
|
dram_to_ramw(ctx, ci, ramw_slice.get());
|
|
|
|
|
2018-10-02 00:05:02 +08:00
|
|
|
// Create actual RAM slices
|
|
|
|
std::unique_ptr<CellInfo> ram0_slice =
|
|
|
|
create_ecp5_cell(ctx, ctx->id("TRELLIS_SLICE"), ci->name.str(ctx) + "$DPRAM0_SLICE");
|
|
|
|
dram_to_ram_slice(ctx, ci, ram0_slice.get(), ramw_slice.get(), 0);
|
|
|
|
|
|
|
|
std::unique_ptr<CellInfo> ram1_slice =
|
|
|
|
create_ecp5_cell(ctx, ctx->id("TRELLIS_SLICE"), ci->name.str(ctx) + "$DPRAM1_SLICE");
|
|
|
|
dram_to_ram_slice(ctx, ci, ram1_slice.get(), ramw_slice.get(), 1);
|
|
|
|
|
|
|
|
// Disconnect ports of original cell after packing
|
|
|
|
disconnect_port(ctx, ci, id_WCK);
|
|
|
|
disconnect_port(ctx, ci, id_WRE);
|
|
|
|
|
|
|
|
disconnect_port(ctx, ci, ctx->id("RAD[0]"));
|
|
|
|
disconnect_port(ctx, ci, ctx->id("RAD[1]"));
|
|
|
|
disconnect_port(ctx, ci, ctx->id("RAD[2]"));
|
|
|
|
disconnect_port(ctx, ci, ctx->id("RAD[3]"));
|
|
|
|
|
|
|
|
// Attempt to pack FFs into RAM slices
|
2018-10-02 01:19:56 +08:00
|
|
|
std::vector<std::tuple<CellInfo *, CellInfo *, int>> ff_packing;
|
2018-10-02 00:05:02 +08:00
|
|
|
std::vector<CellInfo *> tile_ffs;
|
|
|
|
for (auto slice : {ram0_slice.get(), ram1_slice.get()}) {
|
|
|
|
CellInfo *ff0 = nullptr;
|
|
|
|
NetInfo *f0net = slice->ports.at(ctx->id("F0")).net;
|
|
|
|
if (f0net != nullptr) {
|
|
|
|
ff0 = net_only_drives(ctx, f0net, is_ff, ctx->id("DI"), false);
|
2018-10-02 00:45:35 +08:00
|
|
|
if (ff0 != nullptr && can_add_ff_to_tile(tile_ffs, ff0)) {
|
2018-10-02 22:50:45 +08:00
|
|
|
if (can_pack_ff_dram(slice, ff0)) {
|
2018-10-02 01:45:14 +08:00
|
|
|
ff_packing.push_back(std::make_tuple(ff0, slice, 0));
|
|
|
|
tile_ffs.push_back(ff0);
|
|
|
|
packed_cells.insert(ff0->name);
|
|
|
|
}
|
2018-10-02 00:05:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CellInfo *ff1 = nullptr;
|
|
|
|
NetInfo *f1net = slice->ports.at(ctx->id("F1")).net;
|
|
|
|
if (f1net != nullptr) {
|
|
|
|
ff1 = net_only_drives(ctx, f1net, is_ff, ctx->id("DI"), false);
|
|
|
|
if (ff1 != nullptr && (ff0 == nullptr || can_pack_ffs(ff0, ff1)) &&
|
2018-10-02 01:20:14 +08:00
|
|
|
can_add_ff_to_tile(tile_ffs, ff1)) {
|
2018-10-02 22:50:45 +08:00
|
|
|
if (can_pack_ff_dram(slice, ff1)) {
|
2018-10-02 01:45:14 +08:00
|
|
|
ff_packing.push_back(std::make_tuple(ff1, slice, 1));
|
|
|
|
tile_ffs.push_back(ff1);
|
|
|
|
packed_cells.insert(ff1->name);
|
|
|
|
}
|
2018-10-02 00:05:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 01:19:56 +08:00
|
|
|
for (auto ff : ff_packing)
|
|
|
|
ff_to_slice(ctx, std::get<0>(ff), std::get<1>(ff), std::get<2>(ff), true);
|
|
|
|
|
2018-10-02 00:05:02 +08:00
|
|
|
// Setup placement constraints
|
|
|
|
ram0_slice->constr_abs_z = true;
|
|
|
|
ram0_slice->constr_z = 0;
|
|
|
|
|
|
|
|
ram1_slice->constr_parent = ram0_slice.get();
|
|
|
|
ram1_slice->constr_abs_z = true;
|
|
|
|
ram1_slice->constr_x = 0;
|
|
|
|
ram1_slice->constr_y = 0;
|
|
|
|
ram1_slice->constr_z = 1;
|
|
|
|
ram0_slice->constr_children.push_back(ram1_slice.get());
|
|
|
|
|
|
|
|
ramw_slice->constr_parent = ram0_slice.get();
|
|
|
|
ramw_slice->constr_abs_z = true;
|
|
|
|
ramw_slice->constr_x = 0;
|
|
|
|
ramw_slice->constr_y = 0;
|
|
|
|
ramw_slice->constr_z = 2;
|
|
|
|
ram0_slice->constr_children.push_back(ramw_slice.get());
|
|
|
|
|
|
|
|
new_cells.push_back(std::move(ram0_slice));
|
|
|
|
new_cells.push_back(std::move(ram1_slice));
|
2018-10-01 22:23:12 +08:00
|
|
|
new_cells.push_back(std::move(ramw_slice));
|
|
|
|
packed_cells.insert(ci->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flush_cells();
|
|
|
|
}
|
|
|
|
|
2018-07-17 21:44:36 +08:00
|
|
|
// Pack LUTs that have been paired together
|
|
|
|
void pack_lut_pairs()
|
|
|
|
{
|
|
|
|
log_info("Packing paired LUTs into a SLICE...\n");
|
|
|
|
for (auto pair : lutPairs) {
|
|
|
|
CellInfo *lut0 = ctx->cells.at(pair.first).get();
|
|
|
|
CellInfo *lut1 = ctx->cells.at(pair.second).get();
|
|
|
|
std::unique_ptr<CellInfo> slice =
|
|
|
|
create_ecp5_cell(ctx, ctx->id("TRELLIS_SLICE"), lut0->name.str(ctx) + "_SLICE");
|
|
|
|
|
|
|
|
lut_to_slice(ctx, lut0, slice.get(), 0);
|
|
|
|
lut_to_slice(ctx, lut1, slice.get(), 1);
|
|
|
|
|
2018-08-01 20:39:56 +08:00
|
|
|
auto ff0 = lutffPairs.find(lut0->name);
|
2018-07-17 21:44:36 +08:00
|
|
|
|
|
|
|
if (ff0 != lutffPairs.end()) {
|
|
|
|
ff_to_slice(ctx, ctx->cells.at(ff0->second).get(), slice.get(), 0, true);
|
|
|
|
packed_cells.insert(ff0->second);
|
2018-07-18 15:52:53 +08:00
|
|
|
fflutPairs.erase(ff0->second);
|
2018-08-01 20:39:56 +08:00
|
|
|
lutffPairs.erase(lut0->name);
|
2018-07-17 21:44:36 +08:00
|
|
|
}
|
2018-08-01 20:39:56 +08:00
|
|
|
|
|
|
|
auto ff1 = lutffPairs.find(lut1->name);
|
|
|
|
|
2018-07-17 21:44:36 +08:00
|
|
|
if (ff1 != lutffPairs.end()) {
|
|
|
|
ff_to_slice(ctx, ctx->cells.at(ff1->second).get(), slice.get(), 1, true);
|
|
|
|
packed_cells.insert(ff1->second);
|
2018-07-18 15:52:53 +08:00
|
|
|
fflutPairs.erase(ff1->second);
|
2018-08-01 20:39:56 +08:00
|
|
|
lutffPairs.erase(lut1->name);
|
2018-07-17 21:44:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
new_cells.push_back(std::move(slice));
|
|
|
|
packed_cells.insert(lut0->name);
|
|
|
|
packed_cells.insert(lut1->name);
|
|
|
|
}
|
|
|
|
flush_cells();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pack single LUTs that weren't paired into their own slice,
|
|
|
|
// with an optional FF also
|
|
|
|
void pack_remaining_luts()
|
|
|
|
{
|
2018-07-17 21:48:34 +08:00
|
|
|
log_info("Packing unpaired LUTs into a SLICE...\n");
|
2018-07-17 21:44:36 +08:00
|
|
|
for (auto cell : sorted(ctx->cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (is_lut(ctx, ci)) {
|
|
|
|
std::unique_ptr<CellInfo> slice =
|
|
|
|
create_ecp5_cell(ctx, ctx->id("TRELLIS_SLICE"), ci->name.str(ctx) + "_SLICE");
|
|
|
|
lut_to_slice(ctx, ci, slice.get(), 0);
|
|
|
|
auto ff = lutffPairs.find(ci->name);
|
|
|
|
|
|
|
|
if (ff != lutffPairs.end()) {
|
|
|
|
ff_to_slice(ctx, ctx->cells.at(ff->second).get(), slice.get(), 0, true);
|
|
|
|
packed_cells.insert(ff->second);
|
2018-07-18 15:52:53 +08:00
|
|
|
fflutPairs.erase(ff->second);
|
2018-08-01 20:39:56 +08:00
|
|
|
lutffPairs.erase(ci->name);
|
2018-07-17 21:44:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
new_cells.push_back(std::move(slice));
|
2018-07-17 19:41:33 +08:00
|
|
|
packed_cells.insert(ci->name);
|
|
|
|
}
|
2018-07-08 18:56:43 +08:00
|
|
|
}
|
2018-07-17 19:41:33 +08:00
|
|
|
flush_cells();
|
2018-07-08 18:56:43 +08:00
|
|
|
}
|
2018-07-17 19:19:27 +08:00
|
|
|
|
2018-07-17 21:48:34 +08:00
|
|
|
// Pack flipflops that weren't paired with a LUT
|
|
|
|
void pack_remaining_ffs()
|
|
|
|
{
|
|
|
|
log_info("Packing unpaired FFs into a SLICE...\n");
|
|
|
|
for (auto cell : sorted(ctx->cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (is_ff(ctx, ci)) {
|
|
|
|
std::unique_ptr<CellInfo> slice =
|
|
|
|
create_ecp5_cell(ctx, ctx->id("TRELLIS_SLICE"), ci->name.str(ctx) + "_SLICE");
|
|
|
|
ff_to_slice(ctx, ci, slice.get(), 0, false);
|
|
|
|
new_cells.push_back(std::move(slice));
|
|
|
|
packed_cells.insert(ci->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flush_cells();
|
|
|
|
}
|
|
|
|
|
2018-10-01 21:42:19 +08:00
|
|
|
int make_init_with_const_input(int init, int input, bool value)
|
2018-07-18 03:51:24 +08:00
|
|
|
{
|
|
|
|
int new_init = 0;
|
|
|
|
for (int i = 0; i < 16; i++) {
|
2018-10-01 21:42:19 +08:00
|
|
|
if (((i >> input) & 0x1) != value) {
|
|
|
|
int other_i = (i & (~(1 << input))) | (value << input);
|
2018-07-18 03:51:24 +08:00
|
|
|
if ((init >> other_i) & 0x1)
|
|
|
|
new_init |= (1 << i);
|
|
|
|
} else {
|
|
|
|
if ((init >> i) & 0x1)
|
|
|
|
new_init |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
2018-10-01 21:42:19 +08:00
|
|
|
return new_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_lut_input_constant(CellInfo *cell, IdString input, bool value)
|
|
|
|
{
|
|
|
|
int index = std::string("ABCD").find(input.str(ctx));
|
|
|
|
int init = int_or_default(cell->params, ctx->id("INIT"));
|
|
|
|
int new_init = make_init_with_const_input(init, index, value);
|
2018-07-18 15:52:53 +08:00
|
|
|
cell->params[ctx->id("INIT")] = std::to_string(new_init);
|
2018-07-18 03:51:24 +08:00
|
|
|
cell->ports.at(input).net = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-10-01 21:42:19 +08:00
|
|
|
void set_ccu2c_input_constant(CellInfo *cell, IdString input, bool value)
|
|
|
|
{
|
|
|
|
std::string input_str = input.str(ctx);
|
|
|
|
int lut = std::stoi(input_str.substr(1));
|
|
|
|
int index = std::string("ABCD").find(input_str[0]);
|
|
|
|
int init = int_or_default(cell->params, ctx->id("INIT" + std::to_string(lut)));
|
|
|
|
int new_init = make_init_with_const_input(init, index, value);
|
|
|
|
cell->params[ctx->id("INIT" + std::to_string(lut))] = std::to_string(new_init);
|
|
|
|
cell->ports.at(input).net = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_ccu2c_port_high(CellInfo *cell, IdString input)
|
|
|
|
{
|
|
|
|
if (!cell->ports.count(input))
|
|
|
|
return true; // disconnected port is high
|
|
|
|
if (cell->ports.at(input).net == nullptr || cell->ports.at(input).net->name == ctx->id("$PACKER_VCC_NET"))
|
|
|
|
return true; // disconnected or tied-high port
|
|
|
|
if (cell->ports.at(input).net->driver.cell != nullptr &&
|
|
|
|
cell->ports.at(input).net->driver.cell->type == ctx->id("VCC"))
|
|
|
|
return true; // pre-pack high
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-18 15:35:40 +08:00
|
|
|
// Merge a net into a constant net
|
|
|
|
void set_net_constant(const Context *ctx, NetInfo *orig, NetInfo *constnet, bool constval)
|
|
|
|
{
|
|
|
|
orig->driver.cell = nullptr;
|
|
|
|
for (auto user : orig->users) {
|
|
|
|
if (user.cell != nullptr) {
|
|
|
|
CellInfo *uc = user.cell;
|
|
|
|
if (ctx->verbose)
|
|
|
|
log_info("%s user %s\n", orig->name.c_str(ctx), uc->name.c_str(ctx));
|
|
|
|
if (is_lut(ctx, uc)) {
|
|
|
|
set_lut_input_constant(uc, user.port, constval);
|
|
|
|
} else if (is_ff(ctx, uc) && user.port == ctx->id("CE")) {
|
|
|
|
uc->params[ctx->id("CEMUX")] = constval ? "1" : "0";
|
|
|
|
uc->ports[user.port].net = nullptr;
|
2018-10-01 21:42:19 +08:00
|
|
|
} else if (is_carry(ctx, uc)) {
|
|
|
|
if (constval &&
|
|
|
|
(user.port == id_A0 || user.port == id_A1 || user.port == id_B0 || user.port == id_B1 ||
|
|
|
|
user.port == id_C0 || user.port == id_C1 || user.port == id_D0 || user.port == id_D1)) {
|
|
|
|
// Input tied high, nothing special to do (bitstream gen will auto-enable tie-high)
|
|
|
|
uc->ports[user.port].net = nullptr;
|
|
|
|
} else if (!constval) {
|
|
|
|
if (user.port == id_A0 || user.port == id_A1 || user.port == id_B0 || user.port == id_B1) {
|
|
|
|
// These inputs can be switched to tie-high without consequence
|
|
|
|
set_ccu2c_input_constant(uc, user.port, constval);
|
|
|
|
} else if (user.port == id_C0 && is_ccu2c_port_high(uc, id_D0)) {
|
|
|
|
// Partner must be tied high
|
|
|
|
set_ccu2c_input_constant(uc, user.port, constval);
|
|
|
|
} else if (user.port == id_D0 && is_ccu2c_port_high(uc, id_C0)) {
|
|
|
|
// Partner must be tied high
|
|
|
|
set_ccu2c_input_constant(uc, user.port, constval);
|
|
|
|
} else if (user.port == id_C1 && is_ccu2c_port_high(uc, id_D1)) {
|
|
|
|
// Partner must be tied high
|
|
|
|
set_ccu2c_input_constant(uc, user.port, constval);
|
|
|
|
} else if (user.port == id_D1 && is_ccu2c_port_high(uc, id_C1)) {
|
|
|
|
// Partner must be tied high
|
|
|
|
set_ccu2c_input_constant(uc, user.port, constval);
|
|
|
|
} else {
|
|
|
|
// Not allowed to change to a tie-high
|
|
|
|
uc->ports[user.port].net = constnet;
|
|
|
|
constnet->users.push_back(user);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uc->ports[user.port].net = constnet;
|
|
|
|
constnet->users.push_back(user);
|
|
|
|
}
|
2018-07-18 15:35:40 +08:00
|
|
|
} else if (is_ff(ctx, uc) && user.port == ctx->id("LSR") &&
|
|
|
|
((!constval && str_or_default(uc->params, ctx->id("LSRMUX"), "LSR") == "LSR") ||
|
|
|
|
(constval && str_or_default(uc->params, ctx->id("LSRMUX"), "LSR") == "INV"))) {
|
|
|
|
uc->ports[user.port].net = nullptr;
|
2018-10-06 22:59:22 +08:00
|
|
|
} else if (uc->type == id_DP16KD) {
|
|
|
|
if (user.port == id_CLKA || user.port == id_CLKB || user.port == id_RSTA || user.port == id_RSTB ||
|
|
|
|
user.port == id_WEA || user.port == id_WEB || user.port == id_CEA || user.port == id_CEB ||
|
|
|
|
user.port == id_OCEA || user.port == id_OCEB || user.port == id_CSA0 || user.port == id_CSA1 ||
|
|
|
|
user.port == id_CSA2 || user.port == id_CSB0 || user.port == id_CSB1 || user.port == id_CSB2) {
|
|
|
|
// Connect to CIB CLK, LSR or CE. Default state is 1
|
|
|
|
uc->params[ctx->id(user.port.str(ctx) + "MUX")] = constval ? user.port.str(ctx) : "INV";
|
|
|
|
} else {
|
|
|
|
// Connected to CIB ABCD. Default state is bitstream configurable
|
|
|
|
uc->params[ctx->id(user.port.str(ctx) + "MUX")] = constval ? "1" : "0";
|
|
|
|
}
|
|
|
|
uc->ports[user.port].net = nullptr;
|
2018-10-22 18:19:03 +08:00
|
|
|
} else if (uc->type == id_ALU54B || uc->type == id_MULT18X18D) {
|
|
|
|
if (user.port.str(ctx).substr(0, 3) == "CLK" || user.port.str(ctx).substr(0, 2) == "CE" ||
|
|
|
|
user.port.str(ctx).substr(0, 3) == "RST" || user.port.str(ctx).substr(0, 3) == "SRO" ||
|
|
|
|
user.port.str(ctx).substr(0, 3) == "SRI" || user.port.str(ctx).substr(0, 2) == "RO" ||
|
|
|
|
user.port.str(ctx).substr(0, 2) == "MA" || user.port.str(ctx).substr(0, 2) == "MB" ||
|
|
|
|
user.port.str(ctx).substr(0, 3) == "CFB" || user.port.str(ctx).substr(0, 3) == "CIN" ||
|
2018-10-22 23:18:29 +08:00
|
|
|
user.port.str(ctx).substr(0, 6) == "SOURCE" || user.port.str(ctx).substr(0, 6) == "SIGNED" ||
|
|
|
|
user.port.str(ctx).substr(0, 2) == "OP") {
|
2018-10-22 18:19:03 +08:00
|
|
|
uc->ports[user.port].net = constnet;
|
|
|
|
constnet->users.push_back(user);
|
|
|
|
} else {
|
|
|
|
// Connected to CIB ABCD. Default state is bitstream configurable
|
|
|
|
uc->params[ctx->id(user.port.str(ctx) + "MUX")] = constval ? "1" : "0";
|
2018-10-22 23:18:29 +08:00
|
|
|
uc->ports[user.port].net = nullptr;
|
2018-10-22 18:19:03 +08:00
|
|
|
}
|
2018-07-18 15:35:40 +08:00
|
|
|
} else {
|
|
|
|
uc->ports[user.port].net = constnet;
|
|
|
|
constnet->users.push_back(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
orig->users.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pack constants (simple implementation)
|
|
|
|
void pack_constants()
|
|
|
|
{
|
|
|
|
log_info("Packing constants..\n");
|
|
|
|
|
|
|
|
std::unique_ptr<CellInfo> gnd_cell = create_ecp5_cell(ctx, ctx->id("LUT4"), "$PACKER_GND");
|
2018-07-18 15:52:53 +08:00
|
|
|
gnd_cell->params[ctx->id("INIT")] = "0";
|
2018-07-18 15:35:40 +08:00
|
|
|
std::unique_ptr<NetInfo> gnd_net = std::unique_ptr<NetInfo>(new NetInfo);
|
|
|
|
gnd_net->name = ctx->id("$PACKER_GND_NET");
|
|
|
|
gnd_net->driver.cell = gnd_cell.get();
|
|
|
|
gnd_net->driver.port = ctx->id("Z");
|
|
|
|
gnd_cell->ports.at(ctx->id("Z")).net = gnd_net.get();
|
|
|
|
|
|
|
|
std::unique_ptr<CellInfo> vcc_cell = create_ecp5_cell(ctx, ctx->id("LUT4"), "$PACKER_VCC");
|
2018-07-18 15:52:53 +08:00
|
|
|
vcc_cell->params[ctx->id("INIT")] = "65535";
|
2018-07-18 15:35:40 +08:00
|
|
|
std::unique_ptr<NetInfo> vcc_net = std::unique_ptr<NetInfo>(new NetInfo);
|
|
|
|
vcc_net->name = ctx->id("$PACKER_VCC_NET");
|
|
|
|
vcc_net->driver.cell = vcc_cell.get();
|
|
|
|
vcc_net->driver.port = ctx->id("Z");
|
|
|
|
vcc_cell->ports.at(ctx->id("Z")).net = vcc_net.get();
|
|
|
|
|
|
|
|
std::vector<IdString> dead_nets;
|
|
|
|
|
|
|
|
bool gnd_used = false, vcc_used = false;
|
|
|
|
|
|
|
|
for (auto net : sorted(ctx->nets)) {
|
|
|
|
NetInfo *ni = net.second;
|
|
|
|
if (ni->driver.cell != nullptr && ni->driver.cell->type == ctx->id("GND")) {
|
|
|
|
IdString drv_cell = ni->driver.cell->name;
|
|
|
|
set_net_constant(ctx, ni, gnd_net.get(), false);
|
|
|
|
gnd_used = true;
|
|
|
|
dead_nets.push_back(net.first);
|
|
|
|
ctx->cells.erase(drv_cell);
|
|
|
|
} else if (ni->driver.cell != nullptr && ni->driver.cell->type == ctx->id("VCC")) {
|
|
|
|
IdString drv_cell = ni->driver.cell->name;
|
|
|
|
set_net_constant(ctx, ni, vcc_net.get(), true);
|
|
|
|
vcc_used = true;
|
|
|
|
dead_nets.push_back(net.first);
|
|
|
|
ctx->cells.erase(drv_cell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gnd_used) {
|
|
|
|
ctx->cells[gnd_cell->name] = std::move(gnd_cell);
|
|
|
|
ctx->nets[gnd_net->name] = std::move(gnd_net);
|
|
|
|
}
|
|
|
|
if (vcc_used) {
|
|
|
|
ctx->cells[vcc_cell->name] = std::move(vcc_cell);
|
|
|
|
ctx->nets[vcc_net->name] = std::move(vcc_net);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto dn : dead_nets) {
|
|
|
|
ctx->nets.erase(dn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 23:47:03 +08:00
|
|
|
void autocreate_empty_port(CellInfo *cell, IdString port)
|
|
|
|
{
|
|
|
|
if (!cell->ports.count(port)) {
|
|
|
|
cell->ports[port].name = port;
|
|
|
|
cell->ports[port].net = nullptr;
|
|
|
|
cell->ports[port].type = PORT_IN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pack EBR
|
|
|
|
void pack_ebr()
|
|
|
|
{
|
2018-10-06 22:59:22 +08:00
|
|
|
// Autoincrement WID (starting from 3 seems to match vendor behaviour?)
|
|
|
|
int wid = 3;
|
2018-10-05 23:47:03 +08:00
|
|
|
for (auto cell : sorted(ctx->cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (ci->type == id_DP16KD) {
|
|
|
|
// Add ports, even if disconnected, to ensure correct tie-offs
|
|
|
|
for (int i = 0; i < 14; i++) {
|
|
|
|
autocreate_empty_port(ci, ctx->id("ADA" + std::to_string(i)));
|
|
|
|
autocreate_empty_port(ci, ctx->id("ADB" + std::to_string(i)));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 18; i++) {
|
|
|
|
autocreate_empty_port(ci, ctx->id("DIA" + std::to_string(i)));
|
|
|
|
autocreate_empty_port(ci, ctx->id("DIB" + std::to_string(i)));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
autocreate_empty_port(ci, ctx->id("CSA" + std::to_string(i)));
|
|
|
|
autocreate_empty_port(ci, ctx->id("CSB" + std::to_string(i)));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
autocreate_empty_port(ci, ctx->id("CSA" + std::to_string(i)));
|
|
|
|
autocreate_empty_port(ci, ctx->id("CSB" + std::to_string(i)));
|
|
|
|
}
|
|
|
|
|
|
|
|
autocreate_empty_port(ci, id_CLKA);
|
|
|
|
autocreate_empty_port(ci, id_CEA);
|
|
|
|
autocreate_empty_port(ci, id_OCEA);
|
|
|
|
autocreate_empty_port(ci, id_WEA);
|
|
|
|
autocreate_empty_port(ci, id_RSTA);
|
|
|
|
|
|
|
|
autocreate_empty_port(ci, id_CLKB);
|
|
|
|
autocreate_empty_port(ci, id_CEB);
|
|
|
|
autocreate_empty_port(ci, id_OCEB);
|
|
|
|
autocreate_empty_port(ci, id_WEB);
|
|
|
|
autocreate_empty_port(ci, id_RSTB);
|
2018-10-06 22:59:22 +08:00
|
|
|
|
|
|
|
ci->attrs[ctx->id("WID")] = std::to_string(wid++);
|
2018-10-05 23:47:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-22 18:19:03 +08:00
|
|
|
// Pack DSPs
|
|
|
|
void pack_dsps()
|
|
|
|
{
|
|
|
|
for (auto cell : sorted(ctx->cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (ci->type == id_MULT18X18D) {
|
|
|
|
// Add ports, even if disconnected, to ensure correct tie-offs
|
|
|
|
for (auto sig : {"CLK", "CE", "RST"})
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
autocreate_empty_port(ci, ctx->id(sig + std::to_string(i)));
|
|
|
|
for (auto sig : {"SIGNED", "SOURCE"})
|
|
|
|
for (auto c : {"A", "B"})
|
|
|
|
autocreate_empty_port(ci, ctx->id(sig + std::string(c)));
|
|
|
|
for (auto port : {"A", "B", "C"})
|
|
|
|
for (int i = 0; i < 18; i++)
|
|
|
|
autocreate_empty_port(ci, ctx->id(port + std::to_string(i)));
|
|
|
|
for (auto port : {"SRIA", "SRIB"})
|
|
|
|
for (int i = 0; i < 18; i++)
|
|
|
|
autocreate_empty_port(ci, ctx->id(port + std::to_string(i)));
|
|
|
|
} else if (ci->type == id_ALU54B) {
|
|
|
|
for (auto sig : {"CLK", "CE", "RST"})
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
autocreate_empty_port(ci, ctx->id(sig + std::to_string(i)));
|
|
|
|
autocreate_empty_port(ci, id_SIGNEDIA);
|
|
|
|
autocreate_empty_port(ci, id_SIGNEDIB);
|
|
|
|
autocreate_empty_port(ci, id_SIGNEDCIN);
|
|
|
|
for (auto port : {"A", "B", "MA", "MB"})
|
|
|
|
for (int i = 0; i < 36; i++)
|
|
|
|
autocreate_empty_port(ci, ctx->id(port + std::to_string(i)));
|
|
|
|
for (auto port : {"C", "CFB", "CIN"})
|
|
|
|
for (int i = 0; i < 54; i++)
|
|
|
|
autocreate_empty_port(ci, ctx->id(port + std::to_string(i)));
|
|
|
|
for (int i = 0; i < 11; i++)
|
|
|
|
autocreate_empty_port(ci, ctx->id("OP" + std::to_string(i)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-07 22:24:58 +08:00
|
|
|
// "Pack" DCUs
|
2018-11-07 23:08:47 +08:00
|
|
|
void pack_dcus()
|
|
|
|
{
|
2018-11-07 22:24:58 +08:00
|
|
|
for (auto cell : sorted(ctx->cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (ci->type == id_DCUA) {
|
2018-11-08 04:44:43 +08:00
|
|
|
if (!ci->attrs.count(ctx->id("BEL")))
|
|
|
|
log_error("DCU must be constrained to a Bel!\n");
|
2018-11-07 22:24:58 +08:00
|
|
|
// Empty port auto-creation to generate correct tie-downs
|
|
|
|
BelId exemplar_bel;
|
|
|
|
for (auto bel : ctx->getBels()) {
|
|
|
|
if (ctx->getBelType(bel) == id_DCUA) {
|
|
|
|
exemplar_bel = bel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NPNR_ASSERT(exemplar_bel != BelId());
|
|
|
|
for (auto pin : ctx->getBelPins(exemplar_bel))
|
|
|
|
if (ctx->getBelPinType(exemplar_bel, pin) == PORT_IN)
|
|
|
|
autocreate_empty_port(ci, pin);
|
2018-11-08 04:44:43 +08:00
|
|
|
} else if (ci->type == id_EXTREFB) {
|
|
|
|
const NetInfo *refo = net_or_nullptr(ci, id_REFCLKO);
|
|
|
|
CellInfo *dcu = nullptr;
|
|
|
|
if (refo == nullptr)
|
|
|
|
log_error("EXTREFB REFCLKO must not be unconnected\n");
|
|
|
|
for (auto user : refo->users) {
|
|
|
|
if (user.cell->type != id_DCUA || (dcu != nullptr && dcu != user.cell))
|
|
|
|
log_error("EXTREFB REFCLKO must only drive a single DCUA\n");
|
|
|
|
dcu = user.cell;
|
|
|
|
}
|
|
|
|
if (!dcu->attrs.count(ctx->id("BEL")))
|
|
|
|
log_error("DCU must be constrained to a Bel!\n");
|
2018-11-09 23:17:37 +08:00
|
|
|
std::string bel = dcu->attrs.at(ctx->id("BEL"));
|
2018-11-08 04:44:43 +08:00
|
|
|
NPNR_ASSERT(bel.substr(bel.length() - 3) == "DCU");
|
|
|
|
bel.replace(bel.length() - 3, 3, "EXTREF");
|
|
|
|
ci->attrs[ctx->id("BEL")] = bel;
|
|
|
|
} else if (ci->type == id_PCSCLKDIV) {
|
|
|
|
const NetInfo *clki = net_or_nullptr(ci, id_CLKI);
|
|
|
|
if (clki != nullptr && clki->driver.cell != nullptr && clki->driver.cell->type == id_DCUA) {
|
|
|
|
CellInfo *dcu = clki->driver.cell;
|
|
|
|
if (!dcu->attrs.count(ctx->id("BEL")))
|
|
|
|
log_error("DCU must be constrained to a Bel!\n");
|
|
|
|
BelId bel = ctx->getBelByName(ctx->id(dcu->attrs.at(ctx->id("BEL"))));
|
|
|
|
if (bel == BelId())
|
|
|
|
log_error("Invalid DCU bel '%s'\n", dcu->attrs.at(ctx->id("BEL")).c_str());
|
|
|
|
Loc loc = ctx->getBelLocation(bel);
|
|
|
|
// DCU0 -> CLKDIV z=0; DCU1 -> CLKDIV z=1
|
|
|
|
ci->constr_abs_z = true;
|
2018-11-09 23:17:37 +08:00
|
|
|
ci->constr_z = (loc.x >= 69) ? 1 : 0;
|
2018-11-08 04:44:43 +08:00
|
|
|
}
|
2018-11-07 22:24:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:19:27 +08:00
|
|
|
public:
|
2018-07-17 19:41:33 +08:00
|
|
|
void pack()
|
|
|
|
{
|
|
|
|
pack_io();
|
2018-10-05 23:47:03 +08:00
|
|
|
pack_ebr();
|
2018-10-22 18:19:03 +08:00
|
|
|
pack_dsps();
|
2018-11-07 22:24:58 +08:00
|
|
|
pack_dcus();
|
2018-07-18 15:35:40 +08:00
|
|
|
pack_constants();
|
2018-10-02 00:45:35 +08:00
|
|
|
pack_dram();
|
2018-10-01 00:42:47 +08:00
|
|
|
pack_carries();
|
2018-07-17 21:44:36 +08:00
|
|
|
find_lutff_pairs();
|
2018-07-17 19:41:33 +08:00
|
|
|
pack_lut5s();
|
2018-07-17 21:44:36 +08:00
|
|
|
pair_luts();
|
|
|
|
pack_lut_pairs();
|
|
|
|
pack_remaining_luts();
|
2018-07-17 21:48:34 +08:00
|
|
|
pack_remaining_ffs();
|
2018-11-01 00:22:34 +08:00
|
|
|
promote_ecp5_globals(ctx);
|
2018-10-02 00:45:35 +08:00
|
|
|
ctx->check();
|
2018-07-17 19:41:33 +08:00
|
|
|
}
|
2018-07-17 19:19:27 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
Context *ctx;
|
2018-07-17 19:41:33 +08:00
|
|
|
|
|
|
|
std::unordered_set<IdString> packed_cells;
|
|
|
|
std::vector<std::unique_ptr<CellInfo>> new_cells;
|
|
|
|
|
|
|
|
struct SliceUsage
|
|
|
|
{
|
|
|
|
bool lut0_used = false, lut1_used = false;
|
|
|
|
bool ccu2_used = false, dpram_used = false, ramw_used = false;
|
|
|
|
bool ff0_used = false, ff1_used = false;
|
|
|
|
bool mux5_used = false, muxx_used = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unordered_map<IdString, SliceUsage> sliceUsage;
|
2018-07-17 20:19:21 +08:00
|
|
|
std::unordered_map<IdString, IdString> lutffPairs;
|
2018-07-17 21:25:10 +08:00
|
|
|
std::unordered_map<IdString, IdString> fflutPairs;
|
2018-07-17 21:44:36 +08:00
|
|
|
std::unordered_map<IdString, IdString> lutPairs;
|
2018-07-17 19:19:27 +08:00
|
|
|
};
|
2018-07-08 18:56:43 +08:00
|
|
|
// Main pack function
|
2018-07-13 21:16:44 +08:00
|
|
|
bool Arch::pack()
|
2018-07-08 18:56:43 +08:00
|
|
|
{
|
2018-07-13 21:16:44 +08:00
|
|
|
Context *ctx = getCtx();
|
2018-07-08 18:56:43 +08:00
|
|
|
try {
|
|
|
|
log_break();
|
2018-07-17 19:19:27 +08:00
|
|
|
Ecp5Packer(ctx).pack();
|
2018-07-08 18:56:43 +08:00
|
|
|
log_info("Checksum: 0x%08x\n", ctx->checksum());
|
2018-08-19 01:14:18 +08:00
|
|
|
assignArchInfo();
|
2018-07-08 18:56:43 +08:00
|
|
|
return true;
|
|
|
|
} catch (log_execution_error_exception) {
|
2018-08-19 01:14:18 +08:00
|
|
|
assignArchInfo();
|
2018-07-08 18:56:43 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-19 01:14:18 +08:00
|
|
|
void Arch::assignArchInfo()
|
|
|
|
{
|
|
|
|
for (auto cell : sorted(cells)) {
|
|
|
|
CellInfo *ci = cell.second;
|
|
|
|
if (ci->type == id_TRELLIS_SLICE) {
|
2018-10-01 01:39:49 +08:00
|
|
|
|
|
|
|
ci->sliceInfo.using_dff = false;
|
|
|
|
if (ci->ports.count(id_Q0) && ci->ports[id_Q0].net != nullptr)
|
|
|
|
ci->sliceInfo.using_dff = true;
|
|
|
|
if (ci->ports.count(id_Q1) && ci->ports[id_Q1].net != nullptr)
|
|
|
|
ci->sliceInfo.using_dff = true;
|
|
|
|
|
2018-08-19 01:14:18 +08:00
|
|
|
if (ci->ports.count(id_CLK) && ci->ports[id_CLK].net != nullptr)
|
|
|
|
ci->sliceInfo.clk_sig = ci->ports[id_CLK].net->name;
|
|
|
|
else
|
|
|
|
ci->sliceInfo.clk_sig = IdString();
|
|
|
|
|
|
|
|
if (ci->ports.count(id_LSR) && ci->ports[id_LSR].net != nullptr)
|
|
|
|
ci->sliceInfo.lsr_sig = ci->ports[id_LSR].net->name;
|
|
|
|
else
|
|
|
|
ci->sliceInfo.lsr_sig = IdString();
|
|
|
|
|
|
|
|
ci->sliceInfo.clkmux = id(str_or_default(ci->params, id_CLKMUX, "CLK"));
|
|
|
|
ci->sliceInfo.lsrmux = id(str_or_default(ci->params, id_LSRMUX, "LSR"));
|
|
|
|
ci->sliceInfo.srmode = id(str_or_default(ci->params, id_SRMODE, "LSR_OVER_CE"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-08 18:56:43 +08:00
|
|
|
NEXTPNR_NAMESPACE_END
|