diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cache.cc | 31 | ||||
-rw-r--r-- | src/dram.cc | 21 | ||||
-rw-r--r-- | src/storage.cc | 2 |
3 files changed, 29 insertions, 25 deletions
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<void(int index, int offset)> 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<signed int> program) int Dram::process(void *id, int address, std::function<void(int line, int word)> 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; |