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
43#if _GLIBCXX_SIMD_X86INTRIN
45#elif _GLIBCXX_SIMD_HAVE_NEON
46#pragma GCC diagnostic push
49#pragma GCC diagnostic ignored "-Wnarrowing"
51#pragma GCC diagnostic pop
77_GLIBCXX_SIMD_BEGIN_NAMESPACE
79#if !_GLIBCXX_SIMD_X86INTRIN
80using __m128 [[__gnu__::__vector_size__(16)]] = float;
81using __m128d [[__gnu__::__vector_size__(16)]] = double;
82using __m128i [[__gnu__::__vector_size__(16)]] =
long long;
83using __m256 [[__gnu__::__vector_size__(32)]] = float;
84using __m256d [[__gnu__::__vector_size__(32)]] = double;
85using __m256i [[__gnu__::__vector_size__(32)]] =
long long;
86using __m512 [[__gnu__::__vector_size__(64)]] = float;
87using __m512d [[__gnu__::__vector_size__(64)]] = double;
88using __m512i [[__gnu__::__vector_size__(64)]] =
long long;
110template <
int _UsedBytes>
113template <
int _UsedBytes>
114 struct _VecBltnBtmsk;
116template <
typename _Tp,
int _Np>
117 using _VecN = _VecBuiltin<
sizeof(_Tp) * _Np>;
119template <
int _UsedBytes = 16>
120 using _Sse = _VecBuiltin<_UsedBytes>;
122template <
int _UsedBytes = 32>
123 using _Avx = _VecBuiltin<_UsedBytes>;
125template <
int _UsedBytes = 64>
126 using _Avx512 = _VecBltnBtmsk<_UsedBytes>;
128template <
int _UsedBytes = 16>
129 using _Neon = _VecBuiltin<_UsedBytes>;
134using __avx512 = _Avx512<>;
135using __neon = _Neon<>;
136using __neon128 = _Neon<16>;
137using __neon64 = _Neon<8>;
140template <
typename _Tp,
size_t _Np,
typename...>
144 using fixed_size = _Fixed<_Np>;
146using scalar = _Scalar;
151template <
typename _Tp>
154template <
typename _Tp>
157template <
typename _Tp,
typename _Abi>
160template <
typename _Tp,
typename _Abi>
163template <
typename _Tp,
typename _Abi>
168struct element_aligned_tag
170 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
171 static constexpr size_t _S_alignment =
alignof(_Up);
173 template <
typename _Tp,
typename _Up>
174 _GLIBCXX_SIMD_INTRINSIC
static constexpr _Up*
179struct vector_aligned_tag
181 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
182 static constexpr size_t _S_alignment
185 template <
typename _Tp,
typename _Up>
186 _GLIBCXX_SIMD_INTRINSIC
static constexpr _Up*
188 {
return static_cast<_Up*
>(__builtin_assume_aligned(__ptr, _S_alignment<_Tp, _Up>)); }
191template <
size_t _Np>
struct overaligned_tag
193 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
194 static constexpr size_t _S_alignment = _Np;
196 template <
typename _Tp,
typename _Up>
197 _GLIBCXX_SIMD_INTRINSIC
static constexpr _Up*
199 {
return static_cast<_Up*
>(__builtin_assume_aligned(__ptr, _Np)); }
202inline constexpr element_aligned_tag element_aligned = {};
204inline constexpr vector_aligned_tag vector_aligned = {};
207 inline constexpr overaligned_tag<_Np> overaligned = {};
211 using _SizeConstant = integral_constant<size_t, _Xp>;
213constexpr inline bool __have_mmx = _GLIBCXX_SIMD_HAVE_MMX;
214constexpr inline bool __have_sse = _GLIBCXX_SIMD_HAVE_SSE;
215constexpr inline bool __have_sse2 = _GLIBCXX_SIMD_HAVE_SSE2;
216constexpr inline bool __have_sse3 = _GLIBCXX_SIMD_HAVE_SSE3;
217constexpr inline bool __have_ssse3 = _GLIBCXX_SIMD_HAVE_SSSE3;
218constexpr inline bool __have_sse4_1 = _GLIBCXX_SIMD_HAVE_SSE4_1;
219constexpr inline bool __have_sse4_2 = _GLIBCXX_SIMD_HAVE_SSE4_2;
220constexpr inline bool __have_xop = _GLIBCXX_SIMD_HAVE_XOP;
221constexpr inline bool __have_avx = _GLIBCXX_SIMD_HAVE_AVX;
222constexpr inline bool __have_avx2 = _GLIBCXX_SIMD_HAVE_AVX2;
223constexpr inline bool __have_bmi = _GLIBCXX_SIMD_HAVE_BMI1;
224constexpr inline bool __have_bmi2 = _GLIBCXX_SIMD_HAVE_BMI2;
225constexpr inline bool __have_lzcnt = _GLIBCXX_SIMD_HAVE_LZCNT;
226constexpr inline bool __have_sse4a = _GLIBCXX_SIMD_HAVE_SSE4A;
227constexpr inline bool __have_fma = _GLIBCXX_SIMD_HAVE_FMA;
228constexpr inline bool __have_fma4 = _GLIBCXX_SIMD_HAVE_FMA4;
229constexpr inline bool __have_f16c = _GLIBCXX_SIMD_HAVE_F16C;
230constexpr inline bool __have_popcnt = _GLIBCXX_SIMD_HAVE_POPCNT;
231constexpr inline bool __have_avx512f = _GLIBCXX_SIMD_HAVE_AVX512F;
232constexpr inline bool __have_avx512dq = _GLIBCXX_SIMD_HAVE_AVX512DQ;
233constexpr inline bool __have_avx512vl = _GLIBCXX_SIMD_HAVE_AVX512VL;
234constexpr inline bool __have_avx512bw = _GLIBCXX_SIMD_HAVE_AVX512BW;
235constexpr inline bool __have_avx512dq_vl = __have_avx512dq && __have_avx512vl;
236constexpr inline bool __have_avx512bw_vl = __have_avx512bw && __have_avx512vl;
237constexpr inline bool __have_avx512bitalg = _GLIBCXX_SIMD_HAVE_AVX512BITALG;
238constexpr inline bool __have_avx512vbmi2 = _GLIBCXX_SIMD_HAVE_AVX512VBMI2;
239constexpr inline bool __have_avx512vbmi = _GLIBCXX_SIMD_HAVE_AVX512VBMI;
240constexpr inline bool __have_avx512ifma = _GLIBCXX_SIMD_HAVE_AVX512IFMA;
241constexpr inline bool __have_avx512cd = _GLIBCXX_SIMD_HAVE_AVX512CD;
242constexpr inline bool __have_avx512vnni = _GLIBCXX_SIMD_HAVE_AVX512VNNI;
243constexpr inline bool __have_avx512vpopcntdq = _GLIBCXX_SIMD_HAVE_AVX512VPOPCNTDQ;
244constexpr inline bool __have_avx512vp2intersect = _GLIBCXX_SIMD_HAVE_AVX512VP2INTERSECT;
246constexpr inline bool __have_neon = _GLIBCXX_SIMD_HAVE_NEON;
247constexpr inline bool __have_neon_a32 = _GLIBCXX_SIMD_HAVE_NEON_A32;
248constexpr inline bool __have_neon_a64 = _GLIBCXX_SIMD_HAVE_NEON_A64;
249constexpr inline bool __support_neon_float =
250#if defined __GCC_IEC_559
252#elif defined __FAST_MATH__
259constexpr inline bool __have_power10vec =
true;
261constexpr inline bool __have_power10vec =
false;
263#ifdef __POWER9_VECTOR__
264constexpr inline bool __have_power9vec =
true;
266constexpr inline bool __have_power9vec =
false;
268#if defined __POWER8_VECTOR__
269constexpr inline bool __have_power8vec =
true;
271constexpr inline bool __have_power8vec = __have_power9vec;
274constexpr inline bool __have_power_vsx =
true;
276constexpr inline bool __have_power_vsx = __have_power8vec;
278#if defined __ALTIVEC__
279constexpr inline bool __have_power_vmx =
true;
281constexpr inline bool __have_power_vmx = __have_power_vsx;
288#ifdef math_errhandling
292 template <
int = math_errhandling>
294 __handle_fpexcept_impl(
int)
295 {
return math_errhandling & MATH_ERREXCEPT; }
301 __handle_fpexcept_impl(
float)
303#if defined __FAST_MATH__
311 static constexpr bool _S_handle_fpexcept = __handle_fpexcept_impl(0);
314 __floating_point_flags()
317 if constexpr (_S_handle_fpexcept)
321#elif __FINITE_MATH_ONLY__
323#elif __GCC_IEC_559 < 2
326 __flags |= (__FLT_EVAL_METHOD__ + 1) << 3;
333 if constexpr (__have_mmx || __have_sse)
338 | (__have_ssse3 << 4)
339 | (__have_sse4_1 << 5)
340 | (__have_sse4_2 << 6)
345 | (__have_bmi2 << 11)
346 | (__have_lzcnt << 12)
347 | (__have_sse4a << 13)
349 | (__have_fma4 << 15)
350 | (__have_f16c << 16)
351 | (__have_popcnt << 17)
352 | (__have_avx512f << 18)
353 | (__have_avx512dq << 19)
354 | (__have_avx512vl << 20)
355 | (__have_avx512bw << 21)
356 | (__have_avx512bitalg << 22)
357 | (__have_avx512vbmi2 << 23)
358 | (__have_avx512vbmi << 24)
359 | (__have_avx512ifma << 25)
360 | (__have_avx512cd << 26)
361 | (__have_avx512vnni << 27)
362 | (__have_avx512vpopcntdq << 28)
363 | (__have_avx512vp2intersect << 29);
364 else if constexpr (__have_neon)
366 | (__have_neon_a32 << 1)
367 | (__have_neon_a64 << 2)
368 | (__have_neon_a64 << 2)
369 | (__support_neon_float << 3);
370 else if constexpr (__have_power_vmx)
371 return __have_power_vmx
372 | (__have_power_vsx << 1)
373 | (__have_power8vec << 2)
374 | (__have_power9vec << 3)
375 | (__have_power10vec << 4);
382 struct _OdrEnforcer {};
386 struct _MachineFlagsTemplate {};
399 _MachineFlagsTemplate<__machine_flags(), __floating_point_flags()>>;
403 template <
typename _Tp>
404 _GLIBCXX_SIMD_INTRINSIC
constexpr
406 operator()(_Tp __a, _Tp __b)
const
409 return min(__a, __b);
415 template <
typename _Tp>
416 _GLIBCXX_SIMD_INTRINSIC
constexpr
418 operator()(_Tp __a, _Tp __b)
const
421 return max(__a, __b);
428template <
typename _Fp,
size_t... _I>
429 [[__gnu__::__flatten__]] _GLIBCXX_SIMD_INTRINSIC
constexpr
431 __execute_on_index_sequence(_Fp&& __f, index_sequence<_I...>)
432 { ((void)__f(_SizeConstant<_I>()), ...); }
434template <
typename _Fp>
435 _GLIBCXX_SIMD_INTRINSIC
constexpr void
436 __execute_on_index_sequence(_Fp&&, index_sequence<>)
439template <
size_t _Np,
typename _Fp>
440 _GLIBCXX_SIMD_INTRINSIC
constexpr void
441 __execute_n_times(_Fp&& __f)
443 __execute_on_index_sequence(
static_cast<_Fp&&
>(__f),
444 make_index_sequence<_Np>{});
449template <
typename _R,
typename _Fp,
size_t... _I>
450 [[__gnu__::__flatten__]] _GLIBCXX_SIMD_INTRINSIC
constexpr
452 __execute_on_index_sequence_with_return(_Fp&& __f, index_sequence<_I...>)
453 {
return _R{__f(_SizeConstant<_I>())...}; }
455template <
size_t _Np,
typename _R,
typename _Fp>
456 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
457 __generate_from_n_evaluations(_Fp&& __f)
459 return __execute_on_index_sequence_with_return<_R>(
460 static_cast<_Fp&&
>(__f), make_index_sequence<_Np>{});
465template <
size_t... _I,
typename _F0,
typename _FArgs>
466 [[__gnu__::__flatten__]] _GLIBCXX_SIMD_INTRINSIC
constexpr
468 __call_with_n_evaluations(index_sequence<_I...>, _F0&& __f0, _FArgs&& __fargs)
469 {
return __f0(__fargs(_SizeConstant<_I>())...); }
471template <
size_t _Np,
typename _F0,
typename _FArgs>
472 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
473 __call_with_n_evaluations(_F0&& __f0, _FArgs&& __fargs)
475 return __call_with_n_evaluations(make_index_sequence<_Np>{},
476 static_cast<_F0&&
>(__f0),
477 static_cast<_FArgs&&
>(__fargs));
482template <
size_t _First = 0,
size_t... _It,
typename _Tp,
typename _Fp>
483 [[__gnu__::__flatten__]] _GLIBCXX_SIMD_INTRINSIC
constexpr
485 __call_with_subscripts(_Tp&& __x, index_sequence<_It...>, _Fp&& __fun)
486 {
return __fun(__x[_First + _It]...); }
488template <
size_t _Np,
size_t _First = 0,
typename _Tp,
typename _Fp>
489 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
490 __call_with_subscripts(_Tp&& __x, _Fp&& __fun)
492 return __call_with_subscripts<_First>(
static_cast<_Tp&&
>(__x),
493 make_index_sequence<_Np>(),
494 static_cast<_Fp&&
>(__fun));
501using _UChar =
unsigned char;
502using _SChar =
signed char;
503using _UShort =
unsigned short;
504using _UInt =
unsigned int;
505using _ULong =
unsigned long;
506using _ULLong =
unsigned long long;
507using _LLong =
long long;
511template <
typename _T0,
typename...>
512 struct __first_of_pack
513 {
using type = _T0; };
515template <
typename... _Ts>
516 using __first_of_pack_t =
typename __first_of_pack<_Ts...>::type;
520template <
typename _Tp>
521 typename _Tp::value_type
522 __value_type_or_identity_impl(
int);
524template <
typename _Tp>
526 __value_type_or_identity_impl(
float);
528template <
typename _Tp>
529 using __value_type_or_identity_t
530 =
decltype(__value_type_or_identity_impl<_Tp>(
int()));
534template <
typename _Tp>
535 struct __is_vectorizable :
public is_arithmetic<_Tp> {};
538 struct __is_vectorizable<bool> :
public false_type {};
540template <
typename _Tp>
541 inline constexpr bool __is_vectorizable_v = __is_vectorizable<_Tp>::value;
544template <
typename _Tp,
typename = enable_if_t<__is_vectorizable_v<_Tp>>>
545 using _Vectorizable = _Tp;
549template <
typename _Ptr,
typename _ValueType>
550 struct __is_possible_loadstore_conversion
551 : conjunction<__is_vectorizable<_Ptr>, __is_vectorizable<_ValueType>> {};
554 struct __is_possible_loadstore_conversion<bool, bool> :
true_type {};
557template <
typename _Ptr,
typename _ValueType,
559 __is_possible_loadstore_conversion<_Ptr, _ValueType>::value>>
560 using _LoadStorePtr = _Ptr;
564template <
typename _Tp,
typename =
void_t<>>
567template <
typename _Tp>
568 inline constexpr bool __is_bitmask_v = __is_bitmask<_Tp>::value;
571template <
typename _Tp>
572 struct __is_bitmask<_Tp,
573 void_t<decltype(
declval<unsigned&>() = declval<_Tp>() & 1u)>>
578#pragma GCC diagnostic push
579#pragma GCC diagnostic ignored "-Wpedantic"
580template <
size_t _Bytes>
584 static_assert(_Bytes > 0);
585 if constexpr (_Bytes ==
sizeof(int))
587 else if constexpr (_Bytes ==
sizeof(_SChar))
589 else if constexpr (_Bytes ==
sizeof(short))
591 else if constexpr (_Bytes ==
sizeof(long))
593 else if constexpr (_Bytes ==
sizeof(_LLong))
595 #ifdef __SIZEOF_INT128__
596 else if constexpr (_Bytes ==
sizeof(__int128))
599 else if constexpr (_Bytes %
sizeof(int) == 0)
601 constexpr size_t _Np = _Bytes /
sizeof(int);
606 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
609 return __generate_from_n_evaluations<_Np, _Ip>(
610 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
611 return __rhs._M_data[__i] & _M_data[__i];
615 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
618 return __generate_from_n_evaluations<_Np, _Ip>(
619 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
620 return __rhs._M_data[__i] | _M_data[__i];
624 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
627 return __generate_from_n_evaluations<_Np, _Ip>(
628 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
629 return __rhs._M_data[__i] ^ _M_data[__i];
633 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
636 return __generate_from_n_evaluations<_Np, _Ip>(
637 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return ~_M_data[__i]; });
643 static_assert(_Bytes == 0,
"this should be unreachable");
645#pragma GCC diagnostic pop
647template <
typename _Tp>
648 using __int_for_sizeof_t =
decltype(__int_for_sizeof<sizeof(_Tp)>());
651 using __int_with_sizeof_t =
decltype(__int_for_sizeof<_Np>());
655template <
typename _Tp>
659 struct __is_fixed_size_abi<simd_abi::fixed_size<_Np>> :
true_type {};
661template <
typename _Tp>
662 inline constexpr bool __is_fixed_size_abi_v = __is_fixed_size_abi<_Tp>::value;
666template <
typename _Abi>
669 {
return is_same_v<simd_abi::scalar, _Abi>; }
673template <
template <
int>
class _Abi,
int _Bytes>
675 __abi_bytes_impl(_Abi<_Bytes>*)
678template <
typename _Tp>
680 __abi_bytes_impl(_Tp*)
683template <
typename _Abi>
684 inline constexpr int __abi_bytes_v
685 = __abi_bytes_impl(
static_cast<_Abi*
>(
nullptr));
689template <
typename _Abi>
691 __is_builtin_bitmask_abi()
692 {
return is_same_v<simd_abi::_VecBltnBtmsk<__abi_bytes_v<_Abi>>, _Abi>; }
696template <
typename _Abi>
700 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
701 return _Bytes <= 16 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
706template <
typename _Abi>
710 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
711 return _Bytes > 16 && _Bytes <= 32
712 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
717template <
typename _Abi>
721 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
722 return _Bytes <= 64 && is_same_v<simd_abi::_Avx512<_Bytes>, _Abi>;
727template <
typename _Abi>
731 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
732 return _Bytes <= 16 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
737template <
typename,
typename _Up>
738 struct __make_dependent
739 {
using type = _Up; };
741template <
typename _Tp,
typename _Up>
742 using __make_dependent_t =
typename __make_dependent<_Tp, _Up>::type;
748template <
typename... _Args>
749 [[noreturn]] _GLIBCXX_SIMD_ALWAYS_INLINE
void
750 __invoke_ub([[maybe_unused]]
const char* __msg, [[maybe_unused]]
const _Args&... __args)
752#ifdef _GLIBCXX_DEBUG_UB
753 __builtin_fprintf(stderr, __msg, __args...);
756 __builtin_unreachable();
762template <
typename _Tp>
763 struct __assert_unreachable
764 {
static_assert(!is_same_v<_Tp, _Tp>,
"this should be unreachable"); };
768template <typename _Tp, typename _Ap, size_t _Np = simd_size<_Tp, _Ap>::value>
770 __size_or_zero_dispatch(
int)
773template <
typename _Tp,
typename _Ap>
775 __size_or_zero_dispatch(
float)
778template <
typename _Tp,
typename _Ap>
779 inline constexpr size_t __size_or_zero_v
780 = __size_or_zero_dispatch<_Tp, _Ap>(0);
784inline constexpr size_t
785__div_roundup(
size_t __a,
size_t __b)
786{
return (__a + __b - 1) / __b; }
795 _GLIBCXX_SIMD_INTRINSIC
constexpr
796 _ExactBool(
bool __b) : _M_data(__b) {}
798 _ExactBool(
int) =
delete;
800 _GLIBCXX_SIMD_INTRINSIC
constexpr
801 operator bool()
const
812template <
typename _Tp>
813 using __may_alias [[__gnu__::__may_alias__]] = _Tp;
818struct _UnsupportedBase
820 _UnsupportedBase() =
delete;
821 _UnsupportedBase(
const _UnsupportedBase&) =
delete;
822 _UnsupportedBase& operator=(
const _UnsupportedBase&) =
delete;
823 ~_UnsupportedBase() =
delete;
839 using _SimdBase = _UnsupportedBase;
840 using _MaskBase = _UnsupportedBase;
842 static constexpr size_t _S_full_size = 0;
843 static constexpr bool _S_is_partial =
false;
845 static constexpr size_t _S_simd_align = 1;
847 struct _SimdMember {};
848 struct _SimdCastType;
850 static constexpr size_t _S_mask_align = 1;
852 struct _MaskMember {};
853 struct _MaskCastType;
858template <
typename _Tp,
typename _Abi,
typename =
void_t<>>
859 struct _SimdTraits : _InvalidTraits {};
867inline constexpr struct _PrivateInit {} __private_init = {};
869inline constexpr struct _BitsetInit {} __bitset_init = {};
873template <
typename _From,
typename _To,
bool = is_arithmetic_v<_From>,
874 bool = is_arithmetic_v<_To>>
875 struct __is_narrowing_conversion;
879template <
typename _From,
typename _To>
880 struct __is_narrowing_conversion<_From, _To, true, true>
881 :
public __bool_constant<(
882 __digits_v<_From> > __digits_v<_To>
883 || __finite_max_v<_From> > __finite_max_v<_To>
884 || __finite_min_v<_From> < __finite_min_v<_To>
885 || (is_signed_v<_From> && is_unsigned_v<_To>))> {};
887template <
typename _Tp>
888 struct __is_narrowing_conversion<_Tp, bool, true, true>
892 struct __is_narrowing_conversion<bool, bool, true, true>
895template <
typename _Tp>
896 struct __is_narrowing_conversion<_Tp, _Tp, true, true>
899template <
typename _From,
typename _To>
900 struct __is_narrowing_conversion<_From, _To, false, true>
901 :
public negation<is_convertible<_From, _To>> {};
905template <
typename _From,
typename _To,
bool = (sizeof(_From) < sizeof(_To))>
906 struct __converts_to_higher_
integer_rank : public true_type {};
909template <
typename _From,
typename _To>
910 struct __converts_to_higher_integer_rank<_From, _To, false>
911 :
public is_same<decltype(declval<_From>() + declval<_To>()), _To> {};
915template <
typename _Tp,
typename _Ap>
916 _GLIBCXX_SIMD_INTRINSIC
constexpr const auto&
917 __data(
const simd<_Tp, _Ap>& __x);
919template <
typename _Tp,
typename _Ap>
920 _GLIBCXX_SIMD_INTRINSIC
constexpr auto&
921 __data(simd<_Tp, _Ap>& __x);
923template <
typename _Tp,
typename _Ap>
924 _GLIBCXX_SIMD_INTRINSIC
constexpr const auto&
925 __data(
const simd_mask<_Tp, _Ap>& __x);
927template <
typename _Tp,
typename _Ap>
928 _GLIBCXX_SIMD_INTRINSIC
constexpr auto&
929 __data(simd_mask<_Tp, _Ap>& __x);
933template <
typename _FromT,
typename _FromA,
typename _ToT,
typename _ToA,
935 struct _SimdConverter;
937template <
typename _Tp,
typename _Ap>
938 struct _SimdConverter<_Tp, _Ap, _Tp, _Ap, void>
940 template <
typename _Up>
941 _GLIBCXX_SIMD_INTRINSIC
const _Up&
942 operator()(
const _Up& __x)
948template <
typename _V>
949 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
950 __to_value_type_or_member_type(
const _V& __x) ->
decltype(__data(__x))
951 {
return __data(__x); }
953template <
typename _V>
954 _GLIBCXX_SIMD_INTRINSIC
constexpr const typename _V::value_type&
955 __to_value_type_or_member_type(
const typename _V::value_type& __x)
960template <
size_t _Size>
961 struct __bool_storage_member_type;
963template <
size_t _Size>
964 using __bool_storage_member_type_t =
965 typename __bool_storage_member_type<_Size>::type;
975template <
typename _Tp,
typename... _Abis>
980template <
typename _Tp,
int _Np>
981 struct __fixed_size_storage;
983template <
typename _Tp,
int _Np>
984 using __fixed_size_storage_t =
typename __fixed_size_storage<_Tp, _Np>::type;
988template <
typename _Tp,
size_t _Size,
typename =
void_t<>>
991template <
typename _Tp>
992 using _SimdWrapper8 = _SimdWrapper<_Tp, 8 /
sizeof(_Tp)>;
993template <
typename _Tp>
994 using _SimdWrapper16 = _SimdWrapper<_Tp, 16 /
sizeof(_Tp)>;
995template <
typename _Tp>
996 using _SimdWrapper32 = _SimdWrapper<_Tp, 32 /
sizeof(_Tp)>;
997template <
typename _Tp>
998 using _SimdWrapper64 = _SimdWrapper<_Tp, 64 /
sizeof(_Tp)>;
1002template <
typename _Tp>
1005template <
typename _Tp,
size_t _Np>
1006 struct __is_simd_wrapper<_SimdWrapper<_Tp, _Np>> :
true_type {};
1008template <
typename _Tp>
1009 inline constexpr bool __is_simd_wrapper_v = __is_simd_wrapper<_Tp>::value;
1016 template <
typename _Tp,
typename _Fp>
1018 _S_bit_iteration(_Tp __mask, _Fp&& __f)
1020 static_assert(
sizeof(_ULLong) >=
sizeof(_Tp));
1021 conditional_t<
sizeof(_Tp) <=
sizeof(_UInt), _UInt, _ULLong> __k;
1022 if constexpr (is_convertible_v<_Tp,
decltype(__k)>)
1025 __k = __mask.to_ullong();
1038template <
typename _Tp =
void>
1040 {
constexpr _Tp operator()(_Tp __a)
const {
return ++__a; } };
1043 struct __increment<void>
1045 template <
typename _Tp>
1047 operator()(_Tp __a)
const
1051template <
typename _Tp =
void>
1053 {
constexpr _Tp operator()(_Tp __a)
const {
return --__a; } };
1056 struct __decrement<void>
1058 template <
typename _Tp>
1060 operator()(_Tp __a)
const
1066template <
typename _From,
typename _To,
1068 __is_narrowing_conversion<__remove_cvref_t<_From>, _To>>::value>>
1069 using _ValuePreserving = _From;
1071template <
typename _From,
typename _To,
1072 typename _DecayedFrom = __remove_cvref_t<_From>,
1074 is_convertible<_From, _To>,
1076 is_same<_DecayedFrom, _To>, is_same<_DecayedFrom, int>,
1077 conjunction<is_same<_DecayedFrom, _UInt>, is_unsigned<_To>>,
1078 negation<__is_narrowing_conversion<_DecayedFrom, _To>>>>::value>>
1079 using _ValuePreservingOrInt = _From;
1083template <
typename _Tp,
size_t _Bytes,
typename =
void_t<>>
1084 struct __intrinsic_type;
1086template <
typename _Tp,
size_t _Size>
1087 using __intrinsic_type_t =
1088 typename __intrinsic_type<_Tp, _Size *
sizeof(_Tp)>::type;
1090template <
typename _Tp>
1091 using __intrinsic_type2_t =
typename __intrinsic_type<_Tp, 2>::type;
1092template <
typename _Tp>
1093 using __intrinsic_type4_t =
typename __intrinsic_type<_Tp, 4>::type;
1094template <
typename _Tp>
1095 using __intrinsic_type8_t =
typename __intrinsic_type<_Tp, 8>::type;
1096template <
typename _Tp>
1097 using __intrinsic_type16_t =
typename __intrinsic_type<_Tp, 16>::type;
1098template <
typename _Tp>
1099 using __intrinsic_type32_t =
typename __intrinsic_type<_Tp, 32>::type;
1100template <
typename _Tp>
1101 using __intrinsic_type64_t =
typename __intrinsic_type<_Tp, 64>::type;
1105template <
size_t _Np,
bool _Sanitized = false>
1108template <
size_t _Np,
bool _Sanitized>
1109 struct __is_bitmask<_BitMask<_Np, _Sanitized>, void> :
true_type {};
1111template <
size_t _Np>
1112 using _SanitizedBitMask = _BitMask<_Np, true>;
1114template <
size_t _Np,
bool _Sanitized>
1117 static_assert(_Np > 0);
1119 static constexpr size_t _NBytes = __div_roundup(_Np, __CHAR_BIT__);
1125 static constexpr int _S_array_size = __div_roundup(_NBytes,
sizeof(_Tp));
1127 _Tp _M_bits[_S_array_size];
1129 static constexpr int _S_unused_bits
1130 = _Np == 1 ? 0 : _S_array_size *
sizeof(_Tp) * __CHAR_BIT__ - _Np;
1132 static constexpr _Tp _S_bitmask = +_Tp(~_Tp()) >> _S_unused_bits;
1134 constexpr _BitMask() noexcept = default;
1136 constexpr _BitMask(
unsigned long long __x) noexcept
1137 : _M_bits{
static_cast<_Tp
>(__x)} {}
1139 _BitMask(bitset<_Np> __x) noexcept : _BitMask(__x.to_ullong()) {}
1141 constexpr _BitMask(
const _BitMask&)
noexcept =
default;
1143 template <
bool _RhsSanitized,
typename =
enable_if_t<_RhsSanitized ==
false
1144 && _Sanitized ==
true>>
1145 constexpr _BitMask(
const _BitMask<_Np, _RhsSanitized>& __rhs) noexcept
1146 : _BitMask(__rhs._M_sanitized()) {}
1148 constexpr operator _SimdWrapper<bool, _Np>() const noexcept
1150 static_assert(_S_array_size == 1);
1156 _M_to_bits() const noexcept
1158 static_assert(_S_array_size == 1);
1163 constexpr unsigned long long
1164 to_ullong() const noexcept
1166 static_assert(_S_array_size == 1);
1171 constexpr unsigned long
1172 to_ulong() const noexcept
1174 static_assert(_S_array_size == 1);
1178 constexpr bitset<_Np>
1179 _M_to_bitset() const noexcept
1181 static_assert(_S_array_size == 1);
1185 constexpr decltype(
auto)
1186 _M_sanitized()
const noexcept
1188 if constexpr (_Sanitized)
1190 else if constexpr (_Np == 1)
1191 return _SanitizedBitMask<_Np>(_M_bits[0]);
1194 _SanitizedBitMask<_Np> __r = {};
1195 for (
int __i = 0; __i < _S_array_size; ++__i)
1196 __r._M_bits[__i] = _M_bits[__i];
1197 if constexpr (_S_unused_bits > 0)
1198 __r._M_bits[_S_array_size - 1] &= _S_bitmask;
1203 template <
size_t _Mp,
bool _LSanitized>
1204 constexpr _BitMask<_Np + _Mp, _Sanitized>
1205 _M_prepend(_BitMask<_Mp, _LSanitized> __lsb)
const noexcept
1207 constexpr size_t _RN = _Np + _Mp;
1208 using _Rp = _BitMask<_RN, _Sanitized>;
1209 if constexpr (_Rp::_S_array_size == 1)
1211 _Rp __r{{_M_bits[0]}};
1212 __r._M_bits[0] <<= _Mp;
1213 __r._M_bits[0] |= __lsb._M_sanitized()._M_bits[0];
1217 __assert_unreachable<_Rp>();
1223 template <
size_t _DropLsb,
size_t _NewSize = _Np - _DropLsb>
1225 _M_extract() const noexcept
1227 static_assert(_Np > _DropLsb);
1228 static_assert(_DropLsb + _NewSize <=
sizeof(_ULLong) * __CHAR_BIT__,
1229 "not implemented for bitmasks larger than one ullong");
1230 if constexpr (_NewSize == 1)
1232 return _SanitizedBitMask<1>(_M_bits[0] & (_Tp(1) << _DropLsb));
1234 return _BitMask<_NewSize,
1235 ((_NewSize + _DropLsb ==
sizeof(_Tp) * __CHAR_BIT__
1236 && _NewSize + _DropLsb <= _Np)
1237 || ((_Sanitized || _Np ==
sizeof(_Tp) * __CHAR_BIT__)
1238 && _NewSize + _DropLsb >= _Np))>(_M_bits[0]
1244 all() const noexcept
1246 if constexpr (_Np == 1)
1248 else if constexpr (!_Sanitized)
1249 return _M_sanitized().all();
1252 constexpr _Tp __allbits = ~_Tp();
1253 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1254 if (_M_bits[__i] != __allbits)
1256 return _M_bits[_S_array_size - 1] == _S_bitmask;
1263 any() const noexcept
1265 if constexpr (_Np == 1)
1267 else if constexpr (!_Sanitized)
1268 return _M_sanitized().any();
1271 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1272 if (_M_bits[__i] != 0)
1274 return _M_bits[_S_array_size - 1] != 0;
1280 none() const noexcept
1282 if constexpr (_Np == 1)
1284 else if constexpr (!_Sanitized)
1285 return _M_sanitized().none();
1288 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1289 if (_M_bits[__i] != 0)
1291 return _M_bits[_S_array_size - 1] == 0;
1298 count() const noexcept
1300 if constexpr (_Np == 1)
1302 else if constexpr (!_Sanitized)
1303 return _M_sanitized().none();
1306 int __result = __builtin_popcountll(_M_bits[0]);
1307 for (
int __i = 1; __i < _S_array_size; ++__i)
1308 __result += __builtin_popcountll(_M_bits[__i]);
1315 operator[](
size_t __i)
const noexcept
1317 if constexpr (_Np == 1)
1319 else if constexpr (_S_array_size == 1)
1320 return (_M_bits[0] >> __i) & 1;
1323 const size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1324 const size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1325 return (_M_bits[__j] >> __shift) & 1;
1329 template <
size_t __i>
1331 operator[](_SizeConstant<__i>)
const noexcept
1333 static_assert(__i < _Np);
1334 constexpr size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1335 constexpr size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1336 return static_cast<bool>(_M_bits[__j] & (_Tp(1) << __shift));
1341 set(
size_t __i,
bool __x)
noexcept
1343 if constexpr (_Np == 1)
1345 else if constexpr (_S_array_size == 1)
1347 _M_bits[0] &= ~_Tp(_Tp(1) << __i);
1348 _M_bits[0] |= _Tp(_Tp(__x) << __i);
1352 const size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1353 const size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1354 _M_bits[__j] &= ~_Tp(_Tp(1) << __shift);
1355 _M_bits[__j] |= _Tp(_Tp(__x) << __shift);
1359 template <
size_t __i>
1361 set(_SizeConstant<__i>,
bool __x)
noexcept
1363 static_assert(__i < _Np);
1364 if constexpr (_Np == 1)
1368 constexpr size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1369 constexpr size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1370 constexpr _Tp __mask = ~_Tp(_Tp(1) << __shift);
1371 _M_bits[__j] &= __mask;
1372 _M_bits[__j] |= _Tp(_Tp(__x) << __shift);
1378 operator~() const noexcept
1380 if constexpr (_Np == 1)
1384 _BitMask __result{};
1385 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1386 __result._M_bits[__i] = ~_M_bits[__i];
1387 if constexpr (_Sanitized)
1388 __result._M_bits[_S_array_size - 1]
1389 = _M_bits[_S_array_size - 1] ^ _S_bitmask;
1391 __result._M_bits[_S_array_size - 1] = ~_M_bits[_S_array_size - 1];
1397 operator^=(
const _BitMask& __b) &
noexcept
1399 __execute_n_times<_S_array_size>(
1400 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { _M_bits[__i] ^= __b._M_bits[__i]; });
1405 operator|=(
const _BitMask& __b) &
noexcept
1407 __execute_n_times<_S_array_size>(
1408 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { _M_bits[__i] |= __b._M_bits[__i]; });
1413 operator&=(
const _BitMask& __b) &
noexcept
1415 __execute_n_times<_S_array_size>(
1416 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { _M_bits[__i] &= __b._M_bits[__i]; });
1420 friend constexpr _BitMask
1421 operator^(
const _BitMask& __a,
const _BitMask& __b)
noexcept
1428 friend constexpr _BitMask
1429 operator|(
const _BitMask& __a,
const _BitMask& __b)
noexcept
1436 friend constexpr _BitMask
1437 operator&(
const _BitMask& __a,
const _BitMask& __b)
noexcept
1444 _GLIBCXX_SIMD_INTRINSIC
1446 _M_is_constprop()
const
1448 if constexpr (_S_array_size == 0)
1449 return __builtin_constant_p(_M_bits[0]);
1452 for (
int __i = 0; __i < _S_array_size; ++__i)
1453 if (!__builtin_constant_p(_M_bits[__i]))
1464template <
typename _Tp =
void>
1465 static inline constexpr int __min_vector_size = 2 *
sizeof(_Tp);
1467#if _GLIBCXX_SIMD_HAVE_NEON
1469 inline constexpr int __min_vector_size<void> = 8;
1472 inline constexpr int __min_vector_size<void> = 16;
1477template <
typename _Tp,
size_t _Np,
typename =
void>
1478 struct __vector_type_n {};
1481template <
typename _Tp>
1482 struct __vector_type_n<_Tp, 0, void> {};
1485template <
typename _Tp>
1486 struct __vector_type_n<_Tp, 1,
enable_if_t<__is_vectorizable_v<_Tp>>>
1487 {
using type = _Tp; };
1490template <
typename _Tp,
size_t _Np>
1491 struct __vector_type_n<_Tp, _Np,
enable_if_t<__is_vectorizable_v<_Tp> && _Np >= 2>>
1495 static constexpr size_t _S_Bytes =
1501 _S_Np2 < __min_vector_size<_Tp> ? __min_vector_size<_Tp>
1504 using type [[__gnu__::__vector_size__(_S_Bytes)]] = _Tp;
1507template <
typename _Tp,
size_t _Bytes,
size_t = _Bytes % sizeof(_Tp)>
1508 struct __vector_type;
1510template <
typename _Tp,
size_t _Bytes>
1511 struct __vector_type<_Tp, _Bytes, 0>
1512 : __vector_type_n<_Tp, _Bytes / sizeof(_Tp)> {};
1514template <
typename _Tp,
size_t _Size>
1515 using __vector_type_t =
typename __vector_type_n<_Tp, _Size>::type;
1517template <
typename _Tp>
1518 using __vector_type2_t =
typename __vector_type<_Tp, 2>::type;
1519template <
typename _Tp>
1520 using __vector_type4_t =
typename __vector_type<_Tp, 4>::type;
1521template <
typename _Tp>
1522 using __vector_type8_t =
typename __vector_type<_Tp, 8>::type;
1523template <
typename _Tp>
1524 using __vector_type16_t =
typename __vector_type<_Tp, 16>::type;
1525template <
typename _Tp>
1526 using __vector_type32_t =
typename __vector_type<_Tp, 32>::type;
1527template <
typename _Tp>
1528 using __vector_type64_t =
typename __vector_type<_Tp, 64>::type;
1532template <
typename _Tp,
typename =
void_t<>>
1535template <
typename _Tp>
1536 struct __is_vector_type<
1537 _Tp,
void_t<typename __vector_type<
1539 : is_same<_Tp, typename __vector_type<
1540 remove_reference_t<decltype(declval<_Tp>()[0])>,
1541 sizeof(_Tp)>::type> {};
1543template <
typename _Tp>
1544 inline constexpr bool __is_vector_type_v = __is_vector_type<_Tp>::value;
1548#if _GLIBCXX_SIMD_HAVE_SSE_ABI
1549template <
typename _Tp>
1550 using __is_intrinsic_type = __is_vector_type<_Tp>;
1552template <
typename _Tp,
typename =
void_t<>>
1555template <
typename _Tp>
1556 struct __is_intrinsic_type<
1557 _Tp,
void_t<typename __intrinsic_type<
1559 : is_same<_Tp, typename __intrinsic_type<
1560 remove_reference_t<decltype(declval<_Tp>()[0])>,
1561 sizeof(_Tp)>::type> {};
1564template <
typename _Tp>
1565 inline constexpr bool __is_intrinsic_type_v = __is_intrinsic_type<_Tp>::value;
1569template <
typename _Tp,
typename =
void_t<>>
1570 struct _VectorTraitsImpl;
1572template <
typename _Tp>
1573 struct _VectorTraitsImpl<_Tp,
enable_if_t<__is_vector_type_v<_Tp>
1574 || __is_intrinsic_type_v<_Tp>>>
1577 using value_type = remove_reference_t<decltype(declval<_Tp>()[0])>;
1578 static constexpr int _S_full_size =
sizeof(_Tp) /
sizeof(value_type);
1579 using _Wrapper = _SimdWrapper<value_type, _S_full_size>;
1580 template <
typename _Up,
int _W = _S_full_size>
1581 static constexpr bool _S_is
1582 = is_same_v<value_type, _Up> && _W == _S_full_size;
1585template <
typename _Tp,
size_t _Np>
1586 struct _VectorTraitsImpl<_SimdWrapper<_Tp, _Np>,
1587 void_t<__vector_type_t<_Tp, _Np>>>
1589 using type = __vector_type_t<_Tp, _Np>;
1590 using value_type = _Tp;
1591 static constexpr int _S_full_size =
sizeof(type) /
sizeof(value_type);
1592 using _Wrapper = _SimdWrapper<_Tp, _Np>;
1593 static constexpr bool _S_is_partial = (_Np == _S_full_size);
1594 static constexpr int _S_partial_width = _Np;
1595 template <
typename _Up,
int _W = _S_full_size>
1596 static constexpr bool _S_is
1597 = is_same_v<value_type, _Up>&& _W == _S_full_size;
1600template <typename _Tp, typename = typename _VectorTraitsImpl<_Tp>::type>
1601 using _VectorTraits = _VectorTraitsImpl<_Tp>;
1605template <
typename _V>
1606 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
1609 if constexpr (__is_vector_type_v<_V>)
1611 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value)
1613 if constexpr (__is_fixed_size_abi_v<typename _V::abi_type>)
1615 static_assert(is_simd<_V>::value);
1616 static_assert(_V::abi_type::template __traits<
1617 typename _V::value_type>::_SimdMember::_S_tuple_size == 1);
1618 return __as_vector(__data(__x).first);
1620 else if constexpr (_V::size() > 1)
1621 return __data(__x)._M_data;
1624 static_assert(is_simd<_V>::value);
1625 using _Tp =
typename _V::value_type;
1627 constexpr auto __bytes =
sizeof(_Tp) == 8 ? 16 : sizeof(_Tp);
1628 using _RV [[__gnu__::__vector_size__(__bytes)]] = _Tp;
1630 using _RV [[__gnu__::__vector_size__(
sizeof(_Tp))]] = _Tp;
1632 return _RV{__data(__x)};
1635 else if constexpr (__is_vectorizable_v<_V>)
1636 return __vector_type_t<_V, 2>{__x};
1643template <
size_t _Np = 0,
typename _V>
1644 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
1645 __as_wrapper(_V __x)
1647 if constexpr (__is_vector_type_v<_V>)
1648 return _SimdWrapper<
typename _VectorTraits<_V>::value_type,
1649 (_Np > 0 ? _Np : _VectorTraits<_V>::_S_full_size)>(__x);
1650 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value)
1652 static_assert(_V::size() == _Np);
1657 static_assert(_V::_S_size == _Np);
1664template <
typename _To,
typename _From>
1665 _GLIBCXX_SIMD_INTRINSIC
constexpr _To
1666 __intrin_bitcast(_From __v)
1668 static_assert((__is_vector_type_v<_From> || __is_intrinsic_type_v<_From>)
1669 && (__is_vector_type_v<_To> || __is_intrinsic_type_v<_To>));
1670 if constexpr (
sizeof(_To) ==
sizeof(_From))
1671 return reinterpret_cast<_To
>(__v);
1672 else if constexpr (
sizeof(_From) >
sizeof(_To))
1673 if constexpr (
sizeof(_To) >= 16)
1674 return reinterpret_cast<const __may_alias<_To>&
>(__v);
1678 __builtin_memcpy(&__r, &__v,
sizeof(_To));
1681#if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1682 else if constexpr (__have_avx &&
sizeof(_From) == 16 &&
sizeof(_To) == 32)
1683 return reinterpret_cast<_To
>(__builtin_ia32_ps256_ps(
1684 reinterpret_cast<__vector_type_t<float, 4>
>(__v)));
1685 else if constexpr (__have_avx512f &&
sizeof(_From) == 16
1686 &&
sizeof(_To) == 64)
1687 return reinterpret_cast<_To
>(__builtin_ia32_ps512_ps(
1688 reinterpret_cast<__vector_type_t<float, 4>
>(__v)));
1689 else if constexpr (__have_avx512f &&
sizeof(_From) == 32
1690 &&
sizeof(_To) == 64)
1691 return reinterpret_cast<_To
>(__builtin_ia32_ps512_256ps(
1692 reinterpret_cast<__vector_type_t<float, 8>
>(__v)));
1694 else if constexpr (
sizeof(__v) <= 8)
1695 return reinterpret_cast<_To
>(
1696 __vector_type_t<__int_for_sizeof_t<_From>,
sizeof(_To) /
sizeof(_From)>{
1697 reinterpret_cast<__int_for_sizeof_t<_From>
>(__v)});
1700 static_assert(
sizeof(_To) >
sizeof(_From));
1702 __builtin_memcpy(&__r, &__v,
sizeof(_From));
1709template <
typename _To,
size_t _NN = 0,
typename _From,
1710 typename _FromVT = _VectorTraits<_From>,
1711 size_t _Np = _NN == 0 ?
sizeof(_From) /
sizeof(_To) : _NN>
1712 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_To, _Np>
1713 __vector_bitcast(_From __x)
1715 using _R = __vector_type_t<_To, _Np>;
1716 return __intrin_bitcast<_R>(__x);
1719template <
typename _To,
size_t _NN = 0,
typename _Tp,
size_t _Nx,
1721 = _NN == 0 ?
sizeof(_SimdWrapper<_Tp, _Nx>) /
sizeof(_To) : _NN>
1722 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_To, _Np>
1723 __vector_bitcast(
const _SimdWrapper<_Tp, _Nx>& __x)
1725 static_assert(_Np > 1);
1726 return __intrin_bitcast<__vector_type_t<_To, _Np>>(__x._M_data);
1731#ifdef _GLIBCXX_SIMD_WORKAROUND_PR85048
1732template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1733 _To __convert_x86(_Tp);
1735template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1736 _To __convert_x86(_Tp, _Tp);
1738template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1739 _To __convert_x86(_Tp, _Tp, _Tp, _Tp);
1741template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1742 _To __convert_x86(_Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp);
1744template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1745 _To __convert_x86(_Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp,
1746 _Tp, _Tp, _Tp, _Tp);
1751template <
typename _To,
typename _From>
1752 _GLIBCXX_SIMD_INTRINSIC
constexpr _To
1753 __bit_cast(
const _From __x)
1755#if __has_builtin(__builtin_bit_cast)
1756 return __builtin_bit_cast(_To, __x);
1758 static_assert(
sizeof(_To) ==
sizeof(_From));
1759 constexpr bool __to_is_vectorizable
1760 = is_arithmetic_v<_To> || is_enum_v<_To>;
1761 constexpr bool __from_is_vectorizable
1762 = is_arithmetic_v<_From> || is_enum_v<_From>;
1763 if constexpr (__is_vector_type_v<_To> && __is_vector_type_v<_From>)
1764 return reinterpret_cast<_To
>(__x);
1765 else if constexpr (__is_vector_type_v<_To> && __from_is_vectorizable)
1767 using _FV [[__gnu__::__vector_size__(
sizeof(_From))]] = _From;
1768 return reinterpret_cast<_To
>(_FV{__x});
1770 else if constexpr (__to_is_vectorizable && __from_is_vectorizable)
1772 using _TV [[__gnu__::__vector_size__(
sizeof(_To))]] = _To;
1773 using _FV [[__gnu__::__vector_size__(
sizeof(_From))]] = _From;
1774 return reinterpret_cast<_TV
>(_FV{__x})[0];
1776 else if constexpr (__to_is_vectorizable && __is_vector_type_v<_From>)
1778 using _TV [[__gnu__::__vector_size__(
sizeof(_To))]] = _To;
1779 return reinterpret_cast<_TV
>(__x)[0];
1784 __builtin_memcpy(
reinterpret_cast<char*
>(&__r),
1785 reinterpret_cast<const char*
>(&__x),
sizeof(_To));
1793template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>,
1794 typename _R = __
intrinsic_type_t<
typename _TVT::value_type, _TVT::_S_full_size>>
1795 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
1796 __to_intrin(_Tp __x)
1798 static_assert(
sizeof(__x) <=
sizeof(_R),
1799 "__to_intrin may never drop values off the end");
1800 if constexpr (
sizeof(__x) ==
sizeof(_R))
1801 return reinterpret_cast<_R
>(__as_vector(__x));
1804 using _Up = __int_for_sizeof_t<_Tp>;
1805 return reinterpret_cast<_R
>(
1806 __vector_type_t<_Up,
sizeof(_R) /
sizeof(_Up)>{__bit_cast<_Up>(__x)});
1812template <
typename _Tp,
typename... _Args>
1813 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp,
sizeof...(_Args)>
1814 __make_vector(
const _Args&... __args)
1815 {
return __vector_type_t<_Tp,
sizeof...(_Args)>{
static_cast<_Tp
>(__args)...}; }
1819template <
size_t _Np,
typename _Tp,
size_t... _I>
1820 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1821 __vector_broadcast_impl(_Tp __x, index_sequence<_I...>)
1822 {
return __vector_type_t<_Tp, _Np>{((void)_I, __x)...}; }
1824template <
size_t _Np,
typename _Tp>
1825 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1826 __vector_broadcast(_Tp __x)
1827 {
return __vector_broadcast_impl<_Np, _Tp>(__x, make_index_sequence<_Np>()); }
1831 template <
typename _Tp,
size_t _Np,
typename _Gp,
size_t... _I>
1832 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1833 __generate_vector_impl(_Gp&& __gen, index_sequence<_I...>)
1834 {
return __vector_type_t<_Tp, _Np>{
static_cast<_Tp
>(__gen(_SizeConstant<_I>()))...}; }
1836template <
typename _V,
typename _VVT = _VectorTraits<_V>,
typename _Gp>
1837 _GLIBCXX_SIMD_INTRINSIC
constexpr _V
1838 __generate_vector(_Gp&& __gen)
1840 if constexpr (__is_vector_type_v<_V>)
1841 return __generate_vector_impl<
typename _VVT::value_type,
1842 _VVT::_S_full_size>(
1843 static_cast<_Gp&&
>(__gen), make_index_sequence<_VVT::_S_full_size>());
1845 return __generate_vector_impl<
typename _VVT::value_type,
1846 _VVT::_S_partial_width>(
1847 static_cast<_Gp&&
>(__gen),
1848 make_index_sequence<_VVT::_S_partial_width>());
1851template <
typename _Tp,
size_t _Np,
typename _Gp>
1852 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1853 __generate_vector(_Gp&& __gen)
1855 return __generate_vector_impl<_Tp, _Np>(
static_cast<_Gp&&
>(__gen),
1856 make_index_sequence<_Np>());
1861template <
typename _TW>
1862 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1863 __xor(_TW __a, _TW __b)
noexcept
1865 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1867 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1868 _VectorTraitsImpl<_TW>>::value_type;
1869 if constexpr (is_floating_point_v<_Tp>)
1871 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1872 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1873 ^ __vector_bitcast<_Ip>(__b));
1875 else if constexpr (__is_vector_type_v<_TW>)
1878 return __a._M_data ^ __b._M_data;
1886template <
typename _TW>
1887 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1888 __or(_TW __a, _TW __b)
noexcept
1890 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1892 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1893 _VectorTraitsImpl<_TW>>::value_type;
1894 if constexpr (is_floating_point_v<_Tp>)
1896 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1897 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1898 | __vector_bitcast<_Ip>(__b));
1900 else if constexpr (__is_vector_type_v<_TW>)
1903 return __a._M_data | __b._M_data;
1911template <
typename _TW>
1912 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1913 __and(_TW __a, _TW __b)
noexcept
1915 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1917 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1918 _VectorTraitsImpl<_TW>>::value_type;
1919 if constexpr (is_floating_point_v<_Tp>)
1921 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1922 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1923 & __vector_bitcast<_Ip>(__b));
1925 else if constexpr (__is_vector_type_v<_TW>)
1928 return __a._M_data & __b._M_data;
1936#if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1937static constexpr struct
1939 _GLIBCXX_SIMD_INTRINSIC __v4sf
1940 operator()(__v4sf __a, __v4sf __b)
const noexcept
1941 {
return __builtin_ia32_andnps(__a, __b); }
1943 _GLIBCXX_SIMD_INTRINSIC __v2df
1944 operator()(__v2df __a, __v2df __b)
const noexcept
1945 {
return __builtin_ia32_andnpd(__a, __b); }
1947 _GLIBCXX_SIMD_INTRINSIC __v2di
1948 operator()(__v2di __a, __v2di __b)
const noexcept
1949 {
return __builtin_ia32_pandn128(__a, __b); }
1951 _GLIBCXX_SIMD_INTRINSIC __v8sf
1952 operator()(__v8sf __a, __v8sf __b)
const noexcept
1953 {
return __builtin_ia32_andnps256(__a, __b); }
1955 _GLIBCXX_SIMD_INTRINSIC __v4df
1956 operator()(__v4df __a, __v4df __b)
const noexcept
1957 {
return __builtin_ia32_andnpd256(__a, __b); }
1959 _GLIBCXX_SIMD_INTRINSIC __v4di
1960 operator()(__v4di __a, __v4di __b)
const noexcept
1962 if constexpr (__have_avx2)
1963 return __builtin_ia32_andnotsi256(__a, __b);
1965 return reinterpret_cast<__v4di
>(
1966 __builtin_ia32_andnpd256(
reinterpret_cast<__v4df
>(__a),
1967 reinterpret_cast<__v4df
>(__b)));
1970 _GLIBCXX_SIMD_INTRINSIC __v16sf
1971 operator()(__v16sf __a, __v16sf __b)
const noexcept
1973 if constexpr (__have_avx512dq)
1974 return _mm512_andnot_ps(__a, __b);
1976 return reinterpret_cast<__v16sf
>(
1977 _mm512_andnot_si512(
reinterpret_cast<__v8di
>(__a),
1978 reinterpret_cast<__v8di
>(__b)));
1981 _GLIBCXX_SIMD_INTRINSIC __v8df
1982 operator()(__v8df __a, __v8df __b)
const noexcept
1984 if constexpr (__have_avx512dq)
1985 return _mm512_andnot_pd(__a, __b);
1987 return reinterpret_cast<__v8df
>(
1988 _mm512_andnot_si512(
reinterpret_cast<__v8di
>(__a),
1989 reinterpret_cast<__v8di
>(__b)));
1992 _GLIBCXX_SIMD_INTRINSIC __v8di
1993 operator()(__v8di __a, __v8di __b)
const noexcept
1994 {
return _mm512_andnot_si512(__a, __b); }
1998template <
typename _TW>
1999 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
2000 __andnot(_TW __a, _TW __b)
noexcept
2002 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
2004 using _TVT = conditional_t<__is_simd_wrapper_v<_TW>, _TW,
2005 _VectorTraitsImpl<_TW>>;
2006 using _Tp =
typename _TVT::value_type;
2007#if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
2008 if constexpr (
sizeof(_TW) >= 16)
2010 const auto __ai = __to_intrin(__a);
2011 const auto __bi = __to_intrin(__b);
2012 if (!__builtin_is_constant_evaluated()
2013 && !(__builtin_constant_p(__ai) && __builtin_constant_p(__bi)))
2015 const auto __r = _S_x86_andnot(__ai, __bi);
2016 if constexpr (is_convertible_v<
decltype(__r), _TW>)
2019 return reinterpret_cast<typename _TVT::type
>(__r);
2023 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
2024 return __vector_bitcast<_Tp>(~__vector_bitcast<_Ip>(__a)
2025 & __vector_bitcast<_Ip>(__b));
2033template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2034 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp
2035 __not(_Tp __a)
noexcept
2037 if constexpr (is_floating_point_v<typename _TVT::value_type>)
2038 return reinterpret_cast<typename _TVT::type
>(
2039 ~__vector_bitcast<unsigned>(__a));
2046template <
typename _T0,
typename _T1,
typename _Fun,
size_t... _Is>
2047 _GLIBCXX_SIMD_INTRINSIC
constexpr
2048 __vector_type_t<remove_reference_t<decltype(declval<_T0>()[0])>,
sizeof...(_Is)>
2049 __vec_shuffle(_T0 __x, _T1 __y, index_sequence<_Is...> __seq, _Fun __idx_perm)
2051 constexpr int _N0 =
sizeof(__x) /
sizeof(__x[0]);
2052 constexpr int _N1 =
sizeof(__y) /
sizeof(__y[0]);
2053 using _Tp = remove_reference_t<decltype(declval<_T0>()[0])>;
2054 using _RV [[maybe_unused]] = __vector_type_t<_Tp,
sizeof...(_Is)>;
2055#if __has_builtin(__builtin_shufflevector)
2058 if constexpr (
sizeof(__x) >
sizeof(__y) and _N1 == 1)
2059 return __vec_shuffle(__x, _T0{__y[0]}, __seq, __idx_perm);
2060 else if constexpr (
sizeof(__x) >
sizeof(__y))
2061 return __vec_shuffle(__x, __intrin_bitcast<_T0>(__y), __seq, __idx_perm);
2062 else if constexpr (
sizeof(__x) <
sizeof(__y) and _N0 == 1)
2063 return __vec_shuffle(_T1{__x[0]}, __y, __seq, [=](
int __i) {
2064 __i = __idx_perm(__i);
2065 return __i < _N0 ? __i : __i - _N0 + _N1;
2067 else if constexpr (
sizeof(__x) <
sizeof(__y))
2068 return __vec_shuffle(__intrin_bitcast<_T1>(__x), __y, __seq, [=](
int __i) {
2069 __i = __idx_perm(__i);
2070 return __i < _N0 ? __i : __i - _N0 + _N1;
2075 const auto __r = __builtin_shufflevector(__x, __y, [=] {
2076 constexpr int __j = __idx_perm(_Is);
2077 static_assert(__j < _N0 + _N1);
2081 if constexpr (
sizeof(__r) ==
sizeof(_RV))
2084 return _RV {__r[_Is]...};
2092 constexpr int __j = __idx_perm(_Is);
2093 static_assert(__j < _N0 + _N1);
2094 if constexpr (__j < 0)
2096 else if constexpr (__j < _N0)
2099 return __y[__j - _N0];
2105template <
typename _T0,
typename _Fun,
typename _Seq>
2106 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2107 __vec_shuffle(_T0 __x, _Seq __seq, _Fun __idx_perm)
2108 {
return __vec_shuffle(__x, _T0(), __seq, __idx_perm); }
2112template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>,
2113 typename _R = __vector_type_t<
typename _TVT::value_type, _TVT::_S_full_size * 2>>
2115 __concat(_Tp a_, _Tp b_)
2117#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_1
2119 = conditional_t<is_floating_point_v<typename _TVT::value_type>, double,
2121 long long,
typename _TVT::value_type>>;
2122 constexpr int input_width =
sizeof(_Tp) /
sizeof(_W);
2123 const auto __a = __vector_bitcast<_W>(a_);
2124 const auto __b = __vector_bitcast<_W>(b_);
2125 using _Up = __vector_type_t<_W,
sizeof(_R) /
sizeof(_W)>;
2127 constexpr int input_width = _TVT::_S_full_size;
2128 const _Tp& __a = a_;
2129 const _Tp& __b = b_;
2132 if constexpr (input_width == 2)
2133 return reinterpret_cast<_R
>(_Up{__a[0], __a[1], __b[0], __b[1]});
2134 else if constexpr (input_width == 4)
2135 return reinterpret_cast<_R
>(
2136 _Up{__a[0], __a[1], __a[2], __a[3], __b[0], __b[1], __b[2], __b[3]});
2137 else if constexpr (input_width == 8)
2138 return reinterpret_cast<_R
>(
2139 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6], __a[7],
2140 __b[0], __b[1], __b[2], __b[3], __b[4], __b[5], __b[6], __b[7]});
2141 else if constexpr (input_width == 16)
2142 return reinterpret_cast<_R
>(
2143 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6],
2144 __a[7], __a[8], __a[9], __a[10], __a[11], __a[12], __a[13],
2145 __a[14], __a[15], __b[0], __b[1], __b[2], __b[3], __b[4],
2146 __b[5], __b[6], __b[7], __b[8], __b[9], __b[10], __b[11],
2147 __b[12], __b[13], __b[14], __b[15]});
2148 else if constexpr (input_width == 32)
2149 return reinterpret_cast<_R
>(
2150 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6],
2151 __a[7], __a[8], __a[9], __a[10], __a[11], __a[12], __a[13],
2152 __a[14], __a[15], __a[16], __a[17], __a[18], __a[19], __a[20],
2153 __a[21], __a[22], __a[23], __a[24], __a[25], __a[26], __a[27],
2154 __a[28], __a[29], __a[30], __a[31], __b[0], __b[1], __b[2],
2155 __b[3], __b[4], __b[5], __b[6], __b[7], __b[8], __b[9],
2156 __b[10], __b[11], __b[12], __b[13], __b[14], __b[15], __b[16],
2157 __b[17], __b[18], __b[19], __b[20], __b[21], __b[22], __b[23],
2158 __b[24], __b[25], __b[26], __b[27], __b[28], __b[29], __b[30],
2164template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2165 struct _ZeroExtendProxy
2167 using value_type =
typename _TVT::value_type;
2168 static constexpr size_t _Np = _TVT::_S_full_size;
2171 template <
typename _To,
typename _ToVT = _VectorTraits<_To>,
2173 = enable_if_t<is_same_v<
typename _ToVT::value_type, value_type>>>
2174 _GLIBCXX_SIMD_INTRINSIC
operator _To()
const
2176 constexpr size_t _ToN = _ToVT::_S_full_size;
2177 if constexpr (_ToN == _Np)
2179 else if constexpr (_ToN == 2 * _Np)
2181#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_3
2182 if constexpr (__have_avx && _TVT::template _S_is<float, 4>)
2183 return __vector_bitcast<value_type>(
2184 _mm256_insertf128_ps(__m256(), __x, 0));
2185 else if constexpr (__have_avx && _TVT::template _S_is<double, 2>)
2186 return __vector_bitcast<value_type>(
2187 _mm256_insertf128_pd(__m256d(), __x, 0));
2188 else if constexpr (__have_avx2 && _Np *
sizeof(value_type) == 16)
2189 return __vector_bitcast<value_type>(
2190 _mm256_insertf128_si256(__m256i(), __to_intrin(__x), 0));
2191 else if constexpr (__have_avx512f && _TVT::template _S_is<float, 8>)
2193 if constexpr (__have_avx512dq)
2194 return __vector_bitcast<value_type>(
2195 _mm512_insertf32x8(__m512(), __x, 0));
2197 return reinterpret_cast<__m512
>(
2198 _mm512_insertf64x4(__m512d(),
2199 reinterpret_cast<__m256d
>(__x), 0));
2201 else if constexpr (__have_avx512f
2202 && _TVT::template _S_is<double, 4>)
2203 return __vector_bitcast<value_type>(
2204 _mm512_insertf64x4(__m512d(), __x, 0));
2205 else if constexpr (__have_avx512f && _Np *
sizeof(value_type) == 32)
2206 return __vector_bitcast<value_type>(
2207 _mm512_inserti64x4(__m512i(), __to_intrin(__x), 0));
2209 return __concat(__x, _Tp());
2211 else if constexpr (_ToN == 4 * _Np)
2213#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_3
2214 if constexpr (__have_avx512dq && _TVT::template _S_is<double, 2>)
2216 return __vector_bitcast<value_type>(
2217 _mm512_insertf64x2(__m512d(), __x, 0));
2219 else if constexpr (__have_avx512f
2220 && is_floating_point_v<value_type>)
2222 return __vector_bitcast<value_type>(
2223 _mm512_insertf32x4(__m512(),
reinterpret_cast<__m128
>(__x),
2226 else if constexpr (__have_avx512f && _Np *
sizeof(value_type) == 16)
2228 return __vector_bitcast<value_type>(
2229 _mm512_inserti32x4(__m512i(), __to_intrin(__x), 0));
2232 return __concat(__concat(__x, _Tp()),
2233 __vector_type_t<value_type, _Np * 2>());
2235 else if constexpr (_ToN == 8 * _Np)
2236 return __concat(
operator __vector_type_t<value_type, _Np * 4>(),
2237 __vector_type_t<value_type, _Np * 4>());
2238 else if constexpr (_ToN == 16 * _Np)
2239 return __concat(
operator __vector_type_t<value_type, _Np * 8>(),
2240 __vector_type_t<value_type, _Np * 8>());
2242 __assert_unreachable<_Tp>();
2246template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2247 _GLIBCXX_SIMD_INTRINSIC _ZeroExtendProxy<_Tp, _TVT>
2248 __zero_extend(_Tp __x)
2253template <
int _Offset,
2256 typename _TVT = _VectorTraits<_Tp>,
2257 typename _R = __vector_type_t<
typename _TVT::value_type, _TVT::_S_full_size / _SplitBy>>
2258 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2261 using value_type =
typename _TVT::value_type;
2262#if _GLIBCXX_SIMD_X86INTRIN
2263 if constexpr (
sizeof(_Tp) == 64 && _SplitBy == 4 && _Offset > 0)
2265 if constexpr (__have_avx512dq && is_same_v<double, value_type>)
2266 return _mm512_extractf64x2_pd(__to_intrin(__in), _Offset);
2267 else if constexpr (is_floating_point_v<value_type>)
2268 return __vector_bitcast<value_type>(
2269 _mm512_extractf32x4_ps(__intrin_bitcast<__m512>(__in), _Offset));
2271 return reinterpret_cast<_R
>(
2272 _mm512_extracti32x4_epi32(__intrin_bitcast<__m512i>(__in),
2278#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_1
2280 is_floating_point_v<value_type>, double,
2282 static_assert(
sizeof(_R) %
sizeof(_W) == 0);
2283 constexpr int __return_width =
sizeof(_R) /
sizeof(_W);
2284 using _Up = __vector_type_t<_W, __return_width>;
2285 const auto __x = __vector_bitcast<_W>(__in);
2287 constexpr int __return_width = _TVT::_S_full_size / _SplitBy;
2289 const __vector_type_t<value_type, _TVT::_S_full_size>& __x
2292 constexpr int _O = _Offset * __return_width;
2293 return __call_with_subscripts<__return_width, _O>(
2294 __x, [](
auto... __entries) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
2295 return reinterpret_cast<_R
>(_Up{__entries...});
2302template <
typename _Tp,
2303 typename _R = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2304 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2308 __builtin_memcpy(&__r, &__x, 8);
2312template <
typename _Tp,
2313 typename _R = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2314 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2317 static_assert(
sizeof(_Tp) == 16,
"use __hi64z if you meant it");
2319 __builtin_memcpy(&__r,
reinterpret_cast<const char*
>(&__x) + 8, 8);
2323template <
typename _Tp,
2324 typename _R = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2325 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2326 __hi64z([[maybe_unused]] _Tp __x)
2329 if constexpr (
sizeof(_Tp) == 16)
2330 __builtin_memcpy(&__r,
reinterpret_cast<const char*
>(&__x) + 8, 8);
2336template <
typename _Tp>
2337 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2339 {
return __extract<0,
sizeof(_Tp) / 16>(__x); }
2341template <
typename _Tp>
2342 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2345 static_assert(
sizeof(__x) == 32);
2346 return __extract<1, 2>(__x);
2351template <
typename _Tp>
2352 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2355 static_assert(
sizeof(__x) == 64);
2356 return __extract<0, 2>(__x);
2359template <
typename _Tp>
2360 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2363 static_assert(
sizeof(__x) == 64);
2364 return __extract<1, 2>(__x);
2369template <
typename _Tp>
2372 static_assert(__is_vector_type_v<_Tp>);
2376 template <
typename _Up,
typename _UVT = _VectorTraits<_Up>>
2377 _GLIBCXX_SIMD_INTRINSIC
constexpr operator _Up()
const
2378 {
return __intrin_bitcast<typename _UVT::type>(__x); }
2381template <
typename _Tp>
2382 _GLIBCXX_SIMD_INTRINSIC
constexpr _AutoCast<_Tp>
2383 __auto_bitcast(
const _Tp& __x)
2386template <
typename _Tp,
size_t _Np>
2387 _GLIBCXX_SIMD_INTRINSIC
constexpr
2388 _AutoCast<typename _SimdWrapper<_Tp, _Np>::_BuiltinType>
2389 __auto_bitcast(
const _SimdWrapper<_Tp, _Np>& __x)
2390 {
return {__x._M_data}; }
2395#if _GLIBCXX_SIMD_HAVE_SSE_ABI
2397#if _GLIBCXX_SIMD_HAVE_AVX512F && _GLIBCXX_SIMD_X86INTRIN
2398template <
size_t _Size>
2399 struct __bool_storage_member_type
2401 static_assert((_Size & (_Size - 1)) != 0,
2402 "This trait may only be used for non-power-of-2 sizes. "
2403 "Power-of-2 sizes must be specialized.");
2409 struct __bool_storage_member_type<1> {
using type = bool; };
2412 struct __bool_storage_member_type<2> {
using type = __mmask8; };
2415 struct __bool_storage_member_type<4> {
using type = __mmask8; };
2418 struct __bool_storage_member_type<8> {
using type = __mmask8; };
2421 struct __bool_storage_member_type<16> {
using type = __mmask16; };
2424 struct __bool_storage_member_type<32> {
using type = __mmask32; };
2427 struct __bool_storage_member_type<64> {
using type = __mmask64; };
2433#if _GLIBCXX_SIMD_HAVE_SSE
2434template <
typename _Tp,
size_t _Bytes>
2435 struct __intrinsic_type<_Tp, _Bytes,
enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 64>>
2437 static_assert(!is_same_v<_Tp, long double>,
2438 "no __intrinsic_type support for long double on x86");
2440 static constexpr size_t _S_VBytes = _Bytes <= 16 ? 16 : _Bytes <= 32 ? 32 : 64;
2442 using type [[__gnu__::__vector_size__(_S_VBytes)]]
2443 = conditional_t<is_integral_v<_Tp>,
long long int, _Tp>;
2450#if _GLIBCXX_SIMD_HAVE_NEON
2452 struct __intrinsic_type<float, 8, void>
2453 {
using type = float32x2_t; };
2456 struct __intrinsic_type<float, 16, void>
2457 {
using type = float32x4_t; };
2460 struct __intrinsic_type<double, 8, void>
2462#if _GLIBCXX_SIMD_HAVE_NEON_A64
2463 using type = float64x1_t;
2468 struct __intrinsic_type<double, 16, void>
2470#if _GLIBCXX_SIMD_HAVE_NEON_A64
2471 using type = float64x2_t;
2475#define _GLIBCXX_SIMD_ARM_INTRIN(_Bits, _Np) \
2477 struct __intrinsic_type<__int_with_sizeof_t<_Bits / 8>, \
2478 _Np * _Bits / 8, void> \
2479 { using type = int##_Bits##x##_Np##_t; }; \
2481 struct __intrinsic_type<make_unsigned_t<__int_with_sizeof_t<_Bits / 8>>, \
2482 _Np * _Bits / 8, void> \
2483 { using type = uint##_Bits##x##_Np##_t; }
2484_GLIBCXX_SIMD_ARM_INTRIN(8, 8);
2485_GLIBCXX_SIMD_ARM_INTRIN(8, 16);
2486_GLIBCXX_SIMD_ARM_INTRIN(16, 4);
2487_GLIBCXX_SIMD_ARM_INTRIN(16, 8);
2488_GLIBCXX_SIMD_ARM_INTRIN(32, 2);
2489_GLIBCXX_SIMD_ARM_INTRIN(32, 4);
2490_GLIBCXX_SIMD_ARM_INTRIN(64, 1);
2491_GLIBCXX_SIMD_ARM_INTRIN(64, 2);
2492#undef _GLIBCXX_SIMD_ARM_INTRIN
2494template <
typename _Tp,
size_t _Bytes>
2495 struct __intrinsic_type<_Tp, _Bytes,
enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 16>>
2497 static constexpr int _SVecBytes = _Bytes <= 8 ? 8 : 16;
2499 using _Ip = __int_for_sizeof_t<_Tp>;
2502 is_floating_point_v<_Tp>, _Tp,
2503 conditional_t<is_unsigned_v<_Tp>, make_unsigned_t<_Ip>, _Ip>>;
2505 static_assert(!is_same_v<_Tp, _Up> || _SVecBytes != _Bytes,
2506 "should use explicit specialization above");
2508 using type =
typename __intrinsic_type<_Up, _SVecBytes>::type;
2515template <
typename _Tp>
2516 struct __intrinsic_type_impl;
2518#define _GLIBCXX_SIMD_PPC_INTRIN(_Tp) \
2520 struct __intrinsic_type_impl<_Tp> { using type = __vector _Tp; }
2521_GLIBCXX_SIMD_PPC_INTRIN(
float);
2523_GLIBCXX_SIMD_PPC_INTRIN(
double);
2525_GLIBCXX_SIMD_PPC_INTRIN(
signed char);
2526_GLIBCXX_SIMD_PPC_INTRIN(
unsigned char);
2527_GLIBCXX_SIMD_PPC_INTRIN(
signed short);
2528_GLIBCXX_SIMD_PPC_INTRIN(
unsigned short);
2529_GLIBCXX_SIMD_PPC_INTRIN(
signed int);
2530_GLIBCXX_SIMD_PPC_INTRIN(
unsigned int);
2531#if defined __VSX__ || __SIZEOF_LONG__ == 4
2532_GLIBCXX_SIMD_PPC_INTRIN(
signed long);
2533_GLIBCXX_SIMD_PPC_INTRIN(
unsigned long);
2536_GLIBCXX_SIMD_PPC_INTRIN(
signed long long);
2537_GLIBCXX_SIMD_PPC_INTRIN(
unsigned long long);
2539#undef _GLIBCXX_SIMD_PPC_INTRIN
2541template <
typename _Tp,
size_t _Bytes>
2542 struct __intrinsic_type<_Tp, _Bytes,
enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 16>>
2544 static constexpr bool _S_is_ldouble = is_same_v<_Tp, long double>;
2547 static_assert(!(_S_is_ldouble &&
sizeof(
long double) >
sizeof(
double)),
2548 "no __intrinsic_type support for 128-bit floating point on PowerPC");
2551 static_assert(!(is_same_v<_Tp, double>
2552 || (_S_is_ldouble &&
sizeof(
long double) ==
sizeof(
double))),
2553 "no __intrinsic_type support for 64-bit floating point on PowerPC w/o VSX");
2556 static constexpr auto __element_type()
2558 if constexpr (is_floating_point_v<_Tp>)
2560 if constexpr (_S_is_ldouble)
2565 else if constexpr (is_signed_v<_Tp>)
2567 if constexpr (
sizeof(_Tp) ==
sizeof(_SChar))
2569 else if constexpr (
sizeof(_Tp) ==
sizeof(
short))
2571 else if constexpr (
sizeof(_Tp) ==
sizeof(
int))
2573 else if constexpr (
sizeof(_Tp) ==
sizeof(_LLong))
2578 if constexpr (
sizeof(_Tp) ==
sizeof(_UChar))
2580 else if constexpr (
sizeof(_Tp) ==
sizeof(_UShort))
2582 else if constexpr (
sizeof(_Tp) ==
sizeof(_UInt))
2584 else if constexpr (
sizeof(_Tp) ==
sizeof(_ULLong))
2589 using type =
typename __intrinsic_type_impl<
decltype(__element_type())>::type;
2595template <
size_t _W
idth>
2596 struct _SimdWrapper<bool, _Width,
2597 void_t<typename __bool_storage_member_type<_Width>::type>>
2599 using _BuiltinType =
typename __bool_storage_member_type<_Width>::type;
2600 using value_type = bool;
2602 static constexpr size_t _S_full_size =
sizeof(_BuiltinType) * __CHAR_BIT__;
2604 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper<bool, _S_full_size>
2605 __as_full_vector()
const
2608 _GLIBCXX_SIMD_INTRINSIC
constexpr
2609 _SimdWrapper() =
default;
2611 _GLIBCXX_SIMD_INTRINSIC
constexpr
2612 _SimdWrapper(_BuiltinType __k) : _M_data(__k) {};
2614 _GLIBCXX_SIMD_INTRINSIC
2615 operator const _BuiltinType&()
const
2618 _GLIBCXX_SIMD_INTRINSIC
2619 operator _BuiltinType&()
2622 _GLIBCXX_SIMD_INTRINSIC _BuiltinType
2626 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type
2627 operator[](
size_t __i)
const
2628 {
return _M_data & (_BuiltinType(1) << __i); }
2630 template <
size_t __i>
2631 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type
2632 operator[](_SizeConstant<__i>)
const
2633 {
return _M_data & (_BuiltinType(1) << __i); }
2635 _GLIBCXX_SIMD_INTRINSIC
constexpr void
2636 _M_set(
size_t __i, value_type __x)
2639 _M_data |= (_BuiltinType(1) << __i);
2641 _M_data &= ~(_BuiltinType(1) << __i);
2644 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
2645 _M_is_constprop()
const
2646 {
return __builtin_constant_p(_M_data); }
2648 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
2649 _M_is_constprop_none_of()
const
2651 if (__builtin_constant_p(_M_data))
2653 constexpr int __nbits =
sizeof(_BuiltinType) * __CHAR_BIT__;
2654 constexpr _BuiltinType __active_mask
2655 = ~_BuiltinType() >> (__nbits - _Width);
2656 return (_M_data & __active_mask) == 0;
2661 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
2662 _M_is_constprop_all_of()
const
2664 if (__builtin_constant_p(_M_data))
2666 constexpr int __nbits =
sizeof(_BuiltinType) * __CHAR_BIT__;
2667 constexpr _BuiltinType __active_mask
2668 = ~_BuiltinType() >> (__nbits - _Width);
2669 return (_M_data & __active_mask) == __active_mask;
2674 _BuiltinType _M_data;
2678template <
bool _MustZeroInitPadding,
typename _BuiltinType>
2679 struct _SimdWrapperBase;
2681template <
typename _BuiltinType>
2682 struct _SimdWrapperBase<false, _BuiltinType>
2684 _GLIBCXX_SIMD_INTRINSIC
constexpr
2685 _SimdWrapperBase() =
default;
2687 _GLIBCXX_SIMD_INTRINSIC
constexpr
2688 _SimdWrapperBase(_BuiltinType __init) : _M_data(__init) {}
2690 _BuiltinType _M_data;
2693template <
typename _BuiltinType>
2694 struct _SimdWrapperBase<true, _BuiltinType>
2697 _GLIBCXX_SIMD_INTRINSIC
constexpr
2698 _SimdWrapperBase() : _M_data() {}
2700 _GLIBCXX_SIMD_INTRINSIC
constexpr
2701 _SimdWrapperBase(_BuiltinType __init) : _M_data(__init) {}
2703 _BuiltinType _M_data;
2708struct _DisabledSimdWrapper;
2710template <
typename _Tp,
size_t _W
idth>
2711 struct _SimdWrapper<
2713 void_t<__vector_type_t<_Tp, _Width>, __intrinsic_type_t<_Tp, _Width>>>
2714 : _SimdWrapperBase<__has_iec559_behavior<__signaling_NaN, _Tp>::value
2715 && sizeof(_Tp) * _Width
2716 == sizeof(__vector_type_t<_Tp, _Width>),
2717 __vector_type_t<_Tp, _Width>>
2719 static constexpr bool _S_need_default_init
2720 = __has_iec559_behavior<__signaling_NaN, _Tp>::value
2721 and
sizeof(_Tp) * _Width ==
sizeof(__vector_type_t<_Tp, _Width>);
2723 using _BuiltinType = __vector_type_t<_Tp, _Width>;
2725 using _Base = _SimdWrapperBase<_S_need_default_init, _BuiltinType>;
2727 static_assert(__is_vectorizable_v<_Tp>);
2728 static_assert(_Width >= 2);
2730 using value_type = _Tp;
2732 static inline constexpr size_t _S_full_size
2733 =
sizeof(_BuiltinType) /
sizeof(value_type);
2734 static inline constexpr int _S_size = _Width;
2735 static inline constexpr bool _S_is_partial = _S_full_size != _S_size;
2737 using _Base::_M_data;
2739 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper<_Tp, _S_full_size>
2740 __as_full_vector()
const
2743 _GLIBCXX_SIMD_INTRINSIC
constexpr
2744 _SimdWrapper(initializer_list<_Tp> __init)
2745 : _Base(__generate_from_n_evaluations<_Width, _BuiltinType>(
2746 [&](auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
2747 return __init.begin()[__i.value];
2750 _GLIBCXX_SIMD_INTRINSIC
constexpr
2751 _SimdWrapper() =
default;
2753 _GLIBCXX_SIMD_INTRINSIC
constexpr
2754 _SimdWrapper(
const _SimdWrapper&) =
default;
2756 _GLIBCXX_SIMD_INTRINSIC
constexpr
2757 _SimdWrapper(_SimdWrapper&&) =
default;
2759 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper&
2760 operator=(
const _SimdWrapper&) =
default;
2762 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper&
2763 operator=(_SimdWrapper&&) =
default;
2766 using _SimdWrapperBase<_S_need_default_init, _BuiltinType>::_SimdWrapperBase;
2770 _GLIBCXX_SIMD_INTRINSIC
constexpr
2771 _SimdWrapper(conditional_t<is_same_v<_BuiltinType, __intrinsic_type_t<_Tp, _Width>>,
2772 _DisabledSimdWrapper, __intrinsic_type_t<_Tp, _Width>> __x)
2773 : _Base(__vector_bitcast<_Tp, _Width>(__x)) {}
2777 template <
typename _V,
typename _TVT = _VectorTraits<_V>,
2778 typename = enable_if_t<sizeof(
typename _TVT::value_type) == sizeof(_Tp)
2779 and sizeof(_V) == sizeof(_BuiltinType)
2780 and is_
integral_v<_Tp>
2781 and is_
integral_v<
typename _TVT::value_type>>>
2782 _GLIBCXX_SIMD_INTRINSIC
constexpr
2783 _SimdWrapper(_V __x)
2784 : _Base(reinterpret_cast<_BuiltinType>(__x)) {}
2786 template <
typename... _As,
2787 typename =
enable_if_t<((is_same_v<simd_abi::scalar, _As> && ...)
2788 &&
sizeof...(_As) <= _Width)>>
2789 _GLIBCXX_SIMD_INTRINSIC
constexpr
2790 operator _SimdTuple<_Tp, _As...>()
const
2792 return __generate_from_n_evaluations<
sizeof...(_As), _SimdTuple<_Tp, _As...>>(
2793 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
2794 {
return _M_data[int(__i)]; });
2797 _GLIBCXX_SIMD_INTRINSIC
constexpr
2798 operator const _BuiltinType&()
const
2801 _GLIBCXX_SIMD_INTRINSIC
constexpr
2802 operator _BuiltinType&()
2805 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp
2806 operator[](
size_t __i)
const
2807 {
return _M_data[__i]; }
2809 template <
size_t __i>
2810 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp
2811 operator[](_SizeConstant<__i>)
const
2812 {
return _M_data[__i]; }
2814 _GLIBCXX_SIMD_INTRINSIC
constexpr void
2815 _M_set(
size_t __i, _Tp __x)
2817 if (__builtin_is_constant_evaluated())
2818 _M_data = __generate_from_n_evaluations<_Width, _BuiltinType>([&](
auto __j) {
2819 return __j == __i ? __x : _M_data[__j()];
2825 _GLIBCXX_SIMD_INTRINSIC
2827 _M_is_constprop()
const
2828 {
return __builtin_constant_p(_M_data); }
2830 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
2831 _M_is_constprop_none_of()
const
2833 if (__builtin_constant_p(_M_data))
2836 if constexpr (is_floating_point_v<_Tp>)
2838 using _Ip = __int_for_sizeof_t<_Tp>;
2839 const auto __intdata = __vector_bitcast<_Ip>(_M_data);
2840 __execute_n_times<_Width>(
2841 [&](
auto __i) { __r &= __intdata[__i.value] == _Ip(); });
2844 __execute_n_times<_Width>(
2845 [&](
auto __i) { __r &= _M_data[__i.value] == _Tp(); });
2846 if (__builtin_constant_p(__r))
2852 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
2853 _M_is_constprop_all_of()
const
2855 if (__builtin_constant_p(_M_data))
2858 if constexpr (is_floating_point_v<_Tp>)
2860 using _Ip = __int_for_sizeof_t<_Tp>;
2861 const auto __intdata = __vector_bitcast<_Ip>(_M_data);
2862 __execute_n_times<_Width>(
2863 [&](
auto __i) { __r &= __intdata[__i.value] == ~_Ip(); });
2866 __execute_n_times<_Width>(
2867 [&](
auto __i) { __r &= _M_data[__i.value] == ~_Tp(); });
2868 if (__builtin_constant_p(__r))
2878template <
typename _Tp>
2880 __vectorized_sizeof()
2882 if constexpr (!__is_vectorizable_v<_Tp>)
2885 if constexpr (
sizeof(_Tp) <= 8)
2888 if constexpr (__have_avx512bw)
2890 if constexpr (__have_avx512f &&
sizeof(_Tp) >= 4)
2892 if constexpr (__have_avx2)
2894 if constexpr (__have_avx && is_floating_point_v<_Tp>)
2896 if constexpr (__have_sse2)
2898 if constexpr (__have_sse && is_same_v<_Tp, float>)
2908 if constexpr (__have_power8vec
2909 || (__have_power_vmx && (
sizeof(_Tp) < 8))
2910 || (__have_power_vsx && is_floating_point_v<_Tp>) )
2914 if constexpr (__have_neon_a64
2915 || (__have_neon_a32 && !is_same_v<_Tp, double>) )
2917 if constexpr (__have_neon
2922 && (__support_neon_float || !is_floating_point_v<_Tp>))
2932template <
typename _Tp>
2933 inline constexpr int max_fixed_size
2934 = (__have_avx512bw &&
sizeof(_Tp) == 1) ? 64 : 32;
2937#if defined __x86_64__ || defined __aarch64__
2938template <
typename _Tp>
2939 using compatible =
conditional_t<(
sizeof(_Tp) <= 8), _VecBuiltin<16>, scalar>;
2940#elif defined __ARM_NEON
2943template <
typename _Tp>
2946 && (__support_neon_float || !is_floating_point_v<_Tp>)),
2947 _VecBuiltin<16>, scalar>;
2950 using compatible = scalar;
2955template <
typename _Tp>
2957 __determine_native_abi()
2959 constexpr size_t __bytes = __vectorized_sizeof<_Tp>();
2960 if constexpr (__bytes ==
sizeof(_Tp))
2961 return static_cast<scalar*
>(
nullptr);
2962 else if constexpr (__have_avx512vl || (__have_avx512f && __bytes == 64))
2963 return static_cast<_VecBltnBtmsk<__bytes>*
>(
nullptr);
2965 return static_cast<_VecBuiltin<__bytes>*
>(
nullptr);
2968template <
typename _Tp,
typename = enable_if_t<__is_vectorizable_v<_Tp>>>
2969 using native = remove_pointer_t<decltype(__determine_native_abi<_Tp>())>;
2973#if defined _GLIBCXX_SIMD_DEFAULT_ABI
2974template <
typename _Tp>
2975 using __default_abi = _GLIBCXX_SIMD_DEFAULT_ABI<_Tp>;
2977template <
typename _Tp>
2978 using __default_abi = compatible<_Tp>;
2985template <
typename _Tp>
2986 struct is_simd_flag_type
2991 struct is_simd_flag_type<element_aligned_tag>
2996 struct is_simd_flag_type<vector_aligned_tag>
3000template <
size_t _Np>
3001 struct is_simd_flag_type<overaligned_tag<_Np>>
3002 : __bool_constant<(_Np > 0) and __has_single_bit(_Np)>
3005template <
typename _Tp>
3006 inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<_Tp>::value;
3008template <
typename _Tp,
typename = enable_if_t<is_simd_flag_type_v<_Tp>>>
3009 using _IsSimdFlagType = _Tp;
3012template <
typename _Tp,
typename =
void_t<>>
3015template <
typename _Tp>
3016 struct is_abi_tag<_Tp,
void_t<typename _Tp::_IsValidAbiTag>>
3017 :
public _Tp::_IsValidAbiTag {};
3019template <
typename _Tp>
3020 inline constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value;
3023template <
typename _Tp>
3026template <
typename _Tp>
3027 inline constexpr bool is_simd_v = is_simd<_Tp>::value;
3029template <
typename _Tp>
3032template <
typename _Tp>
3033inline constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value;
3036template <
typename _Tp,
typename _Abi,
typename =
void>
3037 struct __simd_size_impl {};
3039template <
typename _Tp,
typename _Abi>
3040 struct __simd_size_impl<
3042 enable_if_t<conjunction_v<__is_vectorizable<_Tp>, is_abi_tag<_Abi>>>>
3043 : _SizeConstant<_Abi::template _S_size<_Tp>> {};
3045template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
3046 struct simd_size : __simd_size_impl<_Tp, _Abi> {};
3048template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
3049 inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
3052template <
typename _Tp,
size_t _Np,
typename =
void>
3053 struct __deduce_impl;
3064template <
typename _Tp,
size_t _Np,
typename...>
3067template <
typename _Tp,
size_t _Np,
typename... _Abis>
3068 using deduce_t =
typename deduce<_Tp, _Np, _Abis...>::type;
3073template <
typename _Tp,
typename _V,
typename =
void>
3076template <
typename _Tp,
typename _Up,
typename _Abi>
3077 struct rebind_simd<_Tp, simd<_Up, _Abi>,
3078 void_t<simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>>
3079 {
using type = simd<_Tp, simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>; };
3081template <
typename _Tp,
typename _Up,
typename _Abi>
3082 struct rebind_simd<_Tp, simd_mask<_Up, _Abi>,
3083 void_t<simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>>
3084 {
using type = simd_mask<_Tp, simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>; };
3086template <
typename _Tp,
typename _V>
3087 using rebind_simd_t =
typename rebind_simd<_Tp, _V>::type;
3090template <
int _Np,
typename _V,
typename =
void>
3093template <
int _Np,
typename _Tp,
typename _Abi>
3094 struct resize_simd<_Np, simd<_Tp, _Abi>,
void_t<simd_abi::deduce_t<_Tp, _Np, _Abi>>>
3095 {
using type = simd<_Tp, simd_abi::deduce_t<_Tp, _Np, _Abi>>; };
3097template <
int _Np,
typename _Tp,
typename _Abi>
3098 struct resize_simd<_Np, simd_mask<_Tp, _Abi>,
void_t<simd_abi::deduce_t<_Tp, _Np, _Abi>>>
3099 {
using type = simd_mask<_Tp, simd_abi::deduce_t<_Tp, _Np, _Abi>>; };
3101template <
int _Np,
typename _V>
3102 using resize_simd_t =
typename resize_simd<_Np, _V>::type;
3106template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
3107 struct memory_alignment
3108 :
public _SizeConstant<vector_aligned_tag::_S_alignment<_Tp, _Up>> {};
3110template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
3111 inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value;
3114template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
3117template <
typename _Tp,
typename _Abi>
3118 struct is_simd<simd<_Tp, _Abi>> :
public true_type {};
3120template <
typename _Tp>
3121 using native_simd = simd<_Tp, simd_abi::native<_Tp>>;
3123template <
typename _Tp,
int _Np>
3124 using fixed_size_simd = simd<_Tp, simd_abi::fixed_size<_Np>>;
3126template <
typename _Tp,
size_t _Np>
3127 using __deduced_simd = simd<_Tp, simd_abi::deduce_t<_Tp, _Np>>;
3130template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
3133template <
typename _Tp,
typename _Abi>
3134 struct is_simd_mask<simd_mask<_Tp, _Abi>> :
public true_type {};
3136template <
typename _Tp>
3137 using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>;
3139template <
typename _Tp,
int _Np>
3140 using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>;
3142template <
typename _Tp,
size_t _Np>
3143 using __deduced_simd_mask = simd_mask<_Tp, simd_abi::deduce_t<_Tp, _Np>>;
3147template <
typename _Tp,
typename _Up,
typename _Ap,
bool = is_simd_v<_Tp>,
typename =
void>
3148 struct __static_simd_cast_return_type;
3150template <
typename _Tp,
typename _A0,
typename _Up,
typename _Ap>
3151 struct __static_simd_cast_return_type<simd_mask<_Tp, _A0>, _Up, _Ap, false, void>
3152 : __static_simd_cast_return_type<simd<_Tp, _A0>, _Up, _Ap> {};
3154template <
typename _Tp,
typename _Up,
typename _Ap>
3155 struct __static_simd_cast_return_type<
3156 _Tp, _Up, _Ap, true,
enable_if_t<_Tp::size() == simd_size_v<_Up, _Ap>>>
3157 {
using type = _Tp; };
3159template <
typename _Tp,
typename _Ap>
3160 struct __static_simd_cast_return_type<_Tp, _Tp, _Ap, false,
3161#ifdef _GLIBCXX_SIMD_FIX_P2TS_ISSUE66
3167 {
using type = simd<_Tp, _Ap>; };
3169template <
typename _Tp,
typename =
void>
3170 struct __safe_make_signed {
using type = _Tp;};
3172template <
typename _Tp>
3173 struct __safe_make_signed<_Tp,
enable_if_t<is_integral_v<_Tp>>>
3176 using type = make_signed_t<make_unsigned_t<_Tp>>;
3179template <
typename _Tp>
3180 using safe_make_signed_t =
typename __safe_make_signed<_Tp>::type;
3182template <
typename _Tp,
typename _Up,
typename _Ap>
3183 struct __static_simd_cast_return_type<_Tp, _Up, _Ap, false,
3184#ifdef _GLIBCXX_SIMD_FIX_P2TS_ISSUE66
3192 (is_integral_v<_Up> && is_integral_v<_Tp> &&
3193#ifndef _GLIBCXX_SIMD_FIX_P2TS_ISSUE65
3194 is_signed_v<_Up> != is_signed_v<_Tp> &&
3196 is_same_v<safe_make_signed_t<_Up>, safe_make_signed_t<_Tp>>),
3197 simd<_Tp, _Ap>, fixed_size_simd<_Tp, simd_size_v<_Up, _Ap>>>;
3200template <
typename _Tp,
typename _Up,
typename _Ap,
3202 =
typename __static_simd_cast_return_type<_Tp, _Up, _Ap>::type>
3203 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _R
3204 static_simd_cast(
const simd<_Up, _Ap>& __x)
3206 if constexpr (is_same<_R, simd<_Up, _Ap>>::value)
3210 _SimdConverter<_Up, _Ap, typename _R::value_type, typename _R::abi_type>
3212 return _R(__private_init, __c(__data(__x)));
3216namespace __proposed {
3217template <
typename _Tp,
typename _Up,
typename _Ap,
3219 =
typename __static_simd_cast_return_type<_Tp, _Up, _Ap>::type>
3220 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
typename _R::mask_type
3221 static_simd_cast(
const simd_mask<_Up, _Ap>& __x)
3223 using _RM =
typename _R::mask_type;
3224 return {__private_init, _RM::abi_type::_MaskImpl::template _S_convert<
3225 typename _RM::simd_type::value_type>(__x)};
3228template <
typename _To,
typename _Up,
typename _Abi>
3229 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3231 simd_bit_cast(
const simd<_Up, _Abi>& __x)
3233 using _Tp =
typename _To::value_type;
3234 using _ToMember =
typename _SimdTraits<_Tp, typename _To::abi_type>::_SimdMember;
3235 using _From = simd<_Up, _Abi>;
3236 using _FromMember =
typename _SimdTraits<_Up, _Abi>::_SimdMember;
3238 static_assert(
sizeof(_To) ==
sizeof(_From));
3239 static_assert(is_trivially_copyable_v<_Tp> && is_trivially_copyable_v<_Up>);
3240 static_assert(is_trivially_copyable_v<_ToMember> && is_trivially_copyable_v<_FromMember>);
3241#if __has_builtin(__builtin_bit_cast)
3242 return {__private_init, __builtin_bit_cast(_ToMember, __data(__x))};
3244 return {__private_init, __bit_cast<_ToMember>(__data(__x))};
3248template <
typename _To,
typename _Up,
typename _Abi>
3249 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3251 simd_bit_cast(
const simd_mask<_Up, _Abi>& __x)
3253 using _From = simd_mask<_Up, _Abi>;
3254 static_assert(
sizeof(_To) ==
sizeof(_From));
3255 static_assert(is_trivially_copyable_v<_From>);
3258 if constexpr (is_simd_v<_To>)
3260 using _Tp =
typename _To::value_type;
3261 using _ToMember =
typename _SimdTraits<_Tp, typename _To::abi_type>::_SimdMember;
3262 static_assert(is_trivially_copyable_v<_ToMember>);
3263#if __has_builtin(__builtin_bit_cast)
3264 return {__private_init, __builtin_bit_cast(_ToMember, __x)};
3266 return {__private_init, __bit_cast<_ToMember>(__x)};
3271 static_assert(is_trivially_copyable_v<_To>);
3272#if __has_builtin(__builtin_bit_cast)
3273 return __builtin_bit_cast(_To, __x);
3275 return __bit_cast<_To>(__x);
3282template <
typename _Tp,
typename _Up,
typename _Ap,
3283 typename _To = __value_type_or_identity_t<_Tp>>
3284 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
auto
3285 simd_cast(
const simd<_ValuePreserving<_Up, _To>, _Ap>& __x)
3286 ->
decltype(static_simd_cast<_Tp>(__x))
3287 {
return static_simd_cast<_Tp>(__x); }
3289namespace __proposed {
3290template <
typename _Tp,
typename _Up,
typename _Ap,
3291 typename _To = __value_type_or_identity_t<_Tp>>
3292 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
auto
3293 simd_cast(
const simd_mask<_ValuePreserving<_Up, _To>, _Ap>& __x)
3294 ->
decltype(static_simd_cast<_Tp>(__x))
3295 {
return static_simd_cast<_Tp>(__x); }
3300namespace __proposed {
3327template <
typename _Tp,
typename _Up,
typename _Ap>
3328 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
enable_if_t<
3329 conjunction_v<is_simd<_Tp>, is_same<typename _Tp::value_type, _Up>>, _Tp>
3330 resizing_simd_cast(
const simd<_Up, _Ap>& __x)
3332 if constexpr (is_same_v<typename _Tp::abi_type, _Ap>)
3334 else if (__builtin_is_constant_evaluated())
3335 return _Tp([&](
auto __i)
constexpr {
3336 return __i < simd_size_v<_Up, _Ap> ? __x[__i] : _Up();
3338 else if constexpr (simd_size_v<_Up, _Ap> == 1)
3344 else if constexpr (_Tp::size() == 1)
3346 else if constexpr (
sizeof(_Tp) ==
sizeof(__x)
3347 && !__is_fixed_size_abi_v<_Ap>)
3348 return {__private_init,
3349 __vector_bitcast<typename _Tp::value_type, _Tp::size()>(
3350 _Ap::_S_masked(__data(__x))._M_data)};
3354 __builtin_memcpy(&__data(__r), &__data(__x),
3356 *
std::min(_Tp::size(), simd_size_v<_Up, _Ap>));
3361template <
typename _Tp,
typename _Up,
typename _Ap>
3362 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3363 enable_if_t<is_simd_mask_v<_Tp>, _Tp>
3364 resizing_simd_cast(
const simd_mask<_Up, _Ap>& __x)
3366 return {__private_init, _Tp::abi_type::_MaskImpl::template _S_convert<
3367 typename _Tp::simd_type::value_type>(__x)};
3373template <
typename _Tp,
int _Np>
3374 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd<_Tp, _Np>
3375 to_fixed_size(
const fixed_size_simd<_Tp, _Np>& __x)
3378template <
typename _Tp,
int _Np>
3379 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd_mask<_Tp, _Np>
3380 to_fixed_size(
const fixed_size_simd_mask<_Tp, _Np>& __x)
3383template <
typename _Tp,
typename _Ap>
3384 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd<_Tp, simd_size_v<_Tp, _Ap>>
3385 to_fixed_size(
const simd<_Tp, _Ap>& __x)
3387 using _Rp = fixed_size_simd<_Tp, simd_size_v<_Tp, _Ap>>;
3388 return _Rp([&__x](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3391template <
typename _Tp,
typename _Ap>
3392 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd_mask<_Tp, simd_size_v<_Tp, _Ap>>
3393 to_fixed_size(
const simd_mask<_Tp, _Ap>& __x)
3395 return {__private_init,
3396 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; }};
3400template <
typename _Tp,
int _Np>
3401 _GLIBCXX_SIMD_INTRINSIC
3402 enable_if_t<(_Np == native_simd<_Tp>::size()), native_simd<_Tp>>
3403 to_native(
const fixed_size_simd<_Tp, _Np>& __x)
3405 alignas(memory_alignment_v<native_simd<_Tp>>) _Tp __mem[_Np];
3406 __x.copy_to(__mem, vector_aligned);
3407 return {__mem, vector_aligned};
3410template <
typename _Tp,
int _Np>
3411 _GLIBCXX_SIMD_INTRINSIC
3412 enable_if_t<(_Np == native_simd_mask<_Tp>::size()), native_simd_mask<_Tp>>
3413 to_native(
const fixed_size_simd_mask<_Tp, _Np>& __x)
3415 return native_simd_mask<_Tp>(
3417 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3421template <
typename _Tp,
int _Np>
3422 _GLIBCXX_SIMD_INTRINSIC
enable_if_t<(_Np == simd<_Tp>::size()), simd<_Tp>>
3423 to_compatible(
const simd<_Tp, simd_abi::fixed_size<_Np>>& __x)
3425 alignas(memory_alignment_v<simd<_Tp>>) _Tp __mem[_Np];
3426 __x.copy_to(__mem, vector_aligned);
3427 return {__mem, vector_aligned};
3430template <
typename _Tp,
int _Np>
3431 _GLIBCXX_SIMD_INTRINSIC
3432 enable_if_t<(_Np == simd_mask<_Tp>::size()), simd_mask<_Tp>>
3433 to_compatible(
const simd_mask<_Tp, simd_abi::fixed_size<_Np>>& __x)
3435 return simd_mask<_Tp>(
3437 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3444template <
typename _M,
typename _Tp>
3445 class const_where_expression
3448 static_assert(is_same_v<_V, __remove_cvref_t<_Tp>>);
3450 struct _Wrapper {
using value_type = _V; };
3453 using _Impl =
typename _V::_Impl;
3456 typename conditional_t<is_arithmetic_v<_V>, _Wrapper, _V>::value_type;
3458 _GLIBCXX_SIMD_INTRINSIC
friend const _M&
3459 __get_mask(
const const_where_expression& __x)
3460 {
return __x._M_k; }
3462 _GLIBCXX_SIMD_INTRINSIC
friend const _Tp&
3463 __get_lvalue(
const const_where_expression& __x)
3464 {
return __x._M_value; }
3470 const_where_expression(
const const_where_expression&) =
delete;
3472 const_where_expression& operator=(
const const_where_expression&) =
delete;
3474 _GLIBCXX_SIMD_INTRINSIC
constexpr
3475 const_where_expression(
const _M& __kk,
const _Tp& dd)
3476 : _M_k(__kk), _M_value(const_cast<_Tp&>(dd)) {}
3478 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _V
3481 return {__private_init,
3482 _Impl::template _S_masked_unary<negate>(__data(_M_k),
3486 template <
typename _Up,
typename _Flags>
3487 [[nodiscard]] _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _V
3488 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>)
const&&
3490 return {__private_init,
3491 _Impl::_S_masked_load(__data(_M_value), __data(_M_k),
3492 _Flags::template _S_apply<_V>(__mem))};
3495 template <
typename _Up,
typename _Flags>
3496 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3497 copy_to(_LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>)
const&&
3499 _Impl::_S_masked_store(__data(_M_value),
3500 _Flags::template _S_apply<_V>(__mem),
3506template <
typename _Tp>
3507 class const_where_expression<bool, _Tp>
3512 static_assert(is_same_v<_V, __remove_cvref_t<_Tp>>);
3514 struct _Wrapper {
using value_type = _V; };
3518 =
typename conditional_t<is_arithmetic_v<_V>, _Wrapper, _V>::value_type;
3520 _GLIBCXX_SIMD_INTRINSIC
friend const _M&
3521 __get_mask(
const const_where_expression& __x)
3522 {
return __x._M_k; }
3524 _GLIBCXX_SIMD_INTRINSIC
friend const _Tp&
3525 __get_lvalue(
const const_where_expression& __x)
3526 {
return __x._M_value; }
3532 const_where_expression(
const const_where_expression&) =
delete;
3533 const_where_expression& operator=(
const const_where_expression&) =
delete;
3535 _GLIBCXX_SIMD_INTRINSIC
constexpr
3536 const_where_expression(
const bool __kk,
const _Tp& dd)
3537 : _M_k(__kk), _M_value(const_cast<_Tp&>(dd)) {}
3539 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _V
3541 {
return _M_k ? -_M_value : _M_value; }
3543 template <
typename _Up,
typename _Flags>
3544 [[nodiscard]] _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _V
3545 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>)
const&&
3546 {
return _M_k ?
static_cast<_V
>(__mem[0]) : _M_value; }
3548 template <
typename _Up,
typename _Flags>
3549 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3550 copy_to(_LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>)
const&&
3553 __mem[0] = _M_value;
3558template <
typename _M,
typename _Tp>
3559 class where_expression :
public const_where_expression<_M, _Tp>
3561 using _Impl =
typename const_where_expression<_M, _Tp>::_Impl;
3563 static_assert(!is_const<_Tp>::value,
3564 "where_expression may only be instantiated with __a non-const "
3567 using typename const_where_expression<_M, _Tp>::value_type;
3568 using const_where_expression<_M, _Tp>::_M_k;
3569 using const_where_expression<_M, _Tp>::_M_value;
3572 is_same<typename _M::abi_type, typename _Tp::abi_type>::value,
"");
3573 static_assert(_M::size() == _Tp::size(),
"");
3575 _GLIBCXX_SIMD_INTRINSIC
friend constexpr _Tp&
3576 __get_lvalue(where_expression& __x)
3577 {
return __x._M_value; }
3580 where_expression(
const where_expression&) =
delete;
3581 where_expression& operator=(
const where_expression&) =
delete;
3583 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3584 where_expression(
const _M& __kk, _Tp& dd)
3585 : const_where_expression<_M, _Tp>(__kk, dd) {}
3587 template <
typename _Up>
3588 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3589 operator=(_Up&& __x) &&
3591 _Impl::_S_masked_assign(__data(_M_k), __data(_M_value),
3592 __to_value_type_or_member_type<_Tp>(
3593 static_cast<_Up&&
>(__x)));
3596#define _GLIBCXX_SIMD_OP_(__op, __name) \
3597 template <typename _Up> \
3598 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR void \
3599 operator __op##=(_Up&& __x)&& \
3601 _Impl::template _S_masked_cassign( \
3602 __data(_M_k), __data(_M_value), \
3603 __to_value_type_or_member_type<_Tp>(static_cast<_Up&&>(__x)), \
3604 [](auto __impl, auto __lhs, auto __rhs) \
3605 constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA \
3606 { return __impl.__name(__lhs, __rhs); }); \
3609 _GLIBCXX_SIMD_OP_(+, _S_plus);
3610 _GLIBCXX_SIMD_OP_(-, _S_minus);
3611 _GLIBCXX_SIMD_OP_(*, _S_multiplies);
3612 _GLIBCXX_SIMD_OP_(/, _S_divides);
3613 _GLIBCXX_SIMD_OP_(%, _S_modulus);
3614 _GLIBCXX_SIMD_OP_(&, _S_bit_and);
3615 _GLIBCXX_SIMD_OP_(|, _S_bit_or);
3616 _GLIBCXX_SIMD_OP_(^, _S_bit_xor);
3617 _GLIBCXX_SIMD_OP_(<<, _S_shift_left);
3618 _GLIBCXX_SIMD_OP_(>>, _S_shift_right);
3619#undef _GLIBCXX_SIMD_OP_
3621 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3625 = _Impl::template _S_masked_unary<__increment>(__data(_M_k), __data(_M_value));
3628 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3632 = _Impl::template _S_masked_unary<__increment>(__data(_M_k), __data(_M_value));
3635 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3639 = _Impl::template _S_masked_unary<__decrement>(__data(_M_k), __data(_M_value));
3642 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3646 = _Impl::template _S_masked_unary<__decrement>(__data(_M_k), __data(_M_value));
3650 template <
typename _Up,
typename _Flags>
3651 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3652 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>) &&
3654 __data(_M_value) = _Impl::_S_masked_load(__data(_M_value), __data(_M_k),
3655 _Flags::template _S_apply<_Tp>(__mem));
3660template <
typename _Tp>
3661 class where_expression<bool, _Tp>
3662 :
public const_where_expression<bool, _Tp>
3665 using typename const_where_expression<_M, _Tp>::value_type;
3666 using const_where_expression<_M, _Tp>::_M_k;
3667 using const_where_expression<_M, _Tp>::_M_value;
3670 where_expression(
const where_expression&) =
delete;
3671 where_expression& operator=(
const where_expression&) =
delete;
3673 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3674 where_expression(
const _M& __kk, _Tp& dd)
3675 : const_where_expression<_M, _Tp>(__kk, dd) {}
3677#define _GLIBCXX_SIMD_OP_(__op) \
3678 template <typename _Up> \
3679 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR void \
3680 operator __op(_Up&& __x)&& \
3681 { if (_M_k) _M_value __op static_cast<_Up&&>(__x); }
3683 _GLIBCXX_SIMD_OP_(=)
3684 _GLIBCXX_SIMD_OP_(+=)
3685 _GLIBCXX_SIMD_OP_(-=)
3686 _GLIBCXX_SIMD_OP_(*=)
3687 _GLIBCXX_SIMD_OP_(/=)
3688 _GLIBCXX_SIMD_OP_(%=)
3689 _GLIBCXX_SIMD_OP_(&=)
3690 _GLIBCXX_SIMD_OP_(|=)
3691 _GLIBCXX_SIMD_OP_(^=)
3692 _GLIBCXX_SIMD_OP_(<<=)
3693 _GLIBCXX_SIMD_OP_(>>=)
3694 #undef _GLIBCXX_SIMD_OP_
3696 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3698 {
if (_M_k) ++_M_value; }
3700 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3702 {
if (_M_k) ++_M_value; }
3704 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3706 {
if (_M_k) --_M_value; }
3708 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3710 {
if (_M_k) --_M_value; }
3713 template <
typename _Up,
typename _Flags>
3714 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
void
3715 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>) &&
3716 {
if (_M_k) _M_value = __mem[0]; }
3720template <
typename _Tp,
typename _Ap>
3721 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3722 where_expression<simd_mask<_Tp, _Ap>, simd<_Tp, _Ap>>
3723 where(
const typename simd<_Tp, _Ap>::mask_type& __k, simd<_Tp, _Ap>& __value)
3724 {
return {__k, __value}; }
3726template <
typename _Tp,
typename _Ap>
3727 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3728 const_where_expression<simd_mask<_Tp, _Ap>, simd<_Tp, _Ap>>
3729 where(
const typename simd<_Tp, _Ap>::mask_type& __k,
const simd<_Tp, _Ap>& __value)
3730 {
return {__k, __value}; }
3732template <
typename _Tp,
typename _Ap>
3733 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3734 where_expression<simd_mask<_Tp, _Ap>, simd_mask<_Tp, _Ap>>
3735 where(
const remove_const_t<simd_mask<_Tp, _Ap>>& __k, simd_mask<_Tp, _Ap>& __value)
3736 {
return {__k, __value}; }
3738template <
typename _Tp,
typename _Ap>
3739 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3740 const_where_expression<simd_mask<_Tp, _Ap>, simd_mask<_Tp, _Ap>>
3741 where(
const remove_const_t<simd_mask<_Tp, _Ap>>& __k,
const simd_mask<_Tp, _Ap>& __value)
3742 {
return {__k, __value}; }
3744template <
typename _Tp>
3745 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR where_expression<bool, _Tp>
3746 where(_ExactBool __k, _Tp& __value)
3747 {
return {__k, __value}; }
3749template <
typename _Tp>
3750 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR const_where_expression<bool, _Tp>
3751 where(_ExactBool __k,
const _Tp& __value)
3752 {
return {__k, __value}; }
3754template <
typename _Tp,
typename _Ap>
3755 _GLIBCXX_SIMD_CONSTEXPR
void
3756 where(
bool __k, simd<_Tp, _Ap>& __value) =
delete;
3758template <
typename _Tp,
typename _Ap>
3759 _GLIBCXX_SIMD_CONSTEXPR
void
3760 where(
bool __k,
const simd<_Tp, _Ap>& __value) =
delete;
3763namespace __proposed {
3764template <
size_t _Np>
3767 const bitset<_Np> __bits;
3770 where_range(bitset<_Np> __b) : __bits(__b) {}
3777 _GLIBCXX_SIMD_INTRINSIC
void
3779 { __bit = __builtin_ctzl(__mask); }
3781 _GLIBCXX_SIMD_INTRINSIC
void
3785 __mask &= (__mask - 1);
3790 iterator(
decltype(__mask) __m) : __mask(__m) { __next_bit(); }
3791 iterator(
const iterator&) =
default;
3792 iterator(iterator&&) =
default;
3794 _GLIBCXX_SIMD_ALWAYS_INLINE
size_t
3798 _GLIBCXX_SIMD_ALWAYS_INLINE
size_t
3802 _GLIBCXX_SIMD_ALWAYS_INLINE iterator&
3810 _GLIBCXX_SIMD_ALWAYS_INLINE iterator
3813 iterator __tmp = *
this;
3819 _GLIBCXX_SIMD_ALWAYS_INLINE
bool
3820 operator==(
const iterator& __rhs)
const
3821 {
return __mask == __rhs.__mask; }
3823 _GLIBCXX_SIMD_ALWAYS_INLINE
bool
3824 operator!=(
const iterator& __rhs)
const
3825 {
return __mask != __rhs.__mask; }
3830 {
return __bits.to_ullong(); }
3837template <
typename _Tp,
typename _Ap>
3838 where_range<simd_size_v<_Tp, _Ap>>
3839 where(
const simd_mask<_Tp, _Ap>& __k)
3840 {
return __k.__to_bitset(); }
3846template <
typename _Tp,
typename _Abi,
typename _BinaryOperation = plus<>>
3847 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3848 reduce(
const simd<_Tp, _Abi>& __v, _BinaryOperation __binary_op = _BinaryOperation())
3849 {
return _Abi::_SimdImpl::_S_reduce(__v, __binary_op); }
3851template <
typename _M,
typename _V,
typename _BinaryOperation = plus<>>
3852 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3853 reduce(
const const_where_expression<_M, _V>& __x,
3854 typename _V::value_type __identity_element, _BinaryOperation __binary_op)
3856 if (__builtin_expect(none_of(__get_mask(__x)),
false))
3857 return __identity_element;
3859 _V __tmp = __identity_element;
3860 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3861 __data(__get_lvalue(__x)));
3862 return reduce(__tmp, __binary_op);
3865template <
typename _M,
typename _V>
3866 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3867 reduce(
const const_where_expression<_M, _V>& __x, plus<> __binary_op = {})
3868 {
return reduce(__x, 0, __binary_op); }
3870template <
typename _M,
typename _V>
3871 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3872 reduce(
const const_where_expression<_M, _V>& __x, multiplies<> __binary_op)
3873 {
return reduce(__x, 1, __binary_op); }
3875template <
typename _M,
typename _V>
3876 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3877 reduce(
const const_where_expression<_M, _V>& __x, bit_and<> __binary_op)
3878 {
return reduce(__x, ~
typename _V::value_type(), __binary_op); }
3880template <
typename _M,
typename _V>
3881 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3882 reduce(
const const_where_expression<_M, _V>& __x, bit_or<> __binary_op)
3883 {
return reduce(__x, 0, __binary_op); }
3885template <
typename _M,
typename _V>
3886 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3887 reduce(
const const_where_expression<_M, _V>& __x, bit_xor<> __binary_op)
3888 {
return reduce(__x, 0, __binary_op); }
3890template <
typename _Tp,
typename _Abi>
3891 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3892 hmin(
const simd<_Tp, _Abi>& __v)
noexcept
3893 {
return _Abi::_SimdImpl::_S_reduce(__v, __detail::_Minimum()); }
3895template <
typename _Tp,
typename _Abi>
3896 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3897 hmax(
const simd<_Tp, _Abi>& __v)
noexcept
3898 {
return _Abi::_SimdImpl::_S_reduce(__v, __detail::_Maximum()); }
3900template <
typename _M,
typename _V>
3901 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3902 typename _V::value_type
3903 hmin(
const const_where_expression<_M, _V>& __x)
noexcept
3905 using _Tp =
typename _V::value_type;
3906 constexpr _Tp __id_elem =
3907#ifdef __FINITE_MATH_ONLY__
3908 __finite_max_v<_Tp>;
3910 __value_or<__infinity, _Tp>(__finite_max_v<_Tp>);
3912 _V __tmp = __id_elem;
3913 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3914 __data(__get_lvalue(__x)));
3915 return _V::abi_type::_SimdImpl::_S_reduce(__tmp, __detail::_Minimum());
3918template <
typename _M,
typename _V>
3919 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3920 typename _V::value_type
3921 hmax(
const const_where_expression<_M, _V>& __x)
noexcept
3923 using _Tp =
typename _V::value_type;
3924 constexpr _Tp __id_elem =
3925#ifdef __FINITE_MATH_ONLY__
3926 __finite_min_v<_Tp>;
3929 if constexpr (__value_exists_v<__infinity, _Tp>)
3930 return -__infinity_v<_Tp>;
3932 return __finite_min_v<_Tp>;
3935 _V __tmp = __id_elem;
3936 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3937 __data(__get_lvalue(__x)));
3938 return _V::abi_type::_SimdImpl::_S_reduce(__tmp, __detail::_Maximum());
3943template <
typename _Tp,
typename _Ap>
3944 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3945 min(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3946 {
return {__private_init, _Ap::_SimdImpl::_S_min(__data(__a), __data(__b))}; }
3948template <
typename _Tp,
typename _Ap>
3949 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3950 max(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3951 {
return {__private_init, _Ap::_SimdImpl::_S_max(__data(__a), __data(__b))}; }
3953template <
typename _Tp,
typename _Ap>
3954 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3955 pair<simd<_Tp, _Ap>, simd<_Tp, _Ap>>
3956 minmax(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3958 const auto pair_of_members
3959 = _Ap::_SimdImpl::_S_minmax(__data(__a), __data(__b));
3960 return {simd<_Tp, _Ap>(__private_init, pair_of_members.first),
3961 simd<_Tp, _Ap>(__private_init, pair_of_members.second)};
3964template <
typename _Tp,
typename _Ap>
3965 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3966 clamp(
const simd<_Tp, _Ap>& __v,
const simd<_Tp, _Ap>& __lo,
const simd<_Tp, _Ap>& __hi)
3968 using _Impl =
typename _Ap::_SimdImpl;
3969 return {__private_init,
3970 _Impl::_S_min(__data(__hi),
3971 _Impl::_S_max(__data(__lo), __data(__v)))};
3976template <
size_t... _Sizes,
typename _Tp,
typename _Ap,
3977 typename =
enable_if_t<((_Sizes + ...) == simd<_Tp, _Ap>::size())>>
3978 inline tuple<simd<_Tp, simd_abi::deduce_t<_Tp, _Sizes>>...>
3979 split(
const simd<_Tp, _Ap>&);
3982template <
int _Index,
int _Total,
int _Combine = 1,
typename _Tp,
size_t _Np>
3983 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_CONST
constexpr
3984 conditional_t<_Np == _Total and _Combine == 1, _Tp, _SimdWrapper<_Tp, _Np / _Total * _Combine>>
3985 __extract_part(
const _SimdWrapper<_Tp, _Np> __x);
3987template <
int _Index,
int _Parts,
int _Combine = 1,
typename _Tp,
typename _A0,
typename... _As>
3988 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
3989 __extract_part(
const _SimdTuple<_Tp, _A0, _As...>& __x);
3993template <
size_t _V0,
size_t... _Values>
3996 template <
size_t _I>
3997 static constexpr size_t
3998 _S_at(_SizeConstant<_I> = {})
4000 if constexpr (_I == 0)
4003 return _SizeList<_Values...>::template _S_at<_I - 1>();
4006 template <
size_t _I>
4007 static constexpr auto
4008 _S_before(_SizeConstant<_I> = {})
4010 if constexpr (_I == 0)
4011 return _SizeConstant<0>();
4013 return _SizeConstant<
4014 _V0 + _SizeList<_Values...>::template _S_before<_I - 1>()>();
4017 template <
size_t _Np>
4018 static constexpr auto
4019 _S_pop_front(_SizeConstant<_Np> = {})
4021 if constexpr (_Np == 0)
4024 return _SizeList<_Values...>::template _S_pop_front<_Np - 1>();
4030template <
typename _Tp,
size_t _Np>
4031 _GLIBCXX_SIMD_INTRINSIC _SimdWrapper<_Tp, _Np / 2>
4032 __extract_center(_SimdWrapper<_Tp, _Np> __x)
4034 static_assert(_Np >= 4);
4035 static_assert(_Np % 4 == 0);
4036#if _GLIBCXX_SIMD_X86INTRIN
4037 if constexpr (__have_avx512f &&
sizeof(_Tp) * _Np == 64)
4039 const auto __intrin = __to_intrin(__x);
4040 if constexpr (is_integral_v<_Tp>)
4041 return __vector_bitcast<_Tp>(_mm512_castsi512_si256(
4042 _mm512_shuffle_i32x4(__intrin, __intrin,
4043 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
4044 else if constexpr (
sizeof(_Tp) == 4)
4045 return __vector_bitcast<_Tp>(_mm512_castps512_ps256(
4046 _mm512_shuffle_f32x4(__intrin, __intrin,
4047 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
4048 else if constexpr (
sizeof(_Tp) == 8)
4049 return __vector_bitcast<_Tp>(_mm512_castpd512_pd256(
4050 _mm512_shuffle_f64x2(__intrin, __intrin,
4051 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
4053 __assert_unreachable<_Tp>();
4055 else if constexpr (
sizeof(_Tp) * _Np == 32 && is_floating_point_v<_Tp>)
4056 return __vector_bitcast<_Tp>(
4057 _mm_shuffle_pd(__lo128(__vector_bitcast<double>(__x)),
4058 __hi128(__vector_bitcast<double>(__x)), 1));
4059 else if constexpr (
sizeof(__x) == 32 &&
sizeof(_Tp) * _Np <= 32)
4060 return __vector_bitcast<_Tp>(
4061 _mm_alignr_epi8(__hi128(__vector_bitcast<_LLong>(__x)),
4062 __lo128(__vector_bitcast<_LLong>(__x)),
4063 sizeof(_Tp) * _Np / 4));
4067 __vector_type_t<_Tp, _Np / 2> __r;
4068 __builtin_memcpy(&__r,
4069 reinterpret_cast<const char*
>(&__x)
4070 +
sizeof(_Tp) * _Np / 4,
4071 sizeof(_Tp) * _Np / 2);
4076template <
typename _Tp,
typename _A0,
typename... _As>
4077 _GLIBCXX_SIMD_INTRINSIC
4078 _SimdWrapper<_Tp, _SimdTuple<_Tp, _A0, _As...>::_S_size() / 2>
4079 __extract_center(
const _SimdTuple<_Tp, _A0, _As...>& __x)
4081 if constexpr (
sizeof...(_As) == 0)
4082 return __extract_center(__x.first);
4084 return __extract_part<1, 4, 2>(__x);
4089template <
size_t... _Sizes,
typename _Tp,
typename... _As>
4091 __split_wrapper(_SizeList<_Sizes...>,
const _SimdTuple<_Tp, _As...>& __x)
4093 return split<_Sizes...>(
4094 fixed_size_simd<_Tp, _SimdTuple<_Tp, _As...>::_S_size()>(__private_init,
4101template <
typename _V,
typename _Ap,
4102 size_t _Parts = simd_size_v<typename _V::value_type, _Ap> / _V::size()>
4103 enable_if_t<simd_size_v<typename _V::value_type, _Ap> == _Parts * _V::size()
4104 && is_simd_v<_V>, array<_V, _Parts>>
4105 split(
const simd<typename _V::value_type, _Ap>& __x)
4107 using _Tp =
typename _V::value_type;
4108 if constexpr (_Parts == 1)
4110 return {simd_cast<_V>(__x)};
4112 else if (__x._M_is_constprop())
4114 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
4115 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4116 return _V([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
4117 {
return __x[__i * _V::size() + __j]; });
4121 __is_fixed_size_abi_v<_Ap>
4122 && (is_same_v<typename _V::abi_type, simd_abi::scalar>
4123 || (__is_fixed_size_abi_v<typename _V::abi_type>
4124 &&
sizeof(_V) ==
sizeof(_Tp) * _V::size()
4128#ifdef _GLIBCXX_SIMD_USE_ALIASING_LOADS
4129 const __may_alias<_Tp>*
const __element_ptr
4130 =
reinterpret_cast<const __may_alias<_Tp>*
>(&__data(__x));
4131 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
4132 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
4133 {
return _V(__element_ptr + __i * _V::size(), vector_aligned); });
4135 const auto& __xx = __data(__x);
4136 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
4137 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4138 [[maybe_unused]]
constexpr size_t __offset
4139 =
decltype(__i)::value * _V::size();
4140 return _V([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4141 constexpr _SizeConstant<__j + __offset> __k;
4147 else if constexpr (is_same_v<typename _V::abi_type, simd_abi::scalar>)
4150 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
4151 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
4155 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
4156 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4157 if constexpr (__is_fixed_size_abi_v<typename _V::abi_type>)
4158 return _V([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4159 return __x[__i * _V::size() + __j];
4162 return _V(__private_init,
4163 __extract_part<
decltype(__i)::value, _Parts>(__data(__x)));
4170template <
typename _V,
typename _Ap,
4171 size_t _Parts = simd_size_v<typename _V::simd_type::value_type, _Ap> / _V::size()>
4172 enable_if_t<is_simd_mask_v<_V> && simd_size_v<
typename
4173 _V::simd_type::value_type, _Ap> == _Parts * _V::size(), array<_V, _Parts>>
4174 split(
const simd_mask<typename _V::simd_type::value_type, _Ap>& __x)
4176 if constexpr (is_same_v<_Ap, typename _V::abi_type>)
4178 else if constexpr (_Parts == 1)
4179 return {__proposed::static_simd_cast<_V>(__x)};
4180 else if constexpr (_Parts == 2 && __is_sse_abi<typename _V::abi_type>()
4181 && __is_avx_abi<_Ap>())
4182 return {_V(__private_init, __lo128(__data(__x))),
4183 _V(__private_init, __hi128(__data(__x)))};
4184 else if constexpr (_V::size() <= __CHAR_BIT__ *
sizeof(_ULLong))
4186 const bitset __bits = __x.__to_bitset();
4187 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
4188 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4189 constexpr size_t __offset = __i * _V::size();
4190 return _V(__bitset_init, (__bits >> __offset).to_ullong());
4195 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
4196 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4197 constexpr size_t __offset = __i * _V::size();
4198 return _V(__private_init,
4199 [&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4200 return __x[__j + __offset];
4208template <
size_t... _Sizes,
typename _Tp,
typename _Ap,
typename>
4209 _GLIBCXX_SIMD_ALWAYS_INLINE
4210 tuple<simd<_Tp, simd_abi::deduce_t<_Tp, _Sizes>>...>
4211 split(
const simd<_Tp, _Ap>& __x)
4213 using _SL = _SizeList<_Sizes...>;
4214 using _Tuple = tuple<__deduced_simd<_Tp, _Sizes>...>;
4215 constexpr size_t _Np = simd_size_v<_Tp, _Ap>;
4216 constexpr size_t _N0 = _SL::template _S_at<0>();
4217 using _V = __deduced_simd<_Tp, _N0>;
4219 if (__x._M_is_constprop())
4220 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>(
4221 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4222 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4223 constexpr size_t __offset = _SL::_S_before(__i);
4224 return _Vi([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4225 return __x[__offset + __j];
4228 else if constexpr (_Np == _N0)
4230 static_assert(
sizeof...(_Sizes) == 1);
4231 return {simd_cast<_V>(__x)};
4234 (__is_fixed_size_abi_v<
4235 _Ap> && __fixed_size_storage_t<_Tp, _Np>::_S_first_size == _N0)
4238 !__is_fixed_size_abi_v<typename _V::abi_type>,
4239 "How can <_Tp, _Np> be __a single _SimdTuple entry but __a "
4245 __split_wrapper(_SL::template _S_pop_front<1>(),
4246 __data(__x).second));
4248 else if constexpr ((!__is_fixed_size_abi_v<simd_abi::deduce_t<_Tp, _Sizes>> && ...))
4250 constexpr array<size_t,
sizeof...(_Sizes)> __size = {_Sizes...};
4251 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>(
4252 [&](
auto __i)
constexpr {
4253 constexpr size_t __offset = [&]() {
4255 for (
unsigned __j = 0; __j < __i; ++__j)
4259 return __deduced_simd<_Tp, __size[__i]>(
4261 __extract_part<__offset, _Np, __size[__i]>(__data(__x)));
4264#ifdef _GLIBCXX_SIMD_USE_ALIASING_LOADS
4265 const __may_alias<_Tp>*
const __element_ptr
4266 =
reinterpret_cast<const __may_alias<_Tp>*
>(&__x);
4267 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>(
4268 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4269 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4270 constexpr size_t __offset = _SL::_S_before(__i);
4271 constexpr size_t __base_align =
alignof(simd<_Tp, _Ap>);
4272 constexpr size_t __a
4273 = __base_align - ((__offset *
sizeof(_Tp)) % __base_align);
4274 constexpr size_t __b = ((__a - 1) & __a) ^ __a;
4275 constexpr size_t __alignment = __b == 0 ? __a : __b;
4276 return _Vi(__element_ptr + __offset, overaligned<__alignment>);
4279 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>(
4280 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4281 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4282 const auto& __xx = __data(__x);
4283 using _Offset =
decltype(_SL::_S_before(__i));
4284 return _Vi([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4285 constexpr _SizeConstant<_Offset::value + __j> __k;
4295template <
size_t _I,
typename _Tp,
typename _Ap,
typename... _As>
4296 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp
4297 __subscript_in_pack(
const simd<_Tp, _Ap>& __x,
const simd<_Tp, _As>&... __xs)
4299 if constexpr (_I < simd_size_v<_Tp, _Ap>)
4302 return __subscript_in_pack<_I - simd_size_v<_Tp, _Ap>>(__xs...);
4307template <
typename _Tp,
typename _A0,
typename... _As>
4308 _GLIBCXX_SIMD_INTRINSIC
void
4309 __store_pack_of_simd(
char* __mem,
const simd<_Tp, _A0>& __x0,
const simd<_Tp, _As>&... __xs)
4311 constexpr size_t __n_bytes =
sizeof(_Tp) * simd_size_v<_Tp, _A0>;
4312 __builtin_memcpy(__mem, &__data(__x0), __n_bytes);
4313 if constexpr (
sizeof...(__xs) > 0)
4314 __store_pack_of_simd(__mem + __n_bytes, __xs...);
4319template <
typename _Tp,
typename... _As,
typename = __detail::__odr_helper>
4320 inline _GLIBCXX_SIMD_CONSTEXPR
4321 simd<_Tp, simd_abi::deduce_t<_Tp, (simd_size_v<_Tp, _As> + ...)>>
4322 concat(
const simd<_Tp, _As>&... __xs)
4324 constexpr int _Np = (simd_size_v<_Tp, _As> + ...);
4325 using _Abi = simd_abi::deduce_t<_Tp, _Np>;
4326 using _Rp = simd<_Tp, _Abi>;
4327 using _RW =
typename _SimdTraits<_Tp, _Abi>::_SimdMember;
4328 if constexpr (
sizeof...(__xs) == 1)
4329 return simd_cast<_Rp>(__xs...);
4330 else if ((... && __xs._M_is_constprop()))
4331 return _Rp([&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
4332 {
return __subscript_in_pack<__i>(__xs...); });
4333 else if constexpr (__is_simd_wrapper_v<_RW> and
sizeof...(__xs) == 2)
4335 return {__private_init,
4338 constexpr int __sizes[2] = {int(simd_size_v<_Tp, _As>)...};
4339 constexpr int __vsizes[2]
4340 = {int(
sizeof(__as_vector(__xs)) /
sizeof(_Tp))...};
4341 constexpr int __padding0 = __vsizes[0] - __sizes[0];
4342 return __i >= _Np ? -1 : __i < __sizes[0] ? __i : __i + __padding0;
4345 else if constexpr (__is_simd_wrapper_v<_RW> and
sizeof...(__xs) == 3)
4346 return [](
const auto& __x0,
const auto& __x1,
const auto& __x2)
4347 _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4348 return concat(concat(__x0, __x1), __x2);
4350 else if constexpr (__is_simd_wrapper_v<_RW> and
sizeof...(__xs) > 3)
4351 return [](
const auto& __x0,
const auto& __x1,
const auto&... __rest)
4352 _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4353 return concat(concat(__x0, __x1), concat(__rest...));
4358 __store_pack_of_simd(
reinterpret_cast<char*
>(&__data(__r)), __xs...);
4365template <
typename _Tp,
typename _Abi,
size_t _Np>
4366 _GLIBCXX_SIMD_ALWAYS_INLINE
4367 _GLIBCXX_SIMD_CONSTEXPR __deduced_simd<_Tp, simd_size_v<_Tp, _Abi> * _Np>
4368 concat(
const array<simd<_Tp, _Abi>, _Np>& __x)
4370 return __call_with_subscripts<_Np>(
4371 __x, [](
const auto&... __xs) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4372 return concat(__xs...);
4380template <
typename _Up,
typename _Accessor = _Up,
4381 typename _ValueType =
typename _Up::value_type>
4382 class _SmartReference
4388 _GLIBCXX_SIMD_INTRINSIC
constexpr _ValueType
4389 _M_read() const noexcept
4391 if constexpr (is_arithmetic_v<_Up>)
4394 return _M_obj[_M_index];
4397 template <
typename _Tp>
4398 _GLIBCXX_SIMD_INTRINSIC
constexpr void
4399 _M_write(_Tp&& __x)
const
4400 { _Accessor::_S_set(_M_obj, _M_index,
static_cast<_Tp&&
>(__x)); }
4403 _GLIBCXX_SIMD_INTRINSIC
constexpr
4404 _SmartReference(_Up& __o,
int __i) noexcept
4405 : _M_index(__i), _M_obj(__o) {}
4407 using value_type = _ValueType;
4409 _GLIBCXX_SIMD_INTRINSIC
4410 _SmartReference(
const _SmartReference&) =
delete;
4412 _GLIBCXX_SIMD_INTRINSIC
constexpr
4413 operator value_type() const noexcept
4414 {
return _M_read(); }
4416 template <
typename _Tp,
typename = _ValuePreservingOrInt<__remove_cvref_t<_Tp>, value_type>>
4417 _GLIBCXX_SIMD_INTRINSIC
constexpr _SmartReference
4418 operator=(_Tp&& __x) &&
4420 _M_write(
static_cast<_Tp&&
>(__x));
4421 return {_M_obj, _M_index};
4424#define _GLIBCXX_SIMD_OP_(__op) \
4425 template <typename _Tp, \
4426 typename _TT = decltype(declval<value_type>() __op declval<_Tp>()), \
4427 typename = _ValuePreservingOrInt<__remove_cvref_t<_Tp>, _TT>, \
4428 typename = _ValuePreservingOrInt<_TT, value_type>> \
4429 _GLIBCXX_SIMD_INTRINSIC constexpr _SmartReference \
4430 operator __op##=(_Tp&& __x) && \
4432 const value_type& __lhs = _M_read(); \
4433 _M_write(__lhs __op __x); \
4434 return {_M_obj, _M_index}; \
4436 _GLIBCXX_SIMD_ALL_ARITHMETICS(_GLIBCXX_SIMD_OP_);
4437 _GLIBCXX_SIMD_ALL_SHIFTS(_GLIBCXX_SIMD_OP_);
4438 _GLIBCXX_SIMD_ALL_BINARY(_GLIBCXX_SIMD_OP_);
4439#undef _GLIBCXX_SIMD_OP_
4441 template <
typename _Tp = void,
4442 typename =
decltype(++declval<conditional_t<true, value_type, _Tp>&>())>
4443 _GLIBCXX_SIMD_INTRINSIC
constexpr _SmartReference
4446 value_type __x = _M_read();
4448 return {_M_obj, _M_index};
4451 template <
typename _Tp = void,
4452 typename =
decltype(declval<conditional_t<true, value_type, _Tp>&>()++)>
4453 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type
4456 const value_type __r = _M_read();
4457 value_type __x = __r;
4462 template <
typename _Tp = void,
4463 typename =
decltype(--declval<conditional_t<true, value_type, _Tp>&>())>
4464 _GLIBCXX_SIMD_INTRINSIC
constexpr _SmartReference
4467 value_type __x = _M_read();
4469 return {_M_obj, _M_index};
4472 template <
typename _Tp = void,
4473 typename =
decltype(declval<conditional_t<true, value_type, _Tp>&>()--)>
4474 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type
4477 const value_type __r = _M_read();
4478 value_type __x = __r;
4483 _GLIBCXX_SIMD_INTRINSIC
friend void
4484 swap(_SmartReference&& __a, _SmartReference&& __b)
noexcept(
4486 is_nothrow_constructible<value_type, _SmartReference&&>,
4487 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4489 value_type __tmp =
static_cast<_SmartReference&&
>(__a);
4490 static_cast<_SmartReference&&
>(__a) =
static_cast<value_type
>(__b);
4491 static_cast<_SmartReference&&
>(__b) =
std::move(__tmp);
4494 _GLIBCXX_SIMD_INTRINSIC
friend void
4495 swap(value_type& __a, _SmartReference&& __b)
noexcept(
4497 is_nothrow_constructible<value_type, value_type&&>,
4498 is_nothrow_assignable<value_type&, value_type&&>,
4499 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4502 __a =
static_cast<value_type
>(__b);
4503 static_cast<_SmartReference&&
>(__b) =
std::move(__tmp);
4506 _GLIBCXX_SIMD_INTRINSIC
friend void
4507 swap(_SmartReference&& __a, value_type& __b)
noexcept(
4509 is_nothrow_constructible<value_type, _SmartReference&&>,
4510 is_nothrow_assignable<value_type&, value_type&&>,
4511 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4513 value_type __tmp(__a);
4514 static_cast<_SmartReference&&
>(__a) =
std::move(__b);
4521template <
int _Bytes>
4522 struct __scalar_abi_wrapper
4524 template <
typename _Tp>
static constexpr size_t _S_full_size = 1;
4525 template <
typename _Tp>
static constexpr size_t _S_size = 1;
4526 template <
typename _Tp>
static constexpr size_t _S_is_partial =
false;
4528 template <
typename _Tp,
typename _Abi = simd_abi::scalar>
4529 static constexpr bool _S_is_valid_v
4530 = _Abi::template _IsValid<_Tp>::value &&
sizeof(_Tp) == _Bytes;
4535template <
typename _Tp>
4536 struct __decay_abi {
using type = _Tp; };
4538template <
int _Bytes>
4539 struct __decay_abi<__scalar_abi_wrapper<_Bytes>>
4540 {
using type = simd_abi::scalar; };
4548template <
template <
int>
class _Abi,
int _Bytes,
typename _Tp>
4549 struct __find_next_valid_abi
4551 static constexpr auto
4555 using _NextAbi = _Abi<_NextBytes>;
4556 if constexpr (_NextBytes <
sizeof(_Tp) * 2)
4557 return _Abi<_Bytes>();
4558 else if constexpr (_NextAbi::template _S_is_partial<_Tp> ==
false
4559 && _NextAbi::template _S_is_valid_v<_Tp>)
4562 return __find_next_valid_abi<_Abi, _NextBytes, _Tp>::_S_choose();
4565 using type =
decltype(_S_choose());
4568template <
int _Bytes,
typename _Tp>
4569 struct __find_next_valid_abi<__scalar_abi_wrapper, _Bytes, _Tp>
4570 {
using type = simd_abi::scalar; };
4573template <
template <
int>
class...>
4576 template <
typename,
int>
static constexpr bool _S_has_valid_abi =
false;
4577 template <
typename,
int>
using _FirstValidAbi = void;
4578 template <
typename,
int>
using _BestAbi = void;
4581template <
template <
int>
class _A0,
template <
int>
class... _Rest>
4582 struct _AbiList<_A0, _Rest...>
4584 template <
typename _Tp,
int _Np>
4585 static constexpr bool _S_has_valid_abi
4586 = _A0<
sizeof(_Tp) * _Np>::template _S_is_valid_v<
4587 _Tp> || _AbiList<_Rest...>::template _S_has_valid_abi<_Tp, _Np>;
4589 template <
typename _Tp,
int _Np>
4591 _A0<
sizeof(_Tp) * _Np>::template _S_is_valid_v<_Tp>,
4592 typename __decay_abi<_A0<
sizeof(_Tp) * _Np>>::type,
4593 typename _AbiList<_Rest...>::template _FirstValidAbi<_Tp, _Np>>;
4595 template <
typename _Tp,
int _Np>
4596 static constexpr auto
4597 _S_determine_best_abi()
4599 static_assert(_Np >= 1);
4600 constexpr int _Bytes =
sizeof(_Tp) * _Np;
4601 if constexpr (_Np == 1)
4602 return __make_dependent_t<_Tp, simd_abi::scalar>{};
4605 constexpr int __fullsize = _A0<_Bytes>::template _S_full_size<_Tp>;
4610 if constexpr (_A0<_Bytes>::template _S_is_valid_v<
4611 _Tp> && __fullsize / 2 < _Np)
4612 return typename __decay_abi<_A0<_Bytes>>::type{};
4616 typename __find_next_valid_abi<_A0, _Bytes, _Tp>::type;
4617 if constexpr (_Bp::template _S_is_valid_v<
4618 _Tp> && _Bp::template _S_size<_Tp> <= _Np)
4622 typename _AbiList<_Rest...>::template _BestAbi<_Tp, _Np>{};
4627 template <
typename _Tp,
int _Np>
4628 using _BestAbi =
decltype(_S_determine_best_abi<_Tp, _Np>());
4636using _AllNativeAbis = _AbiList<simd_abi::_VecBltnBtmsk, simd_abi::_VecBuiltin,
4637 __scalar_abi_wrapper>;
4640template <
typename _Tp,
typename _Abi>
4641 struct _SimdTraits<_Tp, _Abi,
void_t<typename _Abi::template _IsValid<_Tp>>>
4642 : _Abi::template __traits<_Tp> {};
4646template <
typename _Tp,
size_t _Np>
4647 struct __deduce_impl<
4648 _Tp, _Np,
enable_if_t<_AllNativeAbis::template _S_has_valid_abi<_Tp, _Np>>>
4649 {
using type = _AllNativeAbis::_FirstValidAbi<_Tp, _Np>; };
4652template <
typename _Tp,
size_t _Np,
typename =
void>
4653 struct __deduce_fixed_size_fallback {};
4655template <
typename _Tp,
size_t _Np>
4656 struct __deduce_fixed_size_fallback<_Tp, _Np,
4657 enable_if_t<simd_abi::fixed_size<_Np>::template _S_is_valid_v<_Tp>>>
4658 {
using type = simd_abi::fixed_size<_Np>; };
4660template <
typename _Tp,
size_t _Np,
typename>
4661 struct __deduce_impl :
public __deduce_fixed_size_fallback<_Tp, _Np> {};
4667template <
typename _Tp,
typename _Abi>
4668 class simd_mask :
public _SimdTraits<_Tp, _Abi>::_MaskBase
4671 using _Traits = _SimdTraits<_Tp, _Abi>;
4672 using _MemberType =
typename _Traits::_MaskMember;
4678 using _Ip = __int_for_sizeof_t<_Tp>;
4679 static constexpr _Ip* _S_type_tag =
nullptr;
4681 friend typename _Traits::_MaskBase;
4682 friend class simd<_Tp, _Abi>;
4683 friend typename _Traits::_SimdImpl;
4686 using _Impl =
typename _Traits::_MaskImpl;
4691 using value_type = bool;
4692 using reference = _SmartReference<_MemberType, _Impl, value_type>;
4693 using simd_type = simd<_Tp, _Abi>;
4694 using abi_type = _Abi;
4697 static constexpr size_t size()
4698 {
return __size_or_zero_v<_Tp, _Abi>; }
4702 simd_mask() =
default;
4703 simd_mask(
const simd_mask&) =
default;
4704 simd_mask(simd_mask&&) =
default;
4705 simd_mask& operator=(
const simd_mask&) =
default;
4706 simd_mask& operator=(simd_mask&&) =
default;
4710 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
explicit
4711 simd_mask(
typename _Traits::_MaskCastType __init)
4712 : _M_data{__init} {}
4721 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
static simd_mask
4722 __from_bitset(bitset<size()> bs)
4723 {
return {__bitset_init, bs}; }
4725 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR bitset<size()>
4727 {
return _Impl::_S_to_bits(_M_data)._M_to_bitset(); }
4731 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
4732 simd_mask(value_type __x)
4733 : _M_data(_Impl::template _S_broadcast<_Ip>(__x)) {}
4737 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4739 template <
typename _Up,
typename _A2,
4740 typename = enable_if_t<simd_size_v<_Up, _A2> == size()>>
4741 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit(
sizeof(_MemberType)
4742 !=
sizeof(
typename _SimdTraits<_Up, _A2>::_MaskMember))
4743 simd_mask(
const simd_mask<_Up, _A2>& __x)
4744 : simd_mask(__proposed::static_simd_cast<simd_mask>(__x)) {}
4747 template <
typename _Up,
typename =
enable_if_t<conjunction<
4748 is_same<abi_type, simd_abi::fixed_size<size()>>,
4749 is_same<_Up, _Up>>::value>>
4750 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
4751 simd_mask(
const simd_mask<_Up, simd_abi::fixed_size<size()>>& __x)
4752 : _M_data(_Impl::_S_from_bitmask(__data(__x), _S_type_tag)) {}
4757 template <
typename _Flags>
4758 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
4759 simd_mask(
const value_type* __mem, _IsSimdFlagType<_Flags>)
4760 : _M_data(_Impl::template _S_load<_Ip>(_Flags::template _S_apply<simd_mask>(__mem))) {}
4762 template <
typename _Flags>
4763 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
4764 simd_mask(
const value_type* __mem, simd_mask __k, _IsSimdFlagType<_Flags>)
4767 _M_data = _Impl::_S_masked_load(_M_data, __k._M_data,
4768 _Flags::template _S_apply<simd_mask>(__mem));
4773 template <
typename _Flags>
4774 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
void
4775 copy_from(
const value_type* __mem, _IsSimdFlagType<_Flags>)
4776 { _M_data = _Impl::template _S_load<_Ip>(_Flags::template _S_apply<simd_mask>(__mem)); }
4780 template <
typename _Flags>
4781 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
void
4782 copy_to(value_type* __mem, _IsSimdFlagType<_Flags>)
const
4783 { _Impl::_S_store(_M_data, _Flags::template _S_apply<simd_mask>(__mem)); }
4787 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR reference
4788 operator[](
size_t __i)
4791 __invoke_ub(
"Subscript %d is out of range [0, %d]", __i, size() - 1);
4792 return {_M_data, int(__i)};
4795 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR value_type
4796 operator[](
size_t __i)
const
4799 __invoke_ub(
"Subscript %d is out of range [0, %d]", __i, size() - 1);
4800 if constexpr (__is_scalar_abi<_Abi>())
4803 return static_cast<bool>(_M_data[__i]);
4808 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd_mask
4810 {
return {__private_init, _Impl::_S_bit_not(_M_data)}; }
4814 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4816 template <
typename _Up,
typename _A2,
4817 typename = enable_if_t<is_convertible_v<simd_mask<_Up, _A2>, simd_mask>>>
4818 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4819 operator&&(
const simd_mask& __x,
const simd_mask<_Up, _A2>& __y)
4821 return {__private_init,
4822 _Impl::_S_logical_and(__x._M_data, simd_mask(__y)._M_data)};
4825 template <
typename _Up,
typename _A2,
4826 typename = enable_if_t<is_convertible_v<simd_mask<_Up, _A2>, simd_mask>>>
4827 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4828 operator||(
const simd_mask& __x,
const simd_mask<_Up, _A2>& __y)
4830 return {__private_init,
4831 _Impl::_S_logical_or(__x._M_data, simd_mask(__y)._M_data)};
4835 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4836 operator&&(
const simd_mask& __x,
const simd_mask& __y)
4837 {
return {__private_init, _Impl::_S_logical_and(__x._M_data, __y._M_data)}; }
4839 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4840 operator||(
const simd_mask& __x,
const simd_mask& __y)
4841 {
return {__private_init, _Impl::_S_logical_or(__x._M_data, __y._M_data)}; }
4843 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4844 operator&(
const simd_mask& __x,
const simd_mask& __y)
4845 {
return {__private_init, _Impl::_S_bit_and(__x._M_data, __y._M_data)}; }
4847 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4848 operator|(
const simd_mask& __x,
const simd_mask& __y)
4849 {
return {__private_init, _Impl::_S_bit_or(__x._M_data, __y._M_data)}; }
4851 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4852 operator^(
const simd_mask& __x,
const simd_mask& __y)
4853 {
return {__private_init, _Impl::_S_bit_xor(__x._M_data, __y._M_data)}; }
4855 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask&
4856 operator&=(simd_mask& __x,
const simd_mask& __y)
4858 __x._M_data = _Impl::_S_bit_and(__x._M_data, __y._M_data);
4862 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask&
4863 operator|=(simd_mask& __x,
const simd_mask& __y)
4865 __x._M_data = _Impl::_S_bit_or(__x._M_data, __y._M_data);
4869 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask&
4870 operator^=(simd_mask& __x,
const simd_mask& __y)
4872 __x._M_data = _Impl::_S_bit_xor(__x._M_data, __y._M_data);
4878 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4879 operator==(
const simd_mask& __x,
const simd_mask& __y)
4880 {
return !operator!=(__x, __y); }
4882 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4883 operator!=(
const simd_mask& __x,
const simd_mask& __y)
4884 {
return {__private_init, _Impl::_S_bit_xor(__x._M_data, __y._M_data)}; }
4888 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
4889 simd_mask(_PrivateInit,
typename _Traits::_MaskMember __init)
4890 : _M_data(__init) {}
4894 template <typename _Fp, typename = decltype(bool(declval<_Fp>()(size_t())))>
4895 _GLIBCXX_SIMD_INTRINSIC
constexpr
4896 simd_mask(_PrivateInit, _Fp&& __gen)
4899 __execute_n_times<size()>([&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4900 _Impl::_S_set(_M_data, __i, __gen(__i));
4906 _GLIBCXX_SIMD_INTRINSIC
constexpr
4907 simd_mask(_BitsetInit, bitset<size()> __init)
4908 : _M_data(_Impl::_S_from_bitmask(_SanitizedBitMask<size()>(__init), _S_type_tag))
4919 template <
typename _Up,
typename _A2,
4920 typename = enable_if_t<simd_size_v<_Up, _A2> == simd_size_v<_Tp, _Abi>>>
4921 _GLIBCXX_SIMD_ALWAYS_INLINE
4922 operator simd_mask<_Up, _A2>() &&
4924 using namespace std::experimental::__proposed;
4925 return static_simd_cast<simd_mask<_Up, _A2>>(_M_data);
4928 const simd_mask<_Tp, _Abi>& _M_data;
4931 _GLIBCXX_SIMD_INTRINSIC _CvtProxy
4937 #ifdef __GXX_CONDITIONAL_IS_OVERLOADABLE__
4938 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4939 operator?:(
const simd_mask& __k,
const simd_mask& __where_true,
4940 const simd_mask& __where_false)
4942 auto __ret = __where_false;
4943 _Impl::_S_masked_assign(__k._M_data, __ret._M_data, __where_true._M_data);
4947 template <
typename _U1,
typename _U2,
4948 typename _Rp = simd<common_type_t<_U1, _U2>, _Abi>,
4950 is_convertible<_U1, _Rp>, is_convertible<_U2, _Rp>,
4951 is_convertible<simd_mask, typename _Rp::mask_type>>>>
4952 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend _Rp
4953 operator?:(
const simd_mask& __k,
const _U1& __where_true,
4954 const _U2& __where_false)
4956 _Rp __ret = __where_false;
4957 _Rp::_Impl::_S_masked_assign(
4958 __data(
static_cast<typename _Rp::mask_type
>(__k)), __data(__ret),
4959 __data(
static_cast<_Rp
>(__where_true)));
4963 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4964 template <
typename _Kp,
typename _Ak,
typename _Up,
typename _Au,
4966 conjunction_v<is_convertible<simd_mask<_Kp, _Ak>, simd_mask>,
4967 is_convertible<simd_mask<_Up, _Au>, simd_mask>>>>
4968 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4969 operator?:(
const simd_mask<_Kp, _Ak>& __k,
const simd_mask& __where_true,
4970 const simd_mask<_Up, _Au>& __where_false)
4972 simd_mask __ret = __where_false;
4973 _Impl::_S_masked_assign(simd_mask(__k)._M_data, __ret._M_data,
4974 __where_true._M_data);
4982 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
4983 _M_is_constprop()
const
4985 if constexpr (__is_scalar_abi<_Abi>())
4986 return __builtin_constant_p(_M_data);
4988 return _M_data._M_is_constprop();
4994 friend const auto& __data<_Tp, abi_type>(
const simd_mask&);
4995 friend auto& __data<_Tp, abi_type>(simd_mask&);
4996 alignas(_Traits::_S_mask_align) _MemberType _M_data;
5003template <
typename _Tp,
typename _Ap>
5004 _GLIBCXX_SIMD_INTRINSIC
constexpr const auto&
5005 __data(
const simd_mask<_Tp, _Ap>& __x)
5006 {
return __x._M_data; }
5008template <
typename _Tp,
typename _Ap>
5009 _GLIBCXX_SIMD_INTRINSIC
constexpr auto&
5010 __data(simd_mask<_Tp, _Ap>& __x)
5011 {
return __x._M_data; }
5017template <
typename _Tp,
typename _Abi>
5018 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
5019 all_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
5021 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
5023 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
5029 return _Abi::_MaskImpl::_S_all_of(__k);
5032template <
typename _Tp,
typename _Abi>
5033 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
5034 any_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
5036 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
5038 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
5044 return _Abi::_MaskImpl::_S_any_of(__k);
5047template <
typename _Tp,
typename _Abi>
5048 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
5049 none_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
5051 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
5053 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
5059 return _Abi::_MaskImpl::_S_none_of(__k);
5062template <
typename _Tp,
typename _Abi>
5063 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
5064 some_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
5066 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
5068 for (
size_t __i = 1; __i < simd_size_v<_Tp, _Abi>; ++__i)
5069 if (__k[__i] != __k[__i - 1])
5074 return _Abi::_MaskImpl::_S_some_of(__k);
5077template <
typename _Tp,
typename _Abi>
5078 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
5079 popcount(
const simd_mask<_Tp, _Abi>& __k)
noexcept
5081 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
5083 const int __r = __call_with_subscripts<simd_size_v<_Tp, _Abi>>(
5084 __k, [](
auto... __elements) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
5085 return ((__elements != 0) + ...);
5087 if (__builtin_is_constant_evaluated() || __builtin_constant_p(__r))
5090 return _Abi::_MaskImpl::_S_popcount(__k);
5093template <
typename _Tp,
typename _Abi>
5094 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
5095 find_first_set(
const simd_mask<_Tp, _Abi>& __k)
5097 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
5099 constexpr size_t _Np = simd_size_v<_Tp, _Abi>;
5100 const size_t _Idx = __call_with_n_evaluations<_Np>(
5101 [](
auto... __indexes) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
5103 }, [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
5104 return __k[__i] ? +__i : _Np;
5107 __invoke_ub(
"find_first_set(empty mask) is UB");
5108 if (__builtin_constant_p(_Idx))
5111 return _Abi::_MaskImpl::_S_find_first_set(__k);
5114template <
typename _Tp,
typename _Abi>
5115 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
5116 find_last_set(
const simd_mask<_Tp, _Abi>& __k)
5118 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
5120 constexpr size_t _Np = simd_size_v<_Tp, _Abi>;
5121 const int _Idx = __call_with_n_evaluations<_Np>(
5122 [](
auto... __indexes) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
5124 }, [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
5125 return __k[__i] ? int(__i) : -1;
5128 __invoke_ub(
"find_first_set(empty mask) is UB");
5129 if (__builtin_constant_p(_Idx))
5132 return _Abi::_MaskImpl::_S_find_last_set(__k);
5135_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
5136all_of(_ExactBool __x)
noexcept
5139_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
5140any_of(_ExactBool __x)
noexcept
5143_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
5144none_of(_ExactBool __x)
noexcept
5147_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
5148some_of(_ExactBool)
noexcept
5151_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
5155_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
5156find_first_set(_ExactBool)
5159_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
5160find_last_set(_ExactBool)
5167template <
typename _V,
typename _Tp,
typename _Abi,
bool>
5168 class _SimdIntOperators {};
5170template <
typename _V,
typename _Tp,
typename _Abi>
5171 class _SimdIntOperators<_V, _Tp, _Abi, true>
5173 using _Impl =
typename _SimdTraits<_Tp, _Abi>::_SimdImpl;
5175 _GLIBCXX_SIMD_INTRINSIC
constexpr const _V&
5177 {
return *
static_cast<const _V*
>(
this); }
5179 template <
typename _Up>
5180 _GLIBCXX_SIMD_INTRINSIC
static _GLIBCXX_SIMD_CONSTEXPR _V
5181 _S_make_derived(_Up&& __d)
5182 {
return {__private_init,
static_cast<_Up&&
>(__d)}; }
5185 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5187 operator%=(_V& __lhs,
const _V& __x)
5188 {
return __lhs = __lhs % __x; }
5190 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5192 operator&=(_V& __lhs,
const _V& __x)
5193 {
return __lhs = __lhs & __x; }
5195 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5197 operator|=(_V& __lhs,
const _V& __x)
5198 {
return __lhs = __lhs | __x; }
5200 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5202 operator^=(_V& __lhs,
const _V& __x)
5203 {
return __lhs = __lhs ^ __x; }
5205 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5207 operator<<=(_V& __lhs,
const _V& __x)
5208 {
return __lhs = __lhs << __x; }
5210 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5212 operator>>=(_V& __lhs,
const _V& __x)
5213 {
return __lhs = __lhs >> __x; }
5215 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5217 operator<<=(_V& __lhs,
int __x)
5218 {
return __lhs = __lhs << __x; }
5220 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5222 operator>>=(_V& __lhs,
int __x)
5223 {
return __lhs = __lhs >> __x; }
5225 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5229 return _SimdIntOperators::_S_make_derived(
5230 _Impl::_S_modulus(__data(__x), __data(__y)));
5233 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5237 return _SimdIntOperators::_S_make_derived(
5238 _Impl::_S_bit_and(__data(__x), __data(__y)));
5241 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5245 return _SimdIntOperators::_S_make_derived(
5246 _Impl::_S_bit_or(__data(__x), __data(__y)));
5249 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5253 return _SimdIntOperators::_S_make_derived(
5254 _Impl::_S_bit_xor(__data(__x), __data(__y)));
5257 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5261 return _SimdIntOperators::_S_make_derived(
5262 _Impl::_S_bit_shift_left(__data(__x), __data(__y)));
5265 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5269 return _SimdIntOperators::_S_make_derived(
5270 _Impl::_S_bit_shift_right(__data(__x), __data(__y)));
5273 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5278 __invoke_ub(
"The behavior is undefined if the right operand of a "
5279 "shift operation is negative. [expr.shift]\nA shift by "
5282 if (
size_t(__y) >=
sizeof(declval<_Tp>() << __y) * __CHAR_BIT__)
5284 "The behavior is undefined if the right operand of a "
5285 "shift operation is greater than or equal to the width of the "
5286 "promoted left operand. [expr.shift]\nA shift by %d was requested",
5288 return _SimdIntOperators::_S_make_derived(
5289 _Impl::_S_bit_shift_left(__data(__x), __y));
5292 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5298 "The behavior is undefined if the right operand of a shift "
5299 "operation is negative. [expr.shift]\nA shift by %d was requested",
5301 if (
size_t(__y) >=
sizeof(declval<_Tp>() << __y) * __CHAR_BIT__)
5303 "The behavior is undefined if the right operand of a shift "
5304 "operation is greater than or equal to the width of the promoted "
5305 "left operand. [expr.shift]\nA shift by %d was requested",
5307 return _SimdIntOperators::_S_make_derived(
5308 _Impl::_S_bit_shift_right(__data(__x), __y));
5312 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5315 {
return {__private_init, _Impl::_S_complement(__derived()._M_data)}; }
5322template <
typename _Tp,
typename _Abi>
5323 class simd :
public _SimdIntOperators<
5324 simd<_Tp, _Abi>, _Tp, _Abi,
5325 conjunction<is_integral<_Tp>,
5326 typename _SimdTraits<_Tp, _Abi>::_IsValid>::value>,
5327 public _SimdTraits<_Tp, _Abi>::_SimdBase
5329 using _Traits = _SimdTraits<_Tp, _Abi>;
5330 using _MemberType =
typename _Traits::_SimdMember;
5331 using _CastType =
typename _Traits::_SimdCastType;
5332 static constexpr _Tp* _S_type_tag =
nullptr;
5333 friend typename _Traits::_SimdBase;
5336 using _Impl =
typename _Traits::_SimdImpl;
5338 friend _SimdIntOperators<simd, _Tp, _Abi, true>;
5340 using value_type = _Tp;
5341 using reference = _SmartReference<_MemberType, _Impl, value_type>;
5342 using mask_type = simd_mask<_Tp, _Abi>;
5343 using abi_type = _Abi;
5345 static constexpr size_t size()
5346 {
return __size_or_zero_v<_Tp, _Abi>; }
5348 _GLIBCXX_SIMD_CONSTEXPR simd() =
default;
5349 _GLIBCXX_SIMD_CONSTEXPR simd(
const simd&) =
default;
5350 _GLIBCXX_SIMD_CONSTEXPR simd(simd&&) noexcept = default;
5351 _GLIBCXX_SIMD_CONSTEXPR simd& operator=(const simd&) = default;
5352 _GLIBCXX_SIMD_CONSTEXPR simd& operator=(simd&&) noexcept = default;
5355 template <typename _Up,
5356 typename = enable_if_t<!is_same_v<__remove_cvref_t<_Up>,
bool>>>
5357 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5358 simd(_ValuePreservingOrInt<_Up, value_type>&& __x)
5360 _Impl::_S_broadcast(static_cast<value_type>(static_cast<_Up&&>(__x))))
5365 template <
typename _Up>
5366 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5367 simd(
const simd<_Up, simd_abi::fixed_size<size()>>& __x,
5370 is_same<simd_abi::fixed_size<size()>, abi_type>,
5371 negation<__is_narrowing_conversion<_Up, value_type>>,
5372 __converts_to_higher_integer_rank<_Up, value_type>>::value,
5374 : simd{static_cast<array<_Up, size()>>(__x).data(), vector_aligned} {}
5377#ifdef _GLIBCXX_SIMD_ENABLE_STATIC_CAST
5378 template <
typename _Up,
typename _A2,
5379 typename =
decltype(static_simd_cast<simd>(
5380 declval<
const simd<_Up, _A2>&>()))>
5381 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5382 simd(
const simd<_Up, _A2>& __x)
5383 : simd(static_simd_cast<simd>(__x)) {}
5387 template <
typename _Fp>
5388 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5389 simd(_Fp&& __gen, _ValuePreservingOrInt<
decltype(declval<_Fp>()(
5390 declval<_SizeConstant<0>&>())),
5391 value_type>* =
nullptr)
5392 : _M_data(_Impl::_S_generator(static_cast<_Fp&&>(__gen), _S_type_tag)) {}
5395 template <
typename _Up,
typename _Flags>
5396 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5397 simd(
const _Up* __mem, _IsSimdFlagType<_Flags>)
5399 _Impl::_S_load(_Flags::template _S_apply<simd>(__mem), _S_type_tag))
5403 template <
typename _Up,
typename _Flags>
5404 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
void
5405 copy_from(
const _Vectorizable<_Up>* __mem, _IsSimdFlagType<_Flags>)
5407 _M_data =
static_cast<decltype(_M_data)
>(
5408 _Impl::_S_load(_Flags::template _S_apply<simd>(__mem), _S_type_tag));
5412 template <
typename _Up,
typename _Flags>
5413 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
void
5414 copy_to(_Vectorizable<_Up>* __mem, _IsSimdFlagType<_Flags>)
const
5416 _Impl::_S_store(_M_data, _Flags::template _S_apply<simd>(__mem),
5421 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR reference
5422 operator[](
size_t __i)
5423 {
return {_M_data, int(__i)}; }
5425 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR value_type
5426 operator[]([[maybe_unused]]
size_t __i)
const
5428 if constexpr (__is_scalar_abi<_Abi>())
5430 _GLIBCXX_DEBUG_ASSERT(__i == 0);
5434 return _M_data[__i];
5438 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd&
5441 _Impl::_S_increment(_M_data);
5445 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5449 _Impl::_S_increment(_M_data);
5453 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd&
5456 _Impl::_S_decrement(_M_data);
5460 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5464 _Impl::_S_decrement(_M_data);
5469 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR mask_type
5471 {
return {__private_init, _Impl::_S_negate(_M_data)}; }
5473 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5477 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5479 {
return {__private_init, _Impl::_S_unary_minus(_M_data)}; }
5482 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5483 simd(_CastType __init) : _M_data(__init) {}
5486 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5487 operator+=(simd& __lhs,
const simd& __x)
5488 {
return __lhs = __lhs + __x; }
5490 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5491 operator-=(simd& __lhs,
const simd& __x)
5492 {
return __lhs = __lhs - __x; }
5494 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5495 operator*=(simd& __lhs,
const simd& __x)
5496 {
return __lhs = __lhs * __x; }
5498 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5499 operator/=(simd& __lhs,
const simd& __x)
5500 {
return __lhs = __lhs / __x; }
5503 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5504 operator+(
const simd& __x,
const simd& __y)
5505 {
return {__private_init, _Impl::_S_plus(__x._M_data, __y._M_data)}; }
5507 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5508 operator-(
const simd& __x,
const simd& __y)
5509 {
return {__private_init, _Impl::_S_minus(__x._M_data, __y._M_data)}; }
5511 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5512 operator*(
const simd& __x,
const simd& __y)
5513 {
return {__private_init, _Impl::_S_multiplies(__x._M_data, __y._M_data)}; }
5515 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5516 operator/(
const simd& __x,
const simd& __y)
5517 {
return {__private_init, _Impl::_S_divides(__x._M_data, __y._M_data)}; }
5520 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5521 operator==(
const simd& __x,
const simd& __y)
5522 {
return simd::_S_make_mask(_Impl::_S_equal_to(__x._M_data, __y._M_data)); }
5524 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5525 operator!=(
const simd& __x,
const simd& __y)
5527 return simd::_S_make_mask(
5528 _Impl::_S_not_equal_to(__x._M_data, __y._M_data));
5531 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5532 operator<(
const simd& __x,
const simd& __y)
5533 {
return simd::_S_make_mask(_Impl::_S_less(__x._M_data, __y._M_data)); }
5535 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5536 operator<=(
const simd& __x,
const simd& __y)
5538 return simd::_S_make_mask(_Impl::_S_less_equal(__x._M_data, __y._M_data));
5541 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5542 operator>(
const simd& __x,
const simd& __y)
5543 {
return simd::_S_make_mask(_Impl::_S_less(__y._M_data, __x._M_data)); }
5545 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5546 operator>=(
const simd& __x,
const simd& __y)
5548 return simd::_S_make_mask(_Impl::_S_less_equal(__y._M_data, __x._M_data));
5552#ifdef __GXX_CONDITIONAL_IS_OVERLOADABLE__
5553 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5554 operator?:(
const mask_type& __k,
const simd& __where_true,
5555 const simd& __where_false)
5557 auto __ret = __where_false;
5558 _Impl::_S_masked_assign(__data(__k), __data(__ret), __data(__where_true));
5566 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
5567 simd(_PrivateInit,
const _MemberType& __init)
5568 : _M_data(__init) {}
5571 _GLIBCXX_SIMD_INTRINSIC
5572 simd(_BitsetInit, bitset<size()> __init) : _M_data()
5573 { where(mask_type(__bitset_init, __init), *
this) = ~*
this; }
5575 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
5576 _M_is_constprop()
const
5578 if constexpr (__is_scalar_abi<_Abi>())
5579 return __builtin_constant_p(_M_data);
5581 return _M_data._M_is_constprop();
5585 _GLIBCXX_SIMD_INTRINSIC
static constexpr mask_type
5586 _S_make_mask(
typename mask_type::_MemberType __k)
5587 {
return {__private_init, __k}; }
5589 friend const auto& __data<value_type, abi_type>(
const simd&);
5590 friend auto& __data<value_type, abi_type>(simd&);
5591 alignas(_Traits::_S_simd_align) _MemberType _M_data;
5597template <
typename _Tp,
typename _Ap>
5598 _GLIBCXX_SIMD_INTRINSIC
constexpr const auto&
5599 __data(
const simd<_Tp, _Ap>& __x)
5600 {
return __x._M_data; }
5602template <
typename _Tp,
typename _Ap>
5603 _GLIBCXX_SIMD_INTRINSIC
constexpr auto&
5604 __data(simd<_Tp, _Ap>& __x)
5605 {
return __x._M_data; }
5608namespace __float_bitwise_operators {
5609template <
typename _Tp,
typename _Ap>
5610 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5611 operator^(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5612 {
return {__private_init, _Ap::_SimdImpl::_S_bit_xor(__data(__a), __data(__b))}; }
5614template <
typename _Tp,
typename _Ap>
5615 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5616 operator|(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5617 {
return {__private_init, _Ap::_SimdImpl::_S_bit_or(__data(__a), __data(__b))}; }
5619template <
typename _Tp,
typename _Ap>
5620 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5621 operator&(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5622 {
return {__private_init, _Ap::_SimdImpl::_S_bit_and(__data(__a), __data(__b))}; }
5624template <
typename _Tp,
typename _Ap>
5625 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
5626 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Ap>>
5627 operator~(
const simd<_Tp, _Ap>& __a)
5628 {
return {__private_init, _Ap::_SimdImpl::_S_complement(__data(__a))}; }
5633_GLIBCXX_SIMD_END_NAMESPACE
constexpr _If_is_unsigned_integer< _Tp, int > popcount(_Tp __x) noexcept
The number of bits set in x.
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator%(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
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
Create a tuple containing all elements from multiple tuple-like objects.
auto declval() noexcept -> decltype(__declval< _Tp >(0))
constexpr tuple< typename __decay_and_strip< _Elements >::__type... > make_tuple(_Elements &&... __args)
Create a tuple containing copies of the arguments.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
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.
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.
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.