1 /* { dg-do run } */
2 
3 /* Integer reductions.  */
4 
5 #include <stdlib.h>
6 #include "reduction.h"
7 
8 #define ng 8
9 #define nw 4
10 #define vl 32
11 
12 static void
test_reductions(void)13 test_reductions (void)
14 {
15   const int n = 10;
16   int i;
17   int array[n];
18 
19   for (i = 0; i < n; i++)
20     array[i] = i+1;
21 
22   /* Gang reductions.  */
23   check_reduction_op (int, +, 0, array[i], num_gangs (ng), gang);
24   check_reduction_op (int, *, 1, array[i], num_gangs (ng), gang);
25   check_reduction_op (int, &, -1, array[i], num_gangs (ng), gang);
26   check_reduction_op (int, |, 0, array[i], num_gangs (ng), gang);
27   check_reduction_op (int, ^, 0, array[i], num_gangs (ng), gang);
28 
29   /* Worker reductions.  */
30   check_reduction_op (int, +, 0, array[i], num_workers (nw), worker);
31   check_reduction_op (int, *, 1, array[i], num_workers (nw), worker);
32   check_reduction_op (int, &, -1, array[i], num_workers (nw), worker);
33   check_reduction_op (int, |, 0, array[i], num_workers (nw), worker);
34   check_reduction_op (int, ^, 0, array[i], num_workers (nw), worker);
35 
36   /* Vector reductions.  */
37   check_reduction_op (int, +, 0, array[i], vector_length (vl), vector);
38   check_reduction_op (int, *, 1, array[i], vector_length (vl), vector);
39   check_reduction_op (int, &, -1, array[i], vector_length (vl), vector);
40   check_reduction_op (int, |, 0, array[i], vector_length (vl), vector);
41   check_reduction_op (int, ^, 0, array[i], vector_length (vl), vector);
42 
43   /* Combined reductions.  */
44   check_reduction_op (int, +, 0, array[i], num_gangs (ng) num_workers (nw)
45 		      vector_length (vl), gang worker vector);
46   check_reduction_op (int, *, 1, array[i], num_gangs (ng) num_workers (nw)
47 		      vector_length (vl), gang worker vector);
48   check_reduction_op (int, &, -1, array[i], num_gangs (ng) num_workers (nw)
49 		      vector_length (vl), gang worker vector);
50   check_reduction_op (int, |, 0, array[i], num_gangs (ng) num_workers (nw)
51 		      vector_length (vl), gang worker vector);
52   check_reduction_op (int, ^, 0, array[i], num_gangs (ng) num_workers (nw)
53 		      vector_length (vl), gang worker vector);
54 }
55 
56 static void
test_reductions_bool(void)57 test_reductions_bool (void)
58 {
59   const int n = 1000;
60   int i;
61   int array[n];
62   int cmp_val;
63 
64   for (i = 0; i < n; i++)
65     array[i] = i;
66 
67   cmp_val = 5;
68 
69   /* Gang reductions.  */
70   check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_gangs (ng),
71 		      gang);
72   check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_gangs (ng),
73 		      gang);
74 
75   /* Worker reductions.  */
76   check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_workers (nw),
77 		      worker);
78   check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_workers (nw),
79 		      worker);
80 
81   /* Vector reductions.  */
82   check_reduction_op (int, &&, 1, (cmp_val > array[i]), vector_length (vl),
83 		      vector);
84   check_reduction_op (int, ||, 0, (cmp_val > array[i]), vector_length (vl),
85 		      vector);
86 
87   /* Combined reductions.  */
88   check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_gangs (ng)
89 		      num_workers (nw) vector_length (vl), gang worker vector);
90   check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_gangs (ng)
91 		      num_workers (nw) vector_length (vl), gang worker vector);
92 }
93 
94 static void
test_reductions_minmax(void)95 test_reductions_minmax (void)
96 {
97   const int n = 1000;
98   int i;
99   int array[n];
100 
101   for (i = 0; i < n; i++)
102     array[i] = i;
103 
104   /* Gang reductions.  */
105   check_reduction_macro (int, min, n + 1, array[i], num_gangs (ng), gang);
106   check_reduction_macro (int, max, -1, array[i], num_gangs (ng), gang);
107 
108   /* Worker reductions.  */
109   check_reduction_macro (int, min, n + 1, array[i], num_workers (nw), worker);
110   check_reduction_macro (int, max, -1, array[i], num_workers (nw), worker);
111 
112   /* Vector reductions.  */
113   check_reduction_macro (int, min, n + 1, array[i], vector_length (vl),
114 			 vector);
115   check_reduction_macro (int, max, -1, array[i], vector_length (vl), vector);
116 
117   /* Combined reductions.  */
118   check_reduction_macro (int, min, n + 1, array[i], num_gangs (ng)
119 			 num_workers (nw) vector_length (vl), gang worker
120 			 vector);
121   check_reduction_macro (int, max, -1, array[i], num_gangs (ng)
122 			 num_workers (nw) vector_length (vl), gang worker
123 			 vector);
124 }
125 
126 int
main(void)127 main (void)
128 {
129   test_reductions ();
130   test_reductions_bool ();
131   test_reductions_minmax ();
132   return 0;
133 }
134