diff options
-rw-r--r-- | inc/instrDTO.h | 12 | ||||
-rw-r--r-- | src/sim/if.cc | 5 | ||||
-rw-r--r-- | src/sim/instrDTO.cc | 5 | ||||
-rw-r--r-- | src/sim/stage.cc | 4 |
4 files changed, 23 insertions, 3 deletions
diff --git a/inc/instrDTO.h b/inc/instrDTO.h index 755ab9f..72ea67d 100644 --- a/inc/instrDTO.h +++ b/inc/instrDTO.h @@ -48,6 +48,10 @@ class InstrDTO * @return the program counter at the time this instruction was fetched */ unsigned int get_pc(); + /** + * @return 1 if this instruction is invalid, 0 otherwise + */ + int is_squashed(); /** * @param instr_bits @@ -82,6 +86,10 @@ class InstrDTO * @param the program counter at the time this instruction was fetched */ void set_pc(unsigned int pc); + /** + * squashes this instruction + */ + void squash(); private: /** @@ -115,6 +123,10 @@ class InstrDTO * The PC of the instruction */ unsigned int pc; + /** + * If this instruction was made dead + */ + unsigned int squashed; }; #endif /* INSTRDTO_H_INCLUDED */ diff --git a/src/sim/if.cc b/src/sim/if.cc index bab2608..6494912 100644 --- a/src/sim/if.cc +++ b/src/sim/if.cc @@ -12,8 +12,9 @@ InstrDTO *IF::advance(Response p) this->advance_helper(); if (this->curr_instr != nullptr && p == WAIT) { - // mutual consent - ++this->pc; + // don't increment PC if the PC was just set by wb + if (this->curr_instr->is_squashed() != 1) + ++this->pc; r = new InstrDTO(*this->curr_instr); delete curr_instr; curr_instr = nullptr; diff --git a/src/sim/instrDTO.cc b/src/sim/instrDTO.cc index a82ef28..fb6c82b 100644 --- a/src/sim/instrDTO.cc +++ b/src/sim/instrDTO.cc @@ -11,6 +11,7 @@ InstrDTO::InstrDTO() this->mnemonic = ADD; this->type = INV; this->pc = 0; + this->squashed = 0; } signed int InstrDTO::get_instr_bits() { return this->instr_bits; } @@ -29,6 +30,8 @@ Type InstrDTO::get_type() { return this->type; } unsigned int InstrDTO::get_pc() { return this->pc; } +int InstrDTO::is_squashed() { return this->squashed; } + void InstrDTO::set_instr_bits(signed int instr) { this->instr_bits = instr; } void InstrDTO::set_checked_out(signed int checked_out) @@ -47,3 +50,5 @@ void InstrDTO::set_mnemonic(Mnemonic m) { this->mnemonic = m; } void InstrDTO::set_type(Type t) { this->type = t; } void InstrDTO::set_pc(unsigned int pc) { this->pc = pc; } + +void InstrDTO::squash() { this->squashed = 1; } diff --git a/src/sim/stage.cc b/src/sim/stage.cc index 9528e4b..d65ca87 100644 --- a/src/sim/stage.cc +++ b/src/sim/stage.cc @@ -34,6 +34,8 @@ InstrDTO *Stage::advance(Response p) // for (long unsigned int i = 0; i < this->checked_out.size(); ++i) // std::cout << this->checked_out[i] << " "; // std::cout << std::endl; + if (this->curr_instr && this->curr_instr->is_squashed() == 1) + this->status = OK; if (this->curr_instr && this->status != OK) { this->advance_helper(); } @@ -108,7 +110,7 @@ bool Stage::is_checked_out(signed int r) void Stage::squash() { if (curr_instr) { - this->curr_instr->set_mnemonic(NOP); + this->curr_instr->squash(); this->status = OK; } if (this->next) { |