2018-07-06 18:15:07 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Clifford Wolf <clifford@symbioticeda.com>
|
2018-07-06 20:02:37 +08:00
|
|
|
* Copyright (C) 2018 David Shah <david@symbioticeda.com>
|
2018-07-06 18:15:07 +08:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cmath>
|
2018-07-06 20:02:37 +08:00
|
|
|
#include <cstring>
|
2018-07-06 18:15:07 +08:00
|
|
|
#include "log.h"
|
|
|
|
#include "nextpnr.h"
|
2018-07-12 00:15:08 +08:00
|
|
|
#include "placer1.h"
|
2018-07-12 00:04:09 +08:00
|
|
|
#include "router1.h"
|
2018-07-06 18:15:07 +08:00
|
|
|
#include "util.h"
|
2018-07-06 20:02:37 +08:00
|
|
|
|
2018-07-06 18:15:07 +08:00
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2018-07-06 20:02:37 +08:00
|
|
|
static std::tuple<int, int, std::string> split_identifier_name(const std::string &name)
|
|
|
|
{
|
|
|
|
size_t first_slash = name.find('/');
|
|
|
|
NPNR_ASSERT(first_slash != std::string::npos);
|
|
|
|
size_t second_slash = name.find('/', first_slash + 1);
|
|
|
|
NPNR_ASSERT(second_slash != std::string::npos);
|
|
|
|
return std::make_tuple(std::stoi(name.substr(1, first_slash)),
|
|
|
|
std::stoi(name.substr(first_slash + 2, second_slash - first_slash)),
|
|
|
|
name.substr(second_slash + 1));
|
|
|
|
};
|
|
|
|
|
2018-07-06 18:15:07 +08:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
IdString Arch::belTypeToId(BelType type) const
|
|
|
|
{
|
2018-07-06 20:02:37 +08:00
|
|
|
if (type == TYPE_TRELLIS_SLICE)
|
|
|
|
return id("TRELLIS_SLICE");
|
|
|
|
if (type == TYPE_TRELLIS_IO)
|
|
|
|
return id("TRELLIS_IO");
|
2018-07-06 18:15:07 +08:00
|
|
|
return IdString();
|
|
|
|
}
|
|
|
|
|
|
|
|
BelType Arch::belTypeFromId(IdString type) const
|
|
|
|
{
|
2018-07-06 20:02:37 +08:00
|
|
|
if (type == id("TRELLIS_SLICE"))
|
|
|
|
return TYPE_TRELLIS_SLICE;
|
|
|
|
if (type == id("TRELLIS_IO"))
|
|
|
|
return TYPE_TRELLIS_IO;
|
2018-07-06 18:15:07 +08:00
|
|
|
return TYPE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void IdString::initialize_arch(const BaseCtx *ctx)
|
|
|
|
{
|
|
|
|
#define X(t) initialize_add(ctx, #t, PIN_##t);
|
2018-07-06 20:02:37 +08:00
|
|
|
|
2018-07-06 18:15:07 +08:00
|
|
|
#include "portpins.inc"
|
2018-07-06 20:02:37 +08:00
|
|
|
|
2018-07-06 18:15:07 +08:00
|
|
|
#undef X
|
|
|
|
}
|
|
|
|
|
|
|
|
IdString Arch::portPinToId(PortPin type) const
|
|
|
|
{
|
|
|
|
IdString ret;
|
|
|
|
if (type > 0 && type < PIN_MAXIDX)
|
|
|
|
ret.index = type;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
PortPin Arch::portPinFromId(IdString type) const
|
|
|
|
{
|
|
|
|
if (type.index > 0 && type.index < PIN_MAXIDX)
|
|
|
|
return PortPin(type.index);
|
|
|
|
return PIN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
static const ChipInfoPOD *get_chip_info(const RelPtr<ChipInfoPOD> *ptr) { return ptr->get(); }
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
void load_chipdb();
|
|
|
|
#endif
|
|
|
|
|
2018-07-17 18:46:25 +08:00
|
|
|
//#define LFE5U_45F_ONLY
|
2018-07-08 17:15:30 +08:00
|
|
|
|
2018-07-06 18:15:07 +08:00
|
|
|
Arch::Arch(ArchArgs args) : args(args)
|
|
|
|
{
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
load_chipdb();
|
|
|
|
#endif
|
2018-07-09 00:36:59 +08:00
|
|
|
#ifdef LFE5U_45F_ONLY
|
|
|
|
if (args.type == ArchArgs::LFE5U_45F) {
|
|
|
|
chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_45k));
|
2018-07-08 17:15:30 +08:00
|
|
|
} else {
|
|
|
|
log_error("Unsupported ECP5 chip type.\n");
|
|
|
|
}
|
|
|
|
#else
|
2018-07-06 20:02:37 +08:00
|
|
|
if (args.type == ArchArgs::LFE5U_25F) {
|
|
|
|
chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_25k));
|
|
|
|
} else if (args.type == ArchArgs::LFE5U_45F) {
|
|
|
|
chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_45k));
|
|
|
|
} else if (args.type == ArchArgs::LFE5U_85F) {
|
|
|
|
chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_85k));
|
2018-07-06 18:15:07 +08:00
|
|
|
} else {
|
2018-07-06 20:02:37 +08:00
|
|
|
log_error("Unsupported ECP5 chip type.\n");
|
2018-07-06 18:15:07 +08:00
|
|
|
}
|
2018-07-08 17:15:30 +08:00
|
|
|
#endif
|
2018-07-18 22:01:53 +08:00
|
|
|
package_info = nullptr;
|
|
|
|
for (int i = 0; i < chip_info->num_packages; i++) {
|
|
|
|
if (args.package == chip_info->package_info[i].name.get()) {
|
|
|
|
package_info = &(chip_info->package_info[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!package_info)
|
|
|
|
log_error("Unsupported package '%s' for '%s'.\n", args.package.c_str(), getChipName().c_str());
|
2018-07-17 22:18:06 +08:00
|
|
|
|
|
|
|
id_trellis_slice = id("TRELLIS_SLICE");
|
|
|
|
id_clk = id("CLK");
|
|
|
|
id_lsr = id("LSR");
|
|
|
|
id_clkmux = id("CLKMUX");
|
|
|
|
id_lsrmux = id("LSRMUX");
|
|
|
|
id_srmode = id("SRMODE");
|
|
|
|
id_mode = id("MODE");
|
2018-07-06 18:15:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
std::string Arch::getChipName()
|
|
|
|
{
|
2018-07-06 20:02:37 +08:00
|
|
|
|
|
|
|
if (args.type == ArchArgs::LFE5U_25F) {
|
2018-07-09 18:02:31 +08:00
|
|
|
return "LFE5U-25F";
|
2018-07-06 20:02:37 +08:00
|
|
|
} else if (args.type == ArchArgs::LFE5U_45F) {
|
2018-07-09 18:02:31 +08:00
|
|
|
return "LFE5U-45F";
|
2018-07-06 20:02:37 +08:00
|
|
|
} else if (args.type == ArchArgs::LFE5U_85F) {
|
2018-07-09 18:02:31 +08:00
|
|
|
return "LFE5U-85F";
|
2018-07-06 18:15:07 +08:00
|
|
|
} else {
|
|
|
|
log_error("Unknown chip\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
IdString Arch::archArgsToId(ArchArgs args) const
|
|
|
|
{
|
2018-07-06 20:02:37 +08:00
|
|
|
if (args.type == ArchArgs::LFE5U_25F)
|
|
|
|
return id("lfe5u_25f");
|
|
|
|
if (args.type == ArchArgs::LFE5U_45F)
|
|
|
|
return id("lfe5u_45f");
|
|
|
|
if (args.type == ArchArgs::LFE5U_85F)
|
|
|
|
return id("lfe5u_85f");
|
2018-07-06 18:15:07 +08:00
|
|
|
return IdString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2018-07-15 01:50:23 +08:00
|
|
|
BelId Arch::getBelByName(IdString name) const
|
2018-07-06 18:15:07 +08:00
|
|
|
{
|
|
|
|
BelId ret;
|
|
|
|
auto it = bel_by_name.find(name);
|
|
|
|
if (it != bel_by_name.end())
|
2018-07-06 20:02:37 +08:00
|
|
|
return it->second;
|
|
|
|
|
|
|
|
Location loc;
|
|
|
|
std::string basename;
|
2018-07-15 01:50:23 +08:00
|
|
|
std::tie(loc.x, loc.y, basename) = split_identifier_name(name.str(this));
|
2018-07-06 20:02:37 +08:00
|
|
|
ret.location = loc;
|
2018-07-15 01:50:23 +08:00
|
|
|
const LocationTypePOD *loci = locInfo(ret);
|
2018-07-06 20:02:37 +08:00
|
|
|
for (int i = 0; i < loci->num_bels; i++) {
|
|
|
|
if (std::strcmp(loci->bel_data[i].name.get(), basename.c_str()) == 0) {
|
|
|
|
ret.index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret.index >= 0)
|
|
|
|
bel_by_name[name] = ret;
|
2018-07-06 18:15:07 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BelRange Arch::getBelsAtSameTile(BelId bel) const
|
|
|
|
{
|
|
|
|
BelRange br;
|
|
|
|
NPNR_ASSERT(bel != BelId());
|
2018-07-06 20:02:37 +08:00
|
|
|
br.b.cursor_tile = bel.location.y * chip_info->width + bel.location.x;
|
|
|
|
br.e.cursor_tile = bel.location.y * chip_info->width + bel.location.x;
|
|
|
|
br.b.cursor_index = 0;
|
2018-07-17 22:18:06 +08:00
|
|
|
br.e.cursor_index = locInfo(bel)->num_bels - 1;
|
|
|
|
br.b.chip = chip_info;
|
|
|
|
br.e.chip = chip_info;
|
|
|
|
++br.e;
|
2018-07-06 18:15:07 +08:00
|
|
|
return br;
|
|
|
|
}
|
|
|
|
|
2018-07-22 16:59:21 +08:00
|
|
|
WireId Arch::getBelPinWire(BelId bel, PortPin pin) const
|
2018-07-06 18:15:07 +08:00
|
|
|
{
|
|
|
|
WireId ret;
|
|
|
|
|
|
|
|
NPNR_ASSERT(bel != BelId());
|
|
|
|
|
2018-07-15 01:50:23 +08:00
|
|
|
int num_bel_wires = locInfo(bel)->bel_data[bel.index].num_bel_wires;
|
|
|
|
const BelWirePOD *bel_wires = locInfo(bel)->bel_data[bel.index].bel_wires.get();
|
2018-07-06 18:15:07 +08:00
|
|
|
for (int i = 0; i < num_bel_wires; i++)
|
|
|
|
if (bel_wires[i].port == pin) {
|
2018-07-06 20:02:37 +08:00
|
|
|
ret.location = bel.location + bel_wires[i].rel_wire_loc;
|
2018-07-06 18:15:07 +08:00
|
|
|
ret.index = bel_wires[i].wire_index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2018-07-15 01:50:23 +08:00
|
|
|
WireId Arch::getWireByName(IdString name) const
|
2018-07-06 18:15:07 +08:00
|
|
|
{
|
|
|
|
WireId ret;
|
|
|
|
auto it = wire_by_name.find(name);
|
|
|
|
if (it != wire_by_name.end())
|
2018-07-06 20:02:37 +08:00
|
|
|
return it->second;
|
|
|
|
|
|
|
|
Location loc;
|
|
|
|
std::string basename;
|
2018-07-15 01:50:23 +08:00
|
|
|
std::tie(loc.x, loc.y, basename) = split_identifier_name(name.str(this));
|
2018-07-06 20:02:37 +08:00
|
|
|
ret.location = loc;
|
2018-07-15 01:50:23 +08:00
|
|
|
const LocationTypePOD *loci = locInfo(ret);
|
2018-07-06 20:02:37 +08:00
|
|
|
for (int i = 0; i < loci->num_wires; i++) {
|
|
|
|
if (std::strcmp(loci->wire_data[i].name.get(), basename.c_str()) == 0) {
|
|
|
|
ret.index = i;
|
2018-07-08 20:24:32 +08:00
|
|
|
ret.location = loc;
|
2018-07-06 20:02:37 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret.index >= 0)
|
|
|
|
wire_by_name[name] = ret;
|
2018-07-08 20:24:32 +08:00
|
|
|
else
|
|
|
|
ret.location = Location();
|
2018-07-06 18:15:07 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2018-07-15 01:50:23 +08:00
|
|
|
PipId Arch::getPipByName(IdString name) const
|
2018-07-06 18:15:07 +08:00
|
|
|
{
|
|
|
|
auto it = pip_by_name.find(name);
|
|
|
|
if (it != pip_by_name.end())
|
2018-07-06 20:02:37 +08:00
|
|
|
return it->second;
|
2018-07-06 18:15:07 +08:00
|
|
|
|
2018-07-06 20:02:37 +08:00
|
|
|
PipId ret;
|
|
|
|
Location loc;
|
|
|
|
std::string basename;
|
2018-07-15 01:50:23 +08:00
|
|
|
std::tie(loc.x, loc.y, basename) = split_identifier_name(name.str(this));
|
|
|
|
const LocationTypePOD *loci = locInfo(ret);
|
2018-07-06 20:02:37 +08:00
|
|
|
for (int i = 0; i < loci->num_pips; i++) {
|
|
|
|
PipId curr;
|
|
|
|
curr.location = loc;
|
|
|
|
curr.index = i;
|
2018-07-15 01:50:23 +08:00
|
|
|
pip_by_name[getPipName(curr)] = curr;
|
2018-07-06 20:02:37 +08:00
|
|
|
}
|
|
|
|
return pip_by_name[name];
|
2018-07-06 18:15:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
IdString Arch::getPipName(PipId pip) const
|
|
|
|
{
|
|
|
|
NPNR_ASSERT(pip != PipId());
|
|
|
|
|
2018-07-06 20:02:37 +08:00
|
|
|
int x = pip.location.x;
|
|
|
|
int y = pip.location.y;
|
2018-07-06 18:15:07 +08:00
|
|
|
|
2018-07-06 20:02:37 +08:00
|
|
|
std::string src_name = getWireName(getPipSrcWire(pip)).str(this);
|
2018-07-06 18:15:07 +08:00
|
|
|
std::replace(src_name.begin(), src_name.end(), '/', '.');
|
|
|
|
|
2018-07-06 20:02:37 +08:00
|
|
|
std::string dst_name = getWireName(getPipDstWire(pip)).str(this);
|
2018-07-06 18:15:07 +08:00
|
|
|
std::replace(dst_name.begin(), dst_name.end(), '/', '.');
|
|
|
|
|
|
|
|
return id("X" + std::to_string(x) + "/Y" + std::to_string(y) + "/" + src_name + ".->." + dst_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2018-07-18 22:01:53 +08:00
|
|
|
BelId Arch::getPackagePinBel(const std::string &pin) const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < package_info->num_pins; i++) {
|
|
|
|
if (package_info->pin_data[i].name.get() == pin) {
|
|
|
|
BelId bel;
|
|
|
|
bel.location = package_info->pin_data[i].abs_loc;
|
|
|
|
bel.index = package_info->pin_data[i].bel_index;
|
|
|
|
return bel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return BelId();
|
|
|
|
}
|
2018-07-06 18:15:07 +08:00
|
|
|
|
2018-07-18 22:01:53 +08:00
|
|
|
std::string Arch::getBelPackagePin(BelId bel) const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < package_info->num_pins; i++) {
|
|
|
|
if (package_info->pin_data[i].abs_loc == bel.location && package_info->pin_data[i].bel_index == bel.index) {
|
|
|
|
return package_info->pin_data[i].name.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2018-07-06 18:15:07 +08:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2018-07-08 18:56:43 +08:00
|
|
|
void Arch::estimatePosition(BelId bel, int &x, int &y, bool &gb) const
|
|
|
|
{
|
2018-07-08 18:48:25 +08:00
|
|
|
x = bel.location.x;
|
|
|
|
y = bel.location.y;
|
|
|
|
gb = false;
|
|
|
|
}
|
2018-07-06 18:15:07 +08:00
|
|
|
|
2018-07-08 20:24:32 +08:00
|
|
|
delay_t Arch::estimateDelay(WireId src, WireId dst) const
|
|
|
|
{
|
2018-07-22 22:55:10 +08:00
|
|
|
return 200 * (abs(src.location.x - dst.location.x) + abs(src.location.y - dst.location.y));
|
2018-07-08 20:24:32 +08:00
|
|
|
}
|
2018-07-06 18:15:07 +08:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
2018-07-12 00:04:09 +08:00
|
|
|
|
2018-07-13 04:04:13 +08:00
|
|
|
bool Arch::place() { return placer1(getCtx()); }
|
2018-07-12 00:15:08 +08:00
|
|
|
|
2018-07-13 04:04:13 +08:00
|
|
|
bool Arch::route() { return router1(getCtx()); }
|
2018-07-12 00:04:09 +08:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
2018-07-06 18:15:07 +08:00
|
|
|
|
2018-07-15 01:50:23 +08:00
|
|
|
std::vector<GraphicElement> Arch::getDecalGraphics(DecalId decalId) const
|
2018-07-06 18:15:07 +08:00
|
|
|
{
|
|
|
|
std::vector<GraphicElement> ret;
|
2018-07-11 20:27:15 +08:00
|
|
|
// FIXME
|
2018-07-06 18:15:07 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-11 20:27:15 +08:00
|
|
|
DecalXY Arch::getFrameDecal() const { return {}; }
|
2018-07-06 18:15:07 +08:00
|
|
|
|
2018-07-11 20:27:15 +08:00
|
|
|
DecalXY Arch::getBelDecal(BelId bel) const { return {}; }
|
2018-07-06 18:15:07 +08:00
|
|
|
|
2018-07-11 20:27:15 +08:00
|
|
|
DecalXY Arch::getWireDecal(WireId wire) const { return {}; }
|
2018-07-06 18:15:07 +08:00
|
|
|
|
2018-07-11 20:27:15 +08:00
|
|
|
DecalXY Arch::getPipDecal(PipId pip) const { return {}; };
|
2018-07-06 18:15:07 +08:00
|
|
|
|
2018-07-13 00:01:40 +08:00
|
|
|
DecalXY Arch::getGroupDecal(GroupId pip) const { return {}; };
|
2018-07-12 23:22:29 +08:00
|
|
|
|
2018-07-06 20:02:37 +08:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2018-07-08 17:15:30 +08:00
|
|
|
bool Arch::getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, delay_t &delay) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
IdString Arch::getPortClock(const CellInfo *cell, IdString port) const { return IdString(); }
|
|
|
|
|
|
|
|
bool Arch::isClockPort(const CellInfo *cell, IdString port) const { return false; }
|
|
|
|
|
2018-07-06 18:15:07 +08:00
|
|
|
NEXTPNR_NAMESPACE_END
|