-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHazard_detection_unit.v
85 lines (73 loc) · 2.29 KB
/
Hazard_detection_unit.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
`ifndef MODULE_HARZARD_DECT
`define MODULE_HARZARD_DECT
`timescale 1ns / 1ps
//
//
//
//
//
//
module Hazard_detection_unit (
input ID_EX_MemRead,
ID_EX_regWrite,
EX_MEM_MemRead,
ID_branch_comp_re,
input [5:0] ins_op,
input [4:0] IF_ID_RegisterRs,
IF_ID_RegisterRt,
ID_EX_RegisterRt,
ID_EX_RegisterRd,
EX_MEM_RegisterRd,
output reg stall,
flushIDEX,
flushIFID
);
initial begin
stall = 1'b0;
flushIDEX = 1'b0;
flushIFID = 1'b0;
end
always @ ( * ) begin
if (ID_EX_MemRead && ID_EX_RegisterRt && (ID_EX_RegisterRt == IF_ID_RegisterRs || ID_EX_RegisterRt == IF_ID_RegisterRt)) begin
// $display("0000000000000000000");
stall = 1'b1;
flushIDEX = 1'b1;
flushIFID = 1'b0;
end else if ( ( (ins_op == 6'b000100) || (ins_op == 6'b000101) )) begin
if (ID_branch_comp_re) flushIFID = 1'b1;
if ( (ID_EX_regWrite && ID_EX_RegisterRd && (ID_EX_RegisterRd == IF_ID_RegisterRs || ID_EX_RegisterRd == IF_ID_RegisterRt)) )
begin
// $display("1111111111111111111");
stall = 1'b1;
flushIDEX = 1'b1;
end
else if ( (EX_MEM_MemRead && EX_MEM_RegisterRd && (EX_MEM_RegisterRd == IF_ID_RegisterRs || EX_MEM_RegisterRd == IF_ID_RegisterRt) ) )
begin
// $display("2222222222222222222222222222");
stall = 1'b1;
flushIDEX = 1'b1;
end
else
begin
// $display("33333333333333333333333333");
stall = 1'b0;
flushIDEX = 1'b0;
end
end
else if ( ins_op == 6'b000010 )
begin
// $display("44444444444444444");
stall = 1'b0;
flushIDEX = 1'b0;
flushIFID = 1'b1;
end
else
begin
// $display("55555555555555");
stall = 1'b0;
flushIDEX = 1'b0;
flushIFID = 1'b0;
end
end
endmodule
`endif