3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-13 04:28:18 +00:00

Bug fix in $mem verilog backend + changed tests/bram flow of make test.

This commit is contained in:
luke whittlesey 2015-06-04 14:56:13 -04:00
parent 08f9b38a9c
commit a8fe040906
2 changed files with 20 additions and 16 deletions

View file

@ -38,7 +38,7 @@
USING_YOSYS_NAMESPACE USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN PRIVATE_NAMESPACE_BEGIN
bool norename, noattr, attr2comment, noexpr; bool norename, noattr, attr2comment, noexpr, nomem;
int auto_name_counter, auto_name_offset, auto_name_digits; int auto_name_counter, auto_name_offset, auto_name_digits;
std::map<RTLIL::IdString, int> auto_name_map; std::map<RTLIL::IdString, int> auto_name_map;
std::set<RTLIL::IdString> reg_wires, reg_ct; std::set<RTLIL::IdString> reg_wires, reg_ct;
@ -791,14 +791,13 @@ bool dump_cell_expr(std::ostream &f, std::string indent, RTLIL::Cell *cell)
return true; return true;
} }
if (cell->type == "$mem" && false) // FIXME! if (cell->type == "$mem" && nomem == false)
{ {
RTLIL::IdString memid = cell->parameters["\\MEMID"].decode_string(); RTLIL::IdString memid = cell->parameters["\\MEMID"].decode_string();
std::string mem_id = id(cell->parameters["\\MEMID"].decode_string()); std::string mem_id = id(cell->parameters["\\MEMID"].decode_string());
int abits = cell->parameters["\\ABITS"].as_int(); int abits = cell->parameters["\\ABITS"].as_int();
int size = cell->parameters["\\SIZE"].as_int(); int size = cell->parameters["\\SIZE"].as_int();
int width = cell->parameters["\\WIDTH"].as_int(); int width = cell->parameters["\\WIDTH"].as_int();
int offset = cell->parameters["\\OFFSET"].as_int();
bool use_init = !(RTLIL::SigSpec(cell->parameters["\\INIT"]).is_fully_undef()); bool use_init = !(RTLIL::SigSpec(cell->parameters["\\INIT"]).is_fully_undef());
// for memory block make something like: // for memory block make something like:
@ -807,12 +806,7 @@ bool dump_cell_expr(std::ostream &f, std::string indent, RTLIL::Cell *cell)
// memid[0] <= ... // memid[0] <= ...
// end // end
int mem_val; int mem_val;
RTLIL::Memory memory; f << stringf("%s" "reg [%d:%d] %s [%d:%d];\n", indent.c_str(), width-1, 0, mem_id.c_str(), size-1, 0);
memory.name = memid;
memory.width = width;
memory.start_offset = offset;
memory.size = size;
dump_memory(f, indent.c_str(), &memory);
if (use_init) if (use_init)
{ {
f << stringf("%s" "initial begin\n", indent.c_str()); f << stringf("%s" "initial begin\n", indent.c_str());
@ -844,7 +838,7 @@ bool dump_cell_expr(std::ostream &f, std::string indent, RTLIL::Cell *cell)
// temp_id <= array_reg[r_addr]; // temp_id <= array_reg[r_addr];
// assign r_data = temp_id; // assign r_data = temp_id;
std::string temp_id = next_auto_id(); std::string temp_id = next_auto_id();
f << stringf("%s" "reg [%d:0] %s;\n", indent.c_str(), sig_rd_addr.size() - 1, temp_id.c_str()); f << stringf("%s" "reg [%d:0] %s;\n", indent.c_str(), sig_rd_data.size() - 1, temp_id.c_str());
f << stringf("%s" "always @(%sedge ", indent.c_str(), rd_clk_posedge ? "pos" : "neg"); f << stringf("%s" "always @(%sedge ", indent.c_str(), rd_clk_posedge ? "pos" : "neg");
dump_sigspec(f, sig_rd_clk); dump_sigspec(f, sig_rd_clk);
f << stringf(")\n"); f << stringf(")\n");
@ -886,7 +880,7 @@ bool dump_cell_expr(std::ostream &f, std::string indent, RTLIL::Cell *cell)
int nwrite_ports = cell->parameters["\\WR_PORTS"].as_int(); int nwrite_ports = cell->parameters["\\WR_PORTS"].as_int();
RTLIL::SigSpec sig_wr_clk, sig_wr_data, sig_wr_addr, sig_wr_en, sig_wr_en_bit; RTLIL::SigSpec sig_wr_clk, sig_wr_data, sig_wr_addr, sig_wr_en, sig_wr_en_bit;
RTLIL::SigBit last_bit, current_bit; RTLIL::SigBit last_bit;
bool wr_clk_posedge; bool wr_clk_posedge;
RTLIL::SigSpec lof_wen; RTLIL::SigSpec lof_wen;
dict<RTLIL::SigSpec, int> wen_to_width; dict<RTLIL::SigSpec, int> wen_to_width;
@ -910,9 +904,8 @@ bool dump_cell_expr(std::ostream &f, std::string indent, RTLIL::Cell *cell)
lof_wen = RTLIL::SigSpec(last_bit); lof_wen = RTLIL::SigSpec(last_bit);
wen_to_width.clear(); wen_to_width.clear();
wen_to_width[last_bit] = 0; wen_to_width[last_bit] = 0;
for (int j=0; j<width; j++) for (auto &current_bit : sig_wr_en.bits())
{ {
current_bit = sig_wr_en.extract(j);
if (sigmap(current_bit) == sigmap(last_bit)){ if (sigmap(current_bit) == sigmap(last_bit)){
wen_to_width[current_bit] += 1; wen_to_width[current_bit] += 1;
} else { } else {
@ -924,7 +917,7 @@ bool dump_cell_expr(std::ostream &f, std::string indent, RTLIL::Cell *cell)
// make something like: // make something like:
// always @(posedge clk) // always @(posedge clk)
// if (wr_en_bit) // if (wr_en_bit)
// memid[w_addr][??] <= w_data[??]; // memid[w_addr][??] <= w_data[??];
// ... // ...
n = 0; n = 0;
for (auto &wen_bit : lof_wen) { for (auto &wen_bit : lof_wen) {
@ -1292,6 +1285,10 @@ struct VerilogBackend : public Backend {
log(" only write selected modules. modules must be selected entirely or\n"); log(" only write selected modules. modules must be selected entirely or\n");
log(" not at all.\n"); log(" not at all.\n");
log("\n"); log("\n");
log(" -nomem\n");
log(" do not create verilog code for $mem cells. This is only used for\n");
log(" testing.\n");
log("\n");
} }
virtual void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) virtual void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design)
{ {
@ -1301,6 +1298,7 @@ struct VerilogBackend : public Backend {
noattr = false; noattr = false;
attr2comment = false; attr2comment = false;
noexpr = false; noexpr = false;
nomem = false;
bool blackboxes = false; bool blackboxes = false;
bool selected = false; bool selected = false;
@ -1358,6 +1356,10 @@ struct VerilogBackend : public Backend {
selected = true; selected = true;
continue; continue;
} }
if (arg == "-nomem") {
nomem = true;
continue;
}
break; break;
} }
extra_args(f, filename, args, argidx); extra_args(f, filename, args, argidx);

View file

@ -1,7 +1,9 @@
#!/bin/bash #!/bin/bash
set -e set -e
../../yosys -qq -p "proc; opt; memory -nomap -bram temp/brams_${2}.txt; opt -fast -full" \ ../../yosys -qq -p "proc; opt; memory -nomap -bram temp/brams_${2}.txt; opt -fast -full; write_verilog temp/synth_${1}_${2}_stage0.v" \
-l temp/synth_${1}_${2}.log -o temp/synth_${1}_${2}.v temp/brams_${1}.v -l temp/synth_${1}_${2}_stage0.log temp/brams_${1}.v
../../yosys -qq -p "proc; opt; memory -nomap; opt -fast -full; write_verilog -nomem temp/synth_${1}_${2}.v" \
-l temp/synth_${1}_${2}.log temp/synth_${1}_${2}_stage0.v
iverilog -Dvcd_file=\"temp/tb_${1}_${2}.vcd\" -DSIMLIB_MEMDELAY=1ns -o temp/tb_${1}_${2}.tb temp/brams_${1}_tb.v \ iverilog -Dvcd_file=\"temp/tb_${1}_${2}.vcd\" -DSIMLIB_MEMDELAY=1ns -o temp/tb_${1}_${2}.tb temp/brams_${1}_tb.v \
temp/brams_${1}_ref.v temp/synth_${1}_${2}.v temp/brams_${2}.v ../../techlibs/common/simlib.v temp/brams_${1}_ref.v temp/synth_${1}_${2}.v temp/brams_${2}.v ../../techlibs/common/simlib.v
temp/tb_${1}_${2}.tb > temp/tb_${1}_${2}.txt temp/tb_${1}_${2}.tb > temp/tb_${1}_${2}.txt