-
Notifications
You must be signed in to change notification settings - Fork 0
/
hazard_unit.sv
76 lines (70 loc) · 1.58 KB
/
hazard_unit.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
64
65
66
67
68
69
70
71
72
73
74
75
module hazard_unit
(
// Forwarding
input logic [ 4:0] rs1_DE,
input logic [ 4:0] rs2_DE,
input logic [ 4:0] rd_MW,
input logic rf_en_MW,
output logic forward_a,
output logic forward_b,
// Stalling and Flusing
input logic [31:0] inst_IF,
input logic [ 4:0] rd_DE,
input logic [ 1:0] wb_sel_DE,
input logic br_taken,
output logic stall_IF, // to PC register
output logic flush_DE // Flush DE stage
);
logic stall_lw;
// Operand A
always_comb
begin
if (rf_en_MW)
begin
if ((rs1_DE == rd_MW) & (rs1_DE != 0))
begin
forward_a = 1'b1;
end
else
begin
forward_a = 1'b0;
end
end
end
// Operand B
always_comb
begin
if (rf_en_MW)
begin
if ((rs2_DE == rd_MW) & (rs2_DE != 0))
begin
forward_b = 1'b1;
end
else
begin
forward_b = 1'b0;
end
end
end
// Stalling
always_comb
begin
if (wb_sel_DE == 2'b10)
begin
if ( (inst_IF[19:15] == rd_DE) | (inst_IF[24:20] == rd_DE) )
begin
stall_lw = 1'b1;
end
else
begin
stall_lw = 1'b0;
end
end
else
begin
stall_lw = 1'b0;
end
stall_IF = stall_lw;
flush_DE = stall_lw | br_taken;
end
endmodule