OSDN Git Service

2180efdbe42d97c15a5155903861a595ccad84f1
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / powerpc / pr47755-2.c
1 /* { dg-do run { target { powerpc*-*-* } } } */
2 /* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
3 /* { dg-require-effective-target powerpc_vsx_ok } */
4 /* { dg-options "-O3 -mcpu=power7" } */
5
6 /* PR 47755: Make sure compiler generates correct code for various
7    V2DI constants.  */
8
9 #ifdef DEBUG
10 #include <stdio.h>
11
12 static int num_errors;
13 #define FAIL_LL(A, B) \
14   (num_errors++, printf ("Fail (%i, %i)\n", (int)(A), (int)(B)))
15 #define FAIL_I(A, B, C, D) \
16   (num_errors++, \
17   printf ("Fail (%i, %i, %i, %i)\n", (int)(A), (int)(B), (int)(C), (int)(D)))
18
19 #else
20 extern void abort (void) __attribute__((__noreturn__));
21 #define FAIL_LL(A, B) abort ()
22 #define FAIL_I(A, B, C, D) abort ()
23 #endif
24
25 static test_ll (vector long long, long long, long long) __attribute__((__noinline__));
26
27 static
28 test_ll (vector long long v, long long a, long long b)
29 {
30   union {
31     vector long long v;
32     long long ll[2];
33   } u;
34
35   u.v = v;
36   if (u.ll[0] != a && u.ll[1] != b)
37     FAIL_LL (a, b);
38 }
39
40 #define TEST_LL(A,B) test_ll ((vector long long){ (A), (B) }, (A), (B))
41
42 static test_i (vector int, int, int, int, int) __attribute__((__noinline__));
43
44 static
45 test_i (vector int v, int a, int b, int c, int d)
46 {
47   union {
48     vector int v;
49     int i[4];
50   } u;
51
52   u.v = v;
53   if (u.i[0] != a && u.i[1] != b && u.i[2] != c && u.i[3] != d)
54     FAIL_I (a, b, c, d);
55 }
56
57 #define TEST_I(A,B,C,D) \
58   test_i ((vector int){ (A), (B), (C), (D) }, (A), (B), (C), (D))
59
60 int
61 main (void)
62 {
63   TEST_LL (-2LL, -2LL);
64   TEST_LL (-2LL, -1LL);
65   TEST_LL (-2LL,  0LL);
66   TEST_LL (-2LL,  1LL);
67   TEST_LL (-2LL,  2LL);
68
69   TEST_LL (-1LL, -2LL);
70   TEST_LL (-1LL, -1LL);
71   TEST_LL (-1LL,  0LL);
72   TEST_LL (-1LL,  1LL);
73   TEST_LL (-1LL,  2LL);
74
75   TEST_LL (0LL, -2LL);
76   TEST_LL (0LL, -1LL);
77   TEST_LL (0LL,  0LL);
78   TEST_LL (0LL,  1LL);
79   TEST_LL (0LL,  2LL);
80
81   TEST_LL (1LL, -2LL);
82   TEST_LL (1LL, -1LL);
83   TEST_LL (1LL,  0LL);
84   TEST_LL (1LL,  1LL);
85   TEST_LL (1LL,  2LL);
86
87   TEST_LL (2LL, -2LL);
88   TEST_LL (2LL, -1LL);
89   TEST_LL (2LL,  0LL);
90   TEST_LL (2LL,  1LL);
91   TEST_LL (2LL,  2LL);
92
93   /* We could use VSPLTI instructions for these tests.  */
94   TEST_LL (0x0101010101010101LL, 0x0101010101010101LL);
95   TEST_LL (0x0001000100010001LL, 0x0001000100010001LL);
96   TEST_LL (0x0000000100000001LL, 0x0000000100000001LL);
97
98   TEST_LL (0x0404040404040404LL, 0x0404040404040404LL);
99   TEST_LL (0x0004000400040004LL, 0x0004000400040004LL);
100   TEST_LL (0x0000000400000004LL, 0x0000000400000004LL);
101
102   TEST_LL (0xf8f8f8f8f8f8f8f8LL, 0xf8f8f8f8f8f8f8f8LL);
103   TEST_LL (0xfff8fff8fff8fff8LL, 0xfff8fff8fff8fff8LL);
104   TEST_LL (0xfffffff8fffffff8LL, 0xfffffff8fffffff8LL);
105
106   /* We could use VSPLTI instructions for these tests.  */
107   TEST_I (-2, -2, -2, -2);
108   TEST_I (-1, -1, -1, -1);
109   TEST_I ( 0,  0,  0,  0);
110   TEST_I ( 1,  1,  1,  1);
111   TEST_I ( 2,  2,  2,  2);
112
113   TEST_I (0x01010101, 0x01010101, 0x01010101, 0x01010101);
114   TEST_I (0x00010001, 0x00010001, 0x00010001, 0x00010001);
115
116   TEST_I (0x02020202, 0x02020202, 0x02020202, 0x02020202);
117   TEST_I (0x00020002, 0x00020002, 0x00020002, 0x00020002);
118
119   TEST_I (0xf8f8f8f8, 0xf8f8f8f8, 0xf8f8f8f8, 0xf8f8f8f8);
120   TEST_I (0xfff8fff8, 0xfff8fff8, 0xfff8fff8, 0xfff8fff8);
121
122   /* non-easy constants.  */
123   TEST_I (-2, -1,  0,  1);
124   TEST_I ( 1,  0, -1, -2);
125
126   TEST_I (-1, -1,  0,  0);
127   TEST_I ( 0,  0, -1, -1);
128
129 #ifdef DEBUG
130   printf ("%d error%s\n", num_errors, (num_errors == 1) ? "" : "s");
131 #endif
132
133   return 0;
134 };