c++: fix explicit/copy problem [PR109247]
[official-gcc.git] / gcc / testsuite / gdc.dg / torture / simd_shuffle.d
blob3629ceec699fdedcf3939bf844ced259ad4af51d
1 // { dg-additional-options "-mavx" { target avx_runtime } }
2 // { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
3 import gcc.simd;
5 void testshuffle(V, VI = V)()
7 alias E = typeof(V.array[0]);
8 enum numElements = V.sizeof / E.sizeof;
10 static if (numElements == 16)
12 // Test fragment for vectors with 16 elements
13 immutable V[5] in1 =
14 [[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ],
15 [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ],
16 [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ],
17 [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ],
18 [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]];
20 immutable VI[5] mask1 =
21 [[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ],
22 [ 0x10, 0x21, 0x32, 0x43, 0x54, 0x65, 0x76, 0x87,
23 0x98, 0xa9, 0xba, 0xcb, 0xdc, 0xed, 0xfe, 0xff ] ,
24 [ 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ],
25 [ 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15 ],
26 [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 ]];
28 immutable V[5] out1 =
29 [[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ],
30 [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ],
31 [ 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 ],
32 [ 1, 3, 5, 7, 9, 11, 13, 15, 2, 4, 6, 8, 10, 12, 14, 16 ],
33 [ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ]];
35 immutable V[5] in2 =
36 [[ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ],
37 [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ],
38 [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ],
39 [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ],
40 [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ]];
42 immutable V in3 =
43 [ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45 ];
45 immutable VI[5] mask2 =
46 [[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ],
47 [ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ],
48 [ 7, 6, 5, 4, 16, 17, 18, 19, 31, 30, 29, 28, 3, 2, 1, 0 ],
49 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
50 [ 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 ]];
52 immutable V[5] out2 =
53 [[ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ],
54 [ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45 ],
55 [ 17, 16, 15, 14, 30, 31, 32, 33, 45, 44, 43, 42, 13, 12, 11, 10 ],
56 [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ],
57 [ 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45 ]];
59 else static if (numElements == 8)
61 // Test fragment for vectors with 8 elements
62 static if (is(E == uint))
64 enum E A1 = 0x11121314;
65 enum E B1 = 0x21222324;
66 enum E C1 = 0x31323334;
67 enum E D1 = 0x41424344;
68 enum E E1 = 0x51525354;
69 enum E F1 = 0x61626364;
70 enum E G1 = 0x71727374;
71 enum E H1 = 0x81828384;
73 enum E A2 = 0x91929394;
74 enum E B2 = 0xa1a2a3a4;
75 enum E C2 = 0xb1b2b3b4;
76 enum E D2 = 0xc1c2c3c4;
77 enum E E2 = 0xd1d2d3d4;
78 enum E F2 = 0xe1e2e3e4;
79 enum E G2 = 0xf1f2f3f4;
80 enum E H2 = 0x01020304;
82 else static if (is(E == ushort))
84 enum E A1 = 0x1112;
85 enum E B1 = 0x2122;
86 enum E C1 = 0x3132;
87 enum E D1 = 0x4142;
88 enum E E1 = 0x5152;
89 enum E F1 = 0x6162;
90 enum E G1 = 0x7172;
91 enum E H1 = 0x8182;
93 enum E A2 = 0x9192;
94 enum E B2 = 0xa1a2;
95 enum E C2 = 0xb1b2;
96 enum E D2 = 0xc1c2;
97 enum E E2 = 0xd1d2;
98 enum E F2 = 0xe1e2;
99 enum E G2 = 0xf1f2;
100 enum E H2 = 0x0102;
102 else static if (is(E == ubyte))
104 enum E A1 = 0x11;
105 enum E B1 = 0x12;
106 enum E C1 = 0x13;
107 enum E D1 = 0x14;
108 enum E E1 = 0x15;
109 enum E F1 = 0x16;
110 enum E G1 = 0x17;
111 enum E H1 = 0x18;
113 enum E A2 = 0xf1;
114 enum E B2 = 0xf2;
115 enum E C2 = 0xf3;
116 enum E D2 = 0xf4;
117 enum E E2 = 0xf5;
118 enum E F2 = 0xf6;
119 enum E G2 = 0xf7;
120 enum E H2 = 0xf8;
122 else
123 enum unsupported = true;
125 static if (!__traits(compiles, unsupported))
127 immutable V[8] in1 =
128 [[ A1, B1, C1, D1, E1, F1, G1, H1 ],
129 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
130 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
131 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
132 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
133 [ A2, B2, C2, D2, E2, F2, G2, H2 ],
134 [ A2, B2, C2, D2, E2, F2, G2, H2 ],
135 [ A2, B2, C2, D2, E2, F2, G2, H2 ]];
137 immutable VI[8] mask1 =
138 [[ 0, 1, 2, 3, 4, 5, 6, 7 ],
139 [ 0x10, 0x21, 0x32, 0x43, 0x54, 0x65, 0x76, 0x87 ],
140 [ 7, 6, 5, 4, 3, 2, 1, 0 ],
141 [ 7, 0, 5, 3, 2, 4, 1, 6 ],
142 [ 0, 2, 1, 3, 4, 6, 5, 7 ],
143 [ 3, 1, 2, 0, 7, 5, 6, 4 ],
144 [ 0, 0, 0, 0 ],
145 [ 1, 6, 1, 6, 1, 6, 1, 6 ]];
147 immutable V[8] out1 =
148 [[ A1, B1, C1, D1, E1, F1, G1, H1 ],
149 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
150 [ H1, G1, F1, E1, D1, C1, B1, A1 ],
151 [ H1, A1, F1, D1, C1, E1, B1, G1 ],
152 [ A1, C1, B1, D1, E1, G1, F1, H1 ],
153 [ D2, B2, C2, A2, H2, F2, G2, E2 ],
154 [ A2, A2, A2, A2, A2, A2, A2, A2 ],
155 [ B2, G2, B2, G2, B2, G2, B2, G2 ]];
157 immutable V[6] in2 =
158 [[ A1, B1, C1, D1, E1, F1, G1, H1 ],
159 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
160 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
161 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
162 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
163 [ A1, B1, C1, D1, E1, F1, G1, H1 ]];
166 immutable V in3 =
167 [ A2, B2, C2, D2, E2, F2, G2, H2 ];
169 immutable VI[6] mask2 =
170 [[ 0, 1, 2, 3, 4, 5, 6, 7 ],
171 [ 8, 9, 10, 11, 12, 13, 14, 15 ],
172 [ 0, 8, 1, 9, 2, 10, 3, 11 ],
173 [ 0, 15, 4, 11, 12, 3, 7, 8 ],
174 [ 0, 0, 0, 0, 0, 0, 0, 0 ],
175 [ 0x1e, 0x2e, 0x3e, 0x4e, 0x5e, 0x6e, 0x7e, 0x8e ]];
177 immutable V[6] out2 =
178 [[ A1, B1, C1, D1, E1, F1, G1, H1 ],
179 [ A2, B2, C2, D2, E2, F2, G2, H2 ],
180 [ A1, A2, B1, B2, C1, C2, D1, D2 ],
181 [ A1, H2, E1, D2, E2, D1, H1, A2 ],
182 [ A1, A1, A1, A1, A1, A1, A1, A1 ],
183 [ G2, G2, G2, G2, G2, G2, G2, G2 ]];
186 else static if (numElements == 4)
188 // Test fragment for vectors with 4 elements
189 static if (is(E == double))
191 enum E A = 0.69314718055994530942;
192 enum E B = 2.7182818284590452354;
193 enum E C = 2.30258509299404568402;
194 enum E D = 1.4426950408889634074;
196 enum E W = 0.31830988618379067154;
197 enum E X = 3.14159265358979323846;
198 enum E Y = 1.41421356237309504880;
199 enum E Z = 0.70710678118654752440;
201 else static if (is(E == float))
203 enum E A = 0.69314718055994530942f;
204 enum E B = 2.7182818284590452354f;
205 enum E C = 2.30258509299404568402f;
206 enum E D = 1.4426950408889634074f;
208 enum E W = 0.31830988618379067154f;
209 enum E X = 3.14159265358979323846f;
210 enum E Y = 1.41421356237309504880f;
211 enum E Z = 0.70710678118654752440f;
213 else static if (is(E == ulong))
215 enum E A = 0x1112131415161718;
216 enum E B = 0x2122232425262728;
217 enum E C = 0x3132333435363738;
218 enum E D = 0x4142434445464748;
220 enum E W = 0xc1c2c3c4c5c6c7c8;
221 enum E X = 0xd1d2d3d4d5d6d7d8;
222 enum E Y = 0xe1e2e3e4e5e6e7e8;
223 enum E Z = 0xf1f2f3f4f5f6f7f8;
225 else static if (is(E == uint))
227 enum E A = 0x11121314;
228 enum E B = 0x21222324;
229 enum E C = 0x31323334;
230 enum E D = 0x41424344;
232 enum E W = 0xc1c2c3c4;
233 enum E X = 0xd1d2d3d4;
234 enum E Y = 0xe1e2e3e4;
235 enum E Z = 0xf1f2f3f4;
237 else
238 enum unsupported = true;
240 static if (!__traits(compiles, unsupported))
242 immutable V[8] in1 =
243 [[ A, B, C, D ],
244 [ A, B, C, D ],
245 [ A, B, C, D ],
246 [ A, B, C, D ],
247 [ A, B, C, D ],
248 [ W, X, Y, Z ],
249 [ W, X, Y, Z ],
250 [ W, X, Y, Z ]];
252 immutable VI[8] mask1 =
253 [[ 0, 1, 2, 3 ],
254 [ 0+1*4, 1+2*4, 2+3*4, 3+4*4 ],
255 [ 3, 2, 1, 0 ],
256 [ 0, 3, 2, 1 ],
257 [ 0, 2, 1, 3 ],
258 [ 3, 1, 2, 0 ],
259 [ 0, 0, 0, 0 ],
260 [ 1, 2, 1, 2 ]];
262 immutable V[8] out1 =
263 [[ A, B, C, D ],
264 [ A, B, C, D ],
265 [ D, C, B, A ],
266 [ A, D, C, B ],
267 [ A, C, B, D ],
268 [ Z, X, Y, W ],
269 [ W, W, W, W ],
270 [ X, Y, X, Y ]];
273 immutable V[6] in2 =
274 [[ A, B, C, D ],
275 [ A, B, C, D ],
276 [ A, B, C, D ],
277 [ A, B, C, D ],
278 [ A, B, C, D ],
279 [ A, B, C, D ]];
281 immutable V in3 = [ W, X, Y, Z ];
283 immutable VI[6] mask2 =
284 [[ 0, 1, 2, 3 ],
285 [ 4, 5, 6, 7 ],
286 [ 0, 4, 1, 5 ],
287 [ 0, 7, 4, 3 ],
288 [ 0, 0, 0, 0 ],
289 [ 7, 7, 7, 7 ]];
291 immutable V[6] out2 =
292 [[ A, B, C, D ],
293 [ W, X, Y, Z ],
294 [ A, W, B, X ],
295 [ A, Z, W, D ],
296 [ A, A, A, A ],
297 [ Z, Z, Z, Z ]];
300 else static if (numElements == 2)
302 // Test fragment for vectors with 2 elements
303 static if (is(E == double))
305 enum E A = 0.69314718055994530942;
306 enum E B = 2.7182818284590452354;
308 enum E X = 3.14159265358979323846;
309 enum E Y = 1.41421356237309504880;
311 else static if (is(E == float))
313 enum E A = 0.69314718055994530942f;
314 enum E B = 2.7182818284590452354f;
316 enum E X = 3.14159265358979323846f;
317 enum E Y = 1.41421356237309504880f;
319 else static if (is(E == ulong))
321 enum E A = 0x1112131415161718;
322 enum E B = 0x2122232425262728;
324 enum E X = 0xc1c2c3c4c5c6c7c8;
325 enum E Y = 0xd1d2d3d4d5d6d7d8;
327 else static if (is(E == uint))
329 enum E A = 0x11121314;
330 enum E B = 0x21222324;
332 enum E X = 0xd1d2d3d4;
333 enum E Y = 0xe1e2e3e4;
335 else
336 enum unsupported = true;
338 static if (!__traits(compiles, unsupported))
340 immutable V[6] in1 =
341 [[ A, B ],
342 [ A, B ],
343 [ A, B ],
344 [ A, B ],
345 [ X, Y ],
346 [ X, Y ]];
348 immutable VI[6] mask1 =
349 [[ 0, 1 ],
350 [ -16, 1 ],
351 [ 1, 0 ],
352 [ 0, 0 ],
353 [ 1, 1 ],
354 [ 1, 0 ]];
356 immutable V[6] out1 =
357 [[ A, B ],
358 [ A, B ],
359 [ B, A ],
360 [ A, A ],
361 [ Y, Y ],
362 [ Y, X ]];
364 immutable V[7] in2 =
365 [[ A, B ],
366 [ A, B ],
367 [ A, B ],
368 [ A, B ],
369 [ A, B ],
370 [ A, B ],
371 [ A, B ]];
373 immutable V in3 = [ X, Y ];
375 immutable VI[7] mask2 =
376 [[ 0, 1 ],
377 [ 2, 3 ],
378 [ 0, 2 ],
379 [ 2, 1 ],
380 [ 3, 0 ],
381 [ 0, 0 ],
382 [ 3, 3 ]];
384 immutable V[7] out2 =
385 [[ A, B ],
386 [ X, Y ],
387 [ A, X ],
388 [ X, B ],
389 [ Y, A ],
390 [ A, A ],
391 [ Y, Y ]];
394 else
395 enum unsupported = true;
397 static if (!__traits(compiles, unsupported))
399 static foreach (i; 0 .. in1.length)
400 assert(shuffle(in1[i], mask1[i]).array == out1[i].array);
401 static foreach (i; 0 .. in2.length)
402 assert(shuffle(in2[i], in3, mask2[i]).array == out2[i].array);
406 void main()
408 static if (__traits(compiles, __vector(ubyte[16])))
409 testshuffle!(__vector(ubyte[16]))();
411 static if (__traits(compiles, __vector(ushort[16])))
412 testshuffle!(__vector(ushort[16]))();
414 static if (__traits(compiles, __vector(ubyte[8])))
415 testshuffle!(__vector(ubyte[8]))();
417 static if (__traits(compiles, __vector(ushort[8])))
418 testshuffle!(__vector(ushort[8]))();
420 static if (__traits(compiles, __vector(uint[8])))
421 testshuffle!(__vector(uint[8]))();
423 static if (__traits(compiles, __vector(ulong[4])))
425 testshuffle!(__vector(ulong[4]));
427 static if (__traits(compiles, __vector(double[4])))
428 testshuffle!(__vector(double[4]), __vector(ulong[4]));
431 static if (__traits(compiles, __vector(uint[4])))
433 testshuffle!(__vector(uint[4]));
435 static if (__traits(compiles, __vector(float[4])))
436 testshuffle!(__vector(float[4]), __vector(uint[4]));
439 static if (__traits(compiles, __vector(ulong[2])))
441 testshuffle!(__vector(ulong[2]));
443 static if (__traits(compiles, __vector(double[2])))
444 testshuffle!(__vector(double[2]), __vector(ulong[2]));
447 static if (__traits(compiles, __vector(uint[2])))
449 testshuffle!(__vector(uint[2]));
451 static if (__traits(compiles, __vector(float[2])))
452 testshuffle!(__vector(float[2]), __vector(uint[2]));