smmintrin.h revision c82ac95dbd68cbfa13bf8a93f7230fbe252931f7
1b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher/*===---- smmintrin.h - SSE intrinsics -------------------------------------===
2b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher*
3b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* Permission is hereby granted, free of charge, to any person obtaining a copy
4b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* of this software and associated documentation files (the "Software"), to deal
5b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* in the Software without restriction, including without limitation the rights
6b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* copies of the Software, and to permit persons to whom the Software is
8b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* furnished to do so, subject to the following conditions:
9b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher*
10b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* The above copyright notice and this permission notice shall be included in
11b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* all copies or substantial portions of the Software.
12b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher*
13b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher* THE SOFTWARE.
20b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher*
21b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher*===-----------------------------------------------------------------------===
22b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher*/
23b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
24b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#ifndef _SMMINTRIN_H
25b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _SMMINTRIN_H
26b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
27b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#ifndef __SSE4_1__
28b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#error "SSE4.1 instruction set not enabled"
29b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#else
30b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
31b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#include <tmmintrin.h>
32b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
33b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher/* Type defines.  */
34b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christophertypedef double __v2df __attribute__ ((__vector_size__ (16)));
35b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
36b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher/* SSE4 Rounding macros. */
37b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_TO_NEAREST_INT    0x00
38b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_TO_NEG_INF        0x01
39b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_TO_POS_INF        0x02
40b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_TO_ZERO           0x03
41b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_CUR_DIRECTION     0x04
42b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
43b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_RAISE_EXC         0x00
44b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_NO_EXC            0x08
45b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
46b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_NINT      (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEAREST_INT)
47b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_FLOOR     (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEG_INF)
48b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_CEIL      (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_POS_INF)
49b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_TRUNC     (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_ZERO)
50b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _MM_FROUND_RINT      (_MM_FROUND_RAISE_EXC | _MM_FROUND_CUR_DIRECTION)
519ce2116005d417f7a36fa99bba7e499a58650a9aEric Christopher#define _MM_FROUND_NEARBYINT (_MM_FROUND_NO_EXC | _MM_FROUND_CUR_DIRECTION)
52b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
53b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _mm_ceil_ps(X)       _mm_round_ps((X), _MM_FROUND_CEIL)
54b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _mm_ceil_pd(X)       _mm_round_pd((X), _MM_FROUND_CEIL)
55b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _mm_ceil_ss(X, Y)    _mm_round_ss((X), (Y), _MM_FROUND_CEIL)
56b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _mm_ceil_sd(X, Y)    _mm_round_sd((X), (Y), _MM_FROUND_CEIL)
57b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
58b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _mm_floor_ps(X)      _mm_round_ps((X), _MM_FROUND_FLOOR)
59b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _mm_floor_pd(X)      _mm_round_pd((X), _MM_FROUND_FLOOR)
60b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _mm_floor_ss(X, Y)   _mm_round_ss((X), (Y), _MM_FROUND_FLOOR)
61b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#define _mm_floor_sd(X, Y)   _mm_round_sd((X), (Y), _MM_FROUND_FLOOR)
62b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
639ce2116005d417f7a36fa99bba7e499a58650a9aEric Christopher#define _mm_round_ps(X, Y)      __builtin_ia32_roundps((X), (Y))
649ce2116005d417f7a36fa99bba7e499a58650a9aEric Christopher#define _mm_round_ss(X, Y, M)   __builtin_ia32_roundss((X), (Y), (M))
659ce2116005d417f7a36fa99bba7e499a58650a9aEric Christopher#define _mm_round_pd(X, M)      __builtin_ia32_roundpd((X), (M))
669ce2116005d417f7a36fa99bba7e499a58650a9aEric Christopher#define _mm_round_sd(X, Y, M)   __builtin_ia32_roundsd((X), (Y), (M))
67b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
68b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher/* SSE4 Packed Blending Intrinsics.  */
69b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopherstatic inline __m128d __attribute__((__always_inline__, __nodebug__))
70b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher_mm_blend_pd (__m128d __V1, __m128d __V2, const int __M)
71b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher{
72b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher  return (__m128d) __builtin_ia32_blendpd ((__v2df)__V1, (__v2df)__V2, __M);
73b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher}
74b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
75b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopherstatic inline __m128 __attribute__((__always_inline__, __nodebug__))
76b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher_mm_blend_ps (__m128 __V1, __m128 __V2, const int __M)
77b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher{
78b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher  return (__m128) __builtin_ia32_blendps ((__v4sf)__V1, (__v4sf)__V2, __M);
79b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher}
80b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
81b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopherstatic inline __m128d __attribute__((__always_inline__, __nodebug__))
82b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher_mm_blendv_pd (__m128d __V1, __m128d __V2, __m128d __M)
83b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher{
84b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher  return (__m128d) __builtin_ia32_blendvpd ((__v2df)__V1, (__v2df)__V2,
85b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher                                            (__v2df)__M);
86b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher}
87b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
88b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopherstatic inline __m128 __attribute__((__always_inline__, __nodebug__))
89b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher_mm_blendv_ps (__m128 __V1, __m128 __V2, __m128 __M)
90b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher{
91b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher  return (__m128) __builtin_ia32_blendvps ((__v4sf)__V1, (__v4sf)__V2,
92b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher                                           (__v4sf)__M);
93b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher}
94b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
95b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopherstatic inline __m128i __attribute__((__always_inline__, __nodebug__))
96b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher_mm_blendv_epi8 (__m128i __V1, __m128i __V2, __m128i __M)
97b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher{
98b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher  return (__m128i) __builtin_ia32_pblendvb128 ((__v16qi)__V1, (__v16qi)__V2,
99b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher                                               (__v16qi)__M);
100b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher}
101b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
102b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopherstatic inline  __m128i __attribute__((__always_inline__, __nodebug__))
103b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher_mm_blend_epi16 (__m128i __V1, __m128i __V2, const int __M)
104b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher{
105b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher  return (__m128i) __builtin_ia32_pblendw128 ((__v8hi)__V1, (__v8hi)__V2, __M);
106b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher}
107b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
108c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher/* SSE4 Dword Multiply Instructions.  */
109c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopherstatic inline  __m128i __attribute__((__always_inline__, __nodebug__))
110c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher_mm_mullo_epi32 (__m128i __V1, __m128i __V2)
111c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher{
112c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher  return (__m128i) __builtin_ia32_pmulld128((__v4si)__V1, (__v4si)__V2);
113c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher}
114c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher
115c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopherstatic inline  __m128i __attribute__((__always_inline__, __nodebug__))
116c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher_mm_mul_epi32 (__m128i __V1, __m128i __V2)
117c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher{
118c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher  return (__m128i) __builtin_ia32_pmuldq128 ((__v4si)__V1, (__v4si)__V2);
119c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher}
120c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher
121c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher/* SSE4 Floating Point Dot Product Instructions.  */
122c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher#define _mm_dp_ps(X, Y, M) __builtin_ia32_dpps ((X), (Y), (M))
123c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher#define _mm_dp_pd(X, Y, M) __builtin_ia32_dppd ((X), (Y), (M))
124c82ac95dbd68cbfa13bf8a93f7230fbe252931f7Eric Christopher
125b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#endif /* __SSE4_1__ */
126b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher
127b71f95647189f3b0f7f5f5a39c8c3ab8130dcf1fEric Christopher#endif /* _SMMINTRIN_H */
128