(Cont.) work on cache functionality
MODIFY
src/cache.cpp
src/cache.cpp
#include "cache.h"
#include <assert.h>
-Cache::Cache(int missPenalty, int searchPenalty) {
+Cache::Cache(int *cycleCounterPtr, int missPenalty, int searchPenalty) {
// Initialize cache of size, set to zeros
m_missPenalty = missPenalty;
m_searchPenalty = searchPenalty;
+ m_cycleCounterPtr = cycleCounterPtr;
}
void Cache::assertSize(int size) const {

MODIFY
src/cache.h
src/cache.h
class Cache {
public:
- Cache(int missPenalty = 0, int searchPenalty = 0);
+ Cache(int *cycleCounterPtr, int missPenalty = 0, int searchPenalty = 0);
virtual uint32_t readData(uint32_t address) = 0;
virtual void writeData(uint32_t address) = 0;
@@ -17,13 +17,17 @@ public:
protected:
void assertSize(int size) const;
+
int m_readCount = 0;
int m_missCount = 0;
-private:
int m_missPenalty;
int m_searchPenalty;
+ int m_memoryPenalty;
+
uint32_t *m_memoryPtr;
+ int *m_cycleCounterPtr; // pointer to Runner's cycle counter
+ Cache *m_childCache = nullptr; // pointer to child cache (ie. L1 -> L2)
};
#endif // CACHE_H

MODIFY
src/dmcache.cpp
src/dmcache.cpp
#include "dmcache.h"
-DMCache::DMCache(int size) : Cache() {
+DMCache::DMCache(int size, int *cycleCounterPtr) : Cache(cycleCounterPtr) {
assertSize(size);
// Initialize cache to all zeros and invalidated
@@ -20,6 +20,16 @@ uint32_t DMCache::readData(uint32_t address) {
} else {
// Cache miss
m_missCount++;
+ *m_cycleCounterPtr += m_missPenalty;
+ if (m_childCache != nullptr) {
+ // Cache has subcache, delegate memory request to subcache
+ return m_childCache->readData(address);
+ } else {
+ // No subcaches available, read straight from memory
+ *m_cycleCounterPtr += m_memoryPenalty;
+ // @TODO : return an actual memory value here!
+ return 0;
+ }
}
}

MODIFY
src/dmcache.h
src/dmcache.h
// Direct mapped cache
class DMCache : public Cache {
public:
- DMCache(int size);
+ DMCache(int size, int *cycleCounterPtr);
uint32_t readData(uint32_t address) override;
void writeData(uint32_t address) override;

MODIFY
src/facache.cpp
src/facache.cpp
#include "facache.h"
-FACache::FACache(int size) : Cache(size) {}
+FACache::FACache(int size, int *cycleCounterPtr) : Cache(cycleCounterPtr) {}
uint32_t FACache::readData(uint32_t address) {
m_readCount++;

MODIFY
src/facache.h
src/facache.h
// Fully associative cache
class FACache : public Cache {
public:
- FACache(int size);
+ FACache(int size, int *cycleCounterPtr);
uint32_t readData(uint32_t address) override;
void writeData(uint32_t address) override;

(Cont.) work on cache functionality