43 void execute(std::vector<std::string> args, RTLIL::Design* design)
override
45 log_header(design,
"Executing SILICON_BMUX_CASE pass.\n");
46 extra_args(args, 1, design);
48 for (
auto* module : design->selected_modules()) {
49 std::vector<RTLIL::Cell*> muxes;
50 for (
auto* cell : module->selected_cells())
51 if (cell->type == ID($bmux))
52 muxes.push_back(cell);
54 for (
auto* cell : muxes) {
55 const RTLIL::SigSpec data = cell->getPort(ID::A);
56 const RTLIL::SigSpec selection = cell->getPort(ID::S);
57 const RTLIL::SigSpec output = cell->getPort(ID::Y);
58 const int width = cell->getParam(ID::WIDTH).as_int();
60 if (width <= 0 || output.size() != width || selection.empty()
61 || data.size() % width != 0) {
62 log_error(
"Malformed $bmux cell %s.%s.\n", log_id(module), log_id(cell));
65 const int lane_count = data.size() / width;
66 if (selection.size() >= 31 || lane_count != (1 << selection.size())) {
67 log_error(
"Inconsistent selector or data width on $bmux cell %s.%s.\n",
68 log_id(module), log_id(cell));
71 auto* process =
module->addProcess(module->uniquify("$silicon$bmux_case"));
72 process->attributes = cell->attributes;
74 auto* switch_rule =
new RTLIL::SwitchRule;
75 switch_rule->signal = selection;
76 process->root_case.switches.push_back(switch_rule);
78 for (
int lane = 0; lane < lane_count; ++lane) {
79 auto* case_rule =
new RTLIL::CaseRule;
80 case_rule->compare.emplace_back(lane, selection.size());
81 case_rule->actions.emplace_back(output, data.extract(lane * width, width));
82 switch_rule->cases.push_back(case_rule);
85 auto* default_rule =
new RTLIL::CaseRule;
86 default_rule->actions.emplace_back(output, RTLIL::Const(RTLIL::State::Sx, width));
87 switch_rule->cases.push_back(default_rule);
89 log(
"Raised $bmux cell %s.%s to process %s.\n", log_id(module), log_id(cell),