Bugfix in memory_dff

This commit is contained in:
Clifford Wolf 2015-10-31 22:01:41 +01:00
parent ccdbf41be6
commit ddf3e2dc65
2 changed files with 27 additions and 1 deletions

View File

@ -32,6 +32,7 @@ struct MemoryDffWorker
dict<SigBit, SigBit> invbits; dict<SigBit, SigBit> invbits;
dict<SigBit, int> sigbit_users_count; dict<SigBit, int> sigbit_users_count;
dict<SigSpec, Cell*> mux_cells_a, mux_cells_b; dict<SigSpec, Cell*> mux_cells_a, mux_cells_b;
pool<Cell*> forward_merged_dffs, candidate_dffs;
MemoryDffWorker(Module *module) : module(module), sigmap(module) { } MemoryDffWorker(Module *module) : module(module), sigmap(module) { }
@ -46,6 +47,9 @@ struct MemoryDffWorker
for (auto cell : dff_cells) for (auto cell : dff_cells)
{ {
if (after && forward_merged_dffs.count(cell))
continue;
SigSpec this_clk = cell->getPort("\\CLK"); SigSpec this_clk = cell->getPort("\\CLK");
bool this_clk_polarity = cell->parameters["\\CLK_POLARITY"].as_bool(); bool this_clk_polarity = cell->parameters["\\CLK_POLARITY"].as_bool();
@ -71,6 +75,7 @@ struct MemoryDffWorker
bit = d; bit = d;
clk = this_clk; clk = this_clk;
clk_polarity = this_clk_polarity; clk_polarity = this_clk_polarity;
candidate_dffs.insert(cell);
goto replaced_this_bit; goto replaced_this_bit;
} }
@ -87,6 +92,7 @@ struct MemoryDffWorker
RTLIL::SigSpec clk = RTLIL::SigSpec(RTLIL::State::Sx); RTLIL::SigSpec clk = RTLIL::SigSpec(RTLIL::State::Sx);
bool clk_polarity = 0; bool clk_polarity = 0;
candidate_dffs.clear();
RTLIL::SigSpec sig_addr = cell->getPort("\\ADDR"); RTLIL::SigSpec sig_addr = cell->getPort("\\ADDR");
if (!find_sig_before_dff(sig_addr, clk, clk_polarity)) { if (!find_sig_before_dff(sig_addr, clk, clk_polarity)) {
@ -106,13 +112,18 @@ struct MemoryDffWorker
return; return;
} }
if (clk != RTLIL::SigSpec(RTLIL::State::Sx)) { if (clk != RTLIL::SigSpec(RTLIL::State::Sx))
{
for (auto cell : candidate_dffs)
forward_merged_dffs.insert(cell);
cell->setPort("\\CLK", clk); cell->setPort("\\CLK", clk);
cell->setPort("\\ADDR", sig_addr); cell->setPort("\\ADDR", sig_addr);
cell->setPort("\\DATA", sig_data); cell->setPort("\\DATA", sig_data);
cell->setPort("\\EN", sig_en); cell->setPort("\\EN", sig_en);
cell->parameters["\\CLK_ENABLE"] = RTLIL::Const(1); cell->parameters["\\CLK_ENABLE"] = RTLIL::Const(1);
cell->parameters["\\CLK_POLARITY"] = RTLIL::Const(clk_polarity); cell->parameters["\\CLK_POLARITY"] = RTLIL::Const(clk_polarity);
log("merged $dff to cell.\n"); log("merged $dff to cell.\n");
return; return;
} }

View File

@ -228,3 +228,18 @@ module memtest09 (
end end
endmodule endmodule
// ----------------------------------------------------------
module memtest10(input clk, input [5:0] din, output [5:0] dout);
reg [5:0] queue [0:3];
integer i;
always @(posedge clk) begin
queue[0] <= din;
for (i = 1; i < 4; i=i+1) begin
queue[i] <= queue[i-1];
end
end
assign dout = queue[3];
endmodule