Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / mips / user / isa / r5900 / test_r5900_multu.c
blobf043904d699d0bd8dc6c0ceb1ea0186f70597ac7
1 /*
2 * Test R5900-specific three-operand MULTU and MULTU1.
3 */
5 #include <stdio.h>
6 #include <inttypes.h>
7 #include <assert.h>
9 static uint64_t multu(uint32_t rs, uint32_t rt)
11 uint32_t rd, lo, hi;
12 uint64_t r;
14 __asm__ __volatile__ (
15 " multu %0, %3, %4\n"
16 " mflo %1\n"
17 " mfhi %2\n"
18 : "=r" (rd), "=r" (lo), "=r" (hi)
19 : "r" (rs), "r" (rt));
20 r = ((uint64_t)hi << 32) | (uint32_t)lo;
22 assert((uint64_t)rs * rt == r);
23 assert(rd == lo);
25 return r;
28 static uint64_t multu1(uint32_t rs, uint32_t rt)
30 uint32_t rd, lo, hi;
31 uint64_t r;
33 __asm__ __volatile__ (
34 " multu1 %0, %3, %4\n"
35 " mflo1 %1\n"
36 " mfhi1 %2\n"
37 : "=r" (rd), "=r" (lo), "=r" (hi)
38 : "r" (rs), "r" (rt));
39 r = ((uint64_t)hi << 32) | (uint32_t)lo;
41 assert((uint64_t)rs * rt == r);
42 assert(rd == lo);
44 return r;
47 static uint64_t multu_variants(uint32_t rs, uint32_t rt)
49 uint64_t rd = multu(rs, rt);
50 uint64_t rd1 = multu1(rs, rt);
52 assert(rd == rd1);
54 return rd;
57 int main()
59 assert(multu_variants(17, 19) == 323);
60 assert(multu_variants(77773, 99991) == 7776600043);
61 assert(multu_variants(12207031, 305175781) == 3725290219116211);
63 assert(multu_variants(0x80000000U, 0x7FFFFFFF) == 0x3FFFFFFF80000000);
64 assert(multu_variants(0x80000000U, 0x80000000U) == 0x4000000000000000);
65 assert(multu_variants(0xFFFFFFFFU, 0xFFFFFFFFU) == 0xFFFFFFFE00000001U);
67 return 0;