-
Notifications
You must be signed in to change notification settings - Fork 0
/
T.cpp
46 lines (41 loc) · 1.91 KB
/
T.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
44
45
46
#include "../../../include/instructions/sets/extensions/T.h"
#include "../../../include/exceptions.h"
#include "../../../include/instructions/AbstractInstruction.h"
#include "../../../include/instructions/IType.h"
#include "../../../include/instructions/RType.h"
#include "../../../include/units/PipelineHazardController.h"
#include "../../../include/hw/Memory.h"
#include "../../../include/hw/RegisterFile.h"
AbstractInstruction TExtension::decode(bytes instruction, PipelineHazardController* pipelineController, bool* stall) {
// I-Type
ITypeInstruction ins = ITypeInstruction(pipelineController->getXLEN());
ins.decode(instruction);
ins.execute = &execute;
ins.memoryAccess = nullptr;
ins.registerWriteback = &writeback;
if (pipelineController->checkForStaleRegister(ins.getRS1())) {
pipelineController->enqueue(NOP(pipelineController->getXLEN()));
*stall = true;
return NOP(pipelineController->getXLEN());
} else {
ins.setRs1Val(pipelineController->fetchRegisterValue(ins.getRS1()));
}
pipelineController->enqueue(ins);
return ins;
}
void TExtension::execute(AbstractInstruction* instruction, AbstractBranchPredictor* branchPredictor, ulong memorySize, PipelineHazardController* pipelineController) {
if (instruction->getType() != InstructionType::I) {
throw UndefinedInstructionException(instruction, "Instruction not I-Type as expected");
}
if (instruction->getFunc3() == 0) {
instruction->setResult(addByteToBytes(instruction->getRs1Val(), 1));
} else if (instruction->getFunc3() == 1) {
instruction->setResult(addByteToBytes(instruction->getRs1Val(), -1));
} else {
throw UndefinedInstructionException(instruction, "Func3 undefined");
}
pipelineController->storeResultAfterExecution(instruction->getResult());
}
void TExtension::writeback(AbstractInstruction* instruction, RegisterFile* registerFile) {
registerFile->write(instruction->getRD(), instruction->getResult());
}