summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sim/dum.cc1
-rw-r--r--src/sim/id.cc9
-rw-r--r--src/sim/if.cc5
-rw-r--r--src/sim/instrDTO.cc12
-rw-r--r--src/sim/stage.cc1
-rw-r--r--src/sim/wb.cc17
6 files changed, 23 insertions, 22 deletions
diff --git a/src/sim/dum.cc b/src/sim/dum.cc
index f712fce..ab4eaa4 100644
--- a/src/sim/dum.cc
+++ b/src/sim/dum.cc
@@ -11,7 +11,6 @@ InstrDTO *DUM::advance(Response p)
InstrDTO *r = nullptr;
if (this->curr_instr && p == WAIT) {
- this->curr_instr->set_time_of(this->id, this->clock_cycle);
r = new InstrDTO(*this->curr_instr);
delete this->curr_instr;
curr_instr = nullptr;
diff --git a/src/sim/id.cc b/src/sim/id.cc
index d4b56d2..3d5baef 100644
--- a/src/sim/id.cc
+++ b/src/sim/id.cc
@@ -38,7 +38,14 @@ Response ID::read_guard(signed int &v)
void ID::write_guard(signed int &v)
{
- this->checked_out.push_back(v);
+ // zero register shouldn't be written.
+ if (v != 0) {
+ // keep track in the instrDTO for displaying to user and writeback
+ // keep track in checked_out so we can still access this information!
+ this->checked_out.push_back(v);
+ this->curr_instr->set_checked_out(v);
+ std::cout << "checked out: " << v << std::endl;
+ }
v = this->dereference_register(v);
}
diff --git a/src/sim/if.cc b/src/sim/if.cc
index fb49749..1223149 100644
--- a/src/sim/if.cc
+++ b/src/sim/if.cc
@@ -14,7 +14,6 @@ InstrDTO *IF::advance(Response p)
if (this->curr_instr != nullptr && p == WAIT) {
// mutual consent
++this->pc;
- this->curr_instr->set_time_of(this->id, this->clock_cycle);
r = new InstrDTO(*this->curr_instr);
delete curr_instr;
curr_instr = nullptr;
@@ -23,12 +22,12 @@ InstrDTO *IF::advance(Response p)
return r;
}
-std::vector<int> IF::stage_info() {
+std::vector<int> IF::stage_info() {
std::vector<int> info;
if(this->curr_instr){
info.push_back(this->curr_instr->get_pc());
info.push_back(this->curr_instr->get_instr_bits());
- }
+ }
return info;
}
diff --git a/src/sim/instrDTO.cc b/src/sim/instrDTO.cc
index aa49b7e..a82ef28 100644
--- a/src/sim/instrDTO.cc
+++ b/src/sim/instrDTO.cc
@@ -4,6 +4,7 @@
InstrDTO::InstrDTO()
{
this->instr_bits = 0;
+ this->checked_out = -1;
this->s1 = 0;
this->s2 = 0;
this->s3 = 0;
@@ -12,10 +13,10 @@ InstrDTO::InstrDTO()
this->pc = 0;
}
-int InstrDTO::get_time_of(Accessor a) { return this->hist[a]; }
-
signed int InstrDTO::get_instr_bits() { return this->instr_bits; }
+signed int InstrDTO::get_checked_out() { return this->checked_out; }
+
signed int InstrDTO::get_s1() { return this->s1; }
signed int InstrDTO::get_s2() { return this->s2; }
@@ -28,10 +29,13 @@ Type InstrDTO::get_type() { return this->type; }
unsigned int InstrDTO::get_pc() { return this->pc; }
-void InstrDTO::set_time_of(Accessor a, int i) { this->hist[a] = i; }
-
void InstrDTO::set_instr_bits(signed int instr) { this->instr_bits = instr; }
+void InstrDTO::set_checked_out(signed int checked_out)
+{
+ this->checked_out = checked_out;
+}
+
void InstrDTO::set_s1(signed int s) { this->s1 = s; }
void InstrDTO::set_s2(signed int s) { this->s2 = s; }
diff --git a/src/sim/stage.cc b/src/sim/stage.cc
index b7926fd..7df1dba 100644
--- a/src/sim/stage.cc
+++ b/src/sim/stage.cc
@@ -38,7 +38,6 @@ InstrDTO *Stage::advance(Response p)
}
if (this->status == OK && p == WAIT && this->curr_instr) {
// mutual consent
- this->curr_instr->set_time_of(this->id, this->clock_cycle);
r = new InstrDTO(*this->curr_instr);
delete curr_instr;
curr_instr = nullptr;
diff --git a/src/sim/wb.cc b/src/sim/wb.cc
index 01768e8..3fa7dd3 100644
--- a/src/sim/wb.cc
+++ b/src/sim/wb.cc
@@ -3,6 +3,8 @@
#include "instrDTO.h"
#include "response.h"
#include "stage.h"
+#include <array>
+#include <algorithm>
WB::WB(Stage *stage) : Stage(stage) { this->id = WRITE; }
@@ -10,7 +12,7 @@ void WB::advance_helper()
{
if (this->curr_instr->get_mnemonic() != NOP &&
this->curr_instr->get_type() != INV) {
- if (this->should_write())
+ if (this->curr_instr->get_checked_out() > 0)
this->write_handler();
else if (this->should_jump())
this->jump_handler();
@@ -26,8 +28,9 @@ void WB::write_handler()
throw std::runtime_error("instruction tried to pop a register out of "
"an empty queue during writeback.");
- reg = this->checked_out.front();
this->checked_out.pop_front();
+ reg = this->curr_instr->get_checked_out();
+ std::cout << "checked in: " << reg << std::endl;
this->store_register(reg, this->curr_instr->get_s1());
}
@@ -49,13 +52,3 @@ bool WB::should_jump()
t = this->curr_instr->get_type();
return t == J;
}
-
-bool WB::should_write()
-{
- Mnemonic m;
- Type t;
-
- m = this->curr_instr->get_mnemonic();
- t = this->curr_instr->get_type();
- return (t == R || t == I) && (m != STORE && m != STOREV);
-}