Skip to content

Commit

Permalink
fix register file enable bug (#14)
Browse files Browse the repository at this point in the history
* add failing test for register file

* fix bug
  • Loading branch information
hazel-sudz authored Jan 10, 2024
1 parent 2b94bb1 commit 188b66a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/src/cpu/register_file.sv
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module register_file(rst, clk, wr_ena, wr_addr, wr_data, rd_addr0, rd_data0, rd_
for(i=1;i<32;i++) begin
register #(32) REG(
.clk(clk),
.ena(write_addr_decoded[i]),
.ena(write_addr_decoded[i] & wr_ena),
.rst(rst),
.d(wr_data),
.q(xn[i]));
Expand Down
20 changes: 15 additions & 5 deletions src/components/tests/our/test_register_file.sv
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module test_register_file;


logic [4:0] wr_addr;
logic [31:0] wr_data;
logic [31:0] wr_data, wr_data_gen;

logic[4:0] rd_addr0, rd_addr1;
logic[31:0] rd_data0, rd_data1;
Expand Down Expand Up @@ -41,19 +41,29 @@ module test_register_file;
@(negedge clk);
wr_ena = 1;
wr_addr = i;
wr_data_gen = $random();
wr_data = wr_data_gen;
@(posedge clk);

// test to make sure enable works correctly
@(negedge clk);
wr_ena = 0;
wr_data = $random();
#5;
wr_addr = i;
@(posedge clk);

// test reading from register
@(negedge clk);
wr_ena = 0;
rd_addr0 = i;
rd_addr1 = i;
#5;
#1;


// check value of register
$display("[register_file]: [rd_addr0: %0d], [rd_data0: %0d], [rd_addr1: %0d], [rd_data1: %0d], [exp_rd_data0: %0d]", rd_addr0, rd_data1, rd_addr1, rd_data1, wr_data);
assert(wr_data == rd_data0) else $fatal;
assert(wr_data == rd_data1) else $fatal;
assert(wr_data_gen == rd_data0) else $fatal;
assert(wr_data_gen == rd_data1) else $fatal;

end
$display("[PASS RANDOM TEST] iteration #%d", test_cases);
Expand Down

0 comments on commit 188b66a

Please sign in to comment.