Record edge true/false value for gcov
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-all.c
blob6fd579fa6ad24623f387d9ebf5c863ca6e91dfe6
1 /* { dg-require-effective-target vect_int } */
2 /* { dg-require-effective-target vect_float } */
3 /* { dg-add-options bind_pic_locally } */
5 #include <stdarg.h>
6 #include "tree-vect.h"
8 #define N 16
10 int iadd_results[N] = {0,6,12,18,24,30,36,42,48,54,60,66,72,78,84,90};
11 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};
12 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};
13 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};
14 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};
16 /****************************************************/
17 __attribute__ ((noinline))
18 void icheck_results (int *a, int *results)
20 int i;
21 #pragma GCC novector
22 for (i = 0; i < N; i++)
24 if (a[i] != results[i])
25 abort ();
29 __attribute__ ((noinline))
30 void fcheck_results (float *a, float *results)
32 int i;
33 #pragma GCC novector
34 for (i = 0; i < N; i++)
36 if (a[i] != results[i])
37 abort ();
41 __attribute__ ((noinline)) void
42 fbar_mul (float *a)
44 fcheck_results (a, fmul_results);
47 __attribute__ ((noinline)) void
48 fbar_add (float *a)
50 fcheck_results (a, fadd_results);
53 __attribute__ ((noinline)) void
54 ibar_add (int *a)
56 icheck_results (a, iadd_results);
59 __attribute__ ((noinline)) void
60 fbar1 (float *a)
62 fcheck_results (a, fresults1);
65 __attribute__ ((noinline)) void
66 fbar2 (float *a)
68 fcheck_results (a, fresults2);
71 float a[N];
72 float e[N];
73 float b[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
74 float c[N] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
75 float d[N] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30};
76 int ic[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
77 int ib[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
78 int ia[N];
79 char cb[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
80 char ca[N];
81 short sa[N];
83 /* All of the loops below are currently vectorizable. */
85 __attribute__ ((noinline)) int
86 main1 ()
88 int i,j;
90 /* Test 1: copy chars. */
91 for (i = 0; i < N; i++)
93 ca[i] = cb[i];
95 /* check results: */
96 #pragma GCC novector
97 for (i = 0; i < N; i++)
99 if (ca[i] != cb[i])
100 abort ();
104 /* Test 2: fp mult. */
105 for (i = 0; i < N; i++)
107 a[i] = b[i] * c[i];
109 fbar_mul (a);
112 /* Test 3: mixed types (int, fp), same nunits in vector. */
113 for (i = 0; i < N; i++)
115 a[i] = b[i] + c[i] + d[i];
116 e[i] = b[i] + c[i] + d[i];
117 ia[i] = ib[i] + ic[i];
119 ibar_add (ia);
120 fbar_add (a);
121 fbar_add (e);
124 /* Test 4: access with offset. */
125 for (i = 0; i < N/2; i++)
127 a[i] = b[i+N/2] * c[i+N/2] - b[i] * c[i];
128 e[i+N/2] = b[i] * c[i+N/2] + b[i+N/2] * c[i];
130 fbar1 (a);
131 fbar2 (e);
134 /* Test 5: access with offset */
135 for (i = 1; i <=N-4; i++)
137 a[i+3] = b[i-1];
139 /* check results: */
140 #pragma GCC novector
141 for (i = 1; i <=N-4; i++)
143 if (a[i+3] != b[i-1])
144 abort ();
148 /* Test 6 - loop induction with stride != 1. */
149 i = 0;
150 j = 0;
151 while (i < 5*N)
153 a[j] = c[j];
154 i += 5;
155 j++;
157 /* check results: */
158 #pragma GCC novector
159 for (i = 0; i <N; i++)
161 if (a[i] != c[i])
162 abort ();
166 /* Test 7 - reverse access. */
167 for (i = N; i > 0; i--)
169 a[N-i] = d[N-i];
171 /* check results: */
172 #pragma GCC novector
173 for (i = 0; i <N; i++)
175 if (a[i] != d[i])
176 abort ();
180 /* Tests 8,9,10 - constants. */
181 for (i = 0; i < N; i++)
183 a[i] = 5.0;
185 /* check results: */
186 #pragma GCC novector
187 for (i = 0; i < N; i++)
189 if (a[i] != 5.0)
190 abort ();
193 for (i = 0; i < N; i++)
195 sa[i] = 5;
197 /* check results: */
198 #pragma GCC novector
199 for (i = 0; i < N; i++)
201 if (sa[i] != 5)
202 abort ();
205 for (i = 0; i < N; i++)
207 ia[i] = ib[i] + 5;
209 /* check results: */
210 #pragma GCC novector
211 for (i = 0; i < N; i++)
213 if (ia[i] != ib[i] + 5)
214 abort ();
217 return 0;
220 int main (void)
222 check_vect ();
224 return main1 ();
227 /* { dg-final { scan-tree-dump-times "vectorized 10 loops" 1 "vect" } } */
228 /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 0 "vect" { target { { vect_aligned_arrays } && {! vect_sizes_32B_16B} } } } } */
229 /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 1 "vect" { target { {! vect_aligned_arrays } && {vect_sizes_32B_16B} } } } } */
230 /* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 0 "vect" } } */