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-07-24 10:03:31 +08:00
|
|
|
* Copyright (C) 2018 Serge Bazanski <q3k@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-08-11 10:50:27 +08:00
|
|
|
#include <boost/range/iterator_range.hpp>
|
|
|
|
|
2018-06-12 20:31:26 +08:00
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2018-09-30 22:13:18 +08:00
|
|
|
bool Arch::logicCellsCompatible(const CellInfo **it, const size_t size) 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
|
|
|
|
2018-09-30 22:13:18 +08:00
|
|
|
for (auto cell : boost::make_iterator_range(it, it + size)) {
|
2018-09-24 21:27:50 +08:00
|
|
|
NPNR_ASSERT(cell->type == id_ICESTORM_LC);
|
2018-07-18 18:51:07 +08:00
|
|
|
if (cell->lcInfo.dffEnable) {
|
2018-06-12 19:40:22 +08:00
|
|
|
if (!dffs_exist) {
|
|
|
|
dffs_exist = true;
|
2018-07-18 18:51:07 +08:00
|
|
|
cen = cell->lcInfo.cen;
|
|
|
|
clk = cell->lcInfo.clk;
|
|
|
|
sr = cell->lcInfo.sr;
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-07-18 18:51:07 +08:00
|
|
|
if (cen != nullptr && !cen->is_global)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-07-18 18:51:07 +08:00
|
|
|
if (clk != nullptr && !clk->is_global)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-07-18 18:51:07 +08:00
|
|
|
if (sr != nullptr && !sr->is_global)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-07-18 18:51:07 +08:00
|
|
|
if (cell->lcInfo.negClk) {
|
2018-06-12 19:40:22 +08:00
|
|
|
dffs_neg = true;
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-18 18:51:07 +08:00
|
|
|
if (cen != cell->lcInfo.cen)
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-07-18 18:51:07 +08:00
|
|
|
if (clk != cell->lcInfo.clk)
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-07-18 18:51:07 +08:00
|
|
|
if (sr != cell->lcInfo.sr)
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-07-18 18:51:07 +08:00
|
|
|
if (dffs_neg != cell->lcInfo.negClk)
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 18:51:07 +08:00
|
|
|
locals_count += cell->lcInfo.inputCount;
|
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-07-15 01:52:56 +08:00
|
|
|
bool Arch::isBelLocationValid(BelId bel) const
|
2018-06-17 17:45:41 +08:00
|
|
|
{
|
2018-08-08 23:01:18 +08:00
|
|
|
if (getBelType(bel) == id_ICESTORM_LC) {
|
2018-08-11 10:50:27 +08:00
|
|
|
std::array<const CellInfo *, 8> bel_cells;
|
|
|
|
size_t num_cells = 0;
|
2018-07-24 21:52:56 +08:00
|
|
|
Loc bel_loc = getBelLocation(bel);
|
|
|
|
for (auto bel_other : getBelsByTile(bel_loc.x, bel_loc.y)) {
|
2018-08-05 21:25:42 +08:00
|
|
|
CellInfo *ci_other = getBoundBelCell(bel_other);
|
2018-08-11 10:50:27 +08:00
|
|
|
if (ci_other != nullptr)
|
|
|
|
bel_cells[num_cells++] = ci_other;
|
2018-06-17 00:45:32 +08:00
|
|
|
}
|
2018-08-11 10:50:27 +08:00
|
|
|
return logicCellsCompatible(bel_cells.data(), num_cells);
|
2018-06-17 00:45:32 +08:00
|
|
|
} else {
|
2018-08-05 21:25:42 +08:00
|
|
|
CellInfo *ci = getBoundBelCell(bel);
|
|
|
|
if (ci == nullptr)
|
2018-06-17 00:45:32 +08:00
|
|
|
return true;
|
|
|
|
else
|
2018-08-05 21:25:42 +08:00
|
|
|
return isValidBelForCell(ci, bel);
|
2018-06-17 00:45:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-15 01:52:56 +08:00
|
|
|
bool Arch::isValidBelForCell(CellInfo *cell, BelId bel) const
|
2018-06-12 19:40:22 +08:00
|
|
|
{
|
2018-08-08 23:17:16 +08:00
|
|
|
if (cell->type == id_ICESTORM_LC) {
|
2018-08-08 23:01:18 +08:00
|
|
|
NPNR_ASSERT(getBelType(bel) == id_ICESTORM_LC);
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-08-11 10:50:27 +08:00
|
|
|
std::array<const CellInfo *, 8> bel_cells;
|
|
|
|
size_t num_cells = 0;
|
|
|
|
|
2018-07-24 21:52:56 +08:00
|
|
|
Loc bel_loc = getBelLocation(bel);
|
|
|
|
for (auto bel_other : getBelsByTile(bel_loc.x, bel_loc.y)) {
|
2018-08-05 21:25:42 +08:00
|
|
|
CellInfo *ci_other = getBoundBelCell(bel_other);
|
2018-08-11 10:50:27 +08:00
|
|
|
if (ci_other != nullptr && bel_other != bel)
|
|
|
|
bel_cells[num_cells++] = ci_other;
|
2018-06-12 19:40:22 +08:00
|
|
|
}
|
|
|
|
|
2018-08-11 10:50:27 +08:00
|
|
|
bel_cells[num_cells++] = cell;
|
|
|
|
return logicCellsCompatible(bel_cells.data(), num_cells);
|
2018-08-08 23:17:16 +08:00
|
|
|
} else if (cell->type == id_SB_IO) {
|
2018-07-24 08:18:49 +08:00
|
|
|
// Do not allow placement of input SB_IOs on blocks where there a PLL is outputting to.
|
|
|
|
|
2018-07-24 09:35:16 +08:00
|
|
|
// Find shared PLL by looking for driving bel siblings from D_IN_0
|
|
|
|
// that are a PLL clock output.
|
2018-08-08 23:01:18 +08:00
|
|
|
auto wire = getBelPinWire(bel, id_D_IN_0);
|
|
|
|
IdString pll_bel_pin;
|
2018-07-24 09:35:16 +08:00
|
|
|
BelId pll_bel;
|
|
|
|
for (auto pin : getWireBelPins(wire)) {
|
2018-08-08 23:01:18 +08:00
|
|
|
if (pin.pin == id_PLLOUT_A || pin.pin == id_PLLOUT_B) {
|
2018-07-24 09:35:16 +08:00
|
|
|
pll_bel = pin.bel;
|
|
|
|
pll_bel_pin = pin.pin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Is there a PLL that shares this IO buffer?
|
|
|
|
if (pll_bel.index != -1) {
|
2018-07-25 18:57:10 +08:00
|
|
|
auto pll_cell = getBoundBelCell(pll_bel);
|
2018-07-24 09:35:16 +08:00
|
|
|
// Is a PLL placed in this PLL bel?
|
2018-08-05 21:25:42 +08:00
|
|
|
if (pll_cell != nullptr) {
|
2018-07-24 09:35:16 +08:00
|
|
|
// Is the shared port driving a net?
|
2018-08-08 23:01:18 +08:00
|
|
|
auto pi = pll_cell->ports[pll_bel_pin];
|
2018-07-24 09:35:16 +08:00
|
|
|
if (pi.net != nullptr) {
|
2018-07-25 18:32:21 +08:00
|
|
|
// Are we perhaps a PAD INPUT Bel that can be placed here?
|
2018-08-05 21:25:42 +08:00
|
|
|
if (pll_cell->attrs[id("BEL_PAD_INPUT")] == getBelName(bel).str(this)) {
|
2018-07-25 18:32:21 +08:00
|
|
|
return true;
|
|
|
|
}
|
2018-07-24 09:35:16 +08:00
|
|
|
return false;
|
2018-07-24 08:18:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-24 22:14:28 +08:00
|
|
|
Loc ioLoc = getBelLocation(bel);
|
|
|
|
Loc compLoc = ioLoc;
|
|
|
|
compLoc.z = 1 - compLoc.z;
|
|
|
|
|
|
|
|
// Check LVDS pairing
|
|
|
|
if (cell->ioInfo.lvds) {
|
|
|
|
// Check correct z and complement location is free
|
|
|
|
if (ioLoc.z != 0)
|
|
|
|
return false;
|
|
|
|
BelId compBel = getBelByLocation(compLoc);
|
|
|
|
CellInfo *compCell = getBoundBelCell(compBel);
|
|
|
|
if (compCell)
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Check LVDS IO is not placed at complement location
|
|
|
|
BelId compBel = getBelByLocation(compLoc);
|
|
|
|
CellInfo *compCell = getBoundBelCell(compBel);
|
|
|
|
if (compCell && compCell->ioInfo.lvds)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-15 01:52:56 +08:00
|
|
|
return getBelPackagePin(bel) != "";
|
2018-08-08 23:17:16 +08:00
|
|
|
} else if (cell->type == id_SB_GB) {
|
|
|
|
NPNR_ASSERT(cell->ports.at(id_GLOBAL_BUFFER_OUTPUT).net != nullptr);
|
|
|
|
const NetInfo *net = cell->ports.at(id_GLOBAL_BUFFER_OUTPUT).net;
|
2018-08-08 23:01:18 +08:00
|
|
|
IdString glb_net = getWireName(getBelPinWire(bel, id_GLOBAL_BUFFER_OUTPUT));
|
2018-07-15 01:52:56 +08:00
|
|
|
int glb_id = std::stoi(std::string("") + glb_net.str(this).back());
|
2018-07-20 17:36:32 +08:00
|
|
|
if (net->is_reset && net->is_enable)
|
2018-06-16 23:44:35 +08:00
|
|
|
return false;
|
2018-07-20 17:36:32 +08:00
|
|
|
else if (net->is_reset)
|
2018-06-16 23:09:41 +08:00
|
|
|
return (glb_id % 2) == 0;
|
2018-07-20 17:36:32 +08:00
|
|
|
else if (net->is_enable)
|
2018-06-16 23:44:35 +08:00
|
|
|
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
|