Tim Shen | 158e51b | 2018-04-23 21:54:06 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------------- simd ---------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | #ifndef _LIBCPP_EXPERIMENTAL_SIMD |
| 11 | #define _LIBCPP_EXPERIMENTAL_SIMD |
| 12 | |
| 13 | /* |
| 14 | experimental/simd synopsis |
| 15 | |
| 16 | namespace std::experimental { |
| 17 | |
| 18 | inline namespace parallelism_v2 { |
| 19 | |
| 20 | namespace simd_abi { |
| 21 | |
| 22 | struct scalar {}; |
| 23 | template <int N> struct fixed_size {}; |
| 24 | template <typename T> inline constexpr int max_fixed_size = implementation-defined; |
| 25 | template <typename T> using compatible = implementation-defined; |
| 26 | template <typename T> using native = implementation-defined; |
| 27 | |
| 28 | } // simd_abi |
| 29 | |
| 30 | struct element_aligned_tag {}; |
| 31 | struct vector_aligned_tag {}; |
| 32 | template <size_t> struct overaligned_tag {}; |
| 33 | inline constexpr element_aligned_tag element_aligned{}; |
| 34 | inline constexpr vector_aligned_tag vector_aligned{}; |
| 35 | template <size_t N> inline constexpr overaligned_tag<N> overaligned{}; |
| 36 | |
| 37 | // traits [simd.traits] |
| 38 | template <class T> struct is_abi_tag; |
| 39 | template <class T> inline constexpr bool is_abi_tag_v = is_abi_tag<T>::value; |
| 40 | |
| 41 | template <class T> struct is_simd; |
| 42 | template <class T> inline constexpr bool is_simd_v = is_simd<T>::value; |
| 43 | |
| 44 | template <class T> struct is_simd_mask; |
| 45 | template <class T> inline constexpr bool is_simd_mask_v = is_simd_mask<T>::value; |
| 46 | |
| 47 | template <class T> struct is_simd_flag_type; |
| 48 | template <class T> inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<T>::value; |
| 49 | |
| 50 | template <class T, size_t N> struct abi_for_size { using type = see below; }; |
| 51 | template <class T, size_t N> using abi_for_size_t = typename abi_for_size<T, N>::type; |
| 52 | |
| 53 | template <class T, class Abi = simd_abi::compatible<T>> struct simd_size; |
| 54 | template <class T, class Abi = simd_abi::compatible<T>> |
| 55 | inline constexpr size_t simd_size_v = simd_size<T, Abi>::value; |
| 56 | |
| 57 | template <class T, class U = typename T::value_type> struct memory_alignment; |
| 58 | template <class T, class U = typename T::value_type> |
| 59 | inline constexpr size_t memory_alignment_v = memory_alignment<T, U>::value; |
| 60 | |
| 61 | // class template simd [simd.class] |
| 62 | template <class T, class Abi = simd_abi::compatible<T>> class simd; |
| 63 | template <class T> using native_simd = simd<T, simd_abi::native<T>>; |
| 64 | template <class T, int N> using fixed_size_simd = simd<T, simd_abi::fixed_size<N>>; |
| 65 | |
| 66 | // class template simd_mask [simd.mask.class] |
| 67 | template <class T, class Abi = simd_abi::compatible<T>> class simd_mask; |
| 68 | template <class T> using native_simd_mask = simd_mask<T, simd_abi::native<T>>; |
| 69 | template <class T, int N> using fixed_size_simd_mask = simd_mask<T, simd_abi::fixed_size<N>>; |
| 70 | |
| 71 | // casts [simd.casts] |
| 72 | template <class T, class U, class Abi> see below simd_cast(const simd<U, Abi>&); |
| 73 | template <class T, class U, class Abi> see below static_simd_cast(const simd<U, Abi>&); |
| 74 | |
| 75 | template <class T, class Abi> |
| 76 | fixed_size_simd<T, simd_size_v<T, Abi>> to_fixed_size(const simd<T, Abi>&) noexcept; |
| 77 | template <class T, class Abi> |
| 78 | fixed_size_simd_mask<T, simd_size_v<T, Abi>> to_fixed_size(const simd_mask<T, Abi>&) noexcept; |
| 79 | template <class T, size_t N> native_simd<T> to_native(const fixed_size_simd<T, N>&) noexcept; |
| 80 | template <class T, size_t N> |
| 81 | native_simd_mask<T> to_native(const fixed_size_simd_mask<T, N>> &) noexcept; |
| 82 | template <class T, size_t N> simd<T> to_compatible(const fixed_size_simd<T, N>&) noexcept; |
| 83 | template <class T, size_t N> simd_mask<T> to_compatible(const fixed_size_simd_mask<T, N>&) noexcept; |
| 84 | |
| 85 | template <size_t... Sizes, class T, class Abi> |
| 86 | tuple<simd<T, abi_for_size_t<Sizes>>...> split(const simd<T, Abi>&); |
| 87 | template <size_t... Sizes, class T, class Abi> |
| 88 | tuple<simd_mask<T, abi_for_size_t<Sizes>>...> split(const simd_mask<T, Abi>&); |
| 89 | template <class V, class Abi> |
| 90 | array<V, simd_size_v<typename V::value_type, Abi> / V::size()> split( |
| 91 | const simd<typename V::value_type, Abi>&); |
| 92 | template <class V, class Abi> |
| 93 | array<V, simd_size_v<typename V::value_type, Abi> / V::size()> split( |
| 94 | const simd_mask<typename V::value_type, Abi>&); |
| 95 | |
| 96 | template <class T, class... Abis> |
| 97 | simd<T, abi_for_size_t<T, (simd_size_v<T, Abis> + ...)>> concat(const simd<T, Abis>&...); |
| 98 | template <class T, class... Abis> |
| 99 | simd_mask<T, abi_for_size_t<T, (simd_size_v<T, Abis> + ...)>> concat(const simd_mask<T, Abis>&...); |
| 100 | |
| 101 | // reductions [simd.mask.reductions] |
| 102 | template <class T, class Abi> bool all_of(const simd_mask<T, Abi>&) noexcept; |
| 103 | template <class T, class Abi> bool any_of(const simd_mask<T, Abi>&) noexcept; |
| 104 | template <class T, class Abi> bool none_of(const simd_mask<T, Abi>&) noexcept; |
| 105 | template <class T, class Abi> bool some_of(const simd_mask<T, Abi>&) noexcept; |
| 106 | template <class T, class Abi> int popcount(const simd_mask<T, Abi>&) noexcept; |
| 107 | template <class T, class Abi> int find_first_set(const simd_mask<T, Abi>&); |
| 108 | template <class T, class Abi> int find_last_set(const simd_mask<T, Abi>&); |
| 109 | |
| 110 | bool all_of(see below) noexcept; |
| 111 | bool any_of(see below) noexcept; |
| 112 | bool none_of(see below) noexcept; |
| 113 | bool some_of(see below) noexcept; |
| 114 | int popcount(see below) noexcept; |
| 115 | int find_first_set(see below) noexcept; |
| 116 | int find_last_set(see below) noexcept; |
| 117 | |
| 118 | // masked assignment [simd.whereexpr] |
| 119 | template <class M, class T> class const_where_expression; |
| 120 | template <class M, class T> class where_expression; |
| 121 | |
| 122 | // masked assignment [simd.mask.where] |
| 123 | template <class T> struct nodeduce { using type = T; }; // exposition only |
| 124 | |
| 125 | template <class T> using nodeduce_t = typename nodeduce<T>::type; // exposition only |
| 126 | |
| 127 | template <class T, class Abi> |
| 128 | where_expression<simd_mask<T, Abi>, simd<T, Abi>> |
| 129 | where(const typename simd<T, Abi>::mask_type&, simd<T, Abi>&) noexcept; |
| 130 | |
| 131 | template <class T, class Abi> |
| 132 | const_where_expression<simd_mask<T, Abi>, const simd<T, Abi>> |
| 133 | where(const typename simd<T, Abi>::mask_type&, const simd<T, Abi>&) noexcept; |
| 134 | |
| 135 | template <class T, class Abi> |
| 136 | where_expression<simd_mask<T, Abi>, simd_mask<T, Abi>> |
| 137 | where(const nodeduce_t<simd_mask<T, Abi>>&, simd_mask<T, Abi>&) noexcept; |
| 138 | |
| 139 | template <class T, class Abi> |
| 140 | const_where_expression<simd_mask<T, Abi>, const simd_mask<T, Abi>> |
| 141 | where(const nodeduce_t<simd_mask<T, Abi>>&, const simd_mask<T, Abi>&) noexcept; |
| 142 | |
| 143 | template <class T> where_expression<bool, T> where(see below k, T& d) noexcept; |
| 144 | |
| 145 | template <class T> |
| 146 | const_where_expression<bool, const T> where(see below k, const T& d) noexcept; |
| 147 | |
| 148 | // reductions [simd.reductions] |
| 149 | template <class T, class Abi, class BinaryOperation = std::plus<>> |
| 150 | T reduce(const simd<T, Abi>&, BinaryOperation = BinaryOperation()); |
| 151 | |
| 152 | template <class M, class V, class BinaryOperation> |
| 153 | typename V::value_type reduce(const const_where_expression<M, V>& x, |
| 154 | typename V::value_type neutral_element, BinaryOperation binary_op); |
| 155 | |
| 156 | template <class M, class V> |
| 157 | typename V::value_type reduce(const const_where_expression<M, V>& x, plus<> binary_op = plus<>()); |
| 158 | |
| 159 | template <class M, class V> |
| 160 | typename V::value_type reduce(const const_where_expression<M, V>& x, multiplies<> binary_op); |
| 161 | |
| 162 | template <class M, class V> |
| 163 | typename V::value_type reduce(const const_where_expression<M, V>& x, bit_and<> binary_op); |
| 164 | |
| 165 | template <class M, class V> |
| 166 | typename V::value_type reduce(const const_where_expression<M, V>& x, bit_or<> binary_op); |
| 167 | |
| 168 | template <class M, class V> |
| 169 | typename V::value_type reduce(const const_where_expression<M, V>& x, bit_xor<> binary_op); |
| 170 | |
| 171 | template <class T, class Abi> T hmin(const simd<T, Abi>&); |
| 172 | template <class M, class V> T hmin(const const_where_expression<M, V>&); |
| 173 | template <class T, class Abi> T hmax(const simd<T, Abi>&); |
| 174 | template <class M, class V> T hmax(const const_where_expression<M, V>&); |
| 175 | |
| 176 | // algorithms [simd.alg] |
| 177 | template <class T, class Abi> simd<T, Abi> min(const simd<T, Abi>&, const simd<T, Abi>&) noexcept; |
| 178 | |
| 179 | template <class T, class Abi> simd<T, Abi> max(const simd<T, Abi>&, const simd<T, Abi>&) noexcept; |
| 180 | |
| 181 | template <class T, class Abi> |
| 182 | std::pair<simd<T, Abi>, simd<T, Abi>> minmax(const simd<T, Abi>&, const simd<T, Abi>&) noexcept; |
| 183 | |
| 184 | template <class T, class Abi> |
| 185 | simd<T, Abi> clamp(const simd<T, Abi>& v, const simd<T, Abi>& lo, const simd<T, Abi>& hi); |
| 186 | |
| 187 | // [simd.whereexpr] |
| 188 | template <class M, class T> |
| 189 | class const_where_expression { |
| 190 | const M& mask; // exposition only |
| 191 | T& data; // exposition only |
| 192 | public: |
| 193 | const_where_expression(const const_where_expression&) = delete; |
| 194 | const_where_expression& operator=(const const_where_expression&) = delete; |
| 195 | remove_const_t<T> operator-() const &&; |
| 196 | template <class U, class Flags> void copy_to(U* mem, Flags f) const &&; |
| 197 | }; |
| 198 | |
| 199 | template <class M, class T> |
| 200 | class where_expression : public const_where_expression<M, T> { |
| 201 | public: |
| 202 | where_expression(const where_expression&) = delete; |
| 203 | where_expression& operator=(const where_expression&) = delete; |
| 204 | template <class U> void operator=(U&& x); |
| 205 | template <class U> void operator+=(U&& x); |
| 206 | template <class U> void operator-=(U&& x); |
| 207 | template <class U> void operator*=(U&& x); |
| 208 | template <class U> void operator/=(U&& x); |
| 209 | template <class U> void operator%=(U&& x); |
| 210 | template <class U> void operator&=(U&& x); |
| 211 | template <class U> void operator|=(U&& x); |
| 212 | template <class U> void operator^=(U&& x); |
| 213 | template <class U> void operator<<=(U&& x); |
| 214 | template <class U> void operator>>=(U&& x); |
| 215 | void operator++(); |
| 216 | void operator++(int); |
| 217 | void operator--(); |
| 218 | void operator--(int); |
| 219 | template <class U, class Flags> void copy_from(const U* mem, Flags); |
| 220 | }; |
| 221 | |
| 222 | // [simd.class] |
| 223 | template <class T, class Abi> class simd { |
| 224 | public: |
| 225 | using value_type = T; |
| 226 | using reference = see below; |
| 227 | using mask_type = simd_mask<T, Abi>; |
| 228 | |
| 229 | using abi_type = Abi; |
| 230 | static constexpr size_t size() noexcept; |
| 231 | simd() = default; |
| 232 | |
| 233 | // implicit type conversion constructor |
| 234 | template <class U> simd(const simd<U, simd_abi::fixed_size<size()>>&); |
| 235 | |
| 236 | // implicit broadcast constructor (see below for constraints) |
| 237 | template <class U> simd(U&& value); |
| 238 | |
| 239 | // generator constructor (see below for constraints) |
| 240 | template <class G> explicit simd(G&& gen); |
| 241 | |
| 242 | // load constructor |
| 243 | template <class U, class Flags> simd(const U* mem, Flags f); |
| 244 | |
| 245 | // loads [simd.load] |
| 246 | template <class U, class Flags> void copy_from(const U* mem, Flags f); |
| 247 | |
| 248 | // stores [simd.store] |
| 249 | template <class U, class Flags> void copy_to(U* mem, Flags f) const; |
| 250 | |
| 251 | // scalar access [simd.subscr] |
| 252 | reference operator[](size_t); |
| 253 | value_type operator[](size_t) const; |
| 254 | |
| 255 | // unary operators [simd.unary] |
| 256 | simd& operator++(); |
| 257 | simd operator++(int); |
| 258 | simd& operator--(); |
| 259 | simd operator--(int); |
| 260 | mask_type operator!() const; |
| 261 | simd operator~() const; // see below |
| 262 | simd operator+() const; |
| 263 | simd operator-() const; |
| 264 | |
| 265 | // binary operators [simd.binary] |
| 266 | friend simd operator+ (const simd&, const simd&); |
| 267 | friend simd operator- (const simd&, const simd&); |
| 268 | friend simd operator* (const simd&, const simd&); |
| 269 | friend simd operator/ (const simd&, const simd&); |
| 270 | friend simd operator% (const simd&, const simd&); |
| 271 | friend simd operator& (const simd&, const simd&); |
| 272 | friend simd operator| (const simd&, const simd&); |
| 273 | friend simd operator^ (const simd&, const simd&); |
| 274 | friend simd operator<<(const simd&, const simd&); |
| 275 | friend simd operator>>(const simd&, const simd&); |
| 276 | friend simd operator<<(const simd&, int); |
| 277 | friend simd operator>>(const simd&, int); |
| 278 | |
| 279 | // compound assignment [simd.cassign] |
| 280 | friend simd& operator+= (simd&, const simd&); |
| 281 | friend simd& operator-= (simd&, const simd&); |
| 282 | friend simd& operator*= (simd&, const simd&); |
| 283 | friend simd& operator/= (simd&, const simd&); |
| 284 | friend simd& operator%= (simd&, const simd&); |
| 285 | |
| 286 | friend simd& operator&= (simd&, const simd&); |
| 287 | friend simd& operator|= (simd&, const simd&); |
| 288 | friend simd& operator^= (simd&, const simd&); |
| 289 | friend simd& operator<<=(simd&, const simd&); |
| 290 | friend simd& operator>>=(simd&, const simd&); |
| 291 | friend simd& operator<<=(simd&, int); |
| 292 | friend simd& operator>>=(simd&, int); |
| 293 | |
| 294 | // compares [simd.comparison] |
| 295 | friend mask_type operator==(const simd&, const simd&); |
| 296 | friend mask_type operator!=(const simd&, const simd&); |
| 297 | friend mask_type operator>=(const simd&, const simd&); |
| 298 | friend mask_type operator<=(const simd&, const simd&); |
| 299 | friend mask_type operator> (const simd&, const simd&); |
| 300 | friend mask_type operator< (const simd&, const simd&); |
| 301 | }; |
| 302 | |
| 303 | // [simd.math] |
| 304 | template <class Abi> using scharv = simd<signed char, Abi>; // exposition only |
| 305 | template <class Abi> using shortv = simd<short, Abi>; // exposition only |
| 306 | template <class Abi> using intv = simd<int, Abi>; // exposition only |
| 307 | template <class Abi> using longv = simd<long int, Abi>; // exposition only |
| 308 | template <class Abi> using llongv = simd<long long int, Abi>; // exposition only |
| 309 | template <class Abi> using floatv = simd<float, Abi>; // exposition only |
| 310 | template <class Abi> using doublev = simd<double, Abi>; // exposition only |
| 311 | template <class Abi> using ldoublev = simd<long double, Abi>; // exposition only |
| 312 | template <class T, class V> using samesize = fixed_size_simd<T, V::size()>; // exposition only |
| 313 | |
| 314 | template <class Abi> floatv<Abi> acos(floatv<Abi> x); |
| 315 | template <class Abi> doublev<Abi> acos(doublev<Abi> x); |
| 316 | template <class Abi> ldoublev<Abi> acos(ldoublev<Abi> x); |
| 317 | |
| 318 | template <class Abi> floatv<Abi> asin(floatv<Abi> x); |
| 319 | template <class Abi> doublev<Abi> asin(doublev<Abi> x); |
| 320 | template <class Abi> ldoublev<Abi> asin(ldoublev<Abi> x); |
| 321 | |
| 322 | template <class Abi> floatv<Abi> atan(floatv<Abi> x); |
| 323 | template <class Abi> doublev<Abi> atan(doublev<Abi> x); |
| 324 | template <class Abi> ldoublev<Abi> atan(ldoublev<Abi> x); |
| 325 | |
| 326 | template <class Abi> floatv<Abi> atan2(floatv<Abi> y, floatv<Abi> x); |
| 327 | template <class Abi> doublev<Abi> atan2(doublev<Abi> y, doublev<Abi> x); |
| 328 | template <class Abi> ldoublev<Abi> atan2(ldoublev<Abi> y, ldoublev<Abi> x); |
| 329 | |
| 330 | template <class Abi> floatv<Abi> cos(floatv<Abi> x); |
| 331 | template <class Abi> doublev<Abi> cos(doublev<Abi> x); |
| 332 | template <class Abi> ldoublev<Abi> cos(ldoublev<Abi> x); |
| 333 | |
| 334 | template <class Abi> floatv<Abi> sin(floatv<Abi> x); |
| 335 | template <class Abi> doublev<Abi> sin(doublev<Abi> x); |
| 336 | template <class Abi> ldoublev<Abi> sin(ldoublev<Abi> x); |
| 337 | |
| 338 | template <class Abi> floatv<Abi> tan(floatv<Abi> x); |
| 339 | template <class Abi> doublev<Abi> tan(doublev<Abi> x); |
| 340 | template <class Abi> ldoublev<Abi> tan(ldoublev<Abi> x); |
| 341 | |
| 342 | template <class Abi> floatv<Abi> acosh(floatv<Abi> x); |
| 343 | template <class Abi> doublev<Abi> acosh(doublev<Abi> x); |
| 344 | template <class Abi> ldoublev<Abi> acosh(ldoublev<Abi> x); |
| 345 | |
| 346 | template <class Abi> floatv<Abi> asinh(floatv<Abi> x); |
| 347 | template <class Abi> doublev<Abi> asinh(doublev<Abi> x); |
| 348 | template <class Abi> ldoublev<Abi> asinh(ldoublev<Abi> x); |
| 349 | |
| 350 | template <class Abi> floatv<Abi> atanh(floatv<Abi> x); |
| 351 | template <class Abi> doublev<Abi> atanh(doublev<Abi> x); |
| 352 | template <class Abi> ldoublev<Abi> atanh(ldoublev<Abi> x); |
| 353 | |
| 354 | template <class Abi> floatv<Abi> cosh(floatv<Abi> x); |
| 355 | template <class Abi> doublev<Abi> cosh(doublev<Abi> x); |
| 356 | template <class Abi> ldoublev<Abi> cosh(ldoublev<Abi> x); |
| 357 | |
| 358 | template <class Abi> floatv<Abi> sinh(floatv<Abi> x); |
| 359 | template <class Abi> doublev<Abi> sinh(doublev<Abi> x); |
| 360 | template <class Abi> ldoublev<Abi> sinh(ldoublev<Abi> x); |
| 361 | |
| 362 | template <class Abi> floatv<Abi> tanh(floatv<Abi> x); |
| 363 | template <class Abi> doublev<Abi> tanh(doublev<Abi> x); |
| 364 | template <class Abi> ldoublev<Abi> tanh(ldoublev<Abi> x); |
| 365 | |
| 366 | template <class Abi> floatv<Abi> exp(floatv<Abi> x); |
| 367 | template <class Abi> doublev<Abi> exp(doublev<Abi> x); |
| 368 | template <class Abi> ldoublev<Abi> exp(ldoublev<Abi> x); |
| 369 | |
| 370 | template <class Abi> floatv<Abi> exp2(floatv<Abi> x); |
| 371 | template <class Abi> doublev<Abi> exp2(doublev<Abi> x); |
| 372 | template <class Abi> ldoublev<Abi> exp2(ldoublev<Abi> x); |
| 373 | |
| 374 | template <class Abi> floatv<Abi> expm1(floatv<Abi> x); |
| 375 | template <class Abi> doublev<Abi> expm1(doublev<Abi> x); |
| 376 | template <class Abi> ldoublev<Abi> expm1(ldoublev<Abi> x); |
| 377 | |
| 378 | template <class Abi> floatv<Abi> frexp(floatv<Abi> value, samesize<int, floatv<Abi>>* exp); |
| 379 | template <class Abi> doublev<Abi> frexp(doublev<Abi> value, samesize<int, doublev<Abi>>* exp); |
| 380 | template <class Abi> ldoublev<Abi> frexp(ldoublev<Abi> value, samesize<int, ldoublev<Abi>>* exp); |
| 381 | |
| 382 | template <class Abi> samesize<int, floatv<Abi>> ilogb(floatv<Abi> x); |
| 383 | template <class Abi> samesize<int, doublev<Abi>> ilogb(doublev<Abi> x); |
| 384 | template <class Abi> samesize<int, ldoublev<Abi>> ilogb(ldoublev<Abi> x); |
| 385 | |
| 386 | template <class Abi> floatv<Abi> ldexp(floatv<Abi> x, samesize<int, floatv<Abi>> exp); |
| 387 | template <class Abi> doublev<Abi> ldexp(doublev<Abi> x, samesize<int, doublev<Abi>> exp); |
| 388 | template <class Abi> ldoublev<Abi> ldexp(ldoublev<Abi> x, samesize<int, ldoublev<Abi>> exp); |
| 389 | |
| 390 | template <class Abi> floatv<Abi> log(floatv<Abi> x); |
| 391 | template <class Abi> doublev<Abi> log(doublev<Abi> x); |
| 392 | template <class Abi> ldoublev<Abi> log(ldoublev<Abi> x); |
| 393 | |
| 394 | template <class Abi> floatv<Abi> log10(floatv<Abi> x); |
| 395 | template <class Abi> doublev<Abi> log10(doublev<Abi> x); |
| 396 | template <class Abi> ldoublev<Abi> log10(ldoublev<Abi> x); |
| 397 | |
| 398 | template <class Abi> floatv<Abi> log1p(floatv<Abi> x); |
| 399 | template <class Abi> doublev<Abi> log1p(doublev<Abi> x); |
| 400 | template <class Abi> ldoublev<Abi> log1p(ldoublev<Abi> x); |
| 401 | |
| 402 | template <class Abi> floatv<Abi> log2(floatv<Abi> x); |
| 403 | template <class Abi> doublev<Abi> log2(doublev<Abi> x); |
| 404 | template <class Abi> ldoublev<Abi> log2(ldoublev<Abi> x); |
| 405 | |
| 406 | template <class Abi> floatv<Abi> logb(floatv<Abi> x); |
| 407 | template <class Abi> doublev<Abi> logb(doublev<Abi> x); |
| 408 | template <class Abi> ldoublev<Abi> logb(ldoublev<Abi> x); |
| 409 | |
| 410 | template <class Abi> floatv<Abi> modf(floatv<Abi> value, floatv<Abi>* iptr); |
| 411 | template <class Abi> doublev<Abi> modf(doublev<Abi> value, doublev<Abi>* iptr); |
| 412 | template <class Abi> ldoublev<Abi> modf(ldoublev<Abi> value, ldoublev<Abi>* iptr); |
| 413 | |
| 414 | template <class Abi> floatv<Abi> scalbn(floatv<Abi> x, samesize<int, floatv<Abi>> n); |
| 415 | template <class Abi> doublev<Abi> scalbn(doublev<Abi> x, samesize<int, doublev<Abi>> n); |
| 416 | template <class Abi> ldoublev<Abi> scalbn(ldoublev<Abi> x, samesize<int, ldoublev<Abi>> n); |
| 417 | template <class Abi> floatv<Abi> scalbln(floatv<Abi> x, samesize<long int, floatv<Abi>> n); |
| 418 | template <class Abi> doublev<Abi> scalbln(doublev<Abi> x, samesize<long int, doublev<Abi>> n); |
| 419 | template <class Abi> ldoublev<Abi> scalbln(ldoublev<Abi> x, samesize<long int, ldoublev<Abi>> n); |
| 420 | |
| 421 | template <class Abi> floatv<Abi> cbrt(floatv<Abi> x); |
| 422 | template <class Abi> doublev<Abi> cbrt(doublev<Abi> x); |
| 423 | template <class Abi> ldoublev<Abi> cbrt(ldoublev<Abi> x); |
| 424 | |
| 425 | template <class Abi> scharv<Abi> abs(scharv<Abi> j); |
| 426 | template <class Abi> shortv<Abi> abs(shortv<Abi> j); |
| 427 | template <class Abi> intv<Abi> abs(intv<Abi> j); |
| 428 | template <class Abi> longv<Abi> abs(longv<Abi> j); |
| 429 | template <class Abi> llongv<Abi> abs(llongv<Abi> j); |
| 430 | template <class Abi> floatv<Abi> abs(floatv<Abi> j); |
| 431 | template <class Abi> doublev<Abi> abs(doublev<Abi> j); |
| 432 | template <class Abi> ldoublev<Abi> abs(ldoublev<Abi> j); |
| 433 | |
| 434 | template <class Abi> floatv<Abi> hypot(floatv<Abi> x, floatv<Abi> y); |
| 435 | template <class Abi> doublev<Abi> hypot(doublev<Abi> x, doublev<Abi> y); |
| 436 | template <class Abi> ldoublev<Abi> hypot(doublev<Abi> x, doublev<Abi> y); |
| 437 | template <class Abi> floatv<Abi> hypot(floatv<Abi> x, floatv<Abi> y, floatv<Abi> z); |
| 438 | template <class Abi> doublev<Abi> hypot(doublev<Abi> x, doublev<Abi> y, doublev<Abi> z); |
| 439 | template <class Abi> ldoublev<Abi> hypot(ldoublev<Abi> x, ldoublev<Abi> y, ldoublev<Abi> z); |
| 440 | |
| 441 | template <class Abi> floatv<Abi> pow(floatv<Abi> x, floatv<Abi> y); |
| 442 | template <class Abi> doublev<Abi> pow(doublev<Abi> x, doublev<Abi> y); |
| 443 | template <class Abi> ldoublev<Abi> pow(ldoublev<Abi> x, ldoublev<Abi> y); |
| 444 | |
| 445 | template <class Abi> floatv<Abi> sqrt(floatv<Abi> x); |
| 446 | template <class Abi> doublev<Abi> sqrt(doublev<Abi> x); |
| 447 | template <class Abi> ldoublev<Abi> sqrt(ldoublev<Abi> x); |
| 448 | |
| 449 | template <class Abi> floatv<Abi> erf(floatv<Abi> x); |
| 450 | template <class Abi> doublev<Abi> erf(doublev<Abi> x); |
| 451 | template <class Abi> ldoublev<Abi> erf(ldoublev<Abi> x); |
| 452 | template <class Abi> floatv<Abi> erfc(floatv<Abi> x); |
| 453 | template <class Abi> doublev<Abi> erfc(doublev<Abi> x); |
| 454 | template <class Abi> ldoublev<Abi> erfc(ldoublev<Abi> x); |
| 455 | |
| 456 | template <class Abi> floatv<Abi> lgamma(floatv<Abi> x); |
| 457 | template <class Abi> doublev<Abi> lgamma(doublev<Abi> x); |
| 458 | template <class Abi> ldoublev<Abi> lgamma(ldoublev<Abi> x); |
| 459 | |
| 460 | template <class Abi> floatv<Abi> tgamma(floatv<Abi> x); |
| 461 | template <class Abi> doublev<Abi> tgamma(doublev<Abi> x); |
| 462 | template <class Abi> ldoublev<Abi> tgamma(ldoublev<Abi> x); |
| 463 | |
| 464 | template <class Abi> floatv<Abi> ceil(floatv<Abi> x); |
| 465 | template <class Abi> doublev<Abi> ceil(doublev<Abi> x); |
| 466 | template <class Abi> ldoublev<Abi> ceil(ldoublev<Abi> x); |
| 467 | |
| 468 | template <class Abi> floatv<Abi> floor(floatv<Abi> x); |
| 469 | template <class Abi> doublev<Abi> floor(doublev<Abi> x); |
| 470 | template <class Abi> ldoublev<Abi> floor(ldoublev<Abi> x); |
| 471 | |
| 472 | template <class Abi> floatv<Abi> nearbyint(floatv<Abi> x); |
| 473 | template <class Abi> doublev<Abi> nearbyint(doublev<Abi> x); |
| 474 | template <class Abi> ldoublev<Abi> nearbyint(ldoublev<Abi> x); |
| 475 | |
| 476 | template <class Abi> floatv<Abi> rint(floatv<Abi> x); |
| 477 | template <class Abi> doublev<Abi> rint(doublev<Abi> x); |
| 478 | template <class Abi> ldoublev<Abi> rint(ldoublev<Abi> x); |
| 479 | |
| 480 | template <class Abi> samesize<long int, floatv<Abi>> lrint(floatv<Abi> x); |
| 481 | template <class Abi> samesize<long int, doublev<Abi>> lrint(doublev<Abi> x); |
| 482 | template <class Abi> samesize<long int, ldoublev<Abi>> lrint(ldoublev<Abi> x); |
| 483 | template <class Abi> samesize<long long int, floatv<Abi>> llrint(floatv<Abi> x); |
| 484 | template <class Abi> samesize<long long int, doublev<Abi>> llrint(doublev<Abi> x); |
| 485 | template <class Abi> samesize<long long int, ldoublev<Abi>> llrint(ldoublev<Abi> x); |
| 486 | |
| 487 | template <class Abi> floatv<Abi> round(floatv<Abi> x); |
| 488 | template <class Abi> doublev<Abi> round(doublev<Abi> x); |
| 489 | template <class Abi> ldoublev<Abi> round(ldoublev<Abi> x); |
| 490 | template <class Abi> samesize<long int, floatv<Abi>> lround(floatv<Abi> x); |
| 491 | template <class Abi> samesize<long int, doublev<Abi>> lround(doublev<Abi> x); |
| 492 | template <class Abi> samesize<long int, ldoublev<Abi>> lround(ldoublev<Abi> x); |
| 493 | template <class Abi> samesize<long long int, floatv<Abi>> llround(floatv<Abi> x); |
| 494 | template <class Abi> samesize<long long int, doublev<Abi>> llround(doublev<Abi> x); |
| 495 | template <class Abi> samesize<long long int, ldoublev<Abi>> llround(ldoublev<Abi> x); |
| 496 | |
| 497 | template <class Abi> floatv<Abi> trunc(floatv<Abi> x); |
| 498 | template <class Abi> doublev<Abi> trunc(doublev<Abi> x); |
| 499 | template <class Abi> ldoublev<Abi> trunc(ldoublev<Abi> x); |
| 500 | |
| 501 | template <class Abi> floatv<Abi> fmod(floatv<Abi> x, floatv<Abi> y); |
| 502 | template <class Abi> doublev<Abi> fmod(doublev<Abi> x, doublev<Abi> y); |
| 503 | template <class Abi> ldoublev<Abi> fmod(ldoublev<Abi> x, ldoublev<Abi> y); |
| 504 | |
| 505 | template <class Abi> floatv<Abi> remainder(floatv<Abi> x, floatv<Abi> y); |
| 506 | template <class Abi> doublev<Abi> remainder(doublev<Abi> x, doublev<Abi> y); |
| 507 | template <class Abi> ldoublev<Abi> remainder(ldoublev<Abi> x, ldoublev<Abi> y); |
| 508 | |
| 509 | template <class Abi> floatv<Abi> remquo(floatv<Abi> x, floatv<Abi> y, samesize<int, floatv<Abi>>* quo); |
| 510 | template <class Abi> doublev<Abi> remquo(doublev<Abi> x, doublev<Abi> y, samesize<int, doublev<Abi>>* quo); |
| 511 | template <class Abi> ldoublev<Abi> remquo(ldoublev<Abi> x, ldoublev<Abi> y, samesize<int, ldoublev<Abi>>* quo); |
| 512 | |
| 513 | template <class Abi> floatv<Abi> copysign(floatv<Abi> x, floatv<Abi> y); |
| 514 | template <class Abi> doublev<Abi> copysign(doublev<Abi> x, doublev<Abi> y); |
| 515 | template <class Abi> ldoublev<Abi> copysign(ldoublev<Abi> x, ldoublev<Abi> y); |
| 516 | |
| 517 | template <class Abi> doublev<Abi> nan(const char* tagp); |
| 518 | template <class Abi> floatv<Abi> nanf(const char* tagp); |
| 519 | template <class Abi> ldoublev<Abi> nanl(const char* tagp); |
| 520 | |
| 521 | template <class Abi> floatv<Abi> nextafter(floatv<Abi> x, floatv<Abi> y); |
| 522 | template <class Abi> doublev<Abi> nextafter(doublev<Abi> x, doublev<Abi> y); |
| 523 | template <class Abi> ldoublev<Abi> nextafter(ldoublev<Abi> x, ldoublev<Abi> y); |
| 524 | |
| 525 | template <class Abi> floatv<Abi> nexttoward(floatv<Abi> x, ldoublev<Abi> y); |
| 526 | template <class Abi> doublev<Abi> nexttoward(doublev<Abi> x, ldoublev<Abi> y); |
| 527 | template <class Abi> ldoublev<Abi> nexttoward(ldoublev<Abi> x, ldoublev<Abi> y); |
| 528 | |
| 529 | template <class Abi> floatv<Abi> fdim(floatv<Abi> x, floatv<Abi> y); |
| 530 | template <class Abi> doublev<Abi> fdim(doublev<Abi> x, doublev<Abi> y); |
| 531 | template <class Abi> ldoublev<Abi> fdim(ldoublev<Abi> x, ldoublev<Abi> y); |
| 532 | |
| 533 | template <class Abi> floatv<Abi> fmax(floatv<Abi> x, floatv<Abi> y); |
| 534 | template <class Abi> doublev<Abi> fmax(doublev<Abi> x, doublev<Abi> y); |
| 535 | template <class Abi> ldoublev<Abi> fmax(ldoublev<Abi> x, ldoublev<Abi> y); |
| 536 | |
| 537 | template <class Abi> floatv<Abi> fmin(floatv<Abi> x, floatv<Abi> y); |
| 538 | template <class Abi> doublev<Abi> fmin(doublev<Abi> x, doublev<Abi> y); |
| 539 | template <class Abi> ldoublev<Abi> fmin(ldoublev<Abi> x, ldoublev<Abi> y); |
| 540 | |
| 541 | template <class Abi> floatv<Abi> fma(floatv<Abi> x, floatv<Abi> y, floatv<Abi> z); |
| 542 | template <class Abi> doublev<Abi> fma(doublev<Abi> x, doublev<Abi> y, doublev<Abi> z); |
| 543 | template <class Abi> ldoublev<Abi> fma(ldoublev<Abi> x, ldoublev<Abi> y, ldoublev<Abi> z); |
| 544 | |
| 545 | template <class Abi> samesize<int, floatv<Abi>> fpclassify(floatv<Abi> x); |
| 546 | template <class Abi> samesize<int, doublev<Abi>> fpclassify(doublev<Abi> x); |
| 547 | template <class Abi> samesize<int, ldoublev<Abi>> fpclassify(ldoublev<Abi> x); |
| 548 | |
| 549 | template <class Abi> simd_mask<float, Abi> isfinite(floatv<Abi> x); |
| 550 | template <class Abi> simd_mask<double, Abi> isfinite(doublev<Abi> x); |
| 551 | template <class Abi> simd_mask<long double, Abi> isfinite(ldoublev<Abi> x); |
| 552 | |
| 553 | template <class Abi> simd_mask<float, Abi> isinf(floatv<Abi> x); |
| 554 | template <class Abi> simd_mask<double, Abi> isinf(doublev<Abi> x); |
| 555 | template <class Abi> simd_mask<long double, Abi> isinf(ldoublev<Abi> x); |
| 556 | |
| 557 | template <class Abi> simd_mask<float, Abi> isnan(floatv<Abi> x); |
| 558 | template <class Abi> simd_mask<double, Abi> isnan(doublev<Abi> x); |
| 559 | template <class Abi> simd_mask<long double, Abi> isnan(ldoublev<Abi> x); |
| 560 | |
| 561 | template <class Abi> simd_mask<float, Abi> isnormal(floatv<Abi> x); |
| 562 | template <class Abi> simd_mask<double, Abi> isnormal(doublev<Abi> x); |
| 563 | template <class Abi> simd_mask<long double, Abi> isnormal(ldoublev<Abi> x); |
| 564 | |
| 565 | template <class Abi> simd_mask<float, Abi> signbit(floatv<Abi> x); |
| 566 | template <class Abi> simd_mask<double, Abi> signbit(doublev<Abi> x); |
| 567 | template <class Abi> simd_mask<long double, Abi> signbit(ldoublev<Abi> x); |
| 568 | |
| 569 | template <class Abi> simd_mask<float, Abi> isgreater(floatv<Abi> x, floatv<Abi> y); |
| 570 | template <class Abi> simd_mask<double, Abi> isgreater(doublev<Abi> x, doublev<Abi> y); |
| 571 | template <class Abi> simd_mask<long double, Abi> isgreater(ldoublev<Abi> x, ldoublev<Abi> y); |
| 572 | |
| 573 | template <class Abi> simd_mask<float, Abi> isgreaterequal(floatv<Abi> x, floatv<Abi> y); |
| 574 | template <class Abi> simd_mask<double, Abi> isgreaterequal(doublev<Abi> x, doublev<Abi> y); |
| 575 | template <class Abi> simd_mask<long double, Abi> isgreaterequal(ldoublev<Abi> x, ldoublev<Abi> y); |
| 576 | |
| 577 | template <class Abi> simd_mask<float, Abi> isless(floatv<Abi> x, floatv<Abi> y); |
| 578 | template <class Abi> simd_mask<double, Abi> isless(doublev<Abi> x, doublev<Abi> y); |
| 579 | template <class Abi> simd_mask<long double, Abi> isless(ldoublev<Abi> x, ldoublev<Abi> y); |
| 580 | |
| 581 | template <class Abi> simd_mask<float, Abi> islessequal(floatv<Abi> x, floatv<Abi> y); |
| 582 | template <class Abi> simd_mask<double, Abi> islessequal(doublev<Abi> x, doublev<Abi> y); |
| 583 | template <class Abi> simd_mask<long double, Abi> islessequal(ldoublev<Abi> x, ldoublev<Abi> y); |
| 584 | |
| 585 | template <class Abi> simd_mask<float, Abi> islessgreater(floatv<Abi> x, floatv<Abi> y); |
| 586 | template <class Abi> simd_mask<double, Abi> islessgreater(doublev<Abi> x, doublev<Abi> y); |
| 587 | template <class Abi> simd_mask<long double, Abi> islessgreater(ldoublev<Abi> x, ldoublev<Abi> y); |
| 588 | |
| 589 | template <class Abi> simd_mask<float, Abi> isunordered(floatv<Abi> x, floatv<Abi> y); |
| 590 | template <class Abi> simd_mask<double, Abi> isunordered(doublev<Abi> x, doublev<Abi> y); |
| 591 | template <class Abi> simd_mask<long double, Abi> isunordered(ldoublev<Abi> x, ldoublev<Abi> y); |
| 592 | |
| 593 | template <class V> struct simd_div_t { V quot, rem; }; |
| 594 | template <class Abi> simd_div_t<scharv<Abi>> div(scharv<Abi> numer, scharv<Abi> denom); |
| 595 | template <class Abi> simd_div_t<shortv<Abi>> div(shortv<Abi> numer, shortv<Abi> denom); |
| 596 | template <class Abi> simd_div_t<intv<Abi>> div(intv<Abi> numer, intv<Abi> denom); |
| 597 | template <class Abi> simd_div_t<longv<Abi>> div(longv<Abi> numer, longv<Abi> denom); |
| 598 | template <class Abi> simd_div_t<llongv<Abi>> div(llongv<Abi> numer, llongv<Abi> denom); |
| 599 | |
| 600 | // [simd.mask.class] |
| 601 | template <class T, class Abi> |
| 602 | class simd_mask { |
| 603 | public: |
| 604 | using value_type = bool; |
| 605 | using reference = see below; |
| 606 | using simd_type = simd<T, Abi>; |
| 607 | using abi_type = Abi; |
| 608 | static constexpr size_t size() noexcept; |
| 609 | simd_mask() = default; |
| 610 | |
| 611 | // broadcast constructor |
| 612 | explicit simd_mask(value_type) noexcept; |
| 613 | |
| 614 | // implicit type conversion constructor |
| 615 | template <class U> simd_mask(const simd_mask<U, simd_abi::fixed_size<size()>>&) noexcept; |
| 616 | |
| 617 | // load constructor |
| 618 | template <class Flags> simd_mask(const value_type* mem, Flags); |
| 619 | |
| 620 | // loads [simd.mask.copy] |
| 621 | template <class Flags> void copy_from(const value_type* mem, Flags); |
| 622 | template <class Flags> void copy_to(value_type* mem, Flags) const; |
| 623 | |
| 624 | // scalar access [simd.mask.subscr] |
| 625 | reference operator[](size_t); |
| 626 | value_type operator[](size_t) const; |
| 627 | |
| 628 | // unary operators [simd.mask.unary] |
| 629 | simd_mask operator!() const noexcept; |
| 630 | |
| 631 | // simd_mask binary operators [simd.mask.binary] |
| 632 | friend simd_mask operator&&(const simd_mask&, const simd_mask&) noexcept; |
| 633 | friend simd_mask operator||(const simd_mask&, const simd_mask&) noexcept; |
| 634 | friend simd_mask operator& (const simd_mask&, const simd_mask&) noexcept; |
| 635 | friend simd_mask operator| (const simd_mask&, const simd_mask&) noexcept; |
| 636 | friend simd_mask operator^ (const simd_mask&, const simd_mask&) noexcept; |
| 637 | |
| 638 | // simd_mask compound assignment [simd.mask.cassign] |
| 639 | friend simd_mask& operator&=(simd_mask&, const simd_mask&) noexcept; |
| 640 | friend simd_mask& operator|=(simd_mask&, const simd_mask&) noexcept; |
| 641 | friend simd_mask& operator^=(simd_mask&, const simd_mask&) noexcept; |
| 642 | |
| 643 | // simd_mask compares [simd.mask.comparison] |
| 644 | friend simd_mask operator==(const simd_mask&, const simd_mask&) noexcept; |
| 645 | friend simd_mask operator!=(const simd_mask&, const simd_mask&) noexcept; |
| 646 | }; |
| 647 | |
| 648 | } // parallelism_v2 |
| 649 | } // std::experimental |
| 650 | |
| 651 | */ |
| 652 | |
| 653 | #include <experimental/__config> |
| 654 | #include <array> |
| 655 | #include <cstddef> |
| 656 | #include <functional> |
| 657 | |
| 658 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 659 | #pragma GCC system_header |
| 660 | #endif |
| 661 | |
| 662 | _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD |
| 663 | |
| 664 | enum class _StorageKind { |
| 665 | _Scalar, |
| 666 | _Array, |
| 667 | }; |
| 668 | |
| 669 | template <_StorageKind __kind, int _Np> |
| 670 | struct __simd_abi {}; |
| 671 | |
| 672 | template <class _Tp, class _Abi> |
| 673 | struct __simd_storage_traits {}; |
| 674 | |
| 675 | template <class _Tp, int __num_element> |
| 676 | struct __simd_storage_traits<_Tp, |
| 677 | __simd_abi<_StorageKind::_Array, __num_element>> { |
| 678 | using type = std::array<_Tp, __num_element>; |
| 679 | }; |
| 680 | |
| 681 | template <class _Tp> |
| 682 | struct __simd_storage_traits<_Tp, __simd_abi<_StorageKind::_Scalar, 1>> { |
| 683 | using type = _Tp; |
| 684 | }; |
| 685 | |
| 686 | template <class _To, class _From> |
| 687 | constexpr decltype(_To{std::declval<_From>()}, true) |
| 688 | __is_non_narrowing_convertible_impl(_From) { |
| 689 | return true; |
| 690 | } |
| 691 | |
| 692 | template <class _To> |
| 693 | constexpr bool __is_non_narrowing_convertible_impl(...) { |
| 694 | return false; |
| 695 | } |
| 696 | |
| 697 | template <class _From, class _To> |
| 698 | constexpr typename std::enable_if<std::is_arithmetic<_To>::value && |
| 699 | std::is_arithmetic<_From>::value, |
| 700 | bool>::type |
| 701 | __is_non_narrowing_arithmetic_convertible() { |
| 702 | return __is_non_narrowing_convertible_impl<_To>(_From{}); |
| 703 | } |
| 704 | |
| 705 | template <class _From, class _To> |
| 706 | constexpr typename std::enable_if<!(std::is_arithmetic<_To>::value && |
| 707 | std::is_arithmetic<_From>::value), |
| 708 | bool>::type |
| 709 | __is_non_narrowing_arithmetic_convertible() { |
| 710 | return false; |
| 711 | } |
| 712 | |
| 713 | template <class _Tp> |
| 714 | constexpr _Tp __variadic_sum() { |
| 715 | return _Tp{}; |
| 716 | } |
| 717 | |
| 718 | template <class _Tp, class _Up, class... _Args> |
| 719 | constexpr _Tp __variadic_sum(_Up __first, _Args... __rest) { |
| 720 | return static_cast<_Tp>(__first) + __variadic_sum<_Tp>(__rest...); |
| 721 | } |
| 722 | |
| 723 | _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD |
| 724 | _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD_ABI |
| 725 | |
| 726 | using scalar = __simd_abi<_StorageKind::_Scalar, 1>; |
| 727 | |
| 728 | template <int _Np> |
| 729 | using fixed_size = __simd_abi<_StorageKind::_Array, _Np>; |
| 730 | |
| 731 | #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) |
| 732 | template <class _Tp> |
| 733 | _LIBCPP_INLINE_VAR constexpr int max_fixed_size = 32; |
| 734 | #endif |
| 735 | template <class _Tp> |
| 736 | using compatible = fixed_size<16 / sizeof(_Tp)>; |
| 737 | template <class _Tp> |
| 738 | using native = compatible<_Tp>; |
| 739 | |
| 740 | _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD_ABI |
| 741 | _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD |
| 742 | |
| 743 | template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> |
| 744 | class simd; |
| 745 | template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> |
| 746 | class simd_mask; |
| 747 | |
| 748 | struct element_aligned_tag {}; |
| 749 | struct vector_aligned_tag {}; |
| 750 | template <size_t> |
| 751 | struct overaligned_tag {}; |
| 752 | #if _LIBCPP_STD_VER > 14 |
| 753 | _LIBCPP_INLINE_VAR constexpr element_aligned_tag element_aligned{}; |
| 754 | _LIBCPP_INLINE_VAR constexpr vector_aligned_tag vector_aligned{}; |
| 755 | #if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) |
| 756 | template <size_t _Np> |
| 757 | _LIBCPP_INLINE_VAR constexpr overaligned_tag<_Np> overaligned{}; |
| 758 | #endif |
| 759 | #endif |
| 760 | |
| 761 | // traits [simd.traits] |
| 762 | template <class _Tp> |
| 763 | struct is_abi_tag : std::integral_constant<bool, false> {}; |
| 764 | |
| 765 | template <_StorageKind __kind, int _Np> |
| 766 | struct is_abi_tag<__simd_abi<__kind, _Np>> |
| 767 | : std::integral_constant<bool, true> {}; |
| 768 | |
| 769 | template <class _Tp> |
| 770 | struct is_simd : std::integral_constant<bool, false> {}; |
| 771 | |
| 772 | template <class _Tp, class _Abi> |
| 773 | struct is_simd<simd<_Tp, _Abi>> : std::integral_constant<bool, true> {}; |
| 774 | |
| 775 | template <class _Tp> |
| 776 | struct is_simd_mask : std::integral_constant<bool, false> {}; |
| 777 | |
| 778 | template <class _Tp, class _Abi> |
| 779 | struct is_simd_mask<simd_mask<_Tp, _Abi>> : std::integral_constant<bool, true> { |
| 780 | }; |
| 781 | |
| 782 | template <class _Tp> |
| 783 | struct is_simd_flag_type : std::integral_constant<bool, false> {}; |
| 784 | |
| 785 | template <> |
| 786 | struct is_simd_flag_type<element_aligned_tag> |
| 787 | : std::integral_constant<bool, true> {}; |
| 788 | |
| 789 | template <> |
| 790 | struct is_simd_flag_type<vector_aligned_tag> |
| 791 | : std::integral_constant<bool, true> {}; |
| 792 | |
| 793 | template <size_t _Align> |
| 794 | struct is_simd_flag_type<overaligned_tag<_Align>> |
| 795 | : std::integral_constant<bool, true> {}; |
| 796 | |
| 797 | #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) |
| 798 | template <class _Tp> |
| 799 | _LIBCPP_INLINE_VAR constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value; |
| 800 | template <class _Tp> |
| 801 | _LIBCPP_INLINE_VAR constexpr bool is_simd_v = is_simd<_Tp>::value; |
| 802 | template <class _Tp> |
| 803 | _LIBCPP_INLINE_VAR constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value; |
| 804 | template <class _Tp> |
| 805 | _LIBCPP_INLINE_VAR constexpr bool is_simd_flag_type_v = |
| 806 | is_simd_flag_type<_Tp>::value; |
| 807 | #endif |
| 808 | template <class _Tp, size_t _Np> |
| 809 | struct abi_for_size { |
| 810 | using type = simd_abi::fixed_size<_Np>; |
| 811 | }; |
| 812 | template <class _Tp, size_t _Np> |
| 813 | using abi_for_size_t = typename abi_for_size<_Tp, _Np>::type; |
| 814 | |
| 815 | template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> |
| 816 | struct simd_size; |
| 817 | |
| 818 | template <class _Tp, _StorageKind __kind, int _Np> |
| 819 | struct simd_size<_Tp, __simd_abi<__kind, _Np>> |
| 820 | : std::integral_constant<size_t, _Np> { |
| 821 | static_assert( |
| 822 | std::is_arithmetic<_Tp>::value && |
| 823 | !std::is_same<typename std::remove_const<_Tp>::type, bool>::value, |
| 824 | "Element type should be vectorizable"); |
| 825 | }; |
| 826 | |
| 827 | template <class _Tp, class _Up = typename _Tp::value_type> |
| 828 | struct memory_alignment; |
| 829 | |
| 830 | #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) |
| 831 | template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> |
| 832 | _LIBCPP_INLINE_VAR constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value; |
| 833 | |
| 834 | template <class _Tp, class _Up = typename _Tp::value_type> |
| 835 | _LIBCPP_INLINE_VAR constexpr size_t memory_alignment_v = |
| 836 | memory_alignment<_Tp, _Up>::value; |
| 837 | #endif |
| 838 | |
| 839 | // class template simd [simd.class] |
| 840 | template <class _Tp> |
| 841 | using native_simd = simd<_Tp, simd_abi::native<_Tp>>; |
| 842 | template <class _Tp, int _Np> |
| 843 | using fixed_size_simd = simd<_Tp, simd_abi::fixed_size<_Np>>; |
| 844 | |
| 845 | // class template simd_mask [simd.mask.class] |
| 846 | template <class _Tp> |
| 847 | using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>; |
| 848 | |
| 849 | template <class _Tp, int _Np> |
| 850 | using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>; |
| 851 | |
| 852 | // casts [simd.casts] |
| 853 | template <class _Tp> |
| 854 | struct __static_simd_cast_traits { |
| 855 | template <class _Up, class _Abi> |
| 856 | static simd<_Tp, _Abi> __apply(const simd<_Up, _Abi>& __v); |
| 857 | }; |
| 858 | |
| 859 | template <class _Tp, class _NewAbi> |
| 860 | struct __static_simd_cast_traits<simd<_Tp, _NewAbi>> { |
| 861 | template <class _Up, class _Abi> |
| 862 | static typename std::enable_if<simd<_Up, _Abi>::size() == |
| 863 | simd<_Tp, _NewAbi>::size(), |
| 864 | simd<_Tp, _NewAbi>>::type |
| 865 | __apply(const simd<_Up, _Abi>& __v); |
| 866 | }; |
| 867 | |
| 868 | template <class _Tp> |
| 869 | struct __simd_cast_traits { |
| 870 | template <class _Up, class _Abi> |
| 871 | static typename std::enable_if< |
| 872 | __is_non_narrowing_arithmetic_convertible<_Up, _Tp>(), |
| 873 | simd<_Tp, _Abi>>::type |
| 874 | __apply(const simd<_Up, _Abi>& __v); |
| 875 | }; |
| 876 | |
| 877 | template <class _Tp, class _NewAbi> |
| 878 | struct __simd_cast_traits<simd<_Tp, _NewAbi>> { |
| 879 | template <class _Up, class _Abi> |
| 880 | static typename std::enable_if< |
| 881 | __is_non_narrowing_arithmetic_convertible<_Up, _Tp>() && |
| 882 | simd<_Up, _Abi>::size() == simd<_Tp, _NewAbi>::size(), |
| 883 | simd<_Tp, _NewAbi>>::type |
| 884 | __apply(const simd<_Up, _Abi>& __v); |
| 885 | }; |
| 886 | |
| 887 | template <class _Tp, class _Up, class _Abi> |
| 888 | auto simd_cast(const simd<_Up, _Abi>& __v) |
| 889 | -> decltype(__simd_cast_traits<_Tp>::__apply(__v)) { |
| 890 | return __simd_cast_traits<_Tp>::__apply(__v); |
| 891 | } |
| 892 | |
| 893 | template <class _Tp, class _Up, class _Abi> |
| 894 | auto static_simd_cast(const simd<_Up, _Abi>& __v) |
| 895 | -> decltype(__static_simd_cast_traits<_Tp>::__apply(__v)) { |
| 896 | return __static_simd_cast_traits<_Tp>::__apply(__v); |
| 897 | } |
| 898 | |
| 899 | template <class _Tp, class _Abi> |
| 900 | fixed_size_simd<_Tp, simd_size<_Tp, _Abi>::value> |
| 901 | to_fixed_size(const simd<_Tp, _Abi>&) noexcept; |
| 902 | |
| 903 | template <class _Tp, class _Abi> |
| 904 | fixed_size_simd_mask<_Tp, simd_size<_Tp, _Abi>::value> |
| 905 | to_fixed_size(const simd_mask<_Tp, _Abi>&) noexcept; |
| 906 | |
| 907 | template <class _Tp, size_t _Np> |
| 908 | native_simd<_Tp> to_native(const fixed_size_simd<_Tp, _Np>&) noexcept; |
| 909 | |
| 910 | template <class _Tp, size_t _Np> |
| 911 | native_simd_mask<_Tp> to_native(const fixed_size_simd_mask<_Tp, _Np>&) noexcept; |
| 912 | |
| 913 | template <class _Tp, size_t _Np> |
| 914 | simd<_Tp> to_compatible(const fixed_size_simd<_Tp, _Np>&) noexcept; |
| 915 | |
| 916 | template <class _Tp, size_t _Np> |
| 917 | simd_mask<_Tp> to_compatible(const fixed_size_simd_mask<_Tp, _Np>&) noexcept; |
| 918 | |
| 919 | template <size_t... __sizes, class _Tp, class _Abi> |
| 920 | tuple<simd<_Tp, abi_for_size_t<_Tp, __sizes>>...> split(const simd<_Tp, _Abi>&); |
| 921 | |
| 922 | template <size_t... __sizes, class _Tp, class _Abi> |
| 923 | tuple<simd_mask<_Tp, abi_for_size_t<_Tp, __sizes>>...> |
| 924 | split(const simd_mask<_Tp, _Abi>&); |
| 925 | |
| 926 | template <class _SimdType, class _Abi> |
| 927 | array<_SimdType, simd_size<typename _SimdType::value_type, _Abi>::value / |
| 928 | _SimdType::size()> |
| 929 | split(const simd<typename _SimdType::value_type, _Abi>&); |
| 930 | |
| 931 | template <class _SimdType, class _Abi> |
| 932 | array<_SimdType, simd_size<typename _SimdType::value_type, _Abi>::value / |
| 933 | _SimdType::size()> |
| 934 | split(const simd_mask<typename _SimdType::value_type, _Abi>&); |
| 935 | |
| 936 | template <class _Tp, class... _Abis> |
| 937 | simd<_Tp, abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>> |
| 938 | concat(const simd<_Tp, _Abis>&...); |
| 939 | |
| 940 | template <class _Tp, class... _Abis> |
| 941 | simd_mask<_Tp, |
| 942 | abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>> |
| 943 | concat(const simd_mask<_Tp, _Abis>&...); |
| 944 | |
| 945 | // reductions [simd.mask.reductions] |
| 946 | template <class _Tp, class _Abi> |
| 947 | bool all_of(const simd_mask<_Tp, _Abi>&) noexcept; |
| 948 | template <class _Tp, class _Abi> |
| 949 | bool any_of(const simd_mask<_Tp, _Abi>&) noexcept; |
| 950 | template <class _Tp, class _Abi> |
| 951 | bool none_of(const simd_mask<_Tp, _Abi>&) noexcept; |
| 952 | template <class _Tp, class _Abi> |
| 953 | bool some_of(const simd_mask<_Tp, _Abi>&) noexcept; |
| 954 | template <class _Tp, class _Abi> |
| 955 | int popcount(const simd_mask<_Tp, _Abi>&) noexcept; |
| 956 | template <class _Tp, class _Abi> |
| 957 | int find_first_set(const simd_mask<_Tp, _Abi>&); |
| 958 | template <class _Tp, class _Abi> |
| 959 | int find_last_set(const simd_mask<_Tp, _Abi>&); |
| 960 | bool all_of(bool) noexcept; |
| 961 | bool any_of(bool) noexcept; |
| 962 | bool none_of(bool) noexcept; |
| 963 | bool some_of(bool) noexcept; |
| 964 | int popcount(bool) noexcept; |
| 965 | int find_first_set(bool) noexcept; |
| 966 | int find_last_set(bool) noexcept; |
| 967 | |
| 968 | // masked assignment [simd.whereexpr] |
| 969 | template <class _MaskType, class _Tp> |
| 970 | class const_where_expression; |
| 971 | template <class _MaskType, class _Tp> |
| 972 | class where_expression; |
| 973 | |
| 974 | // masked assignment [simd.mask.where] |
| 975 | template <class _Tp> |
| 976 | struct __nodeduce { |
| 977 | using type = _Tp; |
| 978 | }; |
| 979 | |
| 980 | template <class _Tp, class _Abi> |
| 981 | where_expression<simd_mask<_Tp, _Abi>, simd<_Tp, _Abi>> |
| 982 | where(const typename simd<_Tp, _Abi>::mask_type&, simd<_Tp, _Abi>&) noexcept; |
| 983 | |
| 984 | template <class _Tp, class _Abi> |
| 985 | const_where_expression<simd_mask<_Tp, _Abi>, const simd<_Tp, _Abi>> |
| 986 | where(const typename simd<_Tp, _Abi>::mask_type&, |
| 987 | const simd<_Tp, _Abi>&) noexcept; |
| 988 | |
| 989 | template <class _Tp, class _Abi> |
| 990 | where_expression<simd_mask<_Tp, _Abi>, simd_mask<_Tp, _Abi>> |
| 991 | where(const typename __nodeduce<simd_mask<_Tp, _Abi>>::type&, |
| 992 | simd_mask<_Tp, _Abi>&) noexcept; |
| 993 | |
| 994 | template <class _Tp, class _Abi> |
| 995 | const_where_expression<simd_mask<_Tp, _Abi>, const simd_mask<_Tp, _Abi>> |
| 996 | where(const typename __nodeduce<simd_mask<_Tp, _Abi>>::type&, |
| 997 | const simd_mask<_Tp, _Abi>&) noexcept; |
| 998 | |
| 999 | template <class _Tp> |
| 1000 | where_expression<bool, _Tp> where(bool, _Tp&) noexcept; |
| 1001 | |
| 1002 | template <class _Tp> |
| 1003 | const_where_expression<bool, const _Tp> where(bool, const _Tp&) noexcept; |
| 1004 | |
| 1005 | // reductions [simd.reductions] |
| 1006 | template <class _Tp, class _Abi, class _BinaryOp = std::plus<_Tp>> |
| 1007 | _Tp reduce(const simd<_Tp, _Abi>&, _BinaryOp = _BinaryOp()); |
| 1008 | |
| 1009 | template <class _MaskType, class _SimdType, class _BinaryOp> |
| 1010 | typename _SimdType::value_type |
| 1011 | reduce(const const_where_expression<_MaskType, _SimdType>&, |
| 1012 | typename _SimdType::value_type neutral_element, _BinaryOp binary_op); |
| 1013 | |
| 1014 | template <class _MaskType, class _SimdType> |
| 1015 | typename _SimdType::value_type |
| 1016 | reduce(const const_where_expression<_MaskType, _SimdType>&, |
| 1017 | plus<typename _SimdType::value_type> binary_op = {}); |
| 1018 | |
| 1019 | template <class _MaskType, class _SimdType> |
| 1020 | typename _SimdType::value_type |
| 1021 | reduce(const const_where_expression<_MaskType, _SimdType>&, |
| 1022 | multiplies<typename _SimdType::value_type> binary_op); |
| 1023 | |
| 1024 | template <class _MaskType, class _SimdType> |
| 1025 | typename _SimdType::value_type |
| 1026 | reduce(const const_where_expression<_MaskType, _SimdType>&, |
| 1027 | bit_and<typename _SimdType::value_type> binary_op); |
| 1028 | |
| 1029 | template <class _MaskType, class _SimdType> |
| 1030 | typename _SimdType::value_type |
| 1031 | reduce(const const_where_expression<_MaskType, _SimdType>&, |
| 1032 | bit_or<typename _SimdType::value_type> binary_op); |
| 1033 | |
| 1034 | template <class _MaskType, class _SimdType> |
| 1035 | typename _SimdType::value_type |
| 1036 | reduce(const const_where_expression<_MaskType, _SimdType>&, |
| 1037 | bit_xor<typename _SimdType::value_type> binary_op); |
| 1038 | |
| 1039 | template <class _Tp, class _Abi> |
| 1040 | _Tp hmin(const simd<_Tp, _Abi>&); |
| 1041 | template <class _MaskType, class _SimdType> |
| 1042 | typename _SimdType::value_type |
| 1043 | hmin(const const_where_expression<_MaskType, _SimdType>&); |
| 1044 | template <class _Tp, class _Abi> |
| 1045 | _Tp hmax(const simd<_Tp, _Abi>&); |
| 1046 | template <class _MaskType, class _SimdType> |
| 1047 | typename _SimdType::value_type |
| 1048 | hmax(const const_where_expression<_MaskType, _SimdType>&); |
| 1049 | |
| 1050 | // algorithms [simd.alg] |
| 1051 | template <class _Tp, class _Abi> |
| 1052 | simd<_Tp, _Abi> min(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; |
| 1053 | |
| 1054 | template <class _Tp, class _Abi> |
| 1055 | simd<_Tp, _Abi> max(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; |
| 1056 | |
| 1057 | template <class _Tp, class _Abi> |
| 1058 | std::pair<simd<_Tp, _Abi>, simd<_Tp, _Abi>> |
| 1059 | minmax(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; |
| 1060 | |
| 1061 | template <class _Tp, class _Abi> |
| 1062 | simd<_Tp, _Abi> clamp(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&, |
| 1063 | const simd<_Tp, _Abi>&); |
| 1064 | |
| 1065 | // [simd.whereexpr] |
| 1066 | // TODO implement where expressions. |
| 1067 | template <class _MaskType, class _Tp> |
| 1068 | class const_where_expression { |
| 1069 | public: |
| 1070 | const_where_expression(const const_where_expression&) = delete; |
| 1071 | const_where_expression& operator=(const const_where_expression&) = delete; |
| 1072 | typename remove_const<_Tp>::type operator-() const&&; |
| 1073 | template <class _Up, class _Flags> |
| 1074 | void copy_to(_Up*, _Flags) const&&; |
| 1075 | }; |
| 1076 | |
| 1077 | template <class _MaskType, class _Tp> |
| 1078 | class where_expression : public const_where_expression<_MaskType, _Tp> { |
| 1079 | public: |
| 1080 | where_expression(const where_expression&) = delete; |
| 1081 | where_expression& operator=(const where_expression&) = delete; |
| 1082 | template <class _Up> |
| 1083 | void operator=(_Up&&); |
| 1084 | template <class _Up> |
| 1085 | void operator+=(_Up&&); |
| 1086 | template <class _Up> |
| 1087 | void operator-=(_Up&&); |
| 1088 | template <class _Up> |
| 1089 | void operator*=(_Up&&); |
| 1090 | template <class _Up> |
| 1091 | void operator/=(_Up&&); |
| 1092 | template <class _Up> |
| 1093 | void operator%=(_Up&&); |
| 1094 | template <class _Up> |
| 1095 | void operator&=(_Up&&); |
| 1096 | template <class _Up> |
| 1097 | void operator|=(_Up&&); |
| 1098 | template <class _Up> |
| 1099 | void operator^=(_Up&&); |
| 1100 | template <class _Up> |
| 1101 | void operator<<=(_Up&&); |
| 1102 | template <class _Up> |
| 1103 | void operator>>=(_Up&&); |
| 1104 | void operator++(); |
| 1105 | void operator++(int); |
| 1106 | void operator--(); |
| 1107 | void operator--(int); |
| 1108 | template <class _Up, class _Flags> |
| 1109 | void copy_from(const _Up*, _Flags); |
| 1110 | }; |
| 1111 | |
| 1112 | // [simd.class] |
| 1113 | // TODO: implement simd |
| 1114 | template <class _Tp, class _Abi> |
| 1115 | class simd { |
| 1116 | private: |
| 1117 | template <class _Up> |
| 1118 | static constexpr bool __can_broadcast() { |
| 1119 | return (std::is_arithmetic<_Up>::value && |
| 1120 | __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()) || |
| 1121 | (!std::is_arithmetic<_Up>::value && |
| 1122 | std::is_convertible<_Up, _Tp>::value) || |
| 1123 | std::is_same<typename std::remove_const<_Up>::type, int>::value || |
| 1124 | (std::is_same<typename std::remove_const<_Up>::type, |
| 1125 | unsigned int>::value && |
| 1126 | std::is_unsigned<_Tp>::value); |
| 1127 | } |
| 1128 | |
| 1129 | public: |
| 1130 | using value_type = _Tp; |
| 1131 | // TODO: this is strawman implementation. Turn it into a proxy type. |
| 1132 | using reference = _Tp&; |
| 1133 | using mask_type = simd_mask<_Tp, _Abi>; |
| 1134 | |
| 1135 | using abi_type = _Abi; |
| 1136 | |
| 1137 | static constexpr size_t size() noexcept { |
| 1138 | return simd_size<_Tp, _Abi>::value; |
| 1139 | } |
| 1140 | |
| 1141 | simd() = default; |
| 1142 | |
| 1143 | // implicit type conversion constructor |
| 1144 | template <class _Up, |
| 1145 | class = typename std::enable_if< |
| 1146 | std::is_same<_Abi, simd_abi::fixed_size<size()>>::value && |
| 1147 | __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()>::type> |
| 1148 | simd(const simd<_Up, simd_abi::fixed_size<size()>>&) {} |
| 1149 | |
| 1150 | // implicit broadcast constructor |
| 1151 | template <class _Up, |
| 1152 | class = typename std::enable_if<__can_broadcast<_Up>()>::type> |
| 1153 | simd(_Up&&); |
| 1154 | |
| 1155 | // generator constructor |
| 1156 | // TODO: for now only check for the index 0. This is because C++11 doesn't |
| 1157 | // have index_sequence, and it's hard to check for all indicies without using |
| 1158 | // index_sequence. |
| 1159 | template <class _Generator, |
| 1160 | int = decltype(simd(std::declval<_Generator>()( |
| 1161 | std::integral_constant<size_t, 0>())), |
| 1162 | int())()> |
| 1163 | explicit simd(_Generator&&); |
| 1164 | |
| 1165 | // load constructor |
| 1166 | template <class _Up, class _Flags> |
| 1167 | simd(const _Up*, _Flags); |
| 1168 | |
| 1169 | // loads [simd.load] |
| 1170 | template <class _Up, class _Flags> |
| 1171 | void copy_from(const _Up*, _Flags); |
| 1172 | |
| 1173 | // stores [simd.store] |
| 1174 | template <class _Up, class _Flags> |
| 1175 | void copy_to(_Up*, _Flags) const; |
| 1176 | |
| 1177 | // scalar access [simd.subscr] |
| 1178 | reference operator[](size_t); |
| 1179 | value_type operator[](size_t) const; |
| 1180 | |
| 1181 | // unary operators [simd.unary] |
| 1182 | simd& operator++(); |
| 1183 | simd operator++(int); |
| 1184 | simd& operator--(); |
| 1185 | simd operator--(int); |
| 1186 | mask_type operator!() const; |
| 1187 | simd operator~() const; |
| 1188 | simd operator+() const; |
| 1189 | simd operator-() const; |
| 1190 | |
| 1191 | // binary operators [simd.binary] |
| 1192 | friend simd operator+(const simd&, const simd&); |
| 1193 | friend simd operator-(const simd&, const simd&); |
| 1194 | friend simd operator*(const simd&, const simd&); |
| 1195 | friend simd operator/(const simd&, const simd&); |
| 1196 | friend simd operator%(const simd&, const simd&); |
| 1197 | friend simd operator&(const simd&, const simd&); |
| 1198 | friend simd operator|(const simd&, const simd&); |
| 1199 | friend simd operator^(const simd&, const simd&); |
| 1200 | friend simd operator<<(const simd&, const simd&); |
| 1201 | friend simd operator>>(const simd&, const simd&); |
| 1202 | friend simd operator<<(const simd&, int); |
| 1203 | friend simd operator>>(const simd&, int); |
| 1204 | |
| 1205 | // compound assignment [simd.cassign] |
| 1206 | friend simd& operator+=(simd&, const simd&); |
| 1207 | friend simd& operator-=(simd&, const simd&); |
| 1208 | friend simd& operator*=(simd&, const simd&); |
| 1209 | friend simd& operator/=(simd&, const simd&); |
| 1210 | friend simd& operator%=(simd&, const simd&); |
| 1211 | |
| 1212 | friend simd& operator&=(simd&, const simd&); |
| 1213 | friend simd& operator|=(simd&, const simd&); |
| 1214 | friend simd& operator^=(simd&, const simd&); |
| 1215 | friend simd& operator<<=(simd&, const simd&); |
| 1216 | friend simd& operator>>=(simd&, const simd&); |
| 1217 | friend simd& operator<<=(simd&, int); |
| 1218 | friend simd& operator>>=(simd&, int); |
| 1219 | |
| 1220 | // compares [simd.comparison] |
| 1221 | friend mask_type operator==(const simd&, const simd&); |
| 1222 | friend mask_type operator!=(const simd&, const simd&); |
| 1223 | friend mask_type operator>=(const simd&, const simd&); |
| 1224 | friend mask_type operator<=(const simd&, const simd&); |
| 1225 | friend mask_type operator>(const simd&, const simd&); |
| 1226 | friend mask_type operator<(const simd&, const simd&); |
| 1227 | }; |
| 1228 | |
| 1229 | // [simd.mask.class] |
| 1230 | template <class _Tp, class _Abi> |
| 1231 | // TODO: implement simd_mask |
| 1232 | class simd_mask { |
| 1233 | public: |
| 1234 | using value_type = bool; |
| 1235 | // TODO: this is strawman implementation. Turn it into a proxy type. |
| 1236 | using reference = bool&; |
| 1237 | using simd_type = simd<_Tp, _Abi>; |
| 1238 | using abi_type = _Abi; |
| 1239 | static constexpr size_t size() noexcept; |
| 1240 | simd_mask() = default; |
| 1241 | |
| 1242 | // broadcast constructor |
| 1243 | explicit simd_mask(value_type) noexcept; |
| 1244 | |
| 1245 | // implicit type conversion constructor |
| 1246 | template <class _Up> |
| 1247 | simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>&) noexcept; |
| 1248 | |
| 1249 | // load constructor |
| 1250 | template <class _Flags> |
| 1251 | simd_mask(const value_type*, _Flags); |
| 1252 | |
| 1253 | // loads [simd.mask.copy] |
| 1254 | template <class _Flags> |
| 1255 | void copy_from(const value_type*, _Flags); |
| 1256 | template <class _Flags> |
| 1257 | void copy_to(value_type*, _Flags) const; |
| 1258 | |
| 1259 | // scalar access [simd.mask.subscr] |
| 1260 | reference operator[](size_t); |
| 1261 | value_type operator[](size_t) const; |
| 1262 | |
| 1263 | // unary operators [simd.mask.unary] |
| 1264 | simd_mask operator!() const noexcept; |
| 1265 | |
| 1266 | // simd_mask binary operators [simd.mask.binary] |
| 1267 | friend simd_mask operator&&(const simd_mask&, const simd_mask&) noexcept; |
| 1268 | friend simd_mask operator||(const simd_mask&, const simd_mask&) noexcept; |
| 1269 | friend simd_mask operator&(const simd_mask&, const simd_mask&)noexcept; |
| 1270 | friend simd_mask operator|(const simd_mask&, const simd_mask&) noexcept; |
| 1271 | friend simd_mask operator^(const simd_mask&, const simd_mask&) noexcept; |
| 1272 | |
| 1273 | // simd_mask compound assignment [simd.mask.cassign] |
| 1274 | friend simd_mask& operator&=(simd_mask&, const simd_mask&) noexcept; |
| 1275 | friend simd_mask& operator|=(simd_mask&, const simd_mask&) noexcept; |
| 1276 | friend simd_mask& operator^=(simd_mask&, const simd_mask&) noexcept; |
| 1277 | |
| 1278 | // simd_mask compares [simd.mask.comparison] |
| 1279 | friend simd_mask operator==(const simd_mask&, const simd_mask&) noexcept; |
| 1280 | friend simd_mask operator!=(const simd_mask&, const simd_mask&) noexcept; |
| 1281 | }; |
| 1282 | |
| 1283 | _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD |
| 1284 | |
| 1285 | #endif /* _LIBCPP_EXPERIMENTAL_SIMD */ |