summaryrefslogtreecommitdiff
path: root/src/sim/stage.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim/stage.cc')
-rw-r--r--src/sim/stage.cc52
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();
+}