Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / mips / user / isa / r5900 / test_r5900_mult.c
blob5710b395e66499d63af4b06999b55a8541da1ec2
1 /*
2 * Test R5900-specific three-operand MULT and MULT1.
3 */
5 #include <stdio.h>
6 #include <inttypes.h>
7 #include <assert.h>
9 static int64_t mult(int32_t rs, int32_t rt)
11 int32_t rd, lo, hi;
12 int64_t r;
14 __asm__ __volatile__ (
15 " mult %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 = ((int64_t)hi << 32) | (uint32_t)lo;
22 assert((int64_t)rs * rt == r);
23 assert(rd == lo);
25 return r;
28 static int64_t mult1(int32_t rs, int32_t rt)
30 int32_t rd, lo, hi;
31 int64_t r;
33 __asm__ __volatile__ (
34 " mult1 %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 = ((int64_t)hi << 32) | (uint32_t)lo;
41 assert((int64_t)rs * rt == r);
42 assert(rd == lo);
44 return r;
47 static int64_t mult_variants(int32_t rs, int32_t rt)
49 int64_t rd = mult(rs, rt);
50 int64_t rd1 = mult1(rs, rt);
52 assert(rd == rd1);
54 return rd;
57 static void verify_mult_negations(int32_t rs, int32_t rt, int64_t expected)
59 assert(mult_variants(rs, rt) == expected);
60 assert(mult_variants(-rs, rt) == -expected);
61 assert(mult_variants(rs, -rt) == -expected);
62 assert(mult_variants(-rs, -rt) == expected);
65 int main()
67 verify_mult_negations(17, 19, 323);
68 verify_mult_negations(77773, 99991, 7776600043);
69 verify_mult_negations(12207031, 305175781, 3725290219116211);
71 assert(mult_variants(-0x80000000, 0x7FFFFFFF) == -0x3FFFFFFF80000000);
72 assert(mult_variants(-0x80000000, -0x7FFFFFFF) == 0x3FFFFFFF80000000);
73 assert(mult_variants(-0x80000000, -0x80000000) == 0x4000000000000000);
75 return 0;