From 25ce77db5f0dbfe6064eb0553591f1b956bad24a Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 1 Apr 2025 15:57:14 -0400 Subject: Fix a lot of pipeline bugs --- src/sim/stage.cc | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/sim/stage.cc') diff --git a/src/sim/stage.cc b/src/sim/stage.cc index 31d7d0d..b10a206 100644 --- a/src/sim/stage.cc +++ b/src/sim/stage.cc @@ -2,7 +2,6 @@ #include "utils.h" #include #include -#include Stage::Stage(Stage *next) { @@ -28,10 +27,12 @@ void Stage::set_pc(unsigned int pc) { this->pc = pc; } InstrDTO *Stage::advance(Response p) { InstrDTO *r = nullptr; + InstrDTO *s = nullptr; Response n; - if (this->curr_instr && this->status != OK) + if (this->curr_instr && this->status != OK) { this->advance_helper(); + } if (this->status == OK && p == WAIT && this->curr_instr) { // mutual consent this->curr_instr->set_time_of(this->id, this->clock_cycle); @@ -42,8 +43,9 @@ InstrDTO *Stage::advance(Response p) } n = (p != WAIT || this->status != WAIT) ? STALLED : WAIT; - // the power of consent - this->curr_instr = this->next->advance(n); + s = this->next->advance(n); + if (s) + this->curr_instr = s; return r; } @@ -70,6 +72,21 @@ signed int Stage::dereference_register(signed int v) return r; } +void Stage::store_register(signed int v, signed int d) +{ + 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)); + } + + if (v >= GPR_NUM) + this->vrs[v % GPR_NUM] = d; + else + this->gprs[v] = d; +} + bool Stage::is_checked_out(signed int r) { return std::find(this->checked_out.begin(), this->checked_out.end(), r) != -- cgit v1.2.3