2021-01-27 02:05:23 +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>
|
|
|
|
* Copyright (C) 2018-19 gatecat <gatecat@ds0.me>
|
2021-02-05 04:56:12 +08:00
|
|
|
* Copyright (C) 2021 Symbiflow Authors
|
2021-01-27 02:05:23 +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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-03-20 08:35:29 +08:00
|
|
|
#include "arch.h"
|
|
|
|
|
2021-01-27 02:05:23 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/range/adaptor/reversed.hpp>
|
2021-03-23 08:46:00 +08:00
|
|
|
#include <boost/uuid/detail/sha1.hpp>
|
2021-01-27 02:05:23 +08:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstring>
|
|
|
|
#include <queue>
|
2023-01-20 16:04:41 +08:00
|
|
|
#include <set>
|
2021-03-23 08:46:00 +08:00
|
|
|
|
2021-02-06 06:18:38 +08:00
|
|
|
#include "constraints.impl.h"
|
2021-02-13 08:12:16 +08:00
|
|
|
#include "fpga_interchange.h"
|
2021-01-27 02:05:23 +08:00
|
|
|
#include "log.h"
|
|
|
|
#include "nextpnr.h"
|
|
|
|
#include "placer1.h"
|
|
|
|
#include "placer_heap.h"
|
|
|
|
#include "router1.h"
|
|
|
|
#include "router2.h"
|
|
|
|
#include "timing.h"
|
|
|
|
#include "util.h"
|
2021-02-12 07:29:53 +08:00
|
|
|
#include "xdc.h"
|
2021-01-27 02:05:23 +08:00
|
|
|
|
2021-03-20 08:35:29 +08:00
|
|
|
// Include tcl.h late because it messed with defines and let them leave the
|
|
|
|
// scope of the header.
|
|
|
|
#include <tcl.h>
|
2021-03-23 08:46:00 +08:00
|
|
|
|
|
|
|
//#define DEBUG_BINDING
|
|
|
|
//#define USE_LOOKAHEAD
|
|
|
|
//#define DEBUG_CELL_PIN_MAPPING
|
|
|
|
|
2021-03-25 02:07:45 +08:00
|
|
|
// Define to enable some idempotent sanity checks for some important
|
|
|
|
// operations prior to placement and routing.
|
|
|
|
#define IDEMPOTENT_CHECK
|
|
|
|
|
2021-02-16 01:45:52 +08:00
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
struct SiteBelPair
|
|
|
|
{
|
|
|
|
std::string site;
|
|
|
|
IdString bel;
|
|
|
|
|
|
|
|
SiteBelPair() {}
|
|
|
|
SiteBelPair(std::string site, IdString bel) : site(site), bel(bel) {}
|
|
|
|
|
|
|
|
bool operator==(const SiteBelPair &other) const { return site == other.site && bel == other.bel; }
|
2021-06-02 17:01:36 +08:00
|
|
|
unsigned int hash() const { return mkhash(std::hash<std::string>()(site), bel.hash()); }
|
2021-02-16 01:45:52 +08:00
|
|
|
};
|
2021-01-27 02:05:23 +08:00
|
|
|
|
|
|
|
static std::pair<std::string, std::string> split_identifier_name_dot(const std::string &name)
|
|
|
|
{
|
|
|
|
size_t first_dot = name.find('.');
|
|
|
|
NPNR_ASSERT(first_dot != std::string::npos);
|
|
|
|
return std::make_pair(name.substr(0, first_dot), name.substr(first_dot + 1));
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2021-02-06 01:22:55 +08:00
|
|
|
void IdString::initialize_arch(const BaseCtx *ctx) {}
|
2021-01-27 02:05:23 +08:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
static const ChipInfoPOD *get_chip_info(const RelPtr<ChipInfoPOD> *ptr) { return ptr->get(); }
|
|
|
|
|
2021-03-23 08:46:00 +08:00
|
|
|
static std::string sha1_hash(const char *data, size_t size)
|
|
|
|
{
|
|
|
|
boost::uuids::detail::sha1 hasher;
|
|
|
|
hasher.process_bytes(data, size);
|
|
|
|
|
|
|
|
// unsigned int[5]
|
|
|
|
boost::uuids::detail::sha1::digest_type digest;
|
|
|
|
hasher.get_digest(digest);
|
|
|
|
|
|
|
|
std::ostringstream buf;
|
|
|
|
for (int i = 0; i < 5; ++i)
|
|
|
|
buf << std::hex << std::setfill('0') << std::setw(8) << digest[i];
|
|
|
|
|
|
|
|
return buf.str();
|
|
|
|
}
|
|
|
|
|
2021-04-02 06:12:53 +08:00
|
|
|
Arch::Arch(ArchArgs args) : args(args), disallow_site_routing(false)
|
2021-01-27 02:05:23 +08:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
blob_file.open(args.chipdb);
|
|
|
|
if (args.chipdb.empty() || !blob_file.is_open())
|
|
|
|
log_error("Unable to read chipdb %s\n", args.chipdb.c_str());
|
|
|
|
const char *blob = reinterpret_cast<const char *>(blob_file.data());
|
2021-03-23 08:46:00 +08:00
|
|
|
|
|
|
|
chipdb_hash = sha1_hash(blob, blob_file.size());
|
2021-01-27 02:05:23 +08:00
|
|
|
chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(blob));
|
|
|
|
} catch (...) {
|
|
|
|
log_error("Unable to read chipdb %s\n", args.chipdb.c_str());
|
|
|
|
}
|
|
|
|
|
2021-03-20 08:35:29 +08:00
|
|
|
if (chip_info->version != kExpectedChipInfoVersion) {
|
|
|
|
log_error("Expected chipdb with version %d found version %d\n", kExpectedChipInfoVersion, chip_info->version);
|
|
|
|
}
|
|
|
|
|
2021-02-06 06:18:38 +08:00
|
|
|
// Read strings from constids into IdString database, checking that list
|
|
|
|
// is unique and matches expected constid value.
|
2021-02-16 01:45:52 +08:00
|
|
|
const RelSlice<RelPtr<char>> &constids = *chip_info->constids;
|
|
|
|
for (size_t i = 0; i < constids.size(); ++i) {
|
|
|
|
IdString::initialize_add(this, constids[i].get(), i + 1);
|
|
|
|
}
|
|
|
|
|
2021-03-24 00:37:22 +08:00
|
|
|
id_GND = id("GND");
|
|
|
|
id_VCC = id("VCC");
|
|
|
|
|
2021-02-01 23:18:28 +08:00
|
|
|
// Sanity check cell name ids.
|
2021-02-04 06:48:49 +08:00
|
|
|
const CellMapPOD &cell_map = *chip_info->cell_map;
|
2021-02-01 23:18:28 +08:00
|
|
|
int32_t first_cell_id = cell_map.cell_names[0];
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int32_t i = 0; i < cell_map.cell_names.ssize(); ++i) {
|
2021-02-01 23:18:28 +08:00
|
|
|
log_assert(cell_map.cell_names[i] == i + first_cell_id);
|
|
|
|
}
|
2021-02-13 08:12:16 +08:00
|
|
|
|
|
|
|
io_port_types.emplace(this->id("$nextpnr_ibuf"));
|
|
|
|
io_port_types.emplace(this->id("$nextpnr_obuf"));
|
|
|
|
io_port_types.emplace(this->id("$nextpnr_iobuf"));
|
2021-03-24 07:53:42 +08:00
|
|
|
io_port_types.emplace(this->id("$nextpnr_inv"));
|
2021-02-16 01:45:52 +08:00
|
|
|
|
|
|
|
if (!this->args.package.empty()) {
|
|
|
|
IdString package = this->id(this->args.package);
|
|
|
|
package_index = -1;
|
|
|
|
for (size_t i = 0; i < chip_info->packages.size(); ++i) {
|
|
|
|
if (IdString(chip_info->packages[i].package) == package) {
|
|
|
|
NPNR_ASSERT(package_index == -1);
|
|
|
|
package_index = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (package_index == -1) {
|
|
|
|
log_error("Could not find package '%s' in chipdb.\n", this->args.package.c_str());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Default to first package.
|
|
|
|
NPNR_ASSERT(chip_info->packages.size() > 0);
|
2021-02-17 18:45:23 +08:00
|
|
|
if (chip_info->packages.size() == 1) {
|
2021-02-17 06:00:01 +08:00
|
|
|
IdString package_name(chip_info->packages[0].package);
|
|
|
|
this->args.package = package_name.str(this);
|
|
|
|
package_index = 0;
|
|
|
|
} else {
|
2021-02-17 18:45:23 +08:00
|
|
|
log_info(
|
|
|
|
"Package must be specified (with --package arg) when multiple packages are available, packages:\n");
|
|
|
|
for (const auto &package : chip_info->packages) {
|
2021-02-17 06:00:01 +08:00
|
|
|
log_info(" - %s\n", IdString(package.package).c_str(this));
|
|
|
|
}
|
|
|
|
log_error("--package is required!\n");
|
|
|
|
}
|
2021-02-16 01:45:52 +08:00
|
|
|
}
|
|
|
|
|
2021-06-02 17:01:36 +08:00
|
|
|
pool<SiteBelPair> site_bel_pads;
|
2021-02-16 01:45:52 +08:00
|
|
|
for (const auto &package_pin : chip_info->packages[package_index].pins) {
|
|
|
|
IdString site(package_pin.site);
|
|
|
|
IdString bel(package_pin.bel);
|
|
|
|
site_bel_pads.emplace(SiteBelPair(site.str(this), bel));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (BelId bel : getBels()) {
|
|
|
|
auto &bel_data = bel_info(chip_info, bel);
|
2021-02-19 05:26:52 +08:00
|
|
|
const SiteInstInfoPOD &site = get_site_inst(bel);
|
2021-02-16 01:45:52 +08:00
|
|
|
auto iter = site_bel_pads.find(SiteBelPair(site.site_name.get(), IdString(bel_data.name)));
|
|
|
|
if (iter != site_bel_pads.end()) {
|
|
|
|
pads.emplace(bel);
|
|
|
|
}
|
|
|
|
}
|
2021-02-06 06:18:38 +08:00
|
|
|
|
|
|
|
explain_constraints = false;
|
|
|
|
|
|
|
|
int tile_type_index = 0;
|
|
|
|
size_t max_tag_count = 0;
|
2021-02-25 06:02:21 +08:00
|
|
|
|
2021-02-06 06:18:38 +08:00
|
|
|
for (const TileTypeInfoPOD &tile_type : chip_info->tile_types) {
|
|
|
|
max_tag_count = std::max(max_tag_count, tile_type.tags.size());
|
|
|
|
|
2021-02-17 01:45:43 +08:00
|
|
|
auto &type_definition = constraints.definitions[tile_type_index++];
|
2021-02-06 06:18:38 +08:00
|
|
|
for (const ConstraintTagPOD &tag : tile_type.tags) {
|
|
|
|
type_definition.emplace_back();
|
|
|
|
auto &definition = type_definition.back();
|
|
|
|
definition.prefix = IdString(tag.tag_prefix);
|
|
|
|
definition.default_state = IdString(tag.default_state);
|
|
|
|
NPNR_ASSERT(tag.states.size() < kMaxState);
|
|
|
|
|
|
|
|
definition.states.reserve(tag.states.size());
|
|
|
|
for (auto state : tag.states) {
|
|
|
|
definition.states.push_back(IdString(state));
|
|
|
|
}
|
|
|
|
}
|
2021-02-17 09:25:16 +08:00
|
|
|
|
|
|
|
// Logic BELs (e.g. placable BELs) should always appear first in the
|
|
|
|
// bel data list.
|
|
|
|
//
|
|
|
|
// When iterating over BELs this property is depended on to skip
|
|
|
|
// non-placable BELs (e.g. routing BELs and site ports).
|
|
|
|
bool in_logic_bels = true;
|
|
|
|
for (const BelInfoPOD &bel_info : tile_type.bel_data) {
|
|
|
|
if (in_logic_bels && bel_info.category != BEL_CATEGORY_LOGIC) {
|
|
|
|
in_logic_bels = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_logic_bels) {
|
|
|
|
NPNR_ASSERT(bel_info.category != BEL_CATEGORY_LOGIC);
|
|
|
|
}
|
|
|
|
}
|
2021-02-06 06:18:38 +08:00
|
|
|
}
|
|
|
|
|
2021-02-25 06:02:21 +08:00
|
|
|
// Initially LutElement vectors for each tile type.
|
|
|
|
tile_type_index = 0;
|
2022-03-04 23:53:03 +08:00
|
|
|
max_lut_cells = 0;
|
|
|
|
max_lut_pins = 0;
|
2021-02-25 06:02:21 +08:00
|
|
|
lut_elements.resize(chip_info->tile_types.size());
|
|
|
|
for (const TileTypeInfoPOD &tile_type : chip_info->tile_types) {
|
|
|
|
std::vector<LutElement> &elements = lut_elements[tile_type_index++];
|
|
|
|
elements.reserve(tile_type.lut_elements.size());
|
2022-03-04 23:53:03 +08:00
|
|
|
|
|
|
|
int lut_cells_count = 0;
|
2021-02-25 06:02:21 +08:00
|
|
|
for (auto &lut_element : tile_type.lut_elements) {
|
|
|
|
elements.emplace_back();
|
|
|
|
|
|
|
|
LutElement &element = elements.back();
|
|
|
|
element.width = lut_element.width;
|
|
|
|
for (auto &lut_bel : lut_element.lut_bels) {
|
2021-04-02 06:16:23 +08:00
|
|
|
IdString name(lut_bel.name);
|
|
|
|
auto result = element.lut_bels.emplace(name, LutBel());
|
2021-02-25 06:02:21 +08:00
|
|
|
NPNR_ASSERT(result.second);
|
|
|
|
LutBel &lut = result.first->second;
|
|
|
|
|
2021-04-02 06:16:23 +08:00
|
|
|
lut.name = name;
|
|
|
|
|
2021-02-25 06:02:21 +08:00
|
|
|
lut.low_bit = lut_bel.low_bit;
|
|
|
|
lut.high_bit = lut_bel.high_bit;
|
|
|
|
|
|
|
|
lut.pins.reserve(lut_bel.pins.size());
|
|
|
|
for (size_t i = 0; i < lut_bel.pins.size(); ++i) {
|
|
|
|
IdString pin(lut_bel.pins[i]);
|
|
|
|
lut.pins.push_back(pin);
|
|
|
|
lut.pin_to_index[pin] = i;
|
|
|
|
}
|
2021-04-02 06:16:23 +08:00
|
|
|
|
|
|
|
lut.output_pin = IdString(lut_bel.out_pin);
|
2022-03-04 23:53:03 +08:00
|
|
|
lut_cells_count++;
|
|
|
|
|
|
|
|
max_lut_pins = std::max((int)lut_bel.pins.size(), max_lut_pins);
|
2021-02-25 06:02:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
element.compute_pin_order();
|
|
|
|
}
|
2022-03-04 23:53:03 +08:00
|
|
|
|
|
|
|
max_lut_cells = std::max(lut_cells_count, max_lut_cells);
|
2021-02-25 06:02:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Map lut cell types to their LutCellPOD
|
2021-04-02 04:18:07 +08:00
|
|
|
wire_lut = nullptr;
|
2021-02-25 06:02:21 +08:00
|
|
|
for (const LutCellPOD &lut_cell : chip_info->cell_map->lut_cells) {
|
|
|
|
IdString cell_type(lut_cell.cell);
|
|
|
|
auto result = lut_cells.emplace(cell_type, &lut_cell);
|
|
|
|
NPNR_ASSERT(result.second);
|
2021-04-02 04:18:07 +08:00
|
|
|
|
2021-04-12 17:26:39 +08:00
|
|
|
if (lut_cell.input_pins.size() == 1) {
|
2021-04-02 04:18:07 +08:00
|
|
|
// Only really expecting 1 single input LUT type!
|
|
|
|
NPNR_ASSERT(wire_lut == nullptr);
|
|
|
|
wire_lut = &lut_cell;
|
|
|
|
}
|
2021-02-25 06:02:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
raw_bin_constant = std::regex("[01]+", std::regex_constants::ECMAScript | std::regex_constants::optimize);
|
|
|
|
verilog_bin_constant =
|
|
|
|
std::regex("([0-9]+)'b([01]+)", std::regex_constants::ECMAScript | std::regex_constants::optimize);
|
|
|
|
verilog_hex_constant =
|
|
|
|
std::regex("([0-9]+)'h([0-9a-fA-F]+)", std::regex_constants::ECMAScript | std::regex_constants::optimize);
|
|
|
|
|
2021-02-06 06:18:38 +08:00
|
|
|
default_tags.resize(max_tag_count);
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
|
2021-03-23 08:46:00 +08:00
|
|
|
void Arch::init()
|
|
|
|
{
|
|
|
|
#ifdef USE_LOOKAHEAD
|
|
|
|
lookahead.init(getCtx(), getCtx());
|
|
|
|
#endif
|
|
|
|
dedicated_interconnect.init(getCtx());
|
2021-03-23 06:55:34 +08:00
|
|
|
cell_parameters.init(getCtx());
|
2021-04-02 04:18:07 +08:00
|
|
|
|
|
|
|
for (size_t tile_type = 0; tile_type < chip_info->tile_types.size(); ++tile_type) {
|
|
|
|
pseudo_pip_data.init_tile_type(getCtx(), tile_type);
|
|
|
|
}
|
2022-05-12 17:55:16 +08:00
|
|
|
|
|
|
|
// Warn if there is no preferred constant net defined in the architecture
|
|
|
|
IdString const_net_name(getCtx()->chip_info->constants->best_constant_net);
|
|
|
|
if (const_net_name == IdString()) {
|
|
|
|
log_warning("The architecture does not specify preferred constant net. Using VCC as default.\n");
|
|
|
|
}
|
2021-03-23 08:46:00 +08:00
|
|
|
}
|
2021-02-20 08:18:59 +08:00
|
|
|
|
2021-01-27 02:05:23 +08:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
std::string Arch::getChipName() const { return chip_info->name.get(); }
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
IdString Arch::archArgsToId(ArchArgs args) const { return IdString(); }
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Arch::setup_byname() const
|
|
|
|
{
|
2021-03-20 08:35:29 +08:00
|
|
|
by_name_mutex.lock();
|
|
|
|
|
2021-01-27 02:05:23 +08:00
|
|
|
if (tile_by_name.empty()) {
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < chip_info->tiles.ssize(); i++) {
|
2021-02-04 05:37:58 +08:00
|
|
|
tile_by_name[id(chip_info->tiles[i].name.get())] = i;
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (site_by_name.empty()) {
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < chip_info->tiles.ssize(); i++) {
|
2021-01-27 02:05:23 +08:00
|
|
|
auto &tile = chip_info->tiles[i];
|
|
|
|
auto &tile_type = chip_info->tile_types[tile.type];
|
2021-02-20 01:44:14 +08:00
|
|
|
for (size_t j = 0; j < tile_type.site_types.size(); j++) {
|
2021-01-27 02:05:23 +08:00
|
|
|
auto &site = chip_info->sites[tile.sites[j]];
|
2021-02-04 05:37:58 +08:00
|
|
|
site_by_name[id(site.name.get())] = std::make_pair(i, j);
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-20 08:35:29 +08:00
|
|
|
|
|
|
|
by_name_mutex.unlock();
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
|
2021-02-04 05:37:58 +08:00
|
|
|
BelId Arch::getBelByName(IdStringList name) const
|
2021-01-27 02:05:23 +08:00
|
|
|
{
|
|
|
|
BelId ret;
|
2021-02-04 06:48:49 +08:00
|
|
|
if (name.ids.size() != 2) {
|
2021-02-04 05:37:58 +08:00
|
|
|
return BelId();
|
|
|
|
}
|
2021-01-27 02:05:23 +08:00
|
|
|
|
|
|
|
setup_byname();
|
|
|
|
|
|
|
|
int tile, site;
|
2021-02-04 05:37:58 +08:00
|
|
|
std::tie(tile, site) = site_by_name.at(name.ids[0]);
|
2021-01-27 02:05:23 +08:00
|
|
|
auto &tile_info = chip_info->tile_types[chip_info->tiles[tile].type];
|
2021-02-04 05:37:58 +08:00
|
|
|
IdString belname = name.ids[1];
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < tile_info.bel_data.ssize(); i++) {
|
2021-01-27 02:05:23 +08:00
|
|
|
if (tile_info.bel_data[i].site == site && tile_info.bel_data[i].name == belname.index) {
|
|
|
|
ret.tile = tile;
|
|
|
|
ret.index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BelRange Arch::getBelsByTile(int x, int y) const
|
|
|
|
{
|
|
|
|
BelRange br;
|
|
|
|
|
2021-02-05 06:23:12 +08:00
|
|
|
br.b.cursor_tile = get_tile_index(x, y);
|
2021-01-27 02:05:23 +08:00
|
|
|
br.e.cursor_tile = br.b.cursor_tile;
|
|
|
|
br.b.cursor_index = 0;
|
2021-02-05 08:05:01 +08:00
|
|
|
br.e.cursor_index = chip_info->tile_types[chip_info->tiles[br.b.cursor_tile].type].bel_data.size();
|
2021-01-27 02:05:23 +08:00
|
|
|
br.b.chip = chip_info;
|
|
|
|
br.e.chip = chip_info;
|
2021-01-28 10:00:43 +08:00
|
|
|
|
2021-02-04 06:48:49 +08:00
|
|
|
if (br.b != br.e) {
|
2021-01-27 02:05:23 +08:00
|
|
|
++br.e;
|
2021-01-28 10:00:43 +08:00
|
|
|
}
|
2021-01-27 02:05:23 +08:00
|
|
|
return br;
|
|
|
|
}
|
|
|
|
|
|
|
|
WireId Arch::getBelPinWire(BelId bel, IdString pin) const
|
|
|
|
{
|
|
|
|
NPNR_ASSERT(bel != BelId());
|
|
|
|
|
2021-02-05 06:23:12 +08:00
|
|
|
int pin_index = get_bel_pin_index(bel, pin);
|
2021-02-02 06:26:57 +08:00
|
|
|
|
2021-02-05 06:23:12 +08:00
|
|
|
auto &bel_data = bel_info(chip_info, bel);
|
2021-02-02 06:26:57 +08:00
|
|
|
NPNR_ASSERT(pin_index >= 0 && pin_index < bel_data.num_bel_wires);
|
|
|
|
|
|
|
|
const int32_t *wires = bel_data.wires.get();
|
|
|
|
int32_t wire_index = wires[pin_index];
|
2021-02-04 06:48:49 +08:00
|
|
|
if (wire_index < 0) {
|
2021-02-02 06:26:57 +08:00
|
|
|
// This BEL pin is not connected.
|
2021-01-28 10:00:43 +08:00
|
|
|
return WireId();
|
|
|
|
} else {
|
2021-02-05 06:23:12 +08:00
|
|
|
return canonical_wire(chip_info, bel.tile, wire_index);
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PortType Arch::getBelPinType(BelId bel, IdString pin) const
|
|
|
|
{
|
|
|
|
NPNR_ASSERT(bel != BelId());
|
|
|
|
|
2021-02-05 06:23:12 +08:00
|
|
|
int pin_index = get_bel_pin_index(bel, pin);
|
|
|
|
auto &bel_data = bel_info(chip_info, bel);
|
2021-01-29 01:28:40 +08:00
|
|
|
NPNR_ASSERT(pin_index >= 0 && pin_index < bel_data.num_bel_wires);
|
|
|
|
const int32_t *types = bel_data.types.get();
|
|
|
|
return PortType(types[pin_index]);
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2021-02-04 05:37:58 +08:00
|
|
|
WireId Arch::getWireByName(IdStringList name) const
|
2021-01-27 02:05:23 +08:00
|
|
|
{
|
|
|
|
WireId ret;
|
2021-02-04 06:48:49 +08:00
|
|
|
if (name.ids.size() != 2) {
|
2021-02-04 05:37:58 +08:00
|
|
|
return WireId();
|
|
|
|
}
|
|
|
|
|
2021-01-27 02:05:23 +08:00
|
|
|
setup_byname();
|
|
|
|
|
2021-02-04 05:37:58 +08:00
|
|
|
auto iter = site_by_name.find(name.ids[0]);
|
2021-01-27 02:05:23 +08:00
|
|
|
if (iter != site_by_name.end()) {
|
|
|
|
int tile;
|
|
|
|
int site;
|
|
|
|
std::tie(tile, site) = iter->second;
|
|
|
|
auto &tile_info = chip_info->tile_types[chip_info->tiles[tile].type];
|
2021-02-04 05:37:58 +08:00
|
|
|
IdString wirename = name.ids[1];
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < tile_info.wire_data.ssize(); i++) {
|
2021-01-27 02:05:23 +08:00
|
|
|
if (tile_info.wire_data[i].site == site && tile_info.wire_data[i].name == wirename.index) {
|
|
|
|
ret.tile = tile;
|
|
|
|
ret.index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2021-02-04 05:37:58 +08:00
|
|
|
int tile = tile_by_name.at(name.ids[0]);
|
2021-01-27 02:05:23 +08:00
|
|
|
auto &tile_info = chip_info->tile_types[chip_info->tiles[tile].type];
|
2021-02-04 05:37:58 +08:00
|
|
|
IdString wirename = name.ids[1];
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < tile_info.wire_data.ssize(); i++) {
|
2021-01-27 02:05:23 +08:00
|
|
|
if (tile_info.wire_data[i].site == -1 && tile_info.wire_data[i].name == wirename.index) {
|
2021-01-27 10:40:42 +08:00
|
|
|
int32_t node = chip_info->tiles[tile].tile_wire_to_node[i];
|
|
|
|
if (node == -1) {
|
|
|
|
// Not a nodal wire
|
|
|
|
ret.tile = tile;
|
|
|
|
ret.index = i;
|
|
|
|
} else {
|
|
|
|
// Is a nodal wire, set tile to -1
|
|
|
|
ret.tile = -1;
|
|
|
|
ret.index = node;
|
|
|
|
}
|
2021-01-27 02:05:23 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:07:31 +08:00
|
|
|
IdString Arch::getWireType(WireId wire) const
|
|
|
|
{
|
|
|
|
int tile = wire.tile, index = wire.index;
|
|
|
|
if (tile == -1) {
|
|
|
|
// Nodal wire
|
|
|
|
const TileWireRefPOD &wr = chip_info->nodes[wire.index].tile_wires[0];
|
|
|
|
tile = wr.tile;
|
|
|
|
index = wr.index;
|
|
|
|
}
|
|
|
|
auto &w2t = chip_info->tiles[tile].tile_wire_to_type;
|
|
|
|
if (index >= w2t.ssize())
|
|
|
|
return IdString();
|
|
|
|
int wire_type = w2t[index];
|
|
|
|
if (wire_type == -1)
|
|
|
|
return IdString();
|
|
|
|
return IdString(chip_info->wire_types[wire_type].name);
|
|
|
|
}
|
|
|
|
|
2021-05-05 17:36:32 +08:00
|
|
|
bool Arch::is_site_wire(WireId wire) const
|
|
|
|
{
|
|
|
|
if (wire.tile == -1)
|
|
|
|
return false;
|
|
|
|
const auto &tile_type = loc_info(chip_info, wire);
|
|
|
|
return tile_type.wire_data[wire.index].site != -1;
|
|
|
|
}
|
|
|
|
|
2021-05-04 21:07:28 +08:00
|
|
|
WireCategory Arch::get_wire_category(WireId wire) const
|
|
|
|
{
|
|
|
|
int tile = wire.tile, index = wire.index;
|
|
|
|
if (tile == -1) {
|
|
|
|
// Nodal wire
|
|
|
|
const TileWireRefPOD &wr = chip_info->nodes[wire.index].tile_wires[0];
|
|
|
|
tile = wr.tile;
|
|
|
|
index = wr.index;
|
|
|
|
}
|
|
|
|
auto &w2t = chip_info->tiles[tile].tile_wire_to_type;
|
|
|
|
if (index >= w2t.ssize())
|
|
|
|
return WIRE_CAT_GENERAL;
|
|
|
|
int wire_type = w2t[index];
|
|
|
|
if (wire_type == -1)
|
|
|
|
return WIRE_CAT_GENERAL;
|
|
|
|
return WireCategory(chip_info->wire_types[wire_type].category);
|
|
|
|
}
|
|
|
|
|
2021-02-04 06:48:49 +08:00
|
|
|
std::vector<std::pair<IdString, std::string>> Arch::getWireAttrs(WireId wire) const { return {}; }
|
2021-01-27 02:05:23 +08:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2021-02-04 05:37:58 +08:00
|
|
|
PipId Arch::getPipByName(IdStringList name) const
|
2021-01-27 02:05:23 +08:00
|
|
|
{
|
2021-01-28 10:00:43 +08:00
|
|
|
// PIP name structure:
|
|
|
|
// Tile PIP: <tile name>/<source wire name>.<destination wire name>
|
|
|
|
// Site PIP: <site name>/<bel name>/<input bel pin name>
|
|
|
|
// Site pin: <site name>/<bel name>
|
2021-02-04 05:37:58 +08:00
|
|
|
// Psuedo site PIP: <site name>/<source wire name>.<destination wire name>
|
2021-01-27 02:05:23 +08:00
|
|
|
|
|
|
|
setup_byname();
|
|
|
|
|
2021-02-04 06:48:49 +08:00
|
|
|
if (name.ids.size() == 3) {
|
2021-02-04 05:37:58 +08:00
|
|
|
// This is a Site PIP.
|
|
|
|
IdString site_name = name.ids[0];
|
|
|
|
IdString belname = name.ids[1];
|
|
|
|
IdString pinname = name.ids[2];
|
|
|
|
|
2021-01-27 02:05:23 +08:00
|
|
|
int tile;
|
|
|
|
int site;
|
2021-02-04 05:37:58 +08:00
|
|
|
std::tie(tile, site) = site_by_name.at(site_name);
|
2021-03-20 08:35:29 +08:00
|
|
|
auto tile_type_idx = chip_info->tiles[tile].type;
|
|
|
|
auto &tile_info = chip_info->tile_types[tile_type_idx];
|
2021-01-28 10:00:43 +08:00
|
|
|
|
2021-02-04 05:37:58 +08:00
|
|
|
std::array<IdString, 2> ids{name.ids[0], belname};
|
|
|
|
BelId bel = getBelByName(IdStringList(ids));
|
|
|
|
NPNR_ASSERT(bel != BelId());
|
2021-01-28 10:00:43 +08:00
|
|
|
|
2021-02-05 06:23:12 +08:00
|
|
|
int pin_index = get_bel_pin_index(bel, pinname);
|
2021-02-04 05:37:58 +08:00
|
|
|
NPNR_ASSERT(pin_index >= 0);
|
2021-01-28 10:00:43 +08:00
|
|
|
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < tile_info.pip_data.ssize(); i++) {
|
2021-02-04 06:48:49 +08:00
|
|
|
if (tile_info.pip_data[i].site == site && tile_info.pip_data[i].bel == bel.index &&
|
2021-02-04 05:37:58 +08:00
|
|
|
tile_info.pip_data[i].extra_data == pin_index) {
|
|
|
|
|
|
|
|
PipId ret;
|
|
|
|
ret.tile = tile;
|
|
|
|
ret.index = i;
|
|
|
|
return ret;
|
2021-01-28 10:00:43 +08:00
|
|
|
}
|
2021-02-04 05:37:58 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
auto iter = site_by_name.find(name.ids[0]);
|
|
|
|
if (iter != site_by_name.end()) {
|
|
|
|
// This is either a site pin or a psuedo site pip.
|
|
|
|
// psuedo site pips are <site>/<src site wire>.<dst site wire>
|
|
|
|
// site pins are <site>/<bel>
|
|
|
|
int tile;
|
|
|
|
int site;
|
|
|
|
std::tie(tile, site) = iter->second;
|
2021-03-20 08:35:29 +08:00
|
|
|
auto tile_type_idx = chip_info->tiles[tile].type;
|
|
|
|
auto &tile_info = chip_info->tile_types[tile_type_idx];
|
2021-02-04 05:37:58 +08:00
|
|
|
|
|
|
|
std::string pip_second = name.ids[1].str(this);
|
|
|
|
auto split = pip_second.find('.');
|
2021-02-04 06:48:49 +08:00
|
|
|
if (split == std::string::npos) {
|
2021-01-28 10:00:43 +08:00
|
|
|
// This is a site pin!
|
|
|
|
BelId bel = getBelByName(name);
|
|
|
|
NPNR_ASSERT(bel != BelId());
|
|
|
|
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < tile_info.pip_data.ssize(); i++) {
|
2021-02-04 06:48:49 +08:00
|
|
|
if (tile_info.pip_data[i].site == site && tile_info.pip_data[i].bel == bel.index) {
|
2021-02-04 05:37:58 +08:00
|
|
|
|
|
|
|
PipId ret;
|
2021-01-28 10:00:43 +08:00
|
|
|
ret.tile = tile;
|
|
|
|
ret.index = i;
|
2021-02-04 05:37:58 +08:00
|
|
|
return ret;
|
2021-01-28 10:00:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is a psuedo site pip!
|
2021-02-04 05:37:58 +08:00
|
|
|
IdString src_site_wire = id(pip_second.substr(0, split));
|
2021-02-04 06:48:49 +08:00
|
|
|
IdString dst_site_wire = id(pip_second.substr(split + 1));
|
2021-01-28 10:00:43 +08:00
|
|
|
int32_t src_index = -1;
|
|
|
|
int32_t dst_index = -1;
|
2021-02-04 05:37:58 +08:00
|
|
|
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < tile_info.wire_data.ssize(); i++) {
|
2021-01-28 10:00:43 +08:00
|
|
|
if (tile_info.wire_data[i].site == site && tile_info.wire_data[i].name == src_site_wire.index) {
|
|
|
|
src_index = i;
|
2021-02-04 06:48:49 +08:00
|
|
|
if (dst_index != -1) {
|
2021-01-28 10:00:43 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tile_info.wire_data[i].site == site && tile_info.wire_data[i].name == dst_site_wire.index) {
|
|
|
|
dst_index = i;
|
2021-02-04 06:48:49 +08:00
|
|
|
if (src_index != -1) {
|
2021-01-28 10:00:43 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NPNR_ASSERT(src_index != -1);
|
|
|
|
NPNR_ASSERT(dst_index != -1);
|
|
|
|
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < tile_info.pip_data.ssize(); i++) {
|
2021-02-04 06:48:49 +08:00
|
|
|
if (tile_info.pip_data[i].site == site && tile_info.pip_data[i].src_index == src_index &&
|
2021-01-28 10:00:43 +08:00
|
|
|
tile_info.pip_data[i].dst_index == dst_index) {
|
2021-02-04 05:37:58 +08:00
|
|
|
|
|
|
|
PipId ret;
|
2021-01-28 10:00:43 +08:00
|
|
|
ret.tile = tile;
|
|
|
|
ret.index = i;
|
2021-02-04 05:37:58 +08:00
|
|
|
return ret;
|
2021-01-28 10:00:43 +08:00
|
|
|
}
|
|
|
|
}
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
2021-02-04 05:37:58 +08:00
|
|
|
} else {
|
|
|
|
int tile = tile_by_name.at(name.ids[0]);
|
2021-03-20 08:35:29 +08:00
|
|
|
size_t tile_type_idx = chip_info->tiles[tile].type;
|
|
|
|
auto &tile_info = chip_info->tile_types[tile_type_idx];
|
2021-02-04 05:37:58 +08:00
|
|
|
|
|
|
|
std::string pip_second = name.ids[1].str(this);
|
|
|
|
auto spn = split_identifier_name_dot(pip_second);
|
|
|
|
auto src_wire_name = id(spn.first);
|
|
|
|
auto dst_wire_name = id(spn.second);
|
|
|
|
|
|
|
|
int32_t src_index = -1;
|
|
|
|
int32_t dst_index = -1;
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < tile_info.wire_data.ssize(); i++) {
|
2021-02-04 05:37:58 +08:00
|
|
|
if (tile_info.wire_data[i].site == -1 && tile_info.wire_data[i].name == src_wire_name.index) {
|
|
|
|
src_index = i;
|
2021-02-04 06:48:49 +08:00
|
|
|
if (dst_index != -1) {
|
2021-02-04 05:37:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-01-28 10:00:43 +08:00
|
|
|
}
|
2021-02-04 05:37:58 +08:00
|
|
|
if (tile_info.wire_data[i].site == -1 && tile_info.wire_data[i].name == dst_wire_name.index) {
|
|
|
|
dst_index = i;
|
2021-02-04 06:48:49 +08:00
|
|
|
if (src_index != -1) {
|
2021-02-04 05:37:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-01-28 10:00:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 05:37:58 +08:00
|
|
|
NPNR_ASSERT(src_index != -1);
|
|
|
|
NPNR_ASSERT(dst_index != -1);
|
2021-01-27 02:05:23 +08:00
|
|
|
|
2021-02-06 01:32:30 +08:00
|
|
|
for (int i = 0; i < tile_info.pip_data.ssize(); i++) {
|
2021-02-04 06:48:49 +08:00
|
|
|
if (tile_info.pip_data[i].src_index == src_index && tile_info.pip_data[i].dst_index == dst_index) {
|
2021-02-04 05:37:58 +08:00
|
|
|
|
|
|
|
PipId ret;
|
|
|
|
ret.tile = tile;
|
|
|
|
ret.index = i;
|
|
|
|
return ret;
|
|
|
|
}
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 05:37:58 +08:00
|
|
|
return PipId();
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
|
2021-02-04 05:37:58 +08:00
|
|
|
IdStringList Arch::getPipName(PipId pip) const
|
2021-01-27 02:05:23 +08:00
|
|
|
{
|
2021-01-28 10:00:43 +08:00
|
|
|
// PIP name structure:
|
|
|
|
// Tile PIP: <tile name>/<source wire name>.<destination wire name>
|
|
|
|
// Psuedo site PIP: <site name>/<input site wire>.<output site wire>
|
|
|
|
// Site PIP: <site name>/<bel name>/<input bel pin name>
|
|
|
|
// Site pin: <site name>/<bel name>
|
2021-01-27 02:05:23 +08:00
|
|
|
NPNR_ASSERT(pip != PipId());
|
2021-01-28 10:00:43 +08:00
|
|
|
auto &tile = chip_info->tiles[pip.tile];
|
2021-02-05 06:23:12 +08:00
|
|
|
auto &tile_type = loc_info(chip_info, pip);
|
2021-01-28 10:00:43 +08:00
|
|
|
auto &pip_info = tile_type.pip_data[pip.index];
|
|
|
|
if (pip_info.site != -1) {
|
|
|
|
// This is either a site pin or a site pip.
|
2021-02-19 05:26:52 +08:00
|
|
|
auto &site = get_site_inst(pip);
|
2021-01-28 10:00:43 +08:00
|
|
|
auto &bel = tile_type.bel_data[pip_info.bel];
|
|
|
|
IdString bel_name(bel.name);
|
2021-02-04 06:48:49 +08:00
|
|
|
if (bel.category == BEL_CATEGORY_LOGIC) {
|
2021-01-28 10:00:43 +08:00
|
|
|
// This is a psuedo pip
|
2021-02-04 05:37:58 +08:00
|
|
|
IdString src_wire_name = IdString(tile_type.wire_data[pip_info.src_index].name);
|
|
|
|
IdString dst_wire_name = IdString(tile_type.wire_data[pip_info.dst_index].name);
|
|
|
|
IdString pip = id(src_wire_name.str(this) + "." + dst_wire_name.str(this));
|
|
|
|
std::array<IdString, 2> ids{id(site.name.get()), pip};
|
|
|
|
return IdStringList(ids);
|
2021-01-28 10:00:43 +08:00
|
|
|
|
2021-02-04 06:48:49 +08:00
|
|
|
} else if (bel.category == BEL_CATEGORY_ROUTING) {
|
2021-01-28 10:00:43 +08:00
|
|
|
// This is a site pip.
|
|
|
|
IdString pin_name(bel.ports[pip_info.extra_data]);
|
2021-02-04 05:37:58 +08:00
|
|
|
std::array<IdString, 3> ids{id(site.name.get()), bel_name, pin_name};
|
|
|
|
return IdStringList(ids);
|
2021-01-28 10:00:43 +08:00
|
|
|
} else {
|
|
|
|
NPNR_ASSERT(bel.category == BEL_CATEGORY_SITE_PORT);
|
|
|
|
// This is a site pin, just the name of the BEL is a unique identifier.
|
2021-02-04 05:37:58 +08:00
|
|
|
std::array<IdString, 2> ids{id(site.name.get()), bel_name};
|
|
|
|
return IdStringList(ids);
|
2021-01-28 10:00:43 +08:00
|
|
|
}
|
2021-01-27 02:05:23 +08:00
|
|
|
} else {
|
2021-01-28 10:00:43 +08:00
|
|
|
// This is a tile pip.
|
2021-02-04 05:37:58 +08:00
|
|
|
IdString src_wire_name = IdString(tile_type.wire_data[pip_info.src_index].name);
|
|
|
|
IdString dst_wire_name = IdString(tile_type.wire_data[pip_info.dst_index].name);
|
|
|
|
IdString pip = id(src_wire_name.str(this) + "." + dst_wire_name.str(this));
|
|
|
|
std::array<IdString, 2> ids{id(std::string(tile.name.get())), pip};
|
|
|
|
return IdStringList(ids);
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IdString Arch::getPipType(PipId pip) const { return id("PIP"); }
|
|
|
|
|
|
|
|
std::vector<std::pair<IdString, std::string>> Arch::getPipAttrs(PipId pip) const { return {}; }
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
BelId Arch::getBelByLocation(Loc loc) const
|
|
|
|
{
|
|
|
|
BelId bi;
|
|
|
|
if (loc.x >= chip_info->width || loc.y >= chip_info->height)
|
|
|
|
return BelId();
|
2021-02-05 06:23:12 +08:00
|
|
|
bi.tile = get_tile_index(loc);
|
|
|
|
auto &li = loc_info(chip_info, bi);
|
2021-01-27 02:05:23 +08:00
|
|
|
|
2021-02-06 01:32:30 +08:00
|
|
|
if (loc.z >= li.bel_data.ssize()) {
|
2021-01-27 02:05:23 +08:00
|
|
|
return BelId();
|
|
|
|
} else {
|
|
|
|
bi.index = loc.z;
|
|
|
|
return bi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<IdString, std::string>> Arch::getBelAttrs(BelId bel) const { return {}; }
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2022-12-07 17:00:53 +08:00
|
|
|
BoundingBox Arch::getRouteBoundingBox(WireId src, WireId dst) const
|
2021-01-27 02:05:23 +08:00
|
|
|
{
|
|
|
|
int dst_tile = dst.tile == -1 ? chip_info->nodes[dst.index].tile_wires[0].tile : dst.tile;
|
|
|
|
int src_tile = src.tile == -1 ? chip_info->nodes[src.index].tile_wires[0].tile : src.tile;
|
|
|
|
|
2021-03-20 08:35:29 +08:00
|
|
|
int src_x, src_y;
|
|
|
|
get_tile_x_y(src_tile, &src_x, &src_y);
|
|
|
|
|
2021-05-11 18:51:10 +08:00
|
|
|
int x0 = src_x, x1 = src_x, y0 = src_y, y1 = src_y;
|
|
|
|
|
2021-03-20 08:35:29 +08:00
|
|
|
int dst_x, dst_y;
|
|
|
|
get_tile_x_y(dst_tile, &dst_x, &dst_y);
|
|
|
|
|
2021-01-27 02:05:23 +08:00
|
|
|
auto expand = [&](int x, int y) {
|
|
|
|
x0 = std::min(x0, x);
|
|
|
|
x1 = std::max(x1, x);
|
|
|
|
y0 = std::min(y0, y);
|
|
|
|
y1 = std::max(y1, y);
|
|
|
|
};
|
|
|
|
|
2021-03-20 08:35:29 +08:00
|
|
|
expand(dst_x, dst_y);
|
2021-01-27 02:05:23 +08:00
|
|
|
|
|
|
|
if (source_locs.count(src))
|
|
|
|
expand(source_locs.at(src).x, source_locs.at(src).y);
|
|
|
|
|
|
|
|
if (sink_locs.count(dst)) {
|
|
|
|
expand(sink_locs.at(dst).x, sink_locs.at(dst).y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {x0, y0, x1, y1};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Arch::getBudgetOverride(const NetInfo *net_info, const PortRef &sink, delay_t &budget) const { return false; }
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool Arch::pack()
|
|
|
|
{
|
2021-02-25 06:02:21 +08:00
|
|
|
decode_lut_cells();
|
2021-06-18 22:41:19 +08:00
|
|
|
expand_macros();
|
2021-07-01 18:45:23 +08:00
|
|
|
merge_constant_nets();
|
2021-02-06 06:18:38 +08:00
|
|
|
pack_ports();
|
2021-04-19 17:46:35 +08:00
|
|
|
pack_default_conns();
|
2021-06-02 15:49:30 +08:00
|
|
|
pack_cluster();
|
2021-02-06 06:18:38 +08:00
|
|
|
return true;
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
|
2021-03-25 02:07:45 +08:00
|
|
|
static void prepare_for_placement(Context *ctx)
|
2021-01-27 02:05:23 +08:00
|
|
|
{
|
2021-03-25 02:07:45 +08:00
|
|
|
ctx->remove_site_routing();
|
2021-02-06 06:18:38 +08:00
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
// Re-map BEL pins without constant pins
|
2021-03-25 02:07:45 +08:00
|
|
|
for (BelId bel : ctx->getBels()) {
|
|
|
|
CellInfo *cell = ctx->getBoundBelCell(bel);
|
2021-02-24 05:35:45 +08:00
|
|
|
if (cell != nullptr && cell->cell_mapping != -1) {
|
2021-03-25 02:07:45 +08:00
|
|
|
ctx->map_cell_pins(cell, cell->cell_mapping, /*bind_constants=*/false);
|
2021-02-24 05:35:45 +08:00
|
|
|
}
|
|
|
|
}
|
2021-03-25 02:07:45 +08:00
|
|
|
}
|
2021-02-24 05:35:45 +08:00
|
|
|
|
2021-03-25 02:07:45 +08:00
|
|
|
bool Arch::place()
|
|
|
|
{
|
|
|
|
// Before placement, ripup placement specific bindings and unmask all cell
|
|
|
|
// pins.
|
|
|
|
getCtx()->check();
|
|
|
|
prepare_for_placement(getCtx());
|
|
|
|
getCtx()->check();
|
|
|
|
#ifdef IDEMPOTENT_CHECK
|
|
|
|
prepare_for_placement(getCtx());
|
|
|
|
getCtx()->check();
|
|
|
|
#endif
|
|
|
|
|
2021-07-12 22:02:51 +08:00
|
|
|
place_constraints();
|
2021-05-05 17:36:32 +08:00
|
|
|
place_globals();
|
|
|
|
|
2021-03-25 02:07:45 +08:00
|
|
|
std::string placer = str_or_default(settings, id("placer"), defaultPlacer);
|
2021-02-06 06:18:38 +08:00
|
|
|
if (placer == "heap") {
|
|
|
|
PlacerHeapCfg cfg(getCtx());
|
|
|
|
cfg.criticalityExponent = 7;
|
|
|
|
cfg.alpha = 0.08;
|
|
|
|
cfg.beta = 0.4;
|
|
|
|
cfg.placeAllAtOnce = true;
|
|
|
|
cfg.hpwl_scale_x = 1;
|
|
|
|
cfg.hpwl_scale_y = 2;
|
|
|
|
cfg.spread_scale_x = 2;
|
|
|
|
cfg.spread_scale_y = 1;
|
|
|
|
cfg.solverTolerance = 0.6e-6;
|
|
|
|
if (!placer_heap(getCtx(), cfg))
|
|
|
|
return false;
|
|
|
|
} else if (placer == "sa") {
|
|
|
|
if (!placer1(getCtx(), Placer1Cfg(getCtx())))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
log_error("FPGA interchange architecture does not support placer '%s'\n", placer.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
getCtx()->attrs[getCtx()->id("step")] = std::string("place");
|
|
|
|
archInfoToAttributes();
|
2021-03-25 02:07:45 +08:00
|
|
|
|
2021-07-09 21:40:06 +08:00
|
|
|
// Print site LUT mapping caching stats
|
2021-07-22 20:07:35 +08:00
|
|
|
if (!getCtx()->arch_args.disable_lut_mapping_cache) {
|
|
|
|
log_info("Site LUT mapping cache stats:\n");
|
|
|
|
log_info(" miss ratio: %.1f%%\n", getCtx()->site_lut_mapping_cache.getMissRatio() * 100.0f);
|
|
|
|
log_info(" peak size : %zuMB (%zu items)\n", getCtx()->site_lut_mapping_cache.getSizeMB(),
|
|
|
|
getCtx()->site_lut_mapping_cache.getCount());
|
|
|
|
}
|
2021-07-09 21:40:06 +08:00
|
|
|
|
2021-03-25 02:07:45 +08:00
|
|
|
getCtx()->check();
|
|
|
|
|
2021-02-06 06:18:38 +08:00
|
|
|
return true;
|
2021-01-27 02:05:23 +08:00
|
|
|
}
|
|
|
|
|
2021-03-25 02:07:45 +08:00
|
|
|
static void prepare_sites_for_routing(Context *ctx)
|
2021-01-27 02:05:23 +08:00
|
|
|
{
|
2021-03-24 07:53:42 +08:00
|
|
|
// Reset site routing and remove masked cell pins from previous router run
|
|
|
|
// (if any).
|
2021-03-25 02:07:45 +08:00
|
|
|
ctx->remove_site_routing();
|
2021-03-24 07:53:42 +08:00
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
// Re-map BEL pins with constant pins
|
2021-03-25 02:07:45 +08:00
|
|
|
for (BelId bel : ctx->getBels()) {
|
|
|
|
CellInfo *cell = ctx->getBoundBelCell(bel);
|
2021-02-24 05:35:45 +08:00
|
|
|
if (cell != nullptr && cell->cell_mapping != -1) {
|
2021-03-25 02:07:45 +08:00
|
|
|
ctx->map_cell_pins(cell, cell->cell_mapping, /*bind_constants=*/true);
|
2021-02-24 05:35:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-01 18:08:36 +08:00
|
|
|
// Clear the site routing cache. This is because routing at this stage is done with the extra constraint of blocked
|
|
|
|
// pins to ensure a routeable pin choice.
|
|
|
|
ctx->site_routing_cache.clear();
|
|
|
|
|
2021-07-09 21:40:06 +08:00
|
|
|
// Clear the LUT mapping cache
|
|
|
|
ctx->site_lut_mapping_cache.clear();
|
|
|
|
|
2021-03-25 02:07:45 +08:00
|
|
|
// Have site router bind site routing (via bindPip and bindWire).
|
|
|
|
// This is important so that the pseudo pips are correctly blocked prior
|
|
|
|
// to handing the design to the generalized router algorithms.
|
|
|
|
for (auto &tile_pair : ctx->tileStatus) {
|
2021-03-20 09:26:00 +08:00
|
|
|
for (auto &site_router : tile_pair.second.sites) {
|
|
|
|
if (site_router.cells_in_site.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-25 02:07:45 +08:00
|
|
|
site_router.bindSiteRouting(ctx);
|
2021-03-20 09:26:00 +08:00
|
|
|
}
|
2021-04-02 04:18:07 +08:00
|
|
|
|
|
|
|
tile_pair.second.pseudo_pip_model.prepare_for_routing(ctx, tile_pair.second.sites);
|
2021-03-20 09:26:00 +08:00
|
|
|
}
|
2021-03-20 09:10:30 +08:00
|
|
|
|
2021-02-25 06:02:21 +08:00
|
|
|
// Fixup LUT vcc pins.
|
2021-03-25 07:25:15 +08:00
|
|
|
IdString vcc_net_name(ctx->chip_info->constants->vcc_net_name);
|
2022-04-28 23:18:26 +08:00
|
|
|
IdString gnd_net_name(ctx->chip_info->constants->gnd_net_name);
|
|
|
|
|
|
|
|
IdString const_net_name(ctx->chip_info->constants->best_constant_net);
|
2022-05-12 17:55:16 +08:00
|
|
|
NPNR_ASSERT(const_net_name == IdString() || const_net_name == vcc_net_name || const_net_name == gnd_net_name);
|
|
|
|
|
|
|
|
// FIXME: Use VCC if the architecture does not device the best constant
|
|
|
|
if (const_net_name == IdString()) {
|
|
|
|
const_net_name = vcc_net_name;
|
|
|
|
}
|
2022-04-28 23:18:26 +08:00
|
|
|
|
2021-03-25 07:25:15 +08:00
|
|
|
for (BelId bel : ctx->getBels()) {
|
|
|
|
CellInfo *cell = ctx->getBoundBelCell(bel);
|
2021-02-25 06:02:21 +08:00
|
|
|
if (cell == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-04-28 23:18:26 +08:00
|
|
|
for (const auto &it : cell->lut_cell.pin_connections) {
|
|
|
|
const auto &bel_pin = it.first;
|
|
|
|
const auto &conn = it.second;
|
|
|
|
|
|
|
|
// Connected to an active signal or unconnected
|
|
|
|
if (conn == LutCell::PinConnection::Signal || conn == LutCell::PinConnection::Unconnected) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-02-25 06:02:21 +08:00
|
|
|
|
2021-04-09 17:23:56 +08:00
|
|
|
// We can't rely on bel pins not clashing with cell names (for Xilinx they use different naming schemes, for
|
|
|
|
// Nexus they are the same) so add a prefix to the bel pin name to disambiguate it
|
2022-08-10 17:57:17 +08:00
|
|
|
IdString cell_pin = ctx->idf("%s_PHYS", ctx->nameOf(bel_pin));
|
2021-04-09 17:23:56 +08:00
|
|
|
|
2021-02-25 06:02:21 +08:00
|
|
|
PortInfo port_info;
|
2021-04-09 17:23:56 +08:00
|
|
|
port_info.name = cell_pin;
|
2021-02-25 06:02:21 +08:00
|
|
|
port_info.type = PORT_IN;
|
|
|
|
port_info.net = nullptr;
|
|
|
|
|
2021-03-20 09:10:30 +08:00
|
|
|
#ifdef DEBUG_LUT_MAPPING
|
2021-03-25 07:25:15 +08:00
|
|
|
if (ctx->verbose) {
|
2022-04-28 23:18:26 +08:00
|
|
|
log_info("%s must be tied to %s, tying now\n", ctx->nameOfWire(lut_pin_wire),
|
|
|
|
LutCell::nameOfPinConnection(conn).c_str());
|
2021-03-20 09:10:30 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-04-28 23:18:26 +08:00
|
|
|
IdString tie_net_name;
|
|
|
|
switch (conn) {
|
|
|
|
case LutCell::PinConnection::Vcc:
|
|
|
|
tie_net_name = vcc_net_name;
|
|
|
|
break;
|
|
|
|
case LutCell::PinConnection::Gnd:
|
|
|
|
tie_net_name = gnd_net_name;
|
|
|
|
break;
|
|
|
|
case LutCell::PinConnection::Const:
|
|
|
|
tie_net_name = const_net_name;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Should never happen
|
|
|
|
NPNR_ASSERT_FALSE(
|
|
|
|
stringf("Invalid LUT cell pin connection '%s'", LutCell::nameOfPinConnection(conn).c_str())
|
|
|
|
.c_str());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-04-09 17:23:56 +08:00
|
|
|
auto result = cell->ports.emplace(cell_pin, port_info);
|
2021-02-25 06:02:21 +08:00
|
|
|
if (result.second) {
|
2021-04-09 17:23:56 +08:00
|
|
|
cell->cell_bel_pins[cell_pin].push_back(bel_pin);
|
2022-04-28 23:18:26 +08:00
|
|
|
ctx->connectPort(tie_net_name, cell->name, cell_pin);
|
2021-04-09 17:23:56 +08:00
|
|
|
cell->const_ports.emplace(cell_pin);
|
2021-02-25 06:02:21 +08:00
|
|
|
} else {
|
2022-04-28 23:18:26 +08:00
|
|
|
NPNR_ASSERT(result.first->second.net == ctx->getNetByAlias(tie_net_name));
|
2021-04-09 17:23:56 +08:00
|
|
|
auto result2 = cell->cell_bel_pins.emplace(cell_pin, std::vector<IdString>({bel_pin}));
|
2021-02-25 06:02:21 +08:00
|
|
|
NPNR_ASSERT(result2.first->second.at(0) == bel_pin);
|
|
|
|
NPNR_ASSERT(result2.first->second.size() == 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-25 07:25:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Arch::route()
|
|
|
|
{
|
|
|
|
getCtx()->check();
|
|
|
|
prepare_sites_for_routing(getCtx());
|
|
|
|
getCtx()->check();
|
|
|
|
#ifdef IDEMPOTENT_CHECK
|
|
|
|
prepare_sites_for_routing(getCtx());
|
|
|
|
getCtx()->check();
|
|
|
|
#endif
|
2021-02-25 06:02:21 +08:00
|
|
|
|
2021-03-25 07:25:15 +08:00
|
|
|
std::string router = str_or_default(settings, id("router"), defaultRouter);
|
|
|
|
|
2021-04-02 06:12:53 +08:00
|
|
|
// Disallow site routing during general routing. This is because
|
|
|
|
// "prepare_sites_for_routing" has already assigned routing for all sites
|
|
|
|
// in the design, and if the router wants to route-thru a site, it *MUST*
|
|
|
|
// use a pseudo-pip.
|
|
|
|
//
|
|
|
|
// It is not legal in the FPGA interchange to enter a site and not
|
|
|
|
// terminate at a BEL pin.
|
|
|
|
disallow_site_routing = true;
|
|
|
|
|
2021-05-04 21:07:28 +08:00
|
|
|
route_globals();
|
|
|
|
|
2021-03-25 07:25:15 +08:00
|
|
|
bool result;
|
2021-02-25 06:02:21 +08:00
|
|
|
if (router == "router1") {
|
2021-03-25 07:25:15 +08:00
|
|
|
result = router1(getCtx(), Router1Cfg(getCtx()));
|
2021-02-25 06:02:21 +08:00
|
|
|
} else if (router == "router2") {
|
|
|
|
router2(getCtx(), Router2Cfg(getCtx()));
|
2021-03-25 07:25:15 +08:00
|
|
|
result = true;
|
2021-02-25 06:02:21 +08:00
|
|
|
} else {
|
|
|
|
log_error("FPGA interchange architecture does not support router '%s'\n", router.c_str());
|
|
|
|
}
|
2021-03-25 07:25:15 +08:00
|
|
|
|
2021-04-02 06:12:53 +08:00
|
|
|
disallow_site_routing = false;
|
|
|
|
|
2021-03-25 07:25:15 +08:00
|
|
|
getCtx()->attrs[getCtx()->id("step")] = std::string("route");
|
|
|
|
archInfoToAttributes();
|
|
|
|
|
|
|
|
getCtx()->check();
|
|
|
|
|
|
|
|
// Now that routing is complete, unmask BEL pins.
|
|
|
|
unmask_bel_pins();
|
|
|
|
|
|
|
|
getCtx()->check();
|
|
|
|
|
|
|
|
return result;
|
2021-02-25 06:02:21 +08:00
|
|
|
}
|
|
|
|
|
2021-01-27 02:05:23 +08:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2021-02-04 06:48:49 +08:00
|
|
|
std::vector<GraphicElement> Arch::getDecalGraphics(DecalId decal) const { return {}; }
|
2021-01-27 02:05:23 +08:00
|
|
|
|
|
|
|
DecalXY Arch::getBelDecal(BelId bel) const
|
|
|
|
{
|
|
|
|
DecalXY decalxy;
|
|
|
|
return decalxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecalXY Arch::getWireDecal(WireId wire) const
|
|
|
|
{
|
|
|
|
DecalXY decalxy;
|
|
|
|
return decalxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecalXY Arch::getPipDecal(PipId pip) const { return {}; };
|
|
|
|
|
|
|
|
DecalXY Arch::getGroupDecal(GroupId pip) const { return {}; };
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2021-02-08 18:41:03 +08:00
|
|
|
delay_t Arch::estimateDelay(WireId src, WireId dst) const
|
2021-02-02 06:26:57 +08:00
|
|
|
{
|
2021-03-23 08:46:00 +08:00
|
|
|
#ifdef USE_LOOKAHEAD
|
|
|
|
return lookahead.estimateDelay(getCtx(), src, dst);
|
|
|
|
#else
|
2021-04-03 07:23:29 +08:00
|
|
|
// Note: Something is better than nothing when USE_LOOKAHEAD is not
|
|
|
|
// defined.
|
|
|
|
int src_tile = src.tile == -1 ? chip_info->nodes[src.index].tile_wires[0].tile : src.tile;
|
|
|
|
int dst_tile = dst.tile == -1 ? chip_info->nodes[dst.index].tile_wires[0].tile : dst.tile;
|
|
|
|
|
|
|
|
int src_x, src_y;
|
|
|
|
get_tile_x_y(src_tile, &src_x, &src_y);
|
|
|
|
|
|
|
|
int dst_x, dst_y;
|
|
|
|
get_tile_x_y(dst_tile, &dst_x, &dst_y);
|
|
|
|
|
|
|
|
delay_t base = 30 * std::min(std::abs(dst_x - src_x), 18) + 10 * std::max(std::abs(dst_x - src_x) - 18, 0) +
|
|
|
|
60 * std::min(std::abs(dst_y - src_y), 6) + 20 * std::max(std::abs(dst_y - src_y) - 6, 0) + 300;
|
|
|
|
|
|
|
|
base = (base * 3) / 2;
|
|
|
|
return base;
|
2021-03-23 08:46:00 +08:00
|
|
|
#endif
|
2021-02-02 06:26:57 +08:00
|
|
|
}
|
|
|
|
|
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-02-02 06:26:57 +08:00
|
|
|
{
|
|
|
|
// FIXME: Implement when adding timing-driven place and route.
|
2021-12-20 00:41:34 +08:00
|
|
|
NPNR_UNUSED(src_pin);
|
|
|
|
NPNR_UNUSED(dst_pin);
|
2021-02-24 05:35:45 +08:00
|
|
|
int src_x, src_y;
|
2021-12-20 00:41:34 +08:00
|
|
|
get_tile_x_y(src_bel.tile, &src_x, &src_y);
|
2021-02-24 05:35:45 +08:00
|
|
|
|
|
|
|
int dst_x, dst_y;
|
2021-12-20 00:41:34 +08:00
|
|
|
get_tile_x_y(dst_bel.tile, &dst_x, &dst_y);
|
2021-02-24 05:35:45 +08:00
|
|
|
|
|
|
|
delay_t base = 30 * std::min(std::abs(dst_x - src_x), 18) + 10 * std::max(std::abs(dst_x - src_x) - 18, 0) +
|
|
|
|
60 * std::min(std::abs(dst_y - src_y), 6) + 20 * std::max(std::abs(dst_y - src_y) - 6, 0) + 300;
|
|
|
|
|
|
|
|
base = (base * 3) / 2;
|
|
|
|
return base;
|
2021-02-02 06:26:57 +08:00
|
|
|
}
|
|
|
|
|
2021-02-19 18:39:57 +08:00
|
|
|
bool Arch::getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, DelayQuad &delay) const
|
2021-01-27 02:05:23 +08:00
|
|
|
{
|
2021-01-27 06:45:54 +08:00
|
|
|
// FIXME: Implement when adding timing-driven place and route.
|
2021-01-27 02:05:23 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimingPortClass Arch::getPortTimingClass(const CellInfo *cell, IdString port, int &clockInfoCount) const
|
|
|
|
{
|
2021-01-27 06:45:54 +08:00
|
|
|
// FIXME: Implement when adding timing-driven place and route.
|
2021-01-27 02:05:23 +08:00
|
|
|
return TMG_IGNORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimingClockingInfo Arch::getPortClockingInfo(const CellInfo *cell, IdString port, int index) const
|
|
|
|
{
|
2021-01-27 06:45:54 +08:00
|
|
|
// FIXME: Implement when adding timing-driven place and route.
|
2021-01-27 02:05:23 +08:00
|
|
|
TimingClockingInfo info;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2021-02-12 06:24:49 +08:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2021-02-13 08:12:16 +08:00
|
|
|
void Arch::read_logical_netlist(const std::string &filename)
|
|
|
|
{
|
|
|
|
FpgaInterchange::read_logical_netlist(getCtx(), filename);
|
|
|
|
}
|
|
|
|
void Arch::write_physical_netlist(const std::string &filename) const
|
|
|
|
{
|
|
|
|
FpgaInterchange::write_physical_netlist(getCtx(), filename);
|
|
|
|
}
|
2021-02-12 06:24:49 +08:00
|
|
|
|
2021-02-13 00:14:27 +08:00
|
|
|
void Arch::parse_xdc(const std::string &filename)
|
|
|
|
{
|
2021-02-12 07:29:53 +08:00
|
|
|
TclInterp interp(getCtx());
|
|
|
|
auto result = Tcl_EvalFile(interp.interp, filename.c_str());
|
2021-02-13 00:14:27 +08:00
|
|
|
if (result != TCL_OK) {
|
|
|
|
log_error("Error in %s:%d => %s\n", filename.c_str(), Tcl_GetErrorLine(interp.interp),
|
|
|
|
Tcl_GetStringResult(interp.interp));
|
2021-02-12 07:29:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 08:12:16 +08:00
|
|
|
std::string Arch::get_part() const
|
|
|
|
{
|
|
|
|
// FIXME: Need a map between device / package / speed grade and part.
|
|
|
|
return chip_info->name.get() + args.package + "-1";
|
|
|
|
}
|
|
|
|
|
2021-02-12 06:24:49 +08:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2021-01-27 02:05:23 +08:00
|
|
|
#ifdef WITH_HEAP
|
|
|
|
const std::string Arch::defaultPlacer = "heap";
|
|
|
|
#else
|
|
|
|
const std::string Arch::defaultPlacer = "sa";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const std::vector<std::string> Arch::availablePlacers = {"sa",
|
|
|
|
#ifdef WITH_HEAP
|
|
|
|
"heap"
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::string Arch::defaultRouter = "router2";
|
|
|
|
const std::vector<std::string> Arch::availableRouters = {"router1", "router2"};
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
void Arch::map_cell_pins(CellInfo *cell, int32_t mapping, bool bind_constants)
|
2021-02-16 01:45:52 +08:00
|
|
|
{
|
|
|
|
cell->cell_mapping = mapping;
|
2021-02-25 06:02:21 +08:00
|
|
|
if (cell->lut_cell.pins.empty()) {
|
|
|
|
cell->cell_bel_pins.clear();
|
2021-03-25 02:07:45 +08:00
|
|
|
cell->masked_cell_bel_pins.clear();
|
2021-02-25 06:02:21 +08:00
|
|
|
} else {
|
|
|
|
std::vector<IdString> cell_pin_to_remove;
|
|
|
|
for (auto port_pair : cell->cell_bel_pins) {
|
|
|
|
if (!cell->lut_cell.lut_pins.count(port_pair.first)) {
|
|
|
|
cell_pin_to_remove.push_back(port_pair.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (IdString cell_pin : cell_pin_to_remove) {
|
|
|
|
NPNR_ASSERT(cell->cell_bel_pins.erase(cell_pin));
|
|
|
|
}
|
|
|
|
}
|
2021-03-25 02:07:45 +08:00
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
for (IdString const_port : cell->const_ports) {
|
2021-03-25 02:07:45 +08:00
|
|
|
disconnectPort(cell->name, const_port);
|
2021-02-24 05:35:45 +08:00
|
|
|
NPNR_ASSERT(cell->ports.erase(const_port));
|
|
|
|
}
|
2021-02-16 01:45:52 +08:00
|
|
|
|
|
|
|
const CellBelMapPOD &cell_pin_map = chip_info->cell_map->cell_bel_map[mapping];
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
IdString gnd_net_name(chip_info->constants->gnd_net_name);
|
|
|
|
IdString vcc_net_name(chip_info->constants->vcc_net_name);
|
|
|
|
|
2021-02-16 01:45:52 +08:00
|
|
|
for (const auto &pin_map : cell_pin_map.common_pins) {
|
|
|
|
IdString cell_pin(pin_map.cell_pin);
|
|
|
|
IdString bel_pin(pin_map.bel_pin);
|
|
|
|
|
2021-02-25 06:02:21 +08:00
|
|
|
// Skip assigned LUT pins, as they are already mapped!
|
|
|
|
if (cell->lut_cell.lut_pins.count(cell_pin) && cell->cell_bel_pins.count(cell_pin)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-24 00:37:22 +08:00
|
|
|
if (cell_pin == id_GND) {
|
2021-02-24 05:35:45 +08:00
|
|
|
if (bind_constants) {
|
|
|
|
PortInfo port_info;
|
|
|
|
port_info.name = bel_pin;
|
|
|
|
port_info.type = PORT_IN;
|
|
|
|
port_info.net = nullptr;
|
2021-02-20 09:28:25 +08:00
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
auto result = cell->ports.emplace(bel_pin, port_info);
|
|
|
|
if (result.second) {
|
|
|
|
cell->cell_bel_pins[bel_pin].push_back(bel_pin);
|
|
|
|
connectPort(gnd_net_name, cell->name, bel_pin);
|
|
|
|
cell->const_ports.emplace(bel_pin);
|
|
|
|
} else {
|
|
|
|
NPNR_ASSERT(result.first->second.net == getNetByAlias(gnd_net_name));
|
|
|
|
auto result2 = cell->cell_bel_pins.emplace(bel_pin, std::vector<IdString>({bel_pin}));
|
|
|
|
NPNR_ASSERT(result2.first->second.at(0) == bel_pin);
|
|
|
|
NPNR_ASSERT(result2.first->second.size() == 1);
|
|
|
|
}
|
2021-02-23 01:13:44 +08:00
|
|
|
}
|
2021-02-16 01:45:52 +08:00
|
|
|
continue;
|
|
|
|
}
|
2021-02-20 09:28:25 +08:00
|
|
|
|
2021-03-24 00:37:22 +08:00
|
|
|
if (cell_pin == id_VCC) {
|
2021-02-24 05:35:45 +08:00
|
|
|
if (bind_constants) {
|
|
|
|
PortInfo port_info;
|
|
|
|
port_info.name = bel_pin;
|
|
|
|
port_info.type = PORT_IN;
|
|
|
|
port_info.net = nullptr;
|
2021-02-20 09:28:25 +08:00
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
auto result = cell->ports.emplace(bel_pin, port_info);
|
|
|
|
if (result.second) {
|
|
|
|
cell->cell_bel_pins[bel_pin].push_back(bel_pin);
|
|
|
|
connectPort(vcc_net_name, cell->name, bel_pin);
|
|
|
|
cell->const_ports.emplace(bel_pin);
|
|
|
|
} else {
|
|
|
|
NPNR_ASSERT(result.first->second.net == getNetByAlias(vcc_net_name));
|
|
|
|
auto result2 = cell->cell_bel_pins.emplace(bel_pin, std::vector<IdString>({bel_pin}));
|
|
|
|
NPNR_ASSERT(result2.first->second.at(0) == bel_pin);
|
|
|
|
NPNR_ASSERT(result2.first->second.size() == 1);
|
|
|
|
}
|
2021-02-23 01:13:44 +08:00
|
|
|
}
|
2021-02-16 01:45:52 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell->cell_bel_pins[cell_pin].push_back(bel_pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto ¶meter_pin_map : cell_pin_map.parameter_pins) {
|
|
|
|
IdString param_key(parameter_pin_map.key);
|
2021-03-23 06:55:34 +08:00
|
|
|
IdString param_value(parameter_pin_map.value);
|
2021-02-16 01:45:52 +08:00
|
|
|
|
|
|
|
auto iter = cell->params.find(param_key);
|
|
|
|
if (iter == cell->params.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-23 06:55:34 +08:00
|
|
|
if (!cell_parameters.compare_property(getCtx(), cell->type, param_key, iter->second, param_value)) {
|
2021-02-16 01:45:52 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-24 00:37:22 +08:00
|
|
|
#ifdef DEBUG_CELL_PIN_MAPPING
|
|
|
|
log_info("parameter match on param_key %s\n", param_key.c_str(this));
|
|
|
|
#endif
|
|
|
|
|
2021-02-16 01:45:52 +08:00
|
|
|
for (const auto &pin_map : parameter_pin_map.pins) {
|
|
|
|
IdString cell_pin(pin_map.cell_pin);
|
|
|
|
IdString bel_pin(pin_map.bel_pin);
|
2021-03-24 00:37:22 +08:00
|
|
|
#ifdef DEBUG_CELL_PIN_MAPPING
|
|
|
|
log_info(" %s => %s\n", cell_pin.c_str(this), bel_pin.c_str(this));
|
|
|
|
#endif
|
2021-02-16 01:45:52 +08:00
|
|
|
|
2021-02-25 06:02:21 +08:00
|
|
|
// Skip assigned LUT pins, as they are already mapped!
|
|
|
|
if (cell->lut_cell.lut_pins.count(cell_pin) && cell->cell_bel_pins.count(cell_pin)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-24 00:37:22 +08:00
|
|
|
if (cell_pin == id_GND) {
|
2021-02-24 05:35:45 +08:00
|
|
|
if (bind_constants) {
|
|
|
|
PortInfo port_info;
|
|
|
|
port_info.name = bel_pin;
|
|
|
|
port_info.type = PORT_IN;
|
2021-02-25 06:02:21 +08:00
|
|
|
port_info.net = nullptr;
|
2021-02-24 05:35:45 +08:00
|
|
|
|
|
|
|
auto result = cell->ports.emplace(bel_pin, port_info);
|
|
|
|
if (result.second) {
|
|
|
|
cell->cell_bel_pins[bel_pin].push_back(bel_pin);
|
|
|
|
connectPort(gnd_net_name, cell->name, bel_pin);
|
|
|
|
cell->const_ports.emplace(bel_pin);
|
|
|
|
} else {
|
|
|
|
NPNR_ASSERT(result.first->second.net == getNetByAlias(gnd_net_name));
|
|
|
|
auto result2 = cell->cell_bel_pins.emplace(bel_pin, std::vector<IdString>({bel_pin}));
|
|
|
|
NPNR_ASSERT(result2.first->second.at(0) == bel_pin);
|
|
|
|
NPNR_ASSERT(result2.first->second.size() == 1);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 01:45:52 +08:00
|
|
|
continue;
|
|
|
|
}
|
2021-02-20 09:28:25 +08:00
|
|
|
|
2021-03-24 00:37:22 +08:00
|
|
|
if (cell_pin == id_VCC) {
|
2021-02-24 05:35:45 +08:00
|
|
|
if (bind_constants) {
|
|
|
|
PortInfo port_info;
|
|
|
|
port_info.name = bel_pin;
|
|
|
|
port_info.type = PORT_IN;
|
2021-02-25 06:02:21 +08:00
|
|
|
port_info.net = nullptr;
|
2021-02-24 05:35:45 +08:00
|
|
|
|
|
|
|
auto result = cell->ports.emplace(bel_pin, port_info);
|
|
|
|
if (result.second) {
|
|
|
|
cell->cell_bel_pins[bel_pin].push_back(bel_pin);
|
|
|
|
connectPort(vcc_net_name, cell->name, bel_pin);
|
|
|
|
cell->const_ports.emplace(bel_pin);
|
|
|
|
} else {
|
|
|
|
NPNR_ASSERT(result.first->second.net == getNetByAlias(vcc_net_name));
|
|
|
|
auto result2 = cell->cell_bel_pins.emplace(bel_pin, std::vector<IdString>({bel_pin}));
|
|
|
|
NPNR_ASSERT(result2.first->second.at(0) == bel_pin);
|
|
|
|
NPNR_ASSERT(result2.first->second.size() == 1);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 01:45:52 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell->cell_bel_pins[cell_pin].push_back(bel_pin);
|
|
|
|
}
|
|
|
|
}
|
2021-03-24 00:37:22 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG_CELL_PIN_MAPPING
|
|
|
|
log_info("Pin mapping for cell %s (type: %s)\n", cell->name.c_str(getCtx()), cell->type.c_str(getCtx()));
|
|
|
|
for (auto &pin_pair : cell->cell_bel_pins) {
|
|
|
|
log_info(" %s =>", pin_pair.first.c_str(getCtx()));
|
|
|
|
for (IdString bel_pin : pin_pair.second) {
|
|
|
|
log(" %s", bel_pin.c_str(getCtx()));
|
|
|
|
}
|
|
|
|
log("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2021-02-16 01:45:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Arch::map_port_pins(BelId bel, CellInfo *cell) const
|
|
|
|
{
|
|
|
|
IdStringRange pins = getBelPins(bel);
|
2021-02-18 02:18:24 +08:00
|
|
|
IdString pin = get_only_value(pins);
|
|
|
|
|
2021-02-16 01:45:52 +08:00
|
|
|
NPNR_ASSERT(cell->ports.size() == 1);
|
|
|
|
cell->cell_bel_pins[cell->ports.begin()->first].clear();
|
|
|
|
cell->cell_bel_pins[cell->ports.begin()->first].push_back(pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Arch::is_net_within_site(const NetInfo &net) const
|
|
|
|
{
|
|
|
|
if (net.driver.cell == nullptr || net.driver.cell->bel == BelId()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BelId driver = net.driver.cell->bel;
|
|
|
|
int32_t site = bel_info(chip_info, driver).site;
|
|
|
|
NPNR_ASSERT(site >= 0);
|
|
|
|
|
|
|
|
for (const auto &user : net.users) {
|
|
|
|
if (user.cell == nullptr || user.cell->bel == BelId()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
BelId user_bel = user.cell->bel;
|
|
|
|
|
|
|
|
if (user_bel.tile != driver.tile) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bel_info(chip_info, user_bel).site != site) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-17 06:51:25 +08:00
|
|
|
size_t Arch::get_cell_type_index(IdString cell_type) const
|
|
|
|
{
|
|
|
|
const CellMapPOD &cell_map = *chip_info->cell_map;
|
|
|
|
int cell_offset = cell_type.index - cell_map.cell_names[0];
|
2021-02-17 09:25:16 +08:00
|
|
|
if ((cell_offset < 0 || cell_offset >= cell_map.cell_names.ssize())) {
|
2021-02-17 06:51:25 +08:00
|
|
|
log_error("Cell %s is not a placable element.\n", cell_type.c_str(this));
|
|
|
|
}
|
|
|
|
NPNR_ASSERT(cell_map.cell_names[cell_offset] == cell_type.index);
|
|
|
|
|
|
|
|
return cell_offset;
|
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
void Arch::merge_constant_nets()
|
|
|
|
{
|
|
|
|
NetInfo *gnd_net = nullptr;
|
|
|
|
NetInfo *vcc_net = nullptr;
|
2021-02-20 09:28:25 +08:00
|
|
|
|
|
|
|
bool need_gnd_source = false;
|
|
|
|
bool need_vcc_source = false;
|
|
|
|
|
|
|
|
IdString gnd_net_name(chip_info->constants->gnd_net_name);
|
|
|
|
IdString gnd_cell_type(chip_info->constants->gnd_cell_name);
|
|
|
|
IdString gnd_cell_port(chip_info->constants->gnd_cell_port);
|
|
|
|
|
|
|
|
auto gnd_iter = nets.find(gnd_net_name);
|
2021-02-24 05:35:45 +08:00
|
|
|
if (gnd_iter != nets.end()) {
|
2021-02-20 09:28:25 +08:00
|
|
|
NPNR_ASSERT(gnd_iter->second->driver.cell != nullptr);
|
|
|
|
NPNR_ASSERT(gnd_iter->second->driver.cell->type == gnd_cell_type);
|
|
|
|
NPNR_ASSERT(gnd_iter->second->driver.port == gnd_cell_port);
|
|
|
|
|
|
|
|
gnd_net = gnd_iter->second.get();
|
|
|
|
} else {
|
|
|
|
gnd_net = createNet(gnd_net_name);
|
|
|
|
need_gnd_source = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
IdString vcc_net_name(chip_info->constants->vcc_net_name);
|
|
|
|
IdString vcc_cell_type(chip_info->constants->vcc_cell_name);
|
|
|
|
IdString vcc_cell_port(chip_info->constants->vcc_cell_port);
|
|
|
|
|
|
|
|
auto vcc_iter = nets.find(vcc_net_name);
|
2021-02-24 05:35:45 +08:00
|
|
|
if (vcc_iter != nets.end()) {
|
2021-02-20 09:28:25 +08:00
|
|
|
NPNR_ASSERT(vcc_iter->second->driver.cell != nullptr);
|
|
|
|
NPNR_ASSERT(vcc_iter->second->driver.cell->type == vcc_cell_type);
|
|
|
|
NPNR_ASSERT(vcc_iter->second->driver.port == vcc_cell_port);
|
|
|
|
|
|
|
|
vcc_net = vcc_iter->second.get();
|
|
|
|
} else {
|
|
|
|
vcc_net = createNet(vcc_net_name);
|
|
|
|
need_vcc_source = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<IdString> other_gnd_nets;
|
|
|
|
std::vector<IdString> other_vcc_nets;
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
for (auto &net_pair : nets) {
|
|
|
|
if (net_pair.first == gnd_net_name) {
|
2021-02-20 09:28:25 +08:00
|
|
|
NPNR_ASSERT(net_pair.second.get() == gnd_net);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
if (net_pair.first == vcc_net_name) {
|
2021-02-20 09:28:25 +08:00
|
|
|
NPNR_ASSERT(net_pair.second.get() == vcc_net);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NetInfo *net = net_pair.second.get();
|
2021-02-24 05:35:45 +08:00
|
|
|
if (net->driver.cell == nullptr) {
|
2021-02-20 09:28:25 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
if (net->driver.cell->type == gnd_cell_type) {
|
2021-02-20 09:28:25 +08:00
|
|
|
NPNR_ASSERT(net->driver.port == gnd_cell_port);
|
|
|
|
|
|
|
|
other_gnd_nets.push_back(net_pair.first);
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
if (need_gnd_source) {
|
2021-02-20 09:28:25 +08:00
|
|
|
IdString driver_cell = net->driver.cell->name;
|
|
|
|
disconnectPort(driver_cell, gnd_cell_port);
|
|
|
|
connectPort(gnd_net_name, driver_cell, gnd_cell_port);
|
|
|
|
need_gnd_source = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPNR_ASSERT(net->driver.port == gnd_cell_port);
|
2022-02-26 23:17:46 +08:00
|
|
|
indexed_store<PortRef> users_copy = net->users;
|
2021-02-24 05:35:45 +08:00
|
|
|
for (const PortRef &port_ref : users_copy) {
|
2021-02-20 09:28:25 +08:00
|
|
|
IdString cell = port_ref.cell->name;
|
|
|
|
disconnectPort(cell, port_ref.port);
|
|
|
|
connectPort(gnd_net_name, cell, port_ref.port);
|
|
|
|
}
|
2021-02-23 01:13:44 +08:00
|
|
|
|
|
|
|
continue;
|
2021-02-20 09:28:25 +08:00
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
if (net->driver.cell->type == vcc_cell_type) {
|
2021-02-20 09:28:25 +08:00
|
|
|
NPNR_ASSERT(net->driver.port == vcc_cell_port);
|
|
|
|
|
|
|
|
other_vcc_nets.push_back(net_pair.first);
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
if (need_vcc_source) {
|
2021-02-20 09:28:25 +08:00
|
|
|
IdString driver_cell = net->driver.cell->name;
|
|
|
|
disconnectPort(driver_cell, vcc_cell_port);
|
|
|
|
connectPort(vcc_net_name, driver_cell, vcc_cell_port);
|
|
|
|
need_vcc_source = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPNR_ASSERT(net->driver.port == vcc_cell_port);
|
2022-02-26 23:17:46 +08:00
|
|
|
indexed_store<PortRef> users_copy = net->users;
|
2021-02-24 05:35:45 +08:00
|
|
|
for (const PortRef &port_ref : users_copy) {
|
2021-02-20 09:28:25 +08:00
|
|
|
IdString cell = port_ref.cell->name;
|
|
|
|
disconnectPort(cell, port_ref.port);
|
|
|
|
connectPort(vcc_net_name, cell, port_ref.port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
for (IdString other_gnd_net : other_gnd_nets) {
|
|
|
|
NetInfo *net = getNetByAlias(other_gnd_net);
|
2021-02-20 09:28:25 +08:00
|
|
|
NPNR_ASSERT(net->users.empty());
|
2021-02-24 05:35:45 +08:00
|
|
|
if (net->driver.cell) {
|
2021-02-23 01:13:44 +08:00
|
|
|
PortRef driver = net->driver;
|
|
|
|
IdString cell_to_remove = driver.cell->name;
|
|
|
|
disconnectPort(driver.cell->name, driver.port);
|
|
|
|
NPNR_ASSERT(cells.erase(cell_to_remove));
|
|
|
|
}
|
2021-02-20 09:28:25 +08:00
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
for (IdString other_vcc_net : other_vcc_nets) {
|
|
|
|
NetInfo *net = getNetByAlias(other_vcc_net);
|
2021-02-20 09:28:25 +08:00
|
|
|
NPNR_ASSERT(net->users.empty());
|
2021-02-24 05:35:45 +08:00
|
|
|
if (net->driver.cell) {
|
2021-02-23 01:13:44 +08:00
|
|
|
PortRef driver = net->driver;
|
|
|
|
IdString cell_to_remove = driver.cell->name;
|
|
|
|
disconnectPort(driver.cell->name, driver.port);
|
|
|
|
NPNR_ASSERT(cells.erase(cell_to_remove));
|
|
|
|
}
|
2021-02-20 09:28:25 +08:00
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
for (IdString other_gnd_net : other_gnd_nets) {
|
2021-02-20 09:28:25 +08:00
|
|
|
NPNR_ASSERT(nets.erase(other_gnd_net));
|
|
|
|
gnd_net->aliases.push_back(other_gnd_net);
|
|
|
|
net_aliases[other_gnd_net] = gnd_net_name;
|
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
for (IdString other_vcc_net : other_vcc_nets) {
|
2021-02-20 09:28:25 +08:00
|
|
|
NPNR_ASSERT(nets.erase(other_vcc_net));
|
|
|
|
vcc_net->aliases.push_back(other_vcc_net);
|
|
|
|
net_aliases[other_vcc_net] = vcc_net_name;
|
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
if (need_gnd_source) {
|
|
|
|
CellInfo *gnd_cell = createCell(gnd_cell_type, gnd_cell_type);
|
2021-02-20 09:28:25 +08:00
|
|
|
gnd_cell->addOutput(gnd_cell_port);
|
|
|
|
connectPort(gnd_net_name, gnd_cell_type, gnd_cell_port);
|
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
if (need_vcc_source) {
|
|
|
|
CellInfo *vcc_cell = createCell(vcc_cell_type, vcc_cell_type);
|
2021-02-20 09:28:25 +08:00
|
|
|
vcc_cell->addOutput(vcc_cell_port);
|
|
|
|
connectPort(vcc_net_name, vcc_cell_type, vcc_cell_port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-24 05:35:45 +08:00
|
|
|
const std::vector<IdString> &Arch::getBelPinsForCellPin(const CellInfo *cell_info, IdString pin) const
|
|
|
|
{
|
|
|
|
auto iter = cell_info->cell_bel_pins.find(pin);
|
|
|
|
if (iter == cell_info->cell_bel_pins.end()) {
|
|
|
|
return no_pins;
|
|
|
|
} else {
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Arch::report_invalid_bel(BelId bel, CellInfo *cell) const
|
|
|
|
{
|
|
|
|
int32_t mapping = bel_info(chip_info, bel).pin_map[get_cell_type_index(cell->type)];
|
|
|
|
NPNR_ASSERT(mapping < 0);
|
|
|
|
log_error("Cell %s (%s) cannot be placed at BEL %s (mapping %d)\n", cell->name.c_str(this), cell->type.c_str(this),
|
|
|
|
nameOfBel(bel), mapping);
|
|
|
|
}
|
|
|
|
|
2021-02-25 06:02:21 +08:00
|
|
|
void Arch::decode_lut_cells()
|
|
|
|
{
|
|
|
|
for (auto &cell_pair : cells) {
|
|
|
|
CellInfo *cell = cell_pair.second.get();
|
|
|
|
auto iter = lut_cells.find(cell->type);
|
|
|
|
if (iter == lut_cells.end()) {
|
|
|
|
cell->lut_cell.pins.clear();
|
|
|
|
cell->lut_cell.equation.clear();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LutCellPOD &lut_cell = *iter->second;
|
|
|
|
|
|
|
|
cell->lut_cell.pins.reserve(lut_cell.input_pins.size());
|
|
|
|
for (uint32_t pin : lut_cell.input_pins) {
|
|
|
|
cell->lut_cell.pins.push_back(IdString(pin));
|
|
|
|
cell->lut_cell.lut_pins.emplace(IdString(pin));
|
|
|
|
}
|
|
|
|
|
|
|
|
IdString equation_parameter(lut_cell.parameter);
|
|
|
|
const Property &equation = cell->params.at(equation_parameter);
|
|
|
|
cell->lut_cell.equation.resize(1 << cell->lut_cell.pins.size());
|
2021-03-23 06:55:34 +08:00
|
|
|
|
|
|
|
cell->lut_cell.equation = cell_parameters.parse_int_like(getCtx(), cell->type, equation_parameter, equation);
|
2021-02-25 06:02:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-20 09:10:30 +08:00
|
|
|
void Arch::remove_pip_pseudo_wires(PipId pip, NetInfo *net)
|
|
|
|
{
|
|
|
|
WireId wire;
|
|
|
|
wire.tile = pip.tile;
|
|
|
|
const PipInfoPOD &pip_data = pip_info(chip_info, pip);
|
|
|
|
for (int32_t wire_index : pip_data.pseudo_cell_wires) {
|
|
|
|
NPNR_ASSERT(wire_index != -1);
|
|
|
|
wire.index = wire_index;
|
|
|
|
|
|
|
|
auto iter = wire_to_net.find(wire);
|
|
|
|
NPNR_ASSERT(iter != wire_to_net.end());
|
|
|
|
// This wire better already have been assigned to this net!
|
|
|
|
if (iter->second != net) {
|
|
|
|
if (iter->second == nullptr) {
|
|
|
|
log_error("Wire %s part of pseudo pip %s but net is null\n", nameOfWire(wire), nameOfPip(pip));
|
|
|
|
} else {
|
|
|
|
log_error("Wire %s part of pseudo pip %s but net is '%s' instead of net '%s'\n", nameOfWire(wire),
|
|
|
|
nameOfPip(pip), iter->second->name.c_str(this), net->name.c_str(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto wire_iter = net->wires.find(wire);
|
|
|
|
if (wire_iter != net->wires.end()) {
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("Removing %s from net %s, but it's in net wires\n", nameOfWire(wire), net->name.c_str(this));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// This wire is part of net->wires, make sure it has no pip,
|
|
|
|
// but leave it alone. It will get cleaned up via
|
|
|
|
// unbindWire.
|
|
|
|
} else {
|
|
|
|
// This wire is not in net->wires, update wire_to_net.
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("Removing %s from net %s in remove_pip_pseudo_wires\n", nameOfWire(wire),
|
|
|
|
net->name.c_str(this));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
iter->second = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2021-04-02 04:18:07 +08:00
|
|
|
|
2021-04-12 17:26:39 +08:00
|
|
|
if (pip_data.pseudo_cell_wires.size() > 0) {
|
2021-04-02 04:18:07 +08:00
|
|
|
get_tile_status(pip.tile).pseudo_pip_model.unbindPip(getCtx(), pip);
|
|
|
|
}
|
2021-03-20 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2021-03-20 08:35:29 +08:00
|
|
|
void Arch::assign_net_to_wire(WireId wire, NetInfo *net, const char *src, bool require_empty)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("Assigning wire %s to %s from %s\n", nameOfWire(wire), net->name.c_str(this), src);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
NPNR_ASSERT(net != nullptr);
|
|
|
|
auto result = wire_to_net.emplace(wire, net);
|
|
|
|
if (!result.second) {
|
|
|
|
// This wire was already in the map, make sure this assignment was
|
|
|
|
// legal.
|
|
|
|
if (require_empty) {
|
|
|
|
NPNR_ASSERT(result.first->second == nullptr);
|
|
|
|
} else {
|
|
|
|
NPNR_ASSERT(result.first->second == nullptr || result.first->second == net);
|
|
|
|
}
|
|
|
|
result.first->second = net;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Arch::unassign_wire(WireId wire)
|
|
|
|
{
|
|
|
|
NPNR_ASSERT(wire != WireId());
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("unassign_wire %s\n", nameOfWire(wire));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
auto iter = wire_to_net.find(wire);
|
|
|
|
NPNR_ASSERT(iter != wire_to_net.end());
|
|
|
|
|
|
|
|
NetInfo *net = iter->second;
|
|
|
|
NPNR_ASSERT(net != nullptr);
|
|
|
|
|
|
|
|
auto &net_wires = net->wires;
|
|
|
|
auto it = net_wires.find(wire);
|
|
|
|
NPNR_ASSERT(it != net_wires.end());
|
|
|
|
|
|
|
|
auto pip = it->second.pip;
|
|
|
|
if (pip != PipId()) {
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("Removing pip %s because it was used to reach wire %s\n", nameOfPip(pip), nameOfWire(wire));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
auto pip_iter = pip_to_net.find(pip);
|
|
|
|
NPNR_ASSERT(pip_iter != pip_to_net.end());
|
|
|
|
NPNR_ASSERT(pip_iter->second == net);
|
|
|
|
pip_iter->second = nullptr;
|
2021-03-20 09:10:30 +08:00
|
|
|
remove_pip_pseudo_wires(pip, net);
|
2021-03-20 08:35:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
net_wires.erase(it);
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("Removing %s from net %s in unassign_wire\n", nameOfWire(wire), net->name.c_str(this));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
iter->second = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Arch::unbindPip(PipId pip)
|
|
|
|
{
|
|
|
|
NPNR_ASSERT(pip != PipId());
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("unbindPip %s\n", nameOfPip(pip));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
auto pip_iter = pip_to_net.find(pip);
|
|
|
|
NPNR_ASSERT(pip_iter != pip_to_net.end());
|
|
|
|
NetInfo *net = pip_iter->second;
|
|
|
|
NPNR_ASSERT(net != nullptr);
|
|
|
|
|
|
|
|
WireId dst = getPipDstWire(pip);
|
|
|
|
auto wire_iter = wire_to_net.find(dst);
|
|
|
|
NPNR_ASSERT(wire_iter != wire_to_net.end());
|
2021-03-20 09:10:30 +08:00
|
|
|
NPNR_ASSERT(wire_iter->second == net);
|
|
|
|
|
|
|
|
remove_pip_pseudo_wires(pip, net);
|
2021-03-20 08:35:29 +08:00
|
|
|
|
|
|
|
// Clear the net now.
|
|
|
|
pip_iter->second = nullptr;
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("Removing %s from net %s in unbindPip\n", nameOfWire(dst), net->name.c_str(this));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
wire_iter->second = nullptr;
|
|
|
|
NPNR_ASSERT(net->wires.erase(dst) == 1);
|
|
|
|
|
|
|
|
refreshUiPip(pip);
|
|
|
|
refreshUiWire(dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Arch::bindPip(PipId pip, NetInfo *net, PlaceStrength strength)
|
|
|
|
{
|
|
|
|
NPNR_ASSERT(pip != PipId());
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("bindPip %s (%d/%d) to net %s\n", nameOfPip(pip), pip.tile, pip.index, net->name.c_str(this));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
WireId dst = getPipDstWire(pip);
|
|
|
|
NPNR_ASSERT(dst != WireId());
|
|
|
|
|
|
|
|
{
|
|
|
|
// Pip should not already be assigned to anything.
|
|
|
|
auto result = pip_to_net.emplace(pip, net);
|
|
|
|
if (!result.second) {
|
|
|
|
NPNR_ASSERT(result.first->second == nullptr);
|
|
|
|
result.first->second = net;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assign_net_to_wire(dst, net, "bindPip", /*require_empty=*/true);
|
2021-03-20 09:10:30 +08:00
|
|
|
assign_pip_pseudo_wires(pip, net);
|
2021-03-20 08:35:29 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
auto result = net->wires.emplace(dst, PipMap{pip, strength});
|
|
|
|
NPNR_ASSERT(result.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshUiPip(pip);
|
|
|
|
refreshUiWire(dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Arch::bindWire(WireId wire, NetInfo *net, PlaceStrength strength)
|
|
|
|
{
|
|
|
|
NPNR_ASSERT(wire != WireId());
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("bindWire %s to net %s\n", nameOfWire(wire), net->name.c_str(this));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
assign_net_to_wire(wire, net, "bindWire", /*require_empty=*/true);
|
|
|
|
auto &pip_map = net->wires[wire];
|
|
|
|
pip_map.pip = PipId();
|
|
|
|
pip_map.strength = strength;
|
|
|
|
refreshUiWire(wire);
|
|
|
|
}
|
|
|
|
|
2022-12-02 21:20:39 +08:00
|
|
|
bool Arch::checkPipAvailForNet(PipId pip, const NetInfo *net) const
|
2021-03-20 08:35:29 +08:00
|
|
|
{
|
|
|
|
NPNR_ASSERT(pip != PipId());
|
|
|
|
auto pip_iter = pip_to_net.find(pip);
|
|
|
|
if (pip_iter != pip_to_net.end() && pip_iter->second != nullptr) {
|
|
|
|
bool pip_blocked = false;
|
|
|
|
if (net == nullptr) {
|
|
|
|
pip_blocked = true;
|
|
|
|
} else {
|
|
|
|
if (net != pip_iter->second) {
|
|
|
|
pip_blocked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pip_blocked) {
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("Pip %s (%d/%d) is not available, tied to net %s\n", getCtx()->nameOfPip(pip), pip.tile,
|
|
|
|
pip.index, pip_iter->second->name.c_str(getCtx()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
NPNR_ASSERT(pip_iter->first == pip);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-20 09:10:30 +08:00
|
|
|
WireId src = getPipSrcWire(pip);
|
2021-03-20 08:35:29 +08:00
|
|
|
WireId dst = getPipDstWire(pip);
|
|
|
|
|
|
|
|
auto wire_iter = wire_to_net.find(dst);
|
|
|
|
if (wire_iter != wire_to_net.end()) {
|
|
|
|
NetInfo *wire_net = wire_iter->second;
|
|
|
|
if (wire_net != nullptr) {
|
|
|
|
auto net_iter = wire_net->wires.find(dst);
|
|
|
|
if (net_iter != wire_net->wires.end()) {
|
|
|
|
if (net == nullptr) {
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("Pip %s (%d/%d) is not available, dst wire %s is tied to net %s\n",
|
|
|
|
getCtx()->nameOfPip(pip), pip.tile, pip.index, getCtx()->nameOfWire(dst),
|
|
|
|
wire_net->name.c_str(getCtx()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// dst is already driven in this net, do not allow!
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose && net_iter->second.pip != pip) {
|
|
|
|
log_info("Pip %s (%d/%d) is not available, dst wire %s is tied to net %s\n",
|
|
|
|
getCtx()->nameOfPip(pip), pip.tile, pip.index, getCtx()->nameOfWire(dst),
|
|
|
|
wire_net->name.c_str(getCtx()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// This pip is available if this pip is already bound to
|
|
|
|
// this.
|
|
|
|
return net_iter->second.pip == pip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 22:02:22 +08:00
|
|
|
// If this pip is a route-though, make sure all of the route-though are valid.
|
|
|
|
// A route-through is valid if:
|
|
|
|
// - none of the pseudo-pip wires are bound to a net
|
|
|
|
// - the pseudo pip wires are bound to the same net and there are no
|
|
|
|
// lut elements in the tile type: this to prevent the router from choosing
|
|
|
|
// a pseudo-pip on the same LUT and on a different input pin for the same net.
|
2021-03-30 07:19:47 +08:00
|
|
|
const TileTypeInfoPOD &tile_type = loc_info(chip_info, pip);
|
|
|
|
const PipInfoPOD &pip_data = tile_type.pip_data[pip.index];
|
2021-03-20 09:10:30 +08:00
|
|
|
WireId wire;
|
|
|
|
wire.tile = pip.tile;
|
|
|
|
for (int32_t wire_index : pip_data.pseudo_cell_wires) {
|
|
|
|
wire.index = wire_index;
|
|
|
|
NPNR_ASSERT(src != wire);
|
|
|
|
NPNR_ASSERT(dst != wire);
|
|
|
|
|
2021-07-06 17:38:08 +08:00
|
|
|
NetInfo *other_net = getConflictingWireNet(wire);
|
2021-07-15 22:02:22 +08:00
|
|
|
bool is_null_net = other_net == nullptr;
|
|
|
|
if (!is_null_net) {
|
|
|
|
bool is_same_net = other_net == net;
|
|
|
|
bool tile_has_luts = tile_type.lut_elements.size() > 0;
|
|
|
|
if (!is_same_net || tile_has_luts) {
|
2021-03-20 09:10:30 +08:00
|
|
|
#ifdef DEBUG_BINDING
|
2021-07-15 22:02:22 +08:00
|
|
|
if (getCtx()->verbose)
|
|
|
|
log_info("Pip %s is not available because wire %s is tied to a different net "
|
|
|
|
"(other net: %s - orig net: %s) or the pseudo pip may traverses LUTs\n",
|
|
|
|
getCtx()->nameOfPip(pip), getCtx()->nameOfWire(wire), other_net->name.c_str(getCtx()),
|
|
|
|
net == nullptr ? "NULL net" : net->name.c_str(getCtx()));
|
2021-03-20 09:10:30 +08:00
|
|
|
#endif
|
2021-07-15 22:02:22 +08:00
|
|
|
return false;
|
|
|
|
}
|
2021-03-20 09:10:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-13 00:25:47 +08:00
|
|
|
auto tile_status_iter = tileStatus.find(pip.tile);
|
|
|
|
|
2021-04-12 17:26:39 +08:00
|
|
|
if (pip_data.pseudo_cell_wires.size() > 0) {
|
2021-04-02 04:18:07 +08:00
|
|
|
// FIXME: This pseudo pip check is incomplete, because constraint
|
|
|
|
// failures will not be detected. However the current FPGA
|
|
|
|
// interchange schema does not provide a cell type to place.
|
2021-05-13 00:25:47 +08:00
|
|
|
if (tile_status_iter != tileStatus.end() &&
|
|
|
|
!tile_status_iter->second.pseudo_pip_model.checkPipAvail(getCtx(), pip)) {
|
|
|
|
return false;
|
2021-04-02 04:18:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-20 08:35:29 +08:00
|
|
|
if (pip_data.site != -1 && net != nullptr) {
|
|
|
|
NPNR_ASSERT(net->driver.cell != nullptr);
|
|
|
|
NPNR_ASSERT(net->driver.cell->bel != BelId());
|
|
|
|
|
2021-03-30 07:19:47 +08:00
|
|
|
auto &src_wire_data = tile_type.wire_data[pip_data.src_index];
|
|
|
|
auto &dst_wire_data = tile_type.wire_data[pip_data.dst_index];
|
|
|
|
|
2021-03-20 08:35:29 +08:00
|
|
|
bool valid_pip = false;
|
|
|
|
if (pip.tile == net->driver.cell->bel.tile) {
|
2021-05-13 00:25:47 +08:00
|
|
|
if (tile_status_iter == tileStatus.end()) {
|
|
|
|
// there is no tile status and nothing blocks the validity of this PIP
|
|
|
|
valid_pip = true;
|
|
|
|
} else {
|
|
|
|
const BelInfoPOD &bel_data = tile_type.bel_data[net->driver.cell->bel.index];
|
|
|
|
const SiteRouter &site_router = get_site_status(tile_status_iter->second, bel_data);
|
|
|
|
|
2021-05-16 23:25:05 +08:00
|
|
|
const auto &pips = site_router.valid_pips;
|
2021-05-13 00:25:47 +08:00
|
|
|
auto result = std::find(pips.begin(), pips.end(), pip);
|
|
|
|
if (result != pips.end()) {
|
2021-03-30 07:19:47 +08:00
|
|
|
valid_pip = true;
|
|
|
|
}
|
2021-03-20 08:35:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 17:26:39 +08:00
|
|
|
if (disallow_site_routing && !valid_pip) {
|
2021-04-02 06:12:53 +08:00
|
|
|
// For now, if driver is not part of this site, and
|
|
|
|
// disallow_site_routing is set, disallow the edge.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This check isn't perfect. If a driver and sink are in the
|
|
|
|
// same site, it is possible for the router to route-thru the site
|
|
|
|
// ports without hitting a sink, which is not legal in the FPGA
|
|
|
|
// interchange.
|
2021-03-20 08:35:29 +08:00
|
|
|
if (!valid_pip) {
|
|
|
|
// See if one users can enter this site.
|
|
|
|
if (dst_wire_data.site == -1) {
|
|
|
|
// This is an output site port, but not for the driver net.
|
|
|
|
// Disallow.
|
|
|
|
NPNR_ASSERT(src_wire_data.site == pip_data.site);
|
|
|
|
} else {
|
|
|
|
// This might be a valid pip, scan users.
|
|
|
|
for (auto &user : net->users) {
|
|
|
|
NPNR_ASSERT(user.cell != nullptr);
|
|
|
|
if (user.cell->bel == BelId()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &bel_data = bel_info(chip_info, user.cell->bel);
|
|
|
|
if (bel_data.site == pip_data.site) {
|
|
|
|
valid_pip = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!valid_pip) {
|
|
|
|
#ifdef DEBUG_BINDING
|
|
|
|
if (getCtx()->verbose) {
|
|
|
|
log_info("Pip %s is within a site and not available not right now\n", getCtx()->nameOfPip(pip));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-19 07:31:40 +08:00
|
|
|
bool Arch::checkPipAvail(PipId pip) const { return checkPipAvailForNet(pip, nullptr); }
|
2021-03-20 08:35:29 +08:00
|
|
|
|
2021-03-23 08:46:00 +08:00
|
|
|
std::string Arch::get_chipdb_hash() const { return chipdb_hash; }
|
|
|
|
|
2021-03-23 08:38:15 +08:00
|
|
|
bool Arch::is_inverting(PipId pip) const
|
|
|
|
{
|
|
|
|
auto &tile_type = loc_info(chip_info, pip);
|
|
|
|
auto &pip_info = tile_type.pip_data[pip.index];
|
|
|
|
if (pip_info.site == -1) {
|
|
|
|
// FIXME: Some routing pips are inverters, but this is missing from
|
|
|
|
// the chipdb.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &bel_data = tile_type.bel_data[pip_info.bel];
|
|
|
|
|
|
|
|
// Is a fixed inverter if the non_inverting_pin is another pin.
|
|
|
|
return bel_data.non_inverting_pin != pip_info.extra_data && bel_data.inverting_pin == pip_info.extra_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Arch::can_invert(PipId pip) const
|
|
|
|
{
|
|
|
|
auto &tile_type = loc_info(chip_info, pip);
|
|
|
|
auto &pip_info = tile_type.pip_data[pip.index];
|
|
|
|
if (pip_info.site == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &bel_data = tile_type.bel_data[pip_info.bel];
|
|
|
|
|
|
|
|
// Can optionally invert if this pip is both the non_inverting_pin and
|
|
|
|
// inverting pin.
|
|
|
|
return bel_data.non_inverting_pin == pip_info.extra_data && bel_data.inverting_pin == pip_info.extra_data;
|
|
|
|
}
|
|
|
|
|
2021-03-24 07:53:42 +08:00
|
|
|
void Arch::mask_bel_pins_on_site_wire(NetInfo *net, WireId wire)
|
|
|
|
{
|
|
|
|
std::vector<size_t> bel_pins_to_mask;
|
|
|
|
for (const PortRef &port_ref : net->users) {
|
|
|
|
if (port_ref.cell->bel == BelId()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPNR_ASSERT(port_ref.cell != nullptr);
|
|
|
|
auto iter = port_ref.cell->cell_bel_pins.find(port_ref.port);
|
|
|
|
if (iter == port_ref.cell->cell_bel_pins.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<IdString> &cell_bel_pins = iter->second;
|
|
|
|
bel_pins_to_mask.clear();
|
|
|
|
|
|
|
|
for (size_t bel_pin_idx = 0; bel_pin_idx < cell_bel_pins.size(); ++bel_pin_idx) {
|
|
|
|
IdString bel_pin = cell_bel_pins.at(bel_pin_idx);
|
|
|
|
WireId bel_pin_wire = getBelPinWire(port_ref.cell->bel, bel_pin);
|
|
|
|
if (bel_pin_wire == wire) {
|
|
|
|
bel_pins_to_mask.push_back(bel_pin_idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bel_pins_to_mask.empty()) {
|
|
|
|
std::vector<IdString> &masked_cell_bel_pins = port_ref.cell->masked_cell_bel_pins[port_ref.port];
|
|
|
|
// Remove in reverse order to preserve indicies.
|
|
|
|
for (auto riter = bel_pins_to_mask.rbegin(); riter != bel_pins_to_mask.rend(); ++riter) {
|
|
|
|
size_t bel_pin_idx = *riter;
|
|
|
|
masked_cell_bel_pins.push_back(cell_bel_pins.at(bel_pin_idx));
|
|
|
|
cell_bel_pins.erase(cell_bel_pins.begin() + bel_pin_idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Arch::unmask_bel_pins()
|
|
|
|
{
|
|
|
|
for (auto &cell_pair : cells) {
|
|
|
|
CellInfo *cell = cell_pair.second.get();
|
|
|
|
if (cell->masked_cell_bel_pins.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &mask_pair : cell->masked_cell_bel_pins) {
|
|
|
|
IdString cell_port = mask_pair.first;
|
|
|
|
const std::vector<IdString> &bel_pins = mask_pair.second;
|
|
|
|
std::vector<IdString> &cell_bel_pins = cell->cell_bel_pins[cell_port];
|
|
|
|
cell_bel_pins.insert(cell_bel_pins.begin(), bel_pins.begin(), bel_pins.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
cell->masked_cell_bel_pins.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Arch::remove_site_routing()
|
|
|
|
{
|
2021-06-02 17:01:36 +08:00
|
|
|
pool<WireId> wires_to_unbind;
|
2021-03-24 07:53:42 +08:00
|
|
|
for (auto &net_pair : nets) {
|
|
|
|
for (auto &wire_pair : net_pair.second->wires) {
|
|
|
|
WireId wire = wire_pair.first;
|
|
|
|
if (wire_pair.second.strength != STRENGTH_PLACER) {
|
|
|
|
// Only looking for bound placer wires
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
wires_to_unbind.emplace(wire);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (WireId wire : wires_to_unbind) {
|
|
|
|
unbindWire(wire);
|
|
|
|
}
|
|
|
|
|
|
|
|
unmask_bel_pins();
|
2021-03-25 02:07:45 +08:00
|
|
|
|
|
|
|
IdString id_NEXTPNR_INV = id("$nextpnr_inv");
|
|
|
|
IdString id_I = id("I");
|
|
|
|
std::vector<IdString> cells_to_remove;
|
|
|
|
for (auto &cell_pair : cells) {
|
|
|
|
CellInfo *cell = cell_pair.second.get();
|
|
|
|
if (cell->type != id_NEXTPNR_INV) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
disconnectPort(cell_pair.first, id_I);
|
|
|
|
cells_to_remove.push_back(cell_pair.first);
|
|
|
|
tileStatus.at(cell->bel.tile).boundcells[cell->bel.index] = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (IdString cell_name : cells_to_remove) {
|
|
|
|
NPNR_ASSERT(cells.erase(cell_name) == 1);
|
|
|
|
}
|
2021-03-24 07:53:42 +08:00
|
|
|
}
|
|
|
|
|
2021-03-26 08:11:06 +08:00
|
|
|
void Arch::explain_bel_status(BelId bel) const
|
|
|
|
{
|
|
|
|
if (isBelLocationValid(bel)) {
|
|
|
|
log_info("BEL %s is valid!\n", nameOfBel(bel));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto iter = tileStatus.find(bel.tile);
|
|
|
|
NPNR_ASSERT(iter != tileStatus.end());
|
|
|
|
const TileStatus &tile_status = iter->second;
|
|
|
|
const CellInfo *cell = tile_status.boundcells[bel.index];
|
|
|
|
if (!dedicated_interconnect.isBelLocationValid(bel, cell)) {
|
|
|
|
dedicated_interconnect.explain_bel_status(bel, cell);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (io_port_types.count(cell->type)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_cell_valid_constraints(cell, tile_status, /*explain_constraints=*/true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &bel_data = bel_info(chip_info, bel);
|
|
|
|
const SiteRouter &site = get_site_status(tile_status, bel_data);
|
|
|
|
NPNR_ASSERT(!site.checkSiteRouting(getCtx(), tile_status));
|
|
|
|
site.explain(getCtx());
|
|
|
|
}
|
|
|
|
|
2021-04-12 17:26:39 +08:00
|
|
|
DelayQuad Arch::getPipDelay(PipId pip) const
|
|
|
|
{
|
2021-04-02 06:18:17 +08:00
|
|
|
// FIXME: Implement when adding timing-driven place and route.
|
2021-04-12 17:26:39 +08:00
|
|
|
const auto &pip_data = pip_info(chip_info, pip);
|
2021-04-02 06:18:17 +08:00
|
|
|
|
|
|
|
// Scale pseudo-pips by the number of wires they consume to make them
|
|
|
|
// more expensive than a single edge. This approximation exists soley to
|
|
|
|
// make the non-timing driven solution avoid thinking that pseudo-pips
|
|
|
|
// are the same cost as regular pips.
|
2021-04-12 17:26:39 +08:00
|
|
|
return DelayQuad(100 * (1 + pip_data.pseudo_cell_wires.size()));
|
2021-04-02 06:18:17 +08:00
|
|
|
}
|
|
|
|
|
2021-04-19 17:46:35 +08:00
|
|
|
const DefaultCellConnsPOD *Arch::get_default_conns(IdString cell_type) const
|
|
|
|
{
|
|
|
|
for (const auto &conn : chip_info->constants->default_conns) {
|
|
|
|
if (IdString(conn.cell_type) == cell_type)
|
|
|
|
return &conn;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Arch::pack_default_conns()
|
|
|
|
{
|
|
|
|
IdString vcc_net_name(chip_info->constants->vcc_net_name);
|
|
|
|
IdString gnd_net_name(chip_info->constants->gnd_net_name);
|
|
|
|
Context *ctx = getCtx();
|
|
|
|
|
|
|
|
std::vector<IdString> dead_nets;
|
|
|
|
|
2021-06-01 23:51:18 +08:00
|
|
|
for (auto &cell : ctx->cells) {
|
|
|
|
CellInfo *ci = cell.second.get();
|
2021-04-19 17:46:35 +08:00
|
|
|
const DefaultCellConnsPOD *conns = get_default_conns(ci->type);
|
|
|
|
if (conns == nullptr)
|
|
|
|
continue;
|
|
|
|
for (const auto &pin : conns->pins) {
|
|
|
|
IdString pin_name(pin.pin_name);
|
|
|
|
// pin missing, create it
|
|
|
|
if (!ci->ports.count(pin_name))
|
|
|
|
ci->addInput(pin_name);
|
|
|
|
const NetInfo *net = ci->ports.at(pin_name).net;
|
|
|
|
if (net != nullptr) {
|
|
|
|
// pin is connected, and driven, nothing to do
|
|
|
|
if (net->driver.cell != nullptr)
|
|
|
|
continue;
|
|
|
|
// pin is connected but undriven, disconnect the existing net
|
|
|
|
ctx->disconnectPort(ci->name, pin_name);
|
|
|
|
// remove net if it has no remaining users
|
|
|
|
if (net->users.empty())
|
|
|
|
dead_nets.push_back(net->name);
|
|
|
|
}
|
|
|
|
if (pin.value == PIN_VALUE_GND)
|
|
|
|
ctx->connectPort(gnd_net_name, ci->name, pin_name);
|
|
|
|
else if (pin.value == PIN_VALUE_VCC)
|
|
|
|
ctx->connectPort(vcc_net_name, ci->name, pin_name);
|
|
|
|
else
|
|
|
|
NPNR_ASSERT(pin.value == PIN_VALUE_FLOAT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove any left-behind nets with no users and no drivers
|
|
|
|
for (auto net : dead_nets)
|
|
|
|
ctx->nets.erase(net);
|
|
|
|
}
|
|
|
|
|
2021-02-06 06:18:38 +08:00
|
|
|
// Instance constraint templates.
|
|
|
|
template void Arch::ArchConstraints::bindBel(Arch::ArchConstraints::TagState *, const Arch::ConstraintRange);
|
|
|
|
template void Arch::ArchConstraints::unbindBel(Arch::ArchConstraints::TagState *, const Arch::ConstraintRange);
|
|
|
|
template bool Arch::ArchConstraints::isValidBelForCellType(const Context *, uint32_t,
|
|
|
|
const Arch::ArchConstraints::TagState *,
|
|
|
|
const Arch::ConstraintRange, IdString, IdString, BelId,
|
|
|
|
bool) const;
|
|
|
|
|
2021-01-27 02:05:23 +08:00
|
|
|
NEXTPNR_NAMESPACE_END
|