Merge trunk version 193617 into gupc branch.
[official-gcc.git] / gcc / config / i386 / smmintrin.h
blob0095ff08c3020448478d200d42d09f588779ff21
1 /* Copyright (C) 2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
8 any later version.
10 GCC is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
24 /* Implemented from the specification included in the Intel C++ Compiler
25 User Guide and Reference, version 10.0. */
27 #ifndef _SMMINTRIN_H_INCLUDED
28 #define _SMMINTRIN_H_INCLUDED
30 #ifndef __SSE4_1__
31 # error "SSE4.1 instruction set not enabled"
32 #else
34 /* We need definitions from the SSSE3, SSE3, SSE2 and SSE header
35 files. */
36 #include <tmmintrin.h>
38 /* Rounding mode macros. */
39 #define _MM_FROUND_TO_NEAREST_INT 0x00
40 #define _MM_FROUND_TO_NEG_INF 0x01
41 #define _MM_FROUND_TO_POS_INF 0x02
42 #define _MM_FROUND_TO_ZERO 0x03
43 #define _MM_FROUND_CUR_DIRECTION 0x04
45 #define _MM_FROUND_RAISE_EXC 0x00
46 #define _MM_FROUND_NO_EXC 0x08
48 #define _MM_FROUND_NINT \
49 (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_RAISE_EXC)
50 #define _MM_FROUND_FLOOR \
51 (_MM_FROUND_TO_NEG_INF | _MM_FROUND_RAISE_EXC)
52 #define _MM_FROUND_CEIL \
53 (_MM_FROUND_TO_POS_INF | _MM_FROUND_RAISE_EXC)
54 #define _MM_FROUND_TRUNC \
55 (_MM_FROUND_TO_ZERO | _MM_FROUND_RAISE_EXC)
56 #define _MM_FROUND_RINT \
57 (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_RAISE_EXC)
58 #define _MM_FROUND_NEARBYINT \
59 (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_NO_EXC)
61 /* Test Instruction */
62 /* Packed integer 128-bit bitwise comparison. Return 1 if
63 (__V & __M) == 0. */
64 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
65 _mm_testz_si128 (__m128i __M, __m128i __V)
67 return __builtin_ia32_ptestz128 ((__v2di)__M, (__v2di)__V);
70 /* Packed integer 128-bit bitwise comparison. Return 1 if
71 (__V & ~__M) == 0. */
72 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
73 _mm_testc_si128 (__m128i __M, __m128i __V)
75 return __builtin_ia32_ptestc128 ((__v2di)__M, (__v2di)__V);
78 /* Packed integer 128-bit bitwise comparison. Return 1 if
79 (__V & __M) != 0 && (__V & ~__M) != 0. */
80 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
81 _mm_testnzc_si128 (__m128i __M, __m128i __V)
83 return __builtin_ia32_ptestnzc128 ((__v2di)__M, (__v2di)__V);
86 /* Macros for packed integer 128-bit comparison intrinsics. */
87 #define _mm_test_all_zeros(M, V) _mm_testz_si128 ((M), (V))
89 #define _mm_test_all_ones(V) \
90 _mm_testc_si128 ((V), _mm_cmpeq_epi32 ((V), (V)))
92 #define _mm_test_mix_ones_zeros(M, V) _mm_testnzc_si128 ((M), (V))
94 /* Packed/scalar double precision floating point rounding. */
96 #ifdef __OPTIMIZE__
97 extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
98 _mm_round_pd (__m128d __V, const int __M)
100 return (__m128d) __builtin_ia32_roundpd ((__v2df)__V, __M);
103 extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
104 _mm_round_sd(__m128d __D, __m128d __V, const int __M)
106 return (__m128d) __builtin_ia32_roundsd ((__v2df)__D,
107 (__v2df)__V,
108 __M);
110 #else
111 #define _mm_round_pd(V, M) \
112 ((__m128d) __builtin_ia32_roundpd ((__v2df)(__m128d)(V), (int)(M)))
114 #define _mm_round_sd(D, V, M) \
115 ((__m128d) __builtin_ia32_roundsd ((__v2df)(__m128d)(D), \
116 (__v2df)(__m128d)(V), (int)(M)))
117 #endif
119 /* Packed/scalar single precision floating point rounding. */
121 #ifdef __OPTIMIZE__
122 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
123 _mm_round_ps (__m128 __V, const int __M)
125 return (__m128) __builtin_ia32_roundps ((__v4sf)__V, __M);
128 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
129 _mm_round_ss (__m128 __D, __m128 __V, const int __M)
131 return (__m128) __builtin_ia32_roundss ((__v4sf)__D,
132 (__v4sf)__V,
133 __M);
135 #else
136 #define _mm_round_ps(V, M) \
137 ((__m128) __builtin_ia32_roundps ((__v4sf)(__m128)(V), (int)(M)))
139 #define _mm_round_ss(D, V, M) \
140 ((__m128) __builtin_ia32_roundss ((__v4sf)(__m128)(D), \
141 (__v4sf)(__m128)(V), (int)(M)))
142 #endif
144 /* Macros for ceil/floor intrinsics. */
145 #define _mm_ceil_pd(V) _mm_round_pd ((V), _MM_FROUND_CEIL)
146 #define _mm_ceil_sd(D, V) _mm_round_sd ((D), (V), _MM_FROUND_CEIL)
148 #define _mm_floor_pd(V) _mm_round_pd((V), _MM_FROUND_FLOOR)
149 #define _mm_floor_sd(D, V) _mm_round_sd ((D), (V), _MM_FROUND_FLOOR)
151 #define _mm_ceil_ps(V) _mm_round_ps ((V), _MM_FROUND_CEIL)
152 #define _mm_ceil_ss(D, V) _mm_round_ss ((D), (V), _MM_FROUND_CEIL)
154 #define _mm_floor_ps(V) _mm_round_ps ((V), _MM_FROUND_FLOOR)
155 #define _mm_floor_ss(D, V) _mm_round_ss ((D), (V), _MM_FROUND_FLOOR)
157 /* SSE4.1 */
159 /* Integer blend instructions - select data from 2 sources using
160 constant/variable mask. */
162 #ifdef __OPTIMIZE__
163 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
164 _mm_blend_epi16 (__m128i __X, __m128i __Y, const int __M)
166 return (__m128i) __builtin_ia32_pblendw128 ((__v8hi)__X,
167 (__v8hi)__Y,
168 __M);
170 #else
171 #define _mm_blend_epi16(X, Y, M) \
172 ((__m128i) __builtin_ia32_pblendw128 ((__v8hi)(__m128i)(X), \
173 (__v8hi)(__m128i)(Y), (int)(M)))
174 #endif
176 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
177 _mm_blendv_epi8 (__m128i __X, __m128i __Y, __m128i __M)
179 return (__m128i) __builtin_ia32_pblendvb128 ((__v16qi)__X,
180 (__v16qi)__Y,
181 (__v16qi)__M);
184 /* Single precision floating point blend instructions - select data
185 from 2 sources using constant/variable mask. */
187 #ifdef __OPTIMIZE__
188 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
189 _mm_blend_ps (__m128 __X, __m128 __Y, const int __M)
191 return (__m128) __builtin_ia32_blendps ((__v4sf)__X,
192 (__v4sf)__Y,
193 __M);
195 #else
196 #define _mm_blend_ps(X, Y, M) \
197 ((__m128) __builtin_ia32_blendps ((__v4sf)(__m128)(X), \
198 (__v4sf)(__m128)(Y), (int)(M)))
199 #endif
201 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
202 _mm_blendv_ps (__m128 __X, __m128 __Y, __m128 __M)
204 return (__m128) __builtin_ia32_blendvps ((__v4sf)__X,
205 (__v4sf)__Y,
206 (__v4sf)__M);
209 /* Double precision floating point blend instructions - select data
210 from 2 sources using constant/variable mask. */
212 #ifdef __OPTIMIZE__
213 extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
214 _mm_blend_pd (__m128d __X, __m128d __Y, const int __M)
216 return (__m128d) __builtin_ia32_blendpd ((__v2df)__X,
217 (__v2df)__Y,
218 __M);
220 #else
221 #define _mm_blend_pd(X, Y, M) \
222 ((__m128d) __builtin_ia32_blendpd ((__v2df)(__m128d)(X), \
223 (__v2df)(__m128d)(Y), (int)(M)))
224 #endif
226 extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
227 _mm_blendv_pd (__m128d __X, __m128d __Y, __m128d __M)
229 return (__m128d) __builtin_ia32_blendvpd ((__v2df)__X,
230 (__v2df)__Y,
231 (__v2df)__M);
234 /* Dot product instructions with mask-defined summing and zeroing parts
235 of result. */
237 #ifdef __OPTIMIZE__
238 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
239 _mm_dp_ps (__m128 __X, __m128 __Y, const int __M)
241 return (__m128) __builtin_ia32_dpps ((__v4sf)__X,
242 (__v4sf)__Y,
243 __M);
246 extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
247 _mm_dp_pd (__m128d __X, __m128d __Y, const int __M)
249 return (__m128d) __builtin_ia32_dppd ((__v2df)__X,
250 (__v2df)__Y,
251 __M);
253 #else
254 #define _mm_dp_ps(X, Y, M) \
255 ((__m128) __builtin_ia32_dpps ((__v4sf)(__m128)(X), \
256 (__v4sf)(__m128)(Y), (int)(M)))
258 #define _mm_dp_pd(X, Y, M) \
259 ((__m128d) __builtin_ia32_dppd ((__v2df)(__m128d)(X), \
260 (__v2df)(__m128d)(Y), (int)(M)))
261 #endif
263 /* Packed integer 64-bit comparison, zeroing or filling with ones
264 corresponding parts of result. */
265 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
266 _mm_cmpeq_epi64 (__m128i __X, __m128i __Y)
268 return (__m128i) __builtin_ia32_pcmpeqq ((__v2di)__X, (__v2di)__Y);
271 /* Min/max packed integer instructions. */
273 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
274 _mm_min_epi8 (__m128i __X, __m128i __Y)
276 return (__m128i) __builtin_ia32_pminsb128 ((__v16qi)__X, (__v16qi)__Y);
279 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
280 _mm_max_epi8 (__m128i __X, __m128i __Y)
282 return (__m128i) __builtin_ia32_pmaxsb128 ((__v16qi)__X, (__v16qi)__Y);
285 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
286 _mm_min_epu16 (__m128i __X, __m128i __Y)
288 return (__m128i) __builtin_ia32_pminuw128 ((__v8hi)__X, (__v8hi)__Y);
291 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
292 _mm_max_epu16 (__m128i __X, __m128i __Y)
294 return (__m128i) __builtin_ia32_pmaxuw128 ((__v8hi)__X, (__v8hi)__Y);
297 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
298 _mm_min_epi32 (__m128i __X, __m128i __Y)
300 return (__m128i) __builtin_ia32_pminsd128 ((__v4si)__X, (__v4si)__Y);
303 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
304 _mm_max_epi32 (__m128i __X, __m128i __Y)
306 return (__m128i) __builtin_ia32_pmaxsd128 ((__v4si)__X, (__v4si)__Y);
309 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
310 _mm_min_epu32 (__m128i __X, __m128i __Y)
312 return (__m128i) __builtin_ia32_pminud128 ((__v4si)__X, (__v4si)__Y);
315 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
316 _mm_max_epu32 (__m128i __X, __m128i __Y)
318 return (__m128i) __builtin_ia32_pmaxud128 ((__v4si)__X, (__v4si)__Y);
321 /* Packed integer 32-bit multiplication with truncation of upper
322 halves of results. */
323 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
324 _mm_mullo_epi32 (__m128i __X, __m128i __Y)
326 return (__m128i) __builtin_ia32_pmulld128 ((__v4si)__X, (__v4si)__Y);
329 /* Packed integer 32-bit multiplication of 2 pairs of operands
330 with two 64-bit results. */
331 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
332 _mm_mul_epi32 (__m128i __X, __m128i __Y)
334 return (__m128i) __builtin_ia32_pmuldq128 ((__v4si)__X, (__v4si)__Y);
337 /* Insert single precision float into packed single precision array
338 element selected by index N. The bits [7-6] of N define S
339 index, the bits [5-4] define D index, and bits [3-0] define
340 zeroing mask for D. */
342 #ifdef __OPTIMIZE__
343 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
344 _mm_insert_ps (__m128 __D, __m128 __S, const int __N)
346 return (__m128) __builtin_ia32_insertps128 ((__v4sf)__D,
347 (__v4sf)__S,
348 __N);
350 #else
351 #define _mm_insert_ps(D, S, N) \
352 ((__m128) __builtin_ia32_insertps128 ((__v4sf)(__m128)(D), \
353 (__v4sf)(__m128)(S), (int)(N)))
354 #endif
356 /* Helper macro to create the N value for _mm_insert_ps. */
357 #define _MM_MK_INSERTPS_NDX(S, D, M) (((S) << 6) | ((D) << 4) | (M))
359 /* Extract binary representation of single precision float from packed
360 single precision array element of X selected by index N. */
362 #ifdef __OPTIMIZE__
363 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
364 _mm_extract_ps (__m128 __X, const int __N)
366 union { int i; float f; } __tmp;
367 __tmp.f = __builtin_ia32_vec_ext_v4sf ((__v4sf)__X, __N);
368 return __tmp.i;
370 #else
371 #define _mm_extract_ps(X, N) \
372 (__extension__ \
373 ({ \
374 union { int i; float f; } __tmp; \
375 __tmp.f = __builtin_ia32_vec_ext_v4sf ((__v4sf)(__m128)(X), (int)(N)); \
376 __tmp.i; \
378 #endif
380 /* Extract binary representation of single precision float into
381 D from packed single precision array element of S selected
382 by index N. */
383 #define _MM_EXTRACT_FLOAT(D, S, N) \
384 { (D) = __builtin_ia32_vec_ext_v4sf ((__v4sf)(S), (N)); }
386 /* Extract specified single precision float element into the lower
387 part of __m128. */
388 #define _MM_PICK_OUT_PS(X, N) \
389 _mm_insert_ps (_mm_setzero_ps (), (X), \
390 _MM_MK_INSERTPS_NDX ((N), 0, 0x0e))
392 /* Insert integer, S, into packed integer array element of D
393 selected by index N. */
395 #ifdef __OPTIMIZE__
396 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
397 _mm_insert_epi8 (__m128i __D, int __S, const int __N)
399 return (__m128i) __builtin_ia32_vec_set_v16qi ((__v16qi)__D,
400 __S, __N);
403 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
404 _mm_insert_epi32 (__m128i __D, int __S, const int __N)
406 return (__m128i) __builtin_ia32_vec_set_v4si ((__v4si)__D,
407 __S, __N);
410 #ifdef __x86_64__
411 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
412 _mm_insert_epi64 (__m128i __D, long long __S, const int __N)
414 return (__m128i) __builtin_ia32_vec_set_v2di ((__v2di)__D,
415 __S, __N);
417 #endif
418 #else
419 #define _mm_insert_epi8(D, S, N) \
420 ((__m128i) __builtin_ia32_vec_set_v16qi ((__v16qi)(__m128i)(D), \
421 (int)(S), (int)(N)))
423 #define _mm_insert_epi32(D, S, N) \
424 ((__m128i) __builtin_ia32_vec_set_v4si ((__v4si)(__m128i)(D), \
425 (int)(S), (int)(N)))
427 #ifdef __x86_64__
428 #define _mm_insert_epi64(D, S, N) \
429 ((__m128i) __builtin_ia32_vec_set_v2di ((__v2di)(__m128i)(D), \
430 (long long)(S), (int)(N)))
431 #endif
432 #endif
434 /* Extract integer from packed integer array element of X selected by
435 index N. */
437 #ifdef __OPTIMIZE__
438 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
439 _mm_extract_epi8 (__m128i __X, const int __N)
441 return (unsigned char) __builtin_ia32_vec_ext_v16qi ((__v16qi)__X, __N);
444 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
445 _mm_extract_epi32 (__m128i __X, const int __N)
447 return __builtin_ia32_vec_ext_v4si ((__v4si)__X, __N);
450 #ifdef __x86_64__
451 extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
452 _mm_extract_epi64 (__m128i __X, const int __N)
454 return __builtin_ia32_vec_ext_v2di ((__v2di)__X, __N);
456 #endif
457 #else
458 #define _mm_extract_epi8(X, N) \
459 ((int) (unsigned char) __builtin_ia32_vec_ext_v16qi ((__v16qi)(__m128i)(X), (int)(N)))
460 #define _mm_extract_epi32(X, N) \
461 ((int) __builtin_ia32_vec_ext_v4si ((__v4si)(__m128i)(X), (int)(N)))
463 #ifdef __x86_64__
464 #define _mm_extract_epi64(X, N) \
465 ((long long) __builtin_ia32_vec_ext_v2di ((__v2di)(__m128i)(X), (int)(N)))
466 #endif
467 #endif
469 /* Return horizontal packed word minimum and its index in bits [15:0]
470 and bits [18:16] respectively. */
471 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
472 _mm_minpos_epu16 (__m128i __X)
474 return (__m128i) __builtin_ia32_phminposuw128 ((__v8hi)__X);
477 /* Packed integer sign-extension. */
479 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
480 _mm_cvtepi8_epi32 (__m128i __X)
482 return (__m128i) __builtin_ia32_pmovsxbd128 ((__v16qi)__X);
485 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
486 _mm_cvtepi16_epi32 (__m128i __X)
488 return (__m128i) __builtin_ia32_pmovsxwd128 ((__v8hi)__X);
491 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
492 _mm_cvtepi8_epi64 (__m128i __X)
494 return (__m128i) __builtin_ia32_pmovsxbq128 ((__v16qi)__X);
497 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
498 _mm_cvtepi32_epi64 (__m128i __X)
500 return (__m128i) __builtin_ia32_pmovsxdq128 ((__v4si)__X);
503 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
504 _mm_cvtepi16_epi64 (__m128i __X)
506 return (__m128i) __builtin_ia32_pmovsxwq128 ((__v8hi)__X);
509 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
510 _mm_cvtepi8_epi16 (__m128i __X)
512 return (__m128i) __builtin_ia32_pmovsxbw128 ((__v16qi)__X);
515 /* Packed integer zero-extension. */
517 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
518 _mm_cvtepu8_epi32 (__m128i __X)
520 return (__m128i) __builtin_ia32_pmovzxbd128 ((__v16qi)__X);
523 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
524 _mm_cvtepu16_epi32 (__m128i __X)
526 return (__m128i) __builtin_ia32_pmovzxwd128 ((__v8hi)__X);
529 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
530 _mm_cvtepu8_epi64 (__m128i __X)
532 return (__m128i) __builtin_ia32_pmovzxbq128 ((__v16qi)__X);
535 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
536 _mm_cvtepu32_epi64 (__m128i __X)
538 return (__m128i) __builtin_ia32_pmovzxdq128 ((__v4si)__X);
541 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
542 _mm_cvtepu16_epi64 (__m128i __X)
544 return (__m128i) __builtin_ia32_pmovzxwq128 ((__v8hi)__X);
547 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
548 _mm_cvtepu8_epi16 (__m128i __X)
550 return (__m128i) __builtin_ia32_pmovzxbw128 ((__v16qi)__X);
553 /* Pack 8 double words from 2 operands into 8 words of result with
554 unsigned saturation. */
555 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
556 _mm_packus_epi32 (__m128i __X, __m128i __Y)
558 return (__m128i) __builtin_ia32_packusdw128 ((__v4si)__X, (__v4si)__Y);
561 /* Sum absolute 8-bit integer difference of adjacent groups of 4
562 byte integers in the first 2 operands. Starting offsets within
563 operands are determined by the 3rd mask operand. */
565 #ifdef __OPTIMIZE__
566 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
567 _mm_mpsadbw_epu8 (__m128i __X, __m128i __Y, const int __M)
569 return (__m128i) __builtin_ia32_mpsadbw128 ((__v16qi)__X,
570 (__v16qi)__Y, __M);
572 #else
573 #define _mm_mpsadbw_epu8(X, Y, M) \
574 ((__m128i) __builtin_ia32_mpsadbw128 ((__v16qi)(__m128i)(X), \
575 (__v16qi)(__m128i)(Y), (int)(M)))
576 #endif
578 /* Load double quadword using non-temporal aligned hint. */
579 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
580 _mm_stream_load_si128 (__m128i *__X)
582 return (__m128i) __builtin_ia32_movntdqa ((__v2di *) __X);
585 #ifdef __SSE4_2__
587 /* These macros specify the source data format. */
588 #define _SIDD_UBYTE_OPS 0x00
589 #define _SIDD_UWORD_OPS 0x01
590 #define _SIDD_SBYTE_OPS 0x02
591 #define _SIDD_SWORD_OPS 0x03
593 /* These macros specify the comparison operation. */
594 #define _SIDD_CMP_EQUAL_ANY 0x00
595 #define _SIDD_CMP_RANGES 0x04
596 #define _SIDD_CMP_EQUAL_EACH 0x08
597 #define _SIDD_CMP_EQUAL_ORDERED 0x0c
599 /* These macros specify the polarity. */
600 #define _SIDD_POSITIVE_POLARITY 0x00
601 #define _SIDD_NEGATIVE_POLARITY 0x10
602 #define _SIDD_MASKED_POSITIVE_POLARITY 0x20
603 #define _SIDD_MASKED_NEGATIVE_POLARITY 0x30
605 /* These macros specify the output selection in _mm_cmpXstri (). */
606 #define _SIDD_LEAST_SIGNIFICANT 0x00
607 #define _SIDD_MOST_SIGNIFICANT 0x40
609 /* These macros specify the output selection in _mm_cmpXstrm (). */
610 #define _SIDD_BIT_MASK 0x00
611 #define _SIDD_UNIT_MASK 0x40
613 /* Intrinsics for text/string processing. */
615 #ifdef __OPTIMIZE__
616 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
617 _mm_cmpistrm (__m128i __X, __m128i __Y, const int __M)
619 return (__m128i) __builtin_ia32_pcmpistrm128 ((__v16qi)__X,
620 (__v16qi)__Y,
621 __M);
624 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
625 _mm_cmpistri (__m128i __X, __m128i __Y, const int __M)
627 return __builtin_ia32_pcmpistri128 ((__v16qi)__X,
628 (__v16qi)__Y,
629 __M);
632 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
633 _mm_cmpestrm (__m128i __X, int __LX, __m128i __Y, int __LY, const int __M)
635 return (__m128i) __builtin_ia32_pcmpestrm128 ((__v16qi)__X, __LX,
636 (__v16qi)__Y, __LY,
637 __M);
640 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
641 _mm_cmpestri (__m128i __X, int __LX, __m128i __Y, int __LY, const int __M)
643 return __builtin_ia32_pcmpestri128 ((__v16qi)__X, __LX,
644 (__v16qi)__Y, __LY,
645 __M);
647 #else
648 #define _mm_cmpistrm(X, Y, M) \
649 ((__m128i) __builtin_ia32_pcmpistrm128 ((__v16qi)(__m128i)(X), \
650 (__v16qi)(__m128i)(Y), (int)(M)))
651 #define _mm_cmpistri(X, Y, M) \
652 ((int) __builtin_ia32_pcmpistri128 ((__v16qi)(__m128i)(X), \
653 (__v16qi)(__m128i)(Y), (int)(M)))
655 #define _mm_cmpestrm(X, LX, Y, LY, M) \
656 ((__m128i) __builtin_ia32_pcmpestrm128 ((__v16qi)(__m128i)(X), \
657 (int)(LX), (__v16qi)(__m128i)(Y), \
658 (int)(LY), (int)(M)))
659 #define _mm_cmpestri(X, LX, Y, LY, M) \
660 ((int) __builtin_ia32_pcmpestri128 ((__v16qi)(__m128i)(X), (int)(LX), \
661 (__v16qi)(__m128i)(Y), (int)(LY), \
662 (int)(M)))
663 #endif
665 /* Intrinsics for text/string processing and reading values of
666 EFlags. */
668 #ifdef __OPTIMIZE__
669 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
670 _mm_cmpistra (__m128i __X, __m128i __Y, const int __M)
672 return __builtin_ia32_pcmpistria128 ((__v16qi)__X,
673 (__v16qi)__Y,
674 __M);
677 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
678 _mm_cmpistrc (__m128i __X, __m128i __Y, const int __M)
680 return __builtin_ia32_pcmpistric128 ((__v16qi)__X,
681 (__v16qi)__Y,
682 __M);
685 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
686 _mm_cmpistro (__m128i __X, __m128i __Y, const int __M)
688 return __builtin_ia32_pcmpistrio128 ((__v16qi)__X,
689 (__v16qi)__Y,
690 __M);
693 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
694 _mm_cmpistrs (__m128i __X, __m128i __Y, const int __M)
696 return __builtin_ia32_pcmpistris128 ((__v16qi)__X,
697 (__v16qi)__Y,
698 __M);
701 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
702 _mm_cmpistrz (__m128i __X, __m128i __Y, const int __M)
704 return __builtin_ia32_pcmpistriz128 ((__v16qi)__X,
705 (__v16qi)__Y,
706 __M);
709 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
710 _mm_cmpestra (__m128i __X, int __LX, __m128i __Y, int __LY, const int __M)
712 return __builtin_ia32_pcmpestria128 ((__v16qi)__X, __LX,
713 (__v16qi)__Y, __LY,
714 __M);
717 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
718 _mm_cmpestrc (__m128i __X, int __LX, __m128i __Y, int __LY, const int __M)
720 return __builtin_ia32_pcmpestric128 ((__v16qi)__X, __LX,
721 (__v16qi)__Y, __LY,
722 __M);
725 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
726 _mm_cmpestro (__m128i __X, int __LX, __m128i __Y, int __LY, const int __M)
728 return __builtin_ia32_pcmpestrio128 ((__v16qi)__X, __LX,
729 (__v16qi)__Y, __LY,
730 __M);
733 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
734 _mm_cmpestrs (__m128i __X, int __LX, __m128i __Y, int __LY, const int __M)
736 return __builtin_ia32_pcmpestris128 ((__v16qi)__X, __LX,
737 (__v16qi)__Y, __LY,
738 __M);
741 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
742 _mm_cmpestrz (__m128i __X, int __LX, __m128i __Y, int __LY, const int __M)
744 return __builtin_ia32_pcmpestriz128 ((__v16qi)__X, __LX,
745 (__v16qi)__Y, __LY,
746 __M);
748 #else
749 #define _mm_cmpistra(X, Y, M) \
750 ((int) __builtin_ia32_pcmpistria128 ((__v16qi)(__m128i)(X), \
751 (__v16qi)(__m128i)(Y), (int)(M)))
752 #define _mm_cmpistrc(X, Y, M) \
753 ((int) __builtin_ia32_pcmpistric128 ((__v16qi)(__m128i)(X), \
754 (__v16qi)(__m128i)(Y), (int)(M)))
755 #define _mm_cmpistro(X, Y, M) \
756 ((int) __builtin_ia32_pcmpistrio128 ((__v16qi)(__m128i)(X), \
757 (__v16qi)(__m128i)(Y), (int)(M)))
758 #define _mm_cmpistrs(X, Y, M) \
759 ((int) __builtin_ia32_pcmpistris128 ((__v16qi)(__m128i)(X), \
760 (__v16qi)(__m128i)(Y), (int)(M)))
761 #define _mm_cmpistrz(X, Y, M) \
762 ((int) __builtin_ia32_pcmpistriz128 ((__v16qi)(__m128i)(X), \
763 (__v16qi)(__m128i)(Y), (int)(M)))
765 #define _mm_cmpestra(X, LX, Y, LY, M) \
766 ((int) __builtin_ia32_pcmpestria128 ((__v16qi)(__m128i)(X), (int)(LX), \
767 (__v16qi)(__m128i)(Y), (int)(LY), \
768 (int)(M)))
769 #define _mm_cmpestrc(X, LX, Y, LY, M) \
770 ((int) __builtin_ia32_pcmpestric128 ((__v16qi)(__m128i)(X), (int)(LX), \
771 (__v16qi)(__m128i)(Y), (int)(LY), \
772 (int)(M)))
773 #define _mm_cmpestro(X, LX, Y, LY, M) \
774 ((int) __builtin_ia32_pcmpestrio128 ((__v16qi)(__m128i)(X), (int)(LX), \
775 (__v16qi)(__m128i)(Y), (int)(LY), \
776 (int)(M)))
777 #define _mm_cmpestrs(X, LX, Y, LY, M) \
778 ((int) __builtin_ia32_pcmpestris128 ((__v16qi)(__m128i)(X), (int)(LX), \
779 (__v16qi)(__m128i)(Y), (int)(LY), \
780 (int)(M)))
781 #define _mm_cmpestrz(X, LX, Y, LY, M) \
782 ((int) __builtin_ia32_pcmpestriz128 ((__v16qi)(__m128i)(X), (int)(LX), \
783 (__v16qi)(__m128i)(Y), (int)(LY), \
784 (int)(M)))
785 #endif
787 /* Packed integer 64-bit comparison, zeroing or filling with ones
788 corresponding parts of result. */
789 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
790 _mm_cmpgt_epi64 (__m128i __X, __m128i __Y)
792 return (__m128i) __builtin_ia32_pcmpgtq ((__v2di)__X, (__v2di)__Y);
795 #ifdef __POPCNT__
796 #include <popcntintrin.h>
797 #endif
799 /* Accumulate CRC32 (polynomial 0x11EDC6F41) value. */
800 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
801 _mm_crc32_u8 (unsigned int __C, unsigned char __V)
803 return __builtin_ia32_crc32qi (__C, __V);
806 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
807 _mm_crc32_u16 (unsigned int __C, unsigned short __V)
809 return __builtin_ia32_crc32hi (__C, __V);
812 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
813 _mm_crc32_u32 (unsigned int __C, unsigned int __V)
815 return __builtin_ia32_crc32si (__C, __V);
818 #ifdef __x86_64__
819 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
820 _mm_crc32_u64 (unsigned long long __C, unsigned long long __V)
822 return __builtin_ia32_crc32di (__C, __V);
824 #endif
826 #endif /* __SSE4_2__ */
828 #endif /* __SSE4_1__ */
830 #endif /* _SMMINTRIN_H_INCLUDED */