diff options
Diffstat (limited to 'midterm/SRC/scoreboard_monitor.sv')
| -rw-r--r-- | midterm/SRC/scoreboard_monitor.sv | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/midterm/SRC/scoreboard_monitor.sv b/midterm/SRC/scoreboard_monitor.sv new file mode 100644 index 0000000..a51baa0 --- /dev/null +++ b/midterm/SRC/scoreboard_monitor.sv @@ -0,0 +1,63 @@ +import typedef_pkg::*; + +class scoreboard_monitor; + localparam int TOTAL_TESTS = 4 * 256 * 256; + + virtual intf alu_if; + transaction tr; + + function result_t compute_expected_value(input operation_t operation, input operand_t operand_a, + input operand_t operand_b, input result_t actual_result); + automatic result_t expected_result; + + case (operation) + ADD: begin + expected_result = (operand_a + operand_b) & 16'h01FF; + `FAIL_UNLESS_EQUAL(expected_result & 16'h01FF, actual_result & 16'h01FF, $sformatf( + "ADD a=%0d b=%0d", operand_a, operand_b)) + end + MULT: begin + expected_result = operand_a * operand_b; + `FAIL_UNLESS_EQUAL(expected_result, actual_result, $sformatf( + "MULT a=%0d b=%0d", operand_a, operand_b)) + end + OR: begin + expected_result = (operand_a | operand_b) & 16'h00FF; + `FAIL_UNLESS_EQUAL(expected_result & 16'h00FF, actual_result & 16'h00FF, $sformatf( + "OR a=%0d b=%0d", operand_a, operand_b)) + end + AND: begin + expected_result = (operand_a & operand_b) & 16'h00FF; + `FAIL_UNLESS_EQUAL(expected_result & 16'h00FF, actual_result & 16'h00FF, $sformatf( + "AND a=%0d b=%0d", operand_a, operand_b)) + end + default: begin + expected_result = '0; + end + endcase + + return expected_result; + endfunction + + task check(); + for (int i = 0; i < TOTAL_TESTS; i++) begin + @(posedge alu_if.clk iff (alu_if.op_start == 1'b1)); + + tr.operation = alu_if.operation; + tr.operand_a = alu_if.operand_a; + tr.operand_b = alu_if.operand_b; + + @(posedge alu_if.clk); + @(posedge alu_if.clk); + @(negedge alu_if.clk); + + tr.actual_result = alu_if.result; + tr.expected_result = + compute_expected_value(tr.operation, tr.operand_a, tr.operand_b, tr.actual_result); + + tr.print(); + end + + $display("Scoreboard check complete. Total tests: %0d", TOTAL_TESTS); + endtask +endclass |