-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode.cpp
43 lines (38 loc) · 1.03 KB
/
decode.cpp
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
#include <cassert>
#include "decode.h"
DecodeStage::DecodeStage(StageType _type, AbstractStage *_prevStage) : AbstractStage(_type, _prevStage) {
assert(prevStage->getType() == IF);
}
void DecodeStage::process() {
//Check if need to stall
AbstractStage* checkStall = nextStage;
if(!stalled) //only check if not stalled yet
while(checkStall != NULL) {
if(checkStall->getInstruction().isDataDependent(ins)) {
setStalled();
break;
}
checkStall = checkStall->getNextStage();
}
// If not stalled load ALU values
if(!stalled) {
if(ins.isAluImm() || ins.isMemory()) {
ins.setA(getReg(ins.getArg2()));
ins.setB(ins.getImmidiate());
}
if(ins.isAluReg()) {
ins.setA(getReg(ins.getArg2()));
ins.setB(getReg(ins.getArg3()));
}
if(ins.isBranch()) {
ins.setA(getReg(ins.getArg1()));
ins.setB(ins.getImmidiate());
}
//and finally pass the instruction to next stage
nextStage->setInstruction(ins);
} else {
nextStage->getInstruction().clear(); // insert a bubble
}
}
DecodeStage::~DecodeStage() {
}