blob: 42dd3e8d3b8787aabf9ad222d04564bf2f628702 [file] [log] [blame]
Anders Carlsson566d8da2008-12-22 00:01:20 +00001/*===---- xmmintrin.h - SSE 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 __XMMINTRIN_H
25#define __XMMINTRIN_H
26
27#ifndef __SSE__
Anders Carlsson4fd3e632008-12-26 00:57:11 +000028#error "SSE instruction set not enabled"
Anders Carlsson566d8da2008-12-22 00:01:20 +000029#else
30
Anders Carlsson4fcc3132008-12-22 00:48:30 +000031#include <mmintrin.h>
32
Eric Christopher020f1ed2010-03-20 01:08:47 +000033typedef int __v4si __attribute__((__vector_size__(16)));
Anders Carlsson398082e2008-12-22 17:42:23 +000034typedef float __v4sf __attribute__((__vector_size__(16)));
Anders Carlsson566d8da2008-12-22 00:01:20 +000035typedef float __m128 __attribute__((__vector_size__(16)));
36
Chandler Carruth7acb9532010-11-22 08:06:31 +000037// This header should only be included in a hosted environment as it depends on
38// a standard library to provide allocation routines.
39#if __STDC_HOSTED__
Anders Carlsson398082e2008-12-22 17:42:23 +000040#include <mm_malloc.h>
Chandler Carruth7acb9532010-11-22 08:06:31 +000041#endif
Anders Carlsson398082e2008-12-22 17:42:23 +000042
Chris Lattner1bddbcb2010-03-22 18:14:12 +000043static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +000044_mm_add_ss(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +000045{
Eli Friedman80c80042009-06-06 02:13:04 +000046 a[0] += b[0];
47 return a;
Anders Carlsson566d8da2008-12-22 00:01:20 +000048}
49
Chris Lattner1bddbcb2010-03-22 18:14:12 +000050static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +000051_mm_add_ps(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +000052{
53 return a + b;
54}
55
Chris Lattner1bddbcb2010-03-22 18:14:12 +000056static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +000057_mm_sub_ss(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +000058{
Eli Friedman80c80042009-06-06 02:13:04 +000059 a[0] -= b[0];
60 return a;
Anders Carlsson566d8da2008-12-22 00:01:20 +000061}
62
Chris Lattner1bddbcb2010-03-22 18:14:12 +000063static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +000064_mm_sub_ps(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +000065{
66 return a - b;
67}
68
Chris Lattner1bddbcb2010-03-22 18:14:12 +000069static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +000070_mm_mul_ss(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +000071{
Eli Friedman80c80042009-06-06 02:13:04 +000072 a[0] *= b[0];
73 return a;
Anders Carlsson566d8da2008-12-22 00:01:20 +000074}
75
Chris Lattner1bddbcb2010-03-22 18:14:12 +000076static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +000077_mm_mul_ps(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +000078{
79 return a * b;
80}
81
Chris Lattner1bddbcb2010-03-22 18:14:12 +000082static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +000083_mm_div_ss(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +000084{
Eli Friedman80c80042009-06-06 02:13:04 +000085 a[0] /= b[0];
86 return a;
Anders Carlsson566d8da2008-12-22 00:01:20 +000087}
88
Chris Lattner1bddbcb2010-03-22 18:14:12 +000089static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +000090_mm_div_ps(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +000091{
92 return a / b;
93}
94
Chris Lattner1bddbcb2010-03-22 18:14:12 +000095static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +000096_mm_sqrt_ss(__m128 a)
Anders Carlsson566d8da2008-12-22 00:01:20 +000097{
98 return __builtin_ia32_sqrtss(a);
99}
100
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000101static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000102_mm_sqrt_ps(__m128 a)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000103{
104 return __builtin_ia32_sqrtps(a);
105}
106
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000107static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000108_mm_rcp_ss(__m128 a)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000109{
110 return __builtin_ia32_rcpss(a);
111}
112
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000113static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000114_mm_rcp_ps(__m128 a)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000115{
116 return __builtin_ia32_rcpps(a);
117}
118
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000119static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000120_mm_rsqrt_ss(__m128 a)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000121{
122 return __builtin_ia32_rsqrtss(a);
123}
124
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000125static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000126_mm_rsqrt_ps(__m128 a)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000127{
128 return __builtin_ia32_rsqrtps(a);
129}
130
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000131static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000132_mm_min_ss(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000133{
134 return __builtin_ia32_minss(a, b);
135}
136
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000137static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000138_mm_min_ps(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000139{
140 return __builtin_ia32_minps(a, b);
141}
142
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000143static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000144_mm_max_ss(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000145{
146 return __builtin_ia32_maxss(a, b);
147}
148
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000149static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000150_mm_max_ps(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000151{
152 return __builtin_ia32_maxps(a, b);
153}
154
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000155static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000156_mm_and_ps(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000157{
Eli Friedman80c80042009-06-06 02:13:04 +0000158 return (__m128)((__v4si)a & (__v4si)b);
Anders Carlsson566d8da2008-12-22 00:01:20 +0000159}
160
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000161static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000162_mm_andnot_ps(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000163{
Eli Friedman80c80042009-06-06 02:13:04 +0000164 return (__m128)(~(__v4si)a & (__v4si)b);
Anders Carlsson566d8da2008-12-22 00:01:20 +0000165}
166
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000167static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000168_mm_or_ps(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000169{
Eli Friedman80c80042009-06-06 02:13:04 +0000170 return (__m128)((__v4si)a | (__v4si)b);
Anders Carlsson566d8da2008-12-22 00:01:20 +0000171}
172
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000173static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000174_mm_xor_ps(__m128 a, __m128 b)
Anders Carlsson566d8da2008-12-22 00:01:20 +0000175{
Chris Lattner2c483452010-01-07 00:36:41 +0000176 return (__m128)((__v4si)a ^ (__v4si)b);
Anders Carlsson566d8da2008-12-22 00:01:20 +0000177}
178
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000179static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000180_mm_cmpeq_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000181{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000182 return (__m128)__builtin_ia32_cmpss(a, b, 0);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000183}
184
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000185static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000186_mm_cmpeq_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000187{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000188 return (__m128)__builtin_ia32_cmpps(a, b, 0);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000189}
190
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000191static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000192_mm_cmplt_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000193{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000194 return (__m128)__builtin_ia32_cmpss(a, b, 1);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000195}
196
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000197static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000198_mm_cmplt_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000199{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000200 return (__m128)__builtin_ia32_cmpps(a, b, 1);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000201}
202
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000203static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000204_mm_cmple_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000205{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000206 return (__m128)__builtin_ia32_cmpss(a, b, 2);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000207}
208
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000209static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000210_mm_cmple_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000211{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000212 return (__m128)__builtin_ia32_cmpps(a, b, 2);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000213}
214
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000215static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000216_mm_cmpgt_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000217{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000218 return (__m128)__builtin_ia32_cmpss(b, a, 1);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000219}
220
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000221static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000222_mm_cmpgt_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000223{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000224 return (__m128)__builtin_ia32_cmpps(b, a, 1);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000225}
226
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000227static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000228_mm_cmpge_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000229{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000230 return (__m128)__builtin_ia32_cmpss(b, a, 2);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000231}
232
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000233static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000234_mm_cmpge_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000235{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000236 return (__m128)__builtin_ia32_cmpps(b, a, 2);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000237}
238
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000239static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000240_mm_cmpneq_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000241{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000242 return (__m128)__builtin_ia32_cmpss(a, b, 4);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000243}
244
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000245static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000246_mm_cmpneq_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000247{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000248 return (__m128)__builtin_ia32_cmpps(a, b, 4);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000249}
250
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000251static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000252_mm_cmpnlt_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000253{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000254 return (__m128)__builtin_ia32_cmpss(a, b, 5);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000255}
256
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000257static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000258_mm_cmpnlt_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000259{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000260 return (__m128)__builtin_ia32_cmpps(a, b, 5);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000261}
262
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000263static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000264_mm_cmpnle_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000265{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000266 return (__m128)__builtin_ia32_cmpss(a, b, 6);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000267}
268
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000269static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000270_mm_cmpnle_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000271{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000272 return (__m128)__builtin_ia32_cmpps(a, b, 6);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000273}
274
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000275static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000276_mm_cmpngt_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000277{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000278 return (__m128)__builtin_ia32_cmpss(b, a, 5);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000279}
280
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000281static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000282_mm_cmpngt_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000283{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000284 return (__m128)__builtin_ia32_cmpps(b, a, 5);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000285}
286
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000287static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000288_mm_cmpnge_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000289{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000290 return (__m128)__builtin_ia32_cmpss(b, a, 6);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000291}
292
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000293static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000294_mm_cmpnge_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000295{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000296 return (__m128)__builtin_ia32_cmpps(b, a, 6);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000297}
298
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000299static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000300_mm_cmpord_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000301{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000302 return (__m128)__builtin_ia32_cmpss(a, b, 7);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000303}
304
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000305static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000306_mm_cmpord_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000307{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000308 return (__m128)__builtin_ia32_cmpps(a, b, 7);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000309}
310
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000311static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000312_mm_cmpunord_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000313{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000314 return (__m128)__builtin_ia32_cmpss(a, b, 3);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000315}
316
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000317static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000318_mm_cmpunord_ps(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000319{
Anders Carlsson79dcf5f2009-05-18 19:16:46 +0000320 return (__m128)__builtin_ia32_cmpps(a, b, 3);
Anders Carlssonf62c6812008-12-22 00:28:39 +0000321}
322
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000323static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000324_mm_comieq_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000325{
326 return __builtin_ia32_comieq(a, b);
327}
328
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000329static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000330_mm_comilt_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000331{
332 return __builtin_ia32_comilt(a, b);
333}
334
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000335static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000336_mm_comile_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000337{
338 return __builtin_ia32_comile(a, b);
339}
340
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000341static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000342_mm_comigt_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000343{
344 return __builtin_ia32_comigt(a, b);
345}
346
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000347static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000348_mm_comige_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000349{
350 return __builtin_ia32_comige(a, b);
351}
352
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000353static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000354_mm_comineq_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000355{
356 return __builtin_ia32_comineq(a, b);
357}
358
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000359static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000360_mm_ucomieq_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000361{
362 return __builtin_ia32_ucomieq(a, b);
363}
364
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000365static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000366_mm_ucomilt_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000367{
368 return __builtin_ia32_ucomilt(a, b);
369}
370
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000371static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000372_mm_ucomile_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000373{
374 return __builtin_ia32_ucomile(a, b);
375}
376
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000377static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000378_mm_ucomigt_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000379{
380 return __builtin_ia32_ucomigt(a, b);
381}
382
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000383static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000384_mm_ucomige_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000385{
386 return __builtin_ia32_ucomige(a, b);
387}
388
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000389static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000390_mm_ucomineq_ss(__m128 a, __m128 b)
Anders Carlssonf62c6812008-12-22 00:28:39 +0000391{
392 return __builtin_ia32_ucomineq(a, b);
393}
394
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000395static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000396_mm_cvtss_si32(__m128 a)
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000397{
398 return __builtin_ia32_cvtss2si(a);
399}
400
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000401static __inline__ int __attribute__((__always_inline__, __nodebug__))
Chris Lattneref5ebf62010-02-16 18:21:25 +0000402_mm_cvt_ss2si(__m128 a)
403{
404 return _mm_cvtss_si32(a);
405}
406
Eli Friedman80c80042009-06-06 02:13:04 +0000407#ifdef __x86_64__
408
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000409static __inline__ long long __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000410_mm_cvtss_si64(__m128 a)
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000411{
412 return __builtin_ia32_cvtss2si64(a);
413}
414
Eli Friedman80c80042009-06-06 02:13:04 +0000415#endif
416
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000417static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000418_mm_cvtps_pi32(__m128 a)
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000419{
420 return (__m64)__builtin_ia32_cvtps2pi(a);
421}
422
Chandler Carruthfa38c812010-07-22 06:47:28 +0000423static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
424_mm_cvt_ps2pi(__m128 a)
425{
426 return _mm_cvtps_pi32(a);
427}
428
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000429static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000430_mm_cvttss_si32(__m128 a)
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000431{
Eli Friedman80c80042009-06-06 02:13:04 +0000432 return a[0];
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000433}
434
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000435static __inline__ int __attribute__((__always_inline__, __nodebug__))
Chris Lattneref5ebf62010-02-16 18:21:25 +0000436_mm_cvtt_ss2si(__m128 a)
437{
438 return _mm_cvttss_si32(a);
439}
440
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000441static __inline__ long long __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000442_mm_cvttss_si64(__m128 a)
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000443{
Eli Friedman80c80042009-06-06 02:13:04 +0000444 return a[0];
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000445}
446
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000447static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000448_mm_cvttps_pi32(__m128 a)
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000449{
450 return (__m64)__builtin_ia32_cvttps2pi(a);
451}
452
Chandler Carruthfa38c812010-07-22 06:47:28 +0000453static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
454_mm_cvtt_ps2pi(__m128 a)
455{
456 return _mm_cvttps_pi32(a);
457}
458
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000459static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000460_mm_cvtsi32_ss(__m128 a, int b)
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000461{
Eli Friedman80c80042009-06-06 02:13:04 +0000462 a[0] = b;
463 return a;
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000464}
465
Chandler Carruthfa38c812010-07-22 06:47:28 +0000466static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Chandler Carruthd74e3982010-08-08 08:30:05 +0000467_mm_cvt_si2ss(__m128 a, int b)
Chandler Carruthfa38c812010-07-22 06:47:28 +0000468{
469 return _mm_cvtsi32_ss(a, b);
470}
471
Anders Carlsson1b76b802008-12-22 01:26:50 +0000472#ifdef __x86_64__
473
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000474static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000475_mm_cvtsi64_ss(__m128 a, long long b)
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000476{
Eli Friedman80c80042009-06-06 02:13:04 +0000477 a[0] = b;
478 return a;
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000479}
480
Anders Carlsson1b76b802008-12-22 01:26:50 +0000481#endif
482
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000483static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000484_mm_cvtpi32_ps(__m128 a, __m64 b)
Anders Carlsson4fcc3132008-12-22 00:48:30 +0000485{
486 return __builtin_ia32_cvtpi2ps(a, (__v2si)b);
487}
488
Chandler Carruthfa38c812010-07-22 06:47:28 +0000489static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Chandler Carruthd74e3982010-08-08 08:30:05 +0000490_mm_cvt_pi2ps(__m128 a, __m64 b)
Chandler Carruthfa38c812010-07-22 06:47:28 +0000491{
492 return _mm_cvtpi32_ps(a, b);
493}
494
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000495static __inline__ float __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000496_mm_cvtss_f32(__m128 a)
Anders Carlsson1b76b802008-12-22 01:26:50 +0000497{
Anders Carlssona6431dc2008-12-22 07:08:03 +0000498 return a[0];
Anders Carlsson1b76b802008-12-22 01:26:50 +0000499}
500
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000501static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Chris Lattner21b91a32010-02-01 20:14:14 +0000502_mm_loadh_pi(__m128 a, const __m64 *p)
Anders Carlsson97700862008-12-22 02:43:30 +0000503{
Eli Friedmane0ae8bd2009-06-07 07:12:56 +0000504 __m128 b;
505 b[0] = *(float*)p;
506 b[1] = *((float*)p+1);
507 return __builtin_shufflevector(a, b, 0, 1, 4, 5);
Anders Carlsson97700862008-12-22 02:43:30 +0000508}
509
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000510static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Chris Lattner21b91a32010-02-01 20:14:14 +0000511_mm_loadl_pi(__m128 a, const __m64 *p)
Anders Carlsson97700862008-12-22 02:43:30 +0000512{
Eli Friedman80c80042009-06-06 02:13:04 +0000513 __m128 b;
514 b[0] = *(float*)p;
515 b[1] = *((float*)p+1);
Eli Friedmane0ae8bd2009-06-07 07:12:56 +0000516 return __builtin_shufflevector(a, b, 4, 5, 2, 3);
Anders Carlsson97700862008-12-22 02:43:30 +0000517}
518
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000519static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Chris Lattner21b91a32010-02-01 20:14:14 +0000520_mm_load_ss(const float *p)
Anders Carlsson97700862008-12-22 02:43:30 +0000521{
522 return (__m128){ *p, 0, 0, 0 };
523}
524
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000525static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Chris Lattner21b91a32010-02-01 20:14:14 +0000526_mm_load1_ps(const float *p)
Anders Carlsson97700862008-12-22 02:43:30 +0000527{
528 return (__m128){ *p, *p, *p, *p };
529}
530
Eli Friedmandb7351a2009-06-02 05:55:48 +0000531#define _mm_load_ps1(p) _mm_load1_ps(p)
532
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000533static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Chris Lattner21b91a32010-02-01 20:14:14 +0000534_mm_load_ps(const float *p)
Anders Carlsson97700862008-12-22 02:43:30 +0000535{
536 return *(__m128*)p;
537}
538
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000539static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Chris Lattner21b91a32010-02-01 20:14:14 +0000540_mm_loadu_ps(const float *p)
Anders Carlsson97700862008-12-22 02:43:30 +0000541{
542 return __builtin_ia32_loadups(p);
543}
544
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000545static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Chris Lattner21b91a32010-02-01 20:14:14 +0000546_mm_loadr_ps(const float *p)
Anders Carlsson97700862008-12-22 02:43:30 +0000547{
548 __m128 a = _mm_load_ps(p);
549 return __builtin_shufflevector(a, a, 3, 2, 1, 0);
550}
551
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000552static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000553_mm_set_ss(float w)
Anders Carlssona6ba0012008-12-22 02:51:35 +0000554{
555 return (__m128){ w, 0, 0, 0 };
556}
557
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000558static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000559_mm_set1_ps(float w)
Anders Carlssona6ba0012008-12-22 02:51:35 +0000560{
561 return (__m128){ w, w, w, w };
562}
563
Anders Carlsson12868cc2008-12-27 04:26:15 +0000564// Microsoft specific.
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000565static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000566_mm_set_ps1(float w)
Anders Carlsson12868cc2008-12-27 04:26:15 +0000567{
568 return _mm_set1_ps(w);
569}
570
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000571static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000572_mm_set_ps(float z, float y, float x, float w)
Anders Carlssona6ba0012008-12-22 02:51:35 +0000573{
574 return (__m128){ w, x, y, z };
575}
576
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000577static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000578_mm_setr_ps(float z, float y, float x, float w)
Anders Carlssona6ba0012008-12-22 02:51:35 +0000579{
580 return (__m128){ z, y, x, w };
581}
582
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000583static __inline__ __m128 __attribute__((__always_inline__))
Mike Stumpdae44132009-02-13 14:24:50 +0000584_mm_setzero_ps(void)
Anders Carlssona6ba0012008-12-22 02:51:35 +0000585{
586 return (__m128){ 0, 0, 0, 0 };
587}
588
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000589static __inline__ void __attribute__((__always_inline__))
Mike Stumpdae44132009-02-13 14:24:50 +0000590_mm_storeh_pi(__m64 *p, __m128 a)
Anders Carlsson09b93052008-12-22 03:16:40 +0000591{
592 __builtin_ia32_storehps((__v2si *)p, a);
593}
594
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000595static __inline__ void __attribute__((__always_inline__))
Mike Stumpdae44132009-02-13 14:24:50 +0000596_mm_storel_pi(__m64 *p, __m128 a)
Anders Carlsson09b93052008-12-22 03:16:40 +0000597{
598 __builtin_ia32_storelps((__v2si *)p, a);
599}
600
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000601static __inline__ void __attribute__((__always_inline__))
Mike Stumpdae44132009-02-13 14:24:50 +0000602_mm_store_ss(float *p, __m128 a)
Anders Carlsson09b93052008-12-22 03:16:40 +0000603{
604 *p = a[0];
605}
606
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000607static __inline__ void __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000608_mm_storeu_ps(float *p, __m128 a)
Anders Carlsson09b93052008-12-22 03:16:40 +0000609{
610 __builtin_ia32_storeups(p, a);
611}
612
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000613static __inline__ void __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000614_mm_store1_ps(float *p, __m128 a)
Anders Carlsson09b93052008-12-22 03:16:40 +0000615{
616 a = __builtin_shufflevector(a, a, 0, 0, 0, 0);
617 _mm_storeu_ps(p, a);
618}
619
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000620static __inline__ void __attribute__((__always_inline__, __nodebug__))
Chandler Carruthfa38c812010-07-22 06:47:28 +0000621_mm_store_ps1(float *p, __m128 a)
622{
623 return _mm_store1_ps(p, a);
624}
625
626static __inline__ void __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000627_mm_store_ps(float *p, __m128 a)
Anders Carlsson09b93052008-12-22 03:16:40 +0000628{
629 *(__m128 *)p = a;
630}
631
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000632static __inline__ void __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000633_mm_storer_ps(float *p, __m128 a)
Anders Carlsson09b93052008-12-22 03:16:40 +0000634{
635 a = __builtin_shufflevector(a, a, 3, 2, 1, 0);
636 _mm_store_ps(p, a);
637}
638
Chris Lattner551f37c2010-08-27 20:10:06 +0000639#define _MM_HINT_T0 3
Anders Carlssondedad4e2008-12-22 03:50:21 +0000640#define _MM_HINT_T1 2
Chris Lattner551f37c2010-08-27 20:10:06 +0000641#define _MM_HINT_T2 1
Anders Carlssondedad4e2008-12-22 03:50:21 +0000642#define _MM_HINT_NTA 0
643
Nick Lewyckyc2b9b362010-05-30 18:26:21 +0000644/* FIXME: We have to #define this because "sel" must be a constant integer, and
Anders Carlsson62af71c2008-12-22 04:55:36 +0000645 Sema doesn't do any form of constant propagation yet. */
Anders Carlssondedad4e2008-12-22 03:50:21 +0000646
Nick Lewyckyc2b9b362010-05-30 18:26:21 +0000647#define _mm_prefetch(a, sel) (__builtin_prefetch((void *)(a), 0, sel))
Anders Carlssondedad4e2008-12-22 03:50:21 +0000648
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000649static __inline__ void __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000650_mm_stream_pi(__m64 *p, __m64 a)
Anders Carlssondedad4e2008-12-22 03:50:21 +0000651{
652 __builtin_ia32_movntq(p, a);
653}
654
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000655static __inline__ void __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000656_mm_stream_ps(float *p, __m128 a)
Anders Carlssondedad4e2008-12-22 03:50:21 +0000657{
658 __builtin_ia32_movntps(p, a);
659}
660
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000661static __inline__ void __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000662_mm_sfence(void)
Anders Carlssondedad4e2008-12-22 03:50:21 +0000663{
664 __builtin_ia32_sfence();
665}
666
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000667static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000668_mm_extract_pi16(__m64 a, int n)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000669{
Anders Carlsson62af71c2008-12-22 04:55:36 +0000670 __v4hi b = (__v4hi)a;
Eli Friedman80c80042009-06-06 02:13:04 +0000671 return (unsigned short)b[n & 3];
Anders Carlsson62af71c2008-12-22 04:55:36 +0000672}
673
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000674static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000675_mm_insert_pi16(__m64 a, int d, int n)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000676{
Eli Friedman80c80042009-06-06 02:13:04 +0000677 __v4hi b = (__v4hi)a;
678 b[n & 3] = d;
Eli Friedman17d2e3a2009-06-06 03:45:06 +0000679 return (__m64)b;
Anders Carlsson62af71c2008-12-22 04:55:36 +0000680}
681
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000682static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000683_mm_max_pi16(__m64 a, __m64 b)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000684{
685 return (__m64)__builtin_ia32_pmaxsw((__v4hi)a, (__v4hi)b);
686}
687
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000688static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000689_mm_max_pu8(__m64 a, __m64 b)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000690{
691 return (__m64)__builtin_ia32_pmaxub((__v8qi)a, (__v8qi)b);
692}
693
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000694static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000695_mm_min_pi16(__m64 a, __m64 b)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000696{
697 return (__m64)__builtin_ia32_pminsw((__v4hi)a, (__v4hi)b);
698}
699
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000700static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000701_mm_min_pu8(__m64 a, __m64 b)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000702{
703 return (__m64)__builtin_ia32_pminub((__v8qi)a, (__v8qi)b);
704}
705
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000706static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000707_mm_movemask_pi8(__m64 a)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000708{
709 return __builtin_ia32_pmovmskb((__v8qi)a);
710}
711
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000712static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000713_mm_mulhi_pu16(__m64 a, __m64 b)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000714{
715 return (__m64)__builtin_ia32_pmulhuw((__v4hi)a, (__v4hi)b);
716}
717
Eli Friedman098136a2009-06-06 08:08:06 +0000718#define _mm_shuffle_pi16(a, n) \
Chris Lattner69993392010-10-02 21:32:59 +0000719 ((__m64)__builtin_ia32_pshufw(a, n))
Anders Carlsson62af71c2008-12-22 04:55:36 +0000720
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000721static __inline__ void __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000722_mm_maskmove_si64(__m64 d, __m64 n, char *p)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000723{
724 __builtin_ia32_maskmovq((__v8qi)d, (__v8qi)n, p);
725}
726
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000727static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000728_mm_avg_pu8(__m64 a, __m64 b)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000729{
730 return (__m64)__builtin_ia32_pavgb((__v8qi)a, (__v8qi)b);
731}
732
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000733static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000734_mm_avg_pu16(__m64 a, __m64 b)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000735{
736 return (__m64)__builtin_ia32_pavgw((__v4hi)a, (__v4hi)b);
737}
738
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000739static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000740_mm_sad_pu8(__m64 a, __m64 b)
Anders Carlsson62af71c2008-12-22 04:55:36 +0000741{
742 return (__m64)__builtin_ia32_psadbw((__v8qi)a, (__v8qi)b);
743}
Anders Carlssonc1f9afd2008-12-22 05:00:07 +0000744
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000745static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000746_mm_getcsr(void)
Anders Carlssonc1f9afd2008-12-22 05:00:07 +0000747{
748 return __builtin_ia32_stmxcsr();
749}
750
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000751static __inline__ void __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000752_mm_setcsr(unsigned int i)
Anders Carlssonc1f9afd2008-12-22 05:00:07 +0000753{
754 __builtin_ia32_ldmxcsr(i);
755}
756
Eli Friedman098136a2009-06-06 08:08:06 +0000757#define _mm_shuffle_ps(a, b, mask) \
Daniel Dunbar79e5ab72010-06-02 16:35:01 +0000758 (__builtin_shufflevector((__v4sf)(a), (__v4sf)(b), \
Chris Lattnerf805a6c2010-05-15 05:53:53 +0000759 (mask) & 0x3, ((mask) & 0xc) >> 2, \
Eli Friedman098136a2009-06-06 08:08:06 +0000760 (((mask) & 0x30) >> 4) + 4, \
761 (((mask) & 0xc0) >> 6) + 4))
Anders Carlsson50099cb2008-12-22 05:20:34 +0000762
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000763static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000764_mm_unpackhi_ps(__m128 a, __m128 b)
Anders Carlsson50099cb2008-12-22 05:20:34 +0000765{
766 return __builtin_shufflevector(a, b, 2, 6, 3, 7);
767}
768
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000769static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000770_mm_unpacklo_ps(__m128 a, __m128 b)
Anders Carlsson50099cb2008-12-22 05:20:34 +0000771{
772 return __builtin_shufflevector(a, b, 0, 4, 1, 5);
773}
774
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000775static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000776_mm_move_ss(__m128 a, __m128 b)
Anders Carlsson50099cb2008-12-22 05:20:34 +0000777{
778 return __builtin_shufflevector(a, b, 4, 1, 2, 3);
779}
780
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000781static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000782_mm_movehl_ps(__m128 a, __m128 b)
Anders Carlsson50099cb2008-12-22 05:20:34 +0000783{
784 return __builtin_shufflevector(a, b, 6, 7, 2, 3);
785}
786
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000787static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000788_mm_movelh_ps(__m128 a, __m128 b)
Anders Carlsson50099cb2008-12-22 05:20:34 +0000789{
790 return __builtin_shufflevector(a, b, 0, 1, 4, 5);
791}
792
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000793static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000794_mm_cvtpi16_ps(__m64 a)
Anders Carlssona6431dc2008-12-22 07:08:03 +0000795{
796 __m64 b, c;
797 __m128 r;
798
799 b = _mm_setzero_si64();
800 b = _mm_cmpgt_pi16(b, a);
801 c = _mm_unpackhi_pi16(a, b);
802 r = _mm_setzero_ps();
803 r = _mm_cvtpi32_ps(r, c);
804 r = _mm_movelh_ps(r, r);
805 c = _mm_unpacklo_pi16(a, b);
806 r = _mm_cvtpi32_ps(r, c);
807
808 return r;
809}
810
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000811static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000812_mm_cvtpu16_ps(__m64 a)
Anders Carlssona6431dc2008-12-22 07:08:03 +0000813{
814 __m64 b, c;
815 __m128 r;
816
817 b = _mm_setzero_si64();
818 c = _mm_unpackhi_pi16(a, b);
819 r = _mm_setzero_ps();
820 r = _mm_cvtpi32_ps(r, c);
821 r = _mm_movelh_ps(r, r);
822 c = _mm_unpacklo_pi16(a, b);
823 r = _mm_cvtpi32_ps(r, c);
824
825 return r;
826}
827
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000828static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000829_mm_cvtpi8_ps(__m64 a)
Anders Carlssona6431dc2008-12-22 07:08:03 +0000830{
831 __m64 b;
832
833 b = _mm_setzero_si64();
834 b = _mm_cmpgt_pi8(b, a);
835 b = _mm_unpacklo_pi8(a, b);
836
837 return _mm_cvtpi16_ps(b);
838}
839
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000840static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000841_mm_cvtpu8_ps(__m64 a)
Anders Carlssona6431dc2008-12-22 07:08:03 +0000842{
843 __m64 b;
844
845 b = _mm_setzero_si64();
846 b = _mm_unpacklo_pi8(a, b);
847
848 return _mm_cvtpi16_ps(b);
849}
850
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000851static __inline__ __m128 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000852_mm_cvtpi32x2_ps(__m64 a, __m64 b)
Anders Carlssona6431dc2008-12-22 07:08:03 +0000853{
854 __m128 c;
855
856 c = _mm_setzero_ps();
857 c = _mm_cvtpi32_ps(c, b);
858 c = _mm_movelh_ps(c, c);
859
860 return _mm_cvtpi32_ps(c, a);
861}
862
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000863static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000864_mm_cvtps_pi16(__m128 a)
Anders Carlssona6431dc2008-12-22 07:08:03 +0000865{
866 __m64 b, c;
867
868 b = _mm_cvtps_pi32(a);
869 a = _mm_movehl_ps(a, a);
870 c = _mm_cvtps_pi32(a);
871
872 return _mm_packs_pi16(b, c);
873}
874
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000875static __inline__ __m64 __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000876_mm_cvtps_pi8(__m128 a)
Anders Carlssona6431dc2008-12-22 07:08:03 +0000877{
878 __m64 b, c;
879
880 b = _mm_cvtps_pi16(a);
881 c = _mm_setzero_si64();
882
883 return _mm_packs_pi16(b, c);
884}
885
Chris Lattner1bddbcb2010-03-22 18:14:12 +0000886static __inline__ int __attribute__((__always_inline__, __nodebug__))
Mike Stumpdae44132009-02-13 14:24:50 +0000887_mm_movemask_ps(__m128 a)
Anders Carlsson50099cb2008-12-22 05:20:34 +0000888{
889 return __builtin_ia32_movmskps(a);
890}
891
Anders Carlssonb5955092008-12-22 05:42:03 +0000892#define _MM_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
893
Anders Carlsson4cc44272009-02-11 06:29:32 +0000894#define _MM_EXCEPT_INVALID (0x0001)
895#define _MM_EXCEPT_DENORM (0x0002)
896#define _MM_EXCEPT_DIV_ZERO (0x0004)
897#define _MM_EXCEPT_OVERFLOW (0x0008)
898#define _MM_EXCEPT_UNDERFLOW (0x0010)
899#define _MM_EXCEPT_INEXACT (0x0020)
Anders Carlssonbbd1fa22009-01-21 01:49:39 +0000900#define _MM_EXCEPT_MASK (0x003f)
Anders Carlsson4cc44272009-02-11 06:29:32 +0000901
Anders Carlssonbbd1fa22009-01-21 01:49:39 +0000902#define _MM_MASK_INVALID (0x0080)
903#define _MM_MASK_DENORM (0x0100)
Anders Carlssona837a072009-02-14 04:01:38 +0000904#define _MM_MASK_DIV_ZERO (0x0200)
905#define _MM_MASK_OVERFLOW (0x0400)
906#define _MM_MASK_UNDERFLOW (0x0800)
907#define _MM_MASK_INEXACT (0x1000)
Anders Carlssonbbd1fa22009-01-21 01:49:39 +0000908#define _MM_MASK_MASK (0x1f80)
909
Anders Carlssonbbd1fa22009-01-21 01:49:39 +0000910#define _MM_ROUND_NEAREST (0x0000)
911#define _MM_ROUND_DOWN (0x2000)
912#define _MM_ROUND_UP (0x4000)
913#define _MM_ROUND_TOWARD_ZERO (0x6000)
Anders Carlsson4cc44272009-02-11 06:29:32 +0000914#define _MM_ROUND_MASK (0x6000)
Anders Carlssonbbd1fa22009-01-21 01:49:39 +0000915
916#define _MM_FLUSH_ZERO_MASK (0x8000)
917#define _MM_FLUSH_ZERO_ON (0x8000)
918#define _MM_FLUSH_ZERO_OFF (0x8000)
Anders Carlssonb5955092008-12-22 05:42:03 +0000919
920#define _MM_GET_EXCEPTION_MASK() (_mm_getcsr() & _MM_MASK_MASK)
921#define _MM_GET_EXCEPTION_STATE() (_mm_getcsr() & _MM_EXCEPT_MASK)
Anders Carlsson62005c12009-01-20 21:51:44 +0000922#define _MM_GET_FLUSH_ZERO_MODE() (_mm_getcsr() & _MM_FLUSH_ZERO_MASK)
Anders Carlssonb5955092008-12-22 05:42:03 +0000923#define _MM_GET_ROUNDING_MODE() (_mm_getcsr() & _MM_ROUND_MASK)
924
Anders Carlsson62005c12009-01-20 21:51:44 +0000925#define _MM_SET_EXCEPTION_MASK(x) (_mm_setcsr((_mm_getcsr() & ~_MM_MASK_MASK) | (x)))
Anders Carlssonb5955092008-12-22 05:42:03 +0000926#define _MM_SET_EXCEPTION_STATE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_EXCEPT_MASK) | (x)))
Anders Carlsson62005c12009-01-20 21:51:44 +0000927#define _MM_SET_FLUSH_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_FLUSH_ZERO_MASK) | (x)))
Anders Carlssonb5955092008-12-22 05:42:03 +0000928#define _MM_SET_ROUNDING_MODE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_ROUND_MASK) | (x)))
929
930#define _MM_TRANSPOSE4_PS(row0, row1, row2, row3) \
931do { \
932 __m128 tmp3, tmp2, tmp1, tmp0; \
933 tmp0 = _mm_unpacklo_ps((row0), (row1)); \
934 tmp2 = _mm_unpacklo_ps((row2), (row3)); \
935 tmp1 = _mm_unpackhi_ps((row0), (row1)); \
936 tmp3 = _mm_unpackhi_ps((row2), (row3)); \
937 (row0) = _mm_movelh_ps(tmp0, tmp2); \
938 (row1) = _mm_movehl_ps(tmp2, tmp0); \
939 (row2) = _mm_movelh_ps(tmp1, tmp3); \
Chris Lattner9afb2272010-01-27 07:54:50 +0000940 (row3) = _mm_movehl_ps(tmp3, tmp1); \
Anders Carlssonb5955092008-12-22 05:42:03 +0000941} while (0)
942
Chandler Carruthfa38c812010-07-22 06:47:28 +0000943/* Aliases for compatibility. */
944#define _m_pextrw _mm_extract_pi16
945#define _m_pinsrw _mm_insert_pi16
946#define _m_pmaxsw _mm_max_pi16
947#define _m_pmaxub _mm_max_pu8
948#define _m_pminsw _mm_min_pi16
949#define _m_pminub _mm_min_pu8
950#define _m_pmovmskb _mm_movemask_pi8
951#define _m_pmulhuw _mm_mulhi_pu16
952#define _m_pshufw _mm_shuffle_pi16
953#define _m_maskmovq _mm_maskmove_si64
954#define _m_pavgb _mm_avg_pu8
955#define _m_pavgw _mm_avg_pu16
956#define _m_psadbw _mm_sad_pu8
957#define _m_ _mm_
958#define _m_ _mm_
959
Eli Friedmanc7d95dc2009-06-11 18:50:02 +0000960/* Ugly hack for backwards-compatibility (compatible with gcc) */
961#ifdef __SSE2__
Daniel Dunbar3eef3e12009-06-07 08:33:23 +0000962#include <emmintrin.h>
Eli Friedmanc7d95dc2009-06-11 18:50:02 +0000963#endif
Daniel Dunbar3eef3e12009-06-07 08:33:23 +0000964
Anders Carlsson566d8da2008-12-22 00:01:20 +0000965#endif /* __SSE__ */
966
967#endif /* __XMMINTRIN_H */