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-07-15 01:52:56 +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-07-18 18:51:07 +08:00
|
|
|
NPNR_ASSERT(cell->belType == TYPE_ICESTORM_LC);
|
|
|
|
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-07-15 01:52:56 +08:00
|
|
|
if (getBelType(bel) == TYPE_ICESTORM_LC) {
|
2018-06-25 17:43:59 +08:00
|
|
|
std::vector<const CellInfo *> bel_cells;
|
2018-07-15 01:52:56 +08:00
|
|
|
for (auto bel_other : getBelsAtSameTile(bel)) {
|
2018-07-15 01:53:08 +08:00
|
|
|
IdString cell_other = getBoundBelCell(bel_other);
|
2018-06-17 00:45:32 +08:00
|
|
|
if (cell_other != IdString()) {
|
2018-07-15 01:52:56 +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-07-15 01:53:08 +08:00
|
|
|
IdString cellId = getBoundBelCell(bel);
|
2018-06-17 00:45:32 +08:00
|
|
|
if (cellId == IdString())
|
|
|
|
return true;
|
|
|
|
else
|
2018-07-15 01:52:56 +08:00
|
|
|
return isValidBelForCell(cells.at(cellId).get(), 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-07-15 01:52:56 +08:00
|
|
|
if (cell->type == id_icestorm_lc) {
|
|
|
|
NPNR_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-07-15 01:52:56 +08:00
|
|
|
for (auto bel_other : getBelsAtSameTile(bel)) {
|
2018-07-15 01:53:08 +08:00
|
|
|
IdString cell_other = getBoundBelCell(bel_other);
|
2018-06-25 17:43:59 +08:00
|
|
|
if (cell_other != IdString() && bel_other != bel) {
|
2018-07-15 01:52:56 +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-07-15 01:52:56 +08:00
|
|
|
} else if (cell->type == id_sb_io) {
|
|
|
|
return getBelPackagePin(bel) != "";
|
|
|
|
} else if (cell->type == id_sb_gb) {
|
|
|
|
NPNR_ASSERT(cell->ports.at(id_glb_buf_out).net != nullptr);
|
2018-07-20 17:36:32 +08:00
|
|
|
const NetInfo *net = cell->ports.at(id_glb_buf_out).net;
|
2018-07-22 16:59:21 +08:00
|
|
|
IdString glb_net = getWireName(getBelPinWire(bel, PIN_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
|