From 41f612789f652654b5f2fa8c3fee4e348e2081b1 Mon Sep 17 00:00:00 2001 From: Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> Date: Sat, 26 Apr 2025 20:21:02 -0400 Subject: Initial vector extension changes --- src/ex.cc | 587 ++++++++++++++++++++------------------------------------------ 1 file changed, 188 insertions(+), 399 deletions(-) (limited to 'src/ex.cc') diff --git a/src/ex.cc b/src/ex.cc index eac24ff..2ad2d7f 100644 --- a/src/ex.cc +++ b/src/ex.cc @@ -22,415 +22,204 @@ #include "stage.h" #include -// clang-format off -#define INIT_INSTRUCTION(mnemonic, body) \ - {mnemonic, [this](signed int &s1, signed int s2, signed int s3, unsigned int pc) { \ - body; \ - }} -// clang-format on - -EX::EX(Stage *stage) : Stage(stage) -{ - instr_map = { - - /* R type instructions */ - INIT_INSTRUCTION( - ADD, - { - this->set_condition(OF, ADDITION_OF_GUARD(s1, s2)); - this->set_condition(UF, ADDITION_UF_GUARD(s1, s2)); - s1 = s1 + s2; - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - SUB, - { - this->set_condition(OF, SUBTRACTION_OF_GUARD(s1, s2)); - this->set_condition(UF, SUBTRACTION_UF_GUARD(s1, s2)); - s1 = s1 - s2; - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - MUL, - { - this->set_condition(OF, MULTIPLICATION_OF_GUARD(s1, s2)); - this->set_condition(UF, MULTIPLICATION_UF_GUARD(s1, s2)); - s1 = s1 * s2; - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - QUOT, - { - this->handle_divide(s1, s2, false); - (void)pc; - (void)s3; - }), - - INIT_INSTRUCTION( - REM, - { - this->handle_divide(s1, s2, true); - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - SFTR, - { - s1 = s1 >> s2; - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - SFTL, - { - s1 = s1 << s2; - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - AND, - { - this->set_condition(OF, false); - this->set_condition(UF, false); - s1 = s1 & s2; - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - OR, - { - this->set_condition(OF, false); - this->set_condition(UF, false); - s1 = s1 | s2; - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - NOT, - { - this->set_condition(OF, false); - this->set_condition(UF, false); - s1 = ~s1; - (void)pc; - (void)s3; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - XOR, - { - this->set_condition(OF, false); - this->set_condition(UF, false); - s1 = s1 ^ s2; - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - ADDV, - { - (void)pc; - (void)s3; - (void)s2; - (void)s1; - (void)this; - }), - - INIT_INSTRUCTION( - SUBV, - { - (void)pc; - (void)s3; - (void)s2; - (void)s1; - (void)this; - }), - - INIT_INSTRUCTION( - MULV, - { - (void)pc; - (void)s3; - (void)s2; - (void)s1; - (void)this; - }), - - INIT_INSTRUCTION( - DIVV, - { - (void)pc; - (void)s3; - (void)s2; - (void)s1; - (void)this; - }), - - INIT_INSTRUCTION( - CMP, - { - (s1 > s2) ? this->set_condition(GT, true) - : this->set_condition(GT, false); - (s1 == s2) ? this->set_condition(EQ, true) - : this->set_condition(EQ, false); - (void)pc; - (void)s3; - }), - - INIT_INSTRUCTION( - CEV, - { - (void)pc; - (void)s3; - (void)s2; - (void)s1; - (void)this; - }), - - /* I type instructions */ - INIT_INSTRUCTION( - LOAD, - { - s1 = s1 + s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - LOADV, - { - (void)pc; - (void)s3; - (void)s2; - (void)s1; - (void)this; - }), - - INIT_INSTRUCTION( - ADDI, - { - this->set_condition(OF, ADDITION_OF_GUARD(s1, s3)); - this->set_condition(UF, ADDITION_UF_GUARD(s1, s3)); - s1 = s1 + s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - SUBI, - { - this->set_condition(OF, SUBTRACTION_OF_GUARD(s1, s3)); - this->set_condition(UF, SUBTRACTION_UF_GUARD(s1, s3)); - s1 = s1 - s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - SFTRI, - { - s1 = s1 >> s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - SFTLI, - { - s1 = s1 << s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - ANDI, - { - this->set_condition(OF, false); - this->set_condition(UF, false); - s1 = s1 & s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - ORI, - { - this->set_condition(OF, false); - this->set_condition(UF, false); - s1 = s1 | s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - XORI, - { - this->set_condition(OF, false); - this->set_condition(UF, false); - s1 = s1 ^ s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - STORE, - { - s1 = s1 + s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - STOREV, - { - (void)pc; - (void)s3; - (void)s2; - (void)s1; - (void)this; - }), - - /* J type instructions */ - INIT_INSTRUCTION( - JMP, - { - s1 = s1 + s2; - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - JRL, - { - s1 = pc + s2; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - JAL, - { - s1 = s1 + s2; - (void)pc; - (void)s3; - (void)this; - }), - - INIT_INSTRUCTION( - BEQ, - { - (this->get_condition(EQ)) ? s1 = pc + s2 : s1 = -1; - (void)s3; - }), - - INIT_INSTRUCTION( - BGT, - { - (this->get_condition(GT)) ? s1 = pc + s2 : s1 = -1; - (void)s3; - }), - - INIT_INSTRUCTION( - BUF, - { - (this->get_condition(UF)) ? s1 = pc + s2 : s1 = -1; - (void)s3; - }), - - INIT_INSTRUCTION( - BOF, - { - (this->get_condition(OF)) ? s1 = pc + s2 : s1 = -1; - (void)s3; - }), - - INIT_INSTRUCTION( - PUSH, - { - s1 = s1 + s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - POP, - { - s1 = s1 + s3; - (void)pc; - (void)s2; - (void)this; - }), - - INIT_INSTRUCTION( - RET, - { - (void)pc; - (void)s3; - (void)s2; - (void)s1; - (void)this; - }), - - /* NOP */ - INIT_INSTRUCTION( - NOP, - { - (void)pc; - (void)s3; - (void)s2; - (void)s1; - (void)this; - }), - }; -} +// Switch statements for each instruction void EX::advance_helper() { signed int s1, s2, s3; + std::array v1, v2, v3; + signed int v_len; unsigned int pc; Mnemonic m; 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); + if(this->is_vector_type(m)) { + v1 = this->curr_instr->operands.vector.slot_one; + v2 = this->curr_instr->operands.vector.slot_two; + v3 = this->curr_instr->operands.vector.slot_three; + v_len = this->curr_instr->slot_A; + /*if(v_len == 0){ + //clear vector reg + v1.fill(0); + v2.fill(0); + v3.fill(0); + }*/ + } else{ + 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->curr_instr->operands.integer.slot_one = s1; + if(this->is_logical(m)) { + this->set_condition(OF, false); + this->set_condition(UF, false); + } + + switch(m) { + case ADD: + this->set_condition(OF, ADDITION_OF_GUARD(s1, s2)); + this->set_condition(UF, ADDITION_UF_GUARD(s1, s2)); + s1 = s1 + s2; + break; + + case SUB: + this->set_condition(OF, SUBTRACTION_OF_GUARD(s1, s2)); + this->set_condition(UF, SUBTRACTION_UF_GUARD(s1, s2)); + s1 = s1 - s2; + break; + + case MUL: + this->set_condition(OF, MULTIPLICATION_OF_GUARD(s1, s2)); + this->set_condition(UF, MULTIPLICATION_UF_GUARD(s1, s2)); + s1 = s1 * s2; + break; + + case QUOT: + this->handle_divide(s1, s2, false); + break; + + case REM: + this->handle_divide(s1, s2, true); + break; + + case SFTR: + s1 = s1 >> s2; + break; + + case SFTL: + s1 = s1 << s2; + break; + + case AND: + s1 = s1 & s2; + break; + + case OR: + s1 = s1 | s2; + break; + + case XOR: + s1 = s1 ^ s2; + break; + + case NOT: + s1 = ~s1; + break; + + case CMP: + (s1 > s2) ? this->set_condition(GT, true) + : this->set_condition(GT, false); + (s1 == s2) ? this->set_condition(EQ, true) + : this->set_condition(EQ, false); + break; + + case ADDI: + this->set_condition(OF, ADDITION_OF_GUARD(s1, s3)); + this->set_condition(UF, ADDITION_UF_GUARD(s1, s3)); + s1 = s1 + s3; + break; + + case SUBI: + this->set_condition(OF, SUBTRACTION_OF_GUARD(s1, s3)); + this->set_condition(UF, SUBTRACTION_UF_GUARD(s1, s3)); + s1 = s1 - s3; + break; + + case SFTRI: + s1 = s1 >> s3; + break; + + case SFTLI: + s1 = s1 << s3; + break; + + case ANDI: + s1 = s1 & s3; + break; + + case ORI: + s1 = s1 | s3; + break; + + case XORI: + s1 = s1 ^ s3; + break; + + case LOAD: + case STORE: + case PUSH: + case POP: + s1 = s1 + s3; + break; + + case JMP: + case JAL: + s1 = s1 + s2; + break; + + case JRL: + s1 = pc + s2; + break; + + case BEQ: + (this->get_condition(EQ)) ? s1 = pc + s2 : s1 = -1; + break; + + case BGT: + (this->get_condition(GT)) ? s1 = pc + s2 : s1 = -1; + break; + + case BUF: + (this->get_condition(UF)) ? s1 = pc + s2 : s1 = -1; + break; + + case BOF: + (this->get_condition(OF)) ? s1 = pc + s2 : s1 = -1; + break; + + case ADDV: + if(v_len ==0){ + + } else { + for(int i=0;iset_condition(OF, ADDITION_OF_GUARD(v1[i],v2[i])); + this->set_condition(UF, ADDITION_UF_GUARD(v1[i],v2[i])); + v1[i] = v1[i] + v2[i]; + } + } + break; + case SUBV: + for(int i=0;iset_condition(OF, SUBTRACTION_OF_GUARD(v1[i],v2[i])); + this->set_condition(UF, SUBTRACTION_UF_GUARD(v1[i],v2[i])); + v1[i] = v1[i] - v2[i]; + } + break; + case MULV: + for(int i=0;iset_condition(OF, MULTIPLICATION_OF_GUARD(v1[i],v2[i])); + this->set_condition(UF, MULTIPLICATION_UF_GUARD(v1[i],v2[i])); + v1[i] = v1[i] * v2[i]; + } + break; + case DIVV: + for(int i=0;ihandle_divide(v1[i],v2[i],false); + } + break; + case CEV: + case LOADV: + case STOREV: + break; + + case RET: + case NOP: + break; + + } + this->status = OK; } -- cgit v1.2.3 From 66dbfb6ee729e1ff8352c876e6c42aca2081f2e5 Mon Sep 17 00:00:00 2001 From: Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> Date: Sun, 27 Apr 2025 00:15:30 -0400 Subject: EX changes for LOADV and STOREV --- src/ex.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/ex.cc') diff --git a/src/ex.cc b/src/ex.cc index 2ad2d7f..947407a 100644 --- a/src/ex.cc +++ b/src/ex.cc @@ -28,7 +28,7 @@ void EX::advance_helper() { signed int s1, s2, s3; std::array v1, v2, v3; - signed int v_len; + signed int v_len, v_immediate, v_base_addr; unsigned int pc; Mnemonic m; @@ -39,6 +39,12 @@ void EX::advance_helper() v2 = this->curr_instr->operands.vector.slot_two; v3 = this->curr_instr->operands.vector.slot_three; v_len = this->curr_instr->slot_A; + if(this->curr_instr->slot_C){ + v_immediate = this->curr_instr->slot_C; + } + if(this->curr_instr->slot_B){ + v_base_addr = this->curr_instr->slot_B; + } /*if(v_len == 0){ //clear vector reg v1.fill(0); @@ -210,8 +216,15 @@ void EX::advance_helper() } break; case CEV: + bool equal = true; + for(int i=0;i Date: Sun, 27 Apr 2025 15:04:25 -0400 Subject: WB and MEM changes for vectors --- inc/instrDTO.h | 13 ++++++++----- src/ex.cc | 39 +++++++++++++++++++++------------------ src/id.cc | 12 ++++++------ src/mm.cc | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/wb.cc | 11 ++++++++++- 5 files changed, 97 insertions(+), 30 deletions(-) (limited to 'src/ex.cc') diff --git a/inc/instrDTO.h b/inc/instrDTO.h index b99ba20..f3d4597 100644 --- a/inc/instrDTO.h +++ b/inc/instrDTO.h @@ -33,6 +33,12 @@ struct V_TYPE { std::array slot_three; }; +struct LOAD_STORE_V_TYPE{ + signed int base_addr; + signed int immediate; + std::array vector_register; +}; + struct InstrDTO { /** * If this instruction is squashed or not. @@ -43,13 +49,9 @@ struct InstrDTO { */ signed int slot_A; /** - * Optional slot for holding PC / base address + * Optional slot for holding PC */ signed int slot_B; - /** - * Optional slot to hold immediates - */ - signed int slot_C; /** * The mnemonic of the instruction. */ @@ -61,6 +63,7 @@ struct InstrDTO { union { struct U_INT_TYPE integer; struct V_TYPE vector; + struct LOAD_STORE_V_TYPE load_store_vector; } operands; }; diff --git a/src/ex.cc b/src/ex.cc index 947407a..03a4e59 100644 --- a/src/ex.cc +++ b/src/ex.cc @@ -33,29 +33,26 @@ void EX::advance_helper() Mnemonic m; m = this->curr_instr->mnemonic; + pc = this->curr_instr->slot_B; if(this->is_vector_type(m)) { - v1 = this->curr_instr->operands.vector.slot_one; - v2 = this->curr_instr->operands.vector.slot_two; - v3 = this->curr_instr->operands.vector.slot_three; - v_len = this->curr_instr->slot_A; - if(this->curr_instr->slot_C){ - v_immediate = this->curr_instr->slot_C; - } - if(this->curr_instr->slot_B){ - v_base_addr = this->curr_instr->slot_B; + if(this->curr_instr->mnemonic != LOADV && this->curr_instr->mnemonic != STOREV){ + v1 = this->curr_instr->operands.vector.slot_one; + v2 = this->curr_instr->operands.vector.slot_two; + v3 = this->curr_instr->operands.vector.slot_three; + } else { + v_immediate = this->curr_instr->operands.load_store_vector.immediate; + v_base_addr = this->curr_instr->operands.load_store_vector.base_addr; } - /*if(v_len == 0){ - //clear vector reg + v_len = this->curr_instr->slot_A; + if(v_len == 0){ + //clear destination vector reg v1.fill(0); - v2.fill(0); - v3.fill(0); - }*/ + } } else{ 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; } if(this->is_logical(m)) { @@ -216,12 +213,18 @@ void EX::advance_helper() } break; case CEV: - bool equal = true; - for(int i=0;iset_condition(EQ, true); + } else { + this->set_condition(EQ, false); + } + break; case LOADV: case STOREV: v_base_addr = v_base_addr + v_immediate; diff --git a/src/id.cc b/src/id.cc index 28a48a0..1f0e62b 100644 --- a/src/id.cc +++ b/src/id.cc @@ -213,30 +213,30 @@ void ID::decode_I_type(signed int &s1) this->status = (r1 == OK && r2 == OK) ? OK : STALLED; return; case STOREV: - this->curr_instr->slot_C = s3; + this->curr_instr->operands.load_store_vector.immediate = s3; s2 = GET_MID_BITS(s1, s0b, s1b); s1 = GET_LS_BITS(s1, s0b); // base address r1 = this->read_guard(s1); - this->curr_instr->slot_B = s1; + this->curr_instr->operands.load_store_vector.base_addr = s1; // vector value to be stored - r2 = this->read_vec_guard(s2,this->curr_instr->operands.vector.slot_two); + r2 = this->read_vec_guard(s2,this->curr_instr->operands.load_store_vector.vector_register); r3 = this->set_vlen(); this->status = (r1 == OK && r2 == OK && r3 == OK) ? OK : STALLED; return; case LOADV: - this->curr_instr->slot_C = s3; + this->curr_instr->operands.load_store_vector.immediate = s3; s2 = GET_LS_BITS(s1, s0b); s1 = GET_MID_BITS(s1, s0b, s1b); // base address r1 = this->read_guard(s1); - this->curr_instr->slot_B = s1; + this->curr_instr->operands.load_store_vector.base_addr = s1; r3 = this->set_vlen(); if (r1 == OK && r3 == OK) // vector destination - this->write_vec_guard(s2, this->curr_instr->operands.vector.slot_two); + this->write_vec_guard(s2, this->curr_instr->operands.load_store_vector.vector_register); this->status = (r1 == OK && r3 == OK) ? OK : STALLED; return; case LOAD: diff --git a/src/mm.cc b/src/mm.cc index ac77433..8134cf5 100644 --- a/src/mm.cc +++ b/src/mm.cc @@ -24,6 +24,7 @@ void MM::advance_helper() { signed int data; int i; + int vector_delay = VECTOR_MEM_DELAY; switch (this->curr_instr->mnemonic) { case LOAD: @@ -35,6 +36,32 @@ void MM::advance_helper() } else this->status = STALLED; break; + case LOADV: + if (vector_delay == 0){ + signed int word_address = this->curr_instr->operands.load_store_vector.base_addr; + int j = 0; + while(j < this->curr_instr->slot_A){ + i = this->storage->read_word(this, word_address, data); + this->status = i ? OK : STALLED; + if (this->status == OK) { + this->curr_instr->operands.load_store_vector.vector_register[j] = data; + // +1 or +4? + word_address += 1; + j++; + } else { + break; + } + } + if(this->status == OK){ + // if vector is loaded, reset delay + vector_delay = VECTOR_MEM_DELAY; + } else { + this->status = STALLED; + } + } else { + vector_delay--; + } + break; case PUSH: case STORE: @@ -46,6 +73,31 @@ void MM::advance_helper() this->status = STALLED; } break; + case STOREV: + if (vector_delay == 0){ + signed int word_address = this->curr_instr->operands.load_store_vector.base_addr; + int j = 0; + while(j < this->curr_instr->slot_A){ + this->storage->write_word( + this, this->curr_instr->operands.load_store_vector.vector_register[j], word_address); + this->status = i ? OK : STALLED; + if (this->status != OK) { + break; + } else { + word_address += 1; + j++; + } + } + if(this->status == OK){ + // if vector is stored , reset delay + vector_delay = VECTOR_MEM_DELAY; + } else { + this->status = STALLED; + } + } else { + vector_delay--; + } + break; case POP: i = this->storage->read_word(this, this->curr_instr->operands.integer.slot_three, data); diff --git a/src/wb.cc b/src/wb.cc index 79efe44..0dae5f2 100644 --- a/src/wb.cc +++ b/src/wb.cc @@ -51,7 +51,16 @@ void WB::write_handler() this->checked_out.pop_front(); reg = this->curr_instr->checked_out; - this->store_register(reg, this->curr_instr->operands.integer.slot_one); + + if(this->is_vector_type(this->curr_instr->mnemonic)) { + if(this->curr_instr->mnemonic != STOREV && this->curr_instr->mnemonic != LOADV) { + this->store_register>(reg, this->curr_instr->operands.vector.slot_one); + } else { + this->store_register>(reg, this->curr_instr->operands.load_store_vector.vector_register); + } + } else{ + this->store_register(reg, this->curr_instr->operands.integer.slot_one); + } } void WB::jump_handler() -- cgit v1.2.3 From b50cb7048275f5b9255dea7f3ac1362aaa09fe83 Mon Sep 17 00:00:00 2001 From: Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> Date: Sun, 27 Apr 2025 21:09:27 -0400 Subject: Bug fixes --- inc/stage.h | 4 +++- src/ex.cc | 24 ++++++++++++++---------- src/id.cc | 7 ++++++- 3 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src/ex.cc') diff --git a/inc/stage.h b/inc/stage.h index 4e0c252..a5d7fe6 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -136,6 +136,8 @@ class Stage if (v < 0 || v >= GPR_NUM) { throw std::out_of_range("Invalid GPR index"); } + cout << "dereference_register: " << v << endl; + cout << "gprs[v]: " << gprs[v] << endl; return gprs[v]; } else if constexpr (std::is_same_v>) { @@ -188,4 +190,4 @@ class Stage Response status; }; -#endif /* STAGE_H_INCLUDED */ +#endif /* STAGE_H_INCLUDED */ \ No newline at end of file diff --git a/src/ex.cc b/src/ex.cc index 03a4e59..6dfe44f 100644 --- a/src/ex.cc +++ b/src/ex.cc @@ -183,14 +183,10 @@ void EX::advance_helper() break; case ADDV: - if(v_len ==0){ - - } else { - for(int i=0;iset_condition(OF, ADDITION_OF_GUARD(v1[i],v2[i])); - this->set_condition(UF, ADDITION_UF_GUARD(v1[i],v2[i])); - v1[i] = v1[i] + v2[i]; - } + for(int i=0;iset_condition(OF, ADDITION_OF_GUARD(v1[i],v2[i])); + this->set_condition(UF, ADDITION_UF_GUARD(v1[i],v2[i])); + v1[i] = v1[i] + v2[i]; } break; case SUBV: @@ -234,8 +230,16 @@ void EX::advance_helper() case NOP: break; - } - + } + if(this->is_vector_type(m)) { + if(this->curr_instr->mnemonic != LOADV && this->curr_instr->mnemonic != STOREV){ + this->curr_instr->operands.vector.slot_one = v1; + } else { + this->curr_instr->operands.load_store_vector.base_addr = v_base_addr; + } + } else{ + this->curr_instr->operands.integer.slot_one = s1; + } this->status = OK; } diff --git a/src/id.cc b/src/id.cc index 7db67c4..4358150 100644 --- a/src/id.cc +++ b/src/id.cc @@ -253,6 +253,7 @@ void ID::decode_I_type(signed int &s1) s1 = GET_MID_BITS(s1, s0b, s1b); break; default: + this->curr_instr->operands.integer.slot_three = s3; s2 = GET_MID_BITS(s1, s0b, s1b); s1 = GET_LS_BITS(s1, s0b); } @@ -312,6 +313,10 @@ void ID::decode_J_type(signed int &s1) [[fallthrough]]; default: this->status = this->read_guard(s1); - this->curr_instr->operands.integer.slot_one = s1; + if(this->status == OK){ + this->curr_instr->operands.integer.slot_one = s1; + this->curr_instr->operands.integer.slot_two = s2; + this->curr_instr->operands.integer.slot_three = s3; + } } } -- cgit v1.2.3 From a5366c56469bdec480c7eb463f9f71d7a3e3b2d2 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 27 Apr 2025 23:26:40 -0400 Subject: Fix push/pop instruction --- inc/stage.h | 4 +- src/controller.cc | 1 + src/ex.cc | 374 +++++++++++++++++++++++++++--------------------------- src/id.cc | 4 +- 4 files changed, 194 insertions(+), 189 deletions(-) (limited to 'src/ex.cc') diff --git a/inc/stage.h b/inc/stage.h index a5d7fe6..4e0c252 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -136,8 +136,6 @@ class Stage if (v < 0 || v >= GPR_NUM) { throw std::out_of_range("Invalid GPR index"); } - cout << "dereference_register: " << v << endl; - cout << "gprs[v]: " << gprs[v] << endl; return gprs[v]; } else if constexpr (std::is_same_v>) { @@ -190,4 +188,4 @@ class Stage Response status; }; -#endif /* STAGE_H_INCLUDED */ \ No newline at end of file +#endif /* STAGE_H_INCLUDED */ diff --git a/src/controller.cc b/src/controller.cc index a84126d..a5c6691 100644 --- a/src/controller.cc +++ b/src/controller.cc @@ -31,6 +31,7 @@ Controller::Controller(Stage *stage, Storage *storage, bool is_pipelined) this->pc = 0x0; this->checked_out = {}; this->gprs = {0}; + this->vrs.fill({0}); this->gprs.at(2) = MEM_WORDS; // set the stack pointer } diff --git a/src/ex.cc b/src/ex.cc index 6dfe44f..3f86ad4 100644 --- a/src/ex.cc +++ b/src/ex.cc @@ -22,7 +22,6 @@ #include "stage.h" #include - // Switch statements for each instruction void EX::advance_helper() { @@ -32,212 +31,217 @@ void EX::advance_helper() unsigned int pc; Mnemonic m; + s1 = 0, s2 = 0, s3 = 0; m = this->curr_instr->mnemonic; pc = this->curr_instr->slot_B; - if(this->is_vector_type(m)) { - if(this->curr_instr->mnemonic != LOADV && this->curr_instr->mnemonic != STOREV){ + if (this->is_vector_type(m)) { + if (this->curr_instr->mnemonic != LOADV && + this->curr_instr->mnemonic != STOREV) { v1 = this->curr_instr->operands.vector.slot_one; v2 = this->curr_instr->operands.vector.slot_two; - v3 = this->curr_instr->operands.vector.slot_three; + v3 = this->curr_instr->operands.vector.slot_three; } else { - v_immediate = this->curr_instr->operands.load_store_vector.immediate; - v_base_addr = this->curr_instr->operands.load_store_vector.base_addr; + v_immediate = + this->curr_instr->operands.load_store_vector.immediate; + v_base_addr = + this->curr_instr->operands.load_store_vector.base_addr; } v_len = this->curr_instr->slot_A; - if(v_len == 0){ - //clear destination vector reg + if (v_len == 0) { + // clear destination vector reg v1.fill(0); - } - } else{ + } + } else { s1 = this->curr_instr->operands.integer.slot_one; s2 = this->curr_instr->operands.integer.slot_two; s3 = this->curr_instr->operands.integer.slot_three; } - if(this->is_logical(m)) { + if (this->is_logical(m)) { this->set_condition(OF, false); this->set_condition(UF, false); } - switch(m) { - case ADD: - this->set_condition(OF, ADDITION_OF_GUARD(s1, s2)); - this->set_condition(UF, ADDITION_UF_GUARD(s1, s2)); - s1 = s1 + s2; - break; - - case SUB: - this->set_condition(OF, SUBTRACTION_OF_GUARD(s1, s2)); - this->set_condition(UF, SUBTRACTION_UF_GUARD(s1, s2)); - s1 = s1 - s2; - break; - - case MUL: - this->set_condition(OF, MULTIPLICATION_OF_GUARD(s1, s2)); - this->set_condition(UF, MULTIPLICATION_UF_GUARD(s1, s2)); - s1 = s1 * s2; - break; - - case QUOT: - this->handle_divide(s1, s2, false); - break; - - case REM: - this->handle_divide(s1, s2, true); - break; - - case SFTR: - s1 = s1 >> s2; - break; - - case SFTL: - s1 = s1 << s2; - break; - - case AND: - s1 = s1 & s2; - break; - - case OR: - s1 = s1 | s2; - break; - - case XOR: - s1 = s1 ^ s2; - break; - - case NOT: - s1 = ~s1; - break; - - case CMP: - (s1 > s2) ? this->set_condition(GT, true) - : this->set_condition(GT, false); - (s1 == s2) ? this->set_condition(EQ, true) - : this->set_condition(EQ, false); + switch (m) { + case ADD: + this->set_condition(OF, ADDITION_OF_GUARD(s1, s2)); + this->set_condition(UF, ADDITION_UF_GUARD(s1, s2)); + s1 = s1 + s2; + break; + + case SUB: + this->set_condition(OF, SUBTRACTION_OF_GUARD(s1, s2)); + this->set_condition(UF, SUBTRACTION_UF_GUARD(s1, s2)); + s1 = s1 - s2; + break; + + case MUL: + this->set_condition(OF, MULTIPLICATION_OF_GUARD(s1, s2)); + this->set_condition(UF, MULTIPLICATION_UF_GUARD(s1, s2)); + s1 = s1 * s2; + break; + + case QUOT: + this->handle_divide(s1, s2, false); + break; + + case REM: + this->handle_divide(s1, s2, true); + break; + + case SFTR: + s1 = s1 >> s2; + break; + + case SFTL: + s1 = s1 << s2; + break; + + case AND: + s1 = s1 & s2; + break; + + case OR: + s1 = s1 | s2; + break; + + case XOR: + s1 = s1 ^ s2; + break; + + case NOT: + s1 = ~s1; + break; + + case CMP: + (s1 > s2) ? this->set_condition(GT, true) + : this->set_condition(GT, false); + (s1 == s2) ? this->set_condition(EQ, true) + : this->set_condition(EQ, false); + break; + + case ADDI: + this->set_condition(OF, ADDITION_OF_GUARD(s1, s3)); + this->set_condition(UF, ADDITION_UF_GUARD(s1, s3)); + s1 = s1 + s3; + break; + + case SUBI: + this->set_condition(OF, SUBTRACTION_OF_GUARD(s1, s3)); + this->set_condition(UF, SUBTRACTION_UF_GUARD(s1, s3)); + s1 = s1 - s3; + break; + + case SFTRI: + s1 = s1 >> s3; + break; + + case SFTLI: + s1 = s1 << s3; + break; + + case ANDI: + s1 = s1 & s3; + break; + + case ORI: + s1 = s1 | s3; + break; + + case XORI: + s1 = s1 ^ s3; + break; + + case LOAD: + case STORE: + case PUSH: + case POP: + s1 = s1 + s3; + break; + + case JMP: + case JAL: + s1 = s1 + s2; + break; + + case JRL: + s1 = pc + s2; + break; + + case BEQ: + (this->get_condition(EQ)) ? s1 = pc + s2 : s1 = -1; + break; + + case BGT: + (this->get_condition(GT)) ? s1 = pc + s2 : s1 = -1; + break; + + case BUF: + (this->get_condition(UF)) ? s1 = pc + s2 : s1 = -1; + break; + + case BOF: + (this->get_condition(OF)) ? s1 = pc + s2 : s1 = -1; + break; + + case ADDV: + for (int i = 0; i < v_len; i++) { + this->set_condition(OF, ADDITION_OF_GUARD(v1[i], v2[i])); + this->set_condition(UF, ADDITION_UF_GUARD(v1[i], v2[i])); + v1[i] = v1[i] + v2[i]; + } + break; + case SUBV: + for (int i = 0; i < v_len; i++) { + this->set_condition(OF, SUBTRACTION_OF_GUARD(v1[i], v2[i])); + this->set_condition(UF, SUBTRACTION_UF_GUARD(v1[i], v2[i])); + v1[i] = v1[i] - v2[i]; + } + break; + case MULV: + for (int i = 0; i < v_len; i++) { + this->set_condition(OF, MULTIPLICATION_OF_GUARD(v1[i], v2[i])); + this->set_condition(UF, MULTIPLICATION_UF_GUARD(v1[i], v2[i])); + v1[i] = v1[i] * v2[i]; + } + break; + case DIVV: + for (int i = 0; i < v_len; i++) { + this->handle_divide(v1[i], v2[i], false); + } + break; + case CEV: + int i; + for (i = 0; i < v_len; i++) { + if (v1[i] != v2[i]) { break; - - case ADDI: - this->set_condition(OF, ADDITION_OF_GUARD(s1, s3)); - this->set_condition(UF, ADDITION_UF_GUARD(s1, s3)); - s1 = s1 + s3; - break; - - case SUBI: - this->set_condition(OF, SUBTRACTION_OF_GUARD(s1, s3)); - this->set_condition(UF, SUBTRACTION_UF_GUARD(s1, s3)); - s1 = s1 - s3; - break; - - case SFTRI: - s1 = s1 >> s3; - break; - - case SFTLI: - s1 = s1 << s3; - break; - - case ANDI: - s1 = s1 & s3; - break; - - case ORI: - s1 = s1 | s3; - break; - - case XORI: - s1 = s1 ^ s3; - break; - - case LOAD: - case STORE: - case PUSH: - case POP: - s1 = s1 + s3; - break; - - case JMP: - case JAL: - s1 = s1 + s2; - break; - - case JRL: - s1 = pc + s2; - break; - - case BEQ: - (this->get_condition(EQ)) ? s1 = pc + s2 : s1 = -1; - break; - - case BGT: - (this->get_condition(GT)) ? s1 = pc + s2 : s1 = -1; - break; - - case BUF: - (this->get_condition(UF)) ? s1 = pc + s2 : s1 = -1; - break; - - case BOF: - (this->get_condition(OF)) ? s1 = pc + s2 : s1 = -1; - break; - - case ADDV: - for(int i=0;iset_condition(OF, ADDITION_OF_GUARD(v1[i],v2[i])); - this->set_condition(UF, ADDITION_UF_GUARD(v1[i],v2[i])); - v1[i] = v1[i] + v2[i]; } - break; - case SUBV: - for(int i=0;iset_condition(OF, SUBTRACTION_OF_GUARD(v1[i],v2[i])); - this->set_condition(UF, SUBTRACTION_UF_GUARD(v1[i],v2[i])); - v1[i] = v1[i] - v2[i]; - } - break; - case MULV: - for(int i=0;iset_condition(OF, MULTIPLICATION_OF_GUARD(v1[i],v2[i])); - this->set_condition(UF, MULTIPLICATION_UF_GUARD(v1[i],v2[i])); - v1[i] = v1[i] * v2[i]; - } - break; - case DIVV: - for(int i=0;ihandle_divide(v1[i],v2[i],false); - } - break; - case CEV: - int i; - for(i=0;iset_condition(EQ, true); - } else { - this->set_condition(EQ, false); - } - break; - case LOADV: - case STOREV: - v_base_addr = v_base_addr + v_immediate; - break; - - case RET: - case NOP: - break; - + } + if (i == v_len) { + this->set_condition(EQ, true); + } else { + this->set_condition(EQ, false); + } + break; + case LOADV: + case STOREV: + v_base_addr = v_base_addr + v_immediate; + break; + + case RET: + case NOP: + break; } - if(this->is_vector_type(m)) { - if(this->curr_instr->mnemonic != LOADV && this->curr_instr->mnemonic != STOREV){ - this->curr_instr->operands.vector.slot_one = v1; + if (this->is_vector_type(m)) { + if (this->curr_instr->mnemonic != LOADV && + this->curr_instr->mnemonic != STOREV) { + this->curr_instr->operands.vector.slot_one = v1; } else { - this->curr_instr->operands.load_store_vector.base_addr = v_base_addr; - } - } else{ + this->curr_instr->operands.load_store_vector.base_addr = + v_base_addr; + } + } else { this->curr_instr->operands.integer.slot_one = s1; } this->status = OK; diff --git a/src/id.cc b/src/id.cc index 4358150..e4790ef 100644 --- a/src/id.cc +++ b/src/id.cc @@ -285,6 +285,7 @@ void ID::decode_J_type(signed int &s1) s3 = 2; // stack pointer s1 = -1; // increment amount r1 = this->read_guard(s2); + this->curr_instr->operands.integer.slot_one = s1; this->curr_instr->operands.integer.slot_two = s2; r2 = (this->is_checked_out(s3)) ? STALLED : OK; // we read the stack pointer @@ -298,6 +299,7 @@ void ID::decode_J_type(signed int &s1) s2 = s1; // destination s3 = 2; // stack pointer s1 = 1; // increment amount + this->curr_instr->operands.integer.slot_one = s1; r1 = (this->is_checked_out(s3)) ? STALLED : OK; // we read the stack pointer if (r1 == OK) { @@ -316,7 +318,7 @@ void ID::decode_J_type(signed int &s1) if(this->status == OK){ this->curr_instr->operands.integer.slot_one = s1; this->curr_instr->operands.integer.slot_two = s2; - this->curr_instr->operands.integer.slot_three = s3; + this->curr_instr->operands.integer.slot_three = s3; } } } -- cgit v1.2.3 From 336faf3fd701aaf962613abd1ff0a69cbdf021ce Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 27 Apr 2025 23:34:35 -0400 Subject: Fix UI display to not be ridged --- gui/gui.ui | 21 ++++++++++++--------- src/ex.cc | 2 ++ 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src/ex.cc') diff --git a/gui/gui.ui b/gui/gui.ui index 18d5da1..5a5a037 100644 --- a/gui/gui.ui +++ b/gui/gui.ui @@ -6,7 +6,7 @@ 0 0 - 1522 + 1686 621 @@ -18,14 +18,17 @@ - + + + 6 + - 1250 + 0 0 @@ -35,7 +38,7 @@ - + @@ -93,7 +96,7 @@ - 200 + 0 0 @@ -146,7 +149,7 @@ - 200 + 0 0 @@ -199,7 +202,7 @@ - 200 + 0 0 @@ -255,7 +258,7 @@ - 200 + 0 0 @@ -308,7 +311,7 @@ - 200 + 0 0 diff --git a/src/ex.cc b/src/ex.cc index 3f86ad4..286c7ba 100644 --- a/src/ex.cc +++ b/src/ex.cc @@ -32,6 +32,8 @@ void EX::advance_helper() Mnemonic m; s1 = 0, s2 = 0, s3 = 0; + v1 = {0}, v2 = {0}, v3 = {0}; + v_len = 0, v_immediate = 0, v_base_addr = 0; m = this->curr_instr->mnemonic; pc = this->curr_instr->slot_B; -- cgit v1.2.3