From a08582325ef39cb5dc1bbe14043b756b111899b1 Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 10 May 2025 15:07:58 -0400 Subject: Fix tests to use correct register indexes with vector addition --- tests/id.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/id.cc') diff --git a/tests/id.cc b/tests/id.cc index a81e967..ca10677 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -118,7 +118,7 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # two", "[id]") signed int t; InstrDTO *i; - t = this->encode_R_type(0b10000, 0b01000, 0b00100, 0b10, 0b0); + t = this->encode_R_type(0b1000, 0b01000, 0b00100, 0b10, 0b0); i = this->decode_bits(t); CHECK(i->operands.integer.slot_one == 0x00000000); // registers are empty @@ -150,7 +150,7 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # two", "[id]") signed int t; InstrDTO *i; - t = this->encode_I_type(0xCC, 0b101, 0b110, 0b1011, 0b1); + t = this->encode_I_type(0xCC, 0b10101, 0b00110, 0b11011, 0b1); i = this->decode_bits(t); CHECK(i->operands.integer.slot_one == 0x00000000); // registers are empty @@ -166,7 +166,7 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # one", "[id]") signed int t; InstrDTO *i; - t = this->encode_J_type(0x3456, 0b10101, 0b0111, 0b10); + t = this->encode_J_type(0x3456, 0b101, 0b0111, 0b10); i = this->decode_bits(t); CHECK(i->operands.integer.slot_one == 0x00000000); // registers are empty @@ -181,7 +181,7 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") signed int t; InstrDTO *i; - t = this->encode_J_type(0xBBCCF, 0b10101, 0b0011, 0b10); + t = this->encode_J_type(0xBBCCF, 0b00101, 0b0011, 0b10); i = this->decode_bits(t); t = 0xFFFBBCCF; -- cgit v1.2.3 From d0bb0aaf39bb61736e72b30e4d8f1a4a39536a0c Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 10 May 2025 15:17:40 -0400 Subject: Combine read_vec_guard and read_guard using templates --- inc/id.h | 31 ++++++++++++++++++++----------- src/id.cc | 51 +++++++++++++-------------------------------------- tests/id.cc | 15 --------------- 3 files changed, 33 insertions(+), 64 deletions(-) (limited to 'tests/id.cc') diff --git a/inc/id.h b/inc/id.h index ccce961..c1928ed 100644 --- a/inc/id.h +++ b/inc/id.h @@ -32,17 +32,6 @@ class ID : public Stage * not to be called from outside classes during standard execution. */ - /** - * Facilitates register checkout and data hazard management. - * It does this by checking that the register passed in is not currently - * checked out. If true, then replaces r with the value of the register and - * returns OK. If false, returns STALLED. - * - * @param the registers number, to be dereferenced. - * @return OK if `r` is not checked out, STALLED otherwise. - */ - Response read_guard(signed int &r); - Response read_vec_guard(signed int r, std::array &v); Response set_vlen(); private: @@ -104,6 +93,26 @@ class ID : public Stage r = this->dereference_register(v); return r; } + /** + * Facilitates register checkout and data hazard management. + * It does this by checking that the register passed in is not currently + * checked out. If true, then replaces reg with the value of the register and + * returns OK. If false, returns STALLED. + * + * @param the registers number, to be dereferenced. + * @return OK if `reg` is not checked out, STALLED otherwise. + */ + template Response read_guard(int reg, T &result) + { + Response response; + if (this->is_checked_out(reg)) + response = STALLED; + else { + response = OK; + result = this->dereference_register(reg); + } + return response; + } }; #endif /* ID_H_INCLUDED */ diff --git a/src/id.cc b/src/id.cc index 430bf09..bc6b873 100644 --- a/src/id.cc +++ b/src/id.cc @@ -22,31 +22,6 @@ #include "response.h" #include "stage.h" -Response ID::read_guard(signed int &v) -{ - Response r; - if (this->is_checked_out(v)) - r = STALLED; - else { - r = OK; - v = this->dereference_register(v); - } - return r; -} - -Response -ID::read_vec_guard(signed int v, std::array &vrs) -{ - Response r; - if (this->is_checked_out(v)) - r = STALLED; - else { - r = OK; - vrs = this->dereference_register>(v); - } - return r; -} - void ID::advance_helper() { signed int s1; @@ -102,7 +77,7 @@ Response ID::set_vlen() { signed int vlen_reg = 4; Response r; - r = this->read_guard(vlen_reg); + r = this->read_guard(vlen_reg, vlen_reg); vlen_reg = vlen_reg & 0xf; if (r == OK) { if (vlen_reg > V_R_LIMIT) { @@ -129,15 +104,15 @@ void ID::decode_R_type(signed int &s1) s1 = GET_LS_BITS(s1, s0b); if (instr::is_vector_type(this->curr_instr->mnemonic)) { - r1 = this->read_vec_guard( + r1 = this->read_guard>( s1, this->curr_instr->operands.vector.slot_one); - r2 = this->read_vec_guard( + r2 = this->read_guard>( s2, this->curr_instr->operands.vector.slot_two); r3 = this->set_vlen(); } else { - r1 = this->read_guard(s1); + r1 = this->read_guard(s1, s1); this->curr_instr->operands.integer.slot_one = s1; - r2 = this->read_guard(s2); + r2 = this->read_guard(s2, s2); this->curr_instr->operands.integer.slot_two = s2; } @@ -185,10 +160,10 @@ void ID::decode_I_type(signed int &s1) // both operands are read values // s1 is base address - r1 = this->read_guard(s1); + r1 = this->read_guard(s1, s1); this->curr_instr->operands.integer.slot_one = s1; // s2 is value to be stored - r2 = this->read_guard(s2); + r2 = this->read_guard(s2, s2); this->curr_instr->operands.integer.slot_two = s2; this->status = (r1 == OK && r2 == OK) ? OK : STALLED; return; @@ -198,10 +173,10 @@ void ID::decode_I_type(signed int &s1) s1 = GET_LS_BITS(s1, s0b); // base address - r1 = this->read_guard(s1); + r1 = this->read_guard(s1, s1); this->curr_instr->operands.load_store_vector.base_addr = s1; // vector value to be stored - r2 = this->read_vec_guard( + r2 = this->read_guard>( s2, this->curr_instr->operands.load_store_vector.vector_register); r3 = this->set_vlen(); @@ -212,7 +187,7 @@ void ID::decode_I_type(signed int &s1) s2 = GET_LS_BITS(s1, s0b); s1 = GET_MID_BITS(s1, s0b, s1b); // base address - r1 = this->read_guard(s1); + r1 = this->read_guard(s1, s1); this->curr_instr->operands.load_store_vector.base_addr = s1; r3 = this->set_vlen(); if (r1 == OK && r3 == OK) @@ -232,7 +207,7 @@ void ID::decode_I_type(signed int &s1) s1 = GET_LS_BITS(s1, s0b); } - r1 = this->read_guard(s1); + r1 = this->read_guard(s1, s1); this->curr_instr->operands.integer.slot_one = s1; if (r1 == OK) { this->curr_instr->operands.integer.slot_two = @@ -258,7 +233,7 @@ void ID::decode_J_type(signed int &s1) s2 = s1; // source s3 = 2; // stack pointer s1 = -1; // increment amount - r1 = this->read_guard(s2); + r1 = this->read_guard(s2, s2); this->curr_instr->operands.integer.slot_one = s1; this->curr_instr->operands.integer.slot_two = s2; r2 = (this->is_checked_out(s3)) ? STALLED @@ -290,7 +265,7 @@ void ID::decode_J_type(signed int &s1) s1 = 1; // link register [[fallthrough]]; default: - this->status = this->read_guard(s1); + this->status = this->read_guard(s1, s1); if (this->status == OK) { this->curr_instr->operands.integer.slot_one = s1; this->curr_instr->operands.integer.slot_two = s2; diff --git a/tests/id.cc b/tests/id.cc index ca10677..0e7de3b 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -191,18 +191,3 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") delete i; } - -TEST_CASE_METHOD(IDFixture, "read does not conflict with read", "[id]") -{ - signed int v; - Response r; - - v = 0b1; - r = this->d->read_guard(v); - CHECK(v == 0b0); - REQUIRE(r == OK); - - v = 0b1; - this->d->read_guard(v); - REQUIRE(v == 0b0); -} -- cgit v1.2.3 From f0f773a1f2acc3030c89fc5aa6335f667987aa2a Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 10 May 2025 17:02:27 -0400 Subject: Fix issue where decode would overwrite raw bits while in use --- inc/instrDTO.h | 4 ++-- src/controller.cc | 1 + src/ex.cc | 2 +- src/id.cc | 5 ++--- tests/id.cc | 16 ++++++++++++++++ 5 files changed, 22 insertions(+), 6 deletions(-) (limited to 'tests/id.cc') diff --git a/inc/instrDTO.h b/inc/instrDTO.h index f3d4597..f4ef416 100644 --- a/inc/instrDTO.h +++ b/inc/instrDTO.h @@ -19,7 +19,7 @@ #define INSTRDTO_H #include "instr.h" #include "pipe_spec.h" -#include +#include struct U_INT_TYPE { signed int slot_one; @@ -33,7 +33,7 @@ struct V_TYPE { std::array slot_three; }; -struct LOAD_STORE_V_TYPE{ +struct LOAD_STORE_V_TYPE { signed int base_addr; signed int immediate; std::array vector_register; diff --git a/src/controller.cc b/src/controller.cc index e439b30..190d3e2 100644 --- a/src/controller.cc +++ b/src/controller.cc @@ -32,6 +32,7 @@ Controller::Controller(Stage *stage, Storage *storage, bool is_pipelined) this->checked_out = {}; this->gprs = {0}; this->vrs.fill({0}); + this->vrs.at(0).fill(1); // constant 1 vector register this->gprs.at(2) = MEM_WORDS; // set the stack pointer } diff --git a/src/ex.cc b/src/ex.cc index f0ca5b5..73ed615 100644 --- a/src/ex.cc +++ b/src/ex.cc @@ -50,7 +50,7 @@ void EX::advance_helper() v_base_addr = this->curr_instr->operands.load_store_vector.base_addr; } - v_len = this->curr_instr->slot_A; + v_len = this->curr_instr->slot_B; if (v_len == 0) { // clear destination vector reg v1.fill(0); diff --git a/src/id.cc b/src/id.cc index 43975fb..490b03a 100644 --- a/src/id.cc +++ b/src/id.cc @@ -49,7 +49,6 @@ void ID::get_instr_fields(signed int instr_bits) this->decode_J_type(instr_bits); break; case 0b11: - this->curr_instr->mnemonic = NOP; this->status = OK; } @@ -79,9 +78,9 @@ Response ID::set_vlen() vlen_reg = vlen_reg & 0xf; if (r == OK) { if (vlen_reg > V_R_LIMIT) { - this->curr_instr->slot_A = V_R_LIMIT; + this->curr_instr->slot_B = V_R_LIMIT; } else { - this->curr_instr->slot_A = vlen_reg; + this->curr_instr->slot_B = vlen_reg; } } return r; diff --git a/tests/id.cc b/tests/id.cc index 0e7de3b..b52ad9c 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -129,6 +129,22 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # two", "[id]") delete i; } +TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # three", "[id]") +{ + signed int t; + InstrDTO *i; + + t = this->encode_R_type(0b10000, 0b10001, 0b10101, 0b1110, 0b0); + i = this->decode_bits(t); + + 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 == MULV); + + delete i; +} + TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # one", "[id]") { signed int t; -- cgit v1.2.3