| 1 |
/* |
| 2 |
* nextpnr -- Next Generation Place and Route |
| 3 |
* |
| 4 |
* Copyright (C) 2024 The Project Beyond Authors. |
| 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 "pack.h" |
| 21 |
#include <algorithm> |
| 22 |
#include <boost/algorithm/string.hpp> |
| 23 |
#include <boost/optional.hpp> |
| 24 |
#include <iterator> |
| 25 |
#include <queue> |
| 26 |
#include <unordered_set> |
| 27 |
#include "chain_utils.h" |
| 28 |
#include "design_utils.h" |
| 29 |
#include "extra_data.h" |
| 30 |
#include "log.h" |
| 31 |
#include "nextpnr.h" |
| 32 |
|
| 33 |
#define HIMBAECHEL_CONSTIDS "uarch/ng-ultra/constids.inc" |
| 34 |
#include "himbaechel_constids.h" |
| 35 |
|
| 36 |
NEXTPNR_NAMESPACE_BEGIN |
| 37 |
|
| 38 |
// Return true if a cell is a LUT |
| 39 |
inline bool is_lut(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == id_NX_LUT; } |
| 40 |
|
| 41 |
// Return true if a cell is a flipflop |
| 42 |
inline bool is_dff(const BaseCtx *ctx, const CellInfo *cell) { return cell->type.in(id_NX_DFF, id_NX_BFF); } |
| 43 |
|
| 44 |
// Return true if a cell is a FE |
| 45 |
inline bool is_fe(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == id_BEYOND_FE; } |
| 46 |
|
| 47 |
// Return true if a cell is a DFR |
| 48 |
inline bool is_dfr(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == id_NX_DFR; } |
| 49 |
|
| 50 |
// Return true if a cell is a DDFR |
| 51 |
inline bool is_ddfr(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == id_NX_DDFR_U; } |
| 52 |
|
| 53 |
// Return true if a cell is a WFG/WFB |
| 54 |
inline bool is_wfg(const BaseCtx *ctx, const CellInfo *cell) { return cell->type.in(id_WFB, id_WFG); } |
| 55 |
|
| 56 |
// Return true if a cell is a GCK |
| 57 |
inline bool is_gck(const BaseCtx *ctx, const CellInfo *cell) { return cell->type.in(id_GCK, id_NX_GCK_U); } |
| 58 |
|
| 59 |
// Process the contents of packed_cells |
| 60 |
void NgUltraPacker::flush_cells() |
| 61 |
{ |
| 62 |
for (auto pcell : packed_cells) { |
| 63 |
for (auto &port : ctx->cells[pcell]->ports) { |
| 64 |
ctx->cells[pcell]->disconnectPort(port.first); |
| 65 |
} |
| 66 |
ctx->cells.erase(pcell); |
| 67 |
} |
| 68 |
packed_cells.clear(); |
| 69 |
} |
| 70 |
|
| 71 |
void NgUltraPacker::pack_constants(void) |
| 72 |
{ |
| 73 |
log_info("Packing constants..\n"); |
| 74 |
// Replace constants with LUTs |
| 75 |
const dict<IdString, Property> vcc_params = { |
| 76 |
{id_lut_table, Property(0xFFFF, 16)}, {id_lut_used, Property(1, 1)}, {id_dff_used, Property(1, 1)}}; |
| 77 |
const dict<IdString, Property> gnd_params = { |
| 78 |
{id_lut_table, Property(0x0000, 16)}, {id_lut_used, Property(1, 1)}, {id_dff_used, Property(1, 1)}}; |
| 79 |
|
| 80 |
h.replace_constants(CellTypePort(id_BEYOND_FE, id_LO), CellTypePort(id_BEYOND_FE, id_LO), vcc_params, gnd_params); |
| 81 |
} |
| 82 |
|
| 83 |
void NgUltraImpl::remove_constants() |
| 84 |
{ |
| 85 |
log_info("Removing constants..\n"); |
| 86 |
auto fnd_cell = ctx->cells.find(ctx->id("$PACKER_VCC_DRV")); |
| 87 |
if (fnd_cell != ctx->cells.end()) { |
| 88 |
auto fnd_net = ctx->nets.find(ctx->id("$PACKER_VCC")); |
| 89 |
if (fnd_net != ctx->nets.end() && fnd_net->second->users.entries() == 0) { |
| 90 |
BelId bel = (*fnd_cell).second.get()->bel; |
| 91 |
if (bel != BelId()) |
| 92 |
ctx->unbindBel(bel); |
| 93 |
ctx->cells.erase(fnd_cell); |
| 94 |
ctx->nets.erase(fnd_net); |
| 95 |
log_info(" Removed unused VCC cell\n"); |
| 96 |
} |
| 97 |
} |
| 98 |
fnd_cell = ctx->cells.find(ctx->id("$PACKER_GND_DRV")); |
| 99 |
if (fnd_cell != ctx->cells.end()) { |
| 100 |
auto fnd_net = ctx->nets.find(ctx->id("$PACKER_GND")); |
| 101 |
if (fnd_net != ctx->nets.end() && fnd_net->second->users.entries() == 0) { |
| 102 |
BelId bel = (*fnd_cell).second.get()->bel; |
| 103 |
if (bel != BelId()) |
| 104 |
ctx->unbindBel(bel); |
| 105 |
ctx->cells.erase(fnd_cell); |
| 106 |
ctx->nets.erase(fnd_net); |
| 107 |
log_info(" Removed unused GND cell\n"); |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
void NgUltraPacker::update_lut_init() |
| 113 |
{ |
| 114 |
log_info("Update LUT init...\n"); |
| 115 |
|
| 116 |
for (auto &cell : ctx->cells) { |
| 117 |
CellInfo &ci = *cell.second; |
| 118 |
if (!ci.type.in(id_NX_LUT)) |
| 119 |
continue; |
| 120 |
set_lut_input_if_constant(&ci, id_I1); |
| 121 |
set_lut_input_if_constant(&ci, id_I2); |
| 122 |
set_lut_input_if_constant(&ci, id_I3); |
| 123 |
set_lut_input_if_constant(&ci, id_I4); |
| 124 |
NetInfo *o = ci.getPort(id_O); |
| 125 |
if (!o) { |
| 126 |
// Remove those that do not output any value |
| 127 |
log_warning("Removing LUT '%s' since output is not connected.\n", ci.name.c_str(ctx)); |
| 128 |
packed_cells.insert(ci.name); |
| 129 |
} |
| 130 |
} |
| 131 |
flush_cells(); |
| 132 |
} |
| 133 |
|
| 134 |
void NgUltraPacker::dff_rewrite(CellInfo *cell) |
| 135 |
{ |
| 136 |
if (int_or_default(cell->params, id_dff_init, 0) == 0) { |
| 137 |
// Reset not used |
| 138 |
cell->disconnectPort(id_R); |
| 139 |
} else { |
| 140 |
// Reset used |
| 141 |
NetInfo *net = cell->getPort(id_R); |
| 142 |
if (net) { |
| 143 |
if (net->name == ctx->id("$PACKER_GND")) { |
| 144 |
log_warning("Removing reset on '%s' since it is always 0.\n", cell->name.c_str(ctx)); |
| 145 |
cell->setParam(id_dff_init, Property(0, 1)); |
| 146 |
cell->disconnectPort(id_R); |
| 147 |
} else if (net->name == ctx->id("$PACKER_VCC")) { |
| 148 |
log_error("Invalid DFF configuration, reset on '%s' is always 1.\n", cell->name.c_str(ctx)); |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
if (int_or_default(cell->params, id_dff_load, 0) == 0) { |
| 154 |
// Load not used |
| 155 |
cell->disconnectPort(id_L); |
| 156 |
} else { |
| 157 |
// Load used |
| 158 |
NetInfo *net = cell->getPort(id_L); |
| 159 |
if (net) { |
| 160 |
if (net->name == ctx->id("$PACKER_VCC")) { |
| 161 |
log_warning("Removing load enable on '%s' since it is always 1.\n", cell->name.c_str(ctx)); |
| 162 |
cell->setParam(id_dff_load, Property(0, 0)); |
| 163 |
cell->disconnectPort(id_L); |
| 164 |
} else if (net->name == ctx->id("$PACKER_GND")) { |
| 165 |
log_warning("Converting to self loop, since load enable on '%s' is always 0.\n", cell->name.c_str(ctx)); |
| 166 |
cell->setParam(id_dff_load, Property(0, 0)); |
| 167 |
cell->disconnectPort(id_L); |
| 168 |
cell->disconnectPort(id_I); |
| 169 |
NetInfo *out = cell->getPort(id_O); |
| 170 |
cell->connectPort(id_I, out); |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
void NgUltraPacker::ddfr_rewrite(CellInfo *cell) |
| 177 |
{ |
| 178 |
// Reversed logic in comparison to DFF |
| 179 |
if (int_or_default(cell->params, id_dff_load, 0) == 1) { |
| 180 |
// Load not used |
| 181 |
cell->disconnectPort(id_L); |
| 182 |
} else { |
| 183 |
// Load used |
| 184 |
NetInfo *net = cell->getPort(id_L); |
| 185 |
if (net) { |
| 186 |
if (net->name == ctx->id("$PACKER_VCC")) { |
| 187 |
log_warning("Removing load enable on '%s' since it is always 1.\n", cell->name.c_str(ctx)); |
| 188 |
cell->setParam(id_dff_load, Property(0, 0)); |
| 189 |
cell->disconnectPort(id_L); |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
void NgUltraPacker::update_dffs() |
| 196 |
{ |
| 197 |
log_info("Update DFFs...\n"); |
| 198 |
for (auto &cell : ctx->cells) { |
| 199 |
CellInfo &ci = *cell.second; |
| 200 |
if (!ci.type.in(id_NX_DFF)) |
| 201 |
continue; |
| 202 |
dff_rewrite(&ci); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
int NgUltraPacker::make_init_with_const_input(int init, int input, bool value) |
| 207 |
{ |
| 208 |
int new_init = 0; |
| 209 |
for (int i = 0; i < 16; i++) { |
| 210 |
if (((i >> input) & 0x1) != value) { |
| 211 |
int other_i = (i & (~(1 << input))) | (value << input); |
| 212 |
if ((init >> other_i) & 0x1) |
| 213 |
new_init |= (1 << i); |
| 214 |
} else { |
| 215 |
if ((init >> i) & 0x1) |
| 216 |
new_init |= (1 << i); |
| 217 |
} |
| 218 |
} |
| 219 |
return new_init; |
| 220 |
} |
| 221 |
|
| 222 |
void NgUltraPacker::set_lut_input_if_constant(CellInfo *cell, IdString input) |
| 223 |
{ |
| 224 |
NetInfo *net = cell->getPort(input); |
| 225 |
if (!net) |
| 226 |
return; |
| 227 |
if (!net->name.in(ctx->id("$PACKER_GND"), ctx->id("$PACKER_VCC"))) |
| 228 |
return; |
| 229 |
bool value = net->name == ctx->id("$PACKER_VCC"); |
| 230 |
int index = std::string("1234").find(input.str(ctx)); |
| 231 |
int init = int_or_default(cell->params, id_lut_table); |
| 232 |
int new_init = make_init_with_const_input(init, index, value); |
| 233 |
cell->params[id_lut_table] = Property(new_init, 16); |
| 234 |
cell->disconnectPort(input); |
| 235 |
} |
| 236 |
|
| 237 |
void NgUltraPacker::disconnect_if_gnd(CellInfo *cell, IdString input) |
| 238 |
{ |
| 239 |
NetInfo *net = cell->getPort(input); |
| 240 |
if (!net) |
| 241 |
return; |
| 242 |
if (net->name.in(ctx->id("$PACKER_GND"))) { |
| 243 |
cell->disconnectPort(input); |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
void NgUltraPacker::connect_gnd_if_unconnected(CellInfo *cell, IdString input, bool warn = true) |
| 248 |
{ |
| 249 |
NetInfo *net = cell->getPort(input); |
| 250 |
if (net) |
| 251 |
return; |
| 252 |
if (!cell->ports.count(input)) |
| 253 |
cell->addInput(input); |
| 254 |
auto fnd_net = ctx->nets.find(ctx->id("$PACKER_GND")); |
| 255 |
if (fnd_net != ctx->nets.end()) { |
| 256 |
cell->connectPort(input, fnd_net->second.get()); |
| 257 |
if (warn) |
| 258 |
log_warning("Connected GND to mandatory port '%s' of cell '%s'(%s).\n", input.c_str(ctx), |
| 259 |
cell->name.c_str(ctx), cell->type.c_str(ctx)); |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
void NgUltraPacker::lut_to_fe(CellInfo *lut, CellInfo *fe, bool no_dff, Property lut_table) |
| 264 |
{ |
| 265 |
fe->params[id_lut_table] = lut_table; |
| 266 |
fe->params[id_lut_used] = Property(1, 1); |
| 267 |
lut->movePortTo(id_I1, fe, id_I1); |
| 268 |
lut->movePortTo(id_I2, fe, id_I2); |
| 269 |
lut->movePortTo(id_I3, fe, id_I3); |
| 270 |
lut->movePortTo(id_I4, fe, id_I4); |
| 271 |
lut->movePortTo(id_O, fe, id_LO); |
| 272 |
if (no_dff) { |
| 273 |
fe->timing_index = ctx->get_cell_timing_idx(id_BEYOND_FE_LUT); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
void NgUltraPacker::dff_to_fe(CellInfo *dff, CellInfo *fe, bool pass_thru_lut) |
| 278 |
{ |
| 279 |
if (pass_thru_lut) { |
| 280 |
NetInfo *net = dff->getPort(id_I); |
| 281 |
if (net && net->name.in(ctx->id("$PACKER_GND"), ctx->id("$PACKER_VCC"))) { |
| 282 |
// special case if driver is constant |
| 283 |
fe->params[id_lut_table] = Property((net->name == ctx->id("$PACKER_GND")) ? 0x0000 : 0xffff, 16); |
| 284 |
dff->disconnectPort(id_I); |
| 285 |
} else { |
| 286 |
// otherwise just passthru |
| 287 |
fe->params[id_lut_table] = Property(0xaaaa, 16); |
| 288 |
dff->movePortTo(id_I, fe, id_I1); |
| 289 |
} |
| 290 |
fe->params[id_lut_used] = Property(1, 1); |
| 291 |
} else |
| 292 |
dff->movePortTo(id_I, fe, id_DI); |
| 293 |
fe->params[id_dff_used] = Property(1, 1); |
| 294 |
dff->movePortTo(id_O, fe, id_DO); |
| 295 |
if (dff->type == id_NX_BFF) { |
| 296 |
fe->setParam(id_type, Property("BFF")); |
| 297 |
} else { |
| 298 |
fe->setParam(id_type, Property("DFF")); |
| 299 |
|
| 300 |
dff->movePortTo(id_R, fe, id_R); |
| 301 |
dff->movePortTo(id_CK, fe, id_CK); |
| 302 |
dff->movePortTo(id_L, fe, id_L); |
| 303 |
|
| 304 |
if (dff->params.count(id_dff_ctxt)) |
| 305 |
fe->setParam(id_dff_ctxt, dff->params[id_dff_ctxt]); |
| 306 |
if (dff->params.count(id_dff_edge)) |
| 307 |
fe->setParam(id_dff_edge, dff->params[id_dff_edge]); |
| 308 |
if (dff->params.count(id_dff_init)) |
| 309 |
fe->setParam(id_dff_init, dff->params[id_dff_init]); |
| 310 |
if (dff->params.count(id_dff_load)) |
| 311 |
fe->setParam(id_dff_load, dff->params[id_dff_load]); |
| 312 |
if (dff->params.count(id_dff_sync)) |
| 313 |
fe->setParam(id_dff_sync, dff->params[id_dff_sync]); |
| 314 |
if (dff->params.count(id_dff_type)) |
| 315 |
fe->setParam(id_dff_type, dff->params[id_dff_type]); |
| 316 |
} |
| 317 |
if (pass_thru_lut) { |
| 318 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$LO", dff->name.c_str(ctx))); |
| 319 |
fe->connectPort(id_LO, new_out); |
| 320 |
fe->connectPort(id_DI, new_out); |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
void NgUltraPacker::bind_attr_loc(CellInfo *cell, dict<IdString, Property> *attrs) |
| 325 |
{ |
| 326 |
if (attrs->count(id_LOC)) { |
| 327 |
std::string name = attrs->at(id_LOC).as_string(); |
| 328 |
if (boost::starts_with(name, "TILE[")) { |
| 329 |
boost::replace_all(name, ".DFF", ".FE"); |
| 330 |
boost::replace_all(name, ".LUT", ".FE"); |
| 331 |
} |
| 332 |
if (!uarch->locations.count(name)) { |
| 333 |
log_error("Unable to find location %s\n", name.c_str()); |
| 334 |
} |
| 335 |
BelId bel = uarch->locations.at(name); |
| 336 |
ctx->bindBel(bel, cell, PlaceStrength::STRENGTH_LOCKED); |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
void NgUltraPacker::pack_xluts(void) |
| 341 |
{ |
| 342 |
log_info("Pack XLUTs...\n"); |
| 343 |
int xlut_used = 0, lut_only = 0, lut_and_ff = 0; |
| 344 |
for (auto &cell : ctx->cells) { |
| 345 |
CellInfo &ci = *cell.second; |
| 346 |
if (!ci.type.in(id_NX_LUT)) |
| 347 |
continue; |
| 348 |
if (!ci.params.count(id_lut_table)) |
| 349 |
log_error("Cell '%s' missing lut_table\n", ci.name.c_str(ctx)); |
| 350 |
|
| 351 |
if (ci.cluster != ClusterId()) |
| 352 |
continue; |
| 353 |
CellInfo *lut[4]; |
| 354 |
int inputs_used = 0; |
| 355 |
int dff_parts_used = 0; |
| 356 |
for (int i = 0; i < 4; i++) { |
| 357 |
NetInfo *net = ci.getPort(ctx->idf("I%d", i + 1)); |
| 358 |
if (!net) |
| 359 |
continue; |
| 360 |
lut[i] = net_driven_by(ctx, net, is_lut, id_O); |
| 361 |
if (lut[i] == cell.second.get()) |
| 362 |
continue; |
| 363 |
if (lut[i]) { |
| 364 |
if (net->users.entries() > 1) |
| 365 |
dff_parts_used++; |
| 366 |
inputs_used++; |
| 367 |
} |
| 368 |
} |
| 369 |
if (inputs_used != 4) |
| 370 |
continue; |
| 371 |
// we must have a route out for xlut output signal |
| 372 |
if (dff_parts_used > 3) |
| 373 |
continue; |
| 374 |
ci.type = id_XLUT; |
| 375 |
bind_attr_loc(&ci, &ci.attrs); |
| 376 |
ci.cluster = ci.name; |
| 377 |
xlut_used++; |
| 378 |
|
| 379 |
NetInfo *o = ci.getPort(id_O); |
| 380 |
CellInfo *orig_dff = o ? net_only_drives(ctx, o, is_dff, id_I, true) : nullptr; |
| 381 |
|
| 382 |
for (int i = 0; i < 4; i++) { |
| 383 |
ci.constr_children.push_back(lut[i]); |
| 384 |
lut[i]->cluster = ci.cluster; |
| 385 |
lut[i]->type = id_BEYOND_FE; |
| 386 |
lut[i]->constr_z = PLACE_XLUT_FE1 + i; |
| 387 |
lut[i]->renamePort(id_O, id_LO); |
| 388 |
lut[i]->params[id_lut_used] = Property(1, 1); |
| 389 |
NetInfo *net = lut[i]->getPort(id_LO); |
| 390 |
if (net->users.entries() != 2) { |
| 391 |
if (orig_dff && net->users.entries() == 1) { |
| 392 |
// we place DFF on XLUT output on unused DFF |
| 393 |
dff_to_fe(orig_dff, lut[i], false); |
| 394 |
packed_cells.insert(orig_dff->name); |
| 395 |
lut_and_ff++; |
| 396 |
orig_dff = nullptr; |
| 397 |
} else { |
| 398 |
lut[i]->timing_index = ctx->get_cell_timing_idx(id_BEYOND_FE_LUT); |
| 399 |
lut_only++; |
| 400 |
} |
| 401 |
} else { |
| 402 |
CellInfo *dff = (*net->users.begin()).cell; |
| 403 |
if (dff->type != id_NX_DFF) |
| 404 |
dff = (*(++net->users.begin())).cell; |
| 405 |
if (dff->type == id_NX_DFF) { |
| 406 |
dff_to_fe(dff, lut[i], false); |
| 407 |
packed_cells.insert(dff->name); |
| 408 |
lut_and_ff++; |
| 409 |
} else { |
| 410 |
lut[i]->timing_index = ctx->get_cell_timing_idx(id_BEYOND_FE_LUT); |
| 411 |
lut_only++; |
| 412 |
} |
| 413 |
} |
| 414 |
} |
| 415 |
} |
| 416 |
if (xlut_used) |
| 417 |
log_info(" %6d XLUTs used\n", xlut_used); |
| 418 |
if (lut_only) |
| 419 |
log_info(" %6d FEs used as LUT only\n", lut_only); |
| 420 |
if (lut_and_ff) |
| 421 |
log_info(" %6d FEs used as LUT and DFF\n", lut_and_ff); |
| 422 |
flush_cells(); |
| 423 |
} |
| 424 |
|
| 425 |
void NgUltraPacker::pack_dff_chains(void) |
| 426 |
{ |
| 427 |
log_info("Pack DFF chains...\n"); |
| 428 |
std::vector<std::pair<CellInfo *, std::vector<CellInfo *>>> dff_chain_start; |
| 429 |
for (auto &cell : ctx->cells) { |
| 430 |
CellInfo &ci = *cell.second; |
| 431 |
if (!ci.type.in(id_NX_DFF)) |
| 432 |
continue; |
| 433 |
NetInfo *inp = ci.getPort(id_I); |
| 434 |
if (!inp || (inp->driver.cell && inp->driver.cell->type.in(id_NX_DFF))) |
| 435 |
continue; |
| 436 |
int cnt = 0; |
| 437 |
CellInfo *dff = &ci; |
| 438 |
std::vector<CellInfo *> chain; |
| 439 |
CellInfo *start_dff = &ci; |
| 440 |
while (1) { |
| 441 |
NetInfo *o = dff->getPort(id_O); |
| 442 |
if (!o) |
| 443 |
break; |
| 444 |
if (o->users.entries() != 1) |
| 445 |
break; |
| 446 |
dff = (*o->users.begin()).cell; |
| 447 |
if (dff->type == id_NX_DFF && (*o->users.begin()).port == id_I) { |
| 448 |
if (cnt == 95) { // note that start_dff is also part of chain |
| 449 |
dff_chain_start.push_back(make_pair(start_dff, chain)); |
| 450 |
cnt = 0; |
| 451 |
start_dff = dff; |
| 452 |
chain.clear(); |
| 453 |
} else { |
| 454 |
chain.push_back(dff); |
| 455 |
cnt++; |
| 456 |
} |
| 457 |
} else |
| 458 |
break; |
| 459 |
} |
| 460 |
if (cnt) |
| 461 |
dff_chain_start.push_back(make_pair(start_dff, chain)); |
| 462 |
} |
| 463 |
|
| 464 |
int dff_only = 0, lut_and_ff = 0; |
| 465 |
for (auto ch : dff_chain_start) { |
| 466 |
CellInfo *dff = ch.first; |
| 467 |
CellInfo *root = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$fe", dff->name.c_str(ctx))); |
| 468 |
root->cluster = root->name; |
| 469 |
NetInfo *net = dff->getPort(id_I); |
| 470 |
if (net && net->driver.cell->type == id_NX_LUT && net->users.entries() == 1) { |
| 471 |
CellInfo *lut = net->driver.cell; |
| 472 |
if (!lut->params.count(id_lut_table)) |
| 473 |
log_error("Cell '%s' missing lut_table\n", lut->name.c_str(ctx)); |
| 474 |
lut_to_fe(lut, root, false, lut->params[id_lut_table]); |
| 475 |
packed_cells.insert(lut->name); |
| 476 |
dff_to_fe(dff, root, false); |
| 477 |
packed_cells.insert(dff->name); |
| 478 |
++lut_and_ff; |
| 479 |
} else { |
| 480 |
dff_to_fe(dff, root, true); |
| 481 |
packed_cells.insert(dff->name); |
| 482 |
++dff_only; |
| 483 |
} |
| 484 |
for (auto dff : ch.second) { |
| 485 |
CellInfo *new_cell = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$fe", dff->name.c_str(ctx))); |
| 486 |
dff_to_fe(dff, new_cell, true); |
| 487 |
++dff_only; |
| 488 |
root->constr_children.push_back(new_cell); |
| 489 |
new_cell->cluster = root->cluster; |
| 490 |
new_cell->constr_z = PLACE_DFF_CHAIN; |
| 491 |
packed_cells.insert(dff->name); |
| 492 |
} |
| 493 |
} |
| 494 |
if (lut_and_ff) |
| 495 |
log_info(" %6d FEs used as LUT and DFF\n", lut_and_ff); |
| 496 |
if (dff_only) |
| 497 |
log_info(" %6d FEs used as DFF only\n", dff_only); |
| 498 |
flush_cells(); |
| 499 |
} |
| 500 |
|
| 501 |
void NgUltraPacker::pack_lut_multi_dffs(void) |
| 502 |
{ |
| 503 |
log_info("Pack LUT-multi DFFs...\n"); |
| 504 |
|
| 505 |
int dff_only = 0, lut_and_ff = 0, bff_only = 0; |
| 506 |
; |
| 507 |
for (auto &cell : ctx->cells) { |
| 508 |
CellInfo &ci = *cell.second; |
| 509 |
if (!ci.type.in(id_NX_LUT)) |
| 510 |
continue; |
| 511 |
if (!ci.params.count(id_lut_table)) |
| 512 |
log_error("Cell '%s' missing lut_table\n", ci.name.c_str(ctx)); |
| 513 |
|
| 514 |
NetInfo *o = ci.getPort(id_O); |
| 515 |
if (o) { |
| 516 |
if (o->users.entries() < 2) |
| 517 |
continue; |
| 518 |
|
| 519 |
int cnt = 0; |
| 520 |
for (auto u : o->users) { |
| 521 |
if (u.cell->type == id_NX_DFF && u.cell->getPort(id_I) == o) |
| 522 |
cnt++; |
| 523 |
} |
| 524 |
if (cnt < 2) |
| 525 |
continue; |
| 526 |
|
| 527 |
CellInfo *root = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$fe", ci.name.c_str(ctx))); |
| 528 |
packed_cells.insert(ci.name); |
| 529 |
bind_attr_loc(root, &ci.attrs); |
| 530 |
lut_to_fe(&ci, root, false, ci.params[id_lut_table]); |
| 531 |
root->cluster = root->name; |
| 532 |
|
| 533 |
int max_use = (cnt == 4 && o->users.entries() == 4) ? 4 : 3; |
| 534 |
bool use_bff = max_use != 4 && cnt >= 4; |
| 535 |
int i = 0; |
| 536 |
std::vector<PortRef> users; |
| 537 |
for (auto u : o->users) { |
| 538 |
if (u.cell->type == id_NX_DFF && u.cell->getPort(id_I) == o) { |
| 539 |
if (i == 0) { |
| 540 |
packed_cells.insert(u.cell->name); |
| 541 |
dff_to_fe(u.cell, root, false); |
| 542 |
++lut_and_ff; |
| 543 |
} else if (i < max_use) { |
| 544 |
packed_cells.insert(u.cell->name); |
| 545 |
CellInfo *new_cell = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$fe", u.cell->name.c_str(ctx))); |
| 546 |
dff_to_fe(u.cell, new_cell, false); |
| 547 |
root->constr_children.push_back(new_cell); |
| 548 |
new_cell->cluster = root->cluster; |
| 549 |
new_cell->constr_z = PLACE_LUT_CHAIN; |
| 550 |
++dff_only; |
| 551 |
} else { |
| 552 |
use_bff = true; |
| 553 |
users.push_back(u); |
| 554 |
u.cell->disconnectPort(u.port); |
| 555 |
} |
| 556 |
i++; |
| 557 |
} else { |
| 558 |
use_bff = true; |
| 559 |
users.push_back(u); |
| 560 |
u.cell->disconnectPort(u.port); |
| 561 |
} |
| 562 |
} |
| 563 |
if (use_bff) { |
| 564 |
CellInfo *new_cell = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$bff", ci.name.c_str(ctx))); |
| 565 |
new_cell->params[id_dff_used] = Property(1, 1); |
| 566 |
new_cell->setParam(id_type, Property("BFF")); |
| 567 |
new_cell->connectPort(id_DI, o); |
| 568 |
root->constr_children.push_back(new_cell); |
| 569 |
new_cell->cluster = root->cluster; |
| 570 |
new_cell->constr_z = PLACE_LUT_CHAIN; |
| 571 |
bff_only++; |
| 572 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$new", o->name.c_str(ctx))); |
| 573 |
new_cell->connectPort(id_DO, new_out); |
| 574 |
for (auto &user : users) { |
| 575 |
user.cell->connectPort(user.port, new_out); |
| 576 |
} |
| 577 |
} |
| 578 |
} |
| 579 |
} |
| 580 |
if (dff_only) |
| 581 |
log_info(" %6d FEs used as DFF only\n", dff_only); |
| 582 |
if (bff_only) |
| 583 |
log_info(" %6d FEs used as BFF only\n", bff_only); |
| 584 |
if (lut_and_ff) |
| 585 |
log_info(" %6d FEs used as LUT and DFF\n", lut_and_ff); |
| 586 |
flush_cells(); |
| 587 |
} |
| 588 |
|
| 589 |
void NgUltraPacker::pack_lut_dffs(void) |
| 590 |
{ |
| 591 |
log_info("Pack LUT-DFFs...\n"); |
| 592 |
|
| 593 |
int lut_only = 0, lut_and_ff = 0; |
| 594 |
std::vector<CellInfo *> lut_list; |
| 595 |
for (auto &cell : ctx->cells) { |
| 596 |
CellInfo &ci = *cell.second; |
| 597 |
if (!ci.type.in(id_NX_LUT)) |
| 598 |
continue; |
| 599 |
if (!ci.params.count(id_lut_table)) |
| 600 |
log_error("Cell '%s' missing lut_table\n", ci.name.c_str(ctx)); |
| 601 |
packed_cells.insert(ci.name); |
| 602 |
lut_list.push_back(&ci); |
| 603 |
} |
| 604 |
for (auto ci : lut_list) { |
| 605 |
CellInfo *packed = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$fe", ci->name.c_str(ctx))); |
| 606 |
bind_attr_loc(packed, &ci->attrs); |
| 607 |
|
| 608 |
bool packed_dff = false; |
| 609 |
NetInfo *o = ci->getPort(id_O); |
| 610 |
if (o) { |
| 611 |
CellInfo *dff = net_only_drives(ctx, o, is_dff, id_I, true); |
| 612 |
if (dff) { |
| 613 |
if (ctx->verbose) |
| 614 |
log_info("found attached dff %s\n", dff->name.c_str(ctx)); |
| 615 |
lut_to_fe(ci, packed, false, ci->params[id_lut_table]); |
| 616 |
dff_to_fe(dff, packed, false); |
| 617 |
++lut_and_ff; |
| 618 |
packed_cells.insert(dff->name); |
| 619 |
if (ctx->verbose) |
| 620 |
log_info("packed cell %s into %s\n", dff->name.c_str(ctx), packed->name.c_str(ctx)); |
| 621 |
packed_dff = true; |
| 622 |
} |
| 623 |
} |
| 624 |
if (!packed_dff) { |
| 625 |
lut_to_fe(ci, packed, true, ci->params[id_lut_table]); |
| 626 |
++lut_only; |
| 627 |
} |
| 628 |
} |
| 629 |
if (lut_only) |
| 630 |
log_info(" %6d FEs used as LUT only\n", lut_only); |
| 631 |
if (lut_and_ff) |
| 632 |
log_info(" %6d FEs used as LUT and DFF\n", lut_and_ff); |
| 633 |
flush_cells(); |
| 634 |
} |
| 635 |
|
| 636 |
void NgUltraPacker::pack_dffs(void) |
| 637 |
{ |
| 638 |
int dff_only = 0; |
| 639 |
std::vector<CellInfo *> dff_list; |
| 640 |
for (auto &cell : ctx->cells) { |
| 641 |
CellInfo &ci = *cell.second; |
| 642 |
if (!ci.type.in(id_NX_DFF, id_NX_BFF)) |
| 643 |
continue; |
| 644 |
packed_cells.insert(ci.name); |
| 645 |
dff_list.push_back(&ci); |
| 646 |
} |
| 647 |
for (auto ci : dff_list) { |
| 648 |
CellInfo *packed = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$fe", ci->name.c_str(ctx))); |
| 649 |
dff_to_fe(ci, packed, true); |
| 650 |
bind_attr_loc(packed, &ci->attrs); |
| 651 |
++dff_only; |
| 652 |
} |
| 653 |
if (dff_only) |
| 654 |
log_info(" %6d FEs used as DFF only\n", dff_only); |
| 655 |
flush_cells(); |
| 656 |
} |
| 657 |
|
| 658 |
void NgUltraPacker::pack_iobs(void) |
| 659 |
{ |
| 660 |
log_info("Pack IOBs...\n"); |
| 661 |
// Trim nextpnr IOBs - assume IO buffer insertion has been done in synthesis |
| 662 |
for (auto &port : ctx->ports) { |
| 663 |
if (!ctx->cells.count(port.first)) |
| 664 |
log_error("Port '%s' doesn't seem to have a corresponding top level IO\n", ctx->nameOf(port.first)); |
| 665 |
CellInfo *ci = ctx->cells.at(port.first).get(); |
| 666 |
|
| 667 |
PortRef top_port; |
| 668 |
top_port.cell = nullptr; |
| 669 |
bool is_npnr_iob = false; |
| 670 |
|
| 671 |
if (ci->type == ctx->id("$nextpnr_ibuf") || ci->type == ctx->id("$nextpnr_iobuf")) { |
| 672 |
// Might have an input buffer connected to it |
| 673 |
is_npnr_iob = true; |
| 674 |
NetInfo *o = ci->getPort(id_O); |
| 675 |
if (o == nullptr) |
| 676 |
; |
| 677 |
else if (o->users.entries() > 1) |
| 678 |
log_error("Top level pin '%s' has multiple input buffers\n", ctx->nameOf(port.first)); |
| 679 |
else if (o->users.entries() == 1) |
| 680 |
top_port = *o->users.begin(); |
| 681 |
} |
| 682 |
if (ci->type == ctx->id("$nextpnr_obuf") || ci->type == ctx->id("$nextpnr_iobuf")) { |
| 683 |
// Might have an output buffer connected to it |
| 684 |
is_npnr_iob = true; |
| 685 |
NetInfo *i = ci->getPort(id_I); |
| 686 |
if (i != nullptr && i->driver.cell != nullptr) { |
| 687 |
if (top_port.cell != nullptr) |
| 688 |
log_error("Top level pin '%s' has multiple input/output buffers\n", ctx->nameOf(port.first)); |
| 689 |
top_port = i->driver; |
| 690 |
} |
| 691 |
// Edge case of a bidirectional buffer driving an output pin |
| 692 |
if (i->users.entries() > 2) { |
| 693 |
log_error("Top level pin '%s' has illegal buffer configuration\n", ctx->nameOf(port.first)); |
| 694 |
} else if (i->users.entries() == 2) { |
| 695 |
if (top_port.cell != nullptr) |
| 696 |
log_error("Top level pin '%s' has illegal buffer configuration\n", ctx->nameOf(port.first)); |
| 697 |
for (auto &usr : i->users) { |
| 698 |
if (usr.cell->type == ctx->id("$nextpnr_obuf") || usr.cell->type == ctx->id("$nextpnr_iobuf")) |
| 699 |
continue; |
| 700 |
top_port = usr; |
| 701 |
break; |
| 702 |
} |
| 703 |
} |
| 704 |
} |
| 705 |
if (!is_npnr_iob) |
| 706 |
log_error("Port '%s' doesn't seem to have a corresponding top level IO (internal cell type mismatch)\n", |
| 707 |
ctx->nameOf(port.first)); |
| 708 |
|
| 709 |
if (top_port.cell == nullptr) { |
| 710 |
log_info("Trimming port '%s' as it is unused.\n", ctx->nameOf(port.first)); |
| 711 |
} else { |
| 712 |
// Copy attributes to real IO buffer |
| 713 |
for (auto &attrs : ci->attrs) |
| 714 |
top_port.cell->attrs[attrs.first] = attrs.second; |
| 715 |
for (auto ¶ms : ci->params) |
| 716 |
top_port.cell->params[params.first] = params.second; |
| 717 |
|
| 718 |
// Make sure that top level net is set correctly |
| 719 |
port.second.net = top_port.cell->ports.at(top_port.port).net; |
| 720 |
} |
| 721 |
// Now remove the nextpnr-inserted buffer |
| 722 |
ci->disconnectPort(id_I); |
| 723 |
ci->disconnectPort(id_O); |
| 724 |
ctx->cells.erase(port.first); |
| 725 |
} |
| 726 |
std::vector<CellInfo *> to_update; |
| 727 |
for (auto &cell : ctx->cells) { |
| 728 |
CellInfo &ci = *cell.second; |
| 729 |
if (!ci.type.in(id_NX_IOB_I, id_NX_IOB_O, id_NX_IOB)) |
| 730 |
continue; |
| 731 |
if (ci.params.count(id_location) == 0) { |
| 732 |
log_error("Unconstrained IO:%s\n", ctx->nameOf(&ci)); |
| 733 |
} |
| 734 |
std::string loc = ci.params.at(id_location).to_string(); |
| 735 |
BelId bel = ctx->get_package_pin_bel(ctx->id(loc)); |
| 736 |
if (bel == BelId()) |
| 737 |
log_error("Unable to constrain IO '%s', device does not have a pin named '%s'\n", ci.name.c_str(ctx), |
| 738 |
loc.c_str()); |
| 739 |
log_info(" Constraining '%s' to pad '%s'\n", ci.name.c_str(ctx), loc.c_str()); |
| 740 |
if (!ctx->checkBelAvail(bel)) { |
| 741 |
log_error("Can't place %s at %s because it's already taken by %s\n", ctx->nameOf(&ci), ctx->nameOfBel(bel), |
| 742 |
ctx->nameOf(ctx->getBoundBelCell(bel))); |
| 743 |
} |
| 744 |
|
| 745 |
IdString new_type = id_IOP; |
| 746 |
disconnect_if_gnd(&ci, id_T); |
| 747 |
if (ci.getPort(id_T)) { |
| 748 |
// In case T input is used must use different types |
| 749 |
new_type = id_IOTP; |
| 750 |
if (ci.type == id_NX_IOB_O) |
| 751 |
new_type = id_OTP; |
| 752 |
if (ci.type == id_NX_IOB_I) |
| 753 |
new_type = id_ITP; |
| 754 |
} else { |
| 755 |
if (ci.type == id_NX_IOB_O) |
| 756 |
new_type = id_OP; |
| 757 |
if (ci.type == id_NX_IOB_I) |
| 758 |
new_type = id_IP; |
| 759 |
} |
| 760 |
ci.type = new_type; |
| 761 |
ctx->bindBel(bel, &ci, PlaceStrength::STRENGTH_LOCKED); |
| 762 |
if (!ctx->isValidBelForCellType(new_type, bel)) |
| 763 |
log_error("Invalid type of IO for specified location %s %s.\n", new_type.c_str(ctx), |
| 764 |
ctx->getBelType(bel).c_str(ctx)); |
| 765 |
to_update.push_back(&ci); |
| 766 |
} |
| 767 |
int bfr_added = 0; |
| 768 |
int dfr_added = 0; |
| 769 |
int ddfr_added = 0; |
| 770 |
for (auto cell : to_update) { |
| 771 |
NetInfo *c_net = cell->getPort(id_C); |
| 772 |
if (!c_net) |
| 773 |
log_error("C input of IO primitive %s must be connected.\n", cell->name.c_str(ctx)); |
| 774 |
if (c_net->name == ctx->id("$PACKER_GND") && !cell->getPort(id_O)) { |
| 775 |
log_warning("O port of IO primitive %s must be connected. Removing cell.\n", cell->name.c_str(ctx)); |
| 776 |
packed_cells.emplace(cell->name); |
| 777 |
continue; |
| 778 |
} |
| 779 |
if (c_net->name == ctx->id("$PACKER_VCC") && !cell->getPort(id_I)) { |
| 780 |
log_warning("I port of IO primitive %s must be connected. Removing cell.\n", cell->name.c_str(ctx)); |
| 781 |
packed_cells.emplace(cell->name); |
| 782 |
continue; |
| 783 |
} |
| 784 |
if (!cell->getPort(id_I) && !cell->getPort(id_O)) { |
| 785 |
log_warning("I or O port of IO primitive %s must be connected. Removing cell.\n", cell->name.c_str(ctx)); |
| 786 |
packed_cells.emplace(cell->name); |
| 787 |
continue; |
| 788 |
} |
| 789 |
|
| 790 |
{ |
| 791 |
CellInfo *iod = net_driven_by(ctx, c_net, is_dfr, id_O); |
| 792 |
if (iod && c_net->users.entries() != 1) |
| 793 |
log_error("NX_DFR '%s' can only directly drive IOB.\n", iod->name.c_str(ctx)); |
| 794 |
if (!iod) { |
| 795 |
iod = net_driven_by(ctx, c_net, is_ddfr, id_O); |
| 796 |
if (iod && c_net->users.entries() != 1) |
| 797 |
log_error("NX_DDFR '%s' can only directly drive IOB.\n", iod->name.c_str(ctx)); |
| 798 |
if (!iod) { |
| 799 |
bfr_added++; |
| 800 |
iod = create_cell_ptr(id_BFR, ctx->idf("%s$iod_cd", cell->name.c_str(ctx))); |
| 801 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$O", iod->name.c_str(ctx))); |
| 802 |
iod->setParam(id_iobname, str_or_default(cell->params, id_iobname, "")); |
| 803 |
cell->disconnectPort(id_C); |
| 804 |
if (c_net->name == ctx->id("$PACKER_GND")) |
| 805 |
iod->setParam(id_mode, Property(0, 2)); |
| 806 |
else if (c_net->name == ctx->id("$PACKER_VCC")) |
| 807 |
iod->setParam(id_mode, Property(1, 2)); |
| 808 |
else { |
| 809 |
iod->connectPort(id_I, c_net); |
| 810 |
iod->setParam(id_mode, Property(2, 2)); |
| 811 |
iod->setParam(id_data_inv, Property(0, 1)); |
| 812 |
} |
| 813 |
iod->connectPort(id_O, new_out); |
| 814 |
cell->connectPort(id_C, new_out); |
| 815 |
} else { |
| 816 |
ddfr_added++; |
| 817 |
iod->type = id_DDFR; |
| 818 |
iod->setParam(id_iobname, str_or_default(cell->params, id_iobname, "")); |
| 819 |
iod->setParam(id_path, Property(2, 2)); |
| 820 |
ddfr_rewrite(iod); |
| 821 |
disconnect_unused(iod, id_O2); |
| 822 |
disconnect_if_gnd(iod, id_L); |
| 823 |
disconnect_if_gnd(iod, id_R); |
| 824 |
} |
| 825 |
} else { |
| 826 |
dfr_added++; |
| 827 |
iod->type = id_DFR; |
| 828 |
iod->setParam(id_iobname, str_or_default(cell->params, id_iobname, "")); |
| 829 |
dff_rewrite(iod); |
| 830 |
} |
| 831 |
Loc cd_loc = cell->getLocation(); |
| 832 |
cd_loc.z += 3; |
| 833 |
BelId bel = ctx->getBelByLocation(cd_loc); |
| 834 |
ctx->bindBel(bel, iod, PlaceStrength::STRENGTH_LOCKED); |
| 835 |
} |
| 836 |
NetInfo *i_net = cell->getPort(id_I); |
| 837 |
if (i_net) { |
| 838 |
CellInfo *iod = net_driven_by(ctx, i_net, is_dfr, id_O); |
| 839 |
if (iod && i_net->users.entries() != 1) |
| 840 |
log_error("NX_DFR '%s' can only directly drive IOB.\n", iod->name.c_str(ctx)); |
| 841 |
if (!iod) { |
| 842 |
iod = net_driven_by(ctx, i_net, is_ddfr, id_O); |
| 843 |
if (iod && i_net->users.entries() != 1) |
| 844 |
log_error("NX_DDFR '%s' can only directly drive IOB.\n", iod->name.c_str(ctx)); |
| 845 |
if (!iod) { |
| 846 |
bfr_added++; |
| 847 |
iod = create_cell_ptr(id_BFR, ctx->idf("%s$iod_od", cell->name.c_str(ctx))); |
| 848 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$O", iod->name.c_str(ctx))); |
| 849 |
iod->setParam(id_iobname, str_or_default(cell->params, id_iobname, "")); |
| 850 |
cell->disconnectPort(id_I); |
| 851 |
if (i_net->name == ctx->id("$PACKER_GND")) |
| 852 |
iod->setParam(id_mode, Property(0, 2)); |
| 853 |
else if (i_net->name == ctx->id("$PACKER_VCC")) |
| 854 |
iod->setParam(id_mode, Property(1, 2)); |
| 855 |
else { |
| 856 |
iod->connectPort(id_I, i_net); |
| 857 |
iod->setParam(id_mode, Property(2, 2)); |
| 858 |
iod->setParam(id_data_inv, Property(0, 1)); |
| 859 |
} |
| 860 |
iod->connectPort(id_O, new_out); |
| 861 |
cell->connectPort(id_I, new_out); |
| 862 |
} else { |
| 863 |
ddfr_added++; |
| 864 |
iod->type = id_DDFR; |
| 865 |
iod->setParam(id_iobname, str_or_default(cell->params, id_iobname, "")); |
| 866 |
iod->setParam(id_path, Property(0, 2)); |
| 867 |
ddfr_rewrite(iod); |
| 868 |
disconnect_unused(iod, id_O2); |
| 869 |
disconnect_if_gnd(iod, id_L); |
| 870 |
disconnect_if_gnd(iod, id_R); |
| 871 |
} |
| 872 |
} else { |
| 873 |
dfr_added++; |
| 874 |
iod->type = id_DFR; |
| 875 |
iod->setParam(id_iobname, str_or_default(cell->params, id_iobname, "")); |
| 876 |
dff_rewrite(iod); |
| 877 |
} |
| 878 |
Loc cd_loc = cell->getLocation(); |
| 879 |
cd_loc.z += 2; |
| 880 |
BelId bel = ctx->getBelByLocation(cd_loc); |
| 881 |
ctx->bindBel(bel, iod, PlaceStrength::STRENGTH_LOCKED); |
| 882 |
} |
| 883 |
|
| 884 |
NetInfo *o_net = cell->getPort(id_O); |
| 885 |
if (o_net) { |
| 886 |
CellInfo *iod = net_only_drives(ctx, o_net, is_dfr, id_I, true); |
| 887 |
if (!(o_net->users.entries() == 1 && (*o_net->users.begin()).cell->type == id_NX_IOM_U)) { |
| 888 |
bool bfr_mode = false; |
| 889 |
bool ddfr_mode = false; |
| 890 |
if (!iod) { |
| 891 |
iod = net_only_drives(ctx, o_net, is_ddfr, id_I, true); |
| 892 |
if (!iod) { |
| 893 |
bfr_added++; |
| 894 |
iod = create_cell_ptr(id_BFR, ctx->idf("%s$iod_id", cell->name.c_str(ctx))); |
| 895 |
NetInfo *new_in = ctx->createNet(ctx->idf("%s$I", iod->name.c_str(ctx))); |
| 896 |
iod->setParam(id_iobname, str_or_default(cell->params, id_iobname, "")); |
| 897 |
cell->disconnectPort(id_O); |
| 898 |
iod->connectPort(id_O, o_net); |
| 899 |
iod->setParam(id_mode, Property(2, 2)); |
| 900 |
iod->setParam(id_data_inv, Property(0, 1)); |
| 901 |
iod->connectPort(id_I, new_in); |
| 902 |
cell->connectPort(id_O, new_in); |
| 903 |
bfr_mode = true; |
| 904 |
} else { |
| 905 |
ddfr_mode = true; |
| 906 |
ddfr_added++; |
| 907 |
iod->type = id_DDFR; |
| 908 |
iod->setParam(id_iobname, str_or_default(cell->params, id_iobname, "")); |
| 909 |
iod->setParam(id_path, Property(1, 2)); |
| 910 |
ddfr_rewrite(iod); |
| 911 |
disconnect_if_gnd(iod, id_I2); |
| 912 |
disconnect_if_gnd(iod, id_L); |
| 913 |
disconnect_if_gnd(iod, id_R); |
| 914 |
} |
| 915 |
} else { |
| 916 |
dfr_added++; |
| 917 |
iod->type = id_DFR; |
| 918 |
iod->setParam(id_iobname, str_or_default(cell->params, id_iobname, "")); |
| 919 |
dff_rewrite(iod); |
| 920 |
} |
| 921 |
Loc cd_loc = cell->getLocation(); |
| 922 |
cd_loc.z += 1; |
| 923 |
BelId bel = ctx->getBelByLocation(cd_loc); |
| 924 |
ctx->bindBel(bel, iod, PlaceStrength::STRENGTH_LOCKED); |
| 925 |
|
| 926 |
// Depending of DDFR mode we must use one of dedicated routes (ITCs) |
| 927 |
if (!ddfr_mode && ctx->getBelType(bel) == id_DDFR) { |
| 928 |
WireId dwire = ctx->getBelPinWire(bel, id_O); |
| 929 |
for (PipId pip : ctx->getPipsDownhill(dwire)) { |
| 930 |
const auto &extra_data = *uarch->pip_extra_data(pip); |
| 931 |
if (!extra_data.name) |
| 932 |
continue; |
| 933 |
if (extra_data.type != PipExtra::PIP_EXTRA_MUX) |
| 934 |
continue; |
| 935 |
if (bfr_mode && extra_data.input == 2) { |
| 936 |
uarch->blocked_pips.emplace(pip); |
| 937 |
} else if (!bfr_mode && extra_data.input == 1) { |
| 938 |
uarch->blocked_pips.emplace(pip); |
| 939 |
} |
| 940 |
} |
| 941 |
} |
| 942 |
} |
| 943 |
} |
| 944 |
} |
| 945 |
if (ddfr_added) |
| 946 |
log_info(" %6d DDFRs used as DDFR\n", ddfr_added); |
| 947 |
if (dfr_added) |
| 948 |
log_info(" %6d DFRs/DDFRs used as DFR\n", dfr_added); |
| 949 |
if (bfr_added) |
| 950 |
log_info(" %6d DFRs/DDFRs used as BFR\n", bfr_added); |
| 951 |
flush_cells(); |
| 952 |
} |
| 953 |
|
| 954 |
void NgUltraPacker::pack_ioms(void) |
| 955 |
{ |
| 956 |
log_info("Pack IOMs...\n"); |
| 957 |
for (auto &cell : ctx->cells) { |
| 958 |
CellInfo &ci = *cell.second; |
| 959 |
if (!ci.type.in(id_NX_IOM_U)) |
| 960 |
continue; |
| 961 |
ci.type = id_IOM; |
| 962 |
IdString iob; |
| 963 |
for (auto &port : ci.ports) { |
| 964 |
if (port.second.type == PORT_IN && port.second.net != nullptr) { |
| 965 |
if (port.second.net->name == ctx->id("$PACKER_GND")) |
| 966 |
ci.disconnectPort(port.first); |
| 967 |
else if (port.second.net->driver.cell != nullptr && |
| 968 |
port.second.net->driver.cell->type.in(id_IP, id_OP, id_IOP, id_ITP, id_OTP, id_IOTP)) { |
| 969 |
IdString loc = uarch->tile_name_id(port.second.net->driver.cell->bel.tile); |
| 970 |
if (iob != IdString() && loc != iob) { |
| 971 |
log_error("Unable to constrain IOM '%s', connection to multiple IO banks exist.\n", |
| 972 |
ci.name.c_str(ctx)); |
| 973 |
} |
| 974 |
iob = loc; |
| 975 |
} |
| 976 |
} |
| 977 |
} |
| 978 |
if (iob == IdString()) |
| 979 |
log_error("Unable to constrain IOM '%s', no connection to nearby IO banks found.\n", ci.name.c_str(ctx)); |
| 980 |
log_info(" Constraining '%s' to bank '%s'\n", ci.name.c_str(ctx), iob.c_str(ctx)); |
| 981 |
BelId bel = uarch->iom_bels[iob]; |
| 982 |
if (!ctx->checkBelAvail(bel)) { |
| 983 |
log_error("Can't place %s at %s because it's already taken by %s\n", ctx->nameOf(&ci), ctx->nameOfBel(bel), |
| 984 |
ctx->nameOf(ctx->getBoundBelCell(bel))); |
| 985 |
} |
| 986 |
ctx->bindBel(bel, &ci, PlaceStrength::STRENGTH_LOCKED); |
| 987 |
} |
| 988 |
} |
| 989 |
|
| 990 |
void NgUltraPacker::pack_cy_input_and_output(CellInfo *cy, IdString cluster, IdString in_port, IdString out_port, |
| 991 |
int placer, int &lut_only, int &lut_and_ff, int &dff_only) |
| 992 |
{ |
| 993 |
CellInfo *fe = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$%s", cy->name.c_str(ctx), in_port.c_str(ctx))); |
| 994 |
NetInfo *net = cy->getPort(in_port); |
| 995 |
if (net) { |
| 996 |
if (net->name.in(ctx->id("$PACKER_GND"), ctx->id("$PACKER_VCC"))) { |
| 997 |
fe->params[id_lut_table] = Property((net->name == ctx->id("$PACKER_GND")) ? 0x0000 : 0xffff, 16); |
| 998 |
fe->params[id_lut_used] = Property(1, 1); |
| 999 |
cy->disconnectPort(in_port); |
| 1000 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$o", fe->name.c_str(ctx))); |
| 1001 |
fe->connectPort(id_LO, new_out); |
| 1002 |
cy->connectPort(in_port, new_out); |
| 1003 |
} else { |
| 1004 |
fe->params[id_lut_table] = Property(0xaaaa, 16); |
| 1005 |
fe->params[id_lut_used] = Property(1, 1); |
| 1006 |
cy->disconnectPort(in_port); |
| 1007 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$o", fe->name.c_str(ctx))); |
| 1008 |
fe->connectPort(id_I1, net); |
| 1009 |
fe->connectPort(id_LO, new_out); |
| 1010 |
cy->connectPort(in_port, new_out); |
| 1011 |
} |
| 1012 |
lut_only++; |
| 1013 |
} |
| 1014 |
net = cy->getPort(out_port); |
| 1015 |
CellInfo *dff = net_only_drives(ctx, net, is_dff, id_I, true); |
| 1016 |
if (dff) { |
| 1017 |
if (ctx->verbose) |
| 1018 |
log_info("found attached dff %s\n", dff->name.c_str(ctx)); |
| 1019 |
dff_to_fe(dff, fe, false); |
| 1020 |
packed_cells.insert(dff->name); |
| 1021 |
if (net) { |
| 1022 |
lut_only--; |
| 1023 |
lut_and_ff++; |
| 1024 |
} else |
| 1025 |
dff_only++; |
| 1026 |
} else { |
| 1027 |
fe->timing_index = ctx->get_cell_timing_idx(id_BEYOND_FE_LUT); |
| 1028 |
} |
| 1029 |
fe->cluster = cluster; |
| 1030 |
fe->constr_z = placer; |
| 1031 |
cy->constr_children.push_back(fe); |
| 1032 |
} |
| 1033 |
|
| 1034 |
void NgUltraPacker::exchange_if_constant(CellInfo *cell, IdString input1, IdString input2) |
| 1035 |
{ |
| 1036 |
NetInfo *net1 = cell->getPort(input1); |
| 1037 |
NetInfo *net2 = cell->getPort(input2); |
| 1038 |
// GND on A |
| 1039 |
if (net1->name.in(ctx->id("$PACKER_GND"))) { |
| 1040 |
return; |
| 1041 |
} |
| 1042 |
// VCC on A -> exchange |
| 1043 |
// if GND on B and not on A -> exchange |
| 1044 |
if (net1->name.in(ctx->id("$PACKER_VCC")) || net2->name.in(ctx->id("$PACKER_GND"))) { |
| 1045 |
cell->disconnectPort(input1); |
| 1046 |
cell->disconnectPort(input2); |
| 1047 |
cell->connectPort(input1, net2); |
| 1048 |
cell->connectPort(input2, net1); |
| 1049 |
} |
| 1050 |
} |
| 1051 |
|
| 1052 |
void NgUltraPacker::pack_cys(void) |
| 1053 |
{ |
| 1054 |
log_info("Packing carries..\n"); |
| 1055 |
std::vector<CellInfo *> root_cys; |
| 1056 |
int lut_only = 0, lut_and_ff = 0, dff_only = 0; |
| 1057 |
for (auto &cell : ctx->cells) { |
| 1058 |
CellInfo *ci = cell.second.get(); |
| 1059 |
if (ci->type != id_NX_CY) |
| 1060 |
continue; |
| 1061 |
bind_attr_loc(ci, &ci->attrs); |
| 1062 |
NetInfo *ci_net = ci->getPort(id_CI); |
| 1063 |
if (!ci_net || !ci_net->driver.cell || ci_net->driver.cell->type != id_NX_CY) { |
| 1064 |
root_cys.push_back(ci); |
| 1065 |
} |
| 1066 |
for (int i = 1; i <= 4; i++) { |
| 1067 |
connect_gnd_if_unconnected(ci, ctx->idf("A%d", i), false); |
| 1068 |
connect_gnd_if_unconnected(ci, ctx->idf("B%d", i), false); |
| 1069 |
exchange_if_constant(ci, ctx->idf("A%d", i), ctx->idf("B%d", i)); |
| 1070 |
} |
| 1071 |
NetInfo *co_net = ci->getPort(id_CO); |
| 1072 |
if (!co_net) { |
| 1073 |
disconnect_unused(ci, id_CO); |
| 1074 |
// Disconnect unused ports on last CY in chain |
| 1075 |
// at least id_A1 and id_B1 will be connected |
| 1076 |
// Reverse direction, must stop if used, then |
| 1077 |
// rest is used as well |
| 1078 |
if (!ci->getPort(id_S4)) { |
| 1079 |
disconnect_unused(ci, id_S4); |
| 1080 |
disconnect_unused(ci, id_A4); |
| 1081 |
disconnect_unused(ci, id_B4); |
| 1082 |
if (!ci->getPort(id_S3)) { |
| 1083 |
disconnect_unused(ci, id_S3); |
| 1084 |
disconnect_unused(ci, id_A3); |
| 1085 |
disconnect_unused(ci, id_B3); |
| 1086 |
if (!ci->getPort(id_S2)) { |
| 1087 |
disconnect_unused(ci, id_S2); |
| 1088 |
disconnect_unused(ci, id_A2); |
| 1089 |
disconnect_unused(ci, id_B2); |
| 1090 |
}; |
| 1091 |
} |
| 1092 |
} |
| 1093 |
} |
| 1094 |
} |
| 1095 |
|
| 1096 |
std::vector<std::vector<CellInfo *>> groups; |
| 1097 |
for (auto root : root_cys) { |
| 1098 |
std::vector<CellInfo *> group; |
| 1099 |
CellInfo *cy = root; |
| 1100 |
group.push_back(cy); |
| 1101 |
while (true) { |
| 1102 |
NetInfo *co_net = cy->getPort(id_CO); |
| 1103 |
if (co_net && co_net->users.entries() > 0) { |
| 1104 |
cy = (*co_net->users.begin()).cell; |
| 1105 |
if (cy->type != id_NX_CY || co_net->users.entries() != 1) { |
| 1106 |
log_warning("Cells %s CO output connected to:\n", group.back()->name.c_str(ctx)); |
| 1107 |
for (auto user : co_net->users) |
| 1108 |
log_warning("\t%s of type %s\n", user.cell->name.c_str(ctx), user.cell->type.c_str(ctx)); |
| 1109 |
log_error("NX_CY can only be chained with one other NX_CY cell\n"); |
| 1110 |
} |
| 1111 |
group.push_back(cy); |
| 1112 |
} else |
| 1113 |
break; |
| 1114 |
} |
| 1115 |
groups.push_back(group); |
| 1116 |
} |
| 1117 |
|
| 1118 |
for (auto &grp : groups) { |
| 1119 |
CellInfo *root = grp.front(); |
| 1120 |
root->type = id_CY; |
| 1121 |
root->cluster = root->name; |
| 1122 |
if (grp.size() > 24) |
| 1123 |
log_error("NX_CY chains are limited to contain 24 elements maximum.\n"); |
| 1124 |
|
| 1125 |
for (int i = 0; i < int(grp.size()); i++) { |
| 1126 |
CellInfo *cy = grp.at(i); |
| 1127 |
cy->type = id_CY; |
| 1128 |
if (i != 0) { |
| 1129 |
cy->cluster = root->name; |
| 1130 |
root->constr_children.push_back(cy); |
| 1131 |
cy->constr_z = PLACE_CY_CHAIN; |
| 1132 |
} |
| 1133 |
pack_cy_input_and_output(cy, root->name, id_B1, id_S1, PLACE_CY_FE1, lut_only, lut_and_ff, dff_only); |
| 1134 |
// Must check for B input otherwise we have bogus FEs |
| 1135 |
if (cy->getPort(id_B2)) |
| 1136 |
pack_cy_input_and_output(cy, root->name, id_B2, id_S2, PLACE_CY_FE2, lut_only, lut_and_ff, dff_only); |
| 1137 |
if (cy->getPort(id_B3)) |
| 1138 |
pack_cy_input_and_output(cy, root->name, id_B3, id_S3, PLACE_CY_FE3, lut_only, lut_and_ff, dff_only); |
| 1139 |
if (cy->getPort(id_B4)) |
| 1140 |
pack_cy_input_and_output(cy, root->name, id_B4, id_S4, PLACE_CY_FE4, lut_only, lut_and_ff, dff_only); |
| 1141 |
NetInfo *net = cy->getPort(id_CI); |
| 1142 |
if (net) { |
| 1143 |
if (net->name.in(ctx->id("$PACKER_GND"), ctx->id("$PACKER_VCC"))) { |
| 1144 |
// Constant driver for CI is configuration |
| 1145 |
cy->disconnectPort(id_CI); |
| 1146 |
} else { |
| 1147 |
if (net->driver.cell && net->driver.cell->type != id_CY) |
| 1148 |
log_error("CI must be constant or driven by CO in cell '%s'\n", cy->name.c_str(ctx)); |
| 1149 |
} |
| 1150 |
} |
| 1151 |
} |
| 1152 |
} |
| 1153 |
if (lut_only) |
| 1154 |
log_info(" %6d FEs used as LUT only\n", lut_only); |
| 1155 |
if (lut_and_ff) |
| 1156 |
log_info(" %6d FEs used as LUT and DFF\n", lut_and_ff); |
| 1157 |
if (dff_only) |
| 1158 |
log_info(" %6d FEs used as DFF only\n", dff_only); |
| 1159 |
flush_cells(); |
| 1160 |
} |
| 1161 |
|
| 1162 |
void NgUltraPacker::pack_xrf_input_and_output(CellInfo *xrf, IdString cluster, IdString in_port, IdString out_port, |
| 1163 |
ClusterPlacement placement, int &lut_only, int &lut_and_ff, int &dff_only) |
| 1164 |
{ |
| 1165 |
NetInfo *net = xrf->getPort(in_port); |
| 1166 |
NetInfo *net_out = nullptr; |
| 1167 |
if (out_port != IdString()) { |
| 1168 |
net_out = xrf->getPort(out_port); |
| 1169 |
if (net_out && net_out->users.entries() == 0) { |
| 1170 |
xrf->disconnectPort(out_port); |
| 1171 |
net_out = nullptr; |
| 1172 |
} |
| 1173 |
} |
| 1174 |
if (!net && !net_out) |
| 1175 |
return; |
| 1176 |
IdString name = in_port; |
| 1177 |
if (name == IdString()) |
| 1178 |
name = out_port; |
| 1179 |
CellInfo *fe = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$%s", xrf->name.c_str(ctx), name.c_str(ctx))); |
| 1180 |
|
| 1181 |
if (net) { |
| 1182 |
if (net->name.in(ctx->id("$PACKER_GND"), ctx->id("$PACKER_VCC"))) { |
| 1183 |
fe->params[id_lut_table] = Property((net->name == ctx->id("$PACKER_GND")) ? 0x0000 : 0xffff, 16); |
| 1184 |
fe->params[id_lut_used] = Property(1, 1); |
| 1185 |
xrf->disconnectPort(in_port); |
| 1186 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$o", fe->name.c_str(ctx))); |
| 1187 |
fe->connectPort(id_LO, new_out); |
| 1188 |
xrf->connectPort(in_port, new_out); |
| 1189 |
} else { |
| 1190 |
CellInfo *lut = net_driven_by(ctx, net, is_lut, id_O); |
| 1191 |
if (lut && net->users.entries() == 1) { |
| 1192 |
if (!lut->params.count(id_lut_table)) |
| 1193 |
log_error("Cell '%s' missing lut_table\n", lut->name.c_str(ctx)); |
| 1194 |
lut_to_fe(lut, fe, false, lut->params[id_lut_table]); |
| 1195 |
packed_cells.insert(lut->name); |
| 1196 |
} else { |
| 1197 |
fe->params[id_lut_table] = Property(0xaaaa, 16); |
| 1198 |
fe->params[id_lut_used] = Property(1, 1); |
| 1199 |
xrf->disconnectPort(in_port); |
| 1200 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$o", fe->name.c_str(ctx))); |
| 1201 |
fe->connectPort(id_I1, net); |
| 1202 |
fe->connectPort(id_LO, new_out); |
| 1203 |
xrf->connectPort(in_port, new_out); |
| 1204 |
} |
| 1205 |
} |
| 1206 |
lut_only++; |
| 1207 |
} |
| 1208 |
if (net_out) { |
| 1209 |
CellInfo *dff = net_only_drives(ctx, net_out, is_dff, id_I, true); |
| 1210 |
if (dff) { |
| 1211 |
if (ctx->verbose) |
| 1212 |
log_info("found attached dff %s\n", dff->name.c_str(ctx)); |
| 1213 |
dff_to_fe(dff, fe, false); |
| 1214 |
packed_cells.insert(dff->name); |
| 1215 |
if (net) { |
| 1216 |
lut_only--; |
| 1217 |
lut_and_ff++; |
| 1218 |
} else |
| 1219 |
dff_only++; |
| 1220 |
} |
| 1221 |
} |
| 1222 |
fe->cluster = cluster; |
| 1223 |
fe->constr_z = placement; |
| 1224 |
xrf->constr_children.push_back(fe); |
| 1225 |
} |
| 1226 |
|
| 1227 |
void NgUltraPacker::disconnect_unused(CellInfo *cell, IdString port) |
| 1228 |
{ |
| 1229 |
NetInfo *net = cell->getPort(port); |
| 1230 |
if (net) { |
| 1231 |
// NanoXplore tools usually connects 0 to unused port, no need to warn |
| 1232 |
// Sometimes there is unused nets, so number of entries is zero |
| 1233 |
if (net->users.entries() != 0 && !net->name.in(ctx->id("$PACKER_GND"))) |
| 1234 |
log_warning("Disconnected unused port '%s' from cell '%s'.\n", port.c_str(ctx), cell->name.c_str(ctx)); |
| 1235 |
cell->disconnectPort(port); |
| 1236 |
} |
| 1237 |
} |
| 1238 |
|
| 1239 |
void NgUltraPacker::pack_rfs(void) |
| 1240 |
{ |
| 1241 |
log_info("Packing RFs..\n"); |
| 1242 |
int lut_only = 0, lut_and_ff = 0, dff_only = 0; |
| 1243 |
for (auto &cell : ctx->cells) { |
| 1244 |
CellInfo &ci = *cell.second; |
| 1245 |
if (!ci.type.in(id_NX_RFB_U)) |
| 1246 |
continue; |
| 1247 |
int mode = int_or_default(ci.params, id_mode, 0); |
| 1248 |
switch (mode) { |
| 1249 |
case 0: |
| 1250 |
ci.type = id_RF; |
| 1251 |
break; |
| 1252 |
case 1: |
| 1253 |
ci.type = id_RFSP; |
| 1254 |
break; |
| 1255 |
case 2: |
| 1256 |
ci.type = id_XHRF; |
| 1257 |
break; |
| 1258 |
case 3: |
| 1259 |
ci.type = id_XWRF; |
| 1260 |
break; |
| 1261 |
case 4: |
| 1262 |
ci.type = id_XPRF; |
| 1263 |
break; |
| 1264 |
default: |
| 1265 |
log_error("Unknown mode %d for cell '%s'.\n", mode, ci.name.c_str(ctx)); |
| 1266 |
} |
| 1267 |
ci.cluster = ci.name; |
| 1268 |
bind_attr_loc(&ci, &ci.attrs); |
| 1269 |
|
| 1270 |
for (int i = 1; i <= 18; i++) { |
| 1271 |
connect_gnd_if_unconnected(&ci, ctx->idf("I%d", i)); |
| 1272 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("I%d", i), ctx->idf("O%d", i), |
| 1273 |
ClusterPlacement(PLACE_XRF_I1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1274 |
} |
| 1275 |
if (mode != 1) { |
| 1276 |
for (int i = 1; i <= 5; i++) { |
| 1277 |
connect_gnd_if_unconnected(&ci, ctx->idf("RA%d", i)); |
| 1278 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("RA%d", i), IdString(), |
| 1279 |
ClusterPlacement(PLACE_XRF_RA1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1280 |
} |
| 1281 |
} else { |
| 1282 |
// SPREG mode does not use RA inputs |
| 1283 |
for (int i = 1; i <= 5; i++) |
| 1284 |
disconnect_unused(&ci, ctx->idf("RA%d", i)); |
| 1285 |
} |
| 1286 |
|
| 1287 |
if (mode == 2 || mode == 4) { |
| 1288 |
connect_gnd_if_unconnected(&ci, id_RA6); |
| 1289 |
pack_xrf_input_and_output(&ci, ci.name, id_RA6, IdString(), PLACE_XRF_RA6, lut_only, lut_and_ff, dff_only); |
| 1290 |
} else { |
| 1291 |
disconnect_unused(&ci, id_RA6); |
| 1292 |
} |
| 1293 |
|
| 1294 |
if (mode == 4) { |
| 1295 |
for (int i = 7; i <= 10; i++) { |
| 1296 |
connect_gnd_if_unconnected(&ci, ctx->idf("RA%d", i)); |
| 1297 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("RA%d", i), IdString(), |
| 1298 |
ClusterPlacement(PLACE_XRF_RA1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1299 |
} |
| 1300 |
} else { |
| 1301 |
for (int i = 7; i <= 10; i++) |
| 1302 |
disconnect_unused(&ci, ctx->idf("RA%d", i)); |
| 1303 |
} |
| 1304 |
|
| 1305 |
for (int i = 1; i <= 5; i++) { |
| 1306 |
connect_gnd_if_unconnected(&ci, ctx->idf("WA%d", i)); |
| 1307 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("WA%d", i), IdString(), |
| 1308 |
ClusterPlacement(PLACE_XRF_WA1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1309 |
} |
| 1310 |
|
| 1311 |
if (mode == 2) { |
| 1312 |
connect_gnd_if_unconnected(&ci, id_WA6); |
| 1313 |
pack_xrf_input_and_output(&ci, ci.name, id_WA6, IdString(), PLACE_XRF_WA6, lut_only, lut_and_ff, dff_only); |
| 1314 |
} else { |
| 1315 |
disconnect_unused(&ci, id_WA6); |
| 1316 |
} |
| 1317 |
|
| 1318 |
connect_gnd_if_unconnected(&ci, id_WE); |
| 1319 |
pack_xrf_input_and_output(&ci, ci.name, id_WE, IdString(), PLACE_XRF_WE, lut_only, lut_and_ff, dff_only); |
| 1320 |
|
| 1321 |
disconnect_if_gnd(&ci, id_WEA); |
| 1322 |
pack_xrf_input_and_output(&ci, ci.name, id_WEA, IdString(), PLACE_XRF_WEA, lut_only, lut_and_ff, dff_only); |
| 1323 |
|
| 1324 |
if (mode == 3) { |
| 1325 |
for (int i = 19; i <= 36; i++) { |
| 1326 |
connect_gnd_if_unconnected(&ci, ctx->idf("I%d", i)); |
| 1327 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("I%d", i), ctx->idf("O%d", i), |
| 1328 |
ClusterPlacement(PLACE_XRF_I1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1329 |
} |
| 1330 |
} else if (mode == 4) { |
| 1331 |
for (int i = 19; i <= 36; i++) { |
| 1332 |
disconnect_unused(&ci, ctx->idf("I%d", i)); |
| 1333 |
pack_xrf_input_and_output(&ci, ci.name, IdString(), ctx->idf("O%d", i), |
| 1334 |
ClusterPlacement(PLACE_XRF_I1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1335 |
} |
| 1336 |
} else { |
| 1337 |
for (int i = 19; i <= 36; i++) { |
| 1338 |
disconnect_unused(&ci, ctx->idf("I%d", i)); |
| 1339 |
disconnect_unused(&ci, ctx->idf("O%d", i)); |
| 1340 |
} |
| 1341 |
} |
| 1342 |
|
| 1343 |
if (mode > 1) { |
| 1344 |
// XRF |
| 1345 |
ci.ports[id_WCK1].name = id_WCK1; |
| 1346 |
ci.ports[id_WCK1].type = PORT_IN; |
| 1347 |
ci.ports[id_WCK2].name = id_WCK2; |
| 1348 |
ci.ports[id_WCK2].type = PORT_IN; |
| 1349 |
NetInfo *net = ci.getPort(id_WCK); |
| 1350 |
if (net) { |
| 1351 |
ci.disconnectPort(id_WCK); |
| 1352 |
|
| 1353 |
ci.connectPort(id_WCK1, net); |
| 1354 |
ci.connectPort(id_WCK2, net); |
| 1355 |
} |
| 1356 |
} |
| 1357 |
} |
| 1358 |
if (lut_only) |
| 1359 |
log_info(" %6d FEs used as LUT only\n", lut_only); |
| 1360 |
if (lut_and_ff) |
| 1361 |
log_info(" %6d FEs used as LUT and DFF\n", lut_and_ff); |
| 1362 |
if (dff_only) |
| 1363 |
log_info(" %6d FEs used as DFF only\n", dff_only); |
| 1364 |
flush_cells(); |
| 1365 |
} |
| 1366 |
|
| 1367 |
void NgUltraPacker::pack_cdcs(void) |
| 1368 |
{ |
| 1369 |
log_info("Packing CDCs..\n"); |
| 1370 |
int lut_only = 0, lut_and_ff = 0, dff_only = 0; |
| 1371 |
for (auto &cell : ctx->cells) { |
| 1372 |
CellInfo &ci = *cell.second; |
| 1373 |
if (!ci.type.in(id_NX_CDC_U)) |
| 1374 |
continue; |
| 1375 |
int mode = int_or_default(ci.params, id_mode, 0); |
| 1376 |
switch (mode) { |
| 1377 |
case 0: |
| 1378 |
ci.type = id_DDE; |
| 1379 |
break; |
| 1380 |
case 1: |
| 1381 |
ci.type = id_TDE; |
| 1382 |
break; |
| 1383 |
case 2: |
| 1384 |
ci.type = id_CDC; |
| 1385 |
break; |
| 1386 |
case 3: |
| 1387 |
ci.type = id_BGC; |
| 1388 |
break; |
| 1389 |
case 4: |
| 1390 |
ci.type = id_GBC; |
| 1391 |
break; |
| 1392 |
case 5: |
| 1393 |
ci.type = id_XCDC; |
| 1394 |
break; |
| 1395 |
default: |
| 1396 |
log_error("Unknown mode %d for cell '%s'.\n", mode, ci.name.c_str(ctx)); |
| 1397 |
} |
| 1398 |
ci.cluster = ci.name; |
| 1399 |
|
| 1400 |
// If unconnected, connect GND to inputs that are actually used as outputs |
| 1401 |
for (int i = 1; i <= 6; i++) { |
| 1402 |
if (ci.getPort(ctx->idf("AO%d", i))) { |
| 1403 |
connect_gnd_if_unconnected(&ci, ctx->idf("AI%d", i)); |
| 1404 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("AI%d", i), ctx->idf("AO%d", i), |
| 1405 |
ClusterPlacement(PLACE_CDC_AI1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1406 |
} else |
| 1407 |
disconnect_unused(&ci, ctx->idf("AI%d", i)); |
| 1408 |
if (ci.getPort(ctx->idf("BO%d", i))) { |
| 1409 |
connect_gnd_if_unconnected(&ci, ctx->idf("BI%d", i)); |
| 1410 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("BI%d", i), ctx->idf("BO%d", i), |
| 1411 |
ClusterPlacement(PLACE_CDC_BI1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1412 |
} else |
| 1413 |
disconnect_unused(&ci, ctx->idf("BI%d", i)); |
| 1414 |
if (ci.type.in(id_XCDC)) { |
| 1415 |
if (ci.getPort(ctx->idf("CO%d", i))) { |
| 1416 |
connect_gnd_if_unconnected(&ci, ctx->idf("CI%d", i)); |
| 1417 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("CI%d", i), ctx->idf("CO%d", i), |
| 1418 |
ClusterPlacement(PLACE_CDC_CI1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1419 |
} else |
| 1420 |
disconnect_unused(&ci, ctx->idf("CI%d", i)); |
| 1421 |
if (ci.getPort(ctx->idf("DO%d", i))) { |
| 1422 |
connect_gnd_if_unconnected(&ci, ctx->idf("DI%d", i)); |
| 1423 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("DI%d", i), ctx->idf("DO%d", i), |
| 1424 |
ClusterPlacement(PLACE_CDC_DI1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1425 |
} else |
| 1426 |
disconnect_unused(&ci, ctx->idf("DI%d", i)); |
| 1427 |
} |
| 1428 |
} |
| 1429 |
|
| 1430 |
// Remove inputs and outputs that are not used for specific types |
| 1431 |
if (ci.type.in(id_BGC, id_GBC)) { |
| 1432 |
disconnect_unused(&ci, id_CK1); |
| 1433 |
disconnect_unused(&ci, id_CK2); |
| 1434 |
disconnect_unused(&ci, id_ADRSTI); |
| 1435 |
disconnect_unused(&ci, id_ADRSTO); |
| 1436 |
disconnect_unused(&ci, id_BDRSTI); |
| 1437 |
disconnect_unused(&ci, id_BDRSTO); |
| 1438 |
} else { |
| 1439 |
connect_gnd_if_unconnected(&ci, id_ADRSTI); |
| 1440 |
pack_xrf_input_and_output(&ci, ci.name, id_ADRSTI, id_ADRSTO, PLACE_CDC_ADRSTI, lut_only, lut_and_ff, |
| 1441 |
dff_only); |
| 1442 |
connect_gnd_if_unconnected(&ci, id_BDRSTI); |
| 1443 |
pack_xrf_input_and_output(&ci, ci.name, id_BDRSTI, id_BDRSTO, PLACE_CDC_BDRSTI, lut_only, lut_and_ff, |
| 1444 |
dff_only); |
| 1445 |
} |
| 1446 |
if (ci.type.in(id_BGC, id_GBC, id_DDE)) { |
| 1447 |
disconnect_unused(&ci, id_ASRSTI); |
| 1448 |
disconnect_unused(&ci, id_ASRSTO); |
| 1449 |
disconnect_unused(&ci, id_BSRSTI); |
| 1450 |
disconnect_unused(&ci, id_BSRSTO); |
| 1451 |
} else { |
| 1452 |
connect_gnd_if_unconnected(&ci, id_ASRSTI); |
| 1453 |
pack_xrf_input_and_output(&ci, ci.name, id_ASRSTI, id_ASRSTO, PLACE_CDC_ASRSTI, lut_only, lut_and_ff, |
| 1454 |
dff_only); |
| 1455 |
connect_gnd_if_unconnected(&ci, id_BSRSTI); |
| 1456 |
pack_xrf_input_and_output(&ci, ci.name, id_BSRSTI, id_BSRSTO, PLACE_CDC_BSRSTI, lut_only, lut_and_ff, |
| 1457 |
dff_only); |
| 1458 |
} |
| 1459 |
|
| 1460 |
// Only XCDC is using these ports, remove from others if used |
| 1461 |
if (!ci.type.in(id_XCDC)) { |
| 1462 |
disconnect_unused(&ci, id_CDRSTI); |
| 1463 |
disconnect_unused(&ci, id_CDRSTO); |
| 1464 |
for (int i = 1; i <= 6; i++) { |
| 1465 |
disconnect_unused(&ci, ctx->idf("CI%d", i)); |
| 1466 |
disconnect_unused(&ci, ctx->idf("CO%d", i)); |
| 1467 |
} |
| 1468 |
disconnect_unused(&ci, id_CSRSTI); |
| 1469 |
disconnect_unused(&ci, id_CSRSTO); |
| 1470 |
|
| 1471 |
disconnect_unused(&ci, id_DDRSTI); |
| 1472 |
disconnect_unused(&ci, id_DDRSTO); |
| 1473 |
for (int i = 1; i <= 6; i++) { |
| 1474 |
disconnect_unused(&ci, ctx->idf("DI%d", i)); |
| 1475 |
disconnect_unused(&ci, ctx->idf("DO%d", i)); |
| 1476 |
} |
| 1477 |
disconnect_unused(&ci, id_DSRSTI); |
| 1478 |
disconnect_unused(&ci, id_DSRSTO); |
| 1479 |
} else { |
| 1480 |
connect_gnd_if_unconnected(&ci, id_CDRSTI); |
| 1481 |
pack_xrf_input_and_output(&ci, ci.name, id_CDRSTI, id_CDRSTO, PLACE_CDC_CDRSTI, lut_only, lut_and_ff, |
| 1482 |
dff_only); |
| 1483 |
connect_gnd_if_unconnected(&ci, id_DDRSTI); |
| 1484 |
pack_xrf_input_and_output(&ci, ci.name, id_DDRSTI, id_DDRSTO, PLACE_CDC_DDRSTI, lut_only, lut_and_ff, |
| 1485 |
dff_only); |
| 1486 |
connect_gnd_if_unconnected(&ci, id_CSRSTI); |
| 1487 |
pack_xrf_input_and_output(&ci, ci.name, id_CSRSTI, id_CSRSTO, PLACE_CDC_CSRSTI, lut_only, lut_and_ff, |
| 1488 |
dff_only); |
| 1489 |
connect_gnd_if_unconnected(&ci, id_DSRSTI); |
| 1490 |
pack_xrf_input_and_output(&ci, ci.name, id_DSRSTI, id_DSRSTO, PLACE_CDC_DSRSTI, lut_only, lut_and_ff, |
| 1491 |
dff_only); |
| 1492 |
} |
| 1493 |
} |
| 1494 |
if (lut_only) |
| 1495 |
log_info(" %6d FEs used as LUT only\n", lut_only); |
| 1496 |
if (lut_and_ff) |
| 1497 |
log_info(" %6d FEs used as LUT and DFF\n", lut_and_ff); |
| 1498 |
if (dff_only) |
| 1499 |
log_info(" %6d FEs used as DFF only\n", dff_only); |
| 1500 |
flush_cells(); |
| 1501 |
} |
| 1502 |
|
| 1503 |
void NgUltraPacker::pack_fifos(void) |
| 1504 |
{ |
| 1505 |
log_info("Packing FIFOs..\n"); |
| 1506 |
int lut_only = 0, lut_and_ff = 0, dff_only = 0; |
| 1507 |
for (auto &cell : ctx->cells) { |
| 1508 |
CellInfo &ci = *cell.second; |
| 1509 |
if (!ci.type.in(id_NX_FIFO_U)) |
| 1510 |
continue; |
| 1511 |
int mode = int_or_default(ci.params, id_mode, 0); |
| 1512 |
switch (mode) { |
| 1513 |
case 0: |
| 1514 |
ci.type = id_FIFO; |
| 1515 |
break; |
| 1516 |
case 1: |
| 1517 |
ci.type = id_XHFIFO; |
| 1518 |
break; |
| 1519 |
case 2: |
| 1520 |
ci.type = id_XWFIFO; |
| 1521 |
break; |
| 1522 |
default: |
| 1523 |
log_error("Unknown mode %d for cell '%s'.\n", mode, ci.name.c_str(ctx)); |
| 1524 |
} |
| 1525 |
ci.cluster = ci.name; |
| 1526 |
bool use_write_arst = bool_or_default(ci.params, id_use_write_arst, false); |
| 1527 |
bool use_read_arst = bool_or_default(ci.params, id_use_read_arst, false); |
| 1528 |
|
| 1529 |
int rsti = (ci.type == id_FIFO) ? 2 : 4; |
| 1530 |
for (int i = 1; i <= rsti; i++) { |
| 1531 |
IdString port = ctx->idf("WRSTI%d", i); |
| 1532 |
ci.ports[port].name = port; |
| 1533 |
ci.ports[port].type = PORT_IN; |
| 1534 |
port = ctx->idf("RRSTI%d", i); |
| 1535 |
ci.ports[port].name = port; |
| 1536 |
ci.ports[port].type = PORT_IN; |
| 1537 |
} |
| 1538 |
|
| 1539 |
if (use_write_arst) { |
| 1540 |
IdString port = id_WRSTI; |
| 1541 |
connect_gnd_if_unconnected(&ci, port); |
| 1542 |
NetInfo *wrsti_net = ci.getPort(port); |
| 1543 |
ci.disconnectPort(port); |
| 1544 |
for (int i = 1; i <= rsti; i++) |
| 1545 |
ci.connectPort(ctx->idf("WRSTI%d", i), wrsti_net); |
| 1546 |
if (mode != 0) |
| 1547 |
disconnect_unused(&ci, id_WRSTO); |
| 1548 |
pack_xrf_input_and_output(&ci, ci.name, id_WRSTI1, id_WRSTO, PLACE_FIFO_WRSTI1, lut_only, lut_and_ff, |
| 1549 |
dff_only); |
| 1550 |
pack_xrf_input_and_output(&ci, ci.name, id_WRSTI2, IdString(), PLACE_FIFO_WRSTI2, lut_only, lut_and_ff, |
| 1551 |
dff_only); |
| 1552 |
if (mode != 0) { |
| 1553 |
pack_xrf_input_and_output(&ci, ci.name, id_WRSTI3, IdString(), PLACE_FIFO_WRSTI3, lut_only, lut_and_ff, |
| 1554 |
dff_only); |
| 1555 |
pack_xrf_input_and_output(&ci, ci.name, id_WRSTI4, IdString(), PLACE_FIFO_WRSTI4, lut_only, lut_and_ff, |
| 1556 |
dff_only); |
| 1557 |
} |
| 1558 |
} else { |
| 1559 |
disconnect_unused(&ci, id_WRSTI); |
| 1560 |
} |
| 1561 |
if (use_read_arst) { |
| 1562 |
IdString port = id_RRSTI; |
| 1563 |
connect_gnd_if_unconnected(&ci, port); |
| 1564 |
NetInfo *rrsti_net = ci.getPort(port); |
| 1565 |
ci.disconnectPort(port); |
| 1566 |
for (int i = 1; i <= rsti; i++) |
| 1567 |
ci.connectPort(ctx->idf("RRSTI%d", i), rrsti_net); |
| 1568 |
if (mode != 0) |
| 1569 |
disconnect_unused(&ci, id_RRSTO); |
| 1570 |
pack_xrf_input_and_output(&ci, ci.name, id_RRSTI1, id_RRSTO, PLACE_FIFO_RRSTI1, lut_only, lut_and_ff, |
| 1571 |
dff_only); |
| 1572 |
pack_xrf_input_and_output(&ci, ci.name, id_RRSTI2, IdString(), PLACE_FIFO_RRSTI2, lut_only, lut_and_ff, |
| 1573 |
dff_only); |
| 1574 |
if (mode != 0) { |
| 1575 |
pack_xrf_input_and_output(&ci, ci.name, id_RRSTI3, IdString(), PLACE_FIFO_RRSTI3, lut_only, lut_and_ff, |
| 1576 |
dff_only); |
| 1577 |
pack_xrf_input_and_output(&ci, ci.name, id_RRSTI4, IdString(), PLACE_FIFO_RRSTI4, lut_only, lut_and_ff, |
| 1578 |
dff_only); |
| 1579 |
} |
| 1580 |
} else { |
| 1581 |
disconnect_unused(&ci, id_RRSTI); |
| 1582 |
} |
| 1583 |
|
| 1584 |
for (int i = 1; i <= 18; i++) { |
| 1585 |
connect_gnd_if_unconnected(&ci, ctx->idf("I%d", i)); |
| 1586 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("I%d", i), ctx->idf("O%d", i), |
| 1587 |
ClusterPlacement(PLACE_FIFO_I1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1588 |
} |
| 1589 |
|
| 1590 |
if (mode == 0) { |
| 1591 |
for (int i = 19; i <= 36; i++) { |
| 1592 |
disconnect_unused(&ci, ctx->idf("I%d", i)); |
| 1593 |
disconnect_unused(&ci, ctx->idf("O%d", i)); |
| 1594 |
} |
| 1595 |
} else { |
| 1596 |
for (int i = 19; i <= 36; i++) { |
| 1597 |
connect_gnd_if_unconnected(&ci, ctx->idf("I%d", i)); |
| 1598 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("I%d", i), ctx->idf("O%d", i), |
| 1599 |
ClusterPlacement(PLACE_FIFO_I1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1600 |
} |
| 1601 |
} |
| 1602 |
for (int i = 1; i <= 6; i++) { |
| 1603 |
connect_gnd_if_unconnected(&ci, ctx->idf("RAI%d", i)); |
| 1604 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("RAI%d", i), ctx->idf("RAO%d", i), |
| 1605 |
ClusterPlacement(PLACE_FIFO_RAI1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1606 |
|
| 1607 |
connect_gnd_if_unconnected(&ci, ctx->idf("WAI%d", i)); |
| 1608 |
pack_xrf_input_and_output(&ci, ci.name, ctx->idf("WAI%d", i), ctx->idf("WAO%d", i), |
| 1609 |
ClusterPlacement(PLACE_FIFO_WAI1 + i - 1), lut_only, lut_and_ff, dff_only); |
| 1610 |
} |
| 1611 |
|
| 1612 |
if (mode == 0) { |
| 1613 |
disconnect_unused(&ci, id_RAI7); |
| 1614 |
disconnect_unused(&ci, id_WAI7); |
| 1615 |
} else { |
| 1616 |
connect_gnd_if_unconnected(&ci, id_RAI7); |
| 1617 |
pack_xrf_input_and_output(&ci, ci.name, id_RAI7, id_RAO7, PLACE_FIFO_RAI7, lut_only, lut_and_ff, dff_only); |
| 1618 |
|
| 1619 |
connect_gnd_if_unconnected(&ci, id_WAI7); |
| 1620 |
pack_xrf_input_and_output(&ci, ci.name, id_WAI7, id_WAO7, PLACE_FIFO_WAI7, lut_only, lut_and_ff, dff_only); |
| 1621 |
} |
| 1622 |
|
| 1623 |
connect_gnd_if_unconnected(&ci, id_WE); |
| 1624 |
pack_xrf_input_and_output(&ci, ci.name, id_WE, IdString(), PLACE_FIFO_WE, lut_only, lut_and_ff, dff_only); |
| 1625 |
|
| 1626 |
disconnect_if_gnd(&ci, id_WEA); |
| 1627 |
pack_xrf_input_and_output(&ci, ci.name, id_WEA, IdString(), PLACE_FIFO_WEA, lut_only, lut_and_ff, dff_only); |
| 1628 |
|
| 1629 |
if (mode == 0) { |
| 1630 |
// FIFO |
| 1631 |
ci.renamePort(id_WEQ1, id_WEQ); |
| 1632 |
pack_xrf_input_and_output(&ci, ci.name, IdString(), id_WEQ, PLACE_FIFO_WEQ1, lut_only, lut_and_ff, |
| 1633 |
dff_only); |
| 1634 |
disconnect_unused(&ci, id_WEQ2); |
| 1635 |
|
| 1636 |
ci.renamePort(id_REQ1, id_REQ); |
| 1637 |
pack_xrf_input_and_output(&ci, ci.name, IdString(), id_REQ, PLACE_FIFO_REQ1, lut_only, lut_and_ff, |
| 1638 |
dff_only); |
| 1639 |
disconnect_unused(&ci, id_REQ2); |
| 1640 |
} else { |
| 1641 |
pack_xrf_input_and_output(&ci, ci.name, IdString(), id_WEQ1, PLACE_FIFO_WEQ1, lut_only, lut_and_ff, |
| 1642 |
dff_only); |
| 1643 |
pack_xrf_input_and_output(&ci, ci.name, IdString(), id_WEQ2, PLACE_FIFO_WEQ2, lut_only, lut_and_ff, |
| 1644 |
dff_only); |
| 1645 |
pack_xrf_input_and_output(&ci, ci.name, IdString(), id_WEQ1, PLACE_FIFO_REQ1, lut_only, lut_and_ff, |
| 1646 |
dff_only); |
| 1647 |
pack_xrf_input_and_output(&ci, ci.name, IdString(), id_WEQ2, PLACE_FIFO_REQ2, lut_only, lut_and_ff, |
| 1648 |
dff_only); |
| 1649 |
|
| 1650 |
// XFIFO |
| 1651 |
ci.ports[id_WCK1].name = id_WCK1; |
| 1652 |
ci.ports[id_WCK1].type = PORT_IN; |
| 1653 |
ci.ports[id_WCK2].name = id_WCK2; |
| 1654 |
ci.ports[id_WCK2].type = PORT_IN; |
| 1655 |
ci.ports[id_RCK1].name = id_RCK1; |
| 1656 |
ci.ports[id_RCK1].type = PORT_IN; |
| 1657 |
ci.ports[id_RCK2].name = id_RCK2; |
| 1658 |
ci.ports[id_RCK2].type = PORT_IN; |
| 1659 |
NetInfo *net = ci.getPort(id_WCK); |
| 1660 |
if (net) { |
| 1661 |
ci.disconnectPort(id_WCK); |
| 1662 |
|
| 1663 |
ci.connectPort(id_WCK1, net); |
| 1664 |
ci.connectPort(id_WCK2, net); |
| 1665 |
} |
| 1666 |
net = ci.getPort(id_RCK); |
| 1667 |
if (net) { |
| 1668 |
ci.disconnectPort(id_RCK); |
| 1669 |
|
| 1670 |
ci.connectPort(id_RCK1, net); |
| 1671 |
ci.connectPort(id_RCK2, net); |
| 1672 |
} |
| 1673 |
} |
| 1674 |
} |
| 1675 |
if (lut_only) |
| 1676 |
log_info(" %6d FEs used as LUT only\n", lut_only); |
| 1677 |
if (lut_and_ff) |
| 1678 |
log_info(" %6d FEs used as LUT and DFF\n", lut_and_ff); |
| 1679 |
if (dff_only) |
| 1680 |
log_info(" %6d FEs used as DFF only\n", dff_only); |
| 1681 |
flush_cells(); |
| 1682 |
} |
| 1683 |
|
| 1684 |
void NgUltraPacker::insert_ioms() |
| 1685 |
{ |
| 1686 |
std::vector<IdString> pins_needing_iom; |
| 1687 |
for (auto &net : ctx->nets) { |
| 1688 |
NetInfo *ni = net.second.get(); |
| 1689 |
// Skip undriven nets |
| 1690 |
if (ni->driver.cell == nullptr) |
| 1691 |
continue; |
| 1692 |
if (!ni->driver.cell->type.in(id_BFR)) { |
| 1693 |
continue; |
| 1694 |
} |
| 1695 |
Loc iotp_loc = ni->driver.cell->getLocation(); |
| 1696 |
iotp_loc.z -= 1; |
| 1697 |
BelId bel = ctx->getBelByLocation(iotp_loc); |
| 1698 |
if (uarch->global_capable_bels.count(bel) == 0) |
| 1699 |
continue; |
| 1700 |
for (const auto &usr : ni->users) { |
| 1701 |
if (uarch->is_fabric_lowskew_sink(usr) || uarch->is_ring_clock_sink(usr) || |
| 1702 |
uarch->is_tube_clock_sink(usr) || uarch->is_ring_over_tile_clock_sink(usr)) { |
| 1703 |
pins_needing_iom.emplace_back(ni->name); |
| 1704 |
break; |
| 1705 |
} |
| 1706 |
} |
| 1707 |
} |
| 1708 |
// Sort clocks by max fanout |
| 1709 |
log_info("Inserting IOMs...\n"); |
| 1710 |
int bfr_removed = 0; |
| 1711 |
for (size_t i = 0; i < pins_needing_iom.size(); i++) { |
| 1712 |
NetInfo *net = ctx->nets.at(pins_needing_iom.at(i)).get(); |
| 1713 |
Loc iotp_loc = net->driver.cell->getLocation(); |
| 1714 |
iotp_loc.z -= 1; |
| 1715 |
BelId iotp_bel = ctx->getBelByLocation(iotp_loc); |
| 1716 |
|
| 1717 |
IdString iob = uarch->tile_name_id(iotp_bel.tile); |
| 1718 |
BelId bel = uarch->iom_bels[iob]; |
| 1719 |
|
| 1720 |
CellInfo *iom = nullptr; |
| 1721 |
IdString port = uarch->global_capable_bels.at(iotp_bel); |
| 1722 |
CellInfo *input_pad = ctx->getBoundBelCell(iotp_bel); |
| 1723 |
std::string iobname = str_or_default(input_pad->params, id_iobname, ""); |
| 1724 |
if (!ctx->checkBelAvail(bel)) { |
| 1725 |
iom = ctx->getBoundBelCell(bel); |
| 1726 |
log_info(" Reusing IOM in bank '%s' for signal '%s'\n", iob.c_str(ctx), iobname.c_str()); |
| 1727 |
} else { |
| 1728 |
iom = create_cell_ptr(id_IOM, ctx->idf("%s$iom", iob.c_str(ctx))); |
| 1729 |
log_info(" Adding IOM in bank '%s' for signal '%s'\n", iob.c_str(ctx), iobname.c_str()); |
| 1730 |
} |
| 1731 |
if (iom->getPort(port)) { |
| 1732 |
log_error("Port '%s' of IOM cell '%s' is already used.\n", port.c_str(ctx), iom->name.c_str(ctx)); |
| 1733 |
} |
| 1734 |
NetInfo *iom_to_clk = ctx->createNet(ctx->idf("%s$iom", net->name.c_str(ctx))); |
| 1735 |
for (const auto &usr : net->users) { |
| 1736 |
IdString port = usr.port; |
| 1737 |
usr.cell->disconnectPort(port); |
| 1738 |
usr.cell->connectPort(port, iom_to_clk); |
| 1739 |
} |
| 1740 |
iom->connectPort(port, input_pad->getPort(id_O)); |
| 1741 |
iom->connectPort((port == id_P17RI) ? id_CKO1 : id_CKO2, iom_to_clk); |
| 1742 |
if (ctx->checkBelAvail(bel)) |
| 1743 |
ctx->bindBel(bel, iom, PlaceStrength::STRENGTH_LOCKED); |
| 1744 |
CellInfo *bfr = net->driver.cell; |
| 1745 |
if (bfr->type == id_BFR && bfr->getPort(id_O)->users.empty()) { |
| 1746 |
bfr->disconnectPort(id_O); |
| 1747 |
bfr->disconnectPort(id_I); |
| 1748 |
bfr_removed++; |
| 1749 |
ctx->cells.erase(bfr->name); |
| 1750 |
} |
| 1751 |
} |
| 1752 |
if (bfr_removed) |
| 1753 |
log_info(" Removed %d unused BFR\n", bfr_removed); |
| 1754 |
} |
| 1755 |
|
| 1756 |
void NgUltraPacker::insert_wfbs() |
| 1757 |
{ |
| 1758 |
log_info("Inserting WFBs...\n"); |
| 1759 |
for (auto &cell : ctx->cells) { |
| 1760 |
CellInfo &ci = *cell.second; |
| 1761 |
if (ci.type.in(id_IOM)) { |
| 1762 |
insert_wfb(&ci, id_CKO1); |
| 1763 |
insert_wfb(&ci, id_CKO2); |
| 1764 |
} else if (ci.type.in(id_PLL)) { |
| 1765 |
insert_wfb(&ci, id_OSC); |
| 1766 |
insert_wfb(&ci, id_VCO); |
| 1767 |
insert_wfb(&ci, id_REFO); |
| 1768 |
insert_wfb(&ci, id_LDFO); |
| 1769 |
insert_wfb(&ci, id_CLK_DIV1); |
| 1770 |
insert_wfb(&ci, id_CLK_DIV2); |
| 1771 |
insert_wfb(&ci, id_CLK_DIV3); |
| 1772 |
insert_wfb(&ci, id_CLK_DIV4); |
| 1773 |
insert_wfb(&ci, id_CLK_DIVD1); |
| 1774 |
insert_wfb(&ci, id_CLK_DIVD2); |
| 1775 |
insert_wfb(&ci, id_CLK_DIVD3); |
| 1776 |
insert_wfb(&ci, id_CLK_DIVD4); |
| 1777 |
insert_wfb(&ci, id_CLK_DIVD5); |
| 1778 |
insert_wfb(&ci, id_CLK_CAL_DIV); |
| 1779 |
} |
| 1780 |
} |
| 1781 |
} |
| 1782 |
|
| 1783 |
void NgUltraPacker::mandatory_param(CellInfo *cell, IdString param) |
| 1784 |
{ |
| 1785 |
if (!cell->params.count(param)) |
| 1786 |
log_error("Mandatory parameter '%s' of cell '%s'(%s) is missing.\n", param.c_str(ctx), cell->name.c_str(ctx), |
| 1787 |
cell->type.c_str(ctx)); |
| 1788 |
} |
| 1789 |
|
| 1790 |
int NgUltraPacker::memory_width(int config, bool ecc) |
| 1791 |
{ |
| 1792 |
if (ecc) { |
| 1793 |
if (config == 4) |
| 1794 |
return 18; |
| 1795 |
else |
| 1796 |
log_error("ECC mode only support width of 18.\n"); |
| 1797 |
} else { |
| 1798 |
switch (config) { |
| 1799 |
case 0: |
| 1800 |
return 1; // NOECC_48kx1 |
| 1801 |
case 1: |
| 1802 |
return 2; // NOECC_24kx2 |
| 1803 |
case 2: |
| 1804 |
return 4; // NOECC_12kx4 |
| 1805 |
case 3: |
| 1806 |
return 8; // NOECC_6kx8 |
| 1807 |
case 4: |
| 1808 |
return 12; // NOECC_4kx12 |
| 1809 |
case 5: |
| 1810 |
return 24; // NOECC_2kx24 |
| 1811 |
case 6: |
| 1812 |
return 3; // NOECC_16kx3 |
| 1813 |
case 7: |
| 1814 |
return 6; // NOECC_8kx6 |
| 1815 |
} |
| 1816 |
log_error("Unknown memory configuration width config '%d'.\n", config); |
| 1817 |
} |
| 1818 |
} |
| 1819 |
|
| 1820 |
int NgUltraPacker::memory_addr_bits(int config, bool ecc) |
| 1821 |
{ |
| 1822 |
if (ecc) { |
| 1823 |
if (config == 4) |
| 1824 |
return 11; |
| 1825 |
else |
| 1826 |
log_error("ECC mode only support width of 18.\n"); |
| 1827 |
} else { |
| 1828 |
switch (config) { |
| 1829 |
case 0: |
| 1830 |
return 16; // NOECC_48kx1 |
| 1831 |
case 1: |
| 1832 |
return 15; // NOECC_24kx2 |
| 1833 |
case 2: |
| 1834 |
return 14; // NOECC_12kx4 |
| 1835 |
case 3: |
| 1836 |
return 13; // NOECC_6kx8 |
| 1837 |
case 4: |
| 1838 |
return 12; // NOECC_4kx12 |
| 1839 |
case 5: |
| 1840 |
return 11; // NOECC_2kx24 |
| 1841 |
case 6: |
| 1842 |
return 14; // NOECC_16kx3 |
| 1843 |
case 7: |
| 1844 |
return 13; // NOECC_8kx6 |
| 1845 |
} |
| 1846 |
log_error("Unknown memory configuration width config '%d'.\n", config); |
| 1847 |
} |
| 1848 |
} |
| 1849 |
|
| 1850 |
void NgUltraPacker::insert_wfb(CellInfo *cell, IdString port) |
| 1851 |
{ |
| 1852 |
NetInfo *net = cell->getPort(port); |
| 1853 |
if (!net) |
| 1854 |
return; |
| 1855 |
|
| 1856 |
CellInfo *wfg = net_only_drives(ctx, net, is_wfg, id_ZI, true); |
| 1857 |
if (wfg) |
| 1858 |
return; |
| 1859 |
bool in_fabric = false; |
| 1860 |
bool in_ring = false; |
| 1861 |
for (const auto &usr : net->users) { |
| 1862 |
if (uarch->is_fabric_lowskew_sink(usr) || uarch->is_tube_clock_sink(usr) || |
| 1863 |
uarch->is_ring_over_tile_clock_sink(usr)) |
| 1864 |
in_fabric = true; |
| 1865 |
else |
| 1866 |
in_ring = true; |
| 1867 |
} |
| 1868 |
// If all in ring and none in fabric no need for WFB |
| 1869 |
if (in_ring && !in_fabric) |
| 1870 |
return; |
| 1871 |
log_info(" Inserting WFB for cell '%s' port '%s'\n", cell->name.c_str(ctx), port.c_str(ctx)); |
| 1872 |
CellInfo *wfb = create_cell_ptr(id_WFB, ctx->idf("%s$%s", cell->name.c_str(ctx), port.c_str(ctx))); |
| 1873 |
if (in_ring && in_fabric) { |
| 1874 |
// If both in ring and in fabric create new signal |
| 1875 |
wfb->connectPort(id_ZI, net); |
| 1876 |
NetInfo *net_zo = ctx->createNet(ctx->idf("%s$ZO", net->name.c_str(ctx))); |
| 1877 |
wfb->connectPort(id_ZO, net_zo); |
| 1878 |
for (const auto &usr : net->users) { |
| 1879 |
if (uarch->is_fabric_lowskew_sink(usr) || uarch->is_ring_over_tile_clock_sink(usr)) { |
| 1880 |
usr.cell->disconnectPort(usr.port); |
| 1881 |
usr.cell->connectPort(usr.port, net_zo); |
| 1882 |
} |
| 1883 |
} |
| 1884 |
} else { |
| 1885 |
// Only in fabric, reconnect wire directly to WFB |
| 1886 |
cell->disconnectPort(port); |
| 1887 |
wfb->connectPort(id_ZO, net); |
| 1888 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$%s", net->name.c_str(ctx), port.c_str(ctx))); |
| 1889 |
cell->connectPort(port, new_out); |
| 1890 |
wfb->connectPort(id_ZI, new_out); |
| 1891 |
} |
| 1892 |
} |
| 1893 |
|
| 1894 |
void NgUltraPacker::constrain_location(CellInfo *cell) |
| 1895 |
{ |
| 1896 |
std::string location = str_or_default(cell->params, id_location, ""); |
| 1897 |
if (!location.empty()) { |
| 1898 |
if (uarch->locations.count(location)) { |
| 1899 |
BelId bel = uarch->locations[location]; |
| 1900 |
if (ctx->getBelType(bel) != cell->type) { |
| 1901 |
log_error("Location '%s' is wrong for bel type '%s'.\n", location.c_str(), cell->type.c_str(ctx)); |
| 1902 |
} |
| 1903 |
if (ctx->checkBelAvail(bel)) { |
| 1904 |
log_info(" Constraining %s '%s' to '%s'\n", cell->type.c_str(ctx), cell->name.c_str(ctx), |
| 1905 |
location.c_str()); |
| 1906 |
ctx->bindBel(bel, cell, PlaceStrength::STRENGTH_LOCKED); |
| 1907 |
} else { |
| 1908 |
log_error("Bel at location '%s' is already used by other cell.\n", location.c_str()); |
| 1909 |
} |
| 1910 |
|
| 1911 |
} else { |
| 1912 |
log_error("Unknown location '%s' for cell '%s'.\n", location.c_str(), cell->name.c_str(ctx)); |
| 1913 |
} |
| 1914 |
} |
| 1915 |
} |
| 1916 |
|
| 1917 |
void NgUltraPacker::pack_plls(void) |
| 1918 |
{ |
| 1919 |
log_info("Packing PLLs..\n"); |
| 1920 |
for (auto &cell : ctx->cells) { |
| 1921 |
CellInfo &ci = *cell.second; |
| 1922 |
if (!ci.type.in(id_NX_PLL_U)) |
| 1923 |
continue; |
| 1924 |
ci.type = id_PLL; |
| 1925 |
constrain_location(&ci); |
| 1926 |
|
| 1927 |
disconnect_if_gnd(&ci, id_FBK); |
| 1928 |
disconnect_if_gnd(&ci, id_CLK_CAL); |
| 1929 |
disconnect_if_gnd(&ci, id_R); |
| 1930 |
disconnect_if_gnd(&ci, id_EXT_CAL1); |
| 1931 |
disconnect_if_gnd(&ci, id_EXT_CAL2); |
| 1932 |
disconnect_if_gnd(&ci, id_EXT_CAL3); |
| 1933 |
disconnect_if_gnd(&ci, id_EXT_CAL4); |
| 1934 |
disconnect_if_gnd(&ci, id_EXT_CAL5); |
| 1935 |
disconnect_if_gnd(&ci, id_EXT_CAL_LOCKED); |
| 1936 |
disconnect_if_gnd(&ci, id_ARST_CAL); |
| 1937 |
} |
| 1938 |
} |
| 1939 |
|
| 1940 |
void NgUltraPacker::pack_wfgs(void) |
| 1941 |
{ |
| 1942 |
log_info("Packing WFGs..\n"); |
| 1943 |
for (auto &cell : ctx->cells) { |
| 1944 |
CellInfo &ci = *cell.second; |
| 1945 |
if (!ci.type.in(id_NX_WFG_U)) |
| 1946 |
continue; |
| 1947 |
ci.type = id_WFG; |
| 1948 |
constrain_location(&ci); |
| 1949 |
int mode = int_or_default(ci.params, id_mode, 1); |
| 1950 |
if (mode == 0) { // WFB - bypass mode |
| 1951 |
ci.type = id_WFB; |
| 1952 |
// must not be used, zero is tollerated |
| 1953 |
disconnect_unused(&ci, id_SI); |
| 1954 |
disconnect_unused(&ci, id_SO); |
| 1955 |
disconnect_unused(&ci, id_R); |
| 1956 |
} else if (mode == 1) { |
| 1957 |
// Can be unused, if zero it is unused |
| 1958 |
disconnect_if_gnd(&ci, id_SI); |
| 1959 |
disconnect_if_gnd(&ci, id_R); |
| 1960 |
} else if (mode == 2) { |
| 1961 |
// Allow mode 2 |
| 1962 |
} else { |
| 1963 |
log_error("Unknown mode %d for cell '%s'.\n", mode, ci.name.c_str(ctx)); |
| 1964 |
} |
| 1965 |
NetInfo *zi = ci.getPort(id_ZI); |
| 1966 |
if (!zi || !zi->driver.cell) |
| 1967 |
log_error("WFG port ZI of '%s' must be driven.\n", ci.name.c_str(ctx)); |
| 1968 |
NetInfo *zo = ci.getPort(id_ZO); |
| 1969 |
if (!zo || zo->users.entries() == 0) |
| 1970 |
log_error("WFG port ZO of '%s' must be connected.\n", ci.name.c_str(ctx)); |
| 1971 |
} |
| 1972 |
} |
| 1973 |
|
| 1974 |
void NgUltraPacker::pack_gcks(void) |
| 1975 |
{ |
| 1976 |
log_info("Packing GCKs..\n"); |
| 1977 |
for (auto &cell : ctx->cells) { |
| 1978 |
CellInfo &ci = *cell.second; |
| 1979 |
if (!ci.type.in(id_NX_GCK_U)) |
| 1980 |
continue; |
| 1981 |
ci.type = id_GCK; |
| 1982 |
std::string mode = str_or_default(ci.params, id_std_mode, "BYPASS"); |
| 1983 |
if (mode == "BYPASS") { |
| 1984 |
disconnect_unused(&ci, id_SI2); |
| 1985 |
disconnect_unused(&ci, id_CMD); |
| 1986 |
} else if (mode == "CSC") { |
| 1987 |
disconnect_unused(&ci, id_SI1); |
| 1988 |
disconnect_unused(&ci, id_SI2); |
| 1989 |
} else if (mode == "CKS") { |
| 1990 |
disconnect_unused(&ci, id_SI2); |
| 1991 |
} else if (mode == "MUX") { |
| 1992 |
// all used |
| 1993 |
} else |
| 1994 |
log_error("Unknown mode '%s' for cell '%s'.\n", mode.c_str(), ci.name.c_str(ctx)); |
| 1995 |
|
| 1996 |
if (net_driven_by(ctx, ci.getPort(id_SI1), is_gck, id_SO) || |
| 1997 |
net_driven_by(ctx, ci.getPort(id_SI2), is_gck, id_SO) || |
| 1998 |
net_driven_by(ctx, ci.getPort(id_CMD), is_gck, id_SO)) { |
| 1999 |
log_error("Cascaded GCKs are not allowed.\n"); |
| 2000 |
} |
| 2001 |
} |
| 2002 |
} |
| 2003 |
|
| 2004 |
void NgUltraPacker::pack_rams(void) |
| 2005 |
{ |
| 2006 |
log_info("Packing RAMs..\n"); |
| 2007 |
for (auto &cell : ctx->cells) { |
| 2008 |
CellInfo &ci = *cell.second; |
| 2009 |
if (!ci.type.in(id_NX_RAM)) |
| 2010 |
continue; |
| 2011 |
ci.type = id_RAM; |
| 2012 |
bind_attr_loc(&ci, &ci.attrs); |
| 2013 |
// These ACKx and BCKx exists for NX_RAM, but are not available on NX_ULTRA |
| 2014 |
ci.disconnectPort(id_ACKC); |
| 2015 |
ci.disconnectPort(id_ACKD); |
| 2016 |
ci.disconnectPort(id_ACKR); |
| 2017 |
ci.disconnectPort(id_BCKC); |
| 2018 |
ci.disconnectPort(id_BCKD); |
| 2019 |
ci.disconnectPort(id_BCKR); |
| 2020 |
mandatory_param(&ci, id_raw_config0); |
| 2021 |
mandatory_param(&ci, id_raw_config1); |
| 2022 |
Property extr = ci.params[id_raw_config1].extract(0, 16); |
| 2023 |
std::vector<bool> bits = extr.as_bits(); |
| 2024 |
// int ecc_mode = (bits[12] ? 1 : 0) | (bits[13] ? 2 : 0) | (bits[14] ? 4 : 0) | (bits[15] ? 8 : 0); |
| 2025 |
bool ecc = bits[12]; |
| 2026 |
// int a_in_width = memory_width((bits[0] ? 1 : 0) | (bits[1] ? 2 : 0) | (bits[2] ? 4 : 0), ecc); |
| 2027 |
// int b_in_width = memory_width((bits[3] ? 1 : 0) | (bits[4] ? 2 : 0) | (bits[5] ? 4 : 0), ecc); |
| 2028 |
int a_out_width = memory_width((bits[6] ? 1 : 0) | (bits[7] ? 2 : 0) | (bits[8] ? 4 : 0), ecc); |
| 2029 |
int b_out_width = memory_width((bits[9] ? 1 : 0) | (bits[10] ? 2 : 0) | (bits[11] ? 4 : 0), ecc); |
| 2030 |
|
| 2031 |
int a_addr = std::max(memory_addr_bits((bits[0] ? 1 : 0) | (bits[1] ? 2 : 0) | (bits[2] ? 4 : 0), ecc), |
| 2032 |
memory_addr_bits((bits[6] ? 1 : 0) | (bits[7] ? 2 : 0) | (bits[8] ? 4 : 0), ecc)); |
| 2033 |
int b_addr = std::max(memory_addr_bits((bits[3] ? 1 : 0) | (bits[4] ? 2 : 0) | (bits[5] ? 4 : 0), ecc), |
| 2034 |
memory_addr_bits((bits[9] ? 1 : 0) | (bits[10] ? 2 : 0) | (bits[11] ? 4 : 0), ecc)); |
| 2035 |
|
| 2036 |
NetInfo *a_cs = ci.getPort(id_ACS); |
| 2037 |
if (!a_cs || a_cs->name.in(ctx->id("$PACKER_GND"))) { |
| 2038 |
// If there is no chip-select disconnect all |
| 2039 |
disconnect_unused(&ci, id_ACK); |
| 2040 |
for (int i = 0; i < 24; i++) { |
| 2041 |
disconnect_unused(&ci, ctx->idf("AI%d", i + 1)); |
| 2042 |
disconnect_unused(&ci, ctx->idf("AO%d", i + 1)); |
| 2043 |
} |
| 2044 |
for (int i = 0; i < 16; i++) |
| 2045 |
disconnect_unused(&ci, ctx->idf("AA%d", i + 1)); |
| 2046 |
} else { |
| 2047 |
for (int i = a_out_width; i < 24; i++) |
| 2048 |
disconnect_unused(&ci, ctx->idf("AO%d", i + 1)); |
| 2049 |
for (int i = a_addr; i < 16; i++) |
| 2050 |
disconnect_unused(&ci, ctx->idf("AA%d", i + 1)); |
| 2051 |
} |
| 2052 |
|
| 2053 |
NetInfo *b_cs = ci.getPort(id_BCS); |
| 2054 |
if (!b_cs || b_cs->name.in(ctx->id("$PACKER_GND"))) { |
| 2055 |
// If there is no chip-select disconnect all |
| 2056 |
disconnect_unused(&ci, id_BCK); |
| 2057 |
for (int i = 0; i < 24; i++) { |
| 2058 |
disconnect_unused(&ci, ctx->idf("BI%d", i + 1)); |
| 2059 |
disconnect_unused(&ci, ctx->idf("BO%d", i + 1)); |
| 2060 |
} |
| 2061 |
for (int i = 0; i < 16; i++) |
| 2062 |
disconnect_unused(&ci, ctx->idf("BA%d", i + 1)); |
| 2063 |
} else { |
| 2064 |
for (int i = b_out_width; i < 24; i++) |
| 2065 |
disconnect_unused(&ci, ctx->idf("BO%d", i + 1)); |
| 2066 |
for (int i = b_addr; i < 16; i++) |
| 2067 |
disconnect_unused(&ci, ctx->idf("BA%d", i + 1)); |
| 2068 |
} |
| 2069 |
|
| 2070 |
for (auto &p : ci.ports) { |
| 2071 |
if (p.second.type == PortType::PORT_IN) |
| 2072 |
disconnect_if_gnd(&ci, p.first); |
| 2073 |
} |
| 2074 |
} |
| 2075 |
} |
| 2076 |
|
| 2077 |
void NgUltraPacker::dsp_same_driver(IdString port, CellInfo *cell, CellInfo **target) |
| 2078 |
{ |
| 2079 |
if (cell->getPort(port)) { |
| 2080 |
CellInfo *driver = cell->getPort(port)->driver.cell; |
| 2081 |
if (!driver->type.in(id_DSP, id_NX_DSP_U)) |
| 2082 |
log_error("Port '%s' of '%s' can only be driven by DSP.\n", port.c_str(ctx), cell->name.c_str(ctx)); |
| 2083 |
if (*target && *target != driver) |
| 2084 |
log_error("CAI1-24, CBI1-18, CZI1..56 and CCI must be from same DSP for '%s'.\n", cell->name.c_str(ctx)); |
| 2085 |
*target = driver; |
| 2086 |
} |
| 2087 |
} |
| 2088 |
|
| 2089 |
void NgUltraPacker::dsp_same_sink(IdString port, CellInfo *cell, CellInfo **target) |
| 2090 |
{ |
| 2091 |
if (cell->getPort(port)) { |
| 2092 |
if (cell->getPort(port)->users.entries() != 1) |
| 2093 |
log_error("Port '%s' of '%s' can only drive one DSP.\n", port.c_str(ctx), cell->name.c_str(ctx)); |
| 2094 |
CellInfo *driver = (*cell->getPort(port)->users.begin()).cell; |
| 2095 |
if (!driver->type.in(id_DSP, id_NX_DSP_U)) |
| 2096 |
log_error("Port '%s' of '%s' can only drive DSP.\n", port.c_str(ctx), cell->name.c_str(ctx)); |
| 2097 |
if (*target && *target != driver) |
| 2098 |
log_error("CAI1-24, CBI1-18, CZI1..56 and CCI must be from same DSP for '%s'.\n", cell->name.c_str(ctx)); |
| 2099 |
*target = driver; |
| 2100 |
} |
| 2101 |
} |
| 2102 |
|
| 2103 |
void NgUltraPacker::pack_dsps(void) |
| 2104 |
{ |
| 2105 |
log_info("Packing DSPs..\n"); |
| 2106 |
dict<IdString, CellInfo *> dsp_output; |
| 2107 |
std::vector<CellInfo *> root_dsps; |
| 2108 |
for (auto &cell : ctx->cells) { |
| 2109 |
CellInfo &ci = *cell.second; |
| 2110 |
if (!ci.type.in(id_NX_DSP_U)) |
| 2111 |
continue; |
| 2112 |
ci.type = id_DSP; |
| 2113 |
bind_attr_loc(&ci, &ci.attrs); |
| 2114 |
mandatory_param(&ci, id_raw_config0); |
| 2115 |
mandatory_param(&ci, id_raw_config1); |
| 2116 |
mandatory_param(&ci, id_raw_config2); |
| 2117 |
mandatory_param(&ci, id_raw_config3); |
| 2118 |
|
| 2119 |
for (auto &p : ci.ports) { |
| 2120 |
if (p.second.type == PortType::PORT_IN) |
| 2121 |
disconnect_if_gnd(&ci, p.first); |
| 2122 |
} |
| 2123 |
|
| 2124 |
// CAI1-24, CBI1-18, CZI1..56 and CCI must be from same DSP |
| 2125 |
CellInfo *dsp = nullptr; |
| 2126 |
for (int i = 1; i <= 24; i++) |
| 2127 |
dsp_same_driver(ctx->idf("CAI%d", i), &ci, &dsp); |
| 2128 |
for (int i = 1; i <= 18; i++) |
| 2129 |
dsp_same_driver(ctx->idf("CBI%d", i), &ci, &dsp); |
| 2130 |
for (int i = 1; i <= 56; i++) |
| 2131 |
dsp_same_driver(ctx->idf("CZI%d", i), &ci, &dsp); |
| 2132 |
dsp_same_driver(id_CCI, &ci, &dsp); |
| 2133 |
if (!dsp) |
| 2134 |
root_dsps.push_back(&ci); |
| 2135 |
|
| 2136 |
// CAO1-24, CBO1-18, CZO1..56 and CCO must go to same DSP |
| 2137 |
dsp = nullptr; |
| 2138 |
for (int i = 1; i <= 24; i++) |
| 2139 |
dsp_same_sink(ctx->idf("CAO%d", i), &ci, &dsp); |
| 2140 |
for (int i = 1; i <= 18; i++) |
| 2141 |
dsp_same_sink(ctx->idf("CBO%d", i), &ci, &dsp); |
| 2142 |
for (int i = 1; i <= 56; i++) |
| 2143 |
dsp_same_sink(ctx->idf("CZO%d", i), &ci, &dsp); |
| 2144 |
dsp_same_sink(id_CCO, &ci, &dsp); |
| 2145 |
if (dsp) |
| 2146 |
dsp_output.emplace(ci.name, dsp); |
| 2147 |
} |
| 2148 |
for (auto root : root_dsps) { |
| 2149 |
CellInfo *dsp = root; |
| 2150 |
if (dsp_output.count(dsp->name) == 0) |
| 2151 |
continue; |
| 2152 |
root->cluster = root->name; |
| 2153 |
while (true) { |
| 2154 |
if (dsp_output.count(dsp->name) == 0) |
| 2155 |
break; |
| 2156 |
dsp = dsp_output[dsp->name]; |
| 2157 |
dsp->cluster = root->name; |
| 2158 |
root->constr_children.push_back(dsp); |
| 2159 |
dsp->constr_z = PLACE_DSP_CHAIN; |
| 2160 |
} |
| 2161 |
} |
| 2162 |
} |
| 2163 |
|
| 2164 |
void NgUltraPacker::remove_not_used() |
| 2165 |
{ |
| 2166 |
for (auto &cell : ctx->cells) { |
| 2167 |
CellInfo &ci = *cell.second; |
| 2168 |
for (auto &p : ci.ports) { |
| 2169 |
if (p.second.type == PortType::PORT_OUT) { |
| 2170 |
NetInfo *net = ci.getPort(p.first); |
| 2171 |
if (net && net->users.entries() == 0) { |
| 2172 |
ci.disconnectPort(p.first); |
| 2173 |
} |
| 2174 |
} |
| 2175 |
} |
| 2176 |
} |
| 2177 |
} |
| 2178 |
|
| 2179 |
void NgUltraImpl::pack() |
| 2180 |
{ |
| 2181 |
const ArchArgs &args = ctx->args; |
| 2182 |
if (args.options.count("csv")) { |
| 2183 |
parse_csv(args.options["csv"].as<std::string>()); |
| 2184 |
} |
| 2185 |
|
| 2186 |
// Setup |
| 2187 |
NgUltraPacker packer(ctx, this); |
| 2188 |
packer.pack_constants(); |
| 2189 |
packer.remove_not_used(); |
| 2190 |
packer.update_lut_init(); |
| 2191 |
packer.update_dffs(); |
| 2192 |
|
| 2193 |
// CGB |
| 2194 |
packer.pack_rams(); |
| 2195 |
packer.pack_dsps(); |
| 2196 |
|
| 2197 |
// TILE |
| 2198 |
packer.pack_rfs(); |
| 2199 |
packer.pack_cdcs(); |
| 2200 |
packer.pack_fifos(); |
| 2201 |
packer.pack_cys(); |
| 2202 |
if (!args.options.count("no-xlut")) |
| 2203 |
packer.pack_xluts(); |
| 2204 |
if (!args.options.count("no-lut-chains")) |
| 2205 |
packer.pack_lut_multi_dffs(); |
| 2206 |
if (!args.options.count("no-dff-chains")) |
| 2207 |
packer.pack_dff_chains(); |
| 2208 |
packer.pack_lut_dffs(); |
| 2209 |
packer.pack_dffs(); |
| 2210 |
|
| 2211 |
// Tube |
| 2212 |
packer.pack_gcks(); |
| 2213 |
|
| 2214 |
// Ring |
| 2215 |
packer.pack_iobs(); |
| 2216 |
packer.pack_ioms(); |
| 2217 |
packer.pack_plls(); |
| 2218 |
packer.pack_wfgs(); |
| 2219 |
packer.insert_ioms(); |
| 2220 |
packer.insert_wfbs(); |
| 2221 |
|
| 2222 |
packer.pre_place(); |
| 2223 |
} |
| 2224 |
|
| 2225 |
IdString NgUltraPacker::assign_wfg(IdString ckg, IdString ckg2, CellInfo *cell) |
| 2226 |
{ |
| 2227 |
for (auto &item : uarch->unused_wfg) { |
| 2228 |
BelId bel = item.first; |
| 2229 |
if (item.second == ckg || item.second == ckg2) { |
| 2230 |
IdString ckg = item.second; |
| 2231 |
uarch->unused_wfg.erase(bel); |
| 2232 |
log_info(" Using '%s:%s' for cell '%s'.\n", uarch->tile_name(bel.tile).c_str(), |
| 2233 |
ctx->getBelName(bel)[1].c_str(ctx), cell->name.c_str(ctx)); |
| 2234 |
ctx->bindBel(bel, cell, PlaceStrength::STRENGTH_LOCKED); |
| 2235 |
return ckg; |
| 2236 |
} |
| 2237 |
} |
| 2238 |
log_error(" No more available WFGs for cell '%s'.\n", cell->name.c_str(ctx)); |
| 2239 |
} |
| 2240 |
|
| 2241 |
void NgUltraPacker::extract_lowskew_signals(CellInfo *cell, |
| 2242 |
dict<IdString, dict<IdString, std::vector<PortRef>>> &lowskew_signals) |
| 2243 |
{ |
| 2244 |
IdString loc; |
| 2245 |
if (cell->bel != BelId()) |
| 2246 |
loc = uarch->tile_name_id(cell->bel.tile); |
| 2247 |
|
| 2248 |
PortRef ref; |
| 2249 |
ref.cell = cell; |
| 2250 |
auto &sinks = uarch->get_fabric_lowskew_sinks(); |
| 2251 |
if (sinks.count(cell->type)) { |
| 2252 |
for (auto &port : sinks.at(cell->type)) { |
| 2253 |
NetInfo *clock = cell->getPort(port); |
| 2254 |
if (clock && !global_lowskew.count(clock->name)) { |
| 2255 |
ref.port = port; |
| 2256 |
lowskew_signals[loc][clock->name].push_back(ref); |
| 2257 |
} |
| 2258 |
} |
| 2259 |
} |
| 2260 |
} |
| 2261 |
|
| 2262 |
void NgUltraPacker::pre_place(void) |
| 2263 |
{ |
| 2264 |
log_info("Pre-placing PLLs..\n"); |
| 2265 |
|
| 2266 |
for (auto &cell : ctx->cells) { |
| 2267 |
CellInfo &ci = *cell.second; |
| 2268 |
if (!ci.type.in(id_PLL)) |
| 2269 |
continue; |
| 2270 |
// Remove from list those that are used |
| 2271 |
if (ci.bel != BelId()) { |
| 2272 |
uarch->unused_pll.erase(ci.bel); |
| 2273 |
} |
| 2274 |
} |
| 2275 |
// First process those on dedicated clock pins |
| 2276 |
for (auto &cell : ctx->cells) { |
| 2277 |
CellInfo &ci = *cell.second; |
| 2278 |
if (!ci.type.in(id_PLL) || ci.bel != BelId()) |
| 2279 |
continue; |
| 2280 |
|
| 2281 |
NetInfo *ref = ci.getPort(id_REF); |
| 2282 |
if (ref && ref->driver.cell && ref->driver.cell->type == id_IOM) { |
| 2283 |
IdString bank = uarch->tile_name_id(ref->driver.cell->bel.tile); |
| 2284 |
// bool found = false; |
| 2285 |
for (auto &item : uarch->unused_pll) { |
| 2286 |
BelId bel = item.first; |
| 2287 |
std::pair<IdString, IdString> &ckgs = uarch->bank_to_ckg[bank]; |
| 2288 |
if (item.second == ckgs.first || item.second == ckgs.second) { |
| 2289 |
uarch->unused_pll.erase(bel); |
| 2290 |
log_info(" Using PLL in '%s' for cell '%s'.\n", uarch->tile_name(bel.tile).c_str(), |
| 2291 |
ci.name.c_str(ctx)); |
| 2292 |
ctx->bindBel(bel, &ci, PlaceStrength::STRENGTH_LOCKED); |
| 2293 |
// found = true; |
| 2294 |
break; |
| 2295 |
} |
| 2296 |
} |
| 2297 |
} |
| 2298 |
} |
| 2299 |
// If PLL use any other pin, location is not relevant, so we pick available |
| 2300 |
for (auto &cell : ctx->cells) { |
| 2301 |
CellInfo &ci = *cell.second; |
| 2302 |
if (!ci.type.in(id_PLL) || ci.bel != BelId()) |
| 2303 |
continue; |
| 2304 |
if (uarch->unused_pll.empty()) |
| 2305 |
log_error(" No more available PLLs for driving '%s'.\n", ci.name.c_str(ctx)); |
| 2306 |
BelId bel = uarch->unused_pll.begin()->first; |
| 2307 |
uarch->unused_pll.erase(bel); |
| 2308 |
log_info(" Using PLL in '%s' for cell '%s'.\n", uarch->tile_name(bel.tile).c_str(), ci.name.c_str(ctx)); |
| 2309 |
ctx->bindBel(bel, &ci, PlaceStrength::STRENGTH_LOCKED); |
| 2310 |
} |
| 2311 |
|
| 2312 |
log_info("Pre-placing WFB/WFGs..\n"); |
| 2313 |
|
| 2314 |
std::vector<CellInfo *> root_wfgs; |
| 2315 |
for (auto &cell : ctx->cells) { |
| 2316 |
CellInfo &ci = *cell.second; |
| 2317 |
if (!ci.type.in(id_WFG, id_WFB)) |
| 2318 |
continue; |
| 2319 |
NetInfo *zi = ci.getPort(id_ZI); |
| 2320 |
if (!zi || !zi->driver.cell || !zi->driver.cell->type.in(id_WFG, id_WFB)) |
| 2321 |
root_wfgs.push_back(&ci); |
| 2322 |
} |
| 2323 |
|
| 2324 |
std::vector<std::vector<CellInfo *>> groups; |
| 2325 |
for (auto root : root_wfgs) { |
| 2326 |
std::vector<CellInfo *> group; |
| 2327 |
CellInfo *wfg = root; |
| 2328 |
group.push_back(wfg); |
| 2329 |
while (true) { |
| 2330 |
NetInfo *zo_net = wfg->getPort(id_ZO); |
| 2331 |
if (zo_net && zo_net->users.entries() > 0) { |
| 2332 |
wfg = (*zo_net->users.begin()).cell; |
| 2333 |
if (wfg->type.in(id_WFG, id_WFB)) { |
| 2334 |
if (zo_net->users.entries() != 1) |
| 2335 |
log_error("WFG can only be chained with one other WFG cell\n"); |
| 2336 |
group.push_back(wfg); |
| 2337 |
} else |
| 2338 |
break; |
| 2339 |
} else |
| 2340 |
break; |
| 2341 |
} |
| 2342 |
groups.push_back(group); |
| 2343 |
} |
| 2344 |
|
| 2345 |
// First pre-place those depending of PLL |
| 2346 |
for (auto &grp : groups) { |
| 2347 |
CellInfo *root = grp.front(); |
| 2348 |
NetInfo *zi = root->getPort(id_ZI); |
| 2349 |
if (zi->driver.cell->type.in(id_PLL)) { |
| 2350 |
IdString ckg = uarch->tile_name_id(zi->driver.cell->bel.tile); |
| 2351 |
assign_wfg(ckg, IdString(), root); |
| 2352 |
for (int i = 1; i < int(grp.size()); i++) { |
| 2353 |
assign_wfg(ckg, IdString(), grp.at(i)); |
| 2354 |
} |
| 2355 |
} |
| 2356 |
} |
| 2357 |
// Then those that depend on IOM |
| 2358 |
for (auto &grp : groups) { |
| 2359 |
CellInfo *root = grp.front(); |
| 2360 |
NetInfo *zi = root->getPort(id_ZI); |
| 2361 |
if (zi->driver.cell->type.in(id_IOM)) { |
| 2362 |
IdString bank = uarch->tile_name_id(zi->driver.cell->bel.tile); |
| 2363 |
std::pair<IdString, IdString> &ckgs = uarch->bank_to_ckg[bank]; |
| 2364 |
IdString ckg = assign_wfg(ckgs.first, ckgs.second, root); |
| 2365 |
for (int i = 1; i < int(grp.size()); i++) { |
| 2366 |
assign_wfg(ckg, IdString(), grp.at(i)); |
| 2367 |
} |
| 2368 |
} |
| 2369 |
} |
| 2370 |
for (auto &grp : groups) { |
| 2371 |
CellInfo *root = grp.front(); |
| 2372 |
if (root->bel != BelId()) |
| 2373 |
continue; |
| 2374 |
// Assign first available |
| 2375 |
BelId bel = uarch->unused_pll.begin()->first; |
| 2376 |
IdString ckg = uarch->unused_pll.begin()->second; |
| 2377 |
uarch->unused_pll.erase(bel); |
| 2378 |
for (int i = 1; i < int(grp.size()); i++) { |
| 2379 |
assign_wfg(ckg, IdString(), grp.at(i)); |
| 2380 |
} |
| 2381 |
} |
| 2382 |
|
| 2383 |
dict<IdString, dict<IdString, std::vector<PortRef>>> lowskew_signals; |
| 2384 |
for (auto &cell : ctx->cells) |
| 2385 |
extract_lowskew_signals(cell.second.get(), lowskew_signals); |
| 2386 |
|
| 2387 |
log_info("Adding GCK for lowskew signals..\n"); |
| 2388 |
for (auto &n : lowskew_signals[IdString()]) { |
| 2389 |
NetInfo *net = ctx->nets.at(n.first).get(); |
| 2390 |
if (net->driver.cell->type.in(id_BFR, id_DFR, id_DDFR)) { |
| 2391 |
CellInfo *bfr = net->driver.cell; |
| 2392 |
CellInfo *gck_cell = create_cell_ptr(id_GCK, ctx->idf("%s$csc", bfr->name.c_str(ctx))); |
| 2393 |
gck_cell->params[id_std_mode] = Property("CSC"); |
| 2394 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$bfr", bfr->name.c_str(ctx))); |
| 2395 |
NetInfo *old = bfr->getPort(id_O); |
| 2396 |
bfr->disconnectPort(id_O); |
| 2397 |
gck_cell->connectPort(id_SO, old); |
| 2398 |
gck_cell->connectPort(id_CMD, new_out); |
| 2399 |
bfr->connectPort(id_O, new_out); |
| 2400 |
log_info(" Create GCK '%s' for signal '%s'\n", gck_cell->name.c_str(ctx), n.first.c_str(ctx)); |
| 2401 |
} |
| 2402 |
if (net->driver.cell->type.in(id_BEYOND_FE)) { |
| 2403 |
CellInfo *fe = net->driver.cell; |
| 2404 |
if (!fe->params.count(id_lut_table)) |
| 2405 |
continue; |
| 2406 |
if (fe->params.count(id_dff_used)) |
| 2407 |
continue; |
| 2408 |
if (fe->params[id_lut_table] != Property(0x5555, 16)) |
| 2409 |
continue; |
| 2410 |
if (!fe->getPort(id_I1)) |
| 2411 |
continue; |
| 2412 |
CellInfo *bfr = fe->getPort(id_I1)->driver.cell; |
| 2413 |
if (bfr->type.in(id_BFR, id_DFR, id_DDFR)) { |
| 2414 |
CellInfo *gck_cell = create_cell_ptr(id_GCK, ctx->idf("%s$csc", bfr->name.c_str(ctx))); |
| 2415 |
gck_cell->params[id_std_mode] = Property("CSC"); |
| 2416 |
gck_cell->params[id_inv_out] = Property(true); |
| 2417 |
NetInfo *old_out = fe->getPort(id_LO); |
| 2418 |
NetInfo *old_in = fe->getPort(id_I1); |
| 2419 |
fe->disconnectPort(id_LO); |
| 2420 |
fe->disconnectPort(id_I1); |
| 2421 |
gck_cell->connectPort(id_SO, old_out); |
| 2422 |
gck_cell->connectPort(id_CMD, old_in); |
| 2423 |
packed_cells.insert(fe->name); |
| 2424 |
log_info(" Create GCK '%s' for signal '%s'\n", gck_cell->name.c_str(ctx), n.first.c_str(ctx)); |
| 2425 |
} |
| 2426 |
} |
| 2427 |
} |
| 2428 |
flush_cells(); |
| 2429 |
} |
| 2430 |
|
| 2431 |
void NgUltraImpl::disable_beyond_fe_s_output(BelId bel) |
| 2432 |
{ |
| 2433 |
WireId dwire = ctx->getBelPinWire(bel, id_DO); |
| 2434 |
for (PipId pip : ctx->getPipsDownhill(dwire)) { |
| 2435 |
for (PipId pip2 : ctx->getPipsDownhill(ctx->getPipDstWire(pip))) { |
| 2436 |
IdString dst = ctx->getWireName(ctx->getPipDstWire(pip2))[1]; |
| 2437 |
if (boost::ends_with(dst.c_str(ctx), ".DS")) { |
| 2438 |
blocked_pips.emplace(pip2); |
| 2439 |
return; |
| 2440 |
} |
| 2441 |
} |
| 2442 |
} |
| 2443 |
} |
| 2444 |
|
| 2445 |
void NgUltraImpl::postPlace() |
| 2446 |
{ |
| 2447 |
log_break(); |
| 2448 |
log_info("Limiting routing...\n"); |
| 2449 |
for (auto &cell : ctx->cells) { |
| 2450 |
CellInfo &ci = *cell.second; |
| 2451 |
if (ci.type == id_BEYOND_FE) { |
| 2452 |
const auto &extra_data = *bel_extra_data(ci.bel); |
| 2453 |
// Check if CSC mode only if FE is capable |
| 2454 |
if ((extra_data.flags & BEL_EXTRA_FE_CSC)) { |
| 2455 |
if (str_or_default(ci.params, id_type, "") == "CSC") |
| 2456 |
continue; |
| 2457 |
// Disable routing to S output if CSC is not used |
| 2458 |
disable_beyond_fe_s_output(ci.bel); |
| 2459 |
} |
| 2460 |
} else if (ci.type == id_CY) { |
| 2461 |
// In case A input is actually used, but it is connectd to GND |
| 2462 |
// it is considered that signal is comming from RI1 crossbar. |
| 2463 |
// We need to prevent router to use that crossbar output for |
| 2464 |
// any other signal. |
| 2465 |
for (int i = 1; i <= 4; i++) { |
| 2466 |
IdString port = ctx->idf("A%d", i); |
| 2467 |
NetInfo *net = ci.getPort(port); |
| 2468 |
if (!net) |
| 2469 |
continue; |
| 2470 |
if (net->name.in(ctx->id("$PACKER_GND"))) { |
| 2471 |
WireId dwire = ctx->getBelPinWire(ci.bel, port); |
| 2472 |
for (PipId pip : ctx->getPipsUphill(dwire)) { |
| 2473 |
WireId src = ctx->getPipSrcWire(pip); |
| 2474 |
const std::string src_name = ctx->getWireName(src)[1].str(ctx); |
| 2475 |
if (boost::starts_with(src_name, "RI1")) { |
| 2476 |
for (PipId pip2 : ctx->getPipsDownhill(src)) { |
| 2477 |
blocked_pips.emplace(pip2); |
| 2478 |
} |
| 2479 |
} |
| 2480 |
} |
| 2481 |
ci.disconnectPort(port); // Disconnect A |
| 2482 |
} |
| 2483 |
} |
| 2484 |
} |
| 2485 |
} |
| 2486 |
remove_constants(); |
| 2487 |
|
| 2488 |
const ArchArgs &args = ctx->args; |
| 2489 |
NgUltraPacker packer(ctx, this); |
| 2490 |
log_break(); |
| 2491 |
log_info("Running post-placement ...\n"); |
| 2492 |
packer.duplicate_gck(); |
| 2493 |
packer.insert_bypass_gck(); |
| 2494 |
if (!args.options.count("no-csc-insertion")) |
| 2495 |
packer.insert_csc(); |
| 2496 |
log_break(); |
| 2497 |
ctx->assignArchInfo(); |
| 2498 |
} |
| 2499 |
|
| 2500 |
BelId NgUltraPacker::getCSC(Loc l, int row) |
| 2501 |
{ |
| 2502 |
const int z_loc[] = {0, 15, 16, 31}; |
| 2503 |
for (int j = 0; j < 3; j++) { |
| 2504 |
for (int i = 0; i < 4; i++) { |
| 2505 |
BelId bel = ctx->getBelByLocation(Loc(l.x + j + 1, l.y + j % 2 + 2, z_loc[i])); |
| 2506 |
if (!ctx->getBoundBelCell(bel) && (row == 0 || row == (i + 1))) |
| 2507 |
return bel; |
| 2508 |
} |
| 2509 |
} |
| 2510 |
return BelId(); |
| 2511 |
} |
| 2512 |
|
| 2513 |
void NgUltraPacker::insert_csc() |
| 2514 |
{ |
| 2515 |
dict<IdString, dict<IdString, std::vector<PortRef>>> local_system_matrix; |
| 2516 |
log_info("Inserting CSCs...\n"); |
| 2517 |
int insert_new_csc = 0, change_to_csc = 0; |
| 2518 |
for (auto &cell : ctx->cells) { |
| 2519 |
auto ci = cell.second.get(); |
| 2520 |
if (ci->bel != BelId()) { |
| 2521 |
if (uarch->tile_type(ci->bel.tile) == TILE_EXTRA_FABRIC) { |
| 2522 |
extract_lowskew_signals(ci, local_system_matrix); |
| 2523 |
} |
| 2524 |
} |
| 2525 |
} |
| 2526 |
for (auto &lsm : local_system_matrix) { |
| 2527 |
std::string name = lsm.first.c_str(ctx); |
| 2528 |
Loc loc = uarch->tile_locations[name]; |
| 2529 |
std::vector<std::pair<int, IdString>> fanout; |
| 2530 |
for (auto &n : lsm.second) { |
| 2531 |
fanout.push_back(std::make_pair(n.second.size(), n.first)); |
| 2532 |
} |
| 2533 |
std::sort(fanout.begin(), fanout.end(), std::greater<std::pair<int, IdString>>()); |
| 2534 |
int available_csc = 12; |
| 2535 |
for (std::size_t i = 0; i < std::min<std::size_t>(fanout.size(), available_csc); i++) { |
| 2536 |
auto &n = fanout.at(i); |
| 2537 |
|
| 2538 |
NetInfo *net = ctx->nets.at(n.second).get(); |
| 2539 |
CellInfo *cell = net->driver.cell; |
| 2540 |
if (uarch->tile_name(cell->bel.tile) == lsm.first.c_str(ctx) && !cell->params.count(id_dff_used) && |
| 2541 |
cell->cluster == ClusterId()) { |
| 2542 |
BelId newbel = getCSC(loc, 0); |
| 2543 |
if (newbel == BelId()) |
| 2544 |
break; |
| 2545 |
|
| 2546 |
ctx->unbindBel(cell->bel); |
| 2547 |
cell->disconnectPort(id_LO); |
| 2548 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$o", cell->name.c_str(ctx))); |
| 2549 |
cell->params[id_CSC] = Property(Property::State::S1); |
| 2550 |
cell->params[id_type] = Property("CSC"); |
| 2551 |
cell->params[id_dff_used] = Property(1, 1); |
| 2552 |
cell->connectPort(id_LO, new_out); |
| 2553 |
cell->connectPort(id_DI, new_out); |
| 2554 |
|
| 2555 |
cell->connectPort(id_DO, net); |
| 2556 |
ctx->bindBel(newbel, cell, PlaceStrength::STRENGTH_LOCKED); |
| 2557 |
change_to_csc++; |
| 2558 |
continue; |
| 2559 |
} |
| 2560 |
Loc cell_loc = ctx->getBelLocation(cell->bel); |
| 2561 |
BelId newbel = getCSC(loc, (cell_loc.y & 3) + 1); // Take CSC from pefered row |
| 2562 |
if (newbel == BelId()) |
| 2563 |
newbel = getCSC(loc, 0); // Try getting any other CSC |
| 2564 |
if (newbel == BelId()) |
| 2565 |
break; |
| 2566 |
if (lsm.second[n.second].size() < 4) |
| 2567 |
break; |
| 2568 |
|
| 2569 |
CellInfo *fe = |
| 2570 |
create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$%s$csc", net->name.c_str(ctx), lsm.first.c_str(ctx))); |
| 2571 |
NetInfo *new_out = ctx->createNet(ctx->idf("%s$o", fe->name.c_str(ctx))); |
| 2572 |
fe->params[id_lut_table] = Property(0xaaaa, 16); |
| 2573 |
fe->params[id_lut_used] = Property(1, 1); |
| 2574 |
fe->params[id_CSC] = Property(Property::State::S1); |
| 2575 |
fe->params[id_type] = Property("CSC"); |
| 2576 |
fe->params[id_dff_used] = Property(1, 1); |
| 2577 |
fe->connectPort(id_I1, net); |
| 2578 |
fe->connectPort(id_DO, new_out); |
| 2579 |
insert_new_csc++; |
| 2580 |
|
| 2581 |
for (auto &conn : lsm.second[n.second]) |
| 2582 |
conn.cell->disconnectPort(conn.port); |
| 2583 |
for (auto &conn : lsm.second[n.second]) |
| 2584 |
conn.cell->connectPort(conn.port, new_out); |
| 2585 |
|
| 2586 |
ctx->bindBel(newbel, fe, PlaceStrength::STRENGTH_LOCKED); |
| 2587 |
} |
| 2588 |
} |
| 2589 |
if (insert_new_csc) |
| 2590 |
log_info(" %6d FEs inserted as CSC\n", insert_new_csc); |
| 2591 |
if (change_to_csc) |
| 2592 |
log_info(" %6d FEs converted to CSC\n", change_to_csc); |
| 2593 |
} |
| 2594 |
BelId NgUltraPacker::get_available_gck(int lobe, NetInfo *si1, NetInfo *si2) |
| 2595 |
{ |
| 2596 |
auto &gcks = uarch->gck_per_lobe[lobe]; |
| 2597 |
for (int i = 0; i < 20; i++) { |
| 2598 |
auto &g = gcks.at(i); |
| 2599 |
if (g.used) |
| 2600 |
continue; |
| 2601 |
if (si1 && g.si1 != IdString() && g.si1 != si1->name) |
| 2602 |
continue; |
| 2603 |
if (si2 && g.si2 != IdString() && g.si2 != si2->name) |
| 2604 |
continue; |
| 2605 |
if (si1) |
| 2606 |
g.si1 = si1->name; |
| 2607 |
if (si2) |
| 2608 |
g.si2 = si2->name; |
| 2609 |
g.used = true; |
| 2610 |
if (i % 2 == 0) { |
| 2611 |
// next GCK share inputs in reverse order |
| 2612 |
if (si2) |
| 2613 |
gcks.at(i + 1).si1 = si2->name; |
| 2614 |
if (si1) |
| 2615 |
gcks.at(i + 1).si2 = si1->name; |
| 2616 |
} |
| 2617 |
return g.bel; |
| 2618 |
} |
| 2619 |
log_error("No GCK left to promote lowskew signal.\n"); |
| 2620 |
return BelId(); |
| 2621 |
} |
| 2622 |
|
| 2623 |
void NgUltraPacker::duplicate_gck() |
| 2624 |
{ |
| 2625 |
// Unbind all GCKs that are inserted |
| 2626 |
for (auto &cell : ctx->cells) { |
| 2627 |
CellInfo &ci = *cell.second; |
| 2628 |
if (!ci.type.in(id_GCK)) |
| 2629 |
continue; |
| 2630 |
ctx->unbindBel(ci.bel); |
| 2631 |
} |
| 2632 |
|
| 2633 |
log_info("Duplicating existing GCKs...\n"); |
| 2634 |
for (auto &net : ctx->nets) { |
| 2635 |
NetInfo *glb_net = net.second.get(); |
| 2636 |
if (!glb_net->driver.cell) |
| 2637 |
continue; |
| 2638 |
|
| 2639 |
if (!uarch->is_tube_clock_source(glb_net->driver)) |
| 2640 |
continue; |
| 2641 |
|
| 2642 |
log_info(" Lowskew signal '%s'\n", glb_net->name.c_str(ctx)); |
| 2643 |
dict<int, std::vector<PortRef>> connections; |
| 2644 |
for (const auto &usr : glb_net->users) { |
| 2645 |
if (uarch->is_fabric_lowskew_sink(usr) || uarch->is_ring_over_tile_clock_sink(usr)) { |
| 2646 |
if (usr.cell->bel == BelId()) { |
| 2647 |
log_error("Cell '%s' not placed\n", usr.cell->name.c_str(ctx)); |
| 2648 |
} |
| 2649 |
int lobe = uarch->tile_lobe(usr.cell->bel.tile); |
| 2650 |
if (lobe > 0) { |
| 2651 |
connections[lobe].push_back(usr); |
| 2652 |
usr.cell->disconnectPort(usr.port); |
| 2653 |
} |
| 2654 |
} |
| 2655 |
} |
| 2656 |
int cnt = 0; |
| 2657 |
CellInfo *driver = glb_net->driver.cell; |
| 2658 |
NetInfo *si1 = driver->getPort(id_SI1); |
| 2659 |
NetInfo *si2 = driver->getPort(id_SI2); |
| 2660 |
NetInfo *cmd = driver->getPort(id_CMD); |
| 2661 |
for (auto &conn : connections) { |
| 2662 |
BelId bel = get_available_gck(conn.first, si1, si2); |
| 2663 |
CellInfo *gck_cell = nullptr; |
| 2664 |
if (cnt == 0) { |
| 2665 |
gck_cell = driver; |
| 2666 |
log_info(" Assign GCK '%s' to lobe %d\n", gck_cell->name.c_str(ctx), conn.first); |
| 2667 |
} else { |
| 2668 |
gck_cell = create_cell_ptr(id_GCK, ctx->idf("%s$gck_%d", driver->name.c_str(ctx), conn.first)); |
| 2669 |
log_info(" Create GCK '%s' for lobe %d\n", gck_cell->name.c_str(ctx), conn.first); |
| 2670 |
for (auto ¶ms : driver->params) |
| 2671 |
gck_cell->params[params.first] = params.second; |
| 2672 |
if (si1) |
| 2673 |
gck_cell->connectPort(id_SI1, si1); |
| 2674 |
if (si2) |
| 2675 |
gck_cell->connectPort(id_SI2, si2); |
| 2676 |
if (cmd) |
| 2677 |
gck_cell->connectPort(id_CMD, cmd); |
| 2678 |
} |
| 2679 |
gck_cell->disconnectPort(id_SO); |
| 2680 |
NetInfo *new_clk = ctx->createNet(ctx->id(gck_cell->name.str(ctx))); |
| 2681 |
gck_cell->connectPort(id_SO, new_clk); |
| 2682 |
for (const auto &usr : conn.second) { |
| 2683 |
CellInfo *cell = usr.cell; |
| 2684 |
IdString port = usr.port; |
| 2685 |
cell->connectPort(port, new_clk); |
| 2686 |
} |
| 2687 |
global_lowskew.emplace(new_clk->name); |
| 2688 |
ctx->bindBel(bel, gck_cell, PlaceStrength::STRENGTH_LOCKED); |
| 2689 |
cnt++; |
| 2690 |
} |
| 2691 |
} |
| 2692 |
} |
| 2693 |
|
| 2694 |
void NgUltraPacker::insert_bypass_gck() |
| 2695 |
{ |
| 2696 |
log_info("Inserting bypass GCKs...\n"); |
| 2697 |
for (auto &net : ctx->nets) { |
| 2698 |
NetInfo *glb_net = net.second.get(); |
| 2699 |
if (!glb_net->driver.cell) |
| 2700 |
continue; |
| 2701 |
|
| 2702 |
if (!uarch->is_ring_clock_source(glb_net->driver)) |
| 2703 |
continue; |
| 2704 |
|
| 2705 |
log_info(" Lowskew signal '%s'\n", glb_net->name.c_str(ctx)); |
| 2706 |
dict<int, std::vector<PortRef>> connections; |
| 2707 |
for (const auto &usr : glb_net->users) { |
| 2708 |
if (uarch->is_fabric_lowskew_sink(usr) || uarch->is_ring_over_tile_clock_sink(usr)) { |
| 2709 |
if (usr.cell->bel == BelId()) { |
| 2710 |
log_error("Cell '%s' not placed\n", usr.cell->name.c_str(ctx)); |
| 2711 |
} |
| 2712 |
int lobe = uarch->tile_lobe(usr.cell->bel.tile); |
| 2713 |
if (lobe > 0) { |
| 2714 |
connections[lobe].push_back(usr); |
| 2715 |
usr.cell->disconnectPort(usr.port); |
| 2716 |
} |
| 2717 |
} |
| 2718 |
} |
| 2719 |
for (auto &conn : connections) { |
| 2720 |
BelId bel = get_available_gck(conn.first, glb_net, nullptr); |
| 2721 |
|
| 2722 |
log_info(" Create GCK for lobe %d\n", conn.first); |
| 2723 |
CellInfo *gck_cell = create_cell_ptr(id_GCK, ctx->idf("%s$gck_%d", glb_net->name.c_str(ctx), conn.first)); |
| 2724 |
gck_cell->params[id_std_mode] = Property("BYPASS"); |
| 2725 |
gck_cell->connectPort(id_SI1, glb_net); |
| 2726 |
NetInfo *new_clk = ctx->createNet(ctx->id(gck_cell->name.str(ctx))); |
| 2727 |
gck_cell->connectPort(id_SO, new_clk); |
| 2728 |
for (const auto &usr : conn.second) { |
| 2729 |
CellInfo *cell = usr.cell; |
| 2730 |
IdString port = usr.port; |
| 2731 |
cell->connectPort(port, new_clk); |
| 2732 |
} |
| 2733 |
global_lowskew.emplace(new_clk->name); |
| 2734 |
ctx->bindBel(bel, gck_cell, PlaceStrength::STRENGTH_LOCKED); |
| 2735 |
} |
| 2736 |
} |
| 2737 |
} |
| 2738 |
NEXTPNR_NAMESPACE_END |