37 std::set<RTLIL::Cell*>
busy;
46 for (
auto &it : module->
cells_) {
49 for (
auto &it2 : it.second->connections())
77 for (
int i = 0; i <
GetSize(current_val); i++)
91 if (cell->
type ==
"$lcu")
101 if (!
eval(sig_p, undef, cell))
104 if (!
eval(sig_g, undef, cell))
107 if (!
eval(sig_ci, undef, cell))
115 for (
int i = 0; i <
GetSize(coval); i++) {
132 if (sig_y.is_fully_const())
137 if (!
eval(sig_s, undef, cell))
147 if (cell->
type ==
"$mux" || cell->
type ==
"$pmux" || cell->
type ==
"$_MUX_")
149 std::vector<RTLIL::SigSpec> y_candidates;
150 int count_maybe_set_s_bits = 0;
151 int count_set_s_bits = 0;
153 for (
int i = 0; i < sig_s.
size(); i++)
159 y_candidates.push_back(b_slice);
162 count_maybe_set_s_bits++;
168 if (count_set_s_bits == 0)
169 y_candidates.push_back(sig_a);
171 std::vector<RTLIL::Const> y_values;
174 for (
auto &yc : y_candidates) {
175 if (!
eval(yc, undef, cell))
177 y_values.push_back(yc.as_const());
180 if (y_values.size() > 1)
182 std::vector<RTLIL::State> master_bits = y_values.at(0).bits;
184 for (
size_t i = 1; i < y_values.size(); i++) {
185 std::vector<RTLIL::State> &slave_bits = y_values.at(i).bits;
186 log_assert(master_bits.size() == slave_bits.size());
187 for (
size_t j = 0; j < master_bits.size(); j++)
188 if (master_bits[j] != slave_bits[j])
195 set(sig_y, y_values.front());
197 else if (cell->
type ==
"$fa")
203 if (!
eval(sig_a, undef, cell))
206 if (!
eval(sig_b, undef, cell))
209 if (!
eval(sig_c, undef, cell))
219 for (
int i = 0; i <
GetSize(val_y); i++)
226 else if (cell->
type ==
"$alu")
228 bool signed_a = cell->
parameters.count(
"\\A_SIGNED") > 0 && cell->
parameters[
"\\A_SIGNED"].as_bool();
229 bool signed_b = cell->
parameters.count(
"\\B_SIGNED") > 0 && cell->
parameters[
"\\B_SIGNED"].as_bool();
234 if (!
eval(sig_a, undef, cell))
237 if (!
eval(sig_b, undef, cell))
240 if (!
eval(sig_ci, undef, cell))
243 if (!
eval(sig_bi, undef, cell))
256 for (
int i = 0; i <
GetSize(sig_y); i++)
264 bool bit_b = (sig_b[i] ==
RTLIL::S1) != b_inv;
265 bool bit_x = bit_a != bit_b;
269 if (any_input_undef) {
274 bool bit_b = (sig_b[i] ==
RTLIL::S1) != b_inv;
275 bool bit_y = (bit_a != bit_b) != carry;
276 carry = (bit_a && bit_b) || (bit_a && carry) || (bit_b && carry);
282 else if (cell->
type ==
"$macc")
290 for (
auto &port : macc.
ports) {
291 if (!
eval(port.in_a, undef, cell))
293 if (!
eval(port.in_b, undef, cell))
298 if (!macc.
eval(result))
307 if (cell->
type.
in(
"$_AOI3_",
"$_OAI3_",
"$_AOI4_",
"$_OAI4_")) {
314 if (sig_a.
size() > 0 && !
eval(sig_a, undef, cell))
316 if (sig_b.
size() > 0 && !
eval(sig_b, undef, cell))
318 if (sig_c.
size() > 0 && !
eval(sig_c, undef, cell))
320 if (sig_d.
size() > 0 && !
eval(sig_d, undef, cell))
344 if (
busy.count(busy_cell) > 0) {
348 busy.insert(busy_cell);
351 std::set<RTLIL::Cell*> driver_cells;
353 for (
auto cell : driver_cells) {
354 if (!
eval(cell, undef)) {
356 busy.erase(busy_cell);
362 busy.erase(busy_cell);
368 for (
auto &c : sig.
chunks())
377 return eval(sig, undef);
bool is_fully_def() const
RTLIL::SigSpec extract(RTLIL::SigSpec sig)
RTLIL::Const const_xor(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
#define YOSYS_NAMESPACE_END
RTLIL::Const as_const() const
bool eval(RTLIL::Const &result) const
bool eval(RTLIL::SigSpec &sig)
bool eval(RTLIL::Cell *cell, RTLIL::SigSpec &undef)
std::vector< SigMap > stack
std::vector< port_t > ports
std::map< RTLIL::IdString, RTLIL::Const > parameters
void extend_u0(int width, bool is_signed=false)
RTLIL::Const const_or(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
std::set< RTLIL::Cell * > busy
bool in(T first, Args...rest)
RTLIL::Const const_and(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
void apply(RTLIL::SigBit &bit) const
bool cell_known(RTLIL::IdString type)
bool check_any(RTLIL::SigSpec sig)
RTLIL_ATTRIBUTE_MEMBERS bool hasPort(RTLIL::IdString portname) const
bool cell_output(RTLIL::IdString type, RTLIL::IdString port)
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
int GetSize(RTLIL::Wire *wire)
static RTLIL::Const eval(RTLIL::IdString type, const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
#define log_assert(_assert_expr_)
bool is_fully_const() const
void stop(RTLIL::SigSpec sig)
ConstEval(RTLIL::Module *module)
void from_cell(RTLIL::Cell *cell)
void add(RTLIL::SigSpec sig)
SigSet< RTLIL::Cell * > sig2driver
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
#define YOSYS_NAMESPACE_BEGIN
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
std::vector< RTLIL::State > bits
void append(const RTLIL::SigSpec &signal)
void add(RTLIL::SigSpec from, RTLIL::SigSpec to)
bool eval(RTLIL::SigSpec &sig, RTLIL::SigSpec &undef, RTLIL::Cell *busy_cell=NULL)
void set(RTLIL::SigSpec sig, RTLIL::Const value)
void find(RTLIL::SigSpec sig, std::set< T > &result)
void insert(RTLIL::SigSpec sig, T data)
const std::vector< RTLIL::SigChunk > & chunks() const