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