| 1 |
/* |
| 2 |
* nextpnr -- Next Generation Place and Route |
| 3 |
* |
| 4 |
* Copyright (C) 2023 gatecat <[email protected]> |
| 5 |
* |
| 6 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 7 |
* purpose with or without fee is hereby granted, provided that the above |
| 8 |
* copyright notice and this permission notice appear in all copies. |
| 9 |
* |
| 10 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 |
* |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <boost/algorithm/string.hpp> |
| 21 |
#include <queue> |
| 22 |
#include <regex> |
| 23 |
|
| 24 |
#include "himbaechel_api.h" |
| 25 |
#include "log.h" |
| 26 |
#include "nextpnr.h" |
| 27 |
#include "util.h" |
| 28 |
|
| 29 |
#include "placer_heap.h" |
| 30 |
#include "placer_static.h" |
| 31 |
|
| 32 |
#include "xilinx.h" |
| 33 |
|
| 34 |
#include "himbaechel_helpers.h" |
| 35 |
|
| 36 |
#define GEN_INIT_CONSTIDS |
| 37 |
#define HIMBAECHEL_CONSTIDS "uarch/xilinx/constids.inc" |
| 38 |
#include "himbaechel_constids.h" |
| 39 |
|
| 40 |
NEXTPNR_NAMESPACE_BEGIN |
| 41 |
|
| 42 |
XilinxImpl::~XilinxImpl() {}; |
| 43 |
|
| 44 |
po::options_description XilinxImpl::getUArchOptions() |
| 45 |
{ |
| 46 |
po::options_description specific("Xilinx specific options"); |
| 47 |
specific.add_options()("fasm", po::value<std::string>(), "fasm bitstream output file"); |
| 48 |
specific.add_options()("xdc", po::value<std::string>(), "name of constraints file"); |
| 49 |
return specific; |
| 50 |
} |
| 51 |
|
| 52 |
void XilinxImpl::init_database(Arch *arch) |
| 53 |
{ |
| 54 |
const ArchArgs &args = arch->args; |
| 55 |
init_uarch_constids(arch); |
| 56 |
std::smatch match; |
| 57 |
std::regex devicere = std::regex("(xc7[azkv]\\d+t?)([a-z0-9]+)-(\\dL?)"); |
| 58 |
if (!std::regex_match(args.device, match, devicere)) { |
| 59 |
log_error("Invalid device %s\n", args.device.c_str()); |
| 60 |
} |
| 61 |
std::string die = match[1].str(); |
| 62 |
if (die == "xc7a35t") |
| 63 |
die = "xc7a50t"; |
| 64 |
arch->load_chipdb(stringf("xilinx/chipdb-%s.bin", die.c_str())); |
| 65 |
std::string package = match[2].str(); |
| 66 |
arch->set_package(package); |
| 67 |
arch->set_speed_grade("DEFAULT"); |
| 68 |
} |
| 69 |
|
| 70 |
void XilinxImpl::init(Context *ctx) |
| 71 |
{ |
| 72 |
h.init(ctx); |
| 73 |
HimbaechelAPI::init(ctx); |
| 74 |
|
| 75 |
tile_status.resize(ctx->chip_info->tile_insts.size()); |
| 76 |
for (int i = 0; i < ctx->chip_info->tile_insts.ssize(); i++) { |
| 77 |
auto extra_data = tile_extra_data(i); |
| 78 |
tile_status.at(i).site_variant.resize(extra_data->sites.ssize()); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
SiteIndex XilinxImpl::get_bel_site(BelId bel) const |
| 83 |
{ |
| 84 |
auto &bel_data = chip_bel_info(ctx->chip_info, bel); |
| 85 |
auto site_key = BelSiteKey::unpack(bel_data.site); |
| 86 |
return SiteIndex(bel.tile, site_key.site); |
| 87 |
} |
| 88 |
|
| 89 |
IdString XilinxImpl::get_site_name(SiteIndex site) const |
| 90 |
{ |
| 91 |
const auto &site_data = tile_extra_data(site.tile)->sites[site.site]; |
| 92 |
return ctx->idf("%s_X%dY%d", IdString(site_data.name_prefix).c_str(ctx), site_data.site_x, site_data.site_y); |
| 93 |
} |
| 94 |
|
| 95 |
BelId XilinxImpl::get_site_bel(SiteIndex site, IdString bel_name) const |
| 96 |
{ |
| 97 |
const auto &tile_data = chip_tile_info(ctx->chip_info, site.tile); |
| 98 |
for (int32_t i = 0; i < tile_data.bels.ssize(); i++) { |
| 99 |
const auto &bel_data = tile_data.bels[i]; |
| 100 |
if (BelSiteKey::unpack(bel_data.site).site != site.site) |
| 101 |
continue; |
| 102 |
if (reinterpret_cast<const XlnxBelExtraDataPOD *>(bel_data.extra_data.get())->name_in_site != bel_name.index) |
| 103 |
continue; |
| 104 |
return BelId(site.tile, i); |
| 105 |
} |
| 106 |
return BelId(); |
| 107 |
} |
| 108 |
|
| 109 |
IdString XilinxImpl::bel_name_in_site(BelId bel) const |
| 110 |
{ |
| 111 |
const auto &bel_data = chip_bel_info(ctx->chip_info, bel); |
| 112 |
return IdString(reinterpret_cast<const XlnxBelExtraDataPOD *>(bel_data.extra_data.get())->name_in_site); |
| 113 |
} |
| 114 |
|
| 115 |
IdStringList XilinxImpl::get_site_bel_name(BelId bel) const |
| 116 |
{ |
| 117 |
return IdStringList::concat(get_site_name(get_bel_site(bel)), bel_name_in_site(bel)); |
| 118 |
} |
| 119 |
|
| 120 |
WireId XilinxImpl::lookup_wire(int tile, IdString wire_name) const |
| 121 |
{ |
| 122 |
const auto &tdata = chip_tile_info(ctx->chip_info, tile); |
| 123 |
for (int wire = 0; wire < tdata.wires.ssize(); wire++) { |
| 124 |
if (IdString(tdata.wires[wire].name) == wire_name) |
| 125 |
return ctx->normalise_wire(tile, wire); |
| 126 |
} |
| 127 |
return WireId(); |
| 128 |
} |
| 129 |
|
| 130 |
void XilinxImpl::notifyBelChange(BelId bel, CellInfo *cell) |
| 131 |
{ |
| 132 |
auto &ts = tile_status.at(bel.tile); |
| 133 |
auto &bel_data = chip_bel_info(ctx->chip_info, bel); |
| 134 |
auto site_key = BelSiteKey::unpack(bel_data.site); |
| 135 |
// Update bound site variant for pip validity use later on |
| 136 |
if (cell && cell->type != id_PAD && site_key.site >= 0 && site_key.site < int(ts.site_variant.size())) { |
| 137 |
ts.site_variant.at(site_key.site) = site_key.site_variant; |
| 138 |
} |
| 139 |
if (is_logic_tile(bel)) |
| 140 |
update_logic_bel(bel, cell); |
| 141 |
if (is_bram_tile(bel)) |
| 142 |
update_bram_bel(bel, cell); |
| 143 |
} |
| 144 |
|
| 145 |
void XilinxImpl::update_logic_bel(BelId bel, CellInfo *cell) |
| 146 |
{ |
| 147 |
int z = ctx->getBelLocation(bel).z; |
| 148 |
NPNR_ASSERT(z < 128); |
| 149 |
auto &tts = tile_status.at(bel.tile); |
| 150 |
if (!tts.lts) |
| 151 |
tts.lts = std::make_unique<LogicTileStatus>(); |
| 152 |
auto &ts = *(tts.lts); |
| 153 |
auto tags = get_tags(cell), last_tags = get_tags(ts.cells[z]); |
| 154 |
if ((z == ((3 << 4) | BEL_6LUT)) || (z == ((3 << 4) | BEL_5LUT))) { |
| 155 |
if ((tags && tags->lut.is_memory) || (last_tags && last_tags->lut.is_memory)) { |
| 156 |
// Special case - memory write port invalidates everything |
| 157 |
for (int i = 0; i < 8; i++) |
| 158 |
ts.eights[i].dirty = true; |
| 159 |
// if (xc7) |
| 160 |
ts.halfs[0].dirty = true; // WCLK and CLK0 shared |
| 161 |
} |
| 162 |
} |
| 163 |
if ((((z & 0xF) == BEL_6LUT) || ((z & 0xF) == BEL_5LUT)) && |
| 164 |
((tags && tags->lut.is_srl) || (last_tags && last_tags->lut.is_srl))) { |
| 165 |
// SRLs invalidate everything due to write clock |
| 166 |
for (int i = 0; i < 8; i++) |
| 167 |
ts.eights[i].dirty = true; |
| 168 |
// if (xc7) |
| 169 |
ts.halfs[0].dirty = true; // WCLK and CLK0 shared |
| 170 |
} |
| 171 |
|
| 172 |
ts.cells[z] = cell; |
| 173 |
|
| 174 |
// determine which sections to mark as dirty |
| 175 |
switch (z & 0xF) { |
| 176 |
case BEL_FF: |
| 177 |
case BEL_FF2: |
| 178 |
ts.halfs[(z >> 4) / 4].dirty = true; |
| 179 |
if ((((z >> 4) / 4) == 0) /*&& xc7*/) |
| 180 |
ts.eights[3].dirty = true; |
| 181 |
/* fall-through */ |
| 182 |
case BEL_6LUT: |
| 183 |
case BEL_5LUT: |
| 184 |
ts.eights[z >> 4].dirty = true; |
| 185 |
break; |
| 186 |
case BEL_F7MUX: |
| 187 |
ts.eights[z >> 4].dirty = true; |
| 188 |
ts.eights[(z >> 4) + 1].dirty = true; |
| 189 |
break; |
| 190 |
case BEL_F8MUX: |
| 191 |
ts.eights[(z >> 4) + 1].dirty = true; |
| 192 |
ts.eights[(z >> 4) + 2].dirty = true; |
| 193 |
break; |
| 194 |
case BEL_CARRY4: |
| 195 |
for (int i = ((z >> 4) / 4) * 4; i < (((z >> 4) / 4) + 1) * 4; i++) |
| 196 |
ts.eights[i].dirty = true; |
| 197 |
break; |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
void XilinxImpl::update_bram_bel(BelId bel, CellInfo *cell) |
| 202 |
{ |
| 203 |
IdString type = ctx->getBelType(bel); |
| 204 |
if (!type.in(id_RAMBFIFO18E2_RAMBFIFO18E2, id_RAMBFIFO36E2_RAMBFIFO36E2, id_RAMB18E2_RAMB18E2, id_FIFO36E2_FIFO36E2, |
| 205 |
id_RAMBFIFO36E1_RAMBFIFO36E1, id_RAMB36E1_RAMB36E1, id_RAMB18E1_RAMB18E1)) |
| 206 |
return; |
| 207 |
auto &tts = tile_status.at(bel.tile); |
| 208 |
if (!tts.bts) |
| 209 |
tts.bts = std::make_unique<BRAMTileStatus>(); |
| 210 |
int z = ctx->getBelLocation(bel).z; |
| 211 |
NPNR_ASSERT(z >= 0 && z < 12); |
| 212 |
tts.bts->cells[z] = cell; |
| 213 |
} |
| 214 |
|
| 215 |
bool XilinxImpl::is_pip_unavail(PipId pip) const |
| 216 |
{ |
| 217 |
const auto &pip_data = chip_pip_info(ctx->chip_info, pip); |
| 218 |
const auto &extra_data = *reinterpret_cast<const XlnxPipExtraDataPOD *>(pip_data.extra_data.get()); |
| 219 |
unsigned pip_type = pip_data.flags; |
| 220 |
if (pip_type == PIP_SITE_ENTRY) { |
| 221 |
WireId dst = ctx->getPipDstWire(pip); |
| 222 |
if (ctx->getWireType(dst) == id_INTENT_SITE_GND) { |
| 223 |
const auto <s = tile_status[dst.tile].lts; |
| 224 |
if (lts && (lts->cells[BEL_5LUT] != nullptr || lts->cells[BEL_6LUT] != nullptr)) |
| 225 |
return true; // Ground driver only available if lowest 5LUT and 6LUT not used |
| 226 |
} |
| 227 |
} else if (pip_type == PIP_CONST_DRIVER) { |
| 228 |
WireId dst = ctx->getPipDstWire(pip); |
| 229 |
const auto <s = tile_status[dst.tile].lts; |
| 230 |
if (lts && (lts->cells[BEL_5LUT] != nullptr || lts->cells[BEL_6LUT] != nullptr)) |
| 231 |
return true; // Ground driver only available if lowest 5LUT and 6LUT not used |
| 232 |
} else if (pip_type == PIP_SITE_INTERNAL) { |
| 233 |
if (extra_data.bel_name == ID_TRIBUF) |
| 234 |
return true; |
| 235 |
auto site = BelSiteKey::unpack(extra_data.site_key); |
| 236 |
// Check site variant of PIP matches configured site variant of tile |
| 237 |
if (site.site >= 0 && site.site < int(tile_status[pip.tile].site_variant.size())) { |
| 238 |
if (site.site_variant > 0 && site.site_variant != tile_status[pip.tile].site_variant.at(site.site)) |
| 239 |
return true; |
| 240 |
} |
| 241 |
} else if (pip_type == PIP_LUT_PERMUTATION) { |
| 242 |
const auto <s = tile_status[pip.tile].lts; |
| 243 |
if (!lts) |
| 244 |
return false; |
| 245 |
int eight = (extra_data.pip_config >> 8) & 0xF; |
| 246 |
|
| 247 |
if (((extra_data.pip_config >> 4) & 0xF) == (extra_data.pip_config & 0xF)) |
| 248 |
return false; // from==to, always valid |
| 249 |
|
| 250 |
auto lut6 = get_tags(lts->cells[(eight << 4) | BEL_6LUT]); |
| 251 |
if (lut6 && (lut6->lut.is_memory || lut6->lut.is_srl)) |
| 252 |
return true; |
| 253 |
auto lut5 = get_tags(lts->cells[(eight << 4) | BEL_5LUT]); |
| 254 |
if (lut5 && (lut5->lut.is_memory || lut5->lut.is_srl)) |
| 255 |
return true; |
| 256 |
} else if (pip_type == PIP_LUT_ROUTETHRU) { |
| 257 |
int eight = (extra_data.pip_config >> 8) & 0xF; |
| 258 |
int dest = (extra_data.pip_config & 0x1); |
| 259 |
if (eight == 0) |
| 260 |
return true; // FIXME: conflict with ground |
| 261 |
if (dest & 0x1) |
| 262 |
return true; // FIXME: routethru to MUX |
| 263 |
const auto <s = tile_status[pip.tile].lts; |
| 264 |
if (!lts) |
| 265 |
return false; |
| 266 |
const CellInfo *lut6 = lts->cells[(eight << 4) | BEL_6LUT]; |
| 267 |
if (lut6) |
| 268 |
return true; |
| 269 |
const CellInfo *lut5 = lts->cells[(eight << 4) | BEL_5LUT]; |
| 270 |
if (lut5) |
| 271 |
return true; |
| 272 |
} |
| 273 |
|
| 274 |
return false; |
| 275 |
} |
| 276 |
|
| 277 |
void XilinxImpl::prePlace() { assign_cell_tags(); } |
| 278 |
|
| 279 |
void XilinxImpl::postPlace() |
| 280 |
{ |
| 281 |
fixup_placement(); |
| 282 |
ctx->assignArchInfo(); |
| 283 |
} |
| 284 |
|
| 285 |
void XilinxImpl::configurePlacerHeap(PlacerHeapCfg &cfg) |
| 286 |
{ |
| 287 |
cfg.hpwl_scale_x = 2; |
| 288 |
cfg.hpwl_scale_y = 1; |
| 289 |
cfg.beta = 0.5; |
| 290 |
cfg.placeAllAtOnce = true; |
| 291 |
cfg.get_cell_legalisation_weight = [this](Context *, CellInfo *ci) { |
| 292 |
if (ci->type != id_SLICE_LUTX) |
| 293 |
return 1; |
| 294 |
auto tags = get_tags(ci); |
| 295 |
// Place memory first, because they require entire SLICEMs |
| 296 |
return tags->lut.is_memory ? 100 : 1; |
| 297 |
}; |
| 298 |
} |
| 299 |
|
| 300 |
void XilinxImpl::configurePlacerStatic(PlacerStaticCfg &cfg) |
| 301 |
{ |
| 302 |
cfg.hpwl_scale_x = 2; |
| 303 |
cfg.hpwl_scale_y = 1; |
| 304 |
|
| 305 |
cfg.glbBufTypes.insert(id_PSEUDO_GND); |
| 306 |
cfg.glbBufTypes.insert(id_PSEUDO_VCC); |
| 307 |
cfg.glbBufTypes.insert(id_BUFGCTRL); |
| 308 |
cfg.glbBufTypes.insert(id_BUFG_BUFG); |
| 309 |
|
| 310 |
{ |
| 311 |
cfg.cell_groups.emplace_back(); |
| 312 |
auto &comb = cfg.cell_groups.back(); |
| 313 |
comb.name = ctx->id("COMB"); |
| 314 |
comb.bel_area[id_SLICE_LUTX] = StaticRect(1.0f, 0.125f); |
| 315 |
comb.bel_area[id_CARRY4] = StaticRect(0.0f, 0.0f); |
| 316 |
comb.bel_area[id_SELMUX2_1] = StaticRect(0.0f, 0.0f); |
| 317 |
|
| 318 |
comb.cell_area[id_SLICE_LUTX] = StaticRect(1.0f, 0.125f); |
| 319 |
comb.cell_area[id_CARRY4] = StaticRect(1.0f, 0.5f); |
| 320 |
comb.cell_area[id_SELMUX2_1] = StaticRect(1.0f, 0.125f); |
| 321 |
|
| 322 |
comb.zero_area_cells.insert(id_CARRY4); |
| 323 |
comb.zero_area_cells.insert(id_SELMUX2_1); |
| 324 |
|
| 325 |
comb.spacer_rect = StaticRect(1.0f, 0.125f); |
| 326 |
} |
| 327 |
|
| 328 |
{ |
| 329 |
cfg.cell_groups.emplace_back(); |
| 330 |
auto &comb = cfg.cell_groups.back(); |
| 331 |
comb.name = ctx->id("FF"); |
| 332 |
comb.cell_area[id_SLICE_FFX] = StaticRect(1.0f, 0.125f); |
| 333 |
comb.bel_area[id_SLICE_FFX] = StaticRect(1.0f, 0.125f); |
| 334 |
comb.spacer_rect = StaticRect(1.0f, 0.125f); |
| 335 |
} |
| 336 |
|
| 337 |
{ |
| 338 |
cfg.cell_groups.emplace_back(); |
| 339 |
auto &comb = cfg.cell_groups.back(); |
| 340 |
comb.name = ctx->id("RAM"); |
| 341 |
comb.cell_area[id_RAMB18E1_RAMB18E1] = StaticRect(1.0f, 3.0f); |
| 342 |
comb.bel_area[id_RAMB18E1_RAMB18E1] = StaticRect(1.0f, 3.0f); |
| 343 |
comb.cell_area[id_RAMB36E1_RAMB36E1] = StaticRect(1.0f, 6.0f); |
| 344 |
comb.bel_area[id_RAMB36E1_RAMB36E1] = StaticRect(0.0f, 0.0f); |
| 345 |
comb.spacer_rect = StaticRect(1.0f, 3.0f); |
| 346 |
} |
| 347 |
{ |
| 348 |
cfg.cell_groups.emplace_back(); |
| 349 |
auto &comb = cfg.cell_groups.back(); |
| 350 |
comb.name = ctx->id("DSP"); |
| 351 |
comb.cell_area[id_DSP48E1_DSP48E1] = StaticRect(1.0f, 3.0f); |
| 352 |
comb.bel_area[id_DSP48E1_DSP48E1] = StaticRect(1.0f, 3.0f); |
| 353 |
comb.spacer_rect = StaticRect(1.0f, 3.0f); |
| 354 |
} |
| 355 |
cfg.get_cell_area_override = [this](Context *ctx, const CellInfo *ci) -> std::optional<StaticRect> { |
| 356 |
if (ci->type != id_SLICE_LUTX) |
| 357 |
return {}; |
| 358 |
auto tags = get_tags(ci); |
| 359 |
if (tags->lut.is_memory || |
| 360 |
(ci->cluster != ClusterId() && ctx->getClusterRootCell(ci->cluster)->type == id_CARRY4)) { |
| 361 |
// macro LUTs use either a half or whole LUT, always |
| 362 |
return {(tags->lut.input_count == 6) ? StaticRect(1.0f, 0.125f) : StaticRect(1.0f, 0.0625f)}; |
| 363 |
} else { |
| 364 |
switch (tags->lut.input_count) { // sliding scale, smaller LUTs pack better |
| 365 |
case 6: |
| 366 |
return {StaticRect(1.0f, 0.125f)}; |
| 367 |
case 5: |
| 368 |
return {StaticRect(1.0f, 0.09f)}; |
| 369 |
case 4: |
| 370 |
return {StaticRect(1.0f, 0.07f)}; |
| 371 |
case 3: |
| 372 |
return {StaticRect(1.0f, 0.06f)}; |
| 373 |
case 2: |
| 374 |
return {StaticRect(1.0f, 0.04f)}; |
| 375 |
case 1: |
| 376 |
return {StaticRect(1.0f, 0.03f)}; |
| 377 |
default: |
| 378 |
NPNR_ASSERT_FALSE("unhandled LUT input count"); |
| 379 |
} |
| 380 |
} |
| 381 |
}; |
| 382 |
} |
| 383 |
|
| 384 |
void XilinxImpl::preRoute() |
| 385 |
{ |
| 386 |
find_source_sink_locs(); |
| 387 |
route_clocks(); |
| 388 |
} |
| 389 |
|
| 390 |
void XilinxImpl::postRoute() |
| 391 |
{ |
| 392 |
fixup_routing(); |
| 393 |
ctx->assignArchInfo(); |
| 394 |
const ArchArgs &args = ctx->args; |
| 395 |
if (args.options.count("fasm")) { |
| 396 |
write_fasm(args.options["fasm"].as<std::string>()); |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
IdString XilinxImpl::bel_tile_type(BelId bel) const |
| 401 |
{ |
| 402 |
return IdString(chip_tile_info(ctx->chip_info, bel.tile).type_name); |
| 403 |
} |
| 404 |
|
| 405 |
bool XilinxImpl::is_logic_tile(BelId bel) const |
| 406 |
{ |
| 407 |
return bel_tile_type(bel).in(id_CLEL_L, id_CLEL_R, id_CLEM, id_CLEM_R, id_CLBLL_L, id_CLBLL_R, id_CLBLM_L, |
| 408 |
id_CLBLM_R); |
| 409 |
} |
| 410 |
bool XilinxImpl::is_bram_tile(BelId bel) const { return bel_tile_type(bel).in(id_BRAM, id_BRAM_L, id_BRAM_R); } |
| 411 |
|
| 412 |
const XlnxTileInstExtraDataPOD *XilinxImpl::tile_extra_data(int tile) const |
| 413 |
{ |
| 414 |
return reinterpret_cast<const XlnxTileInstExtraDataPOD *>(ctx->chip_info->tile_insts[tile].extra_data.get()); |
| 415 |
} |
| 416 |
|
| 417 |
std::string XilinxImpl::tile_name(int tile) const |
| 418 |
{ |
| 419 |
const auto &data = *tile_extra_data(tile); |
| 420 |
return stringf("%s_X%dY%d", IdString(data.name_prefix).c_str(ctx), data.tile_x, data.tile_y); |
| 421 |
} |
| 422 |
|
| 423 |
Loc XilinxImpl::rel_site_loc(SiteIndex site) const |
| 424 |
{ |
| 425 |
const auto &site_data = tile_extra_data(site.tile)->sites[site.site]; |
| 426 |
return Loc(site_data.rel_x, site_data.rel_y, 0); |
| 427 |
} |
| 428 |
|
| 429 |
SiteIndex XilinxImpl::rel_site(SiteIndex site, int dx, int dy) const |
| 430 |
{ |
| 431 |
const auto &base_site_data = tile_extra_data(site.tile)->sites[site.site]; |
| 432 |
for (size_t i = 0; i < tile_extra_data(site.tile)->sites.size(); i++) { |
| 433 |
const auto &site_data = tile_extra_data(site.tile)->sites[i]; |
| 434 |
if (site_data.name_prefix == base_site_data.name_prefix && site_data.rel_x == (base_site_data.rel_x + dx) && |
| 435 |
site_data.rel_y == (base_site_data.rel_y + dy)) |
| 436 |
return SiteIndex(site.tile, i); |
| 437 |
} |
| 438 |
return SiteIndex(); |
| 439 |
} |
| 440 |
|
| 441 |
int XilinxImpl::hclk_for_iob(BelId pad) const |
| 442 |
{ |
| 443 |
std::string tile_type = bel_tile_type(pad).str(ctx); |
| 444 |
int ioi = pad.tile; |
| 445 |
if (boost::starts_with(tile_type, "LIOB")) |
| 446 |
ioi += 1; |
| 447 |
else if (boost::starts_with(tile_type, "RIOB")) |
| 448 |
ioi -= 1; |
| 449 |
else |
| 450 |
NPNR_ASSERT_FALSE("unknown IOB side"); |
| 451 |
return hclk_for_ioi(ioi); |
| 452 |
} |
| 453 |
|
| 454 |
int XilinxImpl::hclk_for_ioi(int tile) const |
| 455 |
{ |
| 456 |
WireId ioclk0; |
| 457 |
auto &td = chip_tile_info(ctx->chip_info, tile); |
| 458 |
for (int i = 0; i < td.wires.ssize(); i++) { |
| 459 |
std::string name = IdString(td.wires[i].name).str(ctx); |
| 460 |
if (name == "IOI_IOCLK0" || name == "IOI_SING_IOCLK0") { |
| 461 |
ioclk0 = ctx->normalise_wire(tile, i); |
| 462 |
break; |
| 463 |
} |
| 464 |
} |
| 465 |
NPNR_ASSERT(ioclk0 != WireId()); |
| 466 |
for (auto uh : ctx->getPipsUphill(ioclk0)) |
| 467 |
return uh.tile; |
| 468 |
NPNR_ASSERT_FALSE("failed to find HCLK pips"); |
| 469 |
} |
| 470 |
|
| 471 |
void XilinxImpl::assign_cell_tags() |
| 472 |
{ |
| 473 |
cell_tags.resize(ctx->cells.size()); |
| 474 |
for (auto &cell : ctx->cells) { |
| 475 |
CellInfo *ci = cell.second.get(); |
| 476 |
auto &ct = cell_tags.at(ci->flat_index); |
| 477 |
if (ci->type == id_SLICE_LUTX) { |
| 478 |
ct.lut.input_count = 0; |
| 479 |
for (IdString a : {id_A1, id_A2, id_A3, id_A4, id_A5, id_A6}) { |
| 480 |
NetInfo *pn = ci->getPort(a); |
| 481 |
if (pn != nullptr) |
| 482 |
ct.lut.input_sigs[ct.lut.input_count++] = pn; |
| 483 |
} |
| 484 |
ct.lut.output_count = 0; |
| 485 |
for (IdString o : {id_O6, id_O5}) { |
| 486 |
NetInfo *pn = ci->getPort(o); |
| 487 |
if (pn != nullptr) |
| 488 |
ct.lut.output_sigs[ct.lut.output_count++] = pn; |
| 489 |
} |
| 490 |
for (int i = ct.lut.output_count; i < 2; i++) |
| 491 |
ct.lut.output_sigs[i] = nullptr; |
| 492 |
ct.lut.di1_net = ci->getPort(id_DI1); |
| 493 |
ct.lut.di2_net = ci->getPort(id_DI2); |
| 494 |
ct.lut.wclk = ci->getPort(id_CLK); |
| 495 |
ct.lut.memory_group = 0; // fixme |
| 496 |
ct.lut.is_srl = ci->attrs.count(id_X_LUT_AS_SRL); |
| 497 |
ct.lut.is_memory = ci->attrs.count(id_X_LUT_AS_DRAM); |
| 498 |
ct.lut.only_drives_carry = false; |
| 499 |
if (ci->cluster != ClusterId() && ct.lut.output_count > 0 && ct.lut.output_sigs[0] != nullptr && |
| 500 |
ct.lut.output_sigs[0]->users.entries() == 1 && |
| 501 |
(*ct.lut.output_sigs[0]->users.begin()).cell->type == id_CARRY4) |
| 502 |
ct.lut.only_drives_carry = true; |
| 503 |
|
| 504 |
const IdString addr_msb_sigs[] = {id_WA7, id_WA8, id_WA9}; |
| 505 |
for (int i = 0; i < 3; i++) |
| 506 |
ct.lut.address_msb[i] = ci->getPort(addr_msb_sigs[i]); |
| 507 |
|
| 508 |
} else if (ci->type == id_SLICE_FFX) { |
| 509 |
ct.ff.d = ci->getPort(id_D); |
| 510 |
ct.ff.clk = ci->getPort(id_CK); |
| 511 |
ct.ff.ce = ci->getPort(id_CE); |
| 512 |
ct.ff.sr = ci->getPort(id_SR); |
| 513 |
ct.ff.is_clkinv = bool_or_default(ci->params, id_IS_CLK_INVERTED, false); |
| 514 |
ct.ff.is_srinv = bool_or_default(ci->params, id_IS_R_INVERTED, false) || |
| 515 |
bool_or_default(ci->params, id_IS_S_INVERTED, false) || |
| 516 |
bool_or_default(ci->params, id_IS_CLR_INVERTED, false) || |
| 517 |
bool_or_default(ci->params, id_IS_PRE_INVERTED, false); |
| 518 |
ct.ff.is_latch = ci->attrs.count(id_X_FF_AS_LATCH); |
| 519 |
ct.ff.ffsync = ci->attrs.count(id_X_FFSYNC); |
| 520 |
} else if (ci->type.in(id_F7MUX, id_F8MUX, id_F9MUX, id_SELMUX2_1)) { |
| 521 |
ct.mux.sel = ci->getPort(id_S0); |
| 522 |
ct.mux.out = ci->getPort(id_OUT); |
| 523 |
} else if (ci->type == id_CARRY4) { |
| 524 |
for (int i = 0; i < 4; i++) { |
| 525 |
ct.carry.out_sigs[i] = ci->getPort(ctx->idf("O%d", i)); |
| 526 |
ct.carry.cout_sigs[i] = ci->getPort(ctx->idf("CO%d", i)); |
| 527 |
ct.carry.x_sigs[i] = nullptr; |
| 528 |
} |
| 529 |
ct.carry.x_sigs[0] = ci->getPort(id_CYINIT); |
| 530 |
} else if (ci->type == id_RAMB18E1_RAMB18E1 || ci->type == id_RAMB36E1_RAMB36E1) { |
| 531 |
bool read_sdp = ((ci->type == id_RAMB18E1_RAMB18E1 && |
| 532 |
int_or_default(ci->params, ctx->id("READ_WIDTH_B"), 0) == 36) || |
| 533 |
(ci->type == id_RAMB36E1_RAMB36E1 && |
| 534 |
int_or_default(ci->params, ctx->id("READ_WIDTH_B"), 0) == 72)); |
| 535 |
bool write_sdp = ((ci->type == id_RAMB18E1_RAMB18E1 && |
| 536 |
int_or_default(ci->params, ctx->id("WRITE_WIDTH_B"), 0) == 36) || |
| 537 |
(ci->type == id_RAMB36E1_RAMB36E1 && |
| 538 |
int_or_default(ci->params, ctx->id("WRITE_WIDTH_B"), 0) == 72)); |
| 539 |
ci->timing_index = ctx->get_cell_timing_idx( |
| 540 |
ctx->idf("%s_%s_%s", ci->type.c_str(ctx), write_sdp ? "WSDP" : "WTDP", read_sdp ? "RSDP" : "RTDP")); |
| 541 |
} |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
bool XilinxImpl::is_general_routing(WireId wire) const |
| 546 |
{ |
| 547 |
IdString intent = ctx->getWireType(wire); |
| 548 |
return !intent.in(id_INTENT_DEFAULT, id_NODE_DEDICATED, id_NODE_OPTDELAY, id_NODE_OUTPUT, id_NODE_INT_INTERFACE, |
| 549 |
id_PINFEED, id_INPUT, id_PADOUTPUT, id_PADINPUT, id_IOBINPUT, id_IOBOUTPUT, id_GENERIC, |
| 550 |
id_IOBIN2OUT, id_INTENT_SITE_WIRE, id_INTENT_SITE_GND); |
| 551 |
} |
| 552 |
|
| 553 |
void XilinxImpl::find_source_sink_locs() |
| 554 |
{ |
| 555 |
for (auto &net : ctx->nets) { |
| 556 |
NetInfo *ni = net.second.get(); |
| 557 |
for (auto &usr : ni->users) { |
| 558 |
BelId bel = usr.cell->bel; |
| 559 |
if (bel == BelId() || is_logic_tile(bel)) |
| 560 |
continue; // don't need to do this for logic bels, which are always next to their INT |
| 561 |
WireId sink = ctx->getNetinfoSinkWire(ni, usr, 0); |
| 562 |
if (sink == WireId() || sink_locs.count(sink)) |
| 563 |
continue; |
| 564 |
std::queue<WireId> visit; |
| 565 |
dict<WireId, WireId> backtrace; |
| 566 |
int iter = 0; |
| 567 |
// as this is a best-effort optimisation to slightly improve routing, |
| 568 |
// don't spend too long with a nice low iteration limit |
| 569 |
const int iter_max = 500; |
| 570 |
visit.push(sink); |
| 571 |
while (!visit.empty() && iter < iter_max) { |
| 572 |
++iter; |
| 573 |
WireId cursor = visit.front(); |
| 574 |
visit.pop(); |
| 575 |
if (is_general_routing(cursor)) { |
| 576 |
Loc loc(0, 0, 0); |
| 577 |
tile_xy(ctx->chip_info, cursor.tile, loc.x, loc.y); |
| 578 |
sink_locs[sink] = loc; |
| 579 |
|
| 580 |
while (backtrace.count(cursor)) { |
| 581 |
cursor = backtrace.at(cursor); |
| 582 |
if (!sink_locs.count(cursor)) { |
| 583 |
sink_locs[cursor] = loc; |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
break; |
| 588 |
} |
| 589 |
for (auto pip : ctx->getPipsUphill(cursor)) { |
| 590 |
WireId src = ctx->getPipSrcWire(pip); |
| 591 |
if (!backtrace.count(src)) { |
| 592 |
backtrace[src] = cursor; |
| 593 |
visit.push(src); |
| 594 |
} |
| 595 |
} |
| 596 |
} |
| 597 |
} |
| 598 |
auto &drv = ni->driver; |
| 599 |
if (drv.cell != nullptr) { |
| 600 |
BelId bel = drv.cell->bel; |
| 601 |
if (bel == BelId() || is_logic_tile(bel)) |
| 602 |
continue; // don't need to do this for logic bels, which are always next to their INT |
| 603 |
WireId source = ctx->getNetinfoSourceWire(ni); |
| 604 |
if (source == WireId() || source_locs.count(source)) |
| 605 |
continue; |
| 606 |
std::queue<WireId> visit; |
| 607 |
dict<WireId, WireId> backtrace; |
| 608 |
int iter = 0; |
| 609 |
// as this is a best-effort optimisation to slightly improve routing, |
| 610 |
// don't spend too long with a nice low iteration limit |
| 611 |
const int iter_max = 500; |
| 612 |
visit.push(source); |
| 613 |
while (!visit.empty() && iter < iter_max) { |
| 614 |
++iter; |
| 615 |
WireId cursor = visit.front(); |
| 616 |
visit.pop(); |
| 617 |
if (is_general_routing(cursor)) { |
| 618 |
Loc loc(0, 0, 0); |
| 619 |
tile_xy(ctx->chip_info, cursor.tile, loc.x, loc.y); |
| 620 |
source_locs[source] = loc; |
| 621 |
|
| 622 |
while (backtrace.count(cursor)) { |
| 623 |
cursor = backtrace.at(cursor); |
| 624 |
if (!source_locs.count(cursor)) { |
| 625 |
source_locs[cursor] = loc; |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
break; |
| 630 |
} |
| 631 |
for (auto pip : ctx->getPipsDownhill(cursor)) { |
| 632 |
WireId dst = ctx->getPipDstWire(pip); |
| 633 |
if (!backtrace.count(dst)) { |
| 634 |
backtrace[dst] = cursor; |
| 635 |
visit.push(dst); |
| 636 |
} |
| 637 |
} |
| 638 |
} |
| 639 |
} |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
delay_t XilinxImpl::estimateDelay(WireId src, WireId dst) const |
| 644 |
{ |
| 645 |
int sx, sy, dx, dy; |
| 646 |
tile_xy(ctx->chip_info, src.tile, sx, sy); |
| 647 |
tile_xy(ctx->chip_info, dst.tile, dx, dy); |
| 648 |
auto fnd_src = source_locs.find(src); |
| 649 |
if (fnd_src != source_locs.end()) { |
| 650 |
sx = fnd_src->second.x; |
| 651 |
sy = fnd_src->second.y; |
| 652 |
} |
| 653 |
auto fnd_snk = sink_locs.find(dst); |
| 654 |
if (fnd_snk != sink_locs.end()) { |
| 655 |
dx = fnd_snk->second.x; |
| 656 |
dy = fnd_snk->second.y; |
| 657 |
} |
| 658 |
// TODO: improve sophistication here based on old nextpnr-xilinx code |
| 659 |
return 800 + 50 * (std::abs(dy - sy) + std::abs(dx - sx)); |
| 660 |
} |
| 661 |
|
| 662 |
delay_t XilinxImpl::predictDelay(BelId src_bel, IdString src_pin, BelId dst_bel, IdString dst_pin) const |
| 663 |
{ |
| 664 |
int sx, sy, dx, dy; |
| 665 |
tile_xy(ctx->chip_info, src_bel.tile, sx, sy); |
| 666 |
tile_xy(ctx->chip_info, dst_bel.tile, dx, dy); |
| 667 |
// TODO: improve sophistication here based on old nextpnr-xilinx code |
| 668 |
return 500 + 50 * (std::abs(dy - sy) + std::abs(dx - sx)); |
| 669 |
} |
| 670 |
|
| 671 |
BoundingBox XilinxImpl::getRouteBoundingBox(WireId src, WireId dst) const |
| 672 |
{ |
| 673 |
int x0, y0, x1, y1; |
| 674 |
auto expand = [&](int x, int y) { |
| 675 |
x0 = std::min(x0, x); |
| 676 |
x1 = std::max(x1, x); |
| 677 |
y0 = std::min(y0, y); |
| 678 |
y1 = std::max(y1, y); |
| 679 |
}; |
| 680 |
|
| 681 |
tile_xy(ctx->chip_info, src.tile, x0, y0); |
| 682 |
x1 = x0; |
| 683 |
y1 = y0; |
| 684 |
|
| 685 |
int dx, dy; |
| 686 |
tile_xy(ctx->chip_info, dst.tile, dx, dy); |
| 687 |
expand(dx, dy); |
| 688 |
|
| 689 |
auto fnd_src = source_locs.find(src); |
| 690 |
if (fnd_src != source_locs.end()) { |
| 691 |
expand(fnd_src->second.x, fnd_src->second.y); |
| 692 |
} |
| 693 |
auto fnd_snk = sink_locs.find(dst); |
| 694 |
if (fnd_snk != sink_locs.end()) { |
| 695 |
expand(fnd_snk->second.x, fnd_snk->second.y); |
| 696 |
} |
| 697 |
return {x0 - 2, y0 - 2, x1 + 2, y1 + 2}; |
| 698 |
} |
| 699 |
|
| 700 |
namespace { |
| 701 |
struct XilinxArch : HimbaechelArch |
| 702 |
{ |
| 703 |
XilinxArch() : HimbaechelArch("xilinx") {}; |
| 704 |
bool match_device(const std::string &device) override { return device.size() > 3 && device.substr(0, 3) == "xc7"; } |
| 705 |
std::unique_ptr<HimbaechelAPI> create(const std::string &device) override { return std::make_unique<XilinxImpl>(); } |
| 706 |
} xilinxArch; |
| 707 |
} // namespace |
| 708 |
|
| 709 |
NEXTPNR_NAMESPACE_END |