-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.hpp
More file actions
56 lines (47 loc) · 1.46 KB
/
Copy pathcache.hpp
File metadata and controls
56 lines (47 loc) · 1.46 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
#ifndef CACHE
#define CACHE
#include <iostream>
typedef unsigned long ulong;
enum cacheState {
MESSY = 'M',
CLEAN = 'C',
INVALID = 'I'}; //for single-processor, cache state can either be messy or clean (maybe invalid depending on the algorithms used)
struct page
{
ulong addr;
cacheState state;
page(ulong address, cacheState initialState) : addr(address), state(initialState) {}
page(){}
};
class Cache
{
public:
ulong cacheSize_;
ulong blockSize_;
ulong currentSize_;
ulong hitCount, missCount, readCount, writeCount;
Cache *upperCache;
Cache *lowerCache;
Cache() : hitCount(0), missCount(0), readCount(0), writeCount(0) {}
Cache(ulong cacheSize, ulong blockSize) : cacheSize_(cacheSize), blockSize_(blockSize), currentSize_(0), hitCount(0), missCount(0), readCount(0), writeCount(0) {}
void setUpperCache(Cache *cache)
{
upperCache = cache;
}
void setLowerCache(Cache *cache)
{
lowerCache = cache;
}
virtual bool inCache(ulong ){return false;}
virtual void insert(ulong , cacheState ) {}
virtual page evict(ulong ) {return page();}
virtual void read(ulong ) {}
virtual void write(ulong ) {}
virtual void instruction_fetch(ulong ) {} //this may be unused
};
std::ostream& operator<<(std::ostream& stream, const Cache& cache)
{
stream << "hits: " << cache.hitCount << ", misses: " << cache.missCount << ", reads: " << cache.readCount << ", writes: " << cache.writeCount;
return stream;
}
#endif