34 for (
int i = 0; i <
GetSize(super_pattern.
bits); i++)
37 if (super_pattern.
bits[i] != sub_pattern.
bits[i])
49 for (
int in_state : fullstate_cache)
52 for (
auto &it : pattern_cache)
57 for (
size_t j = 0; j < pattern.
bits.size(); j++)
63 for (
int in_state : it.second)
64 if (fullstate_cache.count(in_state) == 0)
67 if (or_sig.
size() == 0)
72 if (eq_sig_a.
size() > 0)
78 eq_cell->
setPort(
"\\A", eq_sig_a);
79 eq_cell->
setPort(
"\\B", eq_sig_b);
88 std::set<int> complete_in_state_cache = it.second;
90 for (
auto &it2 : pattern_cache)
92 complete_in_state_cache.insert(it2.second.begin(), it2.second.end());
94 if (
GetSize(complete_in_state_cache) < num_states)
96 if (or_sig.
size() == 1)
106 or_cell->
setPort(
"\\A", or_sig);
114 switch (and_sig.
size())
133 cases_vector.
append(and_sig);
143 if (cases_vector.
size() > 1) {
145 or_cell->
setPort(
"\\A", cases_vector);
146 or_cell->
setPort(
"\\Y", output);
150 }
else if (cases_vector.
size() == 1) {
174 state_dff->
type =
"$dff";
176 state_dff->
type =
"$adff";
178 state_dff->
parameters[
"\\ARST_VALUE"] = fsm_data.state_table[fsm_data.reset_state];
179 for (
auto &bit : state_dff->
parameters[
"\\ARST_VALUE"].bits)
192 bool encoding_is_onehot =
true;
196 for (
size_t i = 0; i < fsm_data.state_table.size(); i++)
201 for (
size_t j = 0; j < state.
bits.size(); j++)
213 encoding_is_onehot =
false;
216 eq_cell->
setPort(
"\\A", sig_a);
217 eq_cell->
setPort(
"\\B", sig_b);
229 if (
GetSize(fsm_data.state_table) == 1)
231 module->
connect(next_state_wire, fsm_data.state_table.front());
237 for (
size_t i = 0; i < fsm_data.state_table.size(); i++)
239 std::map<RTLIL::Const, std::set<int>> pattern_cache;
240 std::set<int> fullstate_cache;
242 for (
size_t j = 0; j < fsm_data.state_table.size(); j++)
243 fullstate_cache.insert(j);
245 for (
auto &tr : fsm_data.transition_table) {
246 if (tr.state_out ==
int(i))
247 pattern_cache[tr.ctrl_in].insert(tr.state_in);
249 fullstate_cache.erase(tr.state_in);
255 if (encoding_is_onehot)
258 for (
size_t i = 0; i < fsm_data.state_table.size(); i++) {
261 for (
size_t j = 0; j < state.
bits.size(); j++)
273 int reset_state = fsm_data.reset_state;
277 for (
size_t i = 0; i < fsm_data.state_table.size(); i++) {
279 if (
int(i) == fsm_data.reset_state) {
288 mux_cell->
setPort(
"\\A", sig_a);
289 mux_cell->
setPort(
"\\B", sig_b);
290 mux_cell->
setPort(
"\\S", sig_s);
299 for (
int i = 0; i < fsm_data.num_outputs; i++)
301 std::map<RTLIL::Const, std::set<int>> pattern_cache;
302 std::set<int> fullstate_cache;
304 for (
size_t j = 0; j < fsm_data.state_table.size(); j++)
305 fullstate_cache.insert(j);
307 for (
auto &tr : fsm_data.transition_table) {
309 pattern_cache[tr.ctrl_in].insert(tr.state_in);
311 fullstate_cache.erase(tr.state_in);
328 log(
" fsm_map [selection]\n");
330 log(
"This pass translates FSM cells to flip-flops and logic.\n");
335 log_header(
"Executing FSM_MAP pass (mapping FSMs to basic logic).\n");
338 for (
auto &mod_it : design->
modules_) {
339 if (!design->
selected(mod_it.second))
341 std::vector<RTLIL::Cell*> fsm_cells;
342 for (
auto &cell_it : mod_it.second->cells_)
343 if (cell_it.second->type ==
"$fsm" && design->
selected(mod_it.second, cell_it.second))
344 fsm_cells.push_back(cell_it.second);
345 for (
auto cell : fsm_cells)
const char * c_str() const
bool selected(T1 *module) const
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
void log_header(const char *format,...)
static void map_fsm(RTLIL::Cell *fsm_cell, RTLIL::Module *module)
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
std::map< RTLIL::IdString, RTLIL::Const > parameters
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN bool pattern_is_subset(const RTLIL::Const &super_pattern, const RTLIL::Const &sub_pattern)
void connect(const RTLIL::SigSig &conn)
#define PRIVATE_NAMESPACE_BEGIN
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
int GetSize(RTLIL::Wire *wire)
#define log_assert(_assert_expr_)
bool is_fully_const() const
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
#define PRIVATE_NAMESPACE_END
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
#define USING_YOSYS_NAMESPACE
std::map< RTLIL::IdString, RTLIL::Module * > modules_
void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with)
void remove(const std::set< RTLIL::Wire * > &wires)
RTLIL::IdString uniquify(RTLIL::IdString name)
void log(const char *format,...)
void copy_from_cell(RTLIL::Cell *cell)
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 extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
std::pair< SigSpec, SigSpec > SigSig
bool has_marked_bits() const
static void implement_pattern_cache(RTLIL::Module *module, std::map< RTLIL::Const, std::set< int >> &pattern_cache, std::set< int > &fullstate_cache, int num_states, RTLIL::Wire *state_onehot, RTLIL::SigSpec &ctrl_in, RTLIL::SigSpec output)