mirror of
https://github.com/YosysHQ/yosys
synced 2025-09-29 20:59:03 +00:00
Update passes/fsm to avoid bits()
This commit is contained in:
parent
d318775d97
commit
7c3cf9cc42
5 changed files with 32 additions and 44 deletions
|
@ -45,35 +45,27 @@ struct FsmData
|
|||
cell->parameters[ID::STATE_NUM] = RTLIL::Const(state_table.size());
|
||||
cell->parameters[ID::STATE_NUM_LOG2] = RTLIL::Const(state_num_log2);
|
||||
cell->parameters[ID::STATE_RST] = RTLIL::Const(reset_state);
|
||||
cell->parameters[ID::STATE_TABLE] = RTLIL::Const();
|
||||
|
||||
for (int i = 0; i < int(state_table.size()); i++) {
|
||||
std::vector<RTLIL::State> &bits_table = cell->parameters[ID::STATE_TABLE].bits();
|
||||
std::vector<RTLIL::State> &bits_state = state_table[i].bits();
|
||||
bits_table.insert(bits_table.end(), bits_state.begin(), bits_state.end());
|
||||
}
|
||||
RTLIL::Const cell_state_table;
|
||||
for (const RTLIL::Const &c : state_table)
|
||||
cell_state_table.append(c);
|
||||
cell->parameters[ID::STATE_TABLE] = std::move(cell_state_table);
|
||||
|
||||
cell->parameters[ID::TRANS_NUM] = RTLIL::Const(transition_table.size());
|
||||
cell->parameters[ID::TRANS_TABLE] = RTLIL::Const();
|
||||
RTLIL::Const cell_trans_table;
|
||||
for (int i = 0; i < int(transition_table.size()); i++)
|
||||
{
|
||||
std::vector<RTLIL::State> &bits_table = cell->parameters[ID::TRANS_TABLE].bits();
|
||||
transition_t &tr = transition_table[i];
|
||||
|
||||
RTLIL::Const const_state_in = RTLIL::Const(tr.state_in, state_num_log2);
|
||||
RTLIL::Const const_state_out = RTLIL::Const(tr.state_out, state_num_log2);
|
||||
std::vector<RTLIL::State> &bits_state_in = const_state_in.bits();
|
||||
std::vector<RTLIL::State> &bits_state_out = const_state_out.bits();
|
||||
|
||||
std::vector<RTLIL::State> &bits_ctrl_in = tr.ctrl_in.bits();
|
||||
std::vector<RTLIL::State> &bits_ctrl_out = tr.ctrl_out.bits();
|
||||
|
||||
// append lsb first
|
||||
bits_table.insert(bits_table.end(), bits_ctrl_out.begin(), bits_ctrl_out.end());
|
||||
bits_table.insert(bits_table.end(), bits_state_out.begin(), bits_state_out.end());
|
||||
bits_table.insert(bits_table.end(), bits_ctrl_in.begin(), bits_ctrl_in.end());
|
||||
bits_table.insert(bits_table.end(), bits_state_in.begin(), bits_state_in.end());
|
||||
cell_trans_table.append(tr.ctrl_out);
|
||||
cell_trans_table.append(const_state_out);
|
||||
cell_trans_table.append(tr.ctrl_in);
|
||||
cell_trans_table.append(const_state_in);
|
||||
}
|
||||
cell->parameters[ID::TRANS_TABLE] = std::move(cell_trans_table);
|
||||
}
|
||||
|
||||
void copy_from_cell(RTLIL::Cell *cell)
|
||||
|
@ -95,25 +87,18 @@ struct FsmData
|
|||
const RTLIL::Const &trans_table = cell->parameters[ID::TRANS_TABLE];
|
||||
|
||||
for (int i = 0; i < state_num; i++) {
|
||||
RTLIL::Const state_code;
|
||||
int off_begin = i*state_bits, off_end = off_begin + state_bits;
|
||||
state_code.bits().insert(state_code.bits().begin(), state_table.begin()+off_begin, state_table.begin()+off_end);
|
||||
int off_begin = i*state_bits;
|
||||
RTLIL::Const state_code = state_table.extract(off_begin, state_bits);
|
||||
this->state_table.push_back(state_code);
|
||||
}
|
||||
|
||||
for (int i = 0; i < trans_num; i++)
|
||||
{
|
||||
auto off_ctrl_out = trans_table.begin() + i*(num_inputs+num_outputs+2*state_num_log2);
|
||||
auto off_state_out = off_ctrl_out + num_outputs;
|
||||
auto off_ctrl_in = off_state_out + state_num_log2;
|
||||
auto off_state_in = off_ctrl_in + num_inputs;
|
||||
auto off_end = off_state_in + state_num_log2;
|
||||
|
||||
RTLIL::Const state_in, state_out, ctrl_in, ctrl_out;
|
||||
ctrl_out.bits().insert(ctrl_out.bits().begin(), off_ctrl_out, off_state_out);
|
||||
state_out.bits().insert(state_out.bits().begin(), off_state_out, off_ctrl_in);
|
||||
ctrl_in.bits().insert(ctrl_in.bits().begin(), off_ctrl_in, off_state_in);
|
||||
state_in.bits().insert(state_in.bits().begin(), off_state_in, off_end);
|
||||
int base_offset = i*(num_inputs+num_outputs+2*state_num_log2);
|
||||
RTLIL::Const ctrl_out = trans_table.extract(base_offset, num_outputs);
|
||||
RTLIL::Const state_out = trans_table.extract(base_offset + num_outputs, state_num_log2);
|
||||
RTLIL::Const ctrl_in = trans_table.extract(base_offset + num_outputs + state_num_log2, num_inputs);
|
||||
RTLIL::Const state_in = trans_table.extract(base_offset + num_outputs + state_num_log2 + num_inputs, state_num_log2);
|
||||
|
||||
transition_t tr;
|
||||
tr.state_in = state_in.as_int();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue