169 std::vector<RTLIL::SigBit> sig_a =
assign_map(cell->
getPort(
"\\A")).to_sigbit_vector();
170 std::vector<RTLIL::SigBit> sig_b =
assign_map(cell->
getPort(
"\\B")).to_sigbit_vector();
171 std::vector<RTLIL::SigBit> sig_y =
assign_map(cell->
getPort(
"\\Y")).to_sigbit_vector();
173 std::vector<RTLIL::SigBit> new_sig_y;
176 std::vector<std::vector<RTLIL::SigBit>> consolidated_in_tuples;
177 std::map<std::vector<RTLIL::SigBit>,
RTLIL::SigBit> consolidated_in_tuples_map;
179 for (
int i = 0; i < int(sig_y.size()); i++)
181 std::vector<RTLIL::SigBit> in_tuple;
182 bool all_tuple_bits_same =
true;
184 in_tuple.push_back(sig_a.at(i));
185 for (
int j = i; j < int(sig_b.size()); j += int(sig_a.size())) {
186 if (sig_b.at(j) != sig_a.at(i))
187 all_tuple_bits_same =
false;
188 in_tuple.push_back(sig_b.at(j));
191 if (all_tuple_bits_same)
193 old_sig_conn.first.append_bit(sig_y.at(i));
194 old_sig_conn.second.append_bit(sig_a.at(i));
196 else if (consolidated_in_tuples_map.count(in_tuple))
198 old_sig_conn.first.append_bit(sig_y.at(i));
199 old_sig_conn.second.append_bit(consolidated_in_tuples_map.at(in_tuple));
203 consolidated_in_tuples_map[in_tuple] = sig_y.at(i);
204 consolidated_in_tuples.push_back(in_tuple);
205 new_sig_y.push_back(sig_y.at(i));
209 if (new_sig_y.size() != sig_y.size())
216 for (
auto &in_tuple : consolidated_in_tuples) {
218 new_a.
append(in_tuple.at(0));
223 for (
int i = 1; i <= cell->
getPort(
"\\S").
size(); i++)
224 for (
auto &in_tuple : consolidated_in_tuples) {
226 new_b.
append(in_tuple.at(i));
231 cell->
setPort(
"\\Y", new_sig_y);
const char * c_str() const
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
std::map< RTLIL::IdString, RTLIL::Const > parameters
void connect(const RTLIL::SigSig &conn)
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
void log(const char *format,...)
void append(const RTLIL::SigSpec &signal)
std::pair< SigSpec, SigSpec > SigSig