forked from Nilanshrajput/AC2MC-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterStateBuffers.h
193 lines (161 loc) · 3.83 KB
/
InterStateBuffers.h
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#pragma once
#include <iostream>
#include <bitset>
#include <string>
#include <deque>
#define registerWidth 32
using namespace std;
class Register{
private:
int value;
public:
Register(){
value = 0;
}
void reset(){
value = 0;
}
void writeInt(int x){
value = x;
}
void writeBitset(bitset <registerWidth> x){
value = x.to_ulong();
}
int readInt(){
return value;
}
bitset<registerWidth> readBitset(){
bitset <registerWidth> x(value);
return x;
}
};
class InterStateBuffers{
public:
Register RA, RB, RX, RY, RM, RZ, RMD;
int PC;
int mem_register, return_address;
Register IR;
int pc_offset;
int insType;
string ALU_OP;
bool isjalr, isMem;
bool enableCache;
// For stalling
bool stall;
int numStall;
int totalCycles;
int hazard_type; /* 0 No Branch , 1 Jal , 2 Jalr ,3 branch */
int branch_address_def;
int branch_address;
int insTypeD,insTypeE,insTypeM,insTypeW;
int isjalrD,isjalrE,isjalrM,isjalrW;
int wblocD,wblocE,wblocM,wblocW;
int isMemD,isMemE,isMemM,isMemW;
int returnAddD,returnAddE,returnAddM,returnAddW;
bool taken;
int mispredNumber;
bool isMispred;
int nextPC;
int pWrite; // holds the write register value for the previous instruction
int ppWrite; // the instruction before that
string pInst; // instruction
string ppInst; //
int coldmiss;
int hitcount;
int accesscount;
int conflict_misses_data;
int cold_misses_data;
int capacity_misses_data;
int accesses_data;
int hits_data;
//Write back location:- stores register number for writeback,
//-1 for SB type where no write back occurs.
int write_back_location;
//inserting knobs as bool types, specification given with each knob
//take in the value at runtime or hardcode it for development purposes
bool enablePipe ; // E/D pipelining
// This would be used by the control unit
bool enableDF ; // E/D data forwarding
// Used by decode, execute, memory units
bool printRegFile ; // E/D printing register file values after each cycle
// Used by control
bool printISB; // E/D printing pipleline registers after each cycle
// Control
bool printISBspecific; // E/D printing for a specific instruction, handle later
// Control, decode(maybe)
int conflict_misses;
int cold_misses;
int capacity_misses;
InterStateBuffers(){
PC = 1;
return_address = 1;
mem_register = 0;
pc_offset = 0;
isjalr = false;
isMem = false;
write_back_location = -1;
enablePipe = true;
enableDF = true;
printRegFile = false;
printISB = false;
printISBspecific = false;
stall = false;
hazard_type = 0;
wblocW = -1;
wblocM = -1;
wblocE = -1;
wblocD = -1;
returnAddW = -1;
returnAddM = -1;
returnAddE = -1;
returnAddD = -1;
insTypeW = -1;
insTypeM = -1;
insTypeE = -1;
insTypeD = -1;
isjalrW = 0;
isjalrM = 0;
isjalrE = 0;
isjalrD = 0;
isMemW = 0;
isMemM = 0;
isMemE = 0;
isMemD = 0;
taken = true;
mispredNumber = 0;
isMispred = false;
nextPC = 0;
enableCache = true;
pWrite = 0;
ppWrite = 0;
numStall = 0;
totalCycles = 0;
coldmiss = 0;
hitcount = 0;
accesscount = 0;
cold_misses_data = 0;
capacity_misses_data = 0;
conflict_misses_data = 0;
accesses_data = 0;
hits_data = 0;
}
void resetAll(){
RA.reset();
RB.reset();
RX.reset();
RY.reset();
RM.reset();
RZ.reset();
mem_register = 0;
pc_offset = 0;
}
void printAll(){
cout<<"********** Inter State Buffer Values ***********\n";
cout<<"\tRA\t:\t"<<RA.readInt()<<endl;
cout<<"\tRB\t:\t"<<RB.readInt()<<endl;
cout<<"\tRM\t:\t"<<RM.readInt()<<endl;
cout<<"\tRZ\t:\t"<<RZ.readInt()<<endl;
cout<<"\tRY\t:\t"<<RY.readInt()<<endl;
cout<<"*************************************************\n";
}
};