-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALUBench.sv
63 lines (54 loc) · 1.25 KB
/
ALUBench.sv
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
`default_nettype none
`include "Sys.sv"
import params::*;
import alu::*;
import types::*;
class RandVars;
randc data_t alu_a;
randc data_t alu_b;
rand e_alu_op alu_op;
endclass
module ALUBench;
logic clk;
data_t alu_out;
data_t alu_a;
data_t alu_b;
e_alu_op alu_op;
always_ff #5 clk <= ~clk;
RandVars vars = new();
function automatic void f_rand_op(RandVars vars);
if (vars.randomize() == 0) ;
else ;
alu_a = vars.alu_a;
alu_b = vars.alu_b;
alu_op = vars.alu_op;
#10;
case (alu_op)
ADD: assert (alu_out == alu_a + alu_b);
SUB: assert (alu_out == alu_a - alu_b);
XOR: assert (alu_out == (alu_a ^ alu_b));
OR: assert (alu_out == (alu_a | alu_b));
AND: assert (alu_out == (alu_a & alu_b));
NOT: assert (alu_out == ~alu_a);
INC: assert (alu_out == (alu_a + 1));
INC4: assert (alu_out == (alu_a + 4));
DEC: assert (alu_out == (alu_a - 1));
default: $fatal;
endcase
endfunction
ALU u_alu(
.i_clk(clk),
.i_alu_op(alu_op),
.i_a(alu_a),
.i_b(alu_b),
.o_out(alu_out)
);
initial begin
$dumpfile("alu.vcd");
$dumpvars(0, alu_bench);
for (int i = 0; i < 10; i++) begin
f_rand_op(vars);
end
$finish;
end
endmodule