Merge pull request #1105 from YosysHQ/clifford/fixlogicinit
[yosys.git] / passes / techmap / muxcover.cc
1 /*
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
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 "kernel/yosys.h"
21 #include "kernel/sigtools.h"
22
23 USING_YOSYS_NAMESPACE
24 PRIVATE_NAMESPACE_BEGIN
25
26 #define COST_MUX2 100
27 #define COST_MUX4 220
28 #define COST_MUX8 460
29 #define COST_MUX16 940
30
31 struct MuxcoverWorker
32 {
33 Module *module;
34 SigMap sigmap;
35
36 struct newmux_t
37 {
38 int cost;
39 vector<SigBit> inputs, selects;
40 newmux_t() : cost(0) {}
41 };
42
43 struct tree_t
44 {
45 SigBit root;
46 dict<SigBit, Cell*> muxes;
47 dict<SigBit, newmux_t> newmuxes;
48 };
49
50 vector<tree_t> tree_list;
51
52 dict<tuple<SigBit, SigBit, SigBit>, tuple<SigBit, pool<SigBit>, bool>> decode_mux_cache;
53 dict<SigBit, tuple<SigBit, SigBit, SigBit>> decode_mux_reverse_cache;
54 int decode_mux_counter;
55
56 bool use_mux4;
57 bool use_mux8;
58 bool use_mux16;
59 bool nodecode;
60
61 int cost_mux2;
62 int cost_mux4;
63 int cost_mux8;
64 int cost_mux16;
65
66 MuxcoverWorker(Module *module) : module(module), sigmap(module)
67 {
68 use_mux4 = false;
69 use_mux8 = false;
70 use_mux16 = false;
71 nodecode = false;
72 cost_mux2 = COST_MUX2;
73 cost_mux4 = COST_MUX4;
74 cost_mux8 = COST_MUX8;
75 cost_mux16 = COST_MUX16;
76 decode_mux_counter = 0;
77 }
78
79 void treeify()
80 {
81 pool<SigBit> roots;
82 pool<SigBit> used_once;
83 dict<SigBit, Cell*> sig_to_mux;
84
85 for (auto wire : module->wires()) {
86 if (!wire->port_output)
87 continue;
88 for (auto bit : sigmap(wire))
89 roots.insert(bit);
90 }
91
92 for (auto cell : module->cells()) {
93 for (auto conn : cell->connections()) {
94 if (!cell->input(conn.first))
95 continue;
96 for (auto bit : sigmap(conn.second)) {
97 if (used_once.count(bit) || cell->type != "$_MUX_" || conn.first == "\\S")
98 roots.insert(bit);
99 used_once.insert(bit);
100 }
101 }
102 if (cell->type == "$_MUX_")
103 sig_to_mux[sigmap(cell->getPort("\\Y"))] = cell;
104 }
105
106 log(" Treeifying %d MUXes:\n", GetSize(sig_to_mux));
107
108 roots.sort();
109 for (auto rootsig : roots)
110 {
111 tree_t tree;
112 tree.root = rootsig;
113
114 pool<SigBit> wavefront;
115 wavefront.insert(rootsig);
116
117 while (!wavefront.empty()) {
118 SigBit bit = wavefront.pop();
119 if (sig_to_mux.count(bit) && (bit == rootsig || !roots.count(bit))) {
120 Cell *c = sig_to_mux.at(bit);
121 tree.muxes[bit] = c;
122 wavefront.insert(sigmap(c->getPort("\\A")));
123 wavefront.insert(sigmap(c->getPort("\\B")));
124 }
125 }
126
127 if (!tree.muxes.empty()) {
128 log(" Found tree with %d MUXes at root %s.\n", GetSize(tree.muxes), log_signal(tree.root));
129 tree_list.push_back(tree);
130 }
131 }
132
133 log(" Finished treeification: Found %d trees.\n", GetSize(tree_list));
134 }
135
136 bool follow_muxtree(SigBit &ret_bit, tree_t &tree, SigBit bit, const char *path)
137 {
138 if (*path) {
139 if (tree.muxes.count(bit) == 0)
140 return false;
141 char port_name[3] = {'\\', *path, 0};
142 return follow_muxtree(ret_bit, tree, sigmap(tree.muxes.at(bit)->getPort(port_name)), path+1);
143 } else {
144 ret_bit = bit;
145 return true;
146 }
147 }
148
149 int prepare_decode_mux(SigBit &A, SigBit B, SigBit sel, SigBit bit)
150 {
151 if (A == B)
152 return 0;
153
154 tuple<SigBit, SigBit, SigBit> key(A, B, sel);
155 if (decode_mux_cache.count(key) == 0) {
156 auto &entry = decode_mux_cache[key];
157 std::get<0>(entry) = module->addWire(NEW_ID);
158 std::get<2>(entry) = false;
159 decode_mux_reverse_cache[std::get<0>(entry)] = key;
160 }
161
162 auto &entry = decode_mux_cache[key];
163 A = std::get<0>(entry);
164 std::get<1>(entry).insert(bit);
165
166 if (std::get<2>(entry))
167 return 0;
168
169 return cost_mux2 / GetSize(std::get<1>(entry));
170 }
171
172 void implement_decode_mux(SigBit ctrl_bit)
173 {
174 if (decode_mux_reverse_cache.count(ctrl_bit) == 0)
175 return;
176
177 auto &key = decode_mux_reverse_cache.at(ctrl_bit);
178 auto &entry = decode_mux_cache[key];
179
180 if (std::get<2>(entry))
181 return;
182
183 implement_decode_mux(std::get<0>(key));
184 implement_decode_mux(std::get<1>(key));
185
186 module->addMuxGate(NEW_ID, std::get<0>(key), std::get<1>(key), std::get<2>(key), ctrl_bit);
187 std::get<2>(entry) = true;
188 decode_mux_counter++;
189 }
190
191 int find_best_cover(tree_t &tree, SigBit bit)
192 {
193 if (tree.newmuxes.count(bit)) {
194 return tree.newmuxes.at(bit).cost;
195 }
196
197 SigBit A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P;
198 SigBit S1, S2, S3, S4, S5, S6, S7, S8;
199 SigBit T1, T2, T3, T4;
200 SigBit U1, U2;
201 SigBit V1;
202
203 newmux_t best_mux;
204 bool ok = true;
205
206 // 2-Input MUX
207
208 ok = ok && follow_muxtree(A, tree, bit, "A");
209 ok = ok && follow_muxtree(B, tree, bit, "B");
210
211 ok = ok && follow_muxtree(S1, tree, bit, "S");
212
213 if (ok)
214 {
215 newmux_t mux;
216
217 mux.inputs.push_back(A);
218 mux.inputs.push_back(B);
219 mux.selects.push_back(S1);
220
221 mux.cost += cost_mux2;
222 mux.cost += find_best_cover(tree, A);
223 mux.cost += find_best_cover(tree, B);
224
225 best_mux = mux;
226 }
227
228 // 4-Input MUX
229
230 if (use_mux4)
231 {
232 ok = ok && follow_muxtree(A, tree, bit, "AA");
233 ok = ok && follow_muxtree(B, tree, bit, "AB");
234 ok = ok && follow_muxtree(C, tree, bit, "BA");
235 ok = ok && follow_muxtree(D, tree, bit, "BB");
236
237 ok = ok && follow_muxtree(S1, tree, bit, "AS");
238 ok = ok && follow_muxtree(S2, tree, bit, "BS");
239
240 if (nodecode)
241 ok = ok && S1 == S2;
242
243 ok = ok && follow_muxtree(T1, tree, bit, "S");
244
245 if (ok)
246 {
247 newmux_t mux;
248
249 mux.inputs.push_back(A);
250 mux.inputs.push_back(B);
251 mux.inputs.push_back(C);
252 mux.inputs.push_back(D);
253
254 mux.cost += prepare_decode_mux(S1, S2, T1, bit);
255
256 mux.selects.push_back(S1);
257 mux.selects.push_back(T1);
258
259 mux.cost += cost_mux4;
260 mux.cost += find_best_cover(tree, A);
261 mux.cost += find_best_cover(tree, B);
262 mux.cost += find_best_cover(tree, C);
263 mux.cost += find_best_cover(tree, D);
264
265 if (best_mux.cost > mux.cost)
266 best_mux = mux;
267 }
268 }
269
270 // 8-Input MUX
271
272 if (use_mux8)
273 {
274 ok = ok && follow_muxtree(A, tree, bit, "AAA");
275 ok = ok && follow_muxtree(B, tree, bit, "AAB");
276 ok = ok && follow_muxtree(C, tree, bit, "ABA");
277 ok = ok && follow_muxtree(D, tree, bit, "ABB");
278 ok = ok && follow_muxtree(E, tree, bit, "BAA");
279 ok = ok && follow_muxtree(F, tree, bit, "BAB");
280 ok = ok && follow_muxtree(G, tree, bit, "BBA");
281 ok = ok && follow_muxtree(H, tree, bit, "BBB");
282
283 ok = ok && follow_muxtree(S1, tree, bit, "AAS");
284 ok = ok && follow_muxtree(S2, tree, bit, "ABS");
285 ok = ok && follow_muxtree(S3, tree, bit, "BAS");
286 ok = ok && follow_muxtree(S4, tree, bit, "BBS");
287
288 if (nodecode)
289 ok = ok && S1 == S2 && S2 == S3 && S3 == S4;
290
291 ok = ok && follow_muxtree(T1, tree, bit, "AS");
292 ok = ok && follow_muxtree(T2, tree, bit, "BS");
293
294 if (nodecode)
295 ok = ok && T1 == T2;
296
297 ok = ok && follow_muxtree(U1, tree, bit, "S");
298
299 if (ok)
300 {
301 newmux_t mux;
302
303 mux.inputs.push_back(A);
304 mux.inputs.push_back(B);
305 mux.inputs.push_back(C);
306 mux.inputs.push_back(D);
307 mux.inputs.push_back(E);
308 mux.inputs.push_back(F);
309 mux.inputs.push_back(G);
310 mux.inputs.push_back(H);
311
312 mux.cost += prepare_decode_mux(S1, S2, T1, bit);
313 mux.cost += prepare_decode_mux(S3, S4, T2, bit);
314 mux.cost += prepare_decode_mux(S1, S3, U1, bit);
315
316 mux.cost += prepare_decode_mux(T1, T2, U1, bit);
317
318 mux.selects.push_back(S1);
319 mux.selects.push_back(T1);
320 mux.selects.push_back(U1);
321
322 mux.cost += cost_mux8;
323 mux.cost += find_best_cover(tree, A);
324 mux.cost += find_best_cover(tree, B);
325 mux.cost += find_best_cover(tree, C);
326 mux.cost += find_best_cover(tree, D);
327 mux.cost += find_best_cover(tree, E);
328 mux.cost += find_best_cover(tree, F);
329 mux.cost += find_best_cover(tree, G);
330 mux.cost += find_best_cover(tree, H);
331
332 if (best_mux.cost > mux.cost)
333 best_mux = mux;
334 }
335 }
336
337 // 16-Input MUX
338
339 if (use_mux16)
340 {
341 ok = ok && follow_muxtree(A, tree, bit, "AAAA");
342 ok = ok && follow_muxtree(B, tree, bit, "AAAB");
343 ok = ok && follow_muxtree(C, tree, bit, "AABA");
344 ok = ok && follow_muxtree(D, tree, bit, "AABB");
345 ok = ok && follow_muxtree(E, tree, bit, "ABAA");
346 ok = ok && follow_muxtree(F, tree, bit, "ABAB");
347 ok = ok && follow_muxtree(G, tree, bit, "ABBA");
348 ok = ok && follow_muxtree(H, tree, bit, "ABBB");
349 ok = ok && follow_muxtree(I, tree, bit, "BAAA");
350 ok = ok && follow_muxtree(J, tree, bit, "BAAB");
351 ok = ok && follow_muxtree(K, tree, bit, "BABA");
352 ok = ok && follow_muxtree(L, tree, bit, "BABB");
353 ok = ok && follow_muxtree(M, tree, bit, "BBAA");
354 ok = ok && follow_muxtree(N, tree, bit, "BBAB");
355 ok = ok && follow_muxtree(O, tree, bit, "BBBA");
356 ok = ok && follow_muxtree(P, tree, bit, "BBBB");
357
358 ok = ok && follow_muxtree(S1, tree, bit, "AAAS");
359 ok = ok && follow_muxtree(S2, tree, bit, "AABS");
360 ok = ok && follow_muxtree(S3, tree, bit, "ABAS");
361 ok = ok && follow_muxtree(S4, tree, bit, "ABBS");
362 ok = ok && follow_muxtree(S5, tree, bit, "BAAS");
363 ok = ok && follow_muxtree(S6, tree, bit, "BABS");
364 ok = ok && follow_muxtree(S7, tree, bit, "BBAS");
365 ok = ok && follow_muxtree(S8, tree, bit, "BBBS");
366
367 if (nodecode)
368 ok = ok && S1 == S2 && S2 == S3 && S3 == S4 && S4 == S5 && S5 == S6 && S6 == S7 && S7 == S8;
369
370 ok = ok && follow_muxtree(T1, tree, bit, "AAS");
371 ok = ok && follow_muxtree(T2, tree, bit, "ABS");
372 ok = ok && follow_muxtree(T3, tree, bit, "BAS");
373 ok = ok && follow_muxtree(T4, tree, bit, "BBS");
374
375 if (nodecode)
376 ok = ok && T1 == T2 && T2 == T3 && T3 == T4;
377
378 ok = ok && follow_muxtree(U1, tree, bit, "AS");
379 ok = ok && follow_muxtree(U2, tree, bit, "BS");
380
381 if (nodecode)
382 ok = ok && U1 == U2;
383
384 ok = ok && follow_muxtree(V1, tree, bit, "S");
385
386 if (ok)
387 {
388 newmux_t mux;
389
390 mux.inputs.push_back(A);
391 mux.inputs.push_back(B);
392 mux.inputs.push_back(C);
393 mux.inputs.push_back(D);
394 mux.inputs.push_back(E);
395 mux.inputs.push_back(F);
396 mux.inputs.push_back(G);
397 mux.inputs.push_back(H);
398 mux.inputs.push_back(I);
399 mux.inputs.push_back(J);
400 mux.inputs.push_back(K);
401 mux.inputs.push_back(L);
402 mux.inputs.push_back(M);
403 mux.inputs.push_back(N);
404 mux.inputs.push_back(O);
405 mux.inputs.push_back(P);
406
407 mux.cost += prepare_decode_mux(S1, S2, T1, bit);
408 mux.cost += prepare_decode_mux(S3, S4, T2, bit);
409 mux.cost += prepare_decode_mux(S5, S6, T3, bit);
410 mux.cost += prepare_decode_mux(S7, S8, T4, bit);
411 mux.cost += prepare_decode_mux(S1, S3, U1, bit);
412 mux.cost += prepare_decode_mux(S5, S7, U2, bit);
413 mux.cost += prepare_decode_mux(S1, S5, V1, bit);
414
415 mux.cost += prepare_decode_mux(T1, T2, U1, bit);
416 mux.cost += prepare_decode_mux(T3, T4, U2, bit);
417 mux.cost += prepare_decode_mux(T1, T3, V1, bit);
418
419 mux.cost += prepare_decode_mux(U1, U2, V1, bit);
420
421 mux.selects.push_back(S1);
422 mux.selects.push_back(T1);
423 mux.selects.push_back(U1);
424 mux.selects.push_back(V1);
425
426 mux.cost += cost_mux16;
427 mux.cost += find_best_cover(tree, A);
428 mux.cost += find_best_cover(tree, B);
429 mux.cost += find_best_cover(tree, C);
430 mux.cost += find_best_cover(tree, D);
431 mux.cost += find_best_cover(tree, E);
432 mux.cost += find_best_cover(tree, F);
433 mux.cost += find_best_cover(tree, G);
434 mux.cost += find_best_cover(tree, H);
435 mux.cost += find_best_cover(tree, I);
436 mux.cost += find_best_cover(tree, J);
437 mux.cost += find_best_cover(tree, K);
438 mux.cost += find_best_cover(tree, L);
439 mux.cost += find_best_cover(tree, M);
440 mux.cost += find_best_cover(tree, N);
441 mux.cost += find_best_cover(tree, O);
442 mux.cost += find_best_cover(tree, P);
443
444 if (best_mux.cost > mux.cost)
445 best_mux = mux;
446 }
447 }
448
449 tree.newmuxes[bit] = best_mux;
450 return best_mux.cost;
451 }
452
453 void implement_best_cover(tree_t &tree, SigBit bit, int count_muxes_by_type[4])
454 {
455 newmux_t mux = tree.newmuxes.at(bit);
456
457 for (auto inbit : mux.inputs)
458 implement_best_cover(tree, inbit, count_muxes_by_type);
459
460 for (auto selbit : mux.selects)
461 implement_decode_mux(selbit);
462
463 if (GetSize(mux.inputs) == 0)
464 return;
465
466 if (GetSize(mux.inputs) == 2) {
467 count_muxes_by_type[0]++;
468 Cell *cell = module->addCell(NEW_ID, "$_MUX_");
469 cell->setPort("\\A", mux.inputs[0]);
470 cell->setPort("\\B", mux.inputs[1]);
471 cell->setPort("\\S", mux.selects[0]);
472 cell->setPort("\\Y", bit);
473 return;
474 }
475
476 if (GetSize(mux.inputs) == 4) {
477 count_muxes_by_type[1]++;
478 Cell *cell = module->addCell(NEW_ID, "$_MUX4_");
479 cell->setPort("\\A", mux.inputs[0]);
480 cell->setPort("\\B", mux.inputs[1]);
481 cell->setPort("\\C", mux.inputs[2]);
482 cell->setPort("\\D", mux.inputs[3]);
483 cell->setPort("\\S", mux.selects[0]);
484 cell->setPort("\\T", mux.selects[1]);
485 cell->setPort("\\Y", bit);
486 return;
487 }
488
489 if (GetSize(mux.inputs) == 8) {
490 count_muxes_by_type[2]++;
491 Cell *cell = module->addCell(NEW_ID, "$_MUX8_");
492 cell->setPort("\\A", mux.inputs[0]);
493 cell->setPort("\\B", mux.inputs[1]);
494 cell->setPort("\\C", mux.inputs[2]);
495 cell->setPort("\\D", mux.inputs[3]);
496 cell->setPort("\\E", mux.inputs[4]);
497 cell->setPort("\\F", mux.inputs[5]);
498 cell->setPort("\\G", mux.inputs[6]);
499 cell->setPort("\\H", mux.inputs[7]);
500 cell->setPort("\\S", mux.selects[0]);
501 cell->setPort("\\T", mux.selects[1]);
502 cell->setPort("\\U", mux.selects[2]);
503 cell->setPort("\\Y", bit);
504 return;
505 }
506
507 if (GetSize(mux.inputs) == 16) {
508 count_muxes_by_type[3]++;
509 Cell *cell = module->addCell(NEW_ID, "$_MUX16_");
510 cell->setPort("\\A", mux.inputs[0]);
511 cell->setPort("\\B", mux.inputs[1]);
512 cell->setPort("\\C", mux.inputs[2]);
513 cell->setPort("\\D", mux.inputs[3]);
514 cell->setPort("\\E", mux.inputs[4]);
515 cell->setPort("\\F", mux.inputs[5]);
516 cell->setPort("\\G", mux.inputs[6]);
517 cell->setPort("\\H", mux.inputs[7]);
518 cell->setPort("\\I", mux.inputs[8]);
519 cell->setPort("\\J", mux.inputs[9]);
520 cell->setPort("\\K", mux.inputs[10]);
521 cell->setPort("\\L", mux.inputs[11]);
522 cell->setPort("\\M", mux.inputs[12]);
523 cell->setPort("\\N", mux.inputs[13]);
524 cell->setPort("\\O", mux.inputs[14]);
525 cell->setPort("\\P", mux.inputs[15]);
526 cell->setPort("\\S", mux.selects[0]);
527 cell->setPort("\\T", mux.selects[1]);
528 cell->setPort("\\U", mux.selects[2]);
529 cell->setPort("\\V", mux.selects[3]);
530 cell->setPort("\\Y", bit);
531 return;
532 }
533
534 log_abort();
535 }
536
537 void treecover(tree_t &tree)
538 {
539 int count_muxes_by_type[4] = {0, 0, 0, 0};
540 find_best_cover(tree, tree.root);
541 implement_best_cover(tree, tree.root, count_muxes_by_type);
542 log(" Replaced tree at %s: %d MUX2, %d MUX4, %d MUX8, %d MUX16\n", log_signal(tree.root),
543 count_muxes_by_type[0], count_muxes_by_type[1], count_muxes_by_type[2], count_muxes_by_type[3]);
544 for (auto &it : tree.muxes)
545 module->remove(it.second);
546 }
547
548 void run()
549 {
550 log("Covering MUX trees in module %s..\n", log_id(module));
551
552 treeify();
553
554 log(" Covering trees:\n");
555
556 // pre-fill cache of decoder muxes
557 if (!nodecode)
558 for (auto &tree : tree_list) {
559 find_best_cover(tree, tree.root);
560 tree.newmuxes.clear();
561 }
562
563 for (auto &tree : tree_list)
564 treecover(tree);
565
566 if (!nodecode)
567 log(" Added a total of %d decoder MUXes.\n", decode_mux_counter);
568 }
569 };
570
571 struct MuxcoverPass : public Pass {
572 MuxcoverPass() : Pass("muxcover", "cover trees of MUX cells with wider MUXes") { }
573 void help() YS_OVERRIDE
574 {
575 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
576 log("\n");
577 log(" muxcover [options] [selection]\n");
578 log("\n");
579 log("Cover trees of $_MUX_ cells with $_MUX{4,8,16}_ cells\n");
580 log("\n");
581 log(" -mux4[=cost], -mux8[=cost], -mux16[=cost]\n");
582 log(" Use the specified types of MUXes (with optional integer costs). If none\n");
583 log(" of these options are given, the effect is the same as if all of them are.\n");
584 log(" Default costs: $_MUX_ = %d, $_MUX4_ = %d,\n", COST_MUX2, COST_MUX4);
585 log(" $_MUX8_ = %d, $_MUX16_ = %d\n", COST_MUX8, COST_MUX16);
586 log("\n");
587 log(" -nodecode\n");
588 log(" Do not insert decoder logic. This reduces the number of possible\n");
589 log(" substitutions, but guarantees that the resulting circuit is not\n");
590 log(" less efficient than the original circuit.\n");
591 log("\n");
592 }
593 void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
594 {
595 log_header(design, "Executing MUXCOVER pass (mapping to wider MUXes).\n");
596
597 bool use_mux4 = false;
598 bool use_mux8 = false;
599 bool use_mux16 = false;
600 bool nodecode = false;
601 int cost_mux4 = COST_MUX4;
602 int cost_mux8 = COST_MUX8;
603 int cost_mux16 = COST_MUX16;
604
605 size_t argidx;
606 for (argidx = 1; argidx < args.size(); argidx++)
607 {
608 const auto &arg = args[argidx];
609 if (arg.size() >= 5 && arg.substr(0,5) == "-mux4") {
610 use_mux4 = true;
611 if (arg.size() > 5) {
612 if (arg[5] != '=') break;
613 cost_mux4 = atoi(arg.substr(5).c_str());
614 }
615 continue;
616 }
617 if (arg.size() >= 5 && arg.substr(0,5) == "-mux8") {
618 use_mux8 = true;
619 if (arg.size() > 5) {
620 if (arg[5] != '=') break;
621 cost_mux8 = atoi(arg.substr(5).c_str());
622 }
623 continue;
624 }
625 if (arg.size() >= 6 && arg.substr(0,6) == "-mux16") {
626 use_mux16 = true;
627 if (arg.size() > 6) {
628 if (arg[6] != '=') break;
629 cost_mux16 = atoi(arg.substr(6).c_str());
630 }
631 continue;
632 }
633 if (arg == "-nodecode") {
634 nodecode = true;
635 continue;
636 }
637 break;
638 }
639 extra_args(args, argidx, design);
640
641 if (!use_mux4 && !use_mux8 && !use_mux16) {
642 use_mux4 = true;
643 use_mux8 = true;
644 use_mux16 = true;
645 }
646
647 for (auto module : design->selected_modules())
648 {
649 MuxcoverWorker worker(module);
650 worker.use_mux4 = use_mux4;
651 worker.use_mux8 = use_mux8;
652 worker.use_mux16 = use_mux16;
653 worker.cost_mux4 = cost_mux4;
654 worker.cost_mux8 = cost_mux8;
655 worker.cost_mux16 = cost_mux16;
656 worker.nodecode = nodecode;
657 worker.run();
658 }
659 }
660 } MuxcoverPass;
661
662 PRIVATE_NAMESPACE_END