diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/storage/cache.cc | 20 | ||||
-rw-r--r-- | src/utils/utils.cc | 11 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/storage/cache.cc b/src/storage/cache.cc index 67cedda..cf954b0 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -6,17 +6,31 @@ Cache::Cache(int lines, Storage *lower, int delay) { this->data = new std::vector<std::array<signed int, LINE_SIZE>>; - this->data->resize(lines); + this->data->resize(L1_CACHE_SIZE); this->lower = lower; this->delay = delay; - this->lower = nullptr; + for (int i = 0; i < L1_CACHE_SIZE; ++i) + this->stat[i] = 0b01; } Cache::~Cache() { delete this->data; } Response Cache::write(Accessor accessor, signed int data, int address) { - return WAIT; + Response r = WAIT; + + /* Do this first--then process the first cycle immediately. */ + if (this->requester == IDLE) + this->requester = accessor; + + if (this->requester == accessor) { + if (this->wait_time == 0) { + this->do_write(data, address); + r = OK; + } + } + + return r; } Response Cache::read(Accessor accessor, int address, std::array<signed int, LINE_SIZE>& data) { return WAIT; } diff --git a/src/utils/utils.cc b/src/utils/utils.cc new file mode 100644 index 0000000..dfeb2b3 --- /dev/null +++ b/src/utils/utils.cc @@ -0,0 +1,11 @@ +#include "utils.h" +#include "definitions.h" + +void get_bit_fields(int address, int *tag, int *index, int *offset) +{ + *tag = + GET_MID_BITS(address, LINE_SPEC + L1_CACHE_SPEC, + MEM_SPEC + LINE_SPEC + L1_CACHE_SPEC); + *index = GET_MID_BITS(address, LINE_SPEC, L1_CACHE_SPEC + LINE_SPEC); + *offset = GET_LS_BITS(address, LINE_SPEC); +} |