diff options
author | Siddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com> | 2025-04-16 12:41:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-16 12:41:34 -0400 |
commit | 43e660152ebf1d8c8aa46f5478d4d26885d4a12c (patch) | |
tree | 41ab4e108784f6c180ad23fcc3bd3bf9440a9a2b /src/dram.cc | |
parent | be2bc108dc112ae7e21d4a77f7bcbfac88d6fcd4 (diff) | |
parent | 71f69927931e007d0bac13b9268b6a697b45c70a (diff) |
Merge pull request #2 from bdunahu/bdunahu
[WIP] Memory Rewrite
Diffstat (limited to 'src/dram.cc')
-rw-r--r-- | src/dram.cc | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/src/dram.cc b/src/dram.cc index d81e2d2..53db16b 100644 --- a/src/dram.cc +++ b/src/dram.cc @@ -4,7 +4,6 @@ #include <bits/stdc++.h> #include <bitset> #include <iterator> -#include <utils.h> Dram::Dram(int delay) : Storage(delay) { this->data->resize(MEM_LINES); } @@ -25,7 +24,6 @@ Dram::write_word(void *id, signed int data, int address) return process(id, address, [&](int line, int word) { this->data->at(line).at(word) = data; }); } -// TODO requires testing int Dram::read_line(void *id, int address, std::array<signed int, LINE_SIZE> &data_line) { @@ -56,32 +54,18 @@ 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; - r = this->is_access_cleared(id); - if (r) { - int line, word; - get_memory_index(address, line, word); - request_handler(line, word); - } - return r; + if (!preprocess(id) || !this->is_data_ready()) + return 0; + + int line, word; + get_memory_index(address, line, word); + request_handler(line, word); + return 1; } -int -Dram::is_access_cleared(void *id) +void +Dram::get_memory_index(int address, int &line, int &word) { - /* 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; - } - } - return 0; + line = WRAP_ADDRESS(address) / LINE_SIZE; + word = address % LINE_SIZE; } |