This commit is contained in:
LYC 2024-10-28 17:33:34 +08:00
parent c19d6f475d
commit a6f51e4558
3 changed files with 9 additions and 6 deletions

View File

@ -5,7 +5,7 @@ Cache::Cache(char *argv[])
{ {
this->blockSize = atoi(argv[1]); this->blockSize = atoi(argv[1]);
this->size = atoi(argv[2]); this->size = atoi(argv[2]);
this->Assoc = atoi(argv[3]); this->assoc = atoi(argv[3]);
this->replicementPolicy = atoi(argv[4]); this->replicementPolicy = atoi(argv[4]);
this->writePolicy = atoi(argv[5]); this->writePolicy = atoi(argv[5]);
@ -54,12 +54,14 @@ uint32_t Cache::getMaxIndex(){
uint32_t Cache::getAssoc() { uint32_t Cache::getAssoc() {
return this->assoc; return this->assoc;
} }
int Cache::log2_floor(uint32_t x) {
return x == 0 ? -1 : 31 - __builtin_clz(x);
}
CacheTIO Cache::Address2TIO(uint32_t addr) CacheTIO Cache::Address2TIO(uint32_t addr)
{ {
uint32_t offset = addr & om; uint32_t offset = addr & this->offsetMask;
uint32_t index = (addr & im) >> o; uint32_t index = (addr & this->indexMask) >> this->offset;
uint32_t tag = addr >> (o + i); uint32_t tag = addr >> (this->offset + this->index);
return {tag, index, offset}; return {tag, index, offset};
} }

View File

@ -64,6 +64,7 @@ public:
uint32_t getMaxIndex(); uint32_t getMaxIndex();
uint32_t getAssoc(); uint32_t getAssoc();
int log2_floor(uint32_t x)
void writeCache(uint32_t address); void writeCache(uint32_t address);
void readCache(uint32_t address); void readCache(uint32_t address);

View File

@ -4,7 +4,7 @@
#define LFU 1 #define LFU 1
#define WBWA 0 #define WBWA 0
#define WTNA #define WTNA 1
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>