1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
|