From ee433509972d9390a52f188e902eb74e55596822 Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 14 Apr 2025 16:28:05 -0400 Subject: Allow multi-level cache by passing a size into the constructor --- src/cache.cc | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src/cache.cc') diff --git a/src/cache.cc b/src/cache.cc index acbabcf..307d6d0 100644 --- a/src/cache.cc +++ b/src/cache.cc @@ -1,13 +1,17 @@ #include "cache.h" #include "definitions.h" -#include +#include #include -Cache::Cache(Storage *lower, int delay) : Storage(delay) +Cache::Cache(Storage *lower, unsigned int size, int delay) : Storage(delay) { - this->data->resize(L1_CACHE_LINES); + int true_size; + + true_size = 1 << size; + this->data->resize(true_size); + this->meta = std::vector>(true_size, {-1, -1}); + this->size = size; this->lower = lower; - this->meta.fill({-1, -1}); } Cache::~Cache() @@ -35,7 +39,6 @@ Cache::write_line(void *id, std::array data_line, int add }); } -// TODO: tests for multi level cache int Cache::read_line(void *id, int address, std::array &data_line) { @@ -103,8 +106,7 @@ Cache::is_address_missing(int expected) r = 1; if (meta->at(1) >= 0) { q = this->lower->write_line( - this, *actual, - ((index << LINE_SPEC) + (meta->at(0) << (L1_CACHE_LINE_SPEC + LINE_SPEC)))); + this, *actual, ((index << LINE_SPEC) + (meta->at(0) << (this->size + LINE_SPEC)))); if (q) { meta->at(1) = -1; } @@ -118,11 +120,3 @@ Cache::is_address_missing(int expected) return r; } - -std::array, L1_CACHE_LINES> -Cache::get_meta() const -{ - std::array, L1_CACHE_LINES> ret; - std::copy(std::begin(this->meta), std::end(this->meta), std::begin(ret)); - return ret; -} -- cgit v1.2.3