-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTomasulo.cpp
More file actions
127 lines (108 loc) · 2.37 KB
/
Tomasulo.cpp
File metadata and controls
127 lines (108 loc) · 2.37 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "StdAfx.h"
#include "Tomasulo.h"
Tomasulo::Tomasulo(
int addsub_delay,
int mul_delay,
int div_delay,
int instruction_q_depth,
int addsub_rs,
int muldiv_rs,
int load_q_depth,
int store_q_depth)
{
this->pc = 0;
this->mul_delay = mul_delay;
this->div_delay = div_delay;
this->instruction_q_depth = instruction_q_depth;
this->addsub_rs = addsub_rs;
this->muldiv_rs = muldiv_rs;
this->load_q_depth = load_q_depth;
this->store_q_depth = store_q_depth;
addsubRS = new reservationEntry[addsub_rs];
muldivRS = new reservationEntry[muldiv_rs];
loadRS = new reservationEntry[load_q_depth];
storeRS = new reservationEntry[store_q_depth];
for (int i=0; i < addsub_rs; i++) {
addsubRS[i].busy = false;
}
for (int i=0; i < muldiv_rs; i++) {
muldivRS[i].busy = false;
}
for (int i=0; i < load_q_depth; i++) {
loadRS[i].busy = false;
}
for (int i=0; i < store_q_depth; i++) {
storeRS[i].busy = false;
}
memset(this->registersStatus,0,sizeof(this->registersStatus));
}
Tomasulo::~Tomasulo(void)
{
delete[] addsubRS;
delete[] muldivRS;
delete[] loadRS;
delete[] storeRS;
}
bool Tomasulo::addToQueue(vector<std::string> newInstruction)
{
if (this->isInstQueueFull()) {
return false;
}
else
{
instructionsQueue.push(newInstruction);
return true;
}
}
bool Tomasulo::isInstQueueFull()
{
return (instructionsQueue.size() == instruction_q_depth);
}
int Tomasulo::findOpenSpotInRS(reservationEntry* rs,int rsSize)
{
for (int i = 0; i<rsSize; i++) {
if (rs[i].busy == false)
return i;
}
return -1;
}
void Tomasulo::doWork()
{
if (!instructionsQueue.empty()) {
vector<string> currentInst = instructionsQueue.front();
if (issue(currentInst)) {
instructionsQueue.pop();
}
}
for (int i = 0; i < addsub_rs; i++) {
if (addsubRS[i].state == addsub_delay) {
addsubRS[i].busy = false;
//Here to trace instruction finished!
}
addsubRS[i].state += 1;
}
pc++;
}
bool Tomasulo::issue(vector<string> curInst)
{
if (isRSFull(addsubRS,addsub_rs)) {
return false;
} else {
reservationEntry* rse = addsubRS + findOpenSpotInRS(addsubRS,addsub_rs);
rse->op = curInst[0];
rse->busy = true;
rse->state = 0;
}
return true;
}
void doWorkForRS(reservationEntry rs, int rsSize)
{
}
bool Tomasulo::isRSFull(reservationEntry* rs ,int size)
{
for (int i = 0; i < size ; i++) {
if (rs[i].busy == false)
return false;
}
return true;
}