Multiplication
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user