-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainMemory.cpp
More file actions
209 lines (166 loc) · 4.88 KB
/
Copy pathmainMemory.cpp
File metadata and controls
209 lines (166 loc) · 4.88 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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include "memorySimulator.h"
mainMemory::mainMemory(config config_param) {
this->config_params = config_param;
this->bank = 3;
this->channel = 2;
this->rank = 1;
this->blockOffset = (unsigned long)log2(config_params.blocksize);
this->setIndex = (unsigned long)log2(config_params.L3CacheSize / config_param.blocksize);
this->tag = 32 - blockOffset;
// Row interLeaving
this->ByteInbus = 3;
this->column = 11;
this->row = 14;
// cache block interLeaving
/*
*
*
**/
this->openPages = createOpenPages(bank, channel, rank);
}
vector< vector< long>> mainMemory::createOpenPages(unsigned long& bankInRank, unsigned long& channel, unsigned long& ranks) {
vector< vector< long>> myMemory;
unsigned long size = pow(2, bankInRank) * channel * ranks;
myMemory.resize((unsigned long)size);
for (int i = 0; i < size; i++) {
myMemory[i].resize(2);
}
for (int i = 0; i < size; i++) {
for (int j = 0; j < 2; j++) {
myMemory[i][j] = -1;
}
}
return myMemory;
}
vector<string> mainMemory::getBits1(bitset<32> addr) {
string stringAddr = addr.to_string();
vector<string> bits(2);
bits[0] = stringAddr.substr(0, this->tag);
bits[1] = stringAddr.substr(this->tag, this->blockOffset);
return bits;
}
unsigned long mainMemory::getBank() {
return this->bank;
}
unsigned long mainMemory::getChannel() {
return this->channel;
}
unsigned long mainMemory::getRank() {
return this->rank;
}
unsigned long mainMemory::getCoulmnSize() {
return pow(2, this->column);
}
vector<string> mainMemory::getBits(bitset<32> addr) {
string stringAddr = addr.to_string();
vector<string> bits(5);
bits[0] = stringAddr.substr(0, this->row);
bits[1] = stringAddr.substr(this->row, 1);
bits[2] = stringAddr.substr(this->row, this->bank);
bits[3] = stringAddr.substr(this->row + this->bank, this->column);
bits[4] = stringAddr.substr(this->row + this->bank + this->column, this->ByteInbus);
return bits;
}
vector< vector< long>> mainMemory::getPage() {
return this->openPages;
}
void upDatePage(vector< vector< long>>& openPage, unsigned long& tagAddress, int OffsetSize,
unsigned long& DDR_Cycles_PageAndColumnIsOpen, unsigned long& DDR_Cycles_PageOpen
, unsigned long& DDR_Cycles_PageNotOpen, long& CyclesSimulator, AddressMapping AddressMapping)
{
unsigned long tagSize = 32 - OffsetSize;
string tag1, offset1, address;
if (tagSize == 28)
{
bitset<28> tag;
bitset<4> offset;
tag = bitset<28>(tagAddress);
offset = bitset<4>(0);
tag1 = tag.to_string();
offset1 = offset.to_string();
address = tag1 + offset1;
}
if (tagSize == 27)
{
bitset<27> tag;
bitset<5> offset;
tag = bitset<27>(tagAddress);
offset = bitset<5>(0);
tag1 = tag.to_string();
offset1 = offset.to_string();
address = tag1 + offset1;
}
if (tagSize == 26)
{
bitset<26> tag;
bitset<6> offset;
tag = bitset<26>(tagAddress);
offset = bitset<6>(0);
tag1 = tag.to_string();
offset1 = offset.to_string();
address = tag1 + offset1;
}
if (tagSize == 25)
{
bitset<25> tag;
bitset<7> offset;
tag = bitset<25>(tagAddress);
offset = bitset<7>(0);
tag1 = tag.to_string();
offset1 = offset.to_string();
address = tag1 + offset1;
}
int bank1 = 3;
int row1 = 14;
int column1 = 11;
int channel1 = 1;
int hightCloumn = 8;
int lowColumn = 3;
vector<string> bits(6);
if (AddressMapping == AddressMapping::RowInterleaving)
{
bits[0] = address.substr(0, row1);
bits[1] = address.substr(row1, 1);
bits[2] = address.substr(row1, channel1 + bank1);
bits[3] = address.substr(row1 + channel1 + bank1, column1);
}
if (AddressMapping == AddressMapping::CacheBlockInterleaving)
{
bits[0] = address.substr(0, row1);
bits[1] = address.substr(row1, 1);
bits[2] = address.substr(row1 + channel1, hightCloumn);
bits[3] = address.substr(row1 + channel1 + hightCloumn, bank1);
bits[4] = address.substr(row1 + channel1 + hightCloumn + bank1, lowColumn);
bits[3] = bits[3] + bits[1];
bits[5] = bits[2] + bits[4];
}
char* ptr;
long row = strtol(bits[0].c_str(), &ptr, 2);
long channel = strtol(bits[1].c_str(), &ptr, 2);
long bank = strtol(bits[2].c_str(), &ptr, 2);
long column = strtol(bits[3].c_str(), &ptr, 2);
if (AddressMapping == AddressMapping::CacheBlockInterleaving)
{
bank = strtol(bits[3].c_str(), &ptr, 2);
column = strtol(bits[5].c_str(), &ptr, 2);
}
// if the row and the column is open
if (openPage[bank][0] == row && openPage[bank][1] == column)
{
// time !!
CyclesSimulator = CyclesSimulator + DDR_Cycles_PageAndColumnIsOpen;
}
// chack if the page is open
if (openPage[bank][0] != row)
{
openPage[bank][0] = row;
openPage[bank][1] = column;
CyclesSimulator = CyclesSimulator + DDR_Cycles_PageNotOpen;
}
// chack if the correct column is open in the correct page
if (openPage[bank][1] != column)
{
openPage[bank][1] = column;
CyclesSimulator = CyclesSimulator + DDR_Cycles_PageOpen;
}
}