blob: 601d1a11a47cbe24266fe550bf99c237c7848166 [file] [log] [blame]
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001/*===---- 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
Benjamin Kramer6f35f3c2010-08-20 23:00:03 +000024#ifndef __IMMINTRIN_H
25#error "Never use <avxintrin.h> directly; include <immintrin.h> instead."
26#endif
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000027
Richard Smith49e56442013-07-14 05:41:45 +000028#ifndef __AVXINTRIN_H
29#define __AVXINTRIN_H
30
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000031typedef double __v4df __attribute__ ((__vector_size__ (32)));
32typedef float __v8sf __attribute__ ((__vector_size__ (32)));
33typedef long long __v4di __attribute__ ((__vector_size__ (32)));
34typedef int __v8si __attribute__ ((__vector_size__ (32)));
35typedef short __v16hi __attribute__ ((__vector_size__ (32)));
36typedef char __v32qi __attribute__ ((__vector_size__ (32)));
37
38typedef float __m256 __attribute__ ((__vector_size__ (32)));
39typedef double __m256d __attribute__((__vector_size__(32)));
40typedef long long __m256i __attribute__((__vector_size__(32)));
41
Eric Christopher4d1851682015-06-17 07:09:20 +000042/* Define the default attributes for the functions in this file. */
Michael Kupersteine45af542015-06-30 13:36:19 +000043#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("avx")))
Eric Christopher4d1851682015-06-17 07:09:20 +000044
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000045/* Arithmetic */
Michael Kupersteine45af542015-06-30 13:36:19 +000046static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000047_mm256_add_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000048{
David Blaikie3302f2b2013-01-16 23:08:36 +000049 return __a+__b;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000050}
51
Michael Kupersteine45af542015-06-30 13:36:19 +000052static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000053_mm256_add_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000054{
David Blaikie3302f2b2013-01-16 23:08:36 +000055 return __a+__b;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000056}
57
Michael Kupersteine45af542015-06-30 13:36:19 +000058static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000059_mm256_sub_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000060{
David Blaikie3302f2b2013-01-16 23:08:36 +000061 return __a-__b;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000062}
63
Michael Kupersteine45af542015-06-30 13:36:19 +000064static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000065_mm256_sub_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000066{
David Blaikie3302f2b2013-01-16 23:08:36 +000067 return __a-__b;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000068}
69
Michael Kupersteine45af542015-06-30 13:36:19 +000070static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000071_mm256_addsub_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000072{
David Blaikie3302f2b2013-01-16 23:08:36 +000073 return (__m256d)__builtin_ia32_addsubpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000074}
75
Michael Kupersteine45af542015-06-30 13:36:19 +000076static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000077_mm256_addsub_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000078{
David Blaikie3302f2b2013-01-16 23:08:36 +000079 return (__m256)__builtin_ia32_addsubps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000080}
81
Michael Kupersteine45af542015-06-30 13:36:19 +000082static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000083_mm256_div_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000084{
David Blaikie3302f2b2013-01-16 23:08:36 +000085 return __a / __b;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000086}
87
Michael Kupersteine45af542015-06-30 13:36:19 +000088static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000089_mm256_div_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000090{
David Blaikie3302f2b2013-01-16 23:08:36 +000091 return __a / __b;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000092}
93
Michael Kupersteine45af542015-06-30 13:36:19 +000094static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000095_mm256_max_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000096{
David Blaikie3302f2b2013-01-16 23:08:36 +000097 return (__m256d)__builtin_ia32_maxpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000098}
99
Michael Kupersteine45af542015-06-30 13:36:19 +0000100static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000101_mm256_max_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000102{
David Blaikie3302f2b2013-01-16 23:08:36 +0000103 return (__m256)__builtin_ia32_maxps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000104}
105
Michael Kupersteine45af542015-06-30 13:36:19 +0000106static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000107_mm256_min_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000108{
David Blaikie3302f2b2013-01-16 23:08:36 +0000109 return (__m256d)__builtin_ia32_minpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000110}
111
Michael Kupersteine45af542015-06-30 13:36:19 +0000112static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000113_mm256_min_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000114{
David Blaikie3302f2b2013-01-16 23:08:36 +0000115 return (__m256)__builtin_ia32_minps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000116}
117
Michael Kupersteine45af542015-06-30 13:36:19 +0000118static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000119_mm256_mul_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000120{
David Blaikie3302f2b2013-01-16 23:08:36 +0000121 return __a * __b;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000122}
123
Michael Kupersteine45af542015-06-30 13:36:19 +0000124static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000125_mm256_mul_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000126{
David Blaikie3302f2b2013-01-16 23:08:36 +0000127 return __a * __b;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000128}
129
Michael Kupersteine45af542015-06-30 13:36:19 +0000130static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000131_mm256_sqrt_pd(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000132{
David Blaikie3302f2b2013-01-16 23:08:36 +0000133 return (__m256d)__builtin_ia32_sqrtpd256((__v4df)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000134}
135
Michael Kupersteine45af542015-06-30 13:36:19 +0000136static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000137_mm256_sqrt_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000138{
David Blaikie3302f2b2013-01-16 23:08:36 +0000139 return (__m256)__builtin_ia32_sqrtps256((__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000140}
141
Michael Kupersteine45af542015-06-30 13:36:19 +0000142static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000143_mm256_rsqrt_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000144{
David Blaikie3302f2b2013-01-16 23:08:36 +0000145 return (__m256)__builtin_ia32_rsqrtps256((__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000146}
147
Michael Kupersteine45af542015-06-30 13:36:19 +0000148static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000149_mm256_rcp_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000150{
David Blaikie3302f2b2013-01-16 23:08:36 +0000151 return (__m256)__builtin_ia32_rcpps256((__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000152}
153
Chad Rosier060d03b2011-12-17 00:15:26 +0000154#define _mm256_round_pd(V, M) __extension__ ({ \
155 __m256d __V = (V); \
Craig Topper9f009482011-12-24 07:55:14 +0000156 (__m256d)__builtin_ia32_roundpd256((__v4df)__V, (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000157
Chad Rosier060d03b2011-12-17 00:15:26 +0000158#define _mm256_round_ps(V, M) __extension__ ({ \
159 __m256 __V = (V); \
Craig Topper9f009482011-12-24 07:55:14 +0000160 (__m256)__builtin_ia32_roundps256((__v8sf)__V, (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000161
162#define _mm256_ceil_pd(V) _mm256_round_pd((V), _MM_FROUND_CEIL)
163#define _mm256_floor_pd(V) _mm256_round_pd((V), _MM_FROUND_FLOOR)
164#define _mm256_ceil_ps(V) _mm256_round_ps((V), _MM_FROUND_CEIL)
165#define _mm256_floor_ps(V) _mm256_round_ps((V), _MM_FROUND_FLOOR)
166
167/* Logical */
Michael Kupersteine45af542015-06-30 13:36:19 +0000168static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000169_mm256_and_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000170{
David Blaikie3302f2b2013-01-16 23:08:36 +0000171 return (__m256d)((__v4di)__a & (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000172}
173
Michael Kupersteine45af542015-06-30 13:36:19 +0000174static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000175_mm256_and_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000176{
David Blaikie3302f2b2013-01-16 23:08:36 +0000177 return (__m256)((__v8si)__a & (__v8si)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000178}
179
Michael Kupersteine45af542015-06-30 13:36:19 +0000180static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000181_mm256_andnot_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000182{
David Blaikie3302f2b2013-01-16 23:08:36 +0000183 return (__m256d)(~(__v4di)__a & (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000184}
185
Michael Kupersteine45af542015-06-30 13:36:19 +0000186static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000187_mm256_andnot_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000188{
David Blaikie3302f2b2013-01-16 23:08:36 +0000189 return (__m256)(~(__v8si)__a & (__v8si)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000190}
191
Michael Kupersteine45af542015-06-30 13:36:19 +0000192static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000193_mm256_or_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000194{
David Blaikie3302f2b2013-01-16 23:08:36 +0000195 return (__m256d)((__v4di)__a | (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000196}
197
Michael Kupersteine45af542015-06-30 13:36:19 +0000198static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000199_mm256_or_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000200{
David Blaikie3302f2b2013-01-16 23:08:36 +0000201 return (__m256)((__v8si)__a | (__v8si)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000202}
203
Michael Kupersteine45af542015-06-30 13:36:19 +0000204static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000205_mm256_xor_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000206{
David Blaikie3302f2b2013-01-16 23:08:36 +0000207 return (__m256d)((__v4di)__a ^ (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000208}
209
Michael Kupersteine45af542015-06-30 13:36:19 +0000210static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000211_mm256_xor_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000212{
David Blaikie3302f2b2013-01-16 23:08:36 +0000213 return (__m256)((__v8si)__a ^ (__v8si)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000214}
215
216/* Horizontal arithmetic */
Michael Kupersteine45af542015-06-30 13:36:19 +0000217static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000218_mm256_hadd_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000219{
David Blaikie3302f2b2013-01-16 23:08:36 +0000220 return (__m256d)__builtin_ia32_haddpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000221}
222
Michael Kupersteine45af542015-06-30 13:36:19 +0000223static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000224_mm256_hadd_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000225{
David Blaikie3302f2b2013-01-16 23:08:36 +0000226 return (__m256)__builtin_ia32_haddps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000227}
228
Michael Kupersteine45af542015-06-30 13:36:19 +0000229static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000230_mm256_hsub_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000231{
David Blaikie3302f2b2013-01-16 23:08:36 +0000232 return (__m256d)__builtin_ia32_hsubpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000233}
234
Michael Kupersteine45af542015-06-30 13:36:19 +0000235static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000236_mm256_hsub_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000237{
David Blaikie3302f2b2013-01-16 23:08:36 +0000238 return (__m256)__builtin_ia32_hsubps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000239}
240
241/* Vector permutations */
Michael Kupersteine45af542015-06-30 13:36:19 +0000242static __inline __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000243_mm_permutevar_pd(__m128d __a, __m128i __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000244{
David Blaikie3302f2b2013-01-16 23:08:36 +0000245 return (__m128d)__builtin_ia32_vpermilvarpd((__v2df)__a, (__v2di)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000246}
247
Michael Kupersteine45af542015-06-30 13:36:19 +0000248static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000249_mm256_permutevar_pd(__m256d __a, __m256i __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000250{
David Blaikie3302f2b2013-01-16 23:08:36 +0000251 return (__m256d)__builtin_ia32_vpermilvarpd256((__v4df)__a, (__v4di)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000252}
253
Michael Kupersteine45af542015-06-30 13:36:19 +0000254static __inline __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000255_mm_permutevar_ps(__m128 __a, __m128i __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000256{
David Blaikie3302f2b2013-01-16 23:08:36 +0000257 return (__m128)__builtin_ia32_vpermilvarps((__v4sf)__a, (__v4si)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000258}
259
Michael Kupersteine45af542015-06-30 13:36:19 +0000260static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000261_mm256_permutevar_ps(__m256 __a, __m256i __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000262{
Craig Topper9fee8ab2015-01-31 06:33:59 +0000263 return (__m256)__builtin_ia32_vpermilvarps256((__v8sf)__a, (__v8si)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000264}
265
Chad Rosier93375d52011-12-17 01:39:56 +0000266#define _mm_permute_pd(A, C) __extension__ ({ \
267 __m128d __A = (A); \
Craig Topperfec9f8e2012-02-08 05:16:54 +0000268 (__m128d)__builtin_shufflevector((__v2df)__A, (__v2df) _mm_setzero_pd(), \
269 (C) & 0x1, ((C) & 0x2) >> 1); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000270
Chad Rosier93375d52011-12-17 01:39:56 +0000271#define _mm256_permute_pd(A, C) __extension__ ({ \
272 __m256d __A = (A); \
Craig Topperfec9f8e2012-02-08 05:16:54 +0000273 (__m256d)__builtin_shufflevector((__v4df)__A, (__v4df) _mm256_setzero_pd(), \
274 (C) & 0x1, ((C) & 0x2) >> 1, \
275 2 + (((C) & 0x4) >> 2), \
276 2 + (((C) & 0x8) >> 3)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000277
Chad Rosier7caca842011-12-17 01:51:05 +0000278#define _mm_permute_ps(A, C) __extension__ ({ \
279 __m128 __A = (A); \
Craig Topperfec9f8e2012-02-08 05:16:54 +0000280 (__m128)__builtin_shufflevector((__v4sf)__A, (__v4sf) _mm_setzero_ps(), \
281 (C) & 0x3, ((C) & 0xc) >> 2, \
Craig Topper678a53c2012-03-30 05:09:18 +0000282 ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000283
Chad Rosier7caca842011-12-17 01:51:05 +0000284#define _mm256_permute_ps(A, C) __extension__ ({ \
285 __m256 __A = (A); \
Craig Topperfec9f8e2012-02-08 05:16:54 +0000286 (__m256)__builtin_shufflevector((__v8sf)__A, (__v8sf) _mm256_setzero_ps(), \
287 (C) & 0x3, ((C) & 0xc) >> 2, \
288 ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6, \
289 4 + (((C) & 0x03) >> 0), \
290 4 + (((C) & 0x0c) >> 2), \
291 4 + (((C) & 0x30) >> 4), \
292 4 + (((C) & 0xc0) >> 6)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000293
Chad Rosier9138fea252011-12-16 21:07:34 +0000294#define _mm256_permute2f128_pd(V1, V2, M) __extension__ ({ \
295 __m256d __V1 = (V1); \
296 __m256d __V2 = (V2); \
Craig Topper26e74e52012-04-17 05:16:56 +0000297 (__m256d)__builtin_ia32_vperm2f128_pd256((__v4df)__V1, (__v4df)__V2, (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000298
Chad Rosier9138fea252011-12-16 21:07:34 +0000299#define _mm256_permute2f128_ps(V1, V2, M) __extension__ ({ \
300 __m256 __V1 = (V1); \
301 __m256 __V2 = (V2); \
Craig Topper26e74e52012-04-17 05:16:56 +0000302 (__m256)__builtin_ia32_vperm2f128_ps256((__v8sf)__V1, (__v8sf)__V2, (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000303
Chad Rosier9138fea252011-12-16 21:07:34 +0000304#define _mm256_permute2f128_si256(V1, V2, M) __extension__ ({ \
305 __m256i __V1 = (V1); \
306 __m256i __V2 = (V2); \
Craig Topper26e74e52012-04-17 05:16:56 +0000307 (__m256i)__builtin_ia32_vperm2f128_si256((__v8si)__V1, (__v8si)__V2, (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000308
309/* Vector Blend */
Eli Friedmanf16beb32011-11-10 00:11:13 +0000310#define _mm256_blend_pd(V1, V2, M) __extension__ ({ \
311 __m256d __V1 = (V1); \
312 __m256d __V2 = (V2); \
Filipe Cabecinhas5d289b42014-05-13 02:37:02 +0000313 (__m256d)__builtin_shufflevector((__v4df)__V1, (__v4df)__V2, \
314 (((M) & 0x01) ? 4 : 0), \
315 (((M) & 0x02) ? 5 : 1), \
316 (((M) & 0x04) ? 6 : 2), \
317 (((M) & 0x08) ? 7 : 3)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000318
Eli Friedmanf16beb32011-11-10 00:11:13 +0000319#define _mm256_blend_ps(V1, V2, M) __extension__ ({ \
320 __m256 __V1 = (V1); \
321 __m256 __V2 = (V2); \
Filipe Cabecinhas5d289b42014-05-13 02:37:02 +0000322 (__m256)__builtin_shufflevector((__v8sf)__V1, (__v8sf)__V2, \
323 (((M) & 0x01) ? 8 : 0), \
324 (((M) & 0x02) ? 9 : 1), \
325 (((M) & 0x04) ? 10 : 2), \
326 (((M) & 0x08) ? 11 : 3), \
327 (((M) & 0x10) ? 12 : 4), \
328 (((M) & 0x20) ? 13 : 5), \
329 (((M) & 0x40) ? 14 : 6), \
330 (((M) & 0x80) ? 15 : 7)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000331
Michael Kupersteine45af542015-06-30 13:36:19 +0000332static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000333_mm256_blendv_pd(__m256d __a, __m256d __b, __m256d __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000334{
David Blaikie3302f2b2013-01-16 23:08:36 +0000335 return (__m256d)__builtin_ia32_blendvpd256(
336 (__v4df)__a, (__v4df)__b, (__v4df)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000337}
338
Michael Kupersteine45af542015-06-30 13:36:19 +0000339static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000340_mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000341{
David Blaikie5bb70032013-01-16 23:13:42 +0000342 return (__m256)__builtin_ia32_blendvps256(
David Blaikie3302f2b2013-01-16 23:08:36 +0000343 (__v8sf)__a, (__v8sf)__b, (__v8sf)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000344}
345
346/* Vector Dot Product */
Eli Friedmanf16beb32011-11-10 00:11:13 +0000347#define _mm256_dp_ps(V1, V2, M) __extension__ ({ \
348 __m256 __V1 = (V1); \
349 __m256 __V2 = (V2); \
Craig Topper9f009482011-12-24 07:55:14 +0000350 (__m256)__builtin_ia32_dpps256((__v8sf)__V1, (__v8sf)__V2, (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000351
352/* Vector shuffle */
Bob Wilsonc9b97cc2011-11-05 06:08:06 +0000353#define _mm256_shuffle_ps(a, b, mask) __extension__ ({ \
354 __m256 __a = (a); \
355 __m256 __b = (b); \
356 (__m256)__builtin_shufflevector((__v8sf)__a, (__v8sf)__b, \
Bruno Cardoso Lopese712a132010-08-11 01:17:34 +0000357 (mask) & 0x3, ((mask) & 0xc) >> 2, \
Bruno Cardoso Lopes8c333152010-08-11 18:45:43 +0000358 (((mask) & 0x30) >> 4) + 8, (((mask) & 0xc0) >> 6) + 8, \
Bruno Cardoso Lopes7a98a7e2011-08-23 23:29:45 +0000359 ((mask) & 0x3) + 4, (((mask) & 0xc) >> 2) + 4, \
Bob Wilsonc9b97cc2011-11-05 06:08:06 +0000360 (((mask) & 0x30) >> 4) + 12, (((mask) & 0xc0) >> 6) + 12); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000361
Bob Wilsonc9b97cc2011-11-05 06:08:06 +0000362#define _mm256_shuffle_pd(a, b, mask) __extension__ ({ \
363 __m256d __a = (a); \
364 __m256d __b = (b); \
365 (__m256d)__builtin_shufflevector((__v4df)__a, (__v4df)__b, \
Bruno Cardoso Lopese712a132010-08-11 01:17:34 +0000366 (mask) & 0x1, \
367 (((mask) & 0x2) >> 1) + 4, \
368 (((mask) & 0x4) >> 2) + 2, \
Bob Wilsonc9b97cc2011-11-05 06:08:06 +0000369 (((mask) & 0x8) >> 3) + 6); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000370
371/* Compare */
372#define _CMP_EQ_OQ 0x00 /* Equal (ordered, non-signaling) */
373#define _CMP_LT_OS 0x01 /* Less-than (ordered, signaling) */
374#define _CMP_LE_OS 0x02 /* Less-than-or-equal (ordered, signaling) */
375#define _CMP_UNORD_Q 0x03 /* Unordered (non-signaling) */
376#define _CMP_NEQ_UQ 0x04 /* Not-equal (unordered, non-signaling) */
377#define _CMP_NLT_US 0x05 /* Not-less-than (unordered, signaling) */
378#define _CMP_NLE_US 0x06 /* Not-less-than-or-equal (unordered, signaling) */
379#define _CMP_ORD_Q 0x07 /* Ordered (nonsignaling) */
380#define _CMP_EQ_UQ 0x08 /* Equal (unordered, non-signaling) */
381#define _CMP_NGE_US 0x09 /* Not-greater-than-or-equal (unord, signaling) */
382#define _CMP_NGT_US 0x0a /* Not-greater-than (unordered, signaling) */
383#define _CMP_FALSE_OQ 0x0b /* False (ordered, non-signaling) */
384#define _CMP_NEQ_OQ 0x0c /* Not-equal (ordered, non-signaling) */
385#define _CMP_GE_OS 0x0d /* Greater-than-or-equal (ordered, signaling) */
386#define _CMP_GT_OS 0x0e /* Greater-than (ordered, signaling) */
387#define _CMP_TRUE_UQ 0x0f /* True (unordered, non-signaling) */
388#define _CMP_EQ_OS 0x10 /* Equal (ordered, signaling) */
389#define _CMP_LT_OQ 0x11 /* Less-than (ordered, non-signaling) */
390#define _CMP_LE_OQ 0x12 /* Less-than-or-equal (ordered, non-signaling) */
391#define _CMP_UNORD_S 0x13 /* Unordered (signaling) */
392#define _CMP_NEQ_US 0x14 /* Not-equal (unordered, signaling) */
393#define _CMP_NLT_UQ 0x15 /* Not-less-than (unordered, non-signaling) */
394#define _CMP_NLE_UQ 0x16 /* Not-less-than-or-equal (unord, non-signaling) */
395#define _CMP_ORD_S 0x17 /* Ordered (signaling) */
396#define _CMP_EQ_US 0x18 /* Equal (unordered, signaling) */
397#define _CMP_NGE_UQ 0x19 /* Not-greater-than-or-equal (unord, non-sign) */
398#define _CMP_NGT_UQ 0x1a /* Not-greater-than (unordered, non-signaling) */
399#define _CMP_FALSE_OS 0x1b /* False (ordered, signaling) */
400#define _CMP_NEQ_OS 0x1c /* Not-equal (ordered, signaling) */
401#define _CMP_GE_OQ 0x1d /* Greater-than-or-equal (ordered, non-signaling) */
402#define _CMP_GT_OQ 0x1e /* Greater-than (ordered, non-signaling) */
403#define _CMP_TRUE_US 0x1f /* True (unordered, signaling) */
404
Bob Wilsonc9b97cc2011-11-05 06:08:06 +0000405#define _mm_cmp_pd(a, b, c) __extension__ ({ \
406 __m128d __a = (a); \
407 __m128d __b = (b); \
408 (__m128d)__builtin_ia32_cmppd((__v2df)__a, (__v2df)__b, (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000409
Bob Wilsonc9b97cc2011-11-05 06:08:06 +0000410#define _mm_cmp_ps(a, b, c) __extension__ ({ \
411 __m128 __a = (a); \
412 __m128 __b = (b); \
413 (__m128)__builtin_ia32_cmpps((__v4sf)__a, (__v4sf)__b, (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000414
Bob Wilsonc9b97cc2011-11-05 06:08:06 +0000415#define _mm256_cmp_pd(a, b, c) __extension__ ({ \
416 __m256d __a = (a); \
417 __m256d __b = (b); \
418 (__m256d)__builtin_ia32_cmppd256((__v4df)__a, (__v4df)__b, (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000419
Bob Wilsonc9b97cc2011-11-05 06:08:06 +0000420#define _mm256_cmp_ps(a, b, c) __extension__ ({ \
421 __m256 __a = (a); \
422 __m256 __b = (b); \
423 (__m256)__builtin_ia32_cmpps256((__v8sf)__a, (__v8sf)__b, (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000424
Bob Wilsonc9b97cc2011-11-05 06:08:06 +0000425#define _mm_cmp_sd(a, b, c) __extension__ ({ \
426 __m128d __a = (a); \
427 __m128d __b = (b); \
428 (__m128d)__builtin_ia32_cmpsd((__v2df)__a, (__v2df)__b, (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000429
Bob Wilsonc9b97cc2011-11-05 06:08:06 +0000430#define _mm_cmp_ss(a, b, c) __extension__ ({ \
431 __m128 __a = (a); \
432 __m128 __b = (b); \
433 (__m128)__builtin_ia32_cmpss((__v4sf)__a, (__v4sf)__b, (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000434
Michael Kupersteine45af542015-06-30 13:36:19 +0000435static __inline int __DEFAULT_FN_ATTRS
Craig Topper459554f2015-01-31 06:31:30 +0000436_mm256_extract_epi32(__m256i __a, const int __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000437{
David Blaikie3302f2b2013-01-16 23:08:36 +0000438 __v8si __b = (__v8si)__a;
Manman Renc94122e2013-10-23 20:33:14 +0000439 return __b[__imm & 7];
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000440}
441
Michael Kupersteine45af542015-06-30 13:36:19 +0000442static __inline int __DEFAULT_FN_ATTRS
Craig Topper459554f2015-01-31 06:31:30 +0000443_mm256_extract_epi16(__m256i __a, const int __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000444{
David Blaikie3302f2b2013-01-16 23:08:36 +0000445 __v16hi __b = (__v16hi)__a;
Manman Renc94122e2013-10-23 20:33:14 +0000446 return __b[__imm & 15];
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000447}
448
Michael Kupersteine45af542015-06-30 13:36:19 +0000449static __inline int __DEFAULT_FN_ATTRS
Craig Topper459554f2015-01-31 06:31:30 +0000450_mm256_extract_epi8(__m256i __a, const int __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000451{
David Blaikie3302f2b2013-01-16 23:08:36 +0000452 __v32qi __b = (__v32qi)__a;
Manman Renc94122e2013-10-23 20:33:14 +0000453 return __b[__imm & 31];
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000454}
455
456#ifdef __x86_64__
Michael Kupersteine45af542015-06-30 13:36:19 +0000457static __inline long long __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000458_mm256_extract_epi64(__m256i __a, const int __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000459{
David Blaikie3302f2b2013-01-16 23:08:36 +0000460 __v4di __b = (__v4di)__a;
Manman Renc94122e2013-10-23 20:33:14 +0000461 return __b[__imm & 3];
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000462}
463#endif
464
Michael Kupersteine45af542015-06-30 13:36:19 +0000465static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000466_mm256_insert_epi32(__m256i __a, int __b, int const __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000467{
David Blaikie3302f2b2013-01-16 23:08:36 +0000468 __v8si __c = (__v8si)__a;
469 __c[__imm & 7] = __b;
470 return (__m256i)__c;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000471}
472
Michael Kupersteine45af542015-06-30 13:36:19 +0000473static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000474_mm256_insert_epi16(__m256i __a, int __b, int const __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000475{
David Blaikie3302f2b2013-01-16 23:08:36 +0000476 __v16hi __c = (__v16hi)__a;
477 __c[__imm & 15] = __b;
478 return (__m256i)__c;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000479}
480
Michael Kupersteine45af542015-06-30 13:36:19 +0000481static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000482_mm256_insert_epi8(__m256i __a, int __b, int const __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000483{
David Blaikie3302f2b2013-01-16 23:08:36 +0000484 __v32qi __c = (__v32qi)__a;
485 __c[__imm & 31] = __b;
486 return (__m256i)__c;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000487}
488
489#ifdef __x86_64__
Michael Kupersteine45af542015-06-30 13:36:19 +0000490static __inline __m256i __DEFAULT_FN_ATTRS
Filipe Cabecinhasd7400292015-02-19 19:00:33 +0000491_mm256_insert_epi64(__m256i __a, long long __b, int const __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000492{
David Blaikie3302f2b2013-01-16 23:08:36 +0000493 __v4di __c = (__v4di)__a;
494 __c[__imm & 3] = __b;
495 return (__m256i)__c;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000496}
497#endif
498
499/* Conversion */
Michael Kupersteine45af542015-06-30 13:36:19 +0000500static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000501_mm256_cvtepi32_pd(__m128i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000502{
David Blaikie3302f2b2013-01-16 23:08:36 +0000503 return (__m256d)__builtin_ia32_cvtdq2pd256((__v4si) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000504}
505
Michael Kupersteine45af542015-06-30 13:36:19 +0000506static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000507_mm256_cvtepi32_ps(__m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000508{
David Blaikie3302f2b2013-01-16 23:08:36 +0000509 return (__m256)__builtin_ia32_cvtdq2ps256((__v8si) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000510}
511
Michael Kupersteine45af542015-06-30 13:36:19 +0000512static __inline __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000513_mm256_cvtpd_ps(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000514{
David Blaikie3302f2b2013-01-16 23:08:36 +0000515 return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000516}
517
Michael Kupersteine45af542015-06-30 13:36:19 +0000518static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000519_mm256_cvtps_epi32(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000520{
David Blaikie3302f2b2013-01-16 23:08:36 +0000521 return (__m256i)__builtin_ia32_cvtps2dq256((__v8sf) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000522}
523
Michael Kupersteine45af542015-06-30 13:36:19 +0000524static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000525_mm256_cvtps_pd(__m128 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000526{
David Blaikie3302f2b2013-01-16 23:08:36 +0000527 return (__m256d)__builtin_ia32_cvtps2pd256((__v4sf) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000528}
529
Michael Kupersteine45af542015-06-30 13:36:19 +0000530static __inline __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000531_mm256_cvttpd_epi32(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000532{
David Blaikie3302f2b2013-01-16 23:08:36 +0000533 return (__m128i)__builtin_ia32_cvttpd2dq256((__v4df) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000534}
535
Michael Kupersteine45af542015-06-30 13:36:19 +0000536static __inline __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000537_mm256_cvtpd_epi32(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000538{
David Blaikie3302f2b2013-01-16 23:08:36 +0000539 return (__m128i)__builtin_ia32_cvtpd2dq256((__v4df) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000540}
541
Michael Kupersteine45af542015-06-30 13:36:19 +0000542static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000543_mm256_cvttps_epi32(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000544{
David Blaikie3302f2b2013-01-16 23:08:36 +0000545 return (__m256i)__builtin_ia32_cvttps2dq256((__v8sf) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000546}
547
548/* Vector replicate */
Michael Kupersteine45af542015-06-30 13:36:19 +0000549static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000550_mm256_movehdup_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000551{
David Blaikie3302f2b2013-01-16 23:08:36 +0000552 return __builtin_shufflevector(__a, __a, 1, 1, 3, 3, 5, 5, 7, 7);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000553}
554
Michael Kupersteine45af542015-06-30 13:36:19 +0000555static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000556_mm256_moveldup_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000557{
David Blaikie3302f2b2013-01-16 23:08:36 +0000558 return __builtin_shufflevector(__a, __a, 0, 0, 2, 2, 4, 4, 6, 6);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000559}
560
Michael Kupersteine45af542015-06-30 13:36:19 +0000561static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000562_mm256_movedup_pd(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000563{
David Blaikie3302f2b2013-01-16 23:08:36 +0000564 return __builtin_shufflevector(__a, __a, 0, 0, 2, 2);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000565}
566
567/* Unpack and Interleave */
Michael Kupersteine45af542015-06-30 13:36:19 +0000568static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000569_mm256_unpackhi_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000570{
David Blaikie3302f2b2013-01-16 23:08:36 +0000571 return __builtin_shufflevector(__a, __b, 1, 5, 1+2, 5+2);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000572}
573
Michael Kupersteine45af542015-06-30 13:36:19 +0000574static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000575_mm256_unpacklo_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000576{
David Blaikie3302f2b2013-01-16 23:08:36 +0000577 return __builtin_shufflevector(__a, __b, 0, 4, 0+2, 4+2);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000578}
579
Michael Kupersteine45af542015-06-30 13:36:19 +0000580static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000581_mm256_unpackhi_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000582{
David Blaikie3302f2b2013-01-16 23:08:36 +0000583 return __builtin_shufflevector(__a, __b, 2, 10, 2+1, 10+1, 6, 14, 6+1, 14+1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000584}
585
Michael Kupersteine45af542015-06-30 13:36:19 +0000586static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000587_mm256_unpacklo_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000588{
David Blaikie3302f2b2013-01-16 23:08:36 +0000589 return __builtin_shufflevector(__a, __b, 0, 8, 0+1, 8+1, 4, 12, 4+1, 12+1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000590}
591
592/* Bit Test */
Michael Kupersteine45af542015-06-30 13:36:19 +0000593static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000594_mm_testz_pd(__m128d __a, __m128d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000595{
David Blaikie3302f2b2013-01-16 23:08:36 +0000596 return __builtin_ia32_vtestzpd((__v2df)__a, (__v2df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000597}
598
Michael Kupersteine45af542015-06-30 13:36:19 +0000599static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000600_mm_testc_pd(__m128d __a, __m128d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000601{
David Blaikie3302f2b2013-01-16 23:08:36 +0000602 return __builtin_ia32_vtestcpd((__v2df)__a, (__v2df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000603}
604
Michael Kupersteine45af542015-06-30 13:36:19 +0000605static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000606_mm_testnzc_pd(__m128d __a, __m128d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000607{
David Blaikie3302f2b2013-01-16 23:08:36 +0000608 return __builtin_ia32_vtestnzcpd((__v2df)__a, (__v2df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000609}
610
Michael Kupersteine45af542015-06-30 13:36:19 +0000611static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000612_mm_testz_ps(__m128 __a, __m128 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000613{
David Blaikie3302f2b2013-01-16 23:08:36 +0000614 return __builtin_ia32_vtestzps((__v4sf)__a, (__v4sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000615}
616
Michael Kupersteine45af542015-06-30 13:36:19 +0000617static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000618_mm_testc_ps(__m128 __a, __m128 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000619{
David Blaikie3302f2b2013-01-16 23:08:36 +0000620 return __builtin_ia32_vtestcps((__v4sf)__a, (__v4sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000621}
622
Michael Kupersteine45af542015-06-30 13:36:19 +0000623static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000624_mm_testnzc_ps(__m128 __a, __m128 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000625{
David Blaikie3302f2b2013-01-16 23:08:36 +0000626 return __builtin_ia32_vtestnzcps((__v4sf)__a, (__v4sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000627}
628
Michael Kupersteine45af542015-06-30 13:36:19 +0000629static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000630_mm256_testz_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000631{
David Blaikie3302f2b2013-01-16 23:08:36 +0000632 return __builtin_ia32_vtestzpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000633}
634
Michael Kupersteine45af542015-06-30 13:36:19 +0000635static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000636_mm256_testc_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000637{
David Blaikie3302f2b2013-01-16 23:08:36 +0000638 return __builtin_ia32_vtestcpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000639}
640
Michael Kupersteine45af542015-06-30 13:36:19 +0000641static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000642_mm256_testnzc_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000643{
David Blaikie3302f2b2013-01-16 23:08:36 +0000644 return __builtin_ia32_vtestnzcpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000645}
646
Michael Kupersteine45af542015-06-30 13:36:19 +0000647static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000648_mm256_testz_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000649{
David Blaikie3302f2b2013-01-16 23:08:36 +0000650 return __builtin_ia32_vtestzps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000651}
652
Michael Kupersteine45af542015-06-30 13:36:19 +0000653static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000654_mm256_testc_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000655{
David Blaikie3302f2b2013-01-16 23:08:36 +0000656 return __builtin_ia32_vtestcps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000657}
658
Michael Kupersteine45af542015-06-30 13:36:19 +0000659static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000660_mm256_testnzc_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000661{
David Blaikie3302f2b2013-01-16 23:08:36 +0000662 return __builtin_ia32_vtestnzcps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000663}
664
Michael Kupersteine45af542015-06-30 13:36:19 +0000665static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000666_mm256_testz_si256(__m256i __a, __m256i __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000667{
David Blaikie3302f2b2013-01-16 23:08:36 +0000668 return __builtin_ia32_ptestz256((__v4di)__a, (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000669}
670
Michael Kupersteine45af542015-06-30 13:36:19 +0000671static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000672_mm256_testc_si256(__m256i __a, __m256i __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000673{
David Blaikie3302f2b2013-01-16 23:08:36 +0000674 return __builtin_ia32_ptestc256((__v4di)__a, (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000675}
676
Michael Kupersteine45af542015-06-30 13:36:19 +0000677static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000678_mm256_testnzc_si256(__m256i __a, __m256i __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000679{
David Blaikie3302f2b2013-01-16 23:08:36 +0000680 return __builtin_ia32_ptestnzc256((__v4di)__a, (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000681}
682
683/* Vector extract sign mask */
Michael Kupersteine45af542015-06-30 13:36:19 +0000684static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000685_mm256_movemask_pd(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000686{
David Blaikie3302f2b2013-01-16 23:08:36 +0000687 return __builtin_ia32_movmskpd256((__v4df)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000688}
689
Michael Kupersteine45af542015-06-30 13:36:19 +0000690static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000691_mm256_movemask_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000692{
David Blaikie3302f2b2013-01-16 23:08:36 +0000693 return __builtin_ia32_movmskps256((__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000694}
695
David Blaikie3302f2b2013-01-16 23:08:36 +0000696/* Vector __zero */
Michael Kupersteine45af542015-06-30 13:36:19 +0000697static __inline void __DEFAULT_FN_ATTRS
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000698_mm256_zeroall(void)
699{
700 __builtin_ia32_vzeroall();
701}
702
Michael Kupersteine45af542015-06-30 13:36:19 +0000703static __inline void __DEFAULT_FN_ATTRS
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000704_mm256_zeroupper(void)
705{
706 __builtin_ia32_vzeroupper();
707}
708
709/* Vector load with broadcast */
Michael Kupersteine45af542015-06-30 13:36:19 +0000710static __inline __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000711_mm_broadcast_ss(float const *__a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000712{
Adam Nemet286ae082014-05-29 20:47:29 +0000713 float __f = *__a;
714 return (__m128)(__v4sf){ __f, __f, __f, __f };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000715}
716
Michael Kupersteine45af542015-06-30 13:36:19 +0000717static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000718_mm256_broadcast_sd(double const *__a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000719{
Adam Nemet286ae082014-05-29 20:47:29 +0000720 double __d = *__a;
721 return (__m256d)(__v4df){ __d, __d, __d, __d };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000722}
723
Michael Kupersteine45af542015-06-30 13:36:19 +0000724static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000725_mm256_broadcast_ss(float const *__a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000726{
Adam Nemet286ae082014-05-29 20:47:29 +0000727 float __f = *__a;
728 return (__m256)(__v8sf){ __f, __f, __f, __f, __f, __f, __f, __f };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000729}
730
Michael Kupersteine45af542015-06-30 13:36:19 +0000731static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000732_mm256_broadcast_pd(__m128d const *__a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000733{
David Blaikie3302f2b2013-01-16 23:08:36 +0000734 return (__m256d)__builtin_ia32_vbroadcastf128_pd256(__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000735}
736
Michael Kupersteine45af542015-06-30 13:36:19 +0000737static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000738_mm256_broadcast_ps(__m128 const *__a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000739{
David Blaikie3302f2b2013-01-16 23:08:36 +0000740 return (__m256)__builtin_ia32_vbroadcastf128_ps256(__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000741}
742
743/* SIMD load ops */
Michael Kupersteine45af542015-06-30 13:36:19 +0000744static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000745_mm256_load_pd(double const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000746{
David Blaikie3302f2b2013-01-16 23:08:36 +0000747 return *(__m256d *)__p;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000748}
749
Michael Kupersteine45af542015-06-30 13:36:19 +0000750static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000751_mm256_load_ps(float const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000752{
David Blaikie3302f2b2013-01-16 23:08:36 +0000753 return *(__m256 *)__p;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000754}
755
Michael Kupersteine45af542015-06-30 13:36:19 +0000756static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000757_mm256_loadu_pd(double const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000758{
Craig Topper9e9301a2012-01-25 04:26:17 +0000759 struct __loadu_pd {
David Blaikie3302f2b2013-01-16 23:08:36 +0000760 __m256d __v;
David Majnemer1cf22e62015-02-04 00:26:10 +0000761 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000762 return ((struct __loadu_pd*)__p)->__v;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000763}
764
Michael Kupersteine45af542015-06-30 13:36:19 +0000765static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000766_mm256_loadu_ps(float const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000767{
Craig Topper9e9301a2012-01-25 04:26:17 +0000768 struct __loadu_ps {
David Blaikie3302f2b2013-01-16 23:08:36 +0000769 __m256 __v;
David Majnemer1cf22e62015-02-04 00:26:10 +0000770 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000771 return ((struct __loadu_ps*)__p)->__v;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000772}
773
Michael Kupersteine45af542015-06-30 13:36:19 +0000774static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000775_mm256_load_si256(__m256i const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000776{
David Blaikie3302f2b2013-01-16 23:08:36 +0000777 return *__p;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000778}
779
Michael Kupersteine45af542015-06-30 13:36:19 +0000780static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000781_mm256_loadu_si256(__m256i const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000782{
Craig Topper9e9301a2012-01-25 04:26:17 +0000783 struct __loadu_si256 {
David Blaikie3302f2b2013-01-16 23:08:36 +0000784 __m256i __v;
David Majnemer1cf22e62015-02-04 00:26:10 +0000785 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000786 return ((struct __loadu_si256*)__p)->__v;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000787}
788
Michael Kupersteine45af542015-06-30 13:36:19 +0000789static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000790_mm256_lddqu_si256(__m256i const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000791{
David Blaikie3302f2b2013-01-16 23:08:36 +0000792 return (__m256i)__builtin_ia32_lddqu256((char const *)__p);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000793}
794
795/* SIMD store ops */
Michael Kupersteine45af542015-06-30 13:36:19 +0000796static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000797_mm256_store_pd(double *__p, __m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000798{
David Blaikie3302f2b2013-01-16 23:08:36 +0000799 *(__m256d *)__p = __a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000800}
801
Michael Kupersteine45af542015-06-30 13:36:19 +0000802static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000803_mm256_store_ps(float *__p, __m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000804{
David Blaikie3302f2b2013-01-16 23:08:36 +0000805 *(__m256 *)__p = __a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000806}
807
Michael Kupersteine45af542015-06-30 13:36:19 +0000808static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000809_mm256_storeu_pd(double *__p, __m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000810{
David Blaikie3302f2b2013-01-16 23:08:36 +0000811 __builtin_ia32_storeupd256(__p, (__v4df)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000812}
813
Michael Kupersteine45af542015-06-30 13:36:19 +0000814static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000815_mm256_storeu_ps(float *__p, __m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000816{
David Blaikie3302f2b2013-01-16 23:08:36 +0000817 __builtin_ia32_storeups256(__p, (__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000818}
819
Michael Kupersteine45af542015-06-30 13:36:19 +0000820static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000821_mm256_store_si256(__m256i *__p, __m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000822{
David Blaikie3302f2b2013-01-16 23:08:36 +0000823 *__p = __a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000824}
825
Michael Kupersteine45af542015-06-30 13:36:19 +0000826static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000827_mm256_storeu_si256(__m256i *__p, __m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000828{
David Blaikie3302f2b2013-01-16 23:08:36 +0000829 __builtin_ia32_storedqu256((char *)__p, (__v32qi)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000830}
831
832/* Conditional load ops */
Michael Kupersteine45af542015-06-30 13:36:19 +0000833static __inline __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000834_mm_maskload_pd(double const *__p, __m128d __m)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000835{
David Blaikie3302f2b2013-01-16 23:08:36 +0000836 return (__m128d)__builtin_ia32_maskloadpd((const __v2df *)__p, (__v2df)__m);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000837}
838
Michael Kupersteine45af542015-06-30 13:36:19 +0000839static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000840_mm256_maskload_pd(double const *__p, __m256d __m)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000841{
David Blaikie3302f2b2013-01-16 23:08:36 +0000842 return (__m256d)__builtin_ia32_maskloadpd256((const __v4df *)__p,
843 (__v4df)__m);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000844}
845
Michael Kupersteine45af542015-06-30 13:36:19 +0000846static __inline __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000847_mm_maskload_ps(float const *__p, __m128 __m)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000848{
David Blaikie3302f2b2013-01-16 23:08:36 +0000849 return (__m128)__builtin_ia32_maskloadps((const __v4sf *)__p, (__v4sf)__m);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000850}
851
Michael Kupersteine45af542015-06-30 13:36:19 +0000852static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000853_mm256_maskload_ps(float const *__p, __m256 __m)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000854{
David Blaikie3302f2b2013-01-16 23:08:36 +0000855 return (__m256)__builtin_ia32_maskloadps256((const __v8sf *)__p, (__v8sf)__m);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000856}
857
858/* Conditional store ops */
Michael Kupersteine45af542015-06-30 13:36:19 +0000859static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000860_mm256_maskstore_ps(float *__p, __m256 __m, __m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000861{
David Blaikie3302f2b2013-01-16 23:08:36 +0000862 __builtin_ia32_maskstoreps256((__v8sf *)__p, (__v8sf)__m, (__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000863}
864
Michael Kupersteine45af542015-06-30 13:36:19 +0000865static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000866_mm_maskstore_pd(double *__p, __m128d __m, __m128d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000867{
David Blaikie3302f2b2013-01-16 23:08:36 +0000868 __builtin_ia32_maskstorepd((__v2df *)__p, (__v2df)__m, (__v2df)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000869}
870
Michael Kupersteine45af542015-06-30 13:36:19 +0000871static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000872_mm256_maskstore_pd(double *__p, __m256d __m, __m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000873{
David Blaikie3302f2b2013-01-16 23:08:36 +0000874 __builtin_ia32_maskstorepd256((__v4df *)__p, (__v4df)__m, (__v4df)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000875}
876
Michael Kupersteine45af542015-06-30 13:36:19 +0000877static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000878_mm_maskstore_ps(float *__p, __m128 __m, __m128 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000879{
David Blaikie3302f2b2013-01-16 23:08:36 +0000880 __builtin_ia32_maskstoreps((__v4sf *)__p, (__v4sf)__m, (__v4sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000881}
882
883/* Cacheability support ops */
Michael Kupersteine45af542015-06-30 13:36:19 +0000884static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000885_mm256_stream_si256(__m256i *__a, __m256i __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000886{
David Blaikie3302f2b2013-01-16 23:08:36 +0000887 __builtin_ia32_movntdq256((__v4di *)__a, (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000888}
889
Michael Kupersteine45af542015-06-30 13:36:19 +0000890static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000891_mm256_stream_pd(double *__a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000892{
David Blaikie3302f2b2013-01-16 23:08:36 +0000893 __builtin_ia32_movntpd256(__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000894}
895
Michael Kupersteine45af542015-06-30 13:36:19 +0000896static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000897_mm256_stream_ps(float *__p, __m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000898{
David Blaikie3302f2b2013-01-16 23:08:36 +0000899 __builtin_ia32_movntps256(__p, (__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000900}
901
902/* Create vectors */
Simon Pilgrim5aba9922015-08-26 21:17:12 +0000903static __inline__ __m256d __DEFAULT_FN_ATTRS
904_mm256_undefined_pd()
905{
906 return (__m256d)__builtin_ia32_undef256();
907}
908
909static __inline__ __m256 __DEFAULT_FN_ATTRS
910_mm256_undefined_ps()
911{
912 return (__m256)__builtin_ia32_undef256();
913}
914
915static __inline__ __m256i __DEFAULT_FN_ATTRS
916_mm256_undefined_si256()
917{
918 return (__m256i)__builtin_ia32_undef256();
919}
920
Michael Kupersteine45af542015-06-30 13:36:19 +0000921static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000922_mm256_set_pd(double __a, double __b, double __c, double __d)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000923{
David Blaikie3302f2b2013-01-16 23:08:36 +0000924 return (__m256d){ __d, __c, __b, __a };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000925}
926
Michael Kupersteine45af542015-06-30 13:36:19 +0000927static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000928_mm256_set_ps(float __a, float __b, float __c, float __d,
Craig Topper9fee8ab2015-01-31 06:33:59 +0000929 float __e, float __f, float __g, float __h)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000930{
David Blaikie3302f2b2013-01-16 23:08:36 +0000931 return (__m256){ __h, __g, __f, __e, __d, __c, __b, __a };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000932}
933
Michael Kupersteine45af542015-06-30 13:36:19 +0000934static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000935_mm256_set_epi32(int __i0, int __i1, int __i2, int __i3,
Craig Topper9fee8ab2015-01-31 06:33:59 +0000936 int __i4, int __i5, int __i6, int __i7)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000937{
David Blaikie3302f2b2013-01-16 23:08:36 +0000938 return (__m256i)(__v8si){ __i7, __i6, __i5, __i4, __i3, __i2, __i1, __i0 };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000939}
940
Michael Kupersteine45af542015-06-30 13:36:19 +0000941static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000942_mm256_set_epi16(short __w15, short __w14, short __w13, short __w12,
Craig Topper9fee8ab2015-01-31 06:33:59 +0000943 short __w11, short __w10, short __w09, short __w08,
944 short __w07, short __w06, short __w05, short __w04,
945 short __w03, short __w02, short __w01, short __w00)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000946{
David Blaikie3302f2b2013-01-16 23:08:36 +0000947 return (__m256i)(__v16hi){ __w00, __w01, __w02, __w03, __w04, __w05, __w06,
948 __w07, __w08, __w09, __w10, __w11, __w12, __w13, __w14, __w15 };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000949}
950
Michael Kupersteine45af542015-06-30 13:36:19 +0000951static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000952_mm256_set_epi8(char __b31, char __b30, char __b29, char __b28,
Craig Topper9fee8ab2015-01-31 06:33:59 +0000953 char __b27, char __b26, char __b25, char __b24,
954 char __b23, char __b22, char __b21, char __b20,
955 char __b19, char __b18, char __b17, char __b16,
956 char __b15, char __b14, char __b13, char __b12,
957 char __b11, char __b10, char __b09, char __b08,
958 char __b07, char __b06, char __b05, char __b04,
959 char __b03, char __b02, char __b01, char __b00)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000960{
961 return (__m256i)(__v32qi){
David Blaikie3302f2b2013-01-16 23:08:36 +0000962 __b00, __b01, __b02, __b03, __b04, __b05, __b06, __b07,
963 __b08, __b09, __b10, __b11, __b12, __b13, __b14, __b15,
964 __b16, __b17, __b18, __b19, __b20, __b21, __b22, __b23,
965 __b24, __b25, __b26, __b27, __b28, __b29, __b30, __b31
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000966 };
967}
968
Michael Kupersteine45af542015-06-30 13:36:19 +0000969static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000970_mm256_set_epi64x(long long __a, long long __b, long long __c, long long __d)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000971{
David Blaikie3302f2b2013-01-16 23:08:36 +0000972 return (__m256i)(__v4di){ __d, __c, __b, __a };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000973}
974
975/* Create vectors with elements in reverse order */
Michael Kupersteine45af542015-06-30 13:36:19 +0000976static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000977_mm256_setr_pd(double __a, double __b, double __c, double __d)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000978{
David Blaikie3302f2b2013-01-16 23:08:36 +0000979 return (__m256d){ __a, __b, __c, __d };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000980}
981
Michael Kupersteine45af542015-06-30 13:36:19 +0000982static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000983_mm256_setr_ps(float __a, float __b, float __c, float __d,
Craig Topper9fee8ab2015-01-31 06:33:59 +0000984 float __e, float __f, float __g, float __h)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000985{
David Blaikie3302f2b2013-01-16 23:08:36 +0000986 return (__m256){ __a, __b, __c, __d, __e, __f, __g, __h };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000987}
988
Michael Kupersteine45af542015-06-30 13:36:19 +0000989static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000990_mm256_setr_epi32(int __i0, int __i1, int __i2, int __i3,
Craig Topper9fee8ab2015-01-31 06:33:59 +0000991 int __i4, int __i5, int __i6, int __i7)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000992{
David Blaikie3302f2b2013-01-16 23:08:36 +0000993 return (__m256i)(__v8si){ __i0, __i1, __i2, __i3, __i4, __i5, __i6, __i7 };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000994}
995
Michael Kupersteine45af542015-06-30 13:36:19 +0000996static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000997_mm256_setr_epi16(short __w15, short __w14, short __w13, short __w12,
Craig Topper9fee8ab2015-01-31 06:33:59 +0000998 short __w11, short __w10, short __w09, short __w08,
999 short __w07, short __w06, short __w05, short __w04,
1000 short __w03, short __w02, short __w01, short __w00)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001001{
David Blaikie3302f2b2013-01-16 23:08:36 +00001002 return (__m256i)(__v16hi){ __w15, __w14, __w13, __w12, __w11, __w10, __w09,
1003 __w08, __w07, __w06, __w05, __w04, __w03, __w02, __w01, __w00 };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001004}
1005
Michael Kupersteine45af542015-06-30 13:36:19 +00001006static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001007_mm256_setr_epi8(char __b31, char __b30, char __b29, char __b28,
Craig Topper9fee8ab2015-01-31 06:33:59 +00001008 char __b27, char __b26, char __b25, char __b24,
1009 char __b23, char __b22, char __b21, char __b20,
1010 char __b19, char __b18, char __b17, char __b16,
1011 char __b15, char __b14, char __b13, char __b12,
1012 char __b11, char __b10, char __b09, char __b08,
1013 char __b07, char __b06, char __b05, char __b04,
1014 char __b03, char __b02, char __b01, char __b00)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001015{
1016 return (__m256i)(__v32qi){
David Blaikie3302f2b2013-01-16 23:08:36 +00001017 __b31, __b30, __b29, __b28, __b27, __b26, __b25, __b24,
Craig Topper9fee8ab2015-01-31 06:33:59 +00001018 __b23, __b22, __b21, __b20, __b19, __b18, __b17, __b16,
1019 __b15, __b14, __b13, __b12, __b11, __b10, __b09, __b08,
1020 __b07, __b06, __b05, __b04, __b03, __b02, __b01, __b00 };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001021}
1022
Michael Kupersteine45af542015-06-30 13:36:19 +00001023static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001024_mm256_setr_epi64x(long long __a, long long __b, long long __c, long long __d)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001025{
David Blaikie3302f2b2013-01-16 23:08:36 +00001026 return (__m256i)(__v4di){ __a, __b, __c, __d };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001027}
1028
1029/* Create vectors with repeated elements */
Michael Kupersteine45af542015-06-30 13:36:19 +00001030static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001031_mm256_set1_pd(double __w)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001032{
David Blaikie3302f2b2013-01-16 23:08:36 +00001033 return (__m256d){ __w, __w, __w, __w };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001034}
1035
Michael Kupersteine45af542015-06-30 13:36:19 +00001036static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001037_mm256_set1_ps(float __w)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001038{
David Blaikie3302f2b2013-01-16 23:08:36 +00001039 return (__m256){ __w, __w, __w, __w, __w, __w, __w, __w };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001040}
1041
Michael Kupersteine45af542015-06-30 13:36:19 +00001042static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001043_mm256_set1_epi32(int __i)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001044{
David Blaikie3302f2b2013-01-16 23:08:36 +00001045 return (__m256i)(__v8si){ __i, __i, __i, __i, __i, __i, __i, __i };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001046}
1047
Michael Kupersteine45af542015-06-30 13:36:19 +00001048static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001049_mm256_set1_epi16(short __w)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001050{
David Blaikie3302f2b2013-01-16 23:08:36 +00001051 return (__m256i)(__v16hi){ __w, __w, __w, __w, __w, __w, __w, __w, __w, __w,
1052 __w, __w, __w, __w, __w, __w };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001053}
1054
Michael Kupersteine45af542015-06-30 13:36:19 +00001055static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001056_mm256_set1_epi8(char __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001057{
David Blaikie3302f2b2013-01-16 23:08:36 +00001058 return (__m256i)(__v32qi){ __b, __b, __b, __b, __b, __b, __b, __b, __b, __b,
1059 __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b,
1060 __b, __b, __b, __b, __b, __b, __b };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001061}
1062
Michael Kupersteine45af542015-06-30 13:36:19 +00001063static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001064_mm256_set1_epi64x(long long __q)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001065{
David Blaikie3302f2b2013-01-16 23:08:36 +00001066 return (__m256i)(__v4di){ __q, __q, __q, __q };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001067}
1068
David Blaikie3302f2b2013-01-16 23:08:36 +00001069/* Create __zeroed vectors */
Michael Kupersteine45af542015-06-30 13:36:19 +00001070static __inline __m256d __DEFAULT_FN_ATTRS
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001071_mm256_setzero_pd(void)
1072{
1073 return (__m256d){ 0, 0, 0, 0 };
1074}
1075
Michael Kupersteine45af542015-06-30 13:36:19 +00001076static __inline __m256 __DEFAULT_FN_ATTRS
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001077_mm256_setzero_ps(void)
1078{
1079 return (__m256){ 0, 0, 0, 0, 0, 0, 0, 0 };
1080}
1081
Michael Kupersteine45af542015-06-30 13:36:19 +00001082static __inline __m256i __DEFAULT_FN_ATTRS
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001083_mm256_setzero_si256(void)
1084{
1085 return (__m256i){ 0LL, 0LL, 0LL, 0LL };
1086}
1087
1088/* Cast between vector types */
Michael Kupersteine45af542015-06-30 13:36:19 +00001089static __inline __m256 __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001090_mm256_castpd_ps(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001091{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001092 return (__m256)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001093}
1094
Michael Kupersteine45af542015-06-30 13:36:19 +00001095static __inline __m256i __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001096_mm256_castpd_si256(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001097{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001098 return (__m256i)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001099}
1100
Michael Kupersteine45af542015-06-30 13:36:19 +00001101static __inline __m256d __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001102_mm256_castps_pd(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001103{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001104 return (__m256d)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001105}
1106
Michael Kupersteine45af542015-06-30 13:36:19 +00001107static __inline __m256i __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001108_mm256_castps_si256(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001109{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001110 return (__m256i)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001111}
1112
Michael Kupersteine45af542015-06-30 13:36:19 +00001113static __inline __m256 __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001114_mm256_castsi256_ps(__m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001115{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001116 return (__m256)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001117}
1118
Michael Kupersteine45af542015-06-30 13:36:19 +00001119static __inline __m256d __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001120_mm256_castsi256_pd(__m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001121{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001122 return (__m256d)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001123}
1124
Michael Kupersteine45af542015-06-30 13:36:19 +00001125static __inline __m128d __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001126_mm256_castpd256_pd128(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001127{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001128 return __builtin_shufflevector(__a, __a, 0, 1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001129}
1130
Michael Kupersteine45af542015-06-30 13:36:19 +00001131static __inline __m128 __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001132_mm256_castps256_ps128(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001133{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001134 return __builtin_shufflevector(__a, __a, 0, 1, 2, 3);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001135}
1136
Michael Kupersteine45af542015-06-30 13:36:19 +00001137static __inline __m128i __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001138_mm256_castsi256_si128(__m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001139{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001140 return __builtin_shufflevector(__a, __a, 0, 1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001141}
1142
Michael Kupersteine45af542015-06-30 13:36:19 +00001143static __inline __m256d __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001144_mm256_castpd128_pd256(__m128d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001145{
Craig Topperc5244512013-08-05 06:17:21 +00001146 return __builtin_shufflevector(__a, __a, 0, 1, -1, -1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001147}
1148
Michael Kupersteine45af542015-06-30 13:36:19 +00001149static __inline __m256 __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001150_mm256_castps128_ps256(__m128 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001151{
Craig Topperc5244512013-08-05 06:17:21 +00001152 return __builtin_shufflevector(__a, __a, 0, 1, 2, 3, -1, -1, -1, -1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001153}
1154
Michael Kupersteine45af542015-06-30 13:36:19 +00001155static __inline __m256i __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00001156_mm256_castsi128_si256(__m128i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001157{
Craig Topperc5244512013-08-05 06:17:21 +00001158 return __builtin_shufflevector(__a, __a, 0, 1, -1, -1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001159}
Chad Rosierf8df4f42012-03-20 16:40:00 +00001160
Sanjay Patel7f6aa522015-03-10 15:19:26 +00001161/*
1162 Vector insert.
1163 We use macros rather than inlines because we only want to accept
1164 invocations where the immediate M is a constant expression.
1165*/
1166#define _mm256_insertf128_ps(V1, V2, M) __extension__ ({ \
1167 (__m256)__builtin_shufflevector( \
1168 (__v8sf)(V1), \
1169 (__v8sf)_mm256_castps128_ps256((__m128)(V2)), \
1170 (((M) & 1) ? 0 : 8), \
1171 (((M) & 1) ? 1 : 9), \
1172 (((M) & 1) ? 2 : 10), \
1173 (((M) & 1) ? 3 : 11), \
1174 (((M) & 1) ? 8 : 4), \
1175 (((M) & 1) ? 9 : 5), \
1176 (((M) & 1) ? 10 : 6), \
1177 (((M) & 1) ? 11 : 7) );})
1178
1179#define _mm256_insertf128_pd(V1, V2, M) __extension__ ({ \
1180 (__m256d)__builtin_shufflevector( \
1181 (__v4df)(V1), \
1182 (__v4df)_mm256_castpd128_pd256((__m128d)(V2)), \
1183 (((M) & 1) ? 0 : 4), \
1184 (((M) & 1) ? 1 : 5), \
1185 (((M) & 1) ? 4 : 2), \
1186 (((M) & 1) ? 5 : 3) );})
1187
1188#define _mm256_insertf128_si256(V1, V2, M) __extension__ ({ \
1189 (__m256i)__builtin_shufflevector( \
1190 (__v4di)(V1), \
1191 (__v4di)_mm256_castsi128_si256((__m128i)(V2)), \
1192 (((M) & 1) ? 0 : 4), \
1193 (((M) & 1) ? 1 : 5), \
1194 (((M) & 1) ? 4 : 2), \
1195 (((M) & 1) ? 5 : 3) );})
1196
Sanjay Patel0c351ab2015-03-12 15:50:36 +00001197/*
1198 Vector extract.
1199 We use macros rather than inlines because we only want to accept
1200 invocations where the immediate M is a constant expression.
1201*/
1202#define _mm256_extractf128_ps(V, M) __extension__ ({ \
1203 (__m128)__builtin_shufflevector( \
1204 (__v8sf)(V), \
Sanjay Patelf204b002015-03-12 17:23:46 +00001205 (__v8sf)(_mm256_setzero_ps()), \
Sanjay Patel0c351ab2015-03-12 15:50:36 +00001206 (((M) & 1) ? 4 : 0), \
1207 (((M) & 1) ? 5 : 1), \
1208 (((M) & 1) ? 6 : 2), \
1209 (((M) & 1) ? 7 : 3) );})
1210
1211#define _mm256_extractf128_pd(V, M) __extension__ ({ \
1212 (__m128d)__builtin_shufflevector( \
1213 (__v4df)(V), \
Sanjay Patelf204b002015-03-12 17:23:46 +00001214 (__v4df)(_mm256_setzero_pd()), \
Sanjay Patel0c351ab2015-03-12 15:50:36 +00001215 (((M) & 1) ? 2 : 0), \
1216 (((M) & 1) ? 3 : 1) );})
1217
1218#define _mm256_extractf128_si256(V, M) __extension__ ({ \
1219 (__m128i)__builtin_shufflevector( \
1220 (__v4di)(V), \
Sanjay Patelf204b002015-03-12 17:23:46 +00001221 (__v4di)(_mm256_setzero_si256()), \
Sanjay Patel0c351ab2015-03-12 15:50:36 +00001222 (((M) & 1) ? 2 : 0), \
1223 (((M) & 1) ? 3 : 1) );})
1224
Chad Rosierf8df4f42012-03-20 16:40:00 +00001225/* SIMD load ops (unaligned) */
Michael Kupersteine45af542015-06-30 13:36:19 +00001226static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001227_mm256_loadu2_m128(float const *__addr_hi, float const *__addr_lo)
Chad Rosierf8df4f42012-03-20 16:40:00 +00001228{
1229 struct __loadu_ps {
David Blaikie3302f2b2013-01-16 23:08:36 +00001230 __m128 __v;
Chad Rosierf8df4f42012-03-20 16:40:00 +00001231 } __attribute__((__packed__, __may_alias__));
1232
David Blaikie3302f2b2013-01-16 23:08:36 +00001233 __m256 __v256 = _mm256_castps128_ps256(((struct __loadu_ps*)__addr_lo)->__v);
1234 return _mm256_insertf128_ps(__v256, ((struct __loadu_ps*)__addr_hi)->__v, 1);
Chad Rosierf8df4f42012-03-20 16:40:00 +00001235}
1236
Michael Kupersteine45af542015-06-30 13:36:19 +00001237static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001238_mm256_loadu2_m128d(double const *__addr_hi, double const *__addr_lo)
Chad Rosierf8df4f42012-03-20 16:40:00 +00001239{
1240 struct __loadu_pd {
David Blaikie3302f2b2013-01-16 23:08:36 +00001241 __m128d __v;
Chad Rosierf8df4f42012-03-20 16:40:00 +00001242 } __attribute__((__packed__, __may_alias__));
1243
David Blaikie3302f2b2013-01-16 23:08:36 +00001244 __m256d __v256 = _mm256_castpd128_pd256(((struct __loadu_pd*)__addr_lo)->__v);
1245 return _mm256_insertf128_pd(__v256, ((struct __loadu_pd*)__addr_hi)->__v, 1);
Chad Rosierf8df4f42012-03-20 16:40:00 +00001246}
1247
Michael Kupersteine45af542015-06-30 13:36:19 +00001248static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001249_mm256_loadu2_m128i(__m128i const *__addr_hi, __m128i const *__addr_lo)
Chad Rosierf8df4f42012-03-20 16:40:00 +00001250{
1251 struct __loadu_si128 {
David Blaikie3302f2b2013-01-16 23:08:36 +00001252 __m128i __v;
David Majnemer1cf22e62015-02-04 00:26:10 +00001253 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +00001254 __m256i __v256 = _mm256_castsi128_si256(
1255 ((struct __loadu_si128*)__addr_lo)->__v);
1256 return _mm256_insertf128_si256(__v256,
1257 ((struct __loadu_si128*)__addr_hi)->__v, 1);
Chad Rosierf8df4f42012-03-20 16:40:00 +00001258}
1259
1260/* SIMD store ops (unaligned) */
Michael Kupersteine45af542015-06-30 13:36:19 +00001261static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001262_mm256_storeu2_m128(float *__addr_hi, float *__addr_lo, __m256 __a)
Chad Rosierf8df4f42012-03-20 16:40:00 +00001263{
David Blaikie3302f2b2013-01-16 23:08:36 +00001264 __m128 __v128;
Chad Rosierf8df4f42012-03-20 16:40:00 +00001265
David Blaikie3302f2b2013-01-16 23:08:36 +00001266 __v128 = _mm256_castps256_ps128(__a);
1267 __builtin_ia32_storeups(__addr_lo, __v128);
1268 __v128 = _mm256_extractf128_ps(__a, 1);
1269 __builtin_ia32_storeups(__addr_hi, __v128);
Chad Rosierf8df4f42012-03-20 16:40:00 +00001270}
1271
Michael Kupersteine45af542015-06-30 13:36:19 +00001272static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001273_mm256_storeu2_m128d(double *__addr_hi, double *__addr_lo, __m256d __a)
Chad Rosierf8df4f42012-03-20 16:40:00 +00001274{
David Blaikie3302f2b2013-01-16 23:08:36 +00001275 __m128d __v128;
Chad Rosierf8df4f42012-03-20 16:40:00 +00001276
David Blaikie3302f2b2013-01-16 23:08:36 +00001277 __v128 = _mm256_castpd256_pd128(__a);
1278 __builtin_ia32_storeupd(__addr_lo, __v128);
1279 __v128 = _mm256_extractf128_pd(__a, 1);
1280 __builtin_ia32_storeupd(__addr_hi, __v128);
Chad Rosierf8df4f42012-03-20 16:40:00 +00001281}
1282
Michael Kupersteine45af542015-06-30 13:36:19 +00001283static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001284_mm256_storeu2_m128i(__m128i *__addr_hi, __m128i *__addr_lo, __m256i __a)
Chad Rosierf8df4f42012-03-20 16:40:00 +00001285{
David Blaikie3302f2b2013-01-16 23:08:36 +00001286 __m128i __v128;
Chad Rosierf8df4f42012-03-20 16:40:00 +00001287
David Blaikie3302f2b2013-01-16 23:08:36 +00001288 __v128 = _mm256_castsi256_si128(__a);
1289 __builtin_ia32_storedqu((char *)__addr_lo, (__v16qi)__v128);
1290 __v128 = _mm256_extractf128_si256(__a, 1);
1291 __builtin_ia32_storedqu((char *)__addr_hi, (__v16qi)__v128);
Chad Rosierf8df4f42012-03-20 16:40:00 +00001292}
Richard Smith49e56442013-07-14 05:41:45 +00001293
Michael Kupersteine45af542015-06-30 13:36:19 +00001294static __inline __m256 __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00001295_mm256_set_m128 (__m128 __hi, __m128 __lo) {
1296 return (__m256) __builtin_shufflevector(__lo, __hi, 0, 1, 2, 3, 4, 5, 6, 7);
1297}
1298
Michael Kupersteine45af542015-06-30 13:36:19 +00001299static __inline __m256d __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00001300_mm256_set_m128d (__m128d __hi, __m128d __lo) {
1301 return (__m256d)_mm256_set_m128((__m128)__hi, (__m128)__lo);
1302}
1303
Michael Kupersteine45af542015-06-30 13:36:19 +00001304static __inline __m256i __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00001305_mm256_set_m128i (__m128i __hi, __m128i __lo) {
1306 return (__m256i)_mm256_set_m128((__m128)__hi, (__m128)__lo);
1307}
1308
Michael Kupersteine45af542015-06-30 13:36:19 +00001309static __inline __m256 __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00001310_mm256_setr_m128 (__m128 __lo, __m128 __hi) {
1311 return _mm256_set_m128(__hi, __lo);
1312}
1313
Michael Kupersteine45af542015-06-30 13:36:19 +00001314static __inline __m256d __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00001315_mm256_setr_m128d (__m128d __lo, __m128d __hi) {
1316 return (__m256d)_mm256_set_m128((__m128)__hi, (__m128)__lo);
1317}
1318
Michael Kupersteine45af542015-06-30 13:36:19 +00001319static __inline __m256i __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00001320_mm256_setr_m128i (__m128i __lo, __m128i __hi) {
1321 return (__m256i)_mm256_set_m128((__m128)__hi, (__m128)__lo);
1322}
1323
Michael Kupersteine45af542015-06-30 13:36:19 +00001324#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +00001325
Richard Smith49e56442013-07-14 05:41:45 +00001326#endif /* __AVXINTRIN_H */