Debian Codegraph @

clang/test/Sema/constant-builtins-vector.cpp

raw
1 // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -Wno-bit-int-extension %s
2 // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -Wno-bit-int-extension -triple ppc64-unknown-linux %s
3 // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -Wno-bit-int-extension -triple ppc64le-unknown-linux %s
4
5 // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -Wno-bit-int-extension %s -fexperimental-new-constant-interpreter
6 // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -Wno-bit-int-extension -triple ppc64-unknown-linux %s -fexperimental-new-constant-interpreter
7 // RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -Wno-bit-int-extension -triple ppc64le-unknown-linux %s -fexperimental-new-constant-interpreter
8
9 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
10 #define LITTLE_END 1
11 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
12 #define LITTLE_END 0
13 #else
14 #error "huh?"
15 #endif
16
17 // We also support _BitInt as long as it is >=8 and a power of 2.
18 typedef _BitInt(8) BitInt8;
19 typedef _BitInt(32) BitInt32;
20 typedef _BitInt(128) BitInt128;
21
22 typedef double vector4double __attribute__((__vector_size__(32)));
23 typedef float vector4float __attribute__((__vector_size__(16)));
24 typedef long long vector4long __attribute__((__vector_size__(32)));
25 typedef int vector4int __attribute__((__vector_size__(16)));
26 typedef unsigned long long vector4ulong __attribute__((__vector_size__(32)));
27 typedef unsigned int vector4uint __attribute__((__vector_size__(16)));
28 typedef short vector4short __attribute__((__vector_size__(8)));
29 typedef char vector4char __attribute__((__vector_size__(4)));
30 typedef unsigned char vector4uchar __attribute__((__vector_size__(4)));
31 typedef BitInt8 vector4BitInt8 __attribute__((__vector_size__(4)));
32 typedef BitInt32 vector4BitInt32 __attribute__((__vector_size__(16)));
33 typedef BitInt128 vector4BitInt128 __attribute__((__vector_size__(64)));
34 typedef double vector8double __attribute__((__vector_size__(64)));
35 typedef float vector8float __attribute__((__vector_size__(32)));
36 typedef long long vector8long __attribute__((__vector_size__(64)));
37 typedef int vector8int __attribute__((__vector_size__(32)));
38 typedef short vector8short __attribute__((__vector_size__(16)));
39 typedef char vector8char __attribute__((__vector_size__(8)));
40 typedef BitInt8 vector8BitInt8 __attribute__((__vector_size__(8)));
41 typedef BitInt32 vector8BitInt32 __attribute__((__vector_size__(32)));
42 typedef BitInt128 vector8BitInt128 __attribute__((__vector_size__(128)));
43
44 #define CHECK_NUM(__size, __typeFrom, __typeTo, ...) \
45 constexpr vector##__size##__typeTo \
46 from_##vector##__size##__typeFrom##_to_##vector##__size##__typeTo##_var = \
47 __builtin_convertvector((vector##__size##__typeFrom){__VA_ARGS__}, \
48 vector##__size##__typeTo);
49 #define CHECK_TO_ALL_TYPES(__size, __typeFrom, ...) \
50 CHECK_NUM(__size, __typeFrom, double, __VA_ARGS__) \
51 CHECK_NUM(__size, __typeFrom, float, __VA_ARGS__) \
52 CHECK_NUM(__size, __typeFrom, long, __VA_ARGS__) \
53 CHECK_NUM(__size, __typeFrom, int, __VA_ARGS__) \
54 CHECK_NUM(__size, __typeFrom, short, __VA_ARGS__) \
55 CHECK_NUM(__size, __typeFrom, char, __VA_ARGS__) \
56 CHECK_NUM(__size, __typeFrom, BitInt8, __VA_ARGS__) \
57 CHECK_NUM(__size, __typeFrom, BitInt32, __VA_ARGS__) \
58 CHECK_NUM(__size, __typeFrom, BitInt128, __VA_ARGS__) \
59 static_assert( \
60 __builtin_bit_cast( \
61 unsigned, \
62 __builtin_shufflevector( \
63 from_vector##__size##__typeFrom##_to_vector##__size##char_var, \
64 from_vector##__size##__typeFrom##_to_vector##__size##char_var, \
65 0, 1, 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203)); \
66 static_assert( \
67 __builtin_bit_cast( \
68 unsigned long long, \
69 __builtin_shufflevector( \
70 from_vector##__size##__typeFrom##_to_vector##__size##short_var, \
71 from_vector##__size##__typeFrom##_to_vector##__size##short_var, \
72 0, 1, 2, 3)) == \
73 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
74
75 #define CHECK_ALL_COMBINATIONS(__size, ...) \
76 CHECK_TO_ALL_TYPES(__size, double, __VA_ARGS__) \
77 CHECK_TO_ALL_TYPES(__size, float, __VA_ARGS__) \
78 CHECK_TO_ALL_TYPES(__size, long, __VA_ARGS__) \
79 CHECK_TO_ALL_TYPES(__size, int, __VA_ARGS__) \
80 CHECK_TO_ALL_TYPES(__size, short, __VA_ARGS__) \
81 CHECK_TO_ALL_TYPES(__size, char, __VA_ARGS__) \
82 CHECK_TO_ALL_TYPES(__size, BitInt8, __VA_ARGS__) \
83 CHECK_TO_ALL_TYPES(__size, BitInt32, __VA_ARGS__) \
84 CHECK_TO_ALL_TYPES(__size, BitInt128, __VA_ARGS__)
85
86 // The result below is expanded from these macros. Use them to autogenerate the
87 // test cases below.
88 // CHECK_ALL_COMBINATIONS(4, 0, 1, 2, 3);
89 // CHECK_ALL_COMBINATIONS(8, 0, 1, 2, 3, 4, 5, 6, 7);
90
91 constexpr vector4double from_vector4double_to_vector4double_var =
92 __builtin_convertvector((vector4double){0, 1, 2, 3}, vector4double);
93 constexpr vector4float from_vector4double_to_vector4float_var =
94 __builtin_convertvector((vector4double){0, 1, 2, 3}, vector4float);
95 constexpr vector4long from_vector4double_to_vector4long_var =
96 __builtin_convertvector((vector4double){0, 1, 2, 3}, vector4long);
97 constexpr vector4int from_vector4double_to_vector4int_var =
98 __builtin_convertvector((vector4double){0, 1, 2, 3}, vector4int);
99 constexpr vector4short from_vector4double_to_vector4short_var =
100 __builtin_convertvector((vector4double){0, 1, 2, 3}, vector4short);
101 constexpr vector4char from_vector4double_to_vector4char_var =
102 __builtin_convertvector((vector4double){0, 1, 2, 3}, vector4char);
103 constexpr vector4BitInt8 from_vector4double_to_vector4BitInt8_var =
104 __builtin_convertvector((vector4double){0, 1, 2, 3}, vector4BitInt8);
105 constexpr vector4BitInt32 from_vector4double_to_vector4BitInt32_var =
106 __builtin_convertvector((vector4double){0, 1, 2, 3}, vector4BitInt32);
107 constexpr vector4BitInt128 from_vector4double_to_vector4BitInt128_var =
108 __builtin_convertvector((vector4double){0, 1, 2, 3}, vector4BitInt128);
109 static_assert(__builtin_bit_cast(
110 unsigned,
111 __builtin_shufflevector(from_vector4double_to_vector4char_var,
112 from_vector4double_to_vector4char_var,
113 0, 1, 2, 3)) ==
114 (LITTLE_END ? 0x03020100 : 0x00010203));
115 static_assert(__builtin_bit_cast(unsigned long long,
116 __builtin_shufflevector(
117 from_vector4double_to_vector4short_var,
118 from_vector4double_to_vector4short_var, 0,
119 1, 2, 3)) ==
120 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
121 constexpr vector4double from_vector4float_to_vector4double_var =
122 __builtin_convertvector((vector4float){0, 1, 2, 3}, vector4double);
123 constexpr vector4float from_vector4float_to_vector4float_var =
124 __builtin_convertvector((vector4float){0, 1, 2, 3}, vector4float);
125 constexpr vector4long from_vector4float_to_vector4long_var =
126 __builtin_convertvector((vector4float){0, 1, 2, 3}, vector4long);
127 constexpr vector4int from_vector4float_to_vector4int_var =
128 __builtin_convertvector((vector4float){0, 1, 2, 3}, vector4int);
129 constexpr vector4short from_vector4float_to_vector4short_var =
130 __builtin_convertvector((vector4float){0, 1, 2, 3}, vector4short);
131 constexpr vector4char from_vector4float_to_vector4char_var =
132 __builtin_convertvector((vector4float){0, 1, 2, 3}, vector4char);
133 constexpr vector4BitInt8 from_vector4float_to_vector4BitInt8_var =
134 __builtin_convertvector((vector4float){0, 1, 2, 3}, vector4BitInt8);
135 constexpr vector4BitInt32 from_vector4float_to_vector4BitInt32_var =
136 __builtin_convertvector((vector4float){0, 1, 2, 3}, vector4BitInt32);
137 constexpr vector4BitInt128 from_vector4float_to_vector4BitInt128_var =
138 __builtin_convertvector((vector4float){0, 1, 2, 3}, vector4BitInt128);
139 static_assert(__builtin_bit_cast(unsigned,
140 __builtin_shufflevector(
141 from_vector4float_to_vector4char_var,
142 from_vector4float_to_vector4char_var, 0, 1,
143 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203));
144 static_assert(__builtin_bit_cast(
145 unsigned long long,
146 __builtin_shufflevector(from_vector4float_to_vector4short_var,
147 from_vector4float_to_vector4short_var,
148 0, 1, 2, 3)) ==
149 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
150 constexpr vector4double from_vector4long_to_vector4double_var =
151 __builtin_convertvector((vector4long){0, 1, 2, 3}, vector4double);
152 constexpr vector4float from_vector4long_to_vector4float_var =
153 __builtin_convertvector((vector4long){0, 1, 2, 3}, vector4float);
154 constexpr vector4long from_vector4long_to_vector4long_var =
155 __builtin_convertvector((vector4long){0, 1, 2, 3}, vector4long);
156 constexpr vector4int from_vector4long_to_vector4int_var =
157 __builtin_convertvector((vector4long){0, 1, 2, 3}, vector4int);
158 constexpr vector4short from_vector4long_to_vector4short_var =
159 __builtin_convertvector((vector4long){0, 1, 2, 3}, vector4short);
160 constexpr vector4char from_vector4long_to_vector4char_var =
161 __builtin_convertvector((vector4long){0, 1, 2, 3}, vector4char);
162 constexpr vector4BitInt8 from_vector4long_to_vector4BitInt8_var =
163 __builtin_convertvector((vector4long){0, 1, 2, 3}, vector4BitInt8);
164 constexpr vector4BitInt32 from_vector4long_to_vector4BitInt32_var =
165 __builtin_convertvector((vector4long){0, 1, 2, 3}, vector4BitInt32);
166 constexpr vector4BitInt128 from_vector4long_to_vector4BitInt128_var =
167 __builtin_convertvector((vector4long){0, 1, 2, 3}, vector4BitInt128);
168 static_assert(__builtin_bit_cast(unsigned,
169 __builtin_shufflevector(
170 from_vector4long_to_vector4char_var,
171 from_vector4long_to_vector4char_var, 0, 1,
172 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203));
173 static_assert(__builtin_bit_cast(
174 unsigned long long,
175 __builtin_shufflevector(from_vector4long_to_vector4short_var,
176 from_vector4long_to_vector4short_var,
177 0, 1, 2, 3)) ==
178 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
179 constexpr vector4double from_vector4int_to_vector4double_var =
180 __builtin_convertvector((vector4int){0, 1, 2, 3}, vector4double);
181 constexpr vector4float from_vector4int_to_vector4float_var =
182 __builtin_convertvector((vector4int){0, 1, 2, 3}, vector4float);
183 constexpr vector4long from_vector4int_to_vector4long_var =
184 __builtin_convertvector((vector4int){0, 1, 2, 3}, vector4long);
185 constexpr vector4int from_vector4int_to_vector4int_var =
186 __builtin_convertvector((vector4int){0, 1, 2, 3}, vector4int);
187 constexpr vector4short from_vector4int_to_vector4short_var =
188 __builtin_convertvector((vector4int){0, 1, 2, 3}, vector4short);
189 constexpr vector4char from_vector4int_to_vector4char_var =
190 __builtin_convertvector((vector4int){0, 1, 2, 3}, vector4char);
191 constexpr vector4BitInt8 from_vector4int_to_vector4BitInt8_var =
192 __builtin_convertvector((vector4int){0, 1, 2, 3}, vector4BitInt8);
193 constexpr vector4BitInt32 from_vector4int_to_vector4BitInt32_var =
194 __builtin_convertvector((vector4int){0, 1, 2, 3}, vector4BitInt32);
195 constexpr vector4BitInt128 from_vector4int_to_vector4BitInt128_var =
196 __builtin_convertvector((vector4int){0, 1, 2, 3}, vector4BitInt128);
197 static_assert(__builtin_bit_cast(unsigned,
198 __builtin_shufflevector(
199 from_vector4int_to_vector4char_var,
200 from_vector4int_to_vector4char_var, 0, 1,
201 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203));
202 static_assert(__builtin_bit_cast(
203 unsigned long long,
204 __builtin_shufflevector(from_vector4int_to_vector4short_var,
205 from_vector4int_to_vector4short_var,
206 0, 1, 2, 3)) ==
207 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
208 constexpr vector4double from_vector4short_to_vector4double_var =
209 __builtin_convertvector((vector4short){0, 1, 2, 3}, vector4double);
210 constexpr vector4float from_vector4short_to_vector4float_var =
211 __builtin_convertvector((vector4short){0, 1, 2, 3}, vector4float);
212 constexpr vector4long from_vector4short_to_vector4long_var =
213 __builtin_convertvector((vector4short){0, 1, 2, 3}, vector4long);
214 constexpr vector4int from_vector4short_to_vector4int_var =
215 __builtin_convertvector((vector4short){0, 1, 2, 3}, vector4int);
216 constexpr vector4short from_vector4short_to_vector4short_var =
217 __builtin_convertvector((vector4short){0, 1, 2, 3}, vector4short);
218 constexpr vector4char from_vector4short_to_vector4char_var =
219 __builtin_convertvector((vector4short){0, 1, 2, 3}, vector4char);
220 constexpr vector4BitInt8 from_vector4short_to_vector4BitInt8_var =
221 __builtin_convertvector((vector4short){0, 1, 2, 3}, vector4BitInt8);
222 constexpr vector4BitInt32 from_vector4short_to_vector4BitInt32_var =
223 __builtin_convertvector((vector4short){0, 1, 2, 3}, vector4BitInt32);
224 constexpr vector4BitInt128 from_vector4short_to_vector4BitInt128_var =
225 __builtin_convertvector((vector4short){0, 1, 2, 3}, vector4BitInt128);
226 static_assert(__builtin_bit_cast(unsigned,
227 __builtin_shufflevector(
228 from_vector4short_to_vector4char_var,
229 from_vector4short_to_vector4char_var, 0, 1,
230 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203));
231 static_assert(__builtin_bit_cast(
232 unsigned long long,
233 __builtin_shufflevector(from_vector4short_to_vector4short_var,
234 from_vector4short_to_vector4short_var,
235 0, 1, 2, 3)) ==
236 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
237 constexpr vector4double from_vector4char_to_vector4double_var =
238 __builtin_convertvector((vector4char){0, 1, 2, 3}, vector4double);
239 constexpr vector4float from_vector4char_to_vector4float_var =
240 __builtin_convertvector((vector4char){0, 1, 2, 3}, vector4float);
241 constexpr vector4long from_vector4char_to_vector4long_var =
242 __builtin_convertvector((vector4char){0, 1, 2, 3}, vector4long);
243 constexpr vector4int from_vector4char_to_vector4int_var =
244 __builtin_convertvector((vector4char){0, 1, 2, 3}, vector4int);
245 constexpr vector4short from_vector4char_to_vector4short_var =
246 __builtin_convertvector((vector4char){0, 1, 2, 3}, vector4short);
247 constexpr vector4char from_vector4char_to_vector4char_var =
248 __builtin_convertvector((vector4char){0, 1, 2, 3}, vector4char);
249 constexpr vector4BitInt8 from_vector4char_to_vector4BitInt8_var =
250 __builtin_convertvector((vector4char){0, 1, 2, 3}, vector4BitInt8);
251 constexpr vector4BitInt32 from_vector4char_to_vector4BitInt32_var =
252 __builtin_convertvector((vector4char){0, 1, 2, 3}, vector4BitInt32);
253 constexpr vector4BitInt128 from_vector4char_to_vector4BitInt128_var =
254 __builtin_convertvector((vector4char){0, 1, 2, 3}, vector4BitInt128);
255 static_assert(__builtin_bit_cast(unsigned,
256 __builtin_shufflevector(
257 from_vector4char_to_vector4char_var,
258 from_vector4char_to_vector4char_var, 0, 1,
259 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203));
260 static_assert(__builtin_bit_cast(
261 unsigned long long,
262 __builtin_shufflevector(from_vector4char_to_vector4short_var,
263 from_vector4char_to_vector4short_var,
264 0, 1, 2, 3)) ==
265 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
266 constexpr vector4double from_vector4BitInt8_to_vector4double_var =
267 __builtin_convertvector((vector4BitInt8){0, 1, 2, 3}, vector4double);
268 constexpr vector4float from_vector4BitInt8_to_vector4float_var =
269 __builtin_convertvector((vector4BitInt8){0, 1, 2, 3}, vector4float);
270 constexpr vector4long from_vector4BitInt8_to_vector4long_var =
271 __builtin_convertvector((vector4BitInt8){0, 1, 2, 3}, vector4long);
272 constexpr vector4int from_vector4BitInt8_to_vector4int_var =
273 __builtin_convertvector((vector4BitInt8){0, 1, 2, 3}, vector4int);
274 constexpr vector4short from_vector4BitInt8_to_vector4short_var =
275 __builtin_convertvector((vector4BitInt8){0, 1, 2, 3}, vector4short);
276 constexpr vector4char from_vector4BitInt8_to_vector4char_var =
277 __builtin_convertvector((vector4BitInt8){0, 1, 2, 3}, vector4char);
278 constexpr vector4BitInt8 from_vector4BitInt8_to_vector4BitInt8_var =
279 __builtin_convertvector((vector4BitInt8){0, 1, 2, 3}, vector4BitInt8);
280 constexpr vector4BitInt32 from_vector4BitInt8_to_vector4BitInt32_var =
281 __builtin_convertvector((vector4BitInt8){0, 1, 2, 3}, vector4BitInt32);
282 constexpr vector4BitInt128 from_vector4BitInt8_to_vector4BitInt128_var =
283 __builtin_convertvector((vector4BitInt8){0, 1, 2, 3}, vector4BitInt128);
284 static_assert(__builtin_bit_cast(unsigned,
285 __builtin_shufflevector(
286 from_vector4BitInt8_to_vector4char_var,
287 from_vector4BitInt8_to_vector4char_var, 0,
288 1, 2, 3)) ==
289 (LITTLE_END ? 0x03020100 : 0x00010203));
290 static_assert(__builtin_bit_cast(unsigned long long,
291 __builtin_shufflevector(
292 from_vector4BitInt8_to_vector4short_var,
293 from_vector4BitInt8_to_vector4short_var, 0,
294 1, 2, 3)) ==
295 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
296 constexpr vector4double from_vector4BitInt32_to_vector4double_var =
297 __builtin_convertvector((vector4BitInt32){0, 1, 2, 3}, vector4double);
298 constexpr vector4float from_vector4BitInt32_to_vector4float_var =
299 __builtin_convertvector((vector4BitInt32){0, 1, 2, 3}, vector4float);
300 constexpr vector4long from_vector4BitInt32_to_vector4long_var =
301 __builtin_convertvector((vector4BitInt32){0, 1, 2, 3}, vector4long);
302 constexpr vector4int from_vector4BitInt32_to_vector4int_var =
303 __builtin_convertvector((vector4BitInt32){0, 1, 2, 3}, vector4int);
304 constexpr vector4short from_vector4BitInt32_to_vector4short_var =
305 __builtin_convertvector((vector4BitInt32){0, 1, 2, 3}, vector4short);
306 constexpr vector4char from_vector4BitInt32_to_vector4char_var =
307 __builtin_convertvector((vector4BitInt32){0, 1, 2, 3}, vector4char);
308 constexpr vector4BitInt8 from_vector4BitInt32_to_vector4BitInt8_var =
309 __builtin_convertvector((vector4BitInt32){0, 1, 2, 3}, vector4BitInt8);
310 constexpr vector4BitInt32 from_vector4BitInt32_to_vector4BitInt32_var =
311 __builtin_convertvector((vector4BitInt32){0, 1, 2, 3}, vector4BitInt32);
312 constexpr vector4BitInt128 from_vector4BitInt32_to_vector4BitInt128_var =
313 __builtin_convertvector((vector4BitInt32){0, 1, 2, 3}, vector4BitInt128);
314 static_assert(__builtin_bit_cast(unsigned,
315 __builtin_shufflevector(
316 from_vector4BitInt32_to_vector4char_var,
317 from_vector4BitInt32_to_vector4char_var, 0,
318 1, 2, 3)) ==
319 (LITTLE_END ? 0x03020100 : 0x00010203));
320 static_assert(__builtin_bit_cast(unsigned long long,
321 __builtin_shufflevector(
322 from_vector4BitInt32_to_vector4short_var,
323 from_vector4BitInt32_to_vector4short_var,
324 0, 1, 2, 3)) ==
325 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
326 constexpr vector4double from_vector4BitInt128_to_vector4double_var =
327 __builtin_convertvector((vector4BitInt128){0, 1, 2, 3}, vector4double);
328 constexpr vector4float from_vector4BitInt128_to_vector4float_var =
329 __builtin_convertvector((vector4BitInt128){0, 1, 2, 3}, vector4float);
330 constexpr vector4long from_vector4BitInt128_to_vector4long_var =
331 __builtin_convertvector((vector4BitInt128){0, 1, 2, 3}, vector4long);
332 constexpr vector4int from_vector4BitInt128_to_vector4int_var =
333 __builtin_convertvector((vector4BitInt128){0, 1, 2, 3}, vector4int);
334 constexpr vector4short from_vector4BitInt128_to_vector4short_var =
335 __builtin_convertvector((vector4BitInt128){0, 1, 2, 3}, vector4short);
336 constexpr vector4char from_vector4BitInt128_to_vector4char_var =
337 __builtin_convertvector((vector4BitInt128){0, 1, 2, 3}, vector4char);
338 constexpr vector4BitInt8 from_vector4BitInt128_to_vector4BitInt8_var =
339 __builtin_convertvector((vector4BitInt128){0, 1, 2, 3}, vector4BitInt8);
340 constexpr vector4BitInt32 from_vector4BitInt128_to_vector4BitInt32_var =
341 __builtin_convertvector((vector4BitInt128){0, 1, 2, 3}, vector4BitInt32);
342 constexpr vector4BitInt128 from_vector4BitInt128_to_vector4BitInt128_var =
343 __builtin_convertvector((vector4BitInt128){0, 1, 2, 3}, vector4BitInt128);
344 static_assert(__builtin_bit_cast(unsigned,
345 __builtin_shufflevector(
346 from_vector4BitInt128_to_vector4char_var,
347 from_vector4BitInt128_to_vector4char_var,
348 0, 1, 2, 3)) ==
349 (LITTLE_END ? 0x03020100 : 0x00010203));
350 static_assert(__builtin_bit_cast(unsigned long long,
351 __builtin_shufflevector(
352 from_vector4BitInt128_to_vector4short_var,
353 from_vector4BitInt128_to_vector4short_var,
354 0, 1, 2, 3)) ==
355 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
356 ;
357 constexpr vector8double from_vector8double_to_vector8double_var =
358 __builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7},
359 vector8double);
360 constexpr vector8float from_vector8double_to_vector8float_var =
361 __builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7},
362 vector8float);
363 constexpr vector8long from_vector8double_to_vector8long_var =
364 __builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7},
365 vector8long);
366 constexpr vector8int from_vector8double_to_vector8int_var =
367 __builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7},
368 vector8int);
369 constexpr vector8short from_vector8double_to_vector8short_var =
370 __builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7},
371 vector8short);
372 constexpr vector8char from_vector8double_to_vector8char_var =
373 __builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7},
374 vector8char);
375 constexpr vector8BitInt8 from_vector8double_to_vector8BitInt8_var =
376 __builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7},
377 vector8BitInt8);
378 constexpr vector8BitInt32 from_vector8double_to_vector8BitInt32_var =
379 __builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7},
380 vector8BitInt32);
381 constexpr vector8BitInt128 from_vector8double_to_vector8BitInt128_var =
382 __builtin_convertvector((vector8double){0, 1, 2, 3, 4, 5, 6, 7},
383 vector8BitInt128);
384 static_assert(__builtin_bit_cast(
385 unsigned,
386 __builtin_shufflevector(from_vector8double_to_vector8char_var,
387 from_vector8double_to_vector8char_var,
388 0, 1, 2, 3)) ==
389 (LITTLE_END ? 0x03020100 : 0x00010203));
390 static_assert(__builtin_bit_cast(unsigned long long,
391 __builtin_shufflevector(
392 from_vector8double_to_vector8short_var,
393 from_vector8double_to_vector8short_var, 0,
394 1, 2, 3)) ==
395 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
396 constexpr vector8double from_vector8float_to_vector8double_var =
397 __builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7},
398 vector8double);
399 constexpr vector8float from_vector8float_to_vector8float_var =
400 __builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7},
401 vector8float);
402 constexpr vector8long from_vector8float_to_vector8long_var =
403 __builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7},
404 vector8long);
405 constexpr vector8int from_vector8float_to_vector8int_var =
406 __builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7}, vector8int);
407 constexpr vector8short from_vector8float_to_vector8short_var =
408 __builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7},
409 vector8short);
410 constexpr vector8char from_vector8float_to_vector8char_var =
411 __builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7},
412 vector8char);
413 constexpr vector8BitInt8 from_vector8float_to_vector8BitInt8_var =
414 __builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7},
415 vector8BitInt8);
416 constexpr vector8BitInt32 from_vector8float_to_vector8BitInt32_var =
417 __builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7},
418 vector8BitInt32);
419 constexpr vector8BitInt128 from_vector8float_to_vector8BitInt128_var =
420 __builtin_convertvector((vector8float){0, 1, 2, 3, 4, 5, 6, 7},
421 vector8BitInt128);
422 static_assert(__builtin_bit_cast(unsigned,
423 __builtin_shufflevector(
424 from_vector8float_to_vector8char_var,
425 from_vector8float_to_vector8char_var, 0, 1,
426 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203));
427 static_assert(__builtin_bit_cast(
428 unsigned long long,
429 __builtin_shufflevector(from_vector8float_to_vector8short_var,
430 from_vector8float_to_vector8short_var,
431 0, 1, 2, 3)) ==
432 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
433 constexpr vector8double from_vector8long_to_vector8double_var =
434 __builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7},
435 vector8double);
436 constexpr vector8float from_vector8long_to_vector8float_var =
437 __builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7},
438 vector8float);
439 constexpr vector8long from_vector8long_to_vector8long_var =
440 __builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7}, vector8long);
441 constexpr vector8int from_vector8long_to_vector8int_var =
442 __builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7}, vector8int);
443 constexpr vector8short from_vector8long_to_vector8short_var =
444 __builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7},
445 vector8short);
446 constexpr vector8char from_vector8long_to_vector8char_var =
447 __builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7}, vector8char);
448 constexpr vector8BitInt8 from_vector8long_to_vector8BitInt8_var =
449 __builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7},
450 vector8BitInt8);
451 constexpr vector8BitInt32 from_vector8long_to_vector8BitInt32_var =
452 __builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7},
453 vector8BitInt32);
454 constexpr vector8BitInt128 from_vector8long_to_vector8BitInt128_var =
455 __builtin_convertvector((vector8long){0, 1, 2, 3, 4, 5, 6, 7},
456 vector8BitInt128);
457 static_assert(__builtin_bit_cast(unsigned,
458 __builtin_shufflevector(
459 from_vector8long_to_vector8char_var,
460 from_vector8long_to_vector8char_var, 0, 1,
461 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203));
462 static_assert(__builtin_bit_cast(
463 unsigned long long,
464 __builtin_shufflevector(from_vector8long_to_vector8short_var,
465 from_vector8long_to_vector8short_var,
466 0, 1, 2, 3)) ==
467 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
468 constexpr vector8double from_vector8int_to_vector8double_var =
469 __builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7},
470 vector8double);
471 constexpr vector8float from_vector8int_to_vector8float_var =
472 __builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, vector8float);
473 constexpr vector8long from_vector8int_to_vector8long_var =
474 __builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, vector8long);
475 constexpr vector8int from_vector8int_to_vector8int_var =
476 __builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, vector8int);
477 constexpr vector8short from_vector8int_to_vector8short_var =
478 __builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, vector8short);
479 constexpr vector8char from_vector8int_to_vector8char_var =
480 __builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7}, vector8char);
481 constexpr vector8BitInt8 from_vector8int_to_vector8BitInt8_var =
482 __builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7},
483 vector8BitInt8);
484 constexpr vector8BitInt32 from_vector8int_to_vector8BitInt32_var =
485 __builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7},
486 vector8BitInt32);
487 constexpr vector8BitInt128 from_vector8int_to_vector8BitInt128_var =
488 __builtin_convertvector((vector8int){0, 1, 2, 3, 4, 5, 6, 7},
489 vector8BitInt128);
490 static_assert(__builtin_bit_cast(unsigned,
491 __builtin_shufflevector(
492 from_vector8int_to_vector8char_var,
493 from_vector8int_to_vector8char_var, 0, 1,
494 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203));
495 static_assert(__builtin_bit_cast(
496 unsigned long long,
497 __builtin_shufflevector(from_vector8int_to_vector8short_var,
498 from_vector8int_to_vector8short_var,
499 0, 1, 2, 3)) ==
500 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
501 constexpr vector8double from_vector8short_to_vector8double_var =
502 __builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7},
503 vector8double);
504 constexpr vector8float from_vector8short_to_vector8float_var =
505 __builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7},
506 vector8float);
507 constexpr vector8long from_vector8short_to_vector8long_var =
508 __builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7},
509 vector8long);
510 constexpr vector8int from_vector8short_to_vector8int_var =
511 __builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7}, vector8int);
512 constexpr vector8short from_vector8short_to_vector8short_var =
513 __builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7},
514 vector8short);
515 constexpr vector8char from_vector8short_to_vector8char_var =
516 __builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7},
517 vector8char);
518 constexpr vector8BitInt8 from_vector8short_to_vector8BitInt8_var =
519 __builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7},
520 vector8BitInt8);
521 constexpr vector8BitInt32 from_vector8short_to_vector8BitInt32_var =
522 __builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7},
523 vector8BitInt32);
524 constexpr vector8BitInt128 from_vector8short_to_vector8BitInt128_var =
525 __builtin_convertvector((vector8short){0, 1, 2, 3, 4, 5, 6, 7},
526 vector8BitInt128);
527 static_assert(__builtin_bit_cast(unsigned,
528 __builtin_shufflevector(
529 from_vector8short_to_vector8char_var,
530 from_vector8short_to_vector8char_var, 0, 1,
531 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203));
532 static_assert(__builtin_bit_cast(
533 unsigned long long,
534 __builtin_shufflevector(from_vector8short_to_vector8short_var,
535 from_vector8short_to_vector8short_var,
536 0, 1, 2, 3)) ==
537 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
538 constexpr vector8double from_vector8char_to_vector8double_var =
539 __builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7},
540 vector8double);
541 constexpr vector8float from_vector8char_to_vector8float_var =
542 __builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7},
543 vector8float);
544 constexpr vector8long from_vector8char_to_vector8long_var =
545 __builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7}, vector8long);
546 constexpr vector8int from_vector8char_to_vector8int_var =
547 __builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7}, vector8int);
548 constexpr vector8short from_vector8char_to_vector8short_var =
549 __builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7},
550 vector8short);
551 constexpr vector8char from_vector8char_to_vector8char_var =
552 __builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7}, vector8char);
553 constexpr vector8BitInt8 from_vector8char_to_vector8BitInt8_var =
554 __builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7},
555 vector8BitInt8);
556 constexpr vector8BitInt32 from_vector8char_to_vector8BitInt32_var =
557 __builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7},
558 vector8BitInt32);
559 constexpr vector8BitInt128 from_vector8char_to_vector8BitInt128_var =
560 __builtin_convertvector((vector8char){0, 1, 2, 3, 4, 5, 6, 7},
561 vector8BitInt128);
562 static_assert(__builtin_bit_cast(unsigned,
563 __builtin_shufflevector(
564 from_vector8char_to_vector8char_var,
565 from_vector8char_to_vector8char_var, 0, 1,
566 2, 3)) == (LITTLE_END ? 0x03020100 : 0x00010203));
567 static_assert(__builtin_bit_cast(
568 unsigned long long,
569 __builtin_shufflevector(from_vector8char_to_vector8short_var,
570 from_vector8char_to_vector8short_var,
571 0, 1, 2, 3)) ==
572 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
573 constexpr vector8double from_vector8BitInt8_to_vector8double_var =
574 __builtin_convertvector((vector8BitInt8){0, 1, 2, 3, 4, 5, 6, 7},
575 vector8double);
576 constexpr vector8float from_vector8BitInt8_to_vector8float_var =
577 __builtin_convertvector((vector8BitInt8){0, 1, 2, 3, 4, 5, 6, 7},
578 vector8float);
579 constexpr vector8long from_vector8BitInt8_to_vector8long_var =
580 __builtin_convertvector((vector8BitInt8){0, 1, 2, 3, 4, 5, 6, 7},
581 vector8long);
582 constexpr vector8int from_vector8BitInt8_to_vector8int_var =
583 __builtin_convertvector((vector8BitInt8){0, 1, 2, 3, 4, 5, 6, 7},
584 vector8int);
585 constexpr vector8short from_vector8BitInt8_to_vector8short_var =
586 __builtin_convertvector((vector8BitInt8){0, 1, 2, 3, 4, 5, 6, 7},
587 vector8short);
588 constexpr vector8char from_vector8BitInt8_to_vector8char_var =
589 __builtin_convertvector((vector8BitInt8){0, 1, 2, 3, 4, 5, 6, 7},
590 vector8char);
591 constexpr vector8BitInt8 from_vector8BitInt8_to_vector8BitInt8_var =
592 __builtin_convertvector((vector8BitInt8){0, 1, 2, 3, 4, 5, 6, 7},
593 vector8BitInt8);
594 constexpr vector8BitInt32 from_vector8BitInt8_to_vector8BitInt32_var =
595 __builtin_convertvector((vector8BitInt8){0, 1, 2, 3, 4, 5, 6, 7},
596 vector8BitInt32);
597 constexpr vector8BitInt128 from_vector8BitInt8_to_vector8BitInt128_var =
598 __builtin_convertvector((vector8BitInt8){0, 1, 2, 3, 4, 5, 6, 7},
599 vector8BitInt128);
600 static_assert(__builtin_bit_cast(unsigned,
601 __builtin_shufflevector(
602 from_vector8BitInt8_to_vector8char_var,
603 from_vector8BitInt8_to_vector8char_var, 0,
604 1, 2, 3)) ==
605 (LITTLE_END ? 0x03020100 : 0x00010203));
606 static_assert(__builtin_bit_cast(unsigned long long,
607 __builtin_shufflevector(
608 from_vector8BitInt8_to_vector8short_var,
609 from_vector8BitInt8_to_vector8short_var, 0,
610 1, 2, 3)) ==
611 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
612 constexpr vector8double from_vector8BitInt32_to_vector8double_var =
613 __builtin_convertvector((vector8BitInt32){0, 1, 2, 3, 4, 5, 6, 7},
614 vector8double);
615 constexpr vector8float from_vector8BitInt32_to_vector8float_var =
616 __builtin_convertvector((vector8BitInt32){0, 1, 2, 3, 4, 5, 6, 7},
617 vector8float);
618 constexpr vector8long from_vector8BitInt32_to_vector8long_var =
619 __builtin_convertvector((vector8BitInt32){0, 1, 2, 3, 4, 5, 6, 7},
620 vector8long);
621 constexpr vector8int from_vector8BitInt32_to_vector8int_var =
622 __builtin_convertvector((vector8BitInt32){0, 1, 2, 3, 4, 5, 6, 7},
623 vector8int);
624 constexpr vector8short from_vector8BitInt32_to_vector8short_var =
625 __builtin_convertvector((vector8BitInt32){0, 1, 2, 3, 4, 5, 6, 7},
626 vector8short);
627 constexpr vector8char from_vector8BitInt32_to_vector8char_var =
628 __builtin_convertvector((vector8BitInt32){0, 1, 2, 3, 4, 5, 6, 7},
629 vector8char);
630 constexpr vector8BitInt8 from_vector8BitInt32_to_vector8BitInt8_var =
631 __builtin_convertvector((vector8BitInt32){0, 1, 2, 3, 4, 5, 6, 7},
632 vector8BitInt8);
633 constexpr vector8BitInt32 from_vector8BitInt32_to_vector8BitInt32_var =
634 __builtin_convertvector((vector8BitInt32){0, 1, 2, 3, 4, 5, 6, 7},
635 vector8BitInt32);
636 constexpr vector8BitInt128 from_vector8BitInt32_to_vector8BitInt128_var =
637 __builtin_convertvector((vector8BitInt32){0, 1, 2, 3, 4, 5, 6, 7},
638 vector8BitInt128);
639 static_assert(__builtin_bit_cast(unsigned,
640 __builtin_shufflevector(
641 from_vector8BitInt32_to_vector8char_var,
642 from_vector8BitInt32_to_vector8char_var, 0,
643 1, 2, 3)) ==
644 (LITTLE_END ? 0x03020100 : 0x00010203));
645 static_assert(__builtin_bit_cast(unsigned long long,
646 __builtin_shufflevector(
647 from_vector8BitInt32_to_vector8short_var,
648 from_vector8BitInt32_to_vector8short_var,
649 0, 1, 2, 3)) ==
650 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
651 constexpr vector8double from_vector8BitInt128_to_vector8double_var =
652 __builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7},
653 vector8double);
654 constexpr vector8float from_vector8BitInt128_to_vector8float_var =
655 __builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7},
656 vector8float);
657 constexpr vector8long from_vector8BitInt128_to_vector8long_var =
658 __builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7},
659 vector8long);
660 constexpr vector8int from_vector8BitInt128_to_vector8int_var =
661 __builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7},
662 vector8int);
663 constexpr vector8short from_vector8BitInt128_to_vector8short_var =
664 __builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7},
665 vector8short);
666 constexpr vector8char from_vector8BitInt128_to_vector8char_var =
667 __builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7},
668 vector8char);
669 constexpr vector8BitInt8 from_vector8BitInt128_to_vector8BitInt8_var =
670 __builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7},
671 vector8BitInt8);
672 constexpr vector8BitInt32 from_vector8BitInt128_to_vector8BitInt32_var =
673 __builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7},
674 vector8BitInt32);
675 constexpr vector8BitInt128 from_vector8BitInt128_to_vector8BitInt128_var =
676 __builtin_convertvector((vector8BitInt128){0, 1, 2, 3, 4, 5, 6, 7},
677 vector8BitInt128);
678 static_assert(__builtin_bit_cast(unsigned,
679 __builtin_shufflevector(
680 from_vector8BitInt128_to_vector8char_var,
681 from_vector8BitInt128_to_vector8char_var,
682 0, 1, 2, 3)) ==
683 (LITTLE_END ? 0x03020100 : 0x00010203));
684 static_assert(__builtin_bit_cast(unsigned long long,
685 __builtin_shufflevector(
686 from_vector8BitInt128_to_vector8short_var,
687 from_vector8BitInt128_to_vector8short_var,
688 0, 1, 2, 3)) ==
689 (LITTLE_END ? 0x0003000200010000 : 0x0000000100020003));
690 ;
691 #undef CHECK_ALL_COMBINATIONS
692 #undef CHECK_TO_ALL_TYPES
693 #undef CHECK_NUM
694
695 // Shuffle vector
696 constexpr vector4char vector4charConst1 = {0, 1, 2, 3};
697 constexpr vector4char vector4charConst2 = {4, 5, 6, 7};
698 constexpr vector8char vector8intConst = {8, 9, 10, 11, 12, 13, 14, 15};
699
700 constexpr vector4char vectorShuffle1 =
701 __builtin_shufflevector(vector4charConst1, vector4charConst2, 0, 1, 2, 3);
702 static_assert(__builtin_bit_cast(unsigned, vectorShuffle1) ==
703 (LITTLE_END ? 0x03020100 : 0x00010203));
704 constexpr vector4char vectorShuffle2 =
705 __builtin_shufflevector(vector4charConst1, vector4charConst2, 4, 5, 6, 7);
706 static_assert(__builtin_bit_cast(unsigned, vectorShuffle2) ==
707 (LITTLE_END ? 0x07060504 : 0x04050607));
708 constexpr vector4char vectorShuffle3 =
709 __builtin_shufflevector(vector4charConst1, vector4charConst2, 0, 2, 4, 6);
710 static_assert(__builtin_bit_cast(unsigned, vectorShuffle3) ==
711 (LITTLE_END ? 0x06040200 : 0x00020406));
712 constexpr vector8char vectorShuffle4 = __builtin_shufflevector(
713 vector8intConst, vector8intConst, 0, 2, 4, 6, 8, 10, 12, 14);
714 static_assert(__builtin_bit_cast(unsigned long long, vectorShuffle4) ==
715 (LITTLE_END ? 0x0E0C0A080E0C0A08 : 0x080A0C0E080A0C0E));
716 constexpr vector4char vectorShuffle5 =
717 __builtin_shufflevector(vector8intConst, vector8intConst, 0, 2, 4, 6);
718 static_assert(__builtin_bit_cast(unsigned, vectorShuffle5) ==
719 (LITTLE_END ? 0x0E0C0A08 : 0x080A0C0E));
720 constexpr vector8char vectorShuffle6 = __builtin_shufflevector(
721 vector4charConst1, vector4charConst2, 0, 2, 4, 6, 1, 3, 5, 7);
722 static_assert(__builtin_bit_cast(unsigned long long, vectorShuffle6) ==
723 (LITTLE_END ? 0x0705030106040200 : 0x0002040601030507));
724
725 constexpr vector4char
726 vectorShuffleFail1 = // expected-error {{constexpr variable 'vectorShuffleFail1'\
727 must be initialized by a constant expression}}
728 __builtin_shufflevector( // expected-error {{index for __builtin_shufflevector \
729 not within the bounds of the input vectors; index of -1 found at position 0 is not \
730 permitted in a constexpr context}}
731 vector4charConst1,
732 vector4charConst2, -1, -1, -1, -1);
733
734 namespace UnaryShuffleUnsupported {
735 typedef int vi6 __attribute__((ext_vector_type(2)));
736 constexpr int foo() { // expected-error {{never produces a constant expression}}
737 vi6 a = {1,2};
738 vi6 b = {3,4};
739 vi6 r = __builtin_shufflevector(a, b); // expected-note 2{{subexpression not valid in a constant expression}}
740
741 return r[0] + r[1];
742 }
743 static_assert(foo() == 0); // expected-error {{not an integral constant expression}} \
744 // expected-note {{in call to}}
745 }
746
747 static_assert(__builtin_reduce_add((vector4char){}) == 0);
748 static_assert(__builtin_reduce_add((vector4char){1, 2, 3, 4}) == 10);
749 static_assert(__builtin_reduce_add((vector4short){10, 20, 30, 40}) == 100);
750 static_assert(__builtin_reduce_add((vector4int){100, 200, 300, 400}) == 1000);
751 static_assert(__builtin_reduce_add((vector4long){1000, 2000, 3000, 4000}) == 10000);
752 constexpr int reduceAddInt1 = __builtin_reduce_add((vector4int){~(1 << 31), 0, 0, 1});
753 // expected-error@-1 {{must be initialized by a constant expression}} \
754 // expected-note@-1 {{outside the range of representable values of type 'int'}}
755 constexpr long long reduceAddLong1 = __builtin_reduce_add((vector4long){~(1LL << 63), 0, 0, 1});
756 // expected-error@-1 {{must be initialized by a constant expression}} \
757 // expected-note@-1 {{outside the range of representable values of type 'long long'}}
758 constexpr int reduceAddInt2 = __builtin_reduce_add((vector4int){(1 << 31), 0, 0, -1});
759 // expected-error@-1 {{must be initialized by a constant expression}} \
760 // expected-note@-1 {{outside the range of representable values of type 'int'}}
761 constexpr long long reduceAddLong2 = __builtin_reduce_add((vector4long){(1LL << 63), 0, 0, -1});
762 // expected-error@-1 {{must be initialized by a constant expression}} \
763 // expected-note@-1 {{outside the range of representable values of type 'long long'}}
764 static_assert(__builtin_reduce_add((vector4uint){~0U, 0, 0, 1}) == 0);
765 static_assert(__builtin_reduce_add((vector4ulong){~0ULL, 0, 0, 1}) == 0);
766
767 static_assert(__builtin_reduce_mul((vector4char){}) == 0);
768 static_assert(__builtin_reduce_mul((vector4char){1, 2, 3, 4}) == 24);
769 static_assert(__builtin_reduce_mul((vector4short){1, 2, 30, 40}) == 2400);
770 static_assert(__builtin_reduce_mul((vector4int){10, 20, 300, 400}) == 24000000);
771 static_assert(__builtin_reduce_mul((vector4long){1000L, 2000L, 3000L, 4000L}) == 24000000000000L);
772 constexpr int reduceMulInt1 = __builtin_reduce_mul((vector4int){~(1 << 31), 1, 1, 2});
773 // expected-error@-1 {{must be initialized by a constant expression}} \
774 // expected-note@-1 {{outside the range of representable values of type 'int'}}
775 constexpr long long reduceMulLong1 = __builtin_reduce_mul((vector4long){~(1LL << 63), 1, 1, 2});
776 // expected-error@-1 {{must be initialized by a constant expression}} \
777 // expected-note@-1 {{outside the range of representable values of type 'long long'}}
778 constexpr int reduceMulInt2 = __builtin_reduce_mul((vector4int){(1 << 31), 1, 1, 2});
779 // expected-error@-1 {{must be initialized by a constant expression}} \
780 // expected-note@-1 {{outside the range of representable values of type 'int'}}
781 constexpr long long reduceMulLong2 = __builtin_reduce_mul((vector4long){(1LL << 63), 1, 1, 2});
782 // expected-error@-1 {{must be initialized by a constant expression}} \
783 // expected-note@-1 {{outside the range of representable values of type 'long long'}}
784 static_assert(__builtin_reduce_mul((vector4uint){~0U, 1, 1, 2}) == ~0U - 1);
785 static_assert(__builtin_reduce_mul((vector4ulong){~0ULL, 1, 1, 2}) == ~0ULL - 1);
786
787 static_assert(__builtin_reduce_and((vector4char){}) == 0);
788 static_assert(__builtin_reduce_and((vector4char){(char)0x11, (char)0x22, (char)0x44, (char)0x88}) == 0);
789 static_assert(__builtin_reduce_and((vector4short){(short)0x1111, (short)0x2222, (short)0x4444, (short)0x8888}) == 0);
790 static_assert(__builtin_reduce_and((vector4int){(int)0x11111111, (int)0x22222222, (int)0x44444444, (int)0x88888888}) == 0);
791 static_assert(__builtin_reduce_and((vector4long){(long long)0x1111111111111111L, (long long)0x2222222222222222L, (long long)0x4444444444444444L, (long long)0x8888888888888888L}) == 0L);
792 static_assert(__builtin_reduce_and((vector4char){(char)-1, (char)~0x22, (char)~0x44, (char)~0x88}) == 0x11);
793 static_assert(__builtin_reduce_and((vector4short){(short)~0x1111, (short)-1, (short)~0x4444, (short)~0x8888}) == 0x2222);
794 static_assert(__builtin_reduce_and((vector4int){(int)~0x11111111, (int)~0x22222222, (int)-1, (int)~0x88888888}) == 0x44444444);
795 static_assert(__builtin_reduce_and((vector4long){(long long)~0x1111111111111111L, (long long)~0x2222222222222222L, (long long)~0x4444444444444444L, (long long)-1}) == 0x8888888888888888L);
796 static_assert(__builtin_reduce_and((vector4uint){0x11111111U, 0x22222222U, 0x44444444U, 0x88888888U}) == 0U);
797 static_assert(__builtin_reduce_and((vector4ulong){0x1111111111111111UL, 0x2222222222222222UL, 0x4444444444444444UL, 0x8888888888888888UL}) == 0L);
798
799 static_assert(__builtin_reduce_or((vector4char){}) == 0);
800 static_assert(__builtin_reduce_or((vector4char){(char)0x11, (char)0x22, (char)0x44, (char)0x88}) == (char)0xFF);
801 static_assert(__builtin_reduce_or((vector4short){(short)0x1111, (short)0x2222, (short)0x4444, (short)0x8888}) == (short)0xFFFF);
802 static_assert(__builtin_reduce_or((vector4int){(int)0x11111111, (int)0x22222222, (int)0x44444444, (int)0x88888888}) == (int)0xFFFFFFFF);
803 static_assert(__builtin_reduce_or((vector4long){(long long)0x1111111111111111L, (long long)0x2222222222222222L, (long long)0x4444444444444444L, (long long)0x8888888888888888L}) == (long long)0xFFFFFFFFFFFFFFFFL);
804 static_assert(__builtin_reduce_or((vector4char){(char)0, (char)0x22, (char)0x44, (char)0x88}) == ~0x11);
805 static_assert(__builtin_reduce_or((vector4short){(short)0x1111, (short)0, (short)0x4444, (short)0x8888}) == ~0x2222);
806 static_assert(__builtin_reduce_or((vector4int){(int)0x11111111, (int)0x22222222, (int)0, (int)0x88888888}) == ~0x44444444);
807 static_assert(__builtin_reduce_or((vector4long){(long long)0x1111111111111111L, (long long)0x2222222222222222L, (long long)0x4444444444444444L, (long long)0}) == ~0x8888888888888888L);
808 static_assert(__builtin_reduce_or((vector4uint){0x11111111U, 0x22222222U, 0x44444444U, 0x88888888U}) == 0xFFFFFFFFU);
809 static_assert(__builtin_reduce_or((vector4ulong){0x1111111111111111UL, 0x2222222222222222UL, 0x4444444444444444UL, 0x8888888888888888UL}) == 0xFFFFFFFFFFFFFFFFL);
810
811 static_assert(__builtin_reduce_xor((vector4char){}) == 0);
812 static_assert(__builtin_reduce_xor((vector4char){(char)0x11, (char)0x22, (char)0x44, (char)0x88}) == (char)0xFF);
813 static_assert(__builtin_reduce_xor((vector4short){(short)0x1111, (short)0x2222, (short)0x4444, (short)0x8888}) == (short)0xFFFF);
814 static_assert(__builtin_reduce_xor((vector4int){(int)0x11111111, (int)0x22222222, (int)0x44444444, (int)0x88888888}) == (int)0xFFFFFFFF);
815 static_assert(__builtin_reduce_xor((vector4long){(long long)0x1111111111111111L, (long long)0x2222222222222222L, (long long)0x4444444444444444L, (long long)0x8888888888888888L}) == (long long)0xFFFFFFFFFFFFFFFFL);
816 static_assert(__builtin_reduce_xor((vector4uint){0x11111111U, 0x22222222U, 0x44444444U, 0x88888888U}) == 0xFFFFFFFFU);
817 static_assert(__builtin_reduce_xor((vector4ulong){0x1111111111111111UL, 0x2222222222222222UL, 0x4444444444444444UL, 0x8888888888888888UL}) == 0xFFFFFFFFFFFFFFFFUL);
818
819 static_assert(__builtin_reduce_min((vector4char){}) == 0);
820 static_assert(__builtin_reduce_min((vector4char){(char)0x11, (char)0x22, (char)0x44, (char)0x88}) == (char)0x88);
821 static_assert(__builtin_reduce_min((vector4short){(short)0x1111, (short)0x2222, (short)0x4444, (short)0x8888}) == (short)0x8888);
822 static_assert(__builtin_reduce_min((vector4int){(int)0x11111111, (int)0x22222222, (int)0x44444444, (int)0x88888888}) == (int)0x88888888);
823 static_assert(__builtin_reduce_min((vector4long){(long long)0x1111111111111111L, (long long)0x2222222222222222L, (long long)0x4444444444444444L, (long long)0x8888888888888888L}) == (long long)0x8888888888888888L);
824 static_assert(__builtin_reduce_min((vector4uint){0x11111111U, 0x22222222U, 0x44444444U, 0x88888888U}) == 0x11111111U);
825 static_assert(__builtin_reduce_min((vector4ulong){0x1111111111111111UL, 0x2222222222222222UL, 0x4444444444444444UL, 0x8888888888888888UL}) == 0x1111111111111111UL);
826 static_assert(__builtin_reduce_max((vector4char){}) == 0);
827 static_assert(__builtin_reduce_max((vector4char){(char)0x11, (char)0x22, (char)0x44, (char)0x88}) == (char)0x44);
828 static_assert(__builtin_reduce_max((vector4short){(short)0x1111, (short)0x2222, (short)0x4444, (short)0x8888}) == (short)0x4444);
829 static_assert(__builtin_reduce_max((vector4int){(int)0x11111111, (int)0x22222222, (int)0x44444444, (int)0x88888888}) == (int)0x44444444);
830 static_assert(__builtin_reduce_max((vector4long){(long long)0x1111111111111111L, (long long)0x2222222222222222L, (long long)0x4444444444444444L, (long long)0x8888888888888888L}) == (long long)0x4444444444444444L);
831 static_assert(__builtin_reduce_max((vector4uint){0x11111111U, 0x22222222U, 0x44444444U, 0x88888888U}) == 0x88888888U);
832 static_assert(__builtin_reduce_max((vector4ulong){0x1111111111111111UL, 0x2222222222222222UL, 0x4444444444444444UL, 0x8888888888888888UL}) == 0x8888888888888888UL);
833
834 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_popcount((vector4char){1, 2, 3, 4})) == (LITTLE_END ? 0x01020101 : 0x01010201));
835 static_assert(__builtin_bit_cast(unsigned long long, __builtin_elementwise_popcount((vector4short){0, 0x0F0F, ~0, ~0x0F0F})) == (LITTLE_END ? 0x0008001000080000 : 0x0000000800100008));
836 static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4int){1, 2, 3, 4})) == 5);
837 static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4int){0, 0xF0F0, ~0, ~0xF0F0})) == 16 * sizeof(int));
838 static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4long){1L, 2L, 3L, 4L})) == 5L);
839 static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4long){0L, 0xF0F0L, ~0L, ~0xF0F0L})) == 16 * sizeof(long long));
840 static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4uint){1U, 2U, 3U, 4U})) == 5U);
841 static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4uint){0U, 0xF0F0U, ~0U, ~0xF0F0U})) == 16 * sizeof(int));
842 static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4ulong){1UL, 2UL, 3UL, 4UL})) == 5UL);
843 static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4ulong){0ULL, 0xF0F0ULL, ~0ULL, ~0xF0F0ULL})) == 16 * sizeof(unsigned long long));
844 static_assert(__builtin_elementwise_popcount(0) == 0);
845 static_assert(__builtin_elementwise_popcount(0xF0F0) == 8);
846 static_assert(__builtin_elementwise_popcount(~0) == 8 * sizeof(int));
847 static_assert(__builtin_elementwise_popcount(0U) == 0);
848 static_assert(__builtin_elementwise_popcount(0xF0F0U) == 8);
849 static_assert(__builtin_elementwise_popcount(~0U) == 8 * sizeof(int));
850 static_assert(__builtin_elementwise_popcount(0L) == 0);
851 static_assert(__builtin_elementwise_popcount(0xF0F0L) == 8);
852 static_assert(__builtin_elementwise_popcount(~0LL) == 8 * sizeof(long long));
853
854 static_assert(__builtin_elementwise_bitreverse(0x12345678) == 0x1E6A2C48);
855 static_assert(__builtin_elementwise_bitreverse(0x0123456789ABCDEFULL) == 0xF7B3D591E6A2C480);
856 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_bitreverse((vector4char){1, 2, 4, 8})) == (LITTLE_END ? 0x10204080 : 0x80402010));
857 static_assert(__builtin_bit_cast(unsigned long long, __builtin_elementwise_bitreverse((vector4short){1, 2, 4, 8})) == (LITTLE_END ? 0x1000200040008000 : 0x8000400020001000));
858
859 static_assert(__builtin_elementwise_add_sat(1, 2) == 3);
860 static_assert(__builtin_elementwise_add_sat(1U, 2U) == 3U);
861 static_assert(__builtin_elementwise_add_sat(~(1 << 31), 42) == ~(1 << 31));
862 static_assert(__builtin_elementwise_add_sat((1 << 31), -42) == (1 << 31));
863 static_assert(__builtin_elementwise_add_sat(~0U, 1U) == ~0U);
864 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_add_sat((vector4char){1, 2, 3, 4}, (vector4char){1, 2, 3, 4})) == (LITTLE_END ? 0x08060402 : 0x02040608));
865 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_add_sat((vector4uchar){1, 2, 3, 4}, (vector4uchar){0, 1, 2, 3})) == (LITTLE_END ? 0x07050301U : 0x01030507U));
866 static_assert(__builtin_bit_cast(unsigned long long, __builtin_elementwise_add_sat((vector4short){(short)0x8000, (short)0x8001, (short)0x8002, (short)0x8003}, (vector4short){-7, -8, -9, -10}) == (LITTLE_END ? 0x8000800080008000 : 0x8000800080008000)));
867
868 static_assert(__builtin_elementwise_sub_sat(1, 2) == -1);
869 static_assert(__builtin_elementwise_sub_sat(2U, 1U) == 1U);
870 static_assert(__builtin_elementwise_sub_sat(~(1 << 31), -42) == ~(1 << 31));
871 static_assert(__builtin_elementwise_sub_sat((1 << 31), 42) == (1 << 31));
872 static_assert(__builtin_elementwise_sub_sat(0U, 1U) == 0U);
873 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_sub_sat((vector4char){5, 4, 3, 2}, (vector4char){1, 1, 1, 1})) == (LITTLE_END ? 0x01020304 : 0x04030201));
874 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_sub_sat((vector4uchar){5, 4, 3, 2}, (vector4uchar){1, 1, 1, 1})) == (LITTLE_END ? 0x01020304U : 0x04030201U));
875 static_assert(__builtin_bit_cast(unsigned long long, __builtin_elementwise_sub_sat((vector4short){(short)0x8000, (short)0x8001, (short)0x8002, (short)0x8003}, (vector4short){7, 8, 9, 10}) == (LITTLE_END ? 0x8000800080008000 : 0x8000800080008000)));
876
877 static_assert(__builtin_elementwise_max(1, 2) == 2);
878 static_assert(__builtin_elementwise_max(-1, 1) == 1);
879 static_assert(__builtin_elementwise_max(1U, 2U) == 2U);
880 static_assert(__builtin_elementwise_max(~0U, 0U) == ~0U);
881 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_max((vector4char){1, -2, 3, -4}, (vector4char){4, -3, 2, -1})) == (LITTLE_END ? 0xFF03FE04 : 0x04FE03FF ));
882 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_max((vector4uchar){1, 2, 3, 4}, (vector4uchar){4, 3, 2, 1})) == 0x04030304U);
883 static_assert(__builtin_bit_cast(unsigned long long, __builtin_elementwise_max((vector4short){1, -2, 3, -4}, (vector4short){4, -3, 2, -1})) == (LITTLE_END ? 0xFFFF0003FFFE0004 : 0x0004FFFE0003FFFF));
884
885 static_assert(__builtin_elementwise_min(1, 2) == 1);
886 static_assert(__builtin_elementwise_min(-1, 1) == -1);
887 static_assert(__builtin_elementwise_min(1U, 2U) == 1U);
888 static_assert(__builtin_elementwise_min(~0U, 0U) == 0U);
889 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_min((vector4char){1, -2, 3, -4}, (vector4char){4, -3, 2, -1})) == (LITTLE_END ? 0xFC02FD01 : 0x01FD02FC));
890 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_min((vector4uchar){1, 2, 3, 4}, (vector4uchar){4, 3, 2, 1})) == 0x01020201U);
891 static_assert(__builtin_bit_cast(unsigned long long, __builtin_elementwise_min((vector4short){1, -2, 3, -4}, (vector4short){4, -3, 2, -1})) == (LITTLE_END ? 0xFFFC0002FFFD0001 : 0x0001FFFD0002FFFC));
892
893 static_assert(__builtin_elementwise_abs(10) == 10);
894 static_assert(__builtin_elementwise_abs(-10) == 10);
895 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_abs((vector4char){-1, -2, -3, 4})) == (LITTLE_END ? 0x04030201 : 0x01020304));
896 static_assert(__builtin_elementwise_abs((int)(-2147483648)) == (int)(-2147483648)); // the absolute value of the most negative integer remains the most negative integer
897
898 // check floating point for elementwise abs
899 #define CHECK_FOUR_FLOAT_VEC(vec1, vec2) \
900 static_assert(__builtin_fabs(vec1[0] - vec2[0]) < 1e-6); \
901 static_assert(__builtin_fabs(vec1[1] - vec2[1]) < 1e-6); \
902 static_assert(__builtin_fabs(vec1[2] - vec2[2]) < 1e-6); \
903 static_assert(__builtin_fabs(vec1[3] - vec2[3]) < 1e-6);
904
905 // checking floating point vector
906 CHECK_FOUR_FLOAT_VEC(__builtin_elementwise_abs((vector4float){-1.123, 2.123, -3.123, 4.123}), ((vector4float){1.123, 2.123, 3.123, 4.123}))
907 CHECK_FOUR_FLOAT_VEC(__builtin_elementwise_abs((vector4double){-1.123, 2.123, -3.123, 4.123}), ((vector4double){1.123, 2.123, 3.123, 4.123}))
908 static_assert(__builtin_elementwise_abs((float)-1.123) - (float)1.123 < 1e-6); // making sure one element works
909 #undef CHECK_FOUR_FLOAT_VEC
910
911 static_assert(__builtin_elementwise_clzg(2) == 30);
912 static_assert(__builtin_elementwise_clzg(2, 8) == 30);
913 static_assert(__builtin_elementwise_clzg(0, 8) == 8);
914 static_assert(__builtin_elementwise_clzg(0, 0) == 0);
915 static_assert(__builtin_elementwise_clzg((char)2) == 6);
916 static_assert(__builtin_elementwise_clzg((short)2) == 14);
917 static_assert(__builtin_elementwise_clzg((char)1) == 0x7);
918 static_assert(__builtin_elementwise_clzg((char)4) == 0x5);
919 static_assert(__builtin_elementwise_clzg((char)127) == 0x1);
920 static_assert(__builtin_elementwise_clzg((char)128) == 0x0);
921 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_clzg((vector4char){1, 4, 127, (char)128})) == (LITTLE_END ? 0x00010507 : 0x07050100));
922
923 constexpr int clz0 = __builtin_elementwise_clzg(0);
924 // expected-error@-1 {{must be initialized by a constant expression}} \
925 // expected-note@-1 {{evaluation of __builtin_elementwise_clzg with a zero value is undefined}}
926 constexpr vector4char clz1 = __builtin_elementwise_clzg((vector4char){1, 0, 3, 4});
927 // expected-error@-1 {{must be initialized by a constant expression}} \
928 // expected-note@-1 {{evaluation of __builtin_elementwise_clzg with a zero value is undefined}}
929 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_clzg((vector4char){1, 0, 127, 0}, (vector4char){9, -1, 9, -2})) == (LITTLE_END ? 0xFE01FF07 : 0x07FF01FE));
930 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_clzg((vector4char){0, 0, 0, 0}, (vector4char){0, 0, 0, 0})) == 0);
931
932 static_assert(__builtin_elementwise_ctzg(2) == 1);
933 static_assert(__builtin_elementwise_ctzg(2, 8) == 1);
934 static_assert(__builtin_elementwise_ctzg(0, 8) == 8);
935 static_assert(__builtin_elementwise_ctzg(0, 0) == 0);
936 static_assert(__builtin_elementwise_ctzg((char)2) == 1);
937 static_assert(__builtin_elementwise_ctzg((short)2) == 1);
938 static_assert(__builtin_elementwise_ctzg((char)8) == 0x3);
939 static_assert(__builtin_elementwise_ctzg((char)32) == 0x5);
940 static_assert(__builtin_elementwise_ctzg((char)127) == 0x0);
941 static_assert(__builtin_elementwise_ctzg((char)128) == 0x7);
942 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_ctzg((vector4char){8, 32, 127, (char)128})) == (LITTLE_END ? 0x07000503 : 0x03050007));
943
944 constexpr int ctz0 = __builtin_elementwise_ctzg(0);
945 // expected-error@-1 {{must be initialized by a constant expression}} \
946 // expected-note@-1 {{evaluation of __builtin_elementwise_ctzg with a zero value is undefined}}
947 constexpr vector4char ctz1 = __builtin_elementwise_ctzg((vector4char){1, 0, 3, 4});
948 // expected-error@-1 {{must be initialized by a constant expression}} \
949 // expected-note@-1 {{evaluation of __builtin_elementwise_ctzg with a zero value is undefined}}
950 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_ctzg((vector4char){8, 0, 127, 0}, (vector4char){9, -1, 9, -2})) == (LITTLE_END ? 0xFE00FF03 : 0x03FF00FE));
951 static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_ctzg((vector4char){0, 0, 0, 0}, (vector4char){0, 0, 0, 0})) == 0);
952
953 // Non-vector floating point types.
954 static_assert(__builtin_elementwise_fma(2.0, 3.0, 4.0) == 10.0);
955 static_assert(__builtin_elementwise_fma(200.0, 300.0, 400.0) == 60400.0);
956 // Vector type.
957 constexpr vector4float fmaFloat1 =
958 __builtin_elementwise_fma((vector4float){1.0, 2.0, 3.0, 4.0},
959 (vector4float){2.0, 3.0, 4.0, 5.0},
960 (vector4float){3.0, 4.0, 5.0, 6.0});
961 static_assert(fmaFloat1[0] == 5.0);
962 static_assert(fmaFloat1[1] == 10.0);
963 static_assert(fmaFloat1[2] == 17.0);
964 static_assert(fmaFloat1[3] == 26.0);
965 constexpr vector4double fmaDouble1 =
966 __builtin_elementwise_fma((vector4double){1.0, 2.0, 3.0, 4.0},
967 (vector4double){2.0, 3.0, 4.0, 5.0},
968 (vector4double){3.0, 4.0, 5.0, 6.0});
969 static_assert(fmaDouble1[0] == 5.0);
970 static_assert(fmaDouble1[1] == 10.0);
971 static_assert(fmaDouble1[2] == 17.0);
972 static_assert(fmaDouble1[3] == 26.0);
973
974 constexpr float fmaArray[] = {2.0f, 2.0f, 2.0f, 2.0f};
975 constexpr float fmaResult = __builtin_elementwise_fma(fmaArray[1], fmaArray[2], fmaArray[3]);
976 static_assert(fmaResult == 6.0f, "");
977
978 static_assert(__builtin_elementwise_fshl((unsigned char)255, (unsigned char)0, (unsigned char)8) == (unsigned char)255);
979 static_assert(__builtin_elementwise_fshl((char)127, (char)0, (char)8) == (char)127);
980 static_assert(__builtin_elementwise_fshl((unsigned char)0, (unsigned char)255, (unsigned char)8) == (unsigned char)0);
981 static_assert(__builtin_elementwise_fshl((char)0, (char)127, (char)8) == (char)0);
982 static_assert(__builtin_elementwise_fshr((unsigned char)255, (unsigned char)0, (unsigned char)8) == (unsigned char)0);
983 static_assert(__builtin_elementwise_fshr((char)127, (char)0, (char)8) == (char)0);
984 static_assert(__builtin_elementwise_fshr((unsigned char)0, (unsigned char)255, (unsigned char)8) == (unsigned char)255);
985 static_assert(__builtin_elementwise_fshr((char)0, (char)127, (char)8) == (char)127);
986 static_assert(__builtin_elementwise_fshl((unsigned int)4294967295, (unsigned int)0, (unsigned int)32) == (unsigned int)4294967295);
987 static_assert(__builtin_elementwise_fshl((int)2147483647, (int)0, (int)32) == (int)2147483647);
988 static_assert(__builtin_elementwise_fshl((unsigned int)0, (unsigned int)4294967295, (unsigned int)32) == (unsigned int)0);
989 static_assert(__builtin_elementwise_fshl((int)0, (int)2147483647, (int)32) == (int)0);
990 static_assert(__builtin_elementwise_fshr((unsigned int)4294967295, (unsigned int)0, (unsigned int)32) == (unsigned int)0);
991 static_assert(__builtin_elementwise_fshr((int)2147483647, (int)0, (int)32) == (int)0);
992 static_assert(__builtin_elementwise_fshr((unsigned int)0, (unsigned int)4294967295, (unsigned int)32) == (unsigned int)4294967295);
993 static_assert(__builtin_elementwise_fshr((int)0, (int)2147483647, (int)32) == (int)2147483647);
994 static_assert(__builtin_elementwise_fshl((unsigned long long)18446744073709551615ULL, (unsigned long long)0, (unsigned long long)64) == (unsigned long long)18446744073709551615ULL);
995 static_assert(__builtin_elementwise_fshl((long long)9223372036854775807, (long long)0, (long long)64) == (long long)9223372036854775807);
996 static_assert(__builtin_elementwise_fshl((unsigned long long)0, (unsigned long long)18446744073709551615ULL, (unsigned long long)64) == (unsigned long long)0);
997 static_assert(__builtin_elementwise_fshl((long long)0, (long long)9223372036854775807, (long long)64) == (long long)0);
998 static_assert(__builtin_elementwise_fshr((unsigned long long)18446744073709551615ULL, (unsigned long long)0, (unsigned long long)64) == (unsigned long long)0);
999 static_assert(__builtin_elementwise_fshr((long long)9223372036854775807, (long long)0, (long long)64) == (long long)0);
1000 static_assert(__builtin_elementwise_fshr((unsigned long long)0, (unsigned long long)18446744073709551615ULL, (unsigned long long)64) == (unsigned long long)18446744073709551615ULL);
1001 static_assert(__builtin_elementwise_fshr((long long)0, (long long)9223372036854775807, (long long)64) == (long long)9223372036854775807);
1002 static_assert(__builtin_elementwise_fshl((short) 1, (short) 2, (short) 3) == (short)8);
1003 static_assert(__builtin_elementwise_fshl((short) 2, (short) 1, (short) 3) == (short)16);
1004 static_assert(__builtin_elementwise_fshl(1, 2 , 2) == 4);
1005 static_assert(__builtin_elementwise_fshl(2L, 1L , 2L) == 8L);
1006 static_assert(__builtin_elementwise_fshr((unsigned char)1, (unsigned char)2, (unsigned char)3) == (unsigned char)32);
1007 constexpr vector4uchar v4s_fshl_var =
1008 __builtin_elementwise_fshl((vector4uchar){255, 15, 0, 2},
1009 (vector4uchar){0, 15, 255, 1},
1010 (vector4uchar){15, 11, 8, 3});
1011 static_assert(v4s_fshl_var[0] == 128);
1012 static_assert(v4s_fshl_var[1] == 120);
1013 static_assert(v4s_fshl_var[2] == 0);
1014 static_assert(v4s_fshl_var[3] == 16);
1015 constexpr vector4uchar v4s_fshr_var =
1016 __builtin_elementwise_fshr((vector4uchar){255, 15, 0, 1},
1017 (vector4uchar){0, 15, 255, 2},
1018 (vector4uchar){15, 11, 8, 3});
1019 static_assert(v4s_fshr_var[0] == 254);
1020 static_assert(v4s_fshr_var[1] == 225);
1021 static_assert(v4s_fshr_var[2] == 255);
1022 static_assert(v4s_fshr_var[3] == 32);
1023 static_assert(__builtin_elementwise_fshl(v4s_fshl_var[0], v4s_fshl_var[1], v4s_fshl_var[2]) == 128);
1024 static_assert(__builtin_elementwise_fshr(v4s_fshr_var[0], v4s_fshr_var[1], v4s_fshr_var[2]) == 253);