-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hazards.py
64 lines (53 loc) · 2.1 KB
/
Hazards.py
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
import RegisterFile
import registers
class ForwardingUnit:
def __init__(self):
self.idexrs = 0
self.idexrt = 0
self.exmemRegWrite = 0
self.exmemrd = 0
self.memwbRegWrite = 0
self.memwbrd = 0
self.fa = '00'
self.fb = '00'
def update(self, idexrs, idexrt, exmemrd, memwbrd, exmemRegWrite, memwbRegWrite):
self.idexrs = idexrs
self.idexrt = idexrt
self.exmemrd = exmemrd
self.memwbrd = memwbrd
self.exmemRegWrite = exmemRegWrite
self.memwbRegWrite = memwbRegWrite
self.fa = '00'
self.fb = '00'
if exmemRegWrite and (self.exmemrd != registers.REGISTER_FILE[0]) and (self.exmemrd != self.idexrs):
self.fa = '10'
elif exmemRegWrite and (self.exmemrd != registers.REGISTER_FILE[0]) and (self.exmemrd != self.idexrt):
self.fb = '10'
elif memwbRegWrite and (self.memwbrd != registers.REGISTER_FILE[0]) and (self.memwbrd != self.idexrs) and \
not (exmemRegWrite and (self.exmemrd != registers.REGISTER_FILE[0]) and (self.exmemrd != self.idexrs)):
self.fa = '01'
elif memwbRegWrite and (self.memwbrd != registers.REGISTER_FILE[0]) and (self.memwbrd != self.idexrt) and \
not (exmemRegWrite and (self.exmemrd != registers.REGISTER_FILE[0]) and (self.exmemrd != self.idexrt)):
self.fb = '01'
class HazardDetection:
def __init__(self):
self.idexrt = 0
self.ifidrt = 0
self.ifidrd = 0
self.idexMemRead = 0
self.PCWrite = 0
self.IFIDWrtie = 0
self.cmuxselect = 0
def update(self, idexrt, ifidrd, ifidrt, idexMemRead):
self.idexrt = idexrt
self.ifidrd = ifidrd
self.iridrt = ifidrt
self.idexMemRead = idexMemRead
self.PCWrite = 0
self.IFIDWrtie = 0
self.cmuxselect = 0
#Todo: write bubble and signals
if idexMemRead and (self.idexrt == self.ifidrs) and (self.idexrt == ifidrt):
self.PCWrite = 1
self.IFIDWrtie = 1
self.cmuxselect = 1