]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/g++.dg/cilk-plus/CK/for1.cc
2 /* { dg-require-effective-target cilkplus_runtime } */
3 /* { dg-options "-fcilkplus" } */
9 typedef __PTRDIFF_TYPE__
ptrdiff_t;
10 extern "C" void abort ();
16 typedef ptrdiff_t difference_type
;
23 T
&operator [] (const difference_type
&) const;
24 I
&operator = (const I
&);
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
> &);
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
); }
85 J(const I
<T
> &x
, const I
<T
> &y
) : b (x
), e (y
) {}
92 template <typename T
> const I
<T
> &J
<T
>::begin () { return b
; }
93 template <typename T
> const I
<T
> &J
<T
>::end () { return e
; }
101 if (*i
< 0 || *i
>= 2000)
104 printf ("*i(%d) is < 0 or >= 2000\n", *i
);
114 f1 (const I
<int> &x
, const I
<int> &y
)
116 _Cilk_for (I
<int> i
= x
; i
<= y
; i
+= 6)
122 printf("===== Starting F1 =========\n");
123 for (I
<int> i
= x
; i
<= y
; i
+= 6) {
124 printf("Result[%4d] = %2d\n", *i
, results
[*i
]);
131 f2 (const I
<int> &x
, const I
<int> &y
)
133 _Cilk_for (I
<int> i
= x
; i
< y
- 1; i
+= 2)
137 printf("===== Starting F2 =========\n");
138 for (int ii
= 0; ii
< 1998; ii
+= 2) {
139 printf("Result[%4d] = %2d\n", ii
, results
[ii
]);
145 template <typename T
>
147 f3 (const I
<int> &x
, const I
<int> &y
)
149 _Cilk_for (I
<int> i
= x
; i
<= y
; i
+= 1)
152 printf("===== Starting F3 =========\n");
153 for (int ii
= 20; ii
< 1987; ii
+= 1) {
154 printf("Result[%4d] = %2d\n", ii
, results
[ii
]);
161 template <typename T
>
163 f4 (const I
<int> &x
, const I
<int> &y
)
165 _Cilk_for (I
<int> i
= x
+ (2000 - 64); i
> y
+ 10; --i
)
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
]);
176 f5 (const I
<int> &x
, const I
<int> &y
)
178 _Cilk_for (I
<int> i
= x
+ 2000 - 64; i
> y
+ 10; i
-= 10)
181 for (I
<int> i
= x
+ 2000 - 64; i
> y
+ 10; i
-= 10) {
182 printf("Result[%4d] = %2d\n", *i
, results
[*i
]);
190 f6 (const I
<int> &x
, const I
<int> &y
)
192 _Cilk_for (I
<int> i
= x
+ 2000 - 64; i
> y
+ 10; i
-= 10)
198 for (I
<int> i
= x
+ 2000 - 64; i
> y
+ 10; i
= i
- 12 + 2)
201 printf("Result[%4d] = %2d\n", *j
, results
[*j
]);
208 f7 (I
<int> ii
, const I
<int> &x
, const I
<int> &y
)
210 _Cilk_for (I
<int> i
= x
- 10; i
<= y
+ 10; i
+= N
)
213 for (I
<int> i
= x
- 10; i
<= y
+ 10; i
+= N
)
215 printf("Result[%4d] = %2d\n", *i
, results
[*i
]);
225 _Cilk_for (I
<int> i
= j
.begin (); i
<= j
.end () + N
; i
+= 2)
228 for (I
<int> i
= j
.begin (); i
<= j
.end () + N
; i
+= 2) {
229 printf("Result[%4d] = %2d\n", *i
, results
[*i
]);
236 template <typename T
, int N
>
238 f9 (const I
<T
> &x
, const I
<T
> &y
)
240 _Cilk_for (I
<T
> i
= x
; i
<= y
; i
+= N
)
243 for (I
<T
> i
= x
; i
<= y
; i
= i
+ N
)
245 printf("Result[%4d] = %2d\n", *i
, results
[*i
]);
251 template <typename T
, int N
>
253 f10 (const I
<T
> &x
, const I
<T
> &y
)
255 _Cilk_for (I
<T
> i
= x
; i
> y
; i
+= N
)
258 for (I
<T
> i
= x
; i
> y
; i
= i
+ N
) {
259 printf("Result[%4d] = %2d\n", *i
, results
[*i
]);
265 template <typename T
>
267 f11 (const T
&x
, const T
&y
)
269 _Cilk_for (T i
= x
; i
<= y
; i
+= 3)
273 for (T i
= x
; i
<= y
; i
+= 3) {
274 printf("Result[%4d] = %2d\n", *i
, results
[*i
]);
283 template <typename T
>
285 f12 (const T
&x
, const T
&y
)
287 _Cilk_for (T i
= x
; i
> y
; --i
)
290 for (T i
= x
; i
> y
; --i
) {
291 printf("Result[%4d] = %2d\n", *i
, results
[*i
]);
299 template <typename T
>
301 f13 (const T
&x
, const T
&y
)
303 _Cilk_for (T i
= x
; i
<= y
+ N
; i
+= N
)
306 for (T i
= x
; i
< y
+N
; i
+= N
) {
307 printf("Result[%4d] = %2d\n", *i
, results
[*i
]);
314 #define check(expr) \
315 for (int i = 0; i < 2000; i++) \
318 if (results[i] != 1) { \
319 __builtin_abort (); \
323 else if (results[i]) \
331 for (int i
= 0; i
< 2000; i
++)
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);
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);
350 f7
<6> (I
<int> (), &a
[12], &a
[1800]);
351 check (i
>= 2 && i
<= 1808 && (i
- 2) % 6 == 0);
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);