1 // { dg-additional-options "-mavx" { target avx_runtime } }
2 // { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
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
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 ]];
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 ]];
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 ]];
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 ]];
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))
102 else static if (is(E
== ubyte))
123 enum unsupported
= true;
125 static if (!__traits(compiles
, unsupported
))
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 ],
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
]];
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
]];
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;
238 enum unsupported
= true;
240 static if (!__traits(compiles
, unsupported
))
252 immutable VI
[8] mask1
=
254 [ 0+1*4, 1+2*4, 2+3*4, 3+4*4 ],
262 immutable V
[8] out1
=
281 immutable V in3
= [ W
, X
, Y
, Z
];
283 immutable VI
[6] mask2
=
291 immutable V
[6] out2
=
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;
336 enum unsupported
= true;
338 static if (!__traits(compiles
, unsupported
))
348 immutable VI
[6] mask1
=
356 immutable V
[6] out1
=
373 immutable V in3
= [ X
, Y
];
375 immutable VI
[7] mask2
=
384 immutable V
[7] out2
=
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
);
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]));