]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Headers/avxintrin.h
Merge clang trunk r238337 from ^/vendor/clang/dist, resolve conflicts,
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / Headers / avxintrin.h
1 /*===---- avxintrin.h - AVX intrinsics -------------------------------------===
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19  * THE SOFTWARE.
20  *
21  *===-----------------------------------------------------------------------===
22  */
23
24 #ifndef __IMMINTRIN_H
25 #error "Never use <avxintrin.h> directly; include <immintrin.h> instead."
26 #endif
27
28 #ifndef __AVXINTRIN_H
29 #define __AVXINTRIN_H
30
31 typedef double __v4df __attribute__ ((__vector_size__ (32)));
32 typedef float __v8sf __attribute__ ((__vector_size__ (32)));
33 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
34 typedef int __v8si __attribute__ ((__vector_size__ (32)));
35 typedef short __v16hi __attribute__ ((__vector_size__ (32)));
36 typedef char __v32qi __attribute__ ((__vector_size__ (32)));
37
38 typedef float __m256 __attribute__ ((__vector_size__ (32)));
39 typedef double __m256d __attribute__((__vector_size__(32)));
40 typedef long long __m256i __attribute__((__vector_size__(32)));
41
42 /* Arithmetic */
43 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
44 _mm256_add_pd(__m256d __a, __m256d __b)
45 {
46   return __a+__b;
47 }
48
49 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
50 _mm256_add_ps(__m256 __a, __m256 __b)
51 {
52   return __a+__b;
53 }
54
55 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
56 _mm256_sub_pd(__m256d __a, __m256d __b)
57 {
58   return __a-__b;
59 }
60
61 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
62 _mm256_sub_ps(__m256 __a, __m256 __b)
63 {
64   return __a-__b;
65 }
66
67 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
68 _mm256_addsub_pd(__m256d __a, __m256d __b)
69 {
70   return (__m256d)__builtin_ia32_addsubpd256((__v4df)__a, (__v4df)__b);
71 }
72
73 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
74 _mm256_addsub_ps(__m256 __a, __m256 __b)
75 {
76   return (__m256)__builtin_ia32_addsubps256((__v8sf)__a, (__v8sf)__b);
77 }
78
79 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
80 _mm256_div_pd(__m256d __a, __m256d __b)
81 {
82   return __a / __b;
83 }
84
85 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
86 _mm256_div_ps(__m256 __a, __m256 __b)
87 {
88   return __a / __b;
89 }
90
91 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
92 _mm256_max_pd(__m256d __a, __m256d __b)
93 {
94   return (__m256d)__builtin_ia32_maxpd256((__v4df)__a, (__v4df)__b);
95 }
96
97 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
98 _mm256_max_ps(__m256 __a, __m256 __b)
99 {
100   return (__m256)__builtin_ia32_maxps256((__v8sf)__a, (__v8sf)__b);
101 }
102
103 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
104 _mm256_min_pd(__m256d __a, __m256d __b)
105 {
106   return (__m256d)__builtin_ia32_minpd256((__v4df)__a, (__v4df)__b);
107 }
108
109 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
110 _mm256_min_ps(__m256 __a, __m256 __b)
111 {
112   return (__m256)__builtin_ia32_minps256((__v8sf)__a, (__v8sf)__b);
113 }
114
115 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
116 _mm256_mul_pd(__m256d __a, __m256d __b)
117 {
118   return __a * __b;
119 }
120
121 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
122 _mm256_mul_ps(__m256 __a, __m256 __b)
123 {
124   return __a * __b;
125 }
126
127 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
128 _mm256_sqrt_pd(__m256d __a)
129 {
130   return (__m256d)__builtin_ia32_sqrtpd256((__v4df)__a);
131 }
132
133 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
134 _mm256_sqrt_ps(__m256 __a)
135 {
136   return (__m256)__builtin_ia32_sqrtps256((__v8sf)__a);
137 }
138
139 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
140 _mm256_rsqrt_ps(__m256 __a)
141 {
142   return (__m256)__builtin_ia32_rsqrtps256((__v8sf)__a);
143 }
144
145 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
146 _mm256_rcp_ps(__m256 __a)
147 {
148   return (__m256)__builtin_ia32_rcpps256((__v8sf)__a);
149 }
150
151 #define _mm256_round_pd(V, M) __extension__ ({ \
152     __m256d __V = (V); \
153     (__m256d)__builtin_ia32_roundpd256((__v4df)__V, (M)); })
154
155 #define _mm256_round_ps(V, M) __extension__ ({ \
156   __m256 __V = (V); \
157   (__m256)__builtin_ia32_roundps256((__v8sf)__V, (M)); })
158
159 #define _mm256_ceil_pd(V)  _mm256_round_pd((V), _MM_FROUND_CEIL)
160 #define _mm256_floor_pd(V) _mm256_round_pd((V), _MM_FROUND_FLOOR)
161 #define _mm256_ceil_ps(V)  _mm256_round_ps((V), _MM_FROUND_CEIL)
162 #define _mm256_floor_ps(V) _mm256_round_ps((V), _MM_FROUND_FLOOR)
163
164 /* Logical */
165 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
166 _mm256_and_pd(__m256d __a, __m256d __b)
167 {
168   return (__m256d)((__v4di)__a & (__v4di)__b);
169 }
170
171 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
172 _mm256_and_ps(__m256 __a, __m256 __b)
173 {
174   return (__m256)((__v8si)__a & (__v8si)__b);
175 }
176
177 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
178 _mm256_andnot_pd(__m256d __a, __m256d __b)
179 {
180   return (__m256d)(~(__v4di)__a & (__v4di)__b);
181 }
182
183 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
184 _mm256_andnot_ps(__m256 __a, __m256 __b)
185 {
186   return (__m256)(~(__v8si)__a & (__v8si)__b);
187 }
188
189 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
190 _mm256_or_pd(__m256d __a, __m256d __b)
191 {
192   return (__m256d)((__v4di)__a | (__v4di)__b);
193 }
194
195 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
196 _mm256_or_ps(__m256 __a, __m256 __b)
197 {
198   return (__m256)((__v8si)__a | (__v8si)__b);
199 }
200
201 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
202 _mm256_xor_pd(__m256d __a, __m256d __b)
203 {
204   return (__m256d)((__v4di)__a ^ (__v4di)__b);
205 }
206
207 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
208 _mm256_xor_ps(__m256 __a, __m256 __b)
209 {
210   return (__m256)((__v8si)__a ^ (__v8si)__b);
211 }
212
213 /* Horizontal arithmetic */
214 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
215 _mm256_hadd_pd(__m256d __a, __m256d __b)
216 {
217   return (__m256d)__builtin_ia32_haddpd256((__v4df)__a, (__v4df)__b);
218 }
219
220 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
221 _mm256_hadd_ps(__m256 __a, __m256 __b)
222 {
223   return (__m256)__builtin_ia32_haddps256((__v8sf)__a, (__v8sf)__b);
224 }
225
226 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
227 _mm256_hsub_pd(__m256d __a, __m256d __b)
228 {
229   return (__m256d)__builtin_ia32_hsubpd256((__v4df)__a, (__v4df)__b);
230 }
231
232 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
233 _mm256_hsub_ps(__m256 __a, __m256 __b)
234 {
235   return (__m256)__builtin_ia32_hsubps256((__v8sf)__a, (__v8sf)__b);
236 }
237
238 /* Vector permutations */
239 static __inline __m128d __attribute__((__always_inline__, __nodebug__))
240 _mm_permutevar_pd(__m128d __a, __m128i __c)
241 {
242   return (__m128d)__builtin_ia32_vpermilvarpd((__v2df)__a, (__v2di)__c);
243 }
244
245 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
246 _mm256_permutevar_pd(__m256d __a, __m256i __c)
247 {
248   return (__m256d)__builtin_ia32_vpermilvarpd256((__v4df)__a, (__v4di)__c);
249 }
250
251 static __inline __m128 __attribute__((__always_inline__, __nodebug__))
252 _mm_permutevar_ps(__m128 __a, __m128i __c)
253 {
254   return (__m128)__builtin_ia32_vpermilvarps((__v4sf)__a, (__v4si)__c);
255 }
256
257 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
258 _mm256_permutevar_ps(__m256 __a, __m256i __c)
259 {
260   return (__m256)__builtin_ia32_vpermilvarps256((__v8sf)__a, (__v8si)__c);
261 }
262
263 #define _mm_permute_pd(A, C) __extension__ ({ \
264   __m128d __A = (A); \
265   (__m128d)__builtin_shufflevector((__v2df)__A, (__v2df) _mm_setzero_pd(), \
266                                    (C) & 0x1, ((C) & 0x2) >> 1); })
267
268 #define _mm256_permute_pd(A, C) __extension__ ({ \
269   __m256d __A = (A); \
270   (__m256d)__builtin_shufflevector((__v4df)__A, (__v4df) _mm256_setzero_pd(), \
271                                    (C) & 0x1, ((C) & 0x2) >> 1, \
272                                    2 + (((C) & 0x4) >> 2), \
273                                    2 + (((C) & 0x8) >> 3)); })
274
275 #define _mm_permute_ps(A, C) __extension__ ({ \
276   __m128 __A = (A); \
277   (__m128)__builtin_shufflevector((__v4sf)__A, (__v4sf) _mm_setzero_ps(), \
278                                    (C) & 0x3, ((C) & 0xc) >> 2, \
279                                    ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6); })
280
281 #define _mm256_permute_ps(A, C) __extension__ ({ \
282   __m256 __A = (A); \
283   (__m256)__builtin_shufflevector((__v8sf)__A, (__v8sf) _mm256_setzero_ps(), \
284                                   (C) & 0x3, ((C) & 0xc) >> 2, \
285                                   ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6, \
286                                   4 + (((C) & 0x03) >> 0), \
287                                   4 + (((C) & 0x0c) >> 2), \
288                                   4 + (((C) & 0x30) >> 4), \
289                                   4 + (((C) & 0xc0) >> 6)); })
290
291 #define _mm256_permute2f128_pd(V1, V2, M) __extension__ ({ \
292   __m256d __V1 = (V1); \
293   __m256d __V2 = (V2); \
294   (__m256d)__builtin_ia32_vperm2f128_pd256((__v4df)__V1, (__v4df)__V2, (M)); })
295
296 #define _mm256_permute2f128_ps(V1, V2, M) __extension__ ({ \
297   __m256 __V1 = (V1); \
298   __m256 __V2 = (V2); \
299   (__m256)__builtin_ia32_vperm2f128_ps256((__v8sf)__V1, (__v8sf)__V2, (M)); })
300
301 #define _mm256_permute2f128_si256(V1, V2, M) __extension__ ({ \
302   __m256i __V1 = (V1); \
303   __m256i __V2 = (V2); \
304   (__m256i)__builtin_ia32_vperm2f128_si256((__v8si)__V1, (__v8si)__V2, (M)); })
305
306 /* Vector Blend */
307 #define _mm256_blend_pd(V1, V2, M) __extension__ ({ \
308   __m256d __V1 = (V1); \
309   __m256d __V2 = (V2); \
310   (__m256d)__builtin_shufflevector((__v4df)__V1, (__v4df)__V2, \
311                                    (((M) & 0x01) ? 4 : 0), \
312                                    (((M) & 0x02) ? 5 : 1), \
313                                    (((M) & 0x04) ? 6 : 2), \
314                                    (((M) & 0x08) ? 7 : 3)); })
315
316 #define _mm256_blend_ps(V1, V2, M) __extension__ ({ \
317   __m256 __V1 = (V1); \
318   __m256 __V2 = (V2); \
319   (__m256)__builtin_shufflevector((__v8sf)__V1, (__v8sf)__V2, \
320                                   (((M) & 0x01) ?  8 : 0), \
321                                   (((M) & 0x02) ?  9 : 1), \
322                                   (((M) & 0x04) ? 10 : 2), \
323                                   (((M) & 0x08) ? 11 : 3), \
324                                   (((M) & 0x10) ? 12 : 4), \
325                                   (((M) & 0x20) ? 13 : 5), \
326                                   (((M) & 0x40) ? 14 : 6), \
327                                   (((M) & 0x80) ? 15 : 7)); })
328
329 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
330 _mm256_blendv_pd(__m256d __a, __m256d __b, __m256d __c)
331 {
332   return (__m256d)__builtin_ia32_blendvpd256(
333     (__v4df)__a, (__v4df)__b, (__v4df)__c);
334 }
335
336 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
337 _mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c)
338 {
339   return (__m256)__builtin_ia32_blendvps256(
340     (__v8sf)__a, (__v8sf)__b, (__v8sf)__c);
341 }
342
343 /* Vector Dot Product */
344 #define _mm256_dp_ps(V1, V2, M) __extension__ ({ \
345   __m256 __V1 = (V1); \
346   __m256 __V2 = (V2); \
347   (__m256)__builtin_ia32_dpps256((__v8sf)__V1, (__v8sf)__V2, (M)); })
348
349 /* Vector shuffle */
350 #define _mm256_shuffle_ps(a, b, mask) __extension__ ({ \
351         __m256 __a = (a); \
352         __m256 __b = (b); \
353         (__m256)__builtin_shufflevector((__v8sf)__a, (__v8sf)__b, \
354         (mask) & 0x3,                ((mask) & 0xc) >> 2, \
355         (((mask) & 0x30) >> 4) + 8,  (((mask) & 0xc0) >> 6) + 8, \
356         ((mask) & 0x3) + 4,          (((mask) & 0xc) >> 2) + 4, \
357         (((mask) & 0x30) >> 4) + 12, (((mask) & 0xc0) >> 6) + 12); })
358
359 #define _mm256_shuffle_pd(a, b, mask) __extension__ ({ \
360         __m256d __a = (a); \
361         __m256d __b = (b); \
362         (__m256d)__builtin_shufflevector((__v4df)__a, (__v4df)__b, \
363         (mask) & 0x1, \
364         (((mask) & 0x2) >> 1) + 4, \
365         (((mask) & 0x4) >> 2) + 2, \
366         (((mask) & 0x8) >> 3) + 6); })
367
368 /* Compare */
369 #define _CMP_EQ_OQ    0x00 /* Equal (ordered, non-signaling)  */
370 #define _CMP_LT_OS    0x01 /* Less-than (ordered, signaling)  */
371 #define _CMP_LE_OS    0x02 /* Less-than-or-equal (ordered, signaling)  */
372 #define _CMP_UNORD_Q  0x03 /* Unordered (non-signaling)  */
373 #define _CMP_NEQ_UQ   0x04 /* Not-equal (unordered, non-signaling)  */
374 #define _CMP_NLT_US   0x05 /* Not-less-than (unordered, signaling)  */
375 #define _CMP_NLE_US   0x06 /* Not-less-than-or-equal (unordered, signaling)  */
376 #define _CMP_ORD_Q    0x07 /* Ordered (nonsignaling)   */
377 #define _CMP_EQ_UQ    0x08 /* Equal (unordered, non-signaling)  */
378 #define _CMP_NGE_US   0x09 /* Not-greater-than-or-equal (unord, signaling)  */
379 #define _CMP_NGT_US   0x0a /* Not-greater-than (unordered, signaling)  */
380 #define _CMP_FALSE_OQ 0x0b /* False (ordered, non-signaling)  */
381 #define _CMP_NEQ_OQ   0x0c /* Not-equal (ordered, non-signaling)  */
382 #define _CMP_GE_OS    0x0d /* Greater-than-or-equal (ordered, signaling)  */
383 #define _CMP_GT_OS    0x0e /* Greater-than (ordered, signaling)  */
384 #define _CMP_TRUE_UQ  0x0f /* True (unordered, non-signaling)  */
385 #define _CMP_EQ_OS    0x10 /* Equal (ordered, signaling)  */
386 #define _CMP_LT_OQ    0x11 /* Less-than (ordered, non-signaling)  */
387 #define _CMP_LE_OQ    0x12 /* Less-than-or-equal (ordered, non-signaling)  */
388 #define _CMP_UNORD_S  0x13 /* Unordered (signaling)  */
389 #define _CMP_NEQ_US   0x14 /* Not-equal (unordered, signaling)  */
390 #define _CMP_NLT_UQ   0x15 /* Not-less-than (unordered, non-signaling)  */
391 #define _CMP_NLE_UQ   0x16 /* Not-less-than-or-equal (unord, non-signaling)  */
392 #define _CMP_ORD_S    0x17 /* Ordered (signaling)  */
393 #define _CMP_EQ_US    0x18 /* Equal (unordered, signaling)  */
394 #define _CMP_NGE_UQ   0x19 /* Not-greater-than-or-equal (unord, non-sign)  */
395 #define _CMP_NGT_UQ   0x1a /* Not-greater-than (unordered, non-signaling)  */
396 #define _CMP_FALSE_OS 0x1b /* False (ordered, signaling)  */
397 #define _CMP_NEQ_OS   0x1c /* Not-equal (ordered, signaling)  */
398 #define _CMP_GE_OQ    0x1d /* Greater-than-or-equal (ordered, non-signaling)  */
399 #define _CMP_GT_OQ    0x1e /* Greater-than (ordered, non-signaling)  */
400 #define _CMP_TRUE_US  0x1f /* True (unordered, signaling)  */
401
402 #define _mm_cmp_pd(a, b, c) __extension__ ({ \
403   __m128d __a = (a); \
404   __m128d __b = (b); \
405   (__m128d)__builtin_ia32_cmppd((__v2df)__a, (__v2df)__b, (c)); })
406
407 #define _mm_cmp_ps(a, b, c) __extension__ ({ \
408   __m128 __a = (a); \
409   __m128 __b = (b); \
410   (__m128)__builtin_ia32_cmpps((__v4sf)__a, (__v4sf)__b, (c)); })
411
412 #define _mm256_cmp_pd(a, b, c) __extension__ ({ \
413   __m256d __a = (a); \
414   __m256d __b = (b); \
415   (__m256d)__builtin_ia32_cmppd256((__v4df)__a, (__v4df)__b, (c)); })
416
417 #define _mm256_cmp_ps(a, b, c) __extension__ ({ \
418   __m256 __a = (a); \
419   __m256 __b = (b); \
420   (__m256)__builtin_ia32_cmpps256((__v8sf)__a, (__v8sf)__b, (c)); })
421
422 #define _mm_cmp_sd(a, b, c) __extension__ ({ \
423   __m128d __a = (a); \
424   __m128d __b = (b); \
425   (__m128d)__builtin_ia32_cmpsd((__v2df)__a, (__v2df)__b, (c)); })
426
427 #define _mm_cmp_ss(a, b, c) __extension__ ({ \
428   __m128 __a = (a); \
429   __m128 __b = (b); \
430   (__m128)__builtin_ia32_cmpss((__v4sf)__a, (__v4sf)__b, (c)); })
431
432 static __inline int __attribute__((__always_inline__, __nodebug__))
433 _mm256_extract_epi32(__m256i __a, const int __imm)
434 {
435   __v8si __b = (__v8si)__a;
436   return __b[__imm & 7];
437 }
438
439 static __inline int __attribute__((__always_inline__, __nodebug__))
440 _mm256_extract_epi16(__m256i __a, const int __imm)
441 {
442   __v16hi __b = (__v16hi)__a;
443   return __b[__imm & 15];
444 }
445
446 static __inline int __attribute__((__always_inline__, __nodebug__))
447 _mm256_extract_epi8(__m256i __a, const int __imm)
448 {
449   __v32qi __b = (__v32qi)__a;
450   return __b[__imm & 31];
451 }
452
453 #ifdef __x86_64__
454 static __inline long long  __attribute__((__always_inline__, __nodebug__))
455 _mm256_extract_epi64(__m256i __a, const int __imm)
456 {
457   __v4di __b = (__v4di)__a;
458   return __b[__imm & 3];
459 }
460 #endif
461
462 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
463 _mm256_insert_epi32(__m256i __a, int __b, int const __imm)
464 {
465   __v8si __c = (__v8si)__a;
466   __c[__imm & 7] = __b;
467   return (__m256i)__c;
468 }
469
470 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
471 _mm256_insert_epi16(__m256i __a, int __b, int const __imm)
472 {
473   __v16hi __c = (__v16hi)__a;
474   __c[__imm & 15] = __b;
475   return (__m256i)__c;
476 }
477
478 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
479 _mm256_insert_epi8(__m256i __a, int __b, int const __imm)
480 {
481   __v32qi __c = (__v32qi)__a;
482   __c[__imm & 31] = __b;
483   return (__m256i)__c;
484 }
485
486 #ifdef __x86_64__
487 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
488 _mm256_insert_epi64(__m256i __a, long long __b, int const __imm)
489 {
490   __v4di __c = (__v4di)__a;
491   __c[__imm & 3] = __b;
492   return (__m256i)__c;
493 }
494 #endif
495
496 /* Conversion */
497 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
498 _mm256_cvtepi32_pd(__m128i __a)
499 {
500   return (__m256d)__builtin_ia32_cvtdq2pd256((__v4si) __a);
501 }
502
503 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
504 _mm256_cvtepi32_ps(__m256i __a)
505 {
506   return (__m256)__builtin_ia32_cvtdq2ps256((__v8si) __a);
507 }
508
509 static __inline __m128 __attribute__((__always_inline__, __nodebug__))
510 _mm256_cvtpd_ps(__m256d __a)
511 {
512   return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
513 }
514
515 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
516 _mm256_cvtps_epi32(__m256 __a)
517 {
518   return (__m256i)__builtin_ia32_cvtps2dq256((__v8sf) __a);
519 }
520
521 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
522 _mm256_cvtps_pd(__m128 __a)
523 {
524   return (__m256d)__builtin_ia32_cvtps2pd256((__v4sf) __a);
525 }
526
527 static __inline __m128i __attribute__((__always_inline__, __nodebug__))
528 _mm256_cvttpd_epi32(__m256d __a)
529 {
530   return (__m128i)__builtin_ia32_cvttpd2dq256((__v4df) __a);
531 }
532
533 static __inline __m128i __attribute__((__always_inline__, __nodebug__))
534 _mm256_cvtpd_epi32(__m256d __a)
535 {
536   return (__m128i)__builtin_ia32_cvtpd2dq256((__v4df) __a);
537 }
538
539 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
540 _mm256_cvttps_epi32(__m256 __a)
541 {
542   return (__m256i)__builtin_ia32_cvttps2dq256((__v8sf) __a);
543 }
544
545 /* Vector replicate */
546 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
547 _mm256_movehdup_ps(__m256 __a)
548 {
549   return __builtin_shufflevector(__a, __a, 1, 1, 3, 3, 5, 5, 7, 7);
550 }
551
552 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
553 _mm256_moveldup_ps(__m256 __a)
554 {
555   return __builtin_shufflevector(__a, __a, 0, 0, 2, 2, 4, 4, 6, 6);
556 }
557
558 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
559 _mm256_movedup_pd(__m256d __a)
560 {
561   return __builtin_shufflevector(__a, __a, 0, 0, 2, 2);
562 }
563
564 /* Unpack and Interleave */
565 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
566 _mm256_unpackhi_pd(__m256d __a, __m256d __b)
567 {
568   return __builtin_shufflevector(__a, __b, 1, 5, 1+2, 5+2);
569 }
570
571 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
572 _mm256_unpacklo_pd(__m256d __a, __m256d __b)
573 {
574   return __builtin_shufflevector(__a, __b, 0, 4, 0+2, 4+2);
575 }
576
577 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
578 _mm256_unpackhi_ps(__m256 __a, __m256 __b)
579 {
580   return __builtin_shufflevector(__a, __b, 2, 10, 2+1, 10+1, 6, 14, 6+1, 14+1);
581 }
582
583 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
584 _mm256_unpacklo_ps(__m256 __a, __m256 __b)
585 {
586   return __builtin_shufflevector(__a, __b, 0, 8, 0+1, 8+1, 4, 12, 4+1, 12+1);
587 }
588
589 /* Bit Test */
590 static __inline int __attribute__((__always_inline__, __nodebug__))
591 _mm_testz_pd(__m128d __a, __m128d __b)
592 {
593   return __builtin_ia32_vtestzpd((__v2df)__a, (__v2df)__b);
594 }
595
596 static __inline int __attribute__((__always_inline__, __nodebug__))
597 _mm_testc_pd(__m128d __a, __m128d __b)
598 {
599   return __builtin_ia32_vtestcpd((__v2df)__a, (__v2df)__b);
600 }
601
602 static __inline int __attribute__((__always_inline__, __nodebug__))
603 _mm_testnzc_pd(__m128d __a, __m128d __b)
604 {
605   return __builtin_ia32_vtestnzcpd((__v2df)__a, (__v2df)__b);
606 }
607
608 static __inline int __attribute__((__always_inline__, __nodebug__))
609 _mm_testz_ps(__m128 __a, __m128 __b)
610 {
611   return __builtin_ia32_vtestzps((__v4sf)__a, (__v4sf)__b);
612 }
613
614 static __inline int __attribute__((__always_inline__, __nodebug__))
615 _mm_testc_ps(__m128 __a, __m128 __b)
616 {
617   return __builtin_ia32_vtestcps((__v4sf)__a, (__v4sf)__b);
618 }
619
620 static __inline int __attribute__((__always_inline__, __nodebug__))
621 _mm_testnzc_ps(__m128 __a, __m128 __b)
622 {
623   return __builtin_ia32_vtestnzcps((__v4sf)__a, (__v4sf)__b);
624 }
625
626 static __inline int __attribute__((__always_inline__, __nodebug__))
627 _mm256_testz_pd(__m256d __a, __m256d __b)
628 {
629   return __builtin_ia32_vtestzpd256((__v4df)__a, (__v4df)__b);
630 }
631
632 static __inline int __attribute__((__always_inline__, __nodebug__))
633 _mm256_testc_pd(__m256d __a, __m256d __b)
634 {
635   return __builtin_ia32_vtestcpd256((__v4df)__a, (__v4df)__b);
636 }
637
638 static __inline int __attribute__((__always_inline__, __nodebug__))
639 _mm256_testnzc_pd(__m256d __a, __m256d __b)
640 {
641   return __builtin_ia32_vtestnzcpd256((__v4df)__a, (__v4df)__b);
642 }
643
644 static __inline int __attribute__((__always_inline__, __nodebug__))
645 _mm256_testz_ps(__m256 __a, __m256 __b)
646 {
647   return __builtin_ia32_vtestzps256((__v8sf)__a, (__v8sf)__b);
648 }
649
650 static __inline int __attribute__((__always_inline__, __nodebug__))
651 _mm256_testc_ps(__m256 __a, __m256 __b)
652 {
653   return __builtin_ia32_vtestcps256((__v8sf)__a, (__v8sf)__b);
654 }
655
656 static __inline int __attribute__((__always_inline__, __nodebug__))
657 _mm256_testnzc_ps(__m256 __a, __m256 __b)
658 {
659   return __builtin_ia32_vtestnzcps256((__v8sf)__a, (__v8sf)__b);
660 }
661
662 static __inline int __attribute__((__always_inline__, __nodebug__))
663 _mm256_testz_si256(__m256i __a, __m256i __b)
664 {
665   return __builtin_ia32_ptestz256((__v4di)__a, (__v4di)__b);
666 }
667
668 static __inline int __attribute__((__always_inline__, __nodebug__))
669 _mm256_testc_si256(__m256i __a, __m256i __b)
670 {
671   return __builtin_ia32_ptestc256((__v4di)__a, (__v4di)__b);
672 }
673
674 static __inline int __attribute__((__always_inline__, __nodebug__))
675 _mm256_testnzc_si256(__m256i __a, __m256i __b)
676 {
677   return __builtin_ia32_ptestnzc256((__v4di)__a, (__v4di)__b);
678 }
679
680 /* Vector extract sign mask */
681 static __inline int __attribute__((__always_inline__, __nodebug__))
682 _mm256_movemask_pd(__m256d __a)
683 {
684   return __builtin_ia32_movmskpd256((__v4df)__a);
685 }
686
687 static __inline int __attribute__((__always_inline__, __nodebug__))
688 _mm256_movemask_ps(__m256 __a)
689 {
690   return __builtin_ia32_movmskps256((__v8sf)__a);
691 }
692
693 /* Vector __zero */
694 static __inline void __attribute__((__always_inline__, __nodebug__))
695 _mm256_zeroall(void)
696 {
697   __builtin_ia32_vzeroall();
698 }
699
700 static __inline void __attribute__((__always_inline__, __nodebug__))
701 _mm256_zeroupper(void)
702 {
703   __builtin_ia32_vzeroupper();
704 }
705
706 /* Vector load with broadcast */
707 static __inline __m128 __attribute__((__always_inline__, __nodebug__))
708 _mm_broadcast_ss(float const *__a)
709 {
710   float __f = *__a;
711   return (__m128)(__v4sf){ __f, __f, __f, __f };
712 }
713
714 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
715 _mm256_broadcast_sd(double const *__a)
716 {
717   double __d = *__a;
718   return (__m256d)(__v4df){ __d, __d, __d, __d };
719 }
720
721 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
722 _mm256_broadcast_ss(float const *__a)
723 {
724   float __f = *__a;
725   return (__m256)(__v8sf){ __f, __f, __f, __f, __f, __f, __f, __f };
726 }
727
728 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
729 _mm256_broadcast_pd(__m128d const *__a)
730 {
731   return (__m256d)__builtin_ia32_vbroadcastf128_pd256(__a);
732 }
733
734 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
735 _mm256_broadcast_ps(__m128 const *__a)
736 {
737   return (__m256)__builtin_ia32_vbroadcastf128_ps256(__a);
738 }
739
740 /* SIMD load ops */
741 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
742 _mm256_load_pd(double const *__p)
743 {
744   return *(__m256d *)__p;
745 }
746
747 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
748 _mm256_load_ps(float const *__p)
749 {
750   return *(__m256 *)__p;
751 }
752
753 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
754 _mm256_loadu_pd(double const *__p)
755 {
756   struct __loadu_pd {
757     __m256d __v;
758   } __attribute__((__packed__, __may_alias__));
759   return ((struct __loadu_pd*)__p)->__v;
760 }
761
762 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
763 _mm256_loadu_ps(float const *__p)
764 {
765   struct __loadu_ps {
766     __m256 __v;
767   } __attribute__((__packed__, __may_alias__));
768   return ((struct __loadu_ps*)__p)->__v;
769 }
770
771 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
772 _mm256_load_si256(__m256i const *__p)
773 {
774   return *__p;
775 }
776
777 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
778 _mm256_loadu_si256(__m256i const *__p)
779 {
780   struct __loadu_si256 {
781     __m256i __v;
782   } __attribute__((__packed__, __may_alias__));
783   return ((struct __loadu_si256*)__p)->__v;
784 }
785
786 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
787 _mm256_lddqu_si256(__m256i const *__p)
788 {
789   return (__m256i)__builtin_ia32_lddqu256((char const *)__p);
790 }
791
792 /* SIMD store ops */
793 static __inline void __attribute__((__always_inline__, __nodebug__))
794 _mm256_store_pd(double *__p, __m256d __a)
795 {
796   *(__m256d *)__p = __a;
797 }
798
799 static __inline void __attribute__((__always_inline__, __nodebug__))
800 _mm256_store_ps(float *__p, __m256 __a)
801 {
802   *(__m256 *)__p = __a;
803 }
804
805 static __inline void __attribute__((__always_inline__, __nodebug__))
806 _mm256_storeu_pd(double *__p, __m256d __a)
807 {
808   __builtin_ia32_storeupd256(__p, (__v4df)__a);
809 }
810
811 static __inline void __attribute__((__always_inline__, __nodebug__))
812 _mm256_storeu_ps(float *__p, __m256 __a)
813 {
814   __builtin_ia32_storeups256(__p, (__v8sf)__a);
815 }
816
817 static __inline void __attribute__((__always_inline__, __nodebug__))
818 _mm256_store_si256(__m256i *__p, __m256i __a)
819 {
820   *__p = __a;
821 }
822
823 static __inline void __attribute__((__always_inline__, __nodebug__))
824 _mm256_storeu_si256(__m256i *__p, __m256i __a)
825 {
826   __builtin_ia32_storedqu256((char *)__p, (__v32qi)__a);
827 }
828
829 /* Conditional load ops */
830 static __inline __m128d __attribute__((__always_inline__, __nodebug__))
831 _mm_maskload_pd(double const *__p, __m128d __m)
832 {
833   return (__m128d)__builtin_ia32_maskloadpd((const __v2df *)__p, (__v2df)__m);
834 }
835
836 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
837 _mm256_maskload_pd(double const *__p, __m256d __m)
838 {
839   return (__m256d)__builtin_ia32_maskloadpd256((const __v4df *)__p,
840                                                (__v4df)__m);
841 }
842
843 static __inline __m128 __attribute__((__always_inline__, __nodebug__))
844 _mm_maskload_ps(float const *__p, __m128 __m)
845 {
846   return (__m128)__builtin_ia32_maskloadps((const __v4sf *)__p, (__v4sf)__m);
847 }
848
849 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
850 _mm256_maskload_ps(float const *__p, __m256 __m)
851 {
852   return (__m256)__builtin_ia32_maskloadps256((const __v8sf *)__p, (__v8sf)__m);
853 }
854
855 /* Conditional store ops */
856 static __inline void __attribute__((__always_inline__, __nodebug__))
857 _mm256_maskstore_ps(float *__p, __m256 __m, __m256 __a)
858 {
859   __builtin_ia32_maskstoreps256((__v8sf *)__p, (__v8sf)__m, (__v8sf)__a);
860 }
861
862 static __inline void __attribute__((__always_inline__, __nodebug__))
863 _mm_maskstore_pd(double *__p, __m128d __m, __m128d __a)
864 {
865   __builtin_ia32_maskstorepd((__v2df *)__p, (__v2df)__m, (__v2df)__a);
866 }
867
868 static __inline void __attribute__((__always_inline__, __nodebug__))
869 _mm256_maskstore_pd(double *__p, __m256d __m, __m256d __a)
870 {
871   __builtin_ia32_maskstorepd256((__v4df *)__p, (__v4df)__m, (__v4df)__a);
872 }
873
874 static __inline void __attribute__((__always_inline__, __nodebug__))
875 _mm_maskstore_ps(float *__p, __m128 __m, __m128 __a)
876 {
877   __builtin_ia32_maskstoreps((__v4sf *)__p, (__v4sf)__m, (__v4sf)__a);
878 }
879
880 /* Cacheability support ops */
881 static __inline void __attribute__((__always_inline__, __nodebug__))
882 _mm256_stream_si256(__m256i *__a, __m256i __b)
883 {
884   __builtin_ia32_movntdq256((__v4di *)__a, (__v4di)__b);
885 }
886
887 static __inline void __attribute__((__always_inline__, __nodebug__))
888 _mm256_stream_pd(double *__a, __m256d __b)
889 {
890   __builtin_ia32_movntpd256(__a, (__v4df)__b);
891 }
892
893 static __inline void __attribute__((__always_inline__, __nodebug__))
894 _mm256_stream_ps(float *__p, __m256 __a)
895 {
896   __builtin_ia32_movntps256(__p, (__v8sf)__a);
897 }
898
899 /* Create vectors */
900 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
901 _mm256_set_pd(double __a, double __b, double __c, double __d)
902 {
903   return (__m256d){ __d, __c, __b, __a };
904 }
905
906 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
907 _mm256_set_ps(float __a, float __b, float __c, float __d,
908               float __e, float __f, float __g, float __h)
909 {
910   return (__m256){ __h, __g, __f, __e, __d, __c, __b, __a };
911 }
912
913 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
914 _mm256_set_epi32(int __i0, int __i1, int __i2, int __i3,
915                  int __i4, int __i5, int __i6, int __i7)
916 {
917   return (__m256i)(__v8si){ __i7, __i6, __i5, __i4, __i3, __i2, __i1, __i0 };
918 }
919
920 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
921 _mm256_set_epi16(short __w15, short __w14, short __w13, short __w12,
922                  short __w11, short __w10, short __w09, short __w08,
923                  short __w07, short __w06, short __w05, short __w04,
924                  short __w03, short __w02, short __w01, short __w00)
925 {
926   return (__m256i)(__v16hi){ __w00, __w01, __w02, __w03, __w04, __w05, __w06,
927     __w07, __w08, __w09, __w10, __w11, __w12, __w13, __w14, __w15 };
928 }
929
930 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
931 _mm256_set_epi8(char __b31, char __b30, char __b29, char __b28,
932                 char __b27, char __b26, char __b25, char __b24,
933                 char __b23, char __b22, char __b21, char __b20,
934                 char __b19, char __b18, char __b17, char __b16,
935                 char __b15, char __b14, char __b13, char __b12,
936                 char __b11, char __b10, char __b09, char __b08,
937                 char __b07, char __b06, char __b05, char __b04,
938                 char __b03, char __b02, char __b01, char __b00)
939 {
940   return (__m256i)(__v32qi){
941     __b00, __b01, __b02, __b03, __b04, __b05, __b06, __b07,
942     __b08, __b09, __b10, __b11, __b12, __b13, __b14, __b15,
943     __b16, __b17, __b18, __b19, __b20, __b21, __b22, __b23,
944     __b24, __b25, __b26, __b27, __b28, __b29, __b30, __b31
945   };
946 }
947
948 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
949 _mm256_set_epi64x(long long __a, long long __b, long long __c, long long __d)
950 {
951   return (__m256i)(__v4di){ __d, __c, __b, __a };
952 }
953
954 /* Create vectors with elements in reverse order */
955 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
956 _mm256_setr_pd(double __a, double __b, double __c, double __d)
957 {
958   return (__m256d){ __a, __b, __c, __d };
959 }
960
961 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
962 _mm256_setr_ps(float __a, float __b, float __c, float __d,
963                float __e, float __f, float __g, float __h)
964 {
965   return (__m256){ __a, __b, __c, __d, __e, __f, __g, __h };
966 }
967
968 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
969 _mm256_setr_epi32(int __i0, int __i1, int __i2, int __i3,
970                   int __i4, int __i5, int __i6, int __i7)
971 {
972   return (__m256i)(__v8si){ __i0, __i1, __i2, __i3, __i4, __i5, __i6, __i7 };
973 }
974
975 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
976 _mm256_setr_epi16(short __w15, short __w14, short __w13, short __w12,
977        short __w11, short __w10, short __w09, short __w08,
978        short __w07, short __w06, short __w05, short __w04,
979        short __w03, short __w02, short __w01, short __w00)
980 {
981   return (__m256i)(__v16hi){ __w15, __w14, __w13, __w12, __w11, __w10, __w09,
982     __w08, __w07, __w06, __w05, __w04, __w03, __w02, __w01, __w00 };
983 }
984
985 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
986 _mm256_setr_epi8(char __b31, char __b30, char __b29, char __b28,
987                  char __b27, char __b26, char __b25, char __b24,
988                  char __b23, char __b22, char __b21, char __b20,
989                  char __b19, char __b18, char __b17, char __b16,
990                  char __b15, char __b14, char __b13, char __b12,
991                  char __b11, char __b10, char __b09, char __b08,
992                  char __b07, char __b06, char __b05, char __b04,
993                  char __b03, char __b02, char __b01, char __b00)
994 {
995   return (__m256i)(__v32qi){
996     __b31, __b30, __b29, __b28, __b27, __b26, __b25, __b24,
997     __b23, __b22, __b21, __b20, __b19, __b18, __b17, __b16,
998     __b15, __b14, __b13, __b12, __b11, __b10, __b09, __b08,
999     __b07, __b06, __b05, __b04, __b03, __b02, __b01, __b00 };
1000 }
1001
1002 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1003 _mm256_setr_epi64x(long long __a, long long __b, long long __c, long long __d)
1004 {
1005   return (__m256i)(__v4di){ __a, __b, __c, __d };
1006 }
1007
1008 /* Create vectors with repeated elements */
1009 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
1010 _mm256_set1_pd(double __w)
1011 {
1012   return (__m256d){ __w, __w, __w, __w };
1013 }
1014
1015 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
1016 _mm256_set1_ps(float __w)
1017 {
1018   return (__m256){ __w, __w, __w, __w, __w, __w, __w, __w };
1019 }
1020
1021 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1022 _mm256_set1_epi32(int __i)
1023 {
1024   return (__m256i)(__v8si){ __i, __i, __i, __i, __i, __i, __i, __i };
1025 }
1026
1027 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1028 _mm256_set1_epi16(short __w)
1029 {
1030   return (__m256i)(__v16hi){ __w, __w, __w, __w, __w, __w, __w, __w, __w, __w,
1031     __w, __w, __w, __w, __w, __w };
1032 }
1033
1034 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1035 _mm256_set1_epi8(char __b)
1036 {
1037   return (__m256i)(__v32qi){ __b, __b, __b, __b, __b, __b, __b, __b, __b, __b,
1038     __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b,
1039     __b, __b, __b, __b, __b, __b, __b };
1040 }
1041
1042 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1043 _mm256_set1_epi64x(long long __q)
1044 {
1045   return (__m256i)(__v4di){ __q, __q, __q, __q };
1046 }
1047
1048 /* Create __zeroed vectors */
1049 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
1050 _mm256_setzero_pd(void)
1051 {
1052   return (__m256d){ 0, 0, 0, 0 };
1053 }
1054
1055 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
1056 _mm256_setzero_ps(void)
1057 {
1058   return (__m256){ 0, 0, 0, 0, 0, 0, 0, 0 };
1059 }
1060
1061 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1062 _mm256_setzero_si256(void)
1063 {
1064   return (__m256i){ 0LL, 0LL, 0LL, 0LL };
1065 }
1066
1067 /* Cast between vector types */
1068 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
1069 _mm256_castpd_ps(__m256d __a)
1070 {
1071   return (__m256)__a;
1072 }
1073
1074 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1075 _mm256_castpd_si256(__m256d __a)
1076 {
1077   return (__m256i)__a;
1078 }
1079
1080 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
1081 _mm256_castps_pd(__m256 __a)
1082 {
1083   return (__m256d)__a;
1084 }
1085
1086 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1087 _mm256_castps_si256(__m256 __a)
1088 {
1089   return (__m256i)__a;
1090 }
1091
1092 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
1093 _mm256_castsi256_ps(__m256i __a)
1094 {
1095   return (__m256)__a;
1096 }
1097
1098 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
1099 _mm256_castsi256_pd(__m256i __a)
1100 {
1101   return (__m256d)__a;
1102 }
1103
1104 static __inline __m128d __attribute__((__always_inline__, __nodebug__))
1105 _mm256_castpd256_pd128(__m256d __a)
1106 {
1107   return __builtin_shufflevector(__a, __a, 0, 1);
1108 }
1109
1110 static __inline __m128 __attribute__((__always_inline__, __nodebug__))
1111 _mm256_castps256_ps128(__m256 __a)
1112 {
1113   return __builtin_shufflevector(__a, __a, 0, 1, 2, 3);
1114 }
1115
1116 static __inline __m128i __attribute__((__always_inline__, __nodebug__))
1117 _mm256_castsi256_si128(__m256i __a)
1118 {
1119   return __builtin_shufflevector(__a, __a, 0, 1);
1120 }
1121
1122 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
1123 _mm256_castpd128_pd256(__m128d __a)
1124 {
1125   return __builtin_shufflevector(__a, __a, 0, 1, -1, -1);
1126 }
1127
1128 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
1129 _mm256_castps128_ps256(__m128 __a)
1130 {
1131   return __builtin_shufflevector(__a, __a, 0, 1, 2, 3, -1, -1, -1, -1);
1132 }
1133
1134 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1135 _mm256_castsi128_si256(__m128i __a)
1136 {
1137   return __builtin_shufflevector(__a, __a, 0, 1, -1, -1);
1138 }
1139
1140 /* 
1141    Vector insert.
1142    We use macros rather than inlines because we only want to accept
1143    invocations where the immediate M is a constant expression.
1144 */
1145 #define _mm256_insertf128_ps(V1, V2, M) __extension__ ({ \
1146   (__m256)__builtin_shufflevector( \
1147     (__v8sf)(V1), \
1148     (__v8sf)_mm256_castps128_ps256((__m128)(V2)), \
1149     (((M) & 1) ?  0 :  8), \
1150     (((M) & 1) ?  1 :  9), \
1151     (((M) & 1) ?  2 : 10), \
1152     (((M) & 1) ?  3 : 11), \
1153     (((M) & 1) ?  8 :  4), \
1154     (((M) & 1) ?  9 :  5), \
1155     (((M) & 1) ? 10 :  6), \
1156     (((M) & 1) ? 11 :  7) );})
1157
1158 #define _mm256_insertf128_pd(V1, V2, M) __extension__ ({ \
1159   (__m256d)__builtin_shufflevector( \
1160     (__v4df)(V1), \
1161     (__v4df)_mm256_castpd128_pd256((__m128d)(V2)), \
1162     (((M) & 1) ? 0 : 4), \
1163     (((M) & 1) ? 1 : 5), \
1164     (((M) & 1) ? 4 : 2), \
1165     (((M) & 1) ? 5 : 3) );})
1166
1167 #define _mm256_insertf128_si256(V1, V2, M) __extension__ ({ \
1168   (__m256i)__builtin_shufflevector( \
1169     (__v4di)(V1), \
1170     (__v4di)_mm256_castsi128_si256((__m128i)(V2)), \
1171     (((M) & 1) ? 0 : 4), \
1172     (((M) & 1) ? 1 : 5), \
1173     (((M) & 1) ? 4 : 2), \
1174     (((M) & 1) ? 5 : 3) );})
1175
1176 /* 
1177    Vector extract.
1178    We use macros rather than inlines because we only want to accept
1179    invocations where the immediate M is a constant expression.
1180 */
1181 #define _mm256_extractf128_ps(V, M) __extension__ ({ \
1182   (__m128)__builtin_shufflevector( \
1183     (__v8sf)(V), \
1184     (__v8sf)(_mm256_setzero_ps()), \
1185     (((M) & 1) ? 4 : 0), \
1186     (((M) & 1) ? 5 : 1), \
1187     (((M) & 1) ? 6 : 2), \
1188     (((M) & 1) ? 7 : 3) );})
1189
1190 #define _mm256_extractf128_pd(V, M) __extension__ ({ \
1191   (__m128d)__builtin_shufflevector( \
1192     (__v4df)(V), \
1193     (__v4df)(_mm256_setzero_pd()), \
1194     (((M) & 1) ? 2 : 0), \
1195     (((M) & 1) ? 3 : 1) );})
1196
1197 #define _mm256_extractf128_si256(V, M) __extension__ ({ \
1198   (__m128i)__builtin_shufflevector( \
1199     (__v4di)(V), \
1200     (__v4di)(_mm256_setzero_si256()), \
1201     (((M) & 1) ? 2 : 0), \
1202     (((M) & 1) ? 3 : 1) );})
1203
1204 /* SIMD load ops (unaligned) */
1205 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
1206 _mm256_loadu2_m128(float const *__addr_hi, float const *__addr_lo)
1207 {
1208   struct __loadu_ps {
1209     __m128 __v;
1210   } __attribute__((__packed__, __may_alias__));
1211
1212   __m256 __v256 = _mm256_castps128_ps256(((struct __loadu_ps*)__addr_lo)->__v);
1213   return _mm256_insertf128_ps(__v256, ((struct __loadu_ps*)__addr_hi)->__v, 1);
1214 }
1215
1216 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
1217 _mm256_loadu2_m128d(double const *__addr_hi, double const *__addr_lo)
1218 {
1219   struct __loadu_pd {
1220     __m128d __v;
1221   } __attribute__((__packed__, __may_alias__));
1222   
1223   __m256d __v256 = _mm256_castpd128_pd256(((struct __loadu_pd*)__addr_lo)->__v);
1224   return _mm256_insertf128_pd(__v256, ((struct __loadu_pd*)__addr_hi)->__v, 1);
1225 }
1226
1227 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1228 _mm256_loadu2_m128i(__m128i const *__addr_hi, __m128i const *__addr_lo)
1229 {
1230   struct __loadu_si128 {
1231     __m128i __v;
1232   } __attribute__((__packed__, __may_alias__));
1233   __m256i __v256 = _mm256_castsi128_si256(
1234     ((struct __loadu_si128*)__addr_lo)->__v);
1235   return _mm256_insertf128_si256(__v256,
1236                                  ((struct __loadu_si128*)__addr_hi)->__v, 1);
1237 }
1238
1239 /* SIMD store ops (unaligned) */
1240 static __inline void __attribute__((__always_inline__, __nodebug__))
1241 _mm256_storeu2_m128(float *__addr_hi, float *__addr_lo, __m256 __a)
1242 {
1243   __m128 __v128;
1244
1245   __v128 = _mm256_castps256_ps128(__a);
1246   __builtin_ia32_storeups(__addr_lo, __v128);
1247   __v128 = _mm256_extractf128_ps(__a, 1);
1248   __builtin_ia32_storeups(__addr_hi, __v128);
1249 }
1250
1251 static __inline void __attribute__((__always_inline__, __nodebug__))
1252 _mm256_storeu2_m128d(double *__addr_hi, double *__addr_lo, __m256d __a)
1253 {
1254   __m128d __v128;
1255
1256   __v128 = _mm256_castpd256_pd128(__a);
1257   __builtin_ia32_storeupd(__addr_lo, __v128);
1258   __v128 = _mm256_extractf128_pd(__a, 1);
1259   __builtin_ia32_storeupd(__addr_hi, __v128);
1260 }
1261
1262 static __inline void __attribute__((__always_inline__, __nodebug__))
1263 _mm256_storeu2_m128i(__m128i *__addr_hi, __m128i *__addr_lo, __m256i __a)
1264 {
1265   __m128i __v128;
1266
1267   __v128 = _mm256_castsi256_si128(__a);
1268   __builtin_ia32_storedqu((char *)__addr_lo, (__v16qi)__v128);
1269   __v128 = _mm256_extractf128_si256(__a, 1);
1270   __builtin_ia32_storedqu((char *)__addr_hi, (__v16qi)__v128);
1271 }
1272
1273 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
1274 _mm256_set_m128 (__m128 __hi, __m128 __lo) {
1275   return (__m256) __builtin_shufflevector(__lo, __hi, 0, 1, 2, 3, 4, 5, 6, 7);
1276 }
1277
1278 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
1279 _mm256_set_m128d (__m128d __hi, __m128d __lo) {
1280   return (__m256d)_mm256_set_m128((__m128)__hi, (__m128)__lo);
1281 }
1282
1283 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1284 _mm256_set_m128i (__m128i __hi, __m128i __lo) {
1285   return (__m256i)_mm256_set_m128((__m128)__hi, (__m128)__lo);
1286 }
1287
1288 static __inline __m256 __attribute__((__always_inline__, __nodebug__))
1289 _mm256_setr_m128 (__m128 __lo, __m128 __hi) {
1290   return _mm256_set_m128(__hi, __lo);
1291 }
1292
1293 static __inline __m256d __attribute__((__always_inline__, __nodebug__))
1294 _mm256_setr_m128d (__m128d __lo, __m128d __hi) {
1295   return (__m256d)_mm256_set_m128((__m128)__hi, (__m128)__lo);
1296 }
1297
1298 static __inline __m256i __attribute__((__always_inline__, __nodebug__))
1299 _mm256_setr_m128i (__m128i __lo, __m128i __hi) {
1300   return (__m256i)_mm256_set_m128((__m128)__hi, (__m128)__lo);
1301 }
1302
1303 #endif /* __AVXINTRIN_H */