From 15398c34d38489bf14a100bbf01fb9fb4c7e46cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 12 Dec 2017 18:53:02 +0100 Subject: Implement branch and jump instructions --- qtmips_machine/tests/testcore.cpp | 99 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 6 deletions(-) (limited to 'qtmips_machine/tests/testcore.cpp') diff --git a/qtmips_machine/tests/testcore.cpp b/qtmips_machine/tests/testcore.cpp index 27a49b4..593483a 100644 --- a/qtmips_machine/tests/testcore.cpp +++ b/qtmips_machine/tests/testcore.cpp @@ -175,9 +175,6 @@ void MachineTests::pipecore_regs_data() { core_regs_data(); } -#include -using namespace std; - void MachineTests::singlecore_regs() { QFETCH(Instruction, i); QFETCH(Registers, init); @@ -208,16 +205,106 @@ void MachineTests::pipecore_regs() { res.pc_jmp(0x14); CorePipelined core(&init, &mem_used); - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 5; i++) core.step(); // Fire steps for five pipelines stages - } - core.step(); //cout << "well:" << init.read_gp(26) << ":" << regs_used.read_gp(26) << endl; QCOMPARE(init, res); // After doing changes from initial state this should be same state as in case of passed expected result QCOMPARE(mem, mem_used); // There should be no change in memory } +static void core_jmp_data() { + QTest::addColumn("i"); + QTest::addColumn("regs"); + QTest::addColumn("pc"); + + Registers regs; + regs.write_gp(14, -22); + regs.write_gp(15, 22); + regs.write_gp(16, -22); + QTest::newRow("B") << Instruction(4, 0, 0, 61) \ + << regs \ + << regs.read_pc() + 4 + (61 << 2); + QTest::newRow("BEQ") << Instruction(4, 14, 16, 61) \ + << regs \ + << regs.read_pc() + 4 + (61 << 2); + QTest::newRow("BNE") << Instruction(5, 14, 15, 61) \ + << regs \ + << regs.read_pc() + 4 + (61 << 2); + QTest::newRow("BGEZ") << Instruction(1, 15, 1, 61) \ + << regs \ + << regs.read_pc() + 4 + (61 << 2); + QTest::newRow("BGTZ") << Instruction(7, 15, 0, 61) \ + << regs \ + << regs.read_pc() + 4 + (61 << 2); + QTest::newRow("BLEZ") << Instruction(6, 14, 0, 61) \ + << regs \ + << regs.read_pc() + 4 + (61 << 2); + QTest::newRow("BLTZ") << Instruction(1, 14, 0, 61) \ + << regs \ + << regs.read_pc() + 4 + (61 << 2); + QTest::newRow("J") << Instruction(2, 24) \ + << regs \ + << 0x80000000 + (24 << 2); + /* + QTest::newRow("JR") << Instruction(1, 15, 0, 61) \ + << regs \ + << regs.read_pc() + (24 << 2); + */ +} + +void MachineTests::singlecore_jmp_data() { + core_jmp_data(); +} + +void MachineTests::pipecore_jmp_data() { + core_jmp_data(); +} + +void MachineTests::singlecore_jmp() { + QFETCH(Instruction, i); + QFETCH(Registers, regs); + QFETCH(std::uint32_t, pc); + + Memory mem; + mem.write_word(regs.read_pc(), i.data()); + Memory mem_used(mem); + Registers regs_used(regs); + + CoreSingle core(®s_used, &mem_used); + core.step(); + QCOMPARE(regs.read_pc() + 4, regs_used.read_pc()); // First execute delay slot + core.step(); + QCOMPARE(pc, regs_used.read_pc()); // Now do jump + + QCOMPARE(mem, mem_used); // There should be no change in memory + regs_used.pc_abs_jmp(regs.read_pc()); // Reset program counter before we do registers compare + QCOMPARE(regs, regs_used); // There should be no change in registers now +} + +void MachineTests::pipecore_jmp() { + QFETCH(Instruction, i); + QFETCH(Registers, regs); + QFETCH(std::uint32_t, pc); + + Memory mem; + mem.write_word(regs.read_pc(), i.data()); + Memory mem_used(mem); + Registers regs_used(regs); + + CorePipelined core(®s_used, &mem_used); + core.step(); + QCOMPARE(regs.read_pc() + 4, regs_used.read_pc()); // First just fetch + core.step(); + QCOMPARE(pc, regs_used.read_pc()); // Now do jump + for (int i = 0; i < 3; i++) + core.step(); // Follow up with three other steps to complete pipeline to be sure that instruction has no side effects + + QCOMPARE(mem, mem_used); // There should be no change in memory + regs.pc_abs_jmp(pc + 12); // Set reference pc to three more instructions later (where regs_used should be) + QCOMPARE(regs, regs_used); // There should be no change in registers now (except pc) +} + void MachineTests::core_mem_data() { } -- cgit v1.2.3