2018-06-12 19:40:22 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Clifford Wolf <clifford@clifford.at>
|
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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "arch_place.h"
|
2018-06-13 23:07:42 +08:00
|
|
|
#include "cells.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-17 22:03:16 +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-18 23:08:35 +08:00
|
|
|
static bool logicCellsCompatible(const Context *ctx,
|
|
|
|
const std::vector<const CellInfo *> &cells)
|
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-17 17:14:49 +08:00
|
|
|
if (bool_or_default(cell->params, "DFF_ENABLE")) {
|
2018-06-12 19:40:22 +08:00
|
|
|
if (!dffs_exist) {
|
|
|
|
dffs_exist = true;
|
2018-06-17 22:03:16 +08:00
|
|
|
cen = get_net_or_empty(cell, "CEN");
|
|
|
|
clk = get_net_or_empty(cell, "CLK");
|
|
|
|
sr = get_net_or_empty(cell, "SR");
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-06-18 23:08:35 +08:00
|
|
|
if (!is_global_net(ctx, cen) && cen != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-18 23:08:35 +08:00
|
|
|
if (!is_global_net(ctx, clk) && clk != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-18 23:08:35 +08:00
|
|
|
if (!is_global_net(ctx, sr) && sr != nullptr)
|
2018-06-19 19:35:01 +08:00
|
|
|
locals_count++;
|
2018-06-12 19:40:22 +08:00
|
|
|
|
2018-06-17 17:14:49 +08:00
|
|
|
if (bool_or_default(cell->params, "NEG_CLK")) {
|
2018-06-12 19:40:22 +08:00
|
|
|
dffs_neg = true;
|
|
|
|
}
|
|
|
|
} else {
|
2018-06-17 22:03:16 +08:00
|
|
|
if (cen != get_net_or_empty(cell, "CEN"))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-06-17 22:03:16 +08:00
|
|
|
if (clk != get_net_or_empty(cell, "CLK"))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-06-17 22:03:16 +08:00
|
|
|
if (sr != get_net_or_empty(cell, "SR"))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
2018-06-17 17:14:49 +08:00
|
|
|
if (dffs_neg != bool_or_default(cell->params, "NEG_CLK"))
|
2018-06-12 19:40:22 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-17 22:03:16 +08:00
|
|
|
const NetInfo *i0 = get_net_or_empty(cell, "I0"),
|
|
|
|
*i1 = get_net_or_empty(cell, "I1"),
|
|
|
|
*i2 = get_net_or_empty(cell, "I2"),
|
|
|
|
*i3 = get_net_or_empty(cell, "I3");
|
|
|
|
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-18 20:06:37 +08:00
|
|
|
bool isBelLocationValid(Context *ctx, BelId bel)
|
2018-06-17 17:45:41 +08:00
|
|
|
{
|
2018-06-18 20:06:37 +08:00
|
|
|
if (ctx->getBelType(bel) == TYPE_ICESTORM_LC) {
|
2018-06-17 00:45:32 +08:00
|
|
|
std::vector<const CellInfo *> cells;
|
2018-06-18 20:06:37 +08:00
|
|
|
for (auto bel_other : ctx->getBelsAtSameTile(bel)) {
|
|
|
|
IdString cell_other = ctx->getBelCell(bel_other, false);
|
2018-06-17 00:45:32 +08:00
|
|
|
if (cell_other != IdString()) {
|
2018-06-18 20:06:37 +08:00
|
|
|
const CellInfo *ci_other = ctx->cells[cell_other];
|
2018-06-17 00:45:32 +08:00
|
|
|
cells.push_back(ci_other);
|
|
|
|
}
|
|
|
|
}
|
2018-06-18 23:08:35 +08:00
|
|
|
return logicCellsCompatible(ctx, cells);
|
2018-06-17 00:45:32 +08:00
|
|
|
} else {
|
2018-06-18 20:06:37 +08:00
|
|
|
IdString cellId = ctx->getBelCell(bel, false);
|
2018-06-17 00:45:32 +08:00
|
|
|
if (cellId == IdString())
|
|
|
|
return true;
|
|
|
|
else
|
2018-06-18 20:06:37 +08:00
|
|
|
return isValidBelForCell(ctx, ctx->cells.at(cellId), bel);
|
2018-06-17 00:45:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
bool isValidBelForCell(Context *ctx, CellInfo *cell, BelId bel)
|
2018-06-12 19:40:22 +08:00
|
|
|
{
|
|
|
|
if (cell->type == "ICESTORM_LC") {
|
2018-06-18 20:06:37 +08:00
|
|
|
assert(ctx->getBelType(bel) == TYPE_ICESTORM_LC);
|
2018-06-12 19:40:22 +08:00
|
|
|
|
|
|
|
std::vector<const CellInfo *> cells;
|
|
|
|
|
2018-06-18 20:06:37 +08:00
|
|
|
for (auto bel_other : ctx->getBelsAtSameTile(bel)) {
|
|
|
|
IdString cell_other = ctx->getBelCell(bel_other, false);
|
2018-06-12 19:40:22 +08:00
|
|
|
if (cell_other != IdString()) {
|
2018-06-18 20:06:37 +08:00
|
|
|
const CellInfo *ci_other = ctx->cells[cell_other];
|
2018-06-12 19:40:22 +08:00
|
|
|
cells.push_back(ci_other);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cells.push_back(cell);
|
2018-06-18 23:08:35 +08:00
|
|
|
return logicCellsCompatible(ctx, cells);
|
2018-06-16 03:29:02 +08:00
|
|
|
} else if (cell->type == "SB_IO") {
|
2018-06-18 20:06:37 +08:00
|
|
|
return ctx->getBelPackagePin(bel) != "";
|
2018-06-16 23:09:41 +08:00
|
|
|
} else if (cell->type == "SB_GB") {
|
|
|
|
bool is_reset = false, is_cen = false;
|
|
|
|
assert(cell->ports.at("GLOBAL_BUFFER_OUTPUT").net != nullptr);
|
|
|
|
for (auto user : cell->ports.at("GLOBAL_BUFFER_OUTPUT").net->users) {
|
2018-06-18 23:08:35 +08:00
|
|
|
if (is_reset_port(ctx, user))
|
2018-06-16 23:09:41 +08:00
|
|
|
is_reset = true;
|
2018-06-18 23:08:35 +08:00
|
|
|
if (is_enable_port(ctx, user))
|
2018-06-16 23:44:35 +08:00
|
|
|
is_cen = true;
|
2018-06-16 23:09:41 +08:00
|
|
|
}
|
2018-06-18 20:06:37 +08:00
|
|
|
IdString glb_net = ctx->getWireName(
|
|
|
|
ctx->getWireBelPin(bel, PIN_GLOBAL_BUFFER_OUTPUT));
|
2018-06-16 23:09:41 +08:00
|
|
|
int glb_id = std::stoi(std::string("") + glb_net.str().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
|