]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/g++.dg/cilk-plus/CK/for1.cc
[Patch AArch64] Fixup floating point division with -march=armv8-a+nosimd
[thirdparty/gcc.git] / gcc / testsuite / g++.dg / cilk-plus / CK / for1.cc
1 /* { dg-do run } */
2 /* { dg-require-effective-target cilkplus_runtime } */
3 /* { dg-options "-fcilkplus" } */
4
5 #if HAVE_IO
6 #include <cstdio>
7 #endif
8
9 typedef __PTRDIFF_TYPE__ ptrdiff_t;
10 extern "C" void abort ();
11
12 template <typename T>
13 class I
14 {
15 public:
16 typedef ptrdiff_t difference_type;
17 I ();
18 ~I ();
19 I (T *);
20 I (const I &);
21 T &operator * ();
22 T *operator -> ();
23 T &operator [] (const difference_type &) const;
24 I &operator = (const I &);
25 I &operator ++ ();
26 I operator ++ (int);
27 I &operator -- ();
28 I operator -- (int);
29 I &operator += (const difference_type &);
30 I &operator -= (const difference_type &);
31 I operator + (const difference_type &) const;
32 I operator - (const difference_type &) const;
33 template <typename S> friend bool operator == (I<S> &, I<S> &);
34 template <typename S> friend bool operator == (const I<S> &, const I<S> &);
35 template <typename S> friend bool operator < (I<S> &, I<S> &);
36 template <typename S> friend bool operator < (const I<S> &, const I<S> &);
37 template <typename S> friend bool operator <= (I<S> &, I<S> &);
38 template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
39 template <typename S> friend bool operator > (I<S> &, I<S> &);
40 template <typename S> friend bool operator > (const I<S> &, const I<S> &);
41 template <typename S> friend bool operator >= (I<S> &, I<S> &);
42 template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
43 template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
44 template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
45 template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
46 private:
47 T *p;
48 };
49 template <typename T> I<T>::I () : p (0) {}
50 template <typename T> I<T>::~I () {}
51 template <typename T> I<T>::I (T *x) : p (x) {}
52 template <typename T> I<T>::I (const I &x) : p (x.p) {}
53 template <typename T> T &I<T>::operator * () { return *p; }
54 template <typename T> T *I<T>::operator -> () { return p; }
55 template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
56 template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
57 template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
58 template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
59 template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
60 template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
61 template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
62 template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
63 template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
64 template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
65 template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
66 template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
67 template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
68 template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
69 template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
70 template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
71 template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
72 template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
73 template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
74 template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
75 template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
76 template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
77 template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
78 template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
79 template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
80
81 template <typename T>
82 class J
83 {
84 public:
85 J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
86 const I<T> &begin ();
87 const I<T> &end ();
88 private:
89 I<T> b, e;
90 };
91
92 template <typename T> const I<T> &J<T>::begin () { return b; }
93 template <typename T> const I<T> &J<T>::end () { return e; }
94
95 int results[2000];
96
97 template <typename T>
98 void
99 baz (I<T> &i)
100 {
101 if (*i < 0 || *i >= 2000)
102 {
103 #if HAVE_IO
104 printf ("*i(%d) is < 0 or >= 2000\n", *i);
105 fflush (stdout);
106 #endif
107 __builtin_abort ();
108 }
109 else
110 results[*i]++;
111 }
112
113 void
114 f1 (const I<int> &x, const I<int> &y)
115 {
116 _Cilk_for (I<int> i = x; i <= y; i += 6)
117 {
118 baz (i);
119 }
120
121 #if HAVE_IO
122 printf("===== Starting F1 =========\n");
123 for (I<int> i = x; i <= y; i+= 6) {
124 printf("Result[%4d] = %2d\n", *i, results[*i]);
125 fflush (stdout);
126 }
127 #endif
128 }
129
130 void
131 f2 (const I<int> &x, const I<int> &y)
132 {
133 _Cilk_for (I<int> i = x; i < y - 1; i += 2)
134 baz (i);
135
136 #if HAVE_IO
137 printf("===== Starting F2 =========\n");
138 for (int ii = 0; ii < 1998; ii += 2) {
139 printf("Result[%4d] = %2d\n", ii, results[ii]);
140 fflush (stdout);
141 }
142 #endif
143 }
144
145 template <typename T>
146 void
147 f3 (const I<int> &x, const I<int> &y)
148 {
149 _Cilk_for (I<int> i = x; i <= y; i += 1)
150 baz (i);
151 #if HAVE_IO
152 printf("===== Starting F3 =========\n");
153 for (int ii = 20; ii < 1987; ii += 1) {
154 printf("Result[%4d] = %2d\n", ii, results[ii]);
155 fflush (stdout);
156 }
157
158 #endif
159 }
160
161 template <typename T>
162 void
163 f4 (const I<int> &x, const I<int> &y)
164 {
165 _Cilk_for (I<int> i = x + (2000 - 64); i > y + 10; --i)
166 baz (i);
167 #if HAVE_IO
168 printf("===== Starting F3 =========\n");
169 for (I<int> i = x + (2000 - 64); i > y + 10; --i) {
170 printf("Result[%4d] = %2d\n", *i, results[*i]);
171 fflush (stdout);
172 }
173 #endif
174 }
175 void
176 f5 (const I<int> &x, const I<int> &y)
177 {
178 _Cilk_for (I<int> i = x + 2000 - 64; i > y + 10; i -= 10)
179 baz (i);
180 #if HAVE_IO
181 for (I<int> i = x + 2000 - 64; i > y + 10; i -= 10) {
182 printf("Result[%4d] = %2d\n", *i, results[*i]);
183 fflush (stdout);
184 }
185 #endif
186 }
187
188 template <int N>
189 void
190 f6 (const I<int> &x, const I<int> &y)
191 {
192 _Cilk_for (I<int> i = x + 2000 - 64; i > y + 10; i -= 10)
193 {
194 I<int> j = i + N;
195 baz (j);
196 }
197 #if HAVE_IO
198 for (I<int> i = x + 2000 - 64; i > y + 10; i = i - 12 + 2)
199 {
200 I<int> j = i + N;
201 printf("Result[%4d] = %2d\n", *j, results[*j]);
202 fflush (stdout);
203 }
204 #endif
205 }
206 template <int N>
207 void
208 f7 (I<int> ii, const I<int> &x, const I<int> &y)
209 {
210 _Cilk_for (I <int> i = x - 10; i <= y + 10; i += N)
211 baz (i);
212 #if HAVE_IO
213 for (I<int> i = x - 10; i <= y + 10; i += N)
214 {
215 printf("Result[%4d] = %2d\n", *i, results[*i]);
216 fflush (stdout);
217 }
218 #endif
219 }
220
221 template <int N>
222 void
223 f8 (J<int> j)
224 {
225 _Cilk_for (I<int> i = j.begin (); i <= j.end () + N; i += 2)
226 baz (i);
227 #if HAVE_IO
228 for (I<int> i = j.begin (); i <= j.end () + N; i += 2) {
229 printf("Result[%4d] = %2d\n", *i, results[*i]);
230 fflush (stdout);
231 }
232 #endif
233
234 }
235
236 template <typename T, int N>
237 void
238 f9 (const I<T> &x, const I<T> &y)
239 {
240 _Cilk_for (I<T> i = x; i <= y; i += N)
241 baz (i);
242 #if HAVE_IO
243 for (I<T> i = x; i <= y; i = i + N)
244 {
245 printf("Result[%4d] = %2d\n", *i, results[*i]);
246 fflush (stdout);
247 }
248 #endif
249 }
250
251 template <typename T, int N>
252 void
253 f10 (const I<T> &x, const I<T> &y)
254 {
255 _Cilk_for (I<T> i = x; i > y; i += N)
256 baz (i);
257 #if HAVE_IO
258 for (I<T> i = x; i > y; i = i + N) {
259 printf("Result[%4d] = %2d\n", *i, results[*i]);
260 fflush (stdout);
261 }
262 #endif
263 }
264
265 template <typename T>
266 void
267 f11 (const T &x, const T &y)
268 {
269 _Cilk_for (T i = x; i <= y; i += 3)
270 baz (i);
271
272 #if HAVE_IO
273 for (T i = x; i <= y; i += 3) {
274 printf("Result[%4d] = %2d\n", *i, results[*i]);
275 fflush (stdout);
276 }
277 #endif
278 T j = y + 3;
279 baz (j);
280
281 }
282
283 template <typename T>
284 void
285 f12 (const T &x, const T &y)
286 {
287 _Cilk_for (T i = x; i > y; --i)
288 baz (i);
289 #if HAVE_IO
290 for (T i = x; i > y; --i) {
291 printf("Result[%4d] = %2d\n", *i, results[*i]);
292 fflush (stdout);
293 }
294 #endif
295 }
296 template <int N>
297 struct K
298 {
299 template <typename T>
300 static void
301 f13 (const T &x, const T &y)
302 {
303 _Cilk_for (T i = x; i <= y + N; i += N)
304 baz (i);
305 #if HAVE_IO
306 for (T i = x; i < y+N; i += N) {
307 printf("Result[%4d] = %2d\n", *i, results[*i]);
308 fflush (stdout);
309 }
310 #endif
311 }
312 };
313
314 #define check(expr) \
315 for (int i = 0; i < 2000; i++) \
316 if (expr) \
317 { \
318 if (results[i] != 1) { \
319 __builtin_abort (); \
320 } \
321 results[i] = 0; \
322 } \
323 else if (results[i]) \
324 abort ()
325
326 int
327 main ()
328 {
329 int a[2000];
330 long b[2000];
331 for (int i = 0; i < 2000; i++)
332 {
333 a[i] = i;
334 b[i] = i;
335 }
336 f1 (&a[10], &a[1990]);
337 check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0);
338 f2 (&a[0], &a[1999]);
339 check (i < 1998 && (i & 1) == 0);
340 f3<int> (&a[20], &a[1837]);
341 check (i >= 20 && i <= 1837);
342 f4<int> (&a[0], &a[30]);
343 check (i > 40 && i <= 2000 - 64);
344
345 f5 (&a[0], &a[100]);
346 check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
347 f6<-10> (&a[10], &a[110]);
348 check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
349
350 f7<6> (I<int> (), &a[12], &a[1800]);
351 check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0);
352
353 f8<121> (J<int> (&a[14], &a[1803]));
354 check (i >= 14 && i <= 1924 && (i & 1) == 0);
355 f9<int, 7> (&a[33], &a[1967]);
356 check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0);
357 f10<int, -7> (&a[1939], &a[17]);
358 check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
359 f11<I<int> > (&a[16], &a[1981]);
360 check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
361 f12<I<int> > (&a[1761], &a[37]);
362 check (i > 37 && i <= 1761);
363 K<5>::f13<I<int> > (&a[1], &a[1935]);
364 check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0);
365 f9<long, 7> (&b[33], &b[1967]);
366 check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0);
367 f10<long, -7> (&b[1939], &b[17]);
368 check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
369 f11<I<long> > (&b[16], &b[1981]);
370 check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
371 f12<I<long> > (&b[1761], &b[37]);
372 check (i > 37 && i <= 1761);
373 K<5>::f13<I<long> > (&b[1], &b[1935]);
374 check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0);
375 return 0;
376 }