OSDN Git Service

PR testsuite/21010
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / torture / mips-hilo-1.c
1 /* f1 checks that an mtlo is not moved before an mfhi.  f2 does the same
2    for an mthi and an mflo.  */
3 /* { dg-do run { target mips*-*-* } } */
4 /* { dg-options "-mtune=rm7000" } */
5
6 extern void abort (void);
7 extern void exit (int);
8
9 #if !defined(__mips16)
10
11 #define DECLARE(TYPE)                                                   \
12   TYPE __attribute__ ((noinline))                                       \
13   f1##TYPE (TYPE x1, TYPE x2, TYPE x3)                                  \
14   {                                                                     \
15     TYPE t1, t2;                                                        \
16                                                                         \
17     asm ("mult\t%1,%2" : "=h" (t1) : "d" (x1), "d" (x2) : "lo");        \
18     asm ("mflo\t%0" : "=r" (t2) : "l" (x3) : "hi");                     \
19     return t1 + t2;                                                     \
20   }                                                                     \
21                                                                         \
22   TYPE __attribute__ ((noinline))                                       \
23   f2##TYPE (TYPE x1, TYPE x2, TYPE x3)                                  \
24   {                                                                     \
25     TYPE t1, t2;                                                        \
26                                                                         \
27     asm ("mult\t%1,%2" : "=l" (t1) : "d" (x1), "d" (x2) : "hi");        \
28     asm ("mfhi\t%0" : "=r" (t2) : "h" (x3) : "lo");                     \
29     return t1 + t2;                                                     \
30   }
31
32 #define TEST(TYPE)                                                      \
33   if (f1##TYPE (1, 2, 10) != 10)                                        \
34     abort ();                                                           \
35   if (f2##TYPE (1, 2, 40) != 42)                                        \
36     abort ()
37
38 typedef char c;
39 typedef signed char sc;
40 typedef unsigned char uc;
41 typedef short s;
42 typedef unsigned short us;
43 typedef int i;
44 typedef unsigned int ui;
45 typedef long long ll;
46 typedef unsigned long long ull;
47
48 DECLARE (c)
49 DECLARE (sc)
50 DECLARE (uc)
51 DECLARE (s)
52 DECLARE (us)
53 DECLARE (i)
54 DECLARE (ui)
55 #if defined (__mips64)
56 DECLARE (ll)
57 DECLARE (ull)
58 #endif
59
60 int
61 main ()
62 {
63   TEST (c);
64   TEST (sc);
65   TEST (uc);
66   TEST (s);
67   TEST (us);
68   TEST (i);
69   TEST (ui);
70 #if defined (__mips64)
71   TEST (ll);
72   TEST (ull);
73 #endif
74   exit (0);
75 }
76 #else
77 int main () { exit (0); }
78 #endif