1 /* { dg-do run } */
2 /* { dg-require-effective-target avx512f } */
3 /* { dg-options "-O3 -mavx512f -ffast-math -mtune=knl" } */
4
5 #include "avx512f-check.h"
6
7 #define N 1024
8 float f[N];
9 double d[N];
10 int k[N];
11 float *l[N];
12 double *n[N];
13 int **m[N];
14 long q[N];
15 long long **o[N];
16 long long t[N];
17 long long *r[N];
18 int *s[N];
19
20 __attribute__((noinline, noclone)) float
f1(void)21 f1 (void)
22 {
23 int i;
24 float g = 0.0;
25 for (i = 0; i < N / 2; i++)
26 g += f[k[i]];
27 return g;
28 }
29
30 __attribute__((noinline, noclone)) float
f2(float * p)31 f2 (float *p)
32 {
33 int i;
34 float g = 0.0;
35 for (i = 0; i < N / 2; i++)
36 g += p[k[i]];
37 return g;
38 }
39
40 __attribute__((noinline, noclone)) float
f3(void)41 f3 (void)
42 {
43 int i;
44 float g = 0.0;
45 for (i = 0; i < N / 2; i++)
46 g += *l[i];
47 return g;
48 }
49
50 __attribute__((noinline, noclone)) int
f4(void)51 f4 (void)
52 {
53 int i;
54 int g = 0;
55 for (i = 0; i < N / 2; i++)
56 g += **m[i];
57 return g;
58 }
59
60 __attribute__((noinline, noclone)) double
f5(void)61 f5 (void)
62 {
63 int i;
64 double g = 0.0;
65 for (i = 0; i < N / 2; i++)
66 g += d[k[i]];
67 return g;
68 }
69
70 __attribute__((noinline, noclone)) double
f6(double * p)71 f6 (double *p)
72 {
73 int i;
74 double g = 0.0;
75 for (i = 0; i < N / 2; i++)
76 g += p[k[i]];
77 return g;
78 }
79
80 __attribute__((noinline, noclone)) double
f7(void)81 f7 (void)
82 {
83 int i;
84 double g = 0.0;
85 for (i = 0; i < N / 2; i++)
86 g += *n[i];
87 return g;
88 }
89
90 __attribute__((noinline, noclone)) int
f8(void)91 f8 (void)
92 {
93 int i;
94 int g = 0;
95 for (i = 0; i < N / 2; i++)
96 g += **o[i];
97 return g;
98 }
99
100 __attribute__((noinline, noclone)) float
f9(void)101 f9 (void)
102 {
103 int i;
104 float g = 0.0;
105 for (i = 0; i < N / 2; i++)
106 g += f[q[i]];
107 return g;
108 }
109
110 __attribute__((noinline, noclone)) float
f10(float * p)111 f10 (float *p)
112 {
113 int i;
114 float g = 0.0;
115 for (i = 0; i < N / 2; i++)
116 g += p[q[i]];
117 return g;
118 }
119
120 __attribute__((noinline, noclone)) double
f11(void)121 f11 (void)
122 {
123 int i;
124 double g = 0.0;
125 for (i = 0; i < N / 2; i++)
126 g += d[q[i]];
127 return g;
128 }
129
130 __attribute__((noinline, noclone)) double
f12(double * p)131 f12 (double *p)
132 {
133 int i;
134 double g = 0.0;
135 for (i = 0; i < N / 2; i++)
136 g += p[q[i]];
137 return g;
138 }
139
140 static void
avx512f_test(void)141 avx512f_test (void)
142 {
143 int i;
144
145 for (i = 0; i < N; i++)
146 {
147 asm ("");
148 f[i] = -256.0f + i;
149 d[i] = -258.0 + i;
150 k[i] = (i * 731) & (N - 1);
151 q[i] = (i * 657) & (N - 1);
152 t[i] = (i * 657) & (N - 1);
153 l[i] = &f[(i * 239) & (N - 1)];
154 n[i] = &d[(i * 271) & (N - 1)];
155 r[i] = &t[(i * 323) & (N - 1)];
156 s[i] = &k[(i * 565) & (N - 1)];
157 m[i] = &s[(i * 13) & (N - 1)];
158 o[i] = &r[(i * 19) & (N - 1)];
159 }
160
161 if (f1 () != 136448.0f || f2 (f) != 136448.0f || f3 () != 130304.0)
162 abort ();
163 if (f4 () != 261376 || f5 () != 135424.0 || f6 (d) != 135424.0)
164 abort ();
165 if (f7 () != 129280.0 || f8 () != 259840L || f9 () != 130816.0f)
166 abort ();
167 if (f10 (f) != 130816.0f || f11 () != 129792.0 || f12 (d) != 129792.0)
168 abort ();
169 }
170