-
Notifications
You must be signed in to change notification settings - Fork 3
/
alu.test.v
87 lines (67 loc) · 1.26 KB
/
alu.test.v
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
`include "alu.v"
`include "sim.v"
`ifndef TESTS
`define TESTS 32
`endif
module test();
wire reset;
wire clk;
// Connecting wires
wire [31:0] alu_a;
wire [31:0] alu_b;
wire [1:0] alu_cmd;
wire [31:0] alu_result;
wire alu_res_valid;
wire alu_ready;
// You can use arrays (even multidimensional
reg [32+32-1:0] tests [0:`TESTS-1];
reg done = 1'b0;
// This is not synthetizable
integer i;
// Initial block
initial begin
for(i = 0; i < `TESTS; i = i + 1) begin
tests[i] <= {{$random},{$random}};
end
end
reg [31:0] t = 5'h0;
reg [31:0] a,b,res;
reg [1:0] op = `OP_NOP;
assign alu_a = a;
assign alu_b = b;
assign alu_cmd = op;
always @(posedge alu_res_valid) begin
if (alu_result != res)
$display("Result wrong!");
end
always @(posedge alu_ready) begin
a <= tests[t][63:32];
b <= tests[t][31:0];
op <= `OP_ADD;
res <= tests[t][63:32] + tests[t][31:0];
if (t + 1 < `TESTS)
t = t + 1;
else begin
//finish here?
t = 0;
done = 1'b1;
end
end
// ALU module
alu my_alu
(
.clk(clk),
.reset(reset),
.i_a(alu_a),
.i_b(alu_b),
.i_cmd(alu_cmd),
.o_result(alu_result),
.o_valid(alu_res_valid),
.o_ready(alu_ready)
);
// Simulator (clock + reset)
sim my_sim(
.clk(clk),
.reset(reset)
);
endmodule