-
Notifications
You must be signed in to change notification settings - Fork 0
/
cxxcache.h
executable file
·169 lines (140 loc) · 5.24 KB
/
cxxcache.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
// cxxcache.h
// holds classes for the L1 and L2 caches, and main memory
// ECEN4593 cache simulator project
// F2010
// Danny Gale, Chris Messick
//
// Revision History:
// 11/2/2010 Danny Gale created
// 11/2/2010 Danny Gale converted from C structs to C++ classes
// 11/4/2010 Danny Gale added dynamic cacheLine array to L1 and L2 caches
// added some numLines and wordsPerLine, calculated from given params
//
#ifndef _CXXCACHE_H_
#define _CXXCACHE_H_
using namespace std;
#include "set.h"
#include "defines.h"
enum cache_t { CACHETYPE_L1, CACHETYPE_L2 };
class cache
{
public:
// CONSTRUCTOR AND DESTRUCTOR
cache();
cache(cache_t cacheType);
~cache();
// CONSTANT MEMBER FUNCTIONS
unsigned get_blockSize() const { return blockSize; }
unsigned get_cacheSize() const { return cacheSize; }
unsigned get_assoc() const { return assoc; }
unsigned get_tHit() const { return tHit; }
unsigned get_tMiss() const { return tMiss; }
unsigned get_tTransfer() const { return tTransfer; }
unsigned get_busWidth() const { return busWidth; }
unsigned get_numSets() const { return numSets; }
unsigned get_blocksPerSet() const { return blocksPerSet; }
//unsigned get_bytesPerBlock() const { return bytesPerBlock; }
unsigned get_indexBits() const { return indexBits; }
unsigned get_byteBits() const { return byteBits; }
unsigned get_tagBits() const { return tagBits; }
set * get_set(unsigned i) const { return &sets[i]; }
// MEMBER FUNCTIONS
//void write(unsigned addr);
//void read(unsigned addr);
cacheLine * hit(unsigned addr, op_type operation);
cacheLine * write_from_below(unsigned addr);
cacheLine * write_from_above(unsigned addr);
void operate_on(op_type operation, unsigned addr);
unsigned make_tag(unsigned addr);
unsigned make_index(unsigned addr);
void set_blockSize(unsigned newSize);
void set_cacheSize(unsigned newSize);
void set_assoc(unsigned newAssoc);
void set_tHit(unsigned newtHit) { tHit = newtHit; }
void set_tMiss(unsigned newtMiss) {tMiss = newtMiss; }
void set_tTransfer(unsigned newtTransfer) {tTransfer = newtTransfer; }
void set_busWidth(unsigned newbusWidth) { busWidth = newbusWidth; }
void set_numSets(unsigned n);
//void set_bytesPerBlock(unsigned n);
// STATISTICS
unsigned get_writes() const {return writes;}
unsigned get_writeRequests() const {return writeRequests;}
unsigned get_writeMisses() const {return writeMisses;}
unsigned get_writeHits() const {return writeHits;}
unsigned get_reads() const {return reads;}
unsigned get_readRequests() const {return readRequests;}
unsigned get_readMisses() const {return readMisses;}
unsigned get_readHits() const {return readHits;}
unsigned get_requests() const {return requests;}
unsigned get_misses() const {return misses;}
unsigned get_hits() const {return hits;}
//unsigned get_hitsR() const {return hitsR;}
//unsigned get_hitsWD() const {return hitsWD;}
unsigned get_evictions() const {return evictions;}
unsigned get_dirtyEvictions() const { return dirtyEvictions;}
void add_readHit() {readHits++; hits++; reads++;}
//void add_readHitR() {readHits++; hitsR++; reads++;}
void add_writeHit() {writeHits++; hits++; writes++;}
//void add_writeHitWD() {writeHits++; hitsWD++; writes++;}
void add_readMiss() {readMisses++; misses++; reads++;}
void add_writeMiss() {writeMisses++; misses++; writes++;}
void add_hit(op_type operation);
void add_miss(op_type operation);
private:
set * sets;
// given cache parameters
unsigned blockSize;
unsigned cacheSize;
unsigned assoc;
unsigned tHit;
unsigned tMiss;
unsigned tTransfer;
unsigned busWidth;
// calculated cache parameters
unsigned numSets;
unsigned blocksPerSet;
//unsigned bytesPerBlock;
unsigned indexBits;
unsigned byteBits;
unsigned tagBits;
// statistics
unsigned writes;
unsigned writeRequests;
unsigned writeMisses;
unsigned writeHits;
unsigned reads;
unsigned readRequests;
unsigned readMisses;
unsigned readHits;
unsigned requests;
unsigned misses;
unsigned hits;
//unsigned hitsR;
//unsigned hitsWD;
unsigned evictions;
unsigned dirtyEvictions;
};
class main_memory
{
public:
// CONSTRUCTOR AND DESTRUCTOR
main_memory();
~main_memory();
// MEMBER FUNCTIONS
// bool write();
// bool read();
unsigned get_tSendAddr() const { return tSendAddr; }
unsigned get_tReady() const { return tReady; }
unsigned get_tChunk() const { return tChunk; }
unsigned get_chunkSize() const { return chunkSize; }
void set_tSendAddr(unsigned newval) { tSendAddr = newval; }
void set_tReady(unsigned newval) { tReady = newval; }
void set_tChunk(unsigned newval) { tChunk = newval; }
void set_chunkSize(unsigned newval) { chunkSize = newval; }
private:
unsigned tSendAddr;
unsigned tReady;
unsigned tChunk;
unsigned chunkSize;
};
#endif