xref: /freebsd/contrib/llvm-project/clang/lib/Headers/smmintrin.h (revision 5036d9652a5701d00e9e40ea942c278e9f77d33d)
1 /*===---- smmintrin.h - SSE4 intrinsics ------------------------------------===
2  *
3  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4  * See https://llvm.org/LICENSE.txt for license information.
5  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6  *
7  *===-----------------------------------------------------------------------===
8  */
9 
10 #ifndef __SMMINTRIN_H
11 #define __SMMINTRIN_H
12 
13 #if !defined(__i386__) && !defined(__x86_64__)
14 #error "This header is only meant to be used on x86 and x64 architecture"
15 #endif
16 
17 #include <tmmintrin.h>
18 
19 /* Define the default attributes for the functions in this file. */
20 #define __DEFAULT_FN_ATTRS                                                     \
21   __attribute__((__always_inline__, __nodebug__,                               \
22                  __target__("sse4.1,no-evex512"), __min_vector_width__(128)))
23 
24 /* SSE4 Rounding macros. */
25 #define _MM_FROUND_TO_NEAREST_INT 0x00
26 #define _MM_FROUND_TO_NEG_INF 0x01
27 #define _MM_FROUND_TO_POS_INF 0x02
28 #define _MM_FROUND_TO_ZERO 0x03
29 #define _MM_FROUND_CUR_DIRECTION 0x04
30 
31 #define _MM_FROUND_RAISE_EXC 0x00
32 #define _MM_FROUND_NO_EXC 0x08
33 
34 #define _MM_FROUND_NINT (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEAREST_INT)
35 #define _MM_FROUND_FLOOR (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEG_INF)
36 #define _MM_FROUND_CEIL (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_POS_INF)
37 #define _MM_FROUND_TRUNC (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_ZERO)
38 #define _MM_FROUND_RINT (_MM_FROUND_RAISE_EXC | _MM_FROUND_CUR_DIRECTION)
39 #define _MM_FROUND_NEARBYINT (_MM_FROUND_NO_EXC | _MM_FROUND_CUR_DIRECTION)
40 
41 /// Rounds up each element of the 128-bit vector of [4 x float] to an
42 ///    integer and returns the rounded values in a 128-bit vector of
43 ///    [4 x float].
44 ///
45 /// \headerfile <x86intrin.h>
46 ///
47 /// \code
48 /// __m128 _mm_ceil_ps(__m128 X);
49 /// \endcode
50 ///
51 /// This intrinsic corresponds to the <c> VROUNDPS / ROUNDPS </c> instruction.
52 ///
53 /// \param X
54 ///    A 128-bit vector of [4 x float] values to be rounded up.
55 /// \returns A 128-bit vector of [4 x float] containing the rounded values.
56 #define _mm_ceil_ps(X) _mm_round_ps((X), _MM_FROUND_CEIL)
57 
58 /// Rounds up each element of the 128-bit vector of [2 x double] to an
59 ///    integer and returns the rounded values in a 128-bit vector of
60 ///    [2 x double].
61 ///
62 /// \headerfile <x86intrin.h>
63 ///
64 /// \code
65 /// __m128d _mm_ceil_pd(__m128d X);
66 /// \endcode
67 ///
68 /// This intrinsic corresponds to the <c> VROUNDPD / ROUNDPD </c> instruction.
69 ///
70 /// \param X
71 ///    A 128-bit vector of [2 x double] values to be rounded up.
72 /// \returns A 128-bit vector of [2 x double] containing the rounded values.
73 #define _mm_ceil_pd(X) _mm_round_pd((X), _MM_FROUND_CEIL)
74 
75 /// Copies three upper elements of the first 128-bit vector operand to
76 ///    the corresponding three upper elements of the 128-bit result vector of
77 ///    [4 x float]. Rounds up the lowest element of the second 128-bit vector
78 ///    operand to an integer and copies it to the lowest element of the 128-bit
79 ///    result vector of [4 x float].
80 ///
81 /// \headerfile <x86intrin.h>
82 ///
83 /// \code
84 /// __m128 _mm_ceil_ss(__m128 X, __m128 Y);
85 /// \endcode
86 ///
87 /// This intrinsic corresponds to the <c> VROUNDSS / ROUNDSS </c> instruction.
88 ///
89 /// \param X
90 ///    A 128-bit vector of [4 x float]. The values stored in bits [127:32] are
91 ///    copied to the corresponding bits of the result.
92 /// \param Y
93 ///    A 128-bit vector of [4 x float]. The value stored in bits [31:0] is
94 ///    rounded up to the nearest integer and copied to the corresponding bits
95 ///    of the result.
96 /// \returns A 128-bit vector of [4 x float] containing the copied and rounded
97 ///    values.
98 #define _mm_ceil_ss(X, Y) _mm_round_ss((X), (Y), _MM_FROUND_CEIL)
99 
100 /// Copies the upper element of the first 128-bit vector operand to the
101 ///    corresponding upper element of the 128-bit result vector of [2 x double].
102 ///    Rounds up the lower element of the second 128-bit vector operand to an
103 ///    integer and copies it to the lower element of the 128-bit result vector
104 ///    of [2 x double].
105 ///
106 /// \headerfile <x86intrin.h>
107 ///
108 /// \code
109 /// __m128d _mm_ceil_sd(__m128d X, __m128d Y);
110 /// \endcode
111 ///
112 /// This intrinsic corresponds to the <c> VROUNDSD / ROUNDSD </c> instruction.
113 ///
114 /// \param X
115 ///    A 128-bit vector of [2 x double]. The value stored in bits [127:64] is
116 ///    copied to the corresponding bits of the result.
117 /// \param Y
118 ///    A 128-bit vector of [2 x double]. The value stored in bits [63:0] is
119 ///    rounded up to the nearest integer and copied to the corresponding bits
120 ///    of the result.
121 /// \returns A 128-bit vector of [2 x double] containing the copied and rounded
122 ///    values.
123 #define _mm_ceil_sd(X, Y) _mm_round_sd((X), (Y), _MM_FROUND_CEIL)
124 
125 /// Rounds down each element of the 128-bit vector of [4 x float] to an
126 ///    an integer and returns the rounded values in a 128-bit vector of
127 ///    [4 x float].
128 ///
129 /// \headerfile <x86intrin.h>
130 ///
131 /// \code
132 /// __m128 _mm_floor_ps(__m128 X);
133 /// \endcode
134 ///
135 /// This intrinsic corresponds to the <c> VROUNDPS / ROUNDPS </c> instruction.
136 ///
137 /// \param X
138 ///    A 128-bit vector of [4 x float] values to be rounded down.
139 /// \returns A 128-bit vector of [4 x float] containing the rounded values.
140 #define _mm_floor_ps(X) _mm_round_ps((X), _MM_FROUND_FLOOR)
141 
142 /// Rounds down each element of the 128-bit vector of [2 x double] to an
143 ///    integer and returns the rounded values in a 128-bit vector of
144 ///    [2 x double].
145 ///
146 /// \headerfile <x86intrin.h>
147 ///
148 /// \code
149 /// __m128d _mm_floor_pd(__m128d X);
150 /// \endcode
151 ///
152 /// This intrinsic corresponds to the <c> VROUNDPD / ROUNDPD </c> instruction.
153 ///
154 /// \param X
155 ///    A 128-bit vector of [2 x double].
156 /// \returns A 128-bit vector of [2 x double] containing the rounded values.
157 #define _mm_floor_pd(X) _mm_round_pd((X), _MM_FROUND_FLOOR)
158 
159 /// Copies three upper elements of the first 128-bit vector operand to
160 ///    the corresponding three upper elements of the 128-bit result vector of
161 ///    [4 x float]. Rounds down the lowest element of the second 128-bit vector
162 ///    operand to an integer and copies it to the lowest element of the 128-bit
163 ///    result vector of [4 x float].
164 ///
165 /// \headerfile <x86intrin.h>
166 ///
167 /// \code
168 /// __m128 _mm_floor_ss(__m128 X, __m128 Y);
169 /// \endcode
170 ///
171 /// This intrinsic corresponds to the <c> VROUNDSS / ROUNDSS </c> instruction.
172 ///
173 /// \param X
174 ///    A 128-bit vector of [4 x float]. The values stored in bits [127:32] are
175 ///    copied to the corresponding bits of the result.
176 /// \param Y
177 ///    A 128-bit vector of [4 x float]. The value stored in bits [31:0] is
178 ///    rounded down to the nearest integer and copied to the corresponding bits
179 ///    of the result.
180 /// \returns A 128-bit vector of [4 x float] containing the copied and rounded
181 ///    values.
182 #define _mm_floor_ss(X, Y) _mm_round_ss((X), (Y), _MM_FROUND_FLOOR)
183 
184 /// Copies the upper element of the first 128-bit vector operand to the
185 ///    corresponding upper element of the 128-bit result vector of [2 x double].
186 ///    Rounds down the lower element of the second 128-bit vector operand to an
187 ///    integer and copies it to the lower element of the 128-bit result vector
188 ///    of [2 x double].
189 ///
190 /// \headerfile <x86intrin.h>
191 ///
192 /// \code
193 /// __m128d _mm_floor_sd(__m128d X, __m128d Y);
194 /// \endcode
195 ///
196 /// This intrinsic corresponds to the <c> VROUNDSD / ROUNDSD </c> instruction.
197 ///
198 /// \param X
199 ///    A 128-bit vector of [2 x double]. The value stored in bits [127:64] is
200 ///    copied to the corresponding bits of the result.
201 /// \param Y
202 ///    A 128-bit vector of [2 x double]. The value stored in bits [63:0] is
203 ///    rounded down to the nearest integer and copied to the corresponding bits
204 ///    of the result.
205 /// \returns A 128-bit vector of [2 x double] containing the copied and rounded
206 ///    values.
207 #define _mm_floor_sd(X, Y) _mm_round_sd((X), (Y), _MM_FROUND_FLOOR)
208 
209 /// Rounds each element of the 128-bit vector of [4 x float] to an
210 ///    integer value according to the rounding control specified by the second
211 ///    argument and returns the rounded values in a 128-bit vector of
212 ///    [4 x float].
213 ///
214 /// \headerfile <x86intrin.h>
215 ///
216 /// \code
217 /// __m128 _mm_round_ps(__m128 X, const int M);
218 /// \endcode
219 ///
220 /// This intrinsic corresponds to the <c> VROUNDPS / ROUNDPS </c> instruction.
221 ///
222 /// \param X
223 ///    A 128-bit vector of [4 x float].
224 /// \param M
225 ///    An integer value that specifies the rounding operation. \n
226 ///    Bits [7:4] are reserved. \n
227 ///    Bit [3] is a precision exception value: \n
228 ///      0: A normal PE exception is used \n
229 ///      1: The PE field is not updated \n
230 ///    Bit [2] is the rounding control source: \n
231 ///      0: Use bits [1:0] of \a M \n
232 ///      1: Use the current MXCSR setting \n
233 ///    Bits [1:0] contain the rounding control definition: \n
234 ///      00: Nearest \n
235 ///      01: Downward (toward negative infinity) \n
236 ///      10: Upward (toward positive infinity) \n
237 ///      11: Truncated
238 /// \returns A 128-bit vector of [4 x float] containing the rounded values.
239 #define _mm_round_ps(X, M)                                                     \
240   ((__m128)__builtin_ia32_roundps((__v4sf)(__m128)(X), (M)))
241 
242 /// Copies three upper elements of the first 128-bit vector operand to
243 ///    the corresponding three upper elements of the 128-bit result vector of
244 ///    [4 x float]. Rounds the lowest element of the second 128-bit vector
245 ///    operand to an integer value according to the rounding control specified
246 ///    by the third argument and copies it to the lowest element of the 128-bit
247 ///    result vector of [4 x float].
248 ///
249 /// \headerfile <x86intrin.h>
250 ///
251 /// \code
252 /// __m128 _mm_round_ss(__m128 X, __m128 Y, const int M);
253 /// \endcode
254 ///
255 /// This intrinsic corresponds to the <c> VROUNDSS / ROUNDSS </c> instruction.
256 ///
257 /// \param X
258 ///    A 128-bit vector of [4 x float]. The values stored in bits [127:32] are
259 ///    copied to the corresponding bits of the result.
260 /// \param Y
261 ///    A 128-bit vector of [4 x float]. The value stored in bits [31:0] is
262 ///    rounded to the nearest integer using the specified rounding control and
263 ///    copied to the corresponding bits of the result.
264 /// \param M
265 ///    An integer value that specifies the rounding operation. \n
266 ///    Bits [7:4] are reserved. \n
267 ///    Bit [3] is a precision exception value: \n
268 ///      0: A normal PE exception is used \n
269 ///      1: The PE field is not updated \n
270 ///    Bit [2] is the rounding control source: \n
271 ///      0: Use bits [1:0] of \a M \n
272 ///      1: Use the current MXCSR setting \n
273 ///    Bits [1:0] contain the rounding control definition: \n
274 ///      00: Nearest \n
275 ///      01: Downward (toward negative infinity) \n
276 ///      10: Upward (toward positive infinity) \n
277 ///      11: Truncated
278 /// \returns A 128-bit vector of [4 x float] containing the copied and rounded
279 ///    values.
280 #define _mm_round_ss(X, Y, M)                                                  \
281   ((__m128)__builtin_ia32_roundss((__v4sf)(__m128)(X), (__v4sf)(__m128)(Y),    \
282                                   (M)))
283 
284 /// Rounds each element of the 128-bit vector of [2 x double] to an
285 ///    integer value according to the rounding control specified by the second
286 ///    argument and returns the rounded values in a 128-bit vector of
287 ///    [2 x double].
288 ///
289 /// \headerfile <x86intrin.h>
290 ///
291 /// \code
292 /// __m128d _mm_round_pd(__m128d X, const int M);
293 /// \endcode
294 ///
295 /// This intrinsic corresponds to the <c> VROUNDPD / ROUNDPD </c> instruction.
296 ///
297 /// \param X
298 ///    A 128-bit vector of [2 x double].
299 /// \param M
300 ///    An integer value that specifies the rounding operation. \n
301 ///    Bits [7:4] are reserved. \n
302 ///    Bit [3] is a precision exception value: \n
303 ///      0: A normal PE exception is used \n
304 ///      1: The PE field is not updated \n
305 ///    Bit [2] is the rounding control source: \n
306 ///      0: Use bits [1:0] of \a M \n
307 ///      1: Use the current MXCSR setting \n
308 ///    Bits [1:0] contain the rounding control definition: \n
309 ///      00: Nearest \n
310 ///      01: Downward (toward negative infinity) \n
311 ///      10: Upward (toward positive infinity) \n
312 ///      11: Truncated
313 /// \returns A 128-bit vector of [2 x double] containing the rounded values.
314 #define _mm_round_pd(X, M)                                                     \
315   ((__m128d)__builtin_ia32_roundpd((__v2df)(__m128d)(X), (M)))
316 
317 /// Copies the upper element of the first 128-bit vector operand to the
318 ///    corresponding upper element of the 128-bit result vector of [2 x double].
319 ///    Rounds the lower element of the second 128-bit vector operand to an
320 ///    integer value according to the rounding control specified by the third
321 ///    argument and copies it to the lower element of the 128-bit result vector
322 ///    of [2 x double].
323 ///
324 /// \headerfile <x86intrin.h>
325 ///
326 /// \code
327 /// __m128d _mm_round_sd(__m128d X, __m128d Y, const int M);
328 /// \endcode
329 ///
330 /// This intrinsic corresponds to the <c> VROUNDSD / ROUNDSD </c> instruction.
331 ///
332 /// \param X
333 ///    A 128-bit vector of [2 x double]. The value stored in bits [127:64] is
334 ///    copied to the corresponding bits of the result.
335 /// \param Y
336 ///    A 128-bit vector of [2 x double]. The value stored in bits [63:0] is
337 ///    rounded to the nearest integer using the specified rounding control and
338 ///    copied to the corresponding bits of the result.
339 /// \param M
340 ///    An integer value that specifies the rounding operation. \n
341 ///    Bits [7:4] are reserved. \n
342 ///    Bit [3] is a precision exception value: \n
343 ///      0: A normal PE exception is used \n
344 ///      1: The PE field is not updated \n
345 ///    Bit [2] is the rounding control source: \n
346 ///      0: Use bits [1:0] of \a M \n
347 ///      1: Use the current MXCSR setting \n
348 ///    Bits [1:0] contain the rounding control definition: \n
349 ///      00: Nearest \n
350 ///      01: Downward (toward negative infinity) \n
351 ///      10: Upward (toward positive infinity) \n
352 ///      11: Truncated
353 /// \returns A 128-bit vector of [2 x double] containing the copied and rounded
354 ///    values.
355 #define _mm_round_sd(X, Y, M)                                                  \
356   ((__m128d)__builtin_ia32_roundsd((__v2df)(__m128d)(X), (__v2df)(__m128d)(Y), \
357                                    (M)))
358 
359 /* SSE4 Packed Blending Intrinsics.  */
360 /// Returns a 128-bit vector of [2 x double] where the values are
361 ///    selected from either the first or second operand as specified by the
362 ///    third operand, the control mask.
363 ///
364 /// \headerfile <x86intrin.h>
365 ///
366 /// \code
367 /// __m128d _mm_blend_pd(__m128d V1, __m128d V2, const int M);
368 /// \endcode
369 ///
370 /// This intrinsic corresponds to the <c> VBLENDPD / BLENDPD </c> instruction.
371 ///
372 /// \param V1
373 ///    A 128-bit vector of [2 x double].
374 /// \param V2
375 ///    A 128-bit vector of [2 x double].
376 /// \param M
377 ///    An immediate integer operand, with mask bits [1:0] specifying how the
378 ///    values are to be copied. The position of the mask bit corresponds to the
379 ///    index of a copied value. When a mask bit is 0, the corresponding 64-bit
380 ///    element in operand \a V1 is copied to the same position in the result.
381 ///    When a mask bit is 1, the corresponding 64-bit element in operand \a V2
382 ///    is copied to the same position in the result.
383 /// \returns A 128-bit vector of [2 x double] containing the copied values.
384 #define _mm_blend_pd(V1, V2, M)                                                \
385   ((__m128d)__builtin_ia32_blendpd((__v2df)(__m128d)(V1),                      \
386                                    (__v2df)(__m128d)(V2), (int)(M)))
387 
388 /// Returns a 128-bit vector of [4 x float] where the values are selected
389 ///    from either the first or second operand as specified by the third
390 ///    operand, the control mask.
391 ///
392 /// \headerfile <x86intrin.h>
393 ///
394 /// \code
395 /// __m128 _mm_blend_ps(__m128 V1, __m128 V2, const int M);
396 /// \endcode
397 ///
398 /// This intrinsic corresponds to the <c> VBLENDPS / BLENDPS </c> instruction.
399 ///
400 /// \param V1
401 ///    A 128-bit vector of [4 x float].
402 /// \param V2
403 ///    A 128-bit vector of [4 x float].
404 /// \param M
405 ///    An immediate integer operand, with mask bits [3:0] specifying how the
406 ///    values are to be copied. The position of the mask bit corresponds to the
407 ///    index of a copied value. When a mask bit is 0, the corresponding 32-bit
408 ///    element in operand \a V1 is copied to the same position in the result.
409 ///    When a mask bit is 1, the corresponding 32-bit element in operand \a V2
410 ///    is copied to the same position in the result.
411 /// \returns A 128-bit vector of [4 x float] containing the copied values.
412 #define _mm_blend_ps(V1, V2, M)                                                \
413   ((__m128)__builtin_ia32_blendps((__v4sf)(__m128)(V1), (__v4sf)(__m128)(V2),  \
414                                   (int)(M)))
415 
416 /// Returns a 128-bit vector of [2 x double] where the values are
417 ///    selected from either the first or second operand as specified by the
418 ///    third operand, the control mask.
419 ///
420 /// \headerfile <x86intrin.h>
421 ///
422 /// This intrinsic corresponds to the <c> VBLENDVPD / BLENDVPD </c> instruction.
423 ///
424 /// \param __V1
425 ///    A 128-bit vector of [2 x double].
426 /// \param __V2
427 ///    A 128-bit vector of [2 x double].
428 /// \param __M
429 ///    A 128-bit vector operand, with mask bits 127 and 63 specifying how the
430 ///    values are to be copied. The position of the mask bit corresponds to the
431 ///    most significant bit of a copied value. When a mask bit is 0, the
432 ///    corresponding 64-bit element in operand \a __V1 is copied to the same
433 ///    position in the result. When a mask bit is 1, the corresponding 64-bit
434 ///    element in operand \a __V2 is copied to the same position in the result.
435 /// \returns A 128-bit vector of [2 x double] containing the copied values.
436 static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_blendv_pd(__m128d __V1,
437                                                            __m128d __V2,
438                                                            __m128d __M) {
439   return (__m128d)__builtin_ia32_blendvpd((__v2df)__V1, (__v2df)__V2,
440                                           (__v2df)__M);
441 }
442 
443 /// Returns a 128-bit vector of [4 x float] where the values are
444 ///    selected from either the first or second operand as specified by the
445 ///    third operand, the control mask.
446 ///
447 /// \headerfile <x86intrin.h>
448 ///
449 /// This intrinsic corresponds to the <c> VBLENDVPS / BLENDVPS </c> instruction.
450 ///
451 /// \param __V1
452 ///    A 128-bit vector of [4 x float].
453 /// \param __V2
454 ///    A 128-bit vector of [4 x float].
455 /// \param __M
456 ///    A 128-bit vector operand, with mask bits 127, 95, 63, and 31 specifying
457 ///    how the values are to be copied. The position of the mask bit corresponds
458 ///    to the most significant bit of a copied value. When a mask bit is 0, the
459 ///    corresponding 32-bit element in operand \a __V1 is copied to the same
460 ///    position in the result. When a mask bit is 1, the corresponding 32-bit
461 ///    element in operand \a __V2 is copied to the same position in the result.
462 /// \returns A 128-bit vector of [4 x float] containing the copied values.
463 static __inline__ __m128 __DEFAULT_FN_ATTRS _mm_blendv_ps(__m128 __V1,
464                                                           __m128 __V2,
465                                                           __m128 __M) {
466   return (__m128)__builtin_ia32_blendvps((__v4sf)__V1, (__v4sf)__V2,
467                                          (__v4sf)__M);
468 }
469 
470 /// Returns a 128-bit vector of [16 x i8] where the values are selected
471 ///    from either of the first or second operand as specified by the third
472 ///    operand, the control mask.
473 ///
474 /// \headerfile <x86intrin.h>
475 ///
476 /// This intrinsic corresponds to the <c> VPBLENDVB / PBLENDVB </c> instruction.
477 ///
478 /// \param __V1
479 ///    A 128-bit vector of [16 x i8].
480 /// \param __V2
481 ///    A 128-bit vector of [16 x i8].
482 /// \param __M
483 ///    A 128-bit vector operand, with mask bits 127, 119, 111...7 specifying
484 ///    how the values are to be copied. The position of the mask bit corresponds
485 ///    to the most significant bit of a copied value. When a mask bit is 0, the
486 ///    corresponding 8-bit element in operand \a __V1 is copied to the same
487 ///    position in the result. When a mask bit is 1, the corresponding 8-bit
488 ///    element in operand \a __V2 is copied to the same position in the result.
489 /// \returns A 128-bit vector of [16 x i8] containing the copied values.
490 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_blendv_epi8(__m128i __V1,
491                                                              __m128i __V2,
492                                                              __m128i __M) {
493   return (__m128i)__builtin_ia32_pblendvb128((__v16qi)__V1, (__v16qi)__V2,
494                                              (__v16qi)__M);
495 }
496 
497 /// Returns a 128-bit vector of [8 x i16] where the values are selected
498 ///    from either of the first or second operand as specified by the third
499 ///    operand, the control mask.
500 ///
501 /// \headerfile <x86intrin.h>
502 ///
503 /// \code
504 /// __m128i _mm_blend_epi16(__m128i V1, __m128i V2, const int M);
505 /// \endcode
506 ///
507 /// This intrinsic corresponds to the <c> VPBLENDW / PBLENDW </c> instruction.
508 ///
509 /// \param V1
510 ///    A 128-bit vector of [8 x i16].
511 /// \param V2
512 ///    A 128-bit vector of [8 x i16].
513 /// \param M
514 ///    An immediate integer operand, with mask bits [7:0] specifying how the
515 ///    values are to be copied. The position of the mask bit corresponds to the
516 ///    index of a copied value. When a mask bit is 0, the corresponding 16-bit
517 ///    element in operand \a V1 is copied to the same position in the result.
518 ///    When a mask bit is 1, the corresponding 16-bit element in operand \a V2
519 ///    is copied to the same position in the result.
520 /// \returns A 128-bit vector of [8 x i16] containing the copied values.
521 #define _mm_blend_epi16(V1, V2, M)                                             \
522   ((__m128i)__builtin_ia32_pblendw128((__v8hi)(__m128i)(V1),                   \
523                                       (__v8hi)(__m128i)(V2), (int)(M)))
524 
525 /* SSE4 Dword Multiply Instructions.  */
526 /// Multiples corresponding elements of two 128-bit vectors of [4 x i32]
527 ///    and returns the lower 32 bits of the each product in a 128-bit vector of
528 ///    [4 x i32].
529 ///
530 /// \headerfile <x86intrin.h>
531 ///
532 /// This intrinsic corresponds to the <c> VPMULLD / PMULLD </c> instruction.
533 ///
534 /// \param __V1
535 ///    A 128-bit integer vector.
536 /// \param __V2
537 ///    A 128-bit integer vector.
538 /// \returns A 128-bit integer vector containing the products of both operands.
539 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mullo_epi32(__m128i __V1,
540                                                              __m128i __V2) {
541   return (__m128i)((__v4su)__V1 * (__v4su)__V2);
542 }
543 
544 /// Multiplies corresponding even-indexed elements of two 128-bit
545 ///    vectors of [4 x i32] and returns a 128-bit vector of [2 x i64]
546 ///    containing the products.
547 ///
548 /// \headerfile <x86intrin.h>
549 ///
550 /// This intrinsic corresponds to the <c> VPMULDQ / PMULDQ </c> instruction.
551 ///
552 /// \param __V1
553 ///    A 128-bit vector of [4 x i32].
554 /// \param __V2
555 ///    A 128-bit vector of [4 x i32].
556 /// \returns A 128-bit vector of [2 x i64] containing the products of both
557 ///    operands.
558 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_mul_epi32(__m128i __V1,
559                                                            __m128i __V2) {
560   return (__m128i)__builtin_ia32_pmuldq128((__v4si)__V1, (__v4si)__V2);
561 }
562 
563 /* SSE4 Floating Point Dot Product Instructions.  */
564 /// Computes the dot product of the two 128-bit vectors of [4 x float]
565 ///    and returns it in the elements of the 128-bit result vector of
566 ///    [4 x float].
567 ///
568 ///    The immediate integer operand controls which input elements
569 ///    will contribute to the dot product, and where the final results are
570 ///    returned.
571 ///
572 /// \headerfile <x86intrin.h>
573 ///
574 /// \code
575 /// __m128 _mm_dp_ps(__m128 X, __m128 Y, const int M);
576 /// \endcode
577 ///
578 /// This intrinsic corresponds to the <c> VDPPS / DPPS </c> instruction.
579 ///
580 /// \param X
581 ///    A 128-bit vector of [4 x float].
582 /// \param Y
583 ///    A 128-bit vector of [4 x float].
584 /// \param M
585 ///    An immediate integer operand. Mask bits [7:4] determine which elements
586 ///    of the input vectors are used, with bit [4] corresponding to the lowest
587 ///    element and bit [7] corresponding to the highest element of each [4 x
588 ///    float] vector. If a bit is set, the corresponding elements from the two
589 ///    input vectors are used as an input for dot product; otherwise that input
590 ///    is treated as zero. Bits [3:0] determine which elements of the result
591 ///    will receive a copy of the final dot product, with bit [0] corresponding
592 ///    to the lowest element and bit [3] corresponding to the highest element of
593 ///    each [4 x float] subvector. If a bit is set, the dot product is returned
594 ///    in the corresponding element; otherwise that element is set to zero.
595 /// \returns A 128-bit vector of [4 x float] containing the dot product.
596 #define _mm_dp_ps(X, Y, M)                                                     \
597   ((__m128)__builtin_ia32_dpps((__v4sf)(__m128)(X), (__v4sf)(__m128)(Y), (M)))
598 
599 /// Computes the dot product of the two 128-bit vectors of [2 x double]
600 ///    and returns it in the elements of the 128-bit result vector of
601 ///    [2 x double].
602 ///
603 ///    The immediate integer operand controls which input
604 ///    elements will contribute to the dot product, and where the final results
605 ///    are returned.
606 ///
607 /// \headerfile <x86intrin.h>
608 ///
609 /// \code
610 /// __m128d _mm_dp_pd(__m128d X, __m128d Y, const int M);
611 /// \endcode
612 ///
613 /// This intrinsic corresponds to the <c> VDPPD / DPPD </c> instruction.
614 ///
615 /// \param X
616 ///    A 128-bit vector of [2 x double].
617 /// \param Y
618 ///    A 128-bit vector of [2 x double].
619 /// \param M
620 ///    An immediate integer operand. Mask bits [5:4] determine which elements
621 ///    of the input vectors are used, with bit [4] corresponding to the lowest
622 ///    element and bit [5] corresponding to the highest element of each of [2 x
623 ///    double] vector. If a bit is set, the corresponding elements from the two
624 ///    input vectors are used as an input for dot product; otherwise that input
625 ///    is treated as zero. Bits [1:0] determine which elements of the result
626 ///    will receive a copy of the final dot product, with bit [0] corresponding
627 ///    to the lowest element and bit [1] corresponding to the highest element of
628 ///    each [2 x double] vector. If a bit is set, the dot product is returned in
629 ///    the corresponding element; otherwise that element is set to zero.
630 #define _mm_dp_pd(X, Y, M)                                                     \
631   ((__m128d)__builtin_ia32_dppd((__v2df)(__m128d)(X), (__v2df)(__m128d)(Y),    \
632                                 (M)))
633 
634 /* SSE4 Streaming Load Hint Instruction.  */
635 /// Loads integer values from a 128-bit aligned memory location to a
636 ///    128-bit integer vector.
637 ///
638 /// \headerfile <x86intrin.h>
639 ///
640 /// This intrinsic corresponds to the <c> VMOVNTDQA / MOVNTDQA </c> instruction.
641 ///
642 /// \param __V
643 ///    A pointer to a 128-bit aligned memory location that contains the integer
644 ///    values.
645 /// \returns A 128-bit integer vector containing the data stored at the
646 ///    specified memory location.
647 static __inline__ __m128i __DEFAULT_FN_ATTRS
648 _mm_stream_load_si128(const void *__V) {
649   return (__m128i)__builtin_nontemporal_load((const __v2di *)__V);
650 }
651 
652 /* SSE4 Packed Integer Min/Max Instructions.  */
653 /// Compares the corresponding elements of two 128-bit vectors of
654 ///    [16 x i8] and returns a 128-bit vector of [16 x i8] containing the lesser
655 ///    of the two values.
656 ///
657 /// \headerfile <x86intrin.h>
658 ///
659 /// This intrinsic corresponds to the <c> VPMINSB / PMINSB </c> instruction.
660 ///
661 /// \param __V1
662 ///    A 128-bit vector of [16 x i8].
663 /// \param __V2
664 ///    A 128-bit vector of [16 x i8]
665 /// \returns A 128-bit vector of [16 x i8] containing the lesser values.
666 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_min_epi8(__m128i __V1,
667                                                           __m128i __V2) {
668   return (__m128i)__builtin_elementwise_min((__v16qs)__V1, (__v16qs)__V2);
669 }
670 
671 /// Compares the corresponding elements of two 128-bit vectors of
672 ///    [16 x i8] and returns a 128-bit vector of [16 x i8] containing the
673 ///    greater value of the two.
674 ///
675 /// \headerfile <x86intrin.h>
676 ///
677 /// This intrinsic corresponds to the <c> VPMAXSB / PMAXSB </c> instruction.
678 ///
679 /// \param __V1
680 ///    A 128-bit vector of [16 x i8].
681 /// \param __V2
682 ///    A 128-bit vector of [16 x i8].
683 /// \returns A 128-bit vector of [16 x i8] containing the greater values.
684 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_max_epi8(__m128i __V1,
685                                                           __m128i __V2) {
686   return (__m128i)__builtin_elementwise_max((__v16qs)__V1, (__v16qs)__V2);
687 }
688 
689 /// Compares the corresponding elements of two 128-bit vectors of
690 ///    [8 x u16] and returns a 128-bit vector of [8 x u16] containing the lesser
691 ///    value of the two.
692 ///
693 /// \headerfile <x86intrin.h>
694 ///
695 /// This intrinsic corresponds to the <c> VPMINUW / PMINUW </c> instruction.
696 ///
697 /// \param __V1
698 ///    A 128-bit vector of [8 x u16].
699 /// \param __V2
700 ///    A 128-bit vector of [8 x u16].
701 /// \returns A 128-bit vector of [8 x u16] containing the lesser values.
702 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_min_epu16(__m128i __V1,
703                                                            __m128i __V2) {
704   return (__m128i)__builtin_elementwise_min((__v8hu)__V1, (__v8hu)__V2);
705 }
706 
707 /// Compares the corresponding elements of two 128-bit vectors of
708 ///    [8 x u16] and returns a 128-bit vector of [8 x u16] containing the
709 ///    greater value of the two.
710 ///
711 /// \headerfile <x86intrin.h>
712 ///
713 /// This intrinsic corresponds to the <c> VPMAXUW / PMAXUW </c> instruction.
714 ///
715 /// \param __V1
716 ///    A 128-bit vector of [8 x u16].
717 /// \param __V2
718 ///    A 128-bit vector of [8 x u16].
719 /// \returns A 128-bit vector of [8 x u16] containing the greater values.
720 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_max_epu16(__m128i __V1,
721                                                            __m128i __V2) {
722   return (__m128i)__builtin_elementwise_max((__v8hu)__V1, (__v8hu)__V2);
723 }
724 
725 /// Compares the corresponding elements of two 128-bit vectors of
726 ///    [4 x i32] and returns a 128-bit vector of [4 x i32] containing the lesser
727 ///    value of the two.
728 ///
729 /// \headerfile <x86intrin.h>
730 ///
731 /// This intrinsic corresponds to the <c> VPMINSD / PMINSD </c> instruction.
732 ///
733 /// \param __V1
734 ///    A 128-bit vector of [4 x i32].
735 /// \param __V2
736 ///    A 128-bit vector of [4 x i32].
737 /// \returns A 128-bit vector of [4 x i32] containing the lesser values.
738 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_min_epi32(__m128i __V1,
739                                                            __m128i __V2) {
740   return (__m128i)__builtin_elementwise_min((__v4si)__V1, (__v4si)__V2);
741 }
742 
743 /// Compares the corresponding elements of two 128-bit vectors of
744 ///    [4 x i32] and returns a 128-bit vector of [4 x i32] containing the
745 ///    greater value of the two.
746 ///
747 /// \headerfile <x86intrin.h>
748 ///
749 /// This intrinsic corresponds to the <c> VPMAXSD / PMAXSD </c> instruction.
750 ///
751 /// \param __V1
752 ///    A 128-bit vector of [4 x i32].
753 /// \param __V2
754 ///    A 128-bit vector of [4 x i32].
755 /// \returns A 128-bit vector of [4 x i32] containing the greater values.
756 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_max_epi32(__m128i __V1,
757                                                            __m128i __V2) {
758   return (__m128i)__builtin_elementwise_max((__v4si)__V1, (__v4si)__V2);
759 }
760 
761 /// Compares the corresponding elements of two 128-bit vectors of
762 ///    [4 x u32] and returns a 128-bit vector of [4 x u32] containing the lesser
763 ///    value of the two.
764 ///
765 /// \headerfile <x86intrin.h>
766 ///
767 /// This intrinsic corresponds to the <c> VPMINUD / PMINUD </c>  instruction.
768 ///
769 /// \param __V1
770 ///    A 128-bit vector of [4 x u32].
771 /// \param __V2
772 ///    A 128-bit vector of [4 x u32].
773 /// \returns A 128-bit vector of [4 x u32] containing the lesser values.
774 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_min_epu32(__m128i __V1,
775                                                            __m128i __V2) {
776   return (__m128i)__builtin_elementwise_min((__v4su)__V1, (__v4su)__V2);
777 }
778 
779 /// Compares the corresponding elements of two 128-bit vectors of
780 ///    [4 x u32] and returns a 128-bit vector of [4 x u32] containing the
781 ///    greater value of the two.
782 ///
783 /// \headerfile <x86intrin.h>
784 ///
785 /// This intrinsic corresponds to the <c> VPMAXUD / PMAXUD </c> instruction.
786 ///
787 /// \param __V1
788 ///    A 128-bit vector of [4 x u32].
789 /// \param __V2
790 ///    A 128-bit vector of [4 x u32].
791 /// \returns A 128-bit vector of [4 x u32] containing the greater values.
792 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_max_epu32(__m128i __V1,
793                                                            __m128i __V2) {
794   return (__m128i)__builtin_elementwise_max((__v4su)__V1, (__v4su)__V2);
795 }
796 
797 /* SSE4 Insertion and Extraction from XMM Register Instructions.  */
798 /// Takes the first argument \a X and inserts an element from the second
799 ///    argument \a Y as selected by the third argument \a N. That result then
800 ///    has elements zeroed out also as selected by the third argument \a N. The
801 ///    resulting 128-bit vector of [4 x float] is then returned.
802 ///
803 /// \headerfile <x86intrin.h>
804 ///
805 /// \code
806 /// __m128 _mm_insert_ps(__m128 X, __m128 Y, const int N);
807 /// \endcode
808 ///
809 /// This intrinsic corresponds to the <c> VINSERTPS </c> instruction.
810 ///
811 /// \param X
812 ///    A 128-bit vector source operand of [4 x float]. With the exception of
813 ///    those bits in the result copied from parameter \a Y and zeroed by bits
814 ///    [3:0] of \a N, all bits from this parameter are copied to the result.
815 /// \param Y
816 ///    A 128-bit vector source operand of [4 x float]. One single-precision
817 ///    floating-point element from this source, as determined by the immediate
818 ///    parameter, is copied to the result.
819 /// \param N
820 ///    Specifies which bits from operand \a Y will be copied, which bits in the
821 ///    result they will be copied to, and which bits in the result will be
822 ///    cleared. The following assignments are made: \n
823 ///    Bits [7:6] specify the bits to copy from operand \a Y: \n
824 ///      00: Selects bits [31:0] from operand \a Y. \n
825 ///      01: Selects bits [63:32] from operand \a Y. \n
826 ///      10: Selects bits [95:64] from operand \a Y. \n
827 ///      11: Selects bits [127:96] from operand \a Y. \n
828 ///    Bits [5:4] specify the bits in the result to which the selected bits
829 ///    from operand \a Y are copied: \n
830 ///      00: Copies the selected bits from \a Y to result bits [31:0]. \n
831 ///      01: Copies the selected bits from \a Y to result bits [63:32]. \n
832 ///      10: Copies the selected bits from \a Y to result bits [95:64]. \n
833 ///      11: Copies the selected bits from \a Y to result bits [127:96]. \n
834 ///    Bits[3:0]: If any of these bits are set, the corresponding result
835 ///    element is cleared.
836 /// \returns A 128-bit vector of [4 x float] containing the copied
837 ///    single-precision floating point elements from the operands.
838 #define _mm_insert_ps(X, Y, N) __builtin_ia32_insertps128((X), (Y), (N))
839 
840 /// Extracts a 32-bit integer from a 128-bit vector of [4 x float] and
841 ///    returns it, using the immediate value parameter \a N as a selector.
842 ///
843 /// \headerfile <x86intrin.h>
844 ///
845 /// \code
846 /// int _mm_extract_ps(__m128 X, const int N);
847 /// \endcode
848 ///
849 /// This intrinsic corresponds to the <c> VEXTRACTPS / EXTRACTPS </c>
850 /// instruction.
851 ///
852 /// \param X
853 ///    A 128-bit vector of [4 x float].
854 /// \param N
855 ///    An immediate value. Bits [1:0] determines which bits from the argument
856 ///    \a X are extracted and returned: \n
857 ///    00: Bits [31:0] of parameter \a X are returned. \n
858 ///    01: Bits [63:32] of parameter \a X are returned. \n
859 ///    10: Bits [95:64] of parameter \a X are returned. \n
860 ///    11: Bits [127:96] of parameter \a X are returned.
861 /// \returns A 32-bit integer containing the extracted 32 bits of float data.
862 #define _mm_extract_ps(X, N)                                                   \
863   __builtin_bit_cast(                                                          \
864       int, __builtin_ia32_vec_ext_v4sf((__v4sf)(__m128)(X), (int)(N)))
865 
866 /* Miscellaneous insert and extract macros.  */
867 /* Extract a single-precision float from X at index N into D.  */
868 #define _MM_EXTRACT_FLOAT(D, X, N)                                             \
869   do {                                                                         \
870     (D) = __builtin_ia32_vec_ext_v4sf((__v4sf)(__m128)(X), (int)(N));          \
871   } while (0)
872 
873 /* Or together 2 sets of indexes (X and Y) with the zeroing bits (Z) to create
874    an index suitable for _mm_insert_ps.  */
875 #define _MM_MK_INSERTPS_NDX(X, Y, Z) (((X) << 6) | ((Y) << 4) | (Z))
876 
877 /* Extract a float from X at index N into the first index of the return.  */
878 #define _MM_PICK_OUT_PS(X, N)                                                  \
879   _mm_insert_ps(_mm_setzero_ps(), (X), _MM_MK_INSERTPS_NDX((N), 0, 0x0e))
880 
881 /* Insert int into packed integer array at index.  */
882 /// Constructs a 128-bit vector of [16 x i8] by first making a copy of
883 ///    the 128-bit integer vector parameter, and then inserting the lower 8 bits
884 ///    of an integer parameter \a I into an offset specified by the immediate
885 ///    value parameter \a N.
886 ///
887 /// \headerfile <x86intrin.h>
888 ///
889 /// \code
890 /// __m128i _mm_insert_epi8(__m128i X, int I, const int N);
891 /// \endcode
892 ///
893 /// This intrinsic corresponds to the <c> VPINSRB / PINSRB </c> instruction.
894 ///
895 /// \param X
896 ///    A 128-bit integer vector of [16 x i8]. This vector is copied to the
897 ///    result and then one of the sixteen elements in the result vector is
898 ///    replaced by the lower 8 bits of \a I.
899 /// \param I
900 ///    An integer. The lower 8 bits of this operand are written to the result
901 ///    beginning at the offset specified by \a N.
902 /// \param N
903 ///    An immediate value. Bits [3:0] specify the bit offset in the result at
904 ///    which the lower 8 bits of \a I are written. \n
905 ///    0000: Bits [7:0] of the result are used for insertion. \n
906 ///    0001: Bits [15:8] of the result are used for insertion. \n
907 ///    0010: Bits [23:16] of the result are used for insertion. \n
908 ///    0011: Bits [31:24] of the result are used for insertion. \n
909 ///    0100: Bits [39:32] of the result are used for insertion. \n
910 ///    0101: Bits [47:40] of the result are used for insertion. \n
911 ///    0110: Bits [55:48] of the result are used for insertion. \n
912 ///    0111: Bits [63:56] of the result are used for insertion. \n
913 ///    1000: Bits [71:64] of the result are used for insertion. \n
914 ///    1001: Bits [79:72] of the result are used for insertion. \n
915 ///    1010: Bits [87:80] of the result are used for insertion. \n
916 ///    1011: Bits [95:88] of the result are used for insertion. \n
917 ///    1100: Bits [103:96] of the result are used for insertion. \n
918 ///    1101: Bits [111:104] of the result are used for insertion. \n
919 ///    1110: Bits [119:112] of the result are used for insertion. \n
920 ///    1111: Bits [127:120] of the result are used for insertion.
921 /// \returns A 128-bit integer vector containing the constructed values.
922 #define _mm_insert_epi8(X, I, N)                                               \
923   ((__m128i)__builtin_ia32_vec_set_v16qi((__v16qi)(__m128i)(X), (int)(I),      \
924                                          (int)(N)))
925 
926 /// Constructs a 128-bit vector of [4 x i32] by first making a copy of
927 ///    the 128-bit integer vector parameter, and then inserting the 32-bit
928 ///    integer parameter \a I at the offset specified by the immediate value
929 ///    parameter \a N.
930 ///
931 /// \headerfile <x86intrin.h>
932 ///
933 /// \code
934 /// __m128i _mm_insert_epi32(__m128i X, int I, const int N);
935 /// \endcode
936 ///
937 /// This intrinsic corresponds to the <c> VPINSRD / PINSRD </c> instruction.
938 ///
939 /// \param X
940 ///    A 128-bit integer vector of [4 x i32]. This vector is copied to the
941 ///    result and then one of the four elements in the result vector is
942 ///    replaced by \a I.
943 /// \param I
944 ///    A 32-bit integer that is written to the result beginning at the offset
945 ///    specified by \a N.
946 /// \param N
947 ///    An immediate value. Bits [1:0] specify the bit offset in the result at
948 ///    which the integer \a I is written. \n
949 ///    00: Bits [31:0] of the result are used for insertion. \n
950 ///    01: Bits [63:32] of the result are used for insertion. \n
951 ///    10: Bits [95:64] of the result are used for insertion. \n
952 ///    11: Bits [127:96] of the result are used for insertion.
953 /// \returns A 128-bit integer vector containing the constructed values.
954 #define _mm_insert_epi32(X, I, N)                                              \
955   ((__m128i)__builtin_ia32_vec_set_v4si((__v4si)(__m128i)(X), (int)(I),        \
956                                         (int)(N)))
957 
958 #ifdef __x86_64__
959 /// Constructs a 128-bit vector of [2 x i64] by first making a copy of
960 ///    the 128-bit integer vector parameter, and then inserting the 64-bit
961 ///    integer parameter \a I, using the immediate value parameter \a N as an
962 ///    insertion location selector.
963 ///
964 /// \headerfile <x86intrin.h>
965 ///
966 /// \code
967 /// __m128i _mm_insert_epi64(__m128i X, long long I, const int N);
968 /// \endcode
969 ///
970 /// This intrinsic corresponds to the <c> VPINSRQ / PINSRQ </c> instruction.
971 ///
972 /// \param X
973 ///    A 128-bit integer vector of [2 x i64]. This vector is copied to the
974 ///    result and then one of the two elements in the result vector is replaced
975 ///    by \a I.
976 /// \param I
977 ///    A 64-bit integer that is written to the result beginning at the offset
978 ///    specified by \a N.
979 /// \param N
980 ///    An immediate value. Bit [0] specifies the bit offset in the result at
981 ///    which the integer \a I is written. \n
982 ///    0: Bits [63:0] of the result are used for insertion. \n
983 ///    1: Bits [127:64] of the result are used for insertion. \n
984 /// \returns A 128-bit integer vector containing the constructed values.
985 #define _mm_insert_epi64(X, I, N)                                              \
986   ((__m128i)__builtin_ia32_vec_set_v2di((__v2di)(__m128i)(X), (long long)(I),  \
987                                         (int)(N)))
988 #endif /* __x86_64__ */
989 
990 /* Extract int from packed integer array at index.  This returns the element
991  * as a zero extended value, so it is unsigned.
992  */
993 /// Extracts an 8-bit element from the 128-bit integer vector of
994 ///    [16 x i8], using the immediate value parameter \a N as a selector.
995 ///
996 /// \headerfile <x86intrin.h>
997 ///
998 /// \code
999 /// int _mm_extract_epi8(__m128i X, const int N);
1000 /// \endcode
1001 ///
1002 /// This intrinsic corresponds to the <c> VPEXTRB / PEXTRB </c> instruction.
1003 ///
1004 /// \param X
1005 ///    A 128-bit integer vector.
1006 /// \param N
1007 ///    An immediate value. Bits [3:0] specify which 8-bit vector element from
1008 ///    the argument \a X to extract and copy to the result. \n
1009 ///    0000: Bits [7:0] of parameter \a X are extracted. \n
1010 ///    0001: Bits [15:8] of the parameter \a X are extracted. \n
1011 ///    0010: Bits [23:16] of the parameter \a X are extracted. \n
1012 ///    0011: Bits [31:24] of the parameter \a X are extracted. \n
1013 ///    0100: Bits [39:32] of the parameter \a X are extracted. \n
1014 ///    0101: Bits [47:40] of the parameter \a X are extracted. \n
1015 ///    0110: Bits [55:48] of the parameter \a X are extracted. \n
1016 ///    0111: Bits [63:56] of the parameter \a X are extracted. \n
1017 ///    1000: Bits [71:64] of the parameter \a X are extracted. \n
1018 ///    1001: Bits [79:72] of the parameter \a X are extracted. \n
1019 ///    1010: Bits [87:80] of the parameter \a X are extracted. \n
1020 ///    1011: Bits [95:88] of the parameter \a X are extracted. \n
1021 ///    1100: Bits [103:96] of the parameter \a X are extracted. \n
1022 ///    1101: Bits [111:104] of the parameter \a X are extracted. \n
1023 ///    1110: Bits [119:112] of the parameter \a X are extracted. \n
1024 ///    1111: Bits [127:120] of the parameter \a X are extracted.
1025 /// \returns  An unsigned integer, whose lower 8 bits are selected from the
1026 ///    128-bit integer vector parameter and the remaining bits are assigned
1027 ///    zeros.
1028 #define _mm_extract_epi8(X, N)                                                 \
1029   ((int)(unsigned char)__builtin_ia32_vec_ext_v16qi((__v16qi)(__m128i)(X),     \
1030                                                     (int)(N)))
1031 
1032 /// Extracts a 32-bit element from the 128-bit integer vector of
1033 ///    [4 x i32], using the immediate value parameter \a N as a selector.
1034 ///
1035 /// \headerfile <x86intrin.h>
1036 ///
1037 /// \code
1038 /// int _mm_extract_epi32(__m128i X, const int N);
1039 /// \endcode
1040 ///
1041 /// This intrinsic corresponds to the <c> VPEXTRD / PEXTRD </c> instruction.
1042 ///
1043 /// \param X
1044 ///    A 128-bit integer vector.
1045 /// \param N
1046 ///    An immediate value. Bits [1:0] specify which 32-bit vector element from
1047 ///    the argument \a X to extract and copy to the result. \n
1048 ///    00: Bits [31:0] of the parameter \a X are extracted. \n
1049 ///    01: Bits [63:32] of the parameter \a X are extracted. \n
1050 ///    10: Bits [95:64] of the parameter \a X are extracted. \n
1051 ///    11: Bits [127:96] of the parameter \a X are exracted.
1052 /// \returns  An integer, whose lower 32 bits are selected from the 128-bit
1053 ///    integer vector parameter and the remaining bits are assigned zeros.
1054 #define _mm_extract_epi32(X, N)                                                \
1055   ((int)__builtin_ia32_vec_ext_v4si((__v4si)(__m128i)(X), (int)(N)))
1056 
1057 /// Extracts a 64-bit element from the 128-bit integer vector of
1058 ///    [2 x i64], using the immediate value parameter \a N as a selector.
1059 ///
1060 /// \headerfile <x86intrin.h>
1061 ///
1062 /// \code
1063 /// long long _mm_extract_epi64(__m128i X, const int N);
1064 /// \endcode
1065 ///
1066 /// This intrinsic corresponds to the <c> VPEXTRQ / PEXTRQ </c> instruction
1067 /// in 64-bit mode.
1068 ///
1069 /// \param X
1070 ///    A 128-bit integer vector.
1071 /// \param N
1072 ///    An immediate value. Bit [0] specifies which 64-bit vector element from
1073 ///    the argument \a X to return. \n
1074 ///    0: Bits [63:0] are returned. \n
1075 ///    1: Bits [127:64] are returned. \n
1076 /// \returns  A 64-bit integer.
1077 #define _mm_extract_epi64(X, N)                                                \
1078   ((long long)__builtin_ia32_vec_ext_v2di((__v2di)(__m128i)(X), (int)(N)))
1079 
1080 /* SSE4 128-bit Packed Integer Comparisons.  */
1081 /// Tests whether the specified bits in a 128-bit integer vector are all
1082 ///    zeros.
1083 ///
1084 /// \headerfile <x86intrin.h>
1085 ///
1086 /// This intrinsic corresponds to the <c> VPTEST / PTEST </c> instruction.
1087 ///
1088 /// \param __M
1089 ///    A 128-bit integer vector containing the bits to be tested.
1090 /// \param __V
1091 ///    A 128-bit integer vector selecting which bits to test in operand \a __M.
1092 /// \returns TRUE if the specified bits are all zeros; FALSE otherwise.
1093 static __inline__ int __DEFAULT_FN_ATTRS _mm_testz_si128(__m128i __M,
1094                                                          __m128i __V) {
1095   return __builtin_ia32_ptestz128((__v2di)__M, (__v2di)__V);
1096 }
1097 
1098 /// Tests whether the specified bits in a 128-bit integer vector are all
1099 ///    ones.
1100 ///
1101 /// \headerfile <x86intrin.h>
1102 ///
1103 /// This intrinsic corresponds to the <c> VPTEST / PTEST </c> instruction.
1104 ///
1105 /// \param __M
1106 ///    A 128-bit integer vector containing the bits to be tested.
1107 /// \param __V
1108 ///    A 128-bit integer vector selecting which bits to test in operand \a __M.
1109 /// \returns TRUE if the specified bits are all ones; FALSE otherwise.
1110 static __inline__ int __DEFAULT_FN_ATTRS _mm_testc_si128(__m128i __M,
1111                                                          __m128i __V) {
1112   return __builtin_ia32_ptestc128((__v2di)__M, (__v2di)__V);
1113 }
1114 
1115 /// Tests whether the specified bits in a 128-bit integer vector are
1116 ///    neither all zeros nor all ones.
1117 ///
1118 /// \headerfile <x86intrin.h>
1119 ///
1120 /// This intrinsic corresponds to the <c> VPTEST / PTEST </c> instruction.
1121 ///
1122 /// \param __M
1123 ///    A 128-bit integer vector containing the bits to be tested.
1124 /// \param __V
1125 ///    A 128-bit integer vector selecting which bits to test in operand \a __M.
1126 /// \returns TRUE if the specified bits are neither all zeros nor all ones;
1127 ///    FALSE otherwise.
1128 static __inline__ int __DEFAULT_FN_ATTRS _mm_testnzc_si128(__m128i __M,
1129                                                            __m128i __V) {
1130   return __builtin_ia32_ptestnzc128((__v2di)__M, (__v2di)__V);
1131 }
1132 
1133 /// Tests whether the specified bits in a 128-bit integer vector are all
1134 ///    ones.
1135 ///
1136 /// \headerfile <x86intrin.h>
1137 ///
1138 /// \code
1139 /// int _mm_test_all_ones(__m128i V);
1140 /// \endcode
1141 ///
1142 /// This intrinsic corresponds to the <c> VPTEST / PTEST </c> instruction.
1143 ///
1144 /// \param V
1145 ///    A 128-bit integer vector containing the bits to be tested.
1146 /// \returns TRUE if the bits specified in the operand are all set to 1; FALSE
1147 ///    otherwise.
1148 #define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_set1_epi32(-1))
1149 
1150 /// Tests whether the specified bits in a 128-bit integer vector are
1151 ///    neither all zeros nor all ones.
1152 ///
1153 /// \headerfile <x86intrin.h>
1154 ///
1155 /// \code
1156 /// int _mm_test_mix_ones_zeros(__m128i M, __m128i V);
1157 /// \endcode
1158 ///
1159 /// This intrinsic corresponds to the <c> VPTEST / PTEST </c> instruction.
1160 ///
1161 /// \param M
1162 ///    A 128-bit integer vector containing the bits to be tested.
1163 /// \param V
1164 ///    A 128-bit integer vector selecting which bits to test in operand \a M.
1165 /// \returns TRUE if the specified bits are neither all zeros nor all ones;
1166 ///    FALSE otherwise.
1167 #define _mm_test_mix_ones_zeros(M, V) _mm_testnzc_si128((M), (V))
1168 
1169 /// Tests whether the specified bits in a 128-bit integer vector are all
1170 ///    zeros.
1171 ///
1172 /// \headerfile <x86intrin.h>
1173 ///
1174 /// \code
1175 /// int _mm_test_all_zeros(__m128i M, __m128i V);
1176 /// \endcode
1177 ///
1178 /// This intrinsic corresponds to the <c> VPTEST / PTEST </c> instruction.
1179 ///
1180 /// \param M
1181 ///    A 128-bit integer vector containing the bits to be tested.
1182 /// \param V
1183 ///    A 128-bit integer vector selecting which bits to test in operand \a M.
1184 /// \returns TRUE if the specified bits are all zeros; FALSE otherwise.
1185 #define _mm_test_all_zeros(M, V) _mm_testz_si128((M), (V))
1186 
1187 /* SSE4 64-bit Packed Integer Comparisons.  */
1188 /// Compares each of the corresponding 64-bit values of the 128-bit
1189 ///    integer vectors for equality.
1190 ///
1191 ///    Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
1192 ///
1193 /// \headerfile <x86intrin.h>
1194 ///
1195 /// This intrinsic corresponds to the <c> VPCMPEQQ / PCMPEQQ </c> instruction.
1196 ///
1197 /// \param __V1
1198 ///    A 128-bit integer vector.
1199 /// \param __V2
1200 ///    A 128-bit integer vector.
1201 /// \returns A 128-bit integer vector containing the comparison results.
1202 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmpeq_epi64(__m128i __V1,
1203                                                              __m128i __V2) {
1204   return (__m128i)((__v2di)__V1 == (__v2di)__V2);
1205 }
1206 
1207 /* SSE4 Packed Integer Sign-Extension.  */
1208 /// Sign-extends each of the lower eight 8-bit integer elements of a
1209 ///    128-bit vector of [16 x i8] to 16-bit values and returns them in a
1210 ///    128-bit vector of [8 x i16]. The upper eight elements of the input vector
1211 ///    are unused.
1212 ///
1213 /// \headerfile <x86intrin.h>
1214 ///
1215 /// This intrinsic corresponds to the <c> VPMOVSXBW / PMOVSXBW </c> instruction.
1216 ///
1217 /// \param __V
1218 ///    A 128-bit vector of [16 x i8]. The lower eight 8-bit elements are
1219 ///    sign-extended to 16-bit values.
1220 /// \returns A 128-bit vector of [8 x i16] containing the sign-extended values.
1221 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi8_epi16(__m128i __V) {
1222   /* This function always performs a signed extension, but __v16qi is a char
1223      which may be signed or unsigned, so use __v16qs. */
1224   return (__m128i) __builtin_convertvector(
1225       __builtin_shufflevector((__v16qs)__V, (__v16qs)__V, 0, 1, 2, 3, 4, 5, 6,
1226                               7),
1227       __v8hi);
1228 }
1229 
1230 /// Sign-extends each of the lower four 8-bit integer elements of a
1231 ///    128-bit vector of [16 x i8] to 32-bit values and returns them in a
1232 ///    128-bit vector of [4 x i32]. The upper twelve elements of the input
1233 ///    vector are unused.
1234 ///
1235 /// \headerfile <x86intrin.h>
1236 ///
1237 /// This intrinsic corresponds to the <c> VPMOVSXBD / PMOVSXBD </c> instruction.
1238 ///
1239 /// \param __V
1240 ///    A 128-bit vector of [16 x i8]. The lower four 8-bit elements are
1241 ///    sign-extended to 32-bit values.
1242 /// \returns A 128-bit vector of [4 x i32] containing the sign-extended values.
1243 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi8_epi32(__m128i __V) {
1244   /* This function always performs a signed extension, but __v16qi is a char
1245      which may be signed or unsigned, so use __v16qs. */
1246   return (__m128i) __builtin_convertvector(
1247       __builtin_shufflevector((__v16qs)__V, (__v16qs)__V, 0, 1, 2, 3), __v4si);
1248 }
1249 
1250 /// Sign-extends each of the lower two 8-bit integer elements of a
1251 ///    128-bit integer vector of [16 x i8] to 64-bit values and returns them in
1252 ///    a 128-bit vector of [2 x i64]. The upper fourteen elements of the input
1253 ///    vector are unused.
1254 ///
1255 /// \headerfile <x86intrin.h>
1256 ///
1257 /// This intrinsic corresponds to the <c> VPMOVSXBQ / PMOVSXBQ </c> instruction.
1258 ///
1259 /// \param __V
1260 ///    A 128-bit vector of [16 x i8]. The lower two 8-bit elements are
1261 ///    sign-extended to 64-bit values.
1262 /// \returns A 128-bit vector of [2 x i64] containing the sign-extended values.
1263 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi8_epi64(__m128i __V) {
1264   /* This function always performs a signed extension, but __v16qi is a char
1265      which may be signed or unsigned, so use __v16qs. */
1266   return (__m128i) __builtin_convertvector(
1267       __builtin_shufflevector((__v16qs)__V, (__v16qs)__V, 0, 1), __v2di);
1268 }
1269 
1270 /// Sign-extends each of the lower four 16-bit integer elements of a
1271 ///    128-bit integer vector of [8 x i16] to 32-bit values and returns them in
1272 ///    a 128-bit vector of [4 x i32]. The upper four elements of the input
1273 ///    vector are unused.
1274 ///
1275 /// \headerfile <x86intrin.h>
1276 ///
1277 /// This intrinsic corresponds to the <c> VPMOVSXWD / PMOVSXWD </c> instruction.
1278 ///
1279 /// \param __V
1280 ///    A 128-bit vector of [8 x i16]. The lower four 16-bit elements are
1281 ///    sign-extended to 32-bit values.
1282 /// \returns A 128-bit vector of [4 x i32] containing the sign-extended values.
1283 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi16_epi32(__m128i __V) {
1284   return (__m128i) __builtin_convertvector(
1285       __builtin_shufflevector((__v8hi)__V, (__v8hi)__V, 0, 1, 2, 3), __v4si);
1286 }
1287 
1288 /// Sign-extends each of the lower two 16-bit integer elements of a
1289 ///    128-bit integer vector of [8 x i16] to 64-bit values and returns them in
1290 ///    a 128-bit vector of [2 x i64]. The upper six elements of the input
1291 ///    vector are unused.
1292 ///
1293 /// \headerfile <x86intrin.h>
1294 ///
1295 /// This intrinsic corresponds to the <c> VPMOVSXWQ / PMOVSXWQ </c> instruction.
1296 ///
1297 /// \param __V
1298 ///    A 128-bit vector of [8 x i16]. The lower two 16-bit elements are
1299 ///     sign-extended to 64-bit values.
1300 /// \returns A 128-bit vector of [2 x i64] containing the sign-extended values.
1301 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi16_epi64(__m128i __V) {
1302   return (__m128i) __builtin_convertvector(
1303       __builtin_shufflevector((__v8hi)__V, (__v8hi)__V, 0, 1), __v2di);
1304 }
1305 
1306 /// Sign-extends each of the lower two 32-bit integer elements of a
1307 ///    128-bit integer vector of [4 x i32] to 64-bit values and returns them in
1308 ///    a 128-bit vector of [2 x i64]. The upper two elements of the input vector
1309 ///    are unused.
1310 ///
1311 /// \headerfile <x86intrin.h>
1312 ///
1313 /// This intrinsic corresponds to the <c> VPMOVSXDQ / PMOVSXDQ </c> instruction.
1314 ///
1315 /// \param __V
1316 ///    A 128-bit vector of [4 x i32]. The lower two 32-bit elements are
1317 ///    sign-extended to 64-bit values.
1318 /// \returns A 128-bit vector of [2 x i64] containing the sign-extended values.
1319 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepi32_epi64(__m128i __V) {
1320   return (__m128i) __builtin_convertvector(
1321       __builtin_shufflevector((__v4si)__V, (__v4si)__V, 0, 1), __v2di);
1322 }
1323 
1324 /* SSE4 Packed Integer Zero-Extension.  */
1325 /// Zero-extends each of the lower eight 8-bit integer elements of a
1326 ///    128-bit vector of [16 x i8] to 16-bit values and returns them in a
1327 ///    128-bit vector of [8 x i16]. The upper eight elements of the input vector
1328 ///    are unused.
1329 ///
1330 /// \headerfile <x86intrin.h>
1331 ///
1332 /// This intrinsic corresponds to the <c> VPMOVZXBW / PMOVZXBW </c> instruction.
1333 ///
1334 /// \param __V
1335 ///    A 128-bit vector of [16 x i8]. The lower eight 8-bit elements are
1336 ///    zero-extended to 16-bit values.
1337 /// \returns A 128-bit vector of [8 x i16] containing the zero-extended values.
1338 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu8_epi16(__m128i __V) {
1339   return (__m128i) __builtin_convertvector(
1340       __builtin_shufflevector((__v16qu)__V, (__v16qu)__V, 0, 1, 2, 3, 4, 5, 6,
1341                               7),
1342       __v8hi);
1343 }
1344 
1345 /// Zero-extends each of the lower four 8-bit integer elements of a
1346 ///    128-bit vector of [16 x i8] to 32-bit values and returns them in a
1347 ///    128-bit vector of [4 x i32]. The upper twelve elements of the input
1348 ///    vector are unused.
1349 ///
1350 /// \headerfile <x86intrin.h>
1351 ///
1352 /// This intrinsic corresponds to the <c> VPMOVZXBD / PMOVZXBD </c> instruction.
1353 ///
1354 /// \param __V
1355 ///    A 128-bit vector of [16 x i8]. The lower four 8-bit elements are
1356 ///    zero-extended to 32-bit values.
1357 /// \returns A 128-bit vector of [4 x i32] containing the zero-extended values.
1358 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu8_epi32(__m128i __V) {
1359   return (__m128i) __builtin_convertvector(
1360       __builtin_shufflevector((__v16qu)__V, (__v16qu)__V, 0, 1, 2, 3), __v4si);
1361 }
1362 
1363 /// Zero-extends each of the lower two 8-bit integer elements of a
1364 ///    128-bit integer vector of [16 x i8] to 64-bit values and returns them in
1365 ///    a 128-bit vector of [2 x i64]. The upper fourteen elements of the input
1366 ///    vector are unused.
1367 ///
1368 /// \headerfile <x86intrin.h>
1369 ///
1370 /// This intrinsic corresponds to the <c> VPMOVZXBQ / PMOVZXBQ </c> instruction.
1371 ///
1372 /// \param __V
1373 ///    A 128-bit vector of [16 x i8]. The lower two 8-bit elements are
1374 ///    zero-extended to 64-bit values.
1375 /// \returns A 128-bit vector of [2 x i64] containing the zero-extended values.
1376 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu8_epi64(__m128i __V) {
1377   return (__m128i) __builtin_convertvector(
1378       __builtin_shufflevector((__v16qu)__V, (__v16qu)__V, 0, 1), __v2di);
1379 }
1380 
1381 /// Zero-extends each of the lower four 16-bit integer elements of a
1382 ///    128-bit integer vector of [8 x i16] to 32-bit values and returns them in
1383 ///    a 128-bit vector of [4 x i32]. The upper four elements of the input
1384 ///    vector are unused.
1385 ///
1386 /// \headerfile <x86intrin.h>
1387 ///
1388 /// This intrinsic corresponds to the <c> VPMOVZXWD / PMOVZXWD </c> instruction.
1389 ///
1390 /// \param __V
1391 ///    A 128-bit vector of [8 x i16]. The lower four 16-bit elements are
1392 ///    zero-extended to 32-bit values.
1393 /// \returns A 128-bit vector of [4 x i32] containing the zero-extended values.
1394 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu16_epi32(__m128i __V) {
1395   return (__m128i) __builtin_convertvector(
1396       __builtin_shufflevector((__v8hu)__V, (__v8hu)__V, 0, 1, 2, 3), __v4si);
1397 }
1398 
1399 /// Zero-extends each of the lower two 16-bit integer elements of a
1400 ///    128-bit integer vector of [8 x i16] to 64-bit values and returns them in
1401 ///    a 128-bit vector of [2 x i64]. The upper six elements of the input vector
1402 ///    are unused.
1403 ///
1404 /// \headerfile <x86intrin.h>
1405 ///
1406 /// This intrinsic corresponds to the <c> VPMOVZXWQ / PMOVZXWQ </c> instruction.
1407 ///
1408 /// \param __V
1409 ///    A 128-bit vector of [8 x i16]. The lower two 16-bit elements are
1410 ///    zero-extended to 64-bit values.
1411 /// \returns A 128-bit vector of [2 x i64] containing the zero-extended values.
1412 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu16_epi64(__m128i __V) {
1413   return (__m128i) __builtin_convertvector(
1414       __builtin_shufflevector((__v8hu)__V, (__v8hu)__V, 0, 1), __v2di);
1415 }
1416 
1417 /// Zero-extends each of the lower two 32-bit integer elements of a
1418 ///    128-bit integer vector of [4 x i32] to 64-bit values and returns them in
1419 ///    a 128-bit vector of [2 x i64]. The upper two elements of the input vector
1420 ///    are unused.
1421 ///
1422 /// \headerfile <x86intrin.h>
1423 ///
1424 /// This intrinsic corresponds to the <c> VPMOVZXDQ / PMOVZXDQ </c> instruction.
1425 ///
1426 /// \param __V
1427 ///    A 128-bit vector of [4 x i32]. The lower two 32-bit elements are
1428 ///    zero-extended to 64-bit values.
1429 /// \returns A 128-bit vector of [2 x i64] containing the zero-extended values.
1430 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtepu32_epi64(__m128i __V) {
1431   return (__m128i) __builtin_convertvector(
1432       __builtin_shufflevector((__v4su)__V, (__v4su)__V, 0, 1), __v2di);
1433 }
1434 
1435 /* SSE4 Pack with Unsigned Saturation.  */
1436 /// Converts, with saturation, 32-bit signed integers from both 128-bit integer
1437 ///    vector operands into 16-bit unsigned integers, and returns the packed
1438 ///    result.
1439 ///
1440 ///    Values greater than 0xFFFF are saturated to 0xFFFF. Values less than
1441 ///    0x0000 are saturated to 0x0000.
1442 ///
1443 /// \headerfile <x86intrin.h>
1444 ///
1445 /// This intrinsic corresponds to the <c> VPACKUSDW / PACKUSDW </c> instruction.
1446 ///
1447 /// \param __V1
1448 ///    A 128-bit vector of [4 x i32]. The converted [4 x i16] values are
1449 ///    written to the lower 64 bits of the result.
1450 /// \param __V2
1451 ///    A 128-bit vector of [4 x i32]. The converted [4 x i16] values are
1452 ///    written to the higher 64 bits of the result.
1453 /// \returns A 128-bit vector of [8 x i16] containing the converted values.
1454 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_packus_epi32(__m128i __V1,
1455                                                               __m128i __V2) {
1456   return (__m128i)__builtin_ia32_packusdw128((__v4si)__V1, (__v4si)__V2);
1457 }
1458 
1459 /* SSE4 Multiple Packed Sums of Absolute Difference.  */
1460 /// Subtracts 8-bit unsigned integer values and computes the absolute
1461 ///    values of the differences to the corresponding bits in the destination.
1462 ///    Then sums of the absolute differences are returned according to the bit
1463 ///    fields in the immediate operand.
1464 ///
1465 /// \headerfile <x86intrin.h>
1466 ///
1467 /// \code
1468 /// __m128i _mm_mpsadbw_epu8(__m128i X, __m128i Y, const int M);
1469 /// \endcode
1470 ///
1471 /// This intrinsic corresponds to the <c> VMPSADBW / MPSADBW </c> instruction.
1472 ///
1473 /// \param X
1474 ///    A 128-bit vector of [16 x i8].
1475 /// \param Y
1476 ///    A 128-bit vector of [16 x i8].
1477 /// \param M
1478 ///    An 8-bit immediate operand specifying how the absolute differences are to
1479 ///    be calculated, according to the following algorithm:
1480 ///    \code
1481 ///    // M2 represents bit 2 of the immediate operand
1482 ///    // M10 represents bits [1:0] of the immediate operand
1483 ///    i = M2 * 4;
1484 ///    j = M10 * 4;
1485 ///    for (k = 0; k < 8; k = k + 1) {
1486 ///      d0 = abs(X[i + k + 0] - Y[j + 0]);
1487 ///      d1 = abs(X[i + k + 1] - Y[j + 1]);
1488 ///      d2 = abs(X[i + k + 2] - Y[j + 2]);
1489 ///      d3 = abs(X[i + k + 3] - Y[j + 3]);
1490 ///      r[k] = d0 + d1 + d2 + d3;
1491 ///    }
1492 ///    \endcode
1493 /// \returns A 128-bit integer vector containing the sums of the sets of
1494 ///    absolute differences between both operands.
1495 #define _mm_mpsadbw_epu8(X, Y, M)                                              \
1496   ((__m128i)__builtin_ia32_mpsadbw128((__v16qi)(__m128i)(X),                   \
1497                                       (__v16qi)(__m128i)(Y), (M)))
1498 
1499 /// Finds the minimum unsigned 16-bit element in the input 128-bit
1500 ///    vector of [8 x u16] and returns it and along with its index.
1501 ///
1502 /// \headerfile <x86intrin.h>
1503 ///
1504 /// This intrinsic corresponds to the <c> VPHMINPOSUW / PHMINPOSUW </c>
1505 /// instruction.
1506 ///
1507 /// \param __V
1508 ///    A 128-bit vector of [8 x u16].
1509 /// \returns A 128-bit value where bits [15:0] contain the minimum value found
1510 ///    in parameter \a __V, bits [18:16] contain the index of the minimum value
1511 ///    and the remaining bits are set to 0.
1512 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_minpos_epu16(__m128i __V) {
1513   return (__m128i)__builtin_ia32_phminposuw128((__v8hi)__V);
1514 }
1515 
1516 /* Handle the sse4.2 definitions here. */
1517 
1518 /* These definitions are normally in nmmintrin.h, but gcc puts them in here
1519    so we'll do the same.  */
1520 
1521 #undef __DEFAULT_FN_ATTRS
1522 #define __DEFAULT_FN_ATTRS                                                     \
1523   __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
1524 
1525 /* These specify the type of data that we're comparing.  */
1526 #define _SIDD_UBYTE_OPS 0x00
1527 #define _SIDD_UWORD_OPS 0x01
1528 #define _SIDD_SBYTE_OPS 0x02
1529 #define _SIDD_SWORD_OPS 0x03
1530 
1531 /* These specify the type of comparison operation.  */
1532 #define _SIDD_CMP_EQUAL_ANY 0x00
1533 #define _SIDD_CMP_RANGES 0x04
1534 #define _SIDD_CMP_EQUAL_EACH 0x08
1535 #define _SIDD_CMP_EQUAL_ORDERED 0x0c
1536 
1537 /* These macros specify the polarity of the operation.  */
1538 #define _SIDD_POSITIVE_POLARITY 0x00
1539 #define _SIDD_NEGATIVE_POLARITY 0x10
1540 #define _SIDD_MASKED_POSITIVE_POLARITY 0x20
1541 #define _SIDD_MASKED_NEGATIVE_POLARITY 0x30
1542 
1543 /* These macros are used in _mm_cmpXstri() to specify the return.  */
1544 #define _SIDD_LEAST_SIGNIFICANT 0x00
1545 #define _SIDD_MOST_SIGNIFICANT 0x40
1546 
1547 /* These macros are used in _mm_cmpXstri() to specify the return.  */
1548 #define _SIDD_BIT_MASK 0x00
1549 #define _SIDD_UNIT_MASK 0x40
1550 
1551 /* SSE4.2 Packed Comparison Intrinsics.  */
1552 /// Uses the immediate operand \a M to perform a comparison of string
1553 ///    data with implicitly defined lengths that is contained in source operands
1554 ///    \a A and \a B. Returns a 128-bit integer vector representing the result
1555 ///    mask of the comparison.
1556 ///
1557 /// \headerfile <x86intrin.h>
1558 ///
1559 /// \code
1560 /// __m128i _mm_cmpistrm(__m128i A, __m128i B, const int M);
1561 /// \endcode
1562 ///
1563 /// This intrinsic corresponds to the <c> VPCMPISTRM / PCMPISTRM </c>
1564 /// instruction.
1565 ///
1566 /// \param A
1567 ///    A 128-bit integer vector containing one of the source operands to be
1568 ///    compared.
1569 /// \param B
1570 ///    A 128-bit integer vector containing one of the source operands to be
1571 ///    compared.
1572 /// \param M
1573 ///    An 8-bit immediate operand specifying whether the characters are bytes or
1574 ///    words, the type of comparison to perform, and the format of the return
1575 ///    value. \n
1576 ///    Bits [1:0]: Determine source data format. \n
1577 ///      00: 16 unsigned bytes \n
1578 ///      01: 8 unsigned words \n
1579 ///      10: 16 signed bytes \n
1580 ///      11: 8 signed words \n
1581 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
1582 ///      00: Subset: Each character in \a B is compared for equality with all
1583 ///          the characters in \a A. \n
1584 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
1585 ///          basis is greater than or equal for even-indexed elements in \a A,
1586 ///          and less than or equal for odd-indexed elements in \a A. \n
1587 ///      10: Match: Compare each pair of corresponding characters in \a A and
1588 ///          \a B for equality. \n
1589 ///      11: Substring: Search \a B for substring matches of \a A. \n
1590 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
1591 ///                mask of the comparison results. \n
1592 ///      00: No effect. \n
1593 ///      01: Negate the bit mask. \n
1594 ///      10: No effect. \n
1595 ///      11: Negate the bit mask only for bits with an index less than or equal
1596 ///          to the size of \a A or \a B. \n
1597 ///    Bit [6]: Determines whether the result is zero-extended or expanded to 16
1598 ///             bytes. \n
1599 ///      0: The result is zero-extended to 16 bytes. \n
1600 ///      1: The result is expanded to 16 bytes (this expansion is performed by
1601 ///         repeating each bit 8 or 16 times).
1602 /// \returns Returns a 128-bit integer vector representing the result mask of
1603 ///    the comparison.
1604 #define _mm_cmpistrm(A, B, M)                                                  \
1605   ((__m128i)__builtin_ia32_pcmpistrm128((__v16qi)(__m128i)(A),                 \
1606                                         (__v16qi)(__m128i)(B), (int)(M)))
1607 
1608 /// Uses the immediate operand \a M to perform a comparison of string
1609 ///    data with implicitly defined lengths that is contained in source operands
1610 ///    \a A and \a B. Returns an integer representing the result index of the
1611 ///    comparison.
1612 ///
1613 /// \headerfile <x86intrin.h>
1614 ///
1615 /// \code
1616 /// int _mm_cmpistri(__m128i A, __m128i B, const int M);
1617 /// \endcode
1618 ///
1619 /// This intrinsic corresponds to the <c> VPCMPISTRI / PCMPISTRI </c>
1620 /// instruction.
1621 ///
1622 /// \param A
1623 ///    A 128-bit integer vector containing one of the source operands to be
1624 ///    compared.
1625 /// \param B
1626 ///    A 128-bit integer vector containing one of the source operands to be
1627 ///    compared.
1628 /// \param M
1629 ///    An 8-bit immediate operand specifying whether the characters are bytes or
1630 ///    words, the type of comparison to perform, and the format of the return
1631 ///    value. \n
1632 ///    Bits [1:0]: Determine source data format. \n
1633 ///      00: 16 unsigned bytes \n
1634 ///      01: 8 unsigned words \n
1635 ///      10: 16 signed bytes \n
1636 ///      11: 8 signed words \n
1637 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
1638 ///      00: Subset: Each character in \a B is compared for equality with all
1639 ///          the characters in \a A. \n
1640 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
1641 ///          basis is greater than or equal for even-indexed elements in \a A,
1642 ///          and less than or equal for odd-indexed elements in \a A. \n
1643 ///      10: Match: Compare each pair of corresponding characters in \a A and
1644 ///          \a B for equality. \n
1645 ///      11: Substring: Search B for substring matches of \a A. \n
1646 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
1647 ///                mask of the comparison results. \n
1648 ///      00: No effect. \n
1649 ///      01: Negate the bit mask. \n
1650 ///      10: No effect. \n
1651 ///      11: Negate the bit mask only for bits with an index less than or equal
1652 ///          to the size of \a A or \a B. \n
1653 ///    Bit [6]: Determines whether the index of the lowest set bit or the
1654 ///             highest set bit is returned. \n
1655 ///      0: The index of the least significant set bit. \n
1656 ///      1: The index of the most significant set bit. \n
1657 /// \returns Returns an integer representing the result index of the comparison.
1658 #define _mm_cmpistri(A, B, M)                                                  \
1659   ((int)__builtin_ia32_pcmpistri128((__v16qi)(__m128i)(A),                     \
1660                                     (__v16qi)(__m128i)(B), (int)(M)))
1661 
1662 /// Uses the immediate operand \a M to perform a comparison of string
1663 ///    data with explicitly defined lengths that is contained in source operands
1664 ///    \a A and \a B. Returns a 128-bit integer vector representing the result
1665 ///    mask of the comparison.
1666 ///
1667 /// \headerfile <x86intrin.h>
1668 ///
1669 /// \code
1670 /// __m128i _mm_cmpestrm(__m128i A, int LA, __m128i B, int LB, const int M);
1671 /// \endcode
1672 ///
1673 /// This intrinsic corresponds to the <c> VPCMPESTRM / PCMPESTRM </c>
1674 /// instruction.
1675 ///
1676 /// \param A
1677 ///    A 128-bit integer vector containing one of the source operands to be
1678 ///    compared.
1679 /// \param LA
1680 ///    An integer that specifies the length of the string in \a A.
1681 /// \param B
1682 ///    A 128-bit integer vector containing one of the source operands to be
1683 ///    compared.
1684 /// \param LB
1685 ///    An integer that specifies the length of the string in \a B.
1686 /// \param M
1687 ///    An 8-bit immediate operand specifying whether the characters are bytes or
1688 ///    words, the type of comparison to perform, and the format of the return
1689 ///    value. \n
1690 ///    Bits [1:0]: Determine source data format. \n
1691 ///      00: 16 unsigned bytes \n
1692 ///      01: 8 unsigned words \n
1693 ///      10: 16 signed bytes \n
1694 ///      11: 8 signed words \n
1695 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
1696 ///      00: Subset: Each character in \a B is compared for equality with all
1697 ///          the characters in \a A. \n
1698 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
1699 ///          basis is greater than or equal for even-indexed elements in \a A,
1700 ///          and less than or equal for odd-indexed elements in \a A. \n
1701 ///      10: Match: Compare each pair of corresponding characters in \a A and
1702 ///          \a B for equality. \n
1703 ///      11: Substring: Search \a B for substring matches of \a A. \n
1704 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
1705 ///                mask of the comparison results. \n
1706 ///      00: No effect. \n
1707 ///      01: Negate the bit mask. \n
1708 ///      10: No effect. \n
1709 ///      11: Negate the bit mask only for bits with an index less than or equal
1710 ///          to the size of \a A or \a B. \n
1711 ///    Bit [6]: Determines whether the result is zero-extended or expanded to 16
1712 ///             bytes. \n
1713 ///      0: The result is zero-extended to 16 bytes. \n
1714 ///      1: The result is expanded to 16 bytes (this expansion is performed by
1715 ///         repeating each bit 8 or 16 times). \n
1716 /// \returns Returns a 128-bit integer vector representing the result mask of
1717 ///    the comparison.
1718 #define _mm_cmpestrm(A, LA, B, LB, M)                                          \
1719   ((__m128i)__builtin_ia32_pcmpestrm128((__v16qi)(__m128i)(A), (int)(LA),      \
1720                                         (__v16qi)(__m128i)(B), (int)(LB),      \
1721                                         (int)(M)))
1722 
1723 /// Uses the immediate operand \a M to perform a comparison of string
1724 ///    data with explicitly defined lengths that is contained in source operands
1725 ///    \a A and \a B. Returns an integer representing the result index of the
1726 ///    comparison.
1727 ///
1728 /// \headerfile <x86intrin.h>
1729 ///
1730 /// \code
1731 /// int _mm_cmpestri(__m128i A, int LA, __m128i B, int LB, const int M);
1732 /// \endcode
1733 ///
1734 /// This intrinsic corresponds to the <c> VPCMPESTRI / PCMPESTRI </c>
1735 /// instruction.
1736 ///
1737 /// \param A
1738 ///    A 128-bit integer vector containing one of the source operands to be
1739 ///    compared.
1740 /// \param LA
1741 ///    An integer that specifies the length of the string in \a A.
1742 /// \param B
1743 ///    A 128-bit integer vector containing one of the source operands to be
1744 ///    compared.
1745 /// \param LB
1746 ///    An integer that specifies the length of the string in \a B.
1747 /// \param M
1748 ///    An 8-bit immediate operand specifying whether the characters are bytes or
1749 ///    words, the type of comparison to perform, and the format of the return
1750 ///    value. \n
1751 ///    Bits [1:0]: Determine source data format. \n
1752 ///      00: 16 unsigned bytes \n
1753 ///      01: 8 unsigned words \n
1754 ///      10: 16 signed bytes \n
1755 ///      11: 8 signed words \n
1756 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
1757 ///      00: Subset: Each character in \a B is compared for equality with all
1758 ///          the characters in \a A. \n
1759 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
1760 ///          basis is greater than or equal for even-indexed elements in \a A,
1761 ///          and less than or equal for odd-indexed elements in \a A. \n
1762 ///      10: Match: Compare each pair of corresponding characters in \a A and
1763 ///          \a B for equality. \n
1764 ///      11: Substring: Search B for substring matches of \a A. \n
1765 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
1766 ///                mask of the comparison results. \n
1767 ///      00: No effect. \n
1768 ///      01: Negate the bit mask. \n
1769 ///      10: No effect. \n
1770 ///      11: Negate the bit mask only for bits with an index less than or equal
1771 ///          to the size of \a A or \a B. \n
1772 ///    Bit [6]: Determines whether the index of the lowest set bit or the
1773 ///             highest set bit is returned. \n
1774 ///      0: The index of the least significant set bit. \n
1775 ///      1: The index of the most significant set bit. \n
1776 /// \returns Returns an integer representing the result index of the comparison.
1777 #define _mm_cmpestri(A, LA, B, LB, M)                                          \
1778   ((int)__builtin_ia32_pcmpestri128((__v16qi)(__m128i)(A), (int)(LA),          \
1779                                     (__v16qi)(__m128i)(B), (int)(LB),          \
1780                                     (int)(M)))
1781 
1782 /* SSE4.2 Packed Comparison Intrinsics and EFlag Reading.  */
1783 /// Uses the immediate operand \a M to perform a comparison of string
1784 ///    data with implicitly defined lengths that is contained in source operands
1785 ///    \a A and \a B. Returns 1 if the bit mask is zero and the length of the
1786 ///    string in \a B is the maximum, otherwise, returns 0.
1787 ///
1788 /// \headerfile <x86intrin.h>
1789 ///
1790 /// \code
1791 /// int _mm_cmpistra(__m128i A, __m128i B, const int M);
1792 /// \endcode
1793 ///
1794 /// This intrinsic corresponds to the <c> VPCMPISTRI / PCMPISTRI </c>
1795 /// instruction.
1796 ///
1797 /// \param A
1798 ///    A 128-bit integer vector containing one of the source operands to be
1799 ///    compared.
1800 /// \param B
1801 ///    A 128-bit integer vector containing one of the source operands to be
1802 ///    compared.
1803 /// \param M
1804 ///    An 8-bit immediate operand specifying whether the characters are bytes or
1805 ///    words and the type of comparison to perform. \n
1806 ///    Bits [1:0]: Determine source data format. \n
1807 ///      00: 16 unsigned bytes \n
1808 ///      01: 8 unsigned words \n
1809 ///      10: 16 signed bytes \n
1810 ///      11: 8 signed words \n
1811 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
1812 ///      00: Subset: Each character in \a B is compared for equality with all
1813 ///          the characters in \a A. \n
1814 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
1815 ///          basis is greater than or equal for even-indexed elements in \a A,
1816 ///          and less than or equal for odd-indexed elements in \a A. \n
1817 ///      10: Match: Compare each pair of corresponding characters in \a A and
1818 ///          \a B for equality. \n
1819 ///      11: Substring: Search \a B for substring matches of \a A. \n
1820 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
1821 ///                mask of the comparison results. \n
1822 ///      00: No effect. \n
1823 ///      01: Negate the bit mask. \n
1824 ///      10: No effect. \n
1825 ///      11: Negate the bit mask only for bits with an index less than or equal
1826 ///          to the size of \a A or \a B. \n
1827 /// \returns Returns 1 if the bit mask is zero and the length of the string in
1828 ///    \a B is the maximum; otherwise, returns 0.
1829 #define _mm_cmpistra(A, B, M)                                                  \
1830   ((int)__builtin_ia32_pcmpistria128((__v16qi)(__m128i)(A),                    \
1831                                      (__v16qi)(__m128i)(B), (int)(M)))
1832 
1833 /// Uses the immediate operand \a M to perform a comparison of string
1834 ///    data with implicitly defined lengths that is contained in source operands
1835 ///    \a A and \a B. Returns 1 if the bit mask is non-zero, otherwise, returns
1836 ///    0.
1837 ///
1838 /// \headerfile <x86intrin.h>
1839 ///
1840 /// \code
1841 /// int _mm_cmpistrc(__m128i A, __m128i B, const int M);
1842 /// \endcode
1843 ///
1844 /// This intrinsic corresponds to the <c> VPCMPISTRI / PCMPISTRI </c>
1845 /// instruction.
1846 ///
1847 /// \param A
1848 ///    A 128-bit integer vector containing one of the source operands to be
1849 ///    compared.
1850 /// \param B
1851 ///    A 128-bit integer vector containing one of the source operands to be
1852 ///    compared.
1853 /// \param M
1854 ///    An 8-bit immediate operand specifying whether the characters are bytes or
1855 ///    words and the type of comparison to perform. \n
1856 ///    Bits [1:0]: Determine source data format. \n
1857 ///      00: 16 unsigned bytes \n
1858 ///      01: 8 unsigned words \n
1859 ///      10: 16 signed bytes \n
1860 ///      11: 8 signed words \n
1861 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
1862 ///      00: Subset: Each character in \a B is compared for equality with all
1863 ///          the characters in \a A. \n
1864 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
1865 ///          basis is greater than or equal for even-indexed elements in \a A,
1866 ///          and less than or equal for odd-indexed elements in \a A. \n
1867 ///      10: Match: Compare each pair of corresponding characters in \a A and
1868 ///          \a B for equality. \n
1869 ///      11: Substring: Search B for substring matches of \a A. \n
1870 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
1871 ///                mask of the comparison results. \n
1872 ///      00: No effect. \n
1873 ///      01: Negate the bit mask. \n
1874 ///      10: No effect. \n
1875 ///      11: Negate the bit mask only for bits with an index less than or equal
1876 ///          to the size of \a A or \a B.
1877 /// \returns Returns 1 if the bit mask is non-zero, otherwise, returns 0.
1878 #define _mm_cmpistrc(A, B, M)                                                  \
1879   ((int)__builtin_ia32_pcmpistric128((__v16qi)(__m128i)(A),                    \
1880                                      (__v16qi)(__m128i)(B), (int)(M)))
1881 
1882 /// Uses the immediate operand \a M to perform a comparison of string
1883 ///    data with implicitly defined lengths that is contained in source operands
1884 ///    \a A and \a B. Returns bit 0 of the resulting bit mask.
1885 ///
1886 /// \headerfile <x86intrin.h>
1887 ///
1888 /// \code
1889 /// int _mm_cmpistro(__m128i A, __m128i B, const int M);
1890 /// \endcode
1891 ///
1892 /// This intrinsic corresponds to the <c> VPCMPISTRI / PCMPISTRI </c>
1893 /// instruction.
1894 ///
1895 /// \param A
1896 ///    A 128-bit integer vector containing one of the source operands to be
1897 ///    compared.
1898 /// \param B
1899 ///    A 128-bit integer vector containing one of the source operands to be
1900 ///    compared.
1901 /// \param M
1902 ///    An 8-bit immediate operand specifying whether the characters are bytes or
1903 ///    words and the type of comparison to perform. \n
1904 ///    Bits [1:0]: Determine source data format. \n
1905 ///      00: 16 unsigned bytes \n
1906 ///      01: 8 unsigned words \n
1907 ///      10: 16 signed bytes \n
1908 ///      11: 8 signed words \n
1909 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
1910 ///      00: Subset: Each character in \a B is compared for equality with all
1911 ///          the characters in \a A. \n
1912 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
1913 ///          basis is greater than or equal for even-indexed elements in \a A,
1914 ///          and less than or equal for odd-indexed elements in \a A. \n
1915 ///      10: Match: Compare each pair of corresponding characters in \a A and
1916 ///          \a B for equality. \n
1917 ///      11: Substring: Search B for substring matches of \a A. \n
1918 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
1919 ///                mask of the comparison results. \n
1920 ///      00: No effect. \n
1921 ///      01: Negate the bit mask. \n
1922 ///      10: No effect. \n
1923 ///      11: Negate the bit mask only for bits with an index less than or equal
1924 ///          to the size of \a A or \a B. \n
1925 /// \returns Returns bit 0 of the resulting bit mask.
1926 #define _mm_cmpistro(A, B, M)                                                  \
1927   ((int)__builtin_ia32_pcmpistrio128((__v16qi)(__m128i)(A),                    \
1928                                      (__v16qi)(__m128i)(B), (int)(M)))
1929 
1930 /// Uses the immediate operand \a M to perform a comparison of string
1931 ///    data with implicitly defined lengths that is contained in source operands
1932 ///    \a A and \a B. Returns 1 if the length of the string in \a A is less than
1933 ///    the maximum, otherwise, returns 0.
1934 ///
1935 /// \headerfile <x86intrin.h>
1936 ///
1937 /// \code
1938 /// int _mm_cmpistrs(__m128i A, __m128i B, const int M);
1939 /// \endcode
1940 ///
1941 /// This intrinsic corresponds to the <c> VPCMPISTRI / PCMPISTRI </c>
1942 /// instruction.
1943 ///
1944 /// \param A
1945 ///    A 128-bit integer vector containing one of the source operands to be
1946 ///    compared.
1947 /// \param B
1948 ///    A 128-bit integer vector containing one of the source operands to be
1949 ///    compared.
1950 /// \param M
1951 ///    An 8-bit immediate operand specifying whether the characters are bytes or
1952 ///    words and the type of comparison to perform. \n
1953 ///    Bits [1:0]: Determine source data format. \n
1954 ///      00: 16 unsigned bytes \n
1955 ///      01: 8 unsigned words \n
1956 ///      10: 16 signed bytes \n
1957 ///      11: 8 signed words \n
1958 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
1959 ///      00: Subset: Each character in \a B is compared for equality with all
1960 ///          the characters in \a A. \n
1961 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
1962 ///          basis is greater than or equal for even-indexed elements in \a A,
1963 ///          and less than or equal for odd-indexed elements in \a A. \n
1964 ///      10: Match: Compare each pair of corresponding characters in \a A and
1965 ///          \a B for equality. \n
1966 ///      11: Substring: Search \a B for substring matches of \a A. \n
1967 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
1968 ///                mask of the comparison results. \n
1969 ///      00: No effect. \n
1970 ///      01: Negate the bit mask. \n
1971 ///      10: No effect. \n
1972 ///      11: Negate the bit mask only for bits with an index less than or equal
1973 ///          to the size of \a A or \a B. \n
1974 /// \returns Returns 1 if the length of the string in \a A is less than the
1975 ///    maximum, otherwise, returns 0.
1976 #define _mm_cmpistrs(A, B, M)                                                  \
1977   ((int)__builtin_ia32_pcmpistris128((__v16qi)(__m128i)(A),                    \
1978                                      (__v16qi)(__m128i)(B), (int)(M)))
1979 
1980 /// Uses the immediate operand \a M to perform a comparison of string
1981 ///    data with implicitly defined lengths that is contained in source operands
1982 ///    \a A and \a B. Returns 1 if the length of the string in \a B is less than
1983 ///    the maximum, otherwise, returns 0.
1984 ///
1985 /// \headerfile <x86intrin.h>
1986 ///
1987 /// \code
1988 /// int _mm_cmpistrz(__m128i A, __m128i B, const int M);
1989 /// \endcode
1990 ///
1991 /// This intrinsic corresponds to the <c> VPCMPISTRI / PCMPISTRI </c>
1992 /// instruction.
1993 ///
1994 /// \param A
1995 ///    A 128-bit integer vector containing one of the source operands to be
1996 ///    compared.
1997 /// \param B
1998 ///    A 128-bit integer vector containing one of the source operands to be
1999 ///    compared.
2000 /// \param M
2001 ///    An 8-bit immediate operand specifying whether the characters are bytes or
2002 ///    words and the type of comparison to perform. \n
2003 ///    Bits [1:0]: Determine source data format. \n
2004 ///      00: 16 unsigned bytes \n
2005 ///      01: 8 unsigned words \n
2006 ///      10: 16 signed bytes \n
2007 ///      11: 8 signed words \n
2008 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
2009 ///      00: Subset: Each character in \a B is compared for equality with all
2010 ///          the characters in \a A. \n
2011 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
2012 ///          basis is greater than or equal for even-indexed elements in \a A,
2013 ///          and less than or equal for odd-indexed elements in \a A. \n
2014 ///      10: Match: Compare each pair of corresponding characters in \a A and
2015 ///          \a B for equality. \n
2016 ///      11: Substring: Search \a B for substring matches of \a A. \n
2017 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
2018 ///                mask of the comparison results. \n
2019 ///      00: No effect. \n
2020 ///      01: Negate the bit mask. \n
2021 ///      10: No effect. \n
2022 ///      11: Negate the bit mask only for bits with an index less than or equal
2023 ///          to the size of \a A or \a B.
2024 /// \returns Returns 1 if the length of the string in \a B is less than the
2025 ///    maximum, otherwise, returns 0.
2026 #define _mm_cmpistrz(A, B, M)                                                  \
2027   ((int)__builtin_ia32_pcmpistriz128((__v16qi)(__m128i)(A),                    \
2028                                      (__v16qi)(__m128i)(B), (int)(M)))
2029 
2030 /// Uses the immediate operand \a M to perform a comparison of string
2031 ///    data with explicitly defined lengths that is contained in source operands
2032 ///    \a A and \a B. Returns 1 if the bit mask is zero and the length of the
2033 ///    string in \a B is the maximum, otherwise, returns 0.
2034 ///
2035 /// \headerfile <x86intrin.h>
2036 ///
2037 /// \code
2038 /// int _mm_cmpestra(__m128i A, int LA, __m128i B, int LB, const int M);
2039 /// \endcode
2040 ///
2041 /// This intrinsic corresponds to the <c> VPCMPESTRI / PCMPESTRI </c>
2042 /// instruction.
2043 ///
2044 /// \param A
2045 ///    A 128-bit integer vector containing one of the source operands to be
2046 ///    compared.
2047 /// \param LA
2048 ///    An integer that specifies the length of the string in \a A.
2049 /// \param B
2050 ///    A 128-bit integer vector containing one of the source operands to be
2051 ///    compared.
2052 /// \param LB
2053 ///    An integer that specifies the length of the string in \a B.
2054 /// \param M
2055 ///    An 8-bit immediate operand specifying whether the characters are bytes or
2056 ///    words and the type of comparison to perform. \n
2057 ///    Bits [1:0]: Determine source data format. \n
2058 ///      00: 16 unsigned bytes \n
2059 ///      01: 8 unsigned words \n
2060 ///      10: 16 signed bytes \n
2061 ///      11: 8 signed words \n
2062 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
2063 ///      00: Subset: Each character in \a B is compared for equality with all
2064 ///          the characters in \a A. \n
2065 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
2066 ///          basis is greater than or equal for even-indexed elements in \a A,
2067 ///          and less than or equal for odd-indexed elements in \a A. \n
2068 ///      10: Match: Compare each pair of corresponding characters in \a A and
2069 ///          \a B for equality. \n
2070 ///      11: Substring: Search \a B for substring matches of \a A. \n
2071 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
2072 ///                mask of the comparison results. \n
2073 ///      00: No effect. \n
2074 ///      01: Negate the bit mask. \n
2075 ///      10: No effect. \n
2076 ///      11: Negate the bit mask only for bits with an index less than or equal
2077 ///          to the size of \a A or \a B.
2078 /// \returns Returns 1 if the bit mask is zero and the length of the string in
2079 ///    \a B is the maximum, otherwise, returns 0.
2080 #define _mm_cmpestra(A, LA, B, LB, M)                                          \
2081   ((int)__builtin_ia32_pcmpestria128((__v16qi)(__m128i)(A), (int)(LA),         \
2082                                      (__v16qi)(__m128i)(B), (int)(LB),         \
2083                                      (int)(M)))
2084 
2085 /// Uses the immediate operand \a M to perform a comparison of string
2086 ///    data with explicitly defined lengths that is contained in source operands
2087 ///    \a A and \a B. Returns 1 if the resulting mask is non-zero, otherwise,
2088 ///    returns 0.
2089 ///
2090 /// \headerfile <x86intrin.h>
2091 ///
2092 /// \code
2093 /// int _mm_cmpestrc(__m128i A, int LA, __m128i B, int LB, const int M);
2094 /// \endcode
2095 ///
2096 /// This intrinsic corresponds to the <c> VPCMPESTRI / PCMPESTRI </c>
2097 /// instruction.
2098 ///
2099 /// \param A
2100 ///    A 128-bit integer vector containing one of the source operands to be
2101 ///    compared.
2102 /// \param LA
2103 ///    An integer that specifies the length of the string in \a A.
2104 /// \param B
2105 ///    A 128-bit integer vector containing one of the source operands to be
2106 ///    compared.
2107 /// \param LB
2108 ///    An integer that specifies the length of the string in \a B.
2109 /// \param M
2110 ///    An 8-bit immediate operand specifying whether the characters are bytes or
2111 ///    words and the type of comparison to perform. \n
2112 ///    Bits [1:0]: Determine source data format. \n
2113 ///      00: 16 unsigned bytes \n
2114 ///      01: 8 unsigned words \n
2115 ///      10: 16 signed bytes \n
2116 ///      11: 8 signed words \n
2117 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
2118 ///      00: Subset: Each character in \a B is compared for equality with all
2119 ///          the characters in \a A. \n
2120 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
2121 ///          basis is greater than or equal for even-indexed elements in \a A,
2122 ///          and less than or equal for odd-indexed elements in \a A. \n
2123 ///      10: Match: Compare each pair of corresponding characters in \a A and
2124 ///          \a B for equality. \n
2125 ///      11: Substring: Search \a B for substring matches of \a A. \n
2126 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
2127 ///                mask of the comparison results. \n
2128 ///      00: No effect. \n
2129 ///      01: Negate the bit mask. \n
2130 ///      10: No effect. \n
2131 ///      11: Negate the bit mask only for bits with an index less than or equal
2132 ///          to the size of \a A or \a B. \n
2133 /// \returns Returns 1 if the resulting mask is non-zero, otherwise, returns 0.
2134 #define _mm_cmpestrc(A, LA, B, LB, M)                                          \
2135   ((int)__builtin_ia32_pcmpestric128((__v16qi)(__m128i)(A), (int)(LA),         \
2136                                      (__v16qi)(__m128i)(B), (int)(LB),         \
2137                                      (int)(M)))
2138 
2139 /// Uses the immediate operand \a M to perform a comparison of string
2140 ///    data with explicitly defined lengths that is contained in source operands
2141 ///    \a A and \a B. Returns bit 0 of the resulting bit mask.
2142 ///
2143 /// \headerfile <x86intrin.h>
2144 ///
2145 /// \code
2146 /// int _mm_cmpestro(__m128i A, int LA, __m128i B, int LB, const int M);
2147 /// \endcode
2148 ///
2149 /// This intrinsic corresponds to the <c> VPCMPESTRI / PCMPESTRI </c>
2150 /// instruction.
2151 ///
2152 /// \param A
2153 ///    A 128-bit integer vector containing one of the source operands to be
2154 ///    compared.
2155 /// \param LA
2156 ///    An integer that specifies the length of the string in \a A.
2157 /// \param B
2158 ///    A 128-bit integer vector containing one of the source operands to be
2159 ///    compared.
2160 /// \param LB
2161 ///    An integer that specifies the length of the string in \a B.
2162 /// \param M
2163 ///    An 8-bit immediate operand specifying whether the characters are bytes or
2164 ///    words and the type of comparison to perform. \n
2165 ///    Bits [1:0]: Determine source data format. \n
2166 ///      00: 16 unsigned bytes \n
2167 ///      01: 8 unsigned words \n
2168 ///      10: 16 signed bytes \n
2169 ///      11: 8 signed words \n
2170 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
2171 ///      00: Subset: Each character in \a B is compared for equality with all
2172 ///          the characters in \a A. \n
2173 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
2174 ///          basis is greater than or equal for even-indexed elements in \a A,
2175 ///          and less than or equal for odd-indexed elements in \a A. \n
2176 ///      10: Match: Compare each pair of corresponding characters in \a A and
2177 ///          \a B for equality. \n
2178 ///      11: Substring: Search \a B for substring matches of \a A. \n
2179 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
2180 ///                mask of the comparison results. \n
2181 ///      00: No effect. \n
2182 ///      01: Negate the bit mask. \n
2183 ///      10: No effect. \n
2184 ///      11: Negate the bit mask only for bits with an index less than or equal
2185 ///          to the size of \a A or \a B.
2186 /// \returns Returns bit 0 of the resulting bit mask.
2187 #define _mm_cmpestro(A, LA, B, LB, M)                                          \
2188   ((int)__builtin_ia32_pcmpestrio128((__v16qi)(__m128i)(A), (int)(LA),         \
2189                                      (__v16qi)(__m128i)(B), (int)(LB),         \
2190                                      (int)(M)))
2191 
2192 /// Uses the immediate operand \a M to perform a comparison of string
2193 ///    data with explicitly defined lengths that is contained in source operands
2194 ///    \a A and \a B. Returns 1 if the length of the string in \a A is less than
2195 ///    the maximum, otherwise, returns 0.
2196 ///
2197 /// \headerfile <x86intrin.h>
2198 ///
2199 /// \code
2200 /// int _mm_cmpestrs(__m128i A, int LA, __m128i B, int LB, const int M);
2201 /// \endcode
2202 ///
2203 /// This intrinsic corresponds to the <c> VPCMPESTRI / PCMPESTRI </c>
2204 /// instruction.
2205 ///
2206 /// \param A
2207 ///    A 128-bit integer vector containing one of the source operands to be
2208 ///    compared.
2209 /// \param LA
2210 ///    An integer that specifies the length of the string in \a A.
2211 /// \param B
2212 ///    A 128-bit integer vector containing one of the source operands to be
2213 ///    compared.
2214 /// \param LB
2215 ///    An integer that specifies the length of the string in \a B.
2216 /// \param M
2217 ///    An 8-bit immediate operand specifying whether the characters are bytes or
2218 ///    words and the type of comparison to perform. \n
2219 ///    Bits [1:0]: Determine source data format. \n
2220 ///      00: 16 unsigned bytes \n
2221 ///      01: 8 unsigned words \n
2222 ///      10: 16 signed bytes \n
2223 ///      11: 8 signed words \n
2224 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
2225 ///      00: Subset: Each character in \a B is compared for equality with all
2226 ///          the characters in \a A. \n
2227 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
2228 ///          basis is greater than or equal for even-indexed elements in \a A,
2229 ///          and less than or equal for odd-indexed elements in \a A. \n
2230 ///      10: Match: Compare each pair of corresponding characters in \a A and
2231 ///          \a B for equality. \n
2232 ///      11: Substring: Search \a B for substring matches of \a A. \n
2233 ///    Bits [5:4]: Determine whether to perform a one's complement in the bit
2234 ///                mask of the comparison results. \n
2235 ///      00: No effect. \n
2236 ///      01: Negate the bit mask. \n
2237 ///      10: No effect. \n
2238 ///      11: Negate the bit mask only for bits with an index less than or equal
2239 ///          to the size of \a A or \a B. \n
2240 /// \returns Returns 1 if the length of the string in \a A is less than the
2241 ///    maximum, otherwise, returns 0.
2242 #define _mm_cmpestrs(A, LA, B, LB, M)                                          \
2243   ((int)__builtin_ia32_pcmpestris128((__v16qi)(__m128i)(A), (int)(LA),         \
2244                                      (__v16qi)(__m128i)(B), (int)(LB),         \
2245                                      (int)(M)))
2246 
2247 /// Uses the immediate operand \a M to perform a comparison of string
2248 ///    data with explicitly defined lengths that is contained in source operands
2249 ///    \a A and \a B. Returns 1 if the length of the string in \a B is less than
2250 ///    the maximum, otherwise, returns 0.
2251 ///
2252 /// \headerfile <x86intrin.h>
2253 ///
2254 /// \code
2255 /// int _mm_cmpestrz(__m128i A, int LA, __m128i B, int LB, const int M);
2256 /// \endcode
2257 ///
2258 /// This intrinsic corresponds to the <c> VPCMPESTRI </c> instruction.
2259 ///
2260 /// \param A
2261 ///    A 128-bit integer vector containing one of the source operands to be
2262 ///    compared.
2263 /// \param LA
2264 ///    An integer that specifies the length of the string in \a A.
2265 /// \param B
2266 ///    A 128-bit integer vector containing one of the source operands to be
2267 ///    compared.
2268 /// \param LB
2269 ///    An integer that specifies the length of the string in \a B.
2270 /// \param M
2271 ///    An 8-bit immediate operand specifying whether the characters are bytes or
2272 ///    words and the type of comparison to perform. \n
2273 ///    Bits [1:0]: Determine source data format. \n
2274 ///      00: 16 unsigned bytes  \n
2275 ///      01: 8 unsigned words \n
2276 ///      10: 16 signed bytes \n
2277 ///      11: 8 signed words \n
2278 ///    Bits [3:2]: Determine comparison type and aggregation method. \n
2279 ///      00: Subset: Each character in \a B is compared for equality with all
2280 ///          the characters in \a A. \n
2281 ///      01: Ranges: Each character in \a B is compared to \a A. The comparison
2282 ///          basis is greater than or equal for even-indexed elements in \a A,
2283 ///          and less than or equal for odd-indexed elements in \a A. \n
2284 ///      10: Match: Compare each pair of corresponding characters in \a A and
2285 ///          \a B for equality. \n
2286 ///      11: Substring: Search \a B for substring matches of \a A. \n
2287 ///    Bits [5:4]: Determine whether to perform a one's complement on the bit
2288 ///                mask of the comparison results. \n
2289 ///      00: No effect. \n
2290 ///      01: Negate the bit mask. \n
2291 ///      10: No effect. \n
2292 ///      11: Negate the bit mask only for bits with an index less than or equal
2293 ///          to the size of \a A or \a B.
2294 /// \returns Returns 1 if the length of the string in \a B is less than the
2295 ///    maximum, otherwise, returns 0.
2296 #define _mm_cmpestrz(A, LA, B, LB, M)                                          \
2297   ((int)__builtin_ia32_pcmpestriz128((__v16qi)(__m128i)(A), (int)(LA),         \
2298                                      (__v16qi)(__m128i)(B), (int)(LB),         \
2299                                      (int)(M)))
2300 
2301 /* SSE4.2 Compare Packed Data -- Greater Than.  */
2302 /// Compares each of the corresponding 64-bit values of the 128-bit
2303 ///    integer vectors to determine if the values in the first operand are
2304 ///    greater than those in the second operand.
2305 ///
2306 ///    Each comparison returns 0x0 for false, 0xFFFFFFFFFFFFFFFF for true.
2307 ///
2308 /// \headerfile <x86intrin.h>
2309 ///
2310 /// This intrinsic corresponds to the <c> VPCMPGTQ / PCMPGTQ </c> instruction.
2311 ///
2312 /// \param __V1
2313 ///    A 128-bit integer vector.
2314 /// \param __V2
2315 ///    A 128-bit integer vector.
2316 /// \returns A 128-bit integer vector containing the comparison results.
2317 static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cmpgt_epi64(__m128i __V1,
2318                                                              __m128i __V2) {
2319   return (__m128i)((__v2di)__V1 > (__v2di)__V2);
2320 }
2321 
2322 #undef __DEFAULT_FN_ATTRS
2323 
2324 #include <popcntintrin.h>
2325 
2326 #include <crc32intrin.h>
2327 
2328 #endif /* __SMMINTRIN_H */
2329