25#ifndef _GLIBCXX_EXPERIMENTAL_SIMD_H
26#define _GLIBCXX_EXPERIMENTAL_SIMD_H
28#if __cplusplus >= 201703L
30#include "simd_detail.h"
34#ifdef _GLIBCXX_DEBUG_UB
42#if _GLIBCXX_SIMD_X86INTRIN
44#elif _GLIBCXX_SIMD_HAVE_NEON
71_GLIBCXX_SIMD_BEGIN_NAMESPACE
73#if !_GLIBCXX_SIMD_X86INTRIN
74using __m128 [[__gnu__::__vector_size__(16)]] = float;
75using __m128d [[__gnu__::__vector_size__(16)]] = double;
76using __m128i [[__gnu__::__vector_size__(16)]] =
long long;
77using __m256 [[__gnu__::__vector_size__(32)]] = float;
78using __m256d [[__gnu__::__vector_size__(32)]] = double;
79using __m256i [[__gnu__::__vector_size__(32)]] =
long long;
80using __m512 [[__gnu__::__vector_size__(64)]] = float;
81using __m512d [[__gnu__::__vector_size__(64)]] = double;
82using __m512i [[__gnu__::__vector_size__(64)]] =
long long;
104template <
int _UsedBytes>
107template <
int _UsedBytes>
108 struct _VecBltnBtmsk;
110template <
typename _Tp,
int _Np>
111 using _VecN = _VecBuiltin<
sizeof(_Tp) * _Np>;
113template <
int _UsedBytes = 16>
114 using _Sse = _VecBuiltin<_UsedBytes>;
116template <
int _UsedBytes = 32>
117 using _Avx = _VecBuiltin<_UsedBytes>;
119template <
int _UsedBytes = 64>
120 using _Avx512 = _VecBltnBtmsk<_UsedBytes>;
122template <
int _UsedBytes = 16>
123 using _Neon = _VecBuiltin<_UsedBytes>;
128using __avx512 = _Avx512<>;
129using __neon = _Neon<>;
130using __neon128 = _Neon<16>;
131using __neon64 = _Neon<8>;
134template <
typename _Tp,
size_t _Np,
typename...>
138 using fixed_size = _Fixed<_Np>;
140using scalar = _Scalar;
145template <
typename _Tp>
148template <
typename _Tp>
151template <
typename _Tp,
typename _Abi>
154template <
typename _Tp,
typename _Abi>
157template <
typename _Tp,
typename _Abi>
162struct element_aligned_tag
164 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
165 static constexpr size_t _S_alignment =
alignof(_Up);
167 template <
typename _Tp,
typename _Up>
168 _GLIBCXX_SIMD_INTRINSIC
static constexpr _Up*
173struct vector_aligned_tag
175 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
176 static constexpr size_t _S_alignment
177 = std::__bit_ceil(
sizeof(_Up) * _Tp::size());
179 template <
typename _Tp,
typename _Up>
180 _GLIBCXX_SIMD_INTRINSIC
static constexpr _Up*
182 {
return static_cast<_Up*
>(__builtin_assume_aligned(__ptr, _S_alignment<_Tp, _Up>)); }
185template <
size_t _Np>
struct overaligned_tag
187 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
188 static constexpr size_t _S_alignment = _Np;
190 template <
typename _Tp,
typename _Up>
191 _GLIBCXX_SIMD_INTRINSIC
static constexpr _Up*
193 {
return static_cast<_Up*
>(__builtin_assume_aligned(__ptr, _Np)); }
196inline constexpr element_aligned_tag element_aligned = {};
198inline constexpr vector_aligned_tag vector_aligned = {};
201 inline constexpr overaligned_tag<_Np> overaligned = {};
205 using _SizeConstant = integral_constant<size_t, _Xp>;
211 template <
typename _Tp>
212 _GLIBCXX_SIMD_INTRINSIC
constexpr
214 operator()(_Tp __a, _Tp __b)
const
217 return min(__a, __b);
223 template <
typename _Tp>
224 _GLIBCXX_SIMD_INTRINSIC
constexpr
226 operator()(_Tp __a, _Tp __b)
const
229 return max(__a, __b);
236template <
typename _Fp,
size_t... _I>
237 _GLIBCXX_SIMD_INTRINSIC
constexpr void
238 __execute_on_index_sequence(_Fp&& __f, index_sequence<_I...>)
239 { ((void)__f(_SizeConstant<_I>()), ...); }
241template <
typename _Fp>
242 _GLIBCXX_SIMD_INTRINSIC
constexpr void
243 __execute_on_index_sequence(_Fp&&, index_sequence<>)
246template <
size_t _Np,
typename _Fp>
247 _GLIBCXX_SIMD_INTRINSIC
constexpr void
248 __execute_n_times(_Fp&& __f)
250 __execute_on_index_sequence(
static_cast<_Fp&&
>(__f),
251 make_index_sequence<_Np>{});
256template <
typename _R,
typename _Fp,
size_t... _I>
257 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
258 __execute_on_index_sequence_with_return(_Fp&& __f, index_sequence<_I...>)
259 {
return _R{__f(_SizeConstant<_I>())...}; }
261template <
size_t _Np,
typename _R,
typename _Fp>
262 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
263 __generate_from_n_evaluations(_Fp&& __f)
265 return __execute_on_index_sequence_with_return<_R>(
266 static_cast<_Fp&&
>(__f), make_index_sequence<_Np>{});
271template <
size_t... _I,
typename _F0,
typename _FArgs>
272 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
273 __call_with_n_evaluations(index_sequence<_I...>, _F0&& __f0, _FArgs&& __fargs)
274 {
return __f0(__fargs(_SizeConstant<_I>())...); }
276template <
size_t _Np,
typename _F0,
typename _FArgs>
277 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
278 __call_with_n_evaluations(_F0&& __f0, _FArgs&& __fargs)
280 return __call_with_n_evaluations(make_index_sequence<_Np>{},
281 static_cast<_F0&&
>(__f0),
282 static_cast<_FArgs&&
>(__fargs));
287template <
size_t _First = 0,
size_t... _It,
typename _Tp,
typename _Fp>
288 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
289 __call_with_subscripts(_Tp&& __x, index_sequence<_It...>, _Fp&& __fun)
290 {
return __fun(__x[_First + _It]...); }
292template <
size_t _Np,
size_t _First = 0,
typename _Tp,
typename _Fp>
293 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
294 __call_with_subscripts(_Tp&& __x, _Fp&& __fun)
296 return __call_with_subscripts<_First>(
static_cast<_Tp&&
>(__x),
297 make_index_sequence<_Np>(),
298 static_cast<_Fp&&
>(__fun));
305using _UChar =
unsigned char;
306using _SChar =
signed char;
307using _UShort =
unsigned short;
308using _UInt =
unsigned int;
309using _ULong =
unsigned long;
310using _ULLong =
unsigned long long;
311using _LLong =
long long;
315template <
typename _T0,
typename...>
316 struct __first_of_pack
317 {
using type = _T0; };
319template <
typename... _Ts>
320 using __first_of_pack_t =
typename __first_of_pack<_Ts...>::type;
324template <
typename _Tp>
325 typename _Tp::value_type
326 __value_type_or_identity_impl(
int);
328template <
typename _Tp>
330 __value_type_or_identity_impl(
float);
332template <
typename _Tp>
333 using __value_type_or_identity_t
334 =
decltype(__value_type_or_identity_impl<_Tp>(
int()));
338template <
typename _Tp>
339 struct __is_vectorizable :
public is_arithmetic<_Tp> {};
342 struct __is_vectorizable<bool> :
public false_type {};
344template <
typename _Tp>
345 inline constexpr bool __is_vectorizable_v = __is_vectorizable<_Tp>::value;
348template <
typename _Tp,
typename = enable_if_t<__is_vectorizable_v<_Tp>>>
349 using _Vectorizable = _Tp;
353template <
typename _Ptr,
typename _ValueType>
354 struct __is_possible_loadstore_conversion
355 : conjunction<__is_vectorizable<_Ptr>, __is_vectorizable<_ValueType>> {};
358 struct __is_possible_loadstore_conversion<bool, bool> :
true_type {};
361template <
typename _Ptr,
typename _ValueType,
363 __is_possible_loadstore_conversion<_Ptr, _ValueType>::value>>
364 using _LoadStorePtr = _Ptr;
368template <
typename _Tp,
typename =
void_t<>>
371template <
typename _Tp>
372 inline constexpr bool __is_bitmask_v = __is_bitmask<_Tp>::value;
375template <
typename _Tp>
376 struct __is_bitmask<_Tp,
377 void_t<decltype(
declval<unsigned&>() = declval<_Tp>() & 1u)>>
382#pragma GCC diagnostic push
383#pragma GCC diagnostic ignored "-Wpedantic"
384template <
size_t _Bytes>
388 if constexpr (_Bytes ==
sizeof(int))
391 else if constexpr (_Bytes ==
sizeof(char))
394 else if constexpr (_Bytes ==
sizeof(_SChar))
397 else if constexpr (_Bytes ==
sizeof(short))
400 else if constexpr (_Bytes ==
sizeof(long))
403 else if constexpr (_Bytes ==
sizeof(_LLong))
405 #ifdef __SIZEOF_INT128__
406 else if constexpr (_Bytes ==
sizeof(__int128))
409 else if constexpr (_Bytes %
sizeof(int) == 0)
411 constexpr size_t _Np = _Bytes /
sizeof(int);
416 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
419 return __generate_from_n_evaluations<_Np, _Ip>(
420 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
421 return __rhs._M_data[__i] & _M_data[__i];
425 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
428 return __generate_from_n_evaluations<_Np, _Ip>(
429 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
430 return __rhs._M_data[__i] | _M_data[__i];
434 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
437 return __generate_from_n_evaluations<_Np, _Ip>(
438 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
439 return __rhs._M_data[__i] ^ _M_data[__i];
443 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
446 return __generate_from_n_evaluations<_Np, _Ip>(
447 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return ~_M_data[__i]; });
453 static_assert(_Bytes != _Bytes,
"this should be unreachable");
455#pragma GCC diagnostic pop
457template <
typename _Tp>
458 using __int_for_sizeof_t =
decltype(__int_for_sizeof<sizeof(_Tp)>());
461 using __int_with_sizeof_t =
decltype(__int_for_sizeof<_Np>());
465template <
typename _Tp>
469 struct __is_fixed_size_abi<simd_abi::fixed_size<_Np>> :
true_type {};
471template <
typename _Tp>
472 inline constexpr bool __is_fixed_size_abi_v = __is_fixed_size_abi<_Tp>::value;
476constexpr inline bool __have_mmx = _GLIBCXX_SIMD_HAVE_MMX;
477constexpr inline bool __have_sse = _GLIBCXX_SIMD_HAVE_SSE;
478constexpr inline bool __have_sse2 = _GLIBCXX_SIMD_HAVE_SSE2;
479constexpr inline bool __have_sse3 = _GLIBCXX_SIMD_HAVE_SSE3;
480constexpr inline bool __have_ssse3 = _GLIBCXX_SIMD_HAVE_SSSE3;
481constexpr inline bool __have_sse4_1 = _GLIBCXX_SIMD_HAVE_SSE4_1;
482constexpr inline bool __have_sse4_2 = _GLIBCXX_SIMD_HAVE_SSE4_2;
483constexpr inline bool __have_xop = _GLIBCXX_SIMD_HAVE_XOP;
484constexpr inline bool __have_avx = _GLIBCXX_SIMD_HAVE_AVX;
485constexpr inline bool __have_avx2 = _GLIBCXX_SIMD_HAVE_AVX2;
486constexpr inline bool __have_bmi = _GLIBCXX_SIMD_HAVE_BMI1;
487constexpr inline bool __have_bmi2 = _GLIBCXX_SIMD_HAVE_BMI2;
488constexpr inline bool __have_lzcnt = _GLIBCXX_SIMD_HAVE_LZCNT;
489constexpr inline bool __have_sse4a = _GLIBCXX_SIMD_HAVE_SSE4A;
490constexpr inline bool __have_fma = _GLIBCXX_SIMD_HAVE_FMA;
491constexpr inline bool __have_fma4 = _GLIBCXX_SIMD_HAVE_FMA4;
492constexpr inline bool __have_f16c = _GLIBCXX_SIMD_HAVE_F16C;
493constexpr inline bool __have_popcnt = _GLIBCXX_SIMD_HAVE_POPCNT;
494constexpr inline bool __have_avx512f = _GLIBCXX_SIMD_HAVE_AVX512F;
495constexpr inline bool __have_avx512dq = _GLIBCXX_SIMD_HAVE_AVX512DQ;
496constexpr inline bool __have_avx512vl = _GLIBCXX_SIMD_HAVE_AVX512VL;
497constexpr inline bool __have_avx512bw = _GLIBCXX_SIMD_HAVE_AVX512BW;
498constexpr inline bool __have_avx512dq_vl = __have_avx512dq && __have_avx512vl;
499constexpr inline bool __have_avx512bw_vl = __have_avx512bw && __have_avx512vl;
501constexpr inline bool __have_neon = _GLIBCXX_SIMD_HAVE_NEON;
502constexpr inline bool __have_neon_a32 = _GLIBCXX_SIMD_HAVE_NEON_A32;
503constexpr inline bool __have_neon_a64 = _GLIBCXX_SIMD_HAVE_NEON_A64;
504constexpr inline bool __support_neon_float =
505#if defined __GCC_IEC_559
507#elif defined __FAST_MATH__
514constexpr inline bool __have_power10vec =
true;
516constexpr inline bool __have_power10vec =
false;
518#ifdef __POWER9_VECTOR__
519constexpr inline bool __have_power9vec =
true;
521constexpr inline bool __have_power9vec =
false;
523#if defined __POWER8_VECTOR__
524constexpr inline bool __have_power8vec =
true;
526constexpr inline bool __have_power8vec = __have_power9vec;
529constexpr inline bool __have_power_vsx =
true;
531constexpr inline bool __have_power_vsx = __have_power8vec;
533#if defined __ALTIVEC__
534constexpr inline bool __have_power_vmx =
true;
536constexpr inline bool __have_power_vmx = __have_power_vsx;
541template <
typename _Abi>
544 {
return is_same_v<simd_abi::scalar, _Abi>; }
548template <
template <
int>
class _Abi,
int _Bytes>
550 __abi_bytes_impl(_Abi<_Bytes>*)
553template <
typename _Tp>
555 __abi_bytes_impl(_Tp*)
558template <
typename _Abi>
559 inline constexpr int __abi_bytes_v
560 = __abi_bytes_impl(
static_cast<_Abi*
>(
nullptr));
564template <
typename _Abi>
566 __is_builtin_bitmask_abi()
567 {
return is_same_v<simd_abi::_VecBltnBtmsk<__abi_bytes_v<_Abi>>, _Abi>; }
571template <
typename _Abi>
575 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
576 return _Bytes <= 16 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
581template <
typename _Abi>
585 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
586 return _Bytes > 16 && _Bytes <= 32
587 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
592template <
typename _Abi>
596 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
597 return _Bytes <= 64 && is_same_v<simd_abi::_Avx512<_Bytes>, _Abi>;
602template <
typename _Abi>
606 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
607 return _Bytes <= 16 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
612template <
typename,
typename _Up>
613 struct __make_dependent
614 {
using type = _Up; };
616template <
typename _Tp,
typename _Up>
617 using __make_dependent_t =
typename __make_dependent<_Tp, _Up>::type;
623template <
typename... _Args>
624 [[noreturn]] _GLIBCXX_SIMD_ALWAYS_INLINE
void
625 __invoke_ub([[maybe_unused]]
const char* __msg, [[maybe_unused]]
const _Args&... __args)
627#ifdef _GLIBCXX_DEBUG_UB
628 __builtin_fprintf(stderr, __msg, __args...);
631 __builtin_unreachable();
637template <
typename _Tp>
638 struct __assert_unreachable
639 {
static_assert(!is_same_v<_Tp, _Tp>,
"this should be unreachable"); };
643template <typename _Tp, typename _Ap, size_t _Np = simd_size<_Tp, _Ap>::value>
645 __size_or_zero_dispatch(
int)
648template <
typename _Tp,
typename _Ap>
650 __size_or_zero_dispatch(
float)
653template <
typename _Tp,
typename _Ap>
654 inline constexpr size_t __size_or_zero_v
655 = __size_or_zero_dispatch<_Tp, _Ap>(0);
659inline constexpr size_t
660__div_roundup(
size_t __a,
size_t __b)
661{
return (__a + __b - 1) / __b; }
670 _GLIBCXX_SIMD_INTRINSIC
constexpr
671 _ExactBool(
bool __b) : _M_data(__b) {}
673 _ExactBool(
int) =
delete;
675 _GLIBCXX_SIMD_INTRINSIC
constexpr
676 operator bool()
const
687template <
typename _Tp>
688 using __may_alias [[__gnu__::__may_alias__]] = _Tp;
693struct _UnsupportedBase
695 _UnsupportedBase() =
delete;
696 _UnsupportedBase(
const _UnsupportedBase&) =
delete;
697 _UnsupportedBase& operator=(
const _UnsupportedBase&) =
delete;
698 ~_UnsupportedBase() =
delete;
714 using _SimdBase = _UnsupportedBase;
715 using _MaskBase = _UnsupportedBase;
717 static constexpr size_t _S_full_size = 0;
718 static constexpr bool _S_is_partial =
false;
720 static constexpr size_t _S_simd_align = 1;
722 struct _SimdMember {};
723 struct _SimdCastType;
725 static constexpr size_t _S_mask_align = 1;
727 struct _MaskMember {};
728 struct _MaskCastType;
733template <
typename _Tp,
typename _Abi,
typename =
void_t<>>
734 struct _SimdTraits : _InvalidTraits {};
742inline constexpr struct _PrivateInit {} __private_init = {};
744inline constexpr struct _BitsetInit {} __bitset_init = {};
748template <
typename _From,
typename _To,
bool = is_arithmetic_v<_From>,
749 bool = is_arithmetic_v<_To>>
750 struct __is_narrowing_conversion;
754template <
typename _From,
typename _To>
755 struct __is_narrowing_conversion<_From, _To, true, true>
756 :
public __bool_constant<(
757 __digits_v<_From> > __digits_v<_To>
758 || __finite_max_v<_From> > __finite_max_v<_To>
759 || __finite_min_v<_From> < __finite_min_v<_To>
760 || (is_signed_v<_From> && is_unsigned_v<_To>))> {};
762template <
typename _Tp>
763 struct __is_narrowing_conversion<_Tp, bool, true, true>
767 struct __is_narrowing_conversion<bool, bool, true, true>
770template <
typename _Tp>
771 struct __is_narrowing_conversion<_Tp, _Tp, true, true>
774template <
typename _From,
typename _To>
775 struct __is_narrowing_conversion<_From, _To, false, true>
776 :
public negation<is_convertible<_From, _To>> {};
780template <
typename _From,
typename _To,
bool = (sizeof(_From) < sizeof(_To))>
781 struct __converts_to_higher_
integer_rank : public true_type {};
784template <
typename _From,
typename _To>
785 struct __converts_to_higher_integer_rank<_From, _To, false>
786 :
public is_same<decltype(declval<_From>() + declval<_To>()), _To> {};
790template <
typename _Tp,
typename _Ap>
791 _GLIBCXX_SIMD_INTRINSIC
constexpr const auto&
792 __data(
const simd<_Tp, _Ap>& __x);
794template <
typename _Tp,
typename _Ap>
795 _GLIBCXX_SIMD_INTRINSIC
constexpr auto&
796 __data(simd<_Tp, _Ap>& __x);
798template <
typename _Tp,
typename _Ap>
799 _GLIBCXX_SIMD_INTRINSIC
constexpr const auto&
800 __data(
const simd_mask<_Tp, _Ap>& __x);
802template <
typename _Tp,
typename _Ap>
803 _GLIBCXX_SIMD_INTRINSIC
constexpr auto&
804 __data(simd_mask<_Tp, _Ap>& __x);
808template <
typename _FromT,
typename _FromA,
typename _ToT,
typename _ToA,
810 struct _SimdConverter;
812template <
typename _Tp,
typename _Ap>
813 struct _SimdConverter<_Tp, _Ap, _Tp, _Ap, void>
815 template <
typename _Up>
816 _GLIBCXX_SIMD_INTRINSIC
const _Up&
817 operator()(
const _Up& __x)
823template <
typename _V>
824 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
825 __to_value_type_or_member_type(
const _V& __x) ->
decltype(__data(__x))
826 {
return __data(__x); }
828template <
typename _V>
829 _GLIBCXX_SIMD_INTRINSIC
constexpr const typename _V::value_type&
830 __to_value_type_or_member_type(
const typename _V::value_type& __x)
835template <
size_t _Size>
836 struct __bool_storage_member_type;
838template <
size_t _Size>
839 using __bool_storage_member_type_t =
840 typename __bool_storage_member_type<_Size>::type;
850template <
typename _Tp,
typename... _Abis>
855template <
typename _Tp,
int _Np>
856 struct __fixed_size_storage;
858template <
typename _Tp,
int _Np>
859 using __fixed_size_storage_t =
typename __fixed_size_storage<_Tp, _Np>::type;
863template <
typename _Tp,
size_t _Size,
typename =
void_t<>>
866template <
typename _Tp>
867 using _SimdWrapper8 = _SimdWrapper<_Tp, 8 /
sizeof(_Tp)>;
868template <
typename _Tp>
869 using _SimdWrapper16 = _SimdWrapper<_Tp, 16 /
sizeof(_Tp)>;
870template <
typename _Tp>
871 using _SimdWrapper32 = _SimdWrapper<_Tp, 32 /
sizeof(_Tp)>;
872template <
typename _Tp>
873 using _SimdWrapper64 = _SimdWrapper<_Tp, 64 /
sizeof(_Tp)>;
877template <
typename _Tp>
880template <
typename _Tp,
size_t _Np>
881 struct __is_simd_wrapper<_SimdWrapper<_Tp, _Np>> :
true_type {};
883template <
typename _Tp>
884 inline constexpr bool __is_simd_wrapper_v = __is_simd_wrapper<_Tp>::value;
891 template <
typename _Tp,
typename _Fp>
893 _S_bit_iteration(_Tp __mask, _Fp&& __f)
895 static_assert(
sizeof(_ULLong) >=
sizeof(_Tp));
896 conditional_t<
sizeof(_Tp) <=
sizeof(_UInt), _UInt, _ULLong> __k;
897 if constexpr (is_convertible_v<_Tp,
decltype(__k)>)
900 __k = __mask.to_ullong();
903 __f(std::__countr_zero(__k));
913template <
typename _Tp =
void>
915 {
constexpr _Tp operator()(_Tp __a)
const {
return ++__a; } };
918 struct __increment<void>
920 template <
typename _Tp>
922 operator()(_Tp __a)
const
926template <
typename _Tp =
void>
928 {
constexpr _Tp operator()(_Tp __a)
const {
return --__a; } };
931 struct __decrement<void>
933 template <
typename _Tp>
935 operator()(_Tp __a)
const
941template <
typename _From,
typename _To,
943 __is_narrowing_conversion<__remove_cvref_t<_From>, _To>>::value>>
944 using _ValuePreserving = _From;
946template <
typename _From,
typename _To,
947 typename _DecayedFrom = __remove_cvref_t<_From>,
949 is_convertible<_From, _To>,
951 is_same<_DecayedFrom, _To>, is_same<_DecayedFrom, int>,
952 conjunction<is_same<_DecayedFrom, _UInt>, is_unsigned<_To>>,
953 negation<__is_narrowing_conversion<_DecayedFrom, _To>>>>::value>>
954 using _ValuePreservingOrInt = _From;
958template <
typename _Tp,
size_t _Bytes,
typename =
void_t<>>
959 struct __intrinsic_type;
961template <
typename _Tp,
size_t _Size>
962 using __intrinsic_type_t =
963 typename __intrinsic_type<_Tp, _Size *
sizeof(_Tp)>::type;
965template <
typename _Tp>
966 using __intrinsic_type2_t =
typename __intrinsic_type<_Tp, 2>::type;
967template <
typename _Tp>
968 using __intrinsic_type4_t =
typename __intrinsic_type<_Tp, 4>::type;
969template <
typename _Tp>
970 using __intrinsic_type8_t =
typename __intrinsic_type<_Tp, 8>::type;
971template <
typename _Tp>
972 using __intrinsic_type16_t =
typename __intrinsic_type<_Tp, 16>::type;
973template <
typename _Tp>
974 using __intrinsic_type32_t =
typename __intrinsic_type<_Tp, 32>::type;
975template <
typename _Tp>
976 using __intrinsic_type64_t =
typename __intrinsic_type<_Tp, 64>::type;
980template <
size_t _Np,
bool _Sanitized = false>
983template <
size_t _Np,
bool _Sanitized>
984 struct __is_bitmask<_BitMask<_Np, _Sanitized>, void> :
true_type {};
987 using _SanitizedBitMask = _BitMask<_Np, true>;
989template <
size_t _Np,
bool _Sanitized>
992 static_assert(_Np > 0);
994 static constexpr size_t _NBytes = __div_roundup(_Np, __CHAR_BIT__);
998 sizeof(_ULLong), std::__bit_ceil(_NBytes))>>>;
1000 static constexpr int _S_array_size = __div_roundup(_NBytes,
sizeof(_Tp));
1002 _Tp _M_bits[_S_array_size];
1004 static constexpr int _S_unused_bits
1005 = _Np == 1 ? 0 : _S_array_size *
sizeof(_Tp) * __CHAR_BIT__ - _Np;
1007 static constexpr _Tp _S_bitmask = +_Tp(~_Tp()) >> _S_unused_bits;
1009 constexpr _BitMask() noexcept = default;
1011 constexpr _BitMask(
unsigned long long __x) noexcept
1012 : _M_bits{
static_cast<_Tp
>(__x)} {}
1014 _BitMask(bitset<_Np> __x) noexcept : _BitMask(__x.to_ullong()) {}
1016 constexpr _BitMask(
const _BitMask&)
noexcept =
default;
1018 template <
bool _RhsSanitized,
typename =
enable_if_t<_RhsSanitized ==
false
1019 && _Sanitized ==
true>>
1020 constexpr _BitMask(
const _BitMask<_Np, _RhsSanitized>& __rhs) noexcept
1021 : _BitMask(__rhs._M_sanitized()) {}
1023 constexpr operator _SimdWrapper<bool, _Np>() const noexcept
1025 static_assert(_S_array_size == 1);
1031 _M_to_bits() const noexcept
1033 static_assert(_S_array_size == 1);
1038 constexpr unsigned long long
1039 to_ullong() const noexcept
1041 static_assert(_S_array_size == 1);
1046 constexpr unsigned long
1047 to_ulong() const noexcept
1049 static_assert(_S_array_size == 1);
1053 constexpr bitset<_Np>
1054 _M_to_bitset() const noexcept
1056 static_assert(_S_array_size == 1);
1060 constexpr decltype(
auto)
1061 _M_sanitized()
const noexcept
1063 if constexpr (_Sanitized)
1065 else if constexpr (_Np == 1)
1066 return _SanitizedBitMask<_Np>(_M_bits[0]);
1069 _SanitizedBitMask<_Np> __r = {};
1070 for (
int __i = 0; __i < _S_array_size; ++__i)
1071 __r._M_bits[__i] = _M_bits[__i];
1072 if constexpr (_S_unused_bits > 0)
1073 __r._M_bits[_S_array_size - 1] &= _S_bitmask;
1078 template <
size_t _Mp,
bool _LSanitized>
1079 constexpr _BitMask<_Np + _Mp, _Sanitized>
1080 _M_prepend(_BitMask<_Mp, _LSanitized> __lsb)
const noexcept
1082 constexpr size_t _RN = _Np + _Mp;
1083 using _Rp = _BitMask<_RN, _Sanitized>;
1084 if constexpr (_Rp::_S_array_size == 1)
1086 _Rp __r{{_M_bits[0]}};
1087 __r._M_bits[0] <<= _Mp;
1088 __r._M_bits[0] |= __lsb._M_sanitized()._M_bits[0];
1092 __assert_unreachable<_Rp>();
1098 template <
size_t _DropLsb,
size_t _NewSize = _Np - _DropLsb>
1100 _M_extract() const noexcept
1102 static_assert(_Np > _DropLsb);
1103 static_assert(_DropLsb + _NewSize <=
sizeof(_ULLong) * __CHAR_BIT__,
1104 "not implemented for bitmasks larger than one ullong");
1105 if constexpr (_NewSize == 1)
1107 return _SanitizedBitMask<1>(_M_bits[0] & (_Tp(1) << _DropLsb));
1109 return _BitMask<_NewSize,
1110 ((_NewSize + _DropLsb ==
sizeof(_Tp) * __CHAR_BIT__
1111 && _NewSize + _DropLsb <= _Np)
1112 || ((_Sanitized || _Np ==
sizeof(_Tp) * __CHAR_BIT__)
1113 && _NewSize + _DropLsb >= _Np))>(_M_bits[0]
1119 all() const noexcept
1121 if constexpr (_Np == 1)
1123 else if constexpr (!_Sanitized)
1124 return _M_sanitized().all();
1127 constexpr _Tp __allbits = ~_Tp();
1128 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1129 if (_M_bits[__i] != __allbits)
1131 return _M_bits[_S_array_size - 1] == _S_bitmask;
1138 any() const noexcept
1140 if constexpr (_Np == 1)
1142 else if constexpr (!_Sanitized)
1143 return _M_sanitized().any();
1146 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1147 if (_M_bits[__i] != 0)
1149 return _M_bits[_S_array_size - 1] != 0;
1155 none() const noexcept
1157 if constexpr (_Np == 1)
1159 else if constexpr (!_Sanitized)
1160 return _M_sanitized().none();
1163 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1164 if (_M_bits[__i] != 0)
1166 return _M_bits[_S_array_size - 1] == 0;
1173 count() const noexcept
1175 if constexpr (_Np == 1)
1177 else if constexpr (!_Sanitized)
1178 return _M_sanitized().none();
1181 int __result = __builtin_popcountll(_M_bits[0]);
1182 for (
int __i = 1; __i < _S_array_size; ++__i)
1183 __result += __builtin_popcountll(_M_bits[__i]);
1190 operator[](
size_t __i)
const noexcept
1192 if constexpr (_Np == 1)
1194 else if constexpr (_S_array_size == 1)
1195 return (_M_bits[0] >> __i) & 1;
1198 const size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1199 const size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1200 return (_M_bits[__j] >> __shift) & 1;
1204 template <
size_t __i>
1206 operator[](_SizeConstant<__i>)
const noexcept
1208 static_assert(__i < _Np);
1209 constexpr size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1210 constexpr size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1211 return static_cast<bool>(_M_bits[__j] & (_Tp(1) << __shift));
1216 set(
size_t __i,
bool __x)
noexcept
1218 if constexpr (_Np == 1)
1220 else if constexpr (_S_array_size == 1)
1222 _M_bits[0] &= ~_Tp(_Tp(1) << __i);
1223 _M_bits[0] |= _Tp(_Tp(__x) << __i);
1227 const size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1228 const size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1229 _M_bits[__j] &= ~_Tp(_Tp(1) << __shift);
1230 _M_bits[__j] |= _Tp(_Tp(__x) << __shift);
1234 template <
size_t __i>
1236 set(_SizeConstant<__i>,
bool __x)
noexcept
1238 static_assert(__i < _Np);
1239 if constexpr (_Np == 1)
1243 constexpr size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1244 constexpr size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1245 constexpr _Tp __mask = ~_Tp(_Tp(1) << __shift);
1246 _M_bits[__j] &= __mask;
1247 _M_bits[__j] |= _Tp(_Tp(__x) << __shift);
1253 operator~() const noexcept
1255 if constexpr (_Np == 1)
1259 _BitMask __result{};
1260 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1261 __result._M_bits[__i] = ~_M_bits[__i];
1262 if constexpr (_Sanitized)
1263 __result._M_bits[_S_array_size - 1]
1264 = _M_bits[_S_array_size - 1] ^ _S_bitmask;
1266 __result._M_bits[_S_array_size - 1] = ~_M_bits[_S_array_size - 1];
1272 operator^=(
const _BitMask& __b) &
noexcept
1274 __execute_n_times<_S_array_size>(
1275 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { _M_bits[__i] ^= __b._M_bits[__i]; });
1280 operator|=(
const _BitMask& __b) &
noexcept
1282 __execute_n_times<_S_array_size>(
1283 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { _M_bits[__i] |= __b._M_bits[__i]; });
1288 operator&=(
const _BitMask& __b) &
noexcept
1290 __execute_n_times<_S_array_size>(
1291 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { _M_bits[__i] &= __b._M_bits[__i]; });
1295 friend constexpr _BitMask
1296 operator^(
const _BitMask& __a,
const _BitMask& __b)
noexcept
1303 friend constexpr _BitMask
1304 operator|(
const _BitMask& __a,
const _BitMask& __b)
noexcept
1311 friend constexpr _BitMask
1312 operator&(
const _BitMask& __a,
const _BitMask& __b)
noexcept
1319 _GLIBCXX_SIMD_INTRINSIC
1321 _M_is_constprop()
const
1323 if constexpr (_S_array_size == 0)
1324 return __builtin_constant_p(_M_bits[0]);
1327 for (
int __i = 0; __i < _S_array_size; ++__i)
1328 if (!__builtin_constant_p(_M_bits[__i]))
1339template <
typename _Tp =
void>
1340 static inline constexpr int __min_vector_size = 2 *
sizeof(_Tp);
1342#if _GLIBCXX_SIMD_HAVE_NEON
1344 inline constexpr int __min_vector_size<void> = 8;
1347 inline constexpr int __min_vector_size<void> = 16;
1352template <
typename _Tp,
size_t _Np,
typename =
void>
1353 struct __vector_type_n {};
1356template <
typename _Tp>
1357 struct __vector_type_n<_Tp, 0, void> {};
1360template <
typename _Tp>
1361 struct __vector_type_n<_Tp, 1,
enable_if_t<__is_vectorizable_v<_Tp>>>
1362 {
using type = _Tp; };
1365template <
typename _Tp,
size_t _Np>
1366 struct __vector_type_n<_Tp, _Np,
enable_if_t<__is_vectorizable_v<_Tp> && _Np >= 2>>
1368 static constexpr size_t _S_Np2 = std::__bit_ceil(_Np *
sizeof(_Tp));
1370 static constexpr size_t _S_Bytes =
1376 _S_Np2 < __min_vector_size<_Tp> ? __min_vector_size<_Tp>
1379 using type [[__gnu__::__vector_size__(_S_Bytes)]] = _Tp;
1382template <
typename _Tp,
size_t _Bytes,
size_t = _Bytes % sizeof(_Tp)>
1383 struct __vector_type;
1385template <
typename _Tp,
size_t _Bytes>
1386 struct __vector_type<_Tp, _Bytes, 0>
1387 : __vector_type_n<_Tp, _Bytes / sizeof(_Tp)> {};
1389template <
typename _Tp,
size_t _Size>
1390 using __vector_type_t =
typename __vector_type_n<_Tp, _Size>::type;
1392template <
typename _Tp>
1393 using __vector_type2_t =
typename __vector_type<_Tp, 2>::type;
1394template <
typename _Tp>
1395 using __vector_type4_t =
typename __vector_type<_Tp, 4>::type;
1396template <
typename _Tp>
1397 using __vector_type8_t =
typename __vector_type<_Tp, 8>::type;
1398template <
typename _Tp>
1399 using __vector_type16_t =
typename __vector_type<_Tp, 16>::type;
1400template <
typename _Tp>
1401 using __vector_type32_t =
typename __vector_type<_Tp, 32>::type;
1402template <
typename _Tp>
1403 using __vector_type64_t =
typename __vector_type<_Tp, 64>::type;
1407template <
typename _Tp,
typename =
void_t<>>
1410template <
typename _Tp>
1411 struct __is_vector_type<
1412 _Tp,
void_t<typename __vector_type<
1414 : is_same<_Tp, typename __vector_type<
1415 remove_reference_t<decltype(declval<_Tp>()[0])>,
1416 sizeof(_Tp)>::type> {};
1418template <
typename _Tp>
1419 inline constexpr bool __is_vector_type_v = __is_vector_type<_Tp>::value;
1423#if _GLIBCXX_SIMD_HAVE_SSE_ABI
1424template <
typename _Tp>
1425 using __is_intrinsic_type = __is_vector_type<_Tp>;
1427template <
typename _Tp,
typename =
void_t<>>
1430template <
typename _Tp>
1431 struct __is_intrinsic_type<
1432 _Tp,
void_t<typename __intrinsic_type<
1434 : is_same<_Tp, typename __intrinsic_type<
1435 remove_reference_t<decltype(declval<_Tp>()[0])>,
1436 sizeof(_Tp)>::type> {};
1439template <
typename _Tp>
1440 inline constexpr bool __is_intrinsic_type_v = __is_intrinsic_type<_Tp>::value;
1444template <
typename _Tp,
typename =
void_t<>>
1445 struct _VectorTraitsImpl;
1447template <
typename _Tp>
1448 struct _VectorTraitsImpl<_Tp,
enable_if_t<__is_vector_type_v<_Tp>
1449 || __is_intrinsic_type_v<_Tp>>>
1452 using value_type = remove_reference_t<decltype(declval<_Tp>()[0])>;
1453 static constexpr int _S_full_size =
sizeof(_Tp) /
sizeof(value_type);
1454 using _Wrapper = _SimdWrapper<value_type, _S_full_size>;
1455 template <
typename _Up,
int _W = _S_full_size>
1456 static constexpr bool _S_is
1457 = is_same_v<value_type, _Up> && _W == _S_full_size;
1460template <
typename _Tp,
size_t _Np>
1461 struct _VectorTraitsImpl<_SimdWrapper<_Tp, _Np>,
1462 void_t<__vector_type_t<_Tp, _Np>>>
1464 using type = __vector_type_t<_Tp, _Np>;
1465 using value_type = _Tp;
1466 static constexpr int _S_full_size =
sizeof(type) /
sizeof(value_type);
1467 using _Wrapper = _SimdWrapper<_Tp, _Np>;
1468 static constexpr bool _S_is_partial = (_Np == _S_full_size);
1469 static constexpr int _S_partial_width = _Np;
1470 template <
typename _Up,
int _W = _S_full_size>
1471 static constexpr bool _S_is
1472 = is_same_v<value_type, _Up>&& _W == _S_full_size;
1475template <typename _Tp, typename = typename _VectorTraitsImpl<_Tp>::type>
1476 using _VectorTraits = _VectorTraitsImpl<_Tp>;
1480template <
typename _V>
1481 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
1484 if constexpr (__is_vector_type_v<_V>)
1486 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value)
1487 return __data(__x)._M_data;
1488 else if constexpr (__is_vectorizable_v<_V>)
1489 return __vector_type_t<_V, 2>{__x};
1496template <
size_t _Np = 0,
typename _V>
1497 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
1498 __as_wrapper(_V __x)
1500 if constexpr (__is_vector_type_v<_V>)
1501 return _SimdWrapper<
typename _VectorTraits<_V>::value_type,
1502 (_Np > 0 ? _Np : _VectorTraits<_V>::_S_full_size)>(__x);
1503 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value)
1505 static_assert(_V::size() == _Np);
1510 static_assert(_V::_S_size == _Np);
1517template <
typename _To,
typename _From>
1518 _GLIBCXX_SIMD_INTRINSIC
constexpr _To
1519 __intrin_bitcast(_From __v)
1521 static_assert((__is_vector_type_v<_From> || __is_intrinsic_type_v<_From>)
1522 && (__is_vector_type_v<_To> || __is_intrinsic_type_v<_To>));
1523 if constexpr (
sizeof(_To) ==
sizeof(_From))
1524 return reinterpret_cast<_To
>(__v);
1525 else if constexpr (
sizeof(_From) >
sizeof(_To))
1526 if constexpr (
sizeof(_To) >= 16)
1527 return reinterpret_cast<const __may_alias<_To>&
>(__v);
1531 __builtin_memcpy(&__r, &__v,
sizeof(_To));
1534#if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1535 else if constexpr (__have_avx &&
sizeof(_From) == 16 &&
sizeof(_To) == 32)
1536 return reinterpret_cast<_To
>(__builtin_ia32_ps256_ps(
1537 reinterpret_cast<__vector_type_t<float, 4>
>(__v)));
1538 else if constexpr (__have_avx512f &&
sizeof(_From) == 16
1539 &&
sizeof(_To) == 64)
1540 return reinterpret_cast<_To
>(__builtin_ia32_ps512_ps(
1541 reinterpret_cast<__vector_type_t<float, 4>
>(__v)));
1542 else if constexpr (__have_avx512f &&
sizeof(_From) == 32
1543 &&
sizeof(_To) == 64)
1544 return reinterpret_cast<_To
>(__builtin_ia32_ps512_256ps(
1545 reinterpret_cast<__vector_type_t<float, 8>
>(__v)));
1547 else if constexpr (
sizeof(__v) <= 8)
1548 return reinterpret_cast<_To
>(
1549 __vector_type_t<__int_for_sizeof_t<_From>,
sizeof(_To) /
sizeof(_From)>{
1550 reinterpret_cast<__int_for_sizeof_t<_From>
>(__v)});
1553 static_assert(
sizeof(_To) >
sizeof(_From));
1555 __builtin_memcpy(&__r, &__v,
sizeof(_From));
1562template <
typename _To,
size_t _NN = 0,
typename _From,
1563 typename _FromVT = _VectorTraits<_From>,
1564 size_t _Np = _NN == 0 ?
sizeof(_From) /
sizeof(_To) : _NN>
1565 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_To, _Np>
1566 __vector_bitcast(_From __x)
1568 using _R = __vector_type_t<_To, _Np>;
1569 return __intrin_bitcast<_R>(__x);
1572template <
typename _To,
size_t _NN = 0,
typename _Tp,
size_t _Nx,
1574 = _NN == 0 ?
sizeof(_SimdWrapper<_Tp, _Nx>) /
sizeof(_To) : _NN>
1575 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_To, _Np>
1576 __vector_bitcast(
const _SimdWrapper<_Tp, _Nx>& __x)
1578 static_assert(_Np > 1);
1579 return __intrin_bitcast<__vector_type_t<_To, _Np>>(__x._M_data);
1584#ifdef _GLIBCXX_SIMD_WORKAROUND_PR85048
1585template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1586 _To __convert_x86(_Tp);
1588template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1589 _To __convert_x86(_Tp, _Tp);
1591template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1592 _To __convert_x86(_Tp, _Tp, _Tp, _Tp);
1594template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1595 _To __convert_x86(_Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp);
1597template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1598 _To __convert_x86(_Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp,
1599 _Tp, _Tp, _Tp, _Tp);
1604template <
typename _To,
typename _From>
1605 _GLIBCXX_SIMD_INTRINSIC
constexpr _To
1606 __bit_cast(
const _From __x)
1609 static_assert(
sizeof(_To) ==
sizeof(_From));
1610 constexpr bool __to_is_vectorizable
1611 = is_arithmetic_v<_To> || is_enum_v<_To>;
1612 constexpr bool __from_is_vectorizable
1613 = is_arithmetic_v<_From> || is_enum_v<_From>;
1614 if constexpr (__is_vector_type_v<_To> && __is_vector_type_v<_From>)
1615 return reinterpret_cast<_To
>(__x);
1616 else if constexpr (__is_vector_type_v<_To> && __from_is_vectorizable)
1618 using _FV [[gnu::vector_size(
sizeof(_From))]] = _From;
1619 return reinterpret_cast<_To
>(_FV{__x});
1621 else if constexpr (__to_is_vectorizable && __from_is_vectorizable)
1623 using _TV [[gnu::vector_size(
sizeof(_To))]] = _To;
1624 using _FV [[gnu::vector_size(
sizeof(_From))]] = _From;
1625 return reinterpret_cast<_TV
>(_FV{__x})[0];
1627 else if constexpr (__to_is_vectorizable && __is_vector_type_v<_From>)
1629 using _TV [[gnu::vector_size(
sizeof(_To))]] = _To;
1630 return reinterpret_cast<_TV
>(__x)[0];
1635 __builtin_memcpy(
reinterpret_cast<char*
>(&__r),
1636 reinterpret_cast<const char*
>(&__x),
sizeof(_To));
1643template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>,
1644 typename _R = __
intrinsic_type_t<
typename _TVT::value_type, _TVT::_S_full_size>>
1645 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
1646 __to_intrin(_Tp __x)
1648 static_assert(
sizeof(__x) <=
sizeof(_R),
1649 "__to_intrin may never drop values off the end");
1650 if constexpr (
sizeof(__x) ==
sizeof(_R))
1651 return reinterpret_cast<_R
>(__as_vector(__x));
1654 using _Up = __int_for_sizeof_t<_Tp>;
1655 return reinterpret_cast<_R
>(
1656 __vector_type_t<_Up,
sizeof(_R) /
sizeof(_Up)>{__bit_cast<_Up>(__x)});
1662template <
typename _Tp,
typename... _Args>
1663 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp,
sizeof...(_Args)>
1664 __make_vector(
const _Args&... __args)
1665 {
return __vector_type_t<_Tp,
sizeof...(_Args)>{
static_cast<_Tp
>(__args)...}; }
1669template <
size_t _Np,
typename _Tp,
size_t... _I>
1670 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1671 __vector_broadcast_impl(_Tp __x, index_sequence<_I...>)
1672 {
return __vector_type_t<_Tp, _Np>{((void)_I, __x)...}; }
1674template <
size_t _Np,
typename _Tp>
1675 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1676 __vector_broadcast(_Tp __x)
1677 {
return __vector_broadcast_impl<_Np, _Tp>(__x, make_index_sequence<_Np>()); }
1681 template <
typename _Tp,
size_t _Np,
typename _Gp,
size_t... _I>
1682 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1683 __generate_vector_impl(_Gp&& __gen, index_sequence<_I...>)
1684 {
return __vector_type_t<_Tp, _Np>{
static_cast<_Tp
>(__gen(_SizeConstant<_I>()))...}; }
1686template <
typename _V,
typename _VVT = _VectorTraits<_V>,
typename _Gp>
1687 _GLIBCXX_SIMD_INTRINSIC
constexpr _V
1688 __generate_vector(_Gp&& __gen)
1690 if constexpr (__is_vector_type_v<_V>)
1691 return __generate_vector_impl<
typename _VVT::value_type,
1692 _VVT::_S_full_size>(
1693 static_cast<_Gp&&
>(__gen), make_index_sequence<_VVT::_S_full_size>());
1695 return __generate_vector_impl<
typename _VVT::value_type,
1696 _VVT::_S_partial_width>(
1697 static_cast<_Gp&&
>(__gen),
1698 make_index_sequence<_VVT::_S_partial_width>());
1701template <
typename _Tp,
size_t _Np,
typename _Gp>
1702 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1703 __generate_vector(_Gp&& __gen)
1705 return __generate_vector_impl<_Tp, _Np>(
static_cast<_Gp&&
>(__gen),
1706 make_index_sequence<_Np>());
1711template <
typename _TW>
1712 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1713 __xor(_TW __a, _TW __b)
noexcept
1715 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1717 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1718 _VectorTraitsImpl<_TW>>::value_type;
1719 if constexpr (is_floating_point_v<_Tp>)
1721 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1722 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1723 ^ __vector_bitcast<_Ip>(__b));
1725 else if constexpr (__is_vector_type_v<_TW>)
1728 return __a._M_data ^ __b._M_data;
1736template <
typename _TW>
1737 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1738 __or(_TW __a, _TW __b)
noexcept
1740 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1742 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1743 _VectorTraitsImpl<_TW>>::value_type;
1744 if constexpr (is_floating_point_v<_Tp>)
1746 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1747 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1748 | __vector_bitcast<_Ip>(__b));
1750 else if constexpr (__is_vector_type_v<_TW>)
1753 return __a._M_data | __b._M_data;
1761template <
typename _TW>
1762 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1763 __and(_TW __a, _TW __b)
noexcept
1765 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1767 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1768 _VectorTraitsImpl<_TW>>::value_type;
1769 if constexpr (is_floating_point_v<_Tp>)
1771 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1772 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1773 & __vector_bitcast<_Ip>(__b));
1775 else if constexpr (__is_vector_type_v<_TW>)
1778 return __a._M_data & __b._M_data;
1786#if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1787static constexpr struct
1789 _GLIBCXX_SIMD_INTRINSIC __v4sf
1790 operator()(__v4sf __a, __v4sf __b)
const noexcept
1791 {
return __builtin_ia32_andnps(__a, __b); }
1793 _GLIBCXX_SIMD_INTRINSIC __v2df
1794 operator()(__v2df __a, __v2df __b)
const noexcept
1795 {
return __builtin_ia32_andnpd(__a, __b); }
1797 _GLIBCXX_SIMD_INTRINSIC __v2di
1798 operator()(__v2di __a, __v2di __b)
const noexcept
1799 {
return __builtin_ia32_pandn128(__a, __b); }
1801 _GLIBCXX_SIMD_INTRINSIC __v8sf
1802 operator()(__v8sf __a, __v8sf __b)
const noexcept
1803 {
return __builtin_ia32_andnps256(__a, __b); }
1805 _GLIBCXX_SIMD_INTRINSIC __v4df
1806 operator()(__v4df __a, __v4df __b)
const noexcept
1807 {
return __builtin_ia32_andnpd256(__a, __b); }
1809 _GLIBCXX_SIMD_INTRINSIC __v4di
1810 operator()(__v4di __a, __v4di __b)
const noexcept
1812 if constexpr (__have_avx2)
1813 return __builtin_ia32_andnotsi256(__a, __b);
1815 return reinterpret_cast<__v4di
>(
1816 __builtin_ia32_andnpd256(
reinterpret_cast<__v4df
>(__a),
1817 reinterpret_cast<__v4df
>(__b)));
1820 _GLIBCXX_SIMD_INTRINSIC __v16sf
1821 operator()(__v16sf __a, __v16sf __b)
const noexcept
1823 if constexpr (__have_avx512dq)
1824 return _mm512_andnot_ps(__a, __b);
1826 return reinterpret_cast<__v16sf
>(
1827 _mm512_andnot_si512(
reinterpret_cast<__v8di
>(__a),
1828 reinterpret_cast<__v8di
>(__b)));
1831 _GLIBCXX_SIMD_INTRINSIC __v8df
1832 operator()(__v8df __a, __v8df __b)
const noexcept
1834 if constexpr (__have_avx512dq)
1835 return _mm512_andnot_pd(__a, __b);
1837 return reinterpret_cast<__v8df
>(
1838 _mm512_andnot_si512(
reinterpret_cast<__v8di
>(__a),
1839 reinterpret_cast<__v8di
>(__b)));
1842 _GLIBCXX_SIMD_INTRINSIC __v8di
1843 operator()(__v8di __a, __v8di __b)
const noexcept
1844 {
return _mm512_andnot_si512(__a, __b); }
1848template <
typename _TW>
1849 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1850 __andnot(_TW __a, _TW __b)
noexcept
1852 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1854 using _TVT = conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1855 _VectorTraitsImpl<_TW>>;
1856 using _Tp =
typename _TVT::value_type;
1857#if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1858 if constexpr (
sizeof(_TW) >= 16)
1860 const auto __ai = __to_intrin(__a);
1861 const auto __bi = __to_intrin(__b);
1862 if (!__builtin_is_constant_evaluated()
1863 && !(__builtin_constant_p(__ai) && __builtin_constant_p(__bi)))
1865 const auto __r = _S_x86_andnot(__ai, __bi);
1866 if constexpr (is_convertible_v<
decltype(__r), _TW>)
1869 return reinterpret_cast<typename _TVT::type
>(__r);
1873 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1874 return __vector_bitcast<_Tp>(~__vector_bitcast<_Ip>(__a)
1875 & __vector_bitcast<_Ip>(__b));
1883template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1884 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp
1885 __not(_Tp __a)
noexcept
1887 if constexpr (is_floating_point_v<typename _TVT::value_type>)
1888 return reinterpret_cast<typename _TVT::type
>(
1889 ~__vector_bitcast<unsigned>(__a));
1896template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>,
1897 typename _R = __vector_type_t<
typename _TVT::value_type, _TVT::_S_full_size * 2>>
1899 __concat(_Tp a_, _Tp b_)
1901#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_1
1903 = conditional_t<is_floating_point_v<typename _TVT::value_type>, double,
1905 long long,
typename _TVT::value_type>>;
1906 constexpr int input_width =
sizeof(_Tp) /
sizeof(_W);
1907 const auto __a = __vector_bitcast<_W>(a_);
1908 const auto __b = __vector_bitcast<_W>(b_);
1909 using _Up = __vector_type_t<_W,
sizeof(_R) /
sizeof(_W)>;
1911 constexpr int input_width = _TVT::_S_full_size;
1912 const _Tp& __a = a_;
1913 const _Tp& __b = b_;
1916 if constexpr (input_width == 2)
1917 return reinterpret_cast<_R
>(_Up{__a[0], __a[1], __b[0], __b[1]});
1918 else if constexpr (input_width == 4)
1919 return reinterpret_cast<_R
>(
1920 _Up{__a[0], __a[1], __a[2], __a[3], __b[0], __b[1], __b[2], __b[3]});
1921 else if constexpr (input_width == 8)
1922 return reinterpret_cast<_R
>(
1923 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6], __a[7],
1924 __b[0], __b[1], __b[2], __b[3], __b[4], __b[5], __b[6], __b[7]});
1925 else if constexpr (input_width == 16)
1926 return reinterpret_cast<_R
>(
1927 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6],
1928 __a[7], __a[8], __a[9], __a[10], __a[11], __a[12], __a[13],
1929 __a[14], __a[15], __b[0], __b[1], __b[2], __b[3], __b[4],
1930 __b[5], __b[6], __b[7], __b[8], __b[9], __b[10], __b[11],
1931 __b[12], __b[13], __b[14], __b[15]});
1932 else if constexpr (input_width == 32)
1933 return reinterpret_cast<_R
>(
1934 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6],
1935 __a[7], __a[8], __a[9], __a[10], __a[11], __a[12], __a[13],
1936 __a[14], __a[15], __a[16], __a[17], __a[18], __a[19], __a[20],
1937 __a[21], __a[22], __a[23], __a[24], __a[25], __a[26], __a[27],
1938 __a[28], __a[29], __a[30], __a[31], __b[0], __b[1], __b[2],
1939 __b[3], __b[4], __b[5], __b[6], __b[7], __b[8], __b[9],
1940 __b[10], __b[11], __b[12], __b[13], __b[14], __b[15], __b[16],
1941 __b[17], __b[18], __b[19], __b[20], __b[21], __b[22], __b[23],
1942 __b[24], __b[25], __b[26], __b[27], __b[28], __b[29], __b[30],
1948template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1949 struct _ZeroExtendProxy
1951 using value_type =
typename _TVT::value_type;
1952 static constexpr size_t _Np = _TVT::_S_full_size;
1955 template <
typename _To,
typename _ToVT = _VectorTraits<_To>,
1957 = enable_if_t<is_same_v<
typename _ToVT::value_type, value_type>>>
1958 _GLIBCXX_SIMD_INTRINSIC
operator _To()
const
1960 constexpr size_t _ToN = _ToVT::_S_full_size;
1961 if constexpr (_ToN == _Np)
1963 else if constexpr (_ToN == 2 * _Np)
1965#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_3
1966 if constexpr (__have_avx && _TVT::template _S_is<float, 4>)
1967 return __vector_bitcast<value_type>(
1968 _mm256_insertf128_ps(__m256(), __x, 0));
1969 else if constexpr (__have_avx && _TVT::template _S_is<double, 2>)
1970 return __vector_bitcast<value_type>(
1971 _mm256_insertf128_pd(__m256d(), __x, 0));
1972 else if constexpr (__have_avx2 && _Np *
sizeof(value_type) == 16)
1973 return __vector_bitcast<value_type>(
1974 _mm256_insertf128_si256(__m256i(), __to_intrin(__x), 0));
1975 else if constexpr (__have_avx512f && _TVT::template _S_is<float, 8>)
1977 if constexpr (__have_avx512dq)
1978 return __vector_bitcast<value_type>(
1979 _mm512_insertf32x8(__m512(), __x, 0));
1981 return reinterpret_cast<__m512
>(
1982 _mm512_insertf64x4(__m512d(),
1983 reinterpret_cast<__m256d
>(__x), 0));
1985 else if constexpr (__have_avx512f
1986 && _TVT::template _S_is<double, 4>)
1987 return __vector_bitcast<value_type>(
1988 _mm512_insertf64x4(__m512d(), __x, 0));
1989 else if constexpr (__have_avx512f && _Np *
sizeof(value_type) == 32)
1990 return __vector_bitcast<value_type>(
1991 _mm512_inserti64x4(__m512i(), __to_intrin(__x), 0));
1993 return __concat(__x, _Tp());
1995 else if constexpr (_ToN == 4 * _Np)
1997#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_3
1998 if constexpr (__have_avx512dq && _TVT::template _S_is<double, 2>)
2000 return __vector_bitcast<value_type>(
2001 _mm512_insertf64x2(__m512d(), __x, 0));
2003 else if constexpr (__have_avx512f
2004 && is_floating_point_v<value_type>)
2006 return __vector_bitcast<value_type>(
2007 _mm512_insertf32x4(__m512(),
reinterpret_cast<__m128
>(__x),
2010 else if constexpr (__have_avx512f && _Np *
sizeof(value_type) == 16)
2012 return __vector_bitcast<value_type>(
2013 _mm512_inserti32x4(__m512i(), __to_intrin(__x), 0));
2016 return __concat(__concat(__x, _Tp()),
2017 __vector_type_t<value_type, _Np * 2>());
2019 else if constexpr (_ToN == 8 * _Np)
2020 return __concat(
operator __vector_type_t<value_type, _Np * 4>(),
2021 __vector_type_t<value_type, _Np * 4>());
2022 else if constexpr (_ToN == 16 * _Np)
2023 return __concat(
operator __vector_type_t<value_type, _Np * 8>(),
2024 __vector_type_t<value_type, _Np * 8>());
2026 __assert_unreachable<_Tp>();
2030template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2031 _GLIBCXX_SIMD_INTRINSIC _ZeroExtendProxy<_Tp, _TVT>
2032 __zero_extend(_Tp __x)
2037template <
int _Offset,
2040 typename _TVT = _VectorTraits<_Tp>,
2041 typename _R = __vector_type_t<
typename _TVT::value_type, _TVT::_S_full_size / _SplitBy>>
2042 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2045 using value_type =
typename _TVT::value_type;
2046#if _GLIBCXX_SIMD_X86INTRIN
2047 if constexpr (
sizeof(_Tp) == 64 && _SplitBy == 4 && _Offset > 0)
2049 if constexpr (__have_avx512dq && is_same_v<double, value_type>)
2050 return _mm512_extractf64x2_pd(__to_intrin(__in), _Offset);
2051 else if constexpr (is_floating_point_v<value_type>)
2052 return __vector_bitcast<value_type>(
2053 _mm512_extractf32x4_ps(__intrin_bitcast<__m512>(__in), _Offset));
2055 return reinterpret_cast<_R
>(
2056 _mm512_extracti32x4_epi32(__intrin_bitcast<__m512i>(__in),
2062#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_1
2064 is_floating_point_v<value_type>, double,
2066 static_assert(
sizeof(_R) %
sizeof(_W) == 0);
2067 constexpr int __return_width =
sizeof(_R) /
sizeof(_W);
2068 using _Up = __vector_type_t<_W, __return_width>;
2069 const auto __x = __vector_bitcast<_W>(__in);
2071 constexpr int __return_width = _TVT::_S_full_size / _SplitBy;
2073 const __vector_type_t<value_type, _TVT::_S_full_size>& __x
2076 constexpr int _O = _Offset * __return_width;
2077 return __call_with_subscripts<__return_width, _O>(
2078 __x, [](
auto... __entries) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
2079 return reinterpret_cast<_R
>(_Up{__entries...});
2086template <
typename _Tp,
2087 typename _R = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2088 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2092 __builtin_memcpy(&__r, &__x, 8);
2096template <
typename _Tp,
2097 typename _R = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2098 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2101 static_assert(
sizeof(_Tp) == 16,
"use __hi64z if you meant it");
2103 __builtin_memcpy(&__r,
reinterpret_cast<const char*
>(&__x) + 8, 8);
2107template <
typename _Tp,
2108 typename _R = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2109 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2110 __hi64z([[maybe_unused]] _Tp __x)
2113 if constexpr (
sizeof(_Tp) == 16)
2114 __builtin_memcpy(&__r,
reinterpret_cast<const char*
>(&__x) + 8, 8);
2120template <
typename _Tp>
2121 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2123 {
return __extract<0,
sizeof(_Tp) / 16>(__x); }
2125template <
typename _Tp>
2126 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2129 static_assert(
sizeof(__x) == 32);
2130 return __extract<1, 2>(__x);
2135template <
typename _Tp>
2136 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2139 static_assert(
sizeof(__x) == 64);
2140 return __extract<0, 2>(__x);
2143template <
typename _Tp>
2144 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2147 static_assert(
sizeof(__x) == 64);
2148 return __extract<1, 2>(__x);
2153template <
typename _Tp>
2156 static_assert(__is_vector_type_v<_Tp>);
2160 template <
typename _Up,
typename _UVT = _VectorTraits<_Up>>
2161 _GLIBCXX_SIMD_INTRINSIC
constexpr operator _Up()
const
2162 {
return __intrin_bitcast<typename _UVT::type>(__x); }
2165template <
typename _Tp>
2166 _GLIBCXX_SIMD_INTRINSIC
constexpr _AutoCast<_Tp>
2167 __auto_bitcast(
const _Tp& __x)
2170template <
typename _Tp,
size_t _Np>
2171 _GLIBCXX_SIMD_INTRINSIC
constexpr
2172 _AutoCast<typename _SimdWrapper<_Tp, _Np>::_BuiltinType>
2173 __auto_bitcast(
const _SimdWrapper<_Tp, _Np>& __x)
2174 {
return {__x._M_data}; }
2179#if _GLIBCXX_SIMD_HAVE_SSE_ABI
2181#if _GLIBCXX_SIMD_HAVE_AVX512F && _GLIBCXX_SIMD_X86INTRIN
2182template <
size_t _Size>
2183 struct __bool_storage_member_type
2185 static_assert((_Size & (_Size - 1)) != 0,
2186 "This trait may only be used for non-power-of-2 sizes. "
2187 "Power-of-2 sizes must be specialized.");
2189 typename __bool_storage_member_type<std::__bit_ceil(_Size)>::type;
2193 struct __bool_storage_member_type<1> {
using type = bool; };
2196 struct __bool_storage_member_type<2> {
using type = __mmask8; };
2199 struct __bool_storage_member_type<4> {
using type = __mmask8; };
2202 struct __bool_storage_member_type<8> {
using type = __mmask8; };
2205 struct __bool_storage_member_type<16> {
using type = __mmask16; };
2208 struct __bool_storage_member_type<32> {
using type = __mmask32; };
2211 struct __bool_storage_member_type<64> {
using type = __mmask64; };
2217#if _GLIBCXX_SIMD_HAVE_SSE
2218template <
typename _Tp,
size_t _Bytes>
2219 struct __intrinsic_type<_Tp, _Bytes,
enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 64>>
2221 static_assert(!is_same_v<_Tp, long double>,
2222 "no __intrinsic_type support for long double on x86");
2224 static constexpr size_t _S_VBytes = _Bytes <= 16 ? 16 : _Bytes <= 32 ? 32 : 64;
2226 using type [[__gnu__::__vector_size__(_S_VBytes)]]
2227 = conditional_t<is_integral_v<_Tp>,
long long int, _Tp>;
2234#if _GLIBCXX_SIMD_HAVE_NEON
2236 struct __intrinsic_type<float, 8, void>
2237 {
using type = float32x2_t; };
2240 struct __intrinsic_type<float, 16, void>
2241 {
using type = float32x4_t; };
2244 struct __intrinsic_type<double, 8, void>
2246#if _GLIBCXX_SIMD_HAVE_NEON_A64
2247 using type = float64x1_t;
2252 struct __intrinsic_type<double, 16, void>
2254#if _GLIBCXX_SIMD_HAVE_NEON_A64
2255 using type = float64x2_t;
2259#define _GLIBCXX_SIMD_ARM_INTRIN(_Bits, _Np) \
2261 struct __intrinsic_type<__int_with_sizeof_t<_Bits / 8>, \
2262 _Np * _Bits / 8, void> \
2263 { using type = int##_Bits##x##_Np##_t; }; \
2265 struct __intrinsic_type<make_unsigned_t<__int_with_sizeof_t<_Bits / 8>>, \
2266 _Np * _Bits / 8, void> \
2267 { using type = uint##_Bits##x##_Np##_t; }
2268_GLIBCXX_SIMD_ARM_INTRIN(8, 8);
2269_GLIBCXX_SIMD_ARM_INTRIN(8, 16);
2270_GLIBCXX_SIMD_ARM_INTRIN(16, 4);
2271_GLIBCXX_SIMD_ARM_INTRIN(16, 8);
2272_GLIBCXX_SIMD_ARM_INTRIN(32, 2);
2273_GLIBCXX_SIMD_ARM_INTRIN(32, 4);
2274_GLIBCXX_SIMD_ARM_INTRIN(64, 1);
2275_GLIBCXX_SIMD_ARM_INTRIN(64, 2);
2276#undef _GLIBCXX_SIMD_ARM_INTRIN
2278template <
typename _Tp,
size_t _Bytes>
2279 struct __intrinsic_type<_Tp, _Bytes,
enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 16>>
2281 static constexpr int _SVecBytes = _Bytes <= 8 ? 8 : 16;
2283 using _Ip = __int_for_sizeof_t<_Tp>;
2286 is_floating_point_v<_Tp>, _Tp,
2287 conditional_t<is_unsigned_v<_Tp>, make_unsigned_t<_Ip>, _Ip>>;
2289 static_assert(!is_same_v<_Tp, _Up> || _SVecBytes != _Bytes,
2290 "should use explicit specialization above");
2292 using type =
typename __intrinsic_type<_Up, _SVecBytes>::type;
2299template <
typename _Tp>
2300 struct __intrinsic_type_impl;
2302#define _GLIBCXX_SIMD_PPC_INTRIN(_Tp) \
2304 struct __intrinsic_type_impl<_Tp> { using type = __vector _Tp; }
2305_GLIBCXX_SIMD_PPC_INTRIN(
float);
2307_GLIBCXX_SIMD_PPC_INTRIN(
double);
2309_GLIBCXX_SIMD_PPC_INTRIN(
signed char);
2310_GLIBCXX_SIMD_PPC_INTRIN(
unsigned char);
2311_GLIBCXX_SIMD_PPC_INTRIN(
signed short);
2312_GLIBCXX_SIMD_PPC_INTRIN(
unsigned short);
2313_GLIBCXX_SIMD_PPC_INTRIN(
signed int);
2314_GLIBCXX_SIMD_PPC_INTRIN(
unsigned int);
2315#if defined __VSX__ || __SIZEOF_LONG__ == 4
2316_GLIBCXX_SIMD_PPC_INTRIN(
signed long);
2317_GLIBCXX_SIMD_PPC_INTRIN(
unsigned long);
2320_GLIBCXX_SIMD_PPC_INTRIN(
signed long long);
2321_GLIBCXX_SIMD_PPC_INTRIN(
unsigned long long);
2323#undef _GLIBCXX_SIMD_PPC_INTRIN
2325template <
typename _Tp,
size_t _Bytes>
2326 struct __intrinsic_type<_Tp, _Bytes,
enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 16>>
2328 static constexpr bool _S_is_ldouble = is_same_v<_Tp, long double>;
2331 static_assert(!(_S_is_ldouble &&
sizeof(
long double) >
sizeof(
double)),
2332 "no __intrinsic_type support for 128-bit floating point on PowerPC");
2335 static_assert(!(is_same_v<_Tp, double>
2336 || (_S_is_ldouble &&
sizeof(
long double) ==
sizeof(
double))),
2337 "no __intrinsic_type support for 64-bit floating point on PowerPC w/o VSX");
2340 static constexpr auto __element_type()
2342 if constexpr (is_floating_point_v<_Tp>)
2344 if constexpr (_S_is_ldouble)
2349 else if constexpr (is_signed_v<_Tp>)
2351 if constexpr (
sizeof(_Tp) ==
sizeof(_SChar))
2353 else if constexpr (
sizeof(_Tp) ==
sizeof(
short))
2355 else if constexpr (
sizeof(_Tp) ==
sizeof(
int))
2357 else if constexpr (
sizeof(_Tp) ==
sizeof(_LLong))
2362 if constexpr (
sizeof(_Tp) ==
sizeof(_UChar))
2364 else if constexpr (
sizeof(_Tp) ==
sizeof(_UShort))
2366 else if constexpr (
sizeof(_Tp) ==
sizeof(_UInt))
2368 else if constexpr (
sizeof(_Tp) ==
sizeof(_ULLong))
2373 using type =
typename __intrinsic_type_impl<
decltype(__element_type())>::type;
2379template <
size_t _W
idth>
2380 struct _SimdWrapper<bool, _Width,
2381 void_t<typename __bool_storage_member_type<_Width>::type>>
2383 using _BuiltinType =
typename __bool_storage_member_type<_Width>::type;
2384 using value_type = bool;
2386 static constexpr size_t _S_full_size =
sizeof(_BuiltinType) * __CHAR_BIT__;
2388 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper<bool, _S_full_size>
2389 __as_full_vector()
const
2392 _GLIBCXX_SIMD_INTRINSIC
constexpr
2393 _SimdWrapper() =
default;
2395 _GLIBCXX_SIMD_INTRINSIC
constexpr
2396 _SimdWrapper(_BuiltinType __k) : _M_data(__k) {};
2398 _GLIBCXX_SIMD_INTRINSIC
2399 operator const _BuiltinType&()
const
2402 _GLIBCXX_SIMD_INTRINSIC
2403 operator _BuiltinType&()
2406 _GLIBCXX_SIMD_INTRINSIC _BuiltinType
2410 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type
2411 operator[](
size_t __i)
const
2412 {
return _M_data & (_BuiltinType(1) << __i); }
2414 template <
size_t __i>
2415 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type
2416 operator[](_SizeConstant<__i>)
const
2417 {
return _M_data & (_BuiltinType(1) << __i); }
2419 _GLIBCXX_SIMD_INTRINSIC
constexpr void
2420 _M_set(
size_t __i, value_type __x)
2423 _M_data |= (_BuiltinType(1) << __i);
2425 _M_data &= ~(_BuiltinType(1) << __i);
2428 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
2429 _M_is_constprop()
const
2430 {
return __builtin_constant_p(_M_data); }
2432 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
2433 _M_is_constprop_none_of()
const
2435 if (__builtin_constant_p(_M_data))
2437 constexpr int __nbits =
sizeof(_BuiltinType) * __CHAR_BIT__;
2438 constexpr _BuiltinType __active_mask
2439 = ~_BuiltinType() >> (__nbits - _Width);
2440 return (_M_data & __active_mask) == 0;
2445 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
2446 _M_is_constprop_all_of()
const
2448 if (__builtin_constant_p(_M_data))
2450 constexpr int __nbits =
sizeof(_BuiltinType) * __CHAR_BIT__;
2451 constexpr _BuiltinType __active_mask
2452 = ~_BuiltinType() >> (__nbits - _Width);
2453 return (_M_data & __active_mask) == __active_mask;
2458 _BuiltinType _M_data;
2462template <
bool _MustZeroInitPadding,
typename _BuiltinType>
2463 struct _SimdWrapperBase;
2465template <
typename _BuiltinType>
2466 struct _SimdWrapperBase<false, _BuiltinType>
2468 _GLIBCXX_SIMD_INTRINSIC
constexpr
2469 _SimdWrapperBase() =
default;
2471 _GLIBCXX_SIMD_INTRINSIC
constexpr
2472 _SimdWrapperBase(_BuiltinType __init) : _M_data(__init) {}
2474 _BuiltinType _M_data;
2477template <
typename _BuiltinType>
2478 struct _SimdWrapperBase<true, _BuiltinType>
2481 _GLIBCXX_SIMD_INTRINSIC
constexpr
2482 _SimdWrapperBase() : _M_data() {}
2484 _GLIBCXX_SIMD_INTRINSIC
constexpr
2485 _SimdWrapperBase(_BuiltinType __init) : _M_data(__init) {}
2487 _BuiltinType _M_data;
2492template <
typename _Tp,
size_t _W
idth>
2493 struct _SimdWrapper<
2495 void_t<__vector_type_t<_Tp, _Width>, __intrinsic_type_t<_Tp, _Width>>>
2496 : _SimdWrapperBase<__has_iec559_behavior<__signaling_NaN, _Tp>::value
2497 && sizeof(_Tp) * _Width
2498 == sizeof(__vector_type_t<_Tp, _Width>),
2499 __vector_type_t<_Tp, _Width>>
2502 = _SimdWrapperBase<__has_iec559_behavior<__signaling_NaN, _Tp>::value
2503 &&
sizeof(_Tp) * _Width
2504 ==
sizeof(__vector_type_t<_Tp, _Width>),
2505 __vector_type_t<_Tp, _Width>>;
2507 static_assert(__is_vectorizable_v<_Tp>);
2508 static_assert(_Width >= 2);
2510 using _BuiltinType = __vector_type_t<_Tp, _Width>;
2511 using value_type = _Tp;
2513 static inline constexpr size_t _S_full_size
2514 =
sizeof(_BuiltinType) /
sizeof(value_type);
2515 static inline constexpr int _S_size = _Width;
2516 static inline constexpr bool _S_is_partial = _S_full_size != _S_size;
2518 using _Base::_M_data;
2520 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper<_Tp, _S_full_size>
2521 __as_full_vector()
const
2524 _GLIBCXX_SIMD_INTRINSIC
constexpr
2525 _SimdWrapper(initializer_list<_Tp> __init)
2526 : _Base(__generate_from_n_evaluations<_Width, _BuiltinType>(
2527 [&](auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
2528 return __init.
begin()[__i.value];
2531 _GLIBCXX_SIMD_INTRINSIC
constexpr
2532 _SimdWrapper() =
default;
2534 _GLIBCXX_SIMD_INTRINSIC
constexpr
2535 _SimdWrapper(
const _SimdWrapper&) =
default;
2537 _GLIBCXX_SIMD_INTRINSIC
constexpr
2538 _SimdWrapper(_SimdWrapper&&) =
default;
2540 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper&
2541 operator=(
const _SimdWrapper&) =
default;
2543 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper&
2544 operator=(_SimdWrapper&&) =
default;
2546 template <
typename _V,
typename =
enable_if_t<disjunction_v<
2547 is_same<_V, __vector_type_t<_Tp, _Width>>,
2548 is_same<_V, __intrinsic_type_t<_Tp, _Width>>>>>
2549 _GLIBCXX_SIMD_INTRINSIC
constexpr
2550 _SimdWrapper(_V __x)
2552 : _Base(__vector_bitcast<_Tp, _Width>(__x)) {}
2554 template <
typename... _As,
2555 typename =
enable_if_t<((is_same_v<simd_abi::scalar, _As> && ...)
2556 &&
sizeof...(_As) <= _Width)>>
2557 _GLIBCXX_SIMD_INTRINSIC
constexpr
2558 operator _SimdTuple<_Tp, _As...>()
const
2560 return __generate_from_n_evaluations<
sizeof...(_As), _SimdTuple<_Tp, _As...>>(
2561 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
2562 {
return _M_data[int(__i)]; });
2565 _GLIBCXX_SIMD_INTRINSIC
constexpr
2566 operator const _BuiltinType&()
const
2569 _GLIBCXX_SIMD_INTRINSIC
constexpr
2570 operator _BuiltinType&()
2573 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp
2574 operator[](
size_t __i)
const
2575 {
return _M_data[__i]; }
2577 template <
size_t __i>
2578 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp
2579 operator[](_SizeConstant<__i>)
const
2580 {
return _M_data[__i]; }
2582 _GLIBCXX_SIMD_INTRINSIC
constexpr void
2583 _M_set(
size_t __i, _Tp __x)
2585 if (__builtin_is_constant_evaluated())
2586 _M_data = __generate_from_n_evaluations<_Width, _BuiltinType>([&](
auto __j) {
2587 return __j == __i ? __x : _M_data[__j()];
2593 _GLIBCXX_SIMD_INTRINSIC
2595 _M_is_constprop()
const
2596 {
return __builtin_constant_p(_M_data); }
2598 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
2599 _M_is_constprop_none_of()
const
2601 if (__builtin_constant_p(_M_data))
2604 if constexpr (is_floating_point_v<_Tp>)
2606 using _Ip = __int_for_sizeof_t<_Tp>;
2607 const auto __intdata = __vector_bitcast<_Ip>(_M_data);
2608 __execute_n_times<_Width>(
2609 [&](
auto __i) { __r &= __intdata[__i.value] == _Ip(); });
2612 __execute_n_times<_Width>(
2613 [&](
auto __i) { __r &= _M_data[__i.value] == _Tp(); });
2614 if (__builtin_constant_p(__r))
2620 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
2621 _M_is_constprop_all_of()
const
2623 if (__builtin_constant_p(_M_data))
2626 if constexpr (is_floating_point_v<_Tp>)
2628 using _Ip = __int_for_sizeof_t<_Tp>;
2629 const auto __intdata = __vector_bitcast<_Ip>(_M_data);
2630 __execute_n_times<_Width>(
2631 [&](
auto __i) { __r &= __intdata[__i.value] == ~_Ip(); });
2634 __execute_n_times<_Width>(
2635 [&](
auto __i) { __r &= _M_data[__i.value] == ~_Tp(); });
2636 if (__builtin_constant_p(__r))
2646template <
typename _Tp>
2648 __vectorized_sizeof()
2650 if constexpr (!__is_vectorizable_v<_Tp>)
2653 if constexpr (
sizeof(_Tp) <= 8)
2656 if constexpr (__have_avx512bw)
2658 if constexpr (__have_avx512f &&
sizeof(_Tp) >= 4)
2660 if constexpr (__have_avx2)
2662 if constexpr (__have_avx && is_floating_point_v<_Tp>)
2664 if constexpr (__have_sse2)
2666 if constexpr (__have_sse && is_same_v<_Tp, float>)
2676 if constexpr (__have_power8vec
2677 || (__have_power_vmx && (
sizeof(_Tp) < 8))
2678 || (__have_power_vsx && is_floating_point_v<_Tp>) )
2682 if constexpr (__have_neon_a64
2683 || (__have_neon_a32 && !is_same_v<_Tp, double>) )
2685 if constexpr (__have_neon
2690 && (__support_neon_float || !is_floating_point_v<_Tp>))
2700template <
typename _Tp>
2701 inline constexpr int max_fixed_size
2702 = (__have_avx512bw &&
sizeof(_Tp) == 1) ? 64 : 32;
2705#if defined __x86_64__ || defined __aarch64__
2706template <
typename _Tp>
2707 using compatible =
conditional_t<(
sizeof(_Tp) <= 8), _VecBuiltin<16>, scalar>;
2708#elif defined __ARM_NEON
2711template <
typename _Tp>
2714 && (__support_neon_float || !is_floating_point_v<_Tp>)),
2715 _VecBuiltin<16>, scalar>;
2718 using compatible = scalar;
2723template <
typename _Tp>
2725 __determine_native_abi()
2727 constexpr size_t __bytes = __vectorized_sizeof<_Tp>();
2728 if constexpr (__bytes ==
sizeof(_Tp))
2729 return static_cast<scalar*
>(
nullptr);
2730 else if constexpr (__have_avx512vl || (__have_avx512f && __bytes == 64))
2731 return static_cast<_VecBltnBtmsk<__bytes>*
>(
nullptr);
2733 return static_cast<_VecBuiltin<__bytes>*
>(
nullptr);
2736template <
typename _Tp,
typename = enable_if_t<__is_vectorizable_v<_Tp>>>
2737 using native = remove_pointer_t<decltype(__determine_native_abi<_Tp>())>;
2741#if defined _GLIBCXX_SIMD_DEFAULT_ABI
2742template <
typename _Tp>
2743 using __default_abi = _GLIBCXX_SIMD_DEFAULT_ABI<_Tp>;
2745template <
typename _Tp>
2746 using __default_abi = compatible<_Tp>;
2753template <
typename _Tp>
2754 struct is_simd_flag_type
2759 struct is_simd_flag_type<element_aligned_tag>
2764 struct is_simd_flag_type<vector_aligned_tag>
2768template <
size_t _Np>
2769 struct is_simd_flag_type<overaligned_tag<_Np>>
2770 : __bool_constant<(_Np > 0) and __has_single_bit(_Np)>
2773template <
typename _Tp>
2774 inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<_Tp>::value;
2776template <
typename _Tp,
typename = enable_if_t<is_simd_flag_type_v<_Tp>>>
2777 using _IsSimdFlagType = _Tp;
2780template <
typename _Tp,
typename =
void_t<>>
2783template <
typename _Tp>
2784 struct is_abi_tag<_Tp,
void_t<typename _Tp::_IsValidAbiTag>>
2785 :
public _Tp::_IsValidAbiTag {};
2787template <
typename _Tp>
2788 inline constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value;
2791template <
typename _Tp>
2794template <
typename _Tp>
2795 inline constexpr bool is_simd_v = is_simd<_Tp>::value;
2797template <
typename _Tp>
2800template <
typename _Tp>
2801inline constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value;
2804template <
typename _Tp,
typename _Abi,
typename =
void>
2805 struct __simd_size_impl {};
2807template <
typename _Tp,
typename _Abi>
2808 struct __simd_size_impl<
2810 enable_if_t<conjunction_v<__is_vectorizable<_Tp>, is_abi_tag<_Abi>>>>
2811 : _SizeConstant<_Abi::template _S_size<_Tp>> {};
2813template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2814 struct simd_size : __simd_size_impl<_Tp, _Abi> {};
2816template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2817 inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
2820template <
typename _Tp,
size_t _Np,
typename =
void>
2821 struct __deduce_impl;
2832template <
typename _Tp,
size_t _Np,
typename...>
2835template <
typename _Tp,
size_t _Np,
typename... _Abis>
2836 using deduce_t =
typename deduce<_Tp, _Np, _Abis...>::type;
2841template <
typename _Tp,
typename _V,
typename =
void>
2844template <
typename _Tp,
typename _Up,
typename _Abi>
2845 struct rebind_simd<_Tp, simd<_Up, _Abi>,
2846 void_t<simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>>
2847 {
using type = simd<_Tp, simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>; };
2849template <
typename _Tp,
typename _Up,
typename _Abi>
2850 struct rebind_simd<_Tp, simd_mask<_Up, _Abi>,
2851 void_t<simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>>
2852 {
using type = simd_mask<_Tp, simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>; };
2854template <
typename _Tp,
typename _V>
2855 using rebind_simd_t =
typename rebind_simd<_Tp, _V>::type;
2858template <
int _Np,
typename _V,
typename =
void>
2861template <
int _Np,
typename _Tp,
typename _Abi>
2862 struct resize_simd<_Np, simd<_Tp, _Abi>,
void_t<simd_abi::deduce_t<_Tp, _Np, _Abi>>>
2863 {
using type = simd<_Tp, simd_abi::deduce_t<_Tp, _Np, _Abi>>; };
2865template <
int _Np,
typename _Tp,
typename _Abi>
2866 struct resize_simd<_Np, simd_mask<_Tp, _Abi>,
void_t<simd_abi::deduce_t<_Tp, _Np, _Abi>>>
2867 {
using type = simd_mask<_Tp, simd_abi::deduce_t<_Tp, _Np, _Abi>>; };
2869template <
int _Np,
typename _V>
2870 using resize_simd_t =
typename resize_simd<_Np, _V>::type;
2874template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
2875 struct memory_alignment
2876 :
public _SizeConstant<vector_aligned_tag::_S_alignment<_Tp, _Up>> {};
2878template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
2879 inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value;
2882template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2885template <
typename _Tp,
typename _Abi>
2886 struct is_simd<simd<_Tp, _Abi>> :
public true_type {};
2888template <
typename _Tp>
2889 using native_simd = simd<_Tp, simd_abi::native<_Tp>>;
2891template <
typename _Tp,
int _Np>
2892 using fixed_size_simd = simd<_Tp, simd_abi::fixed_size<_Np>>;
2894template <
typename _Tp,
size_t _Np>
2895 using __deduced_simd = simd<_Tp, simd_abi::deduce_t<_Tp, _Np>>;
2898template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2901template <
typename _Tp,
typename _Abi>
2902 struct is_simd_mask<simd_mask<_Tp, _Abi>> :
public true_type {};
2904template <
typename _Tp>
2905 using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>;
2907template <
typename _Tp,
int _Np>
2908 using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>;
2910template <
typename _Tp,
size_t _Np>
2911 using __deduced_simd_mask = simd_mask<_Tp, simd_abi::deduce_t<_Tp, _Np>>;
2915template <
typename _Tp,
typename _Up,
typename _Ap,
bool = is_simd_v<_Tp>,
typename =
void>
2916 struct __static_simd_cast_return_type;
2918template <
typename _Tp,
typename _A0,
typename _Up,
typename _Ap>
2919 struct __static_simd_cast_return_type<simd_mask<_Tp, _A0>, _Up, _Ap, false, void>
2920 : __static_simd_cast_return_type<simd<_Tp, _A0>, _Up, _Ap> {};
2922template <
typename _Tp,
typename _Up,
typename _Ap>
2923 struct __static_simd_cast_return_type<
2924 _Tp, _Up, _Ap, true,
enable_if_t<_Tp::
size() == simd_size_v<_Up, _Ap>>>
2925 {
using type = _Tp; };
2927template <
typename _Tp,
typename _Ap>
2928 struct __static_simd_cast_return_type<_Tp, _Tp, _Ap, false,
2929#ifdef _GLIBCXX_SIMD_FIX_P2TS_ISSUE66
2935 {
using type = simd<_Tp, _Ap>; };
2937template <
typename _Tp,
typename =
void>
2938 struct __safe_make_signed {
using type = _Tp;};
2940template <
typename _Tp>
2941 struct __safe_make_signed<_Tp,
enable_if_t<is_integral_v<_Tp>>>
2944 using type = make_signed_t<make_unsigned_t<_Tp>>;
2947template <
typename _Tp>
2948 using safe_make_signed_t =
typename __safe_make_signed<_Tp>::type;
2950template <
typename _Tp,
typename _Up,
typename _Ap>
2951 struct __static_simd_cast_return_type<_Tp, _Up, _Ap, false,
2952#ifdef _GLIBCXX_SIMD_FIX_P2TS_ISSUE66
2960 (is_integral_v<_Up> && is_integral_v<_Tp> &&
2961#ifndef _GLIBCXX_SIMD_FIX_P2TS_ISSUE65
2962 is_signed_v<_Up> != is_signed_v<_Tp> &&
2964 is_same_v<safe_make_signed_t<_Up>, safe_make_signed_t<_Tp>>),
2965 simd<_Tp, _Ap>, fixed_size_simd<_Tp, simd_size_v<_Up, _Ap>>>;
2968template <
typename _Tp,
typename _Up,
typename _Ap,
2970 =
typename __static_simd_cast_return_type<_Tp, _Up, _Ap>::type>
2971 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _R
2972 static_simd_cast(
const simd<_Up, _Ap>& __x)
2974 if constexpr (is_same<_R, simd<_Up, _Ap>>::value)
2978 _SimdConverter<_Up, _Ap, typename _R::value_type, typename _R::abi_type>
2980 return _R(__private_init, __c(__data(__x)));
2984namespace __proposed {
2985template <
typename _Tp,
typename _Up,
typename _Ap,
2987 =
typename __static_simd_cast_return_type<_Tp, _Up, _Ap>::type>
2988 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
typename _R::mask_type
2989 static_simd_cast(
const simd_mask<_Up, _Ap>& __x)
2991 using _RM =
typename _R::mask_type;
2992 return {__private_init, _RM::abi_type::_MaskImpl::template _S_convert<
2993 typename _RM::simd_type::value_type>(__x)};
2998template <
typename _Tp,
typename _Up,
typename _Ap,
2999 typename _To = __value_type_or_identity_t<_Tp>>
3000 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
auto
3001 simd_cast(
const simd<_ValuePreserving<_Up, _To>, _Ap>& __x)
3002 ->
decltype(static_simd_cast<_Tp>(__x))
3003 {
return static_simd_cast<_Tp>(__x); }
3005namespace __proposed {
3006template <
typename _Tp,
typename _Up,
typename _Ap,
3007 typename _To = __value_type_or_identity_t<_Tp>>
3008 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
auto
3009 simd_cast(
const simd_mask<_ValuePreserving<_Up, _To>, _Ap>& __x)
3010 ->
decltype(static_simd_cast<_Tp>(__x))
3011 {
return static_simd_cast<_Tp>(__x); }
3016namespace __proposed {
3043template <
typename _Tp,
typename _Up,
typename _Ap>
3044 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
enable_if_t<
3045 conjunction_v<is_simd<_Tp>, is_same<typename _Tp::value_type, _Up>>, _Tp>
3046 resizing_simd_cast(
const simd<_Up, _Ap>& __x)
3048 if constexpr (is_same_v<typename _Tp::abi_type, _Ap>)
3050 else if (__builtin_is_constant_evaluated())
3051 return _Tp([&](
auto __i)
constexpr {
3052 return __i < simd_size_v<_Up, _Ap> ? __x[__i] : _Up();
3054 else if constexpr (simd_size_v<_Up, _Ap> == 1)
3060 else if constexpr (_Tp::size() == 1)
3062 else if constexpr (
sizeof(_Tp) ==
sizeof(__x)
3063 && !__is_fixed_size_abi_v<_Ap>)
3064 return {__private_init,
3065 __vector_bitcast<typename _Tp::value_type, _Tp::size()>(
3066 _Ap::_S_masked(__data(__x))._M_data)};
3070 __builtin_memcpy(&__data(__r), &__data(__x),
3072 *
std::min(_Tp::size(), simd_size_v<_Up, _Ap>));
3077template <
typename _Tp,
typename _Up,
typename _Ap>
3078 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3079 enable_if_t<is_simd_mask_v<_Tp>, _Tp>
3080 resizing_simd_cast(
const simd_mask<_Up, _Ap>& __x)
3082 return {__private_init, _Tp::abi_type::_MaskImpl::template _S_convert<
3083 typename _Tp::simd_type::value_type>(__x)};
3089template <
typename _Tp,
int _Np>
3090 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd<_Tp, _Np>
3091 to_fixed_size(
const fixed_size_simd<_Tp, _Np>& __x)
3094template <
typename _Tp,
int _Np>
3095 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd_mask<_Tp, _Np>
3096 to_fixed_size(
const fixed_size_simd_mask<_Tp, _Np>& __x)
3099template <
typename _Tp,
typename _Ap>
3100 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd<_Tp, simd_size_v<_Tp, _Ap>>
3101 to_fixed_size(
const simd<_Tp, _Ap>& __x)
3103 using _Rp = fixed_size_simd<_Tp, simd_size_v<_Tp, _Ap>>;
3104 return _Rp([&__x](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3107template <
typename _Tp,
typename _Ap>
3108 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd_mask<_Tp, simd_size_v<_Tp, _Ap>>
3109 to_fixed_size(
const simd_mask<_Tp, _Ap>& __x)
3111 return {__private_init,
3112 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; }};
3116template <
typename _Tp,
int _Np>
3117 _GLIBCXX_SIMD_INTRINSIC
3118 enable_if_t<(_Np == native_simd<_Tp>::size()), native_simd<_Tp>>
3119 to_native(
const fixed_size_simd<_Tp, _Np>& __x)
3121 alignas(memory_alignment_v<native_simd<_Tp>>) _Tp __mem[_Np];
3122 __x.copy_to(__mem, vector_aligned);
3123 return {__mem, vector_aligned};
3126template <
typename _Tp,
size_t _Np>
3127 _GLIBCXX_SIMD_INTRINSIC
3128 enable_if_t<(_Np == native_simd_mask<_Tp>::size()), native_simd_mask<_Tp>>
3129 to_native(
const fixed_size_simd_mask<_Tp, _Np>& __x)
3131 return native_simd_mask<_Tp>(
3133 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3137template <
typename _Tp,
size_t _Np>
3138 _GLIBCXX_SIMD_INTRINSIC
enable_if_t<(_Np == simd<_Tp>::size()), simd<_Tp>>
3139 to_compatible(
const simd<_Tp, simd_abi::fixed_size<_Np>>& __x)
3141 alignas(memory_alignment_v<simd<_Tp>>) _Tp __mem[_Np];
3142 __x.copy_to(__mem, vector_aligned);
3143 return {__mem, vector_aligned};
3146template <
typename _Tp,
size_t _Np>
3147 _GLIBCXX_SIMD_INTRINSIC
3148 enable_if_t<(_Np == simd_mask<_Tp>::size()), simd_mask<_Tp>>
3149 to_compatible(
const simd_mask<_Tp, simd_abi::fixed_size<_Np>>& __x)
3151 return simd_mask<_Tp>(
3152 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3159template <
typename _M,
typename _Tp>
3160 class const_where_expression
3163 static_assert(is_same_v<_V, __remove_cvref_t<_Tp>>);
3165 struct _Wrapper {
using value_type = _V; };
3168 using _Impl =
typename _V::_Impl;
3171 typename conditional_t<is_arithmetic_v<_V>, _Wrapper, _V>::value_type;
3173 _GLIBCXX_SIMD_INTRINSIC
friend const _M&
3174 __get_mask(
const const_where_expression& __x)
3175 {
return __x._M_k; }
3177 _GLIBCXX_SIMD_INTRINSIC
friend const _Tp&
3178 __get_lvalue(
const const_where_expression& __x)
3179 {
return __x._M_value; }
3185 const_where_expression(
const const_where_expression&) =
delete;
3187 const_where_expression& operator=(
const const_where_expression&) =
delete;
3189 _GLIBCXX_SIMD_INTRINSIC
constexpr
3190 const_where_expression(
const _M& __kk,
const _Tp& dd)
3191 : _M_k(__kk), _M_value(const_cast<_Tp&>(dd)) {}
3193 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _V
3196 return {__private_init,
3197 _Impl::template _S_masked_unary<negate>(__data(_M_k),
3201 template <
typename _Up,
typename _Flags>
3202 [[nodiscard]] _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _V
3203 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>)
const&&
3205 return {__private_init,
3206 _Impl::_S_masked_load(__data(_M_value), __data(_M_k),
3207 _Flags::template _S_apply<_V>(__mem))};
3210 template <
typename _Up,
typename _Flags>
3211 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3212 copy_to(_LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>)
const&&
3214 _Impl::_S_masked_store(__data(_M_value),
3215 _Flags::template _S_apply<_V>(__mem),
3221template <
typename _Tp>
3222 class const_where_expression<bool, _Tp>
3227 static_assert(is_same_v<_V, __remove_cvref_t<_Tp>>);
3229 struct _Wrapper {
using value_type = _V; };
3233 =
typename conditional_t<is_arithmetic_v<_V>, _Wrapper, _V>::value_type;
3235 _GLIBCXX_SIMD_INTRINSIC
friend const _M&
3236 __get_mask(
const const_where_expression& __x)
3237 {
return __x._M_k; }
3239 _GLIBCXX_SIMD_INTRINSIC
friend const _Tp&
3240 __get_lvalue(
const const_where_expression& __x)
3241 {
return __x._M_value; }
3247 const_where_expression(
const const_where_expression&) =
delete;
3248 const_where_expression& operator=(
const const_where_expression&) =
delete;
3250 _GLIBCXX_SIMD_INTRINSIC
constexpr
3251 const_where_expression(
const bool __kk,
const _Tp& dd)
3252 : _M_k(__kk), _M_value(const_cast<_Tp&>(dd)) {}
3254 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _V
3256 {
return _M_k ? -_M_value : _M_value; }
3258 template <
typename _Up,
typename _Flags>
3259 [[nodiscard]] _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _V
3260 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>)
const&&
3261 {
return _M_k ?
static_cast<_V
>(__mem[0]) : _M_value; }
3263 template <
typename _Up,
typename _Flags>
3264 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3265 copy_to(_LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>)
const&&
3268 __mem[0] = _M_value;
3273template <
typename _M,
typename _Tp>
3274 class where_expression :
public const_where_expression<_M, _Tp>
3276 using _Impl =
typename const_where_expression<_M, _Tp>::_Impl;
3278 static_assert(!is_const<_Tp>::value,
3279 "where_expression may only be instantiated with __a non-const "
3282 using typename const_where_expression<_M, _Tp>::value_type;
3283 using const_where_expression<_M, _Tp>::_M_k;
3284 using const_where_expression<_M, _Tp>::_M_value;
3287 is_same<typename _M::abi_type, typename _Tp::abi_type>::value,
"");
3288 static_assert(_M::size() == _Tp::size(),
"");
3290 _GLIBCXX_SIMD_INTRINSIC
friend constexpr _Tp&
3291 __get_lvalue(where_expression& __x)
3292 {
return __x._M_value; }
3295 where_expression(
const where_expression&) =
delete;
3296 where_expression& operator=(
const where_expression&) =
delete;
3298 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3299 where_expression(
const _M& __kk, _Tp& dd)
3300 : const_where_expression<_M, _Tp>(__kk, dd) {}
3302 template <
typename _Up>
3303 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3304 operator=(_Up&& __x) &&
3306 _Impl::_S_masked_assign(__data(_M_k), __data(_M_value),
3307 __to_value_type_or_member_type<_Tp>(
3308 static_cast<_Up&&
>(__x)));
3311#define _GLIBCXX_SIMD_OP_(__op, __name) \
3312 template <typename _Up> \
3313 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR void \
3314 operator __op##=(_Up&& __x)&& \
3316 _Impl::template _S_masked_cassign( \
3317 __data(_M_k), __data(_M_value), \
3318 __to_value_type_or_member_type<_Tp>(static_cast<_Up&&>(__x)), \
3319 [](auto __impl, auto __lhs, auto __rhs) \
3320 constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA \
3321 { return __impl.__name(__lhs, __rhs); }); \
3324 _GLIBCXX_SIMD_OP_(+, _S_plus);
3325 _GLIBCXX_SIMD_OP_(-, _S_minus);
3326 _GLIBCXX_SIMD_OP_(*, _S_multiplies);
3327 _GLIBCXX_SIMD_OP_(/, _S_divides);
3328 _GLIBCXX_SIMD_OP_(%, _S_modulus);
3329 _GLIBCXX_SIMD_OP_(&, _S_bit_and);
3330 _GLIBCXX_SIMD_OP_(|, _S_bit_or);
3331 _GLIBCXX_SIMD_OP_(^, _S_bit_xor);
3332 _GLIBCXX_SIMD_OP_(<<, _S_shift_left);
3333 _GLIBCXX_SIMD_OP_(>>, _S_shift_right);
3334#undef _GLIBCXX_SIMD_OP_
3336 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3340 = _Impl::template _S_masked_unary<__increment>(__data(_M_k), __data(_M_value));
3343 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3347 = _Impl::template _S_masked_unary<__increment>(__data(_M_k), __data(_M_value));
3350 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3354 = _Impl::template _S_masked_unary<__decrement>(__data(_M_k), __data(_M_value));
3357 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3361 = _Impl::template _S_masked_unary<__decrement>(__data(_M_k), __data(_M_value));
3365 template <
typename _Up,
typename _Flags>
3366 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3367 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>) &&
3369 __data(_M_value) = _Impl::_S_masked_load(__data(_M_value), __data(_M_k),
3370 _Flags::template _S_apply<_Tp>(__mem));
3375template <
typename _Tp>
3376 class where_expression<bool, _Tp>
3377 :
public const_where_expression<bool, _Tp>
3380 using typename const_where_expression<_M, _Tp>::value_type;
3381 using const_where_expression<_M, _Tp>::_M_k;
3382 using const_where_expression<_M, _Tp>::_M_value;
3385 where_expression(
const where_expression&) =
delete;
3386 where_expression& operator=(
const where_expression&) =
delete;
3388 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3389 where_expression(
const _M& __kk, _Tp& dd)
3390 : const_where_expression<_M, _Tp>(__kk, dd) {}
3392#define _GLIBCXX_SIMD_OP_(__op) \
3393 template <typename _Up> \
3394 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR void \
3395 operator __op(_Up&& __x)&& \
3396 { if (_M_k) _M_value __op static_cast<_Up&&>(__x); }
3398 _GLIBCXX_SIMD_OP_(=)
3399 _GLIBCXX_SIMD_OP_(+=)
3400 _GLIBCXX_SIMD_OP_(-=)
3401 _GLIBCXX_SIMD_OP_(*=)
3402 _GLIBCXX_SIMD_OP_(/=)
3403 _GLIBCXX_SIMD_OP_(%=)
3404 _GLIBCXX_SIMD_OP_(&=)
3405 _GLIBCXX_SIMD_OP_(|=)
3406 _GLIBCXX_SIMD_OP_(^=)
3407 _GLIBCXX_SIMD_OP_(<<=)
3408 _GLIBCXX_SIMD_OP_(>>=)
3409 #undef _GLIBCXX_SIMD_OP_
3411 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3413 {
if (_M_k) ++_M_value; }
3415 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3417 {
if (_M_k) ++_M_value; }
3419 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3421 {
if (_M_k) --_M_value; }
3423 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3425 {
if (_M_k) --_M_value; }
3428 template <
typename _Up,
typename _Flags>
3429 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3430 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>) &&
3431 {
if (_M_k) _M_value = __mem[0]; }
3435template <
typename _Tp,
typename _Ap>
3436 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3437 where_expression<simd_mask<_Tp, _Ap>, simd<_Tp, _Ap>>
3438 where(
const typename simd<_Tp, _Ap>::mask_type& __k, simd<_Tp, _Ap>& __value)
3439 {
return {__k, __value}; }
3441template <
typename _Tp,
typename _Ap>
3442 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3443 const_where_expression<simd_mask<_Tp, _Ap>, simd<_Tp, _Ap>>
3444 where(
const typename simd<_Tp, _Ap>::mask_type& __k,
const simd<_Tp, _Ap>& __value)
3445 {
return {__k, __value}; }
3447template <
typename _Tp,
typename _Ap>
3448 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3449 where_expression<simd_mask<_Tp, _Ap>, simd_mask<_Tp, _Ap>>
3450 where(
const remove_const_t<simd_mask<_Tp, _Ap>>& __k, simd_mask<_Tp, _Ap>& __value)
3451 {
return {__k, __value}; }
3453template <
typename _Tp,
typename _Ap>
3454 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3455 const_where_expression<simd_mask<_Tp, _Ap>, simd_mask<_Tp, _Ap>>
3456 where(
const remove_const_t<simd_mask<_Tp, _Ap>>& __k,
const simd_mask<_Tp, _Ap>& __value)
3457 {
return {__k, __value}; }
3459template <
typename _Tp>
3460 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR where_expression<bool, _Tp>
3461 where(_ExactBool __k, _Tp& __value)
3462 {
return {__k, __value}; }
3464template <
typename _Tp>
3465 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR const_where_expression<bool, _Tp>
3466 where(_ExactBool __k,
const _Tp& __value)
3467 {
return {__k, __value}; }
3469template <
typename _Tp,
typename _Ap>
3470 _GLIBCXX_SIMD_CONSTEXPR
void
3471 where(
bool __k, simd<_Tp, _Ap>& __value) =
delete;
3473template <
typename _Tp,
typename _Ap>
3474 _GLIBCXX_SIMD_CONSTEXPR
void
3475 where(
bool __k,
const simd<_Tp, _Ap>& __value) =
delete;
3478namespace __proposed {
3479template <
size_t _Np>
3482 const bitset<_Np> __bits;
3485 where_range(bitset<_Np> __b) : __bits(__b) {}
3492 _GLIBCXX_SIMD_INTRINSIC
void
3494 { __bit = __builtin_ctzl(__mask); }
3496 _GLIBCXX_SIMD_INTRINSIC
void
3500 __mask &= (__mask - 1);
3505 iterator(
decltype(__mask) __m) : __mask(__m) { __next_bit(); }
3506 iterator(
const iterator&) =
default;
3507 iterator(iterator&&) =
default;
3509 _GLIBCXX_SIMD_ALWAYS_INLINE
size_t
3513 _GLIBCXX_SIMD_ALWAYS_INLINE
size_t
3517 _GLIBCXX_SIMD_ALWAYS_INLINE iterator&
3525 _GLIBCXX_SIMD_ALWAYS_INLINE iterator
3528 iterator __tmp = *
this;
3534 _GLIBCXX_SIMD_ALWAYS_INLINE
bool
3535 operator==(
const iterator& __rhs)
const
3536 {
return __mask == __rhs.__mask; }
3538 _GLIBCXX_SIMD_ALWAYS_INLINE
bool
3539 operator!=(
const iterator& __rhs)
const
3540 {
return __mask != __rhs.__mask; }
3545 {
return __bits.to_ullong(); }
3552template <
typename _Tp,
typename _Ap>
3553 where_range<simd_size_v<_Tp, _Ap>>
3554 where(
const simd_mask<_Tp, _Ap>& __k)
3555 {
return __k.__to_bitset(); }
3561template <
typename _Tp,
typename _Abi,
typename _BinaryOperation = plus<>>
3562 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3563 reduce(
const simd<_Tp, _Abi>& __v, _BinaryOperation __binary_op = _BinaryOperation())
3564 {
return _Abi::_SimdImpl::_S_reduce(__v, __binary_op); }
3566template <
typename _M,
typename _V,
typename _BinaryOperation = plus<>>
3567 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3568 reduce(
const const_where_expression<_M, _V>& __x,
3569 typename _V::value_type __identity_element, _BinaryOperation __binary_op)
3571 if (__builtin_expect(none_of(__get_mask(__x)),
false))
3572 return __identity_element;
3574 _V __tmp = __identity_element;
3575 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3576 __data(__get_lvalue(__x)));
3577 return reduce(__tmp, __binary_op);
3580template <
typename _M,
typename _V>
3581 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3582 reduce(
const const_where_expression<_M, _V>& __x, plus<> __binary_op = {})
3583 {
return reduce(__x, 0, __binary_op); }
3585template <
typename _M,
typename _V>
3586 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3587 reduce(
const const_where_expression<_M, _V>& __x, multiplies<> __binary_op)
3588 {
return reduce(__x, 1, __binary_op); }
3590template <
typename _M,
typename _V>
3591 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3592 reduce(
const const_where_expression<_M, _V>& __x, bit_and<> __binary_op)
3593 {
return reduce(__x, ~
typename _V::value_type(), __binary_op); }
3595template <
typename _M,
typename _V>
3596 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3597 reduce(
const const_where_expression<_M, _V>& __x, bit_or<> __binary_op)
3598 {
return reduce(__x, 0, __binary_op); }
3600template <
typename _M,
typename _V>
3601 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3602 reduce(
const const_where_expression<_M, _V>& __x, bit_xor<> __binary_op)
3603 {
return reduce(__x, 0, __binary_op); }
3605template <
typename _Tp,
typename _Abi>
3606 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3607 hmin(
const simd<_Tp, _Abi>& __v)
noexcept
3608 {
return _Abi::_SimdImpl::_S_reduce(__v, __detail::_Minimum()); }
3610template <
typename _Tp,
typename _Abi>
3611 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3612 hmax(
const simd<_Tp, _Abi>& __v)
noexcept
3613 {
return _Abi::_SimdImpl::_S_reduce(__v, __detail::_Maximum()); }
3615template <
typename _M,
typename _V>
3616 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3617 typename _V::value_type
3618 hmin(
const const_where_expression<_M, _V>& __x)
noexcept
3620 using _Tp =
typename _V::value_type;
3621 constexpr _Tp __id_elem =
3622#ifdef __FINITE_MATH_ONLY__
3623 __finite_max_v<_Tp>;
3625 __value_or<__infinity, _Tp>(__finite_max_v<_Tp>);
3627 _V __tmp = __id_elem;
3628 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3629 __data(__get_lvalue(__x)));
3630 return _V::abi_type::_SimdImpl::_S_reduce(__tmp, __detail::_Minimum());
3633template <
typename _M,
typename _V>
3634 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3635 typename _V::value_type
3636 hmax(
const const_where_expression<_M, _V>& __x)
noexcept
3638 using _Tp =
typename _V::value_type;
3639 constexpr _Tp __id_elem =
3640#ifdef __FINITE_MATH_ONLY__
3641 __finite_min_v<_Tp>;
3644 if constexpr (__value_exists_v<__infinity, _Tp>)
3645 return -__infinity_v<_Tp>;
3647 return __finite_min_v<_Tp>;
3650 _V __tmp = __id_elem;
3651 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3652 __data(__get_lvalue(__x)));
3653 return _V::abi_type::_SimdImpl::_S_reduce(__tmp, __detail::_Maximum());
3658template <
typename _Tp,
typename _Ap>
3659 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3660 min(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3661 {
return {__private_init, _Ap::_SimdImpl::_S_min(__data(__a), __data(__b))}; }
3663template <
typename _Tp,
typename _Ap>
3664 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3665 max(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3666 {
return {__private_init, _Ap::_SimdImpl::_S_max(__data(__a), __data(__b))}; }
3668template <
typename _Tp,
typename _Ap>
3669 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3670 pair<simd<_Tp, _Ap>, simd<_Tp, _Ap>>
3671 minmax(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3673 const auto pair_of_members
3674 = _Ap::_SimdImpl::_S_minmax(__data(__a), __data(__b));
3675 return {simd<_Tp, _Ap>(__private_init, pair_of_members.first),
3676 simd<_Tp, _Ap>(__private_init, pair_of_members.second)};
3679template <
typename _Tp,
typename _Ap>
3680 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3681 clamp(
const simd<_Tp, _Ap>& __v,
const simd<_Tp, _Ap>& __lo,
const simd<_Tp, _Ap>& __hi)
3683 using _Impl =
typename _Ap::_SimdImpl;
3684 return {__private_init,
3685 _Impl::_S_min(__data(__hi),
3686 _Impl::_S_max(__data(__lo), __data(__v)))};
3691template <
size_t... _Sizes,
typename _Tp,
typename _Ap,
3692 typename =
enable_if_t<((_Sizes + ...) == simd<_Tp, _Ap>::size())>>
3693 inline tuple<simd<_Tp, simd_abi::deduce_t<_Tp, _Sizes>>...>
3694 split(
const simd<_Tp, _Ap>&);
3697template <
int _Index,
int _Total,
int _Combine = 1,
typename _Tp,
size_t _Np>
3698 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_CONST
constexpr
3699 _SimdWrapper<_Tp, _Np / _Total * _Combine>
3700 __extract_part(
const _SimdWrapper<_Tp, _Np> __x);
3702template <
int _Index,
int _Parts,
int _Combine = 1,
typename _Tp,
typename _A0,
typename... _As>
3703 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
3704 __extract_part(
const _SimdTuple<_Tp, _A0, _As...>& __x);
3708template <
size_t _V0,
size_t... _Values>
3711 template <
size_t _I>
3712 static constexpr size_t
3713 _S_at(_SizeConstant<_I> = {})
3715 if constexpr (_I == 0)
3718 return _SizeList<_Values...>::template _S_at<_I - 1>();
3721 template <
size_t _I>
3722 static constexpr auto
3723 _S_before(_SizeConstant<_I> = {})
3725 if constexpr (_I == 0)
3726 return _SizeConstant<0>();
3728 return _SizeConstant<
3729 _V0 + _SizeList<_Values...>::template _S_before<_I - 1>()>();
3732 template <
size_t _Np>
3733 static constexpr auto
3734 _S_pop_front(_SizeConstant<_Np> = {})
3736 if constexpr (_Np == 0)
3739 return _SizeList<_Values...>::template _S_pop_front<_Np - 1>();
3745template <
typename _Tp,
size_t _Np>
3746 _GLIBCXX_SIMD_INTRINSIC _SimdWrapper<_Tp, _Np / 2>
3747 __extract_center(_SimdWrapper<_Tp, _Np> __x)
3749 static_assert(_Np >= 4);
3750 static_assert(_Np % 4 == 0);
3751#if _GLIBCXX_SIMD_X86INTRIN
3752 if constexpr (__have_avx512f &&
sizeof(_Tp) * _Np == 64)
3754 const auto __intrin = __to_intrin(__x);
3755 if constexpr (is_integral_v<_Tp>)
3756 return __vector_bitcast<_Tp>(_mm512_castsi512_si256(
3757 _mm512_shuffle_i32x4(__intrin, __intrin,
3758 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
3759 else if constexpr (
sizeof(_Tp) == 4)
3760 return __vector_bitcast<_Tp>(_mm512_castps512_ps256(
3761 _mm512_shuffle_f32x4(__intrin, __intrin,
3762 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
3763 else if constexpr (
sizeof(_Tp) == 8)
3764 return __vector_bitcast<_Tp>(_mm512_castpd512_pd256(
3765 _mm512_shuffle_f64x2(__intrin, __intrin,
3766 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
3768 __assert_unreachable<_Tp>();
3770 else if constexpr (
sizeof(_Tp) * _Np == 32 && is_floating_point_v<_Tp>)
3771 return __vector_bitcast<_Tp>(
3772 _mm_shuffle_pd(__lo128(__vector_bitcast<double>(__x)),
3773 __hi128(__vector_bitcast<double>(__x)), 1));
3774 else if constexpr (
sizeof(__x) == 32 &&
sizeof(_Tp) * _Np <= 32)
3775 return __vector_bitcast<_Tp>(
3776 _mm_alignr_epi8(__hi128(__vector_bitcast<_LLong>(__x)),
3777 __lo128(__vector_bitcast<_LLong>(__x)),
3778 sizeof(_Tp) * _Np / 4));
3782 __vector_type_t<_Tp, _Np / 2> __r;
3783 __builtin_memcpy(&__r,
3784 reinterpret_cast<const char*
>(&__x)
3785 +
sizeof(_Tp) * _Np / 4,
3786 sizeof(_Tp) * _Np / 2);
3791template <
typename _Tp,
typename _A0,
typename... _As>
3792 _GLIBCXX_SIMD_INTRINSIC
3793 _SimdWrapper<_Tp, _SimdTuple<_Tp, _A0, _As...>::_S_size() / 2>
3794 __extract_center(
const _SimdTuple<_Tp, _A0, _As...>& __x)
3796 if constexpr (
sizeof...(_As) == 0)
3797 return __extract_center(__x.first);
3799 return __extract_part<1, 4, 2>(__x);
3804template <
size_t... _Sizes,
typename _Tp,
typename... _As>
3806 __split_wrapper(_SizeList<_Sizes...>,
const _SimdTuple<_Tp, _As...>& __x)
3808 return split<_Sizes...>(
3809 fixed_size_simd<_Tp, _SimdTuple<_Tp, _As...>::_S_size()>(__private_init,
3816template <
typename _V,
typename _Ap,
3817 size_t _Parts = simd_size_v<typename _V::value_type, _Ap> / _V::size()>
3818 enable_if_t<simd_size_v<typename _V::value_type, _Ap> == _Parts * _V::size()
3819 && is_simd_v<_V>, array<_V, _Parts>>
3820 split(
const simd<typename _V::value_type, _Ap>& __x)
3822 using _Tp =
typename _V::value_type;
3823 if constexpr (_Parts == 1)
3825 return {simd_cast<_V>(__x)};
3827 else if (__x._M_is_constprop())
3829 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3830 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3831 return _V([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
3832 {
return __x[__i * _V::size() + __j]; });
3836 __is_fixed_size_abi_v<_Ap>
3837 && (is_same_v<typename _V::abi_type, simd_abi::scalar>
3838 || (__is_fixed_size_abi_v<typename _V::abi_type>
3839 &&
sizeof(_V) ==
sizeof(_Tp) * _V::size()
3843#ifdef _GLIBCXX_SIMD_USE_ALIASING_LOADS
3844 const __may_alias<_Tp>*
const __element_ptr
3845 =
reinterpret_cast<const __may_alias<_Tp>*
>(&__data(__x));
3846 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3847 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
3848 {
return _V(__element_ptr + __i * _V::size(), vector_aligned); });
3850 const auto& __xx = __data(__x);
3851 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3852 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3853 [[maybe_unused]]
constexpr size_t __offset
3854 =
decltype(__i)::value * _V::size();
3855 return _V([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3856 constexpr _SizeConstant<__j + __offset> __k;
3862 else if constexpr (is_same_v<typename _V::abi_type, simd_abi::scalar>)
3865 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3866 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3870 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3871 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3872 if constexpr (__is_fixed_size_abi_v<typename _V::abi_type>)
3873 return _V([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3874 return __x[__i * _V::size() + __j];
3877 return _V(__private_init,
3878 __extract_part<
decltype(__i)::value, _Parts>(__data(__x)));
3885template <
typename _V,
typename _Ap,
3886 size_t _Parts = simd_size_v<typename _V::simd_type::value_type, _Ap> / _V::size()>
3887 enable_if_t<is_simd_mask_v<_V> && simd_size_v<
typename
3888 _V::simd_type::value_type, _Ap> == _Parts * _V::size(), array<_V, _Parts>>
3889 split(
const simd_mask<typename _V::simd_type::value_type, _Ap>& __x)
3891 if constexpr (is_same_v<_Ap, typename _V::abi_type>)
3893 else if constexpr (_Parts == 1)
3894 return {__proposed::static_simd_cast<_V>(__x)};
3895 else if constexpr (_Parts == 2 && __is_sse_abi<typename _V::abi_type>()
3896 && __is_avx_abi<_Ap>())
3897 return {_V(__private_init, __lo128(__data(__x))),
3898 _V(__private_init, __hi128(__data(__x)))};
3899 else if constexpr (_V::size() <= __CHAR_BIT__ *
sizeof(_ULLong))
3901 const bitset __bits = __x.__to_bitset();
3902 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3903 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3904 constexpr size_t __offset = __i * _V::size();
3905 return _V(__bitset_init, (__bits >> __offset).to_ullong());
3910 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3911 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3912 constexpr size_t __offset = __i * _V::size();
3913 return _V(__private_init,
3914 [&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3915 return __x[__j + __offset];
3923template <
size_t... _Sizes,
typename _Tp,
typename _Ap,
typename>
3924 _GLIBCXX_SIMD_ALWAYS_INLINE
3925 tuple<simd<_Tp, simd_abi::deduce_t<_Tp, _Sizes>>...>
3926 split(
const simd<_Tp, _Ap>& __x)
3928 using _SL = _SizeList<_Sizes...>;
3929 using _Tuple = tuple<__deduced_simd<_Tp, _Sizes>...>;
3930 constexpr size_t _Np = simd_size_v<_Tp, _Ap>;
3931 constexpr size_t _N0 = _SL::template _S_at<0>();
3932 using _V = __deduced_simd<_Tp, _N0>;
3934 if (__x._M_is_constprop())
3935 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>(
3936 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3937 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
3938 constexpr size_t __offset = _SL::_S_before(__i);
3939 return _Vi([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3940 return __x[__offset + __j];
3943 else if constexpr (_Np == _N0)
3945 static_assert(
sizeof...(_Sizes) == 1);
3946 return {simd_cast<_V>(__x)};
3949 (__is_fixed_size_abi_v<
3950 _Ap> && __fixed_size_storage_t<_Tp, _Np>::_S_first_size == _N0)
3953 !__is_fixed_size_abi_v<typename _V::abi_type>,
3954 "How can <_Tp, _Np> be __a single _SimdTuple entry but __a "
3959 return tuple_cat(make_tuple(_V(__private_init, __data(__x).first)),
3960 __split_wrapper(_SL::template _S_pop_front<1>(),
3961 __data(__x).second));
3963 else if constexpr ((!is_same_v<simd_abi::scalar,
3964 simd_abi::deduce_t<_Tp, _Sizes>> && ...)
3965 && (!__is_fixed_size_abi_v<
3966 simd_abi::deduce_t<_Tp, _Sizes>> && ...))
3968 if constexpr (((_Sizes * 2 == _Np) && ...))
3969 return {{__private_init, __extract_part<0, 2>(__data(__x))},
3970 {__private_init, __extract_part<1, 2>(__data(__x))}};
3971 else if constexpr (is_same_v<_SizeList<_Sizes...>,
3972 _SizeList<_Np / 3, _Np / 3, _Np / 3>>)
3973 return {{__private_init, __extract_part<0, 3>(__data(__x))},
3974 {__private_init, __extract_part<1, 3>(__data(__x))},
3975 {__private_init, __extract_part<2, 3>(__data(__x))}};
3976 else if constexpr (is_same_v<_SizeList<_Sizes...>,
3977 _SizeList<2 * _Np / 3, _Np / 3>>)
3978 return {{__private_init, __extract_part<0, 3, 2>(__data(__x))},
3979 {__private_init, __extract_part<2, 3>(__data(__x))}};
3980 else if constexpr (is_same_v<_SizeList<_Sizes...>,
3981 _SizeList<_Np / 3, 2 * _Np / 3>>)
3982 return {{__private_init, __extract_part<0, 3>(__data(__x))},
3983 {__private_init, __extract_part<1, 3, 2>(__data(__x))}};
3984 else if constexpr (is_same_v<_SizeList<_Sizes...>,
3985 _SizeList<_Np / 2, _Np / 4, _Np / 4>>)
3986 return {{__private_init, __extract_part<0, 2>(__data(__x))},
3987 {__private_init, __extract_part<2, 4>(__data(__x))},
3988 {__private_init, __extract_part<3, 4>(__data(__x))}};
3989 else if constexpr (is_same_v<_SizeList<_Sizes...>,
3990 _SizeList<_Np / 4, _Np / 4, _Np / 2>>)
3991 return {{__private_init, __extract_part<0, 4>(__data(__x))},
3992 {__private_init, __extract_part<1, 4>(__data(__x))},
3993 {__private_init, __extract_part<1, 2>(__data(__x))}};
3994 else if constexpr (is_same_v<_SizeList<_Sizes...>,
3995 _SizeList<_Np / 4, _Np / 2, _Np / 4>>)
3996 return {{__private_init, __extract_part<0, 4>(__data(__x))},
3997 {__private_init, __extract_center(__data(__x))},
3998 {__private_init, __extract_part<3, 4>(__data(__x))}};
3999 else if constexpr (((_Sizes * 4 == _Np) && ...))
4000 return {{__private_init, __extract_part<0, 4>(__data(__x))},
4001 {__private_init, __extract_part<1, 4>(__data(__x))},
4002 {__private_init, __extract_part<2, 4>(__data(__x))},
4003 {__private_init, __extract_part<3, 4>(__data(__x))}};
4006#ifdef _GLIBCXX_SIMD_USE_ALIASING_LOADS
4007 const __may_alias<_Tp>*
const __element_ptr
4008 =
reinterpret_cast<const __may_alias<_Tp>*
>(&__x);
4009 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>(
4010 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4011 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4012 constexpr size_t __offset = _SL::_S_before(__i);
4013 constexpr size_t __base_align =
alignof(simd<_Tp, _Ap>);
4014 constexpr size_t __a
4015 = __base_align - ((__offset *
sizeof(_Tp)) % __base_align);
4016 constexpr size_t __b = ((__a - 1) & __a) ^ __a;
4017 constexpr size_t __alignment = __b == 0 ? __a : __b;
4018 return _Vi(__element_ptr + __offset, overaligned<__alignment>);
4021 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>(
4022 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4023 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4024 const auto& __xx = __data(__x);
4025 using _Offset =
decltype(_SL::_S_before(__i));
4026 return _Vi([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4027 constexpr _SizeConstant<_Offset::value + __j> __k;
4037template <
size_t _I,
typename _Tp,
typename _Ap,
typename... _As>
4038 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp
4039 __subscript_in_pack(
const simd<_Tp, _Ap>& __x,
const simd<_Tp, _As>&... __xs)
4041 if constexpr (_I < simd_size_v<_Tp, _Ap>)
4044 return __subscript_in_pack<_I - simd_size_v<_Tp, _Ap>>(__xs...);
4049template <
typename _Tp,
typename _A0,
typename... _As>
4050 _GLIBCXX_SIMD_INTRINSIC
void
4051 __store_pack_of_simd(
char* __mem,
const simd<_Tp, _A0>& __x0,
const simd<_Tp, _As>&... __xs)
4053 constexpr size_t __n_bytes =
sizeof(_Tp) * simd_size_v<_Tp, _A0>;
4054 __builtin_memcpy(__mem, &__data(__x0), __n_bytes);
4055 if constexpr (
sizeof...(__xs) > 0)
4056 __store_pack_of_simd(__mem + __n_bytes, __xs...);
4061template <
typename _Tp,
typename... _As>
4062 inline _GLIBCXX_SIMD_CONSTEXPR
4063 simd<_Tp, simd_abi::deduce_t<_Tp, (simd_size_v<_Tp, _As> + ...)>>
4064 concat(
const simd<_Tp, _As>&... __xs)
4066 using _Rp = __deduced_simd<_Tp, (simd_size_v<_Tp, _As> + ...)>;
4067 if constexpr (
sizeof...(__xs) == 1)
4068 return simd_cast<_Rp>(__xs...);
4069 else if ((... && __xs._M_is_constprop()))
4071 simd_abi::deduce_t<_Tp, (simd_size_v<_Tp, _As> + ...)>>(
4072 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
4073 {
return __subscript_in_pack<__i>(__xs...); });
4077 __store_pack_of_simd(
reinterpret_cast<char*
>(&__data(__r)), __xs...);
4084template <
typename _Tp,
typename _Abi,
size_t _Np>
4085 _GLIBCXX_SIMD_ALWAYS_INLINE
4086 _GLIBCXX_SIMD_CONSTEXPR __deduced_simd<_Tp, simd_size_v<_Tp, _Abi> * _Np>
4087 concat(
const array<simd<_Tp, _Abi>, _Np>& __x)
4089 return __call_with_subscripts<_Np>(
4090 __x, [](
const auto&... __xs) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4091 return concat(__xs...);
4099template <
typename _Up,
typename _Accessor = _Up,
4100 typename _ValueType =
typename _Up::value_type>
4101 class _SmartReference
4107 _GLIBCXX_SIMD_INTRINSIC
constexpr _ValueType
4108 _M_read() const noexcept
4110 if constexpr (is_arithmetic_v<_Up>)
4113 return _M_obj[_M_index];
4116 template <
typename _Tp>
4117 _GLIBCXX_SIMD_INTRINSIC
constexpr void
4118 _M_write(_Tp&& __x)
const
4119 { _Accessor::_S_set(_M_obj, _M_index,
static_cast<_Tp&&
>(__x)); }
4122 _GLIBCXX_SIMD_INTRINSIC
constexpr
4123 _SmartReference(_Up& __o,
int __i) noexcept
4124 : _M_index(__i), _M_obj(__o) {}
4126 using value_type = _ValueType;
4128 _GLIBCXX_SIMD_INTRINSIC
4129 _SmartReference(
const _SmartReference&) =
delete;
4131 _GLIBCXX_SIMD_INTRINSIC
constexpr
4132 operator value_type() const noexcept
4133 {
return _M_read(); }
4135 template <
typename _Tp,
typename = _ValuePreservingOrInt<__remove_cvref_t<_Tp>, value_type>>
4136 _GLIBCXX_SIMD_INTRINSIC
constexpr _SmartReference
4137 operator=(_Tp&& __x) &&
4139 _M_write(
static_cast<_Tp&&
>(__x));
4140 return {_M_obj, _M_index};
4143#define _GLIBCXX_SIMD_OP_(__op) \
4144 template <typename _Tp, \
4145 typename _TT = decltype(declval<value_type>() __op declval<_Tp>()), \
4146 typename = _ValuePreservingOrInt<__remove_cvref_t<_Tp>, _TT>, \
4147 typename = _ValuePreservingOrInt<_TT, value_type>> \
4148 _GLIBCXX_SIMD_INTRINSIC constexpr _SmartReference \
4149 operator __op##=(_Tp&& __x) && \
4151 const value_type& __lhs = _M_read(); \
4152 _M_write(__lhs __op __x); \
4153 return {_M_obj, _M_index}; \
4155 _GLIBCXX_SIMD_ALL_ARITHMETICS(_GLIBCXX_SIMD_OP_);
4156 _GLIBCXX_SIMD_ALL_SHIFTS(_GLIBCXX_SIMD_OP_);
4157 _GLIBCXX_SIMD_ALL_BINARY(_GLIBCXX_SIMD_OP_);
4158#undef _GLIBCXX_SIMD_OP_
4160 template <
typename _Tp = void,
4161 typename =
decltype(++declval<conditional_t<true, value_type, _Tp>&>())>
4162 _GLIBCXX_SIMD_INTRINSIC
constexpr _SmartReference
4165 value_type __x = _M_read();
4167 return {_M_obj, _M_index};
4170 template <
typename _Tp = void,
4171 typename =
decltype(declval<conditional_t<true, value_type, _Tp>&>()++)>
4172 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type
4175 const value_type __r = _M_read();
4176 value_type __x = __r;
4181 template <
typename _Tp = void,
4182 typename =
decltype(--declval<conditional_t<true, value_type, _Tp>&>())>
4183 _GLIBCXX_SIMD_INTRINSIC
constexpr _SmartReference
4186 value_type __x = _M_read();
4188 return {_M_obj, _M_index};
4191 template <
typename _Tp = void,
4192 typename =
decltype(declval<conditional_t<true, value_type, _Tp>&>()--)>
4193 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type
4196 const value_type __r = _M_read();
4197 value_type __x = __r;
4202 _GLIBCXX_SIMD_INTRINSIC
friend void
4203 swap(_SmartReference&& __a, _SmartReference&& __b)
noexcept(
4205 is_nothrow_constructible<value_type, _SmartReference&&>,
4206 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4208 value_type __tmp =
static_cast<_SmartReference&&
>(__a);
4209 static_cast<_SmartReference&&
>(__a) =
static_cast<value_type
>(__b);
4210 static_cast<_SmartReference&&
>(__b) =
std::move(__tmp);
4213 _GLIBCXX_SIMD_INTRINSIC
friend void
4214 swap(value_type& __a, _SmartReference&& __b)
noexcept(
4216 is_nothrow_constructible<value_type, value_type&&>,
4217 is_nothrow_assignable<value_type&, value_type&&>,
4218 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4221 __a =
static_cast<value_type
>(__b);
4222 static_cast<_SmartReference&&
>(__b) =
std::move(__tmp);
4225 _GLIBCXX_SIMD_INTRINSIC
friend void
4226 swap(_SmartReference&& __a, value_type& __b)
noexcept(
4228 is_nothrow_constructible<value_type, _SmartReference&&>,
4229 is_nothrow_assignable<value_type&, value_type&&>,
4230 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4232 value_type __tmp(__a);
4233 static_cast<_SmartReference&&
>(__a) =
std::move(__b);
4240template <
int _Bytes>
4241 struct __scalar_abi_wrapper
4243 template <
typename _Tp>
static constexpr size_t _S_full_size = 1;
4244 template <
typename _Tp>
static constexpr size_t _S_size = 1;
4245 template <
typename _Tp>
static constexpr size_t _S_is_partial =
false;
4247 template <
typename _Tp,
typename _Abi = simd_abi::scalar>
4248 static constexpr bool _S_is_valid_v
4249 = _Abi::template _IsValid<_Tp>::value &&
sizeof(_Tp) == _Bytes;
4254template <
typename _Tp>
4255 struct __decay_abi {
using type = _Tp; };
4257template <
int _Bytes>
4258 struct __decay_abi<__scalar_abi_wrapper<_Bytes>>
4259 {
using type = simd_abi::scalar; };
4267template <
template <
int>
class _Abi,
int _Bytes,
typename _Tp>
4268 struct __find_next_valid_abi
4270 static constexpr auto
4273 constexpr int _NextBytes = std::__bit_ceil(_Bytes) / 2;
4274 using _NextAbi = _Abi<_NextBytes>;
4275 if constexpr (_NextBytes <
sizeof(_Tp) * 2)
4276 return _Abi<_Bytes>();
4277 else if constexpr (_NextAbi::template _S_is_partial<_Tp> ==
false
4278 && _NextAbi::template _S_is_valid_v<_Tp>)
4281 return __find_next_valid_abi<_Abi, _NextBytes, _Tp>::_S_choose();
4284 using type =
decltype(_S_choose());
4287template <
int _Bytes,
typename _Tp>
4288 struct __find_next_valid_abi<__scalar_abi_wrapper, _Bytes, _Tp>
4289 {
using type = simd_abi::scalar; };
4292template <
template <
int>
class...>
4295 template <
typename,
int>
static constexpr bool _S_has_valid_abi =
false;
4296 template <
typename,
int>
using _FirstValidAbi = void;
4297 template <
typename,
int>
using _BestAbi = void;
4300template <
template <
int>
class _A0,
template <
int>
class... _Rest>
4301 struct _AbiList<_A0, _Rest...>
4303 template <
typename _Tp,
int _Np>
4304 static constexpr bool _S_has_valid_abi
4305 = _A0<
sizeof(_Tp) * _Np>::template _S_is_valid_v<
4306 _Tp> || _AbiList<_Rest...>::template _S_has_valid_abi<_Tp, _Np>;
4308 template <
typename _Tp,
int _Np>
4310 _A0<
sizeof(_Tp) * _Np>::template _S_is_valid_v<_Tp>,
4311 typename __decay_abi<_A0<
sizeof(_Tp) * _Np>>::type,
4312 typename _AbiList<_Rest...>::template _FirstValidAbi<_Tp, _Np>>;
4314 template <
typename _Tp,
int _Np>
4315 static constexpr auto
4316 _S_determine_best_abi()
4318 static_assert(_Np >= 1);
4319 constexpr int _Bytes =
sizeof(_Tp) * _Np;
4320 if constexpr (_Np == 1)
4321 return __make_dependent_t<_Tp, simd_abi::scalar>{};
4324 constexpr int __fullsize = _A0<_Bytes>::template _S_full_size<_Tp>;
4329 if constexpr (_A0<_Bytes>::template _S_is_valid_v<
4330 _Tp> && __fullsize / 2 < _Np)
4331 return typename __decay_abi<_A0<_Bytes>>::type{};
4335 typename __find_next_valid_abi<_A0, _Bytes, _Tp>::type;
4336 if constexpr (_Bp::template _S_is_valid_v<
4337 _Tp> && _Bp::template _S_size<_Tp> <= _Np)
4341 typename _AbiList<_Rest...>::template _BestAbi<_Tp, _Np>{};
4346 template <
typename _Tp,
int _Np>
4347 using _BestAbi =
decltype(_S_determine_best_abi<_Tp, _Np>());
4355using _AllNativeAbis = _AbiList<simd_abi::_VecBltnBtmsk, simd_abi::_VecBuiltin,
4356 __scalar_abi_wrapper>;
4359template <
typename _Tp,
typename _Abi>
4360 struct _SimdTraits<_Tp, _Abi,
void_t<typename _Abi::template _IsValid<_Tp>>>
4361 : _Abi::template __traits<_Tp> {};
4365template <
typename _Tp,
size_t _Np>
4366 struct __deduce_impl<
4367 _Tp, _Np,
enable_if_t<_AllNativeAbis::template _S_has_valid_abi<_Tp, _Np>>>
4368 {
using type = _AllNativeAbis::_FirstValidAbi<_Tp, _Np>; };
4371template <
typename _Tp,
size_t _Np,
typename =
void>
4372 struct __deduce_fixed_size_fallback {};
4374template <
typename _Tp,
size_t _Np>
4375 struct __deduce_fixed_size_fallback<_Tp, _Np,
4376 enable_if_t<simd_abi::fixed_size<_Np>::template _S_is_valid_v<_Tp>>>
4377 {
using type = simd_abi::fixed_size<_Np>; };
4379template <
typename _Tp,
size_t _Np,
typename>
4380 struct __deduce_impl :
public __deduce_fixed_size_fallback<_Tp, _Np> {};
4386template <
typename _Tp,
typename _Abi>
4387 class simd_mask :
public _SimdTraits<_Tp, _Abi>::_MaskBase
4390 using _Traits = _SimdTraits<_Tp, _Abi>;
4391 using _MemberType =
typename _Traits::_MaskMember;
4397 using _Ip = __int_for_sizeof_t<_Tp>;
4398 static constexpr _Ip* _S_type_tag =
nullptr;
4400 friend typename _Traits::_MaskBase;
4401 friend class simd<_Tp, _Abi>;
4402 friend typename _Traits::_SimdImpl;
4405 using _Impl =
typename _Traits::_MaskImpl;
4410 using value_type = bool;
4411 using reference = _SmartReference<_MemberType, _Impl, value_type>;
4412 using simd_type = simd<_Tp, _Abi>;
4413 using abi_type = _Abi;
4416 static constexpr size_t size()
4417 {
return __size_or_zero_v<_Tp, _Abi>; }
4421 simd_mask() =
default;
4422 simd_mask(
const simd_mask&) =
default;
4423 simd_mask(simd_mask&&) =
default;
4424 simd_mask& operator=(
const simd_mask&) =
default;
4425 simd_mask& operator=(simd_mask&&) =
default;
4429 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
explicit
4430 simd_mask(
typename _Traits::_MaskCastType __init)
4431 : _M_data{__init} {}
4440 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
static simd_mask
4441 __from_bitset(bitset<
size()> bs)
4442 {
return {__bitset_init, bs}; }
4444 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR bitset<
size()>
4446 {
return _Impl::_S_to_bits(_M_data)._M_to_bitset(); }
4450 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
4451 simd_mask(value_type __x)
4452 : _M_data(_Impl::template _S_broadcast<_Ip>(__x)) {}
4456 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4458 template <
typename _Up,
typename _A2,
4459 typename = enable_if_t<simd_size_v<_Up, _A2> ==
size()>>
4460 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit(
sizeof(_MemberType)
4461 !=
sizeof(
typename _SimdTraits<_Up, _A2>::_MaskMember))
4462 simd_mask(
const simd_mask<_Up, _A2>& __x)
4463 : simd_mask(__proposed::static_simd_cast<simd_mask>(__x)) {}
4466 template <
typename _Up,
typename =
enable_if_t<conjunction<
4467 is_same<abi_type, simd_abi::fixed_size<
size()>>,
4468 is_same<_Up, _Up>>::value>>
4469 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
4470 simd_mask(
const simd_mask<_Up, simd_abi::fixed_size<
size()>>& __x)
4471 : _M_data(_Impl::_S_from_bitmask(__data(__x), _S_type_tag)) {}
4476 template <
typename _Flags>
4477 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
4478 simd_mask(
const value_type* __mem, _IsSimdFlagType<_Flags>)
4479 : _M_data(_Impl::template _S_load<_Ip>(_Flags::template _S_apply<simd_mask>(__mem))) {}
4481 template <
typename _Flags>
4482 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
4483 simd_mask(
const value_type* __mem, simd_mask __k, _IsSimdFlagType<_Flags>)
4486 _M_data = _Impl::_S_masked_load(_M_data, __k._M_data,
4487 _Flags::template _S_apply<simd_mask>(__mem));
4492 template <
typename _Flags>
4493 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
void
4494 copy_from(
const value_type* __mem, _IsSimdFlagType<_Flags>)
4495 { _M_data = _Impl::template _S_load<_Ip>(_Flags::template _S_apply<simd_mask>(__mem)); }
4499 template <
typename _Flags>
4500 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
void
4501 copy_to(value_type* __mem, _IsSimdFlagType<_Flags>)
const
4502 { _Impl::_S_store(_M_data, _Flags::template _S_apply<simd_mask>(__mem)); }
4506 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR reference
4507 operator[](
size_t __i)
4510 __invoke_ub(
"Subscript %d is out of range [0, %d]", __i,
size() - 1);
4511 return {_M_data, int(__i)};
4514 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR value_type
4515 operator[](
size_t __i)
const
4518 __invoke_ub(
"Subscript %d is out of range [0, %d]", __i,
size() - 1);
4519 if constexpr (__is_scalar_abi<_Abi>())
4522 return static_cast<bool>(_M_data[__i]);
4527 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd_mask
4529 {
return {__private_init, _Impl::_S_bit_not(_M_data)}; }
4533 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4535 template <
typename _Up,
typename _A2,
4536 typename = enable_if_t<is_convertible_v<simd_mask<_Up, _A2>, simd_mask>>>
4537 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4538 operator&&(
const simd_mask& __x,
const simd_mask<_Up, _A2>& __y)
4540 return {__private_init,
4541 _Impl::_S_logical_and(__x._M_data, simd_mask(__y)._M_data)};
4544 template <
typename _Up,
typename _A2,
4545 typename = enable_if_t<is_convertible_v<simd_mask<_Up, _A2>, simd_mask>>>
4546 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4547 operator||(
const simd_mask& __x,
const simd_mask<_Up, _A2>& __y)
4549 return {__private_init,
4550 _Impl::_S_logical_or(__x._M_data, simd_mask(__y)._M_data)};
4554 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4555 operator&&(
const simd_mask& __x,
const simd_mask& __y)
4556 {
return {__private_init, _Impl::_S_logical_and(__x._M_data, __y._M_data)}; }
4558 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4559 operator||(
const simd_mask& __x,
const simd_mask& __y)
4560 {
return {__private_init, _Impl::_S_logical_or(__x._M_data, __y._M_data)}; }
4562 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4563 operator&(
const simd_mask& __x,
const simd_mask& __y)
4564 {
return {__private_init, _Impl::_S_bit_and(__x._M_data, __y._M_data)}; }
4566 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4567 operator|(
const simd_mask& __x,
const simd_mask& __y)
4568 {
return {__private_init, _Impl::_S_bit_or(__x._M_data, __y._M_data)}; }
4570 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4571 operator^(
const simd_mask& __x,
const simd_mask& __y)
4572 {
return {__private_init, _Impl::_S_bit_xor(__x._M_data, __y._M_data)}; }
4574 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask&
4575 operator&=(simd_mask& __x,
const simd_mask& __y)
4577 __x._M_data = _Impl::_S_bit_and(__x._M_data, __y._M_data);
4581 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask&
4582 operator|=(simd_mask& __x,
const simd_mask& __y)
4584 __x._M_data = _Impl::_S_bit_or(__x._M_data, __y._M_data);
4588 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask&
4589 operator^=(simd_mask& __x,
const simd_mask& __y)
4591 __x._M_data = _Impl::_S_bit_xor(__x._M_data, __y._M_data);
4597 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4598 operator==(
const simd_mask& __x,
const simd_mask& __y)
4599 {
return !operator!=(__x, __y); }
4601 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4602 operator!=(
const simd_mask& __x,
const simd_mask& __y)
4603 {
return {__private_init, _Impl::_S_bit_xor(__x._M_data, __y._M_data)}; }
4607 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
4608 simd_mask(_PrivateInit,
typename _Traits::_MaskMember __init)
4609 : _M_data(__init) {}
4613 template <typename _Fp, typename = decltype(bool(declval<_Fp>()(size_t())))>
4614 _GLIBCXX_SIMD_INTRINSIC
constexpr
4615 simd_mask(_PrivateInit, _Fp&& __gen)
4618 __execute_n_times<size()>([&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4619 _Impl::_S_set(_M_data, __i, __gen(__i));
4625 _GLIBCXX_SIMD_INTRINSIC
constexpr
4626 simd_mask(_BitsetInit, bitset<
size()> __init)
4627 : _M_data(_Impl::_S_from_bitmask(_SanitizedBitMask<
size()>(__init), _S_type_tag))
4638 template <
typename _Up,
typename _A2,
4639 typename = enable_if_t<simd_size_v<_Up, _A2> == simd_size_v<_Tp, _Abi>>>
4640 operator simd_mask<_Up, _A2>() &&
4642 using namespace std::experimental::__proposed;
4643 return static_simd_cast<simd_mask<_Up, _A2>>(_M_data);
4646 const simd_mask<_Tp, _Abi>& _M_data;
4649 _GLIBCXX_SIMD_INTRINSIC _CvtProxy
4655 #ifdef __GXX_CONDITIONAL_IS_OVERLOADABLE__
4656 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4657 operator?:(
const simd_mask& __k,
const simd_mask& __where_true,
4658 const simd_mask& __where_false)
4660 auto __ret = __where_false;
4661 _Impl::_S_masked_assign(__k._M_data, __ret._M_data, __where_true._M_data);
4665 template <
typename _U1,
typename _U2,
4666 typename _Rp = simd<common_type_t<_U1, _U2>, _Abi>,
4668 is_convertible<_U1, _Rp>, is_convertible<_U2, _Rp>,
4669 is_convertible<simd_mask, typename _Rp::mask_type>>>>
4670 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend _Rp
4671 operator?:(
const simd_mask& __k,
const _U1& __where_true,
4672 const _U2& __where_false)
4674 _Rp __ret = __where_false;
4675 _Rp::_Impl::_S_masked_assign(
4676 __data(
static_cast<typename _Rp::mask_type
>(__k)), __data(__ret),
4677 __data(
static_cast<_Rp
>(__where_true)));
4681 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4682 template <
typename _Kp,
typename _Ak,
typename _Up,
typename _Au,
4684 conjunction_v<is_convertible<simd_mask<_Kp, _Ak>, simd_mask>,
4685 is_convertible<simd_mask<_Up, _Au>, simd_mask>>>>
4686 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4687 operator?:(
const simd_mask<_Kp, _Ak>& __k,
const simd_mask& __where_true,
4688 const simd_mask<_Up, _Au>& __where_false)
4690 simd_mask __ret = __where_false;
4691 _Impl::_S_masked_assign(simd_mask(__k)._M_data, __ret._M_data,
4692 __where_true._M_data);
4700 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
4701 _M_is_constprop()
const
4703 if constexpr (__is_scalar_abi<_Abi>())
4704 return __builtin_constant_p(_M_data);
4706 return _M_data._M_is_constprop();
4712 friend const auto& __data<_Tp, abi_type>(
const simd_mask&);
4713 friend auto& __data<_Tp, abi_type>(simd_mask&);
4714 alignas(_Traits::_S_mask_align) _MemberType _M_data;
4721template <
typename _Tp,
typename _Ap>
4722 _GLIBCXX_SIMD_INTRINSIC
constexpr const auto&
4723 __data(
const simd_mask<_Tp, _Ap>& __x)
4724 {
return __x._M_data; }
4726template <
typename _Tp,
typename _Ap>
4727 _GLIBCXX_SIMD_INTRINSIC
constexpr auto&
4728 __data(simd_mask<_Tp, _Ap>& __x)
4729 {
return __x._M_data; }
4735template <
typename _Tp,
typename _Abi>
4736 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4737 all_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
4739 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4741 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
4747 return _Abi::_MaskImpl::_S_all_of(__k);
4750template <
typename _Tp,
typename _Abi>
4751 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4752 any_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
4754 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4756 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
4762 return _Abi::_MaskImpl::_S_any_of(__k);
4765template <
typename _Tp,
typename _Abi>
4766 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4767 none_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
4769 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4771 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
4777 return _Abi::_MaskImpl::_S_none_of(__k);
4780template <
typename _Tp,
typename _Abi>
4781 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4782 some_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
4784 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4786 for (
size_t __i = 1; __i < simd_size_v<_Tp, _Abi>; ++__i)
4787 if (__k[__i] != __k[__i - 1])
4792 return _Abi::_MaskImpl::_S_some_of(__k);
4795template <
typename _Tp,
typename _Abi>
4796 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4797 popcount(
const simd_mask<_Tp, _Abi>& __k)
noexcept
4799 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4801 const int __r = __call_with_subscripts<simd_size_v<_Tp, _Abi>>(
4802 __k, [](
auto... __elements) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4803 return ((__elements != 0) + ...);
4805 if (__builtin_is_constant_evaluated() || __builtin_constant_p(__r))
4808 return _Abi::_MaskImpl::_S_popcount(__k);
4811template <
typename _Tp,
typename _Abi>
4812 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4813 find_first_set(
const simd_mask<_Tp, _Abi>& __k)
4815 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4817 constexpr size_t _Np = simd_size_v<_Tp, _Abi>;
4818 const size_t _Idx = __call_with_n_evaluations<_Np>(
4819 [](
auto... __indexes) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4821 }, [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4822 return __k[__i] ? +__i : _Np;
4825 __invoke_ub(
"find_first_set(empty mask) is UB");
4826 if (__builtin_constant_p(_Idx))
4829 return _Abi::_MaskImpl::_S_find_first_set(__k);
4832template <
typename _Tp,
typename _Abi>
4833 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4834 find_last_set(
const simd_mask<_Tp, _Abi>& __k)
4836 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4838 constexpr size_t _Np = simd_size_v<_Tp, _Abi>;
4839 const int _Idx = __call_with_n_evaluations<_Np>(
4840 [](
auto... __indexes) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4842 }, [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4843 return __k[__i] ? int(__i) : -1;
4846 __invoke_ub(
"find_first_set(empty mask) is UB");
4847 if (__builtin_constant_p(_Idx))
4850 return _Abi::_MaskImpl::_S_find_last_set(__k);
4853_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4854all_of(_ExactBool __x)
noexcept
4857_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4858any_of(_ExactBool __x)
noexcept
4861_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4862none_of(_ExactBool __x)
noexcept
4865_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4866some_of(_ExactBool)
noexcept
4869_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4870popcount(_ExactBool __x)
noexcept
4873_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4874find_first_set(_ExactBool)
4877_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4878find_last_set(_ExactBool)
4885template <
typename _V,
typename _Impl,
bool>
4886 class _SimdIntOperators {};
4888template <
typename _V,
typename _Impl>
4889 class _SimdIntOperators<_V, _Impl, true>
4891 _GLIBCXX_SIMD_INTRINSIC
constexpr const _V&
4893 {
return *
static_cast<const _V*
>(
this); }
4895 template <
typename _Tp>
4896 _GLIBCXX_SIMD_INTRINSIC
static _GLIBCXX_SIMD_CONSTEXPR _V
4897 _S_make_derived(_Tp&& __d)
4898 {
return {__private_init,
static_cast<_Tp&&
>(__d)}; }
4901 _GLIBCXX_SIMD_CONSTEXPR
friend _V& operator%=(_V& __lhs,
const _V& __x)
4902 {
return __lhs = __lhs % __x; }
4904 _GLIBCXX_SIMD_CONSTEXPR
friend _V& operator&=(_V& __lhs,
const _V& __x)
4905 {
return __lhs = __lhs & __x; }
4907 _GLIBCXX_SIMD_CONSTEXPR
friend _V& operator|=(_V& __lhs,
const _V& __x)
4908 {
return __lhs = __lhs | __x; }
4910 _GLIBCXX_SIMD_CONSTEXPR
friend _V& operator^=(_V& __lhs,
const _V& __x)
4911 {
return __lhs = __lhs ^ __x; }
4913 _GLIBCXX_SIMD_CONSTEXPR
friend _V& operator<<=(_V& __lhs,
const _V& __x)
4914 {
return __lhs = __lhs << __x; }
4916 _GLIBCXX_SIMD_CONSTEXPR
friend _V& operator>>=(_V& __lhs,
const _V& __x)
4917 {
return __lhs = __lhs >> __x; }
4919 _GLIBCXX_SIMD_CONSTEXPR
friend _V& operator<<=(_V& __lhs,
int __x)
4920 {
return __lhs = __lhs << __x; }
4922 _GLIBCXX_SIMD_CONSTEXPR
friend _V& operator>>=(_V& __lhs,
int __x)
4923 {
return __lhs = __lhs >> __x; }
4925 _GLIBCXX_SIMD_CONSTEXPR
friend _V
operator%(
const _V& __x,
const _V& __y)
4927 return _SimdIntOperators::_S_make_derived(
4928 _Impl::_S_modulus(__data(__x), __data(__y)));
4931 _GLIBCXX_SIMD_CONSTEXPR
friend _V
operator&(
const _V& __x,
const _V& __y)
4933 return _SimdIntOperators::_S_make_derived(
4934 _Impl::_S_bit_and(__data(__x), __data(__y)));
4937 _GLIBCXX_SIMD_CONSTEXPR
friend _V
operator|(
const _V& __x,
const _V& __y)
4939 return _SimdIntOperators::_S_make_derived(
4940 _Impl::_S_bit_or(__data(__x), __data(__y)));
4943 _GLIBCXX_SIMD_CONSTEXPR
friend _V
operator^(
const _V& __x,
const _V& __y)
4945 return _SimdIntOperators::_S_make_derived(
4946 _Impl::_S_bit_xor(__data(__x), __data(__y)));
4949 _GLIBCXX_SIMD_CONSTEXPR
friend _V
operator<<(
const _V& __x,
const _V& __y)
4951 return _SimdIntOperators::_S_make_derived(
4952 _Impl::_S_bit_shift_left(__data(__x), __data(__y)));
4955 _GLIBCXX_SIMD_CONSTEXPR
friend _V
operator>>(
const _V& __x,
const _V& __y)
4957 return _SimdIntOperators::_S_make_derived(
4958 _Impl::_S_bit_shift_right(__data(__x), __data(__y)));
4961 template <
typename _VV = _V>
4962 _GLIBCXX_SIMD_CONSTEXPR
friend _V
operator<<(
const _V& __x,
int __y)
4964 using _Tp =
typename _VV::value_type;
4966 __invoke_ub(
"The behavior is undefined if the right operand of a "
4967 "shift operation is negative. [expr.shift]\nA shift by "
4970 if (
size_t(__y) >=
sizeof(declval<_Tp>() << __y) * __CHAR_BIT__)
4972 "The behavior is undefined if the right operand of a "
4973 "shift operation is greater than or equal to the width of the "
4974 "promoted left operand. [expr.shift]\nA shift by %d was requested",
4976 return _SimdIntOperators::_S_make_derived(
4977 _Impl::_S_bit_shift_left(__data(__x), __y));
4980 template <
typename _VV = _V>
4981 _GLIBCXX_SIMD_CONSTEXPR
friend _V
operator>>(
const _V& __x,
int __y)
4983 using _Tp =
typename _VV::value_type;
4986 "The behavior is undefined if the right operand of a shift "
4987 "operation is negative. [expr.shift]\nA shift by %d was requested",
4989 if (
size_t(__y) >=
sizeof(declval<_Tp>() << __y) * __CHAR_BIT__)
4991 "The behavior is undefined if the right operand of a shift "
4992 "operation is greater than or equal to the width of the promoted "
4993 "left operand. [expr.shift]\nA shift by %d was requested",
4995 return _SimdIntOperators::_S_make_derived(
4996 _Impl::_S_bit_shift_right(__data(__x), __y));
5000 _GLIBCXX_SIMD_CONSTEXPR _V operator~()
const
5001 {
return {__private_init, _Impl::_S_complement(__derived()._M_data)}; }
5008template <
typename _Tp,
typename _Abi>
5009 class simd :
public _SimdIntOperators<
5010 simd<_Tp, _Abi>, typename _SimdTraits<_Tp, _Abi>::_SimdImpl,
5011 conjunction<is_integral<_Tp>,
5012 typename _SimdTraits<_Tp, _Abi>::_IsValid>::value>,
5013 public _SimdTraits<_Tp, _Abi>::_SimdBase
5015 using _Traits = _SimdTraits<_Tp, _Abi>;
5016 using _MemberType =
typename _Traits::_SimdMember;
5017 using _CastType =
typename _Traits::_SimdCastType;
5018 static constexpr _Tp* _S_type_tag =
nullptr;
5019 friend typename _Traits::_SimdBase;
5022 using _Impl =
typename _Traits::_SimdImpl;
5024 friend _SimdIntOperators<simd, _Impl, true>;
5026 using value_type = _Tp;
5027 using reference = _SmartReference<_MemberType, _Impl, value_type>;
5028 using mask_type = simd_mask<_Tp, _Abi>;
5029 using abi_type = _Abi;
5031 static constexpr size_t size()
5032 {
return __size_or_zero_v<_Tp, _Abi>; }
5034 _GLIBCXX_SIMD_CONSTEXPR simd() =
default;
5035 _GLIBCXX_SIMD_CONSTEXPR simd(
const simd&) =
default;
5036 _GLIBCXX_SIMD_CONSTEXPR simd(simd&&) noexcept = default;
5037 _GLIBCXX_SIMD_CONSTEXPR simd& operator=(const simd&) = default;
5038 _GLIBCXX_SIMD_CONSTEXPR simd& operator=(simd&&) noexcept = default;
5041 template <typename _Up,
5042 typename = enable_if_t<!is_same_v<__remove_cvref_t<_Up>,
bool>>>
5043 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5044 simd(_ValuePreservingOrInt<_Up, value_type>&& __x)
5046 _Impl::_S_broadcast(static_cast<value_type>(static_cast<_Up&&>(__x))))
5051 template <
typename _Up>
5052 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5053 simd(
const simd<_Up, simd_abi::fixed_size<
size()>>& __x,
5056 is_same<simd_abi::fixed_size<
size()>, abi_type>,
5057 negation<__is_narrowing_conversion<_Up, value_type>>,
5058 __converts_to_higher_integer_rank<_Up, value_type>>::value,
5060 : simd{static_cast<array<_Up,
size()>>(__x).
data(), vector_aligned} {}
5063#ifdef _GLIBCXX_SIMD_ENABLE_STATIC_CAST
5064 template <
typename _Up,
typename _A2,
5065 typename =
decltype(static_simd_cast<simd>(
5066 declval<
const simd<_Up, _A2>&>()))>
5067 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5068 simd(
const simd<_Up, _A2>& __x)
5069 : simd(static_simd_cast<simd>(__x)) {}
5073 template <
typename _Fp>
5074 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5075 simd(_Fp&& __gen, _ValuePreservingOrInt<
decltype(declval<_Fp>()(
5076 declval<_SizeConstant<0>&>())),
5077 value_type>* =
nullptr)
5078 : _M_data(_Impl::_S_generator(static_cast<_Fp&&>(__gen), _S_type_tag)) {}
5081 template <
typename _Up,
typename _Flags>
5082 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5083 simd(
const _Up* __mem, _IsSimdFlagType<_Flags>)
5085 _Impl::_S_load(_Flags::template _S_apply<simd>(__mem), _S_type_tag))
5089 template <
typename _Up,
typename _Flags>
5090 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
void
5091 copy_from(
const _Vectorizable<_Up>* __mem, _IsSimdFlagType<_Flags>)
5093 _M_data =
static_cast<decltype(_M_data)
>(
5094 _Impl::_S_load(_Flags::template _S_apply<simd>(__mem), _S_type_tag));
5098 template <
typename _Up,
typename _Flags>
5099 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
void
5100 copy_to(_Vectorizable<_Up>* __mem, _IsSimdFlagType<_Flags>)
const
5102 _Impl::_S_store(_M_data, _Flags::template _S_apply<simd>(__mem),
5107 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR reference
5108 operator[](
size_t __i)
5109 {
return {_M_data, int(__i)}; }
5111 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR value_type
5112 operator[]([[maybe_unused]]
size_t __i)
const
5114 if constexpr (__is_scalar_abi<_Abi>())
5116 _GLIBCXX_DEBUG_ASSERT(__i == 0);
5120 return _M_data[__i];
5124 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd&
5127 _Impl::_S_increment(_M_data);
5131 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5135 _Impl::_S_increment(_M_data);
5139 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd&
5142 _Impl::_S_decrement(_M_data);
5146 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5150 _Impl::_S_decrement(_M_data);
5155 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR mask_type
5157 {
return {__private_init, _Impl::_S_negate(_M_data)}; }
5159 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5163 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5165 {
return {__private_init, _Impl::_S_unary_minus(_M_data)}; }
5168 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5169 simd(_CastType __init) : _M_data(__init) {}
5172 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5173 operator+=(simd& __lhs,
const simd& __x)
5174 {
return __lhs = __lhs + __x; }
5176 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5177 operator-=(simd& __lhs,
const simd& __x)
5178 {
return __lhs = __lhs - __x; }
5180 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5181 operator*=(simd& __lhs,
const simd& __x)
5182 {
return __lhs = __lhs * __x; }
5184 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5185 operator/=(simd& __lhs,
const simd& __x)
5186 {
return __lhs = __lhs / __x; }
5189 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5190 operator+(
const simd& __x,
const simd& __y)
5191 {
return {__private_init, _Impl::_S_plus(__x._M_data, __y._M_data)}; }
5193 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5194 operator-(
const simd& __x,
const simd& __y)
5195 {
return {__private_init, _Impl::_S_minus(__x._M_data, __y._M_data)}; }
5197 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5198 operator*(
const simd& __x,
const simd& __y)
5199 {
return {__private_init, _Impl::_S_multiplies(__x._M_data, __y._M_data)}; }
5201 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5202 operator/(
const simd& __x,
const simd& __y)
5203 {
return {__private_init, _Impl::_S_divides(__x._M_data, __y._M_data)}; }
5206 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5207 operator==(
const simd& __x,
const simd& __y)
5208 {
return simd::_S_make_mask(_Impl::_S_equal_to(__x._M_data, __y._M_data)); }
5210 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5211 operator!=(
const simd& __x,
const simd& __y)
5213 return simd::_S_make_mask(
5214 _Impl::_S_not_equal_to(__x._M_data, __y._M_data));
5217 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5218 operator<(
const simd& __x,
const simd& __y)
5219 {
return simd::_S_make_mask(_Impl::_S_less(__x._M_data, __y._M_data)); }
5221 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5222 operator<=(
const simd& __x,
const simd& __y)
5224 return simd::_S_make_mask(_Impl::_S_less_equal(__x._M_data, __y._M_data));
5227 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5228 operator>(
const simd& __x,
const simd& __y)
5229 {
return simd::_S_make_mask(_Impl::_S_less(__y._M_data, __x._M_data)); }
5231 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5232 operator>=(
const simd& __x,
const simd& __y)
5234 return simd::_S_make_mask(_Impl::_S_less_equal(__y._M_data, __x._M_data));
5238#ifdef __GXX_CONDITIONAL_IS_OVERLOADABLE__
5239 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5240 operator?:(
const mask_type& __k,
const simd& __where_true,
5241 const simd& __where_false)
5243 auto __ret = __where_false;
5244 _Impl::_S_masked_assign(__data(__k), __data(__ret), __data(__where_true));
5252 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
5253 simd(_PrivateInit,
const _MemberType& __init)
5254 : _M_data(__init) {}
5257 _GLIBCXX_SIMD_INTRINSIC
5258 simd(_BitsetInit, bitset<
size()> __init) : _M_data()
5259 { where(mask_type(__bitset_init, __init), *
this) = ~*
this; }
5261 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
5262 _M_is_constprop()
const
5264 if constexpr (__is_scalar_abi<_Abi>())
5265 return __builtin_constant_p(_M_data);
5267 return _M_data._M_is_constprop();
5271 _GLIBCXX_SIMD_INTRINSIC
static constexpr mask_type
5272 _S_make_mask(
typename mask_type::_MemberType __k)
5273 {
return {__private_init, __k}; }
5275 friend const auto& __data<value_type, abi_type>(
const simd&);
5276 friend auto& __data<value_type, abi_type>(simd&);
5277 alignas(_Traits::_S_simd_align) _MemberType _M_data;
5283template <
typename _Tp,
typename _Ap>
5284 _GLIBCXX_SIMD_INTRINSIC
constexpr const auto&
5285 __data(
const simd<_Tp, _Ap>& __x)
5286 {
return __x._M_data; }
5288template <
typename _Tp,
typename _Ap>
5289 _GLIBCXX_SIMD_INTRINSIC
constexpr auto&
5290 __data(simd<_Tp, _Ap>& __x)
5291 {
return __x._M_data; }
5294namespace __float_bitwise_operators {
5295template <
typename _Tp,
typename _Ap>
5296 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5297 operator^(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5298 {
return {__private_init, _Ap::_SimdImpl::_S_bit_xor(__data(__a), __data(__b))}; }
5300template <
typename _Tp,
typename _Ap>
5301 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5302 operator|(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5303 {
return {__private_init, _Ap::_SimdImpl::_S_bit_or(__data(__a), __data(__b))}; }
5305template <
typename _Tp,
typename _Ap>
5306 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5307 operator&(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5308 {
return {__private_init, _Ap::_SimdImpl::_S_bit_and(__data(__a), __data(__b))}; }
5313_GLIBCXX_SIMD_END_NAMESPACE
constexpr duration< __common_rep_t< _Rep2, _Rep1 >, _Period > operator*(const _Rep1 &__s, const duration< _Rep2, _Period > &__d)
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator%(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
constexpr time_point< _Clock, typename common_type< duration< _Rep1, _Period1 >, _Dur2 >::type > operator+(const duration< _Rep1, _Period1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs)
Adjust a time point forwards by the given duration.
constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator-(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
The difference between two durations.
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator/(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
typename remove_reference< _Tp >::type remove_reference_t
Alias template for remove_reference.
typename make_unsigned< _Tp >::type make_unsigned_t
Alias template for make_unsigned.
void void_t
A metafunction that always yields void, used for detecting valid types.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
typename conditional< _Cond, _Iftrue, _Iffalse >::type conditional_t
Alias template for conditional.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr auto tuple_cat(_Tpls &&... __tpls) -> typename __tuple_cat_result< _Tpls... >::__type
tuple_cat
auto declval() noexcept -> decltype(__declval< _Tp >(0))
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
constexpr const _Tp & clamp(const _Tp &, const _Tp &, const _Tp &)
Returns the value clamped between lo and hi.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr pair< const _Tp &, const _Tp & > minmax(const _Tp &, const _Tp &)
Determines min and max at once as an ordered pair.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
constexpr _Tp reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
Calculate reduction of values in a range.
bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr auto data(_Container &__cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data())
Return the data pointer of a container.
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.