From 2140a23041d3920e001457f2c2acb0853094963d Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 14 Apr 2025 23:27:54 -0400 Subject: Simplify cache/dram process functions --- inc/storage.h | 2 +- src/cache.cc | 31 ++++++++++++++++--------------- src/dram.cc | 21 ++++++++++++--------- src/storage.cc | 2 +- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/inc/storage.h b/inc/storage.h index 1b71794..972e24a 100644 --- a/inc/storage.h +++ b/inc/storage.h @@ -53,7 +53,7 @@ class Storage * @param the id asking for a resource * @return 1 if the access can be carried out this function call, 0 otherwise. */ - int is_access_cleared(); + int is_data_ready(); /** * The data currently stored in this level of storage. */ diff --git a/src/cache.cc b/src/cache.cc index 44a770d..ee4b00c 100644 --- a/src/cache.cc +++ b/src/cache.cc @@ -58,25 +58,26 @@ Cache::read_word(void *id, int address, signed int &data) int Cache::process(void *id, int address, std::function request_handler) { - int r; - - 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)) - r = 0; - else - r = this->is_access_cleared(); - } - if (r) { - int tag, index, offset; - GET_FIELDS(address, &tag, &index, &offset); - request_handler(index, offset); - } - return r; + + if (this->current_request != id) + return 0; + + if (is_address_missing(address)) + return 0; + + if (!this->is_data_ready()) + return 0; + + int tag, index, offset; + GET_FIELDS(address, &tag, &index, &offset); + request_handler(index, offset); + + return 1; } int diff --git a/src/dram.cc b/src/dram.cc index 264cadb..5e7e57a 100644 --- a/src/dram.cc +++ b/src/dram.cc @@ -54,19 +54,22 @@ Dram::load(std::vector program) int Dram::process(void *id, int address, std::function request_handler) { - int r; - if (id == nullptr) throw std::invalid_argument("Accessor cannot be nullptr."); + if (this->current_request == nullptr) this->current_request = id; - 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 r; + + if (this->current_request != id) + return 0; + + if (!this->is_data_ready()) + return 0; + + int line, word; + get_memory_index(address, line, word); + request_handler(line, word); + return 1; } void diff --git a/src/storage.cc b/src/storage.cc index b6be578..17c902d 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -21,7 +21,7 @@ Storage::view(int base, int lines) const } int -Storage::is_access_cleared() +Storage::is_data_ready() { int r; -- cgit v1.2.3