From a6f51e45581f46f0768e742b53f7ecd8c16e1e53 Mon Sep 17 00:00:00 2001 From: LYC Date: Mon, 28 Oct 2024 17:33:34 +0800 Subject: [PATCH] 7 --- cache/Project1/Proj1-1/Proj1-1/src/cache.cc | 12 +++++++----- cache/Project1/Proj1-1/Proj1-1/src/cache.h | 1 + cache/Project1/Proj1-1/Proj1-1/src/public.h | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cache/Project1/Proj1-1/Proj1-1/src/cache.cc b/cache/Project1/Proj1-1/Proj1-1/src/cache.cc index 6f21c21..5c1c877 100644 --- a/cache/Project1/Proj1-1/Proj1-1/src/cache.cc +++ b/cache/Project1/Proj1-1/Proj1-1/src/cache.cc @@ -5,7 +5,7 @@ Cache::Cache(char *argv[]) { this->blockSize = atoi(argv[1]); this->size = atoi(argv[2]); - this->Assoc = atoi(argv[3]); + this->assoc = atoi(argv[3]); this->replicementPolicy = atoi(argv[4]); this->writePolicy = atoi(argv[5]); @@ -54,12 +54,14 @@ uint32_t Cache::getMaxIndex(){ uint32_t Cache::getAssoc() { return this->assoc; } - +int Cache::log2_floor(uint32_t x) { + return x == 0 ? -1 : 31 - __builtin_clz(x); +} CacheTIO Cache::Address2TIO(uint32_t addr) { - uint32_t offset = addr & om; - uint32_t index = (addr & im) >> o; - uint32_t tag = addr >> (o + i); + uint32_t offset = addr & this->offsetMask; + uint32_t index = (addr & this->indexMask) >> this->offset; + uint32_t tag = addr >> (this->offset + this->index); return {tag, index, offset}; } diff --git a/cache/Project1/Proj1-1/Proj1-1/src/cache.h b/cache/Project1/Proj1-1/Proj1-1/src/cache.h index 4cef973..6b8a129 100644 --- a/cache/Project1/Proj1-1/Proj1-1/src/cache.h +++ b/cache/Project1/Proj1-1/Proj1-1/src/cache.h @@ -64,6 +64,7 @@ public: uint32_t getMaxIndex(); uint32_t getAssoc(); + int log2_floor(uint32_t x) void writeCache(uint32_t address); void readCache(uint32_t address); diff --git a/cache/Project1/Proj1-1/Proj1-1/src/public.h b/cache/Project1/Proj1-1/Proj1-1/src/public.h index 469ccc3..968d5c8 100644 --- a/cache/Project1/Proj1-1/Proj1-1/src/public.h +++ b/cache/Project1/Proj1-1/Proj1-1/src/public.h @@ -4,7 +4,7 @@ #define LFU 1 #define WBWA 0 -#define WTNA +#define WTNA 1 #include #include