summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-01 22:06:42 -0400
committerbd <bdunahu@operationnull.com>2025-04-01 22:06:42 -0400
commitd4e3a7a3b1cff6885978093d5cc125e38cc397b3 (patch)
tree92caf723e7eadfa063fafe2291ca6ec4ed9513e0
parent68324683cde10c636a4a602644f3e64d24b0e412 (diff)
Finish adding initial tests for full pipeline
-rw-r--r--inc/id.h2
-rw-r--r--inc/stage.h5
-rw-r--r--src/sim/ex.cc3
-rw-r--r--src/sim/id.cc12
-rw-r--r--src/sim/instrDTO.cc1
-rw-r--r--src/sim/mm.cc2
-rw-r--r--src/sim/stage.cc3
-rw-r--r--src/sim/wb.cc1
-rw-r--r--tests/controller.cc10
-rw-r--r--tests/ex.cc39
10 files changed, 25 insertions, 53 deletions
diff --git a/inc/id.h b/inc/id.h
index 6178ad2..fd8c874 100644
--- a/inc/id.h
+++ b/inc/id.h
@@ -67,7 +67,7 @@ class ID : public Stage
void get_instr_fields(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m, Type &t);
void decode_R_type(signed int &s1, signed int &s2, signed int &s3);
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);
+ void decode_J_type(signed int &s1, signed int &s2, signed int &s3);
/**
* Helper for `get_instr_fields`.
* Given a raw instruction, returns the mnemonic and type.
diff --git a/inc/stage.h b/inc/stage.h
index 20f0191..51ab667 100644
--- a/inc/stage.h
+++ b/inc/stage.h
@@ -55,11 +55,6 @@ class Stage
void set_condition(CC c, bool v);
/**
- * Sets the value of the PC register.
- */
- void set_pc(unsigned int pc);
-
- /**
* Squashes the pipeline.
*/
void squash();
diff --git a/src/sim/ex.cc b/src/sim/ex.cc
index 98a2d19..b6f8a1d 100644
--- a/src/sim/ex.cc
+++ b/src/sim/ex.cc
@@ -163,7 +163,6 @@ EX::EX(Stage *stage) : Stage(stage)
INIT_INSTRUCTION(
CMP,
{
- cout << "CMP: " << s1 << ":" << s2 << std::endl;
(s1 > s2) ? this->set_condition(GT, true)
: this->set_condition(GT, false);
(s1 == s2) ? this->set_condition(EQ, true)
@@ -205,8 +204,6 @@ EX::EX(Stage *stage) : Stage(stage)
INIT_INSTRUCTION(
ADDI,
{
- std::cout << this->id << ": " << s1 << "," << s2 << "," << s3
- << std::endl;
s1 = s1 + s3;
(void)pc;
(void)s2;
diff --git a/src/sim/id.cc b/src/sim/id.cc
index 805a4df..0df26f4 100644
--- a/src/sim/id.cc
+++ b/src/sim/id.cc
@@ -51,9 +51,6 @@ void ID::advance_helper()
if (curr_instr->get_mnemonic() == NOP)
this->status = OK;
else {
- std::cout << this->id << ": " << this->curr_instr->get_s1() << ","
- << this->curr_instr->get_s2() << ","
- << this->curr_instr->get_s3() << std::endl;
s1 = curr_instr->get_instr_bits();
get_instr_fields(s1, s2, s3, m, t);
if (this->status == OK) {
@@ -63,9 +60,6 @@ void ID::advance_helper()
curr_instr->set_mnemonic(m);
curr_instr->set_type(t);
}
- std::cout << this->id << ": " << this->curr_instr->get_s1() << ","
- << this->curr_instr->get_s2() << ","
- << this->curr_instr->get_s3() << std::endl;
}
}
@@ -86,7 +80,7 @@ void ID::get_instr_fields(
break;
case 0b10:
t = J;
- this->decode_J_type(s1, s2);
+ this->decode_J_type(s1, s2, s3);
break;
case 0b11:
t = INV;
@@ -126,7 +120,6 @@ void ID::decode_I_type(
s2 = GET_MID_BITS(s1, s0b, s1b);
s1 = GET_LS_BITS(s1, s0b);
- std::cout << m << ":" << s2 << std::endl;
r1 = this->read_guard(s1);
if (m != STORE && m != STOREV) {
this->status = r1;
@@ -135,12 +128,13 @@ void ID::decode_I_type(
this->status = (this->read_guard(s2) == OK && r1 == OK) ? OK : STALLED;
}
-void ID::decode_J_type(signed int &s1, signed int &s2)
+void ID::decode_J_type(signed int &s1, signed int &s2, signed int &s3)
{
unsigned int s0b, s1b;
s0b = REG_SIZE;
s1b = WORD_SPEC;
+ s3 = 0;
s2 = GET_MID_BITS(s1, s0b, s1b);
s1 = GET_LS_BITS(s1, s0b);
diff --git a/src/sim/instrDTO.cc b/src/sim/instrDTO.cc
index d36e957..aa49b7e 100644
--- a/src/sim/instrDTO.cc
+++ b/src/sim/instrDTO.cc
@@ -9,6 +9,7 @@ InstrDTO::InstrDTO()
this->s3 = 0;
this->mnemonic = ADD;
this->type = INV;
+ this->pc = 0;
}
int InstrDTO::get_time_of(Accessor a) { return this->hist[a]; }
diff --git a/src/sim/mm.cc b/src/sim/mm.cc
index c83ae7d..07a362b 100644
--- a/src/sim/mm.cc
+++ b/src/sim/mm.cc
@@ -15,7 +15,7 @@ void MM::advance_helper()
this->status = this->storage->read_word(
this->id, this->curr_instr->get_s1(), data);
if (this->status == OK) {
- this->curr_instr->set_s2(data);
+ this->curr_instr->set_s1(data);
} else
this->status = STALLED;
break;
diff --git a/src/sim/stage.cc b/src/sim/stage.cc
index bd0ff6b..24bdf75 100644
--- a/src/sim/stage.cc
+++ b/src/sim/stage.cc
@@ -22,8 +22,6 @@ int Stage::clock_cycle;
bool Stage::get_condition(CC c) { return (this->gprs[3] >> c) & 1; }
-void Stage::set_pc(unsigned int pc) { this->pc = pc; }
-
InstrDTO *Stage::advance(Response p)
{
InstrDTO *r = nullptr;
@@ -96,7 +94,6 @@ bool Stage::is_checked_out(signed int r)
void Stage::squash()
{
if (curr_instr) {
- std::cout << "!!!" << std::endl;
this->curr_instr->set_mnemonic(NOP);
this->status = OK;
}
diff --git a/src/sim/wb.cc b/src/sim/wb.cc
index 50acd05..01768e8 100644
--- a/src/sim/wb.cc
+++ b/src/sim/wb.cc
@@ -28,7 +28,6 @@ void WB::write_handler()
reg = this->checked_out.front();
this->checked_out.pop_front();
- std::cout << "storing " << reg << " with " << this->curr_instr->get_s1() << std::endl;
this->store_register(reg, this->curr_instr->get_s1());
}
diff --git a/tests/controller.cc b/tests/controller.cc
index c36eba6..c7e3c93 100644
--- a/tests/controller.cc
+++ b/tests/controller.cc
@@ -187,7 +187,6 @@ TEST_CASE_METHOD(ControllerPipeFixture, "two num adder", "[full pipe]")
CHECK(i->get_instr_bits() == b3);
delete i;
-
i = this->ct->advance(WAIT);
REQUIRE(i == nullptr);
i = this->ct->advance(WAIT);
@@ -259,7 +258,6 @@ TEST_CASE_METHOD(ControllerPipeFixture, "two num adder", "[full pipe]")
CHECK(i->get_time_of(WRITE) == 22);
CHECK(i->get_s1() == 0xE);
CHECK(i->get_s2() == 0x7);
- CHECK(i->get_s3() == 0x0); // doesn't exist
CHECK(this->ct->get_gprs().at(2) == 0x200);
CHECK(this->ct->get_gprs().at(6) == 0x1);
CHECK(i->get_pc() == 0x7);
@@ -332,11 +330,11 @@ TEST_CASE_METHOD(ControllerPipeFixture, "two num adder", "[full pipe]")
REQUIRE(i != nullptr);
CHECK(i->get_mnemonic() == NOP);
+
delete i;
-
i = this->ct->advance(WAIT);
REQUIRE(i != nullptr); // it was already in cache
-
+
CHECK(i->get_time_of(FETCH) == 29); // clear out pipe (4)
CHECK(i->get_time_of(DCDE) == 30);
CHECK(i->get_time_of(EXEC) == 31);
@@ -366,8 +364,8 @@ TEST_CASE_METHOD(ControllerPipeFixture, "two num adder", "[full pipe]")
CHECK(i->get_time_of(EXEC) == 34);
CHECK(i->get_time_of(MEM) == 35);
CHECK(i->get_time_of(WRITE) == 36);
- CHECK(i->get_s1() == 0x0);
- CHECK(i->get_s2() == 0x200);
+ CHECK(i->get_s1() == 0x1);
+ CHECK(i->get_s2() == 0x0);
CHECK(i->get_s3() == 0x0);
CHECK(this->ct->get_gprs().at(2) == 0x200);
CHECK(this->ct->get_gprs().at(6) == 0x1);
diff --git a/tests/ex.cc b/tests/ex.cc
index a0af6fe..13437f7 100644
--- a/tests/ex.cc
+++ b/tests/ex.cc
@@ -640,8 +640,7 @@ TEST_CASE_METHOD(EXFixture, "JRL", "[ex]")
InstrDTO *i;
m = JRL;
- s1 = 100, s2 = -42027, s3 = 0;
- this->ct->set_pc(42096);
+ s1 = 100, s2 = 69, s3 = 0;
i = execute_instr(s1, s2, s3, m);
CHECK(i->get_s1() == 69);
@@ -675,11 +674,10 @@ TEST_CASE_METHOD(EXFixture, "BEQ no cond", "[ex]")
InstrDTO *i;
m = BEQ;
- s1 = 100, s2 = -42027, s3 = 0;
- this->ct->set_pc(42096);
+ s1 = 100, s2 = 50, s3 = 0;
i = execute_instr(s1, s2, s3, m);
- CHECK(i->get_s1() == 42096);
+ CHECK(i->get_s1() == -1);
delete i;
}
@@ -691,12 +689,11 @@ TEST_CASE_METHOD(EXFixture, "BEQ", "[ex]")
InstrDTO *i;
m = BEQ;
- s1 = 100, s2 = -42027, s3 = 0;
- this->ct->set_pc(42096);
+ s1 = 100, s2 = 50, s3 = 0;
this->ct->set_condition(EQ, true);
i = execute_instr(s1, s2, s3, m);
- CHECK(i->get_s1() == 69);
+ CHECK(i->get_s1() == 50);
delete i;
}
@@ -708,11 +705,10 @@ TEST_CASE_METHOD(EXFixture, "BGT no cond", "[ex]")
InstrDTO *i;
m = BGT;
- s1 = 100, s2 = -42027, s3 = 0;
- this->ct->set_pc(42096);
+ s1 = 100, s2 = 50, s3 = 0;
i = execute_instr(s1, s2, s3, m);
- CHECK(i->get_s1() == 42096);
+ CHECK(i->get_s1() == -1);
delete i;
}
@@ -724,12 +720,11 @@ TEST_CASE_METHOD(EXFixture, "BGT", "[ex]")
InstrDTO *i;
m = BGT;
- s1 = 100, s2 = -42027, s3 = 0;
- this->ct->set_pc(42096);
+ s1 = 100, s2 = 50, s3 = 0;
this->ct->set_condition(GT, true);
i = execute_instr(s1, s2, s3, m);
- CHECK(i->get_s1() == 69);
+ CHECK(i->get_s1() == 50);
delete i;
}
@@ -742,10 +737,9 @@ TEST_CASE_METHOD(EXFixture, "BUF no cond", "[ex]")
m = BUF;
s1 = 100, s2 = -42027, s3 = 0;
- this->ct->set_pc(42096);
i = execute_instr(s1, s2, s3, m);
- CHECK(i->get_s1() == 42096);
+ CHECK(i->get_s1() == -1);
delete i;
}
@@ -757,12 +751,11 @@ TEST_CASE_METHOD(EXFixture, "BUF", "[ex]")
InstrDTO *i;
m = BUF;
- s1 = 100, s2 = -42027, s3 = 0;
- this->ct->set_pc(42096);
+ s1 = 100, s2 = 50, s3 = 0;
this->ct->set_condition(UF, true);
i = execute_instr(s1, s2, s3, m);
- CHECK(i->get_s1() == 69);
+ CHECK(i->get_s1() == 50);
delete i;
}
@@ -775,10 +768,9 @@ TEST_CASE_METHOD(EXFixture, "BOF no cond", "[ex]")
m = BOF;
s1 = 100, s2 = -42027, s3 = 0;
- this->ct->set_pc(42096);
i = execute_instr(s1, s2, s3, m);
- CHECK(i->get_s1() == 42096);
+ CHECK(i->get_s1() == -1);
delete i;
}
@@ -790,12 +782,11 @@ TEST_CASE_METHOD(EXFixture, "BOF", "[ex]")
InstrDTO *i;
m = BOF;
- s1 = 100, s2 = -42027, s3 = 0;
- this->ct->set_pc(42096);
+ s1 = 100, s2 = 50, s3 = 0;
this->ct->set_condition(OF, true);
i = execute_instr(s1, s2, s3, m);
- CHECK(i->get_s1() == 69);
+ CHECK(i->get_s1() == 50);
delete i;
}