blob: a62c6cccd01a4f65d49065fe177499d4cdadb67c [file] [log] [blame]
Anders Carlsson85b2a472009-02-17 03:05:04 +00001/*===---- tmmintrin.h - SSSE3 intrinsics -----------------------------------===
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 *
21 *===-----------------------------------------------------------------------===
22 */
23
24#ifndef __TMMINTRIN_H
25#define __TMMINTRIN_H
26
27#ifndef __SSSE3__
28#error "SSSE3 instruction set not enabled"
29#else
30
31#include <pmmintrin.h>
32
Chris Lattner1bddbcb2010-03-22 18:14:12 +000033static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +000034_mm_abs_pi8(__m64 a)
35{
36 return (__m64)__builtin_ia32_pabsb((__v8qi)a);
37}
38
Chris Lattner1bddbcb2010-03-22 18:14:12 +000039static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +000040_mm_abs_epi8(__m128i a)
41{
42 return (__m128i)__builtin_ia32_pabsb128((__v16qi)a);
43}
44
Chris Lattner1bddbcb2010-03-22 18:14:12 +000045static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +000046_mm_abs_pi16(__m64 a)
47{
48 return (__m64)__builtin_ia32_pabsw((__v4hi)a);
49}
50
Chris Lattner1bddbcb2010-03-22 18:14:12 +000051static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +000052_mm_abs_epi16(__m128i a)
53{
54 return (__m128i)__builtin_ia32_pabsw128((__v8hi)a);
55}
56
Chris Lattner1bddbcb2010-03-22 18:14:12 +000057static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +000058_mm_abs_pi32(__m64 a)
59{
60 return (__m64)__builtin_ia32_pabsd((__v2si)a);
61}
62
Chris Lattner1bddbcb2010-03-22 18:14:12 +000063static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +000064_mm_abs_epi32(__m128i a)
65{
66 return (__m128i)__builtin_ia32_pabsd128((__v4si)a);
67}
68
Bob Wilson32bae372011-11-05 06:08:06 +000069#define _mm_alignr_epi8(a, b, n) __extension__ ({ \
70 __m128i __a = (a); \
71 __m128i __b = (b); \
72 (__m128i)__builtin_ia32_palignr128((__v16qi)__a, (__v16qi)__b, (n)); })
73
74#define _mm_alignr_pi8(a, b, n) __extension__ ({ \
75 __m64 __a = (a); \
76 __m64 __b = (b); \
77 (__m64)__builtin_ia32_palignr((__v8qi)__a, (__v8qi)__b, (n)); })
Anders Carlsson85b2a472009-02-17 03:05:04 +000078
Chris Lattner1bddbcb2010-03-22 18:14:12 +000079static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +000080_mm_hadd_epi16(__m128i a, __m128i b)
81{
82 return (__m128i)__builtin_ia32_phaddw128((__v8hi)a, (__v8hi)b);
83}
84
Chris Lattner1bddbcb2010-03-22 18:14:12 +000085static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +000086_mm_hadd_epi32(__m128i a, __m128i b)
87{
88 return (__m128i)__builtin_ia32_phaddd128((__v4si)a, (__v4si)b);
89}
90
Chris Lattner1bddbcb2010-03-22 18:14:12 +000091static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +000092_mm_hadd_pi16(__m64 a, __m64 b)
93{
94 return (__m64)__builtin_ia32_phaddw((__v4hi)a, (__v4hi)b);
95}
96
Chris Lattner1bddbcb2010-03-22 18:14:12 +000097static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +000098_mm_hadd_pi32(__m64 a, __m64 b)
99{
100 return (__m64)__builtin_ia32_phaddd((__v2si)a, (__v2si)b);
101}
102
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000103static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000104_mm_hadds_epi16(__m128i a, __m128i b)
105{
106 return (__m128i)__builtin_ia32_phaddsw128((__v8hi)a, (__v8hi)b);
107}
108
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000109static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000110_mm_hadds_pi16(__m64 a, __m64 b)
111{
112 return (__m64)__builtin_ia32_phaddsw((__v4hi)a, (__v4hi)b);
113}
114
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000115static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000116_mm_hsub_epi16(__m128i a, __m128i b)
117{
118 return (__m128i)__builtin_ia32_phsubw128((__v8hi)a, (__v8hi)b);
119}
120
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000121static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000122_mm_hsub_epi32(__m128i a, __m128i b)
123{
Eli Friedman2e8d8da2009-06-06 07:42:17 +0000124 return (__m128i)__builtin_ia32_phsubd128((__v4si)a, (__v4si)b);
Anders Carlsson85b2a472009-02-17 03:05:04 +0000125}
126
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000127static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000128_mm_hsub_pi16(__m64 a, __m64 b)
129{
Eli Friedman2e8d8da2009-06-06 07:42:17 +0000130 return (__m64)__builtin_ia32_phsubw((__v4hi)a, (__v4hi)b);
Anders Carlsson85b2a472009-02-17 03:05:04 +0000131}
132
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000133static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000134_mm_hsub_pi32(__m64 a, __m64 b)
135{
Eli Friedman2e8d8da2009-06-06 07:42:17 +0000136 return (__m64)__builtin_ia32_phsubd((__v2si)a, (__v2si)b);
Anders Carlsson85b2a472009-02-17 03:05:04 +0000137}
138
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000139static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000140_mm_hsubs_epi16(__m128i a, __m128i b)
141{
142 return (__m128i)__builtin_ia32_phsubsw128((__v8hi)a, (__v8hi)b);
143}
144
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000145static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000146_mm_hsubs_pi16(__m64 a, __m64 b)
147{
148 return (__m64)__builtin_ia32_phsubsw((__v4hi)a, (__v4hi)b);
149}
150
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000151static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000152_mm_maddubs_epi16(__m128i a, __m128i b)
153{
154 return (__m128i)__builtin_ia32_pmaddubsw128((__v16qi)a, (__v16qi)b);
155}
156
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000157static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000158_mm_maddubs_pi16(__m64 a, __m64 b)
159{
160 return (__m64)__builtin_ia32_pmaddubsw((__v8qi)a, (__v8qi)b);
161}
162
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000163static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson2e828f02009-04-20 20:31:10 +0000164_mm_mulhrs_epi16(__m128i a, __m128i b)
Anders Carlsson85b2a472009-02-17 03:05:04 +0000165{
166 return (__m128i)__builtin_ia32_pmulhrsw128((__v8hi)a, (__v8hi)b);
167}
168
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000169static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson2e828f02009-04-20 20:31:10 +0000170_mm_mulhrs_pi16(__m64 a, __m64 b)
Anders Carlsson85b2a472009-02-17 03:05:04 +0000171{
172 return (__m64)__builtin_ia32_pmulhrsw((__v4hi)a, (__v4hi)b);
173}
174
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000175static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000176_mm_shuffle_epi8(__m128i a, __m128i b)
177{
178 return (__m128i)__builtin_ia32_pshufb128((__v16qi)a, (__v16qi)b);
179}
180
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000181static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000182_mm_shuffle_pi8(__m64 a, __m64 b)
183{
184 return (__m64)__builtin_ia32_pshufb((__v8qi)a, (__v8qi)b);
185}
186
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000187static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000188_mm_sign_epi8(__m128i a, __m128i b)
189{
190 return (__m128i)__builtin_ia32_psignb128((__v16qi)a, (__v16qi)b);
191}
192
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000193static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000194_mm_sign_epi16(__m128i a, __m128i b)
195{
196 return (__m128i)__builtin_ia32_psignw128((__v8hi)a, (__v8hi)b);
197}
198
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000199static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000200_mm_sign_epi32(__m128i a, __m128i b)
201{
202 return (__m128i)__builtin_ia32_psignd128((__v4si)a, (__v4si)b);
203}
204
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000205static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000206_mm_sign_pi8(__m64 a, __m64 b)
207{
208 return (__m64)__builtin_ia32_psignb((__v8qi)a, (__v8qi)b);
209}
210
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000211static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000212_mm_sign_pi16(__m64 a, __m64 b)
213{
214 return (__m64)__builtin_ia32_psignw((__v4hi)a, (__v4hi)b);
215}
216
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000217static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Anders Carlsson85b2a472009-02-17 03:05:04 +0000218_mm_sign_pi32(__m64 a, __m64 b)
219{
220 return (__m64)__builtin_ia32_psignd((__v2si)a, (__v2si)b);
221}
222
223#endif /* __SSSE3__ */
224
225#endif /* __TMMINTRIN_H */