-
Notifications
You must be signed in to change notification settings - Fork 0
/
Branch_prediction_algo_tb.v
62 lines (51 loc) · 1.6 KB
/
Branch_prediction_algo_tb.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
`include "Branch_prediction_algo.v"
module BranchPredictor_tb;
reg clk;
reg reset;
reg [31:0] pc;
reg branch_taken;
wire prediction;
// Instantiate the branch predictor
BranchPredictor uut (
.clk(clk),
.reset(reset),
.pc(pc),
.branch_taken(branch_taken),
.prediction(prediction)
);
// Clock generation
initial begin
clk = 0;
forever #5 clk = ~clk;
end
// Test sequence
initial begin
// Initialize
reset = 1;
pc = 0;
branch_taken = 0;
#10 reset = 0;
// Test case 1: branch not taken
#10 pc = 32'h00000004; branch_taken = 0;
#10 pc = 32'h00000004; branch_taken = 0;
#10 pc = 32'h00000004; branch_taken = 0;
// Test case 2: branch taken
#10 pc = 32'h00000008; branch_taken = 1;
#10 pc = 32'h00000008; branch_taken = 1;
#10 pc = 32'h00000008; branch_taken = 1;
// Test case 3: branch taken and not taken alternately
#10 pc = 32'h0000000C; branch_taken = 1;
#10 pc = 32'h0000000C; branch_taken = 0;
#10 pc = 32'h0000000C; branch_taken = 1;
#10 pc = 32'h0000000C; branch_taken = 0;
// End simulation
#20 $finish;
end
// Monitor the outputs
initial begin
$dumpfile("BranchPredictor_tb.vcd");
$dumpvars(0,BranchPredictor_tb);
$monitor("At time %0t: pc = %h, branch_taken = %b, prediction = %b",
$time, pc, branch_taken, prediction);
end
endmodule