Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / riscv64 / test-div.c
bloba90480be3f070a847c20b4ed110c632c5d25732b
1 #include <assert.h>
2 #include <limits.h>
4 struct TestS {
5 long x, y, q, r;
6 };
8 static struct TestS test_s[] = {
9 { 4, 2, 2, 0 }, /* normal cases */
10 { 9, 7, 1, 2 },
11 { 0, 0, -1, 0 }, /* div by zero cases */
12 { 9, 0, -1, 9 },
13 { LONG_MIN, -1, LONG_MIN, 0 }, /* overflow case */
16 struct TestU {
17 unsigned long x, y, q, r;
20 static struct TestU test_u[] = {
21 { 4, 2, 2, 0 }, /* normal cases */
22 { 9, 7, 1, 2 },
23 { 0, 0, ULONG_MAX, 0 }, /* div by zero cases */
24 { 9, 0, ULONG_MAX, 9 },
27 #define ARRAY_SIZE(X) (sizeof(X) / sizeof(*(X)))
29 int main (void)
31 int i;
33 for (i = 0; i < ARRAY_SIZE(test_s); i++) {
34 long q, r;
36 asm("div %0, %2, %3\n\t"
37 "rem %1, %2, %3"
38 : "=&r" (q), "=r" (r)
39 : "r" (test_s[i].x), "r" (test_s[i].y));
41 assert(q == test_s[i].q);
42 assert(r == test_s[i].r);
45 for (i = 0; i < ARRAY_SIZE(test_u); i++) {
46 unsigned long q, r;
48 asm("divu %0, %2, %3\n\t"
49 "remu %1, %2, %3"
50 : "=&r" (q), "=r" (r)
51 : "r" (test_u[i].x), "r" (test_u[i].y));
53 assert(q == test_u[i].q);
54 assert(r == test_u[i].r);
57 return 0;