-
Notifications
You must be signed in to change notification settings - Fork 13
add sw_testbench #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add sw_testbench #50
Changes from 8 commits
36edb5e
0c9d383
a6d5ec9
356be06
bf3307b
2c3457b
a839e49
ebd8ff0
aac18d3
f1af194
540d456
25ea49e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,8 @@ module top ( input wire clk | |
| wire [3:0] __tmp_ALUControl; | ||
| wire [1:0] __tmp_ResultSrc; | ||
| wire [3:0] __tmp_FSMState; | ||
| logic [31:0] dataA | ||
| ,dataB; | ||
|
|
||
| ControlFSM control_fsm | ||
| ( .opcode ( opcode ) | ||
|
|
@@ -83,8 +85,8 @@ module top ( input wire clk | |
|
|
||
| MA memory // instructions and data | ||
| ( .A ( memory_address ) | ||
| , .WD ( 32'hxxxxxxxx ) | ||
| , .WE ( `FALSE ) | ||
| , .WD ( dataB ) | ||
| , .WE ( __tmp_MemWrite ) | ||
| , .CLK ( clk ) | ||
|
|
||
| // outputs | ||
|
|
@@ -130,14 +132,14 @@ module top ( input wire clk | |
| case (__tmp_ALUSrcA) | ||
| ALU_SRC_A__PC: alu_input_a = pc_cur; | ||
| ALU_SRC_A__OLD_PC: alu_input_a = pc_old; | ||
| ALU_SRC_A__RD1: alu_input_a = rd1; | ||
| ALU_SRC_A__RD1: alu_input_a = dataA; | ||
| default: alu_input_a = 32'hxxxxxxxx; | ||
| endcase | ||
| end | ||
|
|
||
| always @(*) begin | ||
| case (__tmp_ALUSrcB) | ||
| ALU_SRC_B__RD2: alu_input_b = rd2; | ||
| ALU_SRC_B__RD2: alu_input_b = dataB; | ||
| ALU_SRC_B__IMM_EXT: alu_input_b = imm_ext; | ||
| ALU_SRC_B__4: alu_input_b = 32'd4; | ||
| default: alu_input_b = 32'hxxxxxxxx; | ||
|
|
@@ -152,5 +154,10 @@ module top ( input wire clk | |
| default: result = 32'hxxxxxxxx; | ||
| endcase | ||
| end | ||
|
|
||
| always @(posedge clk) begin | ||
| dataA <= rd1; | ||
| dataB <= rd2; | ||
| end | ||
|
Comment on lines
+157
to
+161
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So i think figured out what was the issue with the Both approaches are correct, but i think your implementation is probably more inline with how the diagram is layed out -- the sync register is outside of RF and the reads are combinational ; i pushed the update to your PR along with the test bench fixes and it should be good to go now |
||
|
|
||
| endmodule | ||
| endmodule | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| `timescale 1ns/1ps | ||
|
|
||
| `include "test/utils.svh" | ||
|
|
||
| module sw_tb; | ||
|
|
||
| reg clk; | ||
| reg reset; | ||
|
|
||
| top uut | ||
| ( .clk ( clk ) | ||
| , .reset ( reset ) | ||
| ); | ||
|
|
||
| initial begin | ||
| clk = 0; | ||
| forever #5 clk = ~clk; | ||
| end | ||
|
|
||
| task wait_till_next_cfsm_state(input [5:0] expected_state); | ||
| @(posedge clk); #1; | ||
| `assert_equal(uut.control_fsm.current_state, expected_state) | ||
| endtask | ||
|
|
||
| initial begin | ||
| reset <= `TRUE; | ||
|
|
||
| // set up instructions and data memory | ||
| uut.memory.M[ 0] = 32'h00532023; // sw x5, 0(x6) | ||
| uut.memory.M[ 1] = 32'h00532223; // sw x5, 4(x6) | ||
| uut.memory.M[ 2] = 32'h00532423; // sw x5, 8(x6) | ||
| uut.memory.M[10] = 32'hbadab00f; // initial value | ||
| uut.memory.M[11] = 32'hdeadbeef; // initial value | ||
| uut.memory.M[12] = 32'hcafebabe; // initial value | ||
| uut.memory.M[13] = 32'h00000000; // will be written by sw x5, 8(x6) | ||
|
|
||
| // set up register file | ||
| uut.instruction_decode.instanceRegFile.RFMem[6] = 44; // x6 = 44 | ||
| uut.instruction_decode.instanceRegFile.RFMem[5] = 256; // x5 = 256 | ||
|
|
||
| wait_till_next_cfsm_state(uut.control_fsm.FETCH); | ||
|
|
||
| reset <= `FALSE; | ||
|
|
||
| // --- Instruction 1: sw x5, 0(x6) --- | ||
| wait_till_next_cfsm_state(uut.control_fsm.DECODE); | ||
| `assert_equal(uut.opcode, 7'b0100011) | ||
| `assert_equal(uut.instruction_decode.rs1, 6) | ||
| `assert_equal(uut.instruction_decode.rs2, 5) | ||
| `assert_equal(uut.instruction_decode.imm_ext, 0) | ||
|
|
||
| wait_till_next_cfsm_state(uut.control_fsm.MEMADR); | ||
| `assert_equal(uut.alu.out, 44) | ||
|
|
||
| wait_till_next_cfsm_state(uut.control_fsm.MEMWRITE); | ||
| `assert_equal(uut.memory_address, 44) | ||
|
|
||
| wait_till_next_cfsm_state(uut.control_fsm.FETCH); | ||
|
|
||
| `assert_equal(uut.memory.M[11], 256) | ||
| `assert_equal(uut.fetch.pc_cur, 4) | ||
|
|
||
| // --- Instruction 2: sw x5, 4(x6) --- | ||
| wait_till_next_cfsm_state(uut.control_fsm.DECODE); | ||
|
|
||
| `assert_equal(uut.instruction_decode.imm_ext, 4) | ||
|
|
||
| wait_till_next_cfsm_state(uut.control_fsm.MEMADR); | ||
|
|
||
| `assert_equal(uut.alu.out, 48) | ||
|
|
||
| wait_till_next_cfsm_state(uut.control_fsm.MEMWRITE); | ||
|
|
||
| wait_till_next_cfsm_state(uut.control_fsm.FETCH); | ||
|
|
||
| `assert_equal(uut.memory.M[12], 256) | ||
| `assert_equal(uut.fetch.pc_cur, 8) | ||
|
|
||
| // --- Instruction 3: sw x5, 8(x6) --- | ||
| wait_till_next_cfsm_state(uut.control_fsm.DECODE); | ||
|
|
||
| `assert_equal(uut.opcode, 7'b0100011) | ||
| `assert_equal(uut.instruction_decode.rs1, 6) | ||
| `assert_equal(uut.instruction_decode.rs2, 5) | ||
| `assert_equal(uut.instruction_decode.imm_ext, 8) | ||
|
|
||
| wait_till_next_cfsm_state(uut.control_fsm.MEMADR); | ||
|
|
||
| `assert_equal(uut.alu.out, 52) | ||
|
|
||
| wait_till_next_cfsm_state(uut.control_fsm.MEMWRITE); | ||
|
|
||
| wait_till_next_cfsm_state(uut.control_fsm.FETCH); | ||
|
|
||
| `assert_equal(uut.memory.M[13], 256) | ||
|
|
||
| // Final assertions | ||
| `assert_equal(uut.memory.M[11], 256) | ||
| `assert_equal(uut.memory.M[12], 256) | ||
| `assert_equal(uut.memory.M[13], 256) | ||
| `assert_equal(uut.instruction_decode.instanceRegFile.RFMem[5], 256) | ||
| `assert_equal(uut.instruction_decode.instanceRegFile.RFMem[6], 44) | ||
|
|
||
| $finish; | ||
| end | ||
|
|
||
| `SETUP_VCD_DUMP(sw_tb) | ||
|
|
||
| endmodule |
Uh oh!
There was an error while loading. Please reload this page.