1
0

memgen: also randomize ren and rand register

This commit is contained in:
Yunsup Lee 2017-08-08 20:41:53 -07:00
parent 97ad528a32
commit 8705b0e070

View File

@ -101,6 +101,13 @@ def gen_mem(name, width, depth, mask_gran, mask_seg, ports):
sequential.append(' if (%s) reg_%saddr <= %saddr;' % (en, prefix, prefix)) sequential.append(' if (%s) reg_%saddr <= %saddr;' % (en, prefix, prefix))
combinational.append('`ifdef RANDOMIZE_GARBAGE_ASSIGN') combinational.append('`ifdef RANDOMIZE_GARBAGE_ASSIGN')
combinational.append('reg [%d:0] %srandom;' % (((width-1)//32+1)*32-1, prefix)) combinational.append('reg [%d:0] %srandom;' % (((width-1)//32+1)*32-1, prefix))
combinational.append('`ifdef RANDOMIZE_MEM_INIT')
combinational.append(' initial begin')
combinational.append(' #0.002 begin end')
combinational.append(' reg_%sren = $random;' % prefix)
combinational.append(' %srandom = {%s};' % (prefix, ', '.join(['$random'] * ((width-1)//32+1))))
combinational.append(' end')
combinational.append('`endif')
combinational.append('always @(posedge %sclk) %srandom <= {%s};' % (prefix, prefix, ', '.join(['$random'] * ((width-1)//32+1)))) combinational.append('always @(posedge %sclk) %srandom <= {%s};' % (prefix, prefix, ', '.join(['$random'] * ((width-1)//32+1))))
combinational.append('assign %s = reg_%sren ? ram[reg_%saddr] : %srandom[%d:0];' % (data, prefix, prefix, prefix, width-1)) combinational.append('assign %s = reg_%sren ? ram[reg_%saddr] : %srandom[%d:0];' % (data, prefix, prefix, prefix, width-1))
combinational.append('`else') combinational.append('`else')