From 26c24ab3c581967015490d1a11ee098bb5ba338a Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 11 May 2025 12:20:33 -0400 Subject: Replaced STOREV with LOADV --- gui/gui.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'gui/gui.h') diff --git a/gui/gui.h b/gui/gui.h index 3f82898..fd0eacb 100644 --- a/gui/gui.h +++ b/gui/gui.h @@ -160,17 +160,16 @@ class GUI : public QMainWindow {Mnemonic::SUBV, "SUBV"}, {Mnemonic::MULV, "MULV"}, {Mnemonic::DIVV, "DIVV"}, {Mnemonic::CMP, "CMP"}, {Mnemonic::CEV, "CEV"}, {Mnemonic::LOAD, "LOAD"}, - {Mnemonic::LOADV, "LOADV"}, {Mnemonic::ADDI, "ADDI"}, - {Mnemonic::SUBI, "SUBI"}, {Mnemonic::SFTRI, "SFTRI"}, - {Mnemonic::SFTLI, "SFTLI"}, {Mnemonic::ANDI, "ANDI"}, - {Mnemonic::ORI, "ORI"}, {Mnemonic::XORI, "XORI"}, - {Mnemonic::STORE, "STORE"}, {Mnemonic::STOREV, "STOREV"}, - {Mnemonic::JMP, "JMP"}, {Mnemonic::JRL, "JRL"}, - {Mnemonic::JAL, "JAL"}, {Mnemonic::BEQ, "BEQ"}, - {Mnemonic::BGT, "BGT"}, {Mnemonic::BUF, "BUF"}, - {Mnemonic::BOF, "BOF"}, {Mnemonic::PUSH, "PUSH"}, - {Mnemonic::POP, "POP"}, {Mnemonic::NOP, "NOP"}, - {Mnemonic::RET, "RET"}, + {Mnemonic::ADDI, "ADDI"}, {Mnemonic::SUBI, "SUBI"}, + {Mnemonic::SFTRI, "SFTRI"}, {Mnemonic::SFTLI, "SFTLI"}, + {Mnemonic::ANDI, "ANDI"}, {Mnemonic::ORI, "ORI"}, + {Mnemonic::XORI, "XORI"}, {Mnemonic::SRDL, "SRDL"}, + {Mnemonic::SRDS, "SRDS"}, {Mnemonic::JMP, "JMP"}, + {Mnemonic::JRL, "JRL"}, {Mnemonic::JAL, "JAL"}, + {Mnemonic::BEQ, "BEQ"}, {Mnemonic::BGT, "BGT"}, + {Mnemonic::BUF, "BUF"}, {Mnemonic::BOF, "BOF"}, + {Mnemonic::PUSH, "PUSH"}, {Mnemonic::POP, "POP"}, + {Mnemonic::NOP, "NOP"}, {Mnemonic::RET, "RET"}, }; QString mnemonicToString(Mnemonic mnemonic) { -- cgit v1.2.3 From c9d4b54150b67e1701a920719ba2c7c03d897d27 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 11 May 2025 19:40:47 -0400 Subject: Stride load, stride store --- gui/gui.h | 15 ++++++++------- inc/ex.h | 9 ++++++--- inc/mm.h | 13 +++++++++++++ inc/wb.h | 3 ++- src/ex.cc | 33 ++++++++++++++++++++++---------- src/id.cc | 8 +++++++- src/mm.cc | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++------------ src/wb.cc | 13 ++++++++----- 8 files changed, 119 insertions(+), 39 deletions(-) (limited to 'gui/gui.h') diff --git a/gui/gui.h b/gui/gui.h index fd0eacb..d0b8e47 100644 --- a/gui/gui.h +++ b/gui/gui.h @@ -163,13 +163,14 @@ class GUI : public QMainWindow {Mnemonic::ADDI, "ADDI"}, {Mnemonic::SUBI, "SUBI"}, {Mnemonic::SFTRI, "SFTRI"}, {Mnemonic::SFTLI, "SFTLI"}, {Mnemonic::ANDI, "ANDI"}, {Mnemonic::ORI, "ORI"}, - {Mnemonic::XORI, "XORI"}, {Mnemonic::SRDL, "SRDL"}, - {Mnemonic::SRDS, "SRDS"}, {Mnemonic::JMP, "JMP"}, - {Mnemonic::JRL, "JRL"}, {Mnemonic::JAL, "JAL"}, - {Mnemonic::BEQ, "BEQ"}, {Mnemonic::BGT, "BGT"}, - {Mnemonic::BUF, "BUF"}, {Mnemonic::BOF, "BOF"}, - {Mnemonic::PUSH, "PUSH"}, {Mnemonic::POP, "POP"}, - {Mnemonic::NOP, "NOP"}, {Mnemonic::RET, "RET"}, + {Mnemonic::XORI, "XORI"}, {Mnemonic::STORE, "STORE"}, + {Mnemonic::SRDL, "SRDL"}, {Mnemonic::SRDS, "SRDS"}, + {Mnemonic::JMP, "JMP"}, {Mnemonic::JRL, "JRL"}, + {Mnemonic::JAL, "JAL"}, {Mnemonic::BEQ, "BEQ"}, + {Mnemonic::BGT, "BGT"}, {Mnemonic::BUF, "BUF"}, + {Mnemonic::BOF, "BOF"}, {Mnemonic::PUSH, "PUSH"}, + {Mnemonic::POP, "POP"}, {Mnemonic::NOP, "NOP"}, + {Mnemonic::RET, "RET"}, }; QString mnemonicToString(Mnemonic mnemonic) { diff --git a/inc/ex.h b/inc/ex.h index 19b35d4..41195a1 100644 --- a/inc/ex.h +++ b/inc/ex.h @@ -78,7 +78,6 @@ class EX : public Stage * Handles operations involving three vector registers. * @param slot 1, and later, the result of the mnemonic operation. * @param slot 2 - * @param slot 3 * @param the mnemonic * @param the vector length register */ @@ -89,14 +88,18 @@ class EX : public Stage unsigned int v_len); /** - * Handles operations involving a single vector register. + * Handles operations involving a vector result and a scalar. * Currently, this is SRDL and SRDS * @param slot 1, and later, the result of the mnemonic operation. * @param slot 2 * @param the mnemonic * @param the vector length register */ - void handle_s_vector_operations(signed int &s1, signed int s2, Mnemonic m); + void handle_s_vector_operations( + std::array &s1, + signed int s2, + Mnemonic m, + unsigned int v_len); /** * Wrapper for division functions, which detects HALT instructinos (division * by 0). diff --git a/inc/mm.h b/inc/mm.h index 230b258..d54d6ad 100644 --- a/inc/mm.h +++ b/inc/mm.h @@ -29,6 +29,19 @@ class MM : public Stage private: void advance_helper() override; + /** + * Helpers for `advance_helper'. Sets the `this->status' to OK + * If the current memory IO returned OK, and all vector elements + * have been processed. Otherwise, sets `this->status' to STALLED + * @param the response from the storage devices. + */ + void try_start(); + void try_finish(int response); + /** + * The index element currently being loaded or stored. + * Used for strided load/store. + */ + int curr_element = 0; }; #endif /* MM_H_INCLUDED */ diff --git a/inc/wb.h b/inc/wb.h index 35c9240..bbba5bf 100644 --- a/inc/wb.h +++ b/inc/wb.h @@ -51,7 +51,8 @@ class WB : public Stage * @return the vector register to be stored, obtained by copying the * unfilled elements in the destination register to the source. This is * required to ensure what is written back only changes VECTOR_LENGTH number - * of elements. + * of elements. Correctly handles zeroing out ALU operations if the VECTOR + * LENGTH number is zero. */ std::array copy_extra_vector_elements(); }; diff --git a/src/ex.cc b/src/ex.cc index cd00254..22cd092 100644 --- a/src/ex.cc +++ b/src/ex.cc @@ -240,13 +240,25 @@ void EX::handle_vector_operations( this->set_condition(UF, underflow); } -void EX::handle_s_vector_operations(signed int &s1, signed int s2, Mnemonic m) +void EX::handle_s_vector_operations( + std::array &s1, + signed int s2, + Mnemonic m, + unsigned int v_len) { + unsigned int i, inc1, inc2; + switch (m) { - // case SRDL: - // case SRDS: - // s1 = s1 + s2; - // break; + case SRDL: + case SRDS: + inc1 = s1[0]; + s1[0] = s2; + for (i = 1; i < v_len; ++i) { + inc2 = s1[i]; + s1[i] = s1[i - 1] + inc1; + inc1 = inc2; + } + break; default: throw std::invalid_argument("handle_s_vector_operations did not " @@ -270,11 +282,12 @@ void EX::advance_helper() handle_vector_operations( this->curr_instr->operands.vector.slot_one, this->curr_instr->operands.vector.slot_two, m, v_len_or_pc); - }// else { - // handle_s_vector_operations( - // this->curr_instr->operands.s_vector.slot_one, - // this->curr_instr->operands.s_vector.slot_two, m); - // } + } else { + handle_s_vector_operations( + this->curr_instr->operands.s_vector.slot_one, + this->curr_instr->operands.s_vector.slot_two, m, v_len_or_pc); + printArray(this->curr_instr->operands.s_vector.slot_three); + } this->status = OK; } diff --git a/src/id.cc b/src/id.cc index 12f509f..9547486 100644 --- a/src/id.cc +++ b/src/id.cc @@ -135,10 +135,16 @@ void ID::decode_R_type(signed int &s1) this->write_guard>(s3); break; case SRDL: - case SRDS: this->curr_instr->operands.s_vector.slot_three = this->write_guard>(s3); break; + case SRDS: + r1 = this->read_guard>( + s3, this->curr_instr->operands.s_vector.slot_three); + if (r1 != OK) { + this->status = STALLED; + } + break; default: this->curr_instr->operands.integer.slot_three = this->write_guard(s3); diff --git a/src/mm.cc b/src/mm.cc index ac77433..63ee16a 100644 --- a/src/mm.cc +++ b/src/mm.cc @@ -25,15 +25,30 @@ void MM::advance_helper() signed int data; int i; + this->try_start(); + if (this->status == OK) { + return; + } + switch (this->curr_instr->mnemonic) { case LOAD: i = this->storage->read_word( this, this->curr_instr->operands.integer.slot_one, data); - this->status = i ? OK : STALLED; - if (this->status == OK) { + if (i) { this->curr_instr->operands.integer.slot_one = data; - } else - this->status = STALLED; + } + this->try_finish(i); + break; + case SRDL: + i = this->storage->read_word( + this, + this->curr_instr->operands.s_vector.slot_one[this->curr_element], + data); + if (i) { + this->curr_instr->operands.s_vector.slot_one[this->curr_element] = + data; + } + this->try_finish(i); break; case PUSH: @@ -41,22 +56,47 @@ void MM::advance_helper() i = this->storage->write_word( 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; - } + this->try_finish(i); + break; + case SRDS: + i = this->storage->write_word( + this, + this->curr_instr->operands.s_vector.slot_three[this->curr_element], + this->curr_instr->operands.s_vector.slot_one[this->curr_element]); + this->try_finish(i); break; case POP: - i = this->storage->read_word(this, this->curr_instr->operands.integer.slot_three, data); + i = this->storage->read_word( + this, this->curr_instr->operands.integer.slot_three, data); this->status = i ? OK : STALLED; - if (this->status == OK) { + if (i) { this->curr_instr->operands.integer.slot_three = data; - } else - this->status = STALLED; + } break; default: this->status = OK; } } + +void MM::try_start() +{ + if (this->curr_instr->type != SI_INT) { + this->status = + (this->curr_element >= this->curr_instr->slot_B) ? OK : STALLED; + } + if (this->status == OK) + this->curr_element = 0; +} + +void MM::try_finish(int response) +{ + if (this->curr_instr->type == SI_INT) { + this->status = response ? OK : STALLED; + } else { + if (response) { + ++this->curr_element; + } + } +} diff --git a/src/wb.cc b/src/wb.cc index fc714ad..89ee298 100644 --- a/src/wb.cc +++ b/src/wb.cc @@ -58,15 +58,11 @@ void WB::write_handler() this->store_register( reg, this->curr_instr->operands.integer.slot_one); break; + case S_VECT: case R_VECT: this->store_register>( reg, this->copy_extra_vector_elements()); break; - // case S_VECT: - // this->store_register>( - // reg, this->curr_instr->operands.s_vector.slot_three); - // // todo, use copy_extra_vector_elements - // break; } } @@ -97,6 +93,13 @@ std::array WB::copy_extra_vector_elements() int i; std::array v; + if (this->curr_instr->type == S_VECT) { + if (this->curr_instr->slot_B == 0) { + v = {0}; + return v; + } + } + v = this->curr_instr->operands.vector.slot_one; for (i = V_R_LIMIT - 1; i >= this->curr_instr->slot_B; --i) { v[i] = this->curr_instr->operands.vector.slot_three[i]; -- cgit v1.2.3 From 43588597069587f6846a7d64a1957435bec5429d Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 11 May 2025 22:04:46 -0400 Subject: Add ROTV instruction --- gui/gui.h | 12 ++++++------ inc/ex.h | 1 - inc/instr.h | 1 + src/ex.cc | 8 +++++++- src/id.cc | 11 ++++++++--- src/instr.cc | 16 ++++++++-------- 6 files changed, 30 insertions(+), 19 deletions(-) (limited to 'gui/gui.h') diff --git a/gui/gui.h b/gui/gui.h index d0b8e47..a1d97ad 100644 --- a/gui/gui.h +++ b/gui/gui.h @@ -165,12 +165,12 @@ class GUI : public QMainWindow {Mnemonic::ANDI, "ANDI"}, {Mnemonic::ORI, "ORI"}, {Mnemonic::XORI, "XORI"}, {Mnemonic::STORE, "STORE"}, {Mnemonic::SRDL, "SRDL"}, {Mnemonic::SRDS, "SRDS"}, - {Mnemonic::JMP, "JMP"}, {Mnemonic::JRL, "JRL"}, - {Mnemonic::JAL, "JAL"}, {Mnemonic::BEQ, "BEQ"}, - {Mnemonic::BGT, "BGT"}, {Mnemonic::BUF, "BUF"}, - {Mnemonic::BOF, "BOF"}, {Mnemonic::PUSH, "PUSH"}, - {Mnemonic::POP, "POP"}, {Mnemonic::NOP, "NOP"}, - {Mnemonic::RET, "RET"}, + {Mnemonic::ROTV, "ROTV"}, {Mnemonic::JMP, "JMP"}, + {Mnemonic::JRL, "JRL"}, {Mnemonic::JAL, "JAL"}, + {Mnemonic::BEQ, "BEQ"}, {Mnemonic::BGT, "BGT"}, + {Mnemonic::BUF, "BUF"}, {Mnemonic::BOF, "BOF"}, + {Mnemonic::PUSH, "PUSH"}, {Mnemonic::POP, "POP"}, + {Mnemonic::NOP, "NOP"}, {Mnemonic::RET, "RET"}, }; QString mnemonicToString(Mnemonic mnemonic) { diff --git a/inc/ex.h b/inc/ex.h index 41195a1..64eecb7 100644 --- a/inc/ex.h +++ b/inc/ex.h @@ -89,7 +89,6 @@ class EX : public Stage /** * Handles operations involving a vector result and a scalar. - * Currently, this is SRDL and SRDS * @param slot 1, and later, the result of the mnemonic operation. * @param slot 2 * @param the mnemonic diff --git a/inc/instr.h b/inc/instr.h index a083699..5a8ff4a 100644 --- a/inc/instr.h +++ b/inc/instr.h @@ -39,6 +39,7 @@ enum Mnemonic { CEV, SRDL, SRDS, + ROTV, LOAD, ADDI, SUBI, diff --git a/src/ex.cc b/src/ex.cc index 22cd092..f36ea4b 100644 --- a/src/ex.cc +++ b/src/ex.cc @@ -249,6 +249,13 @@ void EX::handle_s_vector_operations( unsigned int i, inc1, inc2; switch (m) { + case ROTV: + s2 = s2 % v_len; + if (s2 < 0) + s2 += v_len; + + std::rotate(s1.begin(), s1.begin() + s2, s1.begin() + v_len); + break; case SRDL: case SRDS: inc1 = s1[0]; @@ -286,7 +293,6 @@ void EX::advance_helper() handle_s_vector_operations( this->curr_instr->operands.s_vector.slot_one, this->curr_instr->operands.s_vector.slot_two, m, v_len_or_pc); - printArray(this->curr_instr->operands.s_vector.slot_three); } this->status = OK; diff --git a/src/id.cc b/src/id.cc index 9547486..58bde6b 100644 --- a/src/id.cc +++ b/src/id.cc @@ -99,25 +99,29 @@ void ID::decode_R_type(signed int &s1) s2 = GET_MID_BITS(s1, s0b, s1b); s1 = GET_LS_BITS(s1, s0b); - if (this->curr_instr->type == SI_INT) { + switch (this->curr_instr->type) { + case SI_INT: r1 = this->read_guard( s1, this->curr_instr->operands.integer.slot_one); r2 = this->read_guard( s2, this->curr_instr->operands.integer.slot_two); r3 = OK; - } else if (this->curr_instr->type == R_VECT) { + break; + case R_VECT: r1 = this->read_guard>( s1, this->curr_instr->operands.vector.slot_one); r2 = this->read_guard>( s2, this->curr_instr->operands.vector.slot_two); r3 = this->set_vlen(); - } else { + break; + case S_VECT: // store the second field in s1, to keep execute+mem consistent r1 = this->read_guard>( s2, this->curr_instr->operands.s_vector.slot_one); r2 = this->read_guard( s1, this->curr_instr->operands.s_vector.slot_two); r3 = this->set_vlen(); + break; } this->status = (r1 == OK && r2 == OK && r3 == OK) ? OK : STALLED; @@ -134,6 +138,7 @@ void ID::decode_R_type(signed int &s1) this->curr_instr->operands.vector.slot_three = this->write_guard>(s3); break; + case ROTV: case SRDL: this->curr_instr->operands.s_vector.slot_three = this->write_guard>(s3); diff --git a/src/instr.cc b/src/instr.cc index 271fc99..a638a38 100644 --- a/src/instr.cc +++ b/src/instr.cc @@ -29,20 +29,20 @@ const std::unordered_map mnemonic_map = { {0b0101000, NOT}, {0b0101100, XOR}, {0b0110000, ADDV}, {0b0110100, SUBV}, {0b0111000, MULV}, {0b0111100, DIVV}, {0b1000000, CMP}, {0b1000100, CEV}, {0b1001000, SRDL}, - {0b1001100, SRDS}, {0b000101, LOAD}, {0b0001001, ADDI}, - {0b0001101, SUBI}, {0b0010001, SFTRI}, {0b0010101, SFTLI}, - {0b0011001, ANDI}, {0b0011101, ORI}, {0b0100001, XORI}, - {0b0100101, STORE}, {0b0000110, JMP}, {0b0001010, JRL}, - {0b0001110, JAL}, {0b0010010, BEQ}, {0b0010110, BGT}, - {0b0011010, BUF}, {0b0011110, BOF}, {0b0100010, PUSH}, - {0b0100110, POP}, {0b0101010, RET}, + {0b1001100, SRDS}, {0b1010000, ROTV}, {0b000101, LOAD}, + {0b0001001, ADDI}, {0b0001101, SUBI}, {0b0010001, SFTRI}, + {0b0010101, SFTLI}, {0b0011001, ANDI}, {0b0011101, ORI}, + {0b0100001, XORI}, {0b0100101, STORE}, {0b0000110, JMP}, + {0b0001010, JRL}, {0b0001110, JAL}, {0b0010010, BEQ}, + {0b0010110, BGT}, {0b0011010, BUF}, {0b0011110, BOF}, + {0b0100010, PUSH}, {0b0100110, POP}, {0b0101010, RET}, }; FieldType get_field_types(Mnemonic m) { if (m == ADDV || m == SUBV || m == MULV || m == DIVV || m == CEV) { return R_VECT; - } else if (m == SRDL || m == SRDS) { + } else if (m == SRDL || m == SRDS || m == ROTV) { return S_VECT; } else { return SI_INT; -- cgit v1.2.3