OSDN Git Service

2005-05-24 Jonathan Wakely <redi@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / vect / vect-none.c
1 /* { dg-do compile } */
2 /* { dg-require-effective-target vect_int } */
3 /* { dg-require-effective-target vect_float } */
4
5 #define N 16
6
7 extern void abort (void);
8
9 int iadd_results[N] = {0,6,12,18,24,30,36,42,48,54,60,66,72,78,84,90};
10 float fadd_results[N] = {0.0,6.0,12.0,18.0,24.0,30.0,36.0,42.0,48.0,54.0,60.0,66.0,72.0,78.0,84.0,90.0};
11 float fmul_results[N] = {0.0,3.0,12.0,27.0,48.0,75.0,108.0,147.0,192.0,243.0,300.0,363.0,432.0,507.0,588.0,675.0};
12 float fresults1[N] = {192.00,240.00,288.00,336.00,384.00,432.00,480.00,528.00,48.00,54.00,60.00,66.00,72.00,78.00,84.00,90.00};
13 float fresults2[N] = {0.00,6.00,12.00,18.00,24.00,30.00,36.00,42.00,0.00,54.00,120.00,198.00,288.00,390.00,504.00,630.00};
14
15 /****************************************************/
16 void icheck_results (int *a, int *results)
17 {
18   int i;
19   for (i = 0; i < N; i++)
20     {
21       if (a[i] != results[i])
22         abort ();
23     }
24 }
25
26 void fcheck_results (float *a, float *results)
27 {
28   int i;
29   for (i = 0; i < N; i++)
30     {
31       if (a[i] != results[i])
32         abort ();
33     }
34 }   
35
36 void 
37 fbar_mul (float *a)
38 {
39   fcheck_results (a, fmul_results);
40
41
42 void 
43 fbar_add (float *a)
44 {
45   fcheck_results (a, fadd_results);
46
47
48 void 
49 ibar_add (int *a)
50 {
51   icheck_results (a, iadd_results);
52
53
54 void 
55 fbar1 (float *a)
56 {
57   fcheck_results (a, fresults1);
58
59
60 void 
61 fbar2 (float *a)
62 {
63   fcheck_results (a, fresults2);
64
65
66
67 /* None of the loops below is currently vectorizable. The vectorizer will
68    be enhanced to vectorize most of these loops.  */
69
70 int
71 foo (int n)
72 {
73   int i,j;
74   float a[N];
75   float e[N];
76   float b[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
77   float c[N] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
78   float d[N] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30};
79   short sc[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
80   short sb[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
81   short sa[N];
82   int ic[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
83   int ib[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
84   int ia[N];
85   int diff = 0;
86   char cb[N];
87   char cc[N];
88   char image[N][N];
89   char block[N][N];
90
91
92   /* Test 1 - type cast.  */
93   for (i = 0; i < N; i++)
94     {
95       ia[i] = (int) sb[i];
96     }
97   fbar (a);
98
99
100   /* Test 2 - strided access pattern.  */
101   for (i = 0; i < N/2; i++)
102     {
103       a[i] = b[2*i+1] * c[2*i+1] - b[2*i] * c[2*i];
104       d[i] = b[2*i] * c[2*i+1] + b[2*i+1] * c[2*i];
105     }
106   fbar (a);
107
108
109   /* Test 3 - no target support for integer mult.  */
110   /* This loop is vectorized on platforms that support vect_int_mult.  */
111   for (i = 0; i < N; i++)
112     {
113       ia[i] = ib[i] * ic[i];
114     }
115   ibar (ia);
116
117
118   /* Test 4 - two types with different nunits in vector.  */
119   for (i = 0; i < N; i++)
120     {
121       ia[i] = ib[i] + ic[i];
122       sa[i] = sb[i] + sc[i];
123     }
124   ibar (ia);
125   sbar (sa);
126
127
128   /* Test 5 - too conservative dependence test.  */
129   for (i = 0; i < N; i++){
130     a[i] = b[i] + c[i];
131     a[i+1] = b[i] + c[i];
132   }
133   fbar (a);
134
135
136   /* Test 6 - condition in loop.  */
137   /* This loop is vectorized on platformst that support vect_condition.  */
138   for (i = 0; i < N; i++){
139     a[i] = (b[i] > 0 ? b[i] : 0);
140   }
141   fbar (a);
142
143
144   /* Test 7 - cross-iteration cycle.  */
145   diff = 0;
146   for (i = 0; i < N; i++) {
147     diff += (cb[i] - cc[i]);
148   }
149   ibar (&diff);
150
151
152   /* Test 8 - outer-loop not attempted; inner-loop has cross 
153      iteration cycle and multi-dimensional arrays.  */
154   diff = 0;
155   for (i = 0; i < N; i++) {
156     for (i = 0; i < N; i++) {
157       diff += (image[i][j] - block[i][j]);
158     }
159   }
160   ibar (&diff);
161
162
163   /* Test 9 - induction.  */
164   for ( i = 0; i < N; i++) {
165     a[i] = i;
166   }
167   fbar (a);
168
169
170   /* Test 10 - reverse access and forward access.  */
171   for (i = N; i > 0; i--)
172     {
173       a[N-i] = b[i-1];
174     }
175   /* check results:  */
176   for (i = 0; i <N; i++)
177     {
178       if (a[i] != b[N-1-i])
179         abort ();
180     }
181
182   return 0;
183 }
184
185 /* { dg-final { scan-tree-dump-times "vectorized " 3 "vect"} } */
186 /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 3 "vect" { xfail powerpc*-*-* i?86-*-* x86_64-*-* } } } */
187 /* { dg-final { scan-tree-dump-times "vectorized 2 loops" 1 "vect" { target powerpc*-*-* } } } */
188 /* { dg-final { scan-tree-dump-times "vectorized 0 loops" 2 "vect" { target powerpc*-*-* } } } */
189 /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { target i?86-*-* x86_64-*-* ia64-*-* } } } */
190 /* { dg-final { scan-tree-dump-times "vectorized 0 loops" 2 "vect" { target i?86-*-* x86_64-*-* ia64-*-* } } } */
191 /* { dg-final { cleanup-tree-dump "vect" } } */