diff options
-rw-r--r-- | instructions.md | 2 | ||||
-rw-r--r-- | qtmips_machine/alu.cpp | 6 | ||||
-rw-r--r-- | qtmips_machine/tests/testalu.cpp | 11 |
3 files changed, 14 insertions, 5 deletions
diff --git a/instructions.md b/instructions.md index 383d234..bfd936e 100644 --- a/instructions.md +++ b/instructions.md @@ -27,7 +27,7 @@ CPU Arithmetic Instruction * [x] SLT * [x] SLTI * [x] SLTIU -* [?] SLTU +* [x] SLTU * [x] SUB * [x] SUBU diff --git a/qtmips_machine/alu.cpp b/qtmips_machine/alu.cpp index 912ccf5..554874a 100644 --- a/qtmips_machine/alu.cpp +++ b/qtmips_machine/alu.cpp @@ -37,10 +37,10 @@ std::uint32_t alu_operate(enum AluOp operation, std::uint32_t s, std::uint32_t t return s ^ t; case ALU_OP_NOR: return ~(s | t); - case ALU_OP_SLTU: - // TODO is this correct implementation? (this is two's complement signed representation so do we care?) - // Intentional falltrough case ALU_OP_SLT: + // Note: this is in two's complement so there is difference in unsigned and signed compare + return ((std::int32_t)s < (std::int32_t)t) ? 1 : 0; + case ALU_OP_SLTU: return (s < t) ? 1 : 0; default: throw QTMIPS_EXCEPTION(UnsupportedAluOperation, "Unknown ALU operation", QString::number(operation, 16)); diff --git a/qtmips_machine/tests/testalu.cpp b/qtmips_machine/tests/testalu.cpp index 2943906..aad101f 100644 --- a/qtmips_machine/tests/testalu.cpp +++ b/qtmips_machine/tests/testalu.cpp @@ -50,7 +50,16 @@ void MachineTests::alu_data() { << (std::uint32_t)0x603 \ << (std::uint8_t)0 \ << (std::uint32_t)0xFFFFF17C; - // TODO SLT-SLTU + QTest::newRow("SLT") << ALU_OP_SLT \ + << (std::uint32_t)-31 \ + << (std::uint32_t)24 \ + << (std::uint8_t)0 \ + << (std::uint32_t)1; + QTest::newRow("SLTU") << ALU_OP_SLTU \ + << (std::uint32_t)24 \ + << (std::uint32_t)32 \ + << (std::uint8_t)0 \ + << (std::uint32_t)1; } void MachineTests::alu() { |