Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1 | /*===---- avxintrin.h - AVX 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 | |
Benjamin Kramer | 6f35f3c | 2010-08-20 23:00:03 +0000 | [diff] [blame] | 24 | #ifndef __IMMINTRIN_H |
| 25 | #error "Never use <avxintrin.h> directly; include <immintrin.h> instead." |
| 26 | #endif |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 27 | |
Richard Smith | 49e5644 | 2013-07-14 05:41:45 +0000 | [diff] [blame] | 28 | #ifndef __AVXINTRIN_H |
| 29 | #define __AVXINTRIN_H |
| 30 | |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 31 | typedef double __v4df __attribute__ ((__vector_size__ (32))); |
| 32 | typedef float __v8sf __attribute__ ((__vector_size__ (32))); |
| 33 | typedef long long __v4di __attribute__ ((__vector_size__ (32))); |
| 34 | typedef int __v8si __attribute__ ((__vector_size__ (32))); |
| 35 | typedef short __v16hi __attribute__ ((__vector_size__ (32))); |
| 36 | typedef char __v32qi __attribute__ ((__vector_size__ (32))); |
| 37 | |
| 38 | typedef float __m256 __attribute__ ((__vector_size__ (32))); |
| 39 | typedef double __m256d __attribute__((__vector_size__(32))); |
| 40 | typedef long long __m256i __attribute__((__vector_size__(32))); |
| 41 | |
| 42 | /* Arithmetic */ |
| 43 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 44 | _mm256_add_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 45 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 46 | return __a+__b; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 50 | _mm256_add_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 51 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 52 | return __a+__b; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 56 | _mm256_sub_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 57 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 58 | return __a-__b; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 62 | _mm256_sub_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 63 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 64 | return __a-__b; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 68 | _mm256_addsub_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 69 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 70 | return (__m256d)__builtin_ia32_addsubpd256((__v4df)__a, (__v4df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 74 | _mm256_addsub_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 75 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 76 | return (__m256)__builtin_ia32_addsubps256((__v8sf)__a, (__v8sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 80 | _mm256_div_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 81 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 82 | return __a / __b; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 86 | _mm256_div_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 87 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 88 | return __a / __b; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 92 | _mm256_max_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 93 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 94 | return (__m256d)__builtin_ia32_maxpd256((__v4df)__a, (__v4df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 98 | _mm256_max_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 99 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 100 | return (__m256)__builtin_ia32_maxps256((__v8sf)__a, (__v8sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 104 | _mm256_min_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 105 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 106 | return (__m256d)__builtin_ia32_minpd256((__v4df)__a, (__v4df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 110 | _mm256_min_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 111 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 112 | return (__m256)__builtin_ia32_minps256((__v8sf)__a, (__v8sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 116 | _mm256_mul_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 117 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 118 | return __a * __b; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 122 | _mm256_mul_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 123 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 124 | return __a * __b; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 128 | _mm256_sqrt_pd(__m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 129 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 130 | return (__m256d)__builtin_ia32_sqrtpd256((__v4df)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 134 | _mm256_sqrt_ps(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 135 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 136 | return (__m256)__builtin_ia32_sqrtps256((__v8sf)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 140 | _mm256_rsqrt_ps(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 141 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 142 | return (__m256)__builtin_ia32_rsqrtps256((__v8sf)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 146 | _mm256_rcp_ps(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 147 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 148 | return (__m256)__builtin_ia32_rcpps256((__v8sf)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Chad Rosier | 060d03b | 2011-12-17 00:15:26 +0000 | [diff] [blame] | 151 | #define _mm256_round_pd(V, M) __extension__ ({ \ |
| 152 | __m256d __V = (V); \ |
Craig Topper | 9f00948 | 2011-12-24 07:55:14 +0000 | [diff] [blame] | 153 | (__m256d)__builtin_ia32_roundpd256((__v4df)__V, (M)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 154 | |
Chad Rosier | 060d03b | 2011-12-17 00:15:26 +0000 | [diff] [blame] | 155 | #define _mm256_round_ps(V, M) __extension__ ({ \ |
| 156 | __m256 __V = (V); \ |
Craig Topper | 9f00948 | 2011-12-24 07:55:14 +0000 | [diff] [blame] | 157 | (__m256)__builtin_ia32_roundps256((__v8sf)__V, (M)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 158 | |
| 159 | #define _mm256_ceil_pd(V) _mm256_round_pd((V), _MM_FROUND_CEIL) |
| 160 | #define _mm256_floor_pd(V) _mm256_round_pd((V), _MM_FROUND_FLOOR) |
| 161 | #define _mm256_ceil_ps(V) _mm256_round_ps((V), _MM_FROUND_CEIL) |
| 162 | #define _mm256_floor_ps(V) _mm256_round_ps((V), _MM_FROUND_FLOOR) |
| 163 | |
| 164 | /* Logical */ |
| 165 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 166 | _mm256_and_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 167 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 168 | return (__m256d)((__v4di)__a & (__v4di)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 172 | _mm256_and_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 173 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 174 | return (__m256)((__v8si)__a & (__v8si)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 178 | _mm256_andnot_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 179 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 180 | return (__m256d)(~(__v4di)__a & (__v4di)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 184 | _mm256_andnot_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 185 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 186 | return (__m256)(~(__v8si)__a & (__v8si)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 190 | _mm256_or_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 191 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 192 | return (__m256d)((__v4di)__a | (__v4di)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 196 | _mm256_or_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 197 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 198 | return (__m256)((__v8si)__a | (__v8si)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 202 | _mm256_xor_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 203 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 204 | return (__m256d)((__v4di)__a ^ (__v4di)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 208 | _mm256_xor_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 209 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 210 | return (__m256)((__v8si)__a ^ (__v8si)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /* Horizontal arithmetic */ |
| 214 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 215 | _mm256_hadd_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 216 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 217 | return (__m256d)__builtin_ia32_haddpd256((__v4df)__a, (__v4df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 221 | _mm256_hadd_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 222 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 223 | return (__m256)__builtin_ia32_haddps256((__v8sf)__a, (__v8sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 227 | _mm256_hsub_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 228 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 229 | return (__m256d)__builtin_ia32_hsubpd256((__v4df)__a, (__v4df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 233 | _mm256_hsub_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 234 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 235 | return (__m256)__builtin_ia32_hsubps256((__v8sf)__a, (__v8sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /* Vector permutations */ |
| 239 | static __inline __m128d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 240 | _mm_permutevar_pd(__m128d __a, __m128i __c) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 241 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 242 | return (__m128d)__builtin_ia32_vpermilvarpd((__v2df)__a, (__v2di)__c); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 246 | _mm256_permutevar_pd(__m256d __a, __m256i __c) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 247 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 248 | return (__m256d)__builtin_ia32_vpermilvarpd256((__v4df)__a, (__v4di)__c); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static __inline __m128 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 252 | _mm_permutevar_ps(__m128 __a, __m128i __c) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 253 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 254 | return (__m128)__builtin_ia32_vpermilvarps((__v4sf)__a, (__v4si)__c); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 258 | _mm256_permutevar_ps(__m256 __a, __m256i __c) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 259 | { |
Craig Topper | 9fee8ab | 2015-01-31 06:33:59 +0000 | [diff] [blame] | 260 | return (__m256)__builtin_ia32_vpermilvarps256((__v8sf)__a, (__v8si)__c); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Chad Rosier | 93375d5 | 2011-12-17 01:39:56 +0000 | [diff] [blame] | 263 | #define _mm_permute_pd(A, C) __extension__ ({ \ |
| 264 | __m128d __A = (A); \ |
Craig Topper | fec9f8e | 2012-02-08 05:16:54 +0000 | [diff] [blame] | 265 | (__m128d)__builtin_shufflevector((__v2df)__A, (__v2df) _mm_setzero_pd(), \ |
| 266 | (C) & 0x1, ((C) & 0x2) >> 1); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 267 | |
Chad Rosier | 93375d5 | 2011-12-17 01:39:56 +0000 | [diff] [blame] | 268 | #define _mm256_permute_pd(A, C) __extension__ ({ \ |
| 269 | __m256d __A = (A); \ |
Craig Topper | fec9f8e | 2012-02-08 05:16:54 +0000 | [diff] [blame] | 270 | (__m256d)__builtin_shufflevector((__v4df)__A, (__v4df) _mm256_setzero_pd(), \ |
| 271 | (C) & 0x1, ((C) & 0x2) >> 1, \ |
| 272 | 2 + (((C) & 0x4) >> 2), \ |
| 273 | 2 + (((C) & 0x8) >> 3)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 274 | |
Chad Rosier | 7caca84 | 2011-12-17 01:51:05 +0000 | [diff] [blame] | 275 | #define _mm_permute_ps(A, C) __extension__ ({ \ |
| 276 | __m128 __A = (A); \ |
Craig Topper | fec9f8e | 2012-02-08 05:16:54 +0000 | [diff] [blame] | 277 | (__m128)__builtin_shufflevector((__v4sf)__A, (__v4sf) _mm_setzero_ps(), \ |
| 278 | (C) & 0x3, ((C) & 0xc) >> 2, \ |
Craig Topper | 678a53c | 2012-03-30 05:09:18 +0000 | [diff] [blame] | 279 | ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 280 | |
Chad Rosier | 7caca84 | 2011-12-17 01:51:05 +0000 | [diff] [blame] | 281 | #define _mm256_permute_ps(A, C) __extension__ ({ \ |
| 282 | __m256 __A = (A); \ |
Craig Topper | fec9f8e | 2012-02-08 05:16:54 +0000 | [diff] [blame] | 283 | (__m256)__builtin_shufflevector((__v8sf)__A, (__v8sf) _mm256_setzero_ps(), \ |
| 284 | (C) & 0x3, ((C) & 0xc) >> 2, \ |
| 285 | ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6, \ |
| 286 | 4 + (((C) & 0x03) >> 0), \ |
| 287 | 4 + (((C) & 0x0c) >> 2), \ |
| 288 | 4 + (((C) & 0x30) >> 4), \ |
| 289 | 4 + (((C) & 0xc0) >> 6)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 290 | |
Chad Rosier | 9138fea25 | 2011-12-16 21:07:34 +0000 | [diff] [blame] | 291 | #define _mm256_permute2f128_pd(V1, V2, M) __extension__ ({ \ |
| 292 | __m256d __V1 = (V1); \ |
| 293 | __m256d __V2 = (V2); \ |
Craig Topper | 26e74e5 | 2012-04-17 05:16:56 +0000 | [diff] [blame] | 294 | (__m256d)__builtin_ia32_vperm2f128_pd256((__v4df)__V1, (__v4df)__V2, (M)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 295 | |
Chad Rosier | 9138fea25 | 2011-12-16 21:07:34 +0000 | [diff] [blame] | 296 | #define _mm256_permute2f128_ps(V1, V2, M) __extension__ ({ \ |
| 297 | __m256 __V1 = (V1); \ |
| 298 | __m256 __V2 = (V2); \ |
Craig Topper | 26e74e5 | 2012-04-17 05:16:56 +0000 | [diff] [blame] | 299 | (__m256)__builtin_ia32_vperm2f128_ps256((__v8sf)__V1, (__v8sf)__V2, (M)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 300 | |
Chad Rosier | 9138fea25 | 2011-12-16 21:07:34 +0000 | [diff] [blame] | 301 | #define _mm256_permute2f128_si256(V1, V2, M) __extension__ ({ \ |
| 302 | __m256i __V1 = (V1); \ |
| 303 | __m256i __V2 = (V2); \ |
Craig Topper | 26e74e5 | 2012-04-17 05:16:56 +0000 | [diff] [blame] | 304 | (__m256i)__builtin_ia32_vperm2f128_si256((__v8si)__V1, (__v8si)__V2, (M)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 305 | |
| 306 | /* Vector Blend */ |
Eli Friedman | f16beb3 | 2011-11-10 00:11:13 +0000 | [diff] [blame] | 307 | #define _mm256_blend_pd(V1, V2, M) __extension__ ({ \ |
| 308 | __m256d __V1 = (V1); \ |
| 309 | __m256d __V2 = (V2); \ |
Filipe Cabecinhas | 5d289b4 | 2014-05-13 02:37:02 +0000 | [diff] [blame] | 310 | (__m256d)__builtin_shufflevector((__v4df)__V1, (__v4df)__V2, \ |
| 311 | (((M) & 0x01) ? 4 : 0), \ |
| 312 | (((M) & 0x02) ? 5 : 1), \ |
| 313 | (((M) & 0x04) ? 6 : 2), \ |
| 314 | (((M) & 0x08) ? 7 : 3)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 315 | |
Eli Friedman | f16beb3 | 2011-11-10 00:11:13 +0000 | [diff] [blame] | 316 | #define _mm256_blend_ps(V1, V2, M) __extension__ ({ \ |
| 317 | __m256 __V1 = (V1); \ |
| 318 | __m256 __V2 = (V2); \ |
Filipe Cabecinhas | 5d289b4 | 2014-05-13 02:37:02 +0000 | [diff] [blame] | 319 | (__m256)__builtin_shufflevector((__v8sf)__V1, (__v8sf)__V2, \ |
| 320 | (((M) & 0x01) ? 8 : 0), \ |
| 321 | (((M) & 0x02) ? 9 : 1), \ |
| 322 | (((M) & 0x04) ? 10 : 2), \ |
| 323 | (((M) & 0x08) ? 11 : 3), \ |
| 324 | (((M) & 0x10) ? 12 : 4), \ |
| 325 | (((M) & 0x20) ? 13 : 5), \ |
| 326 | (((M) & 0x40) ? 14 : 6), \ |
| 327 | (((M) & 0x80) ? 15 : 7)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 328 | |
| 329 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 330 | _mm256_blendv_pd(__m256d __a, __m256d __b, __m256d __c) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 331 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 332 | return (__m256d)__builtin_ia32_blendvpd256( |
| 333 | (__v4df)__a, (__v4df)__b, (__v4df)__c); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 337 | _mm256_blendv_ps(__m256 __a, __m256 __b, __m256 __c) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 338 | { |
David Blaikie | 5bb7003 | 2013-01-16 23:13:42 +0000 | [diff] [blame] | 339 | return (__m256)__builtin_ia32_blendvps256( |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 340 | (__v8sf)__a, (__v8sf)__b, (__v8sf)__c); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /* Vector Dot Product */ |
Eli Friedman | f16beb3 | 2011-11-10 00:11:13 +0000 | [diff] [blame] | 344 | #define _mm256_dp_ps(V1, V2, M) __extension__ ({ \ |
| 345 | __m256 __V1 = (V1); \ |
| 346 | __m256 __V2 = (V2); \ |
Craig Topper | 9f00948 | 2011-12-24 07:55:14 +0000 | [diff] [blame] | 347 | (__m256)__builtin_ia32_dpps256((__v8sf)__V1, (__v8sf)__V2, (M)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 348 | |
| 349 | /* Vector shuffle */ |
Bob Wilson | c9b97cc | 2011-11-05 06:08:06 +0000 | [diff] [blame] | 350 | #define _mm256_shuffle_ps(a, b, mask) __extension__ ({ \ |
| 351 | __m256 __a = (a); \ |
| 352 | __m256 __b = (b); \ |
| 353 | (__m256)__builtin_shufflevector((__v8sf)__a, (__v8sf)__b, \ |
Bruno Cardoso Lopes | e712a13 | 2010-08-11 01:17:34 +0000 | [diff] [blame] | 354 | (mask) & 0x3, ((mask) & 0xc) >> 2, \ |
Bruno Cardoso Lopes | 8c33315 | 2010-08-11 18:45:43 +0000 | [diff] [blame] | 355 | (((mask) & 0x30) >> 4) + 8, (((mask) & 0xc0) >> 6) + 8, \ |
Bruno Cardoso Lopes | 7a98a7e | 2011-08-23 23:29:45 +0000 | [diff] [blame] | 356 | ((mask) & 0x3) + 4, (((mask) & 0xc) >> 2) + 4, \ |
Bob Wilson | c9b97cc | 2011-11-05 06:08:06 +0000 | [diff] [blame] | 357 | (((mask) & 0x30) >> 4) + 12, (((mask) & 0xc0) >> 6) + 12); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 358 | |
Bob Wilson | c9b97cc | 2011-11-05 06:08:06 +0000 | [diff] [blame] | 359 | #define _mm256_shuffle_pd(a, b, mask) __extension__ ({ \ |
| 360 | __m256d __a = (a); \ |
| 361 | __m256d __b = (b); \ |
| 362 | (__m256d)__builtin_shufflevector((__v4df)__a, (__v4df)__b, \ |
Bruno Cardoso Lopes | e712a13 | 2010-08-11 01:17:34 +0000 | [diff] [blame] | 363 | (mask) & 0x1, \ |
| 364 | (((mask) & 0x2) >> 1) + 4, \ |
| 365 | (((mask) & 0x4) >> 2) + 2, \ |
Bob Wilson | c9b97cc | 2011-11-05 06:08:06 +0000 | [diff] [blame] | 366 | (((mask) & 0x8) >> 3) + 6); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 367 | |
| 368 | /* Compare */ |
| 369 | #define _CMP_EQ_OQ 0x00 /* Equal (ordered, non-signaling) */ |
| 370 | #define _CMP_LT_OS 0x01 /* Less-than (ordered, signaling) */ |
| 371 | #define _CMP_LE_OS 0x02 /* Less-than-or-equal (ordered, signaling) */ |
| 372 | #define _CMP_UNORD_Q 0x03 /* Unordered (non-signaling) */ |
| 373 | #define _CMP_NEQ_UQ 0x04 /* Not-equal (unordered, non-signaling) */ |
| 374 | #define _CMP_NLT_US 0x05 /* Not-less-than (unordered, signaling) */ |
| 375 | #define _CMP_NLE_US 0x06 /* Not-less-than-or-equal (unordered, signaling) */ |
| 376 | #define _CMP_ORD_Q 0x07 /* Ordered (nonsignaling) */ |
| 377 | #define _CMP_EQ_UQ 0x08 /* Equal (unordered, non-signaling) */ |
| 378 | #define _CMP_NGE_US 0x09 /* Not-greater-than-or-equal (unord, signaling) */ |
| 379 | #define _CMP_NGT_US 0x0a /* Not-greater-than (unordered, signaling) */ |
| 380 | #define _CMP_FALSE_OQ 0x0b /* False (ordered, non-signaling) */ |
| 381 | #define _CMP_NEQ_OQ 0x0c /* Not-equal (ordered, non-signaling) */ |
| 382 | #define _CMP_GE_OS 0x0d /* Greater-than-or-equal (ordered, signaling) */ |
| 383 | #define _CMP_GT_OS 0x0e /* Greater-than (ordered, signaling) */ |
| 384 | #define _CMP_TRUE_UQ 0x0f /* True (unordered, non-signaling) */ |
| 385 | #define _CMP_EQ_OS 0x10 /* Equal (ordered, signaling) */ |
| 386 | #define _CMP_LT_OQ 0x11 /* Less-than (ordered, non-signaling) */ |
| 387 | #define _CMP_LE_OQ 0x12 /* Less-than-or-equal (ordered, non-signaling) */ |
| 388 | #define _CMP_UNORD_S 0x13 /* Unordered (signaling) */ |
| 389 | #define _CMP_NEQ_US 0x14 /* Not-equal (unordered, signaling) */ |
| 390 | #define _CMP_NLT_UQ 0x15 /* Not-less-than (unordered, non-signaling) */ |
| 391 | #define _CMP_NLE_UQ 0x16 /* Not-less-than-or-equal (unord, non-signaling) */ |
| 392 | #define _CMP_ORD_S 0x17 /* Ordered (signaling) */ |
| 393 | #define _CMP_EQ_US 0x18 /* Equal (unordered, signaling) */ |
| 394 | #define _CMP_NGE_UQ 0x19 /* Not-greater-than-or-equal (unord, non-sign) */ |
| 395 | #define _CMP_NGT_UQ 0x1a /* Not-greater-than (unordered, non-signaling) */ |
| 396 | #define _CMP_FALSE_OS 0x1b /* False (ordered, signaling) */ |
| 397 | #define _CMP_NEQ_OS 0x1c /* Not-equal (ordered, signaling) */ |
| 398 | #define _CMP_GE_OQ 0x1d /* Greater-than-or-equal (ordered, non-signaling) */ |
| 399 | #define _CMP_GT_OQ 0x1e /* Greater-than (ordered, non-signaling) */ |
| 400 | #define _CMP_TRUE_US 0x1f /* True (unordered, signaling) */ |
| 401 | |
Bob Wilson | c9b97cc | 2011-11-05 06:08:06 +0000 | [diff] [blame] | 402 | #define _mm_cmp_pd(a, b, c) __extension__ ({ \ |
| 403 | __m128d __a = (a); \ |
| 404 | __m128d __b = (b); \ |
| 405 | (__m128d)__builtin_ia32_cmppd((__v2df)__a, (__v2df)__b, (c)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 406 | |
Bob Wilson | c9b97cc | 2011-11-05 06:08:06 +0000 | [diff] [blame] | 407 | #define _mm_cmp_ps(a, b, c) __extension__ ({ \ |
| 408 | __m128 __a = (a); \ |
| 409 | __m128 __b = (b); \ |
| 410 | (__m128)__builtin_ia32_cmpps((__v4sf)__a, (__v4sf)__b, (c)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 411 | |
Bob Wilson | c9b97cc | 2011-11-05 06:08:06 +0000 | [diff] [blame] | 412 | #define _mm256_cmp_pd(a, b, c) __extension__ ({ \ |
| 413 | __m256d __a = (a); \ |
| 414 | __m256d __b = (b); \ |
| 415 | (__m256d)__builtin_ia32_cmppd256((__v4df)__a, (__v4df)__b, (c)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 416 | |
Bob Wilson | c9b97cc | 2011-11-05 06:08:06 +0000 | [diff] [blame] | 417 | #define _mm256_cmp_ps(a, b, c) __extension__ ({ \ |
| 418 | __m256 __a = (a); \ |
| 419 | __m256 __b = (b); \ |
| 420 | (__m256)__builtin_ia32_cmpps256((__v8sf)__a, (__v8sf)__b, (c)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 421 | |
Bob Wilson | c9b97cc | 2011-11-05 06:08:06 +0000 | [diff] [blame] | 422 | #define _mm_cmp_sd(a, b, c) __extension__ ({ \ |
| 423 | __m128d __a = (a); \ |
| 424 | __m128d __b = (b); \ |
| 425 | (__m128d)__builtin_ia32_cmpsd((__v2df)__a, (__v2df)__b, (c)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 426 | |
Bob Wilson | c9b97cc | 2011-11-05 06:08:06 +0000 | [diff] [blame] | 427 | #define _mm_cmp_ss(a, b, c) __extension__ ({ \ |
| 428 | __m128 __a = (a); \ |
| 429 | __m128 __b = (b); \ |
| 430 | (__m128)__builtin_ia32_cmpss((__v4sf)__a, (__v4sf)__b, (c)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 431 | |
| 432 | /* Vector extract */ |
Chad Rosier | 0adfe7a | 2011-12-17 01:22:27 +0000 | [diff] [blame] | 433 | #define _mm256_extractf128_pd(A, O) __extension__ ({ \ |
| 434 | __m256d __A = (A); \ |
Craig Topper | 9f00948 | 2011-12-24 07:55:14 +0000 | [diff] [blame] | 435 | (__m128d)__builtin_ia32_vextractf128_pd256((__v4df)__A, (O)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 436 | |
Chad Rosier | 0adfe7a | 2011-12-17 01:22:27 +0000 | [diff] [blame] | 437 | #define _mm256_extractf128_ps(A, O) __extension__ ({ \ |
| 438 | __m256 __A = (A); \ |
Craig Topper | 9f00948 | 2011-12-24 07:55:14 +0000 | [diff] [blame] | 439 | (__m128)__builtin_ia32_vextractf128_ps256((__v8sf)__A, (O)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 440 | |
Chad Rosier | 0adfe7a | 2011-12-17 01:22:27 +0000 | [diff] [blame] | 441 | #define _mm256_extractf128_si256(A, O) __extension__ ({ \ |
| 442 | __m256i __A = (A); \ |
Craig Topper | 9f00948 | 2011-12-24 07:55:14 +0000 | [diff] [blame] | 443 | (__m128i)__builtin_ia32_vextractf128_si256((__v8si)__A, (O)); }) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 444 | |
| 445 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
Craig Topper | 459554f | 2015-01-31 06:31:30 +0000 | [diff] [blame] | 446 | _mm256_extract_epi32(__m256i __a, const int __imm) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 447 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 448 | __v8si __b = (__v8si)__a; |
Manman Ren | c94122e | 2013-10-23 20:33:14 +0000 | [diff] [blame] | 449 | return __b[__imm & 7]; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
Craig Topper | 459554f | 2015-01-31 06:31:30 +0000 | [diff] [blame] | 453 | _mm256_extract_epi16(__m256i __a, const int __imm) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 454 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 455 | __v16hi __b = (__v16hi)__a; |
Manman Ren | c94122e | 2013-10-23 20:33:14 +0000 | [diff] [blame] | 456 | return __b[__imm & 15]; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
Craig Topper | 459554f | 2015-01-31 06:31:30 +0000 | [diff] [blame] | 460 | _mm256_extract_epi8(__m256i __a, const int __imm) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 461 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 462 | __v32qi __b = (__v32qi)__a; |
Manman Ren | c94122e | 2013-10-23 20:33:14 +0000 | [diff] [blame] | 463 | return __b[__imm & 31]; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | #ifdef __x86_64__ |
| 467 | static __inline long long __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 468 | _mm256_extract_epi64(__m256i __a, const int __imm) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 469 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 470 | __v4di __b = (__v4di)__a; |
Manman Ren | c94122e | 2013-10-23 20:33:14 +0000 | [diff] [blame] | 471 | return __b[__imm & 3]; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 472 | } |
| 473 | #endif |
| 474 | |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 475 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 476 | _mm256_insert_epi32(__m256i __a, int __b, int const __imm) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 477 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 478 | __v8si __c = (__v8si)__a; |
| 479 | __c[__imm & 7] = __b; |
| 480 | return (__m256i)__c; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 484 | _mm256_insert_epi16(__m256i __a, int __b, int const __imm) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 485 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 486 | __v16hi __c = (__v16hi)__a; |
| 487 | __c[__imm & 15] = __b; |
| 488 | return (__m256i)__c; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 492 | _mm256_insert_epi8(__m256i __a, int __b, int const __imm) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 493 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 494 | __v32qi __c = (__v32qi)__a; |
| 495 | __c[__imm & 31] = __b; |
| 496 | return (__m256i)__c; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | #ifdef __x86_64__ |
| 500 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
Filipe Cabecinhas | d740029 | 2015-02-19 19:00:33 +0000 | [diff] [blame] | 501 | _mm256_insert_epi64(__m256i __a, long long __b, int const __imm) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 502 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 503 | __v4di __c = (__v4di)__a; |
| 504 | __c[__imm & 3] = __b; |
| 505 | return (__m256i)__c; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 506 | } |
| 507 | #endif |
| 508 | |
| 509 | /* Conversion */ |
| 510 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 511 | _mm256_cvtepi32_pd(__m128i __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 512 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 513 | return (__m256d)__builtin_ia32_cvtdq2pd256((__v4si) __a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 517 | _mm256_cvtepi32_ps(__m256i __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 518 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 519 | return (__m256)__builtin_ia32_cvtdq2ps256((__v8si) __a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static __inline __m128 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 523 | _mm256_cvtpd_ps(__m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 524 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 525 | return (__m128)__builtin_ia32_cvtpd2ps256((__v4df) __a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 529 | _mm256_cvtps_epi32(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 530 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 531 | return (__m256i)__builtin_ia32_cvtps2dq256((__v8sf) __a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 535 | _mm256_cvtps_pd(__m128 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 536 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 537 | return (__m256d)__builtin_ia32_cvtps2pd256((__v4sf) __a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static __inline __m128i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 541 | _mm256_cvttpd_epi32(__m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 542 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 543 | return (__m128i)__builtin_ia32_cvttpd2dq256((__v4df) __a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static __inline __m128i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 547 | _mm256_cvtpd_epi32(__m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 548 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 549 | return (__m128i)__builtin_ia32_cvtpd2dq256((__v4df) __a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 553 | _mm256_cvttps_epi32(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 554 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 555 | return (__m256i)__builtin_ia32_cvttps2dq256((__v8sf) __a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | /* Vector replicate */ |
| 559 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 560 | _mm256_movehdup_ps(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 561 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 562 | return __builtin_shufflevector(__a, __a, 1, 1, 3, 3, 5, 5, 7, 7); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 566 | _mm256_moveldup_ps(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 567 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 568 | return __builtin_shufflevector(__a, __a, 0, 0, 2, 2, 4, 4, 6, 6); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 572 | _mm256_movedup_pd(__m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 573 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 574 | return __builtin_shufflevector(__a, __a, 0, 0, 2, 2); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /* Unpack and Interleave */ |
| 578 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 579 | _mm256_unpackhi_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 580 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 581 | return __builtin_shufflevector(__a, __b, 1, 5, 1+2, 5+2); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 585 | _mm256_unpacklo_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 586 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 587 | return __builtin_shufflevector(__a, __b, 0, 4, 0+2, 4+2); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 591 | _mm256_unpackhi_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 592 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 593 | return __builtin_shufflevector(__a, __b, 2, 10, 2+1, 10+1, 6, 14, 6+1, 14+1); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 597 | _mm256_unpacklo_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 598 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 599 | return __builtin_shufflevector(__a, __b, 0, 8, 0+1, 8+1, 4, 12, 4+1, 12+1); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /* Bit Test */ |
| 603 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 604 | _mm_testz_pd(__m128d __a, __m128d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 605 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 606 | return __builtin_ia32_vtestzpd((__v2df)__a, (__v2df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 610 | _mm_testc_pd(__m128d __a, __m128d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 611 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 612 | return __builtin_ia32_vtestcpd((__v2df)__a, (__v2df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 616 | _mm_testnzc_pd(__m128d __a, __m128d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 617 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 618 | return __builtin_ia32_vtestnzcpd((__v2df)__a, (__v2df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 622 | _mm_testz_ps(__m128 __a, __m128 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 623 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 624 | return __builtin_ia32_vtestzps((__v4sf)__a, (__v4sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 628 | _mm_testc_ps(__m128 __a, __m128 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 629 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 630 | return __builtin_ia32_vtestcps((__v4sf)__a, (__v4sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 634 | _mm_testnzc_ps(__m128 __a, __m128 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 635 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 636 | return __builtin_ia32_vtestnzcps((__v4sf)__a, (__v4sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 640 | _mm256_testz_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 641 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 642 | return __builtin_ia32_vtestzpd256((__v4df)__a, (__v4df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 646 | _mm256_testc_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 647 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 648 | return __builtin_ia32_vtestcpd256((__v4df)__a, (__v4df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 652 | _mm256_testnzc_pd(__m256d __a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 653 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 654 | return __builtin_ia32_vtestnzcpd256((__v4df)__a, (__v4df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 658 | _mm256_testz_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 659 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 660 | return __builtin_ia32_vtestzps256((__v8sf)__a, (__v8sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 664 | _mm256_testc_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 665 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 666 | return __builtin_ia32_vtestcps256((__v8sf)__a, (__v8sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 670 | _mm256_testnzc_ps(__m256 __a, __m256 __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 671 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 672 | return __builtin_ia32_vtestnzcps256((__v8sf)__a, (__v8sf)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 676 | _mm256_testz_si256(__m256i __a, __m256i __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 677 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 678 | return __builtin_ia32_ptestz256((__v4di)__a, (__v4di)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 682 | _mm256_testc_si256(__m256i __a, __m256i __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 683 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 684 | return __builtin_ia32_ptestc256((__v4di)__a, (__v4di)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 688 | _mm256_testnzc_si256(__m256i __a, __m256i __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 689 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 690 | return __builtin_ia32_ptestnzc256((__v4di)__a, (__v4di)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | /* Vector extract sign mask */ |
| 694 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 695 | _mm256_movemask_pd(__m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 696 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 697 | return __builtin_ia32_movmskpd256((__v4df)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | static __inline int __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 701 | _mm256_movemask_ps(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 702 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 703 | return __builtin_ia32_movmskps256((__v8sf)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 704 | } |
| 705 | |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 706 | /* Vector __zero */ |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 707 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
| 708 | _mm256_zeroall(void) |
| 709 | { |
| 710 | __builtin_ia32_vzeroall(); |
| 711 | } |
| 712 | |
| 713 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
| 714 | _mm256_zeroupper(void) |
| 715 | { |
| 716 | __builtin_ia32_vzeroupper(); |
| 717 | } |
| 718 | |
| 719 | /* Vector load with broadcast */ |
| 720 | static __inline __m128 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 721 | _mm_broadcast_ss(float const *__a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 722 | { |
Adam Nemet | 286ae08 | 2014-05-29 20:47:29 +0000 | [diff] [blame] | 723 | float __f = *__a; |
| 724 | return (__m128)(__v4sf){ __f, __f, __f, __f }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 728 | _mm256_broadcast_sd(double const *__a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 729 | { |
Adam Nemet | 286ae08 | 2014-05-29 20:47:29 +0000 | [diff] [blame] | 730 | double __d = *__a; |
| 731 | return (__m256d)(__v4df){ __d, __d, __d, __d }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 735 | _mm256_broadcast_ss(float const *__a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 736 | { |
Adam Nemet | 286ae08 | 2014-05-29 20:47:29 +0000 | [diff] [blame] | 737 | float __f = *__a; |
| 738 | return (__m256)(__v8sf){ __f, __f, __f, __f, __f, __f, __f, __f }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 742 | _mm256_broadcast_pd(__m128d const *__a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 743 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 744 | return (__m256d)__builtin_ia32_vbroadcastf128_pd256(__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 748 | _mm256_broadcast_ps(__m128 const *__a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 749 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 750 | return (__m256)__builtin_ia32_vbroadcastf128_ps256(__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /* SIMD load ops */ |
| 754 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 755 | _mm256_load_pd(double const *__p) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 756 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 757 | return *(__m256d *)__p; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 761 | _mm256_load_ps(float const *__p) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 762 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 763 | return *(__m256 *)__p; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 767 | _mm256_loadu_pd(double const *__p) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 768 | { |
Craig Topper | 9e9301a | 2012-01-25 04:26:17 +0000 | [diff] [blame] | 769 | struct __loadu_pd { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 770 | __m256d __v; |
David Majnemer | 1cf22e6 | 2015-02-04 00:26:10 +0000 | [diff] [blame] | 771 | } __attribute__((__packed__, __may_alias__)); |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 772 | return ((struct __loadu_pd*)__p)->__v; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 776 | _mm256_loadu_ps(float const *__p) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 777 | { |
Craig Topper | 9e9301a | 2012-01-25 04:26:17 +0000 | [diff] [blame] | 778 | struct __loadu_ps { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 779 | __m256 __v; |
David Majnemer | 1cf22e6 | 2015-02-04 00:26:10 +0000 | [diff] [blame] | 780 | } __attribute__((__packed__, __may_alias__)); |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 781 | return ((struct __loadu_ps*)__p)->__v; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 785 | _mm256_load_si256(__m256i const *__p) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 786 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 787 | return *__p; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 791 | _mm256_loadu_si256(__m256i const *__p) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 792 | { |
Craig Topper | 9e9301a | 2012-01-25 04:26:17 +0000 | [diff] [blame] | 793 | struct __loadu_si256 { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 794 | __m256i __v; |
David Majnemer | 1cf22e6 | 2015-02-04 00:26:10 +0000 | [diff] [blame] | 795 | } __attribute__((__packed__, __may_alias__)); |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 796 | return ((struct __loadu_si256*)__p)->__v; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 800 | _mm256_lddqu_si256(__m256i const *__p) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 801 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 802 | return (__m256i)__builtin_ia32_lddqu256((char const *)__p); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | /* SIMD store ops */ |
| 806 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 807 | _mm256_store_pd(double *__p, __m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 808 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 809 | *(__m256d *)__p = __a; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 813 | _mm256_store_ps(float *__p, __m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 814 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 815 | *(__m256 *)__p = __a; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 819 | _mm256_storeu_pd(double *__p, __m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 820 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 821 | __builtin_ia32_storeupd256(__p, (__v4df)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 825 | _mm256_storeu_ps(float *__p, __m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 826 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 827 | __builtin_ia32_storeups256(__p, (__v8sf)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 831 | _mm256_store_si256(__m256i *__p, __m256i __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 832 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 833 | *__p = __a; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 837 | _mm256_storeu_si256(__m256i *__p, __m256i __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 838 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 839 | __builtin_ia32_storedqu256((char *)__p, (__v32qi)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | /* Conditional load ops */ |
| 843 | static __inline __m128d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 844 | _mm_maskload_pd(double const *__p, __m128d __m) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 845 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 846 | return (__m128d)__builtin_ia32_maskloadpd((const __v2df *)__p, (__v2df)__m); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 850 | _mm256_maskload_pd(double const *__p, __m256d __m) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 851 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 852 | return (__m256d)__builtin_ia32_maskloadpd256((const __v4df *)__p, |
| 853 | (__v4df)__m); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | static __inline __m128 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 857 | _mm_maskload_ps(float const *__p, __m128 __m) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 858 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 859 | return (__m128)__builtin_ia32_maskloadps((const __v4sf *)__p, (__v4sf)__m); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 863 | _mm256_maskload_ps(float const *__p, __m256 __m) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 864 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 865 | return (__m256)__builtin_ia32_maskloadps256((const __v8sf *)__p, (__v8sf)__m); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /* Conditional store ops */ |
| 869 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 870 | _mm256_maskstore_ps(float *__p, __m256 __m, __m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 871 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 872 | __builtin_ia32_maskstoreps256((__v8sf *)__p, (__v8sf)__m, (__v8sf)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 876 | _mm_maskstore_pd(double *__p, __m128d __m, __m128d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 877 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 878 | __builtin_ia32_maskstorepd((__v2df *)__p, (__v2df)__m, (__v2df)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 882 | _mm256_maskstore_pd(double *__p, __m256d __m, __m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 883 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 884 | __builtin_ia32_maskstorepd256((__v4df *)__p, (__v4df)__m, (__v4df)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 888 | _mm_maskstore_ps(float *__p, __m128 __m, __m128 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 889 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 890 | __builtin_ia32_maskstoreps((__v4sf *)__p, (__v4sf)__m, (__v4sf)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | /* Cacheability support ops */ |
| 894 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 895 | _mm256_stream_si256(__m256i *__a, __m256i __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 896 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 897 | __builtin_ia32_movntdq256((__v4di *)__a, (__v4di)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 901 | _mm256_stream_pd(double *__a, __m256d __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 902 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 903 | __builtin_ia32_movntpd256(__a, (__v4df)__b); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 907 | _mm256_stream_ps(float *__p, __m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 908 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 909 | __builtin_ia32_movntps256(__p, (__v8sf)__a); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | /* Create vectors */ |
| 913 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 914 | _mm256_set_pd(double __a, double __b, double __c, double __d) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 915 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 916 | return (__m256d){ __d, __c, __b, __a }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 920 | _mm256_set_ps(float __a, float __b, float __c, float __d, |
Craig Topper | 9fee8ab | 2015-01-31 06:33:59 +0000 | [diff] [blame] | 921 | float __e, float __f, float __g, float __h) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 922 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 923 | return (__m256){ __h, __g, __f, __e, __d, __c, __b, __a }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 927 | _mm256_set_epi32(int __i0, int __i1, int __i2, int __i3, |
Craig Topper | 9fee8ab | 2015-01-31 06:33:59 +0000 | [diff] [blame] | 928 | int __i4, int __i5, int __i6, int __i7) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 929 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 930 | return (__m256i)(__v8si){ __i7, __i6, __i5, __i4, __i3, __i2, __i1, __i0 }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 934 | _mm256_set_epi16(short __w15, short __w14, short __w13, short __w12, |
Craig Topper | 9fee8ab | 2015-01-31 06:33:59 +0000 | [diff] [blame] | 935 | short __w11, short __w10, short __w09, short __w08, |
| 936 | short __w07, short __w06, short __w05, short __w04, |
| 937 | short __w03, short __w02, short __w01, short __w00) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 938 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 939 | return (__m256i)(__v16hi){ __w00, __w01, __w02, __w03, __w04, __w05, __w06, |
| 940 | __w07, __w08, __w09, __w10, __w11, __w12, __w13, __w14, __w15 }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 944 | _mm256_set_epi8(char __b31, char __b30, char __b29, char __b28, |
Craig Topper | 9fee8ab | 2015-01-31 06:33:59 +0000 | [diff] [blame] | 945 | char __b27, char __b26, char __b25, char __b24, |
| 946 | char __b23, char __b22, char __b21, char __b20, |
| 947 | char __b19, char __b18, char __b17, char __b16, |
| 948 | char __b15, char __b14, char __b13, char __b12, |
| 949 | char __b11, char __b10, char __b09, char __b08, |
| 950 | char __b07, char __b06, char __b05, char __b04, |
| 951 | char __b03, char __b02, char __b01, char __b00) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 952 | { |
| 953 | return (__m256i)(__v32qi){ |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 954 | __b00, __b01, __b02, __b03, __b04, __b05, __b06, __b07, |
| 955 | __b08, __b09, __b10, __b11, __b12, __b13, __b14, __b15, |
| 956 | __b16, __b17, __b18, __b19, __b20, __b21, __b22, __b23, |
| 957 | __b24, __b25, __b26, __b27, __b28, __b29, __b30, __b31 |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 958 | }; |
| 959 | } |
| 960 | |
| 961 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 962 | _mm256_set_epi64x(long long __a, long long __b, long long __c, long long __d) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 963 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 964 | return (__m256i)(__v4di){ __d, __c, __b, __a }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /* Create vectors with elements in reverse order */ |
| 968 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 969 | _mm256_setr_pd(double __a, double __b, double __c, double __d) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 970 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 971 | return (__m256d){ __a, __b, __c, __d }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 975 | _mm256_setr_ps(float __a, float __b, float __c, float __d, |
Craig Topper | 9fee8ab | 2015-01-31 06:33:59 +0000 | [diff] [blame] | 976 | float __e, float __f, float __g, float __h) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 977 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 978 | return (__m256){ __a, __b, __c, __d, __e, __f, __g, __h }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 982 | _mm256_setr_epi32(int __i0, int __i1, int __i2, int __i3, |
Craig Topper | 9fee8ab | 2015-01-31 06:33:59 +0000 | [diff] [blame] | 983 | int __i4, int __i5, int __i6, int __i7) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 984 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 985 | return (__m256i)(__v8si){ __i0, __i1, __i2, __i3, __i4, __i5, __i6, __i7 }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 989 | _mm256_setr_epi16(short __w15, short __w14, short __w13, short __w12, |
Craig Topper | 9fee8ab | 2015-01-31 06:33:59 +0000 | [diff] [blame] | 990 | short __w11, short __w10, short __w09, short __w08, |
| 991 | short __w07, short __w06, short __w05, short __w04, |
| 992 | short __w03, short __w02, short __w01, short __w00) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 993 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 994 | return (__m256i)(__v16hi){ __w15, __w14, __w13, __w12, __w11, __w10, __w09, |
| 995 | __w08, __w07, __w06, __w05, __w04, __w03, __w02, __w01, __w00 }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 999 | _mm256_setr_epi8(char __b31, char __b30, char __b29, char __b28, |
Craig Topper | 9fee8ab | 2015-01-31 06:33:59 +0000 | [diff] [blame] | 1000 | char __b27, char __b26, char __b25, char __b24, |
| 1001 | char __b23, char __b22, char __b21, char __b20, |
| 1002 | char __b19, char __b18, char __b17, char __b16, |
| 1003 | char __b15, char __b14, char __b13, char __b12, |
| 1004 | char __b11, char __b10, char __b09, char __b08, |
| 1005 | char __b07, char __b06, char __b05, char __b04, |
| 1006 | char __b03, char __b02, char __b01, char __b00) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1007 | { |
| 1008 | return (__m256i)(__v32qi){ |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1009 | __b31, __b30, __b29, __b28, __b27, __b26, __b25, __b24, |
Craig Topper | 9fee8ab | 2015-01-31 06:33:59 +0000 | [diff] [blame] | 1010 | __b23, __b22, __b21, __b20, __b19, __b18, __b17, __b16, |
| 1011 | __b15, __b14, __b13, __b12, __b11, __b10, __b09, __b08, |
| 1012 | __b07, __b06, __b05, __b04, __b03, __b02, __b01, __b00 }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1016 | _mm256_setr_epi64x(long long __a, long long __b, long long __c, long long __d) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1017 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1018 | return (__m256i)(__v4di){ __a, __b, __c, __d }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | /* Create vectors with repeated elements */ |
| 1022 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1023 | _mm256_set1_pd(double __w) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1024 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1025 | return (__m256d){ __w, __w, __w, __w }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1029 | _mm256_set1_ps(float __w) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1030 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1031 | return (__m256){ __w, __w, __w, __w, __w, __w, __w, __w }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1035 | _mm256_set1_epi32(int __i) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1036 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1037 | return (__m256i)(__v8si){ __i, __i, __i, __i, __i, __i, __i, __i }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1041 | _mm256_set1_epi16(short __w) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1042 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1043 | return (__m256i)(__v16hi){ __w, __w, __w, __w, __w, __w, __w, __w, __w, __w, |
| 1044 | __w, __w, __w, __w, __w, __w }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1048 | _mm256_set1_epi8(char __b) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1049 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1050 | return (__m256i)(__v32qi){ __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, |
| 1051 | __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, __b, |
| 1052 | __b, __b, __b, __b, __b, __b, __b }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1056 | _mm256_set1_epi64x(long long __q) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1057 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1058 | return (__m256i)(__v4di){ __q, __q, __q, __q }; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1061 | /* Create __zeroed vectors */ |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1062 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
| 1063 | _mm256_setzero_pd(void) |
| 1064 | { |
| 1065 | return (__m256d){ 0, 0, 0, 0 }; |
| 1066 | } |
| 1067 | |
| 1068 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
| 1069 | _mm256_setzero_ps(void) |
| 1070 | { |
| 1071 | return (__m256){ 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 1072 | } |
| 1073 | |
| 1074 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
| 1075 | _mm256_setzero_si256(void) |
| 1076 | { |
| 1077 | return (__m256i){ 0LL, 0LL, 0LL, 0LL }; |
| 1078 | } |
| 1079 | |
| 1080 | /* Cast between vector types */ |
| 1081 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1082 | _mm256_castpd_ps(__m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1083 | { |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1084 | return (__m256)__a; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1088 | _mm256_castpd_si256(__m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1089 | { |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1090 | return (__m256i)__a; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1094 | _mm256_castps_pd(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1095 | { |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1096 | return (__m256d)__a; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1100 | _mm256_castps_si256(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1101 | { |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1102 | return (__m256i)__a; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1106 | _mm256_castsi256_ps(__m256i __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1107 | { |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1108 | return (__m256)__a; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1112 | _mm256_castsi256_pd(__m256i __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1113 | { |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1114 | return (__m256d)__a; |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | static __inline __m128d __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1118 | _mm256_castpd256_pd128(__m256d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1119 | { |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1120 | return __builtin_shufflevector(__a, __a, 0, 1); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | static __inline __m128 __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1124 | _mm256_castps256_ps128(__m256 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1125 | { |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1126 | return __builtin_shufflevector(__a, __a, 0, 1, 2, 3); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static __inline __m128i __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1130 | _mm256_castsi256_si128(__m256i __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1131 | { |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1132 | return __builtin_shufflevector(__a, __a, 0, 1); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1136 | _mm256_castpd128_pd256(__m128d __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1137 | { |
Craig Topper | c524451 | 2013-08-05 06:17:21 +0000 | [diff] [blame] | 1138 | return __builtin_shufflevector(__a, __a, 0, 1, -1, -1); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1142 | _mm256_castps128_ps256(__m128 __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1143 | { |
Craig Topper | c524451 | 2013-08-05 06:17:21 +0000 | [diff] [blame] | 1144 | return __builtin_shufflevector(__a, __a, 0, 1, 2, 3, -1, -1, -1, -1); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
Reid Kleckner | 7ab75b3 | 2013-04-19 17:00:14 +0000 | [diff] [blame] | 1148 | _mm256_castsi128_si256(__m128i __a) |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1149 | { |
Craig Topper | c524451 | 2013-08-05 06:17:21 +0000 | [diff] [blame] | 1150 | return __builtin_shufflevector(__a, __a, 0, 1, -1, -1); |
Bruno Cardoso Lopes | 7c4b513 | 2010-08-04 22:03:36 +0000 | [diff] [blame] | 1151 | } |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1152 | |
Sanjay Patel | 7f6aa52 | 2015-03-10 15:19:26 +0000 | [diff] [blame^] | 1153 | /* |
| 1154 | Vector insert. |
| 1155 | We use macros rather than inlines because we only want to accept |
| 1156 | invocations where the immediate M is a constant expression. |
| 1157 | */ |
| 1158 | #define _mm256_insertf128_ps(V1, V2, M) __extension__ ({ \ |
| 1159 | (__m256)__builtin_shufflevector( \ |
| 1160 | (__v8sf)(V1), \ |
| 1161 | (__v8sf)_mm256_castps128_ps256((__m128)(V2)), \ |
| 1162 | (((M) & 1) ? 0 : 8), \ |
| 1163 | (((M) & 1) ? 1 : 9), \ |
| 1164 | (((M) & 1) ? 2 : 10), \ |
| 1165 | (((M) & 1) ? 3 : 11), \ |
| 1166 | (((M) & 1) ? 8 : 4), \ |
| 1167 | (((M) & 1) ? 9 : 5), \ |
| 1168 | (((M) & 1) ? 10 : 6), \ |
| 1169 | (((M) & 1) ? 11 : 7) );}) |
| 1170 | |
| 1171 | #define _mm256_insertf128_pd(V1, V2, M) __extension__ ({ \ |
| 1172 | (__m256d)__builtin_shufflevector( \ |
| 1173 | (__v4df)(V1), \ |
| 1174 | (__v4df)_mm256_castpd128_pd256((__m128d)(V2)), \ |
| 1175 | (((M) & 1) ? 0 : 4), \ |
| 1176 | (((M) & 1) ? 1 : 5), \ |
| 1177 | (((M) & 1) ? 4 : 2), \ |
| 1178 | (((M) & 1) ? 5 : 3) );}) |
| 1179 | |
| 1180 | #define _mm256_insertf128_si256(V1, V2, M) __extension__ ({ \ |
| 1181 | (__m256i)__builtin_shufflevector( \ |
| 1182 | (__v4di)(V1), \ |
| 1183 | (__v4di)_mm256_castsi128_si256((__m128i)(V2)), \ |
| 1184 | (((M) & 1) ? 0 : 4), \ |
| 1185 | (((M) & 1) ? 1 : 5), \ |
| 1186 | (((M) & 1) ? 4 : 2), \ |
| 1187 | (((M) & 1) ? 5 : 3) );}) |
| 1188 | |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1189 | /* SIMD load ops (unaligned) */ |
| 1190 | static __inline __m256 __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1191 | _mm256_loadu2_m128(float const *__addr_hi, float const *__addr_lo) |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1192 | { |
| 1193 | struct __loadu_ps { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1194 | __m128 __v; |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1195 | } __attribute__((__packed__, __may_alias__)); |
| 1196 | |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1197 | __m256 __v256 = _mm256_castps128_ps256(((struct __loadu_ps*)__addr_lo)->__v); |
| 1198 | return _mm256_insertf128_ps(__v256, ((struct __loadu_ps*)__addr_hi)->__v, 1); |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | static __inline __m256d __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1202 | _mm256_loadu2_m128d(double const *__addr_hi, double const *__addr_lo) |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1203 | { |
| 1204 | struct __loadu_pd { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1205 | __m128d __v; |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1206 | } __attribute__((__packed__, __may_alias__)); |
| 1207 | |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1208 | __m256d __v256 = _mm256_castpd128_pd256(((struct __loadu_pd*)__addr_lo)->__v); |
| 1209 | return _mm256_insertf128_pd(__v256, ((struct __loadu_pd*)__addr_hi)->__v, 1); |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | static __inline __m256i __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1213 | _mm256_loadu2_m128i(__m128i const *__addr_hi, __m128i const *__addr_lo) |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1214 | { |
| 1215 | struct __loadu_si128 { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1216 | __m128i __v; |
David Majnemer | 1cf22e6 | 2015-02-04 00:26:10 +0000 | [diff] [blame] | 1217 | } __attribute__((__packed__, __may_alias__)); |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1218 | __m256i __v256 = _mm256_castsi128_si256( |
| 1219 | ((struct __loadu_si128*)__addr_lo)->__v); |
| 1220 | return _mm256_insertf128_si256(__v256, |
| 1221 | ((struct __loadu_si128*)__addr_hi)->__v, 1); |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | /* SIMD store ops (unaligned) */ |
| 1225 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1226 | _mm256_storeu2_m128(float *__addr_hi, float *__addr_lo, __m256 __a) |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1227 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1228 | __m128 __v128; |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1229 | |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1230 | __v128 = _mm256_castps256_ps128(__a); |
| 1231 | __builtin_ia32_storeups(__addr_lo, __v128); |
| 1232 | __v128 = _mm256_extractf128_ps(__a, 1); |
| 1233 | __builtin_ia32_storeups(__addr_hi, __v128); |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1237 | _mm256_storeu2_m128d(double *__addr_hi, double *__addr_lo, __m256d __a) |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1238 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1239 | __m128d __v128; |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1240 | |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1241 | __v128 = _mm256_castpd256_pd128(__a); |
| 1242 | __builtin_ia32_storeupd(__addr_lo, __v128); |
| 1243 | __v128 = _mm256_extractf128_pd(__a, 1); |
| 1244 | __builtin_ia32_storeupd(__addr_hi, __v128); |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | static __inline void __attribute__((__always_inline__, __nodebug__)) |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1248 | _mm256_storeu2_m128i(__m128i *__addr_hi, __m128i *__addr_lo, __m256i __a) |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1249 | { |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1250 | __m128i __v128; |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1251 | |
David Blaikie | 3302f2b | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 1252 | __v128 = _mm256_castsi256_si128(__a); |
| 1253 | __builtin_ia32_storedqu((char *)__addr_lo, (__v16qi)__v128); |
| 1254 | __v128 = _mm256_extractf128_si256(__a, 1); |
| 1255 | __builtin_ia32_storedqu((char *)__addr_hi, (__v16qi)__v128); |
Chad Rosier | f8df4f4 | 2012-03-20 16:40:00 +0000 | [diff] [blame] | 1256 | } |
Richard Smith | 49e5644 | 2013-07-14 05:41:45 +0000 | [diff] [blame] | 1257 | |
| 1258 | #endif /* __AVXINTRIN_H */ |