blob: f9a1a1a005967ca9913a42d1b10aee422d0e6b9e [file] [log] [blame]
Benjamin Kramerae8ea1f2010-08-20 16:47:17 +00001/*===---- emmintrin.h - SSE2 intrinsics ------------------------------------===
Anders Carlssonf15e71d2008-12-24 01:45:22 +00002 *
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 */
Benjamin Kramerae8ea1f2010-08-20 16:47:17 +000023
Anders Carlssonf15e71d2008-12-24 01:45:22 +000024#ifndef __EMMINTRIN_H
25#define __EMMINTRIN_H
26
Anders Carlssonf15e71d2008-12-24 01:45:22 +000027#include <xmmintrin.h>
28
29typedef double __m128d __attribute__((__vector_size__(16)));
30typedef long long __m128i __attribute__((__vector_size__(16)));
31
Eric Christopher2a9898f2010-08-26 02:09:25 +000032/* Type defines. */
33typedef double __v2df __attribute__ ((__vector_size__ (16)));
34typedef long long __v2di __attribute__ ((__vector_size__ (16)));
Anders Carlssona283f912008-12-24 02:41:00 +000035typedef short __v8hi __attribute__((__vector_size__(16)));
Anders Carlsson327c8df2009-09-18 19:18:19 +000036typedef char __v16qi __attribute__((__vector_size__(16)));
Anders Carlssonf15e71d2008-12-24 01:45:22 +000037
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 __v16qs __attribute__((__vector_size__(16)));
41
Michael Kupersteina10dff92015-09-21 13:34:47 +000042#include <f16cintrin.h>
43
Eric Christopher4d1851682015-06-17 07:09:20 +000044/* Define the default attributes for the functions in this file. */
Michael Kupersteine45af542015-06-30 13:36:19 +000045#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sse2")))
Eric Christopher4d1851682015-06-17 07:09:20 +000046
Michael Kupersteine45af542015-06-30 13:36:19 +000047static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000048_mm_add_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +000049{
David Blaikie3302f2b2013-01-16 23:08:36 +000050 __a[0] += __b[0];
51 return __a;
Anders Carlssonf15e71d2008-12-24 01:45:22 +000052}
53
Michael Kupersteine45af542015-06-30 13:36:19 +000054static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000055_mm_add_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +000056{
Craig Topper1aa231e2016-05-16 06:38:42 +000057 return (__m128d)((__v2df)__a + (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +000058}
59
Michael Kupersteine45af542015-06-30 13:36:19 +000060static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000061_mm_sub_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +000062{
David Blaikie3302f2b2013-01-16 23:08:36 +000063 __a[0] -= __b[0];
64 return __a;
Anders Carlssonf15e71d2008-12-24 01:45:22 +000065}
66
Michael Kupersteine45af542015-06-30 13:36:19 +000067static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000068_mm_sub_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +000069{
Craig Topper1aa231e2016-05-16 06:38:42 +000070 return (__m128d)((__v2df)__a - (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +000071}
72
Michael Kupersteine45af542015-06-30 13:36:19 +000073static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000074_mm_mul_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +000075{
David Blaikie3302f2b2013-01-16 23:08:36 +000076 __a[0] *= __b[0];
77 return __a;
Anders Carlssonf15e71d2008-12-24 01:45:22 +000078}
79
Michael Kupersteine45af542015-06-30 13:36:19 +000080static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000081_mm_mul_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +000082{
Craig Topper1aa231e2016-05-16 06:38:42 +000083 return (__m128d)((__v2df)__a * (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +000084}
85
Michael Kupersteine45af542015-06-30 13:36:19 +000086static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000087_mm_div_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +000088{
David Blaikie3302f2b2013-01-16 23:08:36 +000089 __a[0] /= __b[0];
90 return __a;
Anders Carlssonf15e71d2008-12-24 01:45:22 +000091}
92
Michael Kupersteine45af542015-06-30 13:36:19 +000093static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +000094_mm_div_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +000095{
Craig Topper1aa231e2016-05-16 06:38:42 +000096 return (__m128d)((__v2df)__a / (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +000097}
98
Michael Kupersteine45af542015-06-30 13:36:19 +000099static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000100_mm_sqrt_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000101{
Craig Topper1aa231e2016-05-16 06:38:42 +0000102 __m128d __c = __builtin_ia32_sqrtsd((__v2df)__b);
David Blaikie3302f2b2013-01-16 23:08:36 +0000103 return (__m128d) { __c[0], __a[1] };
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000104}
105
Michael Kupersteine45af542015-06-30 13:36:19 +0000106static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000107_mm_sqrt_pd(__m128d __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000108{
Craig Topper1aa231e2016-05-16 06:38:42 +0000109 return __builtin_ia32_sqrtpd((__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000110}
111
Michael Kupersteine45af542015-06-30 13:36:19 +0000112static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000113_mm_min_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000114{
Craig Topper1aa231e2016-05-16 06:38:42 +0000115 return __builtin_ia32_minsd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000116}
117
Michael Kupersteine45af542015-06-30 13:36:19 +0000118static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000119_mm_min_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000120{
Craig Topper1aa231e2016-05-16 06:38:42 +0000121 return __builtin_ia32_minpd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000122}
123
Michael Kupersteine45af542015-06-30 13:36:19 +0000124static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000125_mm_max_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000126{
Craig Topper1aa231e2016-05-16 06:38:42 +0000127 return __builtin_ia32_maxsd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000128}
129
Michael Kupersteine45af542015-06-30 13:36:19 +0000130static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000131_mm_max_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000132{
Craig Topper1aa231e2016-05-16 06:38:42 +0000133 return __builtin_ia32_maxpd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000134}
135
Michael Kupersteine45af542015-06-30 13:36:19 +0000136static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000137_mm_and_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000138{
David Blaikie3302f2b2013-01-16 23:08:36 +0000139 return (__m128d)((__v4si)__a & (__v4si)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000140}
141
Michael Kupersteine45af542015-06-30 13:36:19 +0000142static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000143_mm_andnot_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000144{
David Blaikie3302f2b2013-01-16 23:08:36 +0000145 return (__m128d)(~(__v4si)__a & (__v4si)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000146}
147
Michael Kupersteine45af542015-06-30 13:36:19 +0000148static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000149_mm_or_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000150{
David Blaikie3302f2b2013-01-16 23:08:36 +0000151 return (__m128d)((__v4si)__a | (__v4si)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000152}
153
Michael Kupersteine45af542015-06-30 13:36:19 +0000154static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000155_mm_xor_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000156{
David Blaikie3302f2b2013-01-16 23:08:36 +0000157 return (__m128d)((__v4si)__a ^ (__v4si)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000158}
159
Michael Kupersteine45af542015-06-30 13:36:19 +0000160static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000161_mm_cmpeq_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000162{
Craig Topper1aa231e2016-05-16 06:38:42 +0000163 return (__m128d)__builtin_ia32_cmpeqpd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000164}
165
Michael Kupersteine45af542015-06-30 13:36:19 +0000166static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000167_mm_cmplt_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000168{
Craig Topper1aa231e2016-05-16 06:38:42 +0000169 return (__m128d)__builtin_ia32_cmpltpd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000170}
171
Michael Kupersteine45af542015-06-30 13:36:19 +0000172static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000173_mm_cmple_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000174{
Craig Topper1aa231e2016-05-16 06:38:42 +0000175 return (__m128d)__builtin_ia32_cmplepd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000176}
177
Michael Kupersteine45af542015-06-30 13:36:19 +0000178static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000179_mm_cmpgt_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000180{
Craig Topper1aa231e2016-05-16 06:38:42 +0000181 return (__m128d)__builtin_ia32_cmpltpd((__v2df)__b, (__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000182}
183
Michael Kupersteine45af542015-06-30 13:36:19 +0000184static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000185_mm_cmpge_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000186{
Craig Topper1aa231e2016-05-16 06:38:42 +0000187 return (__m128d)__builtin_ia32_cmplepd((__v2df)__b, (__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000188}
189
Michael Kupersteine45af542015-06-30 13:36:19 +0000190static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000191_mm_cmpord_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000192{
Craig Topper1aa231e2016-05-16 06:38:42 +0000193 return (__m128d)__builtin_ia32_cmpordpd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000194}
195
Michael Kupersteine45af542015-06-30 13:36:19 +0000196static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000197_mm_cmpunord_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000198{
Craig Topper1aa231e2016-05-16 06:38:42 +0000199 return (__m128d)__builtin_ia32_cmpunordpd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000200}
201
Michael Kupersteine45af542015-06-30 13:36:19 +0000202static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000203_mm_cmpneq_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000204{
Craig Topper1aa231e2016-05-16 06:38:42 +0000205 return (__m128d)__builtin_ia32_cmpneqpd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000206}
207
Michael Kupersteine45af542015-06-30 13:36:19 +0000208static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000209_mm_cmpnlt_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000210{
Craig Topper1aa231e2016-05-16 06:38:42 +0000211 return (__m128d)__builtin_ia32_cmpnltpd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000212}
213
Michael Kupersteine45af542015-06-30 13:36:19 +0000214static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000215_mm_cmpnle_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000216{
Craig Topper1aa231e2016-05-16 06:38:42 +0000217 return (__m128d)__builtin_ia32_cmpnlepd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000218}
219
Michael Kupersteine45af542015-06-30 13:36:19 +0000220static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000221_mm_cmpngt_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000222{
Craig Topper1aa231e2016-05-16 06:38:42 +0000223 return (__m128d)__builtin_ia32_cmpnltpd((__v2df)__b, (__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000224}
225
Michael Kupersteine45af542015-06-30 13:36:19 +0000226static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000227_mm_cmpnge_pd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000228{
Craig Topper1aa231e2016-05-16 06:38:42 +0000229 return (__m128d)__builtin_ia32_cmpnlepd((__v2df)__b, (__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000230}
231
Michael Kupersteine45af542015-06-30 13:36:19 +0000232static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000233_mm_cmpeq_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000234{
Craig Topper1aa231e2016-05-16 06:38:42 +0000235 return (__m128d)__builtin_ia32_cmpeqsd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000236}
237
Michael Kupersteine45af542015-06-30 13:36:19 +0000238static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000239_mm_cmplt_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000240{
Craig Topper1aa231e2016-05-16 06:38:42 +0000241 return (__m128d)__builtin_ia32_cmpltsd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000242}
243
Michael Kupersteine45af542015-06-30 13:36:19 +0000244static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000245_mm_cmple_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000246{
Craig Topper1aa231e2016-05-16 06:38:42 +0000247 return (__m128d)__builtin_ia32_cmplesd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000248}
249
Michael Kupersteine45af542015-06-30 13:36:19 +0000250static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000251_mm_cmpgt_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000252{
Craig Topper1aa231e2016-05-16 06:38:42 +0000253 __m128d __c = __builtin_ia32_cmpltsd((__v2df)__b, (__v2df)__a);
Manman Ren9bb34d62013-06-17 19:42:49 +0000254 return (__m128d) { __c[0], __a[1] };
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000255}
256
Michael Kupersteine45af542015-06-30 13:36:19 +0000257static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000258_mm_cmpge_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000259{
Craig Topper1aa231e2016-05-16 06:38:42 +0000260 __m128d __c = __builtin_ia32_cmplesd((__v2df)__b, (__v2df)__a);
Manman Ren9bb34d62013-06-17 19:42:49 +0000261 return (__m128d) { __c[0], __a[1] };
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000262}
263
Michael Kupersteine45af542015-06-30 13:36:19 +0000264static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000265_mm_cmpord_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000266{
Craig Topper1aa231e2016-05-16 06:38:42 +0000267 return (__m128d)__builtin_ia32_cmpordsd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000268}
269
Michael Kupersteine45af542015-06-30 13:36:19 +0000270static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000271_mm_cmpunord_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000272{
Craig Topper1aa231e2016-05-16 06:38:42 +0000273 return (__m128d)__builtin_ia32_cmpunordsd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000274}
275
Michael Kupersteine45af542015-06-30 13:36:19 +0000276static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000277_mm_cmpneq_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000278{
Craig Topper1aa231e2016-05-16 06:38:42 +0000279 return (__m128d)__builtin_ia32_cmpneqsd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000280}
281
Michael Kupersteine45af542015-06-30 13:36:19 +0000282static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000283_mm_cmpnlt_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000284{
Craig Topper1aa231e2016-05-16 06:38:42 +0000285 return (__m128d)__builtin_ia32_cmpnltsd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000286}
287
Michael Kupersteine45af542015-06-30 13:36:19 +0000288static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000289_mm_cmpnle_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000290{
Craig Topper1aa231e2016-05-16 06:38:42 +0000291 return (__m128d)__builtin_ia32_cmpnlesd((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000292}
293
Michael Kupersteine45af542015-06-30 13:36:19 +0000294static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000295_mm_cmpngt_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000296{
Craig Topper1aa231e2016-05-16 06:38:42 +0000297 __m128d __c = __builtin_ia32_cmpnltsd((__v2df)__b, (__v2df)__a);
Manman Ren9bb34d62013-06-17 19:42:49 +0000298 return (__m128d) { __c[0], __a[1] };
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000299}
300
Michael Kupersteine45af542015-06-30 13:36:19 +0000301static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000302_mm_cmpnge_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000303{
Craig Topper1aa231e2016-05-16 06:38:42 +0000304 __m128d __c = __builtin_ia32_cmpnlesd((__v2df)__b, (__v2df)__a);
Manman Ren9bb34d62013-06-17 19:42:49 +0000305 return (__m128d) { __c[0], __a[1] };
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000306}
307
Michael Kupersteine45af542015-06-30 13:36:19 +0000308static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000309_mm_comieq_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000310{
Craig Topper1aa231e2016-05-16 06:38:42 +0000311 return __builtin_ia32_comisdeq((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000312}
313
Michael Kupersteine45af542015-06-30 13:36:19 +0000314static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000315_mm_comilt_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000316{
Craig Topper1aa231e2016-05-16 06:38:42 +0000317 return __builtin_ia32_comisdlt((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000318}
319
Michael Kupersteine45af542015-06-30 13:36:19 +0000320static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000321_mm_comile_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000322{
Craig Topper1aa231e2016-05-16 06:38:42 +0000323 return __builtin_ia32_comisdle((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000324}
325
Michael Kupersteine45af542015-06-30 13:36:19 +0000326static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000327_mm_comigt_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000328{
Craig Topper1aa231e2016-05-16 06:38:42 +0000329 return __builtin_ia32_comisdgt((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000330}
331
Michael Kupersteine45af542015-06-30 13:36:19 +0000332static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000333_mm_comige_sd(__m128d __a, __m128d __b)
Eli Friedman89c11332011-10-06 20:31:50 +0000334{
Craig Topper1aa231e2016-05-16 06:38:42 +0000335 return __builtin_ia32_comisdge((__v2df)__a, (__v2df)__b);
Eli Friedman89c11332011-10-06 20:31:50 +0000336}
337
Michael Kupersteine45af542015-06-30 13:36:19 +0000338static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000339_mm_comineq_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000340{
Craig Topper1aa231e2016-05-16 06:38:42 +0000341 return __builtin_ia32_comisdneq((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000342}
343
Michael Kupersteine45af542015-06-30 13:36:19 +0000344static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000345_mm_ucomieq_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000346{
Craig Topper1aa231e2016-05-16 06:38:42 +0000347 return __builtin_ia32_ucomisdeq((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000348}
349
Michael Kupersteine45af542015-06-30 13:36:19 +0000350static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000351_mm_ucomilt_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000352{
Craig Topper1aa231e2016-05-16 06:38:42 +0000353 return __builtin_ia32_ucomisdlt((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000354}
355
Michael Kupersteine45af542015-06-30 13:36:19 +0000356static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000357_mm_ucomile_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000358{
Craig Topper1aa231e2016-05-16 06:38:42 +0000359 return __builtin_ia32_ucomisdle((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000360}
361
Michael Kupersteine45af542015-06-30 13:36:19 +0000362static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000363_mm_ucomigt_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000364{
Craig Topper1aa231e2016-05-16 06:38:42 +0000365 return __builtin_ia32_ucomisdgt((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000366}
367
Michael Kupersteine45af542015-06-30 13:36:19 +0000368static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000369_mm_ucomige_sd(__m128d __a, __m128d __b)
Eli Friedmanf8cb4802011-08-29 21:26:24 +0000370{
Craig Topper1aa231e2016-05-16 06:38:42 +0000371 return __builtin_ia32_ucomisdge((__v2df)__a, (__v2df)__b);
Eli Friedmanf8cb4802011-08-29 21:26:24 +0000372}
373
Michael Kupersteine45af542015-06-30 13:36:19 +0000374static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000375_mm_ucomineq_sd(__m128d __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000376{
Craig Topper1aa231e2016-05-16 06:38:42 +0000377 return __builtin_ia32_ucomisdneq((__v2df)__a, (__v2df)__b);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000378}
379
Michael Kupersteine45af542015-06-30 13:36:19 +0000380static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000381_mm_cvtpd_ps(__m128d __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000382{
Craig Topper1aa231e2016-05-16 06:38:42 +0000383 return __builtin_ia32_cvtpd2ps((__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000384}
385
Michael Kupersteine45af542015-06-30 13:36:19 +0000386static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000387_mm_cvtps_pd(__m128 __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000388{
Simon Pilgrim90770c72016-05-23 22:13:02 +0000389 return (__m128d) __builtin_convertvector(
390 __builtin_shufflevector((__v4sf)__a, (__v4sf)__a, 0, 1), __v2df);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000391}
392
Michael Kupersteine45af542015-06-30 13:36:19 +0000393static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000394_mm_cvtepi32_pd(__m128i __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000395{
Simon Pilgrim90770c72016-05-23 22:13:02 +0000396 return (__m128d) __builtin_convertvector(
397 __builtin_shufflevector((__v4si)__a, (__v4si)__a, 0, 1), __v2df);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000398}
399
Michael Kupersteine45af542015-06-30 13:36:19 +0000400static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000401_mm_cvtpd_epi32(__m128d __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000402{
Craig Topper1aa231e2016-05-16 06:38:42 +0000403 return __builtin_ia32_cvtpd2dq((__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000404}
405
Michael Kupersteine45af542015-06-30 13:36:19 +0000406static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000407_mm_cvtsd_si32(__m128d __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000408{
Craig Topper1aa231e2016-05-16 06:38:42 +0000409 return __builtin_ia32_cvtsd2si((__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000410}
411
Michael Kupersteine45af542015-06-30 13:36:19 +0000412static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000413_mm_cvtsd_ss(__m128 __a, __m128d __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000414{
David Blaikie3302f2b2013-01-16 23:08:36 +0000415 __a[0] = __b[0];
416 return __a;
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000417}
418
Michael Kupersteine45af542015-06-30 13:36:19 +0000419static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000420_mm_cvtsi32_sd(__m128d __a, int __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000421{
David Blaikie3302f2b2013-01-16 23:08:36 +0000422 __a[0] = __b;
423 return __a;
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000424}
425
Michael Kupersteine45af542015-06-30 13:36:19 +0000426static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000427_mm_cvtss_sd(__m128d __a, __m128 __b)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000428{
David Blaikie3302f2b2013-01-16 23:08:36 +0000429 __a[0] = __b[0];
430 return __a;
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000431}
432
Michael Kupersteine45af542015-06-30 13:36:19 +0000433static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000434_mm_cvttpd_epi32(__m128d __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000435{
Craig Topper1aa231e2016-05-16 06:38:42 +0000436 return (__m128i)__builtin_ia32_cvttpd2dq((__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000437}
438
Michael Kupersteine45af542015-06-30 13:36:19 +0000439static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000440_mm_cvttsd_si32(__m128d __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000441{
David Blaikie3302f2b2013-01-16 23:08:36 +0000442 return __a[0];
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000443}
444
Michael Kupersteine45af542015-06-30 13:36:19 +0000445static __inline__ __m64 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000446_mm_cvtpd_pi32(__m128d __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000447{
Craig Topper1aa231e2016-05-16 06:38:42 +0000448 return (__m64)__builtin_ia32_cvtpd2pi((__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000449}
450
Michael Kupersteine45af542015-06-30 13:36:19 +0000451static __inline__ __m64 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000452_mm_cvttpd_pi32(__m128d __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000453{
Craig Topper1aa231e2016-05-16 06:38:42 +0000454 return (__m64)__builtin_ia32_cvttpd2pi((__v2df)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000455}
456
Michael Kupersteine45af542015-06-30 13:36:19 +0000457static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000458_mm_cvtpi32_pd(__m64 __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000459{
David Blaikie3302f2b2013-01-16 23:08:36 +0000460 return __builtin_ia32_cvtpi2pd((__v2si)__a);
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000461}
462
Michael Kupersteine45af542015-06-30 13:36:19 +0000463static __inline__ double __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000464_mm_cvtsd_f64(__m128d __a)
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000465{
David Blaikie3302f2b2013-01-16 23:08:36 +0000466 return __a[0];
Anders Carlssonf15e71d2008-12-24 01:45:22 +0000467}
468
Michael Kupersteine45af542015-06-30 13:36:19 +0000469static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000470_mm_load_pd(double const *__dp)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000471{
David Blaikie3302f2b2013-01-16 23:08:36 +0000472 return *(__m128d*)__dp;
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000473}
474
Michael Kupersteine45af542015-06-30 13:36:19 +0000475static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000476_mm_load1_pd(double const *__dp)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000477{
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000478 struct __mm_load1_pd_struct {
David Blaikie3302f2b2013-01-16 23:08:36 +0000479 double __u;
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000480 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000481 double __u = ((struct __mm_load1_pd_struct*)__dp)->__u;
482 return (__m128d){ __u, __u };
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000483}
484
Eli Friedmanf83c2582009-06-02 05:55:48 +0000485#define _mm_load_pd1(dp) _mm_load1_pd(dp)
486
Michael Kupersteine45af542015-06-30 13:36:19 +0000487static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000488_mm_loadr_pd(double const *__dp)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000489{
David Blaikie3302f2b2013-01-16 23:08:36 +0000490 __m128d __u = *(__m128d*)__dp;
Craig Topper1aa231e2016-05-16 06:38:42 +0000491 return __builtin_shufflevector((__v2df)__u, (__v2df)__u, 1, 0);
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000492}
493
Michael Kupersteine45af542015-06-30 13:36:19 +0000494static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000495_mm_loadu_pd(double const *__dp)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000496{
Bill Wendling502931f2011-05-13 00:11:39 +0000497 struct __loadu_pd {
David Blaikie3302f2b2013-01-16 23:08:36 +0000498 __m128d __v;
David Majnemer1cf22e62015-02-04 00:26:10 +0000499 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000500 return ((struct __loadu_pd*)__dp)->__v;
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000501}
502
Michael Kupersteine45af542015-06-30 13:36:19 +0000503static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000504_mm_load_sd(double const *__dp)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000505{
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000506 struct __mm_load_sd_struct {
David Blaikie3302f2b2013-01-16 23:08:36 +0000507 double __u;
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000508 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000509 double __u = ((struct __mm_load_sd_struct*)__dp)->__u;
510 return (__m128d){ __u, 0 };
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000511}
512
Michael Kupersteine45af542015-06-30 13:36:19 +0000513static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000514_mm_loadh_pd(__m128d __a, double const *__dp)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000515{
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000516 struct __mm_loadh_pd_struct {
David Blaikie3302f2b2013-01-16 23:08:36 +0000517 double __u;
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000518 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000519 double __u = ((struct __mm_loadh_pd_struct*)__dp)->__u;
520 return (__m128d){ __a[0], __u };
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000521}
522
Michael Kupersteine45af542015-06-30 13:36:19 +0000523static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000524_mm_loadl_pd(__m128d __a, double const *__dp)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000525{
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000526 struct __mm_loadl_pd_struct {
David Blaikie3302f2b2013-01-16 23:08:36 +0000527 double __u;
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000528 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000529 double __u = ((struct __mm_loadl_pd_struct*)__dp)->__u;
530 return (__m128d){ __u, __a[1] };
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000531}
532
Michael Kupersteine45af542015-06-30 13:36:19 +0000533static __inline__ __m128d __DEFAULT_FN_ATTRS
Simon Pilgrim5aba9922015-08-26 21:17:12 +0000534_mm_undefined_pd()
535{
536 return (__m128d)__builtin_ia32_undef128();
537}
538
539static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000540_mm_set_sd(double __w)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000541{
David Blaikie3302f2b2013-01-16 23:08:36 +0000542 return (__m128d){ __w, 0 };
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000543}
544
Michael Kupersteine45af542015-06-30 13:36:19 +0000545static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000546_mm_set1_pd(double __w)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000547{
David Blaikie3302f2b2013-01-16 23:08:36 +0000548 return (__m128d){ __w, __w };
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000549}
550
Michael Kupersteine45af542015-06-30 13:36:19 +0000551static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000552_mm_set_pd(double __w, double __x)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000553{
David Blaikie3302f2b2013-01-16 23:08:36 +0000554 return (__m128d){ __x, __w };
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000555}
556
Michael Kupersteine45af542015-06-30 13:36:19 +0000557static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000558_mm_setr_pd(double __w, double __x)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000559{
David Blaikie3302f2b2013-01-16 23:08:36 +0000560 return (__m128d){ __w, __x };
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000561}
562
Michael Kupersteine45af542015-06-30 13:36:19 +0000563static __inline__ __m128d __DEFAULT_FN_ATTRS
Mike Stump5b31ed32009-02-13 14:24:50 +0000564_mm_setzero_pd(void)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000565{
566 return (__m128d){ 0, 0 };
567}
568
Michael Kupersteine45af542015-06-30 13:36:19 +0000569static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000570_mm_move_sd(__m128d __a, __m128d __b)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000571{
David Blaikie3302f2b2013-01-16 23:08:36 +0000572 return (__m128d){ __b[0], __a[1] };
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000573}
574
Michael Kupersteine45af542015-06-30 13:36:19 +0000575static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000576_mm_store_sd(double *__dp, __m128d __a)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000577{
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000578 struct __mm_store_sd_struct {
David Blaikie3302f2b2013-01-16 23:08:36 +0000579 double __u;
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000580 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000581 ((struct __mm_store_sd_struct*)__dp)->__u = __a[0];
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000582}
583
Michael Kupersteine45af542015-06-30 13:36:19 +0000584static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000585_mm_store1_pd(double *__dp, __m128d __a)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000586{
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000587 struct __mm_store1_pd_struct {
David Blaikie3302f2b2013-01-16 23:08:36 +0000588 double __u[2];
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000589 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000590 ((struct __mm_store1_pd_struct*)__dp)->__u[0] = __a[0];
591 ((struct __mm_store1_pd_struct*)__dp)->__u[1] = __a[0];
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000592}
593
Michael Kupersteine45af542015-06-30 13:36:19 +0000594static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000595_mm_store_pd(double *__dp, __m128d __a)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000596{
David Blaikie3302f2b2013-01-16 23:08:36 +0000597 *(__m128d *)__dp = __a;
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000598}
599
Michael Kupersteine45af542015-06-30 13:36:19 +0000600static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000601_mm_storeu_pd(double *__dp, __m128d __a)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000602{
Craig Topper1aa231e2016-05-16 06:38:42 +0000603 __builtin_ia32_storeupd(__dp, (__v2df)__a);
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000604}
605
Michael Kupersteine45af542015-06-30 13:36:19 +0000606static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000607_mm_storer_pd(double *__dp, __m128d __a)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000608{
Craig Topper1aa231e2016-05-16 06:38:42 +0000609 __a = __builtin_shufflevector((__v2df)__a, (__v2df)__a, 1, 0);
David Blaikie3302f2b2013-01-16 23:08:36 +0000610 *(__m128d *)__dp = __a;
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000611}
612
Michael Kupersteine45af542015-06-30 13:36:19 +0000613static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000614_mm_storeh_pd(double *__dp, __m128d __a)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000615{
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000616 struct __mm_storeh_pd_struct {
David Blaikie3302f2b2013-01-16 23:08:36 +0000617 double __u;
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000618 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000619 ((struct __mm_storeh_pd_struct*)__dp)->__u = __a[1];
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000620}
621
Michael Kupersteine45af542015-06-30 13:36:19 +0000622static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000623_mm_storel_pd(double *__dp, __m128d __a)
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000624{
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000625 struct __mm_storeh_pd_struct {
David Blaikie3302f2b2013-01-16 23:08:36 +0000626 double __u;
Eli Friedman9bb51ad2011-09-15 23:15:27 +0000627 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +0000628 ((struct __mm_storeh_pd_struct*)__dp)->__u = __a[0];
Anders Carlssonb08ac0b2008-12-24 02:11:54 +0000629}
630
Michael Kupersteine45af542015-06-30 13:36:19 +0000631static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000632_mm_add_epi8(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000633{
David Blaikie3302f2b2013-01-16 23:08:36 +0000634 return (__m128i)((__v16qi)__a + (__v16qi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000635}
636
Michael Kupersteine45af542015-06-30 13:36:19 +0000637static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000638_mm_add_epi16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000639{
David Blaikie3302f2b2013-01-16 23:08:36 +0000640 return (__m128i)((__v8hi)__a + (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000641}
642
Michael Kupersteine45af542015-06-30 13:36:19 +0000643static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000644_mm_add_epi32(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000645{
David Blaikie3302f2b2013-01-16 23:08:36 +0000646 return (__m128i)((__v4si)__a + (__v4si)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000647}
648
Michael Kupersteine45af542015-06-30 13:36:19 +0000649static __inline__ __m64 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000650_mm_add_si64(__m64 __a, __m64 __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000651{
Craig Topper1aa231e2016-05-16 06:38:42 +0000652 return (__m64)__builtin_ia32_paddq((__v1di)__a, (__v1di)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000653}
654
Michael Kupersteine45af542015-06-30 13:36:19 +0000655static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000656_mm_add_epi64(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000657{
Craig Topper1aa231e2016-05-16 06:38:42 +0000658 return (__m128i)((__v2di)__a + (__v2di)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000659}
660
Michael Kupersteine45af542015-06-30 13:36:19 +0000661static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000662_mm_adds_epi8(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000663{
David Blaikie3302f2b2013-01-16 23:08:36 +0000664 return (__m128i)__builtin_ia32_paddsb128((__v16qi)__a, (__v16qi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000665}
666
Michael Kupersteine45af542015-06-30 13:36:19 +0000667static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000668_mm_adds_epi16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000669{
David Blaikie3302f2b2013-01-16 23:08:36 +0000670 return (__m128i)__builtin_ia32_paddsw128((__v8hi)__a, (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000671}
672
Michael Kupersteine45af542015-06-30 13:36:19 +0000673static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000674_mm_adds_epu8(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000675{
David Blaikie3302f2b2013-01-16 23:08:36 +0000676 return (__m128i)__builtin_ia32_paddusb128((__v16qi)__a, (__v16qi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000677}
678
Michael Kupersteine45af542015-06-30 13:36:19 +0000679static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000680_mm_adds_epu16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000681{
David Blaikie3302f2b2013-01-16 23:08:36 +0000682 return (__m128i)__builtin_ia32_paddusw128((__v8hi)__a, (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000683}
684
Michael Kupersteine45af542015-06-30 13:36:19 +0000685static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000686_mm_avg_epu8(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000687{
David Blaikie3302f2b2013-01-16 23:08:36 +0000688 return (__m128i)__builtin_ia32_pavgb128((__v16qi)__a, (__v16qi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000689}
690
Michael Kupersteine45af542015-06-30 13:36:19 +0000691static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000692_mm_avg_epu16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000693{
David Blaikie3302f2b2013-01-16 23:08:36 +0000694 return (__m128i)__builtin_ia32_pavgw128((__v8hi)__a, (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000695}
696
Michael Kupersteine45af542015-06-30 13:36:19 +0000697static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000698_mm_madd_epi16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000699{
David Blaikie3302f2b2013-01-16 23:08:36 +0000700 return (__m128i)__builtin_ia32_pmaddwd128((__v8hi)__a, (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000701}
702
Michael Kupersteine45af542015-06-30 13:36:19 +0000703static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000704_mm_max_epi16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000705{
David Blaikie3302f2b2013-01-16 23:08:36 +0000706 return (__m128i)__builtin_ia32_pmaxsw128((__v8hi)__a, (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000707}
708
Michael Kupersteine45af542015-06-30 13:36:19 +0000709static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000710_mm_max_epu8(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000711{
David Blaikie3302f2b2013-01-16 23:08:36 +0000712 return (__m128i)__builtin_ia32_pmaxub128((__v16qi)__a, (__v16qi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000713}
714
Michael Kupersteine45af542015-06-30 13:36:19 +0000715static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000716_mm_min_epi16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000717{
David Blaikie3302f2b2013-01-16 23:08:36 +0000718 return (__m128i)__builtin_ia32_pminsw128((__v8hi)__a, (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000719}
720
Michael Kupersteine45af542015-06-30 13:36:19 +0000721static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000722_mm_min_epu8(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000723{
David Blaikie3302f2b2013-01-16 23:08:36 +0000724 return (__m128i)__builtin_ia32_pminub128((__v16qi)__a, (__v16qi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000725}
726
Michael Kupersteine45af542015-06-30 13:36:19 +0000727static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000728_mm_mulhi_epi16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000729{
David Blaikie3302f2b2013-01-16 23:08:36 +0000730 return (__m128i)__builtin_ia32_pmulhw128((__v8hi)__a, (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000731}
732
Michael Kupersteine45af542015-06-30 13:36:19 +0000733static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000734_mm_mulhi_epu16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000735{
David Blaikie3302f2b2013-01-16 23:08:36 +0000736 return (__m128i)__builtin_ia32_pmulhuw128((__v8hi)__a, (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000737}
738
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000739/// \brief Multiplies the corresponding elements of two [8 x short] vectors and
740/// returns a vector containing the low-order 16 bits of each 32-bit product
741/// in the corresponding element.
742///
743/// \headerfile <x86intrin.h>
744///
745/// This intrinsic corresponds to the \c VPMULLW / PMULLW instruction.
746///
747/// \param __a
748/// A 128-bit integer vector containing one of the source operands.
749/// \param __b
750/// A 128-bit integer vector containing one of the source operands.
751/// \returns A 128-bit integer vector containing the products of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000752static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000753_mm_mullo_epi16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000754{
David Blaikie3302f2b2013-01-16 23:08:36 +0000755 return (__m128i)((__v8hi)__a * (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000756}
757
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000758/// \brief Multiplies 32-bit unsigned integer values contained in the lower bits
759/// of the two 64-bit integer vectors and returns the 64-bit unsigned
760/// product.
761///
762/// \headerfile <x86intrin.h>
763///
764/// This intrinsic corresponds to the \c PMULUDQ instruction.
765///
766/// \param __a
767/// A 64-bit integer containing one of the source operands.
768/// \param __b
769/// A 64-bit integer containing one of the source operands.
770/// \returns A 64-bit integer vector containing the product of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000771static __inline__ __m64 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000772_mm_mul_su32(__m64 __a, __m64 __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000773{
David Blaikie3302f2b2013-01-16 23:08:36 +0000774 return __builtin_ia32_pmuludq((__v2si)__a, (__v2si)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000775}
776
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000777/// \brief Multiplies 32-bit unsigned integer values contained in the lower
778/// bits of the corresponding elements of two [2 x i64] vectors, and returns
779/// the 64-bit products in the corresponding elements of a [2 x i64] vector.
780///
781/// \headerfile <x86intrin.h>
782///
783/// This intrinsic corresponds to the \c VPMULUDQ / PMULUDQ instruction.
784///
785/// \param __a
786/// A [2 x i64] vector containing one of the source operands.
787/// \param __b
788/// A [2 x i64] vector containing one of the source operands.
789/// \returns A [2 x i64] vector containing the product of both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000790static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000791_mm_mul_epu32(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000792{
David Blaikie3302f2b2013-01-16 23:08:36 +0000793 return __builtin_ia32_pmuludq128((__v4si)__a, (__v4si)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000794}
795
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000796/// \brief Computes the absolute differences of corresponding 8-bit integer
797/// values in two 128-bit vectors. Sums the first 8 absolute differences, and
798/// separately sums the second 8 absolute differences. Packss these two
799/// unsigned 16-bit integer sums into the upper and lower elements of a
800/// [2 x i64] vector.
801///
802/// \headerfile <x86intrin.h>
803///
804/// This intrinsic corresponds to the \c VPSADBW / PSADBW instruction.
805///
806/// \param __a
807/// A 128-bit integer vector containing one of the source operands.
808/// \param __b
809/// A 128-bit integer vector containing one of the source operands.
810/// \returns A [2 x i64] vector containing the sums of the sets of absolute
811/// differences between both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000812static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000813_mm_sad_epu8(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000814{
David Blaikie3302f2b2013-01-16 23:08:36 +0000815 return __builtin_ia32_psadbw128((__v16qi)__a, (__v16qi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000816}
817
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000818/// \brief Subtracts the corresponding 8-bit integer values in the operands.
819///
820/// \headerfile <x86intrin.h>
821///
822/// This intrinsic corresponds to the \c VPSUBB / PSUBB instruction.
823///
824/// \param __a
825/// A 128-bit integer vector containing the minuends.
826/// \param __b
827/// A 128-bit integer vector containing the subtrahends.
828/// \returns A 128-bit integer vector containing the differences of the values
829/// in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000830static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000831_mm_sub_epi8(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000832{
David Blaikie3302f2b2013-01-16 23:08:36 +0000833 return (__m128i)((__v16qi)__a - (__v16qi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000834}
835
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000836/// \brief Subtracts the corresponding 16-bit integer values in the operands.
837///
838/// \headerfile <x86intrin.h>
839///
840/// This intrinsic corresponds to the \c VPSUBW / PSUBW instruction.
841///
842/// \param __a
843/// A 128-bit integer vector containing the minuends.
844/// \param __b
845/// A 128-bit integer vector containing the subtrahends.
846/// \returns A 128-bit integer vector containing the differences of the values
847/// in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000848static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000849_mm_sub_epi16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000850{
David Blaikie3302f2b2013-01-16 23:08:36 +0000851 return (__m128i)((__v8hi)__a - (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000852}
853
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000854/// \brief Subtracts the corresponding 32-bit integer values in the operands.
855///
856/// \headerfile <x86intrin.h>
857///
858/// This intrinsic corresponds to the \c VPSUBD / PSUBD instruction.
859///
860/// \param __a
861/// A 128-bit integer vector containing the minuends.
862/// \param __b
863/// A 128-bit integer vector containing the subtrahends.
864/// \returns A 128-bit integer vector containing the differences of the values
865/// in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000866static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000867_mm_sub_epi32(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000868{
David Blaikie3302f2b2013-01-16 23:08:36 +0000869 return (__m128i)((__v4si)__a - (__v4si)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000870}
871
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000872/// \brief Subtracts signed or unsigned 64-bit integer values and writes the
873/// difference to the corresponding bits in the destination.
874///
875/// \headerfile <x86intrin.h>
876///
877/// This intrinsic corresponds to the \c PSUBQ instruction.
878///
879/// \param __a
880/// A 64-bit integer vector containing the minuend.
881/// \param __b
882/// A 64-bit integer vector containing the subtrahend.
883/// \returns A 64-bit integer vector containing the difference of the values in
884/// the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000885static __inline__ __m64 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000886_mm_sub_si64(__m64 __a, __m64 __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000887{
Craig Topper1aa231e2016-05-16 06:38:42 +0000888 return (__m64)__builtin_ia32_psubq((__v1di)__a, (__v1di)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000889}
890
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000891/// \brief Subtracts the corresponding elements of two [2 x i64] vectors.
892///
893/// \headerfile <x86intrin.h>
894///
895/// This intrinsic corresponds to the \c VPSUBQ / PSUBQ instruction.
896///
897/// \param __a
898/// A 128-bit integer vector containing the minuends.
899/// \param __b
900/// A 128-bit integer vector containing the subtrahends.
901/// \returns A 128-bit integer vector containing the differences of the values
902/// in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000903static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000904_mm_sub_epi64(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000905{
Craig Topper1aa231e2016-05-16 06:38:42 +0000906 return (__m128i)((__v2di)__a - (__v2di)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000907}
908
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000909/// \brief Subtracts corresponding 8-bit signed integer values in the input and
910/// returns the differences in the corresponding bytes in the destination.
911/// Differences greater than 7Fh are saturated to 7Fh, and differences less
912/// than 80h are saturated to 80h.
913///
914/// \headerfile <x86intrin.h>
915///
916/// This intrinsic corresponds to the \c VPSUBSB / PSUBSB instruction.
917///
918/// \param __a
919/// A 128-bit integer vector containing the minuends.
920/// \param __b
921/// A 128-bit integer vector containing the subtrahends.
922/// \returns A 128-bit integer vector containing the differences of the values
923/// in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000924static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000925_mm_subs_epi8(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000926{
David Blaikie3302f2b2013-01-16 23:08:36 +0000927 return (__m128i)__builtin_ia32_psubsb128((__v16qi)__a, (__v16qi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000928}
929
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000930/// \brief Subtracts corresponding 16-bit signed integer values in the input and
931/// returns the differences in the corresponding bytes in the destination.
932/// Differences greater than 7FFFh are saturated to 7FFFh, and values less
933/// than 8000h are saturated to 8000h.
934///
935/// \headerfile <x86intrin.h>
936///
937/// This intrinsic corresponds to the \c VPSUBSW / PSUBSW instruction.
938///
939/// \param __a
940/// A 128-bit integer vector containing the minuends.
941/// \param __b
942/// A 128-bit integer vector containing the subtrahends.
943/// \returns A 128-bit integer vector containing the differences of the values
944/// in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000945static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000946_mm_subs_epi16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000947{
David Blaikie3302f2b2013-01-16 23:08:36 +0000948 return (__m128i)__builtin_ia32_psubsw128((__v8hi)__a, (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000949}
950
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000951/// \brief Subtracts corresponding 8-bit unsigned integer values in the input
952/// and returns the differences in the corresponding bytes in the
953/// destination. Differences less than 00h are saturated to 00h.
954///
955/// \headerfile <x86intrin.h>
956///
957/// This intrinsic corresponds to the \c VPSUBUSB / PSUBUSB instruction.
958///
959/// \param __a
960/// A 128-bit integer vector containing the minuends.
961/// \param __b
962/// A 128-bit integer vector containing the subtrahends.
963/// \returns A 128-bit integer vector containing the unsigned integer
964/// differences of the values in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000965static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000966_mm_subs_epu8(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000967{
David Blaikie3302f2b2013-01-16 23:08:36 +0000968 return (__m128i)__builtin_ia32_psubusb128((__v16qi)__a, (__v16qi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000969}
970
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000971/// \brief Subtracts corresponding 16-bit unsigned integer values in the input
972/// and returns the differences in the corresponding bytes in the
973/// destination. Differences less than 0000h are saturated to 0000h.
974///
975/// \headerfile <x86intrin.h>
976///
977/// This intrinsic corresponds to the \c VPSUBUSW / PSUBUSW instruction.
978///
979/// \param __a
980/// A 128-bit integer vector containing the minuends.
981/// \param __b
982/// A 128-bit integer vector containing the subtrahends.
983/// \returns A 128-bit integer vector containing the unsigned integer
984/// differences of the values in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +0000985static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +0000986_mm_subs_epu16(__m128i __a, __m128i __b)
Anders Carlssona283f912008-12-24 02:41:00 +0000987{
David Blaikie3302f2b2013-01-16 23:08:36 +0000988 return (__m128i)__builtin_ia32_psubusw128((__v8hi)__a, (__v8hi)__b);
Anders Carlssona283f912008-12-24 02:41:00 +0000989}
990
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +0000991/// \brief Performs a bitwise AND of two 128-bit integer vectors.
992///
993/// \headerfile <x86intrin.h>
994///
995/// This intrinsic corresponds to the \c VPAND / PAND instruction.
996///
997/// \param __a
998/// A 128-bit integer vector containing one of the source operands.
999/// \param __b
1000/// A 128-bit integer vector containing one of the source operands.
1001/// \returns A 128-bit integer vector containing the bitwise AND of the values
1002/// in both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +00001003static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001004_mm_and_si128(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001005{
Craig Topper1aa231e2016-05-16 06:38:42 +00001006 return (__m128i)((__v2di)__a & (__v2di)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001007}
1008
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001009/// \brief Performs a bitwise AND of two 128-bit integer vectors, using the
1010/// one's complement of the values contained in the first source operand.
1011///
1012/// \headerfile <x86intrin.h>
1013///
1014/// This intrinsic corresponds to the \c VPANDN / PANDN instruction.
1015///
1016/// \param __a
1017/// A 128-bit vector containing the left source operand. The one's complement
1018/// of this value is used in the bitwise AND.
1019/// \param __b
1020/// A 128-bit vector containing the right source operand.
1021/// \returns A 128-bit integer vector containing the bitwise AND of the one's
1022/// complement of the first operand and the values in the second operand.
Michael Kupersteine45af542015-06-30 13:36:19 +00001023static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001024_mm_andnot_si128(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001025{
Craig Topper1aa231e2016-05-16 06:38:42 +00001026 return (__m128i)(~(__v2di)__a & (__v2di)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001027}
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001028/// \brief Performs a bitwise OR of two 128-bit integer vectors.
1029///
1030/// \headerfile <x86intrin.h>
1031///
1032/// This intrinsic corresponds to the \c VPOR / POR instruction.
1033///
1034/// \param __a
1035/// A 128-bit integer vector containing one of the source operands.
1036/// \param __b
1037/// A 128-bit integer vector containing one of the source operands.
1038/// \returns A 128-bit integer vector containing the bitwise OR of the values
1039/// in both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +00001040static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001041_mm_or_si128(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001042{
Craig Topper1aa231e2016-05-16 06:38:42 +00001043 return (__m128i)((__v2di)__a | (__v2di)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001044}
1045
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001046/// \brief Performs a bitwise exclusive OR of two 128-bit integer vectors.
1047///
1048/// \headerfile <x86intrin.h>
1049///
1050/// This intrinsic corresponds to the \c VPXOR / PXOR instruction.
1051///
1052/// \param __a
1053/// A 128-bit integer vector containing one of the source operands.
1054/// \param __b
1055/// A 128-bit integer vector containing one of the source operands.
1056/// \returns A 128-bit integer vector containing the bitwise exclusive OR of the
1057/// values in both operands.
Michael Kupersteine45af542015-06-30 13:36:19 +00001058static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001059_mm_xor_si128(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001060{
Craig Topper1aa231e2016-05-16 06:38:42 +00001061 return (__m128i)((__v2di)__a ^ (__v2di)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001062}
1063
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001064/// \brief Left-shifts the 128-bit integer vector operand by the specified
1065/// number of bytes. Low-order bits are cleared.
1066///
1067/// \headerfile <x86intrin.h>
1068///
1069/// \code
1070/// __m128i _mm_slli_si128(__m128i a, const int imm);
1071/// \endcode
1072///
1073/// This intrinsic corresponds to the \c VPSLLDQ / PSLLDQ instruction.
1074///
1075/// \param a
1076/// A 128-bit integer vector containing the source operand.
1077/// \param imm
1078/// An immediate value specifying the number of bytes to left-shift
1079/// operand a.
1080/// \returns A 128-bit integer vector containing the left-shifted value.
Craig Topper51e47412015-02-13 06:04:43 +00001081#define _mm_slli_si128(a, imm) __extension__ ({ \
1082 (__m128i)__builtin_shufflevector((__v16qi)_mm_setzero_si128(), \
1083 (__v16qi)(__m128i)(a), \
1084 ((imm)&0xF0) ? 0 : 16 - ((imm)&0xF), \
1085 ((imm)&0xF0) ? 0 : 17 - ((imm)&0xF), \
1086 ((imm)&0xF0) ? 0 : 18 - ((imm)&0xF), \
1087 ((imm)&0xF0) ? 0 : 19 - ((imm)&0xF), \
1088 ((imm)&0xF0) ? 0 : 20 - ((imm)&0xF), \
1089 ((imm)&0xF0) ? 0 : 21 - ((imm)&0xF), \
1090 ((imm)&0xF0) ? 0 : 22 - ((imm)&0xF), \
1091 ((imm)&0xF0) ? 0 : 23 - ((imm)&0xF), \
1092 ((imm)&0xF0) ? 0 : 24 - ((imm)&0xF), \
1093 ((imm)&0xF0) ? 0 : 25 - ((imm)&0xF), \
1094 ((imm)&0xF0) ? 0 : 26 - ((imm)&0xF), \
1095 ((imm)&0xF0) ? 0 : 27 - ((imm)&0xF), \
1096 ((imm)&0xF0) ? 0 : 28 - ((imm)&0xF), \
1097 ((imm)&0xF0) ? 0 : 29 - ((imm)&0xF), \
1098 ((imm)&0xF0) ? 0 : 30 - ((imm)&0xF), \
1099 ((imm)&0xF0) ? 0 : 31 - ((imm)&0xF)); })
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001100
Craig Toppera4624822015-02-13 06:04:45 +00001101#define _mm_bslli_si128(a, imm) \
1102 _mm_slli_si128((a), (imm))
1103
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001104/// \brief Left-shifts each 16-bit value in the 128-bit integer vector operand
1105/// by the specified number of bits. Low-order bits are cleared.
1106///
1107/// \headerfile <x86intrin.h>
1108///
1109/// This intrinsic corresponds to the \c VPSLLW / PSLLW instruction.
1110///
1111/// \param __a
1112/// A 128-bit integer vector containing the source operand.
1113/// \param __count
1114/// An integer value specifying the number of bits to left-shift each value
1115/// in operand __a.
1116/// \returns A 128-bit integer vector containing the left-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001117static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001118_mm_slli_epi16(__m128i __a, int __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001119{
David Blaikie3302f2b2013-01-16 23:08:36 +00001120 return (__m128i)__builtin_ia32_psllwi128((__v8hi)__a, __count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001121}
1122
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001123/// \brief Left-shifts each 16-bit value in the 128-bit integer vector operand
1124/// by the specified number of bits. Low-order bits are cleared.
1125///
1126/// \headerfile <x86intrin.h>
1127///
1128/// This intrinsic corresponds to the \c VPSLLW / PSLLW instruction.
1129///
1130/// \param __a
1131/// A 128-bit integer vector containing the source operand.
1132/// \param __count
1133/// A 128-bit integer vector in which bits [63:0] specify the number of bits
1134/// to left-shift each value in operand __a.
1135/// \returns A 128-bit integer vector containing the left-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001136static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001137_mm_sll_epi16(__m128i __a, __m128i __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001138{
David Blaikie3302f2b2013-01-16 23:08:36 +00001139 return (__m128i)__builtin_ia32_psllw128((__v8hi)__a, (__v8hi)__count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001140}
1141
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001142/// \brief Left-shifts each 32-bit value in the 128-bit integer vector operand
1143/// by the specified number of bits. Low-order bits are cleared.
1144///
1145/// \headerfile <x86intrin.h>
1146///
1147/// This intrinsic corresponds to the \c VPSLLD / PSLLD instruction.
1148///
1149/// \param __a
1150/// A 128-bit integer vector containing the source operand.
1151/// \param __count
1152/// An integer value specifying the number of bits to left-shift each value
1153/// in operand __a.
1154/// \returns A 128-bit integer vector containing the left-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001155static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001156_mm_slli_epi32(__m128i __a, int __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001157{
David Blaikie3302f2b2013-01-16 23:08:36 +00001158 return (__m128i)__builtin_ia32_pslldi128((__v4si)__a, __count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001159}
1160
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001161/// \brief Left-shifts each 32-bit value in the 128-bit integer vector operand
1162/// by the specified number of bits. Low-order bits are cleared.
1163///
1164/// \headerfile <x86intrin.h>
1165///
1166/// This intrinsic corresponds to the \c VPSLLD / PSLLD instruction.
1167///
1168/// \param __a
1169/// A 128-bit integer vector containing the source operand.
1170/// \param __count
1171/// A 128-bit integer vector in which bits [63:0] specify the number of bits
1172/// to left-shift each value in operand __a.
1173/// \returns A 128-bit integer vector containing the left-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001174static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001175_mm_sll_epi32(__m128i __a, __m128i __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001176{
David Blaikie3302f2b2013-01-16 23:08:36 +00001177 return (__m128i)__builtin_ia32_pslld128((__v4si)__a, (__v4si)__count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001178}
1179
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001180/// \brief Left-shifts each 64-bit value in the 128-bit integer vector operand
1181/// by the specified number of bits. Low-order bits are cleared.
1182///
1183/// \headerfile <x86intrin.h>
1184///
1185/// This intrinsic corresponds to the \c VPSLLQ / PSLLQ instruction.
1186///
1187/// \param __a
1188/// A 128-bit integer vector containing the source operand.
1189/// \param __count
1190/// An integer value specifying the number of bits to left-shift each value
1191/// in operand __a.
1192/// \returns A 128-bit integer vector containing the left-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001193static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001194_mm_slli_epi64(__m128i __a, int __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001195{
Craig Topper1aa231e2016-05-16 06:38:42 +00001196 return __builtin_ia32_psllqi128((__v2di)__a, __count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001197}
1198
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001199/// \brief Left-shifts each 64-bit value in the 128-bit integer vector operand
1200/// by the specified number of bits. Low-order bits are cleared.
1201///
1202/// \headerfile <x86intrin.h>
1203///
1204/// This intrinsic corresponds to the \c VPSLLQ / PSLLQ instruction.
1205///
1206/// \param __a
1207/// A 128-bit integer vector containing the source operand.
1208/// \param __count
1209/// A 128-bit integer vector in which bits [63:0] specify the number of bits
1210/// to left-shift each value in operand __a.
1211/// \returns A 128-bit integer vector containing the left-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001212static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001213_mm_sll_epi64(__m128i __a, __m128i __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001214{
Craig Topper1aa231e2016-05-16 06:38:42 +00001215 return __builtin_ia32_psllq128((__v2di)__a, (__v2di)__count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001216}
1217
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001218/// \brief Right-shifts each 16-bit value in the 128-bit integer vector operand
1219/// by the specified number of bits. High-order bits are filled with the sign
1220/// bit of the initial value.
1221///
1222/// \headerfile <x86intrin.h>
1223///
1224/// This intrinsic corresponds to the \c VPSRAW / PSRAW instruction.
1225///
1226/// \param __a
1227/// A 128-bit integer vector containing the source operand.
1228/// \param __count
1229/// An integer value specifying the number of bits to right-shift each value
1230/// in operand __a.
1231/// \returns A 128-bit integer vector containing the right-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001232static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001233_mm_srai_epi16(__m128i __a, int __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001234{
David Blaikie3302f2b2013-01-16 23:08:36 +00001235 return (__m128i)__builtin_ia32_psrawi128((__v8hi)__a, __count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001236}
1237
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001238/// \brief Right-shifts each 16-bit value in the 128-bit integer vector operand
1239/// by the specified number of bits. High-order bits are filled with the sign
1240/// bit of the initial value.
1241///
1242/// \headerfile <x86intrin.h>
1243///
1244/// This intrinsic corresponds to the \c VPSRAW / PSRAW instruction.
1245///
1246/// \param __a
1247/// A 128-bit integer vector containing the source operand.
1248/// \param __count
1249/// A 128-bit integer vector in which bits [63:0] specify the number of bits
1250/// to right-shift each value in operand __a.
1251/// \returns A 128-bit integer vector containing the right-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001252static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001253_mm_sra_epi16(__m128i __a, __m128i __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001254{
David Blaikie3302f2b2013-01-16 23:08:36 +00001255 return (__m128i)__builtin_ia32_psraw128((__v8hi)__a, (__v8hi)__count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001256}
1257
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001258/// \brief Right-shifts each 32-bit value in the 128-bit integer vector operand
1259/// by the specified number of bits. High-order bits are filled with the sign
1260/// bit of the initial value.
1261///
1262/// \headerfile <x86intrin.h>
1263///
1264/// This intrinsic corresponds to the \c VPSRAD / PSRAD instruction.
1265///
1266/// \param __a
1267/// A 128-bit integer vector containing the source operand.
1268/// \param __count
1269/// An integer value specifying the number of bits to right-shift each value
1270/// in operand __a.
1271/// \returns A 128-bit integer vector containing the right-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001272static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001273_mm_srai_epi32(__m128i __a, int __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001274{
David Blaikie3302f2b2013-01-16 23:08:36 +00001275 return (__m128i)__builtin_ia32_psradi128((__v4si)__a, __count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001276}
1277
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001278/// \brief Right-shifts each 32-bit value in the 128-bit integer vector operand
1279/// by the specified number of bits. High-order bits are filled with the sign
1280/// bit of the initial value.
1281///
1282/// \headerfile <x86intrin.h>
1283///
1284/// This intrinsic corresponds to the \c VPSRAD / PSRAD instruction.
1285///
1286/// \param __a
1287/// A 128-bit integer vector containing the source operand.
1288/// \param __count
1289/// A 128-bit integer vector in which bits [63:0] specify the number of bits
1290/// to right-shift each value in operand __a.
1291/// \returns A 128-bit integer vector containing the right-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001292static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001293_mm_sra_epi32(__m128i __a, __m128i __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001294{
David Blaikie3302f2b2013-01-16 23:08:36 +00001295 return (__m128i)__builtin_ia32_psrad128((__v4si)__a, (__v4si)__count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001296}
1297
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001298/// \brief Right-shifts the 128-bit integer vector operand by the specified
1299/// number of bytes. High-order bits are cleared.
1300///
1301/// \headerfile <x86intrin.h>
1302///
1303/// \code
1304/// __m128i _mm_srli_si128(__m128i a, const int imm);
1305/// \endcode
1306///
1307/// This intrinsic corresponds to the \c VPSRLDQ / PSRLDQ instruction.
1308///
1309/// \param a
1310/// A 128-bit integer vector containing the source operand.
1311/// \param imm
1312/// An immediate value specifying the number of bytes to right-shift operand
1313/// a.
1314/// \returns A 128-bit integer vector containing the right-shifted value.
Craig Topper51e47412015-02-13 06:04:43 +00001315#define _mm_srli_si128(a, imm) __extension__ ({ \
1316 (__m128i)__builtin_shufflevector((__v16qi)(__m128i)(a), \
1317 (__v16qi)_mm_setzero_si128(), \
1318 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 0, \
1319 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 1, \
1320 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 2, \
1321 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 3, \
1322 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 4, \
1323 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 5, \
1324 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 6, \
1325 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 7, \
1326 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 8, \
1327 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 9, \
1328 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 10, \
1329 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 11, \
1330 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 12, \
1331 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 13, \
1332 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 14, \
1333 ((imm)&0xF0) ? 16 : ((imm)&0xF) + 15); })
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001334
Craig Toppera4624822015-02-13 06:04:45 +00001335#define _mm_bsrli_si128(a, imm) \
1336 _mm_srli_si128((a), (imm))
1337
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001338/// \brief Right-shifts each of 16-bit values in the 128-bit integer vector
1339/// operand by the specified number of bits. High-order bits are cleared.
1340///
1341/// \headerfile <x86intrin.h>
1342///
1343/// This intrinsic corresponds to the \c VPSRLW / PSRLW instruction.
1344///
1345/// \param __a
1346/// A 128-bit integer vector containing the source operand.
1347/// \param __count
1348/// An integer value specifying the number of bits to right-shift each value
1349/// in operand __a.
1350/// \returns A 128-bit integer vector containing the right-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001351static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001352_mm_srli_epi16(__m128i __a, int __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001353{
David Blaikie3302f2b2013-01-16 23:08:36 +00001354 return (__m128i)__builtin_ia32_psrlwi128((__v8hi)__a, __count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001355}
1356
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001357/// \brief Right-shifts each of 16-bit values in the 128-bit integer vector
1358/// operand by the specified number of bits. High-order bits are cleared.
1359///
1360/// \headerfile <x86intrin.h>
1361///
1362/// This intrinsic corresponds to the \c VPSRLW / PSRLW instruction.
1363///
1364/// \param __a
1365/// A 128-bit integer vector containing the source operand.
1366/// \param __count
1367/// A 128-bit integer vector in which bits [63:0] specify the number of bits
1368/// to right-shift each value in operand __a.
1369/// \returns A 128-bit integer vector containing the right-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001370static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001371_mm_srl_epi16(__m128i __a, __m128i __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001372{
David Blaikie3302f2b2013-01-16 23:08:36 +00001373 return (__m128i)__builtin_ia32_psrlw128((__v8hi)__a, (__v8hi)__count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001374}
1375
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001376/// \brief Right-shifts each of 32-bit values in the 128-bit integer vector
1377/// operand by the specified number of bits. High-order bits are cleared.
1378///
1379/// \headerfile <x86intrin.h>
1380///
1381/// This intrinsic corresponds to the \c VPSRLD / PSRLD instruction.
1382///
1383/// \param __a
1384/// A 128-bit integer vector containing the source operand.
1385/// \param __count
1386/// An integer value specifying the number of bits to right-shift each value
1387/// in operand __a.
1388/// \returns A 128-bit integer vector containing the right-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001389static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001390_mm_srli_epi32(__m128i __a, int __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001391{
David Blaikie3302f2b2013-01-16 23:08:36 +00001392 return (__m128i)__builtin_ia32_psrldi128((__v4si)__a, __count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001393}
1394
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001395/// \brief Right-shifts each of 32-bit values in the 128-bit integer vector
1396/// operand by the specified number of bits. High-order bits are cleared.
1397///
1398/// \headerfile <x86intrin.h>
1399///
1400/// This intrinsic corresponds to the \c VPSRLD / PSRLD instruction.
1401///
1402/// \param __a
1403/// A 128-bit integer vector containing the source operand.
1404/// \param __count
1405/// A 128-bit integer vector in which bits [63:0] specify the number of bits
1406/// to right-shift each value in operand __a.
1407/// \returns A 128-bit integer vector containing the right-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001408static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001409_mm_srl_epi32(__m128i __a, __m128i __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001410{
David Blaikie3302f2b2013-01-16 23:08:36 +00001411 return (__m128i)__builtin_ia32_psrld128((__v4si)__a, (__v4si)__count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001412}
1413
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001414/// \brief Right-shifts each of 64-bit values in the 128-bit integer vector
1415/// operand by the specified number of bits. High-order bits are cleared.
1416///
1417/// \headerfile <x86intrin.h>
1418///
1419/// This intrinsic corresponds to the \c VPSRLQ / PSRLQ instruction.
1420///
1421/// \param __a
1422/// A 128-bit integer vector containing the source operand.
1423/// \param __count
1424/// An integer value specifying the number of bits to right-shift each value
1425/// in operand __a.
1426/// \returns A 128-bit integer vector containing the right-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001427static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001428_mm_srli_epi64(__m128i __a, int __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001429{
Craig Topper1aa231e2016-05-16 06:38:42 +00001430 return __builtin_ia32_psrlqi128((__v2di)__a, __count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001431}
1432
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001433/// \brief Right-shifts each of 64-bit values in the 128-bit integer vector
1434/// operand by the specified number of bits. High-order bits are cleared.
1435///
1436/// \headerfile <x86intrin.h>
1437///
1438/// This intrinsic corresponds to the \c VPSRLQ / PSRLQ instruction.
1439///
1440/// \param __a
1441/// A 128-bit integer vector containing the source operand.
1442/// \param __count
1443/// A 128-bit integer vector in which bits [63:0] specify the number of bits
1444/// to right-shift each value in operand __a.
1445/// \returns A 128-bit integer vector containing the right-shifted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001446static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001447_mm_srl_epi64(__m128i __a, __m128i __count)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001448{
Craig Topper1aa231e2016-05-16 06:38:42 +00001449 return __builtin_ia32_psrlq128((__v2di)__a, (__v2di)__count);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001450}
1451
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001452/// \brief Compares each of the corresponding 8-bit values of the 128-bit
1453/// integer vectors for equality. Each comparison yields 0h for false, FFh
1454/// for true.
1455///
1456/// \headerfile <x86intrin.h>
1457///
1458/// This intrinsic corresponds to the \c VPCMPEQB / PCMPEQB instruction.
1459///
1460/// \param __a
1461/// A 128-bit integer vector.
1462/// \param __b
1463/// A 128-bit integer vector.
1464/// \returns A 128-bit integer vector containing the comparison results.
Michael Kupersteine45af542015-06-30 13:36:19 +00001465static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001466_mm_cmpeq_epi8(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001467{
David Blaikie3302f2b2013-01-16 23:08:36 +00001468 return (__m128i)((__v16qi)__a == (__v16qi)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001469}
1470
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001471/// \brief Compares each of the corresponding 16-bit values of the 128-bit
1472/// integer vectors for equality. Each comparison yields 0h for false, FFFFh
1473/// for true.
1474///
1475/// \headerfile <x86intrin.h>
1476///
1477/// This intrinsic corresponds to the \c VPCMPEQW / PCMPEQW instruction.
1478///
1479/// \param __a
1480/// A 128-bit integer vector.
1481/// \param __b
1482/// A 128-bit integer vector.
1483/// \returns A 128-bit integer vector containing the comparison results.
Michael Kupersteine45af542015-06-30 13:36:19 +00001484static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001485_mm_cmpeq_epi16(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001486{
David Blaikie3302f2b2013-01-16 23:08:36 +00001487 return (__m128i)((__v8hi)__a == (__v8hi)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001488}
1489
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001490/// \brief Compares each of the corresponding 32-bit values of the 128-bit
1491/// integer vectors for equality. Each comparison yields 0h for false,
1492/// FFFFFFFFh for true.
1493///
1494/// \headerfile <x86intrin.h>
1495///
1496/// This intrinsic corresponds to the \c VPCMPEQD / PCMPEQD instruction.
1497///
1498/// \param __a
1499/// A 128-bit integer vector.
1500/// \param __b
1501/// A 128-bit integer vector.
1502/// \returns A 128-bit integer vector containing the comparison results.
Michael Kupersteine45af542015-06-30 13:36:19 +00001503static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001504_mm_cmpeq_epi32(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001505{
David Blaikie3302f2b2013-01-16 23:08:36 +00001506 return (__m128i)((__v4si)__a == (__v4si)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001507}
1508
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001509/// \brief Compares each of the corresponding signed 8-bit values of the 128-bit
1510/// integer vectors to determine if the values in the first operand are
1511/// greater than those in the second operand. Each comparison yields 0h for
1512/// false, FFh for true.
1513///
1514/// \headerfile <x86intrin.h>
1515///
1516/// This intrinsic corresponds to the \c VPCMPGTB / PCMPGTB instruction.
1517///
1518/// \param __a
1519/// A 128-bit integer vector.
1520/// \param __b
1521/// A 128-bit integer vector.
1522/// \returns A 128-bit integer vector containing the comparison results.
Michael Kupersteine45af542015-06-30 13:36:19 +00001523static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001524_mm_cmpgt_epi8(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001525{
Nick Lewyckyd0ba3792012-02-04 02:16:48 +00001526 /* This function always performs a signed comparison, but __v16qi is a char
Chandler Carruthcbe64112015-10-01 23:40:12 +00001527 which may be signed or unsigned, so use __v16qs. */
David Blaikie3302f2b2013-01-16 23:08:36 +00001528 return (__m128i)((__v16qs)__a > (__v16qs)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001529}
1530
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001531/// \brief Compares each of the corresponding signed 16-bit values of the
1532/// 128-bit integer vectors to determine if the values in the first operand
1533/// are greater than those in the second operand. Each comparison yields 0h
1534/// for false, FFFFh for true.
1535///
1536/// \headerfile <x86intrin.h>
1537///
1538/// This intrinsic corresponds to the \c VPCMPGTW / PCMPGTW instruction.
1539///
1540/// \param __a
1541/// A 128-bit integer vector.
1542/// \param __b
1543/// A 128-bit integer vector.
1544/// \returns A 128-bit integer vector containing the comparison results.
Michael Kupersteine45af542015-06-30 13:36:19 +00001545static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001546_mm_cmpgt_epi16(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001547{
David Blaikie3302f2b2013-01-16 23:08:36 +00001548 return (__m128i)((__v8hi)__a > (__v8hi)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001549}
1550
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001551/// \brief Compares each of the corresponding signed 32-bit values of the
1552/// 128-bit integer vectors to determine if the values in the first operand
1553/// are greater than those in the second operand. Each comparison yields 0h
1554/// for false, FFFFFFFFh for true.
1555///
1556/// \headerfile <x86intrin.h>
1557///
1558/// This intrinsic corresponds to the \c VPCMPGTD / PCMPGTD instruction.
1559///
1560/// \param __a
1561/// A 128-bit integer vector.
1562/// \param __b
1563/// A 128-bit integer vector.
1564/// \returns A 128-bit integer vector containing the comparison results.
Michael Kupersteine45af542015-06-30 13:36:19 +00001565static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001566_mm_cmpgt_epi32(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001567{
David Blaikie3302f2b2013-01-16 23:08:36 +00001568 return (__m128i)((__v4si)__a > (__v4si)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001569}
1570
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001571/// \brief Compares each of the corresponding signed 8-bit values of the 128-bit
1572/// integer vectors to determine if the values in the first operand are less
1573/// than those in the second operand. Each comparison yields 0h for false,
1574/// FFh for true.
1575///
1576/// \headerfile <x86intrin.h>
1577///
1578/// This intrinsic corresponds to the \c VPCMPGTB / PCMPGTB instruction.
1579///
1580/// \param __a
1581/// A 128-bit integer vector.
1582/// \param __b
1583/// A 128-bit integer vector.
1584/// \returns A 128-bit integer vector containing the comparison results.
Michael Kupersteine45af542015-06-30 13:36:19 +00001585static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001586_mm_cmplt_epi8(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001587{
David Blaikie3302f2b2013-01-16 23:08:36 +00001588 return _mm_cmpgt_epi8(__b, __a);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001589}
1590
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001591/// \brief Compares each of the corresponding signed 16-bit values of the
1592/// 128-bit integer vectors to determine if the values in the first operand
1593/// are less than those in the second operand. Each comparison yields 0h for
1594/// false, FFFFh for true.
1595///
1596/// \headerfile <x86intrin.h>
1597///
1598/// This intrinsic corresponds to the \c VPCMPGTW / PCMPGTW instruction.
1599///
1600/// \param __a
1601/// A 128-bit integer vector.
1602/// \param __b
1603/// A 128-bit integer vector.
1604/// \returns A 128-bit integer vector containing the comparison results.
Michael Kupersteine45af542015-06-30 13:36:19 +00001605static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001606_mm_cmplt_epi16(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001607{
David Blaikie3302f2b2013-01-16 23:08:36 +00001608 return _mm_cmpgt_epi16(__b, __a);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001609}
1610
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001611/// \brief Compares each of the corresponding signed 32-bit values of the
1612/// 128-bit integer vectors to determine if the values in the first operand
1613/// are less than those in the second operand. Each comparison yields 0h for
1614/// false, FFFFFFFFh for true.
1615///
1616/// \headerfile <x86intrin.h>
1617///
1618/// This intrinsic corresponds to the \c VPCMPGTD / PCMPGTD instruction.
1619///
1620/// \param __a
1621/// A 128-bit integer vector.
1622/// \param __b
1623/// A 128-bit integer vector.
1624/// \returns A 128-bit integer vector containing the comparison results.
Michael Kupersteine45af542015-06-30 13:36:19 +00001625static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001626_mm_cmplt_epi32(__m128i __a, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001627{
David Blaikie3302f2b2013-01-16 23:08:36 +00001628 return _mm_cmpgt_epi32(__b, __a);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001629}
1630
1631#ifdef __x86_64__
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001632/// \brief Converts a 64-bit signed integer value from the second operand into a
1633/// double-precision value and returns it in the lower element of a [2 x
1634/// double] vector; the upper element of the returned vector is copied from
1635/// the upper element of the first operand.
1636///
1637/// \headerfile <x86intrin.h>
1638///
1639/// This intrinsic corresponds to the \c VCVTSI2SD / CVTSI2SD instruction.
1640///
1641/// \param __a
1642/// A 128-bit vector of [2 x double]. The upper 64 bits of this operand are
1643/// copied to the upper 64 bits of the destination.
1644/// \param __b
1645/// A 64-bit signed integer operand containing the value to be converted.
1646/// \returns A 128-bit vector of [2 x double] whose lower 64 bits contain the
1647/// converted value of the second operand. The upper 64 bits are copied from
1648/// the upper 64 bits of the first operand.
Michael Kupersteine45af542015-06-30 13:36:19 +00001649static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001650_mm_cvtsi64_sd(__m128d __a, long long __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001651{
David Blaikie3302f2b2013-01-16 23:08:36 +00001652 __a[0] = __b;
1653 return __a;
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001654}
1655
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001656/// \brief Converts the first (lower) element of a vector of [2 x double] into a
1657/// 64-bit signed integer value, according to the current rounding mode.
1658///
1659/// \headerfile <x86intrin.h>
1660///
1661/// This intrinsic corresponds to the \c VCVTSD2SI / CVTSD2SI instruction.
1662///
1663/// \param __a
1664/// A 128-bit vector of [2 x double]. The lower 64 bits are used in the
1665/// conversion.
1666/// \returns A 64-bit signed integer containing the converted value.
Michael Kupersteine45af542015-06-30 13:36:19 +00001667static __inline__ long long __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001668_mm_cvtsd_si64(__m128d __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001669{
Craig Topper1aa231e2016-05-16 06:38:42 +00001670 return __builtin_ia32_cvtsd2si64((__v2df)__a);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001671}
1672
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001673/// \brief Converts the first (lower) element of a vector of [2 x double] into a
1674/// 64-bit signed integer value, truncating the result when it is inexact.
1675///
1676/// \headerfile <x86intrin.h>
1677///
1678/// This intrinsic corresponds to the \c VCVTTSD2SI / CVTTSD2SI instruction.
1679///
1680/// \param __a
1681/// A 128-bit vector of [2 x double]. The lower 64 bits are used in the
1682/// conversion.
1683/// \returns A 64-bit signed integer containing the converted value.
Michael Kupersteine45af542015-06-30 13:36:19 +00001684static __inline__ long long __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001685_mm_cvttsd_si64(__m128d __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001686{
David Blaikie3302f2b2013-01-16 23:08:36 +00001687 return __a[0];
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001688}
1689#endif
1690
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001691/// \brief Converts a vector of [4 x i32] into a vector of [4 x float].
1692///
1693/// \headerfile <x86intrin.h>
1694///
1695/// This intrinsic corresponds to the \c VCVTDQ2PS / CVTDQ2PS instruction.
1696///
1697/// \param __a
1698/// A 128-bit integer vector.
1699/// \returns A 128-bit vector of [4 x float] containing the converted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001700static __inline__ __m128 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001701_mm_cvtepi32_ps(__m128i __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001702{
David Blaikie3302f2b2013-01-16 23:08:36 +00001703 return __builtin_ia32_cvtdq2ps((__v4si)__a);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001704}
1705
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001706/// \brief Converts a vector of [4 x float] into a vector of [4 x i32].
1707///
1708/// \headerfile <x86intrin.h>
1709///
1710/// This intrinsic corresponds to the \c VCVTPS2DQ / CVTPS2DQ instruction.
1711///
1712/// \param __a
1713/// A 128-bit vector of [4 x float].
1714/// \returns A 128-bit integer vector of [4 x i32] containing the converted
1715/// values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001716static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001717_mm_cvtps_epi32(__m128 __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001718{
Craig Topper1aa231e2016-05-16 06:38:42 +00001719 return (__m128i)__builtin_ia32_cvtps2dq((__v4sf)__a);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001720}
1721
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001722/// \brief Converts a vector of [4 x float] into a vector of [4 x i32],
1723/// truncating the result when it is inexact.
1724///
1725/// \headerfile <x86intrin.h>
1726///
1727/// This intrinsic corresponds to the \c VCVTTPS2DQ / CVTTPS2DQ instruction.
1728///
1729/// \param __a
1730/// A 128-bit vector of [4 x float].
1731/// \returns A 128-bit vector of [4 x i32] containing the converted values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001732static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001733_mm_cvttps_epi32(__m128 __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001734{
Craig Topper1aa231e2016-05-16 06:38:42 +00001735 return (__m128i)__builtin_ia32_cvttps2dq((__v4sf)__a);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001736}
1737
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001738/// \brief Returns a vector of [4 x i32] where the lowest element is the input
1739/// operand and the remaining elements are zero.
1740///
1741/// \headerfile <x86intrin.h>
1742///
1743/// This intrinsic corresponds to the \c VMOVD / MOVD instruction.
1744///
1745/// \param __a
1746/// A 32-bit signed integer operand.
1747/// \returns A 128-bit vector of [4 x i32].
Michael Kupersteine45af542015-06-30 13:36:19 +00001748static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001749_mm_cvtsi32_si128(int __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001750{
David Blaikie3302f2b2013-01-16 23:08:36 +00001751 return (__m128i)(__v4si){ __a, 0, 0, 0 };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001752}
1753
1754#ifdef __x86_64__
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001755/// \brief Returns a vector of [2 x i64] where the lower element is the input
1756/// operand and the upper element is zero.
1757///
1758/// \headerfile <x86intrin.h>
1759///
1760/// This intrinsic corresponds to the \c VMOVQ / MOVQ instruction.
1761///
1762/// \param __a
1763/// A 64-bit signed integer operand containing the value to be converted.
1764/// \returns A 128-bit vector of [2 x i64] containing the converted value.
Michael Kupersteine45af542015-06-30 13:36:19 +00001765static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001766_mm_cvtsi64_si128(long long __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001767{
David Blaikie3302f2b2013-01-16 23:08:36 +00001768 return (__m128i){ __a, 0 };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001769}
1770#endif
1771
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001772/// \brief Moves the least significant 32 bits of a vector of [4 x i32] to a
1773/// 32-bit signed integer value.
1774///
1775/// \headerfile <x86intrin.h>
1776///
1777/// This intrinsic corresponds to the \c VMOVD / MOVD instruction.
1778///
1779/// \param __a
1780/// A vector of [4 x i32]. The least significant 32 bits are moved to the
1781/// destination.
1782/// \returns A 32-bit signed integer containing the moved value.
Michael Kupersteine45af542015-06-30 13:36:19 +00001783static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001784_mm_cvtsi128_si32(__m128i __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001785{
David Blaikie3302f2b2013-01-16 23:08:36 +00001786 __v4si __b = (__v4si)__a;
1787 return __b[0];
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001788}
1789
1790#ifdef __x86_64__
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001791/// \brief Moves the least significant 64 bits of a vector of [2 x i64] to a
1792/// 64-bit signed integer value.
1793///
1794/// \headerfile <x86intrin.h>
1795///
1796/// This intrinsic corresponds to the \c VMOVQ / MOVQ instruction.
1797///
1798/// \param __a
1799/// A vector of [2 x i64]. The least significant 64 bits are moved to the
1800/// destination.
1801/// \returns A 64-bit signed integer containing the moved value.
Michael Kupersteine45af542015-06-30 13:36:19 +00001802static __inline__ long long __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001803_mm_cvtsi128_si64(__m128i __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001804{
David Blaikie3302f2b2013-01-16 23:08:36 +00001805 return __a[0];
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001806}
1807#endif
1808
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001809/// \brief Moves packed integer values from an aligned 128-bit memory location
1810/// to elements in a 128-bit integer vector.
1811///
1812/// \headerfile <x86intrin.h>
1813///
1814/// This intrinsic corresponds to the \c VMOVDQA / MOVDQA instruction.
1815///
1816/// \param __p
1817/// An aligned pointer to a memory location containing integer values.
1818/// \returns A 128-bit integer vector containing the moved values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001819static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001820_mm_load_si128(__m128i const *__p)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001821{
David Blaikie3302f2b2013-01-16 23:08:36 +00001822 return *__p;
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001823}
1824
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001825/// \brief Moves packed integer values from an unaligned 128-bit memory location
1826/// to elements in a 128-bit integer vector.
1827///
1828/// \headerfile <x86intrin.h>
1829///
1830/// This intrinsic corresponds to the \c VMOVDQU / MOVDQU instruction.
1831///
1832/// \param __p
1833/// A pointer to a memory location containing integer values.
1834/// \returns A 128-bit integer vector containing the moved values.
Michael Kupersteine45af542015-06-30 13:36:19 +00001835static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001836_mm_loadu_si128(__m128i const *__p)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001837{
Bill Wendling502931f2011-05-13 00:11:39 +00001838 struct __loadu_si128 {
David Blaikie3302f2b2013-01-16 23:08:36 +00001839 __m128i __v;
David Majnemer1cf22e62015-02-04 00:26:10 +00001840 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +00001841 return ((struct __loadu_si128*)__p)->__v;
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001842}
1843
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001844/// \brief Returns a vector of [2 x i64] where the lower element is taken from
1845/// the lower element of the operand, and the upper element is zero.
1846///
1847/// \headerfile <x86intrin.h>
1848///
1849/// This intrinsic corresponds to the \c VMOVQ / MOVQ instruction.
1850///
1851/// \param __p
1852/// A 128-bit vector of [2 x i64]. Bits [63:0] are written to bits [63:0] of
1853/// the destination.
1854/// \returns A 128-bit vector of [2 x i64]. The lower order bits contain the
1855/// moved value. The higher order bits are cleared.
Michael Kupersteine45af542015-06-30 13:36:19 +00001856static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00001857_mm_loadl_epi64(__m128i const *__p)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001858{
Eli Friedman9bb51ad2011-09-15 23:15:27 +00001859 struct __mm_loadl_epi64_struct {
David Blaikie3302f2b2013-01-16 23:08:36 +00001860 long long __u;
Eli Friedman9bb51ad2011-09-15 23:15:27 +00001861 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +00001862 return (__m128i) { ((struct __mm_loadl_epi64_struct*)__p)->__u, 0};
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001863}
1864
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001865/// \brief Generates a 128-bit vector of [4 x i32] with unspecified content.
1866/// This could be used as an argument to another intrinsic function where the
1867/// argument is required but the value is not actually used.
1868///
1869/// \headerfile <x86intrin.h>
1870///
1871/// This intrinsic has no corresponding instruction.
1872///
1873/// \returns A 128-bit vector of [4 x i32] with unspecified content.
Michael Kupersteine45af542015-06-30 13:36:19 +00001874static __inline__ __m128i __DEFAULT_FN_ATTRS
Simon Pilgrim5aba9922015-08-26 21:17:12 +00001875_mm_undefined_si128()
1876{
1877 return (__m128i)__builtin_ia32_undef128();
1878}
1879
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001880/// \brief Initializes both 64-bit values in a 128-bit vector of [2 x i64] with
1881/// the specified 64-bit integer values.
1882///
1883/// \headerfile <x86intrin.h>
1884///
1885/// This intrinsic is a utility function and does not correspond to a specific
1886/// instruction.
1887///
1888/// \param __q1
1889/// A 64-bit integer value used to initialize the upper 64 bits of the
1890/// destination vector of [2 x i64].
1891/// \param __q0
1892/// A 64-bit integer value used to initialize the lower 64 bits of the
1893/// destination vector of [2 x i64].
1894/// \returns An initialized 128-bit vector of [2 x i64] containing the values
1895/// provided in the operands.
Simon Pilgrim5aba9922015-08-26 21:17:12 +00001896static __inline__ __m128i __DEFAULT_FN_ATTRS
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00001897_mm_set_epi64x(long long __q1, long long __q0)
Anders Carlssondfa31172009-09-18 17:03:55 +00001898{
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00001899 return (__m128i){ __q0, __q1 };
Anders Carlssondfa31172009-09-18 17:03:55 +00001900}
1901
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001902/// \brief Initializes both 64-bit values in a 128-bit vector of [2 x i64] with
1903/// the specified 64-bit integer values.
1904///
1905/// \headerfile <x86intrin.h>
1906///
1907/// This intrinsic is a utility function and does not correspond to a specific
1908/// instruction.
1909///
1910/// \param __q1
1911/// A 64-bit integer value used to initialize the upper 64 bits of the
1912/// destination vector of [2 x i64].
1913/// \param __q0
1914/// A 64-bit integer value used to initialize the lower 64 bits of the
1915/// destination vector of [2 x i64].
1916/// \returns An initialized 128-bit vector of [2 x i64] containing the values
1917/// provided in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +00001918static __inline__ __m128i __DEFAULT_FN_ATTRS
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00001919_mm_set_epi64(__m64 __q1, __m64 __q0)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001920{
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00001921 return (__m128i){ (long long)__q0, (long long)__q1 };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001922}
1923
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001924/// \brief Initializes the 32-bit values in a 128-bit vector of [4 x i32] with
1925/// the specified 32-bit integer values.
1926///
1927/// \headerfile <x86intrin.h>
1928///
1929/// This intrinsic is a utility function and does not correspond to a specific
1930/// instruction.
1931///
1932/// \param __i3
1933/// A 32-bit integer value used to initialize bits [127:96] of the
1934/// destination vector.
1935/// \param __i2
1936/// A 32-bit integer value used to initialize bits [95:64] of the destination
1937/// vector.
1938/// \param __i1
1939/// A 32-bit integer value used to initialize bits [63:32] of the destination
1940/// vector.
1941/// \param __i0
1942/// A 32-bit integer value used to initialize bits [31:0] of the destination
1943/// vector.
1944/// \returns An initialized 128-bit vector of [4 x i32] containing the values
1945/// provided in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +00001946static __inline__ __m128i __DEFAULT_FN_ATTRS
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00001947_mm_set_epi32(int __i3, int __i2, int __i1, int __i0)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001948{
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00001949 return (__m128i)(__v4si){ __i0, __i1, __i2, __i3};
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001950}
1951
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001952/// \brief Initializes the 16-bit values in a 128-bit vector of [8 x i16] with
1953/// the specified 16-bit integer values.
1954///
1955/// \headerfile <x86intrin.h>
1956///
1957/// This intrinsic is a utility function and does not correspond to a specific
1958/// instruction.
1959///
1960/// \param __w7
1961/// A 16-bit integer value used to initialize bits [127:112] of the
1962/// destination vector.
1963/// \param __w6
1964/// A 16-bit integer value used to initialize bits [111:96] of the
1965/// destination vector.
1966/// \param __w5
1967/// A 16-bit integer value used to initialize bits [95:80] of the destination
1968/// vector.
1969/// \param __w4
1970/// A 16-bit integer value used to initialize bits [79:64] of the destination
1971/// vector.
1972/// \param __w3
1973/// A 16-bit integer value used to initialize bits [63:48] of the destination
1974/// vector.
1975/// \param __w2
1976/// A 16-bit integer value used to initialize bits [47:32] of the destination
1977/// vector.
1978/// \param __w1
1979/// A 16-bit integer value used to initialize bits [31:16] of the destination
1980/// vector.
1981/// \param __w0
1982/// A 16-bit integer value used to initialize bits [15:0] of the destination
1983/// vector.
1984/// \returns An initialized 128-bit vector of [8 x i16] containing the values
1985/// provided in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +00001986static __inline__ __m128i __DEFAULT_FN_ATTRS
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00001987_mm_set_epi16(short __w7, short __w6, short __w5, short __w4, short __w3, short __w2, short __w1, short __w0)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001988{
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00001989 return (__m128i)(__v8hi){ __w0, __w1, __w2, __w3, __w4, __w5, __w6, __w7 };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00001990}
1991
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00001992/// \brief Initializes the 8-bit values in a 128-bit vector of [16 x i8] with
1993/// the specified 8-bit integer values.
1994///
1995/// \headerfile <x86intrin.h>
1996///
1997/// This intrinsic is a utility function and does not correspond to a specific
1998/// instruction.
1999///
2000/// \param __b15
2001/// Initializes bits [127:120] of the destination vector.
2002/// \param __b14
2003/// Initializes bits [119:112] of the destination vector.
2004/// \param __b13
2005/// Initializes bits [111:104] of the destination vector.
2006/// \param __b12
2007/// Initializes bits [103:96] of the destination vector.
2008/// \param __b11
2009/// Initializes bits [95:88] of the destination vector.
2010/// \param __b10
2011/// Initializes bits [87:80] of the destination vector.
2012/// \param __b9
2013/// Initializes bits [79:72] of the destination vector.
2014/// \param __b8
2015/// Initializes bits [71:64] of the destination vector.
2016/// \param __b7
2017/// Initializes bits [63:56] of the destination vector.
2018/// \param __b6
2019/// Initializes bits [55:48] of the destination vector.
2020/// \param __b5
2021/// Initializes bits [47:40] of the destination vector.
2022/// \param __b4
2023/// Initializes bits [39:32] of the destination vector.
2024/// \param __b3
2025/// Initializes bits [31:24] of the destination vector.
2026/// \param __b2
2027/// Initializes bits [23:16] of the destination vector.
2028/// \param __b1
2029/// Initializes bits [15:8] of the destination vector.
2030/// \param __b0
2031/// Initializes bits [7:0] of the destination vector.
2032/// \returns An initialized 128-bit vector of [16 x i8] containing the values
2033/// provided in the operands.
Michael Kupersteine45af542015-06-30 13:36:19 +00002034static __inline__ __m128i __DEFAULT_FN_ATTRS
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00002035_mm_set_epi8(char __b15, char __b14, char __b13, char __b12, char __b11, char __b10, char __b9, char __b8, char __b7, char __b6, char __b5, char __b4, char __b3, char __b2, char __b1, char __b0)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002036{
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00002037 return (__m128i)(__v16qi){ __b0, __b1, __b2, __b3, __b4, __b5, __b6, __b7, __b8, __b9, __b10, __b11, __b12, __b13, __b14, __b15 };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002038}
2039
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00002040/// \brief Initializes both values in a 128-bit integer vector with the
2041/// specified 64-bit integer value.
2042///
2043/// \headerfile <x86intrin.h>
2044///
2045/// This intrinsic is a utility function and does not correspond to a specific
2046/// instruction.
2047///
2048/// \param __q
2049/// Integer value used to initialize the elements of the destination integer
2050/// vector.
2051/// \returns An initialized 128-bit integer vector of [2 x i64] with both
2052/// elements containing the value provided in the operand.
Michael Kupersteine45af542015-06-30 13:36:19 +00002053static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002054_mm_set1_epi64x(long long __q)
Anders Carlssondfa31172009-09-18 17:03:55 +00002055{
David Blaikie3302f2b2013-01-16 23:08:36 +00002056 return (__m128i){ __q, __q };
Anders Carlssondfa31172009-09-18 17:03:55 +00002057}
2058
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00002059/// \brief Initializes both values in a 128-bit vector of [2 x i64] with the
2060/// specified 64-bit value.
2061///
2062/// \headerfile <x86intrin.h>
2063///
2064/// This intrinsic is a utility function and does not correspond to a specific
2065/// instruction.
2066///
2067/// \param __q
2068/// A 64-bit value used to initialize the elements of the destination integer
2069/// vector.
2070/// \returns An initialized 128-bit vector of [2 x i64] with all elements
2071/// containing the value provided in the operand.
Michael Kupersteine45af542015-06-30 13:36:19 +00002072static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002073_mm_set1_epi64(__m64 __q)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002074{
David Blaikie3302f2b2013-01-16 23:08:36 +00002075 return (__m128i){ (long long)__q, (long long)__q };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002076}
2077
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00002078/// \brief Initializes all values in a 128-bit vector of [4 x i32] with the
2079/// specified 32-bit value.
2080///
2081/// \headerfile <x86intrin.h>
2082///
2083/// This intrinsic is a utility function and does not correspond to a specific
2084/// instruction.
2085///
2086/// \param __i
2087/// A 32-bit value used to initialize the elements of the destination integer
2088/// vector.
2089/// \returns An initialized 128-bit vector of [4 x i32] with all elements
2090/// containing the value provided in the operand.
Michael Kupersteine45af542015-06-30 13:36:19 +00002091static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002092_mm_set1_epi32(int __i)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002093{
David Blaikie3302f2b2013-01-16 23:08:36 +00002094 return (__m128i)(__v4si){ __i, __i, __i, __i };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002095}
2096
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00002097/// \brief Initializes all values in a 128-bit vector of [8 x i16] with the
2098/// specified 16-bit value.
2099///
2100/// \headerfile <x86intrin.h>
2101///
2102/// This intrinsic is a utility function and does not correspond to a specific
2103/// instruction.
2104///
2105/// \param __w
2106/// A 16-bit value used to initialize the elements of the destination integer
2107/// vector.
2108/// \returns An initialized 128-bit vector of [8 x i16] with all elements
2109/// containing the value provided in the operand.
Michael Kupersteine45af542015-06-30 13:36:19 +00002110static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002111_mm_set1_epi16(short __w)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002112{
David Blaikie3302f2b2013-01-16 23:08:36 +00002113 return (__m128i)(__v8hi){ __w, __w, __w, __w, __w, __w, __w, __w };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002114}
2115
Ekaterina Romanovaf2ed6202016-04-08 20:45:48 +00002116/// \brief Initializes all values in a 128-bit vector of [16 x i8] with the
2117/// specified 8-bit value.
2118///
2119/// \headerfile <x86intrin.h>
2120///
2121/// This intrinsic is a utility function and does not correspond to a specific
2122/// instruction.
2123///
2124/// \param __b
2125/// An 8-bit value used to initialize the elements of the destination integer
2126/// vector.
2127/// \returns An initialized 128-bit vector of [16 x i8] with all elements
2128/// containing the value provided in the operand.
Michael Kupersteine45af542015-06-30 13:36:19 +00002129static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002130_mm_set1_epi8(char __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002131{
David Blaikie3302f2b2013-01-16 23:08:36 +00002132 return (__m128i)(__v16qi){ __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002133}
2134
Michael Kupersteine45af542015-06-30 13:36:19 +00002135static __inline__ __m128i __DEFAULT_FN_ATTRS
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00002136_mm_setr_epi64(__m64 __q0, __m64 __q1)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002137{
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00002138 return (__m128i){ (long long)__q0, (long long)__q1 };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002139}
2140
Michael Kupersteine45af542015-06-30 13:36:19 +00002141static __inline__ __m128i __DEFAULT_FN_ATTRS
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00002142_mm_setr_epi32(int __i0, int __i1, int __i2, int __i3)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002143{
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00002144 return (__m128i)(__v4si){ __i0, __i1, __i2, __i3};
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002145}
2146
Michael Kupersteine45af542015-06-30 13:36:19 +00002147static __inline__ __m128i __DEFAULT_FN_ATTRS
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00002148_mm_setr_epi16(short __w0, short __w1, short __w2, short __w3, short __w4, short __w5, short __w6, short __w7)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002149{
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00002150 return (__m128i)(__v8hi){ __w0, __w1, __w2, __w3, __w4, __w5, __w6, __w7 };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002151}
2152
Michael Kupersteine45af542015-06-30 13:36:19 +00002153static __inline__ __m128i __DEFAULT_FN_ATTRS
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00002154_mm_setr_epi8(char __b0, char __b1, char __b2, char __b3, char __b4, char __b5, char __b6, char __b7, char __b8, char __b9, char __b10, char __b11, char __b12, char __b13, char __b14, char __b15)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002155{
Michael Kuperstein5c2cb0e2015-09-21 11:45:27 +00002156 return (__m128i)(__v16qi){ __b0, __b1, __b2, __b3, __b4, __b5, __b6, __b7, __b8, __b9, __b10, __b11, __b12, __b13, __b14, __b15 };
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002157}
2158
Michael Kupersteine45af542015-06-30 13:36:19 +00002159static __inline__ __m128i __DEFAULT_FN_ATTRS
Mike Stump5b31ed32009-02-13 14:24:50 +00002160_mm_setzero_si128(void)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002161{
2162 return (__m128i){ 0LL, 0LL };
2163}
2164
Michael Kupersteine45af542015-06-30 13:36:19 +00002165static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002166_mm_store_si128(__m128i *__p, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002167{
David Blaikie3302f2b2013-01-16 23:08:36 +00002168 *__p = __b;
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002169}
2170
Michael Kupersteine45af542015-06-30 13:36:19 +00002171static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002172_mm_storeu_si128(__m128i *__p, __m128i __b)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002173{
David Blaikie3302f2b2013-01-16 23:08:36 +00002174 __builtin_ia32_storedqu((char *)__p, (__v16qi)__b);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002175}
2176
Michael Kupersteine45af542015-06-30 13:36:19 +00002177static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002178_mm_maskmoveu_si128(__m128i __d, __m128i __n, char *__p)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002179{
David Blaikie3302f2b2013-01-16 23:08:36 +00002180 __builtin_ia32_maskmovdqu((__v16qi)__d, (__v16qi)__n, __p);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002181}
2182
Michael Kupersteine45af542015-06-30 13:36:19 +00002183static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002184_mm_storel_epi64(__m128i *__p, __m128i __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002185{
Chad Rosier87622b82012-05-01 18:11:51 +00002186 struct __mm_storel_epi64_struct {
David Blaikie3302f2b2013-01-16 23:08:36 +00002187 long long __u;
Chad Rosier87622b82012-05-01 18:11:51 +00002188 } __attribute__((__packed__, __may_alias__));
David Blaikie3302f2b2013-01-16 23:08:36 +00002189 ((struct __mm_storel_epi64_struct*)__p)->__u = __a[0];
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002190}
2191
Michael Kupersteine45af542015-06-30 13:36:19 +00002192static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002193_mm_stream_pd(double *__p, __m128d __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002194{
Craig Topper1aa231e2016-05-16 06:38:42 +00002195 __builtin_ia32_movntpd(__p, (__v2df)__a);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002196}
2197
Michael Kupersteine45af542015-06-30 13:36:19 +00002198static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002199_mm_stream_si128(__m128i *__p, __m128i __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002200{
Craig Topper1aa231e2016-05-16 06:38:42 +00002201 __builtin_ia32_movntdq(__p, (__v2di)__a);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002202}
2203
Michael Kupersteine45af542015-06-30 13:36:19 +00002204static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002205_mm_stream_si32(int *__p, int __a)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002206{
David Blaikie3302f2b2013-01-16 23:08:36 +00002207 __builtin_ia32_movnti(__p, __a);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002208}
2209
Eli Friedmanf9d8c6c2013-09-23 23:38:39 +00002210#ifdef __x86_64__
Michael Kupersteine45af542015-06-30 13:36:19 +00002211static __inline__ void __DEFAULT_FN_ATTRS
Eli Friedmanf9d8c6c2013-09-23 23:38:39 +00002212_mm_stream_si64(long long *__p, long long __a)
2213{
2214 __builtin_ia32_movnti64(__p, __a);
2215}
2216#endif
2217
Michael Kupersteine45af542015-06-30 13:36:19 +00002218static __inline__ void __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002219_mm_clflush(void const *__p)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002220{
David Blaikie3302f2b2013-01-16 23:08:36 +00002221 __builtin_ia32_clflush(__p);
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002222}
2223
Michael Kupersteine45af542015-06-30 13:36:19 +00002224static __inline__ void __DEFAULT_FN_ATTRS
Mike Stump5b31ed32009-02-13 14:24:50 +00002225_mm_lfence(void)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002226{
2227 __builtin_ia32_lfence();
2228}
2229
Michael Kupersteine45af542015-06-30 13:36:19 +00002230static __inline__ void __DEFAULT_FN_ATTRS
Mike Stump5b31ed32009-02-13 14:24:50 +00002231_mm_mfence(void)
Anders Carlssona0d5ca22008-12-25 23:48:58 +00002232{
2233 __builtin_ia32_mfence();
2234}
2235
Michael Kupersteine45af542015-06-30 13:36:19 +00002236static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002237_mm_packs_epi16(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002238{
David Blaikie3302f2b2013-01-16 23:08:36 +00002239 return (__m128i)__builtin_ia32_packsswb128((__v8hi)__a, (__v8hi)__b);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002240}
2241
Michael Kupersteine45af542015-06-30 13:36:19 +00002242static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002243_mm_packs_epi32(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002244{
David Blaikie3302f2b2013-01-16 23:08:36 +00002245 return (__m128i)__builtin_ia32_packssdw128((__v4si)__a, (__v4si)__b);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002246}
2247
Michael Kupersteine45af542015-06-30 13:36:19 +00002248static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002249_mm_packus_epi16(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002250{
David Blaikie3302f2b2013-01-16 23:08:36 +00002251 return (__m128i)__builtin_ia32_packuswb128((__v8hi)__a, (__v8hi)__b);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002252}
2253
Michael Kupersteine45af542015-06-30 13:36:19 +00002254static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002255_mm_extract_epi16(__m128i __a, int __imm)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002256{
David Blaikie3302f2b2013-01-16 23:08:36 +00002257 __v8hi __b = (__v8hi)__a;
Manman Renbe38b9e2013-10-22 19:24:42 +00002258 return (unsigned short)__b[__imm & 7];
Anders Carlsson85eb1242008-12-26 00:45:50 +00002259}
2260
Michael Kupersteine45af542015-06-30 13:36:19 +00002261static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002262_mm_insert_epi16(__m128i __a, int __b, int __imm)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002263{
David Blaikie3302f2b2013-01-16 23:08:36 +00002264 __v8hi __c = (__v8hi)__a;
2265 __c[__imm & 7] = __b;
2266 return (__m128i)__c;
Anders Carlsson85eb1242008-12-26 00:45:50 +00002267}
2268
Michael Kupersteine45af542015-06-30 13:36:19 +00002269static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002270_mm_movemask_epi8(__m128i __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002271{
David Blaikie3302f2b2013-01-16 23:08:36 +00002272 return __builtin_ia32_pmovmskb128((__v16qi)__a);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002273}
2274
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00002275#define _mm_shuffle_epi32(a, imm) __extension__ ({ \
Craig Topper51e47412015-02-13 06:04:43 +00002276 (__m128i)__builtin_shufflevector((__v4si)(__m128i)(a), \
Craig Topperfd778ee2015-11-10 05:08:08 +00002277 (__v4si)_mm_setzero_si128(), \
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00002278 (imm) & 0x3, ((imm) & 0xc) >> 2, \
2279 ((imm) & 0x30) >> 4, ((imm) & 0xc0) >> 6); })
Chris Lattnerf03406f2011-04-25 20:42:40 +00002280
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00002281#define _mm_shufflelo_epi16(a, imm) __extension__ ({ \
Craig Topper51e47412015-02-13 06:04:43 +00002282 (__m128i)__builtin_shufflevector((__v8hi)(__m128i)(a), \
Craig Topperfd778ee2015-11-10 05:08:08 +00002283 (__v8hi)_mm_setzero_si128(), \
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00002284 (imm) & 0x3, ((imm) & 0xc) >> 2, \
2285 ((imm) & 0x30) >> 4, ((imm) & 0xc0) >> 6, \
2286 4, 5, 6, 7); })
Chris Lattnerf03406f2011-04-25 20:42:40 +00002287
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00002288#define _mm_shufflehi_epi16(a, imm) __extension__ ({ \
Craig Topper51e47412015-02-13 06:04:43 +00002289 (__m128i)__builtin_shufflevector((__v8hi)(__m128i)(a), \
Craig Topperfd778ee2015-11-10 05:08:08 +00002290 (__v8hi)_mm_setzero_si128(), \
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00002291 0, 1, 2, 3, \
2292 4 + (((imm) & 0x03) >> 0), \
2293 4 + (((imm) & 0x0c) >> 2), \
2294 4 + (((imm) & 0x30) >> 4), \
2295 4 + (((imm) & 0xc0) >> 6)); })
Anders Carlsson85eb1242008-12-26 00:45:50 +00002296
Michael Kupersteine45af542015-06-30 13:36:19 +00002297static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002298_mm_unpackhi_epi8(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002299{
David Blaikie3302f2b2013-01-16 23:08:36 +00002300 return (__m128i)__builtin_shufflevector((__v16qi)__a, (__v16qi)__b, 8, 16+8, 9, 16+9, 10, 16+10, 11, 16+11, 12, 16+12, 13, 16+13, 14, 16+14, 15, 16+15);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002301}
2302
Michael Kupersteine45af542015-06-30 13:36:19 +00002303static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002304_mm_unpackhi_epi16(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002305{
David Blaikie3302f2b2013-01-16 23:08:36 +00002306 return (__m128i)__builtin_shufflevector((__v8hi)__a, (__v8hi)__b, 4, 8+4, 5, 8+5, 6, 8+6, 7, 8+7);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002307}
2308
Michael Kupersteine45af542015-06-30 13:36:19 +00002309static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002310_mm_unpackhi_epi32(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002311{
David Blaikie3302f2b2013-01-16 23:08:36 +00002312 return (__m128i)__builtin_shufflevector((__v4si)__a, (__v4si)__b, 2, 4+2, 3, 4+3);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002313}
2314
Michael Kupersteine45af542015-06-30 13:36:19 +00002315static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002316_mm_unpackhi_epi64(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002317{
Craig Topper1aa231e2016-05-16 06:38:42 +00002318 return (__m128i)__builtin_shufflevector((__v2di)__a, (__v2di)__b, 1, 2+1);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002319}
2320
Michael Kupersteine45af542015-06-30 13:36:19 +00002321static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002322_mm_unpacklo_epi8(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002323{
David Blaikie3302f2b2013-01-16 23:08:36 +00002324 return (__m128i)__builtin_shufflevector((__v16qi)__a, (__v16qi)__b, 0, 16+0, 1, 16+1, 2, 16+2, 3, 16+3, 4, 16+4, 5, 16+5, 6, 16+6, 7, 16+7);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002325}
2326
Michael Kupersteine45af542015-06-30 13:36:19 +00002327static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002328_mm_unpacklo_epi16(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002329{
David Blaikie3302f2b2013-01-16 23:08:36 +00002330 return (__m128i)__builtin_shufflevector((__v8hi)__a, (__v8hi)__b, 0, 8+0, 1, 8+1, 2, 8+2, 3, 8+3);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002331}
2332
Michael Kupersteine45af542015-06-30 13:36:19 +00002333static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002334_mm_unpacklo_epi32(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002335{
David Blaikie3302f2b2013-01-16 23:08:36 +00002336 return (__m128i)__builtin_shufflevector((__v4si)__a, (__v4si)__b, 0, 4+0, 1, 4+1);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002337}
2338
Michael Kupersteine45af542015-06-30 13:36:19 +00002339static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002340_mm_unpacklo_epi64(__m128i __a, __m128i __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002341{
Craig Topper1aa231e2016-05-16 06:38:42 +00002342 return (__m128i)__builtin_shufflevector((__v2di)__a, (__v2di)__b, 0, 2+0);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002343}
2344
Michael Kupersteine45af542015-06-30 13:36:19 +00002345static __inline__ __m64 __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002346_mm_movepi64_pi64(__m128i __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002347{
David Blaikie3302f2b2013-01-16 23:08:36 +00002348 return (__m64)__a[0];
Anders Carlsson85eb1242008-12-26 00:45:50 +00002349}
2350
Michael Kupersteine45af542015-06-30 13:36:19 +00002351static __inline__ __m128i __DEFAULT_FN_ATTRS
Alp Tokerd480b1b2013-11-23 22:11:57 +00002352_mm_movpi64_epi64(__m64 __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002353{
David Blaikie3302f2b2013-01-16 23:08:36 +00002354 return (__m128i){ (long long)__a, 0 };
Anders Carlsson85eb1242008-12-26 00:45:50 +00002355}
2356
Michael Kupersteine45af542015-06-30 13:36:19 +00002357static __inline__ __m128i __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002358_mm_move_epi64(__m128i __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002359{
Craig Topper1aa231e2016-05-16 06:38:42 +00002360 return __builtin_shufflevector((__v2di)__a, (__m128i){ 0 }, 0, 2);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002361}
2362
Michael Kupersteine45af542015-06-30 13:36:19 +00002363static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002364_mm_unpackhi_pd(__m128d __a, __m128d __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002365{
Craig Topper1aa231e2016-05-16 06:38:42 +00002366 return __builtin_shufflevector((__v2df)__a, (__v2df)__b, 1, 2+1);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002367}
2368
Michael Kupersteine45af542015-06-30 13:36:19 +00002369static __inline__ __m128d __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002370_mm_unpacklo_pd(__m128d __a, __m128d __b)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002371{
Craig Topper1aa231e2016-05-16 06:38:42 +00002372 return __builtin_shufflevector((__v2df)__a, (__v2df)__b, 0, 2+0);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002373}
2374
Michael Kupersteine45af542015-06-30 13:36:19 +00002375static __inline__ int __DEFAULT_FN_ATTRS
David Blaikie3302f2b2013-01-16 23:08:36 +00002376_mm_movemask_pd(__m128d __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002377{
Craig Topper1aa231e2016-05-16 06:38:42 +00002378 return __builtin_ia32_movmskpd((__v2df)__a);
Anders Carlsson85eb1242008-12-26 00:45:50 +00002379}
2380
Bob Wilsonc9b97cc2011-11-05 06:08:06 +00002381#define _mm_shuffle_pd(a, b, i) __extension__ ({ \
Craig Topperd619eaaa2015-11-11 03:47:10 +00002382 (__m128d)__builtin_shufflevector((__v2df)(__m128d)(a), (__v2df)(__m128d)(b), \
2383 (i) & 1, (((i) & 2) >> 1) + 2); })
Anders Carlsson85eb1242008-12-26 00:45:50 +00002384
Michael Kupersteine45af542015-06-30 13:36:19 +00002385static __inline__ __m128 __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002386_mm_castpd_ps(__m128d __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002387{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002388 return (__m128)__a;
Anders Carlsson85eb1242008-12-26 00:45:50 +00002389}
2390
Michael Kupersteine45af542015-06-30 13:36:19 +00002391static __inline__ __m128i __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002392_mm_castpd_si128(__m128d __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002393{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002394 return (__m128i)__a;
Anders Carlsson85eb1242008-12-26 00:45:50 +00002395}
2396
Michael Kupersteine45af542015-06-30 13:36:19 +00002397static __inline__ __m128d __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002398_mm_castps_pd(__m128 __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002399{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002400 return (__m128d)__a;
Anders Carlsson85eb1242008-12-26 00:45:50 +00002401}
2402
Michael Kupersteine45af542015-06-30 13:36:19 +00002403static __inline__ __m128i __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002404_mm_castps_si128(__m128 __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002405{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002406 return (__m128i)__a;
Anders Carlsson85eb1242008-12-26 00:45:50 +00002407}
2408
Michael Kupersteine45af542015-06-30 13:36:19 +00002409static __inline__ __m128 __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002410_mm_castsi128_ps(__m128i __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002411{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002412 return (__m128)__a;
Anders Carlsson85eb1242008-12-26 00:45:50 +00002413}
2414
Michael Kupersteine45af542015-06-30 13:36:19 +00002415static __inline__ __m128d __DEFAULT_FN_ATTRS
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002416_mm_castsi128_pd(__m128i __a)
Anders Carlsson85eb1242008-12-26 00:45:50 +00002417{
Reid Kleckner7ab75b32013-04-19 17:00:14 +00002418 return (__m128d)__a;
Anders Carlsson85eb1242008-12-26 00:45:50 +00002419}
2420
Michael Kupersteine45af542015-06-30 13:36:19 +00002421static __inline__ void __DEFAULT_FN_ATTRS
Mike Stump5b31ed32009-02-13 14:24:50 +00002422_mm_pause(void)
Anders Carlsson37c23712008-12-26 00:49:43 +00002423{
Craig Topperfb79b5f2015-11-11 08:13:33 +00002424 __builtin_ia32_pause();
Anders Carlsson37c23712008-12-26 00:49:43 +00002425}
2426
Michael Kupersteine45af542015-06-30 13:36:19 +00002427#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +00002428
Anders Carlsson43c2bab2009-01-21 01:49:39 +00002429#define _MM_SHUFFLE2(x, y) (((x) << 1) | (y))
Anders Carlsson37c23712008-12-26 00:49:43 +00002430
Anders Carlssonf15e71d2008-12-24 01:45:22 +00002431#endif /* __EMMINTRIN_H */