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-14 01:57:55 +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-06-12 20:31:26 +08:00
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2018-07-14 18:10:31 +08:00
|
|
|
bool ArchReadMethods::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-14 01:57:55 +08:00
|
|
|
if (bool_or_default(cell->params, parent_->id_dff_en)) {
|
2018-06-12 19:40:22 +08:00
|
|
|
if (!dffs_exist) {
|
|
|
|
dffs_exist = true;
|
2018-07-14 01:57:55 +08:00
|
|
|
cen = get_net_or_empty(cell, parent_->id_cen);
|
|
|
|
clk = get_net_or_empty(cell, parent_->id_clk);
|
|
|
|
sr = get_net_or_empty(cell, parent_->id_sr);
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-07-14 01:57:55 +08:00
|
|
|
if (!parent_->isGlobalNet(cen) && cen != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-07-14 01:57:55 +08:00
|
|
|
if (!parent_->isGlobalNet(clk) && clk != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-07-14 01:57:55 +08:00
|
|
|
if (!parent_->isGlobalNet(sr) && sr != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-07-14 01:57:55 +08:00
|
|
|
if (bool_or_default(cell->params, parent_->id_neg_clk)) {
|
2018-06-12 19:40:22 +08:00
|
|
|
dffs_neg = true;
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-14 01:57:55 +08:00
|
|
|
if (cen != get_net_or_empty(cell, parent_->id_cen))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-07-14 01:57:55 +08:00
|
|
|
if (clk != get_net_or_empty(cell, parent_->id_clk))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-07-14 01:57:55 +08:00
|
|
|
if (sr != get_net_or_empty(cell, parent_->id_sr))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-07-14 01:57:55 +08:00
|
|
|
if (dffs_neg != bool_or_default(cell->params, parent_->id_neg_clk))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-14 01:57:55 +08:00
|
|
|
const NetInfo *i0 = get_net_or_empty(cell, parent_->id_i0), *i1 = get_net_or_empty(cell, parent_->id_i1),
|
|
|
|
*i2 = get_net_or_empty(cell, parent_->id_i2), *i3 = get_net_or_empty(cell, parent_->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-07-14 18:10:31 +08:00
|
|
|
bool ArchReadMethods::isBelLocationValid(BelId bel) const
|
2018-06-17 17:45:41 +08:00
|
|
|
{
|
2018-07-14 01:57:55 +08:00
|
|
|
if (parent_->getBelType(bel) == TYPE_ICESTORM_LC) {
|
2018-06-25 17:43:59 +08:00
|
|
|
std::vector<const CellInfo *> bel_cells;
|
2018-07-14 01:57:55 +08:00
|
|
|
for (auto bel_other : parent_->getBelsAtSameTile(bel)) {
|
|
|
|
IdString cell_other = getBoundBelCell(bel_other);
|
2018-06-17 00:45:32 +08:00
|
|
|
if (cell_other != IdString()) {
|
2018-07-14 01:57:55 +08:00
|
|
|
const CellInfo *ci_other = parent_->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-14 01:57:55 +08:00
|
|
|
IdString cellId = getBoundBelCell(bel);
|
2018-06-17 00:45:32 +08:00
|
|
|
if (cellId == IdString())
|
|
|
|
return true;
|
|
|
|
else
|
2018-07-14 01:57:55 +08:00
|
|
|
return isValidBelForCell(parent_->cells.at(cellId).get(), bel);
|
2018-06-17 00:45:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-14 18:10:31 +08:00
|
|
|
bool ArchReadMethods::isValidBelForCell(CellInfo *cell, BelId bel) const
|
2018-06-12 19:40:22 +08:00
|
|
|
{
|
2018-07-14 01:57:55 +08:00
|
|
|
if (cell->type == parent_->id_icestorm_lc) {
|
|
|
|
NPNR_ASSERT(parent_->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-14 01:57:55 +08:00
|
|
|
for (auto bel_other : parent_->getBelsAtSameTile(bel)) {
|
|
|
|
IdString cell_other = getBoundBelCell(bel_other);
|
2018-06-25 17:43:59 +08:00
|
|
|
if (cell_other != IdString() && bel_other != bel) {
|
2018-07-14 01:57:55 +08:00
|
|
|
const CellInfo *ci_other = parent_->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-14 01:57:55 +08:00
|
|
|
} else if (cell->type == parent_->id_sb_io) {
|
|
|
|
return parent_->getBelPackagePin(bel) != "";
|
|
|
|
} else if (cell->type == parent_->id_sb_gb) {
|
2018-06-16 23:09:41 +08:00
|
|
|
bool is_reset = false, is_cen = false;
|
2018-07-14 01:57:55 +08:00
|
|
|
NPNR_ASSERT(cell->ports.at(parent_->id_glb_buf_out).net != nullptr);
|
|
|
|
for (auto user : cell->ports.at(parent_->id_glb_buf_out).net->users) {
|
|
|
|
if (is_reset_port(parent_, user))
|
2018-06-16 23:09:41 +08:00
|
|
|
is_reset = true;
|
2018-07-14 01:57:55 +08:00
|
|
|
if (is_enable_port(parent_, user))
|
2018-06-16 23:44:35 +08:00
|
|
|
is_cen = true;
|
2018-06-16 23:09:41 +08:00
|
|
|
}
|
2018-07-14 01:57:55 +08:00
|
|
|
IdString glb_net = parent_->getWireName(getWireBelPin(bel, PIN_GLOBAL_BUFFER_OUTPUT));
|
|
|
|
int glb_id = std::stoi(std::string("") + glb_net.str(parent_).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
|