// -*- C++ -*- //===------------------------------- simd ---------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_EXPERIMENTAL_SIMD #define _LIBCPP_EXPERIMENTAL_SIMD /* experimental/simd synopsis namespace std::experimental { inline namespace parallelism_v2 { namespace simd_abi { struct scalar {}; template struct fixed_size {}; template inline constexpr int max_fixed_size = implementation-defined; template using compatible = implementation-defined; template using native = implementation-defined; } // simd_abi struct element_aligned_tag {}; struct vector_aligned_tag {}; template struct overaligned_tag {}; inline constexpr element_aligned_tag element_aligned{}; inline constexpr vector_aligned_tag vector_aligned{}; template inline constexpr overaligned_tag overaligned{}; // traits [simd.traits] template struct is_abi_tag; template inline constexpr bool is_abi_tag_v = is_abi_tag::value; template struct is_simd; template inline constexpr bool is_simd_v = is_simd::value; template struct is_simd_mask; template inline constexpr bool is_simd_mask_v = is_simd_mask::value; template struct is_simd_flag_type; template inline constexpr bool is_simd_flag_type_v = is_simd_flag_type::value; template struct abi_for_size { using type = see below; }; template using abi_for_size_t = typename abi_for_size::type; template > struct simd_size; template > inline constexpr size_t simd_size_v = simd_size::value; template struct memory_alignment; template inline constexpr size_t memory_alignment_v = memory_alignment::value; // class template simd [simd.class] template > class simd; template using native_simd = simd>; template using fixed_size_simd = simd>; // class template simd_mask [simd.mask.class] template > class simd_mask; template using native_simd_mask = simd_mask>; template using fixed_size_simd_mask = simd_mask>; // casts [simd.casts] template see below simd_cast(const simd&); template see below static_simd_cast(const simd&); template fixed_size_simd> to_fixed_size(const simd&) noexcept; template fixed_size_simd_mask> to_fixed_size(const simd_mask&) noexcept; template native_simd to_native(const fixed_size_simd&) noexcept; template native_simd_mask to_native(const fixed_size_simd_mask> &) noexcept; template simd to_compatible(const fixed_size_simd&) noexcept; template simd_mask to_compatible(const fixed_size_simd_mask&) noexcept; template tuple>...> split(const simd&); template tuple>...> split(const simd_mask&); template array / V::size()> split( const simd&); template array / V::size()> split( const simd_mask&); template simd + ...)>> concat(const simd&...); template simd_mask + ...)>> concat(const simd_mask&...); // reductions [simd.mask.reductions] template bool all_of(const simd_mask&) noexcept; template bool any_of(const simd_mask&) noexcept; template bool none_of(const simd_mask&) noexcept; template bool some_of(const simd_mask&) noexcept; template int popcount(const simd_mask&) noexcept; template int find_first_set(const simd_mask&); template int find_last_set(const simd_mask&); bool all_of(see below) noexcept; bool any_of(see below) noexcept; bool none_of(see below) noexcept; bool some_of(see below) noexcept; int popcount(see below) noexcept; int find_first_set(see below) noexcept; int find_last_set(see below) noexcept; // masked assignment [simd.whereexpr] template class const_where_expression; template class where_expression; // masked assignment [simd.mask.where] template struct nodeduce { using type = T; }; // exposition only template using nodeduce_t = typename nodeduce::type; // exposition only template where_expression, simd> where(const typename simd::mask_type&, simd&) noexcept; template const_where_expression, const simd> where(const typename simd::mask_type&, const simd&) noexcept; template where_expression, simd_mask> where(const nodeduce_t>&, simd_mask&) noexcept; template const_where_expression, const simd_mask> where(const nodeduce_t>&, const simd_mask&) noexcept; template where_expression where(see below k, T& d) noexcept; template const_where_expression where(see below k, const T& d) noexcept; // reductions [simd.reductions] template > T reduce(const simd&, BinaryOperation = BinaryOperation()); template typename V::value_type reduce(const const_where_expression& x, typename V::value_type neutral_element, BinaryOperation binary_op); template typename V::value_type reduce(const const_where_expression& x, plus<> binary_op = plus<>()); template typename V::value_type reduce(const const_where_expression& x, multiplies<> binary_op); template typename V::value_type reduce(const const_where_expression& x, bit_and<> binary_op); template typename V::value_type reduce(const const_where_expression& x, bit_or<> binary_op); template typename V::value_type reduce(const const_where_expression& x, bit_xor<> binary_op); template T hmin(const simd&); template T hmin(const const_where_expression&); template T hmax(const simd&); template T hmax(const const_where_expression&); // algorithms [simd.alg] template simd min(const simd&, const simd&) noexcept; template simd max(const simd&, const simd&) noexcept; template std::pair, simd> minmax(const simd&, const simd&) noexcept; template simd clamp(const simd& v, const simd& lo, const simd& hi); // [simd.whereexpr] template class const_where_expression { const M& mask; // exposition only T& data; // exposition only public: const_where_expression(const const_where_expression&) = delete; const_where_expression& operator=(const const_where_expression&) = delete; remove_const_t operator-() const &&; template void copy_to(U* mem, Flags f) const &&; }; template class where_expression : public const_where_expression { public: where_expression(const where_expression&) = delete; where_expression& operator=(const where_expression&) = delete; template void operator=(U&& x); template void operator+=(U&& x); template void operator-=(U&& x); template void operator*=(U&& x); template void operator/=(U&& x); template void operator%=(U&& x); template void operator&=(U&& x); template void operator|=(U&& x); template void operator^=(U&& x); template void operator<<=(U&& x); template void operator>>=(U&& x); void operator++(); void operator++(int); void operator--(); void operator--(int); template void copy_from(const U* mem, Flags); }; // [simd.class] template class simd { public: using value_type = T; using reference = see below; using mask_type = simd_mask; using abi_type = Abi; static constexpr size_t size() noexcept; simd() = default; // implicit type conversion constructor template simd(const simd>&); // implicit broadcast constructor (see below for constraints) template simd(U&& value); // generator constructor (see below for constraints) template explicit simd(G&& gen); // load constructor template simd(const U* mem, Flags f); // loads [simd.load] template void copy_from(const U* mem, Flags f); // stores [simd.store] template void copy_to(U* mem, Flags f) const; // scalar access [simd.subscr] reference operator[](size_t); value_type operator[](size_t) const; // unary operators [simd.unary] simd& operator++(); simd operator++(int); simd& operator--(); simd operator--(int); mask_type operator!() const; simd operator~() const; // see below simd operator+() const; simd operator-() const; // binary operators [simd.binary] friend simd operator+ (const simd&, const simd&); friend simd operator- (const simd&, const simd&); friend simd operator* (const simd&, const simd&); friend simd operator/ (const simd&, const simd&); friend simd operator% (const simd&, const simd&); friend simd operator& (const simd&, const simd&); friend simd operator| (const simd&, const simd&); friend simd operator^ (const simd&, const simd&); friend simd operator<<(const simd&, const simd&); friend simd operator>>(const simd&, const simd&); friend simd operator<<(const simd&, int); friend simd operator>>(const simd&, int); // compound assignment [simd.cassign] friend simd& operator+= (simd&, const simd&); friend simd& operator-= (simd&, const simd&); friend simd& operator*= (simd&, const simd&); friend simd& operator/= (simd&, const simd&); friend simd& operator%= (simd&, const simd&); friend simd& operator&= (simd&, const simd&); friend simd& operator|= (simd&, const simd&); friend simd& operator^= (simd&, const simd&); friend simd& operator<<=(simd&, const simd&); friend simd& operator>>=(simd&, const simd&); friend simd& operator<<=(simd&, int); friend simd& operator>>=(simd&, int); // compares [simd.comparison] friend mask_type operator==(const simd&, const simd&); friend mask_type operator!=(const simd&, const simd&); friend mask_type operator>=(const simd&, const simd&); friend mask_type operator<=(const simd&, const simd&); friend mask_type operator> (const simd&, const simd&); friend mask_type operator< (const simd&, const simd&); }; // [simd.math] template using scharv = simd; // exposition only template using shortv = simd; // exposition only template using intv = simd; // exposition only template using longv = simd; // exposition only template using llongv = simd; // exposition only template using floatv = simd; // exposition only template using doublev = simd; // exposition only template using ldoublev = simd; // exposition only template using samesize = fixed_size_simd; // exposition only template floatv acos(floatv x); template doublev acos(doublev x); template ldoublev acos(ldoublev x); template floatv asin(floatv x); template doublev asin(doublev x); template ldoublev asin(ldoublev x); template floatv atan(floatv x); template doublev atan(doublev x); template ldoublev atan(ldoublev x); template floatv atan2(floatv y, floatv x); template doublev atan2(doublev y, doublev x); template ldoublev atan2(ldoublev y, ldoublev x); template floatv cos(floatv x); template doublev cos(doublev x); template ldoublev cos(ldoublev x); template floatv sin(floatv x); template doublev sin(doublev x); template ldoublev sin(ldoublev x); template floatv tan(floatv x); template doublev tan(doublev x); template ldoublev tan(ldoublev x); template floatv acosh(floatv x); template doublev acosh(doublev x); template ldoublev acosh(ldoublev x); template floatv asinh(floatv x); template doublev asinh(doublev x); template ldoublev asinh(ldoublev x); template floatv atanh(floatv x); template doublev atanh(doublev x); template ldoublev atanh(ldoublev x); template floatv cosh(floatv x); template doublev cosh(doublev x); template ldoublev cosh(ldoublev x); template floatv sinh(floatv x); template doublev sinh(doublev x); template ldoublev sinh(ldoublev x); template floatv tanh(floatv x); template doublev tanh(doublev x); template ldoublev tanh(ldoublev x); template floatv exp(floatv x); template doublev exp(doublev x); template ldoublev exp(ldoublev x); template floatv exp2(floatv x); template doublev exp2(doublev x); template ldoublev exp2(ldoublev x); template floatv expm1(floatv x); template doublev expm1(doublev x); template ldoublev expm1(ldoublev x); template floatv frexp(floatv value, samesize>* exp); template doublev frexp(doublev value, samesize>* exp); template ldoublev frexp(ldoublev value, samesize>* exp); template samesize> ilogb(floatv x); template samesize> ilogb(doublev x); template samesize> ilogb(ldoublev x); template floatv ldexp(floatv x, samesize> exp); template doublev ldexp(doublev x, samesize> exp); template ldoublev ldexp(ldoublev x, samesize> exp); template floatv log(floatv x); template doublev log(doublev x); template ldoublev log(ldoublev x); template floatv log10(floatv x); template doublev log10(doublev x); template ldoublev log10(ldoublev x); template floatv log1p(floatv x); template doublev log1p(doublev x); template ldoublev log1p(ldoublev x); template floatv log2(floatv x); template doublev log2(doublev x); template ldoublev log2(ldoublev x); template floatv logb(floatv x); template doublev logb(doublev x); template ldoublev logb(ldoublev x); template floatv modf(floatv value, floatv* iptr); template doublev modf(doublev value, doublev* iptr); template ldoublev modf(ldoublev value, ldoublev* iptr); template floatv scalbn(floatv x, samesize> n); template doublev scalbn(doublev x, samesize> n); template ldoublev scalbn(ldoublev x, samesize> n); template floatv scalbln(floatv x, samesize> n); template doublev scalbln(doublev x, samesize> n); template ldoublev scalbln(ldoublev x, samesize> n); template floatv cbrt(floatv x); template doublev cbrt(doublev x); template ldoublev cbrt(ldoublev x); template scharv abs(scharv j); template shortv abs(shortv j); template intv abs(intv j); template longv abs(longv j); template llongv abs(llongv j); template floatv abs(floatv j); template doublev abs(doublev j); template ldoublev abs(ldoublev j); template floatv hypot(floatv x, floatv y); template doublev hypot(doublev x, doublev y); template ldoublev hypot(doublev x, doublev y); template floatv hypot(floatv x, floatv y, floatv z); template doublev hypot(doublev x, doublev y, doublev z); template ldoublev hypot(ldoublev x, ldoublev y, ldoublev z); template floatv pow(floatv x, floatv y); template doublev pow(doublev x, doublev y); template ldoublev pow(ldoublev x, ldoublev y); template floatv sqrt(floatv x); template doublev sqrt(doublev x); template ldoublev sqrt(ldoublev x); template floatv erf(floatv x); template doublev erf(doublev x); template ldoublev erf(ldoublev x); template floatv erfc(floatv x); template doublev erfc(doublev x); template ldoublev erfc(ldoublev x); template floatv lgamma(floatv x); template doublev lgamma(doublev x); template ldoublev lgamma(ldoublev x); template floatv tgamma(floatv x); template doublev tgamma(doublev x); template ldoublev tgamma(ldoublev x); template floatv ceil(floatv x); template doublev ceil(doublev x); template ldoublev ceil(ldoublev x); template floatv floor(floatv x); template doublev floor(doublev x); template ldoublev floor(ldoublev x); template floatv nearbyint(floatv x); template doublev nearbyint(doublev x); template ldoublev nearbyint(ldoublev x); template floatv rint(floatv x); template doublev rint(doublev x); template ldoublev rint(ldoublev x); template samesize> lrint(floatv x); template samesize> lrint(doublev x); template samesize> lrint(ldoublev x); template samesize> llrint(floatv x); template samesize> llrint(doublev x); template samesize> llrint(ldoublev x); template floatv round(floatv x); template doublev round(doublev x); template ldoublev round(ldoublev x); template samesize> lround(floatv x); template samesize> lround(doublev x); template samesize> lround(ldoublev x); template samesize> llround(floatv x); template samesize> llround(doublev x); template samesize> llround(ldoublev x); template floatv trunc(floatv x); template doublev trunc(doublev x); template ldoublev trunc(ldoublev x); template floatv fmod(floatv x, floatv y); template doublev fmod(doublev x, doublev y); template ldoublev fmod(ldoublev x, ldoublev y); template floatv remainder(floatv x, floatv y); template doublev remainder(doublev x, doublev y); template ldoublev remainder(ldoublev x, ldoublev y); template floatv remquo(floatv x, floatv y, samesize>* quo); template doublev remquo(doublev x, doublev y, samesize>* quo); template ldoublev remquo(ldoublev x, ldoublev y, samesize>* quo); template floatv copysign(floatv x, floatv y); template doublev copysign(doublev x, doublev y); template ldoublev copysign(ldoublev x, ldoublev y); template doublev nan(const char* tagp); template floatv nanf(const char* tagp); template ldoublev nanl(const char* tagp); template floatv nextafter(floatv x, floatv y); template doublev nextafter(doublev x, doublev y); template ldoublev nextafter(ldoublev x, ldoublev y); template floatv nexttoward(floatv x, ldoublev y); template doublev nexttoward(doublev x, ldoublev y); template ldoublev nexttoward(ldoublev x, ldoublev y); template floatv fdim(floatv x, floatv y); template doublev fdim(doublev x, doublev y); template ldoublev fdim(ldoublev x, ldoublev y); template floatv fmax(floatv x, floatv y); template doublev fmax(doublev x, doublev y); template ldoublev fmax(ldoublev x, ldoublev y); template floatv fmin(floatv x, floatv y); template doublev fmin(doublev x, doublev y); template ldoublev fmin(ldoublev x, ldoublev y); template floatv fma(floatv x, floatv y, floatv z); template doublev fma(doublev x, doublev y, doublev z); template ldoublev fma(ldoublev x, ldoublev y, ldoublev z); template samesize> fpclassify(floatv x); template samesize> fpclassify(doublev x); template samesize> fpclassify(ldoublev x); template simd_mask isfinite(floatv x); template simd_mask isfinite(doublev x); template simd_mask isfinite(ldoublev x); template simd_mask isinf(floatv x); template simd_mask isinf(doublev x); template simd_mask isinf(ldoublev x); template simd_mask isnan(floatv x); template simd_mask isnan(doublev x); template simd_mask isnan(ldoublev x); template simd_mask isnormal(floatv x); template simd_mask isnormal(doublev x); template simd_mask isnormal(ldoublev x); template simd_mask signbit(floatv x); template simd_mask signbit(doublev x); template simd_mask signbit(ldoublev x); template simd_mask isgreater(floatv x, floatv y); template simd_mask isgreater(doublev x, doublev y); template simd_mask isgreater(ldoublev x, ldoublev y); template simd_mask isgreaterequal(floatv x, floatv y); template simd_mask isgreaterequal(doublev x, doublev y); template simd_mask isgreaterequal(ldoublev x, ldoublev y); template simd_mask isless(floatv x, floatv y); template simd_mask isless(doublev x, doublev y); template simd_mask isless(ldoublev x, ldoublev y); template simd_mask islessequal(floatv x, floatv y); template simd_mask islessequal(doublev x, doublev y); template simd_mask islessequal(ldoublev x, ldoublev y); template simd_mask islessgreater(floatv x, floatv y); template simd_mask islessgreater(doublev x, doublev y); template simd_mask islessgreater(ldoublev x, ldoublev y); template simd_mask isunordered(floatv x, floatv y); template simd_mask isunordered(doublev x, doublev y); template simd_mask isunordered(ldoublev x, ldoublev y); template struct simd_div_t { V quot, rem; }; template simd_div_t> div(scharv numer, scharv denom); template simd_div_t> div(shortv numer, shortv denom); template simd_div_t> div(intv numer, intv denom); template simd_div_t> div(longv numer, longv denom); template simd_div_t> div(llongv numer, llongv denom); // [simd.mask.class] template class simd_mask { public: using value_type = bool; using reference = see below; using simd_type = simd; using abi_type = Abi; static constexpr size_t size() noexcept; simd_mask() = default; // broadcast constructor explicit simd_mask(value_type) noexcept; // implicit type conversion constructor template simd_mask(const simd_mask>&) noexcept; // load constructor template simd_mask(const value_type* mem, Flags); // loads [simd.mask.copy] template void copy_from(const value_type* mem, Flags); template void copy_to(value_type* mem, Flags) const; // scalar access [simd.mask.subscr] reference operator[](size_t); value_type operator[](size_t) const; // unary operators [simd.mask.unary] simd_mask operator!() const noexcept; // simd_mask binary operators [simd.mask.binary] friend simd_mask operator&&(const simd_mask&, const simd_mask&) noexcept; friend simd_mask operator||(const simd_mask&, const simd_mask&) noexcept; friend simd_mask operator& (const simd_mask&, const simd_mask&) noexcept; friend simd_mask operator| (const simd_mask&, const simd_mask&) noexcept; friend simd_mask operator^ (const simd_mask&, const simd_mask&) noexcept; // simd_mask compound assignment [simd.mask.cassign] friend simd_mask& operator&=(simd_mask&, const simd_mask&) noexcept; friend simd_mask& operator|=(simd_mask&, const simd_mask&) noexcept; friend simd_mask& operator^=(simd_mask&, const simd_mask&) noexcept; // simd_mask compares [simd.mask.comparison] friend simd_mask operator==(const simd_mask&, const simd_mask&) noexcept; friend simd_mask operator!=(const simd_mask&, const simd_mask&) noexcept; }; } // parallelism_v2 } // std::experimental */ #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD enum class _StorageKind { _Scalar, _Array, }; template <_StorageKind __kind, int _Np> struct __simd_abi {}; template struct __simd_storage_traits {}; template struct __simd_storage_traits<_Tp, __simd_abi<_StorageKind::_Array, __num_element>> { using type = std::array<_Tp, __num_element>; }; template struct __simd_storage_traits<_Tp, __simd_abi<_StorageKind::_Scalar, 1>> { using type = _Tp; }; template constexpr decltype(_To{std::declval<_From>()}, true) __is_non_narrowing_convertible_impl(_From) { return true; } template constexpr bool __is_non_narrowing_convertible_impl(...) { return false; } template constexpr typename std::enable_if::value && std::is_arithmetic<_From>::value, bool>::type __is_non_narrowing_arithmetic_convertible() { return __is_non_narrowing_convertible_impl<_To>(_From{}); } template constexpr typename std::enable_if::value && std::is_arithmetic<_From>::value), bool>::type __is_non_narrowing_arithmetic_convertible() { return false; } template constexpr _Tp __variadic_sum() { return _Tp{}; } template constexpr _Tp __variadic_sum(_Up __first, _Args... __rest) { return static_cast<_Tp>(__first) + __variadic_sum<_Tp>(__rest...); } _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD_ABI using scalar = __simd_abi<_StorageKind::_Scalar, 1>; template using fixed_size = __simd_abi<_StorageKind::_Array, _Np>; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template _LIBCPP_INLINE_VAR constexpr int max_fixed_size = 32; #endif template using compatible = fixed_size<16 / sizeof(_Tp)>; template using native = compatible<_Tp>; _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD_ABI _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD template > class simd; template > class simd_mask; struct element_aligned_tag {}; struct vector_aligned_tag {}; template struct overaligned_tag {}; #if _LIBCPP_STD_VER > 14 _LIBCPP_INLINE_VAR constexpr element_aligned_tag element_aligned{}; _LIBCPP_INLINE_VAR constexpr vector_aligned_tag vector_aligned{}; #if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template _LIBCPP_INLINE_VAR constexpr overaligned_tag<_Np> overaligned{}; #endif #endif // traits [simd.traits] template struct is_abi_tag : std::integral_constant {}; template <_StorageKind __kind, int _Np> struct is_abi_tag<__simd_abi<__kind, _Np>> : std::integral_constant {}; template struct is_simd : std::integral_constant {}; template struct is_simd> : std::integral_constant {}; template struct is_simd_mask : std::integral_constant {}; template struct is_simd_mask> : std::integral_constant { }; template struct is_simd_flag_type : std::integral_constant {}; template <> struct is_simd_flag_type : std::integral_constant {}; template <> struct is_simd_flag_type : std::integral_constant {}; template struct is_simd_flag_type> : std::integral_constant {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template _LIBCPP_INLINE_VAR constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value; template _LIBCPP_INLINE_VAR constexpr bool is_simd_v = is_simd<_Tp>::value; template _LIBCPP_INLINE_VAR constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value; template _LIBCPP_INLINE_VAR constexpr bool is_simd_flag_type_v = is_simd_flag_type<_Tp>::value; #endif template struct abi_for_size { using type = simd_abi::fixed_size<_Np>; }; template using abi_for_size_t = typename abi_for_size<_Tp, _Np>::type; template > struct simd_size; template struct simd_size<_Tp, __simd_abi<__kind, _Np>> : std::integral_constant { static_assert( std::is_arithmetic<_Tp>::value && !std::is_same::type, bool>::value, "Element type should be vectorizable"); }; template struct memory_alignment; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template > _LIBCPP_INLINE_VAR constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value; template _LIBCPP_INLINE_VAR constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value; #endif // class template simd [simd.class] template using native_simd = simd<_Tp, simd_abi::native<_Tp>>; template using fixed_size_simd = simd<_Tp, simd_abi::fixed_size<_Np>>; // class template simd_mask [simd.mask.class] template using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>; template using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>; // casts [simd.casts] template struct __static_simd_cast_traits { template static simd<_Tp, _Abi> __apply(const simd<_Up, _Abi>& __v); }; template struct __static_simd_cast_traits> { template static typename std::enable_if::size() == simd<_Tp, _NewAbi>::size(), simd<_Tp, _NewAbi>>::type __apply(const simd<_Up, _Abi>& __v); }; template struct __simd_cast_traits { template static typename std::enable_if< __is_non_narrowing_arithmetic_convertible<_Up, _Tp>(), simd<_Tp, _Abi>>::type __apply(const simd<_Up, _Abi>& __v); }; template struct __simd_cast_traits> { template static typename std::enable_if< __is_non_narrowing_arithmetic_convertible<_Up, _Tp>() && simd<_Up, _Abi>::size() == simd<_Tp, _NewAbi>::size(), simd<_Tp, _NewAbi>>::type __apply(const simd<_Up, _Abi>& __v); }; template auto simd_cast(const simd<_Up, _Abi>& __v) -> decltype(__simd_cast_traits<_Tp>::__apply(__v)) { return __simd_cast_traits<_Tp>::__apply(__v); } template auto static_simd_cast(const simd<_Up, _Abi>& __v) -> decltype(__static_simd_cast_traits<_Tp>::__apply(__v)) { return __static_simd_cast_traits<_Tp>::__apply(__v); } template fixed_size_simd<_Tp, simd_size<_Tp, _Abi>::value> to_fixed_size(const simd<_Tp, _Abi>&) noexcept; template fixed_size_simd_mask<_Tp, simd_size<_Tp, _Abi>::value> to_fixed_size(const simd_mask<_Tp, _Abi>&) noexcept; template native_simd<_Tp> to_native(const fixed_size_simd<_Tp, _Np>&) noexcept; template native_simd_mask<_Tp> to_native(const fixed_size_simd_mask<_Tp, _Np>&) noexcept; template simd<_Tp> to_compatible(const fixed_size_simd<_Tp, _Np>&) noexcept; template simd_mask<_Tp> to_compatible(const fixed_size_simd_mask<_Tp, _Np>&) noexcept; template tuple>...> split(const simd<_Tp, _Abi>&); template tuple>...> split(const simd_mask<_Tp, _Abi>&); template array<_SimdType, simd_size::value / _SimdType::size()> split(const simd&); template array<_SimdType, simd_size::value / _SimdType::size()> split(const simd_mask&); template simd<_Tp, abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>> concat(const simd<_Tp, _Abis>&...); template simd_mask<_Tp, abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>> concat(const simd_mask<_Tp, _Abis>&...); // reductions [simd.mask.reductions] template bool all_of(const simd_mask<_Tp, _Abi>&) noexcept; template bool any_of(const simd_mask<_Tp, _Abi>&) noexcept; template bool none_of(const simd_mask<_Tp, _Abi>&) noexcept; template bool some_of(const simd_mask<_Tp, _Abi>&) noexcept; template int popcount(const simd_mask<_Tp, _Abi>&) noexcept; template int find_first_set(const simd_mask<_Tp, _Abi>&); template int find_last_set(const simd_mask<_Tp, _Abi>&); bool all_of(bool) noexcept; bool any_of(bool) noexcept; bool none_of(bool) noexcept; bool some_of(bool) noexcept; int popcount(bool) noexcept; int find_first_set(bool) noexcept; int find_last_set(bool) noexcept; // masked assignment [simd.whereexpr] template class const_where_expression; template class where_expression; // masked assignment [simd.mask.where] template struct __nodeduce { using type = _Tp; }; template where_expression, simd<_Tp, _Abi>> where(const typename simd<_Tp, _Abi>::mask_type&, simd<_Tp, _Abi>&) noexcept; template const_where_expression, const simd<_Tp, _Abi>> where(const typename simd<_Tp, _Abi>::mask_type&, const simd<_Tp, _Abi>&) noexcept; template where_expression, simd_mask<_Tp, _Abi>> where(const typename __nodeduce>::type&, simd_mask<_Tp, _Abi>&) noexcept; template const_where_expression, const simd_mask<_Tp, _Abi>> where(const typename __nodeduce>::type&, const simd_mask<_Tp, _Abi>&) noexcept; template where_expression where(bool, _Tp&) noexcept; template const_where_expression where(bool, const _Tp&) noexcept; // reductions [simd.reductions] template > _Tp reduce(const simd<_Tp, _Abi>&, _BinaryOp = _BinaryOp()); template typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&, typename _SimdType::value_type neutral_element, _BinaryOp binary_op); template typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&, plus binary_op = {}); template typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&, multiplies binary_op); template typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&, bit_and binary_op); template typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&, bit_or binary_op); template typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&, bit_xor binary_op); template _Tp hmin(const simd<_Tp, _Abi>&); template typename _SimdType::value_type hmin(const const_where_expression<_MaskType, _SimdType>&); template _Tp hmax(const simd<_Tp, _Abi>&); template typename _SimdType::value_type hmax(const const_where_expression<_MaskType, _SimdType>&); // algorithms [simd.alg] template simd<_Tp, _Abi> min(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; template simd<_Tp, _Abi> max(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; template std::pair, simd<_Tp, _Abi>> minmax(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; template simd<_Tp, _Abi> clamp(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&); // [simd.whereexpr] // TODO implement where expressions. template class const_where_expression { public: const_where_expression(const const_where_expression&) = delete; const_where_expression& operator=(const const_where_expression&) = delete; typename remove_const<_Tp>::type operator-() const&&; template void copy_to(_Up*, _Flags) const&&; }; template class where_expression : public const_where_expression<_MaskType, _Tp> { public: where_expression(const where_expression&) = delete; where_expression& operator=(const where_expression&) = delete; template void operator=(_Up&&); template void operator+=(_Up&&); template void operator-=(_Up&&); template void operator*=(_Up&&); template void operator/=(_Up&&); template void operator%=(_Up&&); template void operator&=(_Up&&); template void operator|=(_Up&&); template void operator^=(_Up&&); template void operator<<=(_Up&&); template void operator>>=(_Up&&); void operator++(); void operator++(int); void operator--(); void operator--(int); template void copy_from(const _Up*, _Flags); }; // [simd.class] // TODO: implement simd template class simd { private: template static constexpr bool __can_broadcast() { return (std::is_arithmetic<_Up>::value && __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()) || (!std::is_arithmetic<_Up>::value && std::is_convertible<_Up, _Tp>::value) || std::is_same::type, int>::value || (std::is_same::type, unsigned int>::value && std::is_unsigned<_Tp>::value); } public: using value_type = _Tp; // TODO: this is strawman implementation. Turn it into a proxy type. using reference = _Tp&; using mask_type = simd_mask<_Tp, _Abi>; using abi_type = _Abi; static constexpr size_t size() noexcept { return simd_size<_Tp, _Abi>::value; } simd() = default; // implicit type conversion constructor template >::value && __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()>::type> simd(const simd<_Up, simd_abi::fixed_size>&) {} // implicit broadcast constructor template ()>::type> simd(_Up&&); // generator constructor // TODO: for now only check for the index 0. This is because C++11 doesn't // have index_sequence, and it's hard to check for all indicies without using // index_sequence. template ()( std::integral_constant())), int())()> explicit simd(_Generator&&); // load constructor template simd(const _Up*, _Flags); // loads [simd.load] template void copy_from(const _Up*, _Flags); // stores [simd.store] template void copy_to(_Up*, _Flags) const; // scalar access [simd.subscr] reference operator[](size_t); value_type operator[](size_t) const; // unary operators [simd.unary] simd& operator++(); simd operator++(int); simd& operator--(); simd operator--(int); mask_type operator!() const; simd operator~() const; simd operator+() const; simd operator-() const; // binary operators [simd.binary] friend simd operator+(const simd&, const simd&); friend simd operator-(const simd&, const simd&); friend simd operator*(const simd&, const simd&); friend simd operator/(const simd&, const simd&); friend simd operator%(const simd&, const simd&); friend simd operator&(const simd&, const simd&); friend simd operator|(const simd&, const simd&); friend simd operator^(const simd&, const simd&); friend simd operator<<(const simd&, const simd&); friend simd operator>>(const simd&, const simd&); friend simd operator<<(const simd&, int); friend simd operator>>(const simd&, int); // compound assignment [simd.cassign] friend simd& operator+=(simd&, const simd&); friend simd& operator-=(simd&, const simd&); friend simd& operator*=(simd&, const simd&); friend simd& operator/=(simd&, const simd&); friend simd& operator%=(simd&, const simd&); friend simd& operator&=(simd&, const simd&); friend simd& operator|=(simd&, const simd&); friend simd& operator^=(simd&, const simd&); friend simd& operator<<=(simd&, const simd&); friend simd& operator>>=(simd&, const simd&); friend simd& operator<<=(simd&, int); friend simd& operator>>=(simd&, int); // compares [simd.comparison] friend mask_type operator==(const simd&, const simd&); friend mask_type operator!=(const simd&, const simd&); friend mask_type operator>=(const simd&, const simd&); friend mask_type operator<=(const simd&, const simd&); friend mask_type operator>(const simd&, const simd&); friend mask_type operator<(const simd&, const simd&); }; // [simd.mask.class] template // TODO: implement simd_mask class simd_mask { public: using value_type = bool; // TODO: this is strawman implementation. Turn it into a proxy type. using reference = bool&; using simd_type = simd<_Tp, _Abi>; using abi_type = _Abi; static constexpr size_t size() noexcept; simd_mask() = default; // broadcast constructor explicit simd_mask(value_type) noexcept; // implicit type conversion constructor template simd_mask(const simd_mask<_Up, simd_abi::fixed_size>&) noexcept; // load constructor template simd_mask(const value_type*, _Flags); // loads [simd.mask.copy] template void copy_from(const value_type*, _Flags); template void copy_to(value_type*, _Flags) const; // scalar access [simd.mask.subscr] reference operator[](size_t); value_type operator[](size_t) const; // unary operators [simd.mask.unary] simd_mask operator!() const noexcept; // simd_mask binary operators [simd.mask.binary] friend simd_mask operator&&(const simd_mask&, const simd_mask&) noexcept; friend simd_mask operator||(const simd_mask&, const simd_mask&) noexcept; friend simd_mask operator&(const simd_mask&, const simd_mask&)noexcept; friend simd_mask operator|(const simd_mask&, const simd_mask&) noexcept; friend simd_mask operator^(const simd_mask&, const simd_mask&) noexcept; // simd_mask compound assignment [simd.mask.cassign] friend simd_mask& operator&=(simd_mask&, const simd_mask&) noexcept; friend simd_mask& operator|=(simd_mask&, const simd_mask&) noexcept; friend simd_mask& operator^=(simd_mask&, const simd_mask&) noexcept; // simd_mask compares [simd.mask.comparison] friend simd_mask operator==(const simd_mask&, const simd_mask&) noexcept; friend simd_mask operator!=(const simd_mask&, const simd_mask&) noexcept; }; _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD #endif /* _LIBCPP_EXPERIMENTAL_SIMD */