aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-11-25 15:22:32 +0100
committerKarel Kočí <cynerd@email.cz>2017-11-25 15:22:32 +0100
commitafa9e930255b3c380ad37fccc0767508534bad13 (patch)
treeddb0c15f684f473067c9b0146f5fe55a4f7f7af4 /qtmips_machine
parentfcb67b16d13de62092e3720d08adb0ef5e35de3d (diff)
downloadqtmips-afa9e930255b3c380ad37fccc0767508534bad13.tar.gz
qtmips-afa9e930255b3c380ad37fccc0767508534bad13.tar.bz2
qtmips-afa9e930255b3c380ad37fccc0767508534bad13.zip
Fix SLTU instruction
Diffstat (limited to 'qtmips_machine')
-rw-r--r--qtmips_machine/alu.cpp6
-rw-r--r--qtmips_machine/tests/testalu.cpp11
2 files changed, 13 insertions, 4 deletions
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() {