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 16namespace std::experimental { 17 18inline namespace parallelism_v2 { 19 20namespace simd_abi { 21 22struct scalar {}; 23template <int N> struct fixed_size {}; 24template <typename T> inline constexpr int max_fixed_size = implementation-defined; 25template <typename T> using compatible = implementation-defined; 26template <typename T> using native = implementation-defined; 27 28} // simd_abi 29 30struct element_aligned_tag {}; 31struct vector_aligned_tag {}; 32template <size_t> struct overaligned_tag {}; 33inline constexpr element_aligned_tag element_aligned{}; 34inline constexpr vector_aligned_tag vector_aligned{}; 35template <size_t N> inline constexpr overaligned_tag<N> overaligned{}; 36 37// traits [simd.traits] 38template <class T> struct is_abi_tag; 39template <class T> inline constexpr bool is_abi_tag_v = is_abi_tag<T>::value; 40 41template <class T> struct is_simd; 42template <class T> inline constexpr bool is_simd_v = is_simd<T>::value; 43 44template <class T> struct is_simd_mask; 45template <class T> inline constexpr bool is_simd_mask_v = is_simd_mask<T>::value; 46 47template <class T> struct is_simd_flag_type; 48template <class T> inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<T>::value; 49 50template <class T, size_t N> struct abi_for_size { using type = see below; }; 51template <class T, size_t N> using abi_for_size_t = typename abi_for_size<T, N>::type; 52 53template <class T, class Abi = simd_abi::compatible<T>> struct simd_size; 54template <class T, class Abi = simd_abi::compatible<T>> 55inline constexpr size_t simd_size_v = simd_size<T, Abi>::value; 56 57template <class T, class U = typename T::value_type> struct memory_alignment; 58template <class T, class U = typename T::value_type> 59inline constexpr size_t memory_alignment_v = memory_alignment<T, U>::value; 60 61// class template simd [simd.class] 62template <class T, class Abi = simd_abi::compatible<T>> class simd; 63template <class T> using native_simd = simd<T, simd_abi::native<T>>; 64template <class T, int N> using fixed_size_simd = simd<T, simd_abi::fixed_size<N>>; 65 66// class template simd_mask [simd.mask.class] 67template <class T, class Abi = simd_abi::compatible<T>> class simd_mask; 68template <class T> using native_simd_mask = simd_mask<T, simd_abi::native<T>>; 69template <class T, int N> using fixed_size_simd_mask = simd_mask<T, simd_abi::fixed_size<N>>; 70 71// casts [simd.casts] 72template <class T, class U, class Abi> see below simd_cast(const simd<U, Abi>&); 73template <class T, class U, class Abi> see below static_simd_cast(const simd<U, Abi>&); 74 75template <class T, class Abi> 76fixed_size_simd<T, simd_size_v<T, Abi>> to_fixed_size(const simd<T, Abi>&) noexcept; 77template <class T, class Abi> 78fixed_size_simd_mask<T, simd_size_v<T, Abi>> to_fixed_size(const simd_mask<T, Abi>&) noexcept; 79template <class T, size_t N> native_simd<T> to_native(const fixed_size_simd<T, N>&) noexcept; 80template <class T, size_t N> 81native_simd_mask<T> to_native(const fixed_size_simd_mask<T, N>> &) noexcept; 82template <class T, size_t N> simd<T> to_compatible(const fixed_size_simd<T, N>&) noexcept; 83template <class T, size_t N> simd_mask<T> to_compatible(const fixed_size_simd_mask<T, N>&) noexcept; 84 85template <size_t... Sizes, class T, class Abi> 86tuple<simd<T, abi_for_size_t<Sizes>>...> split(const simd<T, Abi>&); 87template <size_t... Sizes, class T, class Abi> 88tuple<simd_mask<T, abi_for_size_t<Sizes>>...> split(const simd_mask<T, Abi>&); 89template <class V, class Abi> 90array<V, simd_size_v<typename V::value_type, Abi> / V::size()> split( 91const simd<typename V::value_type, Abi>&); 92template <class V, class Abi> 93array<V, simd_size_v<typename V::value_type, Abi> / V::size()> split( 94const simd_mask<typename V::value_type, Abi>&); 95 96template <class T, class... Abis> 97simd<T, abi_for_size_t<T, (simd_size_v<T, Abis> + ...)>> concat(const simd<T, Abis>&...); 98template <class T, class... Abis> 99simd_mask<T, abi_for_size_t<T, (simd_size_v<T, Abis> + ...)>> concat(const simd_mask<T, Abis>&...); 100 101// reductions [simd.mask.reductions] 102template <class T, class Abi> bool all_of(const simd_mask<T, Abi>&) noexcept; 103template <class T, class Abi> bool any_of(const simd_mask<T, Abi>&) noexcept; 104template <class T, class Abi> bool none_of(const simd_mask<T, Abi>&) noexcept; 105template <class T, class Abi> bool some_of(const simd_mask<T, Abi>&) noexcept; 106template <class T, class Abi> int popcount(const simd_mask<T, Abi>&) noexcept; 107template <class T, class Abi> int find_first_set(const simd_mask<T, Abi>&); 108template <class T, class Abi> int find_last_set(const simd_mask<T, Abi>&); 109 110bool all_of(see below) noexcept; 111bool any_of(see below) noexcept; 112bool none_of(see below) noexcept; 113bool some_of(see below) noexcept; 114int popcount(see below) noexcept; 115int find_first_set(see below) noexcept; 116int find_last_set(see below) noexcept; 117 118// masked assignment [simd.whereexpr] 119template <class M, class T> class const_where_expression; 120template <class M, class T> class where_expression; 121 122// masked assignment [simd.mask.where] 123template <class T> struct nodeduce { using type = T; }; // exposition only 124 125template <class T> using nodeduce_t = typename nodeduce<T>::type; // exposition only 126 127template <class T, class Abi> 128where_expression<simd_mask<T, Abi>, simd<T, Abi>> 129where(const typename simd<T, Abi>::mask_type&, simd<T, Abi>&) noexcept; 130 131template <class T, class Abi> 132const_where_expression<simd_mask<T, Abi>, const simd<T, Abi>> 133where(const typename simd<T, Abi>::mask_type&, const simd<T, Abi>&) noexcept; 134 135template <class T, class Abi> 136where_expression<simd_mask<T, Abi>, simd_mask<T, Abi>> 137where(const nodeduce_t<simd_mask<T, Abi>>&, simd_mask<T, Abi>&) noexcept; 138 139template <class T, class Abi> 140const_where_expression<simd_mask<T, Abi>, const simd_mask<T, Abi>> 141where(const nodeduce_t<simd_mask<T, Abi>>&, const simd_mask<T, Abi>&) noexcept; 142 143template <class T> where_expression<bool, T> where(see below k, T& d) noexcept; 144 145template <class T> 146const_where_expression<bool, const T> where(see below k, const T& d) noexcept; 147 148// reductions [simd.reductions] 149template <class T, class Abi, class BinaryOperation = std::plus<>> 150T reduce(const simd<T, Abi>&, BinaryOperation = BinaryOperation()); 151 152template <class M, class V, class BinaryOperation> 153typename V::value_type reduce(const const_where_expression<M, V>& x, 154typename V::value_type neutral_element, BinaryOperation binary_op); 155 156template <class M, class V> 157typename V::value_type reduce(const const_where_expression<M, V>& x, plus<> binary_op = plus<>()); 158 159template <class M, class V> 160typename V::value_type reduce(const const_where_expression<M, V>& x, multiplies<> binary_op); 161 162template <class M, class V> 163typename V::value_type reduce(const const_where_expression<M, V>& x, bit_and<> binary_op); 164 165template <class M, class V> 166typename V::value_type reduce(const const_where_expression<M, V>& x, bit_or<> binary_op); 167 168template <class M, class V> 169typename V::value_type reduce(const const_where_expression<M, V>& x, bit_xor<> binary_op); 170 171template <class T, class Abi> T hmin(const simd<T, Abi>&); 172template <class M, class V> T hmin(const const_where_expression<M, V>&); 173template <class T, class Abi> T hmax(const simd<T, Abi>&); 174template <class M, class V> T hmax(const const_where_expression<M, V>&); 175 176// algorithms [simd.alg] 177template <class T, class Abi> simd<T, Abi> min(const simd<T, Abi>&, const simd<T, Abi>&) noexcept; 178 179template <class T, class Abi> simd<T, Abi> max(const simd<T, Abi>&, const simd<T, Abi>&) noexcept; 180 181template <class T, class Abi> 182std::pair<simd<T, Abi>, simd<T, Abi>> minmax(const simd<T, Abi>&, const simd<T, Abi>&) noexcept; 183 184template <class T, class Abi> 185simd<T, Abi> clamp(const simd<T, Abi>& v, const simd<T, Abi>& lo, const simd<T, Abi>& hi); 186 187// [simd.whereexpr] 188template <class M, class T> 189class const_where_expression { 190 const M& mask; // exposition only 191 T& data; // exposition only 192public: 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 199template <class M, class T> 200class where_expression : public const_where_expression<M, T> { 201public: 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] 223template <class T, class Abi> class simd { 224public: 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] 304template <class Abi> using scharv = simd<signed char, Abi>; // exposition only 305template <class Abi> using shortv = simd<short, Abi>; // exposition only 306template <class Abi> using intv = simd<int, Abi>; // exposition only 307template <class Abi> using longv = simd<long int, Abi>; // exposition only 308template <class Abi> using llongv = simd<long long int, Abi>; // exposition only 309template <class Abi> using floatv = simd<float, Abi>; // exposition only 310template <class Abi> using doublev = simd<double, Abi>; // exposition only 311template <class Abi> using ldoublev = simd<long double, Abi>; // exposition only 312template <class T, class V> using samesize = fixed_size_simd<T, V::size()>; // exposition only 313 314template <class Abi> floatv<Abi> acos(floatv<Abi> x); 315template <class Abi> doublev<Abi> acos(doublev<Abi> x); 316template <class Abi> ldoublev<Abi> acos(ldoublev<Abi> x); 317 318template <class Abi> floatv<Abi> asin(floatv<Abi> x); 319template <class Abi> doublev<Abi> asin(doublev<Abi> x); 320template <class Abi> ldoublev<Abi> asin(ldoublev<Abi> x); 321 322template <class Abi> floatv<Abi> atan(floatv<Abi> x); 323template <class Abi> doublev<Abi> atan(doublev<Abi> x); 324template <class Abi> ldoublev<Abi> atan(ldoublev<Abi> x); 325 326template <class Abi> floatv<Abi> atan2(floatv<Abi> y, floatv<Abi> x); 327template <class Abi> doublev<Abi> atan2(doublev<Abi> y, doublev<Abi> x); 328template <class Abi> ldoublev<Abi> atan2(ldoublev<Abi> y, ldoublev<Abi> x); 329 330template <class Abi> floatv<Abi> cos(floatv<Abi> x); 331template <class Abi> doublev<Abi> cos(doublev<Abi> x); 332template <class Abi> ldoublev<Abi> cos(ldoublev<Abi> x); 333 334template <class Abi> floatv<Abi> sin(floatv<Abi> x); 335template <class Abi> doublev<Abi> sin(doublev<Abi> x); 336template <class Abi> ldoublev<Abi> sin(ldoublev<Abi> x); 337 338template <class Abi> floatv<Abi> tan(floatv<Abi> x); 339template <class Abi> doublev<Abi> tan(doublev<Abi> x); 340template <class Abi> ldoublev<Abi> tan(ldoublev<Abi> x); 341 342template <class Abi> floatv<Abi> acosh(floatv<Abi> x); 343template <class Abi> doublev<Abi> acosh(doublev<Abi> x); 344template <class Abi> ldoublev<Abi> acosh(ldoublev<Abi> x); 345 346template <class Abi> floatv<Abi> asinh(floatv<Abi> x); 347template <class Abi> doublev<Abi> asinh(doublev<Abi> x); 348template <class Abi> ldoublev<Abi> asinh(ldoublev<Abi> x); 349 350template <class Abi> floatv<Abi> atanh(floatv<Abi> x); 351template <class Abi> doublev<Abi> atanh(doublev<Abi> x); 352template <class Abi> ldoublev<Abi> atanh(ldoublev<Abi> x); 353 354template <class Abi> floatv<Abi> cosh(floatv<Abi> x); 355template <class Abi> doublev<Abi> cosh(doublev<Abi> x); 356template <class Abi> ldoublev<Abi> cosh(ldoublev<Abi> x); 357 358template <class Abi> floatv<Abi> sinh(floatv<Abi> x); 359template <class Abi> doublev<Abi> sinh(doublev<Abi> x); 360template <class Abi> ldoublev<Abi> sinh(ldoublev<Abi> x); 361 362template <class Abi> floatv<Abi> tanh(floatv<Abi> x); 363template <class Abi> doublev<Abi> tanh(doublev<Abi> x); 364template <class Abi> ldoublev<Abi> tanh(ldoublev<Abi> x); 365 366template <class Abi> floatv<Abi> exp(floatv<Abi> x); 367template <class Abi> doublev<Abi> exp(doublev<Abi> x); 368template <class Abi> ldoublev<Abi> exp(ldoublev<Abi> x); 369 370template <class Abi> floatv<Abi> exp2(floatv<Abi> x); 371template <class Abi> doublev<Abi> exp2(doublev<Abi> x); 372template <class Abi> ldoublev<Abi> exp2(ldoublev<Abi> x); 373 374template <class Abi> floatv<Abi> expm1(floatv<Abi> x); 375template <class Abi> doublev<Abi> expm1(doublev<Abi> x); 376template <class Abi> ldoublev<Abi> expm1(ldoublev<Abi> x); 377 378template <class Abi> floatv<Abi> frexp(floatv<Abi> value, samesize<int, floatv<Abi>>* exp); 379template <class Abi> doublev<Abi> frexp(doublev<Abi> value, samesize<int, doublev<Abi>>* exp); 380template <class Abi> ldoublev<Abi> frexp(ldoublev<Abi> value, samesize<int, ldoublev<Abi>>* exp); 381 382template <class Abi> samesize<int, floatv<Abi>> ilogb(floatv<Abi> x); 383template <class Abi> samesize<int, doublev<Abi>> ilogb(doublev<Abi> x); 384template <class Abi> samesize<int, ldoublev<Abi>> ilogb(ldoublev<Abi> x); 385 386template <class Abi> floatv<Abi> ldexp(floatv<Abi> x, samesize<int, floatv<Abi>> exp); 387template <class Abi> doublev<Abi> ldexp(doublev<Abi> x, samesize<int, doublev<Abi>> exp); 388template <class Abi> ldoublev<Abi> ldexp(ldoublev<Abi> x, samesize<int, ldoublev<Abi>> exp); 389 390template <class Abi> floatv<Abi> log(floatv<Abi> x); 391template <class Abi> doublev<Abi> log(doublev<Abi> x); 392template <class Abi> ldoublev<Abi> log(ldoublev<Abi> x); 393 394template <class Abi> floatv<Abi> log10(floatv<Abi> x); 395template <class Abi> doublev<Abi> log10(doublev<Abi> x); 396template <class Abi> ldoublev<Abi> log10(ldoublev<Abi> x); 397 398template <class Abi> floatv<Abi> log1p(floatv<Abi> x); 399template <class Abi> doublev<Abi> log1p(doublev<Abi> x); 400template <class Abi> ldoublev<Abi> log1p(ldoublev<Abi> x); 401 402template <class Abi> floatv<Abi> log2(floatv<Abi> x); 403template <class Abi> doublev<Abi> log2(doublev<Abi> x); 404template <class Abi> ldoublev<Abi> log2(ldoublev<Abi> x); 405 406template <class Abi> floatv<Abi> logb(floatv<Abi> x); 407template <class Abi> doublev<Abi> logb(doublev<Abi> x); 408template <class Abi> ldoublev<Abi> logb(ldoublev<Abi> x); 409 410template <class Abi> floatv<Abi> modf(floatv<Abi> value, floatv<Abi>* iptr); 411template <class Abi> doublev<Abi> modf(doublev<Abi> value, doublev<Abi>* iptr); 412template <class Abi> ldoublev<Abi> modf(ldoublev<Abi> value, ldoublev<Abi>* iptr); 413 414template <class Abi> floatv<Abi> scalbn(floatv<Abi> x, samesize<int, floatv<Abi>> n); 415template <class Abi> doublev<Abi> scalbn(doublev<Abi> x, samesize<int, doublev<Abi>> n); 416template <class Abi> ldoublev<Abi> scalbn(ldoublev<Abi> x, samesize<int, ldoublev<Abi>> n); 417template <class Abi> floatv<Abi> scalbln(floatv<Abi> x, samesize<long int, floatv<Abi>> n); 418template <class Abi> doublev<Abi> scalbln(doublev<Abi> x, samesize<long int, doublev<Abi>> n); 419template <class Abi> ldoublev<Abi> scalbln(ldoublev<Abi> x, samesize<long int, ldoublev<Abi>> n); 420 421template <class Abi> floatv<Abi> cbrt(floatv<Abi> x); 422template <class Abi> doublev<Abi> cbrt(doublev<Abi> x); 423template <class Abi> ldoublev<Abi> cbrt(ldoublev<Abi> x); 424 425template <class Abi> scharv<Abi> abs(scharv<Abi> j); 426template <class Abi> shortv<Abi> abs(shortv<Abi> j); 427template <class Abi> intv<Abi> abs(intv<Abi> j); 428template <class Abi> longv<Abi> abs(longv<Abi> j); 429template <class Abi> llongv<Abi> abs(llongv<Abi> j); 430template <class Abi> floatv<Abi> abs(floatv<Abi> j); 431template <class Abi> doublev<Abi> abs(doublev<Abi> j); 432template <class Abi> ldoublev<Abi> abs(ldoublev<Abi> j); 433 434template <class Abi> floatv<Abi> hypot(floatv<Abi> x, floatv<Abi> y); 435template <class Abi> doublev<Abi> hypot(doublev<Abi> x, doublev<Abi> y); 436template <class Abi> ldoublev<Abi> hypot(doublev<Abi> x, doublev<Abi> y); 437template <class Abi> floatv<Abi> hypot(floatv<Abi> x, floatv<Abi> y, floatv<Abi> z); 438template <class Abi> doublev<Abi> hypot(doublev<Abi> x, doublev<Abi> y, doublev<Abi> z); 439template <class Abi> ldoublev<Abi> hypot(ldoublev<Abi> x, ldoublev<Abi> y, ldoublev<Abi> z); 440 441template <class Abi> floatv<Abi> pow(floatv<Abi> x, floatv<Abi> y); 442template <class Abi> doublev<Abi> pow(doublev<Abi> x, doublev<Abi> y); 443template <class Abi> ldoublev<Abi> pow(ldoublev<Abi> x, ldoublev<Abi> y); 444 445template <class Abi> floatv<Abi> sqrt(floatv<Abi> x); 446template <class Abi> doublev<Abi> sqrt(doublev<Abi> x); 447template <class Abi> ldoublev<Abi> sqrt(ldoublev<Abi> x); 448 449template <class Abi> floatv<Abi> erf(floatv<Abi> x); 450template <class Abi> doublev<Abi> erf(doublev<Abi> x); 451template <class Abi> ldoublev<Abi> erf(ldoublev<Abi> x); 452template <class Abi> floatv<Abi> erfc(floatv<Abi> x); 453template <class Abi> doublev<Abi> erfc(doublev<Abi> x); 454template <class Abi> ldoublev<Abi> erfc(ldoublev<Abi> x); 455 456template <class Abi> floatv<Abi> lgamma(floatv<Abi> x); 457template <class Abi> doublev<Abi> lgamma(doublev<Abi> x); 458template <class Abi> ldoublev<Abi> lgamma(ldoublev<Abi> x); 459 460template <class Abi> floatv<Abi> tgamma(floatv<Abi> x); 461template <class Abi> doublev<Abi> tgamma(doublev<Abi> x); 462template <class Abi> ldoublev<Abi> tgamma(ldoublev<Abi> x); 463 464template <class Abi> floatv<Abi> ceil(floatv<Abi> x); 465template <class Abi> doublev<Abi> ceil(doublev<Abi> x); 466template <class Abi> ldoublev<Abi> ceil(ldoublev<Abi> x); 467 468template <class Abi> floatv<Abi> floor(floatv<Abi> x); 469template <class Abi> doublev<Abi> floor(doublev<Abi> x); 470template <class Abi> ldoublev<Abi> floor(ldoublev<Abi> x); 471 472template <class Abi> floatv<Abi> nearbyint(floatv<Abi> x); 473template <class Abi> doublev<Abi> nearbyint(doublev<Abi> x); 474template <class Abi> ldoublev<Abi> nearbyint(ldoublev<Abi> x); 475 476template <class Abi> floatv<Abi> rint(floatv<Abi> x); 477template <class Abi> doublev<Abi> rint(doublev<Abi> x); 478template <class Abi> ldoublev<Abi> rint(ldoublev<Abi> x); 479 480template <class Abi> samesize<long int, floatv<Abi>> lrint(floatv<Abi> x); 481template <class Abi> samesize<long int, doublev<Abi>> lrint(doublev<Abi> x); 482template <class Abi> samesize<long int, ldoublev<Abi>> lrint(ldoublev<Abi> x); 483template <class Abi> samesize<long long int, floatv<Abi>> llrint(floatv<Abi> x); 484template <class Abi> samesize<long long int, doublev<Abi>> llrint(doublev<Abi> x); 485template <class Abi> samesize<long long int, ldoublev<Abi>> llrint(ldoublev<Abi> x); 486 487template <class Abi> floatv<Abi> round(floatv<Abi> x); 488template <class Abi> doublev<Abi> round(doublev<Abi> x); 489template <class Abi> ldoublev<Abi> round(ldoublev<Abi> x); 490template <class Abi> samesize<long int, floatv<Abi>> lround(floatv<Abi> x); 491template <class Abi> samesize<long int, doublev<Abi>> lround(doublev<Abi> x); 492template <class Abi> samesize<long int, ldoublev<Abi>> lround(ldoublev<Abi> x); 493template <class Abi> samesize<long long int, floatv<Abi>> llround(floatv<Abi> x); 494template <class Abi> samesize<long long int, doublev<Abi>> llround(doublev<Abi> x); 495template <class Abi> samesize<long long int, ldoublev<Abi>> llround(ldoublev<Abi> x); 496 497template <class Abi> floatv<Abi> trunc(floatv<Abi> x); 498template <class Abi> doublev<Abi> trunc(doublev<Abi> x); 499template <class Abi> ldoublev<Abi> trunc(ldoublev<Abi> x); 500 501template <class Abi> floatv<Abi> fmod(floatv<Abi> x, floatv<Abi> y); 502template <class Abi> doublev<Abi> fmod(doublev<Abi> x, doublev<Abi> y); 503template <class Abi> ldoublev<Abi> fmod(ldoublev<Abi> x, ldoublev<Abi> y); 504 505template <class Abi> floatv<Abi> remainder(floatv<Abi> x, floatv<Abi> y); 506template <class Abi> doublev<Abi> remainder(doublev<Abi> x, doublev<Abi> y); 507template <class Abi> ldoublev<Abi> remainder(ldoublev<Abi> x, ldoublev<Abi> y); 508 509template <class Abi> floatv<Abi> remquo(floatv<Abi> x, floatv<Abi> y, samesize<int, floatv<Abi>>* quo); 510template <class Abi> doublev<Abi> remquo(doublev<Abi> x, doublev<Abi> y, samesize<int, doublev<Abi>>* quo); 511template <class Abi> ldoublev<Abi> remquo(ldoublev<Abi> x, ldoublev<Abi> y, samesize<int, ldoublev<Abi>>* quo); 512 513template <class Abi> floatv<Abi> copysign(floatv<Abi> x, floatv<Abi> y); 514template <class Abi> doublev<Abi> copysign(doublev<Abi> x, doublev<Abi> y); 515template <class Abi> ldoublev<Abi> copysign(ldoublev<Abi> x, ldoublev<Abi> y); 516 517template <class Abi> doublev<Abi> nan(const char* tagp); 518template <class Abi> floatv<Abi> nanf(const char* tagp); 519template <class Abi> ldoublev<Abi> nanl(const char* tagp); 520 521template <class Abi> floatv<Abi> nextafter(floatv<Abi> x, floatv<Abi> y); 522template <class Abi> doublev<Abi> nextafter(doublev<Abi> x, doublev<Abi> y); 523template <class Abi> ldoublev<Abi> nextafter(ldoublev<Abi> x, ldoublev<Abi> y); 524 525template <class Abi> floatv<Abi> nexttoward(floatv<Abi> x, ldoublev<Abi> y); 526template <class Abi> doublev<Abi> nexttoward(doublev<Abi> x, ldoublev<Abi> y); 527template <class Abi> ldoublev<Abi> nexttoward(ldoublev<Abi> x, ldoublev<Abi> y); 528 529template <class Abi> floatv<Abi> fdim(floatv<Abi> x, floatv<Abi> y); 530template <class Abi> doublev<Abi> fdim(doublev<Abi> x, doublev<Abi> y); 531template <class Abi> ldoublev<Abi> fdim(ldoublev<Abi> x, ldoublev<Abi> y); 532 533template <class Abi> floatv<Abi> fmax(floatv<Abi> x, floatv<Abi> y); 534template <class Abi> doublev<Abi> fmax(doublev<Abi> x, doublev<Abi> y); 535template <class Abi> ldoublev<Abi> fmax(ldoublev<Abi> x, ldoublev<Abi> y); 536 537template <class Abi> floatv<Abi> fmin(floatv<Abi> x, floatv<Abi> y); 538template <class Abi> doublev<Abi> fmin(doublev<Abi> x, doublev<Abi> y); 539template <class Abi> ldoublev<Abi> fmin(ldoublev<Abi> x, ldoublev<Abi> y); 540 541template <class Abi> floatv<Abi> fma(floatv<Abi> x, floatv<Abi> y, floatv<Abi> z); 542template <class Abi> doublev<Abi> fma(doublev<Abi> x, doublev<Abi> y, doublev<Abi> z); 543template <class Abi> ldoublev<Abi> fma(ldoublev<Abi> x, ldoublev<Abi> y, ldoublev<Abi> z); 544 545template <class Abi> samesize<int, floatv<Abi>> fpclassify(floatv<Abi> x); 546template <class Abi> samesize<int, doublev<Abi>> fpclassify(doublev<Abi> x); 547template <class Abi> samesize<int, ldoublev<Abi>> fpclassify(ldoublev<Abi> x); 548 549template <class Abi> simd_mask<float, Abi> isfinite(floatv<Abi> x); 550template <class Abi> simd_mask<double, Abi> isfinite(doublev<Abi> x); 551template <class Abi> simd_mask<long double, Abi> isfinite(ldoublev<Abi> x); 552 553template <class Abi> simd_mask<float, Abi> isinf(floatv<Abi> x); 554template <class Abi> simd_mask<double, Abi> isinf(doublev<Abi> x); 555template <class Abi> simd_mask<long double, Abi> isinf(ldoublev<Abi> x); 556 557template <class Abi> simd_mask<float, Abi> isnan(floatv<Abi> x); 558template <class Abi> simd_mask<double, Abi> isnan(doublev<Abi> x); 559template <class Abi> simd_mask<long double, Abi> isnan(ldoublev<Abi> x); 560 561template <class Abi> simd_mask<float, Abi> isnormal(floatv<Abi> x); 562template <class Abi> simd_mask<double, Abi> isnormal(doublev<Abi> x); 563template <class Abi> simd_mask<long double, Abi> isnormal(ldoublev<Abi> x); 564 565template <class Abi> simd_mask<float, Abi> signbit(floatv<Abi> x); 566template <class Abi> simd_mask<double, Abi> signbit(doublev<Abi> x); 567template <class Abi> simd_mask<long double, Abi> signbit(ldoublev<Abi> x); 568 569template <class Abi> simd_mask<float, Abi> isgreater(floatv<Abi> x, floatv<Abi> y); 570template <class Abi> simd_mask<double, Abi> isgreater(doublev<Abi> x, doublev<Abi> y); 571template <class Abi> simd_mask<long double, Abi> isgreater(ldoublev<Abi> x, ldoublev<Abi> y); 572 573template <class Abi> simd_mask<float, Abi> isgreaterequal(floatv<Abi> x, floatv<Abi> y); 574template <class Abi> simd_mask<double, Abi> isgreaterequal(doublev<Abi> x, doublev<Abi> y); 575template <class Abi> simd_mask<long double, Abi> isgreaterequal(ldoublev<Abi> x, ldoublev<Abi> y); 576 577template <class Abi> simd_mask<float, Abi> isless(floatv<Abi> x, floatv<Abi> y); 578template <class Abi> simd_mask<double, Abi> isless(doublev<Abi> x, doublev<Abi> y); 579template <class Abi> simd_mask<long double, Abi> isless(ldoublev<Abi> x, ldoublev<Abi> y); 580 581template <class Abi> simd_mask<float, Abi> islessequal(floatv<Abi> x, floatv<Abi> y); 582template <class Abi> simd_mask<double, Abi> islessequal(doublev<Abi> x, doublev<Abi> y); 583template <class Abi> simd_mask<long double, Abi> islessequal(ldoublev<Abi> x, ldoublev<Abi> y); 584 585template <class Abi> simd_mask<float, Abi> islessgreater(floatv<Abi> x, floatv<Abi> y); 586template <class Abi> simd_mask<double, Abi> islessgreater(doublev<Abi> x, doublev<Abi> y); 587template <class Abi> simd_mask<long double, Abi> islessgreater(ldoublev<Abi> x, ldoublev<Abi> y); 588 589template <class Abi> simd_mask<float, Abi> isunordered(floatv<Abi> x, floatv<Abi> y); 590template <class Abi> simd_mask<double, Abi> isunordered(doublev<Abi> x, doublev<Abi> y); 591template <class Abi> simd_mask<long double, Abi> isunordered(ldoublev<Abi> x, ldoublev<Abi> y); 592 593template <class V> struct simd_div_t { V quot, rem; }; 594template <class Abi> simd_div_t<scharv<Abi>> div(scharv<Abi> numer, scharv<Abi> denom); 595template <class Abi> simd_div_t<shortv<Abi>> div(shortv<Abi> numer, shortv<Abi> denom); 596template <class Abi> simd_div_t<intv<Abi>> div(intv<Abi> numer, intv<Abi> denom); 597template <class Abi> simd_div_t<longv<Abi>> div(longv<Abi> numer, longv<Abi> denom); 598template <class Abi> simd_div_t<llongv<Abi>> div(llongv<Abi> numer, llongv<Abi> denom); 599 600// [simd.mask.class] 601template <class T, class Abi> 602class simd_mask { 603public: 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 <algorithm> 655#include <array> 656#include <cstddef> 657#include <functional> 658 659#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 660#pragma GCC system_header 661#endif 662 663_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD 664 665enum class _StorageKind { 666 _Scalar, 667 _Array, 668 _VecExt, 669}; 670 671template <_StorageKind __kind, int _Np> 672struct __simd_abi {}; 673 674template <class _Tp, class _Abi> 675class __simd_storage {}; 676 677template <class _Tp, int __num_element> 678class __simd_storage<_Tp, __simd_abi<_StorageKind::_Array, __num_element>> { 679 std::array<_Tp, __num_element> __storage_; 680 681 template <class, class> 682 friend struct simd; 683 684 template <class, class> 685 friend struct simd_mask; 686 687public: 688 _Tp __get(size_t __index) const noexcept { return __storage_[__index]; }; 689 void __set(size_t __index, _Tp __val) noexcept { 690 __storage_[__index] = __val; 691 } 692}; 693 694template <class _Tp> 695class __simd_storage<_Tp, __simd_abi<_StorageKind::_Scalar, 1>> { 696 _Tp __storage_; 697 698 template <class, class> 699 friend struct simd; 700 701 template <class, class> 702 friend struct simd_mask; 703 704public: 705 _Tp __get(size_t __index) const noexcept { return (&__storage_)[__index]; }; 706 void __set(size_t __index, _Tp __val) noexcept { 707 (&__storage_)[__index] = __val; 708 } 709}; 710 711#ifndef _LIBCPP_HAS_NO_VECTOR_EXTENSION 712 713constexpr size_t __floor_pow_of_2(size_t __val) { 714 return ((__val - 1) & __val) == 0 ? __val 715 : __floor_pow_of_2((__val - 1) & __val); 716} 717 718constexpr size_t __ceil_pow_of_2(size_t __val) { 719 return __val == 1 ? 1 : __floor_pow_of_2(__val - 1) << 1; 720} 721 722template <class _Tp, size_t __bytes> 723struct __vec_ext_traits { 724#if !defined(_LIBCPP_COMPILER_CLANG) 725 typedef _Tp type __attribute__((vector_size(__ceil_pow_of_2(__bytes)))); 726#endif 727}; 728 729#if defined(_LIBCPP_COMPILER_CLANG) 730#define _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, _NUM_ELEMENT) \ 731 template <> \ 732 struct __vec_ext_traits<_TYPE, sizeof(_TYPE) * _NUM_ELEMENT> { \ 733 using type = \ 734 _TYPE __attribute__((vector_size(sizeof(_TYPE) * _NUM_ELEMENT))); \ 735 } 736 737#define _LIBCPP_SPECIALIZE_VEC_EXT_32(_TYPE) \ 738 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 1); \ 739 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 2); \ 740 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 3); \ 741 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 4); \ 742 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 5); \ 743 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 6); \ 744 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 7); \ 745 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 8); \ 746 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 9); \ 747 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 10); \ 748 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 11); \ 749 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 12); \ 750 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 13); \ 751 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 14); \ 752 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 15); \ 753 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 16); \ 754 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 17); \ 755 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 18); \ 756 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 19); \ 757 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 20); \ 758 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 21); \ 759 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 22); \ 760 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 23); \ 761 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 24); \ 762 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 25); \ 763 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 26); \ 764 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 27); \ 765 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 28); \ 766 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 29); \ 767 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 30); \ 768 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 31); \ 769 _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 32); 770 771_LIBCPP_SPECIALIZE_VEC_EXT_32(char); 772_LIBCPP_SPECIALIZE_VEC_EXT_32(char16_t); 773_LIBCPP_SPECIALIZE_VEC_EXT_32(char32_t); 774_LIBCPP_SPECIALIZE_VEC_EXT_32(wchar_t); 775_LIBCPP_SPECIALIZE_VEC_EXT_32(signed char); 776_LIBCPP_SPECIALIZE_VEC_EXT_32(signed short); 777_LIBCPP_SPECIALIZE_VEC_EXT_32(signed int); 778_LIBCPP_SPECIALIZE_VEC_EXT_32(signed long); 779_LIBCPP_SPECIALIZE_VEC_EXT_32(signed long long); 780_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned char); 781_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned short); 782_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned int); 783_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned long); 784_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned long long); 785_LIBCPP_SPECIALIZE_VEC_EXT_32(float); 786_LIBCPP_SPECIALIZE_VEC_EXT_32(double); 787_LIBCPP_SPECIALIZE_VEC_EXT_32(long double); 788 789#undef _LIBCPP_SPECIALIZE_VEC_EXT_32 790#undef _LIBCPP_SPECIALIZE_VEC_EXT 791#endif 792 793template <class _Tp, int __num_element> 794class __simd_storage<_Tp, __simd_abi<_StorageKind::_VecExt, __num_element>> { 795 using _StorageType = 796 typename __vec_ext_traits<_Tp, sizeof(_Tp) * __num_element>::type; 797 798 _StorageType __storage_; 799 800 template <class, class> 801 friend struct simd; 802 803 template <class, class> 804 friend struct simd_mask; 805 806public: 807 _Tp __get(size_t __index) const noexcept { return __storage_[__index]; }; 808 void __set(size_t __index, _Tp __val) noexcept { 809 __storage_[__index] = __val; 810 } 811}; 812 813#endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION 814 815template <class _Vp, class _Tp, class _Abi> 816class __simd_reference { 817 static_assert(std::is_same<_Vp, _Tp>::value, ""); 818 819 template <class, class> 820 friend struct simd; 821 822 template <class, class> 823 friend struct simd_mask; 824 825 __simd_storage<_Tp, _Abi>* __ptr_; 826 size_t __index_; 827 828 __simd_reference(__simd_storage<_Tp, _Abi>* __ptr, size_t __index) 829 : __ptr_(__ptr), __index_(__index) {} 830 831 __simd_reference(const __simd_reference&) = default; 832 833public: 834 __simd_reference() = delete; 835 __simd_reference& operator=(const __simd_reference&) = delete; 836 837 operator _Vp() const { return __ptr_->__get(__index_); } 838 839 __simd_reference operator=(_Vp __value) && { 840 __ptr_->__set(__index_, __value); 841 return *this; 842 } 843 844 __simd_reference operator++() && { 845 return std::move(*this) = __ptr_->__get(__index_) + 1; 846 } 847 848 _Vp operator++(int) && { 849 auto __val = __ptr_->__get(__index_); 850 __ptr_->__set(__index_, __val + 1); 851 return __val; 852 } 853 854 __simd_reference operator--() && { 855 return std::move(*this) = __ptr_->__get(__index_) - 1; 856 } 857 858 _Vp operator--(int) && { 859 auto __val = __ptr_->__get(__index_); 860 __ptr_->__set(__index_, __val - 1); 861 return __val; 862 } 863 864 __simd_reference operator+=(_Vp __value) && { 865 return std::move(*this) = __ptr_->__get(__index_) + __value; 866 } 867 868 __simd_reference operator-=(_Vp __value) && { 869 return std::move(*this) = __ptr_->__get(__index_) - __value; 870 } 871 872 __simd_reference operator*=(_Vp __value) && { 873 return std::move(*this) = __ptr_->__get(__index_) * __value; 874 } 875 876 __simd_reference operator/=(_Vp __value) && { 877 return std::move(*this) = __ptr_->__get(__index_) / __value; 878 } 879 880 __simd_reference operator%=(_Vp __value) && { 881 return std::move(*this) = __ptr_->__get(__index_) % __value; 882 } 883 884 __simd_reference operator>>=(_Vp __value) && { 885 return std::move(*this) = __ptr_->__get(__index_) >> __value; 886 } 887 888 __simd_reference operator<<=(_Vp __value) && { 889 return std::move(*this) = __ptr_->__get(__index_) << __value; 890 } 891 892 __simd_reference operator&=(_Vp __value) && { 893 return std::move(*this) = __ptr_->__get(__index_) & __value; 894 } 895 896 __simd_reference operator|=(_Vp __value) && { 897 return std::move(*this) = __ptr_->__get(__index_) | __value; 898 } 899 900 __simd_reference operator^=(_Vp __value) && { 901 return std::move(*this) = __ptr_->__get(__index_) ^ __value; 902 } 903}; 904 905template <class _To, class _From> 906constexpr decltype(_To{std::declval<_From>()}, true) 907__is_non_narrowing_convertible_impl(_From) { 908 return true; 909} 910 911template <class _To> 912constexpr bool __is_non_narrowing_convertible_impl(...) { 913 return false; 914} 915 916template <class _From, class _To> 917constexpr typename std::enable_if<std::is_arithmetic<_To>::value && 918 std::is_arithmetic<_From>::value, 919 bool>::type 920__is_non_narrowing_arithmetic_convertible() { 921 return __is_non_narrowing_convertible_impl<_To>(_From{}); 922} 923 924template <class _From, class _To> 925constexpr typename std::enable_if<!(std::is_arithmetic<_To>::value && 926 std::is_arithmetic<_From>::value), 927 bool>::type 928__is_non_narrowing_arithmetic_convertible() { 929 return false; 930} 931 932template <class _Tp> 933constexpr _Tp __variadic_sum() { 934 return _Tp{}; 935} 936 937template <class _Tp, class _Up, class... _Args> 938constexpr _Tp __variadic_sum(_Up __first, _Args... __rest) { 939 return static_cast<_Tp>(__first) + __variadic_sum<_Tp>(__rest...); 940} 941 942template <class _Tp> 943struct __nodeduce { 944 using type = _Tp; 945}; 946 947template <class _Tp> 948constexpr bool __vectorizable() { 949 return std::is_arithmetic<_Tp>::value && !std::is_const<_Tp>::value && 950 !std::is_volatile<_Tp>::value && !std::is_same<_Tp, bool>::value; 951} 952 953_LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD 954_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD_ABI 955 956using scalar = __simd_abi<_StorageKind::_Scalar, 1>; 957 958template <int _Np> 959using fixed_size = __simd_abi<_StorageKind::_Array, _Np>; 960 961template <class _Tp> 962_LIBCPP_INLINE_VAR constexpr size_t max_fixed_size = 32; 963 964template <class _Tp> 965using compatible = fixed_size<16 / sizeof(_Tp)>; 966 967#ifndef _LIBCPP_HAS_NO_VECTOR_EXTENSION 968template <class _Tp> 969using native = __simd_abi<_StorageKind::_VecExt, 970 _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)>; 971#else 972template <class _Tp> 973using native = 974 fixed_size<_Tp, _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)>; 975#endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION 976 977_LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD_ABI 978_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD 979 980template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> 981class simd; 982template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> 983class simd_mask; 984 985struct element_aligned_tag {}; 986struct vector_aligned_tag {}; 987template <size_t> 988struct overaligned_tag {}; 989_LIBCPP_INLINE_VAR constexpr element_aligned_tag element_aligned{}; 990_LIBCPP_INLINE_VAR constexpr vector_aligned_tag vector_aligned{}; 991template <size_t _Np> 992_LIBCPP_INLINE_VAR constexpr overaligned_tag<_Np> overaligned{}; 993 994// traits [simd.traits] 995template <class _Tp> 996struct is_abi_tag : std::integral_constant<bool, false> {}; 997 998template <_StorageKind __kind, int _Np> 999struct is_abi_tag<__simd_abi<__kind, _Np>> 1000 : std::integral_constant<bool, true> {}; 1001 1002template <class _Tp> 1003struct is_simd : std::integral_constant<bool, false> {}; 1004 1005template <class _Tp, class _Abi> 1006struct is_simd<simd<_Tp, _Abi>> : std::integral_constant<bool, true> {}; 1007 1008template <class _Tp> 1009struct is_simd_mask : std::integral_constant<bool, false> {}; 1010 1011template <class _Tp, class _Abi> 1012struct is_simd_mask<simd_mask<_Tp, _Abi>> : std::integral_constant<bool, true> { 1013}; 1014 1015template <class _Tp> 1016struct is_simd_flag_type : std::integral_constant<bool, false> {}; 1017 1018template <> 1019struct is_simd_flag_type<element_aligned_tag> 1020 : std::integral_constant<bool, true> {}; 1021 1022template <> 1023struct is_simd_flag_type<vector_aligned_tag> 1024 : std::integral_constant<bool, true> {}; 1025 1026template <size_t _Align> 1027struct is_simd_flag_type<overaligned_tag<_Align>> 1028 : std::integral_constant<bool, true> {}; 1029 1030template <class _Tp> 1031_LIBCPP_INLINE_VAR constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value; 1032template <class _Tp> 1033_LIBCPP_INLINE_VAR constexpr bool is_simd_v = is_simd<_Tp>::value; 1034template <class _Tp> 1035_LIBCPP_INLINE_VAR constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value; 1036template <class _Tp> 1037_LIBCPP_INLINE_VAR constexpr bool is_simd_flag_type_v = 1038 is_simd_flag_type<_Tp>::value; 1039template <class _Tp, size_t _Np> 1040struct abi_for_size { 1041 using type = simd_abi::fixed_size<_Np>; 1042}; 1043template <class _Tp, size_t _Np> 1044using abi_for_size_t = typename abi_for_size<_Tp, _Np>::type; 1045 1046template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> 1047struct simd_size; 1048 1049template <class _Tp, _StorageKind __kind, int _Np> 1050struct simd_size<_Tp, __simd_abi<__kind, _Np>> 1051 : std::integral_constant<size_t, _Np> { 1052 static_assert( 1053 std::is_arithmetic<_Tp>::value && 1054 !std::is_same<typename std::remove_const<_Tp>::type, bool>::value, 1055 "Element type should be vectorizable"); 1056}; 1057 1058// TODO: implement it. 1059template <class _Tp, class _Up = typename _Tp::value_type> 1060struct memory_alignment; 1061 1062template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> 1063_LIBCPP_INLINE_VAR constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value; 1064 1065template <class _Tp, class _Up = typename _Tp::value_type> 1066_LIBCPP_INLINE_VAR constexpr size_t memory_alignment_v = 1067 memory_alignment<_Tp, _Up>::value; 1068 1069// class template simd [simd.class] 1070template <class _Tp> 1071using native_simd = simd<_Tp, simd_abi::native<_Tp>>; 1072template <class _Tp, int _Np> 1073using fixed_size_simd = simd<_Tp, simd_abi::fixed_size<_Np>>; 1074 1075// class template simd_mask [simd.mask.class] 1076template <class _Tp> 1077using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>; 1078 1079template <class _Tp, int _Np> 1080using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>; 1081 1082// casts [simd.casts] 1083template <class _Tp> 1084struct __static_simd_cast_traits { 1085 template <class _Up, class _Abi> 1086 static simd<_Tp, _Abi> __apply(const simd<_Up, _Abi>& __v); 1087}; 1088 1089template <class _Tp, class _NewAbi> 1090struct __static_simd_cast_traits<simd<_Tp, _NewAbi>> { 1091 template <class _Up, class _Abi> 1092 static typename std::enable_if<simd<_Up, _Abi>::size() == 1093 simd<_Tp, _NewAbi>::size(), 1094 simd<_Tp, _NewAbi>>::type 1095 __apply(const simd<_Up, _Abi>& __v); 1096}; 1097 1098template <class _Tp> 1099struct __simd_cast_traits { 1100 template <class _Up, class _Abi> 1101 static typename std::enable_if< 1102 __is_non_narrowing_arithmetic_convertible<_Up, _Tp>(), 1103 simd<_Tp, _Abi>>::type 1104 __apply(const simd<_Up, _Abi>& __v); 1105}; 1106 1107template <class _Tp, class _NewAbi> 1108struct __simd_cast_traits<simd<_Tp, _NewAbi>> { 1109 template <class _Up, class _Abi> 1110 static typename std::enable_if< 1111 __is_non_narrowing_arithmetic_convertible<_Up, _Tp>() && 1112 simd<_Up, _Abi>::size() == simd<_Tp, _NewAbi>::size(), 1113 simd<_Tp, _NewAbi>>::type 1114 __apply(const simd<_Up, _Abi>& __v); 1115}; 1116 1117template <class _Tp, class _Up, class _Abi> 1118auto simd_cast(const simd<_Up, _Abi>& __v) 1119 -> decltype(__simd_cast_traits<_Tp>::__apply(__v)) { 1120 return __simd_cast_traits<_Tp>::__apply(__v); 1121} 1122 1123template <class _Tp, class _Up, class _Abi> 1124auto static_simd_cast(const simd<_Up, _Abi>& __v) 1125 -> decltype(__static_simd_cast_traits<_Tp>::__apply(__v)) { 1126 return __static_simd_cast_traits<_Tp>::__apply(__v); 1127} 1128 1129template <class _Tp, class _Abi> 1130fixed_size_simd<_Tp, simd_size<_Tp, _Abi>::value> 1131to_fixed_size(const simd<_Tp, _Abi>&) noexcept; 1132 1133template <class _Tp, class _Abi> 1134fixed_size_simd_mask<_Tp, simd_size<_Tp, _Abi>::value> 1135to_fixed_size(const simd_mask<_Tp, _Abi>&) noexcept; 1136 1137template <class _Tp, size_t _Np> 1138native_simd<_Tp> to_native(const fixed_size_simd<_Tp, _Np>&) noexcept; 1139 1140template <class _Tp, size_t _Np> 1141native_simd_mask<_Tp> to_native(const fixed_size_simd_mask<_Tp, _Np>&) noexcept; 1142 1143template <class _Tp, size_t _Np> 1144simd<_Tp> to_compatible(const fixed_size_simd<_Tp, _Np>&) noexcept; 1145 1146template <class _Tp, size_t _Np> 1147simd_mask<_Tp> to_compatible(const fixed_size_simd_mask<_Tp, _Np>&) noexcept; 1148 1149template <size_t... __sizes, class _Tp, class _Abi> 1150tuple<simd<_Tp, abi_for_size_t<_Tp, __sizes>>...> split(const simd<_Tp, _Abi>&); 1151 1152template <size_t... __sizes, class _Tp, class _Abi> 1153tuple<simd_mask<_Tp, abi_for_size_t<_Tp, __sizes>>...> 1154split(const simd_mask<_Tp, _Abi>&); 1155 1156template <class _SimdType, class _Abi> 1157array<_SimdType, simd_size<typename _SimdType::value_type, _Abi>::value / 1158 _SimdType::size()> 1159split(const simd<typename _SimdType::value_type, _Abi>&); 1160 1161template <class _SimdType, class _Abi> 1162array<_SimdType, simd_size<typename _SimdType::value_type, _Abi>::value / 1163 _SimdType::size()> 1164split(const simd_mask<typename _SimdType::value_type, _Abi>&); 1165 1166template <class _Tp, class... _Abis> 1167simd<_Tp, abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>> 1168concat(const simd<_Tp, _Abis>&...); 1169 1170template <class _Tp, class... _Abis> 1171simd_mask<_Tp, 1172 abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>> 1173concat(const simd_mask<_Tp, _Abis>&...); 1174 1175// reductions [simd.mask.reductions] 1176template <class _Tp, class _Abi> 1177bool all_of(const simd_mask<_Tp, _Abi>&) noexcept; 1178template <class _Tp, class _Abi> 1179bool any_of(const simd_mask<_Tp, _Abi>&) noexcept; 1180template <class _Tp, class _Abi> 1181bool none_of(const simd_mask<_Tp, _Abi>&) noexcept; 1182template <class _Tp, class _Abi> 1183bool some_of(const simd_mask<_Tp, _Abi>&) noexcept; 1184template <class _Tp, class _Abi> 1185int popcount(const simd_mask<_Tp, _Abi>&) noexcept; 1186template <class _Tp, class _Abi> 1187int find_first_set(const simd_mask<_Tp, _Abi>&); 1188template <class _Tp, class _Abi> 1189int find_last_set(const simd_mask<_Tp, _Abi>&); 1190bool all_of(bool) noexcept; 1191bool any_of(bool) noexcept; 1192bool none_of(bool) noexcept; 1193bool some_of(bool) noexcept; 1194int popcount(bool) noexcept; 1195int find_first_set(bool) noexcept; 1196int find_last_set(bool) noexcept; 1197 1198// masked assignment [simd.whereexpr] 1199template <class _MaskType, class _Tp> 1200class const_where_expression; 1201template <class _MaskType, class _Tp> 1202class where_expression; 1203 1204// masked assignment [simd.mask.where] 1205template <class _Tp, class _Abi> 1206where_expression<simd_mask<_Tp, _Abi>, simd<_Tp, _Abi>> 1207where(const typename simd<_Tp, _Abi>::mask_type&, simd<_Tp, _Abi>&) noexcept; 1208 1209template <class _Tp, class _Abi> 1210const_where_expression<simd_mask<_Tp, _Abi>, const simd<_Tp, _Abi>> 1211where(const typename simd<_Tp, _Abi>::mask_type&, 1212 const simd<_Tp, _Abi>&) noexcept; 1213 1214template <class _Tp, class _Abi> 1215where_expression<simd_mask<_Tp, _Abi>, simd_mask<_Tp, _Abi>> 1216where(const typename __nodeduce<simd_mask<_Tp, _Abi>>::type&, 1217 simd_mask<_Tp, _Abi>&) noexcept; 1218 1219template <class _Tp, class _Abi> 1220const_where_expression<simd_mask<_Tp, _Abi>, const simd_mask<_Tp, _Abi>> 1221where(const typename __nodeduce<simd_mask<_Tp, _Abi>>::type&, 1222 const simd_mask<_Tp, _Abi>&) noexcept; 1223 1224template <class _Tp> 1225where_expression<bool, _Tp> where(bool, _Tp&) noexcept; 1226 1227template <class _Tp> 1228const_where_expression<bool, const _Tp> where(bool, const _Tp&) noexcept; 1229 1230// reductions [simd.reductions] 1231template <class _Tp, class _Abi, class _BinaryOp = std::plus<_Tp>> 1232_Tp reduce(const simd<_Tp, _Abi>&, _BinaryOp = _BinaryOp()); 1233 1234template <class _MaskType, class _SimdType, class _BinaryOp> 1235typename _SimdType::value_type 1236reduce(const const_where_expression<_MaskType, _SimdType>&, 1237 typename _SimdType::value_type neutral_element, _BinaryOp binary_op); 1238 1239template <class _MaskType, class _SimdType> 1240typename _SimdType::value_type 1241reduce(const const_where_expression<_MaskType, _SimdType>&, 1242 plus<typename _SimdType::value_type> binary_op = {}); 1243 1244template <class _MaskType, class _SimdType> 1245typename _SimdType::value_type 1246reduce(const const_where_expression<_MaskType, _SimdType>&, 1247 multiplies<typename _SimdType::value_type> binary_op); 1248 1249template <class _MaskType, class _SimdType> 1250typename _SimdType::value_type 1251reduce(const const_where_expression<_MaskType, _SimdType>&, 1252 bit_and<typename _SimdType::value_type> binary_op); 1253 1254template <class _MaskType, class _SimdType> 1255typename _SimdType::value_type 1256reduce(const const_where_expression<_MaskType, _SimdType>&, 1257 bit_or<typename _SimdType::value_type> binary_op); 1258 1259template <class _MaskType, class _SimdType> 1260typename _SimdType::value_type 1261reduce(const const_where_expression<_MaskType, _SimdType>&, 1262 bit_xor<typename _SimdType::value_type> binary_op); 1263 1264template <class _Tp, class _Abi> 1265_Tp hmin(const simd<_Tp, _Abi>&); 1266template <class _MaskType, class _SimdType> 1267typename _SimdType::value_type 1268hmin(const const_where_expression<_MaskType, _SimdType>&); 1269template <class _Tp, class _Abi> 1270_Tp hmax(const simd<_Tp, _Abi>&); 1271template <class _MaskType, class _SimdType> 1272typename _SimdType::value_type 1273hmax(const const_where_expression<_MaskType, _SimdType>&); 1274 1275// algorithms [simd.alg] 1276template <class _Tp, class _Abi> 1277simd<_Tp, _Abi> min(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; 1278 1279template <class _Tp, class _Abi> 1280simd<_Tp, _Abi> max(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; 1281 1282template <class _Tp, class _Abi> 1283std::pair<simd<_Tp, _Abi>, simd<_Tp, _Abi>> 1284minmax(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; 1285 1286template <class _Tp, class _Abi> 1287simd<_Tp, _Abi> clamp(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&, 1288 const simd<_Tp, _Abi>&); 1289 1290// [simd.whereexpr] 1291// TODO implement where expressions. 1292template <class _MaskType, class _Tp> 1293class const_where_expression { 1294public: 1295 const_where_expression(const const_where_expression&) = delete; 1296 const_where_expression& operator=(const const_where_expression&) = delete; 1297 typename remove_const<_Tp>::type operator-() const&&; 1298 template <class _Up, class _Flags> 1299 void copy_to(_Up*, _Flags) const&&; 1300}; 1301 1302template <class _MaskType, class _Tp> 1303class where_expression : public const_where_expression<_MaskType, _Tp> { 1304public: 1305 where_expression(const where_expression&) = delete; 1306 where_expression& operator=(const where_expression&) = delete; 1307 template <class _Up> 1308 void operator=(_Up&&); 1309 template <class _Up> 1310 void operator+=(_Up&&); 1311 template <class _Up> 1312 void operator-=(_Up&&); 1313 template <class _Up> 1314 void operator*=(_Up&&); 1315 template <class _Up> 1316 void operator/=(_Up&&); 1317 template <class _Up> 1318 void operator%=(_Up&&); 1319 template <class _Up> 1320 void operator&=(_Up&&); 1321 template <class _Up> 1322 void operator|=(_Up&&); 1323 template <class _Up> 1324 void operator^=(_Up&&); 1325 template <class _Up> 1326 void operator<<=(_Up&&); 1327 template <class _Up> 1328 void operator>>=(_Up&&); 1329 void operator++(); 1330 void operator++(int); 1331 void operator--(); 1332 void operator--(int); 1333 template <class _Up, class _Flags> 1334 void copy_from(const _Up*, _Flags); 1335}; 1336 1337// [simd.class] 1338// TODO: implement simd 1339template <class _Tp, class _Abi> 1340class simd { 1341public: 1342 using value_type = _Tp; 1343 using reference = __simd_reference<_Tp, _Tp, _Abi>; 1344 using mask_type = simd_mask<_Tp, _Abi>; 1345 using abi_type = _Abi; 1346 1347 simd() = default; 1348 simd(const simd&) = default; 1349 simd& operator=(const simd&) = default; 1350 1351 static constexpr size_t size() noexcept { 1352 return simd_size<_Tp, _Abi>::value; 1353 } 1354 1355private: 1356 __simd_storage<_Tp, _Abi> __s_; 1357 1358 template <class _Up> 1359 static constexpr bool __can_broadcast() { 1360 return (std::is_arithmetic<_Up>::value && 1361 __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()) || 1362 (!std::is_arithmetic<_Up>::value && 1363 std::is_convertible<_Up, _Tp>::value) || 1364 std::is_same<typename std::remove_const<_Up>::type, int>::value || 1365 (std::is_same<typename std::remove_const<_Up>::type, 1366 unsigned int>::value && 1367 std::is_unsigned<_Tp>::value); 1368 } 1369 1370 template <class _Generator, size_t... __indicies> 1371 static constexpr decltype( 1372 std::forward_as_tuple(std::declval<_Generator>()( 1373 std::integral_constant<size_t, __indicies>())...), 1374 bool()) 1375 __can_generate(std::index_sequence<__indicies...>) { 1376 return !__variadic_sum<bool>( 1377 !__can_broadcast<decltype(std::declval<_Generator>()( 1378 std::integral_constant<size_t, __indicies>()))>()...); 1379 } 1380 1381 template <class _Generator> 1382 static bool __can_generate(...) { 1383 return false; 1384 } 1385 1386 template <class _Generator, size_t... __indicies> 1387 void __generator_init(_Generator&& __g, std::index_sequence<__indicies...>) { 1388 int __not_used[]{((*this)[__indicies] = 1389 __g(std::integral_constant<size_t, __indicies>()), 1390 0)...}; 1391 (void)__not_used; 1392 } 1393 1394public: 1395 // implicit type conversion constructor 1396 template <class _Up, 1397 class = typename std::enable_if< 1398 std::is_same<_Abi, simd_abi::fixed_size<size()>>::value && 1399 __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()>::type> 1400 simd(const simd<_Up, simd_abi::fixed_size<size()>>& __v) { 1401 for (size_t __i = 0; __i < size(); __i++) { 1402 (*this)[__i] = static_cast<_Tp>(__v[__i]); 1403 } 1404 } 1405 1406 // implicit broadcast constructor 1407 template <class _Up, 1408 class = typename std::enable_if<__can_broadcast<_Up>()>::type> 1409 simd(_Up&& __rv) { 1410 auto __v = static_cast<_Tp>(__rv); 1411 for (size_t __i = 0; __i < size(); __i++) { 1412 (*this)[__i] = __v; 1413 } 1414 } 1415 1416 // generator constructor 1417 template <class _Generator, 1418 int = typename std::enable_if< 1419 __can_generate<_Generator>(std::make_index_sequence<size()>()), 1420 int>::type()> 1421 explicit simd(_Generator&& __g) { 1422 __generator_init(std::forward<_Generator>(__g), 1423 std::make_index_sequence<size()>()); 1424 } 1425 1426 // load constructor 1427 template < 1428 class _Up, class _Flags, 1429 class = typename std::enable_if<__vectorizable<_Up>()>::type, 1430 class = typename std::enable_if<is_simd_flag_type<_Flags>::value>::type> 1431 simd(const _Up* __buffer, _Flags) { 1432 // TODO: optimize for overaligned flags 1433 for (size_t __i = 0; __i < size(); __i++) { 1434 (*this)[__i] = static_cast<_Tp>(__buffer[__i]); 1435 } 1436 } 1437 1438 // loads [simd.load] 1439 template <class _Up, class _Flags> 1440 typename std::enable_if<__vectorizable<_Up>() && 1441 is_simd_flag_type<_Flags>::value>::type 1442 copy_from(const _Up* __buffer, _Flags) { 1443 *this = simd(__buffer, _Flags()); 1444 } 1445 1446 // stores [simd.store] 1447 template <class _Up, class _Flags> 1448 typename std::enable_if<__vectorizable<_Up>() && 1449 is_simd_flag_type<_Flags>::value>::type 1450 copy_to(_Up* __buffer, _Flags) const { 1451 // TODO: optimize for overaligned flags 1452 for (size_t __i = 0; __i < size(); __i++) { 1453 __buffer[__i] = static_cast<_Up>((*this)[__i]); 1454 } 1455 } 1456 1457 // scalar access [simd.subscr] 1458 reference operator[](size_t __i) { return reference(&__s_, __i); } 1459 1460 value_type operator[](size_t __i) const { return __s_.__get(__i); } 1461 1462 // unary operators [simd.unary] 1463 simd& operator++(); 1464 simd operator++(int); 1465 simd& operator--(); 1466 simd operator--(int); 1467 mask_type operator!() const; 1468 simd operator~() const; 1469 simd operator+() const; 1470 simd operator-() const; 1471 1472 // binary operators [simd.binary] 1473 friend simd operator+(const simd&, const simd&); 1474 friend simd operator-(const simd&, const simd&); 1475 friend simd operator*(const simd&, const simd&); 1476 friend simd operator/(const simd&, const simd&); 1477 friend simd operator%(const simd&, const simd&); 1478 friend simd operator&(const simd&, const simd&); 1479 friend simd operator|(const simd&, const simd&); 1480 friend simd operator^(const simd&, const simd&); 1481 friend simd operator<<(const simd&, const simd&); 1482 friend simd operator>>(const simd&, const simd&); 1483 friend simd operator<<(const simd&, int); 1484 friend simd operator>>(const simd&, int); 1485 1486 // compound assignment [simd.cassign] 1487 friend simd& operator+=(simd&, const simd&); 1488 friend simd& operator-=(simd&, const simd&); 1489 friend simd& operator*=(simd&, const simd&); 1490 friend simd& operator/=(simd&, const simd&); 1491 friend simd& operator%=(simd&, const simd&); 1492 1493 friend simd& operator&=(simd&, const simd&); 1494 friend simd& operator|=(simd&, const simd&); 1495 friend simd& operator^=(simd&, const simd&); 1496 friend simd& operator<<=(simd&, const simd&); 1497 friend simd& operator>>=(simd&, const simd&); 1498 friend simd& operator<<=(simd&, int); 1499 friend simd& operator>>=(simd&, int); 1500 1501 // compares [simd.comparison] 1502 friend mask_type operator==(const simd&, const simd&); 1503 friend mask_type operator!=(const simd&, const simd&); 1504 friend mask_type operator>=(const simd&, const simd&); 1505 friend mask_type operator<=(const simd&, const simd&); 1506 friend mask_type operator>(const simd&, const simd&); 1507 friend mask_type operator<(const simd&, const simd&); 1508}; 1509 1510// [simd.mask.class] 1511template <class _Tp, class _Abi> 1512// TODO: implement simd_mask 1513class simd_mask { 1514public: 1515 using value_type = bool; 1516 // TODO: this is strawman implementation. Turn it into a proxy type. 1517 using reference = bool&; 1518 using simd_type = simd<_Tp, _Abi>; 1519 using abi_type = _Abi; 1520 static constexpr size_t size() noexcept; 1521 simd_mask() = default; 1522 1523 // broadcast constructor 1524 explicit simd_mask(value_type) noexcept; 1525 1526 // implicit type conversion constructor 1527 template <class _Up> 1528 simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>&) noexcept; 1529 1530 // load constructor 1531 template <class _Flags> 1532 simd_mask(const value_type*, _Flags); 1533 1534 // loads [simd.mask.copy] 1535 template <class _Flags> 1536 void copy_from(const value_type*, _Flags); 1537 template <class _Flags> 1538 void copy_to(value_type*, _Flags) const; 1539 1540 // scalar access [simd.mask.subscr] 1541 reference operator[](size_t); 1542 value_type operator[](size_t) const; 1543 1544 // unary operators [simd.mask.unary] 1545 simd_mask operator!() const noexcept; 1546 1547 // simd_mask binary operators [simd.mask.binary] 1548 friend simd_mask operator&&(const simd_mask&, const simd_mask&) noexcept; 1549 friend simd_mask operator||(const simd_mask&, const simd_mask&) noexcept; 1550 friend simd_mask operator&(const simd_mask&, const simd_mask&)noexcept; 1551 friend simd_mask operator|(const simd_mask&, const simd_mask&) noexcept; 1552 friend simd_mask operator^(const simd_mask&, const simd_mask&) noexcept; 1553 1554 // simd_mask compound assignment [simd.mask.cassign] 1555 friend simd_mask& operator&=(simd_mask&, const simd_mask&) noexcept; 1556 friend simd_mask& operator|=(simd_mask&, const simd_mask&) noexcept; 1557 friend simd_mask& operator^=(simd_mask&, const simd_mask&) noexcept; 1558 1559 // simd_mask compares [simd.mask.comparison] 1560 friend simd_mask operator==(const simd_mask&, const simd_mask&) noexcept; 1561 friend simd_mask operator!=(const simd_mask&, const simd_mask&) noexcept; 1562}; 1563 1564_LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD 1565 1566#endif /* _LIBCPP_EXPERIMENTAL_SIMD */ 1567