summaryrefslogtreecommitdiff
path: root/emulator/hart_test.c
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-05-12 15:29:16 +0200
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-05-12 15:29:16 +0200
commit8ebaea458322a2df925cf351bf6b4f300567150d (patch)
tree83f292e2ab7b3f8cab49d0e0bad2e27ac96f4eee /emulator/hart_test.c
parent822fd8616cf3d960cb2df1d2f25452ef57ea854b (diff)
Multiplication
Diffstat (limited to 'emulator/hart_test.c')
-rw-r--r--emulator/hart_test.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/emulator/hart_test.c b/emulator/hart_test.c
index 5f2549b..1611804 100644
--- a/emulator/hart_test.c
+++ b/emulator/hart_test.c
@@ -2,6 +2,7 @@
#include <inttypes.h>
#include <assert.h>
#include <stdbool.h>
+#include <stdio.h>
#include "emulator/hart.h"
@@ -229,7 +230,42 @@ static void test_branch()
assert(hart.pc == 124);
}
-void test()
+static void test_m()
+{
+ struct Hart hart = {0};
+
+ hart.regs[1] = 0xFFFFFFFE;
+ hart.regs[2] = 4;
+
+ execute(&hart, 0x022081b3); // mul x3, x1, x2
+ assert(hart.regs[3] == 0xFFFFFFF8);
+
+ execute(&hart, 0x0220b1b3); // mulhu x3, x1, x2
+ assert(hart.regs[3] == 0x00000003);
+
+ execute(&hart, 0x0220a1b3); // mulhsu x3, x1, x2
+ assert(hart.regs[3] == 0xFFFFFFFF);
+
+ execute(&hart, 0x022091b3); // mulh x3, x1, x2
+ assert(hart.regs[3] == 0xFFFFFFFF);
+
+ hart.regs[1] = 0xFFFFFFFE;
+ hart.regs[2] = 0xFFFFFFFE;
+
+ execute(&hart, 0x022081b3); // mul x3, x1, x2
+ assert(hart.regs[3] == 0x00000004);
+
+ execute(&hart, 0x0220b1b3); // mulhu x3, x1, x2
+ assert(hart.regs[3] == 0xFFFFFFFC);
+
+ execute(&hart, 0x0220a1b3); // mulhsu x3, x1, x2
+ assert(hart.regs[3] == 0xFFFFFFFE);
+
+ execute(&hart, 0x022091b3); // mulh x3, x1, x2
+ assert(hart.regs[3] == 0x00000000);
+}
+
+int main(int argc, char* argv[])
{
test_addi();
test_slti_sltiu();
@@ -240,10 +276,6 @@ void test()
test_jal();
test_jalr();
test_branch();
-}
-
-int main(int argc, char* argv[])
-{
- test();
+ test_m();
return EXIT_SUCCESS;
}