Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / mips / user / isa / r5900 / test_r5900_maddu.c
blob30936fb2b4a2a07e012e1eb8412cd76ab1b86529
1 /*
2 * Test R5900-specific three-operand MADDU and MADDU1.
3 */
5 #include <stdio.h>
6 #include <inttypes.h>
7 #include <assert.h>
9 uint64_t maddu(uint64_t a, uint32_t rs, uint32_t rt)
11 uint32_t lo = a;
12 uint32_t hi = a >> 32;
13 uint32_t rd;
14 uint64_t r;
16 __asm__ __volatile__ (
17 " mtlo %5\n"
18 " mthi %6\n"
19 " maddu %0, %3, %4\n"
20 " mflo %1\n"
21 " mfhi %2\n"
22 : "=r" (rd), "=r" (lo), "=r" (hi)
23 : "r" (rs), "r" (rt), "r" (lo), "r" (hi));
24 r = ((uint64_t)hi << 32) | (uint32_t)lo;
26 assert(a + (uint64_t)rs * rt == r);
27 assert(rd == lo);
29 return r;
32 uint64_t maddu1(uint64_t a, uint32_t rs, uint32_t rt)
34 uint32_t lo = a;
35 uint32_t hi = a >> 32;
36 uint32_t rd;
37 uint64_t r;
39 __asm__ __volatile__ (
40 " mtlo1 %5\n"
41 " mthi1 %6\n"
42 " maddu1 %0, %3, %4\n"
43 " mflo1 %1\n"
44 " mfhi1 %2\n"
45 : "=r" (rd), "=r" (lo), "=r" (hi)
46 : "r" (rs), "r" (rt), "r" (lo), "r" (hi));
47 r = ((uint64_t)hi << 32) | (uint32_t)lo;
49 assert(a + (uint64_t)rs * rt == r);
50 assert(rd == lo);
52 return r;
55 static int64_t maddu_variants(int64_t a, int32_t rs, int32_t rt)
57 int64_t rd = maddu(a, rs, rt);
58 int64_t rd1 = maddu1(a, rs, rt);
60 assert(rd == rd1);
62 return rd;
65 int main()
67 assert(maddu_variants(13, 17, 19) == 336);
69 return 0;