From 661ba30d5233e1b95ac312e88cd51380e664933b Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 14 Apr 2025 23:10:18 -0400 Subject: Initial refactor of is_access_cleared --- src/cache.cc | 31 ++++++++++--------------------- src/dram.cc | 27 ++++++--------------------- src/storage.cc | 20 +++++++++++++++++++- 3 files changed, 35 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/cache.cc b/src/cache.cc index 307d6d0..44a770d 100644 --- a/src/cache.cc +++ b/src/cache.cc @@ -59,35 +59,24 @@ int Cache::process(void *id, int address, std::function request_handler) { int r; - r = this->is_access_cleared(id, address); - if (r) { - int tag, index, offset; - GET_FIELDS(address, &tag, &index, &offset); - request_handler(index, offset); - } - return r; -} -int -Cache::is_access_cleared(void *id, int address) -{ - /* Do this first--then process the first cycle immediately. */ + r = 0; if (id == nullptr) throw std::invalid_argument("Accessor cannot be nullptr."); if (this->current_request == nullptr) this->current_request = id; if (this->current_request == id) { if (is_address_missing(address)) - return 0; - else if (this->wait_time == 0) { - this->current_request = nullptr; - this->wait_time = delay; - return 1; - } else { - --this->wait_time; - } + r = 0; + else + r = this->is_access_cleared(); } - return 0; + if (r) { + int tag, index, offset; + GET_FIELDS(address, &tag, &index, &offset); + request_handler(index, offset); + } + return r; } int diff --git a/src/dram.cc b/src/dram.cc index 18c1a3e..264cadb 100644 --- a/src/dram.cc +++ b/src/dram.cc @@ -55,33 +55,18 @@ int Dram::process(void *id, int address, std::function request_handler) { int r; - r = this->is_access_cleared(id); - if (r) { - int line, word; - get_memory_index(address, line, word); - request_handler(line, word); - } - return r; -} -int -Dram::is_access_cleared(void *id) -{ - /* Do this first--then process the first cycle immediately. */ if (id == nullptr) throw std::invalid_argument("Accessor cannot be nullptr."); if (this->current_request == nullptr) this->current_request = id; - if (this->current_request == id) { - if (this->wait_time == 0) { - this->current_request = nullptr; - this->wait_time = delay; - return 1; - } else { - --this->wait_time; - } + r = (this->current_request == id) ? this->is_access_cleared() : 0; + if (r) { + int line, word; + get_memory_index(address, line, word); + request_handler(line, word); } - return 0; + return r; } void diff --git a/src/storage.cc b/src/storage.cc index 4ad916b..b6be578 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -2,7 +2,8 @@ #include "definitions.h" #include -Storage::Storage(int delay) { +Storage::Storage(int delay) +{ this->data = new std::vector>; this->delay = delay; this->lower = nullptr; @@ -18,3 +19,20 @@ Storage::view(int base, int lines) const std::copy(this->data->begin() + base, this->data->begin() + base + lines, ret.begin()); return ret; } + +int +Storage::is_access_cleared() +{ + int r; + + r = 0; + if (this->wait_time == 0) { + this->current_request = nullptr; + this->wait_time = delay; + r = 1; + } else { + --this->wait_time; + } + + return r; +} -- cgit v1.2.3