From baacedcc858d8d4857282cc7fb1881a11048a5bc Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 22 Apr 2025 20:55:05 -0400 Subject: Remove subfolders --- src/if.cc | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/if.cc (limited to 'src/if.cc') diff --git a/src/if.cc b/src/if.cc new file mode 100644 index 0000000..054c77c --- /dev/null +++ b/src/if.cc @@ -0,0 +1,65 @@ +// Simulator for the RISC-V[ECTOR] mini-ISA +// Copyright (C) 2025 Siddarth Suresh +// Copyright (C) 2025 bdunahu + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "if.h" +#include "instrDTO.h" +#include "response.h" +#include "stage.h" + +InstrDTO *IF::advance(Response p) +{ + InstrDTO *r = nullptr; + + this->advance_helper(); + if (this->curr_instr != nullptr && p == WAIT) { + // 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; + } + + return r; +} + +std::vector IF::stage_info() { + std::vector info; + if(this->curr_instr){ + info.push_back(this->curr_instr->is_squashed()); + info.push_back(this->curr_instr->get_instr_bits()); + } + return info; +} + +void IF::advance_helper() +{ + Response r; + int i; + signed int bits; + + if (this->curr_instr == nullptr && (this->is_pipelined || this->is_empty)) { + i = this->storage->read_word(this, this->pc, bits); + r = i ? OK : STALLED; + if (r == OK) { + this->curr_instr = new InstrDTO(); + this->curr_instr->set_instr_bits(bits); + this->curr_instr->set_pc(this->pc); + this->is_empty = false; + } + } +} -- cgit v1.2.3 From 302bbdc7ac18cd355f9f081cae202f5434427262 Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 22 Apr 2025 23:39:14 -0400 Subject: Use a struct for InstrDTO --- inc/instrDTO.h | 126 ++++++++++---------------------------------------------- src/ex.cc | 14 +++---- src/id.cc | 20 ++++----- src/if.cc | 14 ++++--- src/instrDTO.cc | 70 ------------------------------- src/mm.cc | 14 ++++--- src/stage.cc | 14 +++---- src/wb.cc | 24 +++++------ tests/ex.cc | 98 +++++++++++++++++++++---------------------- tests/id.cc | 48 ++++++++++----------- tests/if.cc | 8 ++-- 11 files changed, 152 insertions(+), 298 deletions(-) delete mode 100644 src/instrDTO.cc (limited to 'src/if.cc') diff --git a/inc/instrDTO.h b/inc/instrDTO.h index e6c9852..7775b20 100644 --- a/inc/instrDTO.h +++ b/inc/instrDTO.h @@ -22,127 +22,45 @@ #include #include -class InstrDTO -{ - public: - /** - * Constructor. - */ - InstrDTO(); - ~InstrDTO() = default; - - int get_id_cycle(); - /** - * @return instr_bits - */ - signed int get_instr_bits(); - /** - * @return checked_out - */ - signed int get_checked_out(); - /** - * @return s1 - */ - signed int get_s1(); - /** - * @return s2 - */ - signed int get_s2(); - /** - * @return s3 - */ - signed int get_s3(); - /** - * @return the mnemonic of the instruction - */ - Mnemonic get_mnemonic(); - /** - * @return the type of the instruction - */ - Type get_type(); - /** - * @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 - */ - void set_instr_bits(signed int); - /** - * @param checked_out - */ - void set_checked_out(signed int); - /** - * @param s1 - */ - void set_s1(signed int); - /** - * @param s2 - */ - void set_s2(signed int); - /** - * @param s3 - */ - void set_s3(signed int); - /** - * @param the mnemonic of the instruction - */ - void set_mnemonic(Mnemonic); +struct U_INT_TYPE { + signed int slot_one; + signed int slot_two; + signed int slot_three; +}; - /** - * @param the type of the instruction - */ - void set_type(Type); - /** - * @param the program counter at the time this instruction was fetched - */ - void set_pc(unsigned int pc); - /** - * squashes this instruction - */ - void squash(); +struct V_TYPE { +}; - private: +struct InstrDTO { /** - * The raw bits encoding the instruction. + * If this instruction is squashed or not. */ - signed int instr_bits; + unsigned int is_squashed : 1; /** - * The register, if any, this instruction has checked out. A checked out - * register cannot be checked out by another register. This prevents RAW - * conflicts. + * Optional slot for holding the Instruction Bits */ - signed int checked_out; + signed int slot_A; /** - * Slots in this instruction, for storing temporary registers, immediates, - * or other. - * Some instruction types may use these differently. - * The `oper` function is in charge of knowing how to parse these. + * Optional slot for holding PC */ - signed int s1; - signed int s2; - signed int s3; + signed int slot_B; /** - * The mnemonic of the operation. + * The mnemonic of the instruction. */ Mnemonic mnemonic; + // TODO delete me /** * Type of the instruction */ Type type; /** - * The PC of the instruction + * The register this instruction checks out. */ - unsigned int pc; - /** - * If this instruction was made dead - */ - unsigned int squashed; + signed int checked_out; + union { + struct U_INT_TYPE integer; + struct V_TYPE vector; + } operands; }; #endif /* INSTRDTO_H_INCLUDED */ diff --git a/src/ex.cc b/src/ex.cc index 117002c..eac24ff 100644 --- a/src/ex.cc +++ b/src/ex.cc @@ -422,15 +422,15 @@ void EX::advance_helper() unsigned int pc; Mnemonic m; - m = this->curr_instr->get_mnemonic(); - s1 = this->curr_instr->get_s1(); - s2 = this->curr_instr->get_s2(); - s3 = this->curr_instr->get_s3(); - pc = this->curr_instr->get_pc(); + m = this->curr_instr->mnemonic; + s1 = this->curr_instr->operands.integer.slot_one; + s2 = this->curr_instr->operands.integer.slot_two; + s3 = this->curr_instr->operands.integer.slot_three; + pc = this->curr_instr->slot_B; this->instr_map[m](s1, s2, s3, pc); - this->curr_instr->set_s1(s1); + this->curr_instr->operands.integer.slot_one = s1; this->status = OK; } @@ -440,7 +440,7 @@ void EX::handle_divide(signed int &s1, signed int s2, bool is_mod) this->set_condition(UF, false); if (s2 == 0) { // handle everything here - this->curr_instr->set_s1(MAX_INT); + this->curr_instr->operands.integer.slot_one = MAX_INT; this->status = OK; throw HaltException(); } else if ((s1 == -(MAX_INT)-1) && s2 == -1) { diff --git a/src/id.cc b/src/id.cc index 97bd844..14fe595 100644 --- a/src/id.cc +++ b/src/id.cc @@ -57,7 +57,7 @@ void ID::write_guard(signed int &v) // 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); + this->curr_instr->checked_out = v; } v = this->dereference_register(v); } @@ -68,17 +68,17 @@ void ID::advance_helper() Mnemonic m; Type t; - if (curr_instr->get_mnemonic() == NOP) + if (curr_instr->mnemonic == NOP) this->status = OK; else { - s1 = curr_instr->get_instr_bits(); + s1 = curr_instr->slot_A; get_instr_fields(s1, s2, s3, m, t); if (this->status == OK) { - curr_instr->set_s1(s1); - curr_instr->set_s2(s2); - curr_instr->set_s3(s3); - curr_instr->set_mnemonic(m); - curr_instr->set_type(t); + curr_instr->operands.integer.slot_one = s1; + curr_instr->operands.integer.slot_two = s2; + curr_instr->operands.integer.slot_three = s3; + curr_instr->mnemonic = m; + curr_instr->type = t; } } } @@ -221,8 +221,8 @@ std::vector ID::stage_info() { std::vector info; if (this->curr_instr) { - info.push_back(this->curr_instr->is_squashed()); - info.push_back(this->curr_instr->get_instr_bits()); + info.push_back(this->curr_instr->is_squashed); + info.push_back(this->curr_instr->slot_A); } return info; } diff --git a/src/if.cc b/src/if.cc index 054c77c..fd795c7 100644 --- a/src/if.cc +++ b/src/if.cc @@ -27,7 +27,7 @@ InstrDTO *IF::advance(Response p) this->advance_helper(); if (this->curr_instr != nullptr && p == WAIT) { // don't increment PC if the PC was just set by wb - if (this->curr_instr->is_squashed() != 1) + if (this->curr_instr->is_squashed != 1) ++this->pc; r = new InstrDTO(*this->curr_instr); delete curr_instr; @@ -40,8 +40,8 @@ InstrDTO *IF::advance(Response p) std::vector IF::stage_info() { std::vector info; if(this->curr_instr){ - info.push_back(this->curr_instr->is_squashed()); - info.push_back(this->curr_instr->get_instr_bits()); + info.push_back(this->curr_instr->is_squashed); + info.push_back(this->curr_instr->slot_A); } return info; } @@ -57,8 +57,12 @@ void IF::advance_helper() r = i ? OK : STALLED; if (r == OK) { this->curr_instr = new InstrDTO(); - this->curr_instr->set_instr_bits(bits); - this->curr_instr->set_pc(this->pc); + this->curr_instr->slot_A = bits; + this->curr_instr->slot_B = this->pc; + this->curr_instr->type = INV; + this->curr_instr->is_squashed = 0; + this->curr_instr->checked_out = -1; + this->curr_instr->mnemonic = ADD; this->is_empty = false; } } diff --git a/src/instrDTO.cc b/src/instrDTO.cc deleted file mode 100644 index cb093bb..0000000 --- a/src/instrDTO.cc +++ /dev/null @@ -1,70 +0,0 @@ -// Simulator for the RISC-V[ECTOR] mini-ISA -// Copyright (C) 2025 Siddarth Suresh -// Copyright (C) 2025 bdunahu - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#include "instrDTO.h" - -InstrDTO::InstrDTO() -{ - this->instr_bits = 0; - this->checked_out = -1; - this->s1 = 0; - this->s2 = 0; - this->s3 = 0; - this->mnemonic = ADD; - this->type = INV; - this->pc = 0; - this->squashed = 0; -} - -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; } - -signed int InstrDTO::get_s3() { return this->s3; } - -Mnemonic InstrDTO::get_mnemonic() { return this->mnemonic; } - -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) -{ - 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; } - -void InstrDTO::set_s3(signed int s) { this->s3 = s; } - -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/mm.cc b/src/mm.cc index 3df1578..ac77433 100644 --- a/src/mm.cc +++ b/src/mm.cc @@ -25,12 +25,13 @@ void MM::advance_helper() signed int data; int i; - switch (this->curr_instr->get_mnemonic()) { + switch (this->curr_instr->mnemonic) { case LOAD: - i = this->storage->read_word(this, this->curr_instr->get_s1(), data); + i = this->storage->read_word( + this, this->curr_instr->operands.integer.slot_one, data); this->status = i ? OK : STALLED; if (this->status == OK) { - this->curr_instr->set_s1(data); + this->curr_instr->operands.integer.slot_one = data; } else this->status = STALLED; break; @@ -38,7 +39,8 @@ void MM::advance_helper() case PUSH: case STORE: i = this->storage->write_word( - this, this->curr_instr->get_s2(), this->curr_instr->get_s1()); + this, this->curr_instr->operands.integer.slot_two, + this->curr_instr->operands.integer.slot_one); this->status = i ? OK : STALLED; if (this->status != OK) { this->status = STALLED; @@ -46,10 +48,10 @@ void MM::advance_helper() break; case POP: - i = this->storage->read_word(this, this->curr_instr->get_s3(), data); + i = this->storage->read_word(this, this->curr_instr->operands.integer.slot_three, data); this->status = i ? OK : STALLED; if (this->status == OK) { - this->curr_instr->set_s3(data); + this->curr_instr->operands.integer.slot_three = data; } else this->status = STALLED; break; diff --git a/src/stage.cc b/src/stage.cc index b7be595..e5a4333 100644 --- a/src/stage.cc +++ b/src/stage.cc @@ -45,7 +45,7 @@ InstrDTO *Stage::advance(Response p) InstrDTO *s = nullptr; Response n; - if (this->curr_instr && this->curr_instr->is_squashed() == 1) + if (this->curr_instr && this->curr_instr->is_squashed == 1) this->status = OK; if (this->curr_instr && this->status != OK) { this->advance_helper(); @@ -69,11 +69,11 @@ std::vector Stage::stage_info() { std::vector info; if (this->curr_instr) { - info.push_back(this->curr_instr->get_mnemonic()); - info.push_back(this->curr_instr->is_squashed()); - info.push_back(this->curr_instr->get_s1()); - info.push_back(this->curr_instr->get_s2()); - info.push_back(this->curr_instr->get_s3()); + info.push_back(this->curr_instr->mnemonic); + info.push_back(this->curr_instr->is_squashed); + info.push_back(this->curr_instr->operands.integer.slot_one); + info.push_back(this->curr_instr->operands.integer.slot_two); + info.push_back(this->curr_instr->operands.integer.slot_three); } return info; } @@ -121,7 +121,7 @@ bool Stage::is_checked_out(signed int r) void Stage::squash() { if (curr_instr) { - this->curr_instr->squash(); + this->curr_instr->is_squashed = 1; this->status = OK; } if (this->next) { diff --git a/src/wb.cc b/src/wb.cc index 55591b6..08d512b 100644 --- a/src/wb.cc +++ b/src/wb.cc @@ -24,9 +24,9 @@ void WB::advance_helper() { - if (this->curr_instr->get_mnemonic() != NOP && - this->curr_instr->get_type() != INV) { - if (this->curr_instr->get_checked_out() > 0) + if (this->curr_instr->mnemonic != NOP && + this->curr_instr->type != INV) { + if (this->curr_instr->checked_out > 0) this->write_handler(); else if (this->should_jump()) this->jump_handler(); @@ -42,25 +42,25 @@ void WB::write_handler() throw std::runtime_error("instruction tried to pop a register out of " "an empty queue during writeback."); - if (this->curr_instr->get_mnemonic() == POP) { + if (this->curr_instr->mnemonic == POP) { // POP performs a second register write reg = this->checked_out.front(); this->checked_out.pop_front(); - this->store_register(reg, this->curr_instr->get_s3()); + this->store_register(reg, this->curr_instr->operands.integer.slot_three); } this->checked_out.pop_front(); - reg = this->curr_instr->get_checked_out(); - this->store_register(reg, this->curr_instr->get_s1()); + reg = this->curr_instr->checked_out; + this->store_register(reg, this->curr_instr->operands.integer.slot_one); } void WB::jump_handler() { - if (this->curr_instr->get_s1() > 0) { - if (this->curr_instr->get_mnemonic() == JAL) - this->gprs[1] = this->curr_instr->get_pc() + 1;; - this->pc = this->curr_instr->get_s1(); + if (this->curr_instr->operands.integer.slot_one > 0) { + if (this->curr_instr->mnemonic == JAL) + this->gprs[1] = this->curr_instr->slot_B + 1;; + this->pc = this->curr_instr->operands.integer.slot_one; this->checked_out = {}; this->next->squash(); } @@ -70,6 +70,6 @@ bool WB::should_jump() { Type t; - t = this->curr_instr->get_type(); + t = this->curr_instr->type; return t == J; } diff --git a/tests/ex.cc b/tests/ex.cc index 400916e..1fc333e 100644 --- a/tests/ex.cc +++ b/tests/ex.cc @@ -27,10 +27,10 @@ class EXFixture execute_instr(signed int s1, signed int s2, signed int s3, Mnemonic m) { InstrDTO *i = new InstrDTO(); - i->set_s1(s1); - i->set_s2(s2); - i->set_s3(s3); - i->set_mnemonic(m); + i->operands.integer.slot_one = s1; + i->operands.integer.slot_two = s2; + i->operands.integer.slot_three = s3; + i->mnemonic = m; this->dum->set_curr_instr(i); i = this->ct->advance(WAIT); @@ -57,7 +57,7 @@ TEST_CASE_METHOD(EXFixture, "ADD within bounds", "[ex]") s1 = 42000, s2 = -41958, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 42); + CHECK(i->operands.integer.slot_one == 42); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -74,7 +74,7 @@ TEST_CASE_METHOD(EXFixture, "ADD overflow", "[ex]") s1 = MAX_INT, s2 = 1, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -(MAX_INT)-1); + CHECK(i->operands.integer.slot_one == -(MAX_INT)-1); CHECK(ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -91,7 +91,7 @@ TEST_CASE_METHOD(EXFixture, "ADD underflow", "[ex]") s1 = -(MAX_INT)-1, s2 = -1, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == MAX_INT); + CHECK(i->operands.integer.slot_one == MAX_INT); CHECK(!ct->get_condition(OF)); CHECK(ct->get_condition(UF)); @@ -108,7 +108,7 @@ TEST_CASE_METHOD(EXFixture, "SUB within bounds", "[ex]") s1 = 200, s2 = 131, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 69); + CHECK(i->operands.integer.slot_one == 69); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -125,7 +125,7 @@ TEST_CASE_METHOD(EXFixture, "SUB overflow", "[ex]") s1 = MAX_INT, s2 = -1, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -(MAX_INT)-1); + CHECK(i->operands.integer.slot_one == -(MAX_INT)-1); CHECK(ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -142,7 +142,7 @@ TEST_CASE_METHOD(EXFixture, "SUB underflow", "[ex]") s1 = -(MAX_INT)-1, s2 = 1, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == MAX_INT); + CHECK(i->operands.integer.slot_one == MAX_INT); CHECK(!ct->get_condition(OF)); CHECK(ct->get_condition(UF)); @@ -159,7 +159,7 @@ TEST_CASE_METHOD(EXFixture, "MUL within bounds", "[ex]") s1 = 200, s2 = 200, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 40000); + CHECK(i->operands.integer.slot_one == 40000); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -176,7 +176,7 @@ TEST_CASE_METHOD(EXFixture, "MUL overflow", "[ex]") s1 = MAX_INT, s2 = MAX_INT, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 1); + CHECK(i->operands.integer.slot_one == 1); CHECK(ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -193,7 +193,7 @@ TEST_CASE_METHOD(EXFixture, "MUL underflow", "[ex]") s1 = MAX_INT, s2 = -MAX_INT, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -1); + CHECK(i->operands.integer.slot_one == -1); CHECK(!ct->get_condition(OF)); CHECK(ct->get_condition(UF)); @@ -210,7 +210,7 @@ TEST_CASE_METHOD(EXFixture, "QUOT within bounds", "[ex]") s1 = 2043, s2 = 40, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 51); + CHECK(i->operands.integer.slot_one == 51); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -227,7 +227,7 @@ TEST_CASE_METHOD(EXFixture, "QUOT overflow", "[ex]") s1 = -(MAX_INT)-1, s2 = -1, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -(MAX_INT)-1); + CHECK(i->operands.integer.slot_one == -(MAX_INT)-1); CHECK(ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -258,7 +258,7 @@ TEST_CASE_METHOD(EXFixture, "REM within bounds", "[ex]") s1 = 2043, s2 = 40, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 3); + CHECK(i->operands.integer.slot_one == 3); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -289,7 +289,7 @@ TEST_CASE_METHOD(EXFixture, "SFTR within bounds", "[ex]") s1 = 1300, s2 = 6, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 20); + CHECK(i->operands.integer.slot_one == 20); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -314,7 +314,7 @@ TEST_CASE_METHOD(EXFixture, "SFTL within bounds", "[ex]") s1 = 13, s2 = 6, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 832); + CHECK(i->operands.integer.slot_one == 832); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -339,7 +339,7 @@ TEST_CASE_METHOD(EXFixture, "AND", "[ex]") s1 = 1234, s2 = 5678, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 1026); + CHECK(i->operands.integer.slot_one == 1026); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -356,7 +356,7 @@ TEST_CASE_METHOD(EXFixture, "OR", "[ex]") s1 = 1234, s2 = 5678, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 5886); + CHECK(i->operands.integer.slot_one == 5886); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -373,7 +373,7 @@ TEST_CASE_METHOD(EXFixture, "NOT", "[ex]") s1 = 1234, s2 = -1, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -1235); + CHECK(i->operands.integer.slot_one == -1235); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -390,7 +390,7 @@ TEST_CASE_METHOD(EXFixture, "XOR", "[ex]") s1 = 1234, s2 = 5678, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 4860); + CHECK(i->operands.integer.slot_one == 4860); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -456,7 +456,7 @@ TEST_CASE_METHOD(EXFixture, "CMP less", "[ex]") i = execute_instr(s1, s2, s3, m); // should not be changed - CHECK(i->get_s1() == -1); + CHECK(i->operands.integer.slot_one == -1); CHECK(!ct->get_condition(EQ)); CHECK(!ct->get_condition(GT)); @@ -477,7 +477,7 @@ TEST_CASE_METHOD(EXFixture, "CMP equal", "[ex]") i = execute_instr(s1, s2, s3, m); // should not be changed - CHECK(i->get_s1() == 20); + CHECK(i->operands.integer.slot_one == 20); CHECK(ct->get_condition(EQ)); CHECK(!ct->get_condition(GT)); @@ -498,7 +498,7 @@ TEST_CASE_METHOD(EXFixture, "CMP greater", "[ex]") i = execute_instr(s1, s2, s3, m); // should not be changed - CHECK(i->get_s1() == 21); + CHECK(i->operands.integer.slot_one == 21); CHECK(!ct->get_condition(EQ)); CHECK(ct->get_condition(GT)); @@ -531,7 +531,7 @@ TEST_CASE_METHOD(EXFixture, "LOAD", "[ex]") s3 = -41958; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 42); + CHECK(i->operands.integer.slot_one == 42); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -553,7 +553,7 @@ TEST_CASE_METHOD(EXFixture, "ADDI within bounds", "[ex]") s3 = -41958; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 42); + CHECK(i->operands.integer.slot_one == 42); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -570,7 +570,7 @@ TEST_CASE_METHOD(EXFixture, "ADDI overflow", "[ex]") s1 = MAX_INT, s2 = 0, s3 = 1; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -(MAX_INT)-1); + CHECK(i->operands.integer.slot_one == -(MAX_INT)-1); CHECK(ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -587,7 +587,7 @@ TEST_CASE_METHOD(EXFixture, "ADDI underflow", "[ex]") s1 = -(MAX_INT)-1, s2 = 0, s3 = -1; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == MAX_INT); + CHECK(i->operands.integer.slot_one == MAX_INT); CHECK(!ct->get_condition(OF)); CHECK(ct->get_condition(UF)); @@ -604,7 +604,7 @@ TEST_CASE_METHOD(EXFixture, "SUBI within bounds", "[ex]") s1 = 200, s2 = 0, s3 = 131; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 69); + CHECK(i->operands.integer.slot_one == 69); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -621,7 +621,7 @@ TEST_CASE_METHOD(EXFixture, "SUBI overflow", "[ex]") s1 = -(MAX_INT)-1, s2 = 0, s3 = 1; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == MAX_INT); + CHECK(i->operands.integer.slot_one == MAX_INT); CHECK(!ct->get_condition(OF)); CHECK(ct->get_condition(UF)); @@ -638,7 +638,7 @@ TEST_CASE_METHOD(EXFixture, "SUBI underflow", "[ex]") s1 = MAX_INT, s2 = 0, s3 = -1; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -(MAX_INT)-1); + CHECK(i->operands.integer.slot_one == -(MAX_INT)-1); CHECK(ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -655,7 +655,7 @@ TEST_CASE_METHOD(EXFixture, "SFTRI within bounds", "[ex]") s1 = 1300, s2 = 0, s3 = 6; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 20); + CHECK(i->operands.integer.slot_one == 20); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -680,7 +680,7 @@ TEST_CASE_METHOD(EXFixture, "SFTLI within bounds", "[ex]") s1 = 13, s2 = 0, s3 = 6; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 832); + CHECK(i->operands.integer.slot_one == 832); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -705,7 +705,7 @@ TEST_CASE_METHOD(EXFixture, "ANDI", "[ex]") s1 = 1234, s2 = 0, s3 = 5678; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 1026); + CHECK(i->operands.integer.slot_one == 1026); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -722,7 +722,7 @@ TEST_CASE_METHOD(EXFixture, "ORI", "[ex]") s1 = 1234, s2 = 0, s3 = 5678; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 5886); + CHECK(i->operands.integer.slot_one == 5886); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -739,7 +739,7 @@ TEST_CASE_METHOD(EXFixture, "XORI", "[ex]") s1 = 1234, s2 = 0, s3 = 5678; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 4860); + CHECK(i->operands.integer.slot_one == 4860); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -756,7 +756,7 @@ TEST_CASE_METHOD(EXFixture, "STORE", "[ex]") s1 = 42000, s2 = 0, s3 = -41958; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 42); + CHECK(i->operands.integer.slot_one == 42); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -777,7 +777,7 @@ TEST_CASE_METHOD(EXFixture, "JMP", "[ex]") s1 = 42000, s2 = -41958, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 42); + CHECK(i->operands.integer.slot_one == 42); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -794,7 +794,7 @@ TEST_CASE_METHOD(EXFixture, "JRL", "[ex]") s1 = 100, s2 = 69, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 69); + CHECK(i->operands.integer.slot_one == 69); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -811,7 +811,7 @@ TEST_CASE_METHOD(EXFixture, "JAL", "[ex]") s1 = 42000, s2 = -41958, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 42); + CHECK(i->operands.integer.slot_one == 42); CHECK(!ct->get_condition(OF)); CHECK(!ct->get_condition(UF)); @@ -828,7 +828,7 @@ TEST_CASE_METHOD(EXFixture, "BEQ no cond", "[ex]") s1 = 100, s2 = 50, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -1); + CHECK(i->operands.integer.slot_one == -1); delete i; } @@ -844,7 +844,7 @@ TEST_CASE_METHOD(EXFixture, "BEQ", "[ex]") this->ct->set_condition(EQ, true); i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 50); + CHECK(i->operands.integer.slot_one == 50); delete i; } @@ -859,7 +859,7 @@ TEST_CASE_METHOD(EXFixture, "BGT no cond", "[ex]") s1 = 100, s2 = 50, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -1); + CHECK(i->operands.integer.slot_one == -1); delete i; } @@ -875,7 +875,7 @@ TEST_CASE_METHOD(EXFixture, "BGT", "[ex]") this->ct->set_condition(GT, true); i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 50); + CHECK(i->operands.integer.slot_one == 50); delete i; } @@ -890,7 +890,7 @@ TEST_CASE_METHOD(EXFixture, "BUF no cond", "[ex]") s1 = 100, s2 = -42027, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -1); + CHECK(i->operands.integer.slot_one == -1); delete i; } @@ -906,7 +906,7 @@ TEST_CASE_METHOD(EXFixture, "BUF", "[ex]") this->ct->set_condition(UF, true); i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 50); + CHECK(i->operands.integer.slot_one == 50); delete i; } @@ -921,7 +921,7 @@ TEST_CASE_METHOD(EXFixture, "BOF no cond", "[ex]") s1 = 100, s2 = -42027, s3 = 0; i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == -1); + CHECK(i->operands.integer.slot_one == -1); delete i; } @@ -937,7 +937,7 @@ TEST_CASE_METHOD(EXFixture, "BOF", "[ex]") this->ct->set_condition(OF, true); i = execute_instr(s1, s2, s3, m); - CHECK(i->get_s1() == 50); + CHECK(i->operands.integer.slot_one == 50); delete i; } diff --git a/tests/id.cc b/tests/id.cc index 321c013..e82adc3 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -26,7 +26,7 @@ class IDFixture InstrDTO *decode_bits(signed int raw) { InstrDTO *i = new InstrDTO(); - i->set_instr_bits(raw); + i->slot_A = raw; this->dum->set_curr_instr(i); i = this->ct->advance(WAIT); @@ -92,7 +92,7 @@ TEST_CASE_METHOD(IDFixture, "Parse invalid type", "[id]") t = this->encode_R_type(0b0, 0b1, 0b10, 0b11, 0b11); i = this->decode_bits(t); - CHECK(i->get_mnemonic() == NOP); + CHECK(i->mnemonic == NOP); delete i; } @@ -105,10 +105,10 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # one", "[id]") t = this->encode_R_type(0b101, 0b110, 0b111, 0b11, 0b0); i = this->decode_bits(t); - CHECK(i->get_s1() == 0x00000000); // registers are empty - CHECK(i->get_s2() == 0x00000000); - CHECK(i->get_s3() == 0x00000000); - CHECK(i->get_mnemonic() == MUL); + CHECK(i->operands.integer.slot_one == 0x00000000); // registers are empty + CHECK(i->operands.integer.slot_two == 0x00000000); + CHECK(i->operands.integer.slot_three == 0x00000000); + CHECK(i->mnemonic == MUL); delete i; } @@ -121,10 +121,10 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # two", "[id]") t = this->encode_R_type(0b10000, 0b01000, 0b00100, 0b10, 0b0); i = this->decode_bits(t); - CHECK(i->get_s1() == 0x00000000); // registers are empty - CHECK(i->get_s2() == 0x00000000); - CHECK(i->get_s3() == 0x00000000); - CHECK(i->get_mnemonic() == SUB); + CHECK(i->operands.integer.slot_one == 0x00000000); // registers are empty + CHECK(i->operands.integer.slot_two == 0x00000000); + CHECK(i->operands.integer.slot_three == 0x00000000); + CHECK(i->mnemonic == SUB); delete i; } @@ -137,10 +137,10 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # one", "[id]") t = this->encode_I_type(0xF, 0b101, 0b110, 0b0111, 0b1); i = this->decode_bits(t); - CHECK(i->get_s1() == 0x00000000); // registers are empty - CHECK(i->get_s2() == 0x00000000); - CHECK(i->get_s3() == 0xF); - CHECK(i->get_mnemonic() == ANDI); + CHECK(i->operands.integer.slot_one == 0x00000000); // registers are empty + CHECK(i->operands.integer.slot_two == 0x00000000); + CHECK(i->operands.integer.slot_three == 0xF); + CHECK(i->mnemonic == ANDI); delete i; } @@ -153,10 +153,10 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # two", "[id]") t = this->encode_I_type(0xCC, 0b101, 0b110, 0b1011, 0b1); i = this->decode_bits(t); - CHECK(i->get_s1() == 0x00000000); // registers are empty - CHECK(i->get_s2() == 0x00000000); - CHECK(i->get_s3() == 0xCC); - CHECK(i->get_mnemonic() == STOREV); + CHECK(i->operands.integer.slot_one == 0x00000000); // registers are empty + CHECK(i->operands.integer.slot_two == 0x00000000); + CHECK(i->operands.integer.slot_three == 0xCC); + CHECK(i->mnemonic == STOREV); delete i; } @@ -169,9 +169,9 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # one", "[id]") t = this->encode_J_type(0x3456, 0b10101, 0b0111, 0b10); i = this->decode_bits(t); - CHECK(i->get_s1() == 0x00000000); // registers are empty - CHECK(i->get_s2() == 0x3456); - CHECK(i->get_mnemonic() == BOF); + CHECK(i->operands.integer.slot_one == 0x00000000); // registers are empty + CHECK(i->operands.integer.slot_two == 0x3456); + CHECK(i->mnemonic == BOF); delete i; } @@ -185,9 +185,9 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") i = this->decode_bits(t); t = 0xFFFBBCCF; - CHECK(i->get_s1() == 0x00000000); // registers are empty - CHECK(i->get_s2() == t); - CHECK(i->get_mnemonic() == JAL); + CHECK(i->operands.integer.slot_one == 0x00000000); // registers are empty + CHECK(i->operands.integer.slot_two == t); + CHECK(i->mnemonic == JAL); delete i; } diff --git a/tests/if.cc b/tests/if.cc index 8b30d0e..59a7890 100644 --- a/tests/if.cc +++ b/tests/if.cc @@ -75,7 +75,7 @@ TEST_CASE_METHOD(IFFixture, "fetch returns single instuction", "[if_pipe]") InstrDTO *i; i = this->fetch_through(); - REQUIRE(i->get_instr_bits() == this->p[0]); + REQUIRE(i->slot_A == this->p[0]); delete i; } @@ -88,13 +88,13 @@ TEST_CASE_METHOD(IFFixture, "fetch returns two instuctions", "[if_pipe]") expected_cycles = this->m_delay + this->c_delay + 2; i = this->fetch_through(); - REQUIRE(i->get_instr_bits() == this->p[0]); + REQUIRE(i->slot_A == this->p[0]); delete i; expected_cycles += this->c_delay + 1; i = this->fetch_cache(); - REQUIRE(i->get_instr_bits() == this->p[1]); + REQUIRE(i->slot_A == this->p[1]); delete i; } @@ -124,7 +124,7 @@ TEST_CASE_METHOD(IFFixture, "fetch waits with old instruction", "[if_pipe]") i = this->ct->advance(WAIT); REQUIRE(i != nullptr); - REQUIRE(i->get_instr_bits() == this->p[0]); + REQUIRE(i->slot_A == this->p[0]); delete i; } -- cgit v1.2.3 From 263a5d86e0b1acde39523bdd9a49521752255c72 Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 22 Apr 2025 23:55:32 -0400 Subject: Remove 'type' field out of InstrDTO --- inc/id.h | 2 +- inc/instr.h | 2 -- inc/instrDTO.h | 5 ----- src/id.cc | 10 ++-------- src/if.cc | 1 - src/wb.cc | 21 ++++++++++++--------- 6 files changed, 15 insertions(+), 26 deletions(-) (limited to 'src/if.cc') diff --git a/inc/id.h b/inc/id.h index dabf206..39485b6 100644 --- a/inc/id.h +++ b/inc/id.h @@ -78,7 +78,7 @@ class ID : public Stage * @param the resulting third field, which varies per type. * @param the resulting mnemonic. */ - void get_instr_fields(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m, Type &t); + void get_instr_fields(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); void decode_R_type(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); void decode_I_type(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); void decode_J_type(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); diff --git a/inc/instr.h b/inc/instr.h index 62af09a..85eae5b 100644 --- a/inc/instr.h +++ b/inc/instr.h @@ -62,8 +62,6 @@ enum Mnemonic { NOP, }; -enum Type { R, I, J, INV }; - namespace instr { // clang-format off diff --git a/inc/instrDTO.h b/inc/instrDTO.h index 7775b20..6ab14b2 100644 --- a/inc/instrDTO.h +++ b/inc/instrDTO.h @@ -48,11 +48,6 @@ struct InstrDTO { * The mnemonic of the instruction. */ Mnemonic mnemonic; - // TODO delete me - /** - * Type of the instruction - */ - Type type; /** * The register this instruction checks out. */ diff --git a/src/id.cc b/src/id.cc index 14fe595..0135c21 100644 --- a/src/id.cc +++ b/src/id.cc @@ -66,44 +66,38 @@ void ID::advance_helper() { signed int s1, s2, s3; Mnemonic m; - Type t; if (curr_instr->mnemonic == NOP) this->status = OK; else { s1 = curr_instr->slot_A; - get_instr_fields(s1, s2, s3, m, t); + get_instr_fields(s1, s2, s3, m); if (this->status == OK) { curr_instr->operands.integer.slot_one = s1; curr_instr->operands.integer.slot_two = s2; curr_instr->operands.integer.slot_three = s3; curr_instr->mnemonic = m; - curr_instr->type = t; } } } void ID::get_instr_fields( - signed int &s1, signed int &s2, signed int &s3, Mnemonic &m, Type &t) + signed int &s1, signed int &s2, signed int &s3, Mnemonic &m) { unsigned int type; this->split_instr(s1, type, m); switch (type) { case 0b00: - t = R; this->decode_R_type(s1, s2, s3, m); break; case 0b01: - t = I; this->decode_I_type(s1, s2, s3, m); break; case 0b10: - t = J; this->decode_J_type(s1, s2, s3, m); break; case 0b11: - t = INV; this->status = OK; } } diff --git a/src/if.cc b/src/if.cc index fd795c7..62a105c 100644 --- a/src/if.cc +++ b/src/if.cc @@ -59,7 +59,6 @@ void IF::advance_helper() this->curr_instr = new InstrDTO(); this->curr_instr->slot_A = bits; this->curr_instr->slot_B = this->pc; - this->curr_instr->type = INV; this->curr_instr->is_squashed = 0; this->curr_instr->checked_out = -1; this->curr_instr->mnemonic = ADD; diff --git a/src/wb.cc b/src/wb.cc index 08d512b..cd24c6a 100644 --- a/src/wb.cc +++ b/src/wb.cc @@ -19,13 +19,12 @@ #include "instrDTO.h" #include "response.h" #include "stage.h" -#include #include +#include void WB::advance_helper() { - if (this->curr_instr->mnemonic != NOP && - this->curr_instr->type != INV) { + if (this->curr_instr->mnemonic != NOP) { if (this->curr_instr->checked_out > 0) this->write_handler(); else if (this->should_jump()) @@ -46,30 +45,34 @@ void WB::write_handler() // POP performs a second register write reg = this->checked_out.front(); this->checked_out.pop_front(); - this->store_register(reg, this->curr_instr->operands.integer.slot_three); + this->store_register( + reg, this->curr_instr->operands.integer.slot_three); } this->checked_out.pop_front(); reg = this->curr_instr->checked_out; this->store_register(reg, this->curr_instr->operands.integer.slot_one); - } void WB::jump_handler() { if (this->curr_instr->operands.integer.slot_one > 0) { if (this->curr_instr->mnemonic == JAL) - this->gprs[1] = this->curr_instr->slot_B + 1;; + this->gprs[1] = this->curr_instr->slot_B + 1; + ; this->pc = this->curr_instr->operands.integer.slot_one; this->checked_out = {}; this->next->squash(); } } +// TODO clean this up... bool WB::should_jump() { - Type t; + vector Js = {JMP, JRL, JAL, BEQ, BGT, BUF, BOF, PUSH, POP, RET}; - t = this->curr_instr->type; - return t == J; + if (find(Js.begin(), Js.end(), this->curr_instr->mnemonic) != Js.end()) + return true; + else + return false; } -- cgit v1.2.3 From 8e33ba4499bced747f66ed436211876d220342d6 Mon Sep 17 00:00:00 2001 From: bd Date: Wed, 23 Apr 2025 00:47:24 -0400 Subject: Rename Response.WAIT to READY, delete BLOCKED --- inc/response.h | 3 +-- inc/stage.h | 2 +- src/controller.cc | 2 +- src/if.cc | 2 +- src/response.cc | 2 +- src/stage.cc | 8 ++++---- tests/controller.cc | 2 +- tests/dum.h | 2 +- tests/ex.cc | 4 ++-- tests/id.cc | 4 ++-- tests/if.cc | 8 ++++---- 11 files changed, 19 insertions(+), 20 deletions(-) (limited to 'src/if.cc') diff --git a/inc/response.h b/inc/response.h index 501923a..c1f38e7 100644 --- a/inc/response.h +++ b/inc/response.h @@ -21,8 +21,7 @@ enum Response { OK, - WAIT, - BLOCKED, + READY, STALLED, }; diff --git a/inc/stage.h b/inc/stage.h index 745e0ff..7dcb7b4 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -50,7 +50,7 @@ class Stage * ready to accept a new instruction object next cycle. * @return a DTO object containing the next instruction to be processed. * - * Must set the status to WAIT when the current instruction is evicted.. + * Must set the status to READY when the current instruction is evicted.. */ virtual InstrDTO *advance(Response p); diff --git a/src/controller.cc b/src/controller.cc index 1c379ec..8df4b97 100644 --- a/src/controller.cc +++ b/src/controller.cc @@ -38,7 +38,7 @@ void Controller::run_for(int number) int i; for (i = 0; i < number; ++i) { try { - this->advance(WAIT); + this->advance(READY); } catch (HaltException &e) { break; } diff --git a/src/if.cc b/src/if.cc index 62a105c..5f07ee2 100644 --- a/src/if.cc +++ b/src/if.cc @@ -25,7 +25,7 @@ InstrDTO *IF::advance(Response p) InstrDTO *r = nullptr; this->advance_helper(); - if (this->curr_instr != nullptr && p == WAIT) { + if (this->curr_instr != nullptr && p == READY) { // don't increment PC if the PC was just set by wb if (this->curr_instr->is_squashed != 1) ++this->pc; diff --git a/src/response.cc b/src/response.cc index d56419a..7624b82 100644 --- a/src/response.cc +++ b/src/response.cc @@ -20,6 +20,6 @@ std::ostream &operator<<(std::ostream &os, Response r) { - const std::string nameR[] = {"OK", "WAIT", "BLOCKED", "STALLED"}; + const std::string nameR[] = {"OK", "READY", "STALLED"}; return os << nameR[r]; } diff --git a/src/stage.cc b/src/stage.cc index e5a4333..55756b6 100644 --- a/src/stage.cc +++ b/src/stage.cc @@ -23,7 +23,7 @@ Stage::Stage(Stage *next) { this->next = next; this->curr_instr = nullptr; - this->status = WAIT; + this->status = READY; } Stage::~Stage() { delete this->next; }; @@ -50,15 +50,15 @@ InstrDTO *Stage::advance(Response p) if (this->curr_instr && this->status != OK) { this->advance_helper(); } - if (this->status == OK && p == WAIT && this->curr_instr) { + if (this->status == OK && p == READY && this->curr_instr) { // mutual consent r = new InstrDTO(*this->curr_instr); delete curr_instr; curr_instr = nullptr; - this->status = WAIT; + this->status = READY; } - n = (p != WAIT || this->status != WAIT) ? STALLED : WAIT; + n = (p != READY || this->status != READY) ? STALLED : READY; s = this->next->advance(n); if (s) this->curr_instr = s; diff --git a/tests/controller.cc b/tests/controller.cc index 1d1ddb6..9bc71f6 100644 --- a/tests/controller.cc +++ b/tests/controller.cc @@ -37,7 +37,7 @@ class ControllerPipeFixture InstrDTO *i = nullptr; int j; for (j = 0; j < this->stage_num + 1; ++j) { - i = this->ct->advance(WAIT); + i = this->ct->advance(READY); REQUIRE(i == nullptr); } } diff --git a/tests/dum.h b/tests/dum.h index 5bfc646..e60ffad 100644 --- a/tests/dum.h +++ b/tests/dum.h @@ -17,7 +17,7 @@ class DUM : public Stage { InstrDTO *r = nullptr; - if (this->curr_instr && p == WAIT) { + if (this->curr_instr && p == READY) { r = new InstrDTO(*this->curr_instr); delete this->curr_instr; curr_instr = nullptr; diff --git a/tests/ex.cc b/tests/ex.cc index 1fc333e..5972182 100644 --- a/tests/ex.cc +++ b/tests/ex.cc @@ -33,9 +33,9 @@ class EXFixture i->mnemonic = m; this->dum->set_curr_instr(i); - i = this->ct->advance(WAIT); + i = this->ct->advance(READY); REQUIRE(i == nullptr); - i = this->ct->advance(WAIT); + i = this->ct->advance(READY); REQUIRE(i != nullptr); return i; diff --git a/tests/id.cc b/tests/id.cc index e82adc3..a81e967 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -29,9 +29,9 @@ class IDFixture i->slot_A = raw; this->dum->set_curr_instr(i); - i = this->ct->advance(WAIT); + i = this->ct->advance(READY); REQUIRE(i == nullptr); - i = this->ct->advance(WAIT); + i = this->ct->advance(READY); REQUIRE(i != nullptr); return i; diff --git a/tests/if.cc b/tests/if.cc index 59a7890..e2a7dbe 100644 --- a/tests/if.cc +++ b/tests/if.cc @@ -36,7 +36,7 @@ class IFFixture int i; for (i = 0; i < this->m_delay + 1; ++i) { - r = this->ct->advance(WAIT); + r = this->ct->advance(READY); // check response CHECK(r == nullptr); } @@ -52,11 +52,11 @@ class IFFixture int i; for (i = 0; i < this->c_delay; ++i) { - r = this->ct->advance(WAIT); + r = this->ct->advance(READY); // check response REQUIRE(r == nullptr); } - r = this->ct->advance(WAIT); + r = this->ct->advance(READY); // check response REQUIRE(r != nullptr); return r; @@ -122,7 +122,7 @@ TEST_CASE_METHOD(IFFixture, "fetch waits with old instruction", "[if_pipe]") REQUIRE(i != nullptr); } - i = this->ct->advance(WAIT); + i = this->ct->advance(READY); REQUIRE(i != nullptr); REQUIRE(i->slot_A == this->p[0]); -- cgit v1.2.3 From a3528b83dd10fa9cdf7ef5635f615c1b295f3f4c Mon Sep 17 00:00:00 2001 From: bd Date: Fri, 25 Apr 2025 21:12:58 -0400 Subject: Pass full DTO to GUI --- gui/gui.cc | 59 +++++++++++++++++++++++++++++------------------------------ gui/gui.h | 10 +++++----- gui/worker.cc | 10 +++++----- gui/worker.h | 10 +++++----- inc/id.h | 2 -- inc/if.h | 2 -- inc/stage.h | 15 ++++++++------- src/id.cc | 10 ---------- src/if.cc | 9 --------- src/stage.cc | 13 +------------ 10 files changed, 53 insertions(+), 87 deletions(-) (limited to 'src/if.cc') diff --git a/gui/gui.cc b/gui/gui.cc index 496a443..bf9e6cf 100644 --- a/gui/gui.cc +++ b/gui/gui.cc @@ -169,36 +169,36 @@ void GUI::on_worker_refresh_gui(int cycles, int pc) ui->cycle_counter->set_value(cycles); } -void GUI::onWorkerFetchInfo(const std::vector info) +void GUI::onWorkerFetchInfo(const InstrDTO *i) { - if (!info.empty()) { - ui->fetch_squashed->setText(QString::number(info[0])); - ui->fetch_bits->set_value(info[1]); + if (i) { + ui->fetch_squashed->setText(QString::number(i->is_squashed)); + ui->fetch_bits->set_value(i->slot_A); } else { ui->fetch_squashed->clear(); ui->fetch_bits->clear(); } } -void GUI::onWorkerDecodeInfo(const std::vector info) +void GUI::onWorkerDecodeInfo(const InstrDTO *i) { - if (!info.empty()) { - ui->decode_squashed->setText(QString::number(info[0])); - ui->decode_bits->set_value(info[1]); + if (i) { + ui->decode_squashed->setText(QString::number(i->is_squashed)); + ui->decode_bits->set_value(i->slot_A); } else { ui->decode_squashed->clear(); ui->decode_bits->clear(); } } -void GUI::onWorkerExecuteInfo(const std::vector info) +void GUI::onWorkerExecuteInfo(const InstrDTO *i) { - if (!info.empty()) { - ui->execute_mnemonic->setText(mnemonicToString((Mnemonic)info[0])); - ui->execute_squashed->setText(QString::number(info[1])); - ui->execute_s1->set_value(info[2]); - ui->execute_s2->set_value(info[3]); - ui->execute_s3->set_value(info[4]); + if (i) { + ui->execute_mnemonic->setText(mnemonicToString(i->mnemonic)); + ui->execute_squashed->setText(QString::number(i->is_squashed)); + ui->execute_s1->set_value(i->operands.integer.slot_one); + ui->execute_s2->set_value(i->operands.integer.slot_two); + ui->execute_s3->set_value(i->operands.integer.slot_three); } else { ui->execute_mnemonic->clear(); ui->execute_squashed->clear(); @@ -208,15 +208,14 @@ void GUI::onWorkerExecuteInfo(const std::vector info) } } -void GUI::onWorkerMemoryInfo(const std::vector info) +void GUI::onWorkerMemoryInfo(const InstrDTO *i) { - if (!info.empty()) { - std::cout << "this " << info[3] << std::endl; - ui->memory_mnemonic->setText(mnemonicToString((Mnemonic)info[0])); - ui->memory_squashed->setText(QString::number(info[1])); - ui->memory_s1->set_value(info[2]); - ui->memory_s2->set_value(info[3]); - ui->memory_s3->set_value(info[4]); + if (i) { + ui->memory_mnemonic->setText(mnemonicToString(i->mnemonic)); + ui->memory_squashed->setText(QString::number(i->is_squashed)); + ui->memory_s1->set_value(i->operands.integer.slot_one); + ui->memory_s2->set_value(i->operands.integer.slot_two); + ui->memory_s3->set_value(i->operands.integer.slot_three); } else { ui->memory_mnemonic->clear(); ui->memory_squashed->clear(); @@ -226,14 +225,14 @@ void GUI::onWorkerMemoryInfo(const std::vector info) } } -void GUI::onWorkerWriteBackInfo(const std::vector info) +void GUI::onWorkerWriteBackInfo(const InstrDTO *i) { - if (!info.empty()) { - ui->write_mnemonic->setText(mnemonicToString((Mnemonic)info[0])); - ui->write_squashed->setText(QString::number(info[1])); - ui->write_s1->set_value(info[2]); - ui->write_s2->set_value(info[3]); - ui->write_s3->set_value(info[4]); + if (i) { + ui->write_mnemonic->setText(mnemonicToString(i->mnemonic)); + ui->write_squashed->setText(QString::number(i->is_squashed)); + ui->write_s1->set_value(i->operands.integer.slot_one); + ui->write_s2->set_value(i->operands.integer.slot_two); + ui->write_s3->set_value(i->operands.integer.slot_three); } else { ui->write_mnemonic->clear(); ui->write_squashed->clear(); diff --git a/gui/gui.h b/gui/gui.h index 7b03f75..b3a3110 100644 --- a/gui/gui.h +++ b/gui/gui.h @@ -57,15 +57,15 @@ class GUI : public QMainWindow private slots: void on_worker_refresh_gui(int value, int pc); - void onWorkerFetchInfo(const std::vector info); + void onWorkerFetchInfo(const InstrDTO *); - void onWorkerDecodeInfo(const std::vector info); + void onWorkerDecodeInfo(const InstrDTO *); - void onWorkerExecuteInfo(const std::vector info); + void onWorkerExecuteInfo(const InstrDTO *); - void onWorkerMemoryInfo(const std::vector info); + void onWorkerMemoryInfo(const InstrDTO *); - void onWorkerWriteBackInfo(const std::vector info); + void onWorkerWriteBackInfo(const InstrDTO *); void onWorkerShowStorage( const std::vector> data, int i); diff --git a/gui/worker.cc b/gui/worker.cc index 2652fce..203f907 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -89,10 +89,10 @@ void Worker::runSteps(int steps) emit storage(this->s.at(i - 1)->view(0, 1 << this->size_inc * i), i + 1); emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc()); - emit if_info(this->if_stage->stage_info()); - emit id_info(this->id_stage->stage_info()); - emit ex_info(this->ex_stage->stage_info()); - emit mm_info(this->mm_stage->stage_info()); - emit wb_info(this->wb_stage->stage_info()); + emit if_info(this->if_stage->get_instr()); + emit id_info(this->id_stage->get_instr()); + emit ex_info(this->ex_stage->get_instr()); + emit mm_info(this->mm_stage->get_instr()); + emit wb_info(this->wb_stage->get_instr()); this->ct_mutex.unlock(); } diff --git a/gui/worker.h b/gui/worker.h index 95c81d5..072263a 100644 --- a/gui/worker.h +++ b/gui/worker.h @@ -72,11 +72,11 @@ class Worker : public QObject void storage(const std::vector> data, int i); void register_storage(const std::array data); - void if_info(const std::vector info); - void id_info(const std::vector info); - void ex_info(const std::vector info); - void mm_info(const std::vector info); - void wb_info(const std::vector info); + void if_info(const InstrDTO *); + void id_info(const InstrDTO *); + void ex_info(const InstrDTO *); + void mm_info(const InstrDTO *); + void wb_info(const InstrDTO *); void finished(); }; diff --git a/inc/id.h b/inc/id.h index 39485b6..aafe2e5 100644 --- a/inc/id.h +++ b/inc/id.h @@ -50,8 +50,6 @@ class ID : public Stage */ void write_guard(signed int &r); - std::vector stage_info() override; - private: /** * Helper for `get_instr_fields` diff --git a/inc/if.h b/inc/if.h index c374145..f0eb6e2 100644 --- a/inc/if.h +++ b/inc/if.h @@ -28,8 +28,6 @@ class IF : public Stage InstrDTO *advance(Response p) override; - std::vector stage_info() override; - private: void advance_helper() override; }; diff --git a/inc/stage.h b/inc/stage.h index 7dcb7b4..16f1235 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -53,8 +53,14 @@ class Stage * Must set the status to READY when the current instruction is evicted.. */ virtual InstrDTO *advance(Response p); - - virtual std::vector stage_info(); + /** + * @return the current instruction. + */ + InstrDTO *get_instr(); + /** + * Squashes the pipeline. + */ + void squash(); /* The following methods are made public so that they may be tested, and are * not to be called from outside classes during standard execution. @@ -72,11 +78,6 @@ class Stage */ void set_condition(CC c, bool v); - /** - * Squashes the pipeline. - */ - void squash(); - /** * The set of registers currently checked out. */ diff --git a/src/id.cc b/src/id.cc index d8368c8..d2a8f02 100644 --- a/src/id.cc +++ b/src/id.cc @@ -211,13 +211,3 @@ void ID::decode_J_type( } } - -std::vector ID::stage_info() -{ - std::vector info; - if (this->curr_instr) { - info.push_back(this->curr_instr->is_squashed); - info.push_back(this->curr_instr->slot_A); - } - return info; -} diff --git a/src/if.cc b/src/if.cc index 5f07ee2..0f622d4 100644 --- a/src/if.cc +++ b/src/if.cc @@ -37,15 +37,6 @@ InstrDTO *IF::advance(Response p) return r; } -std::vector IF::stage_info() { - std::vector info; - if(this->curr_instr){ - info.push_back(this->curr_instr->is_squashed); - info.push_back(this->curr_instr->slot_A); - } - return info; -} - void IF::advance_helper() { Response r; diff --git a/src/stage.cc b/src/stage.cc index 55756b6..4efe2fe 100644 --- a/src/stage.cc +++ b/src/stage.cc @@ -65,18 +65,7 @@ InstrDTO *Stage::advance(Response p) return r; } -std::vector Stage::stage_info() -{ - std::vector info; - if (this->curr_instr) { - info.push_back(this->curr_instr->mnemonic); - info.push_back(this->curr_instr->is_squashed); - info.push_back(this->curr_instr->operands.integer.slot_one); - info.push_back(this->curr_instr->operands.integer.slot_two); - info.push_back(this->curr_instr->operands.integer.slot_three); - } - return info; -} +InstrDTO *Stage::get_instr() { return this->curr_instr; } void Stage::set_condition(CC c, bool v) { -- cgit v1.2.3