1/*===---- mmintrin.h - MMX 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 __MMINTRIN_H
25#define __MMINTRIN_H
26
27typedef long long __m64 __attribute__((__vector_size__(8)));
28
29typedef int __v2si __attribute__((__vector_size__(8)));
30typedef short __v4hi __attribute__((__vector_size__(8)));
31typedef char __v8qi __attribute__((__vector_size__(8)));
32
33/* Define the default attributes for the functions in this file. */
34#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("mmx")))
35
36static __inline__ void __DEFAULT_FN_ATTRS
37_mm_empty(void)
38{
39    __builtin_ia32_emms();
40}
41
42static __inline__ __m64 __DEFAULT_FN_ATTRS
43_mm_cvtsi32_si64(int __i)
44{
45    return (__m64)__builtin_ia32_vec_init_v2si(__i, 0);
46}
47
48static __inline__ int __DEFAULT_FN_ATTRS
49_mm_cvtsi64_si32(__m64 __m)
50{
51    return __builtin_ia32_vec_ext_v2si((__v2si)__m, 0);
52}
53
54static __inline__ __m64 __DEFAULT_FN_ATTRS
55_mm_cvtsi64_m64(long long __i)
56{
57    return (__m64)__i;
58}
59
60static __inline__ long long __DEFAULT_FN_ATTRS
61_mm_cvtm64_si64(__m64 __m)
62{
63    return (long long)__m;
64}
65
66static __inline__ __m64 __DEFAULT_FN_ATTRS
67_mm_packs_pi16(__m64 __m1, __m64 __m2)
68{
69    return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);
70}
71
72static __inline__ __m64 __DEFAULT_FN_ATTRS
73_mm_packs_pi32(__m64 __m1, __m64 __m2)
74{
75    return (__m64)__builtin_ia32_packssdw((__v2si)__m1, (__v2si)__m2);
76}
77
78static __inline__ __m64 __DEFAULT_FN_ATTRS
79_mm_packs_pu16(__m64 __m1, __m64 __m2)
80{
81    return (__m64)__builtin_ia32_packuswb((__v4hi)__m1, (__v4hi)__m2);
82}
83
84static __inline__ __m64 __DEFAULT_FN_ATTRS
85_mm_unpackhi_pi8(__m64 __m1, __m64 __m2)
86{
87    return (__m64)__builtin_ia32_punpckhbw((__v8qi)__m1, (__v8qi)__m2);
88}
89
90static __inline__ __m64 __DEFAULT_FN_ATTRS
91_mm_unpackhi_pi16(__m64 __m1, __m64 __m2)
92{
93    return (__m64)__builtin_ia32_punpckhwd((__v4hi)__m1, (__v4hi)__m2);
94}
95
96static __inline__ __m64 __DEFAULT_FN_ATTRS
97_mm_unpackhi_pi32(__m64 __m1, __m64 __m2)
98{
99    return (__m64)__builtin_ia32_punpckhdq((__v2si)__m1, (__v2si)__m2);
100}
101
102static __inline__ __m64 __DEFAULT_FN_ATTRS
103_mm_unpacklo_pi8(__m64 __m1, __m64 __m2)
104{
105    return (__m64)__builtin_ia32_punpcklbw((__v8qi)__m1, (__v8qi)__m2);
106}
107
108static __inline__ __m64 __DEFAULT_FN_ATTRS
109_mm_unpacklo_pi16(__m64 __m1, __m64 __m2)
110{
111    return (__m64)__builtin_ia32_punpcklwd((__v4hi)__m1, (__v4hi)__m2);
112}
113
114static __inline__ __m64 __DEFAULT_FN_ATTRS
115_mm_unpacklo_pi32(__m64 __m1, __m64 __m2)
116{
117    return (__m64)__builtin_ia32_punpckldq((__v2si)__m1, (__v2si)__m2);
118}
119
120static __inline__ __m64 __DEFAULT_FN_ATTRS
121_mm_add_pi8(__m64 __m1, __m64 __m2)
122{
123    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
124}
125
126static __inline__ __m64 __DEFAULT_FN_ATTRS
127_mm_add_pi16(__m64 __m1, __m64 __m2)
128{
129    return (__m64)__builtin_ia32_paddw((__v4hi)__m1, (__v4hi)__m2);
130}
131
132static __inline__ __m64 __DEFAULT_FN_ATTRS
133_mm_add_pi32(__m64 __m1, __m64 __m2)
134{
135    return (__m64)__builtin_ia32_paddd((__v2si)__m1, (__v2si)__m2);
136}
137
138static __inline__ __m64 __DEFAULT_FN_ATTRS
139_mm_adds_pi8(__m64 __m1, __m64 __m2)
140{
141    return (__m64)__builtin_ia32_paddsb((__v8qi)__m1, (__v8qi)__m2);
142}
143
144static __inline__ __m64 __DEFAULT_FN_ATTRS
145_mm_adds_pi16(__m64 __m1, __m64 __m2)
146{
147    return (__m64)__builtin_ia32_paddsw((__v4hi)__m1, (__v4hi)__m2);
148}
149
150static __inline__ __m64 __DEFAULT_FN_ATTRS
151_mm_adds_pu8(__m64 __m1, __m64 __m2)
152{
153    return (__m64)__builtin_ia32_paddusb((__v8qi)__m1, (__v8qi)__m2);
154}
155
156static __inline__ __m64 __DEFAULT_FN_ATTRS
157_mm_adds_pu16(__m64 __m1, __m64 __m2)
158{
159    return (__m64)__builtin_ia32_paddusw((__v4hi)__m1, (__v4hi)__m2);
160}
161
162static __inline__ __m64 __DEFAULT_FN_ATTRS
163_mm_sub_pi8(__m64 __m1, __m64 __m2)
164{
165    return (__m64)__builtin_ia32_psubb((__v8qi)__m1, (__v8qi)__m2);
166}
167
168static __inline__ __m64 __DEFAULT_FN_ATTRS
169_mm_sub_pi16(__m64 __m1, __m64 __m2)
170{
171    return (__m64)__builtin_ia32_psubw((__v4hi)__m1, (__v4hi)__m2);
172}
173
174static __inline__ __m64 __DEFAULT_FN_ATTRS
175_mm_sub_pi32(__m64 __m1, __m64 __m2)
176{
177    return (__m64)__builtin_ia32_psubd((__v2si)__m1, (__v2si)__m2);
178}
179
180static __inline__ __m64 __DEFAULT_FN_ATTRS
181_mm_subs_pi8(__m64 __m1, __m64 __m2)
182{
183    return (__m64)__builtin_ia32_psubsb((__v8qi)__m1, (__v8qi)__m2);
184}
185
186static __inline__ __m64 __DEFAULT_FN_ATTRS
187_mm_subs_pi16(__m64 __m1, __m64 __m2)
188{
189    return (__m64)__builtin_ia32_psubsw((__v4hi)__m1, (__v4hi)__m2);
190}
191
192static __inline__ __m64 __DEFAULT_FN_ATTRS
193_mm_subs_pu8(__m64 __m1, __m64 __m2)
194{
195    return (__m64)__builtin_ia32_psubusb((__v8qi)__m1, (__v8qi)__m2);
196}
197
198static __inline__ __m64 __DEFAULT_FN_ATTRS
199_mm_subs_pu16(__m64 __m1, __m64 __m2)
200{
201    return (__m64)__builtin_ia32_psubusw((__v4hi)__m1, (__v4hi)__m2);
202}
203
204static __inline__ __m64 __DEFAULT_FN_ATTRS
205_mm_madd_pi16(__m64 __m1, __m64 __m2)
206{
207    return (__m64)__builtin_ia32_pmaddwd((__v4hi)__m1, (__v4hi)__m2);
208}
209
210static __inline__ __m64 __DEFAULT_FN_ATTRS
211_mm_mulhi_pi16(__m64 __m1, __m64 __m2)
212{
213    return (__m64)__builtin_ia32_pmulhw((__v4hi)__m1, (__v4hi)__m2);
214}
215
216static __inline__ __m64 __DEFAULT_FN_ATTRS
217_mm_mullo_pi16(__m64 __m1, __m64 __m2)
218{
219    return (__m64)__builtin_ia32_pmullw((__v4hi)__m1, (__v4hi)__m2);
220}
221
222static __inline__ __m64 __DEFAULT_FN_ATTRS
223_mm_sll_pi16(__m64 __m, __m64 __count)
224{
225    return (__m64)__builtin_ia32_psllw((__v4hi)__m, __count);
226}
227
228static __inline__ __m64 __DEFAULT_FN_ATTRS
229_mm_slli_pi16(__m64 __m, int __count)
230{
231    return (__m64)__builtin_ia32_psllwi((__v4hi)__m, __count);
232}
233
234static __inline__ __m64 __DEFAULT_FN_ATTRS
235_mm_sll_pi32(__m64 __m, __m64 __count)
236{
237    return (__m64)__builtin_ia32_pslld((__v2si)__m, __count);
238}
239
240static __inline__ __m64 __DEFAULT_FN_ATTRS
241_mm_slli_pi32(__m64 __m, int __count)
242{
243    return (__m64)__builtin_ia32_pslldi((__v2si)__m, __count);
244}
245
246static __inline__ __m64 __DEFAULT_FN_ATTRS
247_mm_sll_si64(__m64 __m, __m64 __count)
248{
249    return (__m64)__builtin_ia32_psllq(__m, __count);
250}
251
252static __inline__ __m64 __DEFAULT_FN_ATTRS
253_mm_slli_si64(__m64 __m, int __count)
254{
255    return (__m64)__builtin_ia32_psllqi(__m, __count);
256}
257
258static __inline__ __m64 __DEFAULT_FN_ATTRS
259_mm_sra_pi16(__m64 __m, __m64 __count)
260{
261    return (__m64)__builtin_ia32_psraw((__v4hi)__m, __count);
262}
263
264static __inline__ __m64 __DEFAULT_FN_ATTRS
265_mm_srai_pi16(__m64 __m, int __count)
266{
267    return (__m64)__builtin_ia32_psrawi((__v4hi)__m, __count);
268}
269
270static __inline__ __m64 __DEFAULT_FN_ATTRS
271_mm_sra_pi32(__m64 __m, __m64 __count)
272{
273    return (__m64)__builtin_ia32_psrad((__v2si)__m, __count);
274}
275
276static __inline__ __m64 __DEFAULT_FN_ATTRS
277_mm_srai_pi32(__m64 __m, int __count)
278{
279    return (__m64)__builtin_ia32_psradi((__v2si)__m, __count);
280}
281
282static __inline__ __m64 __DEFAULT_FN_ATTRS
283_mm_srl_pi16(__m64 __m, __m64 __count)
284{
285    return (__m64)__builtin_ia32_psrlw((__v4hi)__m, __count);
286}
287
288static __inline__ __m64 __DEFAULT_FN_ATTRS
289_mm_srli_pi16(__m64 __m, int __count)
290{
291    return (__m64)__builtin_ia32_psrlwi((__v4hi)__m, __count);
292}
293
294static __inline__ __m64 __DEFAULT_FN_ATTRS
295_mm_srl_pi32(__m64 __m, __m64 __count)
296{
297    return (__m64)__builtin_ia32_psrld((__v2si)__m, __count);
298}
299
300static __inline__ __m64 __DEFAULT_FN_ATTRS
301_mm_srli_pi32(__m64 __m, int __count)
302{
303    return (__m64)__builtin_ia32_psrldi((__v2si)__m, __count);
304}
305
306static __inline__ __m64 __DEFAULT_FN_ATTRS
307_mm_srl_si64(__m64 __m, __m64 __count)
308{
309    return (__m64)__builtin_ia32_psrlq(__m, __count);
310}
311
312static __inline__ __m64 __DEFAULT_FN_ATTRS
313_mm_srli_si64(__m64 __m, int __count)
314{
315    return (__m64)__builtin_ia32_psrlqi(__m, __count);
316}
317
318static __inline__ __m64 __DEFAULT_FN_ATTRS
319_mm_and_si64(__m64 __m1, __m64 __m2)
320{
321    return __builtin_ia32_pand(__m1, __m2);
322}
323
324static __inline__ __m64 __DEFAULT_FN_ATTRS
325_mm_andnot_si64(__m64 __m1, __m64 __m2)
326{
327    return __builtin_ia32_pandn(__m1, __m2);
328}
329
330static __inline__ __m64 __DEFAULT_FN_ATTRS
331_mm_or_si64(__m64 __m1, __m64 __m2)
332{
333    return __builtin_ia32_por(__m1, __m2);
334}
335
336static __inline__ __m64 __DEFAULT_FN_ATTRS
337_mm_xor_si64(__m64 __m1, __m64 __m2)
338{
339    return __builtin_ia32_pxor(__m1, __m2);
340}
341
342static __inline__ __m64 __DEFAULT_FN_ATTRS
343_mm_cmpeq_pi8(__m64 __m1, __m64 __m2)
344{
345    return (__m64)__builtin_ia32_pcmpeqb((__v8qi)__m1, (__v8qi)__m2);
346}
347
348static __inline__ __m64 __DEFAULT_FN_ATTRS
349_mm_cmpeq_pi16(__m64 __m1, __m64 __m2)
350{
351    return (__m64)__builtin_ia32_pcmpeqw((__v4hi)__m1, (__v4hi)__m2);
352}
353
354static __inline__ __m64 __DEFAULT_FN_ATTRS
355_mm_cmpeq_pi32(__m64 __m1, __m64 __m2)
356{
357    return (__m64)__builtin_ia32_pcmpeqd((__v2si)__m1, (__v2si)__m2);
358}
359
360static __inline__ __m64 __DEFAULT_FN_ATTRS
361_mm_cmpgt_pi8(__m64 __m1, __m64 __m2)
362{
363    return (__m64)__builtin_ia32_pcmpgtb((__v8qi)__m1, (__v8qi)__m2);
364}
365
366static __inline__ __m64 __DEFAULT_FN_ATTRS
367_mm_cmpgt_pi16(__m64 __m1, __m64 __m2)
368{
369    return (__m64)__builtin_ia32_pcmpgtw((__v4hi)__m1, (__v4hi)__m2);
370}
371
372static __inline__ __m64 __DEFAULT_FN_ATTRS
373_mm_cmpgt_pi32(__m64 __m1, __m64 __m2)
374{
375    return (__m64)__builtin_ia32_pcmpgtd((__v2si)__m1, (__v2si)__m2);
376}
377
378static __inline__ __m64 __DEFAULT_FN_ATTRS
379_mm_setzero_si64(void)
380{
381    return (__m64){ 0LL };
382}
383
384static __inline__ __m64 __DEFAULT_FN_ATTRS
385_mm_set_pi32(int __i1, int __i0)
386{
387    return (__m64)__builtin_ia32_vec_init_v2si(__i0, __i1);
388}
389
390static __inline__ __m64 __DEFAULT_FN_ATTRS
391_mm_set_pi16(short __s3, short __s2, short __s1, short __s0)
392{
393    return (__m64)__builtin_ia32_vec_init_v4hi(__s0, __s1, __s2, __s3);
394}
395
396static __inline__ __m64 __DEFAULT_FN_ATTRS
397_mm_set_pi8(char __b7, char __b6, char __b5, char __b4, char __b3, char __b2,
398            char __b1, char __b0)
399{
400    return (__m64)__builtin_ia32_vec_init_v8qi(__b0, __b1, __b2, __b3,
401                                               __b4, __b5, __b6, __b7);
402}
403
404static __inline__ __m64 __DEFAULT_FN_ATTRS
405_mm_set1_pi32(int __i)
406{
407    return _mm_set_pi32(__i, __i);
408}
409
410static __inline__ __m64 __DEFAULT_FN_ATTRS
411_mm_set1_pi16(short __w)
412{
413    return _mm_set_pi16(__w, __w, __w, __w);
414}
415
416static __inline__ __m64 __DEFAULT_FN_ATTRS
417_mm_set1_pi8(char __b)
418{
419    return _mm_set_pi8(__b, __b, __b, __b, __b, __b, __b, __b);
420}
421
422static __inline__ __m64 __DEFAULT_FN_ATTRS
423_mm_setr_pi32(int __i0, int __i1)
424{
425    return _mm_set_pi32(__i1, __i0);
426}
427
428static __inline__ __m64 __DEFAULT_FN_ATTRS
429_mm_setr_pi16(short __w0, short __w1, short __w2, short __w3)
430{
431    return _mm_set_pi16(__w3, __w2, __w1, __w0);
432}
433
434static __inline__ __m64 __DEFAULT_FN_ATTRS
435_mm_setr_pi8(char __b0, char __b1, char __b2, char __b3, char __b4, char __b5,
436             char __b6, char __b7)
437{
438    return _mm_set_pi8(__b7, __b6, __b5, __b4, __b3, __b2, __b1, __b0);
439}
440
441#undef __DEFAULT_FN_ATTRS
442
443/* Aliases for compatibility. */
444#define _m_empty _mm_empty
445#define _m_from_int _mm_cvtsi32_si64
446#define _m_from_int64 _mm_cvtsi64_m64
447#define _m_to_int _mm_cvtsi64_si32
448#define _m_to_int64 _mm_cvtm64_si64
449#define _m_packsswb _mm_packs_pi16
450#define _m_packssdw _mm_packs_pi32
451#define _m_packuswb _mm_packs_pu16
452#define _m_punpckhbw _mm_unpackhi_pi8
453#define _m_punpckhwd _mm_unpackhi_pi16
454#define _m_punpckhdq _mm_unpackhi_pi32
455#define _m_punpcklbw _mm_unpacklo_pi8
456#define _m_punpcklwd _mm_unpacklo_pi16
457#define _m_punpckldq _mm_unpacklo_pi32
458#define _m_paddb _mm_add_pi8
459#define _m_paddw _mm_add_pi16
460#define _m_paddd _mm_add_pi32
461#define _m_paddsb _mm_adds_pi8
462#define _m_paddsw _mm_adds_pi16
463#define _m_paddusb _mm_adds_pu8
464#define _m_paddusw _mm_adds_pu16
465#define _m_psubb _mm_sub_pi8
466#define _m_psubw _mm_sub_pi16
467#define _m_psubd _mm_sub_pi32
468#define _m_psubsb _mm_subs_pi8
469#define _m_psubsw _mm_subs_pi16
470#define _m_psubusb _mm_subs_pu8
471#define _m_psubusw _mm_subs_pu16
472#define _m_pmaddwd _mm_madd_pi16
473#define _m_pmulhw _mm_mulhi_pi16
474#define _m_pmullw _mm_mullo_pi16
475#define _m_psllw _mm_sll_pi16
476#define _m_psllwi _mm_slli_pi16
477#define _m_pslld _mm_sll_pi32
478#define _m_pslldi _mm_slli_pi32
479#define _m_psllq _mm_sll_si64
480#define _m_psllqi _mm_slli_si64
481#define _m_psraw _mm_sra_pi16
482#define _m_psrawi _mm_srai_pi16
483#define _m_psrad _mm_sra_pi32
484#define _m_psradi _mm_srai_pi32
485#define _m_psrlw _mm_srl_pi16
486#define _m_psrlwi _mm_srli_pi16
487#define _m_psrld _mm_srl_pi32
488#define _m_psrldi _mm_srli_pi32
489#define _m_psrlq _mm_srl_si64
490#define _m_psrlqi _mm_srli_si64
491#define _m_pand _mm_and_si64
492#define _m_pandn _mm_andnot_si64
493#define _m_por _mm_or_si64
494#define _m_pxor _mm_xor_si64
495#define _m_pcmpeqb _mm_cmpeq_pi8
496#define _m_pcmpeqw _mm_cmpeq_pi16
497#define _m_pcmpeqd _mm_cmpeq_pi32
498#define _m_pcmpgtb _mm_cmpgt_pi8
499#define _m_pcmpgtw _mm_cmpgt_pi16
500#define _m_pcmpgtd _mm_cmpgt_pi32
501
502#endif /* __MMINTRIN_H */
503
504