2021-02-11 19:10:32 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
2021-06-09 20:09:08 +08:00
|
|
|
* Copyright (C) 2018 Claire Xenia Wolf <claire@yosyshq.com>
|
2021-01-31 07:06:55 +08:00
|
|
|
* Copyright (C) 2021 William D. Jones <wjones@wdj-consulting.com>
|
2021-02-11 19:10:32 +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 <iostream>
|
|
|
|
#include <math.h>
|
2020-06-28 07:22:58 +08:00
|
|
|
#include "embed.h"
|
2023-03-08 19:17:37 +08:00
|
|
|
#include "gfx.h"
|
2023-03-17 16:31:38 +08:00
|
|
|
#include "machxo2_available.h"
|
2020-12-08 07:56:27 +08:00
|
|
|
#include "nextpnr.h"
|
2021-02-11 19:10:32 +08:00
|
|
|
#include "placer1.h"
|
|
|
|
#include "placer_heap.h"
|
|
|
|
#include "router1.h"
|
|
|
|
#include "router2.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2020-06-28 07:22:58 +08:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2020-12-08 07:56:27 +08:00
|
|
|
void IdString::initialize_arch(const BaseCtx *ctx)
|
|
|
|
{
|
|
|
|
#define X(t) initialize_add(ctx, #t, ID_##t);
|
2020-06-28 07:22:58 +08:00
|
|
|
|
2020-12-08 07:56:27 +08:00
|
|
|
#include "constids.inc"
|
2020-06-28 07:22:58 +08:00
|
|
|
|
2020-12-08 07:56:27 +08:00
|
|
|
#undef X
|
2020-06-28 07:22:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
2023-03-17 16:31:38 +08:00
|
|
|
static void get_chip_info(std::string device, const ChipInfoPOD **chip_info, const PackageInfoPOD **package_info,
|
|
|
|
const char **device_name, const char **package_name)
|
2020-06-28 07:22:58 +08:00
|
|
|
{
|
2023-03-09 18:04:38 +08:00
|
|
|
std::stringstream ss(available_devices);
|
|
|
|
std::string name;
|
2023-03-17 16:31:38 +08:00
|
|
|
while (getline(ss, name, ';')) {
|
2023-03-09 18:04:38 +08:00
|
|
|
std::string chipdb = stringf("machxo2/chipdb-%s.bin", name.c_str());
|
|
|
|
auto db_ptr = reinterpret_cast<const RelPtr<ChipInfoPOD> *>(get_chipdb(chipdb));
|
|
|
|
if (!db_ptr)
|
|
|
|
continue; // chipdb not available
|
|
|
|
for (auto &chip : db_ptr->get()->variants) {
|
|
|
|
for (auto &pkg : chip.packages) {
|
|
|
|
for (auto &speedgrade : chip.speed_grades) {
|
|
|
|
for (auto &rating : chip.suffixes) {
|
2023-03-17 16:31:38 +08:00
|
|
|
std::string devname = stringf("%s-%d%s%s", chip.name.get(), speedgrade.speed,
|
|
|
|
pkg.short_name.get(), rating.suffix.get());
|
2023-03-09 18:34:15 +08:00
|
|
|
if (device == devname) {
|
2023-03-09 18:04:38 +08:00
|
|
|
*chip_info = db_ptr->get();
|
|
|
|
*package_info = nullptr;
|
|
|
|
*package_name = pkg.name.get();
|
|
|
|
*device_name = chip.name.get();
|
2023-03-18 01:58:04 +08:00
|
|
|
for (auto &pi : db_ptr->get()->package_info) {
|
|
|
|
if (pkg.name.get() == pi.name.get()) {
|
|
|
|
*package_info = π
|
2023-03-09 18:04:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-28 07:22:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-05 13:38:00 +08:00
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
Arch::Arch(ArchArgs args) : args(args)
|
|
|
|
{
|
2023-03-09 18:04:38 +08:00
|
|
|
get_chip_info(args.device, &chip_info, &package_info, &device_name, &package_name);
|
2020-12-05 13:38:00 +08:00
|
|
|
if (chip_info == nullptr)
|
|
|
|
log_error("Unsupported MachXO2 chip type.\n");
|
|
|
|
if (chip_info->const_id_count != DB_CONST_ID_COUNT)
|
|
|
|
log_error("Chip database 'bba' and nextpnr code are out of sync; please rebuild (or contact distribution "
|
|
|
|
"maintainer)!\n");
|
|
|
|
|
|
|
|
if (!package_info)
|
2023-03-09 18:04:38 +08:00
|
|
|
log_error("Unsupported package '%s' for '%s'.\n", package_name, getChipName().c_str());
|
2020-12-07 15:15:51 +08:00
|
|
|
|
2023-03-28 01:40:55 +08:00
|
|
|
tile_status.resize(chip_info->num_tiles);
|
|
|
|
for (int i = 0; i < chip_info->num_tiles; i++) {
|
|
|
|
auto &ts = tile_status.at(i);
|
|
|
|
auto &tile_data = chip_info->tile_info[i];
|
|
|
|
ts.boundcells.resize(chip_info->tiles[i].bel_data.size(), nullptr);
|
|
|
|
for (auto &name : tile_data.tile_names) {
|
2023-03-30 19:17:37 +08:00
|
|
|
if (strcmp(chip_info->tiletype_names[name.type_idx].get(), "PLC") == 0) {
|
2023-03-28 01:40:55 +08:00
|
|
|
// Is a logic tile
|
|
|
|
ts.lts = new LogicTileStatus();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-11 19:34:08 +08:00
|
|
|
BaseArch::init_cell_types();
|
|
|
|
BaseArch::init_bel_buckets();
|
2021-02-11 20:46:31 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < chip_info->width; i++)
|
2022-08-10 17:57:17 +08:00
|
|
|
x_ids.push_back(idf("X%d", i));
|
2021-02-11 20:46:31 +08:00
|
|
|
for (int i = 0; i < chip_info->height; i++)
|
2022-08-10 17:57:17 +08:00
|
|
|
y_ids.push_back(idf("Y%d", i));
|
2021-02-11 20:46:31 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < chip_info->width; i++) {
|
2022-08-10 17:57:17 +08:00
|
|
|
IdString x_id = idf("X%d", i);
|
2021-02-11 20:46:31 +08:00
|
|
|
x_ids.push_back(x_id);
|
|
|
|
id_to_x[x_id] = i;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < chip_info->height; i++) {
|
2022-08-10 17:57:17 +08:00
|
|
|
IdString y_id = idf("Y%d", i);
|
2021-02-11 20:46:31 +08:00
|
|
|
y_ids.push_back(y_id);
|
|
|
|
id_to_y[y_id] = i;
|
|
|
|
}
|
2023-03-30 21:24:53 +08:00
|
|
|
|
|
|
|
wire_tile_vecidx.resize(chip_info->num_tiles, -1);
|
|
|
|
int n_wires = 0;
|
|
|
|
for (auto e : getWires()) {
|
|
|
|
if (e.index == 0) {
|
|
|
|
wire_tile_vecidx.at(e.location.y * chip_info->width + e.location.x) = n_wires;
|
|
|
|
}
|
|
|
|
n_wires++;
|
|
|
|
}
|
|
|
|
wire2net.resize(n_wires, nullptr);
|
|
|
|
wire_fanout.resize(n_wires, 0);
|
|
|
|
|
|
|
|
pip_tile_vecidx.resize(chip_info->num_tiles, -1);
|
|
|
|
int n_pips = 0;
|
|
|
|
for (auto e : getPips()) {
|
|
|
|
if (e.index == 0) {
|
|
|
|
pip_tile_vecidx.at(e.location.y * chip_info->width + e.location.x) = n_pips;
|
|
|
|
}
|
|
|
|
n_pips++;
|
|
|
|
}
|
|
|
|
pip2net.resize(n_pips, nullptr);
|
|
|
|
|
|
|
|
lutperm_allowed.resize(chip_info->width * chip_info->height * 4);
|
2020-12-05 13:38:00 +08:00
|
|
|
}
|
|
|
|
|
2023-03-09 18:04:38 +08:00
|
|
|
void Arch::list_devices()
|
2020-12-05 13:38:00 +08:00
|
|
|
{
|
2023-03-09 18:04:38 +08:00
|
|
|
log("Supported devices: \n");
|
|
|
|
std::stringstream ss(available_devices);
|
|
|
|
std::string name;
|
2023-03-17 16:31:38 +08:00
|
|
|
while (getline(ss, name, ';')) {
|
2023-03-09 18:04:38 +08:00
|
|
|
std::string chipdb = stringf("machxo2/chipdb-%s.bin", name.c_str());
|
|
|
|
auto db_ptr = reinterpret_cast<const RelPtr<ChipInfoPOD> *>(get_chipdb(chipdb));
|
|
|
|
if (!db_ptr)
|
|
|
|
continue; // chipdb not available
|
|
|
|
for (auto &chip : db_ptr->get()->variants) {
|
|
|
|
for (auto &pkg : chip.packages) {
|
|
|
|
for (auto &speedgrade : chip.speed_grades) {
|
|
|
|
for (auto &rating : chip.suffixes) {
|
2023-03-17 16:31:38 +08:00
|
|
|
log(" %s-%d%s%s\n", chip.name.get(), speedgrade.speed, pkg.short_name.get(),
|
|
|
|
rating.suffix.get());
|
2023-03-09 18:04:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-31 11:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-09 18:04:38 +08:00
|
|
|
// -----------------------------------------------------------------------
|
2020-12-07 11:06:24 +08:00
|
|
|
|
2023-03-09 18:04:38 +08:00
|
|
|
std::string Arch::getChipName() const { return args.device; }
|
|
|
|
IdString Arch::archArgsToId(ArchArgs args) const { return id(args.device); }
|
2020-12-07 11:06:24 +08:00
|
|
|
|
2021-02-11 19:10:32 +08:00
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
2021-02-11 19:34:08 +08:00
|
|
|
BelId Arch::getBelByName(IdStringList name) const
|
2021-02-11 19:10:32 +08:00
|
|
|
{
|
2021-02-11 20:46:31 +08:00
|
|
|
if (name.size() != 3)
|
|
|
|
return BelId();
|
2020-12-08 00:48:15 +08:00
|
|
|
BelId ret;
|
|
|
|
Location loc;
|
2021-02-11 20:46:31 +08:00
|
|
|
loc.x = id_to_x.at(name[0]);
|
|
|
|
loc.y = id_to_y.at(name[1]);
|
2020-12-08 00:48:15 +08:00
|
|
|
ret.location = loc;
|
2021-02-11 21:46:29 +08:00
|
|
|
const TileTypePOD *loci = tile_info(ret);
|
2023-03-18 01:58:04 +08:00
|
|
|
for (int i = 0; i < loci->bel_data.ssize(); i++) {
|
2021-02-11 20:46:31 +08:00
|
|
|
if (std::strcmp(loci->bel_data[i].name.get(), name[2].c_str(this)) == 0) {
|
2020-12-08 00:48:15 +08:00
|
|
|
ret.index = i;
|
2021-02-11 20:46:31 +08:00
|
|
|
return ret;
|
2020-12-08 00:48:15 +08:00
|
|
|
}
|
|
|
|
}
|
2021-02-11 20:46:31 +08:00
|
|
|
return BelId();
|
2021-02-11 19:10:32 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 00:48:15 +08:00
|
|
|
BelRange Arch::getBelsByTile(int x, int y) const
|
2021-02-11 19:10:32 +08:00
|
|
|
{
|
2020-12-08 00:48:15 +08:00
|
|
|
BelRange br;
|
|
|
|
|
|
|
|
br.b.cursor_tile = y * chip_info->width + x;
|
|
|
|
br.e.cursor_tile = y * chip_info->width + x;
|
|
|
|
br.b.cursor_index = 0;
|
2023-03-18 01:58:04 +08:00
|
|
|
br.e.cursor_index = chip_info->tiles[y * chip_info->width + x].bel_data.ssize() - 1;
|
2020-12-08 00:48:15 +08:00
|
|
|
br.b.chip = chip_info;
|
|
|
|
br.e.chip = chip_info;
|
|
|
|
if (br.e.cursor_index == -1)
|
|
|
|
++br.e.cursor_index;
|
|
|
|
else
|
|
|
|
++br.e;
|
|
|
|
return br;
|
2021-02-11 19:10:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
WireId Arch::getBelPinWire(BelId bel, IdString pin) const
|
|
|
|
{
|
2023-03-31 00:18:52 +08:00
|
|
|
WireId ret;
|
|
|
|
|
2020-12-08 06:41:34 +08:00
|
|
|
NPNR_ASSERT(bel != BelId());
|
|
|
|
|
2023-03-18 01:58:04 +08:00
|
|
|
for (auto &bw : tile_info(bel)->bel_data[bel.index].bel_wires)
|
|
|
|
if (bw.port == pin.index) {
|
|
|
|
ret.location.x = bw.rel_wire_loc.x;
|
|
|
|
ret.location.y = bw.rel_wire_loc.y;
|
|
|
|
ret.index = bw.wire_index;
|
2023-03-31 00:18:52 +08:00
|
|
|
break;
|
2020-12-08 06:41:34 +08:00
|
|
|
}
|
|
|
|
|
2023-03-31 00:18:52 +08:00
|
|
|
return ret;
|
2021-02-11 19:10:32 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 00:48:15 +08:00
|
|
|
PortType Arch::getBelPinType(BelId bel, IdString pin) const
|
|
|
|
{
|
|
|
|
NPNR_ASSERT(bel != BelId());
|
|
|
|
|
2023-03-18 01:58:04 +08:00
|
|
|
for (auto &bw : tile_info(bel)->bel_data[bel.index].bel_wires)
|
|
|
|
if (bw.port == pin.index)
|
|
|
|
return PortType(bw.type);
|
2020-12-08 00:48:15 +08:00
|
|
|
|
|
|
|
return PORT_INOUT;
|
|
|
|
}
|
2021-02-11 19:10:32 +08:00
|
|
|
|
2020-12-08 14:42:58 +08:00
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
2021-02-11 19:34:08 +08:00
|
|
|
WireId Arch::getWireByName(IdStringList name) const
|
2021-01-27 14:46:32 +08:00
|
|
|
{
|
2021-02-11 20:46:31 +08:00
|
|
|
if (name.size() != 3)
|
|
|
|
return WireId();
|
2021-01-27 14:46:32 +08:00
|
|
|
WireId ret;
|
|
|
|
Location loc;
|
2021-02-11 20:46:31 +08:00
|
|
|
loc.x = id_to_x.at(name[0]);
|
|
|
|
loc.y = id_to_y.at(name[1]);
|
2021-01-27 14:46:32 +08:00
|
|
|
ret.location = loc;
|
2021-02-11 21:46:29 +08:00
|
|
|
const TileTypePOD *loci = tile_info(ret);
|
2023-03-18 01:58:04 +08:00
|
|
|
for (int i = 0; i < loci->wire_data.ssize(); i++) {
|
2021-02-11 20:46:31 +08:00
|
|
|
if (std::strcmp(loci->wire_data[i].name.get(), name[2].c_str(this)) == 0) {
|
2021-01-27 14:46:32 +08:00
|
|
|
ret.index = i;
|
2021-02-11 20:46:31 +08:00
|
|
|
return ret;
|
2021-01-27 14:46:32 +08:00
|
|
|
}
|
|
|
|
}
|
2021-02-11 20:46:31 +08:00
|
|
|
return WireId();
|
2021-01-27 14:46:32 +08:00
|
|
|
}
|
2021-02-11 19:10:32 +08:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
2021-02-11 19:34:08 +08:00
|
|
|
PipId Arch::getPipByName(IdStringList name) const
|
2021-01-27 14:46:32 +08:00
|
|
|
{
|
2021-02-11 20:46:31 +08:00
|
|
|
if (name.size() != 3)
|
|
|
|
return PipId();
|
|
|
|
auto it = pip_by_name.find(name);
|
2021-01-27 14:46:32 +08:00
|
|
|
if (it != pip_by_name.end())
|
|
|
|
return it->second;
|
2021-02-11 19:10:32 +08:00
|
|
|
|
2021-02-11 20:46:31 +08:00
|
|
|
PipId ret;
|
2021-01-27 14:46:32 +08:00
|
|
|
Location loc;
|
|
|
|
std::string basename;
|
2021-02-11 20:46:31 +08:00
|
|
|
loc.x = id_to_x.at(name[0]);
|
|
|
|
loc.y = id_to_y.at(name[1]);
|
2021-01-27 14:46:32 +08:00
|
|
|
ret.location = loc;
|
2021-02-11 21:46:29 +08:00
|
|
|
const TileTypePOD *loci = tile_info(ret);
|
2023-03-18 01:58:04 +08:00
|
|
|
for (int i = 0; i < loci->pip_data.ssize(); i++) {
|
2021-01-27 14:46:32 +08:00
|
|
|
PipId curr;
|
|
|
|
curr.location = loc;
|
|
|
|
curr.index = i;
|
2021-02-11 20:46:31 +08:00
|
|
|
pip_by_name[getPipName(curr)] = curr;
|
2021-01-27 14:46:32 +08:00
|
|
|
}
|
2021-02-11 20:46:31 +08:00
|
|
|
if (pip_by_name.find(name) == pip_by_name.end())
|
|
|
|
NPNR_ASSERT_FALSE_STR("no pip named " + name.str(getCtx()));
|
|
|
|
return pip_by_name[name];
|
2021-01-27 14:46:32 +08:00
|
|
|
}
|
|
|
|
|
2021-02-11 19:34:08 +08:00
|
|
|
IdStringList Arch::getPipName(PipId pip) const
|
2021-01-27 14:46:32 +08:00
|
|
|
{
|
2023-03-18 01:58:04 +08:00
|
|
|
auto &pip_data = tile_info(pip)->pip_data[pip.index];
|
2021-02-11 20:46:31 +08:00
|
|
|
WireId src = getPipSrcWire(pip), dst = getPipDstWire(pip);
|
2023-04-11 16:05:33 +08:00
|
|
|
std::string pip_name =
|
|
|
|
stringf("%d_%d_%s->%d_%d_%s", pip_data.src.x, pip_data.src.y, get_wire_basename(src).c_str(this),
|
|
|
|
pip_data.dst.x, pip_data.dst.y, get_wire_basename(dst).c_str(this));
|
2021-02-11 20:46:31 +08:00
|
|
|
|
|
|
|
std::array<IdString, 3> ids{x_ids.at(pip.location.x), y_ids.at(pip.location.y), id(pip_name)};
|
|
|
|
return IdStringList(ids);
|
2021-02-11 19:10:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
2023-03-31 00:18:52 +08:00
|
|
|
BelId Arch::get_package_pin_bel(const std::string &pin) const
|
|
|
|
{
|
|
|
|
for (auto &ppin : package_info->pin_data) {
|
|
|
|
if (ppin.name.get() == pin) {
|
|
|
|
BelId bel;
|
|
|
|
bel.location = ppin.abs_loc;
|
|
|
|
bel.index = ppin.bel_index;
|
|
|
|
return bel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return BelId();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<IdString> Arch::getBelPins(BelId bel) const
|
|
|
|
{
|
|
|
|
std::vector<IdString> ret;
|
|
|
|
NPNR_ASSERT(bel != BelId());
|
|
|
|
|
|
|
|
for (auto &bw : tile_info(bel)->bel_data[bel.index].bel_wires) {
|
|
|
|
IdString id;
|
|
|
|
id.index = bw.port;
|
|
|
|
ret.push_back(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BelId Arch::getBelByLocation(Loc loc) const
|
|
|
|
{
|
|
|
|
BelId ret;
|
|
|
|
|
|
|
|
if (loc.x >= chip_info->width || loc.y >= chip_info->height)
|
|
|
|
return BelId();
|
|
|
|
|
|
|
|
ret.location.x = loc.x;
|
|
|
|
ret.location.y = loc.y;
|
|
|
|
|
|
|
|
const TileTypePOD *loci = tile_info(ret);
|
|
|
|
for (int i = 0; i < loci->bel_data.ssize(); i++) {
|
|
|
|
if (loci->bel_data[i].z == loc.z) {
|
|
|
|
ret.index = i;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return BelId();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
2021-01-31 01:39:57 +08:00
|
|
|
delay_t Arch::estimateDelay(WireId src, WireId dst) const
|
|
|
|
{
|
|
|
|
// Taxicab distance multiplied by pipDelay (0.01) and fake wireDelay (0.01).
|
|
|
|
// TODO: This function will not work well for entrance to global routing,
|
|
|
|
// as the entrances are located physically far from the DCCAs.
|
|
|
|
return (abs(dst.location.x - src.location.x) + abs(dst.location.y - src.location.y)) * (0.01 + 0.01);
|
|
|
|
}
|
|
|
|
|
2023-03-31 00:18:52 +08:00
|
|
|
BoundingBox Arch::getRouteBoundingBox(WireId src, WireId dst) const
|
|
|
|
{
|
|
|
|
BoundingBox bb;
|
|
|
|
bb.x0 = std::min(src.location.x, dst.location.x);
|
|
|
|
bb.y0 = std::min(src.location.y, dst.location.y);
|
|
|
|
bb.x1 = std::max(src.location.x, dst.location.x);
|
|
|
|
bb.y1 = std::max(src.location.y, dst.location.y);
|
|
|
|
return bb;
|
|
|
|
}
|
|
|
|
|
2021-12-20 00:41:34 +08:00
|
|
|
delay_t Arch::predictDelay(BelId src_bel, IdString src_pin, BelId dst_bel, IdString dst_pin) const
|
2021-01-31 01:39:57 +08:00
|
|
|
{
|
2021-12-20 00:41:34 +08:00
|
|
|
NPNR_UNUSED(src_pin);
|
|
|
|
NPNR_UNUSED(dst_pin);
|
2021-01-31 01:39:57 +08:00
|
|
|
|
2021-12-20 00:41:34 +08:00
|
|
|
NPNR_ASSERT(src_bel != BelId());
|
|
|
|
NPNR_ASSERT(dst_bel != BelId());
|
2021-02-11 19:10:32 +08:00
|
|
|
|
2021-01-31 01:39:57 +08:00
|
|
|
// TODO: Same deal applies here as with estimateDelay.
|
2021-12-20 00:41:34 +08:00
|
|
|
return (abs(dst_bel.location.x - src_bel.location.x) + abs(dst_bel.location.y - src_bel.location.y)) *
|
|
|
|
(0.01 + 0.01);
|
2021-01-31 01:39:57 +08:00
|
|
|
}
|
2021-02-11 19:10:32 +08:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
bool Arch::place()
|
|
|
|
{
|
2022-02-17 01:09:54 +08:00
|
|
|
std::string placer = str_or_default(settings, id_placer, defaultPlacer);
|
2020-06-28 08:22:00 +08:00
|
|
|
if (placer == "sa") {
|
2021-02-11 19:10:32 +08:00
|
|
|
bool retVal = placer1(getCtx(), Placer1Cfg(getCtx()));
|
2022-02-17 01:09:54 +08:00
|
|
|
getCtx()->settings[id_place] = 1;
|
2021-02-11 19:10:32 +08:00
|
|
|
archInfoToAttributes();
|
|
|
|
return retVal;
|
2021-02-11 19:34:08 +08:00
|
|
|
} else if (placer == "heap") {
|
|
|
|
PlacerHeapCfg cfg(getCtx());
|
2023-03-18 02:00:05 +08:00
|
|
|
cfg.ioBufTypes.insert(id_TRELLIS_IO);
|
2021-02-11 19:34:08 +08:00
|
|
|
bool retVal = placer_heap(getCtx(), cfg);
|
2022-02-17 01:09:54 +08:00
|
|
|
getCtx()->settings[id_place] = 1;
|
2021-02-11 19:34:08 +08:00
|
|
|
archInfoToAttributes();
|
|
|
|
return retVal;
|
2021-02-11 19:10:32 +08:00
|
|
|
} else {
|
2020-06-28 08:22:00 +08:00
|
|
|
log_error("MachXO2 architecture does not support placer '%s'\n", placer.c_str());
|
2021-02-11 19:10:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Arch::route()
|
|
|
|
{
|
2022-02-17 01:09:54 +08:00
|
|
|
std::string router = str_or_default(settings, id_router, defaultRouter);
|
2023-03-30 21:24:53 +08:00
|
|
|
|
|
|
|
disable_router_lutperm = getCtx()->setting<bool>("arch.disable_router_lutperm", false);
|
|
|
|
|
2021-02-11 19:10:32 +08:00
|
|
|
bool result;
|
|
|
|
if (router == "router1") {
|
|
|
|
result = router1(getCtx(), Router1Cfg(getCtx()));
|
|
|
|
} else if (router == "router2") {
|
|
|
|
router2(getCtx(), Router2Cfg(getCtx()));
|
|
|
|
result = true;
|
|
|
|
} else {
|
2020-06-28 08:22:00 +08:00
|
|
|
log_error("MachXO2 architecture does not support router '%s'\n", router.c_str());
|
2021-02-11 19:10:32 +08:00
|
|
|
}
|
2022-02-17 01:09:54 +08:00
|
|
|
getCtx()->settings[id_route] = 1;
|
2021-02-11 19:10:32 +08:00
|
|
|
archInfoToAttributes();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-03-08 19:17:37 +08:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
std::vector<GraphicElement> Arch::getDecalGraphics(DecalId decal) const
|
|
|
|
{
|
|
|
|
std::vector<GraphicElement> ret;
|
|
|
|
if (decal.type == DecalId::TYPE_WIRE) {
|
|
|
|
WireId wire;
|
|
|
|
wire.index = decal.z;
|
|
|
|
wire.location = decal.location;
|
|
|
|
auto wire_type = getWireType(wire);
|
|
|
|
int x = decal.location.x;
|
|
|
|
int y = decal.location.y;
|
|
|
|
GraphicElement::style_t style = decal.active ? GraphicElement::STYLE_ACTIVE : GraphicElement::STYLE_INACTIVE;
|
|
|
|
GfxTileWireId tilewire = GfxTileWireId(tile_info(wire)->wire_data[wire.index].tile_wire);
|
2023-03-13 19:45:12 +08:00
|
|
|
gfxTileWire(ret, x, chip_info->height - y - 1, chip_info->width, chip_info->height, wire_type, tilewire, style);
|
2023-03-08 19:17:37 +08:00
|
|
|
} else if (decal.type == DecalId::TYPE_PIP) {
|
|
|
|
PipId pip;
|
|
|
|
pip.index = decal.z;
|
|
|
|
pip.location = decal.location;
|
|
|
|
WireId src_wire = getPipSrcWire(pip);
|
|
|
|
WireId dst_wire = getPipDstWire(pip);
|
|
|
|
int x = decal.location.x;
|
|
|
|
int y = decal.location.y;
|
|
|
|
GfxTileWireId src_id = GfxTileWireId(tile_info(src_wire)->wire_data[src_wire.index].tile_wire);
|
|
|
|
GfxTileWireId dst_id = GfxTileWireId(tile_info(dst_wire)->wire_data[dst_wire.index].tile_wire);
|
|
|
|
GraphicElement::style_t style = decal.active ? GraphicElement::STYLE_ACTIVE : GraphicElement::STYLE_HIDDEN;
|
2023-03-17 16:31:38 +08:00
|
|
|
gfxTilePip(ret, x, chip_info->height - y - 1, chip_info->width, chip_info->height, src_wire,
|
|
|
|
getWireType(src_wire), src_id, dst_wire, getWireType(dst_wire), dst_id, style);
|
2023-03-08 19:17:37 +08:00
|
|
|
} else if (decal.type == DecalId::TYPE_BEL) {
|
|
|
|
BelId bel;
|
|
|
|
bel.index = decal.z;
|
|
|
|
bel.location = decal.location;
|
|
|
|
auto bel_type = getBelType(bel);
|
|
|
|
int x = decal.location.x;
|
|
|
|
int y = decal.location.y;
|
|
|
|
int z = tile_info(bel)->bel_data[bel.index].z;
|
|
|
|
GraphicElement::style_t style = decal.active ? GraphicElement::STYLE_ACTIVE : GraphicElement::STYLE_INACTIVE;
|
2023-03-13 19:45:12 +08:00
|
|
|
gfxTileBel(ret, x, chip_info->height - y - 1, z, chip_info->width, chip_info->height, bel_type, style);
|
2023-03-08 19:17:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecalXY Arch::getBelDecal(BelId bel) const
|
|
|
|
{
|
|
|
|
DecalXY decalxy;
|
|
|
|
decalxy.decal.type = DecalId::TYPE_BEL;
|
|
|
|
decalxy.decal.location = bel.location;
|
|
|
|
decalxy.decal.z = bel.index;
|
|
|
|
decalxy.decal.active = getBoundBelCell(bel) != nullptr;
|
|
|
|
return decalxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecalXY Arch::getWireDecal(WireId wire) const
|
|
|
|
{
|
|
|
|
DecalXY decalxy;
|
|
|
|
decalxy.decal.type = DecalId::TYPE_WIRE;
|
|
|
|
decalxy.decal.location = wire.location;
|
|
|
|
decalxy.decal.z = wire.index;
|
|
|
|
decalxy.decal.active = getBoundWireNet(wire) != nullptr;
|
|
|
|
return decalxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecalXY Arch::getPipDecal(PipId pip) const
|
|
|
|
{
|
|
|
|
DecalXY decalxy;
|
|
|
|
decalxy.decal.type = DecalId::TYPE_PIP;
|
|
|
|
decalxy.decal.location = pip.location;
|
|
|
|
decalxy.decal.z = pip.index;
|
|
|
|
decalxy.decal.active = getBoundPipNet(pip) != nullptr;
|
|
|
|
return decalxy;
|
|
|
|
};
|
|
|
|
|
2023-03-31 00:18:52 +08:00
|
|
|
DecalXY Arch::getGroupDecal(GroupId group) const
|
|
|
|
{
|
|
|
|
DecalXY decalxy;
|
|
|
|
decalxy.decal.type = DecalId::TYPE_GROUP;
|
|
|
|
decalxy.decal.location = group.location;
|
|
|
|
decalxy.decal.z = group.type;
|
|
|
|
decalxy.decal.active = true;
|
|
|
|
return decalxy;
|
|
|
|
}
|
|
|
|
|
2021-02-11 19:10:32 +08:00
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
const std::string Arch::defaultPlacer = "heap";
|
2023-03-17 16:27:36 +08:00
|
|
|
|
|
|
|
const std::vector<std::string> Arch::availablePlacers = {"sa", "heap"};
|
2021-02-11 19:10:32 +08:00
|
|
|
|
|
|
|
const std::string Arch::defaultRouter = "router1";
|
|
|
|
const std::vector<std::string> Arch::availableRouters = {"router1", "router2"};
|
|
|
|
|
2023-03-18 01:58:04 +08:00
|
|
|
std::vector<std::pair<std::string, std::string>> Arch::get_tiles_at_loc(int row, int col)
|
2021-01-31 12:14:48 +08:00
|
|
|
{
|
|
|
|
std::vector<std::pair<std::string, std::string>> ret;
|
|
|
|
auto &tileloc = chip_info->tile_info[row * chip_info->width + col];
|
2023-03-18 01:58:04 +08:00
|
|
|
for (auto &tn : tileloc.tile_names) {
|
2023-04-11 16:05:33 +08:00
|
|
|
ret.push_back(std::make_pair(tn.name.get(), chip_info->tiletype_names[tn.type_idx].get()));
|
2021-01-31 12:14:48 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-30 21:24:53 +08:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2023-03-31 00:18:52 +08:00
|
|
|
GroupId Arch::getGroupByName(IdStringList name) const
|
|
|
|
{
|
|
|
|
for (auto g : getGroups())
|
|
|
|
if (getGroupName(g) == name)
|
|
|
|
return g;
|
|
|
|
return GroupId();
|
|
|
|
}
|
|
|
|
|
|
|
|
IdStringList Arch::getGroupName(GroupId group) const
|
|
|
|
{
|
|
|
|
std::string suffix;
|
|
|
|
|
|
|
|
switch (group.type) {
|
|
|
|
case GroupId::TYPE_SWITCHBOX:
|
|
|
|
suffix = "switchbox";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return IdStringList();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::array<IdString, 3> ids{x_ids.at(group.location.x), y_ids.at(group.location.y), id(suffix)};
|
|
|
|
return IdStringList(ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<GroupId> Arch::getGroups() const
|
|
|
|
{
|
|
|
|
std::vector<GroupId> ret;
|
|
|
|
|
|
|
|
for (int y = 1; y < chip_info->height - 1; y++) {
|
|
|
|
for (int x = 1; x < chip_info->width - 1; x++) {
|
|
|
|
GroupId group;
|
|
|
|
group.type = GroupId::TYPE_SWITCHBOX;
|
|
|
|
group.location.x = x;
|
|
|
|
group.location.y = y;
|
|
|
|
ret.push_back(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<BelId> Arch::getGroupBels(GroupId group) const
|
|
|
|
{
|
|
|
|
std::vector<BelId> ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<WireId> Arch::getGroupWires(GroupId group) const
|
|
|
|
{
|
|
|
|
std::vector<WireId> ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<PipId> Arch::getGroupPips(GroupId group) const
|
|
|
|
{
|
|
|
|
std::vector<PipId> ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<GroupId> Arch::getGroupGroups(GroupId group) const
|
|
|
|
{
|
|
|
|
std::vector<GroupId> ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2023-03-30 21:24:53 +08:00
|
|
|
std::vector<std::pair<IdString, std::string>> Arch::getWireAttrs(WireId wire) const
|
|
|
|
{
|
|
|
|
std::vector<std::pair<IdString, std::string>> ret;
|
|
|
|
auto &wi = tile_info(wire)->wire_data[wire.index];
|
|
|
|
|
|
|
|
ret.push_back(std::make_pair(id_TILE_WIRE_ID, stringf("%d", wi.tile_wire)));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-02-11 19:10:32 +08:00
|
|
|
NEXTPNR_NAMESPACE_END
|