blob: 0f06f787b6a08fc27dd50020990196cd5f52e576 [file] [log] [blame]
Anders Carlsson37958ee2008-03-03 19:29:06 +00001/*===---- mmintrin.h - MMX intrinsics --------------------------------------===
2 *
Anders Carlsson37958ee2008-03-03 19:29:06 +00003 * 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 __MMINTRIN_H
25#define __MMINTRIN_H
26
27#ifndef __MMX__
28#error "MMX instruction set not enabled"
29#else
30
Eli Friedmanedbd9282008-05-14 20:32:22 +000031typedef long long __m64 __attribute__((__vector_size__(8)));
Anders Carlsson37958ee2008-03-03 19:29:06 +000032
Eli Friedmanedbd9282008-05-14 20:32:22 +000033typedef int __v2si __attribute__((__vector_size__(8)));
34typedef short __v4hi __attribute__((__vector_size__(8)));
Anders Carlsson4bf4e302009-09-18 19:18:19 +000035typedef char __v8qi __attribute__((__vector_size__(8)));
Anders Carlsson37958ee2008-03-03 19:29:06 +000036
Mike Stumpe308c412009-02-14 18:02:21 +000037static inline void __attribute__((__always_inline__, __nodebug__))
38_mm_empty(void)
Anders Carlsson37958ee2008-03-03 19:29:06 +000039{
40 __builtin_ia32_emms();
41}
42
Mike Stumpe308c412009-02-14 18:02:21 +000043static inline __m64 __attribute__((__always_inline__, __nodebug__))
44_mm_cvtsi32_si64(int __i)
Anders Carlsson37958ee2008-03-03 19:29:06 +000045{
Eli Friedmanedbd9282008-05-14 20:32:22 +000046 return (__m64)(__v2si){__i, 0};
Anders Carlsson37958ee2008-03-03 19:29:06 +000047}
48
Mike Stumpe308c412009-02-14 18:02:21 +000049static inline int __attribute__((__always_inline__, __nodebug__))
50_mm_cvtsi64_si32(__m64 __m)
Anders Carlsson37958ee2008-03-03 19:29:06 +000051{
Eli Friedmanedbd9282008-05-14 20:32:22 +000052 __v2si __mmx_var2 = (__v2si)__m;
Eli Friedman1e6d14f2008-05-14 20:11:29 +000053 return __mmx_var2[0];
Anders Carlsson37958ee2008-03-03 19:29:06 +000054}
55
Mike Stumpe308c412009-02-14 18:02:21 +000056static inline __m64 __attribute__((__always_inline__, __nodebug__))
57_mm_cvtsi64_m64(long long __i)
Anders Carlsson37958ee2008-03-03 19:29:06 +000058{
Eli Friedmanedbd9282008-05-14 20:32:22 +000059 return (__m64)__i;
Anders Carlsson37958ee2008-03-03 19:29:06 +000060}
61
Mike Stumpe308c412009-02-14 18:02:21 +000062static inline long long __attribute__((__always_inline__, __nodebug__))
63_mm_cvtm64_si64(__m64 __m)
Anders Carlsson37958ee2008-03-03 19:29:06 +000064{
Eli Friedmanedbd9282008-05-14 20:32:22 +000065 return (long long)__m;
Anders Carlsson37958ee2008-03-03 19:29:06 +000066}
67
Mike Stumpe308c412009-02-14 18:02:21 +000068static inline __m64 __attribute__((__always_inline__, __nodebug__))
69_mm_packs_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +000070{
Eli Friedmanedbd9282008-05-14 20:32:22 +000071 return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +000072}
73
Mike Stumpe308c412009-02-14 18:02:21 +000074static inline __m64 __attribute__((__always_inline__, __nodebug__))
75_mm_packs_pi32(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +000076{
Eli Friedmanedbd9282008-05-14 20:32:22 +000077 return (__m64)__builtin_ia32_packssdw((__v2si)__m1, (__v2si)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +000078}
79
Mike Stumpe308c412009-02-14 18:02:21 +000080static inline __m64 __attribute__((__always_inline__, __nodebug__))
81_mm_packs_pu16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +000082{
Eli Friedmanedbd9282008-05-14 20:32:22 +000083 return (__m64)__builtin_ia32_packuswb((__v4hi)__m1, (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +000084}
85
Mike Stumpe308c412009-02-14 18:02:21 +000086static inline __m64 __attribute__((__always_inline__, __nodebug__))
87_mm_unpackhi_pi8(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +000088{
Mike Stumpe308c412009-02-14 18:02:21 +000089 return (__m64)__builtin_shufflevector((__v8qi)__m1, (__v8qi)__m2, 4, 8+4, 5,
90 8+5, 6, 8+6, 7, 8+7);
Anders Carlsson37958ee2008-03-03 19:29:06 +000091}
92
Mike Stumpe308c412009-02-14 18:02:21 +000093static inline __m64 __attribute__((__always_inline__, __nodebug__))
94_mm_unpackhi_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +000095{
Mike Stumpe308c412009-02-14 18:02:21 +000096 return (__m64)__builtin_shufflevector((__v4hi)__m1, (__v4hi)__m2, 2, 4+2, 3,
97 4+3);
Anders Carlsson37958ee2008-03-03 19:29:06 +000098}
99
Mike Stumpe308c412009-02-14 18:02:21 +0000100static inline __m64 __attribute__((__always_inline__, __nodebug__))
101_mm_unpackhi_pi32(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000102{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000103 return (__m64)__builtin_shufflevector((__v2si)__m1, (__v2si)__m2, 1, 2+1);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000104}
105
Mike Stumpe308c412009-02-14 18:02:21 +0000106static inline __m64 __attribute__((__always_inline__, __nodebug__))
107_mm_unpacklo_pi8(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000108{
Mike Stumpe308c412009-02-14 18:02:21 +0000109 return (__m64)__builtin_shufflevector((__v8qi)__m1, (__v8qi)__m2, 0, 8+0, 1,
110 8+1, 2, 8+2, 3, 8+3);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000111}
112
Mike Stumpe308c412009-02-14 18:02:21 +0000113static inline __m64 __attribute__((__always_inline__, __nodebug__))
114_mm_unpacklo_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000115{
Mike Stumpe308c412009-02-14 18:02:21 +0000116 return (__m64)__builtin_shufflevector((__v4hi)__m1, (__v4hi)__m2, 0, 4+0, 1,
117 4+1);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000118}
119
Mike Stumpe308c412009-02-14 18:02:21 +0000120static inline __m64 __attribute__((__always_inline__, __nodebug__))
121_mm_unpacklo_pi32(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000122{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000123 return (__m64)__builtin_shufflevector((__v2si)__m1, (__v2si)__m2, 0, 2+0);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000124}
125
Mike Stumpe308c412009-02-14 18:02:21 +0000126static inline __m64 __attribute__((__always_inline__, __nodebug__))
127_mm_add_pi8(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000128{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000129 return (__m64)((__v8qi)__m1 + (__v8qi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000130}
131
Mike Stumpe308c412009-02-14 18:02:21 +0000132static inline __m64 __attribute__((__always_inline__, __nodebug__))
133_mm_add_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000134{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000135 return (__m64)((__v4hi)__m1 + (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000136}
137
Mike Stumpe308c412009-02-14 18:02:21 +0000138static inline __m64 __attribute__((__always_inline__, __nodebug__))
139_mm_add_pi32(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000140{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000141 return (__m64)((__v2si)__m1 + (__v2si)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000142}
143
Mike Stumpe308c412009-02-14 18:02:21 +0000144static inline __m64 __attribute__((__always_inline__, __nodebug__))
145_mm_adds_pi8(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000146{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000147 return (__m64)__builtin_ia32_paddsb((__v8qi)__m1, (__v8qi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000148}
149
Mike Stumpe308c412009-02-14 18:02:21 +0000150static inline __m64 __attribute__((__always_inline__, __nodebug__))
151_mm_adds_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000152{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000153 return (__m64)__builtin_ia32_paddsw((__v4hi)__m1, (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000154}
155
Mike Stumpe308c412009-02-14 18:02:21 +0000156static inline __m64 __attribute__((__always_inline__, __nodebug__))
157_mm_adds_pu8(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000158{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000159 return (__m64)__builtin_ia32_paddusb((__v8qi)__m1, (__v8qi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000160}
161
Mike Stumpe308c412009-02-14 18:02:21 +0000162static inline __m64 __attribute__((__always_inline__, __nodebug__))
163_mm_adds_pu16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000164{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000165 return (__m64)__builtin_ia32_paddusw((__v4hi)__m1, (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000166}
167
Mike Stumpe308c412009-02-14 18:02:21 +0000168static inline __m64 __attribute__((__always_inline__, __nodebug__))
169_mm_sub_pi8(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000170{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000171 return (__m64)((__v8qi)__m1 - (__v8qi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000172}
173
Mike Stumpe308c412009-02-14 18:02:21 +0000174static inline __m64 __attribute__((__always_inline__, __nodebug__))
175_mm_sub_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000176{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000177 return (__m64)((__v4hi)__m1 - (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000178}
179
Mike Stumpe308c412009-02-14 18:02:21 +0000180static inline __m64 __attribute__((__always_inline__, __nodebug__))
181_mm_sub_pi32(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000182{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000183 return (__m64)((__v2si)__m1 - (__v2si)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000184}
185
Mike Stumpe308c412009-02-14 18:02:21 +0000186static inline __m64 __attribute__((__always_inline__, __nodebug__))
187_mm_subs_pi8(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000188{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000189 return (__m64)__builtin_ia32_psubsb((__v8qi)__m1, (__v8qi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000190}
191
Mike Stumpe308c412009-02-14 18:02:21 +0000192static inline __m64 __attribute__((__always_inline__, __nodebug__))
193_mm_subs_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000194{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000195 return (__m64)__builtin_ia32_psubsw((__v4hi)__m1, (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000196}
197
Mike Stumpe308c412009-02-14 18:02:21 +0000198static inline __m64 __attribute__((__always_inline__, __nodebug__))
199_mm_subs_pu8(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000200{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000201 return (__m64)__builtin_ia32_psubusb((__v8qi)__m1, (__v8qi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000202}
203
Mike Stumpe308c412009-02-14 18:02:21 +0000204static inline __m64 __attribute__((__always_inline__, __nodebug__))
205_mm_subs_pu16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000206{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000207 return (__m64)__builtin_ia32_psubusw((__v4hi)__m1, (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000208}
209
Mike Stumpe308c412009-02-14 18:02:21 +0000210static inline __m64 __attribute__((__always_inline__, __nodebug__))
211_mm_madd_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000212{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000213 return (__m64)__builtin_ia32_pmaddwd((__v4hi)__m1, (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000214}
215
Mike Stumpe308c412009-02-14 18:02:21 +0000216static inline __m64 __attribute__((__always_inline__, __nodebug__))
217_mm_mulhi_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000218{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000219 return (__m64)__builtin_ia32_pmulhw((__v4hi)__m1, (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000220}
221
Mike Stumpe308c412009-02-14 18:02:21 +0000222static inline __m64 __attribute__((__always_inline__, __nodebug__))
223_mm_mullo_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000224{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000225 return (__m64)((__v4hi)__m1 * (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000226}
227
Mike Stumpe308c412009-02-14 18:02:21 +0000228static inline __m64 __attribute__((__always_inline__, __nodebug__))
229_mm_sll_pi16(__m64 __m, __m64 __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000230{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000231 return (__m64)__builtin_ia32_psllw((__v4hi)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000232}
233
Mike Stumpe308c412009-02-14 18:02:21 +0000234static inline __m64 __attribute__((__always_inline__, __nodebug__))
235_mm_slli_pi16(__m64 __m, int __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000236{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000237 return (__m64)__builtin_ia32_psllwi((__v4hi)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000238}
239
Mike Stumpe308c412009-02-14 18:02:21 +0000240static inline __m64 __attribute__((__always_inline__, __nodebug__))
241_mm_sll_pi32(__m64 __m, __m64 __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000242{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000243 return (__m64)__builtin_ia32_pslld((__v2si)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000244}
245
Mike Stumpe308c412009-02-14 18:02:21 +0000246static inline __m64 __attribute__((__always_inline__, __nodebug__))
247_mm_slli_pi32(__m64 __m, int __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000248{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000249 return (__m64)__builtin_ia32_pslldi((__v2si)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000250}
251
Mike Stumpe308c412009-02-14 18:02:21 +0000252static inline __m64 __attribute__((__always_inline__, __nodebug__))
253_mm_sll_si64(__m64 __m, __m64 __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000254{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000255 return __builtin_ia32_psllq(__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000256}
257
Mike Stumpe308c412009-02-14 18:02:21 +0000258static inline __m64 __attribute__((__always_inline__, __nodebug__))
259_mm_slli_si64(__m64 __m, int __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000260{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000261 return __builtin_ia32_psllqi(__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000262}
263
Mike Stumpe308c412009-02-14 18:02:21 +0000264static inline __m64 __attribute__((__always_inline__, __nodebug__))
265_mm_sra_pi16(__m64 __m, __m64 __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000266{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000267 return (__m64)__builtin_ia32_psraw((__v4hi)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000268}
269
Mike Stumpe308c412009-02-14 18:02:21 +0000270static inline __m64 __attribute__((__always_inline__, __nodebug__))
271_mm_srai_pi16(__m64 __m, int __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000272{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000273 return (__m64)__builtin_ia32_psrawi((__v4hi)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000274}
275
Mike Stumpe308c412009-02-14 18:02:21 +0000276static inline __m64 __attribute__((__always_inline__, __nodebug__))
277_mm_sra_pi32(__m64 __m, __m64 __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000278{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000279 return (__m64)__builtin_ia32_psrad((__v2si)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000280}
281
Mike Stumpe308c412009-02-14 18:02:21 +0000282static inline __m64 __attribute__((__always_inline__, __nodebug__))
283_mm_srai_pi32(__m64 __m, int __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000284{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000285 return (__m64)__builtin_ia32_psradi((__v2si)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000286}
287
Mike Stumpe308c412009-02-14 18:02:21 +0000288static inline __m64 __attribute__((__always_inline__, __nodebug__))
289_mm_srl_pi16(__m64 __m, __m64 __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000290{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000291 return (__m64)__builtin_ia32_psrlw((__v4hi)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000292}
293
Mike Stumpe308c412009-02-14 18:02:21 +0000294static inline __m64 __attribute__((__always_inline__, __nodebug__))
295_mm_srli_pi16(__m64 __m, int __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000296{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000297 return (__m64)__builtin_ia32_psrlwi((__v4hi)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000298}
299
Mike Stumpe308c412009-02-14 18:02:21 +0000300static inline __m64 __attribute__((__always_inline__, __nodebug__))
301_mm_srl_pi32(__m64 __m, __m64 __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000302{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000303 return (__m64)__builtin_ia32_psrld((__v2si)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000304}
305
Mike Stumpe308c412009-02-14 18:02:21 +0000306static inline __m64 __attribute__((__always_inline__, __nodebug__))
307_mm_srli_pi32(__m64 __m, int __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000308{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000309 return (__m64)__builtin_ia32_psrldi((__v2si)__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000310}
311
Mike Stumpe308c412009-02-14 18:02:21 +0000312static inline __m64 __attribute__((__always_inline__, __nodebug__))
313_mm_srl_si64(__m64 __m, __m64 __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000314{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000315 return (__m64)__builtin_ia32_psrlq(__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000316}
317
Mike Stumpe308c412009-02-14 18:02:21 +0000318static inline __m64 __attribute__((__always_inline__, __nodebug__))
319_mm_srli_si64(__m64 __m, int __count)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000320{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000321 return __builtin_ia32_psrlqi(__m, __count);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000322}
323
Mike Stumpe308c412009-02-14 18:02:21 +0000324static inline __m64 __attribute__((__always_inline__, __nodebug__))
325_mm_and_si64(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000326{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000327 return __m1 & __m2;
Anders Carlsson37958ee2008-03-03 19:29:06 +0000328}
329
Mike Stumpe308c412009-02-14 18:02:21 +0000330static inline __m64 __attribute__((__always_inline__, __nodebug__))
331_mm_andnot_si64(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000332{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000333 return ~__m1 & __m2;
Anders Carlsson37958ee2008-03-03 19:29:06 +0000334}
335
Mike Stumpe308c412009-02-14 18:02:21 +0000336static inline __m64 __attribute__((__always_inline__, __nodebug__))
337_mm_or_si64(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000338{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000339 return __m1 | __m2;
Anders Carlsson37958ee2008-03-03 19:29:06 +0000340}
341
Mike Stumpe308c412009-02-14 18:02:21 +0000342static inline __m64 __attribute__((__always_inline__, __nodebug__))
343_mm_xor_si64(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000344{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000345 return __m1 ^ __m2;
Anders Carlsson37958ee2008-03-03 19:29:06 +0000346}
347
Mike Stumpe308c412009-02-14 18:02:21 +0000348static inline __m64 __attribute__((__always_inline__, __nodebug__))
349_mm_cmpeq_pi8(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000350{
Eli Friedman3a266f22009-07-22 17:08:01 +0000351 return (__m64)((__v8qi)__m1 == (__v8qi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000352}
353
Mike Stumpe308c412009-02-14 18:02:21 +0000354static inline __m64 __attribute__((__always_inline__, __nodebug__))
355_mm_cmpeq_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000356{
Eli Friedman3a266f22009-07-22 17:08:01 +0000357 return (__m64)((__v4hi)__m1 == (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000358}
359
Mike Stumpe308c412009-02-14 18:02:21 +0000360static inline __m64 __attribute__((__always_inline__, __nodebug__))
361_mm_cmpeq_pi32(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000362{
Eli Friedman3a266f22009-07-22 17:08:01 +0000363 return (__m64)((__v2si)__m1 == (__v2si)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000364}
365
Mike Stumpe308c412009-02-14 18:02:21 +0000366static inline __m64 __attribute__((__always_inline__, __nodebug__))
367_mm_cmpgt_pi8(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000368{
Eli Friedman3a266f22009-07-22 17:08:01 +0000369 return (__m64)((__v8qi)__m1 > (__v8qi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000370}
371
Mike Stumpe308c412009-02-14 18:02:21 +0000372static inline __m64 __attribute__((__always_inline__, __nodebug__))
373_mm_cmpgt_pi16(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000374{
Eli Friedman3a266f22009-07-22 17:08:01 +0000375 return (__m64)((__v4hi)__m1 > (__v4hi)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000376}
377
Mike Stumpe308c412009-02-14 18:02:21 +0000378static inline __m64 __attribute__((__always_inline__, __nodebug__))
379_mm_cmpgt_pi32(__m64 __m1, __m64 __m2)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000380{
Eli Friedman3a266f22009-07-22 17:08:01 +0000381 return (__m64)((__v2si)__m1 > (__v2si)__m2);
Anders Carlsson37958ee2008-03-03 19:29:06 +0000382}
383
Mike Stumpe308c412009-02-14 18:02:21 +0000384static inline __m64 __attribute__((__always_inline__, __nodebug__))
385_mm_setzero_si64(void)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000386{
387 return (__m64){ 0LL };
388}
389
Mike Stumpe308c412009-02-14 18:02:21 +0000390static inline __m64 __attribute__((__always_inline__, __nodebug__))
391_mm_set_pi32(int __i1, int __i0)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000392{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000393 return (__m64)(__v2si){ __i0, __i1 };
Anders Carlsson37958ee2008-03-03 19:29:06 +0000394}
395
Mike Stumpe308c412009-02-14 18:02:21 +0000396static inline __m64 __attribute__((__always_inline__, __nodebug__))
397_mm_set_pi16(short __s3, short __s2, short __s1, short __s0)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000398{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000399 return (__m64)(__v4hi){ __s0, __s1, __s2, __s3 };
Anders Carlsson37958ee2008-03-03 19:29:06 +0000400}
401
Mike Stumpe308c412009-02-14 18:02:21 +0000402static inline __m64 __attribute__((__always_inline__, __nodebug__))
403_mm_set_pi8(char __b7, char __b6, char __b5, char __b4, char __b3, char __b2,
404 char __b1, char __b0)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000405{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000406 return (__m64)(__v8qi){ __b0, __b1, __b2, __b3, __b4, __b5, __b6, __b7 };
Anders Carlsson37958ee2008-03-03 19:29:06 +0000407}
408
Mike Stumpe308c412009-02-14 18:02:21 +0000409static inline __m64 __attribute__((__always_inline__, __nodebug__))
410_mm_set1_pi32(int __i)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000411{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000412 return (__m64)(__v2si){ __i, __i };
Anders Carlsson37958ee2008-03-03 19:29:06 +0000413}
414
Mike Stumpe308c412009-02-14 18:02:21 +0000415static inline __m64 __attribute__((__always_inline__, __nodebug__))
416_mm_set1_pi16(short __s)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000417{
Eli Friedman80c80042009-06-06 02:13:04 +0000418 return (__m64)(__v4hi){ __s, __s, __s, __s };
Anders Carlsson37958ee2008-03-03 19:29:06 +0000419}
420
Mike Stumpe308c412009-02-14 18:02:21 +0000421static inline __m64 __attribute__((__always_inline__, __nodebug__))
422_mm_set1_pi8(char __b)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000423{
Eli Friedman80c80042009-06-06 02:13:04 +0000424 return (__m64)(__v8qi){ __b, __b, __b, __b, __b, __b, __b, __b };
Anders Carlsson37958ee2008-03-03 19:29:06 +0000425}
426
Mike Stumpe308c412009-02-14 18:02:21 +0000427static inline __m64 __attribute__((__always_inline__, __nodebug__))
428_mm_setr_pi32(int __i1, int __i0)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000429{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000430 return (__m64)(__v2si){ __i1, __i0 };
Anders Carlsson37958ee2008-03-03 19:29:06 +0000431}
432
Mike Stumpe308c412009-02-14 18:02:21 +0000433static inline __m64 __attribute__((__always_inline__, __nodebug__))
434_mm_setr_pi16(short __s3, short __s2, short __s1, short __s0)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000435{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000436 return (__m64)(__v4hi){ __s3, __s2, __s1, __s0 };
Anders Carlsson37958ee2008-03-03 19:29:06 +0000437}
438
Mike Stumpe308c412009-02-14 18:02:21 +0000439static inline __m64 __attribute__((__always_inline__, __nodebug__))
440_mm_setr_pi8(char __b7, char __b6, char __b5, char __b4, char __b3, char __b2,
441 char __b1, char __b0)
Anders Carlsson37958ee2008-03-03 19:29:06 +0000442{
Eli Friedmanedbd9282008-05-14 20:32:22 +0000443 return (__m64)(__v8qi){ __b7, __b6, __b5, __b4, __b3, __b2, __b1, __b0 };
Anders Carlsson37958ee2008-03-03 19:29:06 +0000444}
445
446#endif /* __MMX__ */
447
448#endif /* __MMINTRIN_H */
449