data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v
1: b'%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:80: syntax error, unexpected \'.\'\n        .A          (icache_data_idx[LOCAL_DATA_ADDR_WIDTH-1:0]  ),\n        ^\n%Warning-STMTDLY: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:110: Unsupported: Ignoring delay on this delayed statement.\n  #(10/2) icache_data_clk = ~icache_data_clk;\n  ^\n                  ... Use "/* verilator lint_off STMTDLY */" and lint_on around source to disable this message.\n%Warning-STMTDLY: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:112: Unsupported: Ignoring delay on this delayed statement.\n  #(10/2) icache_tag_clk = ~icache_tag_clk;\n  ^\n%Warning-STMTDLY: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:114: Unsupported: Ignoring delay on this delayed statement.\n  #(10/2) forever_clk    = ~forever_clk;\n  ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:134: syntax error, unexpected \'@\'\nrepeat(50)@(posedge icache_data_clk)\n          ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:143: syntax error, unexpected \'@\'\n    @(posedge icache_data_clk)\n    ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:149: syntax error, unexpected \'@\'\n    @(posedge icache_data_clk)\n    ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:153: syntax error, unexpected \'@\'\n    @(posedge icache_data_clk)\n    ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:158: syntax error, unexpected \'@\'\n        repeat(10)@(posedge icache_data_clk)\n                  ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:164: syntax error, unexpected \'=\', expecting IDENTIFIER\nicache_data_cen = 1;\n                ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:171: syntax error, unexpected \'@\'\n    @(posedge icache_data_clk)\n    ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:199: syntax error, unexpected \'@\'\n    @(posedge icache_data_clk)\n    ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:228: syntax error, unexpected \'@\'\n    @(posedge icache_data_clk)\n    ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:242: syntax error, unexpected $display\n        $display("data array read/write test fail when addr is %d\\n", i);\n        ^~~~~~~~\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:254: syntax error, unexpected repeat\nrepeat(50)@(posedge icache_tag_clk)\n^~~~~~\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:262: syntax error, unexpected \'@\'\n    @(posedge icache_tag_clk)\n    ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:290: syntax error, unexpected \'@\'\n    @(posedge icache_tag_clk)\n    ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:318: syntax error, unexpected \'@\'\n    @(posedge icache_tag_clk)\n    ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:347: syntax error, unexpected \'@\'\n    @(posedge icache_tag_clk)\n    ^\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:361: syntax error, unexpected $display\n        $display("tag array read/write test fail when addr is %d\\n", i);\n        ^~~~~~~~\n%Error: data/full_repos/permissive/418750043/smart_run/impl/MEM_INTF/c906_icache_mem_test.v:365: syntax error, unexpected \'=\', expecting IDENTIFIER\n        icache_mem_test_pass = 1;\n                             ^\n%Error: Cannot continue\n'
module c906_icache_mem_test(icache_mem_test_pass);

output icache_mem_test_pass;
`ifdef ICACHE_8K
    parameter LOCAL_DATA_ADDR_WIDTH  = 9;
    parameter LOCAL_TAG_ADDR_WIDTH   = 6;
`elsif ICACHE_16K
    parameter LOCAL_DATA_ADDR_WIDTH  = 10
    parameter LOCAL_TAG_ADDR_WIDTH   = 7;
`elsif ICACHE_32K
    parameter LOCAL_DATA_ADDR_WIDTH  = 11;
    parameter LOCAL_TAG_ADDR_WIDTH   = 8;
`elsif ICACHE_64K
    parameter LOCAL_DATA_ADDR_WIDTH  = 12;
    parameter LOCAL_TAG_ADDR_WIDTH   = 9;
`endif
    
parameter LOCAL_DATA_DATA_WIDTH  = 32;
parameter LOCAL_DATA_WE_WIDTH    = 32;
parameter LOCAL_TAG_DATA_WIDTH   = 59;
parameter LOCAL_TAG_WE_WIDTH     = 59;

reg                               forever_clk;

reg  [LOCAL_DATA_ADDR_WIDTH-1:0]  icache_data_idx;
reg  [LOCAL_DATA_DATA_WIDTH-1:0]  icache_data_din;
reg  [LOCAL_DATA_DATA_WIDTH-1:0]  icache_data_dout;
reg  [LOCAL_DATA_DATA_WIDTH-1:0]  data_mask;
reg  [LOCAL_DATA_DATA_WIDTH-1:0]  data_mask_ff;
reg  [LOCAL_DATA_DATA_WIDTH-1:0]  golden_data;
reg                               icache_data_gwen;
reg  [LOCAL_DATA_WE_WIDTH-1:0]    icache_data_wen;
reg                               icache_data_cen;
reg                               icache_data_clk;

reg  [LOCAL_TAG_ADDR_WIDTH-1:0]   icache_tag_idx;
reg  [LOCAL_TAG_DATA_WIDTH-1:0]   icache_tag_din;
reg  [LOCAL_TAG_DATA_WIDTH-1:0]   icache_tag_dout;
reg  [LOCAL_TAG_DATA_WIDTH-1:0]   tag_mask;
reg  [LOCAL_TAG_DATA_WIDTH-1:0]   tag_mask_ff;
reg  [LOCAL_TAG_DATA_WIDTH-1:0]   golden_tag;
reg                               icache_tag_gwen;
reg  [LOCAL_TAG_WE_WIDTH-1:0]     icache_tag_wen;
reg                               icache_tag_cen;
reg                               icache_tag_clk;

reg                               icache_mem_test_pass;



`ifdef ICACHE_8K
    aq_umc_spsram_512x32 x_data_array(
`endif
`ifdef ICACHE_16K
    aq_umc_spsram_1024x32 x_data_array(
`endif
`ifdef ICACHE_32K
    aq_umc_spsram_2048x32 x_data_array(
`endif
`ifdef ICACHE_64K
    aq_umc_spsram_4096x32 x_data_array(
`endif
        .A          (icache_data_idx[LOCAL_DATA_ADDR_WIDTH-1:0]  ),
        .CEN        (icache_data_cen                             ),
        .CLK        (icache_data_clk                             ),
        .D          (icache_data_din[LOCAL_DATA_DATA_WIDTH-1:0]  ),
        .GWEN       (icache_data_gwen                            ),
        .Q          (icache_data_dout[LOCAL_DATA_DATA_WIDTH-1:0] ),
        .WEN        (icache_data_wen[LOCAL_DATA_WE_WIDTH-1:0]    )
    );

`ifdef ICACHE_8K
    aq_umc_spsram_64x59 x_tag_array(
`endif
`ifdef ICACHE_16K
    aq_umc_spsram_128x59 x_tag_array(
`endif
`ifdef ICACHE_32K
    aq_umc_spsram_256x59 x_tag_array(
`endif
`ifdef ICACHE_64K
    aq_umc_spsram_512x59 x_tag_array(
`endif
        .A          (icache_tag_idx[LOCAL_TAG_ADDR_WIDTH-1:0]  ),
        .CEN        (icache_tag_cen                            ),
        .CLK        (icache_tag_clk                            ),
        .D          (icache_tag_din[LOCAL_TAG_DATA_WIDTH-1:0]  ),
        .GWEN       (icache_tag_gwen                           ),
        .Q          (icache_tag_dout[LOCAL_TAG_DATA_WIDTH-1:0] ),
        .WEN        (icache_tag_wen[LOCAL_TAG_WE_WIDTH-1:0]    )
    );
always
  #(`CLK_PERIOD/2) icache_data_clk = ~icache_data_clk;
always
  #(`CLK_PERIOD/2) icache_tag_clk = ~icache_tag_clk;
always
  #(`CLK_PERIOD/2) forever_clk    = ~forever_clk;

always@(posedge icache_data_clk)
begin
    data_mask <= icache_data_wen[LOCAL_DATA_WE_WIDTH-1:0];
end

always@(posedge icache_tag_clk)
begin
    tag_mask <= icache_tag_wen[LOCAL_TAG_WE_WIDTH-1:0];
end

integer i;

initial
begin
icache_data_clk = 0;
icache_tag_clk = 0;
forever_clk = 0;
icache_mem_test_pass = 0;
repeat(50)@(posedge icache_data_clk)

icache_data_cen = 1;
icache_data_wen = {LOCAL_DATA_WE_WIDTH{1'b1}};
icache_data_gwen = 1'b1;
icache_data_idx = 0;
icache_data_din = 0;
for(i=0;i<10;i=i+1)
begin
    @(posedge icache_data_clk)
    icache_data_cen <= 0;
    icache_data_gwen <= 1'b0;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b0}};
    icache_data_idx <= {LOCAL_DATA_ADDR_WIDTH{1'b0}} + i;
    icache_data_din <= {LOCAL_DATA_DATA_WIDTH{1'b0}} + i;
    @(posedge icache_data_clk)
    icache_data_gwen <= 1'b1;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b1}};
    golden_data      <= icache_data_din;
    @(posedge icache_data_clk)
    @(posedge icache_data_clk)
    if(icache_data_dout != golden_data)
    begin
        $display("data array cen == 0 test fail when i is %d!!!\n", i);
        repeat(10)@(posedge icache_data_clk)
        $finish;
    end
end


icache_data_cen = 1;
icache_data_gwen = 1'b1;
icache_data_wen = {LOCAL_DATA_WE_WIDTH{1'b1}};
icache_data_idx = 0;
icache_data_din = 0;
for(i=10;i<20;i=i+1)
begin
    @(posedge icache_data_clk)
    icache_data_cen <= 1;
    icache_data_gwen <= 1'b0;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b0}};
    icache_data_idx <= {LOCAL_DATA_ADDR_WIDTH{1'b0}} + i;
    icache_data_din <= {LOCAL_DATA_DATA_WIDTH{1'b0}} + i;
    @(posedge icache_data_clk)
    icache_data_gwen <= 1'b1;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b1}};
    golden_data      <= icache_data_din;
    @(posedge icache_data_clk)
    @(posedge icache_data_clk)
    if(icache_data_dout == golden_data)
    begin
        $display("data array cen == 1 test fail when i is %d!!!\n", i);
        repeat(10)@(posedge icache_data_clk)
        $finish;
    end
end


icache_data_cen = 1;
icache_data_gwen = 1'b1;
icache_data_wen = {LOCAL_DATA_WE_WIDTH{1'b1}};
icache_data_idx = 0;
icache_data_din = 0;
for(i=0;i<LOCAL_DATA_WE_WIDTH;i=i+1)
begin
    @(posedge icache_data_clk)
    icache_data_idx  <= 20;
    icache_data_gwen <= 1'b0;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b1}} >> i;
    icache_data_din  <= {LOCAL_DATA_DATA_WIDTH{1'b1}};
    @(posedge icache_data_clk)
    icache_data_gwen <= 1'b1;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b1}};
    golden_data      <= icache_data_din;
    data_mask_ff     <= data_mask;
    @(posedge icache_data_clk)
    @(posedge icache_data_clk)
    if(golden_data != icache_data_dout & (~data_mask_ff))
    begin
        $display("data array wen test fail when i is %d, golden_data is 0x%h, data out is 0x%h\n", i, golden_data, icache_data_dout);
        repeat(10)@(posedge icache_data_clk)
        $finish;
    end
end



icache_data_cen = 1;
icache_data_gwen = 1'b1;
icache_data_wen = {LOCAL_DATA_WE_WIDTH{1'b1}};
icache_data_idx = 0;
icache_data_din = 0;
for(i=0;i<={LOCAL_DATA_ADDR_WIDTH{1'b1}};i=i+1)
begin
    @(posedge icache_data_clk)
    icache_data_cen  <= 0;
    icache_data_gwen <= 1'b0;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b0}};
    icache_data_idx  <= {LOCAL_DATA_ADDR_WIDTH{1'b0}} + i;
    icache_data_din  <= {LOCAL_DATA_DATA_WIDTH{1'b1}};
    @(posedge icache_data_clk)
    icache_data_gwen <=1'b1;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b1}};
    @(posedge icache_data_clk)
    @(posedge icache_data_clk)
    icache_data_idx  <= {LOCAL_DATA_ADDR_WIDTH{1'b0}} + i + 1;
    if(icache_data_dout != {LOCAL_DATA_DATA_WIDTH{1'b1}})
    begin
        $display("data array read/write test fail when addr is %d\n", i);
        repeat(10)@(posedge icache_data_clk)
        $finish;
    end
end







repeat(50)@(posedge icache_tag_clk)
icache_tag_cen = 1;
icache_tag_gwen = 1'b1;
icache_tag_wen = {LOCAL_TAG_WE_WIDTH{1'b1}};
icache_tag_idx = 0;
icache_tag_din = 0;
for(i=0;i<10;i=i+1)
begin
    @(posedge icache_tag_clk)
    icache_tag_cen <= 0;
    icache_tag_gwen <= 1'b0;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b0}};
    icache_tag_idx <= {LOCAL_TAG_ADDR_WIDTH{1'b0}} + i;
    icache_tag_din <= {LOCAL_TAG_DATA_WIDTH{1'b1}} - i;
    @(posedge icache_tag_clk)
    icache_tag_gwen <= 1'b1;
    icache_tag_wen  <= {LOCAL_TAG_WE_WIDTH{1'b1}};
    golden_tag      <= icache_tag_din;
    @(posedge icache_tag_clk)
    @(posedge icache_tag_clk)
    if(icache_tag_dout != golden_tag)
    begin
        $display("tag array cen == 0 test fail when i is %d!!!\n", i);
        repeat(10)@(posedge icache_tag_clk)
        $finish;
    end
end


icache_tag_cen = 1;
icache_tag_gwen = 1'b1;
icache_tag_wen = {LOCAL_TAG_WE_WIDTH{1'b1}};
icache_tag_idx = 0;
icache_tag_din = 0;
for(i=10;i<20;i=i+1)
begin
    @(posedge icache_tag_clk)
    icache_tag_cen <= 1;
    icache_tag_gwen <= 1'b0;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b0}};
    icache_tag_idx <= {LOCAL_TAG_ADDR_WIDTH{1'b0}} + i;
    icache_tag_din <= {LOCAL_TAG_DATA_WIDTH{1'b0}} + i;
    @(posedge icache_tag_clk)
    icache_tag_gwen <= 1'b1;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b1}};
    golden_tag      <= icache_tag_din;
    @(posedge icache_tag_clk)
    @(posedge icache_tag_clk)
    if(icache_tag_dout == golden_tag)
    begin
        $display("tag array cen == 1 test fail when i is %d!!!\n", i);
        repeat(10)@(posedge icache_tag_clk)
        $finish;
    end
end


icache_tag_cen = 1;
icache_tag_gwen = 1'b1;
icache_tag_wen = {LOCAL_TAG_WE_WIDTH{1'b1}};
icache_tag_idx = 0;
icache_tag_din = 0;
for(i=0;i<LOCAL_TAG_WE_WIDTH;i=i+1)
begin
    @(posedge icache_tag_clk)
    icache_tag_idx  <= 20;
    icache_tag_gwen <= 1'b0;
    icache_tag_wen  <= {LOCAL_TAG_WE_WIDTH{1'b1}} >> i;
    icache_tag_din  <= {LOCAL_TAG_DATA_WIDTH{1'b1}};
    @(posedge icache_tag_clk)
    icache_tag_gwen <= 1'b1;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b1}};
    golden_tag      <= icache_tag_din;
    tag_mask_ff     <= tag_mask;
    @(posedge icache_tag_clk)
    @(posedge icache_tag_clk)
    if(golden_tag != icache_tag_dout & (~tag_mask_ff))
    begin
        $display("tag array wen test fail when i is %d, golden_data is 0x%h, data out is 0x%h\n", i, golden_tag, icache_tag_dout);
        repeat(10)@(posedge icache_tag_clk)
        $finish;
    end
end



icache_tag_cen = 1;
icache_tag_gwen = 1'b1;
icache_tag_wen = {LOCAL_TAG_WE_WIDTH{1'b1}};
icache_tag_idx = 0;
icache_tag_din = 0;
for(i=0;i<={LOCAL_TAG_ADDR_WIDTH{1'b1}};i=i+1)
begin
    @(posedge icache_tag_clk)
    icache_tag_cen  <= 0;
    icache_tag_gwen <= 1'b0;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b0}};
    icache_tag_idx  <= {LOCAL_TAG_ADDR_WIDTH{1'b0}} + i;
    icache_tag_din  <= {LOCAL_TAG_DATA_WIDTH{1'b1}};
    @(posedge icache_tag_clk)
    icache_tag_gwen <= 1'b1;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b1}};
    @(posedge icache_tag_clk)
    @(posedge icache_tag_clk)
    icache_tag_idx  <= {LOCAL_TAG_ADDR_WIDTH{1'b0}} + i + 1;
    if(icache_tag_dout != {LOCAL_TAG_DATA_WIDTH{1'b1}})
    begin
        $display("tag array read/write test fail when addr is %d\n", i);
        repeat(10)@(posedge icache_tag_clk)
        $finish;
    end
        icache_mem_test_pass = 1;
end

end




endmodule
module c906_icache_mem_test(icache_mem_test_pass);


output icache_mem_test_pass;
`ifdef ICACHE_8K
    parameter LOCAL_DATA_ADDR_WIDTH  = 9;
    parameter LOCAL_TAG_ADDR_WIDTH   = 6;
`elsif ICACHE_16K
    parameter LOCAL_DATA_ADDR_WIDTH  = 10
    parameter LOCAL_TAG_ADDR_WIDTH   = 7;
`elsif ICACHE_32K
    parameter LOCAL_DATA_ADDR_WIDTH  = 11;
    parameter LOCAL_TAG_ADDR_WIDTH   = 8;
`elsif ICACHE_64K
    parameter LOCAL_DATA_ADDR_WIDTH  = 12;
    parameter LOCAL_TAG_ADDR_WIDTH   = 9;
`endif
    
parameter LOCAL_DATA_DATA_WIDTH  = 32;
parameter LOCAL_DATA_WE_WIDTH    = 32;
parameter LOCAL_TAG_DATA_WIDTH   = 59;
parameter LOCAL_TAG_WE_WIDTH     = 59;

reg                               forever_clk;

reg  [LOCAL_DATA_ADDR_WIDTH-1:0]  icache_data_idx;
reg  [LOCAL_DATA_DATA_WIDTH-1:0]  icache_data_din;
reg  [LOCAL_DATA_DATA_WIDTH-1:0]  icache_data_dout;
reg  [LOCAL_DATA_DATA_WIDTH-1:0]  data_mask;
reg  [LOCAL_DATA_DATA_WIDTH-1:0]  data_mask_ff;
reg  [LOCAL_DATA_DATA_WIDTH-1:0]  golden_data;
reg                               icache_data_gwen;
reg  [LOCAL_DATA_WE_WIDTH-1:0]    icache_data_wen;
reg                               icache_data_cen;
reg                               icache_data_clk;

reg  [LOCAL_TAG_ADDR_WIDTH-1:0]   icache_tag_idx;
reg  [LOCAL_TAG_DATA_WIDTH-1:0]   icache_tag_din;
reg  [LOCAL_TAG_DATA_WIDTH-1:0]   icache_tag_dout;
reg  [LOCAL_TAG_DATA_WIDTH-1:0]   tag_mask;
reg  [LOCAL_TAG_DATA_WIDTH-1:0]   tag_mask_ff;
reg  [LOCAL_TAG_DATA_WIDTH-1:0]   golden_tag;
reg                               icache_tag_gwen;
reg  [LOCAL_TAG_WE_WIDTH-1:0]     icache_tag_wen;
reg                               icache_tag_cen;
reg                               icache_tag_clk;

reg                               icache_mem_test_pass;



`ifdef ICACHE_8K
    aq_umc_spsram_512x32 x_data_array(
`endif
`ifdef ICACHE_16K
    aq_umc_spsram_1024x32 x_data_array(
`endif
`ifdef ICACHE_32K
    aq_umc_spsram_2048x32 x_data_array(
`endif
`ifdef ICACHE_64K
    aq_umc_spsram_4096x32 x_data_array(
`endif
        .A          (icache_data_idx[LOCAL_DATA_ADDR_WIDTH-1:0]  ),
        .CEN        (icache_data_cen                             ),
        .CLK        (icache_data_clk                             ),
        .D          (icache_data_din[LOCAL_DATA_DATA_WIDTH-1:0]  ),
        .GWEN       (icache_data_gwen                            ),
        .Q          (icache_data_dout[LOCAL_DATA_DATA_WIDTH-1:0] ),
        .WEN        (icache_data_wen[LOCAL_DATA_WE_WIDTH-1:0]    )
    );

`ifdef ICACHE_8K
    aq_umc_spsram_64x59 x_tag_array(
`endif
`ifdef ICACHE_16K
    aq_umc_spsram_128x59 x_tag_array(
`endif
`ifdef ICACHE_32K
    aq_umc_spsram_256x59 x_tag_array(
`endif
`ifdef ICACHE_64K
    aq_umc_spsram_512x59 x_tag_array(
`endif
        .A          (icache_tag_idx[LOCAL_TAG_ADDR_WIDTH-1:0]  ),
        .CEN        (icache_tag_cen                            ),
        .CLK        (icache_tag_clk                            ),
        .D          (icache_tag_din[LOCAL_TAG_DATA_WIDTH-1:0]  ),
        .GWEN       (icache_tag_gwen                           ),
        .Q          (icache_tag_dout[LOCAL_TAG_DATA_WIDTH-1:0] ),
        .WEN        (icache_tag_wen[LOCAL_TAG_WE_WIDTH-1:0]    )
    );
always
  #(`CLK_PERIOD/2) icache_data_clk = ~icache_data_clk;
always
  #(`CLK_PERIOD/2) icache_tag_clk = ~icache_tag_clk;
always
  #(`CLK_PERIOD/2) forever_clk    = ~forever_clk;

always@(posedge icache_data_clk)
begin
    data_mask <= icache_data_wen[LOCAL_DATA_WE_WIDTH-1:0];
end

always@(posedge icache_tag_clk)
begin
    tag_mask <= icache_tag_wen[LOCAL_TAG_WE_WIDTH-1:0];
end

integer i;

initial
begin
icache_data_clk = 0;
icache_tag_clk = 0;
forever_clk = 0;
icache_mem_test_pass = 0;
repeat(50)@(posedge icache_data_clk)

icache_data_cen = 1;
icache_data_wen = {LOCAL_DATA_WE_WIDTH{1'b1}};
icache_data_gwen = 1'b1;
icache_data_idx = 0;
icache_data_din = 0;
for(i=0;i<10;i=i+1)
begin
    @(posedge icache_data_clk)
    icache_data_cen <= 0;
    icache_data_gwen <= 1'b0;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b0}};
    icache_data_idx <= {LOCAL_DATA_ADDR_WIDTH{1'b0}} + i;
    icache_data_din <= {LOCAL_DATA_DATA_WIDTH{1'b0}} + i;
    @(posedge icache_data_clk)
    icache_data_gwen <= 1'b1;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b1}};
    golden_data      <= icache_data_din;
    @(posedge icache_data_clk)
    @(posedge icache_data_clk)
    if(icache_data_dout != golden_data)
    begin
        $display("data array cen == 0 test fail when i is %d!!!\n", i);
        repeat(10)@(posedge icache_data_clk)
        $finish;
    end
end


icache_data_cen = 1;
icache_data_gwen = 1'b1;
icache_data_wen = {LOCAL_DATA_WE_WIDTH{1'b1}};
icache_data_idx = 0;
icache_data_din = 0;
for(i=10;i<20;i=i+1)
begin
    @(posedge icache_data_clk)
    icache_data_cen <= 1;
    icache_data_gwen <= 1'b0;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b0}};
    icache_data_idx <= {LOCAL_DATA_ADDR_WIDTH{1'b0}} + i;
    icache_data_din <= {LOCAL_DATA_DATA_WIDTH{1'b0}} + i;
    @(posedge icache_data_clk)
    icache_data_gwen <= 1'b1;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b1}};
    golden_data      <= icache_data_din;
    @(posedge icache_data_clk)
    @(posedge icache_data_clk)
    if(icache_data_dout == golden_data)
    begin
        $display("data array cen == 1 test fail when i is %d!!!\n", i);
        repeat(10)@(posedge icache_data_clk)
        $finish;
    end
end


icache_data_cen = 1;
icache_data_gwen = 1'b1;
icache_data_wen = {LOCAL_DATA_WE_WIDTH{1'b1}};
icache_data_idx = 0;
icache_data_din = 0;
for(i=0;i<LOCAL_DATA_WE_WIDTH;i=i+1)
begin
    @(posedge icache_data_clk)
    icache_data_idx  <= 20;
    icache_data_gwen <= 1'b0;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b1}} >> i;
    icache_data_din  <= {LOCAL_DATA_DATA_WIDTH{1'b1}};
    @(posedge icache_data_clk)
    icache_data_gwen <= 1'b1;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b1}};
    golden_data      <= icache_data_din;
    data_mask_ff     <= data_mask;
    @(posedge icache_data_clk)
    @(posedge icache_data_clk)
    if(golden_data != icache_data_dout & (~data_mask_ff))
    begin
        $display("data array wen test fail when i is %d, golden_data is 0x%h, data out is 0x%h\n", i, golden_data, icache_data_dout);
        repeat(10)@(posedge icache_data_clk)
        $finish;
    end
end



icache_data_cen = 1;
icache_data_gwen = 1'b1;
icache_data_wen = {LOCAL_DATA_WE_WIDTH{1'b1}};
icache_data_idx = 0;
icache_data_din = 0;
for(i=0;i<={LOCAL_DATA_ADDR_WIDTH{1'b1}};i=i+1)
begin
    @(posedge icache_data_clk)
    icache_data_cen  <= 0;
    icache_data_gwen <= 1'b0;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b0}};
    icache_data_idx  <= {LOCAL_DATA_ADDR_WIDTH{1'b0}} + i;
    icache_data_din  <= {LOCAL_DATA_DATA_WIDTH{1'b1}};
    @(posedge icache_data_clk)
    icache_data_gwen <=1'b1;
    icache_data_wen <= {LOCAL_DATA_WE_WIDTH{1'b1}};
    @(posedge icache_data_clk)
    @(posedge icache_data_clk)
    icache_data_idx  <= {LOCAL_DATA_ADDR_WIDTH{1'b0}} + i + 1;
    if(icache_data_dout != {LOCAL_DATA_DATA_WIDTH{1'b1}})
    begin
        $display("data array read/write test fail when addr is %d\n", i);
        repeat(10)@(posedge icache_data_clk)
        $finish;
    end
end







repeat(50)@(posedge icache_tag_clk)
icache_tag_cen = 1;
icache_tag_gwen = 1'b1;
icache_tag_wen = {LOCAL_TAG_WE_WIDTH{1'b1}};
icache_tag_idx = 0;
icache_tag_din = 0;
for(i=0;i<10;i=i+1)
begin
    @(posedge icache_tag_clk)
    icache_tag_cen <= 0;
    icache_tag_gwen <= 1'b0;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b0}};
    icache_tag_idx <= {LOCAL_TAG_ADDR_WIDTH{1'b0}} + i;
    icache_tag_din <= {LOCAL_TAG_DATA_WIDTH{1'b1}} - i;
    @(posedge icache_tag_clk)
    icache_tag_gwen <= 1'b1;
    icache_tag_wen  <= {LOCAL_TAG_WE_WIDTH{1'b1}};
    golden_tag      <= icache_tag_din;
    @(posedge icache_tag_clk)
    @(posedge icache_tag_clk)
    if(icache_tag_dout != golden_tag)
    begin
        $display("tag array cen == 0 test fail when i is %d!!!\n", i);
        repeat(10)@(posedge icache_tag_clk)
        $finish;
    end
end


icache_tag_cen = 1;
icache_tag_gwen = 1'b1;
icache_tag_wen = {LOCAL_TAG_WE_WIDTH{1'b1}};
icache_tag_idx = 0;
icache_tag_din = 0;
for(i=10;i<20;i=i+1)
begin
    @(posedge icache_tag_clk)
    icache_tag_cen <= 1;
    icache_tag_gwen <= 1'b0;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b0}};
    icache_tag_idx <= {LOCAL_TAG_ADDR_WIDTH{1'b0}} + i;
    icache_tag_din <= {LOCAL_TAG_DATA_WIDTH{1'b0}} + i;
    @(posedge icache_tag_clk)
    icache_tag_gwen <= 1'b1;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b1}};
    golden_tag      <= icache_tag_din;
    @(posedge icache_tag_clk)
    @(posedge icache_tag_clk)
    if(icache_tag_dout == golden_tag)
    begin
        $display("tag array cen == 1 test fail when i is %d!!!\n", i);
        repeat(10)@(posedge icache_tag_clk)
        $finish;
    end
end


icache_tag_cen = 1;
icache_tag_gwen = 1'b1;
icache_tag_wen = {LOCAL_TAG_WE_WIDTH{1'b1}};
icache_tag_idx = 0;
icache_tag_din = 0;
for(i=0;i<LOCAL_TAG_WE_WIDTH;i=i+1)
begin
    @(posedge icache_tag_clk)
    icache_tag_idx  <= 20;
    icache_tag_gwen <= 1'b0;
    icache_tag_wen  <= {LOCAL_TAG_WE_WIDTH{1'b1}} >> i;
    icache_tag_din  <= {LOCAL_TAG_DATA_WIDTH{1'b1}};
    @(posedge icache_tag_clk)
    icache_tag_gwen <= 1'b1;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b1}};
    golden_tag      <= icache_tag_din;
    tag_mask_ff     <= tag_mask;
    @(posedge icache_tag_clk)
    @(posedge icache_tag_clk)
    if(golden_tag != icache_tag_dout & (~tag_mask_ff))
    begin
        $display("tag array wen test fail when i is %d, golden_data is 0x%h, data out is 0x%h\n", i, golden_tag, icache_tag_dout);
        repeat(10)@(posedge icache_tag_clk)
        $finish;
    end
end



icache_tag_cen = 1;
icache_tag_gwen = 1'b1;
icache_tag_wen = {LOCAL_TAG_WE_WIDTH{1'b1}};
icache_tag_idx = 0;
icache_tag_din = 0;
for(i=0;i<={LOCAL_TAG_ADDR_WIDTH{1'b1}};i=i+1)
begin
    @(posedge icache_tag_clk)
    icache_tag_cen  <= 0;
    icache_tag_gwen <= 1'b0;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b0}};
    icache_tag_idx  <= {LOCAL_TAG_ADDR_WIDTH{1'b0}} + i;
    icache_tag_din  <= {LOCAL_TAG_DATA_WIDTH{1'b1}};
    @(posedge icache_tag_clk)
    icache_tag_gwen <= 1'b1;
    icache_tag_wen <= {LOCAL_TAG_WE_WIDTH{1'b1}};
    @(posedge icache_tag_clk)
    @(posedge icache_tag_clk)
    icache_tag_idx  <= {LOCAL_TAG_ADDR_WIDTH{1'b0}} + i + 1;
    if(icache_tag_dout != {LOCAL_TAG_DATA_WIDTH{1'b1}})
    begin
        $display("tag array read/write test fail when addr is %d\n", i);
        repeat(10)@(posedge icache_tag_clk)
        $finish;
    end
        icache_mem_test_pass = 1;
end

end




endmodule