smmintrin.h revision 263508
1302080Shselasky/*===---- smmintrin.h - SSE4 intrinsics ------------------------------------===
2302080Shselasky *
3349669Shselasky * Permission is hereby granted, free of charge, to any person obtaining a copy
4302080Shselasky * of this software and associated documentation files (the "Software"), to deal
5302080Shselasky * in the Software without restriction, including without limitation the rights
6302080Shselasky * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7302080Shselasky * copies of the Software, and to permit persons to whom the Software is
8302080Shselasky * furnished to do so, subject to the following conditions:
9302080Shselasky *
10302080Shselasky * The above copyright notice and this permission notice shall be included in
11302080Shselasky * all copies or substantial portions of the Software.
12302080Shselasky *
13302080Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14302080Shselasky * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15302080Shselasky * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16302080Shselasky * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17302080Shselasky * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18302080Shselasky * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19302080Shselasky * THE SOFTWARE.
20302080Shselasky *
21302080Shselasky *===-----------------------------------------------------------------------===
22302080Shselasky */
23302080Shselasky
24302080Shselasky#ifndef _SMMINTRIN_H
25302080Shselasky#define _SMMINTRIN_H
26302080Shselasky
27302080Shselasky#ifndef __SSE4_1__
28302080Shselasky#error "SSE4.1 instruction set not enabled"
29302080Shselasky#else
30302080Shselasky
31302080Shselasky#include <tmmintrin.h>
32302080Shselasky
33302080Shselasky/* SSE4 Rounding macros. */
34302080Shselasky#define _MM_FROUND_TO_NEAREST_INT    0x00
35302080Shselasky#define _MM_FROUND_TO_NEG_INF        0x01
36302080Shselasky#define _MM_FROUND_TO_POS_INF        0x02
37302080Shselasky#define _MM_FROUND_TO_ZERO           0x03
38302080Shselasky#define _MM_FROUND_CUR_DIRECTION     0x04
39302080Shselasky
40302080Shselasky#define _MM_FROUND_RAISE_EXC         0x00
41302080Shselasky#define _MM_FROUND_NO_EXC            0x08
42302080Shselasky
43302080Shselasky#define _MM_FROUND_NINT      (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEAREST_INT)
44302080Shselasky#define _MM_FROUND_FLOOR     (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEG_INF)
45302080Shselasky#define _MM_FROUND_CEIL      (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_POS_INF)
46302080Shselasky#define _MM_FROUND_TRUNC     (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_ZERO)
47302080Shselasky#define _MM_FROUND_RINT      (_MM_FROUND_RAISE_EXC | _MM_FROUND_CUR_DIRECTION)
48302080Shselasky#define _MM_FROUND_NEARBYINT (_MM_FROUND_NO_EXC | _MM_FROUND_CUR_DIRECTION)
49302080Shselasky
50302080Shselasky#define _mm_ceil_ps(X)       _mm_round_ps((X), _MM_FROUND_CEIL)
51302080Shselasky#define _mm_ceil_pd(X)       _mm_round_pd((X), _MM_FROUND_CEIL)
52302080Shselasky#define _mm_ceil_ss(X, Y)    _mm_round_ss((X), (Y), _MM_FROUND_CEIL)
53302080Shselasky#define _mm_ceil_sd(X, Y)    _mm_round_sd((X), (Y), _MM_FROUND_CEIL)
54302080Shselasky
55302080Shselasky#define _mm_floor_ps(X)      _mm_round_ps((X), _MM_FROUND_FLOOR)
56302080Shselasky#define _mm_floor_pd(X)      _mm_round_pd((X), _MM_FROUND_FLOOR)
57302080Shselasky#define _mm_floor_ss(X, Y)   _mm_round_ss((X), (Y), _MM_FROUND_FLOOR)
58302080Shselasky#define _mm_floor_sd(X, Y)   _mm_round_sd((X), (Y), _MM_FROUND_FLOOR)
59302080Shselasky
60302080Shselasky#define _mm_round_ps(X, M) __extension__ ({ \
61302080Shselasky  __m128 __X = (X); \
62302080Shselasky  (__m128) __builtin_ia32_roundps((__v4sf)__X, (M)); })
63302080Shselasky
64302080Shselasky#define _mm_round_ss(X, Y, M) __extension__ ({ \
65302080Shselasky  __m128 __X = (X); \
66302080Shselasky  __m128 __Y = (Y); \
67302080Shselasky  (__m128) __builtin_ia32_roundss((__v4sf)__X, (__v4sf)__Y, (M)); })
68302080Shselasky
69302080Shselasky#define _mm_round_pd(X, M) __extension__ ({ \
70302080Shselasky  __m128d __X = (X); \
71302080Shselasky  (__m128d) __builtin_ia32_roundpd((__v2df)__X, (M)); })
72302080Shselasky
73302080Shselasky#define _mm_round_sd(X, Y, M) __extension__ ({ \
74302080Shselasky  __m128d __X = (X); \
75302080Shselasky  __m128d __Y = (Y); \
76302080Shselasky  (__m128d) __builtin_ia32_roundsd((__v2df)__X, (__v2df)__Y, (M)); })
77302080Shselasky
78302080Shselasky/* SSE4 Packed Blending Intrinsics.  */
79302080Shselasky#define _mm_blend_pd(V1, V2, M) __extension__ ({ \
80302080Shselasky  __m128d __V1 = (V1); \
81302080Shselasky  __m128d __V2 = (V2); \
82302080Shselasky  (__m128d) __builtin_ia32_blendpd ((__v2df)__V1, (__v2df)__V2, (M)); })
83302080Shselasky
84302080Shselasky#define _mm_blend_ps(V1, V2, M) __extension__ ({ \
85302080Shselasky  __m128 __V1 = (V1); \
86302080Shselasky  __m128 __V2 = (V2); \
87302080Shselasky  (__m128) __builtin_ia32_blendps ((__v4sf)__V1, (__v4sf)__V2, (M)); })
88349669Shselasky
89349669Shselaskystatic __inline__ __m128d __attribute__((__always_inline__, __nodebug__))
90349669Shselasky_mm_blendv_pd (__m128d __V1, __m128d __V2, __m128d __M)
91349669Shselasky{
92349669Shselasky  return (__m128d) __builtin_ia32_blendvpd ((__v2df)__V1, (__v2df)__V2,
93349669Shselasky                                            (__v2df)__M);
94349669Shselasky}
95349669Shselasky
96349669Shselaskystatic __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
97349669Shselasky_mm_blendv_ps (__m128 __V1, __m128 __V2, __m128 __M)
98349669Shselasky{
99349669Shselasky  return (__m128) __builtin_ia32_blendvps ((__v4sf)__V1, (__v4sf)__V2,
100349669Shselasky                                           (__v4sf)__M);
101349669Shselasky}
102349669Shselasky
103349669Shselaskystatic __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
104349669Shselasky_mm_blendv_epi8 (__m128i __V1, __m128i __V2, __m128i __M)
105349669Shselasky{
106302080Shselasky  return (__m128i) __builtin_ia32_pblendvb128 ((__v16qi)__V1, (__v16qi)__V2,
107302080Shselasky                                               (__v16qi)__M);
108302080Shselasky}
109349669Shselasky
110302080Shselasky#define _mm_blend_epi16(V1, V2, M) __extension__ ({ \
111302080Shselasky  __m128i __V1 = (V1); \
112302080Shselasky  __m128i __V2 = (V2); \
113302080Shselasky  (__m128i) __builtin_ia32_pblendw128 ((__v8hi)__V1, (__v8hi)__V2, (M)); })
114302080Shselasky
115302080Shselasky/* SSE4 Dword Multiply Instructions.  */
116302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
117302080Shselasky_mm_mullo_epi32 (__m128i __V1, __m128i __V2)
118302080Shselasky{
119302080Shselasky  return (__m128i) ((__v4si)__V1 * (__v4si)__V2);
120302080Shselasky}
121302080Shselasky
122302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
123302080Shselasky_mm_mul_epi32 (__m128i __V1, __m128i __V2)
124302080Shselasky{
125302080Shselasky  return (__m128i) __builtin_ia32_pmuldq128 ((__v4si)__V1, (__v4si)__V2);
126357439Shselasky}
127357439Shselasky
128302080Shselasky/* SSE4 Floating Point Dot Product Instructions.  */
129357439Shselasky#define _mm_dp_ps(X, Y, M) __extension__ ({ \
130302080Shselasky  __m128 __X = (X); \
131302080Shselasky  __m128 __Y = (Y); \
132302080Shselasky  (__m128) __builtin_ia32_dpps((__v4sf)__X, (__v4sf)__Y, (M)); })
133302080Shselasky
134302080Shselasky#define _mm_dp_pd(X, Y, M) __extension__ ({\
135302080Shselasky  __m128d __X = (X); \
136302080Shselasky  __m128d __Y = (Y); \
137302080Shselasky  (__m128d) __builtin_ia32_dppd((__v2df)__X, (__v2df)__Y, (M)); })
138302080Shselasky
139302080Shselasky/* SSE4 Streaming Load Hint Instruction.  */
140302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
141302080Shselasky_mm_stream_load_si128 (__m128i *__V)
142302080Shselasky{
143302080Shselasky  return (__m128i) __builtin_ia32_movntdqa ((__v2di *) __V);
144302080Shselasky}
145302080Shselasky
146302080Shselasky/* SSE4 Packed Integer Min/Max Instructions.  */
147302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
148302080Shselasky_mm_min_epi8 (__m128i __V1, __m128i __V2)
149302080Shselasky{
150302080Shselasky  return (__m128i) __builtin_ia32_pminsb128 ((__v16qi) __V1, (__v16qi) __V2);
151302080Shselasky}
152302080Shselasky
153302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
154302080Shselasky_mm_max_epi8 (__m128i __V1, __m128i __V2)
155302080Shselasky{
156302080Shselasky  return (__m128i) __builtin_ia32_pmaxsb128 ((__v16qi) __V1, (__v16qi) __V2);
157302080Shselasky}
158302080Shselasky
159302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
160302080Shselasky_mm_min_epu16 (__m128i __V1, __m128i __V2)
161302080Shselasky{
162302080Shselasky  return (__m128i) __builtin_ia32_pminuw128 ((__v8hi) __V1, (__v8hi) __V2);
163302080Shselasky}
164302080Shselasky
165302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
166302080Shselasky_mm_max_epu16 (__m128i __V1, __m128i __V2)
167302080Shselasky{
168302080Shselasky  return (__m128i) __builtin_ia32_pmaxuw128 ((__v8hi) __V1, (__v8hi) __V2);
169302080Shselasky}
170302080Shselasky
171302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
172302080Shselasky_mm_min_epi32 (__m128i __V1, __m128i __V2)
173302080Shselasky{
174302080Shselasky  return (__m128i) __builtin_ia32_pminsd128 ((__v4si) __V1, (__v4si) __V2);
175302080Shselasky}
176302080Shselasky
177302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
178302080Shselasky_mm_max_epi32 (__m128i __V1, __m128i __V2)
179302080Shselasky{
180302080Shselasky  return (__m128i) __builtin_ia32_pmaxsd128 ((__v4si) __V1, (__v4si) __V2);
181302080Shselasky}
182302080Shselasky
183302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
184302080Shselasky_mm_min_epu32 (__m128i __V1, __m128i __V2)
185302080Shselasky{
186302080Shselasky  return (__m128i) __builtin_ia32_pminud128((__v4si) __V1, (__v4si) __V2);
187302080Shselasky}
188302080Shselasky
189302080Shselaskystatic __inline__  __m128i __attribute__((__always_inline__, __nodebug__))
190302080Shselasky_mm_max_epu32 (__m128i __V1, __m128i __V2)
191302080Shselasky{
192302080Shselasky  return (__m128i) __builtin_ia32_pmaxud128((__v4si) __V1, (__v4si) __V2);
193302080Shselasky}
194302080Shselasky
195302080Shselasky/* SSE4 Insertion and Extraction from XMM Register Instructions.  */
196302080Shselasky#define _mm_insert_ps(X, Y, N) __builtin_ia32_insertps128((X), (Y), (N))
197302080Shselasky#define _mm_extract_ps(X, N) (__extension__                      \
198302080Shselasky                              ({ union { int __i; float __f; } __t;  \
199302080Shselasky                                 __v4sf __a = (__v4sf)(X);       \
200302080Shselasky                                 __t.__f = __a[(N) & 3];                 \
201302080Shselasky                                 __t.__i;}))
202302080Shselasky
203302080Shselasky/* Miscellaneous insert and extract macros.  */
204302080Shselasky/* Extract a single-precision float from X at index N into D.  */
205349669Shselasky#define _MM_EXTRACT_FLOAT(D, X, N) (__extension__ ({ __v4sf __a = (__v4sf)(X); \
206349669Shselasky                                                    (D) = __a[N]; }))
207302080Shselasky
208302080Shselasky/* Or together 2 sets of indexes (X and Y) with the zeroing bits (Z) to create
209302080Shselasky   an index suitable for _mm_insert_ps.  */
210302080Shselasky#define _MM_MK_INSERTPS_NDX(X, Y, Z) (((X) << 6) | ((Y) << 4) | (Z))
211302080Shselasky
212302080Shselasky/* Extract a float from X at index N into the first index of the return.  */
213302080Shselasky#define _MM_PICK_OUT_PS(X, N) _mm_insert_ps (_mm_setzero_ps(), (X),   \
214302080Shselasky                                             _MM_MK_INSERTPS_NDX((N), 0, 0x0e))
215302080Shselasky
216302080Shselasky/* Insert int into packed integer array at index.  */
217302080Shselasky#define _mm_insert_epi8(X, I, N) (__extension__ ({ __v16qi __a = (__v16qi)(X); \
218302080Shselasky                                                   __a[(N) & 15] = (I);             \
219302080Shselasky                                                   __a;}))
220302080Shselasky#define _mm_insert_epi32(X, I, N) (__extension__ ({ __v4si __a = (__v4si)(X); \
221302080Shselasky                                                    __a[(N) & 3] = (I);           \
222302080Shselasky                                                    __a;}))
223302080Shselasky#ifdef __x86_64__
224302080Shselasky#define _mm_insert_epi64(X, I, N) (__extension__ ({ __v2di __a = (__v2di)(X); \
225302080Shselasky                                                    __a[(N) & 1] = (I);           \
226302080Shselasky                                                    __a;}))
227302080Shselasky#endif /* __x86_64__ */
228302080Shselasky
229302080Shselasky/* Extract int from packed integer array at index.  This returns the element
230302080Shselasky * as a zero extended value, so it is unsigned.
231302080Shselasky */
232302080Shselasky#define _mm_extract_epi8(X, N) (__extension__ ({ __v16qi __a = (__v16qi)(X); \
233302080Shselasky                                                 (int)(unsigned char) \
234302080Shselasky                                                     __a[(N) & 15];}))
235302080Shselasky#define _mm_extract_epi32(X, N) (__extension__ ({ __v4si __a = (__v4si)(X); \
236302080Shselasky                                                  __a[(N) & 3];}))
237302080Shselasky#ifdef __x86_64__
238302080Shselasky#define _mm_extract_epi64(X, N) (__extension__ ({ __v2di __a = (__v2di)(X); \
239302080Shselasky                                                  __a[(N) & 1];}))
240302080Shselasky#endif /* __x86_64 */
241302080Shselasky
242302080Shselasky/* SSE4 128-bit Packed Integer Comparisons.  */
243302080Shselaskystatic __inline__ int __attribute__((__always_inline__, __nodebug__))
244302080Shselasky_mm_testz_si128(__m128i __M, __m128i __V)
245302080Shselasky{
246302080Shselasky  return __builtin_ia32_ptestz128((__v2di)__M, (__v2di)__V);
247302080Shselasky}
248302080Shselasky
249302080Shselaskystatic __inline__ int __attribute__((__always_inline__, __nodebug__))
250302080Shselasky_mm_testc_si128(__m128i __M, __m128i __V)
251{
252  return __builtin_ia32_ptestc128((__v2di)__M, (__v2di)__V);
253}
254
255static __inline__ int __attribute__((__always_inline__, __nodebug__))
256_mm_testnzc_si128(__m128i __M, __m128i __V)
257{
258  return __builtin_ia32_ptestnzc128((__v2di)__M, (__v2di)__V);
259}
260
261#define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_cmpeq_epi32((V), (V)))
262#define _mm_test_mix_ones_zeros(M, V) _mm_testnzc_si128((M), (V))
263#define _mm_test_all_zeros(M, V) _mm_testz_si128 ((M), (V))
264
265/* SSE4 64-bit Packed Integer Comparisons.  */
266static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
267_mm_cmpeq_epi64(__m128i __V1, __m128i __V2)
268{
269  return (__m128i)((__v2di)__V1 == (__v2di)__V2);
270}
271
272/* SSE4 Packed Integer Sign-Extension.  */
273static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
274_mm_cvtepi8_epi16(__m128i __V)
275{
276  return (__m128i) __builtin_ia32_pmovsxbw128((__v16qi) __V);
277}
278
279static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
280_mm_cvtepi8_epi32(__m128i __V)
281{
282  return (__m128i) __builtin_ia32_pmovsxbd128((__v16qi) __V);
283}
284
285static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
286_mm_cvtepi8_epi64(__m128i __V)
287{
288  return (__m128i) __builtin_ia32_pmovsxbq128((__v16qi) __V);
289}
290
291static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
292_mm_cvtepi16_epi32(__m128i __V)
293{
294  return (__m128i) __builtin_ia32_pmovsxwd128((__v8hi) __V);
295}
296
297static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
298_mm_cvtepi16_epi64(__m128i __V)
299{
300  return (__m128i) __builtin_ia32_pmovsxwq128((__v8hi)__V);
301}
302
303static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
304_mm_cvtepi32_epi64(__m128i __V)
305{
306  return (__m128i) __builtin_ia32_pmovsxdq128((__v4si)__V);
307}
308
309/* SSE4 Packed Integer Zero-Extension.  */
310static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
311_mm_cvtepu8_epi16(__m128i __V)
312{
313  return (__m128i) __builtin_ia32_pmovzxbw128((__v16qi) __V);
314}
315
316static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
317_mm_cvtepu8_epi32(__m128i __V)
318{
319  return (__m128i) __builtin_ia32_pmovzxbd128((__v16qi)__V);
320}
321
322static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
323_mm_cvtepu8_epi64(__m128i __V)
324{
325  return (__m128i) __builtin_ia32_pmovzxbq128((__v16qi)__V);
326}
327
328static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
329_mm_cvtepu16_epi32(__m128i __V)
330{
331  return (__m128i) __builtin_ia32_pmovzxwd128((__v8hi)__V);
332}
333
334static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
335_mm_cvtepu16_epi64(__m128i __V)
336{
337  return (__m128i) __builtin_ia32_pmovzxwq128((__v8hi)__V);
338}
339
340static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
341_mm_cvtepu32_epi64(__m128i __V)
342{
343  return (__m128i) __builtin_ia32_pmovzxdq128((__v4si)__V);
344}
345
346/* SSE4 Pack with Unsigned Saturation.  */
347static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
348_mm_packus_epi32(__m128i __V1, __m128i __V2)
349{
350  return (__m128i) __builtin_ia32_packusdw128((__v4si)__V1, (__v4si)__V2);
351}
352
353/* SSE4 Multiple Packed Sums of Absolute Difference.  */
354#define _mm_mpsadbw_epu8(X, Y, M) __extension__ ({ \
355  __m128i __X = (X); \
356  __m128i __Y = (Y); \
357  (__m128i) __builtin_ia32_mpsadbw128((__v16qi)__X, (__v16qi)__Y, (M)); })
358
359static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
360_mm_minpos_epu16(__m128i __V)
361{
362  return (__m128i) __builtin_ia32_phminposuw128((__v8hi)__V);
363}
364
365/* These definitions are normally in nmmintrin.h, but gcc puts them in here
366   so we'll do the same.  */
367#ifdef __SSE4_2__
368
369/* These specify the type of data that we're comparing.  */
370#define _SIDD_UBYTE_OPS                 0x00
371#define _SIDD_UWORD_OPS                 0x01
372#define _SIDD_SBYTE_OPS                 0x02
373#define _SIDD_SWORD_OPS                 0x03
374
375/* These specify the type of comparison operation.  */
376#define _SIDD_CMP_EQUAL_ANY             0x00
377#define _SIDD_CMP_RANGES                0x04
378#define _SIDD_CMP_EQUAL_EACH            0x08
379#define _SIDD_CMP_EQUAL_ORDERED         0x0c
380
381/* These macros specify the polarity of the operation.  */
382#define _SIDD_POSITIVE_POLARITY         0x00
383#define _SIDD_NEGATIVE_POLARITY         0x10
384#define _SIDD_MASKED_POSITIVE_POLARITY  0x20
385#define _SIDD_MASKED_NEGATIVE_POLARITY  0x30
386
387/* These macros are used in _mm_cmpXstri() to specify the return.  */
388#define _SIDD_LEAST_SIGNIFICANT         0x00
389#define _SIDD_MOST_SIGNIFICANT          0x40
390
391/* These macros are used in _mm_cmpXstri() to specify the return.  */
392#define _SIDD_BIT_MASK                  0x00
393#define _SIDD_UNIT_MASK                 0x40
394
395/* SSE4.2 Packed Comparison Intrinsics.  */
396#define _mm_cmpistrm(A, B, M) __builtin_ia32_pcmpistrm128((A), (B), (M))
397#define _mm_cmpistri(A, B, M) __builtin_ia32_pcmpistri128((A), (B), (M))
398
399#define _mm_cmpestrm(A, LA, B, LB, M) \
400     __builtin_ia32_pcmpestrm128((A), (LA), (B), (LB), (M))
401#define _mm_cmpestri(A, LA, B, LB, M) \
402     __builtin_ia32_pcmpestri128((A), (LA), (B), (LB), (M))
403
404/* SSE4.2 Packed Comparison Intrinsics and EFlag Reading.  */
405#define _mm_cmpistra(A, B, M) \
406     __builtin_ia32_pcmpistria128((A), (B), (M))
407#define _mm_cmpistrc(A, B, M) \
408     __builtin_ia32_pcmpistric128((A), (B), (M))
409#define _mm_cmpistro(A, B, M) \
410     __builtin_ia32_pcmpistrio128((A), (B), (M))
411#define _mm_cmpistrs(A, B, M) \
412     __builtin_ia32_pcmpistris128((A), (B), (M))
413#define _mm_cmpistrz(A, B, M) \
414     __builtin_ia32_pcmpistriz128((A), (B), (M))
415
416#define _mm_cmpestra(A, LA, B, LB, M) \
417     __builtin_ia32_pcmpestria128((A), (LA), (B), (LB), (M))
418#define _mm_cmpestrc(A, LA, B, LB, M) \
419     __builtin_ia32_pcmpestric128((A), (LA), (B), (LB), (M))
420#define _mm_cmpestro(A, LA, B, LB, M) \
421     __builtin_ia32_pcmpestrio128((A), (LA), (B), (LB), (M))
422#define _mm_cmpestrs(A, LA, B, LB, M) \
423     __builtin_ia32_pcmpestris128((A), (LA), (B), (LB), (M))
424#define _mm_cmpestrz(A, LA, B, LB, M) \
425     __builtin_ia32_pcmpestriz128((A), (LA), (B), (LB), (M))
426
427/* SSE4.2 Compare Packed Data -- Greater Than.  */
428static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
429_mm_cmpgt_epi64(__m128i __V1, __m128i __V2)
430{
431  return (__m128i)((__v2di)__V1 > (__v2di)__V2);
432}
433
434/* SSE4.2 Accumulate CRC32.  */
435static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
436_mm_crc32_u8(unsigned int __C, unsigned char __D)
437{
438  return __builtin_ia32_crc32qi(__C, __D);
439}
440
441static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
442_mm_crc32_u16(unsigned int __C, unsigned short __D)
443{
444  return __builtin_ia32_crc32hi(__C, __D);
445}
446
447static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
448_mm_crc32_u32(unsigned int __C, unsigned int __D)
449{
450  return __builtin_ia32_crc32si(__C, __D);
451}
452
453#ifdef __x86_64__
454static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
455_mm_crc32_u64(unsigned long long __C, unsigned long long __D)
456{
457  return __builtin_ia32_crc32di(__C, __D);
458}
459#endif /* __x86_64__ */
460
461#ifdef __POPCNT__
462#include <popcntintrin.h>
463#endif
464
465#endif /* __SSE4_2__ */
466#endif /* __SSE4_1__ */
467
468#endif /* _SMMINTRIN_H */
469