39 std::vector<port_t> new_ports;
43 for (
auto &port :
ports)
49 std::swap(port.in_a, port.in_b);
51 if (
GetSize(port.in_a) == 1 &&
GetSize(port.in_b) == 0 && !port.is_signed && !port.do_subtract) {
56 if (port.in_a.is_fully_const() && port.in_b.is_fully_const()) {
59 v =
const_mul(v, port.in_b.as_const(), port.is_signed, port.is_signed, width);
61 off =
const_sub(off, v, port.is_signed, port.is_signed, width);
63 off =
const_add(off, v, port.is_signed, port.is_signed, width);
69 port.in_a.remove(
GetSize(port.in_a)-1);
71 port.in_b.remove(
GetSize(port.in_b)-1);
74 port.in_a.remove(
GetSize(port.in_a)-1);
76 port.in_b.remove(
GetSize(port.in_b)-1);
79 new_ports.push_back(port);
93 new_ports.push_back(port);
96 new_ports.swap(ports);
97 bit_ports = new_bit_ports;
107 std::vector<RTLIL::State> config_bits = cell->
getParam(
"\\CONFIG").
bits;
109 int config_cursor = 0;
114 if (config_bits[config_cursor++] ==
RTLIL::S1) num_bits |= 1;
115 if (config_bits[config_cursor++] ==
RTLIL::S1) num_bits |= 2;
116 if (config_bits[config_cursor++] ==
RTLIL::S1) num_bits |= 4;
117 if (config_bits[config_cursor++] ==
RTLIL::S1) num_bits |= 8;
119 int port_a_cursor = 0;
120 while (port_a_cursor <
GetSize(port_a))
122 log_assert(config_cursor + 2 + 2*num_bits <= config_width);
129 for (
int i = 0; i < num_bits; i++)
130 if (config_bits[config_cursor++] ==
RTLIL::S1)
133 this_port.
in_a = port_a.
extract(port_a_cursor, size_a);
134 port_a_cursor += size_a;
137 for (
int i = 0; i < num_bits; i++)
138 if (config_bits[config_cursor++] ==
RTLIL::S1)
141 this_port.
in_b = port_a.
extract(port_a_cursor, size_b);
142 port_a_cursor += size_b;
144 if (size_a || size_b)
145 ports.push_back(this_port);
155 std::vector<RTLIL::State> config_bits;
156 int max_size = 0, num_bits = 0;
158 for (
auto &port :
ports) {
159 max_size = std::max(max_size,
GetSize(port.in_a));
160 max_size = std::max(max_size,
GetSize(port.in_b));
164 num_bits++, max_size /= 2;
168 config_bits.push_back(num_bits & 2 ?
RTLIL::S1 : RTLIL::S0);
169 config_bits.push_back(num_bits & 4 ?
RTLIL::S1 : RTLIL::S0);
170 config_bits.push_back(num_bits & 8 ?
RTLIL::S1 : RTLIL::S0);
172 for (
auto &port : ports)
177 config_bits.push_back(port.is_signed ?
RTLIL::S1 : RTLIL::S0);
178 config_bits.push_back(port.do_subtract ?
RTLIL::S1 : RTLIL::S0);
180 int size_a =
GetSize(port.in_a);
181 for (
int i = 0; i < num_bits; i++)
182 config_bits.push_back(size_a & (1 << i) ?
RTLIL::S1 : RTLIL::S0);
184 int size_b =
GetSize(port.in_b);
185 for (
int i = 0; i < num_bits; i++)
186 config_bits.push_back(size_b & (1 << i) ?
RTLIL::S1 : RTLIL::S0);
194 cell->
setParam(
"\\CONFIG", config_bits);
202 for (
auto &bit : result.
bits)
205 for (
auto &port :
ports)
207 if (!port.in_a.is_fully_const() || !port.in_b.is_fully_const())
212 summand =
const_pos(port.in_a.as_const(), port.in_b.as_const(), port.is_signed, port.is_signed,
GetSize(result));
214 summand =
const_mul(port.in_a.as_const(), port.in_b.as_const(), port.is_signed, port.is_signed,
GetSize(result));
216 if (port.do_subtract)
217 result =
const_sub(result, summand, port.is_signed, port.is_signed,
GetSize(result));
219 result =
const_add(result, summand, port.is_signed, port.is_signed,
GetSize(result));
void to_cell(RTLIL::Cell *cell) const
void setParam(RTLIL::IdString paramname, RTLIL::Const value)
#define YOSYS_NAMESPACE_END
bool eval(RTLIL::Const &result) const
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
RTLIL::Const const_sub(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
std::vector< port_t > ports
RTLIL::Const const_mul(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
int GetSize(RTLIL::Wire *wire)
#define log_assert(_assert_expr_)
void from_cell(RTLIL::Cell *cell)
int as_int(bool is_signed=false) const
#define YOSYS_NAMESPACE_BEGIN
const RTLIL::Const & getParam(RTLIL::IdString paramname) const
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
std::vector< RTLIL::State > bits
void append(const RTLIL::SigSpec &signal)
RTLIL::Const const_add(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
Macc(RTLIL::Cell *cell=nullptr)
RTLIL::Const const_pos(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)