Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 1 | /*===---- 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 Carlsson | 4fd3e63 | 2008-12-26 00:57:11 +0000 | [diff] [blame] | 28 | #error "SSE instruction set not enabled" |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 29 | #else |
| 30 | |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 31 | #include <mmintrin.h> |
| 32 | |
Eric Christopher | 020f1ed | 2010-03-20 01:08:47 +0000 | [diff] [blame] | 33 | typedef int __v4si __attribute__((__vector_size__(16))); |
Anders Carlsson | 398082e | 2008-12-22 17:42:23 +0000 | [diff] [blame] | 34 | typedef float __v4sf __attribute__((__vector_size__(16))); |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 35 | typedef float __m128 __attribute__((__vector_size__(16))); |
| 36 | |
Anders Carlsson | 398082e | 2008-12-22 17:42:23 +0000 | [diff] [blame] | 37 | #include <mm_malloc.h> |
Anders Carlsson | 398082e | 2008-12-22 17:42:23 +0000 | [diff] [blame] | 38 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 39 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 40 | _mm_add_ss(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 41 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 42 | a[0] += b[0]; |
| 43 | return a; |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 46 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 47 | _mm_add_ps(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 48 | { |
| 49 | return a + b; |
| 50 | } |
| 51 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 52 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 53 | _mm_sub_ss(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 54 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 55 | a[0] -= b[0]; |
| 56 | return a; |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 59 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 60 | _mm_sub_ps(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 61 | { |
| 62 | return a - b; |
| 63 | } |
| 64 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 65 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 66 | _mm_mul_ss(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 67 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 68 | a[0] *= b[0]; |
| 69 | return a; |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 72 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 73 | _mm_mul_ps(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 74 | { |
| 75 | return a * b; |
| 76 | } |
| 77 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 78 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 79 | _mm_div_ss(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 80 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 81 | a[0] /= b[0]; |
| 82 | return a; |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 85 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 86 | _mm_div_ps(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 87 | { |
| 88 | return a / b; |
| 89 | } |
| 90 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 91 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 92 | _mm_sqrt_ss(__m128 a) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 93 | { |
| 94 | return __builtin_ia32_sqrtss(a); |
| 95 | } |
| 96 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 97 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 98 | _mm_sqrt_ps(__m128 a) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 99 | { |
| 100 | return __builtin_ia32_sqrtps(a); |
| 101 | } |
| 102 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 103 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 104 | _mm_rcp_ss(__m128 a) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 105 | { |
| 106 | return __builtin_ia32_rcpss(a); |
| 107 | } |
| 108 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 109 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 110 | _mm_rcp_ps(__m128 a) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 111 | { |
| 112 | return __builtin_ia32_rcpps(a); |
| 113 | } |
| 114 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 115 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 116 | _mm_rsqrt_ss(__m128 a) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 117 | { |
| 118 | return __builtin_ia32_rsqrtss(a); |
| 119 | } |
| 120 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 121 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 122 | _mm_rsqrt_ps(__m128 a) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 123 | { |
| 124 | return __builtin_ia32_rsqrtps(a); |
| 125 | } |
| 126 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 127 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 128 | _mm_min_ss(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 129 | { |
| 130 | return __builtin_ia32_minss(a, b); |
| 131 | } |
| 132 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 133 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 134 | _mm_min_ps(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 135 | { |
| 136 | return __builtin_ia32_minps(a, b); |
| 137 | } |
| 138 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 139 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 140 | _mm_max_ss(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 141 | { |
| 142 | return __builtin_ia32_maxss(a, b); |
| 143 | } |
| 144 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 145 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 146 | _mm_max_ps(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 147 | { |
| 148 | return __builtin_ia32_maxps(a, b); |
| 149 | } |
| 150 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 151 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 152 | _mm_and_ps(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 153 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 154 | return (__m128)((__v4si)a & (__v4si)b); |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 157 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 158 | _mm_andnot_ps(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 159 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 160 | return (__m128)(~(__v4si)a & (__v4si)b); |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 163 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 164 | _mm_or_ps(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 165 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 166 | return (__m128)((__v4si)a | (__v4si)b); |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 169 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 170 | _mm_xor_ps(__m128 a, __m128 b) |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 171 | { |
Chris Lattner | 2c48345 | 2010-01-07 00:36:41 +0000 | [diff] [blame] | 172 | return (__m128)((__v4si)a ^ (__v4si)b); |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 175 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 176 | _mm_cmpeq_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 177 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 178 | return (__m128)__builtin_ia32_cmpss(a, b, 0); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 181 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 182 | _mm_cmpeq_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 183 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 184 | return (__m128)__builtin_ia32_cmpps(a, b, 0); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 187 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 188 | _mm_cmplt_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 189 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 190 | return (__m128)__builtin_ia32_cmpss(a, b, 1); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 193 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 194 | _mm_cmplt_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 195 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 196 | return (__m128)__builtin_ia32_cmpps(a, b, 1); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 199 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 200 | _mm_cmple_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 201 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 202 | return (__m128)__builtin_ia32_cmpss(a, b, 2); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 205 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 206 | _mm_cmple_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 207 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 208 | return (__m128)__builtin_ia32_cmpps(a, b, 2); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 211 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 212 | _mm_cmpgt_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 213 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 214 | return (__m128)__builtin_ia32_cmpss(b, a, 1); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 217 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 218 | _mm_cmpgt_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 219 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 220 | return (__m128)__builtin_ia32_cmpps(b, a, 1); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 223 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 224 | _mm_cmpge_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 225 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 226 | return (__m128)__builtin_ia32_cmpss(b, a, 2); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 229 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 230 | _mm_cmpge_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 231 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 232 | return (__m128)__builtin_ia32_cmpps(b, a, 2); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 235 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 236 | _mm_cmpneq_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 237 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 238 | return (__m128)__builtin_ia32_cmpss(a, b, 4); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 241 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 242 | _mm_cmpneq_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 243 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 244 | return (__m128)__builtin_ia32_cmpps(a, b, 4); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 247 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 248 | _mm_cmpnlt_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 249 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 250 | return (__m128)__builtin_ia32_cmpss(a, b, 5); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 253 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 254 | _mm_cmpnlt_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 255 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 256 | return (__m128)__builtin_ia32_cmpps(a, b, 5); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 259 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 260 | _mm_cmpnle_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 261 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 262 | return (__m128)__builtin_ia32_cmpss(a, b, 6); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 265 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 266 | _mm_cmpnle_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 267 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 268 | return (__m128)__builtin_ia32_cmpps(a, b, 6); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 271 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 272 | _mm_cmpngt_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 273 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 274 | return (__m128)__builtin_ia32_cmpss(b, a, 5); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 277 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 278 | _mm_cmpngt_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 279 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 280 | return (__m128)__builtin_ia32_cmpps(b, a, 5); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 283 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 284 | _mm_cmpnge_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 285 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 286 | return (__m128)__builtin_ia32_cmpss(b, a, 6); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 289 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 290 | _mm_cmpnge_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 291 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 292 | return (__m128)__builtin_ia32_cmpps(b, a, 6); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 295 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 296 | _mm_cmpord_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 297 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 298 | return (__m128)__builtin_ia32_cmpss(a, b, 7); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 301 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 302 | _mm_cmpord_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 303 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 304 | return (__m128)__builtin_ia32_cmpps(a, b, 7); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 307 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 308 | _mm_cmpunord_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 309 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 310 | return (__m128)__builtin_ia32_cmpss(a, b, 3); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 313 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 314 | _mm_cmpunord_ps(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 315 | { |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 316 | return (__m128)__builtin_ia32_cmpps(a, b, 3); |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 319 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 320 | _mm_comieq_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 321 | { |
| 322 | return __builtin_ia32_comieq(a, b); |
| 323 | } |
| 324 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 325 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 326 | _mm_comilt_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 327 | { |
| 328 | return __builtin_ia32_comilt(a, b); |
| 329 | } |
| 330 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 331 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 332 | _mm_comile_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 333 | { |
| 334 | return __builtin_ia32_comile(a, b); |
| 335 | } |
| 336 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 337 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 338 | _mm_comigt_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 339 | { |
| 340 | return __builtin_ia32_comigt(a, b); |
| 341 | } |
| 342 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 343 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 344 | _mm_comige_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 345 | { |
| 346 | return __builtin_ia32_comige(a, b); |
| 347 | } |
| 348 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 349 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 350 | _mm_comineq_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 351 | { |
| 352 | return __builtin_ia32_comineq(a, b); |
| 353 | } |
| 354 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 355 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 356 | _mm_ucomieq_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 357 | { |
| 358 | return __builtin_ia32_ucomieq(a, b); |
| 359 | } |
| 360 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 361 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 362 | _mm_ucomilt_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 363 | { |
| 364 | return __builtin_ia32_ucomilt(a, b); |
| 365 | } |
| 366 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 367 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 368 | _mm_ucomile_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 369 | { |
| 370 | return __builtin_ia32_ucomile(a, b); |
| 371 | } |
| 372 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 373 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 374 | _mm_ucomigt_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 375 | { |
| 376 | return __builtin_ia32_ucomigt(a, b); |
| 377 | } |
| 378 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 379 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 380 | _mm_ucomige_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 381 | { |
| 382 | return __builtin_ia32_ucomige(a, b); |
| 383 | } |
| 384 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 385 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 386 | _mm_ucomineq_ss(__m128 a, __m128 b) |
Anders Carlsson | f62c681 | 2008-12-22 00:28:39 +0000 | [diff] [blame] | 387 | { |
| 388 | return __builtin_ia32_ucomineq(a, b); |
| 389 | } |
| 390 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 391 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 392 | _mm_cvtss_si32(__m128 a) |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 393 | { |
| 394 | return __builtin_ia32_cvtss2si(a); |
| 395 | } |
| 396 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 397 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Chris Lattner | ef5ebf6 | 2010-02-16 18:21:25 +0000 | [diff] [blame] | 398 | _mm_cvt_ss2si(__m128 a) |
| 399 | { |
| 400 | return _mm_cvtss_si32(a); |
| 401 | } |
| 402 | |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 403 | #ifdef __x86_64__ |
| 404 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 405 | static __inline__ long long __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 406 | _mm_cvtss_si64(__m128 a) |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 407 | { |
| 408 | return __builtin_ia32_cvtss2si64(a); |
| 409 | } |
| 410 | |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 411 | #endif |
| 412 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 413 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 414 | _mm_cvtps_pi32(__m128 a) |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 415 | { |
| 416 | return (__m64)__builtin_ia32_cvtps2pi(a); |
| 417 | } |
| 418 | |
Chandler Carruth | fa38c81 | 2010-07-22 06:47:28 +0000 | [diff] [blame] | 419 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
| 420 | _mm_cvt_ps2pi(__m128 a) |
| 421 | { |
| 422 | return _mm_cvtps_pi32(a); |
| 423 | } |
| 424 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 425 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 426 | _mm_cvttss_si32(__m128 a) |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 427 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 428 | return a[0]; |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 431 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Chris Lattner | ef5ebf6 | 2010-02-16 18:21:25 +0000 | [diff] [blame] | 432 | _mm_cvtt_ss2si(__m128 a) |
| 433 | { |
| 434 | return _mm_cvttss_si32(a); |
| 435 | } |
| 436 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 437 | static __inline__ long long __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 438 | _mm_cvttss_si64(__m128 a) |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 439 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 440 | return a[0]; |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 443 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 444 | _mm_cvttps_pi32(__m128 a) |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 445 | { |
| 446 | return (__m64)__builtin_ia32_cvttps2pi(a); |
| 447 | } |
| 448 | |
Chandler Carruth | fa38c81 | 2010-07-22 06:47:28 +0000 | [diff] [blame] | 449 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
| 450 | _mm_cvtt_ps2pi(__m128 a) |
| 451 | { |
| 452 | return _mm_cvttps_pi32(a); |
| 453 | } |
| 454 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 455 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 456 | _mm_cvtsi32_ss(__m128 a, int b) |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 457 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 458 | a[0] = b; |
| 459 | return a; |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Chandler Carruth | fa38c81 | 2010-07-22 06:47:28 +0000 | [diff] [blame] | 462 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Chandler Carruth | d74e398 | 2010-08-08 08:30:05 +0000 | [diff] [blame] | 463 | _mm_cvt_si2ss(__m128 a, int b) |
Chandler Carruth | fa38c81 | 2010-07-22 06:47:28 +0000 | [diff] [blame] | 464 | { |
| 465 | return _mm_cvtsi32_ss(a, b); |
| 466 | } |
| 467 | |
Anders Carlsson | 1b76b80 | 2008-12-22 01:26:50 +0000 | [diff] [blame] | 468 | #ifdef __x86_64__ |
| 469 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 470 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 471 | _mm_cvtsi64_ss(__m128 a, long long b) |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 472 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 473 | a[0] = b; |
| 474 | return a; |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Anders Carlsson | 1b76b80 | 2008-12-22 01:26:50 +0000 | [diff] [blame] | 477 | #endif |
| 478 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 479 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 480 | _mm_cvtpi32_ps(__m128 a, __m64 b) |
Anders Carlsson | 4fcc313 | 2008-12-22 00:48:30 +0000 | [diff] [blame] | 481 | { |
| 482 | return __builtin_ia32_cvtpi2ps(a, (__v2si)b); |
| 483 | } |
| 484 | |
Chandler Carruth | fa38c81 | 2010-07-22 06:47:28 +0000 | [diff] [blame] | 485 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Chandler Carruth | d74e398 | 2010-08-08 08:30:05 +0000 | [diff] [blame] | 486 | _mm_cvt_pi2ps(__m128 a, __m64 b) |
Chandler Carruth | fa38c81 | 2010-07-22 06:47:28 +0000 | [diff] [blame] | 487 | { |
| 488 | return _mm_cvtpi32_ps(a, b); |
| 489 | } |
| 490 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 491 | static __inline__ float __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 492 | _mm_cvtss_f32(__m128 a) |
Anders Carlsson | 1b76b80 | 2008-12-22 01:26:50 +0000 | [diff] [blame] | 493 | { |
Anders Carlsson | a6431dc | 2008-12-22 07:08:03 +0000 | [diff] [blame] | 494 | return a[0]; |
Anders Carlsson | 1b76b80 | 2008-12-22 01:26:50 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 497 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Chris Lattner | 21b91a3 | 2010-02-01 20:14:14 +0000 | [diff] [blame] | 498 | _mm_loadh_pi(__m128 a, const __m64 *p) |
Anders Carlsson | 9770086 | 2008-12-22 02:43:30 +0000 | [diff] [blame] | 499 | { |
Eli Friedman | e0ae8bd | 2009-06-07 07:12:56 +0000 | [diff] [blame] | 500 | __m128 b; |
| 501 | b[0] = *(float*)p; |
| 502 | b[1] = *((float*)p+1); |
| 503 | return __builtin_shufflevector(a, b, 0, 1, 4, 5); |
Anders Carlsson | 9770086 | 2008-12-22 02:43:30 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 506 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Chris Lattner | 21b91a3 | 2010-02-01 20:14:14 +0000 | [diff] [blame] | 507 | _mm_loadl_pi(__m128 a, const __m64 *p) |
Anders Carlsson | 9770086 | 2008-12-22 02:43:30 +0000 | [diff] [blame] | 508 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 509 | __m128 b; |
| 510 | b[0] = *(float*)p; |
| 511 | b[1] = *((float*)p+1); |
Eli Friedman | e0ae8bd | 2009-06-07 07:12:56 +0000 | [diff] [blame] | 512 | return __builtin_shufflevector(a, b, 4, 5, 2, 3); |
Anders Carlsson | 9770086 | 2008-12-22 02:43:30 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 515 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Chris Lattner | 21b91a3 | 2010-02-01 20:14:14 +0000 | [diff] [blame] | 516 | _mm_load_ss(const float *p) |
Anders Carlsson | 9770086 | 2008-12-22 02:43:30 +0000 | [diff] [blame] | 517 | { |
| 518 | return (__m128){ *p, 0, 0, 0 }; |
| 519 | } |
| 520 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 521 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Chris Lattner | 21b91a3 | 2010-02-01 20:14:14 +0000 | [diff] [blame] | 522 | _mm_load1_ps(const float *p) |
Anders Carlsson | 9770086 | 2008-12-22 02:43:30 +0000 | [diff] [blame] | 523 | { |
| 524 | return (__m128){ *p, *p, *p, *p }; |
| 525 | } |
| 526 | |
Eli Friedman | db7351a | 2009-06-02 05:55:48 +0000 | [diff] [blame] | 527 | #define _mm_load_ps1(p) _mm_load1_ps(p) |
| 528 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 529 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Chris Lattner | 21b91a3 | 2010-02-01 20:14:14 +0000 | [diff] [blame] | 530 | _mm_load_ps(const float *p) |
Anders Carlsson | 9770086 | 2008-12-22 02:43:30 +0000 | [diff] [blame] | 531 | { |
| 532 | return *(__m128*)p; |
| 533 | } |
| 534 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 535 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Chris Lattner | 21b91a3 | 2010-02-01 20:14:14 +0000 | [diff] [blame] | 536 | _mm_loadu_ps(const float *p) |
Anders Carlsson | 9770086 | 2008-12-22 02:43:30 +0000 | [diff] [blame] | 537 | { |
| 538 | return __builtin_ia32_loadups(p); |
| 539 | } |
| 540 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 541 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Chris Lattner | 21b91a3 | 2010-02-01 20:14:14 +0000 | [diff] [blame] | 542 | _mm_loadr_ps(const float *p) |
Anders Carlsson | 9770086 | 2008-12-22 02:43:30 +0000 | [diff] [blame] | 543 | { |
| 544 | __m128 a = _mm_load_ps(p); |
| 545 | return __builtin_shufflevector(a, a, 3, 2, 1, 0); |
| 546 | } |
| 547 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 548 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 549 | _mm_set_ss(float w) |
Anders Carlsson | a6ba001 | 2008-12-22 02:51:35 +0000 | [diff] [blame] | 550 | { |
| 551 | return (__m128){ w, 0, 0, 0 }; |
| 552 | } |
| 553 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 554 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 555 | _mm_set1_ps(float w) |
Anders Carlsson | a6ba001 | 2008-12-22 02:51:35 +0000 | [diff] [blame] | 556 | { |
| 557 | return (__m128){ w, w, w, w }; |
| 558 | } |
| 559 | |
Anders Carlsson | 12868cc | 2008-12-27 04:26:15 +0000 | [diff] [blame] | 560 | // Microsoft specific. |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 561 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 562 | _mm_set_ps1(float w) |
Anders Carlsson | 12868cc | 2008-12-27 04:26:15 +0000 | [diff] [blame] | 563 | { |
| 564 | return _mm_set1_ps(w); |
| 565 | } |
| 566 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 567 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 568 | _mm_set_ps(float z, float y, float x, float w) |
Anders Carlsson | a6ba001 | 2008-12-22 02:51:35 +0000 | [diff] [blame] | 569 | { |
| 570 | return (__m128){ w, x, y, z }; |
| 571 | } |
| 572 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 573 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 574 | _mm_setr_ps(float z, float y, float x, float w) |
Anders Carlsson | a6ba001 | 2008-12-22 02:51:35 +0000 | [diff] [blame] | 575 | { |
| 576 | return (__m128){ z, y, x, w }; |
| 577 | } |
| 578 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 579 | static __inline__ __m128 __attribute__((__always_inline__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 580 | _mm_setzero_ps(void) |
Anders Carlsson | a6ba001 | 2008-12-22 02:51:35 +0000 | [diff] [blame] | 581 | { |
| 582 | return (__m128){ 0, 0, 0, 0 }; |
| 583 | } |
| 584 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 585 | static __inline__ void __attribute__((__always_inline__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 586 | _mm_storeh_pi(__m64 *p, __m128 a) |
Anders Carlsson | 09b9305 | 2008-12-22 03:16:40 +0000 | [diff] [blame] | 587 | { |
| 588 | __builtin_ia32_storehps((__v2si *)p, a); |
| 589 | } |
| 590 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 591 | static __inline__ void __attribute__((__always_inline__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 592 | _mm_storel_pi(__m64 *p, __m128 a) |
Anders Carlsson | 09b9305 | 2008-12-22 03:16:40 +0000 | [diff] [blame] | 593 | { |
| 594 | __builtin_ia32_storelps((__v2si *)p, a); |
| 595 | } |
| 596 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 597 | static __inline__ void __attribute__((__always_inline__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 598 | _mm_store_ss(float *p, __m128 a) |
Anders Carlsson | 09b9305 | 2008-12-22 03:16:40 +0000 | [diff] [blame] | 599 | { |
| 600 | *p = a[0]; |
| 601 | } |
| 602 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 603 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 604 | _mm_storeu_ps(float *p, __m128 a) |
Anders Carlsson | 09b9305 | 2008-12-22 03:16:40 +0000 | [diff] [blame] | 605 | { |
| 606 | __builtin_ia32_storeups(p, a); |
| 607 | } |
| 608 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 609 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 610 | _mm_store1_ps(float *p, __m128 a) |
Anders Carlsson | 09b9305 | 2008-12-22 03:16:40 +0000 | [diff] [blame] | 611 | { |
| 612 | a = __builtin_shufflevector(a, a, 0, 0, 0, 0); |
| 613 | _mm_storeu_ps(p, a); |
| 614 | } |
| 615 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 616 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
Chandler Carruth | fa38c81 | 2010-07-22 06:47:28 +0000 | [diff] [blame] | 617 | _mm_store_ps1(float *p, __m128 a) |
| 618 | { |
| 619 | return _mm_store1_ps(p, a); |
| 620 | } |
| 621 | |
| 622 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 623 | _mm_store_ps(float *p, __m128 a) |
Anders Carlsson | 09b9305 | 2008-12-22 03:16:40 +0000 | [diff] [blame] | 624 | { |
| 625 | *(__m128 *)p = a; |
| 626 | } |
| 627 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 628 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 629 | _mm_storer_ps(float *p, __m128 a) |
Anders Carlsson | 09b9305 | 2008-12-22 03:16:40 +0000 | [diff] [blame] | 630 | { |
| 631 | a = __builtin_shufflevector(a, a, 3, 2, 1, 0); |
| 632 | _mm_store_ps(p, a); |
| 633 | } |
| 634 | |
Chris Lattner | 551f37c | 2010-08-27 20:10:06 +0000 | [diff] [blame] | 635 | #define _MM_HINT_T0 3 |
Anders Carlsson | dedad4e | 2008-12-22 03:50:21 +0000 | [diff] [blame] | 636 | #define _MM_HINT_T1 2 |
Chris Lattner | 551f37c | 2010-08-27 20:10:06 +0000 | [diff] [blame] | 637 | #define _MM_HINT_T2 1 |
Anders Carlsson | dedad4e | 2008-12-22 03:50:21 +0000 | [diff] [blame] | 638 | #define _MM_HINT_NTA 0 |
| 639 | |
Nick Lewycky | c2b9b36 | 2010-05-30 18:26:21 +0000 | [diff] [blame] | 640 | /* FIXME: We have to #define this because "sel" must be a constant integer, and |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 641 | Sema doesn't do any form of constant propagation yet. */ |
Anders Carlsson | dedad4e | 2008-12-22 03:50:21 +0000 | [diff] [blame] | 642 | |
Nick Lewycky | c2b9b36 | 2010-05-30 18:26:21 +0000 | [diff] [blame] | 643 | #define _mm_prefetch(a, sel) (__builtin_prefetch((void *)(a), 0, sel)) |
Anders Carlsson | dedad4e | 2008-12-22 03:50:21 +0000 | [diff] [blame] | 644 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 645 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 646 | _mm_stream_pi(__m64 *p, __m64 a) |
Anders Carlsson | dedad4e | 2008-12-22 03:50:21 +0000 | [diff] [blame] | 647 | { |
| 648 | __builtin_ia32_movntq(p, a); |
| 649 | } |
| 650 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 651 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 652 | _mm_stream_ps(float *p, __m128 a) |
Anders Carlsson | dedad4e | 2008-12-22 03:50:21 +0000 | [diff] [blame] | 653 | { |
| 654 | __builtin_ia32_movntps(p, a); |
| 655 | } |
| 656 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 657 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 658 | _mm_sfence(void) |
Anders Carlsson | dedad4e | 2008-12-22 03:50:21 +0000 | [diff] [blame] | 659 | { |
| 660 | __builtin_ia32_sfence(); |
| 661 | } |
| 662 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 663 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 664 | _mm_extract_pi16(__m64 a, int n) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 665 | { |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 666 | __v4hi b = (__v4hi)a; |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 667 | return (unsigned short)b[n & 3]; |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 670 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 671 | _mm_insert_pi16(__m64 a, int d, int n) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 672 | { |
Eli Friedman | 80c8004 | 2009-06-06 02:13:04 +0000 | [diff] [blame] | 673 | __v4hi b = (__v4hi)a; |
| 674 | b[n & 3] = d; |
Eli Friedman | 17d2e3a | 2009-06-06 03:45:06 +0000 | [diff] [blame] | 675 | return (__m64)b; |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 678 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 679 | _mm_max_pi16(__m64 a, __m64 b) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 680 | { |
| 681 | return (__m64)__builtin_ia32_pmaxsw((__v4hi)a, (__v4hi)b); |
| 682 | } |
| 683 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 684 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 685 | _mm_max_pu8(__m64 a, __m64 b) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 686 | { |
| 687 | return (__m64)__builtin_ia32_pmaxub((__v8qi)a, (__v8qi)b); |
| 688 | } |
| 689 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 690 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 691 | _mm_min_pi16(__m64 a, __m64 b) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 692 | { |
| 693 | return (__m64)__builtin_ia32_pminsw((__v4hi)a, (__v4hi)b); |
| 694 | } |
| 695 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 696 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 697 | _mm_min_pu8(__m64 a, __m64 b) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 698 | { |
| 699 | return (__m64)__builtin_ia32_pminub((__v8qi)a, (__v8qi)b); |
| 700 | } |
| 701 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 702 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 703 | _mm_movemask_pi8(__m64 a) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 704 | { |
| 705 | return __builtin_ia32_pmovmskb((__v8qi)a); |
| 706 | } |
| 707 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 708 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 709 | _mm_mulhi_pu16(__m64 a, __m64 b) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 710 | { |
| 711 | return (__m64)__builtin_ia32_pmulhuw((__v4hi)a, (__v4hi)b); |
| 712 | } |
| 713 | |
Eli Friedman | 098136a | 2009-06-06 08:08:06 +0000 | [diff] [blame] | 714 | #define _mm_shuffle_pi16(a, n) \ |
Chris Lattner | 6999339 | 2010-10-02 21:32:59 +0000 | [diff] [blame] | 715 | ((__m64)__builtin_ia32_pshufw(a, n)) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 716 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 717 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 718 | _mm_maskmove_si64(__m64 d, __m64 n, char *p) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 719 | { |
| 720 | __builtin_ia32_maskmovq((__v8qi)d, (__v8qi)n, p); |
| 721 | } |
| 722 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 723 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 724 | _mm_avg_pu8(__m64 a, __m64 b) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 725 | { |
| 726 | return (__m64)__builtin_ia32_pavgb((__v8qi)a, (__v8qi)b); |
| 727 | } |
| 728 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 729 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 730 | _mm_avg_pu16(__m64 a, __m64 b) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 731 | { |
| 732 | return (__m64)__builtin_ia32_pavgw((__v4hi)a, (__v4hi)b); |
| 733 | } |
| 734 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 735 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 736 | _mm_sad_pu8(__m64 a, __m64 b) |
Anders Carlsson | 62af71c | 2008-12-22 04:55:36 +0000 | [diff] [blame] | 737 | { |
| 738 | return (__m64)__builtin_ia32_psadbw((__v8qi)a, (__v8qi)b); |
| 739 | } |
Anders Carlsson | c1f9afd | 2008-12-22 05:00:07 +0000 | [diff] [blame] | 740 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 741 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 742 | _mm_getcsr(void) |
Anders Carlsson | c1f9afd | 2008-12-22 05:00:07 +0000 | [diff] [blame] | 743 | { |
| 744 | return __builtin_ia32_stmxcsr(); |
| 745 | } |
| 746 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 747 | static __inline__ void __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 748 | _mm_setcsr(unsigned int i) |
Anders Carlsson | c1f9afd | 2008-12-22 05:00:07 +0000 | [diff] [blame] | 749 | { |
| 750 | __builtin_ia32_ldmxcsr(i); |
| 751 | } |
| 752 | |
Eli Friedman | 098136a | 2009-06-06 08:08:06 +0000 | [diff] [blame] | 753 | #define _mm_shuffle_ps(a, b, mask) \ |
Daniel Dunbar | 79e5ab7 | 2010-06-02 16:35:01 +0000 | [diff] [blame] | 754 | (__builtin_shufflevector((__v4sf)(a), (__v4sf)(b), \ |
Chris Lattner | f805a6c | 2010-05-15 05:53:53 +0000 | [diff] [blame] | 755 | (mask) & 0x3, ((mask) & 0xc) >> 2, \ |
Eli Friedman | 098136a | 2009-06-06 08:08:06 +0000 | [diff] [blame] | 756 | (((mask) & 0x30) >> 4) + 4, \ |
| 757 | (((mask) & 0xc0) >> 6) + 4)) |
Anders Carlsson | 50099cb | 2008-12-22 05:20:34 +0000 | [diff] [blame] | 758 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 759 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 760 | _mm_unpackhi_ps(__m128 a, __m128 b) |
Anders Carlsson | 50099cb | 2008-12-22 05:20:34 +0000 | [diff] [blame] | 761 | { |
| 762 | return __builtin_shufflevector(a, b, 2, 6, 3, 7); |
| 763 | } |
| 764 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 765 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 766 | _mm_unpacklo_ps(__m128 a, __m128 b) |
Anders Carlsson | 50099cb | 2008-12-22 05:20:34 +0000 | [diff] [blame] | 767 | { |
| 768 | return __builtin_shufflevector(a, b, 0, 4, 1, 5); |
| 769 | } |
| 770 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 771 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 772 | _mm_move_ss(__m128 a, __m128 b) |
Anders Carlsson | 50099cb | 2008-12-22 05:20:34 +0000 | [diff] [blame] | 773 | { |
| 774 | return __builtin_shufflevector(a, b, 4, 1, 2, 3); |
| 775 | } |
| 776 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 777 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 778 | _mm_movehl_ps(__m128 a, __m128 b) |
Anders Carlsson | 50099cb | 2008-12-22 05:20:34 +0000 | [diff] [blame] | 779 | { |
| 780 | return __builtin_shufflevector(a, b, 6, 7, 2, 3); |
| 781 | } |
| 782 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 783 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 784 | _mm_movelh_ps(__m128 a, __m128 b) |
Anders Carlsson | 50099cb | 2008-12-22 05:20:34 +0000 | [diff] [blame] | 785 | { |
| 786 | return __builtin_shufflevector(a, b, 0, 1, 4, 5); |
| 787 | } |
| 788 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 789 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 790 | _mm_cvtpi16_ps(__m64 a) |
Anders Carlsson | a6431dc | 2008-12-22 07:08:03 +0000 | [diff] [blame] | 791 | { |
| 792 | __m64 b, c; |
| 793 | __m128 r; |
| 794 | |
| 795 | b = _mm_setzero_si64(); |
| 796 | b = _mm_cmpgt_pi16(b, a); |
| 797 | c = _mm_unpackhi_pi16(a, b); |
| 798 | r = _mm_setzero_ps(); |
| 799 | r = _mm_cvtpi32_ps(r, c); |
| 800 | r = _mm_movelh_ps(r, r); |
| 801 | c = _mm_unpacklo_pi16(a, b); |
| 802 | r = _mm_cvtpi32_ps(r, c); |
| 803 | |
| 804 | return r; |
| 805 | } |
| 806 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 807 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 808 | _mm_cvtpu16_ps(__m64 a) |
Anders Carlsson | a6431dc | 2008-12-22 07:08:03 +0000 | [diff] [blame] | 809 | { |
| 810 | __m64 b, c; |
| 811 | __m128 r; |
| 812 | |
| 813 | b = _mm_setzero_si64(); |
| 814 | c = _mm_unpackhi_pi16(a, b); |
| 815 | r = _mm_setzero_ps(); |
| 816 | r = _mm_cvtpi32_ps(r, c); |
| 817 | r = _mm_movelh_ps(r, r); |
| 818 | c = _mm_unpacklo_pi16(a, b); |
| 819 | r = _mm_cvtpi32_ps(r, c); |
| 820 | |
| 821 | return r; |
| 822 | } |
| 823 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 824 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 825 | _mm_cvtpi8_ps(__m64 a) |
Anders Carlsson | a6431dc | 2008-12-22 07:08:03 +0000 | [diff] [blame] | 826 | { |
| 827 | __m64 b; |
| 828 | |
| 829 | b = _mm_setzero_si64(); |
| 830 | b = _mm_cmpgt_pi8(b, a); |
| 831 | b = _mm_unpacklo_pi8(a, b); |
| 832 | |
| 833 | return _mm_cvtpi16_ps(b); |
| 834 | } |
| 835 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 836 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 837 | _mm_cvtpu8_ps(__m64 a) |
Anders Carlsson | a6431dc | 2008-12-22 07:08:03 +0000 | [diff] [blame] | 838 | { |
| 839 | __m64 b; |
| 840 | |
| 841 | b = _mm_setzero_si64(); |
| 842 | b = _mm_unpacklo_pi8(a, b); |
| 843 | |
| 844 | return _mm_cvtpi16_ps(b); |
| 845 | } |
| 846 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 847 | static __inline__ __m128 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 848 | _mm_cvtpi32x2_ps(__m64 a, __m64 b) |
Anders Carlsson | a6431dc | 2008-12-22 07:08:03 +0000 | [diff] [blame] | 849 | { |
| 850 | __m128 c; |
| 851 | |
| 852 | c = _mm_setzero_ps(); |
| 853 | c = _mm_cvtpi32_ps(c, b); |
| 854 | c = _mm_movelh_ps(c, c); |
| 855 | |
| 856 | return _mm_cvtpi32_ps(c, a); |
| 857 | } |
| 858 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 859 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 860 | _mm_cvtps_pi16(__m128 a) |
Anders Carlsson | a6431dc | 2008-12-22 07:08:03 +0000 | [diff] [blame] | 861 | { |
| 862 | __m64 b, c; |
| 863 | |
| 864 | b = _mm_cvtps_pi32(a); |
| 865 | a = _mm_movehl_ps(a, a); |
| 866 | c = _mm_cvtps_pi32(a); |
| 867 | |
| 868 | return _mm_packs_pi16(b, c); |
| 869 | } |
| 870 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 871 | static __inline__ __m64 __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 872 | _mm_cvtps_pi8(__m128 a) |
Anders Carlsson | a6431dc | 2008-12-22 07:08:03 +0000 | [diff] [blame] | 873 | { |
| 874 | __m64 b, c; |
| 875 | |
| 876 | b = _mm_cvtps_pi16(a); |
| 877 | c = _mm_setzero_si64(); |
| 878 | |
| 879 | return _mm_packs_pi16(b, c); |
| 880 | } |
| 881 | |
Chris Lattner | 1bddbcb | 2010-03-22 18:14:12 +0000 | [diff] [blame] | 882 | static __inline__ int __attribute__((__always_inline__, __nodebug__)) |
Mike Stump | dae4413 | 2009-02-13 14:24:50 +0000 | [diff] [blame] | 883 | _mm_movemask_ps(__m128 a) |
Anders Carlsson | 50099cb | 2008-12-22 05:20:34 +0000 | [diff] [blame] | 884 | { |
| 885 | return __builtin_ia32_movmskps(a); |
| 886 | } |
| 887 | |
Anders Carlsson | b595509 | 2008-12-22 05:42:03 +0000 | [diff] [blame] | 888 | #define _MM_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w)) |
| 889 | |
Anders Carlsson | 4cc4427 | 2009-02-11 06:29:32 +0000 | [diff] [blame] | 890 | #define _MM_EXCEPT_INVALID (0x0001) |
| 891 | #define _MM_EXCEPT_DENORM (0x0002) |
| 892 | #define _MM_EXCEPT_DIV_ZERO (0x0004) |
| 893 | #define _MM_EXCEPT_OVERFLOW (0x0008) |
| 894 | #define _MM_EXCEPT_UNDERFLOW (0x0010) |
| 895 | #define _MM_EXCEPT_INEXACT (0x0020) |
Anders Carlsson | bbd1fa2 | 2009-01-21 01:49:39 +0000 | [diff] [blame] | 896 | #define _MM_EXCEPT_MASK (0x003f) |
Anders Carlsson | 4cc4427 | 2009-02-11 06:29:32 +0000 | [diff] [blame] | 897 | |
Anders Carlsson | bbd1fa2 | 2009-01-21 01:49:39 +0000 | [diff] [blame] | 898 | #define _MM_MASK_INVALID (0x0080) |
| 899 | #define _MM_MASK_DENORM (0x0100) |
Anders Carlsson | a837a07 | 2009-02-14 04:01:38 +0000 | [diff] [blame] | 900 | #define _MM_MASK_DIV_ZERO (0x0200) |
| 901 | #define _MM_MASK_OVERFLOW (0x0400) |
| 902 | #define _MM_MASK_UNDERFLOW (0x0800) |
| 903 | #define _MM_MASK_INEXACT (0x1000) |
Anders Carlsson | bbd1fa2 | 2009-01-21 01:49:39 +0000 | [diff] [blame] | 904 | #define _MM_MASK_MASK (0x1f80) |
| 905 | |
Anders Carlsson | bbd1fa2 | 2009-01-21 01:49:39 +0000 | [diff] [blame] | 906 | #define _MM_ROUND_NEAREST (0x0000) |
| 907 | #define _MM_ROUND_DOWN (0x2000) |
| 908 | #define _MM_ROUND_UP (0x4000) |
| 909 | #define _MM_ROUND_TOWARD_ZERO (0x6000) |
Anders Carlsson | 4cc4427 | 2009-02-11 06:29:32 +0000 | [diff] [blame] | 910 | #define _MM_ROUND_MASK (0x6000) |
Anders Carlsson | bbd1fa2 | 2009-01-21 01:49:39 +0000 | [diff] [blame] | 911 | |
| 912 | #define _MM_FLUSH_ZERO_MASK (0x8000) |
| 913 | #define _MM_FLUSH_ZERO_ON (0x8000) |
| 914 | #define _MM_FLUSH_ZERO_OFF (0x8000) |
Anders Carlsson | b595509 | 2008-12-22 05:42:03 +0000 | [diff] [blame] | 915 | |
| 916 | #define _MM_GET_EXCEPTION_MASK() (_mm_getcsr() & _MM_MASK_MASK) |
| 917 | #define _MM_GET_EXCEPTION_STATE() (_mm_getcsr() & _MM_EXCEPT_MASK) |
Anders Carlsson | 62005c1 | 2009-01-20 21:51:44 +0000 | [diff] [blame] | 918 | #define _MM_GET_FLUSH_ZERO_MODE() (_mm_getcsr() & _MM_FLUSH_ZERO_MASK) |
Anders Carlsson | b595509 | 2008-12-22 05:42:03 +0000 | [diff] [blame] | 919 | #define _MM_GET_ROUNDING_MODE() (_mm_getcsr() & _MM_ROUND_MASK) |
| 920 | |
Anders Carlsson | 62005c1 | 2009-01-20 21:51:44 +0000 | [diff] [blame] | 921 | #define _MM_SET_EXCEPTION_MASK(x) (_mm_setcsr((_mm_getcsr() & ~_MM_MASK_MASK) | (x))) |
Anders Carlsson | b595509 | 2008-12-22 05:42:03 +0000 | [diff] [blame] | 922 | #define _MM_SET_EXCEPTION_STATE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_EXCEPT_MASK) | (x))) |
Anders Carlsson | 62005c1 | 2009-01-20 21:51:44 +0000 | [diff] [blame] | 923 | #define _MM_SET_FLUSH_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_FLUSH_ZERO_MASK) | (x))) |
Anders Carlsson | b595509 | 2008-12-22 05:42:03 +0000 | [diff] [blame] | 924 | #define _MM_SET_ROUNDING_MODE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_ROUND_MASK) | (x))) |
| 925 | |
| 926 | #define _MM_TRANSPOSE4_PS(row0, row1, row2, row3) \ |
| 927 | do { \ |
| 928 | __m128 tmp3, tmp2, tmp1, tmp0; \ |
| 929 | tmp0 = _mm_unpacklo_ps((row0), (row1)); \ |
| 930 | tmp2 = _mm_unpacklo_ps((row2), (row3)); \ |
| 931 | tmp1 = _mm_unpackhi_ps((row0), (row1)); \ |
| 932 | tmp3 = _mm_unpackhi_ps((row2), (row3)); \ |
| 933 | (row0) = _mm_movelh_ps(tmp0, tmp2); \ |
| 934 | (row1) = _mm_movehl_ps(tmp2, tmp0); \ |
| 935 | (row2) = _mm_movelh_ps(tmp1, tmp3); \ |
Chris Lattner | 9afb227 | 2010-01-27 07:54:50 +0000 | [diff] [blame] | 936 | (row3) = _mm_movehl_ps(tmp3, tmp1); \ |
Anders Carlsson | b595509 | 2008-12-22 05:42:03 +0000 | [diff] [blame] | 937 | } while (0) |
| 938 | |
Chandler Carruth | fa38c81 | 2010-07-22 06:47:28 +0000 | [diff] [blame] | 939 | /* Aliases for compatibility. */ |
| 940 | #define _m_pextrw _mm_extract_pi16 |
| 941 | #define _m_pinsrw _mm_insert_pi16 |
| 942 | #define _m_pmaxsw _mm_max_pi16 |
| 943 | #define _m_pmaxub _mm_max_pu8 |
| 944 | #define _m_pminsw _mm_min_pi16 |
| 945 | #define _m_pminub _mm_min_pu8 |
| 946 | #define _m_pmovmskb _mm_movemask_pi8 |
| 947 | #define _m_pmulhuw _mm_mulhi_pu16 |
| 948 | #define _m_pshufw _mm_shuffle_pi16 |
| 949 | #define _m_maskmovq _mm_maskmove_si64 |
| 950 | #define _m_pavgb _mm_avg_pu8 |
| 951 | #define _m_pavgw _mm_avg_pu16 |
| 952 | #define _m_psadbw _mm_sad_pu8 |
| 953 | #define _m_ _mm_ |
| 954 | #define _m_ _mm_ |
| 955 | |
Eli Friedman | c7d95dc | 2009-06-11 18:50:02 +0000 | [diff] [blame] | 956 | /* Ugly hack for backwards-compatibility (compatible with gcc) */ |
| 957 | #ifdef __SSE2__ |
Daniel Dunbar | 3eef3e1 | 2009-06-07 08:33:23 +0000 | [diff] [blame] | 958 | #include <emmintrin.h> |
Eli Friedman | c7d95dc | 2009-06-11 18:50:02 +0000 | [diff] [blame] | 959 | #endif |
Daniel Dunbar | 3eef3e1 | 2009-06-07 08:33:23 +0000 | [diff] [blame] | 960 | |
Anders Carlsson | 566d8da | 2008-12-22 00:01:20 +0000 | [diff] [blame] | 961 | #endif /* __SSE__ */ |
| 962 | |
| 963 | #endif /* __XMMINTRIN_H */ |