blob: 20e9ef4e57600c86f620accb9a093a10e0bf382e [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
Chandler Carruthcbe64112015-10-01 23:40:12 +000038/* We need an explicitly signed variant for char. Note that this shouldn't
39 * appear in the interface though. */
40typedef signed char __v32qs __attribute__((__vector_size__(32)));
41
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000042typedef float __m256 __attribute__ ((__vector_size__ (32)));
43typedef double __m256d __attribute__((__vector_size__(32)));
44typedef long long __m256i __attribute__((__vector_size__(32)));
45
Eric Christopher4d1851682015-06-17 07:09:20 +000046/* Define the default attributes for the functions in this file. */
Michael Kupersteine45af542015-06-30 13:36:19 +000047#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("avx")))
Eric Christopher4d1851682015-06-17 07:09:20 +000048
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000049/* Arithmetic */
Ekaterina Romanova13f189d2016-03-11 00:05:54 +000050/// \brief Adds two 256-bit vectors of [4 x double].
51///
52/// \headerfile <x86intrin.h>
53///
54/// This intrinsic corresponds to the \c VADDPD / ADDPD instruction.
55///
56/// \param __a
57/// A 256-bit vector of [4 x double] containing one of the source operands.
58/// \param __b
59/// A 256-bit vector of [4 x double] containing one of the source operands.
60/// \returns A 256-bit vector of [4 x double] containing the sums of both
61/// operands.
Michael Kupersteine45af542015-06-30 13:36:19 +000062static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000063_mm256_add_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000064{
Craig Topper1aa231e2016-05-16 06:38:42 +000065 return (__m256d)((__v4df)__a+(__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000066}
67
Ekaterina Romanova13f189d2016-03-11 00:05:54 +000068/// \brief Adds two 256-bit vectors of [8 x float].
69///
70/// \headerfile <x86intrin.h>
71///
72/// This intrinsic corresponds to the \c VADDPS / ADDPS instruction.
73///
74/// \param __a
75/// A 256-bit vector of [8 x float] containing one of the source operands.
76/// \param __b
77/// A 256-bit vector of [8 x float] containing one of the source operands.
78/// \returns A 256-bit vector of [8 x float] containing the sums of both
79/// operands.
Michael Kupersteine45af542015-06-30 13:36:19 +000080static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000081_mm256_add_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000082{
Craig Topper1aa231e2016-05-16 06:38:42 +000083 return (__m256)((__v8sf)__a+(__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +000084}
85
Ekaterina Romanova13f189d2016-03-11 00:05:54 +000086/// \brief Subtracts two 256-bit vectors of [4 x double].
87///
88/// \headerfile <x86intrin.h>
89///
90/// This intrinsic corresponds to the \c VSUBPD / SUBPD instruction.
91///
92/// \param __a
93/// A 256-bit vector of [4 x double] containing the minuend.
94/// \param __b
95/// A 256-bit vector of [4 x double] containing the subtrahend.
96/// \returns A 256-bit vector of [4 x double] containing the differences between
97/// both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +000098static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000099_mm256_sub_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000100{
Craig Topper1aa231e2016-05-16 06:38:42 +0000101 return (__m256d)((__v4df)__a-(__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000102}
103
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000104/// \brief Subtracts two 256-bit vectors of [8 x float].
105///
106/// \headerfile <x86intrin.h>
107///
108/// This intrinsic corresponds to the \c VSUBPS / SUBPS instruction.
109///
110/// \param __a
111/// A 256-bit vector of [8 x float] containing the minuend.
112/// \param __b
113/// A 256-bit vector of [8 x float] containing the subtrahend.
114/// \returns A 256-bit vector of [8 x float] containing the differences between
115/// both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000116static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000117_mm256_sub_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000118{
Craig Topper1aa231e2016-05-16 06:38:42 +0000119 return (__m256)((__v8sf)__a-(__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000120}
121
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000122/// \brief Adds the even-indexed values and subtracts the odd-indexed values of
123/// two 256-bit vectors of [4 x double].
124///
125/// \headerfile <x86intrin.h>
126///
127/// This intrinsic corresponds to the \c VADDSUBPD / ADDSUBPD instruction.
128///
129/// \param __a
130/// A 256-bit vector of [4 x double] containing the left source operand.
131/// \param __b
132/// A 256-bit vector of [4 x double] containing the right source operand.
133/// \returns A 256-bit vector of [4 x double] containing the alternating sums
134/// and differences between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000135static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000136_mm256_addsub_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000137{
David Blaikie3302f2b2013-01-16 23:08:36 +0000138 return (__m256d)__builtin_ia32_addsubpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000139}
140
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000141/// \brief Adds the even-indexed values and subtracts the odd-indexed values of
142/// two 256-bit vectors of [8 x float].
143///
144/// \headerfile <x86intrin.h>
145///
146/// This intrinsic corresponds to the \c VADDSUBPS / ADDSUBPS instruction.
147///
148/// \param __a
149/// A 256-bit vector of [8 x float] containing the left source operand.
150/// \param __b
151/// A 256-bit vector of [8 x float] containing the right source operand.
152/// \returns A 256-bit vector of [8 x float] containing the alternating sums and
153/// differences between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000154static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000155_mm256_addsub_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000156{
David Blaikie3302f2b2013-01-16 23:08:36 +0000157 return (__m256)__builtin_ia32_addsubps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000158}
159
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000160/// \brief Divides two 256-bit vectors of [4 x double].
161///
162/// \headerfile <x86intrin.h>
163///
164/// This intrinsic corresponds to the \c VDIVPD / DIVPD instruction.
165///
166/// \param __a
167/// A 256-bit vector of [4 x double] containing the dividend.
168/// \param __b
169/// A 256-bit vector of [4 x double] containing the divisor.
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000170/// \returns A 256-bit vector of [4 x double] containing the quotients of both
171/// operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000172static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000173_mm256_div_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000174{
Craig Topper1aa231e2016-05-16 06:38:42 +0000175 return (__m256d)((__v4df)__a/(__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000176}
177
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000178/// \brief Divides two 256-bit vectors of [8 x float].
179///
180/// \headerfile <x86intrin.h>
181///
182/// This intrinsic corresponds to the \c VDIVPS / DIVPS instruction.
183///
184/// \param __a
185/// A 256-bit vector of [8 x float] containing the dividend.
186/// \param __b
187/// A 256-bit vector of [8 x float] containing the divisor.
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000188/// \returns A 256-bit vector of [8 x float] containing the quotients of both
189/// operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000190static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000191_mm256_div_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000192{
Craig Topper1aa231e2016-05-16 06:38:42 +0000193 return (__m256)((__v8sf)__a/(__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000194}
195
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000196/// \brief Compares two 256-bit vectors of [4 x double] and returns the greater
197/// of each pair of values.
198///
199/// \headerfile <x86intrin.h>
200///
201/// This intrinsic corresponds to the \c VMAXPD / MAXPD instruction.
202///
203/// \param __a
204/// A 256-bit vector of [4 x double] containing one of the operands.
205/// \param __b
206/// A 256-bit vector of [4 x double] containing one of the operands.
207/// \returns A 256-bit vector of [4 x double] containing the maximum values
208/// between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000209static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000210_mm256_max_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000211{
David Blaikie3302f2b2013-01-16 23:08:36 +0000212 return (__m256d)__builtin_ia32_maxpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000213}
214
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000215/// \brief Compares two 256-bit vectors of [8 x float] and returns the greater
216/// of each pair of values.
217///
218/// \headerfile <x86intrin.h>
219///
220/// This intrinsic corresponds to the \c VMAXPS / MAXPS instruction.
221///
222/// \param __a
223/// A 256-bit vector of [8 x float] containing one of the operands.
224/// \param __b
225/// A 256-bit vector of [8 x float] containing one of the operands.
226/// \returns A 256-bit vector of [8 x float] containing the maximum values
227/// between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000228static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000229_mm256_max_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000230{
David Blaikie3302f2b2013-01-16 23:08:36 +0000231 return (__m256)__builtin_ia32_maxps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000232}
233
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000234/// \brief Compares two 256-bit vectors of [4 x double] and returns the lesser
235/// of each pair of values.
236///
237/// \headerfile <x86intrin.h>
238///
239/// This intrinsic corresponds to the \c VMINPD / MINPD instruction.
240///
241/// \param __a
242/// A 256-bit vector of [4 x double] containing one of the operands.
243/// \param __b
244/// A 256-bit vector of [4 x double] containing one of the operands.
245/// \returns A 256-bit vector of [4 x double] containing the minimum values
246/// between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000247static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000248_mm256_min_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000249{
David Blaikie3302f2b2013-01-16 23:08:36 +0000250 return (__m256d)__builtin_ia32_minpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000251}
252
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000253/// \brief Compares two 256-bit vectors of [8 x float] and returns the lesser
254/// of each pair of values.
255///
256/// \headerfile <x86intrin.h>
257///
258/// This intrinsic corresponds to the \c VMINPS / MINPS instruction.
259///
260/// \param __a
261/// A 256-bit vector of [8 x float] containing one of the operands.
262/// \param __b
263/// A 256-bit vector of [8 x float] containing one of the operands.
264/// \returns A 256-bit vector of [8 x float] containing the minimum values
265/// between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000266static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000267_mm256_min_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000268{
David Blaikie3302f2b2013-01-16 23:08:36 +0000269 return (__m256)__builtin_ia32_minps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000270}
271
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000272/// \brief Multiplies two 256-bit vectors of [4 x double].
273///
274/// \headerfile <x86intrin.h>
275///
276/// This intrinsic corresponds to the \c VMULPD / MULPD instruction.
277///
278/// \param __a
279/// A 256-bit vector of [4 x double] containing one of the operands.
280/// \param __b
281/// A 256-bit vector of [4 x double] containing one of the operands.
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000282/// \returns A 256-bit vector of [4 x double] containing the products of both
283/// operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000284static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000285_mm256_mul_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000286{
Craig Topper1aa231e2016-05-16 06:38:42 +0000287 return (__m256d)((__v4df)__a * (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000288}
289
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000290/// \brief Multiplies two 256-bit vectors of [8 x float].
291///
292/// \headerfile <x86intrin.h>
293///
294/// This intrinsic corresponds to the \c VMULPS / MULPS instruction.
295///
296/// \param __a
297/// A 256-bit vector of [8 x float] containing one of the operands.
298/// \param __b
299/// A 256-bit vector of [8 x float] containing one of the operands.
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000300/// \returns A 256-bit vector of [8 x float] containing the products of both
301/// operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000302static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000303_mm256_mul_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000304{
Craig Topper1aa231e2016-05-16 06:38:42 +0000305 return (__m256)((__v8sf)__a * (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000306}
307
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000308/// \brief Calculates the square roots of the values in a 256-bit vector of
309/// [4 x double].
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000310///
311/// \headerfile <x86intrin.h>
312///
313/// This intrinsic corresponds to the \c VSQRTPD / SQRTPD instruction.
314///
315/// \param __a
316/// A 256-bit vector of [4 x double].
317/// \returns A 256-bit vector of [4 x double] containing the square roots of the
318/// values in the operand.
Michael Kupersteine45af542015-06-30 13:36:19 +0000319static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000320_mm256_sqrt_pd(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000321{
David Blaikie3302f2b2013-01-16 23:08:36 +0000322 return (__m256d)__builtin_ia32_sqrtpd256((__v4df)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000323}
324
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000325/// \brief Calculates the square roots of the values in a 256-bit vector of
326/// [8 x float].
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000327///
328/// \headerfile <x86intrin.h>
329///
330/// This intrinsic corresponds to the \c VSQRTPS / SQRTPS instruction.
331///
332/// \param __a
333/// A 256-bit vector of [8 x float].
334/// \returns A 256-bit vector of [8 x float] containing the square roots of the
335/// values in the operand.
Michael Kupersteine45af542015-06-30 13:36:19 +0000336static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000337_mm256_sqrt_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000338{
David Blaikie3302f2b2013-01-16 23:08:36 +0000339 return (__m256)__builtin_ia32_sqrtps256((__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000340}
341
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000342/// \brief Calculates the reciprocal square roots of the values in a 256-bit
343/// vector of [8 x float].
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000344///
345/// \headerfile <x86intrin.h>
346///
347/// This intrinsic corresponds to the \c VRSQRTPS / RSQRTPS instruction.
348///
349/// \param __a
350/// A 256-bit vector of [8 x float].
351/// \returns A 256-bit vector of [8 x float] containing the reciprocal square
352/// roots of the values in the operand.
Michael Kupersteine45af542015-06-30 13:36:19 +0000353static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000354_mm256_rsqrt_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000355{
David Blaikie3302f2b2013-01-16 23:08:36 +0000356 return (__m256)__builtin_ia32_rsqrtps256((__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000357}
358
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000359/// \brief Calculates the reciprocals of the values in a 256-bit vector of
360/// [8 x float].
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000361///
362/// \headerfile <x86intrin.h>
363///
364/// This intrinsic corresponds to the \c VRCPPS / RCPPS instruction.
365///
366/// \param __a
367/// A 256-bit vector of [8 x float].
368/// \returns A 256-bit vector of [8 x float] containing the reciprocals of the
369/// values in the operand.
Michael Kupersteine45af542015-06-30 13:36:19 +0000370static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000371_mm256_rcp_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000372{
David Blaikie3302f2b2013-01-16 23:08:36 +0000373 return (__m256)__builtin_ia32_rcpps256((__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000374}
375
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000376/// \brief Rounds the values in a 256-bit vector of [4 x double] as specified
377/// by the byte operand. The source values are rounded to integer values and
378/// returned as 64-bit double-precision floating-point values.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000379///
380/// \headerfile <x86intrin.h>
381///
382/// \code
383/// __m256d _mm256_round_pd(__m256d V, const int M);
384/// \endcode
385///
386/// This intrinsic corresponds to the \c VROUNDPD / ROUNDPD instruction.
387///
388/// \param V
389/// A 256-bit vector of [4 x double].
390/// \param M
391/// An integer value that specifies the rounding operation.
392/// Bits [7:4] are reserved.
393/// Bit [3] is a precision exception value:
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000394/// 0: A normal PE exception is used.
395/// 1: The PE field is not updated.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000396/// Bit [2] is the rounding control source:
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000397/// 0: Use bits [1:0] of M.
398/// 1: Use the current MXCSR setting.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000399/// Bits [1:0] contain the rounding control definition:
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000400/// 00: Nearest.
401/// 01: Downward (toward negative infinity).
402/// 10: Upward (toward positive infinity).
403/// 11: Truncated.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000404/// \returns A 256-bit vector of [4 x double] containing the rounded values.
Chad Rosier060d03b2011-12-17 00:15:26 +0000405#define _mm256_round_pd(V, M) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +0000406 (__m256d)__builtin_ia32_roundpd256((__v4df)(__m256d)(V), (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000407
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000408/// \brief Rounds the values stored in a 256-bit vector of [8 x float] as
409/// specified by the byte operand. The source values are rounded to integer
410/// values and returned as floating-point values.
411///
412/// \headerfile <x86intrin.h>
413///
414/// \code
415/// __m256 _mm256_round_ps(__m256 V, const int M);
416/// \endcode
417///
418/// This intrinsic corresponds to the \c VROUNDPS / ROUNDPS instruction.
419///
420/// \param V
421/// A 256-bit vector of [8 x float].
422/// \param M
423/// An integer value that specifies the rounding operation.
424/// Bits [7:4] are reserved.
425/// Bit [3] is a precision exception value:
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000426/// 0: A normal PE exception is used.
427/// 1: The PE field is not updated.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000428/// Bit [2] is the rounding control source:
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000429/// 0: Use bits [1:0] of M.
430/// 1: Use the current MXCSR setting.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000431/// Bits [1:0] contain the rounding control definition:
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000432/// 00: Nearest.
433/// 01: Downward (toward negative infinity).
434/// 10: Upward (toward positive infinity).
435/// 11: Truncated.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000436/// \returns A 256-bit vector of [8 x float] containing the rounded values.
Chad Rosier060d03b2011-12-17 00:15:26 +0000437#define _mm256_round_ps(V, M) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +0000438 (__m256)__builtin_ia32_roundps256((__v8sf)(__m256)(V), (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000439
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000440/// \brief Rounds up the values stored in a 256-bit vector of [4 x double]. The
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000441/// source values are rounded up to integer values and returned as 64-bit
442/// double-precision floating-point values.
443///
444/// \headerfile <x86intrin.h>
445///
446/// \code
447/// __m256d _mm256_ceil_pd(__m256d V);
448/// \endcode
449///
450/// This intrinsic corresponds to the \c VROUNDPD / ROUNDPD instruction.
451///
452/// \param V
453/// A 256-bit vector of [4 x double].
454/// \returns A 256-bit vector of [4 x double] containing the rounded up values.
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000455#define _mm256_ceil_pd(V) _mm256_round_pd((V), _MM_FROUND_CEIL)
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000456
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000457/// \brief Rounds down the values stored in a 256-bit vector of [4 x double].
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000458/// The source values are rounded down to integer values and returned as
459/// 64-bit double-precision floating-point values.
460///
461/// \headerfile <x86intrin.h>
462///
463/// \code
464/// __m256d _mm256_floor_pd(__m256d V);
465/// \endcode
466///
467/// This intrinsic corresponds to the \c VROUNDPD / ROUNDPD instruction.
468///
469/// \param V
470/// A 256-bit vector of [4 x double].
471/// \returns A 256-bit vector of [4 x double] containing the rounded down
472/// values.
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000473#define _mm256_floor_pd(V) _mm256_round_pd((V), _MM_FROUND_FLOOR)
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000474
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000475/// \brief Rounds up the values stored in a 256-bit vector of [8 x float]. The
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000476/// source values are rounded up to integer values and returned as
477/// floating-point values.
478///
479/// \headerfile <x86intrin.h>
480///
481/// \code
482/// __m256 _mm256_ceil_ps(__m256 V);
483/// \endcode
484///
485/// This intrinsic corresponds to the \c VROUNDPS / ROUNDPS instruction.
486///
487/// \param V
488/// A 256-bit vector of [8 x float].
489/// \returns A 256-bit vector of [8 x float] containing the rounded up values.
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000490#define _mm256_ceil_ps(V) _mm256_round_ps((V), _MM_FROUND_CEIL)
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000491
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000492/// \brief Rounds down the values stored in a 256-bit vector of [8 x float]. The
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000493/// source values are rounded down to integer values and returned as
494/// floating-point values.
495///
496/// \headerfile <x86intrin.h>
497///
498/// \code
499/// __m256 _mm256_floor_ps(__m256 V);
500/// \endcode
501///
502/// This intrinsic corresponds to the \c VROUNDPS / ROUNDPS instruction.
503///
504/// \param V
505/// A 256-bit vector of [8 x float].
506/// \returns A 256-bit vector of [8 x float] containing the rounded down values.
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000507#define _mm256_floor_ps(V) _mm256_round_ps((V), _MM_FROUND_FLOOR)
508
509/* Logical */
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000510/// \brief Performs a bitwise AND of two 256-bit vectors of [4 x double].
511///
512/// \headerfile <x86intrin.h>
513///
514/// This intrinsic corresponds to the \c VANDPD / ANDPD instruction.
515///
516/// \param __a
517/// A 256-bit vector of [4 x double] containing one of the source operands.
518/// \param __b
519/// A 256-bit vector of [4 x double] containing one of the source operands.
520/// \returns A 256-bit vector of [4 x double] containing the bitwise AND of the
521/// values between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000522static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000523_mm256_and_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000524{
David Blaikie3302f2b2013-01-16 23:08:36 +0000525 return (__m256d)((__v4di)__a & (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000526}
527
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000528/// \brief Performs a bitwise AND of two 256-bit vectors of [8 x float].
529///
530/// \headerfile <x86intrin.h>
531///
532/// This intrinsic corresponds to the \c VANDPS / ANDPS instruction.
533///
534/// \param __a
535/// A 256-bit vector of [8 x float] containing one of the source operands.
536/// \param __b
537/// A 256-bit vector of [8 x float] containing one of the source operands.
538/// \returns A 256-bit vector of [8 x float] containing the bitwise AND of the
539/// values between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000540static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000541_mm256_and_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000542{
David Blaikie3302f2b2013-01-16 23:08:36 +0000543 return (__m256)((__v8si)__a & (__v8si)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000544}
545
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000546/// \brief Performs a bitwise AND of two 256-bit vectors of [4 x double], using
547/// the one's complement of the values contained in the first source operand.
548///
549/// \headerfile <x86intrin.h>
550///
551/// This intrinsic corresponds to the \c VANDNPD / ANDNPD instruction.
552///
553/// \param __a
554/// A 256-bit vector of [4 x double] containing the left source operand. The
555/// one's complement of this value is used in the bitwise AND.
556/// \param __b
557/// A 256-bit vector of [4 x double] containing the right source operand.
558/// \returns A 256-bit vector of [4 x double] containing the bitwise AND of the
559/// values of the second operand and the one's complement of the first
560/// operand.
Michael Kupersteine45af542015-06-30 13:36:19 +0000561static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000562_mm256_andnot_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000563{
David Blaikie3302f2b2013-01-16 23:08:36 +0000564 return (__m256d)(~(__v4di)__a & (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000565}
566
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000567/// \brief Performs a bitwise AND of two 256-bit vectors of [8 x float], using
568/// the one's complement of the values contained in the first source operand.
569///
570/// \headerfile <x86intrin.h>
571///
572/// This intrinsic corresponds to the \c VANDNPS / ANDNPS instruction.
573///
574/// \param __a
575/// A 256-bit vector of [8 x float] containing the left source operand. The
576/// one's complement of this value is used in the bitwise AND.
577/// \param __b
578/// A 256-bit vector of [8 x float] containing the right source operand.
579/// \returns A 256-bit vector of [8 x float] containing the bitwise AND of the
580/// values of the second operand and the one's complement of the first
581/// operand.
Michael Kupersteine45af542015-06-30 13:36:19 +0000582static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000583_mm256_andnot_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000584{
David Blaikie3302f2b2013-01-16 23:08:36 +0000585 return (__m256)(~(__v8si)__a & (__v8si)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000586}
587
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000588/// \brief Performs a bitwise OR of two 256-bit vectors of [4 x double].
589///
590/// \headerfile <x86intrin.h>
591///
592/// This intrinsic corresponds to the \c VORPD / ORPD instruction.
593///
594/// \param __a
595/// A 256-bit vector of [4 x double] containing one of the source operands.
596/// \param __b
597/// A 256-bit vector of [4 x double] containing one of the source operands.
598/// \returns A 256-bit vector of [4 x double] containing the bitwise OR of the
599/// values between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000600static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000601_mm256_or_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000602{
David Blaikie3302f2b2013-01-16 23:08:36 +0000603 return (__m256d)((__v4di)__a | (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000604}
605
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000606/// \brief Performs a bitwise OR of two 256-bit vectors of [8 x float].
607///
608/// \headerfile <x86intrin.h>
609///
610/// This intrinsic corresponds to the \c VORPS / ORPS instruction.
611///
612/// \param __a
613/// A 256-bit vector of [8 x float] containing one of the source operands.
614/// \param __b
615/// A 256-bit vector of [8 x float] containing one of the source operands.
616/// \returns A 256-bit vector of [8 x float] containing the bitwise OR of the
617/// values between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000618static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000619_mm256_or_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000620{
David Blaikie3302f2b2013-01-16 23:08:36 +0000621 return (__m256)((__v8si)__a | (__v8si)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000622}
623
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000624/// \brief Performs a bitwise XOR of two 256-bit vectors of [4 x double].
625///
626/// \headerfile <x86intrin.h>
627///
628/// This intrinsic corresponds to the \c VXORPD / XORPD instruction.
629///
630/// \param __a
631/// A 256-bit vector of [4 x double] containing one of the source operands.
632/// \param __b
633/// A 256-bit vector of [4 x double] containing one of the source operands.
634/// \returns A 256-bit vector of [4 x double] containing the bitwise XOR of the
635/// values between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000636static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000637_mm256_xor_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000638{
David Blaikie3302f2b2013-01-16 23:08:36 +0000639 return (__m256d)((__v4di)__a ^ (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000640}
641
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000642/// \brief Performs a bitwise XOR of two 256-bit vectors of [8 x float].
643///
644/// \headerfile <x86intrin.h>
645///
646/// This intrinsic corresponds to the \c VXORPS / XORPS instruction.
647///
648/// \param __a
649/// A 256-bit vector of [8 x float] containing one of the source operands.
650/// \param __b
651/// A 256-bit vector of [8 x float] containing one of the source operands.
652/// \returns A 256-bit vector of [8 x float] containing the bitwise XOR of the
653/// values between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000654static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000655_mm256_xor_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000656{
David Blaikie3302f2b2013-01-16 23:08:36 +0000657 return (__m256)((__v8si)__a ^ (__v8si)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000658}
659
660/* Horizontal arithmetic */
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000661/// \brief Horizontally adds the adjacent pairs of values contained in two
662/// 256-bit vectors of [4 x double].
663///
664/// \headerfile <x86intrin.h>
665///
666/// This intrinsic corresponds to the \c VHADDPD / HADDPD instruction.
667///
668/// \param __a
669/// A 256-bit vector of [4 x double] containing one of the source operands.
670/// The horizontal sums of the values are returned in the even-indexed
671/// elements of a vector of [4 x double].
672/// \param __b
673/// A 256-bit vector of [4 x double] containing one of the source operands.
674/// The horizontal sums of the values are returned in the odd-indexed
675/// elements of a vector of [4 x double].
676/// \returns A 256-bit vector of [4 x double] containing the horizontal sums of
677/// both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000678static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000679_mm256_hadd_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000680{
David Blaikie3302f2b2013-01-16 23:08:36 +0000681 return (__m256d)__builtin_ia32_haddpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000682}
683
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000684/// \brief Horizontally adds the adjacent pairs of values contained in two
685/// 256-bit vectors of [8 x float].
686///
687/// \headerfile <x86intrin.h>
688///
689/// This intrinsic corresponds to the \c VHADDPS / HADDPS instruction.
690///
691/// \param __a
692/// A 256-bit vector of [8 x float] containing one of the source operands.
693/// The horizontal sums of the values are returned in the elements with
694/// index 0, 1, 4, 5 of a vector of [8 x float].
695/// \param __b
696/// A 256-bit vector of [8 x float] containing one of the source operands.
697/// The horizontal sums of the values are returned in the elements with
698/// index 2, 3, 6, 7 of a vector of [8 x float].
699/// \returns A 256-bit vector of [8 x float] containing the horizontal sums of
700/// both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000701static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000702_mm256_hadd_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000703{
David Blaikie3302f2b2013-01-16 23:08:36 +0000704 return (__m256)__builtin_ia32_haddps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000705}
706
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000707/// \brief Horizontally subtracts the adjacent pairs of values contained in two
708/// 256-bit vectors of [4 x double].
709///
710/// \headerfile <x86intrin.h>
711///
712/// This intrinsic corresponds to the \c VHSUBPD / HSUBPD instruction.
713///
714/// \param __a
715/// A 256-bit vector of [4 x double] containing one of the source operands.
716/// The horizontal differences between the values are returned in the
717/// even-indexed elements of a vector of [4 x double].
718/// \param __b
719/// A 256-bit vector of [4 x double] containing one of the source operands.
720/// The horizontal differences between the values are returned in the
721/// odd-indexed elements of a vector of [4 x double].
722/// \returns A 256-bit vector of [4 x double] containing the horizontal
723/// differences of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000724static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000725_mm256_hsub_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000726{
David Blaikie3302f2b2013-01-16 23:08:36 +0000727 return (__m256d)__builtin_ia32_hsubpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000728}
729
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000730/// \brief Horizontally subtracts the adjacent pairs of values contained in two
731/// 256-bit vectors of [8 x float].
732///
733/// \headerfile <x86intrin.h>
734///
735/// This intrinsic corresponds to the \c VHSUBPS / HSUBPS instruction.
736///
737/// \param __a
738/// A 256-bit vector of [8 x float] containing one of the source operands.
739/// The horizontal differences between the values are returned in the
740/// elements with index 0, 1, 4, 5 of a vector of [8 x float].
741/// \param __b
742/// A 256-bit vector of [8 x float] containing one of the source operands.
743/// The horizontal differences between the values are returned in the
744/// elements with index 2, 3, 6, 7 of a vector of [8 x float].
745/// \returns A 256-bit vector of [8 x float] containing the horizontal
746/// differences of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000747static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000748_mm256_hsub_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000749{
David Blaikie3302f2b2013-01-16 23:08:36 +0000750 return (__m256)__builtin_ia32_hsubps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000751}
752
753/* Vector permutations */
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000754/// \brief Copies the values in a 128-bit vector of [2 x double] as specified
755/// by the 128-bit integer vector operand.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000756///
757/// \headerfile <x86intrin.h>
758///
759/// This intrinsic corresponds to the \c VPERMILPD / PERMILPD instruction.
760///
761/// \param __a
762/// A 128-bit vector of [2 x double].
763/// \param __c
764/// A 128-bit integer vector operand specifying how the values are to be
765/// copied.
766/// Bit [1]:
767/// 0: Bits [63:0] of the source are copied to bits [63:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000768/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000769/// 1: Bits [127:64] of the source are copied to bits [63:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000770/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000771/// Bit [65]:
772/// 0: Bits [63:0] of the source are copied to bits [127:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000773/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000774/// 1: Bits [127:64] of the source are copied to bits [127:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000775/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000776/// \returns A 128-bit vector of [2 x double] containing the copied values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000777static __inline __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000778_mm_permutevar_pd(__m128d __a, __m128i __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000779{
David Blaikie3302f2b2013-01-16 23:08:36 +0000780 return (__m128d)__builtin_ia32_vpermilvarpd((__v2df)__a, (__v2di)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000781}
782
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000783/// \brief Copies the values in a 256-bit vector of [4 x double] as
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000784/// specified by the 256-bit integer vector operand.
785///
786/// \headerfile <x86intrin.h>
787///
788/// This intrinsic corresponds to the \c VPERMILPD / PERMILPD instruction.
789///
790/// \param __a
791/// A 256-bit vector of [4 x double].
792/// \param __c
793/// A 256-bit integer vector operand specifying how the values are to be
794/// copied.
795/// Bit [1]:
796/// 0: Bits [63:0] of the source are copied to bits [63:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000797/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000798/// 1: Bits [127:64] of the source are copied to bits [63:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000799/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000800/// Bit [65]:
801/// 0: Bits [63:0] of the source are copied to bits [127:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000802/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000803/// 1: Bits [127:64] of the source are copied to bits [127:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000804/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000805/// Bit [129]:
806/// 0: Bits [191:128] of the source are copied to bits [191:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000807/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000808/// 1: Bits [255:192] of the source are copied to bits [191:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000809/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000810/// Bit [193]:
811/// 0: Bits [191:128] of the source are copied to bits [255:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000812/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000813/// 1: Bits [255:192] of the source are copied to bits [255:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000814/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000815/// \returns A 256-bit vector of [4 x double] containing the copied values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000816static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000817_mm256_permutevar_pd(__m256d __a, __m256i __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000818{
David Blaikie3302f2b2013-01-16 23:08:36 +0000819 return (__m256d)__builtin_ia32_vpermilvarpd256((__v4df)__a, (__v4di)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000820}
821
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000822/// \brief Copies the values stored in a 128-bit vector of [4 x float] as
823/// specified by the 128-bit integer vector operand.
824///
825/// \headerfile <x86intrin.h>
826///
827/// This intrinsic corresponds to the \c VPERMILPS / PERMILPS instruction.
828///
829/// \param __a
830/// A 128-bit vector of [4 x float].
831/// \param __c
832/// A 128-bit integer vector operand specifying how the values are to be
833/// copied.
834/// Bits [1:0]:
835/// 00: Bits [31:0] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000836/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000837/// 01: Bits [63:32] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000838/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000839/// 10: Bits [95:64] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000840/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000841/// 11: Bits [127:96] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000842/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000843/// Bits [33:32]:
844/// 00: Bits [31:0] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000845/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000846/// 01: Bits [63:32] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000847/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000848/// 10: Bits [95:64] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000849/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000850/// 11: Bits [127:96] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000851/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000852/// Bits [65:64]:
853/// 00: Bits [31:0] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000854/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000855/// 01: Bits [63:32] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000856/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000857/// 10: Bits [95:64] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000858/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000859/// 11: Bits [127:96] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000860/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000861/// Bits [97:96]:
862/// 00: Bits [31:0] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000863/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000864/// 01: Bits [63:32] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000865/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000866/// 10: Bits [95:64] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000867/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000868/// 11: Bits [127:96] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000869/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000870/// \returns A 128-bit vector of [4 x float] containing the copied values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000871static __inline __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000872_mm_permutevar_ps(__m128 __a, __m128i __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000873{
David Blaikie3302f2b2013-01-16 23:08:36 +0000874 return (__m128)__builtin_ia32_vpermilvarps((__v4sf)__a, (__v4si)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000875}
876
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000877/// \brief Copies the values stored in a 256-bit vector of [8 x float] as
878/// specified by the 256-bit integer vector operand.
879///
880/// \headerfile <x86intrin.h>
881///
882/// This intrinsic corresponds to the \c VPERMILPS / PERMILPS instruction.
883///
884/// \param __a
885/// A 256-bit vector of [8 x float].
886/// \param __c
887/// A 256-bit integer vector operand specifying how the values are to be
888/// copied.
889/// Bits [1:0]:
890/// 00: Bits [31:0] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000891/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000892/// 01: Bits [63:32] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000893/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000894/// 10: Bits [95:64] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000895/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000896/// 11: Bits [127:96] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000897/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000898/// Bits [33:32]:
899/// 00: Bits [31:0] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000900/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000901/// 01: Bits [63:32] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000902/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000903/// 10: Bits [95:64] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000904/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000905/// 11: Bits [127:96] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000906/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000907/// Bits [65:64]:
908/// 00: Bits [31:0] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000909/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000910/// 01: Bits [63:32] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000911/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000912/// 10: Bits [95:64] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000913/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000914/// 11: Bits [127:96] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000915/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000916/// Bits [97:96]:
917/// 00: Bits [31:0] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000918/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000919/// 01: Bits [63:32] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000920/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000921/// 10: Bits [95:64] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000922/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000923/// 11: Bits [127:96] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000924/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000925/// Bits [129:128]:
926/// 00: Bits [159:128] of the source are copied to bits [159:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000927/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000928/// 01: Bits [191:160] of the source are copied to bits [159:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000929/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000930/// 10: Bits [223:192] of the source are copied to bits [159:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000931/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000932/// 11: Bits [255:224] of the source are copied to bits [159:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000933/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000934/// Bits [161:160]:
935/// 00: Bits [159:128] of the source are copied to bits [191:160] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000936/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000937/// 01: Bits [191:160] of the source are copied to bits [191:160] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000938/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000939/// 10: Bits [223:192] of the source are copied to bits [191:160] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000940/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000941/// 11: Bits [255:224] of the source are copied to bits [191:160] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000942/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000943/// Bits [193:192]:
944/// 00: Bits [159:128] of the source are copied to bits [223:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000945/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000946/// 01: Bits [191:160] of the source are copied to bits [223:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000947/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000948/// 10: Bits [223:192] of the source are copied to bits [223:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000949/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000950/// 11: Bits [255:224] of the source are copied to bits [223:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000951/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000952/// Bits [225:224]:
953/// 00: Bits [159:128] of the source are copied to bits [255:224] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000954/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000955/// 01: Bits [191:160] of the source are copied to bits [255:224] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000956/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000957/// 10: Bits [223:192] of the source are copied to bits [255:224] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000958/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000959/// 11: Bits [255:224] of the source are copied to bits [255:224] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000960/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000961/// \returns A 256-bit vector of [8 x float] containing the copied values.
Michael Kupersteine45af542015-06-30 13:36:19 +0000962static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000963_mm256_permutevar_ps(__m256 __a, __m256i __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000964{
Craig Topper9fee8ab2015-01-31 06:33:59 +0000965 return (__m256)__builtin_ia32_vpermilvarps256((__v8sf)__a, (__v8si)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000966}
967
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000968/// \brief Copies the values in a 128-bit vector of [2 x double] as
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000969/// specified by the immediate integer operand.
970///
971/// \headerfile <x86intrin.h>
972///
973/// \code
974/// __m128d _mm_permute_pd(__m128d A, const int C);
975/// \endcode
976///
977/// This intrinsic corresponds to the \c VPERMILPD / PERMILPD instruction.
978///
979/// \param A
980/// A 128-bit vector of [2 x double].
981/// \param C
982/// An immediate integer operand specifying how the values are to be copied.
983/// Bit [0]:
984/// 0: Bits [63:0] of the source are copied to bits [63:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000985/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000986/// 1: Bits [127:64] of the source are copied to bits [63:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000987/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000988/// Bit [1]:
989/// 0: Bits [63:0] of the source are copied to bits [127:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000990/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000991/// 1: Bits [127:64] of the source are copied to bits [127:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000992/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +0000993/// \returns A 128-bit vector of [2 x double] containing the copied values.
Chad Rosier93375d52011-12-17 01:39:56 +0000994#define _mm_permute_pd(A, C) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +0000995 (__m128d)__builtin_shufflevector((__v2df)(__m128d)(A), \
996 (__v2df)_mm_setzero_pd(), \
Craig Topperfec9f8e2012-02-08 05:16:54 +0000997 (C) & 0x1, ((C) & 0x2) >> 1); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +0000998
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +0000999/// \brief Copies the values in a 256-bit vector of [4 x double] as
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001000/// specified by the immediate integer operand.
1001///
1002/// \headerfile <x86intrin.h>
1003///
1004/// \code
1005/// __m256d _mm256_permute_pd(__m256d A, const int C);
1006/// \endcode
1007///
1008/// This intrinsic corresponds to the \c VPERMILPD / PERMILPD instruction.
1009///
1010/// \param A
1011/// A 256-bit vector of [4 x double].
1012/// \param C
1013/// An immediate integer operand specifying how the values are to be copied.
1014/// Bit [0]:
1015/// 0: Bits [63:0] of the source are copied to bits [63:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001016/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001017/// 1: Bits [127:64] of the source are copied to bits [63:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001018/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001019/// Bit [1]:
1020/// 0: Bits [63:0] of the source are copied to bits [127:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001021/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001022/// 1: Bits [127:64] of the source are copied to bits [127:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001023/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001024/// Bit [2]:
1025/// 0: Bits [191:128] of the source are copied to bits [191:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001026/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001027/// 1: Bits [255:192] of the source are copied to bits [191:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001028/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001029/// Bit [3]:
1030/// 0: Bits [191:128] of the source are copied to bits [255:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001031/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001032/// 1: Bits [255:192] of the source are copied to bits [255:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001033/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001034/// \returns A 256-bit vector of [4 x double] containing the copied values.
Chad Rosier93375d52011-12-17 01:39:56 +00001035#define _mm256_permute_pd(A, C) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001036 (__m256d)__builtin_shufflevector((__v4df)(__m256d)(A), \
1037 (__v4df)_mm256_setzero_pd(), \
Craig Topperfec9f8e2012-02-08 05:16:54 +00001038 (C) & 0x1, ((C) & 0x2) >> 1, \
1039 2 + (((C) & 0x4) >> 2), \
1040 2 + (((C) & 0x8) >> 3)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001041
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001042/// \brief Copies the values in a 128-bit vector of [4 x float] as
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001043/// specified by the immediate integer operand.
1044///
1045/// \headerfile <x86intrin.h>
1046///
1047/// \code
1048/// __m128 _mm_permute_ps(__m128 A, const int C);
1049/// \endcode
1050///
1051/// This intrinsic corresponds to the \c VPERMILPS / PERMILPS instruction.
1052///
1053/// \param A
1054/// A 128-bit vector of [4 x float].
1055/// \param C
1056/// An immediate integer operand specifying how the values are to be copied.
1057/// Bits [1:0]:
1058/// 00: Bits [31:0] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001059/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001060/// 01: Bits [63:32] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001061/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001062/// 10: Bits [95:64] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001063/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001064/// 11: Bits [127:96] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001065/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001066/// Bits [3:2]:
1067/// 00: Bits [31:0] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001068/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001069/// 01: Bits [63:32] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001070/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001071/// 10: Bits [95:64] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001072/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001073/// 11: Bits [127:96] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001074/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001075/// Bits [5:4]:
1076/// 00: Bits [31:0] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001077/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001078/// 01: Bits [63:32] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001079/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001080/// 10: Bits [95:64] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001081/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001082/// 11: Bits [127:96] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001083/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001084/// Bits [7:6]:
1085/// 00: Bits [31:0] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001086/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001087/// 01: Bits [63:32] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001088/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001089/// 10: Bits [95:64] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001090/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001091/// 11: Bits [127:96] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001092/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001093/// \returns A 128-bit vector of [4 x float] containing the copied values.
Chad Rosier7caca842011-12-17 01:51:05 +00001094#define _mm_permute_ps(A, C) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001095 (__m128)__builtin_shufflevector((__v4sf)(__m128)(A), \
1096 (__v4sf)_mm_setzero_ps(), \
Craig Topperfec9f8e2012-02-08 05:16:54 +00001097 (C) & 0x3, ((C) & 0xc) >> 2, \
Craig Topper678a53c2012-03-30 05:09:18 +00001098 ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001099
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001100/// \brief Copies the values in a 256-bit vector of [8 x float] as
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001101/// specified by the immediate integer operand.
1102///
1103/// \headerfile <x86intrin.h>
1104///
1105/// \code
1106/// __m256 _mm256_permute_ps(__m256 A, const int C);
1107/// \endcode
1108///
1109/// This intrinsic corresponds to the \c VPERMILPS / PERMILPS instruction.
1110///
1111/// \param A
1112/// A 256-bit vector of [8 x float].
1113/// \param C
1114/// An immediate integer operand specifying how the values are to be copied.
1115/// Bits [1:0]:
1116/// 00: Bits [31:0] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001117/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001118/// 01: Bits [63:32] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001119/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001120/// 10: Bits [95:64] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001121/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001122/// 11: Bits [127:96] of the source are copied to bits [31:0] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001123/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001124/// Bits [3:2]:
1125/// 00: Bits [31:0] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001126/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001127/// 01: Bits [63:32] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001128/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001129/// 10: Bits [95:64] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001130/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001131/// 11: Bits [127:96] of the source are copied to bits [63:32] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001132/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001133/// Bits [5:4]:
1134/// 00: Bits [31:0] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001135/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001136/// 01: Bits [63:32] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001137/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001138/// 10: Bits [95:64] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001139/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001140/// 11: Bits [127:96] of the source are copied to bits [95:64] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001141/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001142/// Bits [7:6]:
1143/// 00: Bits [31:0] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001144/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001145/// 01: Bits [63:32] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001146/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001147/// 10: Bits [95:64] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001148/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001149/// 11: Bits [127:96] of the source are copied to bits [127:96] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001150/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001151/// Bits [1:0]:
1152/// 00: Bits [159:128] of the source are copied to bits [159:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001153/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001154/// 01: Bits [191:160] of the source are copied to bits [159:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001155/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001156/// 10: Bits [223:192] of the source are copied to bits [159:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001157/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001158/// 11: Bits [255:224] of the source are copied to bits [159:128] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001159/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001160/// Bits [3:2]:
1161/// 00: Bits [159:128] of the source are copied to bits [191:160] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001162/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001163/// 01: Bits [191:160] of the source are copied to bits [191:160] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001164/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001165/// 10: Bits [223:192] of the source are copied to bits [191:160] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001166/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001167/// 11: Bits [255:224] of the source are copied to bits [191:160] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001168/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001169/// Bits [5:4]:
1170/// 00: Bits [159:128] of the source are copied to bits [223:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001171/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001172/// 01: Bits [191:160] of the source are copied to bits [223:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001173/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001174/// 10: Bits [223:192] of the source are copied to bits [223:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001175/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001176/// 11: Bits [255:224] of the source are copied to bits [223:192] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001177/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001178/// Bits [7:6]:
1179/// 00: Bits [159:128] of the source are copied to bits [255:224] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001180/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001181/// 01: Bits [191:160] of the source are copied to bits [255:224] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001182/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001183/// 10: Bits [223:192] of the source are copied to bits [255:224] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001184/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001185/// 11: Bits [255:224] of the source are copied to bits [255:224] of the
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001186/// returned vector.
Ekaterina Romanova13f189d2016-03-11 00:05:54 +00001187/// \returns A 256-bit vector of [8 x float] containing the copied values.
Chad Rosier7caca842011-12-17 01:51:05 +00001188#define _mm256_permute_ps(A, C) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001189 (__m256)__builtin_shufflevector((__v8sf)(__m256)(A), \
1190 (__v8sf)_mm256_setzero_ps(), \
Craig Topperfec9f8e2012-02-08 05:16:54 +00001191 (C) & 0x3, ((C) & 0xc) >> 2, \
1192 ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6, \
1193 4 + (((C) & 0x03) >> 0), \
1194 4 + (((C) & 0x0c) >> 2), \
1195 4 + (((C) & 0x30) >> 4), \
1196 4 + (((C) & 0xc0) >> 6)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001197
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001198/// \brief Permutes 128-bit data values stored in two 256-bit vectors of
1199/// [4 x double], as specified by the immediate integer operand.
1200///
1201/// \headerfile <x86intrin.h>
1202///
1203/// \code
1204/// __m256d _mm256_permute2f128_pd(__m256d V1, __m256d V2, const int M);
1205/// \endcode
1206///
1207/// This intrinsic corresponds to the \c VPERM2F128 / PERM2F128 instruction.
1208///
1209/// \param V1
1210/// A 256-bit vector of [4 x double].
1211/// \param V2
1212/// A 256-bit vector of [4 x double.
1213/// \param M
1214/// An immediate integer operand specifying how the values are to be
1215/// permuted.
1216/// Bits [1:0]:
1217/// 00: Bits [127:0] of operand V1 are copied to bits [127:0] of the
1218/// destination.
1219/// 01: Bits [255:128] of operand V1 are copied to bits [127:0] of the
1220/// destination.
1221/// 10: Bits [127:0] of operand V2 are copied to bits [127:0] of the
1222/// destination.
1223/// 11: Bits [255:128] of operand V2 are copied to bits [127:0] of the
1224/// destination.
1225/// Bits [5:4]:
1226/// 00: Bits [127:0] of operand V1 are copied to bits [255:128] of the
1227/// destination.
1228/// 01: Bits [255:128] of operand V1 are copied to bits [255:128] of the
1229/// destination.
1230/// 10: Bits [127:0] of operand V2 are copied to bits [255:128] of the
1231/// destination.
1232/// 11: Bits [255:128] of operand V2 are copied to bits [255:128] of the
1233/// destination.
1234/// \returns A 256-bit vector of [4 x double] containing the copied values.
Chad Rosier9138fea252011-12-16 21:07:34 +00001235#define _mm256_permute2f128_pd(V1, V2, M) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001236 (__m256d)__builtin_ia32_vperm2f128_pd256((__v4df)(__m256d)(V1), \
1237 (__v4df)(__m256d)(V2), (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001238
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001239/// \brief Permutes 128-bit data values stored in two 256-bit vectors of
1240/// [8 x float], as specified by the immediate integer operand.
1241///
1242/// \headerfile <x86intrin.h>
1243///
1244/// \code
1245/// __m256 _mm256_permute2f128_ps(__m256 V1, __m256 V2, const int M);
1246/// \endcode
1247///
1248/// This intrinsic corresponds to the \c VPERM2F128 / PERM2F128 instruction.
1249///
1250/// \param V1
1251/// A 256-bit vector of [8 x float].
1252/// \param V2
1253/// A 256-bit vector of [8 x float].
1254/// \param M
1255/// An immediate integer operand specifying how the values are to be
1256/// permuted.
1257/// Bits [1:0]:
1258/// 00: Bits [127:0] of operand V1 are copied to bits [127:0] of the
1259/// destination.
1260/// 01: Bits [255:128] of operand V1 are copied to bits [127:0] of the
1261/// destination.
1262/// 10: Bits [127:0] of operand V2 are copied to bits [127:0] of the
1263/// destination.
1264/// 11: Bits [255:128] of operand V2 are copied to bits [127:0] of the
1265/// destination.
1266/// Bits [5:4]:
1267/// 00: Bits [127:0] of operand V1 are copied to bits [255:128] of the
1268/// destination.
1269/// 01: Bits [255:128] of operand V1 are copied to bits [255:128] of the
1270/// destination.
1271/// 10: Bits [127:0] of operand V2 are copied to bits [255:128] of the
1272/// destination.
1273/// 11: Bits [255:128] of operand V2 are copied to bits [255:128] of the
1274/// destination.
1275/// \returns A 256-bit vector of [8 x float] containing the copied values.
Chad Rosier9138fea252011-12-16 21:07:34 +00001276#define _mm256_permute2f128_ps(V1, V2, M) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001277 (__m256)__builtin_ia32_vperm2f128_ps256((__v8sf)(__m256)(V1), \
1278 (__v8sf)(__m256)(V2), (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001279
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001280/// \brief Permutes 128-bit data values stored in two 256-bit integer vectors,
1281/// as specified by the immediate integer operand.
1282///
1283/// \headerfile <x86intrin.h>
1284///
1285/// \code
1286/// __m256i _mm256_permute2f128_si256(__m256i V1, __m256i V2, const int M);
1287/// \endcode
1288///
1289/// This intrinsic corresponds to the \c VPERM2F128 / PERM2F128 instruction.
1290///
1291/// \param V1
1292/// A 256-bit integer vector.
1293/// \param V2
1294/// A 256-bit integer vector.
1295/// \param M
1296/// An immediate integer operand specifying how the values are to be copied.
1297/// Bits [1:0]:
1298/// 00: Bits [127:0] of operand V1 are copied to bits [127:0] of the
1299/// destination.
1300/// 01: Bits [255:128] of operand V1 are copied to bits [127:0] of the
1301/// destination.
1302/// 10: Bits [127:0] of operand V2 are copied to bits [127:0] of the
1303/// destination.
1304/// 11: Bits [255:128] of operand V2 are copied to bits [127:0] of the
1305/// destination.
1306/// Bits [5:4]:
1307/// 00: Bits [127:0] of operand V1 are copied to bits [255:128] of the
1308/// destination.
1309/// 01: Bits [255:128] of operand V1 are copied to bits [255:128] of the
1310/// destination.
1311/// 10: Bits [127:0] of operand V2 are copied to bits [255:128] of the
1312/// destination.
1313/// 11: Bits [255:128] of operand V2 are copied to bits [255:128] of the
1314/// destination.
1315/// \returns A 256-bit integer vector containing the copied values.
Chad Rosier9138fea252011-12-16 21:07:34 +00001316#define _mm256_permute2f128_si256(V1, V2, M) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001317 (__m256i)__builtin_ia32_vperm2f128_si256((__v8si)(__m256i)(V1), \
1318 (__v8si)(__m256i)(V2), (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001319
1320/* Vector Blend */
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001321/// \brief Merges 64-bit double-precision data values stored in either of the
1322/// two 256-bit vectors of [4 x double], as specified by the immediate
1323/// integer operand.
1324///
1325/// \headerfile <x86intrin.h>
1326///
1327/// \code
1328/// __m256d _mm256_blend_pd(__m256d V1, __m256d V2, const int M);
1329/// \endcode
1330///
1331/// This intrinsic corresponds to the \c VBLENDPD / BLENDPD instruction.
1332///
1333/// \param V1
1334/// A 256-bit vector of [4 x double].
1335/// \param V2
1336/// A 256-bit vector of [4 x double].
1337/// \param M
1338/// An immediate integer operand, with mask bits [3:0] specifying how the
1339/// values are to be copied. The position of the mask bit corresponds to the
1340/// index of a copied value. When a mask bit is 0, the corresponding 64-bit
1341/// element in operand V1 is copied to the same position in the destination.
1342/// When a mask bit is 1, the corresponding 64-bit element in operand V2 is
1343/// copied to the same position in the destination.
1344/// \returns A 256-bit vector of [4 x double] containing the copied values.
Eli Friedmanf16beb32011-11-10 00:11:13 +00001345#define _mm256_blend_pd(V1, V2, M) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001346 (__m256d)__builtin_shufflevector((__v4df)(__m256d)(V1), \
1347 (__v4df)(__m256d)(V2), \
Filipe Cabecinhas5d289b42014-05-13 02:37:02 +00001348 (((M) & 0x01) ? 4 : 0), \
1349 (((M) & 0x02) ? 5 : 1), \
1350 (((M) & 0x04) ? 6 : 2), \
1351 (((M) & 0x08) ? 7 : 3)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001352
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001353/// \brief Merges 32-bit single-precision data values stored in either of the
1354/// two 256-bit vectors of [8 x float], as specified by the immediate
1355/// integer operand.
1356///
1357/// \headerfile <x86intrin.h>
1358///
1359/// \code
1360/// __m256 _mm256_blend_ps(__m256 V1, __m256 V2, const int M);
1361/// \endcode
1362///
1363/// This intrinsic corresponds to the \c VBLENDPS / BLENDPS instruction.
1364///
1365/// \param V1
1366/// A 256-bit vector of [8 x float].
1367/// \param V2
1368/// A 256-bit vector of [8 x float].
1369/// \param M
1370/// An immediate integer operand, with mask bits [7:0] specifying how the
1371/// values are to be copied. The position of the mask bit corresponds to the
1372/// index of a copied value. When a mask bit is 0, the corresponding 32-bit
1373/// element in operand V1 is copied to the same position in the destination.
1374/// When a mask bit is 1, the corresponding 32-bit element in operand V2 is
1375/// copied to the same position in the destination.
1376/// \returns A 256-bit vector of [8 x float] containing the copied values.
Eli Friedmanf16beb32011-11-10 00:11:13 +00001377#define _mm256_blend_ps(V1, V2, M) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001378 (__m256)__builtin_shufflevector((__v8sf)(__m256)(V1), \
1379 (__v8sf)(__m256)(V2), \
Filipe Cabecinhas5d289b42014-05-13 02:37:02 +00001380 (((M) & 0x01) ? 8 : 0), \
1381 (((M) & 0x02) ? 9 : 1), \
1382 (((M) & 0x04) ? 10 : 2), \
1383 (((M) & 0x08) ? 11 : 3), \
1384 (((M) & 0x10) ? 12 : 4), \
1385 (((M) & 0x20) ? 13 : 5), \
1386 (((M) & 0x40) ? 14 : 6), \
1387 (((M) & 0x80) ? 15 : 7)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001388
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001389/// \brief Merges 64-bit double-precision data values stored in either of the
1390/// two 256-bit vectors of [4 x double], as specified by the 256-bit vector
1391/// operand.
1392///
1393/// \headerfile <x86intrin.h>
1394///
1395/// This intrinsic corresponds to the \c VBLENDVPD / BLENDVPD instruction.
1396///
1397/// \param __a
1398/// A 256-bit vector of [4 x double].
1399/// \param __b
1400/// A 256-bit vector of [4 x double].
1401/// \param __c
1402/// A 256-bit vector operand, with mask bits 255, 191, 127, and 63 specifying
1403/// how the values are to be copied. The position of the mask bit corresponds
1404/// to the most significant bit of a copied value. When a mask bit is 0, the
1405/// corresponding 64-bit element in operand __a is copied to the same
1406/// position in the destination. When a mask bit is 1, the corresponding
1407/// 64-bit element in operand __b is copied to the same position in the
1408/// destination.
1409/// \returns A 256-bit vector of [4 x double] containing the copied values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001410static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001411_mm256_blendv_pd(__m256d __a, __m256d __b, __m256d __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001412{
David Blaikie3302f2b2013-01-16 23:08:36 +00001413 return (__m256d)__builtin_ia32_blendvpd256(
1414 (__v4df)__a, (__v4df)__b, (__v4df)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001415}
1416
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001417/// \brief Merges 32-bit single-precision data values stored in either of the
1418/// two 256-bit vectors of [8 x float], as specified by the 256-bit vector
1419/// operand.
1420///
1421/// \headerfile <x86intrin.h>
1422///
1423/// This intrinsic corresponds to the \c VBLENDVPS / BLENDVPS instruction.
1424///
1425/// \param __a
1426/// A 256-bit vector of [8 x float].
1427/// \param __b
1428/// A 256-bit vector of [8 x float].
1429/// \param __c
1430/// A 256-bit vector operand, with mask bits 255, 223, 191, 159, 127, 95, 63,
1431/// and 31 specifying how the values are to be copied. The position of the
1432/// mask bit corresponds to the most significant bit of a copied value. When
1433/// a mask bit is 0, the corresponding 32-bit element in operand __a is
1434/// copied to the same position in the destination. When a mask bit is 1, the
1435/// corresponding 32-bit element in operand __b is copied to the same
1436/// position in the destination.
1437/// \returns A 256-bit vector of [8 x float] containing the copied values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001438static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001439_mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001440{
David Blaikie5bb70032013-01-16 23:13:42 +00001441 return (__m256)__builtin_ia32_blendvps256(
David Blaikie3302f2b2013-01-16 23:08:36 +00001442 (__v8sf)__a, (__v8sf)__b, (__v8sf)__c);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001443}
1444
1445/* Vector Dot Product */
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001446/// \brief Computes two dot products in parallel, using the lower and upper
1447/// halves of two [8 x float] vectors as input to the two computations, and
1448/// returning the two dot products in the lower and upper halves of the
1449/// [8 x float] result. The immediate integer operand controls which
1450/// input elements will contribute to the dot product, and where the final
1451/// results are returned. In general, for each dot product, the four
1452/// corresponding elements of the input vectors are multiplied; the first
1453/// two and second two products are summed, then the two sums are added to
1454/// form the final result.
1455///
1456/// \headerfile <x86intrin.h>
1457///
1458/// \code
1459/// __m256 _mm256_dp_ps(__m256 V1, __m256 V2, const int M);
1460/// \endcode
1461///
1462/// This intrinsic corresponds to the \c VDPPS / DPPS instruction.
1463///
1464/// \param V1
1465/// A vector of [8 x float] values, treated as two [4 x float] vectors.
1466/// \param V2
1467/// A vector of [8 x float] values, treated as two [4 x float] vectors.
1468/// \param M
1469/// An immediate integer argument. Bits [7:4] determine which elements of
1470/// the input vectors are used, with bit [4] corresponding to the lowest
1471/// element and bit [7] corresponding to the highest element of each [4 x
1472/// float] subvector. If a bit is set, the corresponding elements from the
1473/// two input vectors are used as an input for dot product; otherwise that
1474/// input is treated as zero. Bits [3:0] determine which elements of the
1475/// result will receive a copy of the final dot product, with bit [0]
1476/// corresponding to the lowest element and bit [3] corresponding to the
1477/// highest element of each [4 x float] subvector. If a bit is set, the dot
1478/// product is returned in the corresponding element; otherwise that element
1479/// is set to zero. The bitmask is applied in the same way to each of the
1480/// two parallel dot product computations.
1481/// \returns A 256-bit vector of [8 x float] containing the two dot products.
Eli Friedmanf16beb32011-11-10 00:11:13 +00001482#define _mm256_dp_ps(V1, V2, M) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001483 (__m256)__builtin_ia32_dpps256((__v8sf)(__m256)(V1), \
1484 (__v8sf)(__m256)(V2), (M)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001485
1486/* Vector shuffle */
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001487/// \brief Selects 8 float values from the 256-bit operands of [8 x float], as
1488/// specified by the immediate value operand. The four selected elements in
1489/// each operand are copied to the destination according to the bits
1490/// specified in the immediate operand. The selected elements from the first
1491/// 256-bit operand are copied to bits [63:0] and bits [191:128] of the
1492/// destination, and the selected elements from the second 256-bit operand
1493/// are copied to bits [127:64] and bits [255:192] of the destination. For
1494/// example, if bits [7:0] of the immediate operand contain a value of 0xFF,
1495/// the 256-bit destination vector would contain the following values: b[7],
1496/// b[7], a[7], a[7], b[3], b[3], a[3], a[3].
1497///
1498/// \headerfile <x86intrin.h>
1499///
1500/// \code
1501/// __m256 _mm256_shuffle_ps(__m256 a, __m256 b, const int mask);
1502/// \endcode
1503///
1504/// This intrinsic corresponds to the \c VSHUFPS / SHUFPS instruction.
1505///
1506/// \param a
1507/// A 256-bit vector of [8 x float]. The four selected elements in this
1508/// operand are copied to bits [63:0] and bits [191:128] in the destination,
1509/// according to the bits specified in the immediate operand.
1510/// \param b
1511/// A 256-bit vector of [8 x float]. The four selected elements in this
1512/// operand are copied to bits [127:64] and bits [255:192] in the
1513/// destination, according to the bits specified in the immediate operand.
1514/// \param mask
1515/// An immediate value containing an 8-bit value specifying which elements to
1516/// copy from a and b. Bits [3:0] specify the values copied from operand a.
1517/// Bits [7:4] specify the values copied from operand b.
1518/// The destinations within the 256-bit destination are assigned values as
1519/// follows, according to the bit value assignments described below:
1520/// Bits [1:0] are used to assign values to bits [31:0] and [159:128] in the
1521/// destination.
1522/// Bits [3:2] are used to assign values to bits [63:32] and [191:160] in the
1523/// destination.
1524/// Bits [5:4] are used to assign values to bits [95:64] and [223:192] in the
1525/// destination.
1526/// Bits [7:6] are used to assign values to bits [127:96] and [255:224] in
1527/// the destination.
1528/// Bit value assignments:
1529/// 00: Bits [31:0] and [159:128] are copied from the selected operand.
1530/// 01: Bits [63:32] and [191:160] are copied from the selected operand.
1531/// 10: Bits [95:64] and [223:192] are copied from the selected operand.
1532/// 11: Bits [127:96] and [255:224] are copied from the selected operand.
1533/// \returns A 256-bit vector of [8 x float] containing the shuffled values.
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00001534#define _mm256_shuffle_ps(a, b, mask) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001535 (__m256)__builtin_shufflevector((__v8sf)(__m256)(a), \
1536 (__v8sf)(__m256)(b), \
1537 (mask) & 0x3, \
1538 ((mask) & 0xc) >> 2, \
1539 (((mask) & 0x30) >> 4) + 8, \
1540 (((mask) & 0xc0) >> 6) + 8, \
1541 ((mask) & 0x3) + 4, \
1542 (((mask) & 0xc) >> 2) + 4, \
1543 (((mask) & 0x30) >> 4) + 12, \
1544 (((mask) & 0xc0) >> 6) + 12); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001545
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001546/// \brief Selects four double-precision values from the 256-bit operands of
1547/// [4 x double], as specified by the immediate value operand. The selected
1548/// elements from the first 256-bit operand are copied to bits [63:0] and
1549/// bits [191:128] in the destination, and the selected elements from the
1550/// second 256-bit operand are copied to bits [127:64] and bits [255:192] in
1551/// the destination. For example, if bits [3:0] of the immediate operand
1552/// contain a value of 0xF, the 256-bit destination vector would contain the
1553/// following values: b[3], a[3], b[1], a[1].
1554///
1555/// \headerfile <x86intrin.h>
1556///
1557/// \code
1558/// __m256d _mm256_shuffle_pd(__m256d a, __m256d b, const int mask);
1559/// \endcode
1560///
1561/// This intrinsic corresponds to the \c VSHUFPD / SHUFPD instruction.
1562///
1563/// \param a
1564/// A 256-bit vector of [4 x double].
1565/// \param b
1566/// A 256-bit vector of [4 x double].
1567/// \param mask
1568/// An immediate value containing 8-bit values specifying which elements to
1569/// copy from a and b:
1570/// Bit [0]=0: Bits [63:0] are copied from a to bits [63:0] of the
1571/// destination.
1572/// Bit [0]=1: Bits [127:64] are copied from a to bits [63:0] of the
1573/// destination.
1574/// Bit [1]=0: Bits [63:0] are copied from b to bits [127:64] of the
1575/// destination.
1576/// Bit [1]=1: Bits [127:64] are copied from b to bits [127:64] of the
1577/// destination.
1578/// Bit [2]=0: Bits [191:128] are copied from a to bits [191:128] of the
1579/// destination.
1580/// Bit [2]=1: Bits [255:192] are copied from a to bits [191:128] of the
1581/// destination.
1582/// Bit [3]=0: Bits [191:128] are copied from b to bits [255:192] of the
1583/// destination.
1584/// Bit [3]=1: Bits [255:192] are copied from b to bits [255:192] of the
1585/// destination.
1586/// \returns A 256-bit vector of [4 x double] containing the shuffled values.
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00001587#define _mm256_shuffle_pd(a, b, mask) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001588 (__m256d)__builtin_shufflevector((__v4df)(__m256d)(a), \
1589 (__v4df)(__m256d)(b), \
1590 (mask) & 0x1, \
1591 (((mask) & 0x2) >> 1) + 4, \
1592 (((mask) & 0x4) >> 2) + 2, \
1593 (((mask) & 0x8) >> 3) + 6); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001594
1595/* Compare */
1596#define _CMP_EQ_OQ 0x00 /* Equal (ordered, non-signaling) */
1597#define _CMP_LT_OS 0x01 /* Less-than (ordered, signaling) */
1598#define _CMP_LE_OS 0x02 /* Less-than-or-equal (ordered, signaling) */
1599#define _CMP_UNORD_Q 0x03 /* Unordered (non-signaling) */
1600#define _CMP_NEQ_UQ 0x04 /* Not-equal (unordered, non-signaling) */
1601#define _CMP_NLT_US 0x05 /* Not-less-than (unordered, signaling) */
1602#define _CMP_NLE_US 0x06 /* Not-less-than-or-equal (unordered, signaling) */
1603#define _CMP_ORD_Q 0x07 /* Ordered (nonsignaling) */
1604#define _CMP_EQ_UQ 0x08 /* Equal (unordered, non-signaling) */
1605#define _CMP_NGE_US 0x09 /* Not-greater-than-or-equal (unord, signaling) */
1606#define _CMP_NGT_US 0x0a /* Not-greater-than (unordered, signaling) */
1607#define _CMP_FALSE_OQ 0x0b /* False (ordered, non-signaling) */
1608#define _CMP_NEQ_OQ 0x0c /* Not-equal (ordered, non-signaling) */
1609#define _CMP_GE_OS 0x0d /* Greater-than-or-equal (ordered, signaling) */
1610#define _CMP_GT_OS 0x0e /* Greater-than (ordered, signaling) */
1611#define _CMP_TRUE_UQ 0x0f /* True (unordered, non-signaling) */
1612#define _CMP_EQ_OS 0x10 /* Equal (ordered, signaling) */
1613#define _CMP_LT_OQ 0x11 /* Less-than (ordered, non-signaling) */
1614#define _CMP_LE_OQ 0x12 /* Less-than-or-equal (ordered, non-signaling) */
1615#define _CMP_UNORD_S 0x13 /* Unordered (signaling) */
1616#define _CMP_NEQ_US 0x14 /* Not-equal (unordered, signaling) */
1617#define _CMP_NLT_UQ 0x15 /* Not-less-than (unordered, non-signaling) */
1618#define _CMP_NLE_UQ 0x16 /* Not-less-than-or-equal (unord, non-signaling) */
1619#define _CMP_ORD_S 0x17 /* Ordered (signaling) */
1620#define _CMP_EQ_US 0x18 /* Equal (unordered, signaling) */
1621#define _CMP_NGE_UQ 0x19 /* Not-greater-than-or-equal (unord, non-sign) */
1622#define _CMP_NGT_UQ 0x1a /* Not-greater-than (unordered, non-signaling) */
1623#define _CMP_FALSE_OS 0x1b /* False (ordered, signaling) */
1624#define _CMP_NEQ_OS 0x1c /* Not-equal (ordered, signaling) */
1625#define _CMP_GE_OQ 0x1d /* Greater-than-or-equal (ordered, non-signaling) */
1626#define _CMP_GT_OQ 0x1e /* Greater-than (ordered, non-signaling) */
1627#define _CMP_TRUE_US 0x1f /* True (unordered, signaling) */
1628
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001629/// \brief Compares each of the corresponding double-precision values of two
1630/// 128-bit vectors of [2 x double], using the operation specified by the
1631/// immediate integer operand. Returns a [2 x double] vector consisting of
1632/// two doubles corresponding to the two comparison results: zero if the
1633/// comparison is false, and all 1's if the comparison is true.
1634///
1635/// \headerfile <x86intrin.h>
1636///
1637/// \code
1638/// __m128d _mm_cmp_pd(__m128d a, __m128d b, const int c);
1639/// \endcode
1640///
1641/// This intrinsic corresponds to the \c VCMPPD / CMPPD instruction.
1642///
1643/// \param a
1644/// A 128-bit vector of [2 x double].
1645/// \param b
1646/// A 128-bit vector of [2 x double].
1647/// \param c
1648/// An immediate integer operand, with bits [4:0] specifying which comparison
1649/// operation to use:
1650/// 00h, 08h, 10h, 18h: Equal
1651/// 01h, 09h, 11h, 19h: Less than
1652/// 02h, 0Ah, 12h, 1Ah: Less than or equal / Greater than or equal (swapped
1653/// operands)
1654/// 03h, 0Bh, 13h, 1Bh: Unordered
1655/// 04h, 0Ch, 14h, 1Ch: Not equal
1656/// 05h, 0Dh, 15h, 1Dh: Not less than / Not greater than (swapped operands)
1657/// 06h, 0Eh, 16h, 1Eh: Not less than or equal / Not greater than or equal
1658/// (swapped operands)
1659/// 07h, 0Fh, 17h, 1Fh: Ordered
1660/// \returns A 128-bit vector of [2 x double] containing the comparison results.
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00001661#define _mm_cmp_pd(a, b, c) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001662 (__m128d)__builtin_ia32_cmppd((__v2df)(__m128d)(a), \
1663 (__v2df)(__m128d)(b), (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001664
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001665/// \brief Compares each of the corresponding values of two 128-bit vectors of
1666/// [4 x float], using the operation specified by the immediate integer
1667/// operand. Returns a [4 x float] vector consisting of four floats
1668/// corresponding to the four comparison results: zero if the comparison is
1669/// false, and all 1's if the comparison is true.
1670///
1671/// \headerfile <x86intrin.h>
1672///
1673/// \code
1674/// __m128 _mm_cmp_ps(__m128 a, __m128 b, const int c);
1675/// \endcode
1676///
1677/// This intrinsic corresponds to the \c VCMPPS / CMPPS instruction.
1678///
1679/// \param a
1680/// A 128-bit vector of [4 x float].
1681/// \param b
1682/// A 128-bit vector of [4 x float].
1683/// \param c
1684/// An immediate integer operand, with bits [4:0] specifying which comparison
1685/// operation to use:
1686/// 00h, 08h, 10h, 18h: Equal
1687/// 01h, 09h, 11h, 19h: Less than
1688/// 02h, 0Ah, 12h, 1Ah: Less than or equal / Greater than or equal (swapped
1689/// operands)
1690/// 03h, 0Bh, 13h, 1Bh: Unordered
1691/// 04h, 0Ch, 14h, 1Ch: Not equal
1692/// 05h, 0Dh, 15h, 1Dh: Not less than / Not greater than (swapped operands)
1693/// 06h, 0Eh, 16h, 1Eh: Not less than or equal / Not greater than or equal
1694/// (swapped operands)
1695/// 07h, 0Fh, 17h, 1Fh: Ordered
1696/// \returns A 128-bit vector of [4 x float] containing the comparison results.
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00001697#define _mm_cmp_ps(a, b, c) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001698 (__m128)__builtin_ia32_cmpps((__v4sf)(__m128)(a), \
1699 (__v4sf)(__m128)(b), (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001700
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001701/// \brief Compares each of the corresponding double-precision values of two
1702/// 256-bit vectors of [4 x double], using the operation specified by the
1703/// immediate integer operand. Returns a [4 x double] vector consisting of
1704/// four doubles corresponding to the four comparison results: zero if the
1705/// comparison is false, and all 1's if the comparison is true.
1706///
1707/// \headerfile <x86intrin.h>
1708///
1709/// \code
1710/// __m256d _mm256_cmp_pd(__m256d a, __m256d b, const int c);
1711/// \endcode
1712///
1713/// This intrinsic corresponds to the \c VCMPPD / CMPPD instruction.
1714///
1715/// \param a
1716/// A 256-bit vector of [4 x double].
1717/// \param b
1718/// A 256-bit vector of [4 x double].
1719/// \param c
1720/// An immediate integer operand, with bits [4:0] specifying which comparison
1721/// operation to use:
1722/// 00h, 08h, 10h, 18h: Equal
1723/// 01h, 09h, 11h, 19h: Less than
1724/// 02h, 0Ah, 12h, 1Ah: Less than or equal / Greater than or equal (swapped
1725/// operands)
1726/// 03h, 0Bh, 13h, 1Bh: Unordered
1727/// 04h, 0Ch, 14h, 1Ch: Not equal
1728/// 05h, 0Dh, 15h, 1Dh: Not less than / Not greater than (swapped operands)
1729/// 06h, 0Eh, 16h, 1Eh: Not less than or equal / Not greater than or equal
1730/// (swapped operands)
1731/// 07h, 0Fh, 17h, 1Fh: Ordered
1732/// \returns A 256-bit vector of [4 x double] containing the comparison results.
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00001733#define _mm256_cmp_pd(a, b, c) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001734 (__m256d)__builtin_ia32_cmppd256((__v4df)(__m256d)(a), \
1735 (__v4df)(__m256d)(b), (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001736
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001737/// \brief Compares each of the corresponding values of two 256-bit vectors of
1738/// [8 x float], using the operation specified by the immediate integer
1739/// operand. Returns a [8 x float] vector consisting of eight floats
1740/// corresponding to the eight comparison results: zero if the comparison is
1741/// false, and all 1's if the comparison is true.
1742///
1743/// \headerfile <x86intrin.h>
1744///
1745/// \code
1746/// __m256 _mm256_cmp_ps(__m256 a, __m256 b, const int c);
1747/// \endcode
1748///
1749/// This intrinsic corresponds to the \c VCMPPS / CMPPS instruction.
1750///
1751/// \param a
1752/// A 256-bit vector of [8 x float].
1753/// \param b
1754/// A 256-bit vector of [8 x float].
1755/// \param c
1756/// An immediate integer operand, with bits [4:0] specifying which comparison
1757/// operation to use:
1758/// 00h, 08h, 10h, 18h: Equal
1759/// 01h, 09h, 11h, 19h: Less than
1760/// 02h, 0Ah, 12h, 1Ah: Less than or equal / Greater than or equal (swapped
1761/// operands)
1762/// 03h, 0Bh, 13h, 1Bh: Unordered
1763/// 04h, 0Ch, 14h, 1Ch: Not equal
1764/// 05h, 0Dh, 15h, 1Dh: Not less than / Not greater than (swapped operands)
1765/// 06h, 0Eh, 16h, 1Eh: Not less than or equal / Not greater than or equal
1766/// (swapped operands)
1767/// 07h, 0Fh, 17h, 1Fh: Ordered
1768/// \returns A 256-bit vector of [8 x float] containing the comparison results.
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00001769#define _mm256_cmp_ps(a, b, c) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001770 (__m256)__builtin_ia32_cmpps256((__v8sf)(__m256)(a), \
1771 (__v8sf)(__m256)(b), (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001772
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001773/// \brief Compares each of the corresponding scalar double-precision values of
1774/// two 128-bit vectors of [2 x double], using the operation specified by the
1775/// immediate integer operand. If the result is true, all 64 bits of the
1776/// destination vector are set; otherwise they are cleared.
1777///
1778/// \headerfile <x86intrin.h>
1779///
1780/// \code
1781/// __m128d _mm_cmp_sd(__m128d a, __m128d b, const int c);
1782/// \endcode
1783///
1784/// This intrinsic corresponds to the \c VCMPSD / CMPSD instruction.
1785///
1786/// \param a
1787/// A 128-bit vector of [2 x double].
1788/// \param b
1789/// A 128-bit vector of [2 x double].
1790/// \param c
1791/// An immediate integer operand, with bits [4:0] specifying which comparison
1792/// operation to use:
1793/// 00h, 08h, 10h, 18h: Equal
1794/// 01h, 09h, 11h, 19h: Less than
1795/// 02h, 0Ah, 12h, 1Ah: Less than or equal / Greater than or equal (swapped
1796/// operands)
1797/// 03h, 0Bh, 13h, 1Bh: Unordered
1798/// 04h, 0Ch, 14h, 1Ch: Not equal
1799/// 05h, 0Dh, 15h, 1Dh: Not less than / Not greater than (swapped operands)
1800/// 06h, 0Eh, 16h, 1Eh: Not less than or equal / Not greater than or equal
1801/// (swapped operands)
1802/// 07h, 0Fh, 17h, 1Fh: Ordered
1803/// \returns A 128-bit vector of [2 x double] containing the comparison results.
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00001804#define _mm_cmp_sd(a, b, c) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001805 (__m128d)__builtin_ia32_cmpsd((__v2df)(__m128d)(a), \
1806 (__v2df)(__m128d)(b), (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001807
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001808/// \brief Compares each of the corresponding scalar values of two 128-bit
1809/// vectors of [4 x float], using the operation specified by the immediate
1810/// integer operand. If the result is true, all 32 bits of the destination
1811/// vector are set; otherwise they are cleared.
1812///
1813/// \headerfile <x86intrin.h>
1814///
1815/// \code
1816/// __m128 _mm_cmp_ss(__m128 a, __m128 b, const int c);
1817/// \endcode
1818///
1819/// This intrinsic corresponds to the \c VCMPSS / CMPSS instruction.
1820///
1821/// \param a
1822/// A 128-bit vector of [4 x float].
1823/// \param b
1824/// A 128-bit vector of [4 x float].
1825/// \param c
1826/// An immediate integer operand, with bits [4:0] specifying which comparison
1827/// operation to use:
1828/// 00h, 08h, 10h, 18h: Equal
1829/// 01h, 09h, 11h, 19h: Less than
1830/// 02h, 0Ah, 12h, 1Ah: Less than or equal / Greater than or equal (swapped
1831/// operands)
1832/// 03h, 0Bh, 13h, 1Bh: Unordered
1833/// 04h, 0Ch, 14h, 1Ch: Not equal
1834/// 05h, 0Dh, 15h, 1Dh: Not less than / Not greater than (swapped operands)
1835/// 06h, 0Eh, 16h, 1Eh: Not less than or equal / Not greater than or equal
1836/// (swapped operands)
1837/// 07h, 0Fh, 17h, 1Fh: Ordered
1838/// \returns A 128-bit vector of [4 x float] containing the comparison results.
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00001839#define _mm_cmp_ss(a, b, c) __extension__ ({ \
Craig Topper71481662015-11-10 05:08:05 +00001840 (__m128)__builtin_ia32_cmpss((__v4sf)(__m128)(a), \
1841 (__v4sf)(__m128)(b), (c)); })
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001842
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001843/// \brief Takes a [8 x i32] vector and returns the vector element value
1844/// indexed by the immediate constant operand.
1845///
1846/// \headerfile <x86intrin.h>
1847///
1848/// This intrinsic corresponds to the \c VEXTRACTF128+COMPOSITE /
1849/// EXTRACTF128+COMPOSITE instruction.
1850///
1851/// \param __a
1852/// A 256-bit vector of [8 x i32].
1853/// \param __imm
1854/// An immediate integer operand with bits [2:0] determining which vector
1855/// element is extracted and returned.
1856/// \returns A 32-bit integer containing the extracted 32 bits of extended
1857/// packed data.
Michael Kupersteine45af542015-06-30 13:36:19 +00001858static __inline int __DEFAULT_FN_ATTRS
Craig Topper459554f2015-01-31 06:31:30 +00001859_mm256_extract_epi32(__m256i __a, const int __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001860{
David Blaikie3302f2b2013-01-16 23:08:36 +00001861 __v8si __b = (__v8si)__a;
Manman Renc94122e2013-10-23 20:33:14 +00001862 return __b[__imm & 7];
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001863}
1864
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001865/// \brief Takes a [16 x i16] vector and returns the vector element value
1866/// indexed by the immediate constant operand.
1867///
1868/// \headerfile <x86intrin.h>
1869///
1870/// This intrinsic corresponds to the \c VEXTRACTF128+COMPOSITE /
1871/// EXTRACTF128+COMPOSITE instruction.
1872///
1873/// \param __a
1874/// A 256-bit integer vector of [16 x i16].
1875/// \param __imm
1876/// An immediate integer operand with bits [3:0] determining which vector
1877/// element is extracted and returned.
1878/// \returns A 32-bit integer containing the extracted 16 bits of extended
1879/// packed data.
Michael Kupersteine45af542015-06-30 13:36:19 +00001880static __inline int __DEFAULT_FN_ATTRS
Craig Topper459554f2015-01-31 06:31:30 +00001881_mm256_extract_epi16(__m256i __a, const int __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001882{
David Blaikie3302f2b2013-01-16 23:08:36 +00001883 __v16hi __b = (__v16hi)__a;
Manman Renc94122e2013-10-23 20:33:14 +00001884 return __b[__imm & 15];
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001885}
1886
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001887/// \brief Takes a [32 x i8] vector and returns the vector element value
1888/// indexed by the immediate constant operand.
1889///
1890/// \headerfile <x86intrin.h>
1891///
1892/// This intrinsic corresponds to the \c VEXTRACTF128+COMPOSITE /
1893/// EXTRACTF128+COMPOSITE instruction.
1894///
1895/// \param __a
1896/// A 256-bit integer vector of [32 x i8].
1897/// \param __imm
1898/// An immediate integer operand with bits [4:0] determining which vector
1899/// element is extracted and returned.
1900/// \returns A 32-bit integer containing the extracted 8 bits of extended packed
1901/// data.
Michael Kupersteine45af542015-06-30 13:36:19 +00001902static __inline int __DEFAULT_FN_ATTRS
Craig Topper459554f2015-01-31 06:31:30 +00001903_mm256_extract_epi8(__m256i __a, const int __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001904{
David Blaikie3302f2b2013-01-16 23:08:36 +00001905 __v32qi __b = (__v32qi)__a;
Manman Renc94122e2013-10-23 20:33:14 +00001906 return __b[__imm & 31];
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001907}
1908
1909#ifdef __x86_64__
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001910/// \brief Takes a [4 x i64] vector and returns the vector element value
1911/// indexed by the immediate constant operand.
1912///
1913/// \headerfile <x86intrin.h>
1914///
1915/// This intrinsic corresponds to the \c VEXTRACTF128+COMPOSITE /
1916/// EXTRACTF128+COMPOSITE instruction.
1917///
1918/// \param __a
1919/// A 256-bit integer vector of [4 x i64].
1920/// \param __imm
1921/// An immediate integer operand with bits [1:0] determining which vector
1922/// element is extracted and returned.
1923/// \returns A 64-bit integer containing the extracted 64 bits of extended
1924/// packed data.
Michael Kupersteine45af542015-06-30 13:36:19 +00001925static __inline long long __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001926_mm256_extract_epi64(__m256i __a, const int __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001927{
David Blaikie3302f2b2013-01-16 23:08:36 +00001928 __v4di __b = (__v4di)__a;
Manman Renc94122e2013-10-23 20:33:14 +00001929 return __b[__imm & 3];
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001930}
1931#endif
1932
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001933/// \brief Takes a [8 x i32] vector and replaces the vector element value
1934/// indexed by the immediate constant operand by a new value. Returns the
1935/// modified vector.
1936///
1937/// \headerfile <x86intrin.h>
1938///
1939/// This intrinsic corresponds to the \c VINSERTF128+COMPOSITE /
1940/// INSERTF128+COMPOSITE instruction.
1941///
1942/// \param __a
1943/// A vector of [8 x i32] to be used by the insert operation.
1944/// \param __b
1945/// An integer value. The replacement value for the insert operation.
1946/// \param __imm
1947/// An immediate integer specifying the index of the vector element to be
1948/// replaced.
1949/// \returns A copy of vector __a, after replacing its element indexed by __imm
1950/// with __b.
Michael Kupersteine45af542015-06-30 13:36:19 +00001951static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001952_mm256_insert_epi32(__m256i __a, int __b, int const __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001953{
David Blaikie3302f2b2013-01-16 23:08:36 +00001954 __v8si __c = (__v8si)__a;
1955 __c[__imm & 7] = __b;
1956 return (__m256i)__c;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001957}
1958
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001959
1960/// \brief Takes a [16 x i16] vector and replaces the vector element value
1961/// indexed by the immediate constant operand with a new value. Returns the
1962/// modified vector.
1963///
1964/// \headerfile <x86intrin.h>
1965///
1966/// This intrinsic corresponds to the \c VINSERTF128+COMPOSITE /
1967/// INSERTF128+COMPOSITE instruction.
1968///
1969/// \param __a
1970/// A vector of [16 x i16] to be used by the insert operation.
1971/// \param __b
1972/// An i16 integer value. The replacement value for the insert operation.
1973/// \param __imm
1974/// An immediate integer specifying the index of the vector element to be
1975/// replaced.
1976/// \returns A copy of vector __a, after replacing its element indexed by __imm
1977/// with __b.
Michael Kupersteine45af542015-06-30 13:36:19 +00001978static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001979_mm256_insert_epi16(__m256i __a, int __b, int const __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001980{
David Blaikie3302f2b2013-01-16 23:08:36 +00001981 __v16hi __c = (__v16hi)__a;
1982 __c[__imm & 15] = __b;
1983 return (__m256i)__c;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00001984}
1985
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00001986/// \brief Takes a [32 x i8] vector and replaces the vector element value
1987/// indexed by the immediate constant operand with a new value. Returns the
1988/// modified vector.
1989///
1990/// \headerfile <x86intrin.h>
1991///
1992/// This intrinsic corresponds to the \c VINSERTF128+COMPOSITE /
1993/// INSERTF128+COMPOSITE instruction.
1994///
1995/// \param __a
1996/// A vector of [32 x i8] to be used by the insert operation.
1997/// \param __b
1998/// An i8 integer value. The replacement value for the insert operation.
1999/// \param __imm
2000/// An immediate integer specifying the index of the vector element to be
2001/// replaced.
2002/// \returns A copy of vector __a, after replacing its element indexed by __imm
2003/// with __b.
Michael Kupersteine45af542015-06-30 13:36:19 +00002004static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002005_mm256_insert_epi8(__m256i __a, int __b, int const __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002006{
David Blaikie3302f2b2013-01-16 23:08:36 +00002007 __v32qi __c = (__v32qi)__a;
2008 __c[__imm & 31] = __b;
2009 return (__m256i)__c;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002010}
2011
2012#ifdef __x86_64__
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00002013/// \brief Takes a [4 x i64] vector and replaces the vector element value
2014/// indexed by the immediate constant operand with a new value. Returns the
2015/// modified vector.
2016///
2017/// \headerfile <x86intrin.h>
2018///
2019/// This intrinsic corresponds to the \c VINSERTF128+COMPOSITE /
2020/// INSERTF128+COMPOSITE instruction.
2021///
2022/// \param __a
2023/// A vector of [4 x i64] to be used by the insert operation.
2024/// \param __b
2025/// A 64-bit integer value. The replacement value for the insert operation.
2026/// \param __imm
2027/// An immediate integer specifying the index of the vector element to be
2028/// replaced.
2029/// \returns A copy of vector __a, after replacing its element indexed by __imm
2030/// with __b.
Michael Kupersteine45af542015-06-30 13:36:19 +00002031static __inline __m256i __DEFAULT_FN_ATTRS
Filipe Cabecinhasd7400292015-02-19 19:00:33 +00002032_mm256_insert_epi64(__m256i __a, long long __b, int const __imm)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002033{
David Blaikie3302f2b2013-01-16 23:08:36 +00002034 __v4di __c = (__v4di)__a;
2035 __c[__imm & 3] = __b;
2036 return (__m256i)__c;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002037}
2038#endif
2039
2040/* Conversion */
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00002041/// \brief Converts a vector of [4 x i32] into a vector of [4 x double].
2042///
2043/// \headerfile <x86intrin.h>
2044///
2045/// This intrinsic corresponds to the \c VCVTDQ2PD / CVTDQ2PD instruction.
2046///
2047/// \param __a
2048/// A 128-bit integer vector of [4 x i32].
2049/// \returns A 256-bit vector of [4 x double] containing the converted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00002050static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002051_mm256_cvtepi32_pd(__m128i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002052{
David Blaikie3302f2b2013-01-16 23:08:36 +00002053 return (__m256d)__builtin_ia32_cvtdq2pd256((__v4si) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002054}
2055
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00002056/// \brief Converts a vector of [8 x i32] into a vector of [8 x float].
2057///
2058/// \headerfile <x86intrin.h>
2059///
2060/// This intrinsic corresponds to the \c VCVTDQ2PS / CVTDQ2PS instruction.
2061///
2062/// \param __a
2063/// A 256-bit integer vector.
2064/// \returns A 256-bit vector of [8 x float] containing the converted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00002065static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002066_mm256_cvtepi32_ps(__m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002067{
David Blaikie3302f2b2013-01-16 23:08:36 +00002068 return (__m256)__builtin_ia32_cvtdq2ps256((__v8si) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002069}
2070
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00002071/// \brief Converts a 256-bit vector of [4 x double] into a 128-bit vector of
2072/// [4 x float].
2073///
2074/// \headerfile <x86intrin.h>
2075///
2076/// This intrinsic corresponds to the \c VCVTPD2PS / CVTPD2PS instruction.
2077///
2078/// \param __a
2079/// A 256-bit vector of [4 x double].
2080/// \returns A 128-bit vector of [4 x float] containing the converted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00002081static __inline __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002082_mm256_cvtpd_ps(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002083{
David Blaikie3302f2b2013-01-16 23:08:36 +00002084 return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002085}
2086
Ekaterina Romanova1168fdc2016-05-16 22:54:45 +00002087/// \brief Converts a vector of [8 x float] into a vector of [8 x i32].
2088///
2089/// \headerfile <x86intrin.h>
2090///
2091/// This intrinsic corresponds to the \c VCVTPS2DQ / CVTPS2DQ instruction.
2092///
2093/// \param __a
2094/// A 256-bit vector of [8 x float].
2095/// \returns A 256-bit integer vector containing the converted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00002096static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002097_mm256_cvtps_epi32(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002098{
David Blaikie3302f2b2013-01-16 23:08:36 +00002099 return (__m256i)__builtin_ia32_cvtps2dq256((__v8sf) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002100}
2101
Michael Kupersteine45af542015-06-30 13:36:19 +00002102static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002103_mm256_cvtps_pd(__m128 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002104{
David Blaikie3302f2b2013-01-16 23:08:36 +00002105 return (__m256d)__builtin_ia32_cvtps2pd256((__v4sf) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002106}
2107
Michael Kupersteine45af542015-06-30 13:36:19 +00002108static __inline __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002109_mm256_cvttpd_epi32(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002110{
David Blaikie3302f2b2013-01-16 23:08:36 +00002111 return (__m128i)__builtin_ia32_cvttpd2dq256((__v4df) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002112}
2113
Michael Kupersteine45af542015-06-30 13:36:19 +00002114static __inline __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002115_mm256_cvtpd_epi32(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002116{
David Blaikie3302f2b2013-01-16 23:08:36 +00002117 return (__m128i)__builtin_ia32_cvtpd2dq256((__v4df) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002118}
2119
Michael Kupersteine45af542015-06-30 13:36:19 +00002120static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002121_mm256_cvttps_epi32(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002122{
David Blaikie3302f2b2013-01-16 23:08:36 +00002123 return (__m256i)__builtin_ia32_cvttps2dq256((__v8sf) __a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002124}
2125
2126/* Vector replicate */
Michael Kupersteine45af542015-06-30 13:36:19 +00002127static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002128_mm256_movehdup_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002129{
Craig Topper1aa231e2016-05-16 06:38:42 +00002130 return __builtin_shufflevector((__v8sf)__a, (__v8sf)__a, 1, 1, 3, 3, 5, 5, 7, 7);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002131}
2132
Michael Kupersteine45af542015-06-30 13:36:19 +00002133static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002134_mm256_moveldup_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002135{
Craig Topper1aa231e2016-05-16 06:38:42 +00002136 return __builtin_shufflevector((__v8sf)__a, (__v8sf)__a, 0, 0, 2, 2, 4, 4, 6, 6);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002137}
2138
Michael Kupersteine45af542015-06-30 13:36:19 +00002139static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002140_mm256_movedup_pd(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002141{
Craig Topper1aa231e2016-05-16 06:38:42 +00002142 return __builtin_shufflevector((__v4df)__a, (__v4df)__a, 0, 0, 2, 2);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002143}
2144
2145/* Unpack and Interleave */
Michael Kupersteine45af542015-06-30 13:36:19 +00002146static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002147_mm256_unpackhi_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002148{
Craig Topper1aa231e2016-05-16 06:38:42 +00002149 return __builtin_shufflevector((__v4df)__a, (__v4df)__b, 1, 5, 1+2, 5+2);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002150}
2151
Michael Kupersteine45af542015-06-30 13:36:19 +00002152static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002153_mm256_unpacklo_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002154{
Craig Topper1aa231e2016-05-16 06:38:42 +00002155 return __builtin_shufflevector((__v4df)__a, (__v4df)__b, 0, 4, 0+2, 4+2);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002156}
2157
Michael Kupersteine45af542015-06-30 13:36:19 +00002158static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002159_mm256_unpackhi_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002160{
Craig Topper1aa231e2016-05-16 06:38:42 +00002161 return __builtin_shufflevector((__v8sf)__a, (__v8sf)__b, 2, 10, 2+1, 10+1, 6, 14, 6+1, 14+1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002162}
2163
Michael Kupersteine45af542015-06-30 13:36:19 +00002164static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002165_mm256_unpacklo_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002166{
Craig Topper1aa231e2016-05-16 06:38:42 +00002167 return __builtin_shufflevector((__v8sf)__a, (__v8sf)__b, 0, 8, 0+1, 8+1, 4, 12, 4+1, 12+1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002168}
2169
2170/* Bit Test */
Michael Kupersteine45af542015-06-30 13:36:19 +00002171static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002172_mm_testz_pd(__m128d __a, __m128d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002173{
David Blaikie3302f2b2013-01-16 23:08:36 +00002174 return __builtin_ia32_vtestzpd((__v2df)__a, (__v2df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002175}
2176
Michael Kupersteine45af542015-06-30 13:36:19 +00002177static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002178_mm_testc_pd(__m128d __a, __m128d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002179{
David Blaikie3302f2b2013-01-16 23:08:36 +00002180 return __builtin_ia32_vtestcpd((__v2df)__a, (__v2df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002181}
2182
Michael Kupersteine45af542015-06-30 13:36:19 +00002183static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002184_mm_testnzc_pd(__m128d __a, __m128d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002185{
David Blaikie3302f2b2013-01-16 23:08:36 +00002186 return __builtin_ia32_vtestnzcpd((__v2df)__a, (__v2df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002187}
2188
Michael Kupersteine45af542015-06-30 13:36:19 +00002189static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002190_mm_testz_ps(__m128 __a, __m128 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002191{
David Blaikie3302f2b2013-01-16 23:08:36 +00002192 return __builtin_ia32_vtestzps((__v4sf)__a, (__v4sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002193}
2194
Michael Kupersteine45af542015-06-30 13:36:19 +00002195static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002196_mm_testc_ps(__m128 __a, __m128 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002197{
David Blaikie3302f2b2013-01-16 23:08:36 +00002198 return __builtin_ia32_vtestcps((__v4sf)__a, (__v4sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002199}
2200
Michael Kupersteine45af542015-06-30 13:36:19 +00002201static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002202_mm_testnzc_ps(__m128 __a, __m128 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002203{
David Blaikie3302f2b2013-01-16 23:08:36 +00002204 return __builtin_ia32_vtestnzcps((__v4sf)__a, (__v4sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002205}
2206
Michael Kupersteine45af542015-06-30 13:36:19 +00002207static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002208_mm256_testz_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002209{
David Blaikie3302f2b2013-01-16 23:08:36 +00002210 return __builtin_ia32_vtestzpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002211}
2212
Michael Kupersteine45af542015-06-30 13:36:19 +00002213static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002214_mm256_testc_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002215{
David Blaikie3302f2b2013-01-16 23:08:36 +00002216 return __builtin_ia32_vtestcpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002217}
2218
Michael Kupersteine45af542015-06-30 13:36:19 +00002219static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002220_mm256_testnzc_pd(__m256d __a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002221{
David Blaikie3302f2b2013-01-16 23:08:36 +00002222 return __builtin_ia32_vtestnzcpd256((__v4df)__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002223}
2224
Michael Kupersteine45af542015-06-30 13:36:19 +00002225static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002226_mm256_testz_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002227{
David Blaikie3302f2b2013-01-16 23:08:36 +00002228 return __builtin_ia32_vtestzps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002229}
2230
Michael Kupersteine45af542015-06-30 13:36:19 +00002231static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002232_mm256_testc_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002233{
David Blaikie3302f2b2013-01-16 23:08:36 +00002234 return __builtin_ia32_vtestcps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002235}
2236
Michael Kupersteine45af542015-06-30 13:36:19 +00002237static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002238_mm256_testnzc_ps(__m256 __a, __m256 __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002239{
David Blaikie3302f2b2013-01-16 23:08:36 +00002240 return __builtin_ia32_vtestnzcps256((__v8sf)__a, (__v8sf)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002241}
2242
Michael Kupersteine45af542015-06-30 13:36:19 +00002243static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002244_mm256_testz_si256(__m256i __a, __m256i __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002245{
David Blaikie3302f2b2013-01-16 23:08:36 +00002246 return __builtin_ia32_ptestz256((__v4di)__a, (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002247}
2248
Michael Kupersteine45af542015-06-30 13:36:19 +00002249static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002250_mm256_testc_si256(__m256i __a, __m256i __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002251{
David Blaikie3302f2b2013-01-16 23:08:36 +00002252 return __builtin_ia32_ptestc256((__v4di)__a, (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002253}
2254
Michael Kupersteine45af542015-06-30 13:36:19 +00002255static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002256_mm256_testnzc_si256(__m256i __a, __m256i __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002257{
David Blaikie3302f2b2013-01-16 23:08:36 +00002258 return __builtin_ia32_ptestnzc256((__v4di)__a, (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002259}
2260
2261/* Vector extract sign mask */
Michael Kupersteine45af542015-06-30 13:36:19 +00002262static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002263_mm256_movemask_pd(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002264{
David Blaikie3302f2b2013-01-16 23:08:36 +00002265 return __builtin_ia32_movmskpd256((__v4df)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002266}
2267
Michael Kupersteine45af542015-06-30 13:36:19 +00002268static __inline int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002269_mm256_movemask_ps(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002270{
David Blaikie3302f2b2013-01-16 23:08:36 +00002271 return __builtin_ia32_movmskps256((__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002272}
2273
David Blaikie3302f2b2013-01-16 23:08:36 +00002274/* Vector __zero */
Michael Kupersteine45af542015-06-30 13:36:19 +00002275static __inline void __DEFAULT_FN_ATTRS
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002276_mm256_zeroall(void)
2277{
2278 __builtin_ia32_vzeroall();
2279}
2280
Michael Kupersteine45af542015-06-30 13:36:19 +00002281static __inline void __DEFAULT_FN_ATTRS
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002282_mm256_zeroupper(void)
2283{
2284 __builtin_ia32_vzeroupper();
2285}
2286
2287/* Vector load with broadcast */
Michael Kupersteine45af542015-06-30 13:36:19 +00002288static __inline __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002289_mm_broadcast_ss(float const *__a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002290{
Adam Nemet286ae082014-05-29 20:47:29 +00002291 float __f = *__a;
2292 return (__m128)(__v4sf){ __f, __f, __f, __f };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002293}
2294
Michael Kupersteine45af542015-06-30 13:36:19 +00002295static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002296_mm256_broadcast_sd(double const *__a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002297{
Adam Nemet286ae082014-05-29 20:47:29 +00002298 double __d = *__a;
2299 return (__m256d)(__v4df){ __d, __d, __d, __d };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002300}
2301
Michael Kupersteine45af542015-06-30 13:36:19 +00002302static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002303_mm256_broadcast_ss(float const *__a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002304{
Adam Nemet286ae082014-05-29 20:47:29 +00002305 float __f = *__a;
2306 return (__m256)(__v8sf){ __f, __f, __f, __f, __f, __f, __f, __f };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002307}
2308
Michael Kupersteine45af542015-06-30 13:36:19 +00002309static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002310_mm256_broadcast_pd(__m128d const *__a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002311{
Craig Topper1aa231e2016-05-16 06:38:42 +00002312 return (__m256d)__builtin_ia32_vbroadcastf128_pd256((__v2df const *)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002313}
2314
Michael Kupersteine45af542015-06-30 13:36:19 +00002315static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002316_mm256_broadcast_ps(__m128 const *__a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002317{
Craig Topper1aa231e2016-05-16 06:38:42 +00002318 return (__m256)__builtin_ia32_vbroadcastf128_ps256((__v4sf const *)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002319}
2320
2321/* SIMD load ops */
Michael Kupersteine45af542015-06-30 13:36:19 +00002322static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002323_mm256_load_pd(double const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002324{
David Blaikie3302f2b2013-01-16 23:08:36 +00002325 return *(__m256d *)__p;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002326}
2327
Michael Kupersteine45af542015-06-30 13:36:19 +00002328static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002329_mm256_load_ps(float const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002330{
David Blaikie3302f2b2013-01-16 23:08:36 +00002331 return *(__m256 *)__p;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002332}
2333
Michael Kupersteine45af542015-06-30 13:36:19 +00002334static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002335_mm256_loadu_pd(double const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002336{
Craig Topper9e9301a2012-01-25 04:26:17 +00002337 struct __loadu_pd {
David Blaikie3302f2b2013-01-16 23:08:36 +00002338 __m256d __v;
David Majnemer1cf22e62015-02-04 00:26:10 +00002339 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +00002340 return ((struct __loadu_pd*)__p)->__v;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002341}
2342
Michael Kupersteine45af542015-06-30 13:36:19 +00002343static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002344_mm256_loadu_ps(float const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002345{
Craig Topper9e9301a2012-01-25 04:26:17 +00002346 struct __loadu_ps {
David Blaikie3302f2b2013-01-16 23:08:36 +00002347 __m256 __v;
David Majnemer1cf22e62015-02-04 00:26:10 +00002348 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +00002349 return ((struct __loadu_ps*)__p)->__v;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002350}
2351
Michael Kupersteine45af542015-06-30 13:36:19 +00002352static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002353_mm256_load_si256(__m256i const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002354{
David Blaikie3302f2b2013-01-16 23:08:36 +00002355 return *__p;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002356}
2357
Michael Kupersteine45af542015-06-30 13:36:19 +00002358static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002359_mm256_loadu_si256(__m256i const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002360{
Craig Topper9e9301a2012-01-25 04:26:17 +00002361 struct __loadu_si256 {
David Blaikie3302f2b2013-01-16 23:08:36 +00002362 __m256i __v;
David Majnemer1cf22e62015-02-04 00:26:10 +00002363 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +00002364 return ((struct __loadu_si256*)__p)->__v;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002365}
2366
Michael Kupersteine45af542015-06-30 13:36:19 +00002367static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002368_mm256_lddqu_si256(__m256i const *__p)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002369{
David Blaikie3302f2b2013-01-16 23:08:36 +00002370 return (__m256i)__builtin_ia32_lddqu256((char const *)__p);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002371}
2372
2373/* SIMD store ops */
Michael Kupersteine45af542015-06-30 13:36:19 +00002374static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002375_mm256_store_pd(double *__p, __m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002376{
David Blaikie3302f2b2013-01-16 23:08:36 +00002377 *(__m256d *)__p = __a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002378}
2379
Michael Kupersteine45af542015-06-30 13:36:19 +00002380static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002381_mm256_store_ps(float *__p, __m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002382{
David Blaikie3302f2b2013-01-16 23:08:36 +00002383 *(__m256 *)__p = __a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002384}
2385
Michael Kupersteine45af542015-06-30 13:36:19 +00002386static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002387_mm256_storeu_pd(double *__p, __m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002388{
David Blaikie3302f2b2013-01-16 23:08:36 +00002389 __builtin_ia32_storeupd256(__p, (__v4df)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002390}
2391
Michael Kupersteine45af542015-06-30 13:36:19 +00002392static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002393_mm256_storeu_ps(float *__p, __m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002394{
David Blaikie3302f2b2013-01-16 23:08:36 +00002395 __builtin_ia32_storeups256(__p, (__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002396}
2397
Michael Kupersteine45af542015-06-30 13:36:19 +00002398static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002399_mm256_store_si256(__m256i *__p, __m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002400{
David Blaikie3302f2b2013-01-16 23:08:36 +00002401 *__p = __a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002402}
2403
Michael Kupersteine45af542015-06-30 13:36:19 +00002404static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002405_mm256_storeu_si256(__m256i *__p, __m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002406{
David Blaikie3302f2b2013-01-16 23:08:36 +00002407 __builtin_ia32_storedqu256((char *)__p, (__v32qi)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002408}
2409
2410/* Conditional load ops */
Michael Kupersteine45af542015-06-30 13:36:19 +00002411static __inline __m128d __DEFAULT_FN_ATTRS
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002412_mm_maskload_pd(double const *__p, __m128i __m)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002413{
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002414 return (__m128d)__builtin_ia32_maskloadpd((const __v2df *)__p, (__v2di)__m);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002415}
2416
Michael Kupersteine45af542015-06-30 13:36:19 +00002417static __inline __m256d __DEFAULT_FN_ATTRS
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002418_mm256_maskload_pd(double const *__p, __m256i __m)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002419{
David Blaikie3302f2b2013-01-16 23:08:36 +00002420 return (__m256d)__builtin_ia32_maskloadpd256((const __v4df *)__p,
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002421 (__v4di)__m);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002422}
2423
Michael Kupersteine45af542015-06-30 13:36:19 +00002424static __inline __m128 __DEFAULT_FN_ATTRS
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002425_mm_maskload_ps(float const *__p, __m128i __m)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002426{
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002427 return (__m128)__builtin_ia32_maskloadps((const __v4sf *)__p, (__v4si)__m);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002428}
2429
Michael Kupersteine45af542015-06-30 13:36:19 +00002430static __inline __m256 __DEFAULT_FN_ATTRS
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002431_mm256_maskload_ps(float const *__p, __m256i __m)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002432{
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002433 return (__m256)__builtin_ia32_maskloadps256((const __v8sf *)__p, (__v8si)__m);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002434}
2435
2436/* Conditional store ops */
Michael Kupersteine45af542015-06-30 13:36:19 +00002437static __inline void __DEFAULT_FN_ATTRS
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002438_mm256_maskstore_ps(float *__p, __m256i __m, __m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002439{
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002440 __builtin_ia32_maskstoreps256((__v8sf *)__p, (__v8si)__m, (__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002441}
2442
Michael Kupersteine45af542015-06-30 13:36:19 +00002443static __inline void __DEFAULT_FN_ATTRS
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002444_mm_maskstore_pd(double *__p, __m128i __m, __m128d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002445{
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002446 __builtin_ia32_maskstorepd((__v2df *)__p, (__v2di)__m, (__v2df)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002447}
2448
Michael Kupersteine45af542015-06-30 13:36:19 +00002449static __inline void __DEFAULT_FN_ATTRS
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002450_mm256_maskstore_pd(double *__p, __m256i __m, __m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002451{
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002452 __builtin_ia32_maskstorepd256((__v4df *)__p, (__v4di)__m, (__v4df)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002453}
2454
Michael Kupersteine45af542015-06-30 13:36:19 +00002455static __inline void __DEFAULT_FN_ATTRS
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002456_mm_maskstore_ps(float *__p, __m128i __m, __m128 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002457{
Andrea Di Biagio8bb12d02015-10-20 11:19:54 +00002458 __builtin_ia32_maskstoreps((__v4sf *)__p, (__v4si)__m, (__v4sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002459}
2460
2461/* Cacheability support ops */
Michael Kupersteine45af542015-06-30 13:36:19 +00002462static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002463_mm256_stream_si256(__m256i *__a, __m256i __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002464{
David Blaikie3302f2b2013-01-16 23:08:36 +00002465 __builtin_ia32_movntdq256((__v4di *)__a, (__v4di)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002466}
2467
Michael Kupersteine45af542015-06-30 13:36:19 +00002468static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002469_mm256_stream_pd(double *__a, __m256d __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002470{
David Blaikie3302f2b2013-01-16 23:08:36 +00002471 __builtin_ia32_movntpd256(__a, (__v4df)__b);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002472}
2473
Michael Kupersteine45af542015-06-30 13:36:19 +00002474static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002475_mm256_stream_ps(float *__p, __m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002476{
David Blaikie3302f2b2013-01-16 23:08:36 +00002477 __builtin_ia32_movntps256(__p, (__v8sf)__a);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002478}
2479
2480/* Create vectors */
Simon Pilgrim5aba9922015-08-26 21:17:12 +00002481static __inline__ __m256d __DEFAULT_FN_ATTRS
2482_mm256_undefined_pd()
2483{
2484 return (__m256d)__builtin_ia32_undef256();
2485}
2486
2487static __inline__ __m256 __DEFAULT_FN_ATTRS
2488_mm256_undefined_ps()
2489{
2490 return (__m256)__builtin_ia32_undef256();
2491}
2492
2493static __inline__ __m256i __DEFAULT_FN_ATTRS
2494_mm256_undefined_si256()
2495{
2496 return (__m256i)__builtin_ia32_undef256();
2497}
2498
Michael Kupersteine45af542015-06-30 13:36:19 +00002499static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002500_mm256_set_pd(double __a, double __b, double __c, double __d)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002501{
David Blaikie3302f2b2013-01-16 23:08:36 +00002502 return (__m256d){ __d, __c, __b, __a };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002503}
2504
Michael Kupersteine45af542015-06-30 13:36:19 +00002505static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002506_mm256_set_ps(float __a, float __b, float __c, float __d,
Craig Topper9fee8ab2015-01-31 06:33:59 +00002507 float __e, float __f, float __g, float __h)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002508{
David Blaikie3302f2b2013-01-16 23:08:36 +00002509 return (__m256){ __h, __g, __f, __e, __d, __c, __b, __a };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002510}
2511
Michael Kupersteine45af542015-06-30 13:36:19 +00002512static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002513_mm256_set_epi32(int __i0, int __i1, int __i2, int __i3,
Craig Topper9fee8ab2015-01-31 06:33:59 +00002514 int __i4, int __i5, int __i6, int __i7)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002515{
David Blaikie3302f2b2013-01-16 23:08:36 +00002516 return (__m256i)(__v8si){ __i7, __i6, __i5, __i4, __i3, __i2, __i1, __i0 };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002517}
2518
Michael Kupersteine45af542015-06-30 13:36:19 +00002519static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002520_mm256_set_epi16(short __w15, short __w14, short __w13, short __w12,
Craig Topper9fee8ab2015-01-31 06:33:59 +00002521 short __w11, short __w10, short __w09, short __w08,
2522 short __w07, short __w06, short __w05, short __w04,
2523 short __w03, short __w02, short __w01, short __w00)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002524{
David Blaikie3302f2b2013-01-16 23:08:36 +00002525 return (__m256i)(__v16hi){ __w00, __w01, __w02, __w03, __w04, __w05, __w06,
2526 __w07, __w08, __w09, __w10, __w11, __w12, __w13, __w14, __w15 };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002527}
2528
Michael Kupersteine45af542015-06-30 13:36:19 +00002529static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002530_mm256_set_epi8(char __b31, char __b30, char __b29, char __b28,
Craig Topper9fee8ab2015-01-31 06:33:59 +00002531 char __b27, char __b26, char __b25, char __b24,
2532 char __b23, char __b22, char __b21, char __b20,
2533 char __b19, char __b18, char __b17, char __b16,
2534 char __b15, char __b14, char __b13, char __b12,
2535 char __b11, char __b10, char __b09, char __b08,
2536 char __b07, char __b06, char __b05, char __b04,
2537 char __b03, char __b02, char __b01, char __b00)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002538{
2539 return (__m256i)(__v32qi){
David Blaikie3302f2b2013-01-16 23:08:36 +00002540 __b00, __b01, __b02, __b03, __b04, __b05, __b06, __b07,
2541 __b08, __b09, __b10, __b11, __b12, __b13, __b14, __b15,
2542 __b16, __b17, __b18, __b19, __b20, __b21, __b22, __b23,
2543 __b24, __b25, __b26, __b27, __b28, __b29, __b30, __b31
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002544 };
2545}
2546
Michael Kupersteine45af542015-06-30 13:36:19 +00002547static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002548_mm256_set_epi64x(long long __a, long long __b, long long __c, long long __d)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002549{
David Blaikie3302f2b2013-01-16 23:08:36 +00002550 return (__m256i)(__v4di){ __d, __c, __b, __a };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002551}
2552
2553/* Create vectors with elements in reverse order */
Michael Kupersteine45af542015-06-30 13:36:19 +00002554static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002555_mm256_setr_pd(double __a, double __b, double __c, double __d)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002556{
David Blaikie3302f2b2013-01-16 23:08:36 +00002557 return (__m256d){ __a, __b, __c, __d };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002558}
2559
Michael Kupersteine45af542015-06-30 13:36:19 +00002560static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002561_mm256_setr_ps(float __a, float __b, float __c, float __d,
Craig Topper9fee8ab2015-01-31 06:33:59 +00002562 float __e, float __f, float __g, float __h)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002563{
David Blaikie3302f2b2013-01-16 23:08:36 +00002564 return (__m256){ __a, __b, __c, __d, __e, __f, __g, __h };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002565}
2566
Michael Kupersteine45af542015-06-30 13:36:19 +00002567static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002568_mm256_setr_epi32(int __i0, int __i1, int __i2, int __i3,
Craig Topper9fee8ab2015-01-31 06:33:59 +00002569 int __i4, int __i5, int __i6, int __i7)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002570{
David Blaikie3302f2b2013-01-16 23:08:36 +00002571 return (__m256i)(__v8si){ __i0, __i1, __i2, __i3, __i4, __i5, __i6, __i7 };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002572}
2573
Michael Kupersteine45af542015-06-30 13:36:19 +00002574static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002575_mm256_setr_epi16(short __w15, short __w14, short __w13, short __w12,
Craig Topper9fee8ab2015-01-31 06:33:59 +00002576 short __w11, short __w10, short __w09, short __w08,
2577 short __w07, short __w06, short __w05, short __w04,
2578 short __w03, short __w02, short __w01, short __w00)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002579{
David Blaikie3302f2b2013-01-16 23:08:36 +00002580 return (__m256i)(__v16hi){ __w15, __w14, __w13, __w12, __w11, __w10, __w09,
2581 __w08, __w07, __w06, __w05, __w04, __w03, __w02, __w01, __w00 };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002582}
2583
Michael Kupersteine45af542015-06-30 13:36:19 +00002584static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002585_mm256_setr_epi8(char __b31, char __b30, char __b29, char __b28,
Craig Topper9fee8ab2015-01-31 06:33:59 +00002586 char __b27, char __b26, char __b25, char __b24,
2587 char __b23, char __b22, char __b21, char __b20,
2588 char __b19, char __b18, char __b17, char __b16,
2589 char __b15, char __b14, char __b13, char __b12,
2590 char __b11, char __b10, char __b09, char __b08,
2591 char __b07, char __b06, char __b05, char __b04,
2592 char __b03, char __b02, char __b01, char __b00)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002593{
2594 return (__m256i)(__v32qi){
David Blaikie3302f2b2013-01-16 23:08:36 +00002595 __b31, __b30, __b29, __b28, __b27, __b26, __b25, __b24,
Craig Topper9fee8ab2015-01-31 06:33:59 +00002596 __b23, __b22, __b21, __b20, __b19, __b18, __b17, __b16,
2597 __b15, __b14, __b13, __b12, __b11, __b10, __b09, __b08,
2598 __b07, __b06, __b05, __b04, __b03, __b02, __b01, __b00 };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002599}
2600
Michael Kupersteine45af542015-06-30 13:36:19 +00002601static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002602_mm256_setr_epi64x(long long __a, long long __b, long long __c, long long __d)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002603{
David Blaikie3302f2b2013-01-16 23:08:36 +00002604 return (__m256i)(__v4di){ __a, __b, __c, __d };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002605}
2606
2607/* Create vectors with repeated elements */
Michael Kupersteine45af542015-06-30 13:36:19 +00002608static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002609_mm256_set1_pd(double __w)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002610{
David Blaikie3302f2b2013-01-16 23:08:36 +00002611 return (__m256d){ __w, __w, __w, __w };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002612}
2613
Michael Kupersteine45af542015-06-30 13:36:19 +00002614static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002615_mm256_set1_ps(float __w)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002616{
David Blaikie3302f2b2013-01-16 23:08:36 +00002617 return (__m256){ __w, __w, __w, __w, __w, __w, __w, __w };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002618}
2619
Michael Kupersteine45af542015-06-30 13:36:19 +00002620static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002621_mm256_set1_epi32(int __i)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002622{
David Blaikie3302f2b2013-01-16 23:08:36 +00002623 return (__m256i)(__v8si){ __i, __i, __i, __i, __i, __i, __i, __i };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002624}
2625
Michael Kupersteine45af542015-06-30 13:36:19 +00002626static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002627_mm256_set1_epi16(short __w)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002628{
David Blaikie3302f2b2013-01-16 23:08:36 +00002629 return (__m256i)(__v16hi){ __w, __w, __w, __w, __w, __w, __w, __w, __w, __w,
2630 __w, __w, __w, __w, __w, __w };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002631}
2632
Michael Kupersteine45af542015-06-30 13:36:19 +00002633static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002634_mm256_set1_epi8(char __b)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002635{
David Blaikie3302f2b2013-01-16 23:08:36 +00002636 return (__m256i)(__v32qi){ __b, __b, __b, __b, __b, __b, __b, __b, __b, __b,
2637 __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b,
2638 __b, __b, __b, __b, __b, __b, __b };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002639}
2640
Michael Kupersteine45af542015-06-30 13:36:19 +00002641static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002642_mm256_set1_epi64x(long long __q)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002643{
David Blaikie3302f2b2013-01-16 23:08:36 +00002644 return (__m256i)(__v4di){ __q, __q, __q, __q };
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002645}
2646
David Blaikie3302f2b2013-01-16 23:08:36 +00002647/* Create __zeroed vectors */
Michael Kupersteine45af542015-06-30 13:36:19 +00002648static __inline __m256d __DEFAULT_FN_ATTRS
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002649_mm256_setzero_pd(void)
2650{
2651 return (__m256d){ 0, 0, 0, 0 };
2652}
2653
Michael Kupersteine45af542015-06-30 13:36:19 +00002654static __inline __m256 __DEFAULT_FN_ATTRS
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002655_mm256_setzero_ps(void)
2656{
2657 return (__m256){ 0, 0, 0, 0, 0, 0, 0, 0 };
2658}
2659
Michael Kupersteine45af542015-06-30 13:36:19 +00002660static __inline __m256i __DEFAULT_FN_ATTRS
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002661_mm256_setzero_si256(void)
2662{
2663 return (__m256i){ 0LL, 0LL, 0LL, 0LL };
2664}
2665
2666/* Cast between vector types */
Michael Kupersteine45af542015-06-30 13:36:19 +00002667static __inline __m256 __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002668_mm256_castpd_ps(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002669{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002670 return (__m256)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002671}
2672
Michael Kupersteine45af542015-06-30 13:36:19 +00002673static __inline __m256i __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002674_mm256_castpd_si256(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002675{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002676 return (__m256i)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002677}
2678
Michael Kupersteine45af542015-06-30 13:36:19 +00002679static __inline __m256d __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002680_mm256_castps_pd(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002681{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002682 return (__m256d)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002683}
2684
Michael Kupersteine45af542015-06-30 13:36:19 +00002685static __inline __m256i __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002686_mm256_castps_si256(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002687{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002688 return (__m256i)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002689}
2690
Michael Kupersteine45af542015-06-30 13:36:19 +00002691static __inline __m256 __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002692_mm256_castsi256_ps(__m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002693{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002694 return (__m256)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002695}
2696
Michael Kupersteine45af542015-06-30 13:36:19 +00002697static __inline __m256d __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002698_mm256_castsi256_pd(__m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002699{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002700 return (__m256d)__a;
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002701}
2702
Michael Kupersteine45af542015-06-30 13:36:19 +00002703static __inline __m128d __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002704_mm256_castpd256_pd128(__m256d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002705{
Craig Topper1aa231e2016-05-16 06:38:42 +00002706 return __builtin_shufflevector((__v4df)__a, (__v4df)__a, 0, 1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002707}
2708
Michael Kupersteine45af542015-06-30 13:36:19 +00002709static __inline __m128 __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002710_mm256_castps256_ps128(__m256 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002711{
Craig Topper1aa231e2016-05-16 06:38:42 +00002712 return __builtin_shufflevector((__v8sf)__a, (__v8sf)__a, 0, 1, 2, 3);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002713}
2714
Michael Kupersteine45af542015-06-30 13:36:19 +00002715static __inline __m128i __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002716_mm256_castsi256_si128(__m256i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002717{
Craig Topper1aa231e2016-05-16 06:38:42 +00002718 return __builtin_shufflevector((__v4di)__a, (__v4di)__a, 0, 1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002719}
2720
Michael Kupersteine45af542015-06-30 13:36:19 +00002721static __inline __m256d __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002722_mm256_castpd128_pd256(__m128d __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002723{
Craig Topper1aa231e2016-05-16 06:38:42 +00002724 return __builtin_shufflevector((__v2df)__a, (__v2df)__a, 0, 1, -1, -1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002725}
2726
Michael Kupersteine45af542015-06-30 13:36:19 +00002727static __inline __m256 __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002728_mm256_castps128_ps256(__m128 __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002729{
Craig Topper1aa231e2016-05-16 06:38:42 +00002730 return __builtin_shufflevector((__v4sf)__a, (__v4sf)__a, 0, 1, 2, 3, -1, -1, -1, -1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002731}
2732
Michael Kupersteine45af542015-06-30 13:36:19 +00002733static __inline __m256i __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002734_mm256_castsi128_si256(__m128i __a)
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002735{
Craig Topper1aa231e2016-05-16 06:38:42 +00002736 return __builtin_shufflevector((__v2di)__a, (__v2di)__a, 0, 1, -1, -1);
Bruno Cardoso Lopes7c4b5132010-08-04 22:03:36 +00002737}
Chad Rosierf8df4f42012-03-20 16:40:00 +00002738
Sean Silvae4c37602015-09-12 02:55:19 +00002739/*
Sanjay Patel7f6aa522015-03-10 15:19:26 +00002740 Vector insert.
2741 We use macros rather than inlines because we only want to accept
2742 invocations where the immediate M is a constant expression.
2743*/
2744#define _mm256_insertf128_ps(V1, V2, M) __extension__ ({ \
2745 (__m256)__builtin_shufflevector( \
Craig Topperd619eaaa2015-11-11 03:47:10 +00002746 (__v8sf)(__m256)(V1), \
Sanjay Patel7f6aa522015-03-10 15:19:26 +00002747 (__v8sf)_mm256_castps128_ps256((__m128)(V2)), \
2748 (((M) & 1) ? 0 : 8), \
2749 (((M) & 1) ? 1 : 9), \
2750 (((M) & 1) ? 2 : 10), \
2751 (((M) & 1) ? 3 : 11), \
2752 (((M) & 1) ? 8 : 4), \
2753 (((M) & 1) ? 9 : 5), \
2754 (((M) & 1) ? 10 : 6), \
2755 (((M) & 1) ? 11 : 7) );})
2756
2757#define _mm256_insertf128_pd(V1, V2, M) __extension__ ({ \
2758 (__m256d)__builtin_shufflevector( \
Craig Topperd619eaaa2015-11-11 03:47:10 +00002759 (__v4df)(__m256d)(V1), \
Sanjay Patel7f6aa522015-03-10 15:19:26 +00002760 (__v4df)_mm256_castpd128_pd256((__m128d)(V2)), \
2761 (((M) & 1) ? 0 : 4), \
2762 (((M) & 1) ? 1 : 5), \
2763 (((M) & 1) ? 4 : 2), \
2764 (((M) & 1) ? 5 : 3) );})
2765
2766#define _mm256_insertf128_si256(V1, V2, M) __extension__ ({ \
2767 (__m256i)__builtin_shufflevector( \
Craig Topperd619eaaa2015-11-11 03:47:10 +00002768 (__v4di)(__m256i)(V1), \
Sanjay Patel7f6aa522015-03-10 15:19:26 +00002769 (__v4di)_mm256_castsi128_si256((__m128i)(V2)), \
2770 (((M) & 1) ? 0 : 4), \
2771 (((M) & 1) ? 1 : 5), \
2772 (((M) & 1) ? 4 : 2), \
2773 (((M) & 1) ? 5 : 3) );})
2774
Sean Silvae4c37602015-09-12 02:55:19 +00002775/*
Sanjay Patel0c351ab2015-03-12 15:50:36 +00002776 Vector extract.
2777 We use macros rather than inlines because we only want to accept
2778 invocations where the immediate M is a constant expression.
2779*/
2780#define _mm256_extractf128_ps(V, M) __extension__ ({ \
2781 (__m128)__builtin_shufflevector( \
Craig Topperd619eaaa2015-11-11 03:47:10 +00002782 (__v8sf)(__m256)(V), \
Sanjay Patelf204b002015-03-12 17:23:46 +00002783 (__v8sf)(_mm256_setzero_ps()), \
Sanjay Patel0c351ab2015-03-12 15:50:36 +00002784 (((M) & 1) ? 4 : 0), \
2785 (((M) & 1) ? 5 : 1), \
2786 (((M) & 1) ? 6 : 2), \
2787 (((M) & 1) ? 7 : 3) );})
2788
2789#define _mm256_extractf128_pd(V, M) __extension__ ({ \
2790 (__m128d)__builtin_shufflevector( \
Craig Topperd619eaaa2015-11-11 03:47:10 +00002791 (__v4df)(__m256d)(V), \
Sanjay Patelf204b002015-03-12 17:23:46 +00002792 (__v4df)(_mm256_setzero_pd()), \
Sanjay Patel0c351ab2015-03-12 15:50:36 +00002793 (((M) & 1) ? 2 : 0), \
2794 (((M) & 1) ? 3 : 1) );})
2795
2796#define _mm256_extractf128_si256(V, M) __extension__ ({ \
2797 (__m128i)__builtin_shufflevector( \
Craig Topperd619eaaa2015-11-11 03:47:10 +00002798 (__v4di)(__m256i)(V), \
Sanjay Patelf204b002015-03-12 17:23:46 +00002799 (__v4di)(_mm256_setzero_si256()), \
Sanjay Patel0c351ab2015-03-12 15:50:36 +00002800 (((M) & 1) ? 2 : 0), \
2801 (((M) & 1) ? 3 : 1) );})
2802
Chad Rosierf8df4f42012-03-20 16:40:00 +00002803/* SIMD load ops (unaligned) */
Michael Kupersteine45af542015-06-30 13:36:19 +00002804static __inline __m256 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002805_mm256_loadu2_m128(float const *__addr_hi, float const *__addr_lo)
Chad Rosierf8df4f42012-03-20 16:40:00 +00002806{
2807 struct __loadu_ps {
David Blaikie3302f2b2013-01-16 23:08:36 +00002808 __m128 __v;
Chad Rosierf8df4f42012-03-20 16:40:00 +00002809 } __attribute__((__packed__, __may_alias__));
2810
David Blaikie3302f2b2013-01-16 23:08:36 +00002811 __m256 __v256 = _mm256_castps128_ps256(((struct __loadu_ps*)__addr_lo)->__v);
2812 return _mm256_insertf128_ps(__v256, ((struct __loadu_ps*)__addr_hi)->__v, 1);
Chad Rosierf8df4f42012-03-20 16:40:00 +00002813}
2814
Michael Kupersteine45af542015-06-30 13:36:19 +00002815static __inline __m256d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002816_mm256_loadu2_m128d(double const *__addr_hi, double const *__addr_lo)
Chad Rosierf8df4f42012-03-20 16:40:00 +00002817{
2818 struct __loadu_pd {
David Blaikie3302f2b2013-01-16 23:08:36 +00002819 __m128d __v;
Chad Rosierf8df4f42012-03-20 16:40:00 +00002820 } __attribute__((__packed__, __may_alias__));
Sean Silvae4c37602015-09-12 02:55:19 +00002821
David Blaikie3302f2b2013-01-16 23:08:36 +00002822 __m256d __v256 = _mm256_castpd128_pd256(((struct __loadu_pd*)__addr_lo)->__v);
2823 return _mm256_insertf128_pd(__v256, ((struct __loadu_pd*)__addr_hi)->__v, 1);
Chad Rosierf8df4f42012-03-20 16:40:00 +00002824}
2825
Michael Kupersteine45af542015-06-30 13:36:19 +00002826static __inline __m256i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002827_mm256_loadu2_m128i(__m128i const *__addr_hi, __m128i const *__addr_lo)
Chad Rosierf8df4f42012-03-20 16:40:00 +00002828{
2829 struct __loadu_si128 {
David Blaikie3302f2b2013-01-16 23:08:36 +00002830 __m128i __v;
David Majnemer1cf22e62015-02-04 00:26:10 +00002831 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +00002832 __m256i __v256 = _mm256_castsi128_si256(
2833 ((struct __loadu_si128*)__addr_lo)->__v);
2834 return _mm256_insertf128_si256(__v256,
2835 ((struct __loadu_si128*)__addr_hi)->__v, 1);
Chad Rosierf8df4f42012-03-20 16:40:00 +00002836}
2837
2838/* SIMD store ops (unaligned) */
Michael Kupersteine45af542015-06-30 13:36:19 +00002839static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002840_mm256_storeu2_m128(float *__addr_hi, float *__addr_lo, __m256 __a)
Chad Rosierf8df4f42012-03-20 16:40:00 +00002841{
David Blaikie3302f2b2013-01-16 23:08:36 +00002842 __m128 __v128;
Chad Rosierf8df4f42012-03-20 16:40:00 +00002843
David Blaikie3302f2b2013-01-16 23:08:36 +00002844 __v128 = _mm256_castps256_ps128(__a);
2845 __builtin_ia32_storeups(__addr_lo, __v128);
2846 __v128 = _mm256_extractf128_ps(__a, 1);
2847 __builtin_ia32_storeups(__addr_hi, __v128);
Chad Rosierf8df4f42012-03-20 16:40:00 +00002848}
2849
Michael Kupersteine45af542015-06-30 13:36:19 +00002850static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002851_mm256_storeu2_m128d(double *__addr_hi, double *__addr_lo, __m256d __a)
Chad Rosierf8df4f42012-03-20 16:40:00 +00002852{
David Blaikie3302f2b2013-01-16 23:08:36 +00002853 __m128d __v128;
Chad Rosierf8df4f42012-03-20 16:40:00 +00002854
David Blaikie3302f2b2013-01-16 23:08:36 +00002855 __v128 = _mm256_castpd256_pd128(__a);
2856 __builtin_ia32_storeupd(__addr_lo, __v128);
2857 __v128 = _mm256_extractf128_pd(__a, 1);
2858 __builtin_ia32_storeupd(__addr_hi, __v128);
Chad Rosierf8df4f42012-03-20 16:40:00 +00002859}
2860
Michael Kupersteine45af542015-06-30 13:36:19 +00002861static __inline void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002862_mm256_storeu2_m128i(__m128i *__addr_hi, __m128i *__addr_lo, __m256i __a)
Chad Rosierf8df4f42012-03-20 16:40:00 +00002863{
David Blaikie3302f2b2013-01-16 23:08:36 +00002864 __m128i __v128;
Chad Rosierf8df4f42012-03-20 16:40:00 +00002865
David Blaikie3302f2b2013-01-16 23:08:36 +00002866 __v128 = _mm256_castsi256_si128(__a);
2867 __builtin_ia32_storedqu((char *)__addr_lo, (__v16qi)__v128);
2868 __v128 = _mm256_extractf128_si256(__a, 1);
2869 __builtin_ia32_storedqu((char *)__addr_hi, (__v16qi)__v128);
Chad Rosierf8df4f42012-03-20 16:40:00 +00002870}
Richard Smith49e56442013-07-14 05:41:45 +00002871
Michael Kupersteine45af542015-06-30 13:36:19 +00002872static __inline __m256 __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00002873_mm256_set_m128 (__m128 __hi, __m128 __lo) {
Craig Topper1aa231e2016-05-16 06:38:42 +00002874 return (__m256) __builtin_shufflevector((__v4sf)__lo, (__v4sf)__hi, 0, 1, 2, 3, 4, 5, 6, 7);
Michael Kuperstein76190042015-05-20 07:46:52 +00002875}
2876
Michael Kupersteine45af542015-06-30 13:36:19 +00002877static __inline __m256d __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00002878_mm256_set_m128d (__m128d __hi, __m128d __lo) {
2879 return (__m256d)_mm256_set_m128((__m128)__hi, (__m128)__lo);
2880}
2881
Michael Kupersteine45af542015-06-30 13:36:19 +00002882static __inline __m256i __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00002883_mm256_set_m128i (__m128i __hi, __m128i __lo) {
2884 return (__m256i)_mm256_set_m128((__m128)__hi, (__m128)__lo);
2885}
2886
Michael Kupersteine45af542015-06-30 13:36:19 +00002887static __inline __m256 __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00002888_mm256_setr_m128 (__m128 __lo, __m128 __hi) {
2889 return _mm256_set_m128(__hi, __lo);
2890}
2891
Michael Kupersteine45af542015-06-30 13:36:19 +00002892static __inline __m256d __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00002893_mm256_setr_m128d (__m128d __lo, __m128d __hi) {
2894 return (__m256d)_mm256_set_m128((__m128)__hi, (__m128)__lo);
2895}
2896
Michael Kupersteine45af542015-06-30 13:36:19 +00002897static __inline __m256i __DEFAULT_FN_ATTRS
Michael Kuperstein76190042015-05-20 07:46:52 +00002898_mm256_setr_m128i (__m128i __lo, __m128i __hi) {
2899 return (__m256i)_mm256_set_m128((__m128)__hi, (__m128)__lo);
2900}
2901
Michael Kupersteine45af542015-06-30 13:36:19 +00002902#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +00002903
Richard Smith49e56442013-07-14 05:41:45 +00002904#endif /* __AVXINTRIN_H */