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++)
265 next_state_sig.replace(bit_idx,
RTLIL::SigSpec(next_state_onehot, i));
267 log_assert(!next_state_sig.has_marked_bits());
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);
const char * c_str() const
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
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
int GetSize(RTLIL::Wire *wire)
#define log_assert(_assert_expr_)
bool is_fully_const() const
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
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)
std::pair< SigSpec, SigSpec > SigSig
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)