diff options
author | bd <bdunahu@operationnull.com> | 2025-03-29 19:45:21 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-29 19:45:21 -0400 |
commit | 6bce0485a0f9ce92bc235f063a1f9aab2d59a1c9 (patch) | |
tree | 8ac46090c2d9b8570464fcb76fd26c19a4f7f7a9 /src/sim/stage.cc | |
parent | d21a1a9caa1f1791343a5376121936e552b1124c (diff) |
Add proper read and write guard methods, clean up id test file
Diffstat (limited to 'src/sim/stage.cc')
-rw-r--r-- | src/sim/stage.cc | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/src/sim/stage.cc b/src/sim/stage.cc index 48ee494..a8f3f9e 100644 --- a/src/sim/stage.cc +++ b/src/sim/stage.cc @@ -1,9 +1,7 @@ #include "stage.h" #include "utils.h" #include <array> -#include <set> - -static Logger *global_log = Logger::getInstance(); +#include <deque> Stage::Stage(Stage *next) { @@ -16,51 +14,29 @@ Stage::~Stage() { delete this->next; }; std::array<int, GPR_NUM> Stage::gprs; std::array<int, V_NUM> Stage::vrs; -std::set<unsigned int> Stage::checked_out; +std::deque<signed int> Stage::checked_out; unsigned int Stage::pc; Storage *Stage::storage; bool Stage::is_pipelined; int Stage::clock_cycle; -Response Stage::check_out(unsigned int &v) -{ - Response r; - if (this->is_checked_out(v)) - r = BLOCKED; - else { - r = OK; - v = this->check_out_register(v); - } - return r; -} - -bool Stage::is_checked_out(unsigned int r) -{ - return this->checked_out.find(r) != this->checked_out.end(); -} - -signed int Stage::check_out_register(unsigned int v) +signed int Stage::dereference_register(signed int v) { signed int r; - this->checked_out.insert(v); - r = this->dereference_register(v); - return r; -} - -signed int Stage::dereference_register(unsigned int v) -{ - signed int r; - - if (v >= GPR_NUM + V_NUM) { - global_log->log( - ERROR, string_format( - "instruction tried to access register %d, which does " - "not exist", - v)); - exit(EXIT_FAILURE); + if (v < 0 || v >= GPR_NUM + V_NUM) { + throw std::out_of_range(string_format( + "instruction tried to access register %d, which does " + "not exist", + v)); } r = (v >= GPR_NUM) ? this->vrs[v % GPR_NUM] : this->gprs[v]; return r; } + +bool Stage::is_checked_out(signed int r) +{ + return std::find(this->checked_out.begin(), this->checked_out.end(), r) != + this->checked_out.end(); +} |