2018-06-12 19:40:22 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
2018-06-22 22:19:17 +08:00
|
|
|
* Copyright (C) 2018 Clifford Wolf <clifford@symbioticeda.com>
|
2018-06-17 17:49:57 +08:00
|
|
|
* Copyright (C) 2018 David Shah <david@symbioticeda.com>
|
2018-06-12 19:40:22 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-06-13 23:07:42 +08:00
|
|
|
#include "cells.h"
|
2018-06-25 17:43:59 +08:00
|
|
|
#include "nextpnr.h"
|
2018-06-17 17:14:49 +08:00
|
|
|
#include "util.h"
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-06-12 20:31:26 +08:00
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2018-06-23 22:12:52 +08:00
|
|
|
static const NetInfo *get_net_or_empty(const CellInfo *cell, const IdString port)
|
2018-06-15 03:12:15 +08:00
|
|
|
{
|
|
|
|
auto found = cell->ports.find(port);
|
|
|
|
if (found != cell->ports.end())
|
|
|
|
return found->second.net;
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
2018-06-25 17:43:59 +08:00
|
|
|
bool Arch::logicCellsCompatible(const std::vector<const CellInfo *> &cells) const
|
2018-06-12 19:40:22 +08:00
|
|
|
{
|
|
|
|
bool dffs_exist = false, dffs_neg = false;
|
|
|
|
const NetInfo *cen = nullptr, *clk = nullptr, *sr = nullptr;
|
2018-06-19 19:35:01 +08:00
|
|
|
int locals_count = 0;
|
2018-06-12 19:40:22 +08:00
|
|
|
|
|
|
|
for (auto cell : cells) {
|
2018-06-19 20:44:49 +08:00
|
|
|
if (bool_or_default(cell->params, id_dff_en)) {
|
2018-06-12 19:40:22 +08:00
|
|
|
if (!dffs_exist) {
|
|
|
|
dffs_exist = true;
|
2018-06-19 20:44:49 +08:00
|
|
|
cen = get_net_or_empty(cell, id_cen);
|
|
|
|
clk = get_net_or_empty(cell, id_clk);
|
|
|
|
sr = get_net_or_empty(cell, id_sr);
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-06-25 17:43:59 +08:00
|
|
|
if (!isGlobalNet(cen) && cen != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-25 17:43:59 +08:00
|
|
|
if (!isGlobalNet(clk) && clk != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-25 17:43:59 +08:00
|
|
|
if (!isGlobalNet(sr) && sr != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-06-19 20:44:49 +08:00
|
|
|
if (bool_or_default(cell->params, id_neg_clk)) {
|
2018-06-12 19:40:22 +08:00
|
|
|
dffs_neg = true;
|
|
|
|
}
|
|
|
|
} else {
|
2018-06-19 20:44:49 +08:00
|
|
|
if (cen != get_net_or_empty(cell, id_cen))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-06-19 20:44:49 +08:00
|
|
|
if (clk != get_net_or_empty(cell, id_clk))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-06-19 20:44:49 +08:00
|
|
|
if (sr != get_net_or_empty(cell, id_sr))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-06-19 20:44:49 +08:00
|
|
|
if (dffs_neg != bool_or_default(cell->params, id_neg_clk))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-23 22:12:52 +08:00
|
|
|
const NetInfo *i0 = get_net_or_empty(cell, id_i0), *i1 = get_net_or_empty(cell, id_i1),
|
|
|
|
*i2 = get_net_or_empty(cell, id_i2), *i3 = get_net_or_empty(cell, id_i3);
|
2018-06-17 22:03:16 +08:00
|
|
|
if (i0 != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-17 22:03:16 +08:00
|
|
|
if (i1 != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-17 22:03:16 +08:00
|
|
|
if (i2 != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-17 22:03:16 +08:00
|
|
|
if (i3 != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-12 19:40:22 +08:00
|
|
|
}
|
|
|
|
|
2018-06-19 19:35:01 +08:00
|
|
|
return locals_count <= 32;
|
2018-06-12 19:40:22 +08:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:43:59 +08:00
|
|
|
bool Arch::isBelLocationValid(BelId bel) const
|
2018-06-17 17:45:41 +08:00
|
|
|
{
|
2018-06-25 17:43:59 +08:00
|
|
|
if (getBelType(bel) == TYPE_ICESTORM_LC) {
|
|
|
|
std::vector<const CellInfo *> bel_cells;
|
|
|
|
for (auto bel_other : getBelsAtSameTile(bel)) {
|
|
|
|
IdString cell_other = getBoundBelCell(bel_other);
|
2018-06-17 00:45:32 +08:00
|
|
|
if (cell_other != IdString()) {
|
2018-06-26 03:33:48 +08:00
|
|
|
const CellInfo *ci_other = cells.at(cell_other).get();
|
2018-06-25 17:43:59 +08:00
|
|
|
bel_cells.push_back(ci_other);
|
2018-06-17 00:45:32 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-25 17:43:59 +08:00
|
|
|
return logicCellsCompatible(bel_cells);
|
2018-06-17 00:45:32 +08:00
|
|
|
} else {
|
2018-06-25 17:43:59 +08:00
|
|
|
IdString cellId = getBoundBelCell(bel);
|
2018-06-17 00:45:32 +08:00
|
|
|
if (cellId == IdString())
|
|
|
|
return true;
|
|
|
|
else
|
2018-06-26 03:33:48 +08:00
|
|
|
return isValidBelForCell(cells.at(cellId).get(), bel);
|
2018-06-17 00:45:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:43:59 +08:00
|
|
|
bool Arch::isValidBelForCell(CellInfo *cell, BelId bel) const
|
2018-06-12 19:40:22 +08:00
|
|
|
{
|
2018-06-19 20:44:49 +08:00
|
|
|
if (cell->type == id_icestorm_lc) {
|
2018-06-25 17:43:59 +08:00
|
|
|
assert(getBelType(bel) == TYPE_ICESTORM_LC);
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-06-25 17:43:59 +08:00
|
|
|
std::vector<const CellInfo *> bel_cells;
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-06-25 17:43:59 +08:00
|
|
|
for (auto bel_other : getBelsAtSameTile(bel)) {
|
|
|
|
IdString cell_other = getBoundBelCell(bel_other);
|
|
|
|
if (cell_other != IdString() && bel_other != bel) {
|
2018-06-26 03:33:48 +08:00
|
|
|
const CellInfo *ci_other = cells.at(cell_other).get();
|
2018-06-25 17:43:59 +08:00
|
|
|
bel_cells.push_back(ci_other);
|
2018-06-12 19:40:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:43:59 +08:00
|
|
|
bel_cells.push_back(cell);
|
|
|
|
return logicCellsCompatible(bel_cells);
|
2018-06-19 20:44:49 +08:00
|
|
|
} else if (cell->type == id_sb_io) {
|
2018-06-25 17:43:59 +08:00
|
|
|
return getBelPackagePin(bel) != "";
|
2018-06-19 20:44:49 +08:00
|
|
|
} else if (cell->type == id_sb_gb) {
|
2018-06-16 23:09:41 +08:00
|
|
|
bool is_reset = false, is_cen = false;
|
2018-06-25 17:43:59 +08:00
|
|
|
assert(cell->ports.at(id_glb_buf_out).net != nullptr);
|
|
|
|
for (auto user : cell->ports.at(id_glb_buf_out).net->users) {
|
|
|
|
if (is_reset_port(this, user))
|
2018-06-16 23:09:41 +08:00
|
|
|
is_reset = true;
|
2018-06-25 17:43:59 +08:00
|
|
|
if (is_enable_port(this, user))
|
2018-06-16 23:44:35 +08:00
|
|
|
is_cen = true;
|
2018-06-16 23:09:41 +08:00
|
|
|
}
|
2018-06-25 17:43:59 +08:00
|
|
|
IdString glb_net = getWireName(getWireBelPin(bel, PIN_GLOBAL_BUFFER_OUTPUT));
|
|
|
|
int glb_id = std::stoi(std::string("") + glb_net.str(this).back());
|
2018-06-16 23:44:35 +08:00
|
|
|
if (is_reset && is_cen)
|
|
|
|
return false;
|
|
|
|
else if (is_reset)
|
2018-06-16 23:09:41 +08:00
|
|
|
return (glb_id % 2) == 0;
|
2018-06-16 23:44:35 +08:00
|
|
|
else if (is_cen)
|
|
|
|
return (glb_id % 2) == 1;
|
2018-06-16 23:09:41 +08:00
|
|
|
else
|
|
|
|
return true;
|
2018-06-12 19:40:22 +08:00
|
|
|
} else {
|
|
|
|
// TODO: IO cell clock checks
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2018-06-12 20:31:26 +08:00
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_END
|