From 8ebaea458322a2df925cf351bf6b4f300567150d Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sun, 12 May 2024 15:29:16 +0200 Subject: Multiplication --- emulator/hart_test.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'emulator/hart_test.c') 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 #include #include +#include #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; } -- cgit