-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.cpp
More file actions
41 lines (34 loc) · 1.08 KB
/
Copy pathcache.cpp
File metadata and controls
41 lines (34 loc) · 1.08 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
/**
* Author : Gaurav Maheshwari, CS08B005 (gaurav.m.iitm@gmail.com)
*/
#include "cache.h"
#include "address.h"
Cache::Cache (int associativity, int blockSizeInBytes, int cacheSizeInBytes) {
this->associativity = associativity;
this->blockSizeInBytes = blockSizeInBytes;
this->cacheSizeInBytes = cacheSizeInBytes;
numRowsInCache = cacheSizeInBytes / (associativity * blockSizeInBytes);
cache.reserve(sizeof(LRUQueue) * numRowsInCache);
for (int i = 0; i < numRowsInCache; i++) {
cache.push_back(LRUQueue(associativity));
}
numColdMiss = 0;
numMisses = 0;
numHits = 0;
}
/**
* Updates cache appropriately when an access to 'address' occurs.
* Updates Hit count, Miss count, Cold Miss count appropriately.
*/
void Cache::updateCache (Address address) {
if (addressLog.find(make_pair(address.getSet(), address.getIndex()))
== addressLog.end()) {
addressLog.insert(make_pair(address.getSet(), address.getIndex()));
numColdMiss++;
}
bool status = cache[address.getSet()].updateLRUQueue(address);
if (status)
numHits++;
else
numMisses++;
}