281 for (
auto &port : macc.ports)
283 log(
" %s %s (%d bits, %s)\n", port.do_subtract ?
"sub" :
"add",
log_signal(port.in_a),
284 GetSize(port.in_a), port.is_signed ?
"signed" :
"unsigned");
286 log(
" %s %s * %s (%dx%d bits, %s)\n", port.do_subtract ?
"sub" :
"add",
log_signal(port.in_a),
log_signal(port.in_b),
287 GetSize(port.in_a),
GetSize(port.in_b), port.is_signed ?
"signed" :
"unsigned");
289 if (
GetSize(macc.bit_ports) != 0)
294 typedef std::pair<RTLIL::SigSpec, bool> summand_t;
295 std::vector<summand_t> summands;
297 for (
auto &port : macc.ports) {
298 summand_t this_summand;
301 module->
addMul(
NEW_ID, port.in_a, port.in_b, this_summand.first, port.is_signed);
302 }
else if (
GetSize(port.in_a) != width) {
304 module->
addPos(
NEW_ID, port.in_a, this_summand.first, port.is_signed);
306 this_summand.first = port.in_a;
308 this_summand.second = port.do_subtract;
309 summands.push_back(this_summand);
312 for (
auto &bit : macc.bit_ports)
313 summands.push_back(summand_t(bit,
false));
320 std::vector<summand_t> new_summands;
321 for (
int i = 0; i <
GetSize(summands); i += 2) {
323 summand_t this_summand;
325 this_summand.second = summands[i].second && summands[i+1].second;
326 if (summands[i].second == summands[i+1].second)
327 module->
addAdd(
NEW_ID, summands[i].first, summands[i+1].first, this_summand.first);
328 else if (summands[i].second)
329 module->
addSub(
NEW_ID, summands[i+1].first, summands[i].first, this_summand.first);
330 else if (summands[i+1].second)
331 module->
addSub(
NEW_ID, summands[i].first, summands[i+1].first, this_summand.first);
334 new_summands.push_back(this_summand);
336 new_summands.push_back(summands[i]);
338 summands.swap(new_summands);
341 if (summands.front().second)
350 for (
auto &port : macc.ports)
352 worker.add(port.in_a, port.is_signed, port.do_subtract);
354 worker.add(port.in_a, port.in_b, port.is_signed, port.do_subtract);
356 for (
auto &bit : macc.bit_ports)
std::set< RTLIL::SigBit > to_sigbit_set() const
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
RTLIL::Cell * addAdd(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed=false)
RTLIL::Cell * addNeg(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed=false)
void connect(const RTLIL::SigSig &conn)
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
int GetSize(RTLIL::Wire *wire)
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
RTLIL::Cell * addMul(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed=false)
void from_cell(RTLIL::Cell *cell)
RTLIL::Cell * addSub(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed=false)
void log(const char *format,...)
void append(const RTLIL::SigSpec &signal)
RTLIL::Cell * addPos(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed=false)