blob: f30a5adedb0341b541d625193ab82e7344bfceff [file] [log] [blame]
Ying Wanga6720142011-12-20 14:43:20 -08001/*===---- 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
Stephen Hines996e4dc2013-08-13 01:04:14 -070028#ifndef __AVXINTRIN_H
29#define __AVXINTRIN_H
30
Ying Wanga6720142011-12-20 14:43:20 -080031typedef 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
42/* Arithmetic */
43static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070044_mm256_add_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -080045{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070046 return __a+__b;
Ying Wanga6720142011-12-20 14:43:20 -080047}
48
49static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070050_mm256_add_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -080051{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070052 return __a+__b;
Ying Wanga6720142011-12-20 14:43:20 -080053}
54
55static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070056_mm256_sub_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -080057{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070058 return __a-__b;
Ying Wanga6720142011-12-20 14:43:20 -080059}
60
61static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070062_mm256_sub_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -080063{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070064 return __a-__b;
Ying Wanga6720142011-12-20 14:43:20 -080065}
66
67static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070068_mm256_addsub_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -080069{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070070 return (__m256d)__builtin_ia32_addsubpd256((__v4df)__a, (__v4df)__b);
Ying Wanga6720142011-12-20 14:43:20 -080071}
72
73static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070074_mm256_addsub_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -080075{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070076 return (__m256)__builtin_ia32_addsubps256((__v8sf)__a, (__v8sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -080077}
78
79static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070080_mm256_div_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -080081{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070082 return __a / __b;
Ying Wanga6720142011-12-20 14:43:20 -080083}
84
85static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070086_mm256_div_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -080087{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070088 return __a / __b;
Ying Wanga6720142011-12-20 14:43:20 -080089}
90
91static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070092_mm256_max_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -080093{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070094 return (__m256d)__builtin_ia32_maxpd256((__v4df)__a, (__v4df)__b);
Ying Wanga6720142011-12-20 14:43:20 -080095}
96
97static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -070098_mm256_max_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -080099{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700100 return (__m256)__builtin_ia32_maxps256((__v8sf)__a, (__v8sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800101}
102
103static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700104_mm256_min_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800105{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700106 return (__m256d)__builtin_ia32_minpd256((__v4df)__a, (__v4df)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800107}
108
109static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700110_mm256_min_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800111{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700112 return (__m256)__builtin_ia32_minps256((__v8sf)__a, (__v8sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800113}
114
115static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700116_mm256_mul_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800117{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700118 return __a * __b;
Ying Wanga6720142011-12-20 14:43:20 -0800119}
120
121static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700122_mm256_mul_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800123{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700124 return __a * __b;
Ying Wanga6720142011-12-20 14:43:20 -0800125}
126
127static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700128_mm256_sqrt_pd(__m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -0800129{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700130 return (__m256d)__builtin_ia32_sqrtpd256((__v4df)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800131}
132
133static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700134_mm256_sqrt_ps(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800135{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700136 return (__m256)__builtin_ia32_sqrtps256((__v8sf)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800137}
138
139static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700140_mm256_rsqrt_ps(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800141{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700142 return (__m256)__builtin_ia32_rsqrtps256((__v8sf)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800143}
144
145static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700146_mm256_rcp_ps(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800147{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700148 return (__m256)__builtin_ia32_rcpps256((__v8sf)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800149}
150
Ying Wang60999142013-01-07 13:59:36 -0800151#define _mm256_round_pd(V, M) __extension__ ({ \
152 __m256d __V = (V); \
153 (__m256d)__builtin_ia32_roundpd256((__v4df)__V, (M)); })
Ying Wanga6720142011-12-20 14:43:20 -0800154
Ying Wang60999142013-01-07 13:59:36 -0800155#define _mm256_round_ps(V, M) __extension__ ({ \
156 __m256 __V = (V); \
157 (__m256)__builtin_ia32_roundps256((__v8sf)__V, (M)); })
Ying Wanga6720142011-12-20 14:43:20 -0800158
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 */
165static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700166_mm256_and_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800167{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700168 return (__m256d)((__v4di)__a & (__v4di)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800169}
170
171static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700172_mm256_and_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800173{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700174 return (__m256)((__v8si)__a & (__v8si)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800175}
176
177static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700178_mm256_andnot_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800179{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700180 return (__m256d)(~(__v4di)__a & (__v4di)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800181}
182
183static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700184_mm256_andnot_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800185{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700186 return (__m256)(~(__v8si)__a & (__v8si)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800187}
188
189static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700190_mm256_or_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800191{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700192 return (__m256d)((__v4di)__a | (__v4di)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800193}
194
195static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700196_mm256_or_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800197{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700198 return (__m256)((__v8si)__a | (__v8si)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800199}
200
201static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700202_mm256_xor_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800203{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700204 return (__m256d)((__v4di)__a ^ (__v4di)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800205}
206
207static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700208_mm256_xor_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800209{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700210 return (__m256)((__v8si)__a ^ (__v8si)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800211}
212
213/* Horizontal arithmetic */
214static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700215_mm256_hadd_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800216{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700217 return (__m256d)__builtin_ia32_haddpd256((__v4df)__a, (__v4df)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800218}
219
220static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700221_mm256_hadd_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800222{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700223 return (__m256)__builtin_ia32_haddps256((__v8sf)__a, (__v8sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800224}
225
226static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700227_mm256_hsub_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800228{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700229 return (__m256d)__builtin_ia32_hsubpd256((__v4df)__a, (__v4df)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800230}
231
232static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700233_mm256_hsub_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800234{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700235 return (__m256)__builtin_ia32_hsubps256((__v8sf)__a, (__v8sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800236}
237
238/* Vector permutations */
239static __inline __m128d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700240_mm_permutevar_pd(__m128d __a, __m128i __c)
Ying Wanga6720142011-12-20 14:43:20 -0800241{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700242 return (__m128d)__builtin_ia32_vpermilvarpd((__v2df)__a, (__v2di)__c);
Ying Wanga6720142011-12-20 14:43:20 -0800243}
244
245static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700246_mm256_permutevar_pd(__m256d __a, __m256i __c)
Ying Wanga6720142011-12-20 14:43:20 -0800247{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700248 return (__m256d)__builtin_ia32_vpermilvarpd256((__v4df)__a, (__v4di)__c);
Ying Wanga6720142011-12-20 14:43:20 -0800249}
250
251static __inline __m128 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700252_mm_permutevar_ps(__m128 __a, __m128i __c)
Ying Wanga6720142011-12-20 14:43:20 -0800253{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700254 return (__m128)__builtin_ia32_vpermilvarps((__v4sf)__a, (__v4si)__c);
Ying Wanga6720142011-12-20 14:43:20 -0800255}
256
257static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700258_mm256_permutevar_ps(__m256 __a, __m256i __c)
Ying Wanga6720142011-12-20 14:43:20 -0800259{
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700260 return (__m256)__builtin_ia32_vpermilvarps256((__v8sf)__a, (__v8si)__c);
Ying Wanga6720142011-12-20 14:43:20 -0800261}
262
Ying Wang60999142013-01-07 13:59:36 -0800263#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); })
Ying Wanga6720142011-12-20 14:43:20 -0800267
Ying Wang60999142013-01-07 13:59:36 -0800268#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800274
Ying Wang60999142013-01-07 13:59:36 -0800275#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); })
Ying Wanga6720142011-12-20 14:43:20 -0800280
Ying Wang60999142013-01-07 13:59:36 -0800281#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800290
Ying Wang60999142013-01-07 13:59:36 -0800291#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800295
Ying Wang60999142013-01-07 13:59:36 -0800296#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800300
Ying Wang60999142013-01-07 13:59:36 -0800301#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800305
306/* Vector Blend */
Ying Wang60999142013-01-07 13:59:36 -0800307#define _mm256_blend_pd(V1, V2, M) __extension__ ({ \
308 __m256d __V1 = (V1); \
309 __m256d __V2 = (V2); \
Stephen Hinese65db132014-05-30 13:26:31 -0700310 (__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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800315
Ying Wang60999142013-01-07 13:59:36 -0800316#define _mm256_blend_ps(V1, V2, M) __extension__ ({ \
317 __m256 __V1 = (V1); \
318 __m256 __V2 = (V2); \
Stephen Hinese65db132014-05-30 13:26:31 -0700319 (__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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800328
329static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700330_mm256_blendv_pd(__m256d __a, __m256d __b, __m256d __c)
Ying Wanga6720142011-12-20 14:43:20 -0800331{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700332 return (__m256d)__builtin_ia32_blendvpd256(
333 (__v4df)__a, (__v4df)__b, (__v4df)__c);
Ying Wanga6720142011-12-20 14:43:20 -0800334}
335
336static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700337_mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c)
Ying Wanga6720142011-12-20 14:43:20 -0800338{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700339 return (__m256)__builtin_ia32_blendvps256(
340 (__v8sf)__a, (__v8sf)__b, (__v8sf)__c);
Ying Wanga6720142011-12-20 14:43:20 -0800341}
342
343/* Vector Dot Product */
Ying Wang60999142013-01-07 13:59:36 -0800344#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800348
349/* Vector shuffle */
Ying Wang60999142013-01-07 13:59:36 -0800350#define _mm256_shuffle_ps(a, b, mask) __extension__ ({ \
351 __m256 __a = (a); \
352 __m256 __b = (b); \
353 (__m256)__builtin_shufflevector((__v8sf)__a, (__v8sf)__b, \
Ying Wanga6720142011-12-20 14:43:20 -0800354 (mask) & 0x3, ((mask) & 0xc) >> 2, \
355 (((mask) & 0x30) >> 4) + 8, (((mask) & 0xc0) >> 6) + 8, \
356 ((mask) & 0x3) + 4, (((mask) & 0xc) >> 2) + 4, \
Ying Wang60999142013-01-07 13:59:36 -0800357 (((mask) & 0x30) >> 4) + 12, (((mask) & 0xc0) >> 6) + 12); })
Ying Wanga6720142011-12-20 14:43:20 -0800358
Ying Wang60999142013-01-07 13:59:36 -0800359#define _mm256_shuffle_pd(a, b, mask) __extension__ ({ \
360 __m256d __a = (a); \
361 __m256d __b = (b); \
362 (__m256d)__builtin_shufflevector((__v4df)__a, (__v4df)__b, \
Ying Wanga6720142011-12-20 14:43:20 -0800363 (mask) & 0x1, \
364 (((mask) & 0x2) >> 1) + 4, \
365 (((mask) & 0x4) >> 2) + 2, \
Ying Wang60999142013-01-07 13:59:36 -0800366 (((mask) & 0x8) >> 3) + 6); })
Ying Wanga6720142011-12-20 14:43:20 -0800367
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
Ying Wang60999142013-01-07 13:59:36 -0800402#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800406
Ying Wang60999142013-01-07 13:59:36 -0800407#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800411
Ying Wang60999142013-01-07 13:59:36 -0800412#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800416
Ying Wang60999142013-01-07 13:59:36 -0800417#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800421
Ying Wang60999142013-01-07 13:59:36 -0800422#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800426
Ying Wang60999142013-01-07 13:59:36 -0800427#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)); })
Ying Wanga6720142011-12-20 14:43:20 -0800431
Ying Wanga6720142011-12-20 14:43:20 -0800432static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700433_mm256_extract_epi32(__m256i __a, const int __imm)
Ying Wanga6720142011-12-20 14:43:20 -0800434{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700435 __v8si __b = (__v8si)__a;
Stephen Hines803c4682014-02-19 18:30:17 -0800436 return __b[__imm & 7];
Ying Wanga6720142011-12-20 14:43:20 -0800437}
438
439static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700440_mm256_extract_epi16(__m256i __a, const int __imm)
Ying Wanga6720142011-12-20 14:43:20 -0800441{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700442 __v16hi __b = (__v16hi)__a;
Stephen Hines803c4682014-02-19 18:30:17 -0800443 return __b[__imm & 15];
Ying Wanga6720142011-12-20 14:43:20 -0800444}
445
446static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700447_mm256_extract_epi8(__m256i __a, const int __imm)
Ying Wanga6720142011-12-20 14:43:20 -0800448{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700449 __v32qi __b = (__v32qi)__a;
Stephen Hines803c4682014-02-19 18:30:17 -0800450 return __b[__imm & 31];
Ying Wanga6720142011-12-20 14:43:20 -0800451}
452
453#ifdef __x86_64__
454static __inline long long __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700455_mm256_extract_epi64(__m256i __a, const int __imm)
Ying Wanga6720142011-12-20 14:43:20 -0800456{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700457 __v4di __b = (__v4di)__a;
Stephen Hines803c4682014-02-19 18:30:17 -0800458 return __b[__imm & 3];
Ying Wanga6720142011-12-20 14:43:20 -0800459}
460#endif
461
Ying Wanga6720142011-12-20 14:43:20 -0800462static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700463_mm256_insert_epi32(__m256i __a, int __b, int const __imm)
Ying Wanga6720142011-12-20 14:43:20 -0800464{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700465 __v8si __c = (__v8si)__a;
466 __c[__imm & 7] = __b;
467 return (__m256i)__c;
Ying Wanga6720142011-12-20 14:43:20 -0800468}
469
470static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700471_mm256_insert_epi16(__m256i __a, int __b, int const __imm)
Ying Wanga6720142011-12-20 14:43:20 -0800472{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700473 __v16hi __c = (__v16hi)__a;
474 __c[__imm & 15] = __b;
475 return (__m256i)__c;
Ying Wanga6720142011-12-20 14:43:20 -0800476}
477
478static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700479_mm256_insert_epi8(__m256i __a, int __b, int const __imm)
Ying Wanga6720142011-12-20 14:43:20 -0800480{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700481 __v32qi __c = (__v32qi)__a;
482 __c[__imm & 31] = __b;
483 return (__m256i)__c;
Ying Wanga6720142011-12-20 14:43:20 -0800484}
485
486#ifdef __x86_64__
487static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700488_mm256_insert_epi64(__m256i __a, long long __b, int const __imm)
Ying Wanga6720142011-12-20 14:43:20 -0800489{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700490 __v4di __c = (__v4di)__a;
491 __c[__imm & 3] = __b;
492 return (__m256i)__c;
Ying Wanga6720142011-12-20 14:43:20 -0800493}
494#endif
495
496/* Conversion */
497static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700498_mm256_cvtepi32_pd(__m128i __a)
Ying Wanga6720142011-12-20 14:43:20 -0800499{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700500 return (__m256d)__builtin_ia32_cvtdq2pd256((__v4si) __a);
Ying Wanga6720142011-12-20 14:43:20 -0800501}
502
503static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700504_mm256_cvtepi32_ps(__m256i __a)
Ying Wanga6720142011-12-20 14:43:20 -0800505{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700506 return (__m256)__builtin_ia32_cvtdq2ps256((__v8si) __a);
Ying Wanga6720142011-12-20 14:43:20 -0800507}
508
509static __inline __m128 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700510_mm256_cvtpd_ps(__m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -0800511{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700512 return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
Ying Wanga6720142011-12-20 14:43:20 -0800513}
514
515static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700516_mm256_cvtps_epi32(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800517{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700518 return (__m256i)__builtin_ia32_cvtps2dq256((__v8sf) __a);
Ying Wanga6720142011-12-20 14:43:20 -0800519}
520
521static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700522_mm256_cvtps_pd(__m128 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800523{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700524 return (__m256d)__builtin_ia32_cvtps2pd256((__v4sf) __a);
Ying Wanga6720142011-12-20 14:43:20 -0800525}
526
527static __inline __m128i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700528_mm256_cvttpd_epi32(__m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -0800529{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700530 return (__m128i)__builtin_ia32_cvttpd2dq256((__v4df) __a);
Ying Wanga6720142011-12-20 14:43:20 -0800531}
532
533static __inline __m128i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700534_mm256_cvtpd_epi32(__m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -0800535{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700536 return (__m128i)__builtin_ia32_cvtpd2dq256((__v4df) __a);
Ying Wanga6720142011-12-20 14:43:20 -0800537}
538
539static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700540_mm256_cvttps_epi32(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800541{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700542 return (__m256i)__builtin_ia32_cvttps2dq256((__v8sf) __a);
Ying Wanga6720142011-12-20 14:43:20 -0800543}
544
545/* Vector replicate */
546static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700547_mm256_movehdup_ps(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800548{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700549 return __builtin_shufflevector(__a, __a, 1, 1, 3, 3, 5, 5, 7, 7);
Ying Wanga6720142011-12-20 14:43:20 -0800550}
551
552static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700553_mm256_moveldup_ps(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800554{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700555 return __builtin_shufflevector(__a, __a, 0, 0, 2, 2, 4, 4, 6, 6);
Ying Wanga6720142011-12-20 14:43:20 -0800556}
557
558static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700559_mm256_movedup_pd(__m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -0800560{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700561 return __builtin_shufflevector(__a, __a, 0, 0, 2, 2);
Ying Wanga6720142011-12-20 14:43:20 -0800562}
563
564/* Unpack and Interleave */
565static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700566_mm256_unpackhi_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800567{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700568 return __builtin_shufflevector(__a, __b, 1, 5, 1+2, 5+2);
Ying Wanga6720142011-12-20 14:43:20 -0800569}
570
571static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700572_mm256_unpacklo_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800573{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700574 return __builtin_shufflevector(__a, __b, 0, 4, 0+2, 4+2);
Ying Wanga6720142011-12-20 14:43:20 -0800575}
576
577static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700578_mm256_unpackhi_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800579{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700580 return __builtin_shufflevector(__a, __b, 2, 10, 2+1, 10+1, 6, 14, 6+1, 14+1);
Ying Wanga6720142011-12-20 14:43:20 -0800581}
582
583static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700584_mm256_unpacklo_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800585{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700586 return __builtin_shufflevector(__a, __b, 0, 8, 0+1, 8+1, 4, 12, 4+1, 12+1);
Ying Wanga6720142011-12-20 14:43:20 -0800587}
588
589/* Bit Test */
590static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700591_mm_testz_pd(__m128d __a, __m128d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800592{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700593 return __builtin_ia32_vtestzpd((__v2df)__a, (__v2df)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800594}
595
596static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700597_mm_testc_pd(__m128d __a, __m128d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800598{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700599 return __builtin_ia32_vtestcpd((__v2df)__a, (__v2df)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800600}
601
602static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700603_mm_testnzc_pd(__m128d __a, __m128d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800604{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700605 return __builtin_ia32_vtestnzcpd((__v2df)__a, (__v2df)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800606}
607
608static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700609_mm_testz_ps(__m128 __a, __m128 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800610{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700611 return __builtin_ia32_vtestzps((__v4sf)__a, (__v4sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800612}
613
614static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700615_mm_testc_ps(__m128 __a, __m128 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800616{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700617 return __builtin_ia32_vtestcps((__v4sf)__a, (__v4sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800618}
619
620static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700621_mm_testnzc_ps(__m128 __a, __m128 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800622{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700623 return __builtin_ia32_vtestnzcps((__v4sf)__a, (__v4sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800624}
625
626static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700627_mm256_testz_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800628{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700629 return __builtin_ia32_vtestzpd256((__v4df)__a, (__v4df)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800630}
631
632static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700633_mm256_testc_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800634{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700635 return __builtin_ia32_vtestcpd256((__v4df)__a, (__v4df)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800636}
637
638static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700639_mm256_testnzc_pd(__m256d __a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800640{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700641 return __builtin_ia32_vtestnzcpd256((__v4df)__a, (__v4df)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800642}
643
644static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700645_mm256_testz_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800646{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700647 return __builtin_ia32_vtestzps256((__v8sf)__a, (__v8sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800648}
649
650static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700651_mm256_testc_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800652{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700653 return __builtin_ia32_vtestcps256((__v8sf)__a, (__v8sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800654}
655
656static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700657_mm256_testnzc_ps(__m256 __a, __m256 __b)
Ying Wanga6720142011-12-20 14:43:20 -0800658{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700659 return __builtin_ia32_vtestnzcps256((__v8sf)__a, (__v8sf)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800660}
661
662static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700663_mm256_testz_si256(__m256i __a, __m256i __b)
Ying Wanga6720142011-12-20 14:43:20 -0800664{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700665 return __builtin_ia32_ptestz256((__v4di)__a, (__v4di)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800666}
667
668static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700669_mm256_testc_si256(__m256i __a, __m256i __b)
Ying Wanga6720142011-12-20 14:43:20 -0800670{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700671 return __builtin_ia32_ptestc256((__v4di)__a, (__v4di)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800672}
673
674static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700675_mm256_testnzc_si256(__m256i __a, __m256i __b)
Ying Wanga6720142011-12-20 14:43:20 -0800676{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700677 return __builtin_ia32_ptestnzc256((__v4di)__a, (__v4di)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800678}
679
680/* Vector extract sign mask */
681static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700682_mm256_movemask_pd(__m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -0800683{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700684 return __builtin_ia32_movmskpd256((__v4df)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800685}
686
687static __inline int __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700688_mm256_movemask_ps(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800689{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700690 return __builtin_ia32_movmskps256((__v8sf)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800691}
692
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700693/* Vector __zero */
Ying Wanga6720142011-12-20 14:43:20 -0800694static __inline void __attribute__((__always_inline__, __nodebug__))
695_mm256_zeroall(void)
696{
697 __builtin_ia32_vzeroall();
698}
699
700static __inline void __attribute__((__always_inline__, __nodebug__))
701_mm256_zeroupper(void)
702{
703 __builtin_ia32_vzeroupper();
704}
705
706/* Vector load with broadcast */
707static __inline __m128 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700708_mm_broadcast_ss(float const *__a)
Ying Wanga6720142011-12-20 14:43:20 -0800709{
Stephen Hines990d2fc2014-07-23 10:40:48 -0700710 float __f = *__a;
711 return (__m128)(__v4sf){ __f, __f, __f, __f };
Ying Wanga6720142011-12-20 14:43:20 -0800712}
713
714static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700715_mm256_broadcast_sd(double const *__a)
Ying Wanga6720142011-12-20 14:43:20 -0800716{
Stephen Hines990d2fc2014-07-23 10:40:48 -0700717 double __d = *__a;
718 return (__m256d)(__v4df){ __d, __d, __d, __d };
Ying Wanga6720142011-12-20 14:43:20 -0800719}
720
721static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700722_mm256_broadcast_ss(float const *__a)
Ying Wanga6720142011-12-20 14:43:20 -0800723{
Stephen Hines990d2fc2014-07-23 10:40:48 -0700724 float __f = *__a;
725 return (__m256)(__v8sf){ __f, __f, __f, __f, __f, __f, __f, __f };
Ying Wanga6720142011-12-20 14:43:20 -0800726}
727
728static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700729_mm256_broadcast_pd(__m128d const *__a)
Ying Wanga6720142011-12-20 14:43:20 -0800730{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700731 return (__m256d)__builtin_ia32_vbroadcastf128_pd256(__a);
Ying Wanga6720142011-12-20 14:43:20 -0800732}
733
734static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700735_mm256_broadcast_ps(__m128 const *__a)
Ying Wanga6720142011-12-20 14:43:20 -0800736{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700737 return (__m256)__builtin_ia32_vbroadcastf128_ps256(__a);
Ying Wanga6720142011-12-20 14:43:20 -0800738}
739
740/* SIMD load ops */
741static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700742_mm256_load_pd(double const *__p)
Ying Wanga6720142011-12-20 14:43:20 -0800743{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700744 return *(__m256d *)__p;
Ying Wanga6720142011-12-20 14:43:20 -0800745}
746
747static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700748_mm256_load_ps(float const *__p)
Ying Wanga6720142011-12-20 14:43:20 -0800749{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700750 return *(__m256 *)__p;
Ying Wanga6720142011-12-20 14:43:20 -0800751}
752
753static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700754_mm256_loadu_pd(double const *__p)
Ying Wanga6720142011-12-20 14:43:20 -0800755{
Ying Wang60999142013-01-07 13:59:36 -0800756 struct __loadu_pd {
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700757 __m256d __v;
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700758 } __attribute__((__packed__, __may_alias__));
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700759 return ((struct __loadu_pd*)__p)->__v;
Ying Wanga6720142011-12-20 14:43:20 -0800760}
761
762static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700763_mm256_loadu_ps(float const *__p)
Ying Wanga6720142011-12-20 14:43:20 -0800764{
Ying Wang60999142013-01-07 13:59:36 -0800765 struct __loadu_ps {
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700766 __m256 __v;
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700767 } __attribute__((__packed__, __may_alias__));
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700768 return ((struct __loadu_ps*)__p)->__v;
Ying Wanga6720142011-12-20 14:43:20 -0800769}
770
771static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700772_mm256_load_si256(__m256i const *__p)
Ying Wanga6720142011-12-20 14:43:20 -0800773{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700774 return *__p;
Ying Wanga6720142011-12-20 14:43:20 -0800775}
776
777static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700778_mm256_loadu_si256(__m256i const *__p)
Ying Wanga6720142011-12-20 14:43:20 -0800779{
Ying Wang60999142013-01-07 13:59:36 -0800780 struct __loadu_si256 {
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700781 __m256i __v;
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700782 } __attribute__((__packed__, __may_alias__));
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700783 return ((struct __loadu_si256*)__p)->__v;
Ying Wanga6720142011-12-20 14:43:20 -0800784}
785
786static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700787_mm256_lddqu_si256(__m256i const *__p)
Ying Wanga6720142011-12-20 14:43:20 -0800788{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700789 return (__m256i)__builtin_ia32_lddqu256((char const *)__p);
Ying Wanga6720142011-12-20 14:43:20 -0800790}
791
792/* SIMD store ops */
793static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700794_mm256_store_pd(double *__p, __m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -0800795{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700796 *(__m256d *)__p = __a;
Ying Wanga6720142011-12-20 14:43:20 -0800797}
798
799static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700800_mm256_store_ps(float *__p, __m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800801{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700802 *(__m256 *)__p = __a;
Ying Wanga6720142011-12-20 14:43:20 -0800803}
804
805static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700806_mm256_storeu_pd(double *__p, __m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -0800807{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700808 __builtin_ia32_storeupd256(__p, (__v4df)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800809}
810
811static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700812_mm256_storeu_ps(float *__p, __m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800813{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700814 __builtin_ia32_storeups256(__p, (__v8sf)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800815}
816
817static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700818_mm256_store_si256(__m256i *__p, __m256i __a)
Ying Wanga6720142011-12-20 14:43:20 -0800819{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700820 *__p = __a;
Ying Wanga6720142011-12-20 14:43:20 -0800821}
822
823static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700824_mm256_storeu_si256(__m256i *__p, __m256i __a)
Ying Wanga6720142011-12-20 14:43:20 -0800825{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700826 __builtin_ia32_storedqu256((char *)__p, (__v32qi)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800827}
828
829/* Conditional load ops */
830static __inline __m128d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700831_mm_maskload_pd(double const *__p, __m128d __m)
Ying Wanga6720142011-12-20 14:43:20 -0800832{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700833 return (__m128d)__builtin_ia32_maskloadpd((const __v2df *)__p, (__v2df)__m);
Ying Wanga6720142011-12-20 14:43:20 -0800834}
835
836static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700837_mm256_maskload_pd(double const *__p, __m256d __m)
Ying Wanga6720142011-12-20 14:43:20 -0800838{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700839 return (__m256d)__builtin_ia32_maskloadpd256((const __v4df *)__p,
840 (__v4df)__m);
Ying Wanga6720142011-12-20 14:43:20 -0800841}
842
843static __inline __m128 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700844_mm_maskload_ps(float const *__p, __m128 __m)
Ying Wanga6720142011-12-20 14:43:20 -0800845{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700846 return (__m128)__builtin_ia32_maskloadps((const __v4sf *)__p, (__v4sf)__m);
Ying Wanga6720142011-12-20 14:43:20 -0800847}
848
849static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700850_mm256_maskload_ps(float const *__p, __m256 __m)
Ying Wanga6720142011-12-20 14:43:20 -0800851{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700852 return (__m256)__builtin_ia32_maskloadps256((const __v8sf *)__p, (__v8sf)__m);
Ying Wanga6720142011-12-20 14:43:20 -0800853}
854
855/* Conditional store ops */
856static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700857_mm256_maskstore_ps(float *__p, __m256 __m, __m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800858{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700859 __builtin_ia32_maskstoreps256((__v8sf *)__p, (__v8sf)__m, (__v8sf)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800860}
861
862static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700863_mm_maskstore_pd(double *__p, __m128d __m, __m128d __a)
Ying Wanga6720142011-12-20 14:43:20 -0800864{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700865 __builtin_ia32_maskstorepd((__v2df *)__p, (__v2df)__m, (__v2df)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800866}
867
868static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700869_mm256_maskstore_pd(double *__p, __m256d __m, __m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -0800870{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700871 __builtin_ia32_maskstorepd256((__v4df *)__p, (__v4df)__m, (__v4df)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800872}
873
874static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700875_mm_maskstore_ps(float *__p, __m128 __m, __m128 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800876{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700877 __builtin_ia32_maskstoreps((__v4sf *)__p, (__v4sf)__m, (__v4sf)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800878}
879
880/* Cacheability support ops */
881static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700882_mm256_stream_si256(__m256i *__a, __m256i __b)
Ying Wanga6720142011-12-20 14:43:20 -0800883{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700884 __builtin_ia32_movntdq256((__v4di *)__a, (__v4di)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800885}
886
887static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700888_mm256_stream_pd(double *__a, __m256d __b)
Ying Wanga6720142011-12-20 14:43:20 -0800889{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700890 __builtin_ia32_movntpd256(__a, (__v4df)__b);
Ying Wanga6720142011-12-20 14:43:20 -0800891}
892
893static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700894_mm256_stream_ps(float *__p, __m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -0800895{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700896 __builtin_ia32_movntps256(__p, (__v8sf)__a);
Ying Wanga6720142011-12-20 14:43:20 -0800897}
898
899/* Create vectors */
900static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700901_mm256_set_pd(double __a, double __b, double __c, double __d)
Ying Wanga6720142011-12-20 14:43:20 -0800902{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700903 return (__m256d){ __d, __c, __b, __a };
Ying Wanga6720142011-12-20 14:43:20 -0800904}
905
906static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700907_mm256_set_ps(float __a, float __b, float __c, float __d,
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700908 float __e, float __f, float __g, float __h)
Ying Wanga6720142011-12-20 14:43:20 -0800909{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700910 return (__m256){ __h, __g, __f, __e, __d, __c, __b, __a };
Ying Wanga6720142011-12-20 14:43:20 -0800911}
912
913static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700914_mm256_set_epi32(int __i0, int __i1, int __i2, int __i3,
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700915 int __i4, int __i5, int __i6, int __i7)
Ying Wanga6720142011-12-20 14:43:20 -0800916{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700917 return (__m256i)(__v8si){ __i7, __i6, __i5, __i4, __i3, __i2, __i1, __i0 };
Ying Wanga6720142011-12-20 14:43:20 -0800918}
919
920static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700921_mm256_set_epi16(short __w15, short __w14, short __w13, short __w12,
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700922 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)
Ying Wanga6720142011-12-20 14:43:20 -0800925{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700926 return (__m256i)(__v16hi){ __w00, __w01, __w02, __w03, __w04, __w05, __w06,
927 __w07, __w08, __w09, __w10, __w11, __w12, __w13, __w14, __w15 };
Ying Wanga6720142011-12-20 14:43:20 -0800928}
929
930static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700931_mm256_set_epi8(char __b31, char __b30, char __b29, char __b28,
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700932 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)
Ying Wanga6720142011-12-20 14:43:20 -0800939{
940 return (__m256i)(__v32qi){
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700941 __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
Ying Wanga6720142011-12-20 14:43:20 -0800945 };
946}
947
948static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700949_mm256_set_epi64x(long long __a, long long __b, long long __c, long long __d)
Ying Wanga6720142011-12-20 14:43:20 -0800950{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700951 return (__m256i)(__v4di){ __d, __c, __b, __a };
Ying Wanga6720142011-12-20 14:43:20 -0800952}
953
954/* Create vectors with elements in reverse order */
955static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700956_mm256_setr_pd(double __a, double __b, double __c, double __d)
Ying Wanga6720142011-12-20 14:43:20 -0800957{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700958 return (__m256d){ __a, __b, __c, __d };
Ying Wanga6720142011-12-20 14:43:20 -0800959}
960
961static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700962_mm256_setr_ps(float __a, float __b, float __c, float __d,
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700963 float __e, float __f, float __g, float __h)
Ying Wanga6720142011-12-20 14:43:20 -0800964{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700965 return (__m256){ __a, __b, __c, __d, __e, __f, __g, __h };
Ying Wanga6720142011-12-20 14:43:20 -0800966}
967
968static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700969_mm256_setr_epi32(int __i0, int __i1, int __i2, int __i3,
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700970 int __i4, int __i5, int __i6, int __i7)
Ying Wanga6720142011-12-20 14:43:20 -0800971{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700972 return (__m256i)(__v8si){ __i0, __i1, __i2, __i3, __i4, __i5, __i6, __i7 };
Ying Wanga6720142011-12-20 14:43:20 -0800973}
974
975static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700976_mm256_setr_epi16(short __w15, short __w14, short __w13, short __w12,
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700977 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)
Ying Wanga6720142011-12-20 14:43:20 -0800980{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700981 return (__m256i)(__v16hi){ __w15, __w14, __w13, __w12, __w11, __w10, __w09,
982 __w08, __w07, __w06, __w05, __w04, __w03, __w02, __w01, __w00 };
Ying Wanga6720142011-12-20 14:43:20 -0800983}
984
985static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700986_mm256_setr_epi8(char __b31, char __b30, char __b29, char __b28,
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700987 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)
Ying Wanga6720142011-12-20 14:43:20 -0800994{
995 return (__m256i)(__v32qi){
Stephen Hinesc6ee7df2013-04-02 18:41:57 -0700996 __b31, __b30, __b29, __b28, __b27, __b26, __b25, __b24,
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700997 __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 };
Ying Wanga6720142011-12-20 14:43:20 -08001000}
1001
1002static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001003_mm256_setr_epi64x(long long __a, long long __b, long long __c, long long __d)
Ying Wanga6720142011-12-20 14:43:20 -08001004{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001005 return (__m256i)(__v4di){ __a, __b, __c, __d };
Ying Wanga6720142011-12-20 14:43:20 -08001006}
1007
1008/* Create vectors with repeated elements */
1009static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001010_mm256_set1_pd(double __w)
Ying Wanga6720142011-12-20 14:43:20 -08001011{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001012 return (__m256d){ __w, __w, __w, __w };
Ying Wanga6720142011-12-20 14:43:20 -08001013}
1014
1015static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001016_mm256_set1_ps(float __w)
Ying Wanga6720142011-12-20 14:43:20 -08001017{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001018 return (__m256){ __w, __w, __w, __w, __w, __w, __w, __w };
Ying Wanga6720142011-12-20 14:43:20 -08001019}
1020
1021static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001022_mm256_set1_epi32(int __i)
Ying Wanga6720142011-12-20 14:43:20 -08001023{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001024 return (__m256i)(__v8si){ __i, __i, __i, __i, __i, __i, __i, __i };
Ying Wanga6720142011-12-20 14:43:20 -08001025}
1026
1027static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001028_mm256_set1_epi16(short __w)
Ying Wanga6720142011-12-20 14:43:20 -08001029{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001030 return (__m256i)(__v16hi){ __w, __w, __w, __w, __w, __w, __w, __w, __w, __w,
1031 __w, __w, __w, __w, __w, __w };
Ying Wanga6720142011-12-20 14:43:20 -08001032}
1033
1034static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001035_mm256_set1_epi8(char __b)
Ying Wanga6720142011-12-20 14:43:20 -08001036{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001037 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 };
Ying Wanga6720142011-12-20 14:43:20 -08001040}
1041
1042static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001043_mm256_set1_epi64x(long long __q)
Ying Wanga6720142011-12-20 14:43:20 -08001044{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001045 return (__m256i)(__v4di){ __q, __q, __q, __q };
Ying Wanga6720142011-12-20 14:43:20 -08001046}
1047
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001048/* Create __zeroed vectors */
Ying Wanga6720142011-12-20 14:43:20 -08001049static __inline __m256d __attribute__((__always_inline__, __nodebug__))
1050_mm256_setzero_pd(void)
1051{
1052 return (__m256d){ 0, 0, 0, 0 };
1053}
1054
1055static __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
1061static __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 */
1068static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001069_mm256_castpd_ps(__m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -08001070{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001071 return (__m256)__a;
Ying Wanga6720142011-12-20 14:43:20 -08001072}
1073
1074static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001075_mm256_castpd_si256(__m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -08001076{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001077 return (__m256i)__a;
Ying Wanga6720142011-12-20 14:43:20 -08001078}
1079
1080static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001081_mm256_castps_pd(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -08001082{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001083 return (__m256d)__a;
Ying Wanga6720142011-12-20 14:43:20 -08001084}
1085
1086static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001087_mm256_castps_si256(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -08001088{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001089 return (__m256i)__a;
Ying Wanga6720142011-12-20 14:43:20 -08001090}
1091
1092static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001093_mm256_castsi256_ps(__m256i __a)
Ying Wanga6720142011-12-20 14:43:20 -08001094{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001095 return (__m256)__a;
Ying Wanga6720142011-12-20 14:43:20 -08001096}
1097
1098static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001099_mm256_castsi256_pd(__m256i __a)
Ying Wanga6720142011-12-20 14:43:20 -08001100{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001101 return (__m256d)__a;
Ying Wanga6720142011-12-20 14:43:20 -08001102}
1103
1104static __inline __m128d __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001105_mm256_castpd256_pd128(__m256d __a)
Ying Wanga6720142011-12-20 14:43:20 -08001106{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001107 return __builtin_shufflevector(__a, __a, 0, 1);
Ying Wanga6720142011-12-20 14:43:20 -08001108}
1109
1110static __inline __m128 __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001111_mm256_castps256_ps128(__m256 __a)
Ying Wanga6720142011-12-20 14:43:20 -08001112{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001113 return __builtin_shufflevector(__a, __a, 0, 1, 2, 3);
Ying Wanga6720142011-12-20 14:43:20 -08001114}
1115
1116static __inline __m128i __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001117_mm256_castsi256_si128(__m256i __a)
Ying Wanga6720142011-12-20 14:43:20 -08001118{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001119 return __builtin_shufflevector(__a, __a, 0, 1);
Ying Wanga6720142011-12-20 14:43:20 -08001120}
1121
1122static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001123_mm256_castpd128_pd256(__m128d __a)
Ying Wanga6720142011-12-20 14:43:20 -08001124{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001125 return __builtin_shufflevector(__a, __a, 0, 1, -1, -1);
Ying Wanga6720142011-12-20 14:43:20 -08001126}
1127
1128static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001129_mm256_castps128_ps256(__m128 __a)
Ying Wanga6720142011-12-20 14:43:20 -08001130{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001131 return __builtin_shufflevector(__a, __a, 0, 1, 2, 3, -1, -1, -1, -1);
Ying Wanga6720142011-12-20 14:43:20 -08001132}
1133
1134static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hines996e4dc2013-08-13 01:04:14 -07001135_mm256_castsi128_si256(__m128i __a)
Ying Wanga6720142011-12-20 14:43:20 -08001136{
Stephen Hines996e4dc2013-08-13 01:04:14 -07001137 return __builtin_shufflevector(__a, __a, 0, 1, -1, -1);
Ying Wanga6720142011-12-20 14:43:20 -08001138}
Ying Wang60999142013-01-07 13:59:36 -08001139
Stephen Hines3f868232015-04-10 09:22:19 -07001140/*
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
Ying Wang60999142013-01-07 13:59:36 -08001204/* SIMD load ops (unaligned) */
1205static __inline __m256 __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001206_mm256_loadu2_m128(float const *__addr_hi, float const *__addr_lo)
Ying Wang60999142013-01-07 13:59:36 -08001207{
1208 struct __loadu_ps {
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001209 __m128 __v;
Ying Wang60999142013-01-07 13:59:36 -08001210 } __attribute__((__packed__, __may_alias__));
1211
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001212 __m256 __v256 = _mm256_castps128_ps256(((struct __loadu_ps*)__addr_lo)->__v);
1213 return _mm256_insertf128_ps(__v256, ((struct __loadu_ps*)__addr_hi)->__v, 1);
Ying Wang60999142013-01-07 13:59:36 -08001214}
1215
1216static __inline __m256d __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001217_mm256_loadu2_m128d(double const *__addr_hi, double const *__addr_lo)
Ying Wang60999142013-01-07 13:59:36 -08001218{
1219 struct __loadu_pd {
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001220 __m128d __v;
Ying Wang60999142013-01-07 13:59:36 -08001221 } __attribute__((__packed__, __may_alias__));
1222
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001223 __m256d __v256 = _mm256_castpd128_pd256(((struct __loadu_pd*)__addr_lo)->__v);
1224 return _mm256_insertf128_pd(__v256, ((struct __loadu_pd*)__addr_hi)->__v, 1);
Ying Wang60999142013-01-07 13:59:36 -08001225}
1226
1227static __inline __m256i __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001228_mm256_loadu2_m128i(__m128i const *__addr_hi, __m128i const *__addr_lo)
Ying Wang60999142013-01-07 13:59:36 -08001229{
1230 struct __loadu_si128 {
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001231 __m128i __v;
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -07001232 } __attribute__((__packed__, __may_alias__));
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001233 __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);
Ying Wang60999142013-01-07 13:59:36 -08001237}
1238
1239/* SIMD store ops (unaligned) */
1240static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001241_mm256_storeu2_m128(float *__addr_hi, float *__addr_lo, __m256 __a)
Ying Wang60999142013-01-07 13:59:36 -08001242{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001243 __m128 __v128;
Ying Wang60999142013-01-07 13:59:36 -08001244
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001245 __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);
Ying Wang60999142013-01-07 13:59:36 -08001249}
1250
1251static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001252_mm256_storeu2_m128d(double *__addr_hi, double *__addr_lo, __m256d __a)
Ying Wang60999142013-01-07 13:59:36 -08001253{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001254 __m128d __v128;
Ying Wang60999142013-01-07 13:59:36 -08001255
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001256 __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);
Ying Wang60999142013-01-07 13:59:36 -08001260}
1261
1262static __inline void __attribute__((__always_inline__, __nodebug__))
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001263_mm256_storeu2_m128i(__m128i *__addr_hi, __m128i *__addr_lo, __m256i __a)
Ying Wang60999142013-01-07 13:59:36 -08001264{
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001265 __m128i __v128;
Ying Wang60999142013-01-07 13:59:36 -08001266
Stephen Hinesc6ee7df2013-04-02 18:41:57 -07001267 __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);
Ying Wang60999142013-01-07 13:59:36 -08001271}
Stephen Hines996e4dc2013-08-13 01:04:14 -07001272
1273#endif /* __AVXINTRIN_H */