blob: e271f9953cd9ea6a48d8f1704f3d8e1466edf9a7 [file] [log] [blame]
Anders Carlsson1a37d0a2010-03-24 05:31:31 +00001/*===---- smmintrin.h - SSE4 intrinsics ------------------------------------===
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 *
21 *===-----------------------------------------------------------------------===
22 */
Eric Christopherb71f9562010-03-04 02:56:19 +000023
24#ifndef _SMMINTRIN_H
25#define _SMMINTRIN_H
26
27#ifndef __SSE4_1__
28#error "SSE4.1 instruction set not enabled"
29#else
30
31#include <tmmintrin.h>
32
33/* Type defines. */
34typedef double __v2df __attribute__ ((__vector_size__ (16)));
Eric Christopher03568482010-03-07 06:29:09 +000035typedef long long __v2di __attribute__ ((__vector_size__ (16)));
Eric Christopherb71f9562010-03-04 02:56:19 +000036
37/* SSE4 Rounding macros. */
38#define _MM_FROUND_TO_NEAREST_INT 0x00
39#define _MM_FROUND_TO_NEG_INF 0x01
40#define _MM_FROUND_TO_POS_INF 0x02
41#define _MM_FROUND_TO_ZERO 0x03
42#define _MM_FROUND_CUR_DIRECTION 0x04
43
44#define _MM_FROUND_RAISE_EXC 0x00
45#define _MM_FROUND_NO_EXC 0x08
46
47#define _MM_FROUND_NINT (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEAREST_INT)
48#define _MM_FROUND_FLOOR (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEG_INF)
49#define _MM_FROUND_CEIL (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_POS_INF)
50#define _MM_FROUND_TRUNC (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_ZERO)
51#define _MM_FROUND_RINT (_MM_FROUND_RAISE_EXC | _MM_FROUND_CUR_DIRECTION)
Eric Christopher9ce21162010-03-06 10:31:44 +000052#define _MM_FROUND_NEARBYINT (_MM_FROUND_NO_EXC | _MM_FROUND_CUR_DIRECTION)
Eric Christopherb71f9562010-03-04 02:56:19 +000053
54#define _mm_ceil_ps(X) _mm_round_ps((X), _MM_FROUND_CEIL)
55#define _mm_ceil_pd(X) _mm_round_pd((X), _MM_FROUND_CEIL)
56#define _mm_ceil_ss(X, Y) _mm_round_ss((X), (Y), _MM_FROUND_CEIL)
57#define _mm_ceil_sd(X, Y) _mm_round_sd((X), (Y), _MM_FROUND_CEIL)
58
59#define _mm_floor_ps(X) _mm_round_ps((X), _MM_FROUND_FLOOR)
60#define _mm_floor_pd(X) _mm_round_pd((X), _MM_FROUND_FLOOR)
61#define _mm_floor_ss(X, Y) _mm_round_ss((X), (Y), _MM_FROUND_FLOOR)
62#define _mm_floor_sd(X, Y) _mm_round_sd((X), (Y), _MM_FROUND_FLOOR)
63
Eric Christopher9ce21162010-03-06 10:31:44 +000064#define _mm_round_ps(X, Y) __builtin_ia32_roundps((X), (Y))
65#define _mm_round_ss(X, Y, M) __builtin_ia32_roundss((X), (Y), (M))
66#define _mm_round_pd(X, M) __builtin_ia32_roundpd((X), (M))
67#define _mm_round_sd(X, Y, M) __builtin_ia32_roundsd((X), (Y), (M))
Eric Christopherb71f9562010-03-04 02:56:19 +000068
69/* SSE4 Packed Blending Intrinsics. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +000070static __inline__ __m128d __attribute__((__always_inline__, __nodebug__))
Eric Christopherb71f9562010-03-04 02:56:19 +000071_mm_blend_pd (__m128d __V1, __m128d __V2, const int __M)
72{
73 return (__m128d) __builtin_ia32_blendpd ((__v2df)__V1, (__v2df)__V2, __M);
74}
75
Chris Lattner1bddbcb2010-03-22 18:14:12 +000076static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Eric Christopherb71f9562010-03-04 02:56:19 +000077_mm_blend_ps (__m128 __V1, __m128 __V2, const int __M)
78{
79 return (__m128) __builtin_ia32_blendps ((__v4sf)__V1, (__v4sf)__V2, __M);
80}
81
Chris Lattner1bddbcb2010-03-22 18:14:12 +000082static __inline__ __m128d __attribute__((__always_inline__, __nodebug__))
Eric Christopherb71f9562010-03-04 02:56:19 +000083_mm_blendv_pd (__m128d __V1, __m128d __V2, __m128d __M)
84{
85 return (__m128d) __builtin_ia32_blendvpd ((__v2df)__V1, (__v2df)__V2,
86 (__v2df)__M);
87}
88
Chris Lattner1bddbcb2010-03-22 18:14:12 +000089static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Eric Christopherb71f9562010-03-04 02:56:19 +000090_mm_blendv_ps (__m128 __V1, __m128 __V2, __m128 __M)
91{
92 return (__m128) __builtin_ia32_blendvps ((__v4sf)__V1, (__v4sf)__V2,
93 (__v4sf)__M);
94}
95
Chris Lattner1bddbcb2010-03-22 18:14:12 +000096static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopherb71f9562010-03-04 02:56:19 +000097_mm_blendv_epi8 (__m128i __V1, __m128i __V2, __m128i __M)
98{
99 return (__m128i) __builtin_ia32_pblendvb128 ((__v16qi)__V1, (__v16qi)__V2,
100 (__v16qi)__M);
101}
102
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000103static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopherb71f9562010-03-04 02:56:19 +0000104_mm_blend_epi16 (__m128i __V1, __m128i __V2, const int __M)
105{
106 return (__m128i) __builtin_ia32_pblendw128 ((__v8hi)__V1, (__v8hi)__V2, __M);
107}
108
Eric Christopherc82ac952010-03-07 06:17:19 +0000109/* SSE4 Dword Multiply Instructions. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000110static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopherc82ac952010-03-07 06:17:19 +0000111_mm_mullo_epi32 (__m128i __V1, __m128i __V2)
112{
Eric Christopher054c2762010-03-26 00:51:28 +0000113 return (__m128i) ((__v4si)__V1 * (__v4si)__V2);
Eric Christopherc82ac952010-03-07 06:17:19 +0000114}
115
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000116static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopherc82ac952010-03-07 06:17:19 +0000117_mm_mul_epi32 (__m128i __V1, __m128i __V2)
118{
119 return (__m128i) __builtin_ia32_pmuldq128 ((__v4si)__V1, (__v4si)__V2);
120}
121
122/* SSE4 Floating Point Dot Product Instructions. */
123#define _mm_dp_ps(X, Y, M) __builtin_ia32_dpps ((X), (Y), (M))
124#define _mm_dp_pd(X, Y, M) __builtin_ia32_dppd ((X), (Y), (M))
125
Eric Christopher03568482010-03-07 06:29:09 +0000126/* SSE4 Streaming Load Hint Instruction. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000127static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher03568482010-03-07 06:29:09 +0000128_mm_stream_load_si128 (__m128i *__V)
129{
130 return (__m128i) __builtin_ia32_movntdqa ((__v2di *) __V);
131}
132
Eric Christopher3afda602010-03-07 07:00:42 +0000133/* SSE4 Packed Integer Min/Max Instructions. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000134static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher3afda602010-03-07 07:00:42 +0000135_mm_min_epi8 (__m128i __V1, __m128i __V2)
136{
137 return (__m128i) __builtin_ia32_pminsb128 ((__v16qi) __V1, (__v16qi) __V2);
138}
139
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000140static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher3afda602010-03-07 07:00:42 +0000141_mm_max_epi8 (__m128i __V1, __m128i __V2)
142{
143 return (__m128i) __builtin_ia32_pmaxsb128 ((__v16qi) __V1, (__v16qi) __V2);
144}
145
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000146static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher3afda602010-03-07 07:00:42 +0000147_mm_min_epu16 (__m128i __V1, __m128i __V2)
148{
149 return (__m128i) __builtin_ia32_pminuw128 ((__v8hi) __V1, (__v8hi) __V2);
150}
151
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000152static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher3afda602010-03-07 07:00:42 +0000153_mm_max_epu16 (__m128i __V1, __m128i __V2)
154{
155 return (__m128i) __builtin_ia32_pmaxuw128 ((__v8hi) __V1, (__v8hi) __V2);
156}
157
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000158static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher3afda602010-03-07 07:00:42 +0000159_mm_min_epi32 (__m128i __V1, __m128i __V2)
160{
161 return (__m128i) __builtin_ia32_pminsd128 ((__v4si) __V1, (__v4si) __V2);
162}
163
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000164static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher3afda602010-03-07 07:00:42 +0000165_mm_max_epi32 (__m128i __V1, __m128i __V2)
166{
167 return (__m128i) __builtin_ia32_pmaxsd128 ((__v4si) __V1, (__v4si) __V2);
168}
169
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000170static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher3afda602010-03-07 07:00:42 +0000171_mm_min_epu32 (__m128i __V1, __m128i __V2)
172{
173 return (__m128i) __builtin_ia32_pminud128((__v4si) __V1, (__v4si) __V2);
174}
175
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000176static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher3afda602010-03-07 07:00:42 +0000177_mm_max_epu32 (__m128i __V1, __m128i __V2)
178{
179 return (__m128i) __builtin_ia32_pmaxud128((__v4si) __V1, (__v4si) __V2);
180}
181
Eric Christopher9a2a69f2010-03-10 00:50:58 +0000182/* SSE4 Insertion and Extraction from XMM Register Instructions. */
183#define _mm_insert_ps(X, Y, N) __builtin_ia32_insertps128((X), (Y), (N))
184#define _mm_extract_ps(X, N) (__extension__ \
185 ({ union { int i; float f; } __t; \
186 __v4sf __a = (__v4sf)X; \
187 __t.f = __a[N]; \
188 __t.i;}))
189
190/* Miscellaneous insert and extract macros. */
191/* Extract a single-precision float from X at index N into D. */
192#define _MM_EXTRACT_FLOAT(D, X, N) (__extension__ ({ __v4sf __a = (__v4sf)X; \
193 (D) = __a[N]; }))
194
195/* Or together 2 sets of indexes (X and Y) with the zeroing bits (Z) to create
196 an index suitable for _mm_insert_ps. */
197#define _MM_MK_INSERTPS_NDX(X, Y, Z) (((X) << 6) | ((Y) << 4) | (Z))
198
199/* Extract a float from X at index N into the first index of the return. */
200#define _MM_PICK_OUT_PS(X, N) _mm_insert_ps (_mm_setzero_ps(), (X), \
201 _MM_MK_INSERTPS_NDX((N), 0, 0x0e))
Eric Christopher6fa43e32010-03-11 23:36:29 +0000202
203/* Insert int into packed integer array at index. */
204#define _mm_insert_epi8(X, I, N) (__extension__ ({ __v16qi __a = (__v16qi)X; \
205 __a[N] = I; \
206 __a;}))
207#define _mm_insert_epi32(X, I, N) (__extension__ ({ __v4si __a = (__v4si)X; \
208 __a[N] = I; \
209 __a;}))
210#ifdef __x86_64__
211#define _mm_insert_epi64(X, I, N) (__extension__ ({ __v2di __a = (__v2di)X; \
212 __a[N] = I; \
213 __a;}))
214#endif /* __x86_64__ */
Eric Christopher9a2a69f2010-03-10 00:50:58 +0000215
Eric Christopherff8aeaa2010-03-11 23:50:18 +0000216/* Extract int from packed integer array at index. */
217#define _mm_extract_epi8(X, N) (__extension__ ({ __v16qi __a = (__v16qi)X; \
218 __a[N];}))
219#define _mm_extract_epi32(X, N) (__extension__ ({ __v4si __a = (__v4si)X; \
220 __a[N];}))
221#ifdef __x86_64__
222#define _mm_extract_epi64(X, N) (__extension__ ({ __v2di __a = (__v2di)X; \
223 __a[N];}))
224#endif /* __x86_64 */
225
Eric Christopher0c2b4f42010-03-12 01:22:33 +0000226/* SSE4 128-bit Packed Integer Comparisons. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000227static __inline__ int __attribute__((__always_inline__, __nodebug__))
Eric Christopher0c2b4f42010-03-12 01:22:33 +0000228_mm_testz_si128(__m128i __M, __m128i __V)
229{
230 return __builtin_ia32_ptestz128((__v2di)__M, (__v2di)__V);
231}
232
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000233static __inline__ int __attribute__((__always_inline__, __nodebug__))
Eric Christopher0c2b4f42010-03-12 01:22:33 +0000234_mm_testc_si128(__m128i __M, __m128i __V)
235{
236 return __builtin_ia32_ptestc128((__v2di)__M, (__v2di)__V);
237}
238
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000239static __inline__ int __attribute__((__always_inline__, __nodebug__))
Eric Christopher0c2b4f42010-03-12 01:22:33 +0000240_mm_testnzc_si128(__m128i __M, __m128i __V)
241{
242 return __builtin_ia32_ptestnzc128((__v2di)__M, (__v2di)__V);
243}
244
245#define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_cmpeq_epi32((V), (V)))
246#define _mm_test_mix_ones_zeros(M, V) _mm_testnzc_si128((M), (V))
247#define _mm_test_all_zeros(M, V) _mm_testz_si128 ((V), (V))
248
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000249/* SSE4 64-bit Packed Integer Comparisons. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000250static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000251_mm_cmpeq_epi64(__m128i __V1, __m128i __V2)
252{
253 return (__m128i) __builtin_ia32_pcmpeqq((__v2di)__V1, (__v2di)__V2);
254}
255
256/* SSE4 Packed Integer Sign-Extension. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000257static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000258_mm_cvtepi8_epi16(__m128i __V)
259{
260 return (__m128i) __builtin_ia32_pmovsxbw128((__v16qi) __V);
261}
262
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000263static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000264_mm_cvtepi8_epi32(__m128i __V)
265{
266 return (__m128i) __builtin_ia32_pmovsxbd128((__v16qi) __V);
267}
268
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000269static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000270_mm_cvtepi8_epi64(__m128i __V)
271{
272 return (__m128i) __builtin_ia32_pmovsxbq128((__v16qi) __V);
273}
274
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000275static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000276_mm_cvtepi16_epi32(__m128i __V)
277{
278 return (__m128i) __builtin_ia32_pmovsxwd128((__v8hi) __V);
279}
280
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000281static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000282_mm_cvtepi16_epi64(__m128i __V)
283{
284 return (__m128i) __builtin_ia32_pmovsxwq128((__v8hi)__V);
285}
286
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000287static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000288_mm_cvtepi32_epi64(__m128i __V)
289{
290 return (__m128i) __builtin_ia32_pmovsxdq128((__v4si)__V);
291}
292
293/* SSE4 Packed Integer Zero-Extension. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000294static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000295_mm_cvtepu8_epi16(__m128i __V)
296{
297 return (__m128i) __builtin_ia32_pmovzxbw128((__v16qi) __V);
298}
299
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000300static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000301_mm_cvtepu8_epi32(__m128i __V)
302{
303 return (__m128i) __builtin_ia32_pmovzxbd128((__v16qi)__V);
304}
305
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000306static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000307_mm_cvtepu8_epi64(__m128i __V)
308{
309 return (__m128i) __builtin_ia32_pmovzxbq128((__v16qi)__V);
310}
311
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000312static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000313_mm_cvtepu16_epi32(__m128i __V)
314{
315 return (__m128i) __builtin_ia32_pmovzxwd128((__v8hi)__V);
316}
317
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000318static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000319_mm_cvtepu16_epi64(__m128i __V)
320{
321 return (__m128i) __builtin_ia32_pmovzxwq128((__v8hi)__V);
322}
323
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000324static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000325_mm_cvtepu32_epi64(__m128i __V)
326{
327 return (__m128i) __builtin_ia32_pmovzxdq128((__v4si)__V);
328}
329
330/* SSE4 Pack with Unsigned Saturation. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000331static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher7bd0dfd2010-03-15 23:22:58 +0000332_mm_packus_epi32(__m128i __V1, __m128i __V2)
333{
334 return (__m128i) __builtin_ia32_packusdw128((__v4si)__V1, (__v4si)__V2);
335}
336
337/* SSE4 Multiple Packed Sums of Absolute Difference. */
338#define _mm_mpsadbw_epu8(X, Y, M) __builtin_ia32_mpsadbw128((X), (Y), (M))
339
Eric Christopher67a59362010-03-20 07:43:28 +0000340/* These definitions are normally in nmmintrin.h, but gcc puts them in here
341 so we'll do the same. */
342#ifdef __SSE4_2__
343
344/* These specify the type of data that we're comparing. */
345#define _SIDD_UBYTE_OPS 0x00
346#define _SIDD_UWORD_OPS 0x01
347#define _SIDD_SBYTE_OPS 0x02
348#define _SIDD_SWORD_OPS 0x03
349
350/* These specify the type of comparison operation. */
351#define _SIDD_CMP_EQUAL_ANY 0x00
352#define _SIDD_CMP_RANGES 0x04
353#define _SIDD_CMP_EQUAL_EACH 0x08
354#define _SIDD_CMP_EQUAL_ORDERED 0x0c
355
356/* These macros specify the polarity of the operation. */
357#define _SIDD_POSITIVE_POLARITY 0x00
358#define _SIDD_NEGATIVE_POLARITY 0x10
359#define _SIDD_MASKED_POSITIVE_POLARITY 0x20
360#define _SIDD_MASKED_NEGATIVE_POLARITY 0x30
361
362/* These macros are used in _mm_cmpXstri() to specify the return. */
363#define _SIDD_LEAST_SIGNIFICANT 0x00
364#define _SIDD_MOST_SIGNIFICANT 0x40
365
366/* These macros are used in _mm_cmpXstri() to specify the return. */
367#define _SIDD_BIT_MASK 0x00
368#define _SIDD_UNIT_MASK 0x40
369
370/* SSE4.2 Packed Comparison Intrinsics. */
371#define _mm_cmpistrm(A, B, M) __builtin_ia32_pcmpistrm128((A), (B), (M))
372#define _mm_cmpistri(A, B, M) __builtin_ia32_pcmpistri128((A), (B), (M))
373
374#define _mm_cmpestrm(A, LA, B, LB, M) \
375 __builtin_ia32_pcmpestrm128((A), (LA), (B), (LB), (M))
376#define _mm_cmpestri(X, LX, Y, LY, M) \
377 __builtin_ia32_pcmpestri128((A), (LA), (B), (LB), (M))
378
379/* SSE4.2 Packed Comparison Intrinsics and EFlag Reading. */
380#define _mm_cmpistra(A, LA, B, LB, M) \
381 __builtin_ia32_pcmpistria128((A), (LA), (B), (LB), (M))
382#define _mm_cmpistrc(A, LA, B, LB, M) \
383 __builtin_ia32_pcmpistric128((A), (LA), (B), (LB), (M))
384#define _mm_cmpistro(A, LA, B, LB, M) \
385 __builtin_ia32_pcmpistrio128((A), (LA), (B), (LB), (M))
386#define _mm_cmpistrs(A, LA, B, LB, M) \
387 __builtin_ia32_pcmpistris128((A), (LA), (B), (LB), (M))
388#define _mm_cmpistrz(A, LA, B, LB, M) \
389 __builtin_ia32_pcmpistriz128((A), (LA), (B), (LB), (M))
390
391#define _mm_cmpestra(A, LA, B, LB, M) \
392 __builtin_ia32_pcmpestria128((A), (LA), (B), (LB), (M))
393#define _mm_cmpestrc(A, LA, B, LB, M) \
394 __builtin_ia32_pcmpestric128((A), (LA), (B), (LB), (M))
395#define _mm_cmpestro(A, LA, B, LB, M) \
396 __builtin_ia32_pcmpestrio128((A), (LA), (B), (LB), (M))
397#define _mm_cmpestrs(A, LA, B, LB, M) \
398 __builtin_ia32_pcmpestris128((A), (LA), (B), (LB), (M))
399#define _mm_cmpestrz(A, LA, B, LB, M) \
400 __builtin_ia32_pcmpestriz128((A), (LA), (B), (LB), (M))
401
402/* SSE4.2 Compare Packed Data -- Greater Than. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000403static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Eric Christopher67a59362010-03-20 07:43:28 +0000404_mm_cmpgt_epi64(__m128i __V1, __m128i __V2)
405{
406 return __builtin_ia32_pcmpgtq((__v2di)__V1, (__v2di)__V2);
407}
408
409/* SSE4.2 Accumulate CRC32. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000410static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
Eric Christopher67a59362010-03-20 07:43:28 +0000411_mm_crc32_u8(unsigned int __C, unsigned char __D)
412{
413 return __builtin_ia32_crc32qi(__C, __D);
414}
415
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000416static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
Eric Christopher67a59362010-03-20 07:43:28 +0000417_mm_crc32_u16(unsigned int __C, unsigned short __D)
418{
419 return __builtin_ia32_crc32hi(__C, __D);
420}
421
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000422static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
Eric Christopher67a59362010-03-20 07:43:28 +0000423_mm_crc32_u32(unsigned int __C, unsigned int __D)
424{
425 return __builtin_ia32_crc32si(__C, __D);
426}
427
428#ifdef __x86_64__
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000429static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
Eric Christopher67a59362010-03-20 07:43:28 +0000430_mm_crc32_u64(unsigned long long __C, unsigned long long __D)
431{
432 return __builtin_ia32_crc32di(__C, __D);
433}
434#endif /* __x86_64__ */
435
436/* SSE4.2 Population Count. */
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000437static __inline__ int __attribute__((__always_inline__, __nodebug__))
Eric Christopher67a59362010-03-20 07:43:28 +0000438_mm_popcnt_u32(unsigned int __A)
439{
440 return __builtin_popcount(__A);
441}
442
443#ifdef __x86_64__
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000444static __inline__ long long __attribute__((__always_inline__, __nodebug__))
Eric Christopher67a59362010-03-20 07:43:28 +0000445_mm_popcnt_u64(unsigned long long __A)
446{
447 return __builtin_popcountll(__A);
448}
449#endif /* __x86_64__ */
450
451#endif /* __SSE4_2__ */
Eric Christopherb71f9562010-03-04 02:56:19 +0000452#endif /* __SSE4_1__ */
453
454#endif /* _SMMINTRIN_H */