From ebeb29d1b87c533c1e80e86ceed9ddc40e4d2cb2 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 30 Mar 2025 19:42:34 -0400 Subject: Add tests for EX --- inc/stage.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'inc/stage.h') diff --git a/inc/stage.h b/inc/stage.h index 56a3589..d1b6ee1 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -40,6 +40,16 @@ class Stage */ virtual InstrDTO *advance(Response p); + /* The following methods are made public so that they may be tested, and are + * not to be called from outside classes during standard execution. + */ + + /** + * Gets the bit in the condition code register correspondng to `c`. + * @param the condition code to retrieve, + */ + bool get_condition(CC c); + protected: /** * The function expected to do the majority of the work. @@ -53,11 +63,6 @@ class Stage * @param the truthy value to set it to. */ void set_condition(CC c, bool v); - /** - * Gets the bit in the condition code register correspondng to `c`. - * @param the condition code to retrieve, - */ - bool get_condition(CC c); /** * Helper for `check_out`. * Returns true if r are not checked out, false otherwise. -- cgit v1.2.3 From 4e0d121beed51c75221ef883e0fd7ec7b0ec24f2 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 30 Mar 2025 20:08:59 -0400 Subject: Implementation and tests for J types --- inc/stage.h | 5 +++ src/sim/ex.cc | 45 +++++++++++++++---- src/sim/stage.cc | 12 +++-- tests/ex.cc | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+), 13 deletions(-) (limited to 'inc/stage.h') diff --git a/inc/stage.h b/inc/stage.h index d1b6ee1..84d2a7b 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -50,6 +50,11 @@ class Stage */ bool get_condition(CC c); + /** + * Sets the value of the PC register. + */ + void set_pc(unsigned int pc); + protected: /** * The function expected to do the majority of the work. diff --git a/src/sim/ex.cc b/src/sim/ex.cc index b4e86ac..b043eb3 100644 --- a/src/sim/ex.cc +++ b/src/sim/ex.cc @@ -227,23 +227,50 @@ EX::EX(Stage *stage) : Stage(stage) }), /* J type instructions */ - INIT_INSTRUCTION(JMP, {}), + INIT_INSTRUCTION( + JMP, + { + s1 = s1 + s2; + (void)this; + }), - INIT_INSTRUCTION(JRL, {}), + INIT_INSTRUCTION( + JRL, + { + s1 = this->pc + s2; + (void)this; + }), - INIT_INSTRUCTION(JAL, {}), + INIT_INSTRUCTION( + JAL, + { + s1 = s1 + s2; + (void)this; + }), - INIT_INSTRUCTION(BEQ, {}), + INIT_INSTRUCTION(BEQ, { s1 = this->pc + s2; }), - INIT_INSTRUCTION(BGT, {}), + INIT_INSTRUCTION(BGT, { s1 = this->pc + s2; }), - INIT_INSTRUCTION(BUF, {}), + INIT_INSTRUCTION(BUF, { s1 = this->pc + s2; }), - INIT_INSTRUCTION(BOF, {}), + INIT_INSTRUCTION(BOF, { s1 = this->pc + s2; }), - INIT_INSTRUCTION(PUSH, {}), + INIT_INSTRUCTION( + PUSH, + { + (void)s2; + (void)s1; + (void)this; + }), - INIT_INSTRUCTION(POP, {}), + INIT_INSTRUCTION( + POP, + { + (void)s2; + (void)s1; + (void)this; + }), /* NOP */ INIT_INSTRUCTION( diff --git a/src/sim/stage.cc b/src/sim/stage.cc index 74a2176..2c03741 100644 --- a/src/sim/stage.cc +++ b/src/sim/stage.cc @@ -21,6 +21,14 @@ Storage *Stage::storage; bool Stage::is_pipelined; 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; @@ -50,10 +58,6 @@ void Stage::set_condition(CC c, bool v) this->gprs[3] = this->gprs[3] & ~(1 << c); } -bool Stage::get_condition(CC c) { - return (this->gprs[3] >> c) & 1; -} - signed int Stage::dereference_register(signed int v) { signed int r; diff --git a/tests/ex.cc b/tests/ex.cc index 29c5fbc..cfa459d 100644 --- a/tests/ex.cc +++ b/tests/ex.cc @@ -611,3 +611,135 @@ TEST_CASE_METHOD(EXFixture, "STORE", "[ex]") // TEST_CASE_METHOD(EXFixture, "STOREV", "[ex]") // { // } + +TEST_CASE_METHOD(EXFixture, "JMP", "[ex]") +{ + signed int s1 = 0, s2 = 0; + Mnemonic m; + InstrDTO *i; + + m = JMP; + s1 = 42000, s2 = -41958; + i = execute_instr(s1, s2, m); + + CHECK(i->get_s1() == 42); + CHECK(!ct->get_condition(OF)); + CHECK(!ct->get_condition(UF)); + + delete i; +} + +TEST_CASE_METHOD(EXFixture, "JRL", "[ex]") +{ + signed int s1 = 0, s2 = 0; + Mnemonic m; + InstrDTO *i; + + m = JRL; + s1 = 100, s2 = -42027; + this->ct->set_pc(42096); + i = execute_instr(s1, s2, m); + + CHECK(i->get_s1() == 69); + CHECK(!ct->get_condition(OF)); + CHECK(!ct->get_condition(UF)); + + delete i; +} + +TEST_CASE_METHOD(EXFixture, "JAL", "[ex]") +{ + signed int s1 = 0, s2 = 0; + Mnemonic m; + InstrDTO *i; + + m = JAL; + s1 = 42000, s2 = -41958; + i = execute_instr(s1, s2, m); + + CHECK(i->get_s1() == 42); + CHECK(!ct->get_condition(OF)); + CHECK(!ct->get_condition(UF)); + + delete i; +} + +TEST_CASE_METHOD(EXFixture, "BEQ", "[ex]") +{ + signed int s1 = 0, s2 = 0; + Mnemonic m; + InstrDTO *i; + + m = BEQ; + s1 = 100, s2 = -42027; + this->ct->set_pc(42096); + i = execute_instr(s1, s2, m); + + CHECK(i->get_s1() == 69); + CHECK(!ct->get_condition(OF)); + CHECK(!ct->get_condition(UF)); + + delete i; +} + +TEST_CASE_METHOD(EXFixture, "BGT", "[ex]") +{ + signed int s1 = 0, s2 = 0; + Mnemonic m; + InstrDTO *i; + + m = BGT; + s1 = 100, s2 = -42027; + this->ct->set_pc(42096); + i = execute_instr(s1, s2, m); + + CHECK(i->get_s1() == 69); + CHECK(!ct->get_condition(OF)); + CHECK(!ct->get_condition(UF)); + + delete i; +} + +TEST_CASE_METHOD(EXFixture, "BUF", "[ex]") +{ + signed int s1 = 0, s2 = 0; + Mnemonic m; + InstrDTO *i; + + m = BUF; + s1 = 100, s2 = -42027; + this->ct->set_pc(42096); + i = execute_instr(s1, s2, m); + + CHECK(i->get_s1() == 69); + CHECK(!ct->get_condition(OF)); + CHECK(!ct->get_condition(UF)); + + delete i; +} + +TEST_CASE_METHOD(EXFixture, "BOF", "[ex]") +{ + signed int s1 = 0, s2 = 0; + Mnemonic m; + InstrDTO *i; + + m = BOF; + s1 = 100, s2 = -42027; + this->ct->set_pc(42096); + i = execute_instr(s1, s2, m); + + CHECK(i->get_s1() == 69); + CHECK(!ct->get_condition(OF)); + CHECK(!ct->get_condition(UF)); + + delete i; +} + +// TEST_CASE_METHOD(EXFixture, "PUSH", "[ex]") +// { +// } + +// TEST_CASE_METHOD(EXFixture, "POP", "[ex]") +// { +// } -- cgit v1.2.3