diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -789,6 +789,9 @@ expected experimental/__config experimental/__memory + experimental/__simd/scalar.h + experimental/__simd/utility.h + experimental/__simd/vec_ext.h experimental/algorithm experimental/deque experimental/forward_list diff --git a/libcxx/include/experimental/__simd/scalar.h b/libcxx/include/experimental/__simd/scalar.h new file mode 100644 --- /dev/null +++ b/libcxx/include/experimental/__simd/scalar.h @@ -0,0 +1,25 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H +#define _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H + +#include +#include + +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD_ABI + +struct __scalar { + static constexpr bool __is_abi_tag = true; + static constexpr size_t __simd_size = 1; +}; + +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD_ABI + +#endif // _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H diff --git a/libcxx/include/experimental/__simd/utility.h b/libcxx/include/experimental/__simd/utility.h new file mode 100644 --- /dev/null +++ b/libcxx/include/experimental/__simd/utility.h @@ -0,0 +1,77 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H +#define _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H + +#include +#include +#include + +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD + +class _Bool { + const bool __v; + +public: + constexpr _Bool(bool __b) : __v(__b) {} + _Bool(int) = delete; + constexpr operator bool() const { return __v; } +}; + +template +constexpr decltype(_To{declval<_From>()}, true) __is_non_narrowing_convertible_impl(_From) { + return true; +} + +template +constexpr bool __is_non_narrowing_convertible_impl(...) { + return false; +} + +template +constexpr bool __is_non_narrowing_arithmetic_convertible() { + if constexpr (is_arithmetic_v<_To> && is_arithmetic_v<_From>) + return __is_non_narrowing_convertible_impl<_To>(_From{}); + else + return false; +} + +template +constexpr _Tp __variadic_sum(_Args... __args) { + return (static_cast<_Tp>(__args) + ...); +} + +template +constexpr bool __is_vectorizable() { + return is_arithmetic_v<_Tp> && !is_const_v<_Tp> && !is_volatile_v<_Tp> && !is_same_v<_Tp, bool>; +} + +template +constexpr bool __can_broadcast() { + return (is_arithmetic_v<_Up> && __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()) || + (!is_arithmetic_v<_Up> && is_convertible_v<_Up, _Tp>) || is_same_v, int> || + (is_same_v, unsigned int> && is_unsigned_v<_Tp>); +} + +template +constexpr decltype(forward_as_tuple(declval<_Generator>()(integral_constant())...), bool()) +__can_generate(index_sequence<__indicies...>) { + return !__variadic_sum( + !__can_broadcast<_Tp, decltype(declval<_Generator>()(integral_constant()))>()...); +} + +template +bool __can_generate(...) { + return false; +} + +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD + +#endif // _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H diff --git a/libcxx/include/experimental/__simd/vec_ext.h b/libcxx/include/experimental/__simd/vec_ext.h new file mode 100644 --- /dev/null +++ b/libcxx/include/experimental/__simd/vec_ext.h @@ -0,0 +1,26 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL___SIMD_VEC_EXT_H +#define _LIBCPP_EXPERIMENTAL___SIMD_VEC_EXT_H + +#include +#include + +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD_ABI + +template +struct __vec_ext { + static constexpr bool __is_abi_tag = _Np > 0 && _Np <= 32; + static constexpr size_t __simd_size = _Np; +}; + +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD_ABI + +#endif // _LIBCPP_EXPERIMENTAL___SIMD_VEC_EXT_H diff --git a/libcxx/include/experimental/simd b/libcxx/include/experimental/simd --- a/libcxx/include/experimental/simd +++ b/libcxx/include/experimental/simd @@ -10,641 +10,218 @@ #ifndef _LIBCPP_EXPERIMENTAL_SIMD #define _LIBCPP_EXPERIMENTAL_SIMD +#define __cpp_lib_experimental_parallel_simd 201803 + /* experimental/simd synopsis namespace std::experimental { - inline namespace parallelism_v2 { + namespace simd_abi { + using scalar = see below; + template using fixed_size = see below; + template inline constexpr int max_fixed_size = implementation-defined; + template using compatible = implementation-defined; + template using native = implementation-defined; + + template struct deduce { using type = see below; }; + template using deduce_t = + typename deduce::type; + } -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; -}; - + 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{}; + + // 9.4, simd type 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 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; + + template struct rebind_simd { using type = see below; }; + template using rebind_simd_t = typename rebind_simd::type; + template struct resize_simd { using type = see below; }; + template using resize_simd_t = typename resize_simd::type; + + // 9.6, Class template simd + template> class simd; + template using native_simd = simd>; + template using fixed_size_simd = simd>; + + // 9.8, Class template simd_mask + template> class simd_mask; + template using native_simd_mask = simd_mask>; + template using fixed_size_simd_mask = + simd_mask>; + + // 9.7.5, Casts + template see below simd_cast(const simd&) noexcept; + template see below static_simd_cast(const simd&) noexcept; + + 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&) noexcept; + template + tuple>...> + split(const simd_mask&) noexcept; + template + array / V::size()> + split(const simd&) noexcept; + template + array / V::size()> + split(const simd_mask&) noexcept; + + template + array / N, simd>, N> + split_by(const simd& x) noexcept; + template + array / N, simd_mask>, N> + split_by(const simd_mask& x) noexcept; + + template + simd + ...)>> + concat(const simd&...) noexcept; + template + simd_mask + ...)>> + concat(const simd_mask&...) noexcept; + + template + resize_simd * N, simd> + concat(const array, N>& arr) noexcept; + template + resize_simd * N, simd_mask> + concat(const array, N>& arr) noexcept; + + // 9.9.4, 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(T) noexcept; + bool any_of(T) noexcept; + bool none_of(T) noexcept; + bool some_of(T) noexcept; + int popcount(T) noexcept; + int find_first_set(T); + int find_last_set(T); + + // 9.5, Where expression class templates + template class const_where_expression; + template class where_expression; + + // 9.9.5, Where functions + template + where_expression, simd> + where(const typename simd::mask_type&, simd&) noexcept; + + template + const_where_expression, simd> + where(const typename simd::mask_type&, const simd&) noexcept; + + template + where_expression, simd_mask> + where(const type_identity_t>&, simd_mask&) noexcept; + + template + const_where_expression, simd_mask> + where(const type_identity_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; + + // 9.7.4, Reductions + template> + T reduce(const simd&, + BinaryOperation = {}); + + template + typename V::value_type reduce(const const_where_expression& x, + typename V::value_type identity_element, + BinaryOperation binary_op); + template + typename V::value_type reduce(const const_where_expression& x, + plus<> binary_op = {}) noexcept; + template + typename V::value_type reduce(const const_where_expression& x, + multiplies<> binary_op) noexcept; + template + typename V::value_type reduce(const const_where_expression& x, + bit_and<> binary_op) noexcept; + template + typename V::value_type reduce(const const_where_expression& x, + bit_or<> binary_op) noexcept; + template + typename V::value_type reduce(const const_where_expression& x, + bit_xor<> binary_op) noexcept; + + template + T hmin(const simd&) noexcept; + template + typename V::value_type hmin(const const_where_expression&) noexcept; + template + T hmax(const simd&) noexcept; + template + typename V::value_type hmax(const const_where_expression&) noexcept; + + // 9.7.6, Algorithms + template + simd + min(const simd& a, const simd& b) noexcept; + template + simd + max(const simd& a, const simd& b) noexcept; + template + pair, simd> + minmax(const simd& a, const simd& b) noexcept; + template + simd + clamp(const simd& v, + const simd& lo, + const simd& hi); } // parallelism_v2 } // std::experimental @@ -653,8 +230,10 @@ #include <__assert> // all public C++ headers provide the assertion handler #include <__functional/operations.h> #include -#include #include +#include +#include +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -664,917 +243,425 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD - #if _LIBCPP_STD_VER >= 17 -enum class _StorageKind { - _Scalar, - _Array, - _VecExt, -}; - -template <_StorageKind __kind, int _Np> -struct __simd_abi {}; - -template -class __simd_storage {}; - -template -class __simd_storage<_Tp, __simd_abi<_StorageKind::_Array, __num_element>> { - std::array<_Tp, __num_element> __storage_; - - template - friend struct simd; - - template - friend struct simd_mask; - -public: - _Tp __get(size_t __index) const noexcept { return __storage_[__index]; } - void __set(size_t __index, _Tp __val) noexcept { - __storage_[__index] = __val; - } -}; - -template -class __simd_storage<_Tp, __simd_abi<_StorageKind::_Scalar, 1>> { - _Tp __storage_; - - template - friend struct simd; - - template - friend struct simd_mask; - -public: - _Tp __get(size_t __index) const noexcept { return (&__storage_)[__index]; } - void __set(size_t __index, _Tp __val) noexcept { - (&__storage_)[__index] = __val; - } -}; - -#ifndef _LIBCPP_HAS_NO_VECTOR_EXTENSION - -_LIBCPP_HIDE_FROM_ABI constexpr size_t __floor_pow_of_2(size_t __val) { - return ((__val - 1) & __val) == 0 ? __val - : __floor_pow_of_2((__val - 1) & __val); -} +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD_ABI -_LIBCPP_HIDE_FROM_ABI constexpr size_t __ceil_pow_of_2(size_t __val) { - return __val == 1 ? 1 : __floor_pow_of_2(__val - 1) << 1; -} +using scalar = __scalar; +template using fixed_size = __vec_ext<_Np>; +template inline constexpr int max_fixed_size = 32; +template using compatible = __vec_ext<16 / sizeof(_Tp)>; +template using native = __vec_ext<_LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)>; -template -struct __vec_ext_traits { -#if !defined(_LIBCPP_COMPILER_CLANG_BASED) - typedef _Tp type __attribute__((vector_size(__ceil_pow_of_2(__bytes)))); -#endif +// TODO: Refine implementation-defined deduce ABI +template struct deduce { + using type = fixed_size<_Np>; }; +template using deduce_t = + typename deduce<_Tp, _Np, _Abis...>::type; -#if defined(_LIBCPP_COMPILER_CLANG_BASED) -#define _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, _NUM_ELEMENT) \ - template <> \ - struct __vec_ext_traits<_TYPE, sizeof(_TYPE) * _NUM_ELEMENT> { \ - using type = \ - _TYPE __attribute__((vector_size(sizeof(_TYPE) * _NUM_ELEMENT))); \ - } - -#define _LIBCPP_SPECIALIZE_VEC_EXT_32(_TYPE) \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 1); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 2); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 3); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 4); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 5); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 6); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 7); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 8); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 9); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 10); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 11); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 12); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 13); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 14); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 15); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 16); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 17); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 18); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 19); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 20); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 21); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 22); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 23); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 24); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 25); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 26); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 27); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 28); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 29); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 30); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 31); \ - _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 32) - -_LIBCPP_SPECIALIZE_VEC_EXT_32(char); -_LIBCPP_SPECIALIZE_VEC_EXT_32(char16_t); -_LIBCPP_SPECIALIZE_VEC_EXT_32(char32_t); -_LIBCPP_SPECIALIZE_VEC_EXT_32(wchar_t); -_LIBCPP_SPECIALIZE_VEC_EXT_32(signed char); -_LIBCPP_SPECIALIZE_VEC_EXT_32(signed short); -_LIBCPP_SPECIALIZE_VEC_EXT_32(signed int); -_LIBCPP_SPECIALIZE_VEC_EXT_32(signed long); -_LIBCPP_SPECIALIZE_VEC_EXT_32(signed long long); -_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned char); -_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned short); -_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned int); -_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned long); -_LIBCPP_SPECIALIZE_VEC_EXT_32(unsigned long long); -_LIBCPP_SPECIALIZE_VEC_EXT_32(float); -_LIBCPP_SPECIALIZE_VEC_EXT_32(double); -_LIBCPP_SPECIALIZE_VEC_EXT_32(long double); - -#undef _LIBCPP_SPECIALIZE_VEC_EXT_32 -#undef _LIBCPP_SPECIALIZE_VEC_EXT -#endif - -template -class __simd_storage<_Tp, __simd_abi<_StorageKind::_VecExt, __num_element>> { - using _StorageType = - typename __vec_ext_traits<_Tp, sizeof(_Tp) * __num_element>::type; - - _StorageType __storage_; - - template - friend struct simd; +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD_ABI - template - friend struct simd_mask; +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD +template class __simd_reference { // exposition only public: - _Tp __get(size_t __index) const noexcept { return __storage_[__index]; } - void __set(size_t __index, _Tp __val) noexcept { - __storage_[__index] = __val; - } -}; - -#endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION - -template -class __simd_reference { - static_assert(std::is_same<_Vp, _Tp>::value, ""); - - template - friend struct simd; - - template - friend struct simd_mask; + using value_type = _Vp; - __simd_storage<_Tp, _Abi>* __ptr_; - size_t __index_; - - __simd_reference(__simd_storage<_Tp, _Abi>* __ptr, size_t __index) - : __ptr_(__ptr), __index_(__index) {} - - __simd_reference(const __simd_reference&) = default; - -public: __simd_reference() = delete; - __simd_reference& operator=(const __simd_reference&) = delete; - - operator _Vp() const { return __ptr_->__get(__index_); } - - __simd_reference operator=(_Vp __value) && { - __ptr_->__set(__index_, __value); - return *this; - } - - __simd_reference operator++() && { - return std::move(*this) = __ptr_->__get(__index_) + 1; - } - - _Vp operator++(int) && { - auto __val = __ptr_->__get(__index_); - __ptr_->__set(__index_, __val + 1); - return __val; - } - - __simd_reference operator--() && { - return std::move(*this) = __ptr_->__get(__index_) - 1; - } - - _Vp operator--(int) && { - auto __val = __ptr_->__get(__index_); - __ptr_->__set(__index_, __val - 1); - return __val; - } - - __simd_reference operator+=(_Vp __value) && { - return std::move(*this) = __ptr_->__get(__index_) + __value; - } - - __simd_reference operator-=(_Vp __value) && { - return std::move(*this) = __ptr_->__get(__index_) - __value; - } - - __simd_reference operator*=(_Vp __value) && { - return std::move(*this) = __ptr_->__get(__index_) * __value; - } - - __simd_reference operator/=(_Vp __value) && { - return std::move(*this) = __ptr_->__get(__index_) / __value; - } - - __simd_reference operator%=(_Vp __value) && { - return std::move(*this) = __ptr_->__get(__index_) % __value; - } - - __simd_reference operator>>=(_Vp __value) && { - return std::move(*this) = __ptr_->__get(__index_) >> __value; - } - - __simd_reference operator<<=(_Vp __value) && { - return std::move(*this) = __ptr_->__get(__index_) << __value; - } - - __simd_reference operator&=(_Vp __value) && { - return std::move(*this) = __ptr_->__get(__index_) & __value; - } - - __simd_reference operator|=(_Vp __value) && { - return std::move(*this) = __ptr_->__get(__index_) | __value; - } - - __simd_reference operator^=(_Vp __value) && { - return std::move(*this) = __ptr_->__get(__index_) ^ __value; - } -}; - -template -_LIBCPP_HIDE_FROM_ABI constexpr decltype(_To{std::declval<_From>()}, true) -__is_non_narrowing_convertible_impl(_From) { - return true; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __is_non_narrowing_convertible_impl(...) { - return false; -} - -template -_LIBCPP_HIDE_FROM_ABI -constexpr typename std::enable_if::value && - std::is_arithmetic<_From>::value, - bool>::type -__is_non_narrowing_arithmetic_convertible() { - return experimental::__is_non_narrowing_convertible_impl<_To>(_From{}); -} - -template -_LIBCPP_HIDE_FROM_ABI -constexpr typename std::enable_if::value && - std::is_arithmetic<_From>::value), - bool>::type -__is_non_narrowing_arithmetic_convertible() { - return false; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr _Tp __variadic_sum() { - return _Tp{}; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr _Tp __variadic_sum(_Up __first, _Args... __rest) { - return static_cast<_Tp>(__first) + experimental::__variadic_sum<_Tp>(__rest...); -} - -template -struct __nodeduce { - using type = _Tp; + __simd_reference(const __simd_reference&) = delete; + + operator value_type() const noexcept; + + template __simd_reference operator=(_Up&& __x) && noexcept; + + template __simd_reference operator+=(_Up&& __x) && noexcept; + template __simd_reference operator-=(_Up&& __x) && noexcept; + template __simd_reference operator*=(_Up&& __x) && noexcept; + template __simd_reference operator/=(_Up&& __x) && noexcept; + template __simd_reference operator%=(_Up&& __x) && noexcept; + template __simd_reference operator|=(_Up&& __x) && noexcept; + template __simd_reference operator&=(_Up&& __x) && noexcept; + template __simd_reference operator^=(_Up&& __x) && noexcept; + template __simd_reference operator<<=(_Up&& __x) && noexcept; + template __simd_reference operator>>=(_Up&& __x) && noexcept; + + __simd_reference operator++() && noexcept; + value_type operator++(int) && noexcept; + __simd_reference operator--() && noexcept; + value_type operator--(int) && noexcept; + + friend void swap(__simd_reference&& __a, __simd_reference&& __b) noexcept; + friend void swap(value_type& __a, __simd_reference&& __b) noexcept; + friend void swap(__simd_reference&& __a, value_type& __b) noexcept; }; -template -_LIBCPP_HIDE_FROM_ABI constexpr bool __vectorizable() { - return std::is_arithmetic<_Tp>::value && !std::is_const<_Tp>::value && - !std::is_volatile<_Tp>::value && !std::is_same<_Tp, bool>::value; -} - -_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>; - -template -inline constexpr size_t max_fixed_size = 32; - -template -using compatible = fixed_size<16 / sizeof(_Tp)>; - -#ifndef _LIBCPP_HAS_NO_VECTOR_EXTENSION -template -using native = __simd_abi<_StorageKind::_VecExt, - _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)>; -#else -template -using native = - fixed_size<_Tp, _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)>; -#endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION - -_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 {}; +template struct overaligned_tag {}; inline constexpr element_aligned_tag element_aligned{}; inline constexpr vector_aligned_tag vector_aligned{}; -template -inline constexpr overaligned_tag<_Np> overaligned{}; - -// 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 inline constexpr overaligned_tag<_Np> overaligned{}; + +// 9.6, Class template simd +template> class simd; +template using native_simd = simd<_Tp, simd_abi::native<_Tp>>; +template using fixed_size_simd = simd<_Tp, simd_abi::fixed_size<_Np>>; + +// 9.8, Class template simd_mask +template> class simd_mask; +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>>; + +// 9.4, simd type traits +template struct __is_abi_tag_impl : false_type {}; +template struct __is_abi_tag_impl<_Tp, enable_if_t<_Tp::__is_abi_tag>> : bool_constant<_Tp::__is_abi_tag> {}; +template struct is_abi_tag : __is_abi_tag_impl<_Tp> {}; +template inline constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value; + +template struct is_simd; +template inline constexpr bool is_simd_v = is_simd<_Tp>::value; + +template struct is_simd_mask; +template inline constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value; + +template struct is_simd_flag_type; +template inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<_Tp>::value; + +template struct __simd_size_impl {}; +template + struct __simd_size_impl<_Tp, _Abi, enable_if_t<__is_vectorizable<_Tp>() && is_abi_tag_v<_Abi>>> + : integral_constant {}; +template> struct simd_size : __simd_size_impl<_Tp, _Abi> {}; +template> + inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value; + +template struct memory_alignment; +template + inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value; + +template struct rebind_simd { using type = void; }; +template using rebind_simd_t = typename rebind_simd<_Tp, _Vp>::type; +template struct resize_simd { using type = void; }; +template using resize_simd_t = typename resize_simd<_Np, _Vp>::type; + +// 9.7.5, Casts +template void simd_cast(const simd<_Up, _Abi>&) noexcept; +template void static_simd_cast(const simd<_Up, _Abi>&) noexcept; + +template + fixed_size_simd<_Tp, simd_size_v<_Tp, _Abi>> + to_fixed_size(const simd<_Tp, _Abi>&) noexcept; +template + fixed_size_simd_mask<_Tp, simd_size_v<_Tp, _Abi>> + 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>&) noexcept; +template + tuple>...> + split(const simd_mask<_Tp, _Abi>&) noexcept; +template + array<_Vp, simd_size_v / _Vp::size()> + split(const simd&) noexcept; +template + array<_Vp, simd_size_v / _Vp::size()> + split(const simd_mask&) noexcept; + +template + array / _Np, simd<_Tp, _Abi>>, _Np> + split_by(const simd<_Tp, _Abi>& __x) noexcept; +template + array / _Np, simd_mask<_Tp, _Abi>>, _Np> + split_by(const simd_mask<_Tp, _Abi>& __x) noexcept; + +template + simd<_Tp, simd_abi::deduce_t<_Tp, (simd_size_v<_Tp, _Abis> + ...)>> + concat(const simd<_Tp, _Abis>&...) noexcept; +template + simd_mask<_Tp, simd_abi::deduce_t<_Tp, (simd_size_v<_Tp, _Abis> + ...)>> + concat(const simd_mask<_Tp, _Abis>&...) noexcept; + +template + resize_simd * _Np, simd<_Tp, _Abi>> + concat(const array, _Np>& __arr) noexcept; +template + resize_simd * _Np, simd_mask<_Tp, _Abi>> + concat(const array, _Np>& __arr) noexcept; + +// 9.9.4, 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); +int find_last_set(_Bool); + +// 9.5, Where expression class templates +template class const_where_expression; +template class where_expression; + +// 9.9.5, Where functions +template + where_expression, simd<_Tp, _Abi>> + where(const typename simd<_Tp, _Abi>::mask_type&, simd<_Tp, _Abi>&) noexcept; + +template + const_where_expression, 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 type_identity_t>&, simd_mask<_Tp, _Abi>&) noexcept; + +template + const_where_expression, simd_mask<_Tp, _Abi>> + where(const type_identity_t>&, const simd_mask<_Tp, _Abi>&) noexcept; + +template + where_expression + where(_Bool __k, _Tp& __d) noexcept; + +template + const_where_expression + where(_Bool __k, const _Tp& __d) noexcept; + + +// 9.7.4, Reductions +template> + _Tp reduce(const simd<_Tp, _Abi>&, + _BinaryOperation = {}); + +template + typename _Vp::value_type reduce(const const_where_expression<_Mp, _Vp>& __x, + typename _Vp::value_type __identity_element, + _BinaryOperation __binary_op); +template + typename _Vp::value_type reduce(const const_where_expression<_Mp, _Vp>& __x, + plus<> __binary_op = {}) noexcept; +template + typename _Vp::value_type reduce(const const_where_expression<_Mp, _Vp>& __x, + multiplies<> __binary_op) noexcept; +template + typename _Vp::value_type reduce(const const_where_expression<_Mp, _Vp>& __x, + bit_and<> __binary_op) noexcept; +template + typename _Vp::value_type reduce(const const_where_expression<_Mp, _Vp>& __x, + bit_or<> __binary_op) noexcept; +template + typename _Vp::value_type reduce(const const_where_expression<_Mp, _Vp>& __x, + bit_xor<> __binary_op) noexcept; + +template + _Tp hmin(const simd<_Tp, _Abi>&) noexcept; +template + typename _Vp::value_type hmin(const const_where_expression<_Mp, _Vp>&) noexcept; +template + _Tp hmax(const simd<_Tp, _Abi>&) noexcept; +template + typename _Vp::value_type hmax(const const_where_expression<_Mp, _Vp>&) noexcept; + +// 9.7.6, Algorithms +template + simd<_Tp, _Abi> + min(const simd<_Tp, _Abi>& __a, const simd<_Tp, _Abi>& __b) noexcept; +template + simd<_Tp, _Abi> + max(const simd<_Tp, _Abi>& __a, const simd<_Tp, _Abi>& __b) noexcept; +template + pair, simd<_Tp, _Abi>> + minmax(const simd<_Tp, _Abi>& __a, const simd<_Tp, _Abi>& __b) noexcept; +template + simd<_Tp, _Abi> + clamp(const simd<_Tp, _Abi>& __v, + const simd<_Tp, _Abi>& __lo, + const simd<_Tp, _Abi>& __hi); + + +// 9.5, Where expression class templates defination +template class const_where_expression { + const _Mp __mask; // exposition only + _Tp& __data; // exposition only -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 {}; - -template -inline constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value; -template -inline constexpr bool is_simd_v = is_simd<_Tp>::value; -template -inline constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value; -template -inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<_Tp>::value; -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<__remove_const_t<_Tp>, bool>::value, - "Element type should be vectorizable"); -}; - -// TODO: implement it. -template -struct memory_alignment; - -template > -inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value; - -template -inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value; - -// 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 -_LIBCPP_HIDE_FROM_ABI auto simd_cast(const simd<_Up, _Abi>& __v) - -> decltype(__simd_cast_traits<_Tp>::__apply(__v)) { - return __simd_cast_traits<_Tp>::__apply(__v); -} - -template -_LIBCPP_HIDE_FROM_ABI 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, experimental::__variadic_sum(simd_size<_Tp, _Abis>::value...)>> -concat(const simd<_Tp, _Abis>&...); - -template -simd_mask<_Tp, - abi_for_size_t<_Tp, experimental::__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 -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); - -template -typename _SimdType::value_type -reduce(const const_where_expression<_MaskType, _SimdType>&, - plus = {}); - -template -typename _SimdType::value_type -reduce(const const_where_expression<_MaskType, _SimdType>&, - multiplies); - -template -typename _SimdType::value_type -reduce(const const_where_expression<_MaskType, _SimdType>&, - bit_and); - -template -typename _SimdType::value_type -reduce(const const_where_expression<_MaskType, _SimdType>&, - bit_or); - -template -typename _SimdType::value_type -reduce(const const_where_expression<_MaskType, _SimdType>&, - bit_xor); - -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; - __remove_const_t<_Tp> operator-() const&&; - template - void copy_to(_Up*, _Flags) const&&; + + _Tp operator-() const && noexcept; + _Tp operator+() const && noexcept; + _Tp operator~() const && noexcept; + + template void copy_to(_Up* __mem, _Flags) const &&; }; -template -class where_expression : public const_where_expression<_MaskType, _Tp> { +template +class where_expression : public const_where_expression<_Mp, _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); + template void operator=(_Up&& x) && noexcept; + template void operator+=(_Up&& x) && noexcept; + template void operator-=(_Up&& x) && noexcept; + template void operator*=(_Up&& x) && noexcept; + template void operator/=(_Up&& x) && noexcept; + template void operator%=(_Up&& x) && noexcept; + template void operator&=(_Up&& x) && noexcept; + template void operator|=(_Up&& x) && noexcept; + template void operator^=(_Up&& x) && noexcept; + template void operator<<=(_Up&& x) && noexcept; + template void operator>>=(_Up&& x) && noexcept; + + void operator++() && noexcept; + void operator++(int) && noexcept; + void operator--() && noexcept; + void operator--(int) && noexcept; + + template void copy_from(const _Up* __mem, _Flags) &&; }; -// [simd.class] -// TODO: implement simd -template -class simd { +// 9.6, Class template simd defination +template class simd { public: using value_type = _Tp; - using reference = __simd_reference<_Tp, _Tp, _Abi>; + using reference = __simd_reference; using mask_type = simd_mask<_Tp, _Abi>; using abi_type = _Abi; - simd() = default; - simd(const simd&) = default; - simd& operator=(const simd&) = default; + static constexpr size_t size() noexcept { return simd_size_v; }; - static constexpr size_t size() noexcept { - return simd_size<_Tp, _Abi>::value; - } + simd() noexcept = default; -private: - __simd_storage<_Tp, _Abi> __s_; - - 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<__remove_const_t<_Up>, int>::value || - (std::is_same<__remove_const_t<_Up>, - unsigned int>::value && - std::is_unsigned<_Tp>::value); - } + // 9.6.4, simd constructors + template(), int> = 0> + simd(_Up&& __value) noexcept; + template simd(const simd<_Up, simd_abi::fixed_size>&) noexcept; + template(make_index_sequence()), int> = 0> + explicit simd(_Gen&& __gen) noexcept; + template simd(const _Up* __mem, _Flags); - template - static constexpr decltype( - std::forward_as_tuple(std::declval<_Generator>()( - std::integral_constant())...), - bool()) - __can_generate(std::index_sequence<__indicies...>) { - return !experimental::__variadic_sum( - !__can_broadcast()( - std::integral_constant()))>()...); - } + // 9.6.5, simd copy functions + template void copy_from(const _Up* __mem, _Flags); + template void copy_to(_Up* __mem, _Flags); - template - static bool __can_generate(...) { - return false; - } - - template - void __generator_init(_Generator&& __g, std::index_sequence<__indicies...>) { - int __not_used[]{((*this)[__indicies] = - __g(std::integral_constant()), - 0)...}; - (void)__not_used; - } - -public: - // implicit type conversion constructor - template >::value && - __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()>::type> - simd(const simd<_Up, simd_abi::fixed_size>& __v) { - for (size_t __i = 0; __i < size(); __i++) { - (*this)[__i] = static_cast<_Tp>(__v[__i]); - } - } - - // implicit broadcast constructor - template ()>::type> - simd(_Up&& __rv) { - auto __v = static_cast<_Tp>(__rv); - for (size_t __i = 0; __i < size(); __i++) { - (*this)[__i] = __v; - } - } - - // generator constructor - template (std::make_index_sequence()), - int>::type()> - explicit simd(_Generator&& __g) { - __generator_init(std::forward<_Generator>(__g), - std::make_index_sequence()); - } - - // load constructor - template < - class _Up, class _Flags, - class = typename std::enable_if<__vectorizable<_Up>()>::type, - class = typename std::enable_if::value>::type> - simd(const _Up* __buffer, _Flags) { - // TODO: optimize for overaligned flags - for (size_t __i = 0; __i < size(); __i++) { - (*this)[__i] = static_cast<_Tp>(__buffer[__i]); - } - } - - // loads [simd.load] - template - typename std::enable_if<__vectorizable<_Up>() && - is_simd_flag_type<_Flags>::value>::type - copy_from(const _Up* __buffer, _Flags) { - *this = simd(__buffer, _Flags()); - } - - // stores [simd.store] - template - typename std::enable_if<__vectorizable<_Up>() && - is_simd_flag_type<_Flags>::value>::type - copy_to(_Up* __buffer, _Flags) const { - // TODO: optimize for overaligned flags - for (size_t __i = 0; __i < size(); __i++) { - __buffer[__i] = static_cast<_Up>((*this)[__i]); - } - } + // 9.6.6, simd subscript operators + reference operator[](size_t); + value_type operator[](size_t) const; - // scalar access [simd.subscr] - reference operator[](size_t __i) { return reference(&__s_, __i); } - - value_type operator[](size_t __i) const { return __s_.__get(__i); } - - // 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; - -#if 0 - // 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&); -#endif + // 9.6.7, simd unary operators + simd& operator++() noexcept; + simd operator++(int) noexcept; + simd& operator--() noexcept; + simd operator--(int) noexcept; + mask_type operator!() const noexcept; + simd operator~() const noexcept; + simd operator+() const noexcept; + simd operator-() const noexcept; + + // 9.7.1, simd binary operators + friend simd operator+(const simd&, const simd&) noexcept; + friend simd operator-(const simd&, const simd&) noexcept; + friend simd operator*(const simd&, const simd&) noexcept; + friend simd operator/(const simd&, const simd&) noexcept; + friend simd operator%(const simd&, const simd&) noexcept; + friend simd operator&(const simd&, const simd&) noexcept; + friend simd operator|(const simd&, const simd&) noexcept; + friend simd operator^(const simd&, const simd&) noexcept; + friend simd operator<<(const simd&, const simd&) noexcept; + friend simd operator>>(const simd&, const simd&) noexcept; + friend simd operator<<(const simd&, int) noexcept; + friend simd operator>>(const simd&, int) noexcept; + + // 9.7.2, simd compound assignment + friend simd& operator+=(simd&, const simd&) noexcept; + friend simd& operator-=(simd&, const simd&) noexcept; + friend simd& operator*=(simd&, const simd&) noexcept; + friend simd& operator/=(simd&, const simd&) noexcept; + friend simd& operator%=(simd&, const simd&) noexcept; + friend simd& operator&=(simd&, const simd&) noexcept; + friend simd& operator|=(simd&, const simd&) noexcept; + friend simd& operator^=(simd&, const simd&) noexcept; + friend simd& operator<<=(simd&, const simd&) noexcept; + friend simd& operator>>=(simd&, const simd&) noexcept; + friend simd& operator<<=(simd&, int) noexcept; + friend simd& operator>>=(simd&, int) noexcept; + + // 9.7.3, simd compare operators + friend mask_type operator==(const simd&, const simd&) noexcept; + friend mask_type operator!=(const simd&, const simd&) noexcept; + friend mask_type operator>=(const simd&, const simd&) noexcept; + friend mask_type operator<=(const simd&, const simd&) noexcept; + friend mask_type operator>(const simd&, const simd&) noexcept; + friend mask_type operator<(const simd&, const simd&) noexcept; }; -// [simd.mask.class] -template -// TODO: implement simd_mask -class simd_mask { +// 9.8, Class template simd_mask defination +template class simd_mask { public: using value_type = bool; - // TODO: this is strawman implementation. Turn it into a proxy type. - using reference = bool&; + using reference = __simd_reference; 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; + static constexpr size_t size() noexcept { return simd_type::size(); }; - // implicit type conversion constructor - template - simd_mask(const simd_mask<_Up, simd_abi::fixed_size>&) noexcept; + simd_mask() noexcept = default; - // load constructor - template - simd_mask(const value_type*, _Flags); + // 9.8.3, Constructors + explicit simd_mask(value_type) noexcept; + template + simd_mask(const simd_mask<_Up, simd_abi::fixed_size>&) noexcept; + template simd_mask(const value_type* __mem, _Flags); - // loads [simd.mask.copy] - template - void copy_from(const value_type*, _Flags); - template - void copy_to(value_type*, _Flags) const; + // 9.8.4, Copy functions + template void copy_from(const value_type* __mem, _Flags); + template void copy_to(value_type* __mem, _Flags); - // scalar access [simd.mask.subscr] + // 9.8.5, Subscript operators reference operator[](size_t); value_type operator[](size_t) const; - // unary operators [simd.mask.unary] + // 9.8.6, Unary operators simd_mask operator!() const noexcept; -#if 0 - // simd_mask binary operators [simd.mask.binary] + // 9.9.1, Binary operators 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; friend simd_mask operator^(const simd_mask&, const simd_mask&) noexcept; - // simd_mask compound assignment [simd.mask.cassign] + // 9.9.2, Compound assignment 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] + // 9.9.3, Comparisons friend simd_mask operator==(const simd_mask&, const simd_mask&) noexcept; friend simd_mask operator!=(const simd_mask&, const simd_mask&) noexcept; -#endif }; -#endif // _LIBCPP_STD_VER >= 17 _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD +#endif // _LIBCPP_STD_VER >= 17 + _LIBCPP_POP_MACROS #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 diff --git a/libcxx/test/std/experimental/simd/simd.abi/vector_extension.pass.cpp b/libcxx/test/std/experimental/simd/simd.abi/vector_extension.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.abi/vector_extension.pass.cpp +++ /dev/null @@ -1,70 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.abi] - -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -constexpr inline int reg_width() { -#if defined(__AVX__) - return 32; -#else - return 16; -#endif -} - -#ifndef _LIBCPP_HAS_NO_VECTOR_EXTENSION - -static_assert( - sizeof(ex::simd>) == 1, - ""); -static_assert( - sizeof(ex::simd>) == 2, - ""); -static_assert( - sizeof(ex::simd>) == 4, - ""); -static_assert( - sizeof(ex::simd>) == 16, - ""); -static_assert( - sizeof(ex::simd>) == - 16, - ""); -static_assert( - sizeof(ex::simd>) == - 32, - ""); -static_assert( - std::is_same, - ex::__simd_abi>::value, - ""); -#else -static_assert( - std::is_same, - ex::__simd_abi>::value, - ""); - -#endif - -static_assert(std::is_same, - ex::__simd_abi>::value, - ""); - -int main(int, char**) { - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.access/default.pass.cpp b/libcxx/test/std/experimental/simd/simd.access/default.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.access/default.pass.cpp +++ /dev/null @@ -1,220 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// scalar access [simd.subscr] -// reference operator[](size_t); -// value_type operator[](size_t) const; - -#include -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -template -void test_access() { - { - SimdType a(42), b(4); - static_assert(std::is_convertible::value, ""); - - assert(a[0] == 42); - assert(!a[0] == !42); - assert(~a[0] == ~42); - assert(+a[0] == +42); - assert(-a[0] == -42); - assert(a[0] + b[0] == 42 + 4); - assert(a[0] - b[0] == 42 - 4); - assert(a[0] * b[0] == 42 * 4); - assert(a[0] / b[0] == 42 / 4); - assert(a[0] % b[0] == 42 % 4); - assert(a[0] << b[0] == (42 << 4)); - assert(a[0] >> b[0] == (42 >> 4)); - assert((a[0] < b[0]) == false); - assert((a[0] <= b[0]) == false); - assert((a[0] > b[0]) == true); - assert((a[0] >= b[0]) == true); - assert((a[0] == b[0]) == false); - assert((a[0] != b[0]) == true); - assert((a[0] & b[0]) == (42 & 4)); - assert((a[0] | b[0]) == (42 | 4)); - assert((a[0] ^ b[0]) == (42 ^ 4)); - assert((a[0] && b[0]) == true); - assert((a[0] || b[0]) == true); - - { - auto c = a; - ++c[0]; - assert(c[0] == 42 + 1); - assert(c[1] == 42); - } - { - auto c = a; - auto ret = c[0]++; - assert(ret == 42); - assert(c[0] == 42 + 1); - assert(c[1] == 42); - } - { - auto c = a; - --c[0]; - assert(c[0] == 42 - 1); - assert(c[1] == 42); - } - { - auto c = a; - auto ret = c[0]--; - assert(ret == 42); - assert(c[0] == 42 - 1); - assert(c[1] == 42); - } - - { - auto c = a; - c[0] += b[0]; - assert(c[0] == 42 + 4); - assert(c[1] == 42); - } - { - auto c = a; - c[0] -= b[0]; - assert(c[0] == 42 - 4); - assert(c[1] == 42); - } - { - auto c = a; - c[0] *= b[0]; - assert(c[0] == 42 * 4); - assert(c[1] == 42); - } - { - auto c = a; - c[0] /= b[0]; - assert(c[0] == 42 / 4); - assert(c[1] == 42); - } - { - auto c = a; - c[0] %= b[0]; - assert(c[0] == 42 % 4); - assert(c[1] == 42); - } - { - auto c = a; - c[0] >>= b[0]; - assert(c[0] == (42 >> 4)); - assert(c[1] == 42); - } - { - auto c = a; - c[0] <<= b[0]; - assert(c[0] == (42 << 4)); - assert(c[1] == 42); - } - { - auto c = a; - c[0] &= b[0]; - assert(c[0] == (42 & 4)); - assert(c[1] == 42); - } - { - auto c = a; - c[0] |= b[0]; - assert(c[0] == (42 | 4)); - assert(c[1] == 42); - } - { - auto c = a; - c[0] ^= b[0]; - assert(c[0] == (42 ^ 4)); - assert(c[1] == 42); - } - - { - auto c = a; - (void)(a[0] + (c[0] += a[0])); - } - { - auto c = a; - (void)(a[0] + (c[0] -= a[0])); - } - { - auto c = a; - (void)(a[0] + (c[0] *= a[0])); - } - { - auto c = a; - (void)(a[0] + (c[0] /= a[0])); - } - { - auto c = a; - (void)(a[0] + (c[0] %= a[0])); - } - { - auto c = a; - (void)(a[0] + (c[0] >>= b[0])); - } - { - auto c = a; - (void)(a[0] + (c[0] <<= b[0])); - } - { - auto c = a; - (void)(a[0] + (c[0] &= a[0])); - } - { - auto c = a; - (void)(a[0] + (c[0] |= a[0])); - } - { - auto c = a; - (void)(a[0] + (c[0] ^= a[0])); - } - } - { - const SimdType a(42); - const SimdType b(4); - static_assert(std::is_same::value, ""); - - assert(a[0] == 42); - assert(!a[0] == !42); - assert(~a[0] == ~42); - assert(+a[0] == +42); - assert(-a[0] == -42); - assert(a[0] + b[0] == 42 + 4); - assert(a[0] - b[0] == 42 - 4); - assert(a[0] * b[0] == 42 * 4); - assert(a[0] / b[0] == 42 / 4); - assert(a[0] % b[0] == 42 % 4); - assert(a[0] << b[0] == (42 << 4)); - assert(a[0] >> b[0] == (42 >> 4)); - assert((a[0] < b[0]) == false); - assert((a[0] <= b[0]) == false); - assert((a[0] > b[0]) == true); - assert((a[0] >= b[0]) == true); - assert((a[0] == b[0]) == false); - assert((a[0] != b[0]) == true); - assert((a[0] & b[0]) == (42 & 4)); - assert((a[0] | b[0]) == (42 | 4)); - assert((a[0] ^ b[0]) == (42 ^ 4)); - assert((a[0] && b[0]) == true); - assert((a[0] || b[0]) == true); - } -} - -int main(int, char**) { - test_access>(); - test_access>(); - - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp b/libcxx/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp +++ /dev/null @@ -1,49 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.casts] -// template see below ex::simd_cast<(const -// ex::simd&); - -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -static_assert( - std::is_same(ex::native_simd())), - ex::native_simd>::value, - ""); - -static_assert(std::is_same( - ex::fixed_size_simd())), - ex::fixed_size_simd>::value, - ""); - -static_assert( - std::is_same>( - ex::simd())), - ex::fixed_size_simd>::value, - ""); - -static_assert( - std::is_same< - decltype(ex::simd_cast>( - ex::fixed_size_simd())), - ex::simd>::value, - ""); - -int main(int, char**) { - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp b/libcxx/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp +++ /dev/null @@ -1,44 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.casts] -// template see below ex::static_simd_cast<(const -// ex::simd&); - -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -static_assert( - std::is_same(ex::native_simd())), - ex::native_simd>::value, - ""); - -static_assert( - std::is_same>( - ex::simd())), - ex::fixed_size_simd>::value, - ""); - -static_assert( - std::is_same< - decltype(ex::static_simd_cast>( - ex::fixed_size_simd())), - ex::simd>::value, - ""); - -int main(int, char**) { - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.class/simd_width.pass.cpp b/libcxx/test/std/experimental/simd/simd.class/simd_width.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/experimental/simd/simd.class/simd_width.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 + +// +// +// [simd.class] +// static constexpr size_t size() noexcept; + +#include "../test_utils.h" +#include + +namespace ex = std::experimental::parallelism_v2; +struct CheckSimdWidth { + template + void operator()() { + const ex::simd<_Tp, SimdAbi> origin_simd{}; + static_assert(origin_simd.size() == ex::simd_size_v<_Tp, SimdAbi>); + } +}; +template +void test_simd_abi() {} +template +void test_simd_abi() { + F{}.template operator()<_Tp, SimdAbi>(); + test_simd_abi(); +} + +int main(int, char**) { + test_all_simd_abi(); + return 0; +} diff --git a/libcxx/test/std/experimental/simd/simd.cons/broadcast.pass.cpp b/libcxx/test/std/experimental/simd/simd.cons/broadcast.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.cons/broadcast.pass.cpp +++ /dev/null @@ -1,87 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.class] -// template simd(U&& value); - -#include -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -template -auto not_supported_native_simd_ctor(Args&&... args) - -> decltype(ex::native_simd(std::forward(args)...), - void()) = delete; - -template -void not_supported_native_simd_ctor(...) {} - -template -auto supported_native_simd_ctor(Args&&... args) - -> decltype(ex::native_simd(std::forward(args)...), void()) {} - -template -void supported_native_simd_ctor(...) = delete; - -void compile_narrowing_conversion() { - supported_native_simd_ctor(3); - supported_native_simd_ctor(3); - supported_native_simd_ctor(3); - supported_native_simd_ctor(3); - supported_native_simd_ctor(3); - supported_native_simd_ctor(3); - supported_native_simd_ctor(3); - supported_native_simd_ctor(3); - supported_native_simd_ctor(3.f); - supported_native_simd_ctor(3.); - supported_native_simd_ctor(3.); - - not_supported_native_simd_ctor(3.); - not_supported_native_simd_ctor(long(3)); - not_supported_native_simd_ctor(long(3)); - not_supported_native_simd_ctor(3.); -} - -void compile_convertible() { - struct ConvertibleToInt { - operator int64_t() const; - }; - supported_native_simd_ctor(ConvertibleToInt()); - - struct NotConvertibleToInt {}; - not_supported_native_simd_ctor(NotConvertibleToInt()); -} - -void compile_unsigned() { - not_supported_native_simd_ctor(3u); - supported_native_simd_ctor(3u); -} - -template -void test_broadcast() { - SimdType a(3); - for (size_t i = 0; i < a.size(); i++) { - assert(a[i] == 3); - } -} - -int main(int, char**) { - test_broadcast>(); - test_broadcast>(); - test_broadcast>(); - - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.cons/default.pass.cpp b/libcxx/test/std/experimental/simd/simd.cons/default.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.cons/default.pass.cpp +++ /dev/null @@ -1,31 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.class] -// simd() = default; - -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -int main(int, char**) { - static_assert(ex::native_simd().size() > 0, ""); - static_assert(ex::fixed_size_simd().size() == 4, ""); - static_assert(ex::fixed_size_simd().size() == 5, ""); - static_assert(ex::fixed_size_simd().size() == 1, ""); - static_assert(ex::fixed_size_simd().size() == 32, ""); - - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.cons/generator.pass.cpp b/libcxx/test/std/experimental/simd/simd.cons/generator.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.cons/generator.pass.cpp +++ /dev/null @@ -1,92 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.class] -// template explicit simd(G&& gen); - -#include -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -template -auto not_supported_simd128_ctor(Args&&... args) -> decltype( - ex::fixed_size_simd(std::forward(args)...), - void()) = delete; - -template -void not_supported_simd128_ctor(...) {} - -template -auto supported_simd128_ctor(Args&&... args) -> decltype( - ex::fixed_size_simd(std::forward(args)...), - void()) {} - -template -void supported_simd128_ctor(...) = delete; - -struct identity { - template - int operator()(std::integral_constant) const { - return value; - } -}; - -void compile_generator() { - supported_simd128_ctor(identity()); - not_supported_simd128_ctor([](int i) { return float(i); }); - not_supported_simd128_ctor([](intptr_t i) { return (int*)(i); }); - not_supported_simd128_ctor([](int* i) { return i; }); -} - -struct limited_identity { - template - typename std::conditional::type - operator()(std::integral_constant) const { - return value; - } -}; - -void compile_limited_identity() { - supported_simd128_ctor(limited_identity()); - not_supported_simd128_ctor(limited_identity()); -} - -template -void test_generator() { - { - SimdType a([](int i) { return i; }); - assert(a[0] == 0); - assert(a[1] == 1); - assert(a[2] == 2); - assert(a[3] == 3); - } - { - SimdType a([](int i) { return 2 * i - 1; }); - assert(a[0] == -1); - assert(a[1] == 1); - assert(a[2] == 3); - assert(a[3] == 5); - } -} - -int main(int, char**) { - // TODO: adjust the tests when this assertion fails. - assert(ex::native_simd::size() >= 4); - test_generator>(); - test_generator>(); - - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.cons/load.pass.cpp b/libcxx/test/std/experimental/simd/simd.cons/load.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.cons/load.pass.cpp +++ /dev/null @@ -1,120 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.class] -// template simd(const U* mem, Flags f); - -#include -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -template -auto not_supported_native_simd_ctor(Args&&... args) - -> decltype(ex::native_simd(std::forward(args)...), - void()) = delete; - -template -void not_supported_native_simd_ctor(...) {} - -template -auto supported_native_simd_ctor(Args&&... args) - -> decltype(ex::native_simd(std::forward(args)...), void()) {} - -template -void supported_native_simd_ctor(...) = delete; - -void compile_load_ctor() { - supported_native_simd_ctor((int*)nullptr, ex::element_aligned_tag()); - supported_native_simd_ctor((int*)nullptr, - ex::element_aligned_tag()); - supported_native_simd_ctor((float*)nullptr, - ex::element_aligned_tag()); - supported_native_simd_ctor((unsigned int*)nullptr, - ex::element_aligned_tag()); - supported_native_simd_ctor((float*)nullptr, - ex::element_aligned_tag()); - - not_supported_native_simd_ctor((int*)nullptr, int()); -} - -template -void test_load_ctor() { - alignas(32) int32_t buffer[] = {4, 3, 2, 1}; - { - SimdType a(buffer, ex::element_aligned_tag()); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } - { - SimdType a(buffer, ex::vector_aligned_tag()); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } - { - SimdType a(buffer, ex::overaligned_tag<32>()); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } - - { - SimdType a(buffer, ex::element_aligned); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } - { - SimdType a(buffer, ex::vector_aligned); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } - { - SimdType a(buffer, ex::overaligned<32>); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } -} - -template -void test_converting_load_ctor() { - float buffer[] = {1., 2., 4., 8.}; - SimdType a(buffer, ex::element_aligned_tag()); - assert(a[0] == 1); - assert(a[1] == 2); - assert(a[2] == 4); - assert(a[3] == 8); -} - -int main(int, char**) { - // TODO: adjust the tests when this assertion fails. - assert(ex::native_simd::size() >= 4); - test_load_ctor>(); - test_load_ctor>(); - test_converting_load_ctor>(); - test_converting_load_ctor>(); - - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_width.pass.cpp b/libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_width.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_width.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 + +// +// +// [simd.mask.class] +// static constexpr size_t size() noexcept; + +#include "../test_utils.h" +#include + +namespace ex = std::experimental::parallelism_v2; +struct CheckSimdMaskWidth { + template + void operator()() { + const ex::simd_mask<_Tp, SimdAbi> origin_simd_mask{}; + static_assert(origin_simd_mask.size() == ex::simd_size_v<_Tp, SimdAbi>); + } +}; +template +void test_simd_abi() {} +template +void test_simd_abi() { + F{}.template operator()<_Tp, SimdAbi>(); + test_simd_abi(); +} + +int main(int, char**) { + test_all_simd_abi(); + return 0; +} diff --git a/libcxx/test/std/experimental/simd/simd.mem/load.pass.cpp b/libcxx/test/std/experimental/simd/simd.mem/load.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.mem/load.pass.cpp +++ /dev/null @@ -1,124 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// loads [simd.load] -// template void copy_from(const U* mem, Flags f); - -#include -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -template -auto not_supported_load(Args&&... args) -> decltype( - std::declval>().copy_from(std::forward(args)...), - void()) = delete; - -template -void not_supported_load(...) {} - -template -auto supported_load(Args&&... args) -> decltype( - std::declval>().copy_from(std::forward(args)...), - void()) {} - -template -void supported_load(...) = delete; - -void compile_load() { - supported_load((int*)nullptr, ex::element_aligned_tag()); - supported_load((int*)nullptr, ex::element_aligned_tag()); - supported_load((float*)nullptr, ex::element_aligned_tag()); - supported_load((unsigned int*)nullptr, ex::element_aligned_tag()); - supported_load((float*)nullptr, ex::element_aligned_tag()); - - not_supported_load((int*)nullptr, int()); -} - -template -void test_load() { - alignas(32) int32_t buffer[] = {4, 3, 2, 1}; - { - SimdType a; - a.copy_from(buffer, ex::element_aligned_tag()); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } - { - SimdType a; - a.copy_from(buffer, ex::vector_aligned_tag()); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } - { - SimdType a; - a.copy_from(buffer, ex::overaligned_tag<32>()); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } - - { - SimdType a; - a.copy_from(buffer, ex::element_aligned); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } - { - SimdType a; - a.copy_from(buffer, ex::vector_aligned); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } - { - SimdType a; - a.copy_from(buffer, ex::overaligned<32>); - assert(a[0] == 4); - assert(a[1] == 3); - assert(a[2] == 2); - assert(a[3] == 1); - } -} - -template -void test_converting_load() { - float buffer[] = {1., 2., 4., 8.}; - SimdType a; - a.copy_from(buffer, ex::element_aligned_tag()); - assert(a[0] == 1); - assert(a[1] == 2); - assert(a[2] == 4); - assert(a[3] == 8); -} - -int main(int, char**) { - // TODO: adjust the tests when this assertion fails. - assert(ex::native_simd::size() >= 4); - test_load>(); - test_load>(); - test_converting_load>(); - test_converting_load>(); - - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.mem/store.pass.cpp b/libcxx/test/std/experimental/simd/simd.mem/store.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.mem/store.pass.cpp +++ /dev/null @@ -1,97 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// // stores [simd.store] -// template void copy_to(U* mem, Flags f) const; - -#include -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -template -void test_store() { - SimdType a([](int i) { return 4 - i; }); - { - alignas(32) int32_t buffer[4] = {0}; - a.copy_to(buffer, ex::element_aligned_tag()); - assert(buffer[0] == 4); - assert(buffer[1] == 3); - assert(buffer[2] == 2); - assert(buffer[3] == 1); - } - { - alignas(32) int32_t buffer[4] = {0}; - a.copy_to(buffer, ex::vector_aligned_tag()); - assert(buffer[0] == 4); - assert(buffer[1] == 3); - assert(buffer[2] == 2); - assert(buffer[3] == 1); - } - { - alignas(32) int32_t buffer[4] = {0}; - a.copy_to(buffer, ex::overaligned_tag<32>()); - assert(buffer[0] == 4); - assert(buffer[1] == 3); - assert(buffer[2] == 2); - assert(buffer[3] == 1); - } - - { - alignas(32) int32_t buffer[4] = {0}; - a.copy_to(buffer, ex::element_aligned); - assert(buffer[0] == 4); - assert(buffer[1] == 3); - assert(buffer[2] == 2); - assert(buffer[3] == 1); - } - { - alignas(32) int32_t buffer[4] = {0}; - a.copy_to(buffer, ex::vector_aligned); - assert(buffer[0] == 4); - assert(buffer[1] == 3); - assert(buffer[2] == 2); - assert(buffer[3] == 1); - } - { - alignas(32) int32_t buffer[4] = {0}; - a.copy_to(buffer, ex::overaligned<32>); - assert(buffer[0] == 4); - assert(buffer[1] == 3); - assert(buffer[2] == 2); - assert(buffer[3] == 1); - } -} - -template -void test_converting_store() { - float buffer[4] = {0.}; - SimdType a([](int i) { return 1 << i; }); - a.copy_to(buffer, ex::element_aligned_tag()); - assert(buffer[0] == 1.); - assert(buffer[1] == 2.); - assert(buffer[2] == 4.); - assert(buffer[3] == 8.); -} - -int main(int, char**) { - // TODO: adjust the tests when this assertion fails. - test_store>(); - test_store>(); - test_converting_store>(); - test_converting_store>(); - - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.traits/abi_for_size.pass.cpp b/libcxx/test/std/experimental/simd/simd.traits/abi_for_size.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.traits/abi_for_size.pass.cpp +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.traits] -// template struct abi_for_size { using type = see below ; -// }; template using ex::abi_for_size_t = typename -// ex::abi_for_size::type; - -#include -#include - -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -static_assert(std::is_same::type, - ex::simd_abi::fixed_size<4>>::value, - ""); - -static_assert(std::is_same, - ex::simd_abi::fixed_size<4>>::value, - ""); - -int main(int, char**) { - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.traits/is_abi_tag.pass.cpp b/libcxx/test/std/experimental/simd/simd.traits/is_abi_tag.pass.cpp --- a/libcxx/test/std/experimental/simd/simd.traits/is_abi_tag.pass.cpp +++ b/libcxx/test/std/experimental/simd/simd.traits/is_abi_tag.pass.cpp @@ -12,103 +12,67 @@ // // [simd.traits] // template struct is_abi_tag; -// template inline constexpr bool ex::is_abi_tag_v = -// ex::is_abi_tag::value; +// template inline constexpr bool ex::is_abi_tag_v = ex::is_abi_tag::value; +#include "../test_utils.h" #include #include -#include "test_macros.h" namespace ex = std::experimental::parallelism_v2; -struct UserType {}; - -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); - -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); - -static_assert(ex::is_abi_tag::value, ""); -static_assert( - !std::is_same>::value, - ""); - -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); -static_assert(ex::is_abi_tag>::value, ""); - -static_assert(!ex::is_abi_tag::value, ""); -static_assert(!ex::is_abi_tag::value, ""); -static_assert(!ex::is_abi_tag::value, ""); -static_assert(!ex::is_abi_tag::value, ""); -static_assert(!ex::is_abi_tag>::value, ""); -static_assert(!ex::is_abi_tag>::value, ""); -static_assert(!ex::is_abi_tag>::value, ""); -static_assert(!ex::is_abi_tag>::value, ""); - -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); - -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); - -static_assert(ex::is_abi_tag_v, ""); -static_assert( - !std::is_same>::value, - ""); - -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); -static_assert(ex::is_abi_tag_v>, ""); - -static_assert(!ex::is_abi_tag_v, ""); -static_assert(!ex::is_abi_tag_v, ""); -static_assert(!ex::is_abi_tag_v, ""); -static_assert(!ex::is_abi_tag_v, ""); -static_assert(!ex::is_abi_tag_v>, ""); -static_assert(!ex::is_abi_tag_v>, ""); -static_assert(!ex::is_abi_tag_v>, ""); -static_assert(!ex::is_abi_tag_v>, ""); +struct CheckIsAbiTagTrue { + template + void operator()() { + static_assert(_Tp::value); + } +}; + +struct CheckIsAbiTagFalse { + template + void operator()() { + static_assert(!_Tp::value); + } +}; + +struct CheckIsAbiTagVTrue { + template + void operator()() { + static_assert(_Tp); + } +}; + +struct CheckIsAbiTagVFalse { + template + void operator()() { + static_assert(!_Tp); + } +}; + +template +void test_simd_abi() {} +template +void test_simd_abi() { + if constexpr (std::is_same::value) { + F{}.template operator()>(); + } else if constexpr (std::is_same::value) { + F{}.template operator()>(); + F{}.template operator()>>(); + F{}.template operator()>>(); + } else if constexpr (std::is_same::value) { + F{}.template operator()>(); + } else { + F{}.template operator()>(); + F{}.template operator()>>(); + F{}.template operator()>>(); + } + + test_simd_abi(); +} int main(int, char**) { + test_all_simd_abi(); + test_all_simd_abi(); + test_all_simd_abi(); + test_all_simd_abi(); return 0; } diff --git a/libcxx/test/std/experimental/simd/simd.traits/is_simd.pass.cpp b/libcxx/test/std/experimental/simd/simd.traits/is_simd.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.traits/is_simd.pass.cpp +++ /dev/null @@ -1,130 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.traits] -// template struct ex::is_simd; -// template inline constexpr bool ex::is_simd_v = -// ex::is_simd::value; - -#include -#include -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -struct UserType {}; - -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); - -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); - -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); - -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); -static_assert(ex::is_simd>::value, ""); - -static_assert(!ex::is_simd::value, ""); -static_assert(!ex::is_simd::value, ""); -static_assert(!ex::is_simd::value, ""); -static_assert(!ex::is_simd>::value, ""); -static_assert(!ex::is_simd>::value, ""); -static_assert(!ex::is_simd::value, ""); - -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); - -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); - -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); - -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); -static_assert(ex::is_simd_v>, ""); - -static_assert(!ex::is_simd_v, ""); -static_assert(!ex::is_simd_v, ""); -static_assert(!ex::is_simd_v, ""); -static_assert(!ex::is_simd_v>, ""); -static_assert(!ex::is_simd_v>, ""); -static_assert(!ex::is_simd_v, ""); - -int main(int, char**) { - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.traits/is_simd_flag_type.pass.cpp b/libcxx/test/std/experimental/simd/simd.traits/is_simd_flag_type.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.traits/is_simd_flag_type.pass.cpp +++ /dev/null @@ -1,52 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.traits] -// template struct is_simd_flag_type; -// template inline constexpr bool ex::is_simd_flag_type_v = -// ex::is_simd_flag_type::value; - -#include -#include -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -struct UserType {}; - -static_assert(ex::is_simd_flag_type::value, ""); -static_assert(ex::is_simd_flag_type::value, ""); -static_assert(ex::is_simd_flag_type>::value, ""); -static_assert(ex::is_simd_flag_type>::value, ""); - -static_assert(!ex::is_simd_flag_type::value, ""); -static_assert(!ex::is_simd_flag_type::value, ""); -static_assert(!ex::is_simd_flag_type::value, ""); -static_assert(!ex::is_simd_flag_type::value, ""); -static_assert(!ex::is_simd_flag_type>::value, ""); -static_assert(!ex::is_simd_flag_type>::value, ""); - -static_assert(ex::is_simd_flag_type_v, ""); -static_assert(ex::is_simd_flag_type_v, ""); -static_assert(ex::is_simd_flag_type_v>, ""); -static_assert(ex::is_simd_flag_type_v>, ""); - -static_assert(!ex::is_simd_flag_type_v, ""); -static_assert(!ex::is_simd_flag_type_v, ""); -static_assert(!ex::is_simd_flag_type_v, ""); -static_assert(!ex::is_simd_flag_type_v, ""); -static_assert(!ex::is_simd_flag_type_v>, ""); -static_assert(!ex::is_simd_flag_type_v>, ""); - -int main(int, char**) { - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.traits/is_simd_mask.pass.cpp b/libcxx/test/std/experimental/simd/simd.traits/is_simd_mask.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/experimental/simd/simd.traits/is_simd_mask.pass.cpp +++ /dev/null @@ -1,153 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++03, c++11, c++14 - -// -// -// [simd.traits] -// template struct ex::is_simd_mask; -// template inline constexpr bool ex::is_simd_mask_v = -// ex::is_simd_mask::value; - -#include -#include -#include "test_macros.h" - -namespace ex = std::experimental::parallelism_v2; - -struct UserType {}; - -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); - -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); - -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, ""); - -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, - ""); -static_assert(ex::is_simd_mask>::value, ""); -static_assert(ex::is_simd_mask>::value, - ""); - -static_assert(!ex::is_simd_mask::value, ""); -static_assert(!ex::is_simd_mask::value, ""); -static_assert(!ex::is_simd_mask::value, ""); -static_assert(!ex::is_simd_mask>::value, ""); -static_assert(!ex::is_simd_mask>::value, ""); -static_assert(!ex::is_simd_mask::value, ""); - -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); - -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); - -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); - -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); -static_assert(ex::is_simd_mask_v>, ""); - -static_assert(!ex::is_simd_mask_v, ""); -static_assert(!ex::is_simd_mask_v, ""); -static_assert(!ex::is_simd_mask_v, ""); -static_assert(!ex::is_simd_mask_v>, ""); -static_assert(!ex::is_simd_mask_v>, ""); -static_assert(!ex::is_simd_mask_v, ""); - -int main(int, char**) { - return 0; -} diff --git a/libcxx/test/std/experimental/simd/simd.traits/simd_size.pass.cpp b/libcxx/test/std/experimental/simd/simd.traits/simd_size.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/experimental/simd/simd.traits/simd_size.pass.cpp @@ -0,0 +1,116 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 + +// +// +// [simd.traits] +//template > struct simd_size; +//template > +//inline constexpr size_t ex::simd_size_v = ex::simd_size::value; + +#include "../test_utils.h" +#include + +namespace ex = std::experimental::parallelism_v2; + +struct CheckSimdSizeDeduce { + template > + void operator()() { + static_assert(ex::simd_size<_Tp, SimdAbi>::value == _Np); + }; +}; +struct CheckSimdSizeVDeduce { + template > + void operator()() { + static_assert(ex::simd_size_v<_Tp, SimdAbi> == _Np); + }; +}; +struct CheckSimdSizeFixedSize { + template > + void operator()() { + static_assert(ex::simd_size<_Tp, SimdAbi>::value == _Np); + }; +}; +struct CheckSimdSizeVFixedSize { + template > + void operator()() { + static_assert(ex::simd_size_v<_Tp, SimdAbi> == _Np); + }; +}; + +struct CheckSimdSizeScalar { + template + void operator()() { + static_assert(ex::simd_size<_Tp, SimdAbi>::value == 1); + }; +}; +struct CheckSimdSizeVScalar { + template + void operator()() { + static_assert(ex::simd_size_v<_Tp, SimdAbi> == 1); + }; +}; +struct CheckSimdSizeCompatible { + template > + void operator()() { + static_assert(ex::simd_size<_Tp, SimdAbi>::value == 16 / sizeof(_Tp)); + }; +}; +struct CheckSimdSizeVCompatible { + template > + void operator()() { + static_assert(ex::simd_size_v<_Tp, SimdAbi> == 16 / sizeof(_Tp)); + }; +}; + +struct CheckSimdSizeNative { + template > + void operator()() { + static_assert(ex::simd_size<_Tp, SimdAbi>::value == _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)); + }; +}; +struct CheckSimdSizeVNative { + template > + void operator()() { + static_assert(ex::simd_size_v<_Tp, SimdAbi> == _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)); + }; +}; + +template +void test_simd_abi() {} +template +void test_simd_abi() { + if constexpr (std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value) { + F{}.template operator()<_Tp, _Np>(); + } else { + F{}.template operator()<_Tp>(); + } + test_simd_abi(); +} + +int main(int, char**) { + test_all_simd_abi(); + test_all_simd_abi(); + + test_all_simd_abi(); + test_all_simd_abi(); + + test_all_simd_abi(); + test_all_simd_abi(); + + test_all_simd_abi(); + test_all_simd_abi(); + + test_all_simd_abi(); + test_all_simd_abi(); + + return 0; +} diff --git a/libcxx/test/std/experimental/simd/test_utils.h b/libcxx/test/std/experimental/simd/test_utils.h new file mode 100644 --- /dev/null +++ b/libcxx/test/std/experimental/simd/test_utils.h @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef TEST_UTIL_H +#define TEST_UTIL_H + +#include +#include + +namespace ex = std::experimental::parallelism_v2; + +template +void test_simd_abi(); + +template +void test_all_simd_abi(std::integer_sequence) { + using namespace ex; + + (test_simd_abi, + simd_abi::fixed_size<_Np + 1>, + simd_abi::scalar, + simd_abi::compatible<_Tp>, + simd_abi::deduce_t<_Tp, _Np + 1>>(), + ...); +} + +template +void test_all_simd_abi() { + constexpr auto integer_seq_from_make_integer = std::make_integer_sequence(); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); + test_all_simd_abi(integer_seq_from_make_integer); +} +#endif // TEST_UTIL_H