mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-13 04:28:18 +00:00
memory_dff: Use Mem helper.
This commit is contained in:
parent
9420bde09f
commit
8c734e07b8
|
@ -21,6 +21,7 @@
|
||||||
#include "kernel/yosys.h"
|
#include "kernel/yosys.h"
|
||||||
#include "kernel/sigtools.h"
|
#include "kernel/sigtools.h"
|
||||||
#include "kernel/ffinit.h"
|
#include "kernel/ffinit.h"
|
||||||
|
#include "kernel/mem.h"
|
||||||
|
|
||||||
USING_YOSYS_NAMESPACE
|
USING_YOSYS_NAMESPACE
|
||||||
PRIVATE_NAMESPACE_BEGIN
|
PRIVATE_NAMESPACE_BEGIN
|
||||||
|
@ -210,16 +211,17 @@ struct MemoryDffWorker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_rd_cell(RTLIL::Cell *cell)
|
void handle_rd_port(Mem &mem, int idx)
|
||||||
{
|
{
|
||||||
log("Checking cell `%s' in module `%s': ", cell->name.c_str(), module->name.c_str());
|
auto &port = mem.rd_ports[idx];
|
||||||
|
log("Checking read port `%s'[%d] in module `%s': ", mem.memid.c_str(), idx, module->name.c_str());
|
||||||
|
|
||||||
bool clk_polarity = 0;
|
bool clk_polarity = 0;
|
||||||
bool en_polarity = 0;
|
bool en_polarity = 0;
|
||||||
|
|
||||||
RTLIL::SigSpec clk_data = RTLIL::SigSpec(RTLIL::State::Sx);
|
RTLIL::SigSpec clk_data = RTLIL::SigSpec(RTLIL::State::Sx);
|
||||||
RTLIL::SigSpec en_data;
|
RTLIL::SigSpec en_data;
|
||||||
RTLIL::SigSpec sig_data = cell->getPort(ID::DATA);
|
RTLIL::SigSpec sig_data = port.data;
|
||||||
|
|
||||||
for (auto bit : sigmap(sig_data))
|
for (auto bit : sigmap(sig_data))
|
||||||
if (sigbit_users_count[bit] > 1)
|
if (sigbit_users_count[bit] > 1)
|
||||||
|
@ -230,28 +232,30 @@ struct MemoryDffWorker
|
||||||
if (!en_polarity)
|
if (!en_polarity)
|
||||||
en_data = module->LogicNot(NEW_ID, en_data);
|
en_data = module->LogicNot(NEW_ID, en_data);
|
||||||
disconnect_dff(sig_data);
|
disconnect_dff(sig_data);
|
||||||
cell->setPort(ID::CLK, clk_data);
|
port.clk = clk_data;
|
||||||
cell->setPort(ID::EN, en_data);
|
port.en = en_data;
|
||||||
cell->setPort(ID::DATA, sig_data);
|
port.data = sig_data;
|
||||||
cell->parameters[ID::CLK_ENABLE] = RTLIL::Const(1);
|
port.clk_enable = true;
|
||||||
cell->parameters[ID::CLK_POLARITY] = RTLIL::Const(clk_polarity);
|
port.clk_polarity = clk_polarity;
|
||||||
cell->parameters[ID::TRANSPARENT] = RTLIL::Const(0);
|
port.transparent = false;
|
||||||
|
mem.emit();
|
||||||
log("merged data $dff to cell.\n");
|
log("merged data $dff to cell.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_ff_after_read_merging:;
|
skip_ff_after_read_merging:;
|
||||||
RTLIL::SigSpec clk_addr = RTLIL::SigSpec(RTLIL::State::Sx);
|
RTLIL::SigSpec clk_addr = RTLIL::SigSpec(RTLIL::State::Sx);
|
||||||
RTLIL::SigSpec sig_addr = cell->getPort(ID::ADDR);
|
RTLIL::SigSpec sig_addr = port.addr;
|
||||||
if (find_sig_before_dff(sig_addr, clk_addr, clk_polarity) &&
|
if (find_sig_before_dff(sig_addr, clk_addr, clk_polarity) &&
|
||||||
clk_addr != RTLIL::SigSpec(RTLIL::State::Sx))
|
clk_addr != RTLIL::SigSpec(RTLIL::State::Sx))
|
||||||
{
|
{
|
||||||
cell->setPort(ID::CLK, clk_addr);
|
port.clk = clk_addr;
|
||||||
cell->setPort(ID::EN, State::S1);
|
port.en = State::S1;
|
||||||
cell->setPort(ID::ADDR, sig_addr);
|
port.addr = sig_addr;
|
||||||
cell->parameters[ID::CLK_ENABLE] = RTLIL::Const(1);
|
port.clk_enable = true;
|
||||||
cell->parameters[ID::CLK_POLARITY] = RTLIL::Const(clk_polarity);
|
port.clk_polarity = clk_polarity;
|
||||||
cell->parameters[ID::TRANSPARENT] = RTLIL::Const(1);
|
port.transparent = true;
|
||||||
|
mem.emit();
|
||||||
log("merged address $dff to cell.\n");
|
log("merged address $dff to cell.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -286,9 +290,12 @@ struct MemoryDffWorker
|
||||||
sigbit_users_count[bit]++;
|
sigbit_users_count[bit]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto cell : module->selected_cells())
|
for (auto &mem : Mem::get_selected_memories(module)) {
|
||||||
if (cell->type == ID($memrd) && !cell->parameters[ID::CLK_ENABLE].as_bool())
|
for (int i = 0; i < GetSize(mem.rd_ports); i++) {
|
||||||
handle_rd_cell(cell);
|
if (!mem.rd_ports[i].clk_enable)
|
||||||
|
handle_rd_port(mem, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue