Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / mips / user / isa / r5900 / test_r5900_divu1.c
blob72aeed31debf9bc187e621a62366820d84725767
1 /*
2 * Test R5900-specific DIVU1.
3 */
5 #include <stdio.h>
6 #include <inttypes.h>
7 #include <assert.h>
9 struct quotient_remainder { uint32_t quotient, remainder; };
11 static struct quotient_remainder divu1(uint32_t rs, uint32_t rt)
13 uint32_t lo, hi;
15 __asm__ __volatile__ (
16 " divu1 $0, %2, %3\n"
17 " mflo1 %0\n"
18 " mfhi1 %1\n"
19 : "=r" (lo), "=r" (hi)
20 : "r" (rs), "r" (rt));
22 assert(rs / rt == lo);
23 assert(rs % rt == hi);
25 return (struct quotient_remainder) { .quotient = lo, .remainder = hi };
28 static void verify_divu1(uint32_t rs, uint32_t rt,
29 uint32_t expected_quotient,
30 uint32_t expected_remainder)
32 struct quotient_remainder qr = divu1(rs, rt);
34 assert(qr.quotient == expected_quotient);
35 assert(qr.remainder == expected_remainder);
38 int main()
40 verify_divu1(0, 1, 0, 0);
41 verify_divu1(1, 1, 1, 0);
42 verify_divu1(1, 2, 0, 1);
43 verify_divu1(17, 19, 0, 17);
44 verify_divu1(19, 17, 1, 2);
45 verify_divu1(77773, 101, 770, 3);
47 return 0;