Debian Codegraph @

gcc/testsuite/gdc.dg/torture/simd_blendvector.d

raw
1 // { dg-additional-options "-mavx" { target avx_runtime } }
2 // { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
3 import gcc.simd;
4
5 void testblendvector(V, VI = V)()
6 {
7 alias E = typeof(V.array[0]);
8 enum numElements = V.sizeof / E.sizeof;
9
10 static if (numElements == 16)
11 {
12 // Test fragment for vectors with 16 elements
13 immutable V[5] in1 =
14 [[ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ],
15 [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ],
16 [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ],
17 [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ],
18 [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ]];
19
20 immutable V in2 =
21 [ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45 ];
22
23 immutable VI[5] mask1 =
24 [[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ],
25 [ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ],
26 [ 7, 6, 5, 4, 16, 17, 18, 19, 31, 30, 29, 28, 3, 2, 1, 0 ],
27 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
28 [ 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 ]];
29
30 immutable V[5] out1 =
31 [[30, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],
32 [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],
33 [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 45],
34 [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45],
35 [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]];
36 }
37 else static if (numElements == 8)
38 {
39 // Test fragment for vectors with 8 elements
40 static if (is(E == uint))
41 {
42 enum E A1 = 0x11121314;
43 enum E B1 = 0x21222324;
44 enum E C1 = 0x31323334;
45 enum E D1 = 0x41424344;
46 enum E E1 = 0x51525354;
47 enum E F1 = 0x61626364;
48 enum E G1 = 0x71727374;
49 enum E H1 = 0x81828384;
50
51 enum E A2 = 0x91929394;
52 enum E B2 = 0xa1a2a3a4;
53 enum E C2 = 0xb1b2b3b4;
54 enum E D2 = 0xc1c2c3c4;
55 enum E E2 = 0xd1d2d3d4;
56 enum E F2 = 0xe1e2e3e4;
57 enum E G2 = 0xf1f2f3f4;
58 enum E H2 = 0x01020304;
59 }
60 else static if (is(E == ushort))
61 {
62 enum E A1 = 0x1112;
63 enum E B1 = 0x2122;
64 enum E C1 = 0x3132;
65 enum E D1 = 0x4142;
66 enum E E1 = 0x5152;
67 enum E F1 = 0x6162;
68 enum E G1 = 0x7172;
69 enum E H1 = 0x8182;
70
71 enum E A2 = 0x9192;
72 enum E B2 = 0xa1a2;
73 enum E C2 = 0xb1b2;
74 enum E D2 = 0xc1c2;
75 enum E E2 = 0xd1d2;
76 enum E F2 = 0xe1e2;
77 enum E G2 = 0xf1f2;
78 enum E H2 = 0x0102;
79 }
80 else static if (is(E == ubyte))
81 {
82 enum E A1 = 0x11;
83 enum E B1 = 0x12;
84 enum E C1 = 0x13;
85 enum E D1 = 0x14;
86 enum E E1 = 0x15;
87 enum E F1 = 0x16;
88 enum E G1 = 0x17;
89 enum E H1 = 0x18;
90
91 enum E A2 = 0xf1;
92 enum E B2 = 0xf2;
93 enum E C2 = 0xf3;
94 enum E D2 = 0xf4;
95 enum E E2 = 0xf5;
96 enum E F2 = 0xf6;
97 enum E G2 = 0xf7;
98 enum E H2 = 0xf8;
99 }
100 else
101 enum unsupported = true;
102
103 static if (!__traits(compiles, unsupported))
104 {
105 immutable V[6] in1 =
106 [[ A1, B1, C1, D1, E1, F1, G1, H1 ],
107 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
108 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
109 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
110 [ A1, B1, C1, D1, E1, F1, G1, H1 ],
111 [ A1, B1, C1, D1, E1, F1, G1, H1 ]];
112
113
114 immutable V in2 =
115 [ A2, B2, C2, D2, E2, F2, G2, H2 ];
116
117 immutable VI[6] mask1 =
118 [[ 0, 1, 2 , 3 , 4 , 5 , 6 , 0 ],
119 [ 8, 9, 0, 11, 12, 13, 0, 15 ],
120 [ 0, 8, 1, 0, 2, 0, 3, 11 ],
121 [ 0, 15, 4, 11, 0, 3, 7, 8 ],
122 [ 0, 0, 0, 0, 0, 0, 0, 0 ],
123 [ 0x1e, 0x2e, 0x3e, 0x4e, 0x5e, 0x6e, 0x7e, 0x8e ]];
124
125 immutable V[6] out1 =
126 [[ A2, B1, C1, D1, E1, F1, G1, H2 ],
127 [ A1, B1, C2, D1, E1, F1, G2, H1 ],
128 [ A2, B1, C1, D2, E1, F2, G1, H1 ],
129 [ A2, B1, C1, D1, E2, F1, G1, H1 ],
130 [ A2, B2, C2, D2, E2, F2, G2, H2 ],
131 [ A1, B1, C1, D1, E1, F1, G1, H1 ]];
132 }
133 }
134 else static if (numElements == 4)
135 {
136 // Test fragment for vectors with 4 elements
137 static if (is(E == double))
138 {
139 enum E A = 0.69314718055994530942;
140 enum E B = 2.7182818284590452354;
141 enum E C = 2.30258509299404568402;
142 enum E D = 1.4426950408889634074;
143
144 enum E W = 0.31830988618379067154;
145 enum E X = 3.14159265358979323846;
146 enum E Y = 1.41421356237309504880;
147 enum E Z = 0.70710678118654752440;
148 }
149 else static if (is(E == float))
150 {
151 enum E A = 0.69314718055994530942f;
152 enum E B = 2.7182818284590452354f;
153 enum E C = 2.30258509299404568402f;
154 enum E D = 1.4426950408889634074f;
155
156 enum E W = 0.31830988618379067154f;
157 enum E X = 3.14159265358979323846f;
158 enum E Y = 1.41421356237309504880f;
159 enum E Z = 0.70710678118654752440f;
160 }
161 else static if (is(E == ulong))
162 {
163 enum E A = 0x1112131415161718;
164 enum E B = 0x2122232425262728;
165 enum E C = 0x3132333435363738;
166 enum E D = 0x4142434445464748;
167
168 enum E W = 0xc1c2c3c4c5c6c7c8;
169 enum E X = 0xd1d2d3d4d5d6d7d8;
170 enum E Y = 0xe1e2e3e4e5e6e7e8;
171 enum E Z = 0xf1f2f3f4f5f6f7f8;
172 }
173 else static if (is(E == uint))
174 {
175 enum E A = 0x11121314;
176 enum E B = 0x21222324;
177 enum E C = 0x31323334;
178 enum E D = 0x41424344;
179
180 enum E W = 0xc1c2c3c4;
181 enum E X = 0xd1d2d3d4;
182 enum E Y = 0xe1e2e3e4;
183 enum E Z = 0xf1f2f3f4;
184 }
185 else
186 enum unsupported = true;
187
188 static if (!__traits(compiles, unsupported))
189 {
190 immutable V[6] in1 =
191 [[ A, B, C, D ],
192 [ A, B, C, D ],
193 [ A, B, C, D ],
194 [ A, B, C, D ],
195 [ A, B, C, D ],
196 [ A, B, C, D ]];
197
198 immutable V in2 = [ W, X, Y, Z ];
199
200 immutable VI[6] mask1 =
201 [[ 0, 1, 2, 3 ],
202 [ 4, 0, 6, 7 ],
203 [ 0, 4, 0, 5 ],
204 [ 0, 7, 4, 0 ],
205 [ 0, 0, 0, 0 ],
206 [ 7, 7, 7, 7 ]];
207
208 immutable V[6] out1 =
209 [[ W, B, C, D ],
210 [ A, X, C, D ],
211 [ W, B, Y, D ],
212 [ W, B, C, Z ],
213 [ W, X, Y, Z ],
214 [ A, B, C, D ]];
215 }
216 }
217 else static if (numElements == 2)
218 {
219 // Test fragment for vectors with 2 elements
220 static if (is(E == double))
221 {
222 enum E A = 0.69314718055994530942;
223 enum E B = 2.7182818284590452354;
224
225 enum E X = 3.14159265358979323846;
226 enum E Y = 1.41421356237309504880;
227 }
228 else static if (is(E == float))
229 {
230 enum E A = 0.69314718055994530942f;
231 enum E B = 2.7182818284590452354f;
232
233 enum E X = 3.14159265358979323846f;
234 enum E Y = 1.41421356237309504880f;
235 }
236 else static if (is(E == ulong))
237 {
238 enum E A = 0x1112131415161718;
239 enum E B = 0x2122232425262728;
240
241 enum E X = 0xc1c2c3c4c5c6c7c8;
242 enum E Y = 0xd1d2d3d4d5d6d7d8;
243 }
244 else static if (is(E == uint))
245 {
246 enum E A = 0x11121314;
247 enum E B = 0x21222324;
248
249 enum E X = 0xd1d2d3d4;
250 enum E Y = 0xe1e2e3e4;
251 }
252 else
253 enum unsupported = true;
254
255 static if (!__traits(compiles, unsupported))
256 {
257 immutable V[7] in1 =
258 [[ A, B ],
259 [ A, B ],
260 [ A, B ],
261 [ A, B ],
262 [ A, B ],
263 [ A, B ],
264 [ A, B ]];
265
266 immutable V in2 = [ X, Y ];
267
268 immutable VI[7] mask1 =
269 [[ 0, 1 ],
270 [ 2, 3 ],
271 [ 0, 2 ],
272 [ 2, 1 ],
273 [ 3, 0 ],
274 [ 0, 0 ],
275 [ 3, 3 ]];
276
277 immutable V[7] out1 =
278 [[ X, B ],
279 [ A, B ],
280 [ X, B ],
281 [ A, B ],
282 [ A, Y ],
283 [ X, Y ],
284 [ A, B ]];
285 }
286 }
287 else
288 enum unsupported = true;
289
290 static if (!__traits(compiles, unsupported))
291 {
292 static foreach (i; 0 .. in1.length)
293 assert(blendvector(in1[i], in2, mask1[i]).array == out1[i].array);
294 }
295 }
296
297 void main()
298 {
299 static if (__traits(compiles, __vector(ubyte[16])))
300 testblendvector!(__vector(ubyte[16]))();
301
302 static if (__traits(compiles, __vector(ushort[16])))
303 testblendvector!(__vector(ushort[16]))();
304
305 static if (__traits(compiles, __vector(ubyte[8])))
306 testblendvector!(__vector(ubyte[8]))();
307
308 static if (__traits(compiles, __vector(ushort[8])))
309 testblendvector!(__vector(ushort[8]))();
310
311 static if (__traits(compiles, __vector(uint[8])))
312 testblendvector!(__vector(uint[8]))();
313
314 static if (__traits(compiles, __vector(ulong[4])))
315 {
316 testblendvector!(__vector(ulong[4]));
317
318 static if (__traits(compiles, __vector(double[4])))
319 testblendvector!(__vector(double[4]), __vector(ulong[4]));
320 }
321
322 static if (__traits(compiles, __vector(uint[4])))
323 {
324 testblendvector!(__vector(uint[4]));
325
326 static if (__traits(compiles, __vector(float[4])))
327 testblendvector!(__vector(float[4]), __vector(uint[4]));
328 }
329
330 static if (__traits(compiles, __vector(ulong[2])))
331 {
332 testblendvector!(__vector(ulong[2]));
333
334 static if (__traits(compiles, __vector(double[2])))
335 testblendvector!(__vector(double[2]), __vector(ulong[2]));
336 }
337
338 static if (__traits(compiles, __vector(uint[2])))
339 {
340 testblendvector!(__vector(uint[2]));
341
342 static if (__traits(compiles, __vector(float[2])))
343 testblendvector!(__vector(float[2]), __vector(uint[2]));
344 }
345 }