3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-08-02 09:20:23 +00:00

Added support for gate-level cells in dff2dffe

This commit is contained in:
Clifford Wolf 2014-12-24 10:49:54 +01:00
parent 4aa9fbbf3f
commit afcacd6437

View file

@ -20,6 +20,7 @@
#include "kernel/yosys.h" #include "kernel/yosys.h"
#include "kernel/sigtools.h" #include "kernel/sigtools.h"
#include "kernel/celltypes.h" #include "kernel/celltypes.h"
#include "passes/techmap/simplemap.h"
USING_YOSYS_NAMESPACE USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN PRIVATE_NAMESPACE_BEGIN
@ -47,12 +48,12 @@ struct Dff2dffeWorker
} }
for (auto cell : module->cells()) { for (auto cell : module->cells()) {
if (cell->type == "$mux" || cell->type == "$pmux") { if (cell->type == "$mux" || cell->type == "$pmux" || cell->type == "$_MUX_") {
RTLIL::SigSpec sig_y = sigmap(cell->getPort("\\Y")); RTLIL::SigSpec sig_y = sigmap(cell->getPort("\\Y"));
for (int i = 0; i < GetSize(sig_y); i++) for (int i = 0; i < GetSize(sig_y); i++)
bit2mux[sig_y[i]] = cell_int_t(cell, i); bit2mux[sig_y[i]] = cell_int_t(cell, i);
} }
if (cell->type == "$dff") if (cell->type == "$dff" || cell->type == "$_DFF_N_" || cell->type == "$_DFF_P_")
dff_cells.push_back(cell); dff_cells.push_back(cell);
for (auto conn : cell->connections()) { for (auto conn : cell->connections()) {
if (ct.cell_output(cell->type, conn.first)) if (ct.cell_output(cell->type, conn.first))
@ -133,22 +134,44 @@ struct Dff2dffeWorker
// TBD // TBD
} }
RTLIL::SigSpec make_patterns_logic(patterns_t patterns) RTLIL::SigSpec make_patterns_logic(patterns_t patterns, bool make_gates)
{ {
RTLIL::SigSpec or_input; RTLIL::SigSpec or_input;
for (auto pat : patterns) {
for (auto pat : patterns)
{
RTLIL::SigSpec s1, s2; RTLIL::SigSpec s1, s2;
for (auto it : pat) { for (auto it : pat) {
s1.append(it.first); s1.append(it.first);
s2.append(it.second); s2.append(it.second);
} }
or_input.append(module->Ne(NEW_ID, s1, s2));
RTLIL::SigSpec y = module->addWire(NEW_ID);
RTLIL::Cell *c = module->addNe(NEW_ID, s1, s2, y);
if (make_gates) {
simplemap(module, c);
module->remove(c);
}
or_input.append(y);
} }
if (GetSize(or_input) == 0) if (GetSize(or_input) == 0)
return RTLIL::S1; return RTLIL::S1;
if (GetSize(or_input) == 1) if (GetSize(or_input) == 1)
return or_input; return or_input;
return module->ReduceOr(NEW_ID, or_input);
RTLIL::SigSpec y = module->addWire(NEW_ID);
RTLIL::Cell *c = module->addReduceOr(NEW_ID, or_input, y);
if (make_gates) {
simplemap(module, c);
module->remove(c);
}
return y;
} }
void handle_dff_cell(RTLIL::Cell *dff_cell) void handle_dff_cell(RTLIL::Cell *dff_cell)
@ -174,9 +197,15 @@ struct Dff2dffeWorker
new_sig_d.append(sig_d[i]); new_sig_d.append(sig_d[i]);
new_sig_q.append(sig_q[i]); new_sig_q.append(sig_q[i]);
} }
RTLIL::Cell *new_cell = module->addDffe(NEW_ID, dff_cell->getPort("\\CLK"), make_patterns_logic(it.first), if (dff_cell->type == "$dff") {
new_sig_d, new_sig_q, dff_cell->getParam("\\CLK_POLARITY").as_bool(), true); RTLIL::Cell *new_cell = module->addDffe(NEW_ID, dff_cell->getPort("\\CLK"), make_patterns_logic(it.first, false),
log(" created $dffe cell %s for %s -> %s.\n", log_id(new_cell), log_signal(new_sig_d), log_signal(new_sig_q)); new_sig_d, new_sig_q, dff_cell->getParam("\\CLK_POLARITY").as_bool(), true);
log(" created $dffe cell %s for %s -> %s.\n", log_id(new_cell), log_signal(new_sig_d), log_signal(new_sig_q));
} else {
RTLIL::Cell *new_cell = module->addDffeGate(NEW_ID, dff_cell->getPort("\\C"), make_patterns_logic(it.first, true),
new_sig_d, new_sig_q, dff_cell->type == "$_DFF_P_", true);
log(" created %s cell %s for %s -> %s.\n", log_id(new_cell->type), log_id(new_cell), log_signal(new_sig_d), log_signal(new_sig_q));
}
} }
if (remaining_indices.empty()) { if (remaining_indices.empty()) {