Debian Codegraph @

himbaechel/uarch/gatemate/pack.cc

raw
1 /*
2 * nextpnr -- Next Generation Place and Route
3 *
4 * Copyright (C) 2024 The Project Peppercorn 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 "design_utils.h"
22 #include "gatemate_util.h"
23
24 #define HIMBAECHEL_CONSTIDS "uarch/gatemate/constids.inc"
25 #include "himbaechel_constids.h"
26
27 NEXTPNR_NAMESPACE_BEGIN
28
29 void GateMatePacker::flush_cells()
30 {
31 for (auto pcell : packed_cells) {
32 for (auto &port : ctx->cells[pcell]->ports) {
33 ctx->cells[pcell]->disconnectPort(port.first);
34 }
35 if (ctx->cells[pcell]->bel != BelId())
36 ctx->unbindBel(ctx->cells[pcell]->bel);
37 ctx->cells.erase(pcell);
38 }
39 packed_cells.clear();
40 }
41
42 void GateMatePacker::disconnect_if_gnd(CellInfo *cell, IdString input)
43 {
44 if (cell->getPort(input) == net_PACKER_GND)
45 cell->disconnectPort(input);
46 }
47
48 void GateMatePacker::pack_misc()
49 {
50 log_info("Packing misc..\n");
51 for (auto &cell : ctx->cells) {
52 CellInfo &ci = *cell.second;
53 if (!ci.type.in(id_CC_USR_RSTN))
54 continue;
55 ci.type = id_USR_RSTN;
56 ci.cluster = ci.name;
57 Loc fixed_loc = uarch->locations[std::make_pair(id_USR_RSTN, uarch->preferred_die)];
58 ctx->bindBel(ctx->getBelByLocation(fixed_loc), &ci, PlaceStrength::STRENGTH_FIXED);
59
60 move_ram_i_fixed(&ci, id_USR_RSTN, fixed_loc);
61 }
62 for (auto &cell : ctx->cells) {
63 CellInfo &ci = *cell.second;
64 if (!ci.type.in(id_CC_CFG_CTRL))
65 continue;
66 ci.type = id_CFG_CTRL;
67 ci.cluster = ci.name;
68 Loc fixed_loc = uarch->locations[std::make_pair(id_CFG_CTRL, uarch->preferred_die)];
69 ctx->bindBel(ctx->getBelByLocation(fixed_loc), &ci, PlaceStrength::STRENGTH_FIXED);
70
71 move_ram_o_fixed(&ci, id_CLK, fixed_loc);
72 move_ram_o_fixed(&ci, id_EN, fixed_loc);
73 move_ram_o_fixed(&ci, id_VALID, fixed_loc);
74 move_ram_o_fixed(&ci, id_RECFG, fixed_loc);
75 for (int i = 0; i < 8; i++)
76 move_ram_o_fixed(&ci, ctx->idf("DATA[%d]", i), fixed_loc);
77 }
78 for (auto &cell : ctx->cells) {
79 CellInfo &ci = *cell.second;
80 if (!ci.type.in(id_CC_ODDR, id_CC_IDDR))
81 continue;
82 log_error("Cell '%s' of type %s is not connected to GPIO pin.\n", ci.name.c_str(ctx), ci.type.c_str(ctx));
83 }
84 }
85
86 void GateMatePacker::disconnect_not_used()
87 {
88 for (auto &cell : ctx->cells) {
89 CellInfo &ci = *cell.second;
90 for (auto &p : ci.ports) {
91 if (p.second.type == PortType::PORT_OUT) {
92 NetInfo *net = ci.getPort(p.first);
93 if (net && net->users.entries() == 0) {
94 ci.disconnectPort(p.first);
95 }
96 }
97 }
98 }
99 }
100
101 void GateMatePacker::copy_constraint(const NetInfo *in_net, NetInfo *out_net)
102 {
103 if (!in_net || !out_net)
104 return;
105 if (ctx->debug)
106 log_info("Copy clock period constraint on net '%s' from net '%s'\n", out_net->name.c_str(ctx),
107 in_net->name.c_str(ctx));
108 if (out_net->clkconstr.get() != nullptr)
109 log_warning("Found multiple clock constraints on net '%s'\n", out_net->name.c_str(ctx));
110 if (in_net->clkconstr) {
111 out_net->clkconstr = std::unique_ptr<ClockConstraint>(new ClockConstraint());
112 out_net->clkconstr->low = in_net->clkconstr->low;
113 out_net->clkconstr->high = in_net->clkconstr->high;
114 out_net->clkconstr->period = in_net->clkconstr->period;
115 }
116 }
117
118 void GateMatePacker::move_connections(NetInfo *from_net, NetInfo *to_net)
119 {
120 for (const auto &usr : from_net->users) {
121 IdString port = usr.port;
122 usr.cell->disconnectPort(port);
123 usr.cell->connectPort(port, to_net);
124 }
125 }
126
127 void GateMatePacker::count_cell(CellInfo &ci)
128 {
129 packed_cells.insert(ci.name);
130 count_per_type[ci.type]++;
131 count++;
132 }
133
134 inline int lut2_apply_constant_inputs(int init, int d0_const, int d1_const)
135 {
136 int b0 = (init >> 0) & 1;
137 int b1 = (init >> 1) & 1;
138 int b2 = (init >> 2) & 1;
139 int b3 = (init >> 3) & 1;
140
141 int out[4];
142
143 for (int i = 0; i < 4; i++) {
144 int D1 = (i >> 1) & 1;
145 int D0 = (i >> 0) & 1;
146
147 // Apply constants if present
148 if (d0_const != -1)
149 D0 = d0_const;
150 if (d1_const != -1)
151 D1 = d1_const;
152
153 int src = (D1 << 1) | D0;
154 out[i] = (src == 0) ? b0 : (src == 1) ? b1 : (src == 2) ? b2 : b3;
155 }
156
157 return (out[3] << 3) | (out[2] << 2) | (out[1] << 1) | out[0];
158 }
159
160 void GateMatePacker::optimize_lut2(CellInfo &ci, IdString i0, IdString i1, IdString init)
161 {
162 auto lut2_same_inputs = [&](int lut) -> int {
163 int b0 = lut & 1; // bit 0
164 int b3 = (lut >> 3) & 1; // bit 3
165
166 return (b3 << 3) | (b3 << 2) | (b0 << 1) | b0;
167 };
168
169 uint8_t val = int_or_default(ci.params, init, 0);
170 int d0_const = -1;
171 int d1_const = -1;
172 if (ci.getPort(i0) && ci.getPort(i0) == net_PACKER_GND) {
173 d0_const = 0;
174 ci.disconnectPort(i0);
175 }
176 if (ci.getPort(i0) && ci.getPort(i0) == net_PACKER_VCC) {
177 d0_const = 1;
178 ci.disconnectPort(i0);
179 }
180 if (ci.getPort(i1) && ci.getPort(i1) == net_PACKER_GND) {
181 d1_const = 0;
182 ci.disconnectPort(i1);
183 }
184 if (ci.getPort(i1) && ci.getPort(i1) == net_PACKER_VCC) {
185 d1_const = 1;
186 ci.disconnectPort(i1);
187 }
188
189 val = lut2_apply_constant_inputs(val, d0_const, d1_const);
190
191 if (ci.getPort(i0) == ci.getPort(i1)) {
192 val = lut2_same_inputs(val);
193 ci.params[init] = Property(val, 4);
194 ci.disconnectPort(i1);
195 }
196 }
197
198 void GateMatePacker::optimize_lut()
199 {
200 for (auto &cell : ctx->cells) {
201 CellInfo &ci = *cell.second;
202 if (ci.type == id_CC_LUT2) {
203 optimize_lut2(ci, id_I0, id_I1, id_INIT);
204 } else if (ci.type == id_CC_L2T4) {
205 optimize_lut2(ci, id_I0, id_I1, id_INIT_L00);
206 optimize_lut2(ci, id_I2, id_I3, id_INIT_L01);
207 } else if (ci.type == id_CC_L2T5) {
208 optimize_lut2(ci, id_I0, id_I1, id_INIT_L02);
209 optimize_lut2(ci, id_I2, id_I3, id_INIT_L03);
210 }
211 if (!ci.type.in(id_CC_LUT1, id_CC_LUT2))
212 continue;
213 if (ci.attrs.count(ctx->id("keep")))
214 continue;
215 NetInfo *o_net = ci.getPort(id_O);
216 if (!o_net) {
217 count_cell(ci);
218 continue;
219 }
220
221 uint8_t val = int_or_default(ci.params, id_INIT, 0);
222 if (ci.type == id_CC_LUT1)
223 val = val << 2 | val;
224 switch (val) {
225 case LUT_ZERO: // constant 0
226 move_connections(o_net, net_PACKER_GND);
227 count_cell(ci);
228 break;
229 case LUT_D0: // propagate
230 move_connections(o_net, ci.getPort(id_I0));
231 count_cell(ci);
232 break;
233 case LUT_D1: // propagate
234 move_connections(o_net, ci.getPort(id_I1));
235 count_cell(ci);
236 break;
237 case LUT_ONE: // constant 1
238 move_connections(o_net, net_PACKER_VCC);
239 count_cell(ci);
240 break;
241 default:
242 break;
243 }
244 }
245 flush_cells();
246 }
247
248 void GateMatePacker::optimize_mx()
249 {
250 for (auto &cell : ctx->cells) {
251 CellInfo &ci = *cell.second;
252 if (!ci.type.in(id_CC_MX2, id_CC_MX4))
253 continue;
254 if (ci.attrs.count(ctx->id("keep")))
255 continue;
256 NetInfo *y_net = ci.getPort(id_Y);
257 if (!y_net) {
258 count_cell(ci);
259 continue;
260 }
261 if (ci.type == id_CC_MX2) {
262 if (ci.getPort(id_S0) == net_PACKER_GND) {
263 move_connections(y_net, ci.getPort(id_D0));
264 count_cell(ci);
265 continue;
266 } else if (ci.getPort(id_S0) == net_PACKER_VCC) {
267 move_connections(y_net, ci.getPort(id_D1));
268 count_cell(ci);
269 continue;
270 }
271 } else {
272 if ((ci.getPort(id_S1) == net_PACKER_GND) && (ci.getPort(id_S0) == net_PACKER_GND)) {
273 move_connections(y_net, ci.getPort(id_D0));
274 count_cell(ci);
275 continue;
276 } else if ((ci.getPort(id_S1) == net_PACKER_GND) && (ci.getPort(id_S0) == net_PACKER_VCC)) {
277 move_connections(y_net, ci.getPort(id_D1));
278 count_cell(ci);
279 continue;
280 } else if ((ci.getPort(id_S1) == net_PACKER_VCC) && (ci.getPort(id_S0) == net_PACKER_GND)) {
281 move_connections(y_net, ci.getPort(id_D2));
282 count_cell(ci);
283 continue;
284 } else if ((ci.getPort(id_S1) == net_PACKER_VCC) && (ci.getPort(id_S0) == net_PACKER_VCC)) {
285 move_connections(y_net, ci.getPort(id_D3));
286 count_cell(ci);
287 continue;
288 }
289 }
290 }
291 flush_cells();
292 }
293
294 void GateMatePacker::optimize_ff()
295 {
296 for (auto &cell : ctx->cells) {
297 CellInfo &ci = *cell.second;
298 if (!ci.type.in(id_CC_DFF, id_CC_DLT))
299 continue;
300 if (ci.attrs.count(ctx->id("keep")))
301 continue;
302
303 NetInfo *q_net = ci.getPort(id_Q);
304 if (!q_net) {
305 count_cell(ci);
306 continue;
307 }
308
309 int cpe_clk = int_or_default(ci.params, id_C_CPE_CLK, 0);
310 int cpe_en = int_or_default(ci.params, id_C_CPE_EN, 0);
311 int cpe_res = int_or_default(ci.params, id_C_CPE_RES, 0);
312 int cpe_set = int_or_default(ci.params, id_C_CPE_SET, 0);
313 int ff_init = int_or_default(ci.params, id_FF_INIT, 0);
314 bool ff_has_init = (ff_init >> 1) & 1;
315 bool ff_init_value = ff_init & 1;
316
317 if (cpe_res == 0) { // RES is always ON
318 move_connections(q_net, net_PACKER_GND);
319 count_cell(ci);
320 continue;
321 }
322 if (cpe_set == 0) { // SET is always ON
323 move_connections(q_net, net_PACKER_VCC);
324 count_cell(ci);
325 continue;
326 }
327
328 if (ci.type == id_CC_DFF) {
329 if ((cpe_en == 0 || cpe_clk == 0) && ci.getPort(id_SR) == nullptr) {
330 // Only when there is no SR signal
331 // EN always OFF (never loads) or CLK never triggers
332 move_connections(q_net,
333 ff_has_init ? (ff_init_value ? net_PACKER_VCC : net_PACKER_GND) : net_PACKER_GND);
334 count_cell(ci);
335 continue;
336 }
337 } else {
338 if (cpe_clk == 3 && ci.getPort(id_SR) == nullptr && cpe_res == 3 && cpe_set == 3) {
339 // Clamp G if there is no set or reset
340 move_connections(q_net, ci.getPort(id_D));
341 count_cell(ci);
342 continue;
343 }
344 }
345 }
346 flush_cells();
347 }
348
349 void GateMatePacker::cleanup()
350 {
351 log_info("Running cleanups..\n");
352 dff_update_params();
353 int i = 1;
354 do {
355 count = 0;
356 disconnect_not_used();
357 optimize_lut();
358 optimize_mx();
359 optimize_ff();
360 for (auto c : count_per_type)
361 log_info(" %6d %s cells removed (iteration %d)\n", c.second, c.first.c_str(ctx), i);
362 count_per_type.clear();
363 i++;
364 } while (count != 0);
365 }
366
367 void GateMatePacker::rename_param(CellInfo *cell, IdString name, IdString new_name, int width)
368 {
369 if (cell->params.count(name)) {
370 cell->params[new_name] = Property(int_or_default(cell->params, name, 0), width);
371 cell->unsetParam(name);
372 }
373 }
374
375 void GateMatePacker::repack_cpe()
376 {
377 log_info("Repacking CPEs..\n");
378 for (auto &cell : ctx->cells) {
379 if (cell.second->type.in(id_CPE_L2T4)) {
380 Loc l = ctx->getBelLocation(cell.second->bel);
381 if (l.z == CPE_LT_L_Z) {
382 if (!cell.second->params.count(id_INIT_L20))
383 cell.second->params[id_INIT_L20] = Property(LUT_D1, 4);
384 }
385 cell.second->params[id_L2T4_UPPER] = Property((l.z == CPE_LT_U_Z) ? 1 : 0, 1);
386 } else if (cell.second->type.in(id_CPE_LT_L)) {
387 BelId bel = cell.second->bel;
388 PlaceStrength strength = cell.second->belStrength;
389 uint8_t func = int_or_default(cell.second->params, id_C_FUNCTION, 0);
390 Loc loc = ctx->getBelLocation(bel);
391 loc.z = CPE_LT_FULL_Z;
392 ctx->unbindBel(bel);
393 ctx->bindBel(ctx->getBelByLocation(loc), cell.second.get(), strength);
394 cell.second->renamePort(id_D0_00, id_D0_02);
395 cell.second->renamePort(id_D1_00, id_D1_02);
396 cell.second->renamePort(id_D0_01, id_D0_03);
397 cell.second->renamePort(id_D1_01, id_D1_03);
398 cell.second->renamePort(id_D0_10, id_D0_11);
399 cell.second->renamePort(id_D1_10, id_D1_11);
400
401 cell.second->renamePort(id_IN1, id_IN5);
402 cell.second->renamePort(id_IN2, id_IN6);
403 cell.second->renamePort(id_IN3, id_IN7);
404 cell.second->renamePort(id_IN4, id_IN8);
405 cell.second->renamePort(id_OUT, id_OUT1);
406 cell.second->renamePort(id_CPOUT, id_CPOUT1);
407 if (!cell.second->params.count(id_INIT_L20))
408 cell.second->params[id_INIT_L20] = Property(LUT_D1, 4);
409 rename_param(cell.second.get(), id_INIT_L00, id_INIT_L02, 4);
410 rename_param(cell.second.get(), id_INIT_L01, id_INIT_L03, 4);
411 rename_param(cell.second.get(), id_INIT_L10, id_INIT_L11, 4);
412
413 switch (func) {
414 case C_ADDF:
415 cell.second->type = id_CPE_ADDF;
416 break;
417 case C_ADDF2:
418 cell.second->type = id_CPE_ADDF2;
419 break;
420 case C_MULT:
421 cell.second->type = id_CPE_MULT;
422 break;
423 case C_MX4:
424 cell.second->type = id_CPE_MX4;
425 break;
426 case C_EN_CIN:
427 log_error("EN_CIN should be using L2T4.\n");
428 break;
429 case C_CONCAT:
430 cell.second->type = id_CPE_CONCAT;
431 break;
432 case C_ADDCIN:
433 log_error("ADDCIN should be using L2T4.\n");
434 break;
435 default:
436 break;
437 }
438
439 loc.z = CPE_LT_U_Z;
440 CellInfo *upper = ctx->getBoundBelCell(ctx->getBelByLocation(loc));
441 if (upper->params.count(id_INIT_L00))
442 cell.second->params[id_INIT_L00] = Property(int_or_default(upper->params, id_INIT_L00, 0), 4);
443 if (upper->params.count(id_INIT_L01))
444 cell.second->params[id_INIT_L01] = Property(int_or_default(upper->params, id_INIT_L01, 0), 4);
445 if (upper->params.count(id_INIT_L10))
446 cell.second->params[id_INIT_L10] = Property(int_or_default(upper->params, id_INIT_L10, 0), 4);
447 if (upper->params.count(id_C_I1))
448 cell.second->params[id_C_I1] = Property(int_or_default(upper->params, id_C_I1, 0), 1);
449 if (upper->params.count(id_C_I2))
450 cell.second->params[id_C_I2] = Property(int_or_default(upper->params, id_C_I2, 0), 1);
451
452 upper->movePortTo(id_D0_00, cell.second.get(), id_D0_00);
453 upper->movePortTo(id_D1_00, cell.second.get(), id_D1_00);
454 upper->movePortTo(id_D0_01, cell.second.get(), id_D0_01);
455 upper->movePortTo(id_D1_01, cell.second.get(), id_D1_01);
456 upper->movePortTo(id_D0_10, cell.second.get(), id_D0_10);
457 upper->movePortTo(id_D1_10, cell.second.get(), id_D1_10);
458
459 upper->movePortTo(id_IN1, cell.second.get(), id_IN1);
460 upper->movePortTo(id_IN2, cell.second.get(), id_IN2);
461 upper->movePortTo(id_IN3, cell.second.get(), id_IN3);
462 upper->movePortTo(id_IN4, cell.second.get(), id_IN4);
463 upper->movePortTo(id_OUT, cell.second.get(), id_OUT2);
464 upper->movePortTo(id_CPOUT, cell.second.get(), id_CPOUT2);
465
466 }
467 // Mark for deletion
468 else if (cell.second->type.in(id_CPE_LT_U, id_CPE_DUMMY)) {
469 packed_cells.insert(cell.second->name);
470 }
471 }
472 flush_cells();
473 }
474
475 void GateMatePacker::remove_double_constrained()
476 {
477 for (auto &cell : ctx->cells) {
478 CellInfo &ci = *cell.second;
479 if (!ci.attrs.count(ctx->id("BEL")))
480 continue;
481 if (ci.cluster != ClusterId()) {
482 log_warning("Removing BEL attribute for cell '%s'.\n", ci.name.c_str(ctx));
483 ci.unsetAttr(ctx->id("BEL"));
484 }
485 }
486 }
487
488 void GateMatePacker::recursiveAddToRegion(CellInfo *root, IdString die)
489 {
490 if (root->region && root->region->name != die)
491 log_error("Trying to assign cell '%s' to multiple regions.\n", root->name.c_str(ctx));
492 ctx->constrainCellToRegion(root->name, die);
493 for (auto cell : root->constr_children) {
494 if (cell->region && cell->region->name != die)
495 log_error("Trying to assign cell '%s' to multiple regions.\n", cell->name.c_str(ctx));
496 ctx->constrainCellToRegion(cell->name, die);
497 recursiveAddToRegion(cell, die);
498 }
499 }
500
501 void GateMatePacker::assign_clocks()
502 {
503 log_info("Assign cells based on clock..\n");
504 for (auto &glob : uarch->global_signals) {
505 const NetInfo *net = glob.first;
506 for (auto &user : net->users) {
507 IdString die = uarch->index_to_die[uarch->tile_extra_data(net->driver.cell->bel.tile)->die];
508 if (user.cell->region && user.cell->region->name != die)
509 log_error("Trying to assign cell '%s' to multiple regions.\n", user.cell->name.c_str(ctx));
510 ctx->constrainCellToRegion(user.cell->name, die);
511 }
512 }
513 }
514
515 static IdString get_scopename(Context *ctx, CellInfo &ci)
516 {
517 std::string scope = "top";
518 if (ci.attrs.count(ctx->id("scopename"))) {
519 scope = str_or_default(ci.attrs, ctx->id("scopename"), "");
520 scope = "top " + scope;
521 } else if (ci.attrs.count(ctx->id("hdlname"))) {
522 scope = str_or_default(ci.attrs, ctx->id("hdlname"), "");
523 scope = "top " + scope;
524 }
525 return IdString(ctx, scope.c_str());
526 }
527
528 void GateMatePacker::find_regions()
529 {
530 for (auto &cell : ctx->cells) {
531 CellInfo &ci = *cell.second;
532 IdString name = get_scopename(ctx, ci);
533 uarch->scopenames.emplace(name);
534 }
535 if (uarch->scopenames.size() > 1) {
536 log_info("Detected regions..\n");
537 for (auto &scope : uarch->scopenames) {
538 log_info(" %s\n", scope.c_str(ctx));
539 }
540 }
541 }
542
543 void GateMatePacker::assign_regions()
544 {
545 log_info("Assign cell region based on attributes..\n");
546 for (auto &cell : ctx->cells) {
547 CellInfo &ci = *cell.second;
548 IdString name = get_scopename(ctx, ci);
549 if (uarch->scopenames_used.count(name))
550 ctx->constrainCellToRegion(ci.name, name);
551 if (ci.attrs.count(id_GATEMATE_DIE) != 0) {
552 std::string die_name = str_or_default(ci.attrs, id_GATEMATE_DIE, "");
553 IdString die = ctx->id(die_name);
554 if (!uarch->die_to_index.count(die))
555 log_error("Trying to assign cell '%s' to non existing die '%s'.\n", ci.name.c_str(ctx), die.c_str(ctx));
556 if (ci.region && ci.region->name != die)
557 log_error("Trying to assign cell '%s' to multiple regions.\n", ci.name.c_str(ctx));
558 ctx->constrainCellToRegion(ci.name, die);
559 }
560 }
561 }
562
563 void GateMatePacker::fix_regions()
564 {
565 log_info("Fix cell assigned regions..\n");
566 for (auto &cell : ctx->cells) {
567 CellInfo &ci = *cell.second;
568 if (ci.region && ci.cluster != ClusterId()) {
569 CellInfo *root = ctx->getClusterRootCell(ci.cluster);
570 recursiveAddToRegion(root, ci.region->name);
571 }
572 }
573 }
574
575 /*
576 Since A2 and A4 (multi-die) devices are composed of multiple A1 dies, and each die has its own
577 separate set of global clocks, there are several strategies for distributing these clocks:
578
579 mirror — (default)
580 Allows up to four clocks. A mirrored PLL and BUFG are instantiated on each die.
581 This ensures all clocks are available on all dies, but clocks are not phase-synchronized
582 across dies. As a result, designs may experience timing issues at higher frequencies.
583
584 clk1 — (experimental)
585 Most designs use a single global clock. In this mode, the clock is generated on one die,
586 output through an unused dedicated clock pin, and re-entered as an input on the other dies.
587 Since global clock inputs are shared between dies, this enables higher-frequency operation
588 for designs that span multiple dies.
589
590 full — (experimental)
591 Intended for designs that need to utilize all available PLLs across all dies.
592 In this strategy, placement is restricted so that logic using a specific clock
593 resides only in the die where that clock is available. This generally works well,
594 though it can be problematic for RAM blocks that may require access to multiple
595 global clock signals.
596 */
597 void GateMateImpl::pack()
598 {
599 const ArchArgs &args = ctx->args;
600 GateMatePacker packer(ctx, this);
601 packer.find_regions();
602 if (args.options.count("ccf")) {
603 parse_ccf(args.options["ccf"].as<std::string>());
604 }
605
606 if (args.options.count("strategy")) {
607 std::string val = args.options["strategy"].as<std::string>();
608 if (val == "mirror") {
609 strategy = MultiDieStrategy::CLOCK_MIRROR;
610 log_info("Multidie mode: CLOCK MIRROR.\n");
611 } else if (val == "clk1") {
612 strategy = MultiDieStrategy::REUSE_CLK1;
613 log_info("Multidie mode: REUSE CLK1.\n");
614 } else if (val == "full") {
615 strategy = MultiDieStrategy::FULL_USE;
616 log_info("Multidie mode: FULL USE.\n");
617 } else {
618 log_error("Unknown value='%s' for 'strategy' option. Allowed values are 'mirror', 'full' and 'clk1'.\n",
619 val.c_str());
620 }
621 } else {
622 strategy = MultiDieStrategy::CLOCK_MIRROR;
623 if (dies != 1)
624 log_warning("Multi die clock placement strategy set to 'mirror'.\n");
625 }
626
627 if (forced_die != IdString()) {
628 preferred_die = die_to_index[forced_die];
629 if (strategy == MultiDieStrategy::FULL_USE)
630 log_error("Not allowed to use forced die in FULL USE mode.\n");
631 }
632
633 if (strategy == MultiDieStrategy::REUSE_CLK1 || strategy == MultiDieStrategy::FULL_USE)
634 preferred_die = 0;
635
636 if (forced_die == IdString())
637 packer.assign_regions();
638 packer.pack_constants();
639 packer.cleanup();
640 packer.pack_io();
641 packer.insert_clocking();
642 packer.pack_pll();
643 packer.pack_bufg();
644 packer.pack_io_sel(); // merge in FF and DDR
645 packer.pack_misc();
646 packer.pack_ram();
647 packer.pack_serdes();
648 packer.pack_mult();
649 packer.pack_addf();
650 packer.pack_cpe();
651 packer.copy_clocks();
652 packer.remove_constants();
653 packer.remove_double_constrained();
654 if (forced_die != IdString()) {
655 for (auto &cell : ctx->cells) {
656 if (cell.second->belStrength != PlaceStrength::STRENGTH_FIXED)
657 ctx->constrainCellToRegion(cell.second->name, forced_die);
658 }
659 }
660 if (strategy == MultiDieStrategy::FULL_USE)
661 packer.assign_clocks();
662 packer.fix_regions();
663 }
664
665 void GateMateImpl::repack()
666 {
667 GateMatePacker packer(ctx, this);
668 packer.repack_ram();
669 packer.repack_cpe();
670 if (strategy != MultiDieStrategy::FULL_USE)
671 packer.reassign_clocks();
672 packer.remove_clocking();
673 }
674
675 NEXTPNR_NAMESPACE_END