2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel/register.h"
|
|
|
|
#include "kernel/sigtools.h"
|
|
|
|
#include "kernel/consteval.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
RTLIL::SigSpec find_any_lvalue(const RTLIL::Process *proc)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
RTLIL::SigSpec lvalue;
|
|
|
|
|
|
|
|
for (auto sync : proc->syncs)
|
|
|
|
for (auto &action : sync->actions)
|
2014-07-22 13:15:14 -05:00
|
|
|
if (action.first.size() > 0) {
|
2013-01-05 04:13:26 -06:00
|
|
|
lvalue = action.first;
|
|
|
|
lvalue.sort_and_unify();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto sync : proc->syncs) {
|
|
|
|
RTLIL::SigSpec this_lvalue;
|
|
|
|
for (auto &action : sync->actions)
|
|
|
|
this_lvalue.append(action.first);
|
|
|
|
this_lvalue.sort_and_unify();
|
|
|
|
RTLIL::SigSpec common_sig = this_lvalue.extract(lvalue);
|
2014-07-22 13:15:14 -05:00
|
|
|
if (common_sig.size() > 0)
|
2013-01-05 04:13:26 -06:00
|
|
|
lvalue = common_sig;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lvalue;
|
|
|
|
}
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
void gen_dffsr_complex(RTLIL::Module *mod, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, RTLIL::SigSpec clk, bool clk_polarity,
|
2013-10-24 09:54:05 -05:00
|
|
|
std::map<RTLIL::SigSpec, std::set<RTLIL::SyncRule*>> &async_rules, RTLIL::Process *proc)
|
|
|
|
{
|
2014-07-22 13:15:14 -05:00
|
|
|
RTLIL::SigSpec sig_sr_set = RTLIL::SigSpec(0, sig_d.size());
|
|
|
|
RTLIL::SigSpec sig_sr_clr = RTLIL::SigSpec(0, sig_d.size());
|
2013-10-24 09:54:05 -05:00
|
|
|
|
|
|
|
for (auto &it : async_rules)
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec sync_value = it.first;
|
|
|
|
RTLIL::SigSpec sync_value_inv;
|
|
|
|
RTLIL::SigSpec sync_high_signals;
|
|
|
|
RTLIL::SigSpec sync_low_signals;
|
|
|
|
|
|
|
|
for (auto &it2 : it.second)
|
|
|
|
if (it2->type == RTLIL::SyncType::ST0)
|
|
|
|
sync_low_signals.append(it2->signal);
|
|
|
|
else if (it2->type == RTLIL::SyncType::ST1)
|
|
|
|
sync_high_signals.append(it2->signal);
|
|
|
|
else
|
|
|
|
log_abort();
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sync_low_signals.size() > 1) {
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *cell = mod->addCell(NEW_ID, ID($reduce_or));
|
|
|
|
cell->parameters[ID::A_SIGNED] = RTLIL::Const(0);
|
|
|
|
cell->parameters[ID::A_WIDTH] = RTLIL::Const(sync_low_signals.size());
|
|
|
|
cell->parameters[ID::Y_WIDTH] = RTLIL::Const(1);
|
2020-03-12 14:57:01 -05:00
|
|
|
cell->setPort(ID::A, sync_low_signals);
|
|
|
|
cell->setPort(ID::Y, sync_low_signals = mod->addWire(NEW_ID));
|
2013-10-24 09:54:05 -05:00
|
|
|
}
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sync_low_signals.size() > 0) {
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *cell = mod->addCell(NEW_ID, ID($not));
|
|
|
|
cell->parameters[ID::A_SIGNED] = RTLIL::Const(0);
|
|
|
|
cell->parameters[ID::A_WIDTH] = RTLIL::Const(sync_low_signals.size());
|
|
|
|
cell->parameters[ID::Y_WIDTH] = RTLIL::Const(1);
|
2020-03-12 14:57:01 -05:00
|
|
|
cell->setPort(ID::A, sync_low_signals);
|
|
|
|
cell->setPort(ID::Y, mod->addWire(NEW_ID));
|
|
|
|
sync_high_signals.append(cell->getPort(ID::Y));
|
2013-10-24 09:54:05 -05:00
|
|
|
}
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sync_high_signals.size() > 1) {
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *cell = mod->addCell(NEW_ID, ID($reduce_or));
|
|
|
|
cell->parameters[ID::A_SIGNED] = RTLIL::Const(0);
|
|
|
|
cell->parameters[ID::A_WIDTH] = RTLIL::Const(sync_high_signals.size());
|
|
|
|
cell->parameters[ID::Y_WIDTH] = RTLIL::Const(1);
|
2020-03-12 14:57:01 -05:00
|
|
|
cell->setPort(ID::A, sync_high_signals);
|
|
|
|
cell->setPort(ID::Y, sync_high_signals = mod->addWire(NEW_ID));
|
2013-10-24 09:54:05 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *inv_cell = mod->addCell(NEW_ID, ID($not));
|
|
|
|
inv_cell->parameters[ID::A_SIGNED] = RTLIL::Const(0);
|
|
|
|
inv_cell->parameters[ID::A_WIDTH] = RTLIL::Const(sig_d.size());
|
|
|
|
inv_cell->parameters[ID::Y_WIDTH] = RTLIL::Const(sig_d.size());
|
2020-03-12 14:57:01 -05:00
|
|
|
inv_cell->setPort(ID::A, sync_value);
|
|
|
|
inv_cell->setPort(ID::Y, sync_value_inv = mod->addWire(NEW_ID, sig_d.size()));
|
2013-10-24 09:54:05 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *mux_set_cell = mod->addCell(NEW_ID, ID($mux));
|
|
|
|
mux_set_cell->parameters[ID::WIDTH] = RTLIL::Const(sig_d.size());
|
2020-03-12 14:57:01 -05:00
|
|
|
mux_set_cell->setPort(ID::A, sig_sr_set);
|
|
|
|
mux_set_cell->setPort(ID::B, sync_value);
|
|
|
|
mux_set_cell->setPort(ID::S, sync_high_signals);
|
|
|
|
mux_set_cell->setPort(ID::Y, sig_sr_set = mod->addWire(NEW_ID, sig_d.size()));
|
2013-10-24 09:54:05 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *mux_clr_cell = mod->addCell(NEW_ID, ID($mux));
|
|
|
|
mux_clr_cell->parameters[ID::WIDTH] = RTLIL::Const(sig_d.size());
|
2020-03-12 14:57:01 -05:00
|
|
|
mux_clr_cell->setPort(ID::A, sig_sr_clr);
|
|
|
|
mux_clr_cell->setPort(ID::B, sync_value_inv);
|
|
|
|
mux_clr_cell->setPort(ID::S, sync_high_signals);
|
|
|
|
mux_clr_cell->setPort(ID::Y, sig_sr_clr = mod->addWire(NEW_ID, sig_d.size()));
|
2013-10-24 09:54:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
std::stringstream sstr;
|
2014-07-31 06:19:47 -05:00
|
|
|
sstr << "$procdff$" << (autoidx++);
|
2013-10-24 09:54:05 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *cell = mod->addCell(sstr.str(), ID($dffsr));
|
2013-10-24 09:54:05 -05:00
|
|
|
cell->attributes = proc->attributes;
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::WIDTH] = RTLIL::Const(sig_d.size());
|
|
|
|
cell->parameters[ID::CLK_POLARITY] = RTLIL::Const(clk_polarity, 1);
|
|
|
|
cell->parameters[ID::SET_POLARITY] = RTLIL::Const(true, 1);
|
|
|
|
cell->parameters[ID::CLR_POLARITY] = RTLIL::Const(true, 1);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->setPort(ID::CLK, clk);
|
|
|
|
cell->setPort(ID::SET, sig_sr_set);
|
|
|
|
cell->setPort(ID::CLR, sig_sr_clr);
|
2013-10-24 09:54:05 -05:00
|
|
|
|
|
|
|
log(" created %s cell `%s' with %s edge clock and multiple level-sensitive resets.\n",
|
|
|
|
cell->type.c_str(), cell->name.c_str(), clk_polarity ? "positive" : "negative");
|
|
|
|
}
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
void gen_dffsr(RTLIL::Module *mod, RTLIL::SigSpec sig_in, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_out,
|
2013-10-18 06:26:52 -05:00
|
|
|
bool clk_polarity, bool set_polarity, RTLIL::SigSpec clk, RTLIL::SigSpec set, RTLIL::Process *proc)
|
|
|
|
{
|
|
|
|
std::stringstream sstr;
|
2014-07-31 06:19:47 -05:00
|
|
|
sstr << "$procdff$" << (autoidx++);
|
2013-10-18 06:26:52 -05:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
RTLIL::SigSpec sig_set_inv = mod->addWire(NEW_ID, sig_in.size());
|
|
|
|
RTLIL::SigSpec sig_sr_set = mod->addWire(NEW_ID, sig_in.size());
|
|
|
|
RTLIL::SigSpec sig_sr_clr = mod->addWire(NEW_ID, sig_in.size());
|
2013-10-18 06:26:52 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *inv_set = mod->addCell(NEW_ID, ID($not));
|
|
|
|
inv_set->parameters[ID::A_SIGNED] = RTLIL::Const(0);
|
|
|
|
inv_set->parameters[ID::A_WIDTH] = RTLIL::Const(sig_in.size());
|
|
|
|
inv_set->parameters[ID::Y_WIDTH] = RTLIL::Const(sig_in.size());
|
2020-03-12 14:57:01 -05:00
|
|
|
inv_set->setPort(ID::A, sig_set);
|
|
|
|
inv_set->setPort(ID::Y, sig_set_inv);
|
2013-10-18 06:26:52 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *mux_sr_set = mod->addCell(NEW_ID, ID($mux));
|
|
|
|
mux_sr_set->parameters[ID::WIDTH] = RTLIL::Const(sig_in.size());
|
2020-03-12 14:57:01 -05:00
|
|
|
mux_sr_set->setPort(set_polarity ? ID::A : ID::B, RTLIL::Const(0, sig_in.size()));
|
|
|
|
mux_sr_set->setPort(set_polarity ? ID::B : ID::A, sig_set);
|
|
|
|
mux_sr_set->setPort(ID::Y, sig_sr_set);
|
|
|
|
mux_sr_set->setPort(ID::S, set);
|
2013-10-18 06:26:52 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *mux_sr_clr = mod->addCell(NEW_ID, ID($mux));
|
|
|
|
mux_sr_clr->parameters[ID::WIDTH] = RTLIL::Const(sig_in.size());
|
2020-03-12 14:57:01 -05:00
|
|
|
mux_sr_clr->setPort(set_polarity ? ID::A : ID::B, RTLIL::Const(0, sig_in.size()));
|
|
|
|
mux_sr_clr->setPort(set_polarity ? ID::B : ID::A, sig_set_inv);
|
|
|
|
mux_sr_clr->setPort(ID::Y, sig_sr_clr);
|
|
|
|
mux_sr_clr->setPort(ID::S, set);
|
2013-10-18 06:26:52 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *cell = mod->addCell(sstr.str(), ID($dffsr));
|
2013-10-18 06:26:52 -05:00
|
|
|
cell->attributes = proc->attributes;
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::WIDTH] = RTLIL::Const(sig_in.size());
|
|
|
|
cell->parameters[ID::CLK_POLARITY] = RTLIL::Const(clk_polarity, 1);
|
|
|
|
cell->parameters[ID::SET_POLARITY] = RTLIL::Const(true, 1);
|
|
|
|
cell->parameters[ID::CLR_POLARITY] = RTLIL::Const(true, 1);
|
|
|
|
cell->setPort(ID::D, sig_in);
|
|
|
|
cell->setPort(ID::Q, sig_out);
|
|
|
|
cell->setPort(ID::CLK, clk);
|
|
|
|
cell->setPort(ID::SET, sig_sr_set);
|
|
|
|
cell->setPort(ID::CLR, sig_sr_clr);
|
2013-10-18 06:26:52 -05:00
|
|
|
|
|
|
|
log(" created %s cell `%s' with %s edge clock and %s level non-const reset.\n", cell->type.c_str(), cell->name.c_str(),
|
|
|
|
clk_polarity ? "positive" : "negative", set_polarity ? "positive" : "negative");
|
|
|
|
}
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
void gen_dff(RTLIL::Module *mod, RTLIL::SigSpec sig_in, RTLIL::Const val_rst, RTLIL::SigSpec sig_out,
|
2013-01-05 04:13:26 -06:00
|
|
|
bool clk_polarity, bool arst_polarity, RTLIL::SigSpec clk, RTLIL::SigSpec *arst, RTLIL::Process *proc)
|
|
|
|
{
|
|
|
|
std::stringstream sstr;
|
2014-07-31 06:19:47 -05:00
|
|
|
sstr << "$procdff$" << (autoidx++);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *cell = mod->addCell(sstr.str(), clk.empty() ? ID($ff) : arst ? ID($adff) : ID($dff));
|
2013-01-05 04:13:26 -06:00
|
|
|
cell->attributes = proc->attributes;
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::WIDTH] = RTLIL::Const(sig_in.size());
|
2013-01-05 04:13:26 -06:00
|
|
|
if (arst) {
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::ARST_POLARITY] = RTLIL::Const(arst_polarity, 1);
|
|
|
|
cell->parameters[ID::ARST_VALUE] = val_rst;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2016-10-14 05:33:56 -05:00
|
|
|
if (!clk.empty()) {
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::CLK_POLARITY] = RTLIL::Const(clk_polarity, 1);
|
2016-10-14 05:33:56 -05:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::D, sig_in);
|
|
|
|
cell->setPort(ID::Q, sig_out);
|
2013-01-05 04:13:26 -06:00
|
|
|
if (arst)
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::ARST, *arst);
|
2016-10-14 05:33:56 -05:00
|
|
|
if (!clk.empty())
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::CLK, clk);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2016-10-14 05:33:56 -05:00
|
|
|
if (!clk.empty())
|
|
|
|
log(" created %s cell `%s' with %s edge clock", cell->type.c_str(), cell->name.c_str(), clk_polarity ? "positive" : "negative");
|
|
|
|
else
|
|
|
|
log(" created %s cell `%s' with global clock", cell->type.c_str(), cell->name.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
if (arst)
|
2013-10-18 06:26:52 -05:00
|
|
|
log(" and %s level reset", arst_polarity ? "positive" : "negative");
|
2013-01-05 04:13:26 -06:00
|
|
|
log(".\n");
|
|
|
|
}
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
void proc_dff(RTLIL::Module *mod, RTLIL::Process *proc, ConstEval &ce)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec sig = find_any_lvalue(proc);
|
2013-10-21 07:51:58 -05:00
|
|
|
bool free_sync_level = false;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig.size() == 0)
|
2013-01-05 04:13:26 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
log("Creating register for signal `%s.%s' using process `%s.%s'.\n",
|
|
|
|
mod->name.c_str(), log_signal(sig), mod->name.c_str(), proc->name.c_str());
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
RTLIL::SigSpec insig = RTLIL::SigSpec(RTLIL::State::Sz, sig.size());
|
|
|
|
RTLIL::SigSpec rstval = RTLIL::SigSpec(RTLIL::State::Sz, sig.size());
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SyncRule *sync_level = NULL;
|
|
|
|
RTLIL::SyncRule *sync_edge = NULL;
|
|
|
|
RTLIL::SyncRule *sync_always = NULL;
|
2016-10-14 05:33:56 -05:00
|
|
|
bool global_clock = false;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2013-10-21 07:51:58 -05:00
|
|
|
std::map<RTLIL::SigSpec, std::set<RTLIL::SyncRule*>> many_async_rules;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
for (auto sync : proc->syncs)
|
|
|
|
for (auto &action : sync->actions)
|
|
|
|
{
|
2014-07-22 13:15:14 -05:00
|
|
|
if (action.first.extract(sig).size() == 0)
|
2013-01-05 04:13:26 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sync->type == RTLIL::SyncType::ST0 || sync->type == RTLIL::SyncType::ST1) {
|
2013-10-21 07:51:58 -05:00
|
|
|
if (sync_level != NULL && sync_level != sync) {
|
|
|
|
// log_error("Multiple level sensitive events found for this signal!\n");
|
|
|
|
many_async_rules[rstval].insert(sync_level);
|
2014-07-22 13:15:14 -05:00
|
|
|
rstval = RTLIL::SigSpec(RTLIL::State::Sz, sig.size());
|
2013-10-21 07:51:58 -05:00
|
|
|
}
|
2014-07-22 13:15:14 -05:00
|
|
|
rstval = RTLIL::SigSpec(RTLIL::State::Sz, sig.size());
|
2013-01-05 04:13:26 -06:00
|
|
|
sig.replace(action.first, action.second, &rstval);
|
|
|
|
sync_level = sync;
|
|
|
|
}
|
|
|
|
else if (sync->type == RTLIL::SyncType::STp || sync->type == RTLIL::SyncType::STn) {
|
|
|
|
if (sync_edge != NULL && sync_edge != sync)
|
|
|
|
log_error("Multiple edge sensitive events found for this signal!\n");
|
|
|
|
sig.replace(action.first, action.second, &insig);
|
|
|
|
sync_edge = sync;
|
|
|
|
}
|
|
|
|
else if (sync->type == RTLIL::SyncType::STa) {
|
|
|
|
if (sync_always != NULL && sync_always != sync)
|
|
|
|
log_error("Multiple always events found for this signal!\n");
|
|
|
|
sig.replace(action.first, action.second, &insig);
|
|
|
|
sync_always = sync;
|
|
|
|
}
|
2016-10-14 05:33:56 -05:00
|
|
|
else if (sync->type == RTLIL::SyncType::STg) {
|
|
|
|
sig.replace(action.first, action.second, &insig);
|
|
|
|
global_clock = true;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
else {
|
|
|
|
log_error("Event with any-edge sensitivity found for this signal!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
action.first.remove2(sig, &action.second);
|
|
|
|
}
|
|
|
|
|
2013-10-21 07:51:58 -05:00
|
|
|
if (many_async_rules.size() > 0)
|
|
|
|
{
|
|
|
|
many_async_rules[rstval].insert(sync_level);
|
|
|
|
if (many_async_rules.size() == 1)
|
|
|
|
{
|
|
|
|
sync_level = new RTLIL::SyncRule;
|
|
|
|
sync_level->type = RTLIL::SyncType::ST1;
|
2014-07-21 05:41:29 -05:00
|
|
|
sync_level->signal = mod->addWire(NEW_ID);
|
2013-10-21 07:51:58 -05:00
|
|
|
sync_level->actions.push_back(RTLIL::SigSig(sig, rstval));
|
|
|
|
free_sync_level = true;
|
|
|
|
|
|
|
|
RTLIL::SigSpec inputs, compare;
|
|
|
|
for (auto &it : many_async_rules[rstval]) {
|
|
|
|
inputs.append(it->signal);
|
|
|
|
compare.append(it->type == RTLIL::SyncType::ST0 ? RTLIL::State::S1 : RTLIL::State::S0);
|
|
|
|
}
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(inputs.size() == compare.size());
|
2013-10-21 07:51:58 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::Cell *cell = mod->addCell(NEW_ID, ID($ne));
|
|
|
|
cell->parameters[ID::A_SIGNED] = RTLIL::Const(false, 1);
|
|
|
|
cell->parameters[ID::B_SIGNED] = RTLIL::Const(false, 1);
|
|
|
|
cell->parameters[ID::A_WIDTH] = RTLIL::Const(inputs.size());
|
|
|
|
cell->parameters[ID::B_WIDTH] = RTLIL::Const(inputs.size());
|
|
|
|
cell->parameters[ID::Y_WIDTH] = RTLIL::Const(1);
|
2020-03-12 14:57:01 -05:00
|
|
|
cell->setPort(ID::A, inputs);
|
|
|
|
cell->setPort(ID::B, compare);
|
|
|
|
cell->setPort(ID::Y, sync_level->signal);
|
2013-10-21 07:51:58 -05:00
|
|
|
|
|
|
|
many_async_rules.clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-22 13:15:14 -05:00
|
|
|
rstval = RTLIL::SigSpec(RTLIL::State::Sz, sig.size());
|
2013-10-21 07:51:58 -05:00
|
|
|
sync_level = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-12 10:13:27 -06:00
|
|
|
SigSpec sig_q = sig;
|
2013-01-05 04:13:26 -06:00
|
|
|
ce.assign_map.apply(insig);
|
|
|
|
ce.assign_map.apply(rstval);
|
|
|
|
ce.assign_map.apply(sig);
|
|
|
|
|
2014-06-19 05:29:29 -05:00
|
|
|
if (rstval == sig) {
|
2021-03-05 20:59:03 -06:00
|
|
|
if (sync_level->type == RTLIL::SyncType::ST1)
|
|
|
|
insig = mod->Mux(NEW_ID, insig, sig, sync_level->signal);
|
|
|
|
else
|
|
|
|
insig = mod->Mux(NEW_ID, sig, insig, sync_level->signal);
|
2014-07-22 13:15:14 -05:00
|
|
|
rstval = RTLIL::SigSpec(RTLIL::State::Sz, sig.size());
|
2014-06-19 05:29:29 -05:00
|
|
|
sync_level = NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
if (sync_always) {
|
2013-10-21 07:51:58 -05:00
|
|
|
if (sync_edge || sync_level || many_async_rules.size() > 0)
|
2013-01-05 04:13:26 -06:00
|
|
|
log_error("Mixed always event with edge and/or level sensitive events!\n");
|
|
|
|
log(" created direct connection (no actual register cell created).\n");
|
2014-07-26 07:32:50 -05:00
|
|
|
mod->connect(RTLIL::SigSig(sig, insig));
|
2013-01-05 04:13:26 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-10-14 05:33:56 -05:00
|
|
|
if (!sync_edge && !global_clock)
|
2013-01-05 04:13:26 -06:00
|
|
|
log_error("Missing edge-sensitive event for this signal!\n");
|
|
|
|
|
2013-10-21 07:51:58 -05:00
|
|
|
if (many_async_rules.size() > 0)
|
|
|
|
{
|
2014-11-09 03:44:23 -06:00
|
|
|
log_warning("Complex async reset for dff `%s'.\n", log_signal(sig));
|
2013-10-24 09:54:05 -05:00
|
|
|
gen_dffsr_complex(mod, insig, sig, sync_edge->signal, sync_edge->type == RTLIL::SyncType::STp, many_async_rules, proc);
|
2013-10-21 07:51:58 -05:00
|
|
|
}
|
|
|
|
else if (!rstval.is_fully_const() && !ce.eval(rstval))
|
2013-10-18 06:26:52 -05:00
|
|
|
{
|
2014-11-09 03:44:23 -06:00
|
|
|
log_warning("Async reset value `%s' is not constant!\n", log_signal(rstval));
|
2017-12-12 10:13:27 -06:00
|
|
|
gen_dffsr(mod, insig, rstval, sig_q,
|
2013-10-18 06:26:52 -05:00
|
|
|
sync_edge->type == RTLIL::SyncType::STp,
|
|
|
|
sync_level && sync_level->type == RTLIL::SyncType::ST1,
|
|
|
|
sync_edge->signal, sync_level->signal, proc);
|
2013-10-21 07:51:58 -05:00
|
|
|
}
|
|
|
|
else
|
2017-12-12 10:13:27 -06:00
|
|
|
gen_dff(mod, insig, rstval.as_const(), sig_q,
|
2016-10-14 05:33:56 -05:00
|
|
|
sync_edge && sync_edge->type == RTLIL::SyncType::STp,
|
2013-10-18 06:26:52 -05:00
|
|
|
sync_level && sync_level->type == RTLIL::SyncType::ST1,
|
2016-10-14 05:33:56 -05:00
|
|
|
sync_edge ? sync_edge->signal : SigSpec(),
|
|
|
|
sync_level ? &sync_level->signal : NULL, proc);
|
2013-10-21 07:51:58 -05:00
|
|
|
|
|
|
|
if (free_sync_level)
|
|
|
|
delete sync_level;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ProcDffPass : public Pass {
|
2013-03-01 02:26:29 -06:00
|
|
|
ProcDffPass() : Pass("proc_dff", "extract flip-flops from processes") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2013-03-01 02:26:29 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" proc_dff [selection]\n");
|
|
|
|
log("\n");
|
2013-03-17 16:02:30 -05:00
|
|
|
log("This pass identifies flip-flops in the processes and converts them to\n");
|
|
|
|
log("d-type flip-flop cells.\n");
|
2013-03-01 02:26:29 -06:00
|
|
|
log("\n");
|
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Executing PROC_DFF pass (convert process syncs to FFs).\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
extra_args(args, 1, design);
|
|
|
|
|
2014-07-27 03:41:42 -05:00
|
|
|
for (auto mod : design->modules())
|
|
|
|
if (design->selected(mod)) {
|
|
|
|
ConstEval ce(mod);
|
|
|
|
for (auto &proc_it : mod->processes)
|
|
|
|
if (design->selected(mod, proc_it.second))
|
|
|
|
proc_dff(mod, proc_it.second, ce);
|
2013-03-01 02:26:29 -06:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
} ProcDffPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|