2016-10-14 07:55:07 -05:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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/yosys.h"
|
|
|
|
#include "kernel/sigtools.h"
|
|
|
|
|
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
struct Clk2fflogicPass : public Pass {
|
|
|
|
Clk2fflogicPass() : Pass("clk2fflogic", "convert clocked FFs to generic $ff cells") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2016-10-14 07:55:07 -05:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" clk2fflogic [options] [selection]\n");
|
|
|
|
log("\n");
|
|
|
|
log("This command replaces clocked flip-flops with generic $ff cells that use the\n");
|
|
|
|
log("implicit global clock. This is useful for formal verification of designs with\n");
|
|
|
|
log("multiple clocks.\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2016-10-14 07:55:07 -05:00
|
|
|
{
|
|
|
|
// bool flag_noinit = false;
|
|
|
|
|
|
|
|
log_header(design, "Executing CLK2FFLOGIC pass (convert clocked FFs to generic $ff cells).\n");
|
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
// if (args[argidx] == "-noinit") {
|
|
|
|
// flag_noinit = true;
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
|
|
|
for (auto module : design->selected_modules())
|
|
|
|
{
|
|
|
|
SigMap sigmap(module);
|
|
|
|
dict<SigBit, State> initbits;
|
|
|
|
pool<SigBit> del_initbits;
|
|
|
|
|
|
|
|
for (auto wire : module->wires())
|
2020-04-02 11:51:32 -05:00
|
|
|
if (wire->attributes.count(ID::init) > 0)
|
2016-10-14 07:55:07 -05:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
Const initval = wire->attributes.at(ID::init);
|
2016-10-14 07:55:07 -05:00
|
|
|
SigSpec initsig = sigmap(wire);
|
|
|
|
|
|
|
|
for (int i = 0; i < GetSize(initval) && i < GetSize(initsig); i++)
|
|
|
|
if (initval[i] == State::S0 || initval[i] == State::S1)
|
|
|
|
initbits[initsig[i]] = initval[i];
|
|
|
|
}
|
|
|
|
|
2016-10-16 16:03:29 -05:00
|
|
|
for (auto cell : vector<Cell*>(module->selected_cells()))
|
2016-10-14 07:55:07 -05:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
if (cell->type.in(ID($mem)))
|
2017-12-13 12:14:34 -06:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
int abits = cell->getParam(ID::ABITS).as_int();
|
|
|
|
int width = cell->getParam(ID::WIDTH).as_int();
|
|
|
|
int rd_ports = cell->getParam(ID::RD_PORTS).as_int();
|
|
|
|
int wr_ports = cell->getParam(ID::WR_PORTS).as_int();
|
2017-12-13 19:07:31 -06:00
|
|
|
|
|
|
|
for (int i = 0; i < rd_ports; i++) {
|
2020-04-02 11:51:32 -05:00
|
|
|
if (cell->getParam(ID::RD_CLK_ENABLE).extract(i).as_bool())
|
2017-12-13 19:07:31 -06:00
|
|
|
log_error("Read port %d of memory %s.%s is clocked. This is not supported by \"clk2fflogic\"! "
|
|
|
|
"Call \"memory\" with -nordff to avoid this error.\n", i, log_id(cell), log_id(module));
|
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
Const wr_clk_en_param = cell->getParam(ID::WR_CLK_ENABLE);
|
|
|
|
Const wr_clk_pol_param = cell->getParam(ID::WR_CLK_POLARITY);
|
2017-12-13 19:07:31 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec wr_clk_port = cell->getPort(ID::WR_CLK);
|
|
|
|
SigSpec wr_en_port = cell->getPort(ID::WR_EN);
|
|
|
|
SigSpec wr_addr_port = cell->getPort(ID::WR_ADDR);
|
|
|
|
SigSpec wr_data_port = cell->getPort(ID::WR_DATA);
|
2017-12-13 19:07:31 -06:00
|
|
|
|
|
|
|
for (int wport = 0; wport < wr_ports; wport++)
|
|
|
|
{
|
|
|
|
bool clken = wr_clk_en_param[wport] == State::S1;
|
|
|
|
bool clkpol = wr_clk_pol_param[wport] == State::S1;
|
|
|
|
|
|
|
|
if (!clken)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SigBit clk = wr_clk_port[wport];
|
|
|
|
SigSpec en = wr_en_port.extract(wport*width, width);
|
|
|
|
SigSpec addr = wr_addr_port.extract(wport*abits, abits);
|
|
|
|
SigSpec data = wr_data_port.extract(wport*width, width);
|
|
|
|
|
|
|
|
log("Modifying write port %d on memory %s.%s: CLK=%s, A=%s, D=%s\n",
|
|
|
|
wport, log_id(module), log_id(cell), log_signal(clk),
|
|
|
|
log_signal(addr), log_signal(data));
|
|
|
|
|
|
|
|
Wire *past_clk = module->addWire(NEW_ID);
|
2020-04-02 11:51:32 -05:00
|
|
|
past_clk->attributes[ID::init] = clkpol ? State::S1 : State::S0;
|
2017-12-13 19:07:31 -06:00
|
|
|
module->addFf(NEW_ID, clk, past_clk);
|
|
|
|
|
|
|
|
SigSpec clock_edge_pattern;
|
|
|
|
|
|
|
|
if (clkpol) {
|
2020-03-13 10:17:39 -05:00
|
|
|
clock_edge_pattern.append(State::S0);
|
|
|
|
clock_edge_pattern.append(State::S1);
|
2017-12-13 19:07:31 -06:00
|
|
|
} else {
|
2020-03-13 10:17:39 -05:00
|
|
|
clock_edge_pattern.append(State::S1);
|
|
|
|
clock_edge_pattern.append(State::S0);
|
2017-12-13 19:07:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
SigSpec clock_edge = module->Eqx(NEW_ID, {clk, SigSpec(past_clk)}, clock_edge_pattern);
|
|
|
|
|
2017-12-13 19:29:19 -06:00
|
|
|
SigSpec en_q = module->addWire(NEW_ID, GetSize(en));
|
2017-12-13 19:07:31 -06:00
|
|
|
module->addFf(NEW_ID, en, en_q);
|
|
|
|
|
|
|
|
SigSpec addr_q = module->addWire(NEW_ID, GetSize(addr));
|
|
|
|
module->addFf(NEW_ID, addr, addr_q);
|
|
|
|
|
|
|
|
SigSpec data_q = module->addWire(NEW_ID, GetSize(data));
|
|
|
|
module->addFf(NEW_ID, data, data_q);
|
|
|
|
|
|
|
|
wr_clk_port[wport] = State::S0;
|
|
|
|
wr_en_port.replace(wport*width, module->Mux(NEW_ID, Const(0, GetSize(en_q)), en_q, clock_edge));
|
|
|
|
wr_addr_port.replace(wport*abits, addr_q);
|
|
|
|
wr_data_port.replace(wport*width, data_q);
|
|
|
|
|
|
|
|
wr_clk_en_param[wport] = State::S0;
|
|
|
|
wr_clk_pol_param[wport] = State::S0;
|
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setParam(ID::WR_CLK_ENABLE, wr_clk_en_param);
|
|
|
|
cell->setParam(ID::WR_CLK_POLARITY, wr_clk_pol_param);
|
2017-12-13 19:07:31 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::WR_CLK, wr_clk_port);
|
|
|
|
cell->setPort(ID::WR_EN, wr_en_port);
|
|
|
|
cell->setPort(ID::WR_ADDR, wr_addr_port);
|
|
|
|
cell->setPort(ID::WR_DATA, wr_data_port);
|
2017-12-13 12:14:34 -06:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (cell->type.in(ID($dlatch), ID($dlatchsr)))
|
2016-10-17 06:28:55 -05:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
bool enpol = cell->parameters[ID::EN_POLARITY].as_bool();
|
2016-10-17 06:28:55 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec sig_en = cell->getPort(ID::EN);
|
|
|
|
SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
SigSpec sig_q = cell->getPort(ID::Q);
|
2016-10-17 06:28:55 -05:00
|
|
|
|
|
|
|
log("Replacing %s.%s (%s): EN=%s, D=%s, Q=%s\n",
|
|
|
|
log_id(module), log_id(cell), log_id(cell->type),
|
|
|
|
log_signal(sig_en), log_signal(sig_d), log_signal(sig_q));
|
|
|
|
|
|
|
|
Wire *past_q = module->addWire(NEW_ID, GetSize(sig_q));
|
|
|
|
module->addFf(NEW_ID, sig_q, past_q);
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (cell->type == ID($dlatch))
|
2018-02-26 05:20:28 -06:00
|
|
|
{
|
|
|
|
if (enpol)
|
|
|
|
module->addMux(NEW_ID, past_q, sig_d, sig_en, sig_q);
|
|
|
|
else
|
|
|
|
module->addMux(NEW_ID, sig_d, past_q, sig_en, sig_q);
|
|
|
|
}
|
2016-10-17 06:28:55 -05:00
|
|
|
else
|
2018-02-26 05:20:28 -06:00
|
|
|
{
|
|
|
|
SigSpec t;
|
|
|
|
if (enpol)
|
|
|
|
t = module->Mux(NEW_ID, past_q, sig_d, sig_en);
|
|
|
|
else
|
|
|
|
t = module->Mux(NEW_ID, sig_d, past_q, sig_en);
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec s = cell->getPort(ID::SET);
|
|
|
|
if (!cell->parameters[ID::SET_POLARITY].as_bool())
|
2018-02-26 05:20:28 -06:00
|
|
|
s = module->Not(NEW_ID, s);
|
|
|
|
t = module->Or(NEW_ID, t, s);
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec c = cell->getPort(ID::CLR);
|
|
|
|
if (cell->parameters[ID::CLR_POLARITY].as_bool())
|
2018-02-26 05:20:28 -06:00
|
|
|
c = module->Not(NEW_ID, c);
|
|
|
|
module->addAnd(NEW_ID, t, c, sig_q);
|
|
|
|
}
|
2016-10-17 06:28:55 -05:00
|
|
|
|
|
|
|
Const initval;
|
|
|
|
bool assign_initval = false;
|
|
|
|
for (int i = 0; i < GetSize(sig_d); i++) {
|
|
|
|
SigBit qbit = sigmap(sig_q[i]);
|
|
|
|
if (initbits.count(qbit)) {
|
|
|
|
initval.bits.push_back(initbits.at(qbit));
|
|
|
|
del_initbits.insert(qbit);
|
|
|
|
} else
|
|
|
|
initval.bits.push_back(State::Sx);
|
|
|
|
if (initval.bits.back() != State::Sx)
|
|
|
|
assign_initval = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (assign_initval)
|
2020-04-02 11:51:32 -05:00
|
|
|
past_q->attributes[ID::init] = initval;
|
2016-10-17 06:28:55 -05:00
|
|
|
|
|
|
|
module->remove(cell);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
bool word_dff = cell->type.in(ID($dff), ID($adff), ID($dffsr));
|
2020-01-15 11:51:31 -06:00
|
|
|
if (word_dff || cell->type.in(ID($_DFF_N_), ID($_DFF_P_),
|
|
|
|
ID($_DFF_NN0_), ID($_DFF_NN1_), ID($_DFF_NP0_), ID($_DFF_NP1_),
|
|
|
|
ID($_DFF_PP0_), ID($_DFF_PP1_), ID($_DFF_PN0_), ID($_DFF_PN1_),
|
|
|
|
ID($_DFFSR_NNN_), ID($_DFFSR_NNP_), ID($_DFFSR_NPN_), ID($_DFFSR_NPP_),
|
|
|
|
ID($_DFFSR_PNN_), ID($_DFFSR_PNP_), ID($_DFFSR_PPN_), ID($_DFFSR_PPP_)))
|
2016-10-14 07:55:07 -05:00
|
|
|
{
|
2020-01-15 11:51:31 -06:00
|
|
|
bool clkpol;
|
|
|
|
SigSpec clk;
|
|
|
|
if (word_dff) {
|
2020-04-02 11:51:32 -05:00
|
|
|
clkpol = cell->parameters[ID::CLK_POLARITY].as_bool();
|
|
|
|
clk = cell->getPort(ID::CLK);
|
2020-01-15 11:51:31 -06:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (cell->type.in(ID($_DFF_P_), ID($_DFF_N_),
|
|
|
|
ID($_DFF_NN0_), ID($_DFF_NN1_), ID($_DFF_NP0_), ID($_DFF_NP1_),
|
|
|
|
ID($_DFF_PP0_), ID($_DFF_PP1_), ID($_DFF_PN0_), ID($_DFF_PN1_)))
|
|
|
|
clkpol = cell->type[6] == 'P';
|
|
|
|
else if (cell->type.in(ID($_DFFSR_NNN_), ID($_DFFSR_NNP_), ID($_DFFSR_NPN_), ID($_DFFSR_NPP_),
|
|
|
|
ID($_DFFSR_PNN_), ID($_DFFSR_PNP_), ID($_DFFSR_PPN_), ID($_DFFSR_PPP_)))
|
|
|
|
clkpol = cell->type[8] == 'P';
|
|
|
|
else log_abort();
|
2020-04-02 11:51:32 -05:00
|
|
|
clk = cell->getPort(ID::C);
|
2020-01-15 11:51:31 -06:00
|
|
|
}
|
2016-10-14 07:55:07 -05:00
|
|
|
|
2016-10-16 16:03:29 -05:00
|
|
|
Wire *past_clk = module->addWire(NEW_ID);
|
2020-04-02 11:51:32 -05:00
|
|
|
past_clk->attributes[ID::init] = clkpol ? State::S1 : State::S0;
|
2020-01-15 11:51:31 -06:00
|
|
|
|
|
|
|
if (word_dff)
|
|
|
|
module->addFf(NEW_ID, clk, past_clk);
|
|
|
|
else
|
|
|
|
module->addFfGate(NEW_ID, clk, past_clk);
|
2016-10-14 07:55:07 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
SigSpec sig_q = cell->getPort(ID::Q);
|
2016-10-14 07:55:07 -05:00
|
|
|
|
|
|
|
log("Replacing %s.%s (%s): CLK=%s, D=%s, Q=%s\n",
|
|
|
|
log_id(module), log_id(cell), log_id(cell->type),
|
|
|
|
log_signal(clk), log_signal(sig_d), log_signal(sig_q));
|
|
|
|
|
2016-10-14 11:34:44 -05:00
|
|
|
SigSpec clock_edge_pattern;
|
|
|
|
|
|
|
|
if (clkpol) {
|
2020-03-13 10:17:39 -05:00
|
|
|
clock_edge_pattern.append(State::S0);
|
|
|
|
clock_edge_pattern.append(State::S1);
|
2016-10-14 11:34:44 -05:00
|
|
|
} else {
|
2020-03-13 10:17:39 -05:00
|
|
|
clock_edge_pattern.append(State::S1);
|
|
|
|
clock_edge_pattern.append(State::S0);
|
2016-10-14 11:34:44 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 16:03:29 -05:00
|
|
|
SigSpec clock_edge = module->Eqx(NEW_ID, {clk, SigSpec(past_clk)}, clock_edge_pattern);
|
2016-10-14 07:55:07 -05:00
|
|
|
|
|
|
|
Wire *past_d = module->addWire(NEW_ID, GetSize(sig_d));
|
|
|
|
Wire *past_q = module->addWire(NEW_ID, GetSize(sig_q));
|
2020-01-15 11:51:31 -06:00
|
|
|
if (word_dff) {
|
|
|
|
module->addFf(NEW_ID, sig_d, past_d);
|
|
|
|
module->addFf(NEW_ID, sig_q, past_q);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
module->addFfGate(NEW_ID, sig_d, past_d);
|
|
|
|
module->addFfGate(NEW_ID, sig_q, past_q);
|
|
|
|
}
|
2016-10-14 07:55:07 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (cell->type == ID($adff))
|
2016-10-16 16:03:29 -05:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec arst = cell->getPort(ID::ARST);
|
2016-10-16 16:03:29 -05:00
|
|
|
SigSpec qval = module->Mux(NEW_ID, past_q, past_d, clock_edge);
|
2020-04-02 11:51:32 -05:00
|
|
|
Const rstval = cell->parameters[ID::ARST_VALUE];
|
2016-10-16 16:03:29 -05:00
|
|
|
|
2019-07-09 15:44:39 -05:00
|
|
|
Wire *past_arst = module->addWire(NEW_ID);
|
|
|
|
module->addFf(NEW_ID, arst, past_arst);
|
2020-04-02 11:51:32 -05:00
|
|
|
if (cell->parameters[ID::ARST_POLARITY].as_bool())
|
2019-07-09 15:44:39 -05:00
|
|
|
arst = module->LogicOr(NEW_ID, arst, past_arst);
|
|
|
|
else
|
|
|
|
arst = module->LogicAnd(NEW_ID, arst, past_arst);
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (cell->parameters[ID::ARST_POLARITY].as_bool())
|
2016-10-16 16:03:29 -05:00
|
|
|
module->addMux(NEW_ID, qval, rstval, arst, sig_q);
|
|
|
|
else
|
|
|
|
module->addMux(NEW_ID, rstval, qval, arst, sig_q);
|
|
|
|
}
|
|
|
|
else
|
2020-01-15 11:51:31 -06:00
|
|
|
if (cell->type.in(ID($_DFF_NN0_), ID($_DFF_NN1_), ID($_DFF_NP0_), ID($_DFF_NP1_),
|
|
|
|
ID($_DFF_PP0_), ID($_DFF_PP1_), ID($_DFF_PN0_), ID($_DFF_PN1_)))
|
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec arst = cell->getPort(ID::R);
|
2020-01-15 11:51:31 -06:00
|
|
|
SigSpec qval = module->MuxGate(NEW_ID, past_q, past_d, clock_edge);
|
|
|
|
SigBit rstval = (cell->type[8] == '1');
|
|
|
|
|
|
|
|
Wire *past_arst = module->addWire(NEW_ID);
|
|
|
|
module->addFfGate(NEW_ID, arst, past_arst);
|
|
|
|
if (cell->type[7] == 'P')
|
|
|
|
arst = module->OrGate(NEW_ID, arst, past_arst);
|
|
|
|
else
|
|
|
|
arst = module->AndGate(NEW_ID, arst, past_arst);
|
|
|
|
|
|
|
|
if (cell->type[7] == 'P')
|
|
|
|
module->addMuxGate(NEW_ID, qval, rstval, arst, sig_q);
|
|
|
|
else
|
|
|
|
module->addMuxGate(NEW_ID, rstval, qval, arst, sig_q);
|
|
|
|
}
|
|
|
|
else
|
2020-04-02 11:51:32 -05:00
|
|
|
if (cell->type == ID($dffsr))
|
2016-10-17 06:28:55 -05:00
|
|
|
{
|
|
|
|
SigSpec qval = module->Mux(NEW_ID, past_q, past_d, clock_edge);
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec setval = cell->getPort(ID::SET);
|
|
|
|
SigSpec clrval = cell->getPort(ID::CLR);
|
2016-10-17 06:28:55 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!cell->parameters[ID::SET_POLARITY].as_bool())
|
2016-10-17 06:28:55 -05:00
|
|
|
setval = module->Not(NEW_ID, setval);
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (cell->parameters[ID::CLR_POLARITY].as_bool())
|
2016-10-17 06:28:55 -05:00
|
|
|
clrval = module->Not(NEW_ID, clrval);
|
|
|
|
|
|
|
|
qval = module->Or(NEW_ID, qval, setval);
|
|
|
|
module->addAnd(NEW_ID, qval, clrval, sig_q);
|
|
|
|
}
|
|
|
|
else
|
2020-01-15 11:51:31 -06:00
|
|
|
if (cell->type.in(ID($_DFFSR_NNN_), ID($_DFFSR_NNP_), ID($_DFFSR_NPN_), ID($_DFFSR_NPP_),
|
|
|
|
ID($_DFFSR_PNN_), ID($_DFFSR_PNP_), ID($_DFFSR_PPN_), ID($_DFFSR_PPP_)))
|
|
|
|
{
|
|
|
|
SigSpec qval = module->MuxGate(NEW_ID, past_q, past_d, clock_edge);
|
2020-03-12 14:57:01 -05:00
|
|
|
SigSpec setval = cell->getPort(ID::S);
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec clrval = cell->getPort(ID::R);
|
2020-01-15 11:51:31 -06:00
|
|
|
|
|
|
|
if (cell->type[9] != 'P')
|
|
|
|
setval = module->Not(NEW_ID, setval);
|
|
|
|
|
|
|
|
if (cell->type[10] == 'P')
|
|
|
|
clrval = module->Not(NEW_ID, clrval);
|
|
|
|
|
|
|
|
qval = module->OrGate(NEW_ID, qval, setval);
|
|
|
|
module->addAndGate(NEW_ID, qval, clrval, sig_q);
|
|
|
|
}
|
2020-04-02 11:51:32 -05:00
|
|
|
else if (cell->type == ID($dff))
|
2016-10-16 16:03:29 -05:00
|
|
|
{
|
|
|
|
module->addMux(NEW_ID, past_q, past_d, clock_edge, sig_q);
|
|
|
|
}
|
2020-01-15 11:51:31 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
module->addMuxGate(NEW_ID, past_q, past_d, clock_edge, sig_q);
|
|
|
|
}
|
2016-10-14 07:55:07 -05:00
|
|
|
|
|
|
|
Const initval;
|
|
|
|
bool assign_initval = false;
|
|
|
|
for (int i = 0; i < GetSize(sig_d); i++) {
|
|
|
|
SigBit qbit = sigmap(sig_q[i]);
|
|
|
|
if (initbits.count(qbit)) {
|
|
|
|
initval.bits.push_back(initbits.at(qbit));
|
|
|
|
del_initbits.insert(qbit);
|
|
|
|
} else
|
|
|
|
initval.bits.push_back(State::Sx);
|
|
|
|
if (initval.bits.back() != State::Sx)
|
|
|
|
assign_initval = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (assign_initval) {
|
2020-04-02 11:51:32 -05:00
|
|
|
past_d->attributes[ID::init] = initval;
|
|
|
|
past_q->attributes[ID::init] = initval;
|
2016-10-14 07:55:07 -05:00
|
|
|
}
|
|
|
|
|
2016-10-16 16:03:29 -05:00
|
|
|
module->remove(cell);
|
2016-10-14 07:55:07 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto wire : module->wires())
|
2020-04-02 11:51:32 -05:00
|
|
|
if (wire->attributes.count(ID::init) > 0)
|
2016-10-14 07:55:07 -05:00
|
|
|
{
|
|
|
|
bool delete_initattr = true;
|
2020-04-02 11:51:32 -05:00
|
|
|
Const initval = wire->attributes.at(ID::init);
|
2016-10-14 07:55:07 -05:00
|
|
|
SigSpec initsig = sigmap(wire);
|
|
|
|
|
|
|
|
for (int i = 0; i < GetSize(initval) && i < GetSize(initsig); i++)
|
|
|
|
if (del_initbits.count(initsig[i]) > 0)
|
|
|
|
initval[i] = State::Sx;
|
|
|
|
else if (initval[i] != State::Sx)
|
|
|
|
delete_initattr = false;
|
|
|
|
|
|
|
|
if (delete_initattr)
|
2020-04-02 11:51:32 -05:00
|
|
|
wire->attributes.erase(ID::init);
|
2016-10-14 07:55:07 -05:00
|
|
|
else
|
2020-04-02 11:51:32 -05:00
|
|
|
wire->attributes.at(ID::init) = initval;
|
2016-10-14 07:55:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} Clk2fflogicPass;
|
|
|
|
|
|
|
|
PRIVATE_NAMESPACE_END
|