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
72_GLIBCXX_SIMD_BEGIN_NAMESPACE
74#if !_GLIBCXX_SIMD_X86INTRIN
75using __m128 [[__gnu__::__vector_size__(16)]] = float;
76using __m128d [[__gnu__::__vector_size__(16)]] = double;
77using __m128i [[__gnu__::__vector_size__(16)]] =
long long;
78using __m256 [[__gnu__::__vector_size__(32)]] = float;
79using __m256d [[__gnu__::__vector_size__(32)]] = double;
80using __m256i [[__gnu__::__vector_size__(32)]] =
long long;
81using __m512 [[__gnu__::__vector_size__(64)]] = float;
82using __m512d [[__gnu__::__vector_size__(64)]] = double;
83using __m512i [[__gnu__::__vector_size__(64)]] =
long long;
105template <
int _UsedBytes>
108template <
int _UsedBytes>
109 struct _VecBltnBtmsk;
111template <
typename _Tp,
int _Np>
112 using _VecN = _VecBuiltin<
sizeof(_Tp) * _Np>;
114template <
int _UsedBytes = 16>
115 using _Sse = _VecBuiltin<_UsedBytes>;
117template <
int _UsedBytes = 32>
118 using _Avx = _VecBuiltin<_UsedBytes>;
120template <
int _UsedBytes = 64>
121 using _Avx512 = _VecBltnBtmsk<_UsedBytes>;
123template <
int _UsedBytes = 16>
124 using _Neon = _VecBuiltin<_UsedBytes>;
129using __avx512 = _Avx512<>;
130using __neon = _Neon<>;
131using __neon128 = _Neon<16>;
132using __neon64 = _Neon<8>;
135template <
typename _Tp,
size_t _Np,
typename...>
139 using fixed_size = _Fixed<_Np>;
141using scalar = _Scalar;
146template <
typename _Tp>
149template <
typename _Tp>
152template <
typename _Tp,
typename _Abi>
155template <
typename _Tp,
typename _Abi>
158template <
typename _Tp,
typename _Abi>
163struct element_aligned_tag
165 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
166 static constexpr size_t _S_alignment =
alignof(_Up);
168 template <
typename _Tp,
typename _Up>
169 _GLIBCXX_SIMD_INTRINSIC
static constexpr _Up*
174struct vector_aligned_tag
176 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
177 static constexpr size_t _S_alignment
178 = std::__bit_ceil(
sizeof(_Up) * _Tp::size());
180 template <
typename _Tp,
typename _Up>
181 _GLIBCXX_SIMD_INTRINSIC
static constexpr _Up*
184 return static_cast<_Up*
>(
185 __builtin_assume_aligned(__ptr, _S_alignment<_Tp, _Up>));
189template <
size_t _Np>
struct overaligned_tag
191 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
192 static constexpr size_t _S_alignment = _Np;
194 template <
typename _Tp,
typename _Up>
195 _GLIBCXX_SIMD_INTRINSIC
static constexpr _Up*
197 {
return static_cast<_Up*
>(__builtin_assume_aligned(__ptr, _Np)); }
200inline constexpr element_aligned_tag element_aligned = {};
202inline constexpr vector_aligned_tag vector_aligned = {};
205 inline constexpr overaligned_tag<_Np> overaligned = {};
209 using _SizeConstant = integral_constant<size_t, _Xp>;
211constexpr inline bool __have_mmx = _GLIBCXX_SIMD_HAVE_MMX;
212constexpr inline bool __have_sse = _GLIBCXX_SIMD_HAVE_SSE;
213constexpr inline bool __have_sse2 = _GLIBCXX_SIMD_HAVE_SSE2;
214constexpr inline bool __have_sse3 = _GLIBCXX_SIMD_HAVE_SSE3;
215constexpr inline bool __have_ssse3 = _GLIBCXX_SIMD_HAVE_SSSE3;
216constexpr inline bool __have_sse4_1 = _GLIBCXX_SIMD_HAVE_SSE4_1;
217constexpr inline bool __have_sse4_2 = _GLIBCXX_SIMD_HAVE_SSE4_2;
218constexpr inline bool __have_xop = _GLIBCXX_SIMD_HAVE_XOP;
219constexpr inline bool __have_avx = _GLIBCXX_SIMD_HAVE_AVX;
220constexpr inline bool __have_avx2 = _GLIBCXX_SIMD_HAVE_AVX2;
221constexpr inline bool __have_bmi = _GLIBCXX_SIMD_HAVE_BMI1;
222constexpr inline bool __have_bmi2 = _GLIBCXX_SIMD_HAVE_BMI2;
223constexpr inline bool __have_lzcnt = _GLIBCXX_SIMD_HAVE_LZCNT;
224constexpr inline bool __have_sse4a = _GLIBCXX_SIMD_HAVE_SSE4A;
225constexpr inline bool __have_fma = _GLIBCXX_SIMD_HAVE_FMA;
226constexpr inline bool __have_fma4 = _GLIBCXX_SIMD_HAVE_FMA4;
227constexpr inline bool __have_f16c = _GLIBCXX_SIMD_HAVE_F16C;
228constexpr inline bool __have_popcnt = _GLIBCXX_SIMD_HAVE_POPCNT;
229constexpr inline bool __have_avx512f = _GLIBCXX_SIMD_HAVE_AVX512F;
230constexpr inline bool __have_avx512dq = _GLIBCXX_SIMD_HAVE_AVX512DQ;
231constexpr inline bool __have_avx512vl = _GLIBCXX_SIMD_HAVE_AVX512VL;
232constexpr inline bool __have_avx512bw = _GLIBCXX_SIMD_HAVE_AVX512BW;
233constexpr inline bool __have_avx512dq_vl = __have_avx512dq && __have_avx512vl;
234constexpr inline bool __have_avx512bw_vl = __have_avx512bw && __have_avx512vl;
235constexpr inline bool __have_avx512bitalg = _GLIBCXX_SIMD_HAVE_AVX512BITALG;
236constexpr inline bool __have_avx512vbmi2 = _GLIBCXX_SIMD_HAVE_AVX512VBMI2;
237constexpr inline bool __have_avx512vbmi = _GLIBCXX_SIMD_HAVE_AVX512VBMI;
238constexpr inline bool __have_avx512ifma = _GLIBCXX_SIMD_HAVE_AVX512IFMA;
239constexpr inline bool __have_avx512cd = _GLIBCXX_SIMD_HAVE_AVX512CD;
240constexpr inline bool __have_avx512vnni = _GLIBCXX_SIMD_HAVE_AVX512VNNI;
241constexpr inline bool __have_avx512vpopcntdq = _GLIBCXX_SIMD_HAVE_AVX512VPOPCNTDQ;
242constexpr inline bool __have_avx512vp2intersect = _GLIBCXX_SIMD_HAVE_AVX512VP2INTERSECT;
244constexpr inline bool __have_neon = _GLIBCXX_SIMD_HAVE_NEON;
245constexpr inline bool __have_neon_a32 = _GLIBCXX_SIMD_HAVE_NEON_A32;
246constexpr inline bool __have_neon_a64 = _GLIBCXX_SIMD_HAVE_NEON_A64;
247constexpr inline bool __support_neon_float =
248#if defined __GCC_IEC_559
250#elif defined __FAST_MATH__
257constexpr inline bool __have_power10vec =
true;
259constexpr inline bool __have_power10vec =
false;
261#ifdef __POWER9_VECTOR__
262constexpr inline bool __have_power9vec =
true;
264constexpr inline bool __have_power9vec =
false;
266#if defined __POWER8_VECTOR__
267constexpr inline bool __have_power8vec =
true;
269constexpr inline bool __have_power8vec = __have_power9vec;
272constexpr inline bool __have_power_vsx =
true;
274constexpr inline bool __have_power_vsx = __have_power8vec;
276#if defined __ALTIVEC__
277constexpr inline bool __have_power_vmx =
true;
279constexpr inline bool __have_power_vmx = __have_power_vsx;
286#ifdef math_errhandling
290 template <
int = math_errhandling>
291 constexpr bool __handle_fpexcept_impl(
int)
292 {
return math_errhandling & MATH_ERREXCEPT; }
297 constexpr bool __handle_fpexcept_impl(
float)
299#if defined __FAST_MATH__
307 static constexpr bool _S_handle_fpexcept = __handle_fpexcept_impl(0);
309 constexpr std::uint_least64_t
310 __floating_point_flags()
312 std::uint_least64_t __flags = 0;
313 if constexpr (_S_handle_fpexcept)
317#elif __FINITE_MATH_ONLY__
319#elif __GCC_IEC_559 < 2
322 __flags |= (__FLT_EVAL_METHOD__ + 1) << 3;
326 constexpr std::uint_least64_t
329 if constexpr (__have_mmx || __have_sse)
334 | (__have_ssse3 << 4)
335 | (__have_sse4_1 << 5)
336 | (__have_sse4_2 << 6)
341 | (__have_bmi2 << 11)
342 | (__have_lzcnt << 12)
343 | (__have_sse4a << 13)
345 | (__have_fma4 << 15)
346 | (__have_f16c << 16)
347 | (__have_popcnt << 17)
348 | (__have_avx512f << 18)
349 | (__have_avx512dq << 19)
350 | (__have_avx512vl << 20)
351 | (__have_avx512bw << 21)
352 | (__have_avx512bitalg << 22)
353 | (__have_avx512vbmi2 << 23)
354 | (__have_avx512vbmi << 24)
355 | (__have_avx512ifma << 25)
356 | (__have_avx512cd << 26)
357 | (__have_avx512vnni << 27)
358 | (__have_avx512vpopcntdq << 28)
359 | (__have_avx512vp2intersect << 29);
360 else if constexpr (__have_neon)
362 | (__have_neon_a32 << 1)
363 | (__have_neon_a64 << 2)
364 | (__have_neon_a64 << 2)
365 | (__support_neon_float << 3);
366 else if constexpr (__have_power_vmx)
367 return __have_power_vmx
368 | (__have_power_vsx << 1)
369 | (__have_power8vec << 2)
370 | (__have_power9vec << 3)
371 | (__have_power10vec << 4);
378 struct _OdrEnforcer {};
381 template <std::uint_least64_t...>
382 struct _MachineFlagsTemplate {};
395 _MachineFlagsTemplate<__machine_flags(), __floating_point_flags()>>;
399 template <
typename _Tp>
400 _GLIBCXX_SIMD_INTRINSIC
constexpr
402 operator()(_Tp __a, _Tp __b)
const
405 return min(__a, __b);
411 template <
typename _Tp>
412 _GLIBCXX_SIMD_INTRINSIC
constexpr
414 operator()(_Tp __a, _Tp __b)
const
417 return max(__a, __b);
424template <
typename _Fp,
size_t... _I>
425 [[__gnu__::__flatten__]] _GLIBCXX_SIMD_INTRINSIC
constexpr
427 __execute_on_index_sequence(_Fp&& __f, index_sequence<_I...>)
428 { ((void)__f(_SizeConstant<_I>()), ...); }
430template <
typename _Fp>
431 _GLIBCXX_SIMD_INTRINSIC
constexpr void
432 __execute_on_index_sequence(_Fp&&, index_sequence<>)
435template <
size_t _Np,
typename _Fp>
436 _GLIBCXX_SIMD_INTRINSIC
constexpr void
437 __execute_n_times(_Fp&& __f)
439 __execute_on_index_sequence(
static_cast<_Fp&&
>(__f),
440 make_index_sequence<_Np>{});
445template <
typename _R,
typename _Fp,
size_t... _I>
446 [[__gnu__::__flatten__]] _GLIBCXX_SIMD_INTRINSIC
constexpr
448 __execute_on_index_sequence_with_return(_Fp&& __f, index_sequence<_I...>)
449 {
return _R{__f(_SizeConstant<_I>())...}; }
451template <
size_t _Np,
typename _R,
typename _Fp>
452 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
453 __generate_from_n_evaluations(_Fp&& __f)
455 return __execute_on_index_sequence_with_return<_R>(
456 static_cast<_Fp&&
>(__f), make_index_sequence<_Np>{});
461template <
size_t... _I,
typename _F0,
typename _FArgs>
462 [[__gnu__::__flatten__]] _GLIBCXX_SIMD_INTRINSIC
constexpr
464 __call_with_n_evaluations(index_sequence<_I...>, _F0&& __f0, _FArgs&& __fargs)
465 {
return __f0(__fargs(_SizeConstant<_I>())...); }
467template <
size_t _Np,
typename _F0,
typename _FArgs>
468 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
469 __call_with_n_evaluations(_F0&& __f0, _FArgs&& __fargs)
471 return __call_with_n_evaluations(make_index_sequence<_Np>{},
472 static_cast<_F0&&
>(__f0),
473 static_cast<_FArgs&&
>(__fargs));
478template <
size_t _First = 0,
size_t... _It,
typename _Tp,
typename _Fp>
479 [[__gnu__::__flatten__]] _GLIBCXX_SIMD_INTRINSIC
constexpr
481 __call_with_subscripts(_Tp&& __x, index_sequence<_It...>, _Fp&& __fun)
482 {
return __fun(__x[_First + _It]...); }
484template <
size_t _Np,
size_t _First = 0,
typename _Tp,
typename _Fp>
485 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
486 __call_with_subscripts(_Tp&& __x, _Fp&& __fun)
488 return __call_with_subscripts<_First>(
static_cast<_Tp&&
>(__x),
489 make_index_sequence<_Np>(),
490 static_cast<_Fp&&
>(__fun));
497using _UChar =
unsigned char;
498using _SChar =
signed char;
499using _UShort =
unsigned short;
500using _UInt =
unsigned int;
501using _ULong =
unsigned long;
502using _ULLong =
unsigned long long;
503using _LLong =
long long;
507template <
typename _T0,
typename...>
508 struct __first_of_pack
509 {
using type = _T0; };
511template <
typename... _Ts>
512 using __first_of_pack_t =
typename __first_of_pack<_Ts...>::type;
516template <
typename _Tp>
517 typename _Tp::value_type
518 __value_type_or_identity_impl(
int);
520template <
typename _Tp>
522 __value_type_or_identity_impl(
float);
524template <
typename _Tp>
525 using __value_type_or_identity_t
526 =
decltype(__value_type_or_identity_impl<_Tp>(
int()));
530template <
typename _Tp>
531 struct __is_vectorizable :
public is_arithmetic<_Tp> {};
534 struct __is_vectorizable<bool> :
public false_type {};
536template <
typename _Tp>
537 inline constexpr bool __is_vectorizable_v = __is_vectorizable<_Tp>::value;
540template <
typename _Tp,
typename = enable_if_t<__is_vectorizable_v<_Tp>>>
541 using _Vectorizable = _Tp;
545template <
typename _Ptr,
typename _ValueType>
546 struct __is_possible_loadstore_conversion
547 : conjunction<__is_vectorizable<_Ptr>, __is_vectorizable<_ValueType>> {};
550 struct __is_possible_loadstore_conversion<bool, bool> :
true_type {};
553template <
typename _Ptr,
typename _ValueType,
555 __is_possible_loadstore_conversion<_Ptr, _ValueType>::value>>
556 using _LoadStorePtr = _Ptr;
560template <
typename _Tp,
typename =
void_t<>>
563template <
typename _Tp>
564 inline constexpr bool __is_bitmask_v = __is_bitmask<_Tp>::value;
567template <
typename _Tp>
568 struct __is_bitmask<_Tp,
569 void_t<decltype(
declval<unsigned&>() = declval<_Tp>() & 1u)>>
574#pragma GCC diagnostic push
575#pragma GCC diagnostic ignored "-Wpedantic"
576template <
size_t _Bytes>
580 if constexpr (_Bytes ==
sizeof(int))
583 else if constexpr (_Bytes ==
sizeof(char))
586 else if constexpr (_Bytes ==
sizeof(_SChar))
589 else if constexpr (_Bytes ==
sizeof(short))
592 else if constexpr (_Bytes ==
sizeof(long))
595 else if constexpr (_Bytes ==
sizeof(_LLong))
597 #ifdef __SIZEOF_INT128__
598 else if constexpr (_Bytes ==
sizeof(__int128))
601 else if constexpr (_Bytes %
sizeof(int) == 0)
603 constexpr size_t _Np = _Bytes /
sizeof(int);
608 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
611 return __generate_from_n_evaluations<_Np, _Ip>(
612 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
613 return __rhs._M_data[__i] & _M_data[__i];
617 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
620 return __generate_from_n_evaluations<_Np, _Ip>(
621 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
622 return __rhs._M_data[__i] | _M_data[__i];
626 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
629 return __generate_from_n_evaluations<_Np, _Ip>(
630 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
631 return __rhs._M_data[__i] ^ _M_data[__i];
635 _GLIBCXX_SIMD_INTRINSIC
constexpr _Ip
638 return __generate_from_n_evaluations<_Np, _Ip>(
639 [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return ~_M_data[__i]; });
645 static_assert(_Bytes != _Bytes,
"this should be unreachable");
647#pragma GCC diagnostic pop
649template <
typename _Tp>
650 using __int_for_sizeof_t =
decltype(__int_for_sizeof<sizeof(_Tp)>());
653 using __int_with_sizeof_t =
decltype(__int_for_sizeof<_Np>());
657template <
typename _Tp>
661 struct __is_fixed_size_abi<simd_abi::fixed_size<_Np>> :
true_type {};
663template <
typename _Tp>
664 inline constexpr bool __is_fixed_size_abi_v = __is_fixed_size_abi<_Tp>::value;
668template <
typename _Abi>
671 {
return is_same_v<simd_abi::scalar, _Abi>; }
675template <
template <
int>
class _Abi,
int _Bytes>
677 __abi_bytes_impl(_Abi<_Bytes>*)
680template <
typename _Tp>
682 __abi_bytes_impl(_Tp*)
685template <
typename _Abi>
686 inline constexpr int __abi_bytes_v
687 = __abi_bytes_impl(
static_cast<_Abi*
>(
nullptr));
691template <
typename _Abi>
693 __is_builtin_bitmask_abi()
694 {
return is_same_v<simd_abi::_VecBltnBtmsk<__abi_bytes_v<_Abi>>, _Abi>; }
698template <
typename _Abi>
702 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
703 return _Bytes <= 16 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
708template <
typename _Abi>
712 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
713 return _Bytes > 16 && _Bytes <= 32
714 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
719template <
typename _Abi>
723 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
724 return _Bytes <= 64 && is_same_v<simd_abi::_Avx512<_Bytes>, _Abi>;
729template <
typename _Abi>
733 constexpr auto _Bytes = __abi_bytes_v<_Abi>;
734 return _Bytes <= 16 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
739template <
typename,
typename _Up>
740 struct __make_dependent
741 {
using type = _Up; };
743template <
typename _Tp,
typename _Up>
744 using __make_dependent_t =
typename __make_dependent<_Tp, _Up>::type;
750template <
typename... _Args>
751 [[noreturn]] _GLIBCXX_SIMD_ALWAYS_INLINE
void
752 __invoke_ub([[maybe_unused]]
const char* __msg,
753 [[maybe_unused]]
const _Args&... __args)
755#ifdef _GLIBCXX_DEBUG_UB
756 __builtin_fprintf(stderr, __msg, __args...);
759 __builtin_unreachable();
765template <
typename _Tp>
766 struct __assert_unreachable
767 {
static_assert(!is_same_v<_Tp, _Tp>,
"this should be unreachable"); };
771template <typename _Tp, typename _Ap, size_t _Np = simd_size<_Tp, _Ap>::value>
773 __size_or_zero_dispatch(
int)
776template <
typename _Tp,
typename _Ap>
778 __size_or_zero_dispatch(
float)
781template <
typename _Tp,
typename _Ap>
782 inline constexpr size_t __size_or_zero_v
783 = __size_or_zero_dispatch<_Tp, _Ap>(0);
787inline constexpr size_t
788__div_roundup(
size_t __a,
size_t __b)
789{
return (__a + __b - 1) / __b; }
798 _GLIBCXX_SIMD_INTRINSIC
constexpr _ExactBool(
bool __b) : _M_data(__b) {}
800 _ExactBool(
int) =
delete;
802 _GLIBCXX_SIMD_INTRINSIC
constexpr operator bool()
const {
return _M_data; }
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();
1028 __f(std::__countr_zero(__k));
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__);
1123 sizeof(_ULLong), std::__bit_ceil(_NBytes))>>>;
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,
1492 enable_if_t<__is_vectorizable_v<_Tp> && _Np >= 2>>
1494 static constexpr size_t _S_Np2 = std::__bit_ceil(_Np *
sizeof(_Tp));
1496 static constexpr size_t _S_Bytes =
1502 _S_Np2 < __min_vector_size<_Tp> ? __min_vector_size<_Tp>
1505 using type [[__gnu__::__vector_size__(_S_Bytes)]] = _Tp;
1508template <
typename _Tp,
size_t _Bytes,
size_t = _Bytes % sizeof(_Tp)>
1509 struct __vector_type;
1511template <
typename _Tp,
size_t _Bytes>
1512 struct __vector_type<_Tp, _Bytes, 0>
1513 : __vector_type_n<_Tp, _Bytes / sizeof(_Tp)> {};
1515template <
typename _Tp,
size_t _Size>
1516 using __vector_type_t =
typename __vector_type_n<_Tp, _Size>::type;
1518template <
typename _Tp>
1519 using __vector_type2_t =
typename __vector_type<_Tp, 2>::type;
1520template <
typename _Tp>
1521 using __vector_type4_t =
typename __vector_type<_Tp, 4>::type;
1522template <
typename _Tp>
1523 using __vector_type8_t =
typename __vector_type<_Tp, 8>::type;
1524template <
typename _Tp>
1525 using __vector_type16_t =
typename __vector_type<_Tp, 16>::type;
1526template <
typename _Tp>
1527 using __vector_type32_t =
typename __vector_type<_Tp, 32>::type;
1528template <
typename _Tp>
1529 using __vector_type64_t =
typename __vector_type<_Tp, 64>::type;
1533template <
typename _Tp,
typename =
void_t<>>
1536template <
typename _Tp>
1537 struct __is_vector_type<
1538 _Tp,
void_t<typename __vector_type<
1540 : is_same<_Tp, typename __vector_type<
1541 remove_reference_t<decltype(declval<_Tp>()[0])>,
1542 sizeof(_Tp)>::type> {};
1544template <
typename _Tp>
1545 inline constexpr bool __is_vector_type_v = __is_vector_type<_Tp>::value;
1549#if _GLIBCXX_SIMD_HAVE_SSE_ABI
1550template <
typename _Tp>
1551 using __is_intrinsic_type = __is_vector_type<_Tp>;
1553template <
typename _Tp,
typename =
void_t<>>
1556template <
typename _Tp>
1557 struct __is_intrinsic_type<
1558 _Tp,
void_t<typename __intrinsic_type<
1560 : is_same<_Tp, typename __intrinsic_type<
1561 remove_reference_t<decltype(declval<_Tp>()[0])>,
1562 sizeof(_Tp)>::type> {};
1565template <
typename _Tp>
1566 inline constexpr bool __is_intrinsic_type_v = __is_intrinsic_type<_Tp>::value;
1570template <
typename _Tp,
typename =
void_t<>>
1571 struct _VectorTraitsImpl;
1573template <
typename _Tp>
1574 struct _VectorTraitsImpl<_Tp,
enable_if_t<__is_vector_type_v<_Tp>
1575 || __is_intrinsic_type_v<_Tp>>>
1578 using value_type = remove_reference_t<decltype(declval<_Tp>()[0])>;
1579 static constexpr int _S_full_size =
sizeof(_Tp) /
sizeof(value_type);
1580 using _Wrapper = _SimdWrapper<value_type, _S_full_size>;
1581 template <
typename _Up,
int _W = _S_full_size>
1582 static constexpr bool _S_is
1583 = is_same_v<value_type, _Up> && _W == _S_full_size;
1586template <
typename _Tp,
size_t _Np>
1587 struct _VectorTraitsImpl<_SimdWrapper<_Tp, _Np>,
1588 void_t<__vector_type_t<_Tp, _Np>>>
1590 using type = __vector_type_t<_Tp, _Np>;
1591 using value_type = _Tp;
1592 static constexpr int _S_full_size =
sizeof(type) /
sizeof(value_type);
1593 using _Wrapper = _SimdWrapper<_Tp, _Np>;
1594 static constexpr bool _S_is_partial = (_Np == _S_full_size);
1595 static constexpr int _S_partial_width = _Np;
1596 template <
typename _Up,
int _W = _S_full_size>
1597 static constexpr bool _S_is
1598 = is_same_v<value_type, _Up>&& _W == _S_full_size;
1601template <typename _Tp, typename = typename _VectorTraitsImpl<_Tp>::type>
1602 using _VectorTraits = _VectorTraitsImpl<_Tp>;
1606template <
typename _V>
1607 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
1610 if constexpr (__is_vector_type_v<_V>)
1612 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value)
1613 return __data(__x)._M_data;
1614 else if constexpr (__is_vectorizable_v<_V>)
1615 return __vector_type_t<_V, 2>{__x};
1622template <
size_t _Np = 0,
typename _V>
1623 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
1624 __as_wrapper(_V __x)
1626 if constexpr (__is_vector_type_v<_V>)
1627 return _SimdWrapper<
typename _VectorTraits<_V>::value_type,
1628 (_Np > 0 ? _Np : _VectorTraits<_V>::_S_full_size)>(__x);
1629 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value)
1631 static_assert(_V::size() == _Np);
1636 static_assert(_V::_S_size == _Np);
1643template <
typename _To,
typename _From>
1644 _GLIBCXX_SIMD_INTRINSIC
constexpr _To
1645 __intrin_bitcast(_From __v)
1647 static_assert((__is_vector_type_v<_From> || __is_intrinsic_type_v<_From>)
1648 && (__is_vector_type_v<_To> || __is_intrinsic_type_v<_To>));
1649 if constexpr (
sizeof(_To) ==
sizeof(_From))
1650 return reinterpret_cast<_To
>(__v);
1651 else if constexpr (
sizeof(_From) >
sizeof(_To))
1652 if constexpr (
sizeof(_To) >= 16)
1653 return reinterpret_cast<const __may_alias<_To>&
>(__v);
1657 __builtin_memcpy(&__r, &__v,
sizeof(_To));
1660#if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1661 else if constexpr (__have_avx &&
sizeof(_From) == 16 &&
sizeof(_To) == 32)
1662 return reinterpret_cast<_To
>(__builtin_ia32_ps256_ps(
1663 reinterpret_cast<__vector_type_t<float, 4>
>(__v)));
1664 else if constexpr (__have_avx512f &&
sizeof(_From) == 16
1665 &&
sizeof(_To) == 64)
1666 return reinterpret_cast<_To
>(__builtin_ia32_ps512_ps(
1667 reinterpret_cast<__vector_type_t<float, 4>
>(__v)));
1668 else if constexpr (__have_avx512f &&
sizeof(_From) == 32
1669 &&
sizeof(_To) == 64)
1670 return reinterpret_cast<_To
>(__builtin_ia32_ps512_256ps(
1671 reinterpret_cast<__vector_type_t<float, 8>
>(__v)));
1673 else if constexpr (
sizeof(__v) <= 8)
1674 return reinterpret_cast<_To
>(
1675 __vector_type_t<__int_for_sizeof_t<_From>,
sizeof(_To) /
sizeof(_From)>{
1676 reinterpret_cast<__int_for_sizeof_t<_From>
>(__v)});
1679 static_assert(
sizeof(_To) >
sizeof(_From));
1681 __builtin_memcpy(&__r, &__v,
sizeof(_From));
1688template <
typename _To,
size_t _NN = 0,
typename _From,
1689 typename _FromVT = _VectorTraits<_From>,
1690 size_t _Np = _NN == 0 ?
sizeof(_From) /
sizeof(_To) : _NN>
1691 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_To, _Np>
1692 __vector_bitcast(_From __x)
1694 using _R = __vector_type_t<_To, _Np>;
1695 return __intrin_bitcast<_R>(__x);
1698template <
typename _To,
size_t _NN = 0,
typename _Tp,
size_t _Nx,
1700 = _NN == 0 ?
sizeof(_SimdWrapper<_Tp, _Nx>) /
sizeof(_To) : _NN>
1701 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_To, _Np>
1702 __vector_bitcast(
const _SimdWrapper<_Tp, _Nx>& __x)
1704 static_assert(_Np > 1);
1705 return __intrin_bitcast<__vector_type_t<_To, _Np>>(__x._M_data);
1710#ifdef _GLIBCXX_SIMD_WORKAROUND_PR85048
1711template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1712 _To __convert_x86(_Tp);
1714template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1715 _To __convert_x86(_Tp, _Tp);
1717template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1718 _To __convert_x86(_Tp, _Tp, _Tp, _Tp);
1720template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1721 _To __convert_x86(_Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp);
1723template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1724 _To __convert_x86(_Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp,
1725 _Tp, _Tp, _Tp, _Tp);
1730template <
typename _To,
typename _From>
1731 _GLIBCXX_SIMD_INTRINSIC
constexpr _To
1732 __bit_cast(
const _From __x)
1734#if __has_builtin(__builtin_bit_cast)
1735 return __builtin_bit_cast(_To, __x);
1737 static_assert(
sizeof(_To) ==
sizeof(_From));
1738 constexpr bool __to_is_vectorizable
1739 = is_arithmetic_v<_To> || is_enum_v<_To>;
1740 constexpr bool __from_is_vectorizable
1741 = is_arithmetic_v<_From> || is_enum_v<_From>;
1742 if constexpr (__is_vector_type_v<_To> && __is_vector_type_v<_From>)
1743 return reinterpret_cast<_To
>(__x);
1744 else if constexpr (__is_vector_type_v<_To> && __from_is_vectorizable)
1746 using _FV [[gnu::vector_size(
sizeof(_From))]] = _From;
1747 return reinterpret_cast<_To
>(_FV{__x});
1749 else if constexpr (__to_is_vectorizable && __from_is_vectorizable)
1751 using _TV [[gnu::vector_size(
sizeof(_To))]] = _To;
1752 using _FV [[gnu::vector_size(
sizeof(_From))]] = _From;
1753 return reinterpret_cast<_TV
>(_FV{__x})[0];
1755 else if constexpr (__to_is_vectorizable && __is_vector_type_v<_From>)
1757 using _TV [[gnu::vector_size(
sizeof(_To))]] = _To;
1758 return reinterpret_cast<_TV
>(__x)[0];
1763 __builtin_memcpy(
reinterpret_cast<char*
>(&__r),
1764 reinterpret_cast<const char*
>(&__x),
sizeof(_To));
1772template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>,
1774 = __
intrinsic_type_t<
typename _TVT::value_type, _TVT::_S_full_size>>
1775 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
1776 __to_intrin(_Tp __x)
1778 static_assert(
sizeof(__x) <=
sizeof(_R),
1779 "__to_intrin may never drop values off the end");
1780 if constexpr (
sizeof(__x) ==
sizeof(_R))
1781 return reinterpret_cast<_R
>(__as_vector(__x));
1784 using _Up = __int_for_sizeof_t<_Tp>;
1785 return reinterpret_cast<_R
>(
1786 __vector_type_t<_Up,
sizeof(_R) /
sizeof(_Up)>{__bit_cast<_Up>(__x)});
1792template <
typename _Tp,
typename... _Args>
1793 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp,
sizeof...(_Args)>
1794 __make_vector(
const _Args&... __args)
1796 return __vector_type_t<_Tp,
sizeof...(_Args)>{
static_cast<_Tp
>(__args)...};
1801template <
size_t _Np,
typename _Tp>
1802 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1803 __vector_broadcast(_Tp __x)
1805 return __call_with_n_evaluations<_Np>(
1806 [](
auto... __xx) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
1807 return __vector_type_t<_Tp, _Np>{__xx...};
1808 }, [&__x](int) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x; });
1813 template <
typename _Tp,
size_t _Np,
typename _Gp,
size_t... _I>
1814 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1815 __generate_vector_impl(_Gp&& __gen, index_sequence<_I...>)
1817 return __vector_type_t<_Tp, _Np>{
1818 static_cast<_Tp
>(__gen(_SizeConstant<_I>()))...};
1821template <
typename _V,
typename _VVT = _VectorTraits<_V>,
typename _Gp>
1822 _GLIBCXX_SIMD_INTRINSIC
constexpr _V
1823 __generate_vector(_Gp&& __gen)
1825 if constexpr (__is_vector_type_v<_V>)
1826 return __generate_vector_impl<
typename _VVT::value_type,
1827 _VVT::_S_full_size>(
1828 static_cast<_Gp&&
>(__gen), make_index_sequence<_VVT::_S_full_size>());
1830 return __generate_vector_impl<
typename _VVT::value_type,
1831 _VVT::_S_partial_width>(
1832 static_cast<_Gp&&
>(__gen),
1833 make_index_sequence<_VVT::_S_partial_width>());
1836template <
typename _Tp,
size_t _Np,
typename _Gp>
1837 _GLIBCXX_SIMD_INTRINSIC
constexpr __vector_type_t<_Tp, _Np>
1838 __generate_vector(_Gp&& __gen)
1840 return __generate_vector_impl<_Tp, _Np>(
static_cast<_Gp&&
>(__gen),
1841 make_index_sequence<_Np>());
1846template <
typename _TW>
1847 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1848 __xor(_TW __a, _TW __b)
noexcept
1850 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1852 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1853 _VectorTraitsImpl<_TW>>::value_type;
1854 if constexpr (is_floating_point_v<_Tp>)
1856 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1857 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1858 ^ __vector_bitcast<_Ip>(__b));
1860 else if constexpr (__is_vector_type_v<_TW>)
1863 return __a._M_data ^ __b._M_data;
1871template <
typename _TW>
1872 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1873 __or(_TW __a, _TW __b)
noexcept
1875 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1877 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1878 _VectorTraitsImpl<_TW>>::value_type;
1879 if constexpr (is_floating_point_v<_Tp>)
1881 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1882 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1883 | __vector_bitcast<_Ip>(__b));
1885 else if constexpr (__is_vector_type_v<_TW>)
1888 return __a._M_data | __b._M_data;
1896template <
typename _TW>
1897 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1898 __and(_TW __a, _TW __b)
noexcept
1900 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1902 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1903 _VectorTraitsImpl<_TW>>::value_type;
1904 if constexpr (is_floating_point_v<_Tp>)
1906 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1907 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1908 & __vector_bitcast<_Ip>(__b));
1910 else if constexpr (__is_vector_type_v<_TW>)
1913 return __a._M_data & __b._M_data;
1921#if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1922static constexpr struct
1924 _GLIBCXX_SIMD_INTRINSIC __v4sf
1925 operator()(__v4sf __a, __v4sf __b)
const noexcept
1926 {
return __builtin_ia32_andnps(__a, __b); }
1928 _GLIBCXX_SIMD_INTRINSIC __v2df
1929 operator()(__v2df __a, __v2df __b)
const noexcept
1930 {
return __builtin_ia32_andnpd(__a, __b); }
1932 _GLIBCXX_SIMD_INTRINSIC __v2di
1933 operator()(__v2di __a, __v2di __b)
const noexcept
1934 {
return __builtin_ia32_pandn128(__a, __b); }
1936 _GLIBCXX_SIMD_INTRINSIC __v8sf
1937 operator()(__v8sf __a, __v8sf __b)
const noexcept
1938 {
return __builtin_ia32_andnps256(__a, __b); }
1940 _GLIBCXX_SIMD_INTRINSIC __v4df
1941 operator()(__v4df __a, __v4df __b)
const noexcept
1942 {
return __builtin_ia32_andnpd256(__a, __b); }
1944 _GLIBCXX_SIMD_INTRINSIC __v4di
1945 operator()(__v4di __a, __v4di __b)
const noexcept
1947 if constexpr (__have_avx2)
1948 return __builtin_ia32_andnotsi256(__a, __b);
1950 return reinterpret_cast<__v4di
>(
1951 __builtin_ia32_andnpd256(
reinterpret_cast<__v4df
>(__a),
1952 reinterpret_cast<__v4df
>(__b)));
1955 _GLIBCXX_SIMD_INTRINSIC __v16sf
1956 operator()(__v16sf __a, __v16sf __b)
const noexcept
1958 if constexpr (__have_avx512dq)
1959 return _mm512_andnot_ps(__a, __b);
1961 return reinterpret_cast<__v16sf
>(
1962 _mm512_andnot_si512(
reinterpret_cast<__v8di
>(__a),
1963 reinterpret_cast<__v8di
>(__b)));
1966 _GLIBCXX_SIMD_INTRINSIC __v8df
1967 operator()(__v8df __a, __v8df __b)
const noexcept
1969 if constexpr (__have_avx512dq)
1970 return _mm512_andnot_pd(__a, __b);
1972 return reinterpret_cast<__v8df
>(
1973 _mm512_andnot_si512(
reinterpret_cast<__v8di
>(__a),
1974 reinterpret_cast<__v8di
>(__b)));
1977 _GLIBCXX_SIMD_INTRINSIC __v8di
1978 operator()(__v8di __a, __v8di __b)
const noexcept
1979 {
return _mm512_andnot_si512(__a, __b); }
1983template <
typename _TW>
1984 _GLIBCXX_SIMD_INTRINSIC
constexpr _TW
1985 __andnot(_TW __a, _TW __b)
noexcept
1987 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1989 using _TVT = conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1990 _VectorTraitsImpl<_TW>>;
1991 using _Tp =
typename _TVT::value_type;
1992#if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1993 if constexpr (
sizeof(_TW) >= 16)
1995 const auto __ai = __to_intrin(__a);
1996 const auto __bi = __to_intrin(__b);
1997 if (!__builtin_is_constant_evaluated()
1998 && !(__builtin_constant_p(__ai) && __builtin_constant_p(__bi)))
2000 const auto __r = _S_x86_andnot(__ai, __bi);
2001 if constexpr (is_convertible_v<
decltype(__r), _TW>)
2004 return reinterpret_cast<typename _TVT::type
>(__r);
2008 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
2009 return __vector_bitcast<_Tp>(~__vector_bitcast<_Ip>(__a)
2010 & __vector_bitcast<_Ip>(__b));
2018template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2019 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp
2020 __not(_Tp __a)
noexcept
2022 if constexpr (is_floating_point_v<typename _TVT::value_type>)
2023 return reinterpret_cast<typename _TVT::type
>(
2024 ~__vector_bitcast<unsigned>(__a));
2031template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>,
2032 typename _R = __vector_type_t<
typename _TVT::value_type,
2033 _TVT::_S_full_size * 2>>
2035 __concat(_Tp a_, _Tp b_)
2037#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_1
2039 = conditional_t<is_floating_point_v<typename _TVT::value_type>, double,
2041 long long,
typename _TVT::value_type>>;
2042 constexpr int input_width =
sizeof(_Tp) /
sizeof(_W);
2043 const auto __a = __vector_bitcast<_W>(a_);
2044 const auto __b = __vector_bitcast<_W>(b_);
2045 using _Up = __vector_type_t<_W,
sizeof(_R) /
sizeof(_W)>;
2047 constexpr int input_width = _TVT::_S_full_size;
2048 const _Tp& __a = a_;
2049 const _Tp& __b = b_;
2052 if constexpr (input_width == 2)
2053 return reinterpret_cast<_R
>(_Up{__a[0], __a[1], __b[0], __b[1]});
2054 else if constexpr (input_width == 4)
2055 return reinterpret_cast<_R
>(
2056 _Up{__a[0], __a[1], __a[2], __a[3], __b[0], __b[1], __b[2], __b[3]});
2057 else if constexpr (input_width == 8)
2058 return reinterpret_cast<_R
>(
2059 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6], __a[7],
2060 __b[0], __b[1], __b[2], __b[3], __b[4], __b[5], __b[6], __b[7]});
2061 else if constexpr (input_width == 16)
2062 return reinterpret_cast<_R
>(
2063 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6],
2064 __a[7], __a[8], __a[9], __a[10], __a[11], __a[12], __a[13],
2065 __a[14], __a[15], __b[0], __b[1], __b[2], __b[3], __b[4],
2066 __b[5], __b[6], __b[7], __b[8], __b[9], __b[10], __b[11],
2067 __b[12], __b[13], __b[14], __b[15]});
2068 else if constexpr (input_width == 32)
2069 return reinterpret_cast<_R
>(
2070 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6],
2071 __a[7], __a[8], __a[9], __a[10], __a[11], __a[12], __a[13],
2072 __a[14], __a[15], __a[16], __a[17], __a[18], __a[19], __a[20],
2073 __a[21], __a[22], __a[23], __a[24], __a[25], __a[26], __a[27],
2074 __a[28], __a[29], __a[30], __a[31], __b[0], __b[1], __b[2],
2075 __b[3], __b[4], __b[5], __b[6], __b[7], __b[8], __b[9],
2076 __b[10], __b[11], __b[12], __b[13], __b[14], __b[15], __b[16],
2077 __b[17], __b[18], __b[19], __b[20], __b[21], __b[22], __b[23],
2078 __b[24], __b[25], __b[26], __b[27], __b[28], __b[29], __b[30],
2084template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2085 struct _ZeroExtendProxy
2087 using value_type =
typename _TVT::value_type;
2088 static constexpr size_t _Np = _TVT::_S_full_size;
2091 template <
typename _To,
typename _ToVT = _VectorTraits<_To>,
2093 = enable_if_t<is_same_v<
typename _ToVT::value_type, value_type>>>
2094 _GLIBCXX_SIMD_INTRINSIC
operator _To()
const
2096 constexpr size_t _ToN = _ToVT::_S_full_size;
2097 if constexpr (_ToN == _Np)
2099 else if constexpr (_ToN == 2 * _Np)
2101#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_3
2102 if constexpr (__have_avx && _TVT::template _S_is<float, 4>)
2103 return __vector_bitcast<value_type>(
2104 _mm256_insertf128_ps(__m256(), __x, 0));
2105 else if constexpr (__have_avx && _TVT::template _S_is<double, 2>)
2106 return __vector_bitcast<value_type>(
2107 _mm256_insertf128_pd(__m256d(), __x, 0));
2108 else if constexpr (__have_avx2 && _Np *
sizeof(value_type) == 16)
2109 return __vector_bitcast<value_type>(
2110 _mm256_insertf128_si256(__m256i(), __to_intrin(__x), 0));
2111 else if constexpr (__have_avx512f && _TVT::template _S_is<float, 8>)
2113 if constexpr (__have_avx512dq)
2114 return __vector_bitcast<value_type>(
2115 _mm512_insertf32x8(__m512(), __x, 0));
2117 return reinterpret_cast<__m512
>(
2118 _mm512_insertf64x4(__m512d(),
2119 reinterpret_cast<__m256d
>(__x), 0));
2121 else if constexpr (__have_avx512f
2122 && _TVT::template _S_is<double, 4>)
2123 return __vector_bitcast<value_type>(
2124 _mm512_insertf64x4(__m512d(), __x, 0));
2125 else if constexpr (__have_avx512f && _Np *
sizeof(value_type) == 32)
2126 return __vector_bitcast<value_type>(
2127 _mm512_inserti64x4(__m512i(), __to_intrin(__x), 0));
2129 return __concat(__x, _Tp());
2131 else if constexpr (_ToN == 4 * _Np)
2133#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_3
2134 if constexpr (__have_avx512dq && _TVT::template _S_is<double, 2>)
2136 return __vector_bitcast<value_type>(
2137 _mm512_insertf64x2(__m512d(), __x, 0));
2139 else if constexpr (__have_avx512f
2140 && is_floating_point_v<value_type>)
2142 return __vector_bitcast<value_type>(
2143 _mm512_insertf32x4(__m512(),
reinterpret_cast<__m128
>(__x),
2146 else if constexpr (__have_avx512f && _Np *
sizeof(value_type) == 16)
2148 return __vector_bitcast<value_type>(
2149 _mm512_inserti32x4(__m512i(), __to_intrin(__x), 0));
2152 return __concat(__concat(__x, _Tp()),
2153 __vector_type_t<value_type, _Np * 2>());
2155 else if constexpr (_ToN == 8 * _Np)
2156 return __concat(
operator __vector_type_t<value_type, _Np * 4>(),
2157 __vector_type_t<value_type, _Np * 4>());
2158 else if constexpr (_ToN == 16 * _Np)
2159 return __concat(
operator __vector_type_t<value_type, _Np * 8>(),
2160 __vector_type_t<value_type, _Np * 8>());
2162 __assert_unreachable<_Tp>();
2166template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2167 _GLIBCXX_SIMD_INTRINSIC _ZeroExtendProxy<_Tp, _TVT>
2168 __zero_extend(_Tp __x)
2173template <
int _Offset,
2176 typename _TVT = _VectorTraits<_Tp>,
2177 typename _R = __vector_type_t<
typename _TVT::value_type,
2178 _TVT::_S_full_size / _SplitBy>>
2179 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2182 using value_type =
typename _TVT::value_type;
2183#if _GLIBCXX_SIMD_X86INTRIN
2184 if constexpr (
sizeof(_Tp) == 64 && _SplitBy == 4 && _Offset > 0)
2186 if constexpr (__have_avx512dq && is_same_v<double, value_type>)
2187 return _mm512_extractf64x2_pd(__to_intrin(__in), _Offset);
2188 else if constexpr (is_floating_point_v<value_type>)
2189 return __vector_bitcast<value_type>(
2190 _mm512_extractf32x4_ps(__intrin_bitcast<__m512>(__in), _Offset));
2192 return reinterpret_cast<_R
>(
2193 _mm512_extracti32x4_epi32(__intrin_bitcast<__m512i>(__in),
2199#ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_1
2201 is_floating_point_v<value_type>, double,
2203 static_assert(
sizeof(_R) %
sizeof(_W) == 0);
2204 constexpr int __return_width =
sizeof(_R) /
sizeof(_W);
2205 using _Up = __vector_type_t<_W, __return_width>;
2206 const auto __x = __vector_bitcast<_W>(__in);
2208 constexpr int __return_width = _TVT::_S_full_size / _SplitBy;
2210 const __vector_type_t<value_type, _TVT::_S_full_size>& __x
2213 constexpr int _O = _Offset * __return_width;
2214 return __call_with_subscripts<__return_width, _O>(
2215 __x, [](
auto... __entries) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
2216 return reinterpret_cast<_R
>(_Up{__entries...});
2223template <
typename _Tp,
2225 = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2226 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2230 __builtin_memcpy(&__r, &__x, 8);
2234template <
typename _Tp,
2236 = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2237 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2240 static_assert(
sizeof(_Tp) == 16,
"use __hi64z if you meant it");
2242 __builtin_memcpy(&__r,
reinterpret_cast<const char*
>(&__x) + 8, 8);
2246template <
typename _Tp,
2248 = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2249 _GLIBCXX_SIMD_INTRINSIC
constexpr _R
2250 __hi64z([[maybe_unused]] _Tp __x)
2253 if constexpr (
sizeof(_Tp) == 16)
2254 __builtin_memcpy(&__r,
reinterpret_cast<const char*
>(&__x) + 8, 8);
2260template <
typename _Tp>
2261 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2263 {
return __extract<0,
sizeof(_Tp) / 16>(__x); }
2265template <
typename _Tp>
2266 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2269 static_assert(
sizeof(__x) == 32);
2270 return __extract<1, 2>(__x);
2275template <
typename _Tp>
2276 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2279 static_assert(
sizeof(__x) == 64);
2280 return __extract<0, 2>(__x);
2283template <
typename _Tp>
2284 _GLIBCXX_SIMD_INTRINSIC
constexpr auto
2287 static_assert(
sizeof(__x) == 64);
2288 return __extract<1, 2>(__x);
2293template <
typename _Tp>
2296 static_assert(__is_vector_type_v<_Tp>);
2300 template <
typename _Up,
typename _UVT = _VectorTraits<_Up>>
2301 _GLIBCXX_SIMD_INTRINSIC
constexpr operator _Up()
const
2302 {
return __intrin_bitcast<typename _UVT::type>(__x); }
2305template <
typename _Tp>
2306 _GLIBCXX_SIMD_INTRINSIC
constexpr _AutoCast<_Tp>
2307 __auto_bitcast(
const _Tp& __x)
2310template <
typename _Tp,
size_t _Np>
2311 _GLIBCXX_SIMD_INTRINSIC
constexpr
2312 _AutoCast<typename _SimdWrapper<_Tp, _Np>::_BuiltinType>
2313 __auto_bitcast(
const _SimdWrapper<_Tp, _Np>& __x)
2314 {
return {__x._M_data}; }
2319#if _GLIBCXX_SIMD_HAVE_SSE_ABI
2321#if _GLIBCXX_SIMD_HAVE_AVX512F && _GLIBCXX_SIMD_X86INTRIN
2322template <
size_t _Size>
2323 struct __bool_storage_member_type
2325 static_assert((_Size & (_Size - 1)) != 0,
2326 "This trait may only be used for non-power-of-2 sizes. "
2327 "Power-of-2 sizes must be specialized.");
2329 typename __bool_storage_member_type<std::__bit_ceil(_Size)>::type;
2333 struct __bool_storage_member_type<1> {
using type = bool; };
2336 struct __bool_storage_member_type<2> {
using type = __mmask8; };
2339 struct __bool_storage_member_type<4> {
using type = __mmask8; };
2342 struct __bool_storage_member_type<8> {
using type = __mmask8; };
2345 struct __bool_storage_member_type<16> {
using type = __mmask16; };
2348 struct __bool_storage_member_type<32> {
using type = __mmask32; };
2351 struct __bool_storage_member_type<64> {
using type = __mmask64; };
2357#if _GLIBCXX_SIMD_HAVE_SSE
2358template <
typename _Tp,
size_t _Bytes>
2359 struct __intrinsic_type<_Tp, _Bytes,
2360 enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 64>>
2362 static_assert(!is_same_v<_Tp, long double>,
2363 "no __intrinsic_type support for long double on x86");
2365 static constexpr size_t _S_VBytes = _Bytes <= 16 ? 16
2369 using type [[__gnu__::__vector_size__(_S_VBytes)]]
2370 = conditional_t<is_integral_v<_Tp>,
long long int, _Tp>;
2377#if _GLIBCXX_SIMD_HAVE_NEON
2379 struct __intrinsic_type<float, 8, void>
2380 {
using type = float32x2_t; };
2383 struct __intrinsic_type<float, 16, void>
2384 {
using type = float32x4_t; };
2386#if _GLIBCXX_SIMD_HAVE_NEON_A64
2388 struct __intrinsic_type<double, 8, void>
2389 {
using type = float64x1_t; };
2392 struct __intrinsic_type<double, 16, void>
2393 {
using type = float64x2_t; };
2396#define _GLIBCXX_SIMD_ARM_INTRIN(_Bits, _Np) \
2398 struct __intrinsic_type<__int_with_sizeof_t<_Bits / 8>, \
2399 _Np * _Bits / 8, void> \
2400 { using type = int##_Bits##x##_Np##_t; }; \
2402 struct __intrinsic_type<make_unsigned_t<__int_with_sizeof_t<_Bits / 8>>, \
2403 _Np * _Bits / 8, void> \
2404 { using type = uint##_Bits##x##_Np##_t; }
2405_GLIBCXX_SIMD_ARM_INTRIN(8, 8);
2406_GLIBCXX_SIMD_ARM_INTRIN(8, 16);
2407_GLIBCXX_SIMD_ARM_INTRIN(16, 4);
2408_GLIBCXX_SIMD_ARM_INTRIN(16, 8);
2409_GLIBCXX_SIMD_ARM_INTRIN(32, 2);
2410_GLIBCXX_SIMD_ARM_INTRIN(32, 4);
2411_GLIBCXX_SIMD_ARM_INTRIN(64, 1);
2412_GLIBCXX_SIMD_ARM_INTRIN(64, 2);
2413#undef _GLIBCXX_SIMD_ARM_INTRIN
2415template <
typename _Tp,
size_t _Bytes>
2416 struct __intrinsic_type<_Tp, _Bytes,
2417 enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 16>>
2419 static constexpr int _SVecBytes = _Bytes <= 8 ? 8 : 16;
2420 using _Ip = __int_for_sizeof_t<_Tp>;
2422 is_floating_point_v<_Tp>, _Tp,
2423 conditional_t<is_unsigned_v<_Tp>, make_unsigned_t<_Ip>, _Ip>>;
2424 static_assert(!is_same_v<_Tp, _Up> || _SVecBytes != _Bytes,
2425 "should use explicit specialization above");
2426 using type =
typename __intrinsic_type<_Up, _SVecBytes>::type;
2433template <
typename _Tp>
2434 struct __intrinsic_type_impl;
2436#define _GLIBCXX_SIMD_PPC_INTRIN(_Tp) \
2438 struct __intrinsic_type_impl<_Tp> { using type = __vector _Tp; }
2439_GLIBCXX_SIMD_PPC_INTRIN(
float);
2441_GLIBCXX_SIMD_PPC_INTRIN(
double);
2443_GLIBCXX_SIMD_PPC_INTRIN(
signed char);
2444_GLIBCXX_SIMD_PPC_INTRIN(
unsigned char);
2445_GLIBCXX_SIMD_PPC_INTRIN(
signed short);
2446_GLIBCXX_SIMD_PPC_INTRIN(
unsigned short);
2447_GLIBCXX_SIMD_PPC_INTRIN(
signed int);
2448_GLIBCXX_SIMD_PPC_INTRIN(
unsigned int);
2449#if defined __VSX__ || __SIZEOF_LONG__ == 4
2450_GLIBCXX_SIMD_PPC_INTRIN(
signed long);
2451_GLIBCXX_SIMD_PPC_INTRIN(
unsigned long);
2454_GLIBCXX_SIMD_PPC_INTRIN(
signed long long);
2455_GLIBCXX_SIMD_PPC_INTRIN(
unsigned long long);
2457#undef _GLIBCXX_SIMD_PPC_INTRIN
2459template <
typename _Tp,
size_t _Bytes>
2460 struct __intrinsic_type<_Tp, _Bytes,
2461 enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 16>>
2463 static constexpr bool _S_is_ldouble = is_same_v<_Tp, long double>;
2465 static_assert(!(_S_is_ldouble &&
sizeof(
long double) >
sizeof(
double)),
2466 "no __intrinsic_type support for 128-bit floating point on PowerPC");
2468 static_assert(!(is_same_v<_Tp, double>
2469 || (_S_is_ldouble &&
sizeof(
long double) ==
sizeof(
double))),
2470 "no __intrinsic_type support for 64-bit floating point on PowerPC w/o VSX");
2473 typename __intrinsic_type_impl<
2474 conditional_t<is_floating_point_v<_Tp>,
2475 conditional_t<_S_is_ldouble, double, _Tp>,
2476 __int_for_sizeof_t<_Tp>>>::type;
2482template <
size_t _W
idth>
2483 struct _SimdWrapper<bool, _Width,
2484 void_t<typename __bool_storage_member_type<_Width>::type>>
2486 using _BuiltinType =
typename __bool_storage_member_type<_Width>::type;
2487 using value_type = bool;
2489 static constexpr size_t _S_full_size =
sizeof(_BuiltinType) * __CHAR_BIT__;
2491 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper<bool, _S_full_size>
2492 __as_full_vector()
const {
return _M_data; }
2494 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper() =
default;
2495 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper(_BuiltinType __k)
2498 _GLIBCXX_SIMD_INTRINSIC
operator const _BuiltinType&()
const
2501 _GLIBCXX_SIMD_INTRINSIC
operator _BuiltinType&()
2504 _GLIBCXX_SIMD_INTRINSIC _BuiltinType __intrin()
const
2507 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type operator[](
size_t __i)
const
2508 {
return _M_data & (_BuiltinType(1) << __i); }
2510 template <
size_t __i>
2511 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type
2512 operator[](_SizeConstant<__i>)
const
2513 {
return _M_data & (_BuiltinType(1) << __i); }
2515 _GLIBCXX_SIMD_INTRINSIC
constexpr void _M_set(
size_t __i, value_type __x)
2518 _M_data |= (_BuiltinType(1) << __i);
2520 _M_data &= ~(_BuiltinType(1) << __i);
2523 _GLIBCXX_SIMD_INTRINSIC
2524 constexpr bool _M_is_constprop()
const
2525 {
return __builtin_constant_p(_M_data); }
2527 _GLIBCXX_SIMD_INTRINSIC
constexpr bool _M_is_constprop_none_of()
const
2529 if (__builtin_constant_p(_M_data))
2531 constexpr int __nbits =
sizeof(_BuiltinType) * __CHAR_BIT__;
2532 constexpr _BuiltinType __active_mask
2533 = ~_BuiltinType() >> (__nbits - _Width);
2534 return (_M_data & __active_mask) == 0;
2539 _GLIBCXX_SIMD_INTRINSIC
constexpr bool _M_is_constprop_all_of()
const
2541 if (__builtin_constant_p(_M_data))
2543 constexpr int __nbits =
sizeof(_BuiltinType) * __CHAR_BIT__;
2544 constexpr _BuiltinType __active_mask
2545 = ~_BuiltinType() >> (__nbits - _Width);
2546 return (_M_data & __active_mask) == __active_mask;
2551 _BuiltinType _M_data;
2555template <
bool _MustZeroInitPadding,
typename _BuiltinType>
2556 struct _SimdWrapperBase;
2558template <
typename _BuiltinType>
2559 struct _SimdWrapperBase<false, _BuiltinType>
2561 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapperBase() =
default;
2562 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapperBase(_BuiltinType __init)
2566 _BuiltinType _M_data;
2569template <
typename _BuiltinType>
2570 struct _SimdWrapperBase<true, _BuiltinType>
2573 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapperBase() : _M_data() {}
2574 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapperBase(_BuiltinType __init)
2578 _BuiltinType _M_data;
2583template <
typename _Tp,
size_t _W
idth>
2584 struct _SimdWrapper<
2586 void_t<__vector_type_t<_Tp, _Width>, __intrinsic_type_t<_Tp, _Width>>>
2587 : _SimdWrapperBase<__has_iec559_behavior<__signaling_NaN, _Tp>::value
2588 && sizeof(_Tp) * _Width
2589 == sizeof(__vector_type_t<_Tp, _Width>),
2590 __vector_type_t<_Tp, _Width>>
2593 = _SimdWrapperBase<__has_iec559_behavior<__signaling_NaN, _Tp>::value
2594 &&
sizeof(_Tp) * _Width
2595 ==
sizeof(__vector_type_t<_Tp, _Width>),
2596 __vector_type_t<_Tp, _Width>>;
2598 static_assert(__is_vectorizable_v<_Tp>);
2599 static_assert(_Width >= 2);
2601 using _BuiltinType = __vector_type_t<_Tp, _Width>;
2602 using value_type = _Tp;
2604 static inline constexpr size_t _S_full_size
2605 =
sizeof(_BuiltinType) /
sizeof(value_type);
2606 static inline constexpr int _S_size = _Width;
2607 static inline constexpr bool _S_is_partial = _S_full_size != _S_size;
2609 using _Base::_M_data;
2611 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper<_Tp, _S_full_size>
2612 __as_full_vector()
const
2615 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper(initializer_list<_Tp> __init)
2616 : _Base(__generate_from_n_evaluations<_Width, _BuiltinType>(
2617 [&](auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { return __init.begin()[__i.value]; })) {}
2619 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper() =
default;
2620 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper(
const _SimdWrapper&)
2622 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper(_SimdWrapper&&) =
default;
2624 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper&
2625 operator=(
const _SimdWrapper&) =
default;
2626 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper&
2627 operator=(_SimdWrapper&&) =
default;
2629 template <
typename _V,
typename =
enable_if_t<disjunction_v<
2630 is_same<_V, __vector_type_t<_Tp, _Width>>,
2631 is_same<_V, __intrinsic_type_t<_Tp, _Width>>>>>
2632 _GLIBCXX_SIMD_INTRINSIC
constexpr _SimdWrapper(_V __x)
2634 : _Base(__vector_bitcast<_Tp, _Width>(__x)) {}
2636 template <
typename... _As,
2637 typename =
enable_if_t<((is_same_v<simd_abi::scalar, _As> && ...)
2638 &&
sizeof...(_As) <= _Width)>>
2639 _GLIBCXX_SIMD_INTRINSIC
constexpr
2640 operator _SimdTuple<_Tp, _As...>()
const
2642 return __generate_from_n_evaluations<
sizeof...(_As), _SimdTuple<_Tp, _As...>>(
2643 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
2644 {
return _M_data[int(__i)]; });
2647 _GLIBCXX_SIMD_INTRINSIC
constexpr operator const _BuiltinType&()
const
2650 _GLIBCXX_SIMD_INTRINSIC
constexpr operator _BuiltinType&()
2653 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp operator[](
size_t __i)
const
2654 {
return _M_data[__i]; }
2656 template <
size_t __i>
2657 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp operator[](_SizeConstant<__i>)
const
2658 {
return _M_data[__i]; }
2660 _GLIBCXX_SIMD_INTRINSIC
constexpr void _M_set(
size_t __i, _Tp __x)
2661 { _M_data[__i] = __x; }
2663 _GLIBCXX_SIMD_INTRINSIC
2664 constexpr bool _M_is_constprop()
const
2665 {
return __builtin_constant_p(_M_data); }
2667 _GLIBCXX_SIMD_INTRINSIC
constexpr bool _M_is_constprop_none_of()
const
2669 if (__builtin_constant_p(_M_data))
2672 if constexpr (is_floating_point_v<_Tp>)
2674 using _Ip = __int_for_sizeof_t<_Tp>;
2675 const auto __intdata = __vector_bitcast<_Ip>(_M_data);
2676 __execute_n_times<_Width>(
2677 [&](
auto __i) { __r &= __intdata[__i.value] == _Ip(); });
2680 __execute_n_times<_Width>(
2681 [&](
auto __i) { __r &= _M_data[__i.value] == _Tp(); });
2682 if (__builtin_constant_p(__r))
2688 _GLIBCXX_SIMD_INTRINSIC
constexpr bool _M_is_constprop_all_of()
const
2690 if (__builtin_constant_p(_M_data))
2693 if constexpr (is_floating_point_v<_Tp>)
2695 using _Ip = __int_for_sizeof_t<_Tp>;
2696 const auto __intdata = __vector_bitcast<_Ip>(_M_data);
2697 __execute_n_times<_Width>(
2698 [&](
auto __i) { __r &= __intdata[__i.value] == ~_Ip(); });
2701 __execute_n_times<_Width>(
2702 [&](
auto __i) { __r &= _M_data[__i.value] == ~_Tp(); });
2703 if (__builtin_constant_p(__r))
2713template <
typename _Tp>
2715 __vectorized_sizeof()
2717 if constexpr (!__is_vectorizable_v<_Tp>)
2720 if constexpr (
sizeof(_Tp) <= 8)
2723 if constexpr (__have_avx512bw)
2725 if constexpr (__have_avx512f &&
sizeof(_Tp) >= 4)
2727 if constexpr (__have_avx2)
2729 if constexpr (__have_avx && is_floating_point_v<_Tp>)
2731 if constexpr (__have_sse2)
2733 if constexpr (__have_sse && is_same_v<_Tp, float>)
2743 if constexpr (__have_power8vec
2744 || (__have_power_vmx && (
sizeof(_Tp) < 8))
2745 || (__have_power_vsx && is_floating_point_v<_Tp>) )
2749 if constexpr (__have_neon_a64
2750 || (__have_neon_a32 && !is_same_v<_Tp, double>) )
2752 if constexpr (__have_neon
2757 && (__support_neon_float || !is_floating_point_v<_Tp>))
2767template <
typename _Tp>
2768 inline constexpr int max_fixed_size
2769 = (__have_avx512bw &&
sizeof(_Tp) == 1) ? 64 : 32;
2772#if defined __x86_64__ || defined __aarch64__
2773template <
typename _Tp>
2774 using compatible =
conditional_t<(
sizeof(_Tp) <= 8), _VecBuiltin<16>, scalar>;
2775#elif defined __ARM_NEON
2778template <
typename _Tp>
2781 && (__support_neon_float || !is_floating_point_v<_Tp>)),
2782 _VecBuiltin<16>, scalar>;
2785 using compatible = scalar;
2790template <
typename _Tp>
2792 __determine_native_abi()
2794 constexpr size_t __bytes = __vectorized_sizeof<_Tp>();
2795 if constexpr (__bytes ==
sizeof(_Tp))
2796 return static_cast<scalar*
>(
nullptr);
2797 else if constexpr (__have_avx512vl || (__have_avx512f && __bytes == 64))
2798 return static_cast<_VecBltnBtmsk<__bytes>*
>(
nullptr);
2800 return static_cast<_VecBuiltin<__bytes>*
>(
nullptr);
2803template <
typename _Tp,
typename = enable_if_t<__is_vectorizable_v<_Tp>>>
2804 using native = remove_pointer_t<decltype(__determine_native_abi<_Tp>())>;
2808#if defined _GLIBCXX_SIMD_DEFAULT_ABI
2809template <
typename _Tp>
2810 using __default_abi = _GLIBCXX_SIMD_DEFAULT_ABI<_Tp>;
2812template <
typename _Tp>
2813 using __default_abi = compatible<_Tp>;
2821template <
typename _Tp,
typename =
void_t<>>
2824template <
typename _Tp>
2825 struct is_abi_tag<_Tp,
void_t<typename _Tp::_IsValidAbiTag>>
2826 :
public _Tp::_IsValidAbiTag {};
2828template <
typename _Tp>
2829 inline constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value;
2832template <
typename _Tp>
2835template <
typename _Tp>
2836 inline constexpr bool is_simd_v = is_simd<_Tp>::value;
2838template <
typename _Tp>
2841template <
typename _Tp>
2842inline constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value;
2845template <
typename _Tp,
typename _Abi,
typename =
void>
2846 struct __simd_size_impl {};
2848template <
typename _Tp,
typename _Abi>
2849 struct __simd_size_impl<
2851 enable_if_t<conjunction_v<__is_vectorizable<_Tp>, is_abi_tag<_Abi>>>>
2852 : _SizeConstant<_Abi::template _S_size<_Tp>> {};
2854template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2855 struct simd_size : __simd_size_impl<_Tp, _Abi> {};
2857template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2858 inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
2861template <
typename _Tp,
size_t _Np,
typename =
void>
2862 struct __deduce_impl;
2873template <
typename _Tp,
size_t _Np,
typename...>
2876template <
typename _Tp,
size_t _Np,
typename... _Abis>
2877 using deduce_t =
typename deduce<_Tp, _Np, _Abis...>::type;
2882template <
typename _Tp,
typename _V,
typename =
void>
2885template <
typename _Tp,
typename _Up,
typename _Abi>
2887 _Tp, simd<_Up, _Abi>,
2888 void_t<simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>>
2891 = simd<_Tp, simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>;
2894template <
typename _Tp,
typename _Up,
typename _Abi>
2896 _Tp, simd_mask<_Up, _Abi>,
2897 void_t<simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>>
2900 = simd_mask<_Tp, simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>;
2903template <
typename _Tp,
typename _V>
2904 using rebind_simd_t =
typename rebind_simd<_Tp, _V>::type;
2907template <
int _Np,
typename _V,
typename =
void>
2910template <
int _Np,
typename _Tp,
typename _Abi>
2911 struct resize_simd<_Np, simd<_Tp, _Abi>,
2912 void_t<simd_abi::deduce_t<_Tp, _Np, _Abi>>>
2913 {
using type = simd<_Tp, simd_abi::deduce_t<_Tp, _Np, _Abi>>; };
2915template <
int _Np,
typename _Tp,
typename _Abi>
2916 struct resize_simd<_Np, simd_mask<_Tp, _Abi>,
2917 void_t<simd_abi::deduce_t<_Tp, _Np, _Abi>>>
2918 {
using type = simd_mask<_Tp, simd_abi::deduce_t<_Tp, _Np, _Abi>>; };
2920template <
int _Np,
typename _V>
2921 using resize_simd_t =
typename resize_simd<_Np, _V>::type;
2925template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
2926 struct memory_alignment
2927 :
public _SizeConstant<vector_aligned_tag::_S_alignment<_Tp, _Up>> {};
2929template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
2930 inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value;
2933template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2936template <
typename _Tp,
typename _Abi>
2937 struct is_simd<simd<_Tp, _Abi>> :
public true_type {};
2939template <
typename _Tp>
2940 using native_simd = simd<_Tp, simd_abi::native<_Tp>>;
2942template <
typename _Tp,
int _Np>
2943 using fixed_size_simd = simd<_Tp, simd_abi::fixed_size<_Np>>;
2945template <
typename _Tp,
size_t _Np>
2946 using __deduced_simd = simd<_Tp, simd_abi::deduce_t<_Tp, _Np>>;
2949template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2952template <
typename _Tp,
typename _Abi>
2953 struct is_simd_mask<simd_mask<_Tp, _Abi>> :
public true_type {};
2955template <
typename _Tp>
2956 using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>;
2958template <
typename _Tp,
int _Np>
2959 using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>;
2961template <
typename _Tp,
size_t _Np>
2962 using __deduced_simd_mask = simd_mask<_Tp, simd_abi::deduce_t<_Tp, _Np>>;
2966template <
typename _Tp,
typename _Up,
typename _Ap,
bool = is_simd_v<_Tp>,
2968 struct __static_simd_cast_return_type;
2970template <
typename _Tp,
typename _A0,
typename _Up,
typename _Ap>
2971 struct __static_simd_cast_return_type<simd_mask<_Tp, _A0>, _Up, _Ap, false,
2973 : __static_simd_cast_return_type<simd<_Tp, _A0>, _Up, _Ap> {};
2975template <
typename _Tp,
typename _Up,
typename _Ap>
2976 struct __static_simd_cast_return_type<
2977 _Tp, _Up, _Ap, true,
enable_if_t<_Tp::size() == simd_size_v<_Up, _Ap>>>
2978 {
using type = _Tp; };
2980template <
typename _Tp,
typename _Ap>
2981 struct __static_simd_cast_return_type<_Tp, _Tp, _Ap, false,
2982#ifdef _GLIBCXX_SIMD_FIX_P2TS_ISSUE66
2988 {
using type = simd<_Tp, _Ap>; };
2990template <
typename _Tp,
typename =
void>
2991 struct __safe_make_signed {
using type = _Tp;};
2993template <
typename _Tp>
2994 struct __safe_make_signed<_Tp,
enable_if_t<is_integral_v<_Tp>>>
2997 using type = make_signed_t<make_unsigned_t<_Tp>>;
3000template <
typename _Tp>
3001 using safe_make_signed_t =
typename __safe_make_signed<_Tp>::type;
3003template <
typename _Tp,
typename _Up,
typename _Ap>
3004 struct __static_simd_cast_return_type<_Tp, _Up, _Ap, false,
3005#ifdef _GLIBCXX_SIMD_FIX_P2TS_ISSUE66
3013 (is_integral_v<_Up> && is_integral_v<_Tp> &&
3014#ifndef _GLIBCXX_SIMD_FIX_P2TS_ISSUE65
3015 is_signed_v<_Up> != is_signed_v<_Tp> &&
3017 is_same_v<safe_make_signed_t<_Up>, safe_make_signed_t<_Tp>>),
3018 simd<_Tp, _Ap>, fixed_size_simd<_Tp, simd_size_v<_Up, _Ap>>>;
3021template <
typename _Tp,
typename _Up,
typename _Ap,
3023 =
typename __static_simd_cast_return_type<_Tp, _Up, _Ap>::type>
3024 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _R
3025 static_simd_cast(
const simd<_Up, _Ap>& __x)
3027 if constexpr (is_same<_R, simd<_Up, _Ap>>::value)
3031 _SimdConverter<_Up, _Ap, typename _R::value_type, typename _R::abi_type>
3033 return _R(__private_init, __c(__data(__x)));
3037namespace __proposed {
3038template <
typename _Tp,
typename _Up,
typename _Ap,
3040 =
typename __static_simd_cast_return_type<_Tp, _Up, _Ap>::type>
3041 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
typename _R::mask_type
3042 static_simd_cast(
const simd_mask<_Up, _Ap>& __x)
3044 using _RM =
typename _R::mask_type;
3045 return {__private_init, _RM::abi_type::_MaskImpl::template _S_convert<
3046 typename _RM::simd_type::value_type>(__x)};
3049template <
typename _To,
typename _Up,
typename _Abi>
3050 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3052 simd_bit_cast(
const simd<_Up, _Abi>& __x)
3054 using _Tp =
typename _To::value_type;
3055 using _ToMember =
typename _SimdTraits<_Tp, typename _To::abi_type>::_SimdMember;
3056 using _From = simd<_Up, _Abi>;
3057 using _FromMember =
typename _SimdTraits<_Up, _Abi>::_SimdMember;
3059 static_assert(
sizeof(_To) ==
sizeof(_From));
3060 static_assert(is_trivially_copyable_v<_Tp> && is_trivially_copyable_v<_Up>);
3061 static_assert(is_trivially_copyable_v<_ToMember> && is_trivially_copyable_v<_FromMember>);
3062#if __has_builtin(__builtin_bit_cast)
3063 return {__private_init, __builtin_bit_cast(_ToMember, __data(__x))};
3065 return {__private_init, __bit_cast<_ToMember>(__data(__x))};
3069template <
typename _To,
typename _Up,
typename _Abi>
3070 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3072 simd_bit_cast(
const simd_mask<_Up, _Abi>& __x)
3074 using _From = simd_mask<_Up, _Abi>;
3075 static_assert(
sizeof(_To) ==
sizeof(_From));
3076 static_assert(is_trivially_copyable_v<_From>);
3079 if constexpr (is_simd_v<_To>)
3081 using _Tp =
typename _To::value_type;
3082 using _ToMember =
typename _SimdTraits<_Tp, typename _To::abi_type>::_SimdMember;
3083 static_assert(is_trivially_copyable_v<_ToMember>);
3084#if __has_builtin(__builtin_bit_cast)
3085 return {__private_init, __builtin_bit_cast(_ToMember, __x)};
3087 return {__private_init, __bit_cast<_ToMember>(__x)};
3092 static_assert(is_trivially_copyable_v<_To>);
3093#if __has_builtin(__builtin_bit_cast)
3094 return __builtin_bit_cast(_To, __x);
3096 return __bit_cast<_To>(__x);
3103template <
typename _Tp,
typename _Up,
typename _Ap,
3104 typename _To = __value_type_or_identity_t<_Tp>>
3105 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
auto
3106 simd_cast(
const simd<_ValuePreserving<_Up, _To>, _Ap>& __x)
3107 ->
decltype(static_simd_cast<_Tp>(__x))
3108 {
return static_simd_cast<_Tp>(__x); }
3110namespace __proposed {
3111template <
typename _Tp,
typename _Up,
typename _Ap,
3112 typename _To = __value_type_or_identity_t<_Tp>>
3113 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
auto
3114 simd_cast(
const simd_mask<_ValuePreserving<_Up, _To>, _Ap>& __x)
3115 ->
decltype(static_simd_cast<_Tp>(__x))
3116 {
return static_simd_cast<_Tp>(__x); }
3121namespace __proposed {
3148template <
typename _Tp,
typename _Up,
typename _Ap>
3149 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
enable_if_t<
3150 conjunction_v<is_simd<_Tp>, is_same<typename _Tp::value_type, _Up>>, _Tp>
3151 resizing_simd_cast(
const simd<_Up, _Ap>& __x)
3153 if constexpr (is_same_v<typename _Tp::abi_type, _Ap>)
3155 else if constexpr (simd_size_v<_Up, _Ap> == 1)
3161 else if constexpr (_Tp::size() == 1)
3163 else if constexpr (
sizeof(_Tp) ==
sizeof(__x)
3164 && !__is_fixed_size_abi_v<_Ap>)
3165 return {__private_init,
3166 __vector_bitcast<typename _Tp::value_type, _Tp::size()>(
3167 _Ap::_S_masked(__data(__x))._M_data)};
3171 __builtin_memcpy(&__data(__r), &__data(__x),
3173 *
std::min(_Tp::size(), simd_size_v<_Up, _Ap>));
3178template <
typename _Tp,
typename _Up,
typename _Ap>
3179 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3180 enable_if_t<is_simd_mask_v<_Tp>, _Tp>
3181 resizing_simd_cast(
const simd_mask<_Up, _Ap>& __x)
3183 return {__private_init, _Tp::abi_type::_MaskImpl::template _S_convert<
3184 typename _Tp::simd_type::value_type>(__x)};
3190template <
typename _Tp,
int _Np>
3191 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd<_Tp, _Np>
3192 to_fixed_size(
const fixed_size_simd<_Tp, _Np>& __x)
3195template <
typename _Tp,
int _Np>
3196 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd_mask<_Tp, _Np>
3197 to_fixed_size(
const fixed_size_simd_mask<_Tp, _Np>& __x)
3200template <
typename _Tp,
typename _Ap>
3201 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd<_Tp, simd_size_v<_Tp, _Ap>>
3202 to_fixed_size(
const simd<_Tp, _Ap>& __x)
3204 using _Rp = fixed_size_simd<_Tp, simd_size_v<_Tp, _Ap>>;
3205 return _Rp([&__x](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3208template <
typename _Tp,
typename _Ap>
3209 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd_mask<_Tp, simd_size_v<_Tp, _Ap>>
3210 to_fixed_size(
const simd_mask<_Tp, _Ap>& __x)
3212 return {__private_init,
3213 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; }};
3217template <
typename _Tp,
int _Np>
3218 _GLIBCXX_SIMD_INTRINSIC
3219 enable_if_t<(_Np == native_simd<_Tp>::size()), native_simd<_Tp>>
3220 to_native(
const fixed_size_simd<_Tp, _Np>& __x)
3222 alignas(memory_alignment_v<native_simd<_Tp>>) _Tp __mem[_Np];
3223 __x.copy_to(__mem, vector_aligned);
3224 return {__mem, vector_aligned};
3227template <
typename _Tp,
size_t _Np>
3228 _GLIBCXX_SIMD_INTRINSIC
3229 enable_if_t<(_Np == native_simd_mask<_Tp>::size()), native_simd_mask<_Tp>>
3230 to_native(
const fixed_size_simd_mask<_Tp, _Np>& __x)
3232 return native_simd_mask<_Tp>(
3234 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3238template <
typename _Tp,
size_t _Np>
3239 _GLIBCXX_SIMD_INTRINSIC
enable_if_t<(_Np == simd<_Tp>::size()), simd<_Tp>>
3240 to_compatible(
const simd<_Tp, simd_abi::fixed_size<_Np>>& __x)
3242 alignas(memory_alignment_v<simd<_Tp>>) _Tp __mem[_Np];
3243 __x.copy_to(__mem, vector_aligned);
3244 return {__mem, vector_aligned};
3247template <
typename _Tp,
size_t _Np>
3248 _GLIBCXX_SIMD_INTRINSIC
3249 enable_if_t<(_Np == simd_mask<_Tp>::size()), simd_mask<_Tp>>
3250 to_compatible(
const simd_mask<_Tp, simd_abi::fixed_size<_Np>>& __x)
3252 return simd_mask<_Tp>(
3253 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3260template <
typename _M,
typename _Tp>
3261 class const_where_expression
3264 static_assert(is_same_v<_V, __remove_cvref_t<_Tp>>);
3266 struct _Wrapper {
using value_type = _V; };
3269 using _Impl =
typename _V::_Impl;
3272 typename conditional_t<is_arithmetic_v<_V>, _Wrapper, _V>::value_type;
3274 _GLIBCXX_SIMD_INTRINSIC
friend const _M&
3275 __get_mask(
const const_where_expression& __x)
3276 {
return __x._M_k; }
3278 _GLIBCXX_SIMD_INTRINSIC
friend const _Tp&
3279 __get_lvalue(
const const_where_expression& __x)
3280 {
return __x._M_value; }
3286 const_where_expression(
const const_where_expression&) =
delete;
3287 const_where_expression& operator=(
const const_where_expression&) =
delete;
3289 _GLIBCXX_SIMD_INTRINSIC const_where_expression(
const _M& __kk,
const _Tp& dd)
3290 : _M_k(__kk), _M_value(const_cast<_Tp&>(dd)) {}
3292 _GLIBCXX_SIMD_INTRINSIC _V
3295 return {__private_init,
3296 _Impl::template _S_masked_unary<negate>(__data(_M_k),
3300 template <
typename _Up,
typename _Flags>
3301 [[nodiscard]] _GLIBCXX_SIMD_INTRINSIC _V
3302 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _Flags)
const&&
3304 return {__private_init,
3305 _Impl::_S_masked_load(__data(_M_value), __data(_M_k),
3306 _Flags::template _S_apply<_V>(__mem))};
3309 template <
typename _Up,
typename _Flags>
3310 _GLIBCXX_SIMD_INTRINSIC
void
3311 copy_to(_LoadStorePtr<_Up, value_type>* __mem, _Flags)
const&&
3313 _Impl::_S_masked_store(__data(_M_value),
3314 _Flags::template _S_apply<_V>(__mem),
3320template <
typename _Tp>
3321 class const_where_expression<bool, _Tp>
3326 static_assert(is_same_v<_V, __remove_cvref_t<_Tp>>);
3328 struct _Wrapper {
using value_type = _V; };
3332 typename conditional_t<is_arithmetic_v<_V>, _Wrapper, _V>::value_type;
3334 _GLIBCXX_SIMD_INTRINSIC
friend const _M&
3335 __get_mask(
const const_where_expression& __x)
3336 {
return __x._M_k; }
3338 _GLIBCXX_SIMD_INTRINSIC
friend const _Tp&
3339 __get_lvalue(
const const_where_expression& __x)
3340 {
return __x._M_value; }
3346 const_where_expression(
const const_where_expression&) =
delete;
3347 const_where_expression& operator=(
const const_where_expression&) =
delete;
3349 _GLIBCXX_SIMD_INTRINSIC const_where_expression(
const bool __kk,
const _Tp& dd)
3350 : _M_k(__kk), _M_value(const_cast<_Tp&>(dd)) {}
3352 _GLIBCXX_SIMD_INTRINSIC _V
operator-() const&&
3353 {
return _M_k ? -_M_value : _M_value; }
3355 template <
typename _Up,
typename _Flags>
3356 [[nodiscard]] _GLIBCXX_SIMD_INTRINSIC _V
3357 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _Flags)
const&&
3358 {
return _M_k ?
static_cast<_V
>(__mem[0]) : _M_value; }
3360 template <
typename _Up,
typename _Flags>
3361 _GLIBCXX_SIMD_INTRINSIC
void
3362 copy_to(_LoadStorePtr<_Up, value_type>* __mem, _Flags)
const&&
3365 __mem[0] = _M_value;
3370template <
typename _M,
typename _Tp>
3371 class where_expression :
public const_where_expression<_M, _Tp>
3373 using _Impl =
typename const_where_expression<_M, _Tp>::_Impl;
3375 static_assert(!is_const<_Tp>::value,
3376 "where_expression may only be instantiated with __a non-const "
3379 using typename const_where_expression<_M, _Tp>::value_type;
3380 using const_where_expression<_M, _Tp>::_M_k;
3381 using const_where_expression<_M, _Tp>::_M_value;
3384 is_same<typename _M::abi_type, typename _Tp::abi_type>::value,
"");
3385 static_assert(_M::size() == _Tp::size(),
"");
3387 _GLIBCXX_SIMD_INTRINSIC
friend _Tp& __get_lvalue(where_expression& __x)
3388 {
return __x._M_value; }
3391 where_expression(
const where_expression&) =
delete;
3392 where_expression& operator=(
const where_expression&) =
delete;
3394 _GLIBCXX_SIMD_INTRINSIC where_expression(
const _M& __kk, _Tp& dd)
3395 : const_where_expression<_M, _Tp>(__kk, dd) {}
3397 template <
typename _Up>
3398 _GLIBCXX_SIMD_INTRINSIC
void operator=(_Up&& __x) &&
3400 _Impl::_S_masked_assign(__data(_M_k), __data(_M_value),
3401 __to_value_type_or_member_type<_Tp>(
3402 static_cast<_Up&&
>(__x)));
3405#define _GLIBCXX_SIMD_OP_(__op, __name) \
3406 template <typename _Up> \
3407 _GLIBCXX_SIMD_INTRINSIC void operator __op##=(_Up&& __x)&& \
3409 _Impl::template _S_masked_cassign( \
3410 __data(_M_k), __data(_M_value), \
3411 __to_value_type_or_member_type<_Tp>(static_cast<_Up&&>(__x)), \
3412 [](auto __impl, auto __lhs, auto __rhs) \
3413 constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA \
3414 { return __impl.__name(__lhs, __rhs); }); \
3417 _GLIBCXX_SIMD_OP_(+, _S_plus);
3418 _GLIBCXX_SIMD_OP_(-, _S_minus);
3419 _GLIBCXX_SIMD_OP_(*, _S_multiplies);
3420 _GLIBCXX_SIMD_OP_(/, _S_divides);
3421 _GLIBCXX_SIMD_OP_(%, _S_modulus);
3422 _GLIBCXX_SIMD_OP_(&, _S_bit_and);
3423 _GLIBCXX_SIMD_OP_(|, _S_bit_or);
3424 _GLIBCXX_SIMD_OP_(^, _S_bit_xor);
3425 _GLIBCXX_SIMD_OP_(<<, _S_shift_left);
3426 _GLIBCXX_SIMD_OP_(>>, _S_shift_right);
3427#undef _GLIBCXX_SIMD_OP_
3429 _GLIBCXX_SIMD_INTRINSIC
void operator++() &&
3432 = _Impl::template _S_masked_unary<__increment>(__data(_M_k),
3436 _GLIBCXX_SIMD_INTRINSIC
void operator++(
int) &&
3439 = _Impl::template _S_masked_unary<__increment>(__data(_M_k),
3443 _GLIBCXX_SIMD_INTRINSIC
void operator--() &&
3446 = _Impl::template _S_masked_unary<__decrement>(__data(_M_k),
3450 _GLIBCXX_SIMD_INTRINSIC
void operator--(
int) &&
3453 = _Impl::template _S_masked_unary<__decrement>(__data(_M_k),
3458 template <
typename _Up,
typename _Flags>
3459 _GLIBCXX_SIMD_INTRINSIC
void
3460 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _Flags) &&
3463 = _Impl::_S_masked_load(__data(_M_value), __data(_M_k),
3464 _Flags::template _S_apply<_Tp>(__mem));
3469template <
typename _Tp>
3470 class where_expression<bool, _Tp> :
public const_where_expression<bool, _Tp>
3473 using typename const_where_expression<_M, _Tp>::value_type;
3474 using const_where_expression<_M, _Tp>::_M_k;
3475 using const_where_expression<_M, _Tp>::_M_value;
3478 where_expression(
const where_expression&) =
delete;
3479 where_expression& operator=(
const where_expression&) =
delete;
3481 _GLIBCXX_SIMD_INTRINSIC where_expression(
const _M& __kk, _Tp& dd)
3482 : const_where_expression<_M, _Tp>(__kk, dd) {}
3484#define _GLIBCXX_SIMD_OP_(__op) \
3485 template <typename _Up> \
3486 _GLIBCXX_SIMD_INTRINSIC void operator __op(_Up&& __x)&& \
3487 { if (_M_k) _M_value __op static_cast<_Up&&>(__x); }
3489 _GLIBCXX_SIMD_OP_(=)
3490 _GLIBCXX_SIMD_OP_(+=)
3491 _GLIBCXX_SIMD_OP_(-=)
3492 _GLIBCXX_SIMD_OP_(*=)
3493 _GLIBCXX_SIMD_OP_(/=)
3494 _GLIBCXX_SIMD_OP_(%=)
3495 _GLIBCXX_SIMD_OP_(&=)
3496 _GLIBCXX_SIMD_OP_(|=)
3497 _GLIBCXX_SIMD_OP_(^=)
3498 _GLIBCXX_SIMD_OP_(<<=)
3499 _GLIBCXX_SIMD_OP_(>>=)
3500 #undef _GLIBCXX_SIMD_OP_
3502 _GLIBCXX_SIMD_INTRINSIC
void operator++() &&
3503 {
if (_M_k) ++_M_value; }
3505 _GLIBCXX_SIMD_INTRINSIC
void operator++(
int) &&
3506 {
if (_M_k) ++_M_value; }
3508 _GLIBCXX_SIMD_INTRINSIC
void operator--() &&
3509 {
if (_M_k) --_M_value; }
3511 _GLIBCXX_SIMD_INTRINSIC
void operator--(
int) &&
3512 {
if (_M_k) --_M_value; }
3515 template <
typename _Up,
typename _Flags>
3516 _GLIBCXX_SIMD_INTRINSIC
void
3517 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _Flags) &&
3518 {
if (_M_k) _M_value = __mem[0]; }
3522template <
typename _Tp,
typename _Ap>
3523 _GLIBCXX_SIMD_INTRINSIC where_expression<simd_mask<_Tp, _Ap>, simd<_Tp, _Ap>>
3524 where(
const typename simd<_Tp, _Ap>::mask_type& __k, simd<_Tp, _Ap>& __value)
3525 {
return {__k, __value}; }
3527template <
typename _Tp,
typename _Ap>
3528 _GLIBCXX_SIMD_INTRINSIC
3529 const_where_expression<simd_mask<_Tp, _Ap>, simd<_Tp, _Ap>>
3530 where(
const typename simd<_Tp, _Ap>::mask_type& __k,
3531 const simd<_Tp, _Ap>& __value)
3532 {
return {__k, __value}; }
3534template <
typename _Tp,
typename _Ap>
3535 _GLIBCXX_SIMD_INTRINSIC
3536 where_expression<simd_mask<_Tp, _Ap>, simd_mask<_Tp, _Ap>>
3537 where(
const remove_const_t<simd_mask<_Tp, _Ap>>& __k,
3538 simd_mask<_Tp, _Ap>& __value)
3539 {
return {__k, __value}; }
3541template <
typename _Tp,
typename _Ap>
3542 _GLIBCXX_SIMD_INTRINSIC
3543 const_where_expression<simd_mask<_Tp, _Ap>, simd_mask<_Tp, _Ap>>
3544 where(
const remove_const_t<simd_mask<_Tp, _Ap>>& __k,
3545 const simd_mask<_Tp, _Ap>& __value)
3546 {
return {__k, __value}; }
3548template <
typename _Tp>
3549 _GLIBCXX_SIMD_INTRINSIC where_expression<bool, _Tp>
3550 where(_ExactBool __k, _Tp& __value)
3551 {
return {__k, __value}; }
3553template <
typename _Tp>
3554 _GLIBCXX_SIMD_INTRINSIC const_where_expression<bool, _Tp>
3555 where(_ExactBool __k,
const _Tp& __value)
3556 {
return {__k, __value}; }
3558 template <
typename _Tp,
typename _Ap>
3559 void where(
bool __k, simd<_Tp, _Ap>& __value) =
delete;
3561 template <
typename _Tp,
typename _Ap>
3562 void where(
bool __k,
const simd<_Tp, _Ap>& __value) =
delete;
3565namespace __proposed {
3566template <
size_t _Np>
3569 const bitset<_Np> __bits;
3572 where_range(bitset<_Np> __b) : __bits(__b) {}
3579 _GLIBCXX_SIMD_INTRINSIC
void __next_bit()
3580 { __bit = __builtin_ctzl(__mask); }
3582 _GLIBCXX_SIMD_INTRINSIC
void __reset_lsb()
3585 __mask &= (__mask - 1);
3590 iterator(
decltype(__mask) __m) : __mask(__m) { __next_bit(); }
3591 iterator(
const iterator&) =
default;
3592 iterator(iterator&&) =
default;
3594 _GLIBCXX_SIMD_ALWAYS_INLINE
size_t operator->()
const
3597 _GLIBCXX_SIMD_ALWAYS_INLINE
size_t operator*()
const
3600 _GLIBCXX_SIMD_ALWAYS_INLINE iterator& operator++()
3607 _GLIBCXX_SIMD_ALWAYS_INLINE iterator operator++(
int)
3609 iterator __tmp = *
this;
3615 _GLIBCXX_SIMD_ALWAYS_INLINE
bool operator==(
const iterator& __rhs)
const
3616 {
return __mask == __rhs.__mask; }
3618 _GLIBCXX_SIMD_ALWAYS_INLINE
bool operator!=(
const iterator& __rhs)
const
3619 {
return __mask != __rhs.__mask; }
3622 iterator begin()
const
3623 {
return __bits.to_ullong(); }
3625 iterator end()
const
3629template <
typename _Tp,
typename _Ap>
3630 where_range<simd_size_v<_Tp, _Ap>>
3631 where(
const simd_mask<_Tp, _Ap>& __k)
3632 {
return __k.__to_bitset(); }
3638template <
typename _Tp,
typename _Abi,
typename _BinaryOperation = plus<>>
3639 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3640 reduce(
const simd<_Tp, _Abi>& __v,
3641 _BinaryOperation __binary_op = _BinaryOperation())
3642 {
return _Abi::_SimdImpl::_S_reduce(__v, __binary_op); }
3644template <
typename _M,
typename _V,
typename _BinaryOperation = plus<>>
3645 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3646 reduce(
const const_where_expression<_M, _V>& __x,
3647 typename _V::value_type __identity_element,
3648 _BinaryOperation __binary_op)
3650 if (__builtin_expect(none_of(__get_mask(__x)),
false))
3651 return __identity_element;
3653 _V __tmp = __identity_element;
3654 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3655 __data(__get_lvalue(__x)));
3656 return reduce(__tmp, __binary_op);
3659template <
typename _M,
typename _V>
3660 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3661 reduce(
const const_where_expression<_M, _V>& __x, plus<> __binary_op = {})
3662 {
return reduce(__x, 0, __binary_op); }
3664template <
typename _M,
typename _V>
3665 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3666 reduce(
const const_where_expression<_M, _V>& __x, multiplies<> __binary_op)
3667 {
return reduce(__x, 1, __binary_op); }
3669template <
typename _M,
typename _V>
3670 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3671 reduce(
const const_where_expression<_M, _V>& __x, bit_and<> __binary_op)
3672 {
return reduce(__x, ~
typename _V::value_type(), __binary_op); }
3674template <
typename _M,
typename _V>
3675 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3676 reduce(
const const_where_expression<_M, _V>& __x, bit_or<> __binary_op)
3677 {
return reduce(__x, 0, __binary_op); }
3679template <
typename _M,
typename _V>
3680 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3681 reduce(
const const_where_expression<_M, _V>& __x, bit_xor<> __binary_op)
3682 {
return reduce(__x, 0, __binary_op); }
3684template <
typename _Tp,
typename _Abi>
3685 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3686 hmin(
const simd<_Tp, _Abi>& __v)
noexcept
3688 return _Abi::_SimdImpl::_S_reduce(__v, __detail::_Minimum());
3691template <
typename _Tp,
typename _Abi>
3692 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3693 hmax(
const simd<_Tp, _Abi>& __v)
noexcept
3695 return _Abi::_SimdImpl::_S_reduce(__v, __detail::_Maximum());
3698template <
typename _M,
typename _V>
3699 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3700 typename _V::value_type
3701 hmin(
const const_where_expression<_M, _V>& __x)
noexcept
3703 using _Tp =
typename _V::value_type;
3704 constexpr _Tp __id_elem =
3705#ifdef __FINITE_MATH_ONLY__
3706 __finite_max_v<_Tp>;
3708 __value_or<__infinity, _Tp>(__finite_max_v<_Tp>);
3710 _V __tmp = __id_elem;
3711 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3712 __data(__get_lvalue(__x)));
3713 return _V::abi_type::_SimdImpl::_S_reduce(__tmp, __detail::_Minimum());
3716template <
typename _M,
typename _V>
3717 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3718 typename _V::value_type
3719 hmax(
const const_where_expression<_M, _V>& __x)
noexcept
3721 using _Tp =
typename _V::value_type;
3722 constexpr _Tp __id_elem =
3723#ifdef __FINITE_MATH_ONLY__
3724 __finite_min_v<_Tp>;
3727 if constexpr (__value_exists_v<__infinity, _Tp>)
3728 return -__infinity_v<_Tp>;
3730 return __finite_min_v<_Tp>;
3733 _V __tmp = __id_elem;
3734 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3735 __data(__get_lvalue(__x)));
3736 return _V::abi_type::_SimdImpl::_S_reduce(__tmp, __detail::_Maximum());
3741template <
typename _Tp,
typename _Ap>
3742 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3743 min(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3744 {
return {__private_init, _Ap::_SimdImpl::_S_min(__data(__a), __data(__b))}; }
3746template <
typename _Tp,
typename _Ap>
3747 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3748 max(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3749 {
return {__private_init, _Ap::_SimdImpl::_S_max(__data(__a), __data(__b))}; }
3751template <
typename _Tp,
typename _Ap>
3752 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3753 pair<simd<_Tp, _Ap>, simd<_Tp, _Ap>>
3754 minmax(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3756 const auto pair_of_members
3757 = _Ap::_SimdImpl::_S_minmax(__data(__a), __data(__b));
3758 return {simd<_Tp, _Ap>(__private_init, pair_of_members.first),
3759 simd<_Tp, _Ap>(__private_init, pair_of_members.second)};
3762template <
typename _Tp,
typename _Ap>
3763 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3764 clamp(
const simd<_Tp, _Ap>& __v,
const simd<_Tp, _Ap>& __lo,
3765 const simd<_Tp, _Ap>& __hi)
3767 using _Impl =
typename _Ap::_SimdImpl;
3768 return {__private_init,
3769 _Impl::_S_min(__data(__hi),
3770 _Impl::_S_max(__data(__lo), __data(__v)))};
3775template <
size_t... _Sizes,
typename _Tp,
typename _Ap,
3776 typename =
enable_if_t<((_Sizes + ...) == simd<_Tp, _Ap>::size())>>
3777 inline tuple<simd<_Tp, simd_abi::deduce_t<_Tp, _Sizes>>...>
3778 split(
const simd<_Tp, _Ap>&);
3781template <
int _Index,
int _Total,
int _Combine = 1,
typename _Tp,
size_t _Np>
3782 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_CONST
3783 _SimdWrapper<_Tp, _Np / _Total * _Combine>
3784 __extract_part(
const _SimdWrapper<_Tp, _Np> __x);
3786template <
int _Index,
int _Parts,
int _Combine = 1,
typename _Tp,
typename _A0,
3788 _GLIBCXX_SIMD_INTRINSIC
auto
3789 __extract_part(
const _SimdTuple<_Tp, _A0, _As...>& __x);
3793template <
size_t _V0,
size_t... _Values>
3796 template <
size_t _I>
3797 static constexpr size_t _S_at(_SizeConstant<_I> = {})
3799 if constexpr (_I == 0)
3802 return _SizeList<_Values...>::template _S_at<_I - 1>();
3805 template <
size_t _I>
3806 static constexpr auto _S_before(_SizeConstant<_I> = {})
3808 if constexpr (_I == 0)
3809 return _SizeConstant<0>();
3811 return _SizeConstant<
3812 _V0 + _SizeList<_Values...>::template _S_before<_I - 1>()>();
3815 template <
size_t _Np>
3816 static constexpr auto _S_pop_front(_SizeConstant<_Np> = {})
3818 if constexpr (_Np == 0)
3821 return _SizeList<_Values...>::template _S_pop_front<_Np - 1>();
3827template <
typename _Tp,
size_t _Np>
3828 _GLIBCXX_SIMD_INTRINSIC _SimdWrapper<_Tp, _Np / 2>
3829 __extract_center(_SimdWrapper<_Tp, _Np> __x)
3831 static_assert(_Np >= 4);
3832 static_assert(_Np % 4 == 0);
3833#if _GLIBCXX_SIMD_X86INTRIN
3834 if constexpr (__have_avx512f &&
sizeof(_Tp) * _Np == 64)
3836 const auto __intrin = __to_intrin(__x);
3837 if constexpr (is_integral_v<_Tp>)
3838 return __vector_bitcast<_Tp>(_mm512_castsi512_si256(
3839 _mm512_shuffle_i32x4(__intrin, __intrin,
3840 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
3841 else if constexpr (
sizeof(_Tp) == 4)
3842 return __vector_bitcast<_Tp>(_mm512_castps512_ps256(
3843 _mm512_shuffle_f32x4(__intrin, __intrin,
3844 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
3845 else if constexpr (
sizeof(_Tp) == 8)
3846 return __vector_bitcast<_Tp>(_mm512_castpd512_pd256(
3847 _mm512_shuffle_f64x2(__intrin, __intrin,
3848 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
3850 __assert_unreachable<_Tp>();
3852 else if constexpr (
sizeof(_Tp) * _Np == 32 && is_floating_point_v<_Tp>)
3853 return __vector_bitcast<_Tp>(
3854 _mm_shuffle_pd(__lo128(__vector_bitcast<double>(__x)),
3855 __hi128(__vector_bitcast<double>(__x)), 1));
3856 else if constexpr (
sizeof(__x) == 32 &&
sizeof(_Tp) * _Np <= 32)
3857 return __vector_bitcast<_Tp>(
3858 _mm_alignr_epi8(__hi128(__vector_bitcast<_LLong>(__x)),
3859 __lo128(__vector_bitcast<_LLong>(__x)),
3860 sizeof(_Tp) * _Np / 4));
3864 __vector_type_t<_Tp, _Np / 2> __r;
3865 __builtin_memcpy(&__r,
3866 reinterpret_cast<const char*
>(&__x)
3867 +
sizeof(_Tp) * _Np / 4,
3868 sizeof(_Tp) * _Np / 2);
3873template <
typename _Tp,
typename _A0,
typename... _As>
3874 _GLIBCXX_SIMD_INTRINSIC
3875 _SimdWrapper<_Tp, _SimdTuple<_Tp, _A0, _As...>::_S_size() / 2>
3876 __extract_center(
const _SimdTuple<_Tp, _A0, _As...>& __x)
3878 if constexpr (
sizeof...(_As) == 0)
3879 return __extract_center(__x.first);
3881 return __extract_part<1, 4, 2>(__x);
3886template <
size_t... _Sizes,
typename _Tp,
typename... _As>
3888 __split_wrapper(_SizeList<_Sizes...>,
const _SimdTuple<_Tp, _As...>& __x)
3890 return split<_Sizes...>(
3891 fixed_size_simd<_Tp, _SimdTuple<_Tp, _As...>::_S_size()>(__private_init,
3898template <
typename _V,
typename _Ap,
3899 size_t _Parts = simd_size_v<typename _V::value_type, _Ap> / _V::size()>
3900 enable_if_t<simd_size_v<typename _V::value_type, _Ap> == _Parts * _V::size()
3901 && is_simd_v<_V>, array<_V, _Parts>>
3902 split(
const simd<typename _V::value_type, _Ap>& __x)
3904 using _Tp =
typename _V::value_type;
3905 if constexpr (_Parts == 1)
3907 return {simd_cast<_V>(__x)};
3909 else if (__x._M_is_constprop())
3911 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3912 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3913 return _V([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
3914 {
return __x[__i * _V::size() + __j]; });
3918 __is_fixed_size_abi_v<_Ap>
3919 && (is_same_v<typename _V::abi_type, simd_abi::scalar>
3920 || (__is_fixed_size_abi_v<typename _V::abi_type>
3921 &&
sizeof(_V) ==
sizeof(_Tp) * _V::size()
3925#ifdef _GLIBCXX_SIMD_USE_ALIASING_LOADS
3926 const __may_alias<_Tp>*
const __element_ptr
3927 =
reinterpret_cast<const __may_alias<_Tp>*
>(&__data(__x));
3928 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3929 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
3930 {
return _V(__element_ptr + __i * _V::size(), vector_aligned); });
3932 const auto& __xx = __data(__x);
3933 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3934 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3935 [[maybe_unused]]
constexpr size_t __offset
3936 =
decltype(__i)::value * _V::size();
3937 return _V([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3938 constexpr _SizeConstant<__j + __offset> __k;
3944 else if constexpr (is_same_v<typename _V::abi_type, simd_abi::scalar>)
3947 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3948 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
return __x[__i]; });
3952 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3953 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3954 if constexpr (__is_fixed_size_abi_v<typename _V::abi_type>)
3955 return _V([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3956 return __x[__i * _V::size() + __j];
3959 return _V(__private_init,
3960 __extract_part<
decltype(__i)::value, _Parts>(__data(__x)));
3967template <
typename _V,
typename _Ap,
3969 = simd_size_v<typename _V::simd_type::value_type, _Ap> / _V::size()>
3970 enable_if_t<is_simd_mask_v<_V> && simd_size_v<
typename
3971 _V::simd_type::value_type, _Ap> == _Parts * _V::size(), array<_V, _Parts>>
3972 split(
const simd_mask<typename _V::simd_type::value_type, _Ap>& __x)
3974 if constexpr (is_same_v<_Ap, typename _V::abi_type>)
3976 else if constexpr (_Parts == 1)
3977 return {__proposed::static_simd_cast<_V>(__x)};
3978 else if constexpr (_Parts == 2 && __is_sse_abi<typename _V::abi_type>()
3979 && __is_avx_abi<_Ap>())
3980 return {_V(__private_init, __lo128(__data(__x))),
3981 _V(__private_init, __hi128(__data(__x)))};
3982 else if constexpr (_V::size() <= __CHAR_BIT__ *
sizeof(_ULLong))
3984 const bitset __bits = __x.__to_bitset();
3985 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3986 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3987 constexpr size_t __offset = __i * _V::size();
3988 return _V(__bitset_init, (__bits >> __offset).to_ullong());
3993 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>(
3994 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3995 constexpr size_t __offset = __i * _V::size();
3996 return _V(__private_init,
3997 [&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
3998 return __x[__j + __offset];
4006template <
size_t... _Sizes,
typename _Tp,
typename _Ap,
typename>
4007 _GLIBCXX_SIMD_ALWAYS_INLINE
4008 tuple<simd<_Tp, simd_abi::deduce_t<_Tp, _Sizes>>...>
4009 split(
const simd<_Tp, _Ap>& __x)
4011 using _SL = _SizeList<_Sizes...>;
4012 using _Tuple = tuple<__deduced_simd<_Tp, _Sizes>...>;
4013 constexpr size_t _Np = simd_size_v<_Tp, _Ap>;
4014 constexpr size_t _N0 = _SL::template _S_at<0>();
4015 using _V = __deduced_simd<_Tp, _N0>;
4017 if (__x._M_is_constprop())
4018 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>(
4019 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4020 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4021 constexpr size_t __offset = _SL::_S_before(__i);
4022 return _Vi([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4023 return __x[__offset + __j];
4026 else if constexpr (_Np == _N0)
4028 static_assert(
sizeof...(_Sizes) == 1);
4029 return {simd_cast<_V>(__x)};
4032 (__is_fixed_size_abi_v<
4033 _Ap> && __fixed_size_storage_t<_Tp, _Np>::_S_first_size == _N0)
4036 !__is_fixed_size_abi_v<typename _V::abi_type>,
4037 "How can <_Tp, _Np> be __a single _SimdTuple entry but __a "
4043 __split_wrapper(_SL::template _S_pop_front<1>(),
4044 __data(__x).second));
4046 else if constexpr ((!is_same_v<simd_abi::scalar,
4047 simd_abi::deduce_t<_Tp, _Sizes>> && ...)
4048 && (!__is_fixed_size_abi_v<
4049 simd_abi::deduce_t<_Tp, _Sizes>> && ...))
4051 if constexpr (((_Sizes * 2 == _Np) && ...))
4052 return {{__private_init, __extract_part<0, 2>(__data(__x))},
4053 {__private_init, __extract_part<1, 2>(__data(__x))}};
4054 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4055 _SizeList<_Np / 3, _Np / 3, _Np / 3>>)
4056 return {{__private_init, __extract_part<0, 3>(__data(__x))},
4057 {__private_init, __extract_part<1, 3>(__data(__x))},
4058 {__private_init, __extract_part<2, 3>(__data(__x))}};
4059 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4060 _SizeList<2 * _Np / 3, _Np / 3>>)
4061 return {{__private_init, __extract_part<0, 3, 2>(__data(__x))},
4062 {__private_init, __extract_part<2, 3>(__data(__x))}};
4063 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4064 _SizeList<_Np / 3, 2 * _Np / 3>>)
4065 return {{__private_init, __extract_part<0, 3>(__data(__x))},
4066 {__private_init, __extract_part<1, 3, 2>(__data(__x))}};
4067 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4068 _SizeList<_Np / 2, _Np / 4, _Np / 4>>)
4069 return {{__private_init, __extract_part<0, 2>(__data(__x))},
4070 {__private_init, __extract_part<2, 4>(__data(__x))},
4071 {__private_init, __extract_part<3, 4>(__data(__x))}};
4072 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4073 _SizeList<_Np / 4, _Np / 4, _Np / 2>>)
4074 return {{__private_init, __extract_part<0, 4>(__data(__x))},
4075 {__private_init, __extract_part<1, 4>(__data(__x))},
4076 {__private_init, __extract_part<1, 2>(__data(__x))}};
4077 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4078 _SizeList<_Np / 4, _Np / 2, _Np / 4>>)
4079 return {{__private_init, __extract_part<0, 4>(__data(__x))},
4080 {__private_init, __extract_center(__data(__x))},
4081 {__private_init, __extract_part<3, 4>(__data(__x))}};
4082 else if constexpr (((_Sizes * 4 == _Np) && ...))
4083 return {{__private_init, __extract_part<0, 4>(__data(__x))},
4084 {__private_init, __extract_part<1, 4>(__data(__x))},
4085 {__private_init, __extract_part<2, 4>(__data(__x))},
4086 {__private_init, __extract_part<3, 4>(__data(__x))}};
4089#ifdef _GLIBCXX_SIMD_USE_ALIASING_LOADS
4090 const __may_alias<_Tp>*
const __element_ptr
4091 =
reinterpret_cast<const __may_alias<_Tp>*
>(&__x);
4092 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>(
4093 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4094 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4095 constexpr size_t __offset = _SL::_S_before(__i);
4096 constexpr size_t __base_align =
alignof(simd<_Tp, _Ap>);
4097 constexpr size_t __a
4098 = __base_align - ((__offset *
sizeof(_Tp)) % __base_align);
4099 constexpr size_t __b = ((__a - 1) & __a) ^ __a;
4100 constexpr size_t __alignment = __b == 0 ? __a : __b;
4101 return _Vi(__element_ptr + __offset, overaligned<__alignment>);
4104 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>(
4105 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4106 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4107 const auto& __xx = __data(__x);
4108 using _Offset =
decltype(_SL::_S_before(__i));
4109 return _Vi([&](
auto __j)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4110 constexpr _SizeConstant<_Offset::value + __j> __k;
4120template <
size_t _I,
typename _Tp,
typename _Ap,
typename... _As>
4121 _GLIBCXX_SIMD_INTRINSIC
constexpr _Tp
4122 __subscript_in_pack(
const simd<_Tp, _Ap>& __x,
const simd<_Tp, _As>&... __xs)
4124 if constexpr (_I < simd_size_v<_Tp, _Ap>)
4127 return __subscript_in_pack<_I - simd_size_v<_Tp, _Ap>>(__xs...);
4132template <
typename _Tp,
typename _A0,
typename... _As>
4133 _GLIBCXX_SIMD_INTRINSIC
void
4134 __store_pack_of_simd(
char* __mem,
const simd<_Tp, _A0>& __x0,
4135 const simd<_Tp, _As>&... __xs)
4137 constexpr size_t __n_bytes =
sizeof(_Tp) * simd_size_v<_Tp, _A0>;
4138 __builtin_memcpy(__mem, &__data(__x0), __n_bytes);
4139 if constexpr (
sizeof...(__xs) > 0)
4140 __store_pack_of_simd(__mem + __n_bytes, __xs...);
4145template <
typename _Tp,
typename... _As,
typename = __detail::__odr_helper>
4146 inline _GLIBCXX_SIMD_CONSTEXPR
4147 simd<_Tp, simd_abi::deduce_t<_Tp, (simd_size_v<_Tp, _As> + ...)>>
4148 concat(
const simd<_Tp, _As>&... __xs)
4150 using _Rp = __deduced_simd<_Tp, (simd_size_v<_Tp, _As> + ...)>;
4151 if constexpr (
sizeof...(__xs) == 1)
4152 return simd_cast<_Rp>(__xs...);
4153 else if ((... && __xs._M_is_constprop()))
4155 simd_abi::deduce_t<_Tp, (simd_size_v<_Tp, _As> + ...)>>(
4156 [&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA
4157 {
return __subscript_in_pack<__i>(__xs...); });
4161 __store_pack_of_simd(
reinterpret_cast<char*
>(&__data(__r)), __xs...);
4168template <
typename _Tp,
typename _Abi,
size_t _Np>
4169 _GLIBCXX_SIMD_ALWAYS_INLINE
4170 _GLIBCXX_SIMD_CONSTEXPR __deduced_simd<_Tp, simd_size_v<_Tp, _Abi> * _Np>
4171 concat(
const array<simd<_Tp, _Abi>, _Np>& __x)
4173 return __call_with_subscripts<_Np>(
4174 __x, [](
const auto&... __xs) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4175 return concat(__xs...);
4183template <
typename _Up,
typename _Accessor = _Up,
4184 typename _ValueType =
typename _Up::value_type>
4185 class _SmartReference
4191 _GLIBCXX_SIMD_INTRINSIC
constexpr _ValueType _M_read() const noexcept
4193 if constexpr (is_arithmetic_v<_Up>)
4196 return _M_obj[_M_index];
4199 template <
typename _Tp>
4200 _GLIBCXX_SIMD_INTRINSIC
constexpr void _M_write(_Tp&& __x)
const
4201 { _Accessor::_S_set(_M_obj, _M_index,
static_cast<_Tp&&
>(__x)); }
4204 _GLIBCXX_SIMD_INTRINSIC
constexpr
4205 _SmartReference(_Up& __o,
int __i) noexcept
4206 : _M_index(__i), _M_obj(__o) {}
4208 using value_type = _ValueType;
4210 _GLIBCXX_SIMD_INTRINSIC _SmartReference(
const _SmartReference&) =
delete;
4212 _GLIBCXX_SIMD_INTRINSIC
constexpr operator value_type() const noexcept
4213 {
return _M_read(); }
4215 template <
typename _Tp,
4217 = _ValuePreservingOrInt<__remove_cvref_t<_Tp>, value_type>>
4218 _GLIBCXX_SIMD_INTRINSIC
constexpr _SmartReference operator=(_Tp&& __x) &&
4220 _M_write(
static_cast<_Tp&&
>(__x));
4221 return {_M_obj, _M_index};
4224#define _GLIBCXX_SIMD_OP_(__op) \
4225 template <typename _Tp, \
4227 = decltype(declval<value_type>() __op declval<_Tp>()), \
4228 typename = _ValuePreservingOrInt<__remove_cvref_t<_Tp>, _TT>, \
4229 typename = _ValuePreservingOrInt<_TT, value_type>> \
4230 _GLIBCXX_SIMD_INTRINSIC constexpr _SmartReference \
4231 operator __op##=(_Tp&& __x) && \
4233 const value_type& __lhs = _M_read(); \
4234 _M_write(__lhs __op __x); \
4235 return {_M_obj, _M_index}; \
4237 _GLIBCXX_SIMD_ALL_ARITHMETICS(_GLIBCXX_SIMD_OP_);
4238 _GLIBCXX_SIMD_ALL_SHIFTS(_GLIBCXX_SIMD_OP_);
4239 _GLIBCXX_SIMD_ALL_BINARY(_GLIBCXX_SIMD_OP_);
4240#undef _GLIBCXX_SIMD_OP_
4242 template <
typename _Tp = void,
4244 =
decltype(++declval<conditional_t<true, value_type, _Tp>&>())>
4245 _GLIBCXX_SIMD_INTRINSIC
constexpr _SmartReference operator++() &&
4247 value_type __x = _M_read();
4249 return {_M_obj, _M_index};
4252 template <
typename _Tp = void,
4254 =
decltype(declval<conditional_t<true, value_type, _Tp>&>()++)>
4255 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type operator++(
int) &&
4257 const value_type __r = _M_read();
4258 value_type __x = __r;
4263 template <
typename _Tp = void,
4265 =
decltype(--declval<conditional_t<true, value_type, _Tp>&>())>
4266 _GLIBCXX_SIMD_INTRINSIC
constexpr _SmartReference operator--() &&
4268 value_type __x = _M_read();
4270 return {_M_obj, _M_index};
4273 template <
typename _Tp = void,
4275 =
decltype(declval<conditional_t<true, value_type, _Tp>&>()--)>
4276 _GLIBCXX_SIMD_INTRINSIC
constexpr value_type operator--(
int) &&
4278 const value_type __r = _M_read();
4279 value_type __x = __r;
4284 _GLIBCXX_SIMD_INTRINSIC
friend void
4285 swap(_SmartReference&& __a, _SmartReference&& __b)
noexcept(
4287 is_nothrow_constructible<value_type, _SmartReference&&>,
4288 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4290 value_type __tmp =
static_cast<_SmartReference&&
>(__a);
4291 static_cast<_SmartReference&&
>(__a) =
static_cast<value_type
>(__b);
4292 static_cast<_SmartReference&&
>(__b) =
std::move(__tmp);
4295 _GLIBCXX_SIMD_INTRINSIC
friend void
4296 swap(value_type& __a, _SmartReference&& __b)
noexcept(
4298 is_nothrow_constructible<value_type, value_type&&>,
4299 is_nothrow_assignable<value_type&, value_type&&>,
4300 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4303 __a =
static_cast<value_type
>(__b);
4304 static_cast<_SmartReference&&
>(__b) =
std::move(__tmp);
4307 _GLIBCXX_SIMD_INTRINSIC
friend void
4308 swap(_SmartReference&& __a, value_type& __b)
noexcept(
4310 is_nothrow_constructible<value_type, _SmartReference&&>,
4311 is_nothrow_assignable<value_type&, value_type&&>,
4312 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4314 value_type __tmp(__a);
4315 static_cast<_SmartReference&&
>(__a) =
std::move(__b);
4322template <
int _Bytes>
4323 struct __scalar_abi_wrapper
4325 template <
typename _Tp>
static constexpr size_t _S_full_size = 1;
4326 template <
typename _Tp>
static constexpr size_t _S_size = 1;
4327 template <
typename _Tp>
static constexpr size_t _S_is_partial =
false;
4329 template <
typename _Tp,
typename _Abi = simd_abi::scalar>
4330 static constexpr bool _S_is_valid_v
4331 = _Abi::template _IsValid<_Tp>::value &&
sizeof(_Tp) == _Bytes;
4336template <
typename _Tp>
4337 struct __decay_abi {
using type = _Tp; };
4339template <
int _Bytes>
4340 struct __decay_abi<__scalar_abi_wrapper<_Bytes>>
4341 {
using type = simd_abi::scalar; };
4349template <
template <
int>
class _Abi,
int _Bytes,
typename _Tp>
4350 struct __find_next_valid_abi
4352 static constexpr auto _S_choose()
4354 constexpr int _NextBytes = std::__bit_ceil(_Bytes) / 2;
4355 using _NextAbi = _Abi<_NextBytes>;
4356 if constexpr (_NextBytes <
sizeof(_Tp) * 2)
4357 return _Abi<_Bytes>();
4358 else if constexpr (_NextAbi::template _S_is_partial<_Tp> ==
false
4359 && _NextAbi::template _S_is_valid_v<_Tp>)
4362 return __find_next_valid_abi<_Abi, _NextBytes, _Tp>::_S_choose();
4365 using type =
decltype(_S_choose());
4368template <
int _Bytes,
typename _Tp>
4369 struct __find_next_valid_abi<__scalar_abi_wrapper, _Bytes, _Tp>
4370 {
using type = simd_abi::scalar; };
4373template <
template <
int>
class...>
4376 template <
typename,
int>
static constexpr bool _S_has_valid_abi =
false;
4377 template <
typename,
int>
using _FirstValidAbi = void;
4378 template <
typename,
int>
using _BestAbi = void;
4381template <
template <
int>
class _A0,
template <
int>
class... _Rest>
4382 struct _AbiList<_A0, _Rest...>
4384 template <
typename _Tp,
int _Np>
4385 static constexpr bool _S_has_valid_abi
4386 = _A0<
sizeof(_Tp) * _Np>::template _S_is_valid_v<
4387 _Tp> || _AbiList<_Rest...>::template _S_has_valid_abi<_Tp, _Np>;
4389 template <
typename _Tp,
int _Np>
4391 _A0<
sizeof(_Tp) * _Np>::template _S_is_valid_v<_Tp>,
4392 typename __decay_abi<_A0<
sizeof(_Tp) * _Np>>::type,
4393 typename _AbiList<_Rest...>::template _FirstValidAbi<_Tp, _Np>>;
4395 template <
typename _Tp,
int _Np>
4396 static constexpr auto _S_determine_best_abi()
4398 static_assert(_Np >= 1);
4399 constexpr int _Bytes =
sizeof(_Tp) * _Np;
4400 if constexpr (_Np == 1)
4401 return __make_dependent_t<_Tp, simd_abi::scalar>{};
4404 constexpr int __fullsize = _A0<_Bytes>::template _S_full_size<_Tp>;
4409 if constexpr (_A0<_Bytes>::template _S_is_valid_v<
4410 _Tp> && __fullsize / 2 < _Np)
4411 return typename __decay_abi<_A0<_Bytes>>::type{};
4415 typename __find_next_valid_abi<_A0, _Bytes, _Tp>::type;
4416 if constexpr (_Bp::template _S_is_valid_v<
4417 _Tp> && _Bp::template _S_size<_Tp> <= _Np)
4421 typename _AbiList<_Rest...>::template _BestAbi<_Tp, _Np>{};
4426 template <
typename _Tp,
int _Np>
4427 using _BestAbi =
decltype(_S_determine_best_abi<_Tp, _Np>());
4435using _AllNativeAbis = _AbiList<simd_abi::_VecBltnBtmsk, simd_abi::_VecBuiltin,
4436 __scalar_abi_wrapper>;
4439template <
typename _Tp,
typename _Abi>
4440 struct _SimdTraits<_Tp, _Abi,
void_t<typename _Abi::template _IsValid<_Tp>>>
4441 : _Abi::template __traits<_Tp> {};
4445template <
typename _Tp,
size_t _Np>
4446 struct __deduce_impl<
4447 _Tp, _Np,
enable_if_t<_AllNativeAbis::template _S_has_valid_abi<_Tp, _Np>>>
4448 {
using type = _AllNativeAbis::_FirstValidAbi<_Tp, _Np>; };
4451template <
typename _Tp,
size_t _Np,
typename =
void>
4452 struct __deduce_fixed_size_fallback {};
4454template <
typename _Tp,
size_t _Np>
4455 struct __deduce_fixed_size_fallback<_Tp, _Np,
4456 enable_if_t<simd_abi::fixed_size<_Np>::template _S_is_valid_v<_Tp>>>
4457 {
using type = simd_abi::fixed_size<_Np>; };
4459template <
typename _Tp,
size_t _Np,
typename>
4460 struct __deduce_impl :
public __deduce_fixed_size_fallback<_Tp, _Np> {};
4466template <
typename _Tp,
typename _Abi>
4467 class simd_mask :
public _SimdTraits<_Tp, _Abi>::_MaskBase
4470 using _Traits = _SimdTraits<_Tp, _Abi>;
4471 using _MemberType =
typename _Traits::_MaskMember;
4477 using _Ip = __int_for_sizeof_t<_Tp>;
4478 static constexpr _Ip* _S_type_tag =
nullptr;
4480 friend typename _Traits::_MaskBase;
4481 friend class simd<_Tp, _Abi>;
4482 friend typename _Traits::_SimdImpl;
4485 using _Impl =
typename _Traits::_MaskImpl;
4490 using value_type = bool;
4491 using reference = _SmartReference<_MemberType, _Impl, value_type>;
4492 using simd_type = simd<_Tp, _Abi>;
4493 using abi_type = _Abi;
4496 static constexpr size_t size()
4497 {
return __size_or_zero_v<_Tp, _Abi>; }
4501 simd_mask() =
default;
4502 simd_mask(
const simd_mask&) =
default;
4503 simd_mask(simd_mask&&) =
default;
4504 simd_mask& operator=(
const simd_mask&) =
default;
4505 simd_mask& operator=(simd_mask&&) =
default;
4509 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit
4510 simd_mask(
typename _Traits::_MaskCastType __init)
4511 : _M_data{__init} {}
4520 _GLIBCXX_SIMD_ALWAYS_INLINE
static simd_mask
4521 __from_bitset(bitset<size()> bs)
4522 {
return {__bitset_init, bs}; }
4524 _GLIBCXX_SIMD_ALWAYS_INLINE bitset<size()>
4526 {
return _Impl::_S_to_bits(_M_data)._M_to_bitset(); }
4530 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
4531 simd_mask(value_type __x)
4532 : _M_data(_Impl::template _S_broadcast<_Ip>(__x)) {}
4536 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4538 template <
typename _Up,
typename _A2,
4539 typename = enable_if_t<simd_size_v<_Up, _A2> == size()>>
4540 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit(
sizeof(_MemberType)
4541 !=
sizeof(
typename _SimdTraits<_Up, _A2>::_MaskMember))
4542 simd_mask(
const simd_mask<_Up, _A2>& __x)
4543 : simd_mask(__proposed::static_simd_cast<simd_mask>(__x)) {}
4546 template <
typename _Up,
typename =
enable_if_t<conjunction<
4547 is_same<abi_type, simd_abi::fixed_size<size()>>,
4548 is_same<_Up, _Up>>::value>>
4549 _GLIBCXX_SIMD_ALWAYS_INLINE
4550 simd_mask(
const simd_mask<_Up, simd_abi::fixed_size<size()>>& __x)
4551 : _M_data(_Impl::_S_from_bitmask(__data(__x), _S_type_tag)) {}
4556 template <
typename _Flags>
4557 _GLIBCXX_SIMD_ALWAYS_INLINE
4558 simd_mask(
const value_type* __mem, _Flags)
4559 : _M_data(_Impl::template _S_load<_Ip>(
4560 _Flags::template _S_apply<simd_mask>(__mem))) {}
4562 template <
typename _Flags>
4563 _GLIBCXX_SIMD_ALWAYS_INLINE
4564 simd_mask(
const value_type* __mem, simd_mask __k, _Flags)
4568 = _Impl::_S_masked_load(_M_data, __k._M_data,
4569 _Flags::template _S_apply<simd_mask>(__mem));
4574 template <
typename _Flags>
4575 _GLIBCXX_SIMD_ALWAYS_INLINE
void
4576 copy_from(
const value_type* __mem, _Flags)
4578 _M_data = _Impl::template _S_load<_Ip>(
4579 _Flags::template _S_apply<simd_mask>(__mem));
4584 template <
typename _Flags>
4585 _GLIBCXX_SIMD_ALWAYS_INLINE
void
4586 copy_to(value_type* __mem, _Flags)
const
4587 { _Impl::_S_store(_M_data, _Flags::template _S_apply<simd_mask>(__mem)); }
4591 _GLIBCXX_SIMD_ALWAYS_INLINE reference
4592 operator[](
size_t __i)
4595 __invoke_ub(
"Subscript %d is out of range [0, %d]", __i, size() - 1);
4596 return {_M_data, int(__i)};
4599 _GLIBCXX_SIMD_ALWAYS_INLINE value_type
4600 operator[](
size_t __i)
const
4603 __invoke_ub(
"Subscript %d is out of range [0, %d]", __i, size() - 1);
4604 if constexpr (__is_scalar_abi<_Abi>())
4607 return static_cast<bool>(_M_data[__i]);
4612 _GLIBCXX_SIMD_ALWAYS_INLINE simd_mask
4614 {
return {__private_init, _Impl::_S_bit_not(_M_data)}; }
4618 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4620 template <
typename _Up,
typename _A2,
4622 = enable_if_t<is_convertible_v<simd_mask<_Up, _A2>, simd_mask>>>
4623 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4624 operator&&(
const simd_mask& __x,
const simd_mask<_Up, _A2>& __y)
4626 return {__private_init,
4627 _Impl::_S_logical_and(__x._M_data, simd_mask(__y)._M_data)};
4630 template <
typename _Up,
typename _A2,
4632 = enable_if_t<is_convertible_v<simd_mask<_Up, _A2>, simd_mask>>>
4633 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4634 operator||(
const simd_mask& __x,
const simd_mask<_Up, _A2>& __y)
4636 return {__private_init,
4637 _Impl::_S_logical_or(__x._M_data, simd_mask(__y)._M_data)};
4641 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4642 operator&&(
const simd_mask& __x,
const simd_mask& __y)
4644 return {__private_init, _Impl::_S_logical_and(__x._M_data, __y._M_data)};
4647 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4648 operator||(
const simd_mask& __x,
const simd_mask& __y)
4650 return {__private_init, _Impl::_S_logical_or(__x._M_data, __y._M_data)};
4653 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4654 operator&(
const simd_mask& __x,
const simd_mask& __y)
4655 {
return {__private_init, _Impl::_S_bit_and(__x._M_data, __y._M_data)}; }
4657 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4658 operator|(
const simd_mask& __x,
const simd_mask& __y)
4659 {
return {__private_init, _Impl::_S_bit_or(__x._M_data, __y._M_data)}; }
4661 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4662 operator^(
const simd_mask& __x,
const simd_mask& __y)
4663 {
return {__private_init, _Impl::_S_bit_xor(__x._M_data, __y._M_data)}; }
4665 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask&
4666 operator&=(simd_mask& __x,
const simd_mask& __y)
4668 __x._M_data = _Impl::_S_bit_and(__x._M_data, __y._M_data);
4672 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask&
4673 operator|=(simd_mask& __x,
const simd_mask& __y)
4675 __x._M_data = _Impl::_S_bit_or(__x._M_data, __y._M_data);
4679 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask&
4680 operator^=(simd_mask& __x,
const simd_mask& __y)
4682 __x._M_data = _Impl::_S_bit_xor(__x._M_data, __y._M_data);
4688 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4689 operator==(
const simd_mask& __x,
const simd_mask& __y)
4690 {
return !operator!=(__x, __y); }
4692 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4693 operator!=(
const simd_mask& __x,
const simd_mask& __y)
4694 {
return {__private_init, _Impl::_S_bit_xor(__x._M_data, __y._M_data)}; }
4698 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
4699 simd_mask(_PrivateInit,
typename _Traits::_MaskMember __init)
4700 : _M_data(__init) {}
4704 template <typename _Fp, typename = decltype(bool(declval<_Fp>()(size_t())))>
4705 _GLIBCXX_SIMD_INTRINSIC
constexpr
4706 simd_mask(_PrivateInit, _Fp&& __gen)
4709 __execute_n_times<size()>([&](
auto __i)
constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4710 _Impl::_S_set(_M_data, __i, __gen(__i));
4716 _GLIBCXX_SIMD_INTRINSIC simd_mask(_BitsetInit, bitset<size()> __init)
4718 _Impl::_S_from_bitmask(_SanitizedBitMask<size()>(__init), _S_type_tag))
4729 template <
typename _Up,
typename _A2,
4731 = enable_if_t<simd_size_v<_Up, _A2> == simd_size_v<_Tp, _Abi>>>
4732 _GLIBCXX_SIMD_ALWAYS_INLINE
4733 operator simd_mask<_Up, _A2>() &&
4735 using namespace std::experimental::__proposed;
4736 return static_simd_cast<simd_mask<_Up, _A2>>(_M_data);
4739 const simd_mask<_Tp, _Abi>& _M_data;
4742 _GLIBCXX_SIMD_INTRINSIC _CvtProxy
4748 #ifdef __GXX_CONDITIONAL_IS_OVERLOADABLE__
4749 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4750 operator?:(
const simd_mask& __k,
const simd_mask& __where_true,
4751 const simd_mask& __where_false)
4753 auto __ret = __where_false;
4754 _Impl::_S_masked_assign(__k._M_data, __ret._M_data, __where_true._M_data);
4758 template <
typename _U1,
typename _U2,
4759 typename _Rp = simd<common_type_t<_U1, _U2>, _Abi>,
4761 is_convertible<_U1, _Rp>, is_convertible<_U2, _Rp>,
4762 is_convertible<simd_mask, typename _Rp::mask_type>>>>
4763 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend _Rp
4764 operator?:(
const simd_mask& __k,
const _U1& __where_true,
4765 const _U2& __where_false)
4767 _Rp __ret = __where_false;
4768 _Rp::_Impl::_S_masked_assign(
4769 __data(
static_cast<typename _Rp::mask_type
>(__k)), __data(__ret),
4770 __data(
static_cast<_Rp
>(__where_true)));
4774 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4775 template <
typename _Kp,
typename _Ak,
typename _Up,
typename _Au,
4777 conjunction_v<is_convertible<simd_mask<_Kp, _Ak>, simd_mask>,
4778 is_convertible<simd_mask<_Up, _Au>, simd_mask>>>>
4779 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4780 operator?:(
const simd_mask<_Kp, _Ak>& __k,
const simd_mask& __where_true,
4781 const simd_mask<_Up, _Au>& __where_false)
4783 simd_mask __ret = __where_false;
4784 _Impl::_S_masked_assign(simd_mask(__k)._M_data, __ret._M_data,
4785 __where_true._M_data);
4793 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
4794 _M_is_constprop()
const
4796 if constexpr (__is_scalar_abi<_Abi>())
4797 return __builtin_constant_p(_M_data);
4799 return _M_data._M_is_constprop();
4805 friend const auto& __data<_Tp, abi_type>(
const simd_mask&);
4806 friend auto& __data<_Tp, abi_type>(simd_mask&);
4807 alignas(_Traits::_S_mask_align) _MemberType _M_data;
4814template <
typename _Tp,
typename _Ap>
4815 _GLIBCXX_SIMD_INTRINSIC
constexpr const auto&
4816 __data(
const simd_mask<_Tp, _Ap>& __x)
4817 {
return __x._M_data; }
4819template <
typename _Tp,
typename _Ap>
4820 _GLIBCXX_SIMD_INTRINSIC
constexpr auto&
4821 __data(simd_mask<_Tp, _Ap>& __x)
4822 {
return __x._M_data; }
4828template <
typename _Tp,
typename _Abi>
4829 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4830 all_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
4832 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4834 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
4840 return _Abi::_MaskImpl::_S_all_of(__k);
4843template <
typename _Tp,
typename _Abi>
4844 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4845 any_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
4847 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4849 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
4855 return _Abi::_MaskImpl::_S_any_of(__k);
4858template <
typename _Tp,
typename _Abi>
4859 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4860 none_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
4862 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4864 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
4870 return _Abi::_MaskImpl::_S_none_of(__k);
4873template <
typename _Tp,
typename _Abi>
4874 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4875 some_of(
const simd_mask<_Tp, _Abi>& __k)
noexcept
4877 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4879 for (
size_t __i = 1; __i < simd_size_v<_Tp, _Abi>; ++__i)
4880 if (__k[__i] != __k[__i - 1])
4885 return _Abi::_MaskImpl::_S_some_of(__k);
4888template <
typename _Tp,
typename _Abi>
4889 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4890 popcount(
const simd_mask<_Tp, _Abi>& __k)
noexcept
4892 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4894 const int __r = __call_with_subscripts<simd_size_v<_Tp, _Abi>>(
4895 __k, [](
auto... __elements) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4896 return ((__elements != 0) + ...);
4898 if (__builtin_is_constant_evaluated() || __builtin_constant_p(__r))
4901 return _Abi::_MaskImpl::_S_popcount(__k);
4904template <
typename _Tp,
typename _Abi>
4905 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4906 find_first_set(
const simd_mask<_Tp, _Abi>& __k)
4908 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4910 constexpr size_t _Np = simd_size_v<_Tp, _Abi>;
4911 const size_t _Idx = __call_with_n_evaluations<_Np>(
4912 [](
auto... __indexes) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4914 }, [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4915 return __k[__i] ? +__i : _Np;
4918 __invoke_ub(
"find_first_set(empty mask) is UB");
4919 if (__builtin_constant_p(_Idx))
4922 return _Abi::_MaskImpl::_S_find_first_set(__k);
4925template <
typename _Tp,
typename _Abi>
4926 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4927 find_last_set(
const simd_mask<_Tp, _Abi>& __k)
4929 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4931 constexpr size_t _Np = simd_size_v<_Tp, _Abi>;
4932 const int _Idx = __call_with_n_evaluations<_Np>(
4933 [](
auto... __indexes) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4935 }, [&](
auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
4936 return __k[__i] ? int(__i) : -1;
4939 __invoke_ub(
"find_first_set(empty mask) is UB");
4940 if (__builtin_constant_p(_Idx))
4943 return _Abi::_MaskImpl::_S_find_last_set(__k);
4946_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4947all_of(_ExactBool __x)
noexcept
4950_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4951any_of(_ExactBool __x)
noexcept
4954_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4955none_of(_ExactBool __x)
noexcept
4958_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4959some_of(_ExactBool)
noexcept
4962_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4966_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4967find_first_set(_ExactBool)
4970_GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4971find_last_set(_ExactBool)
4978template <
typename _V,
typename _Tp,
typename _Abi,
bool>
4979 class _SimdIntOperators {};
4981template <
typename _V,
typename _Tp,
typename _Abi>
4982 class _SimdIntOperators<_V, _Tp, _Abi, true>
4984 using _Impl =
typename _SimdTraits<_Tp, _Abi>::_SimdImpl;
4986 _GLIBCXX_SIMD_INTRINSIC
const _V& __derived()
const
4987 {
return *
static_cast<const _V*
>(
this); }
4989 template <
typename _Up>
4990 _GLIBCXX_SIMD_INTRINSIC
static _GLIBCXX_SIMD_CONSTEXPR _V
4991 _S_make_derived(_Up&& __d)
4992 {
return {__private_init,
static_cast<_Up&&
>(__d)}; }
4995 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
4997 operator%=(_V& __lhs,
const _V& __x)
4998 {
return __lhs = __lhs % __x; }
5000 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5002 operator&=(_V& __lhs,
const _V& __x)
5003 {
return __lhs = __lhs & __x; }
5005 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5007 operator|=(_V& __lhs,
const _V& __x)
5008 {
return __lhs = __lhs | __x; }
5010 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5012 operator^=(_V& __lhs,
const _V& __x)
5013 {
return __lhs = __lhs ^ __x; }
5015 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5017 operator<<=(_V& __lhs,
const _V& __x)
5018 {
return __lhs = __lhs << __x; }
5020 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5022 operator>>=(_V& __lhs,
const _V& __x)
5023 {
return __lhs = __lhs >> __x; }
5025 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5027 operator<<=(_V& __lhs,
int __x)
5028 {
return __lhs = __lhs << __x; }
5030 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5032 operator>>=(_V& __lhs,
int __x)
5033 {
return __lhs = __lhs >> __x; }
5035 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5037 operator%(
const _V& __x,
const _V& __y)
5039 return _SimdIntOperators::_S_make_derived(
5040 _Impl::_S_modulus(__data(__x), __data(__y)));
5043 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5047 return _SimdIntOperators::_S_make_derived(
5048 _Impl::_S_bit_and(__data(__x), __data(__y)));
5051 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5055 return _SimdIntOperators::_S_make_derived(
5056 _Impl::_S_bit_or(__data(__x), __data(__y)));
5059 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5063 return _SimdIntOperators::_S_make_derived(
5064 _Impl::_S_bit_xor(__data(__x), __data(__y)));
5067 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5071 return _SimdIntOperators::_S_make_derived(
5072 _Impl::_S_bit_shift_left(__data(__x), __data(__y)));
5075 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5079 return _SimdIntOperators::_S_make_derived(
5080 _Impl::_S_bit_shift_right(__data(__x), __data(__y)));
5083 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5088 __invoke_ub(
"The behavior is undefined if the right operand of a "
5089 "shift operation is negative. [expr.shift]\nA shift by "
5092 if (
size_t(__y) >=
sizeof(declval<_Tp>() << __y) * __CHAR_BIT__)
5094 "The behavior is undefined if the right operand of a "
5095 "shift operation is greater than or equal to the width of the "
5096 "promoted left operand. [expr.shift]\nA shift by %d was requested",
5098 return _SimdIntOperators::_S_make_derived(
5099 _Impl::_S_bit_shift_left(__data(__x), __y));
5102 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5108 "The behavior is undefined if the right operand of a shift "
5109 "operation is negative. [expr.shift]\nA shift by %d was requested",
5111 if (
size_t(__y) >=
sizeof(declval<_Tp>() << __y) * __CHAR_BIT__)
5113 "The behavior is undefined if the right operand of a shift "
5114 "operation is greater than or equal to the width of the promoted "
5115 "left operand. [expr.shift]\nA shift by %d was requested",
5117 return _SimdIntOperators::_S_make_derived(
5118 _Impl::_S_bit_shift_right(__data(__x), __y));
5122 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5125 {
return {__private_init, _Impl::_S_complement(__derived()._M_data)}; }
5132template <
typename _Tp,
typename _Abi>
5133 class simd :
public _SimdIntOperators<
5134 simd<_Tp, _Abi>, _Tp, _Abi,
5135 conjunction<is_integral<_Tp>,
5136 typename _SimdTraits<_Tp, _Abi>::_IsValid>::value>,
5137 public _SimdTraits<_Tp, _Abi>::_SimdBase
5139 using _Traits = _SimdTraits<_Tp, _Abi>;
5140 using _MemberType =
typename _Traits::_SimdMember;
5141 using _CastType =
typename _Traits::_SimdCastType;
5142 static constexpr _Tp* _S_type_tag =
nullptr;
5143 friend typename _Traits::_SimdBase;
5146 using _Impl =
typename _Traits::_SimdImpl;
5148 friend _SimdIntOperators<simd, _Tp, _Abi, true>;
5150 using value_type = _Tp;
5151 using reference = _SmartReference<_MemberType, _Impl, value_type>;
5152 using mask_type = simd_mask<_Tp, _Abi>;
5153 using abi_type = _Abi;
5155 static constexpr size_t size()
5156 {
return __size_or_zero_v<_Tp, _Abi>; }
5158 _GLIBCXX_SIMD_CONSTEXPR simd() =
default;
5159 _GLIBCXX_SIMD_CONSTEXPR simd(
const simd&) =
default;
5160 _GLIBCXX_SIMD_CONSTEXPR simd(simd&&) noexcept = default;
5161 _GLIBCXX_SIMD_CONSTEXPR simd& operator=(const simd&) = default;
5162 _GLIBCXX_SIMD_CONSTEXPR simd& operator=(simd&&) noexcept = default;
5165 template <typename _Up,
5166 typename = enable_if_t<!is_same_v<__remove_cvref_t<_Up>,
bool>>>
5167 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5168 simd(_ValuePreservingOrInt<_Up, value_type>&& __x)
5170 _Impl::_S_broadcast(static_cast<value_type>(static_cast<_Up&&>(__x))))
5175 template <
typename _Up>
5176 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5177 simd(
const simd<_Up, simd_abi::fixed_size<size()>>& __x,
5180 is_same<simd_abi::fixed_size<size()>, abi_type>,
5181 negation<__is_narrowing_conversion<_Up, value_type>>,
5182 __converts_to_higher_integer_rank<_Up, value_type>>::value,
5184 : simd{static_cast<array<_Up, size()>>(__x).data(), vector_aligned} {}
5187#ifdef _GLIBCXX_SIMD_ENABLE_STATIC_CAST
5188 template <
typename _Up,
typename _A2,
5189 typename =
decltype(static_simd_cast<simd>(
5190 declval<
const simd<_Up, _A2>&>()))>
5191 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5192 simd(
const simd<_Up, _A2>& __x)
5193 : simd(static_simd_cast<simd>(__x)) {}
5197 template <
typename _Fp>
5198 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5199 simd(_Fp&& __gen, _ValuePreservingOrInt<
decltype(declval<_Fp>()(
5200 declval<_SizeConstant<0>&>())),
5201 value_type>* =
nullptr)
5202 : _M_data(_Impl::_S_generator(static_cast<_Fp&&>(__gen), _S_type_tag)) {}
5205 template <
typename _Up,
typename _Flags>
5206 _GLIBCXX_SIMD_ALWAYS_INLINE
5207 simd(
const _Up* __mem, _Flags)
5209 _Impl::_S_load(_Flags::template _S_apply<simd>(__mem), _S_type_tag))
5213 template <
typename _Up,
typename _Flags>
5214 _GLIBCXX_SIMD_ALWAYS_INLINE
void
5215 copy_from(
const _Vectorizable<_Up>* __mem, _Flags)
5217 _M_data =
static_cast<decltype(_M_data)
>(
5218 _Impl::_S_load(_Flags::template _S_apply<simd>(__mem), _S_type_tag));
5222 template <
typename _Up,
typename _Flags>
5223 _GLIBCXX_SIMD_ALWAYS_INLINE
void
5224 copy_to(_Vectorizable<_Up>* __mem, _Flags)
const
5226 _Impl::_S_store(_M_data, _Flags::template _S_apply<simd>(__mem),
5231 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR reference
5232 operator[](
size_t __i)
5233 {
return {_M_data, int(__i)}; }
5235 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR value_type
5236 operator[]([[maybe_unused]]
size_t __i)
const
5238 if constexpr (__is_scalar_abi<_Abi>())
5240 _GLIBCXX_DEBUG_ASSERT(__i == 0);
5244 return _M_data[__i];
5248 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd&
5251 _Impl::_S_increment(_M_data);
5255 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5259 _Impl::_S_increment(_M_data);
5263 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd&
5266 _Impl::_S_decrement(_M_data);
5270 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5274 _Impl::_S_decrement(_M_data);
5279 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR mask_type
5281 {
return {__private_init, _Impl::_S_negate(_M_data)}; }
5283 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5287 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5289 {
return {__private_init, _Impl::_S_unary_minus(_M_data)}; }
5292 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5293 simd(_CastType __init) : _M_data(__init) {}
5296 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5297 operator+=(simd& __lhs,
const simd& __x)
5298 {
return __lhs = __lhs + __x; }
5300 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5301 operator-=(simd& __lhs,
const simd& __x)
5302 {
return __lhs = __lhs - __x; }
5304 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5305 operator*=(simd& __lhs,
const simd& __x)
5306 {
return __lhs = __lhs * __x; }
5308 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5309 operator/=(simd& __lhs,
const simd& __x)
5310 {
return __lhs = __lhs / __x; }
5313 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5314 operator+(
const simd& __x,
const simd& __y)
5315 {
return {__private_init, _Impl::_S_plus(__x._M_data, __y._M_data)}; }
5317 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5318 operator-(
const simd& __x,
const simd& __y)
5319 {
return {__private_init, _Impl::_S_minus(__x._M_data, __y._M_data)}; }
5321 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5322 operator*(
const simd& __x,
const simd& __y)
5323 {
return {__private_init, _Impl::_S_multiplies(__x._M_data, __y._M_data)}; }
5325 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5326 operator/(
const simd& __x,
const simd& __y)
5327 {
return {__private_init, _Impl::_S_divides(__x._M_data, __y._M_data)}; }
5330 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5331 operator==(
const simd& __x,
const simd& __y)
5332 {
return simd::_S_make_mask(_Impl::_S_equal_to(__x._M_data, __y._M_data)); }
5334 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5335 operator!=(
const simd& __x,
const simd& __y)
5337 return simd::_S_make_mask(
5338 _Impl::_S_not_equal_to(__x._M_data, __y._M_data));
5341 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5342 operator<(
const simd& __x,
const simd& __y)
5343 {
return simd::_S_make_mask(_Impl::_S_less(__x._M_data, __y._M_data)); }
5345 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5346 operator<=(
const simd& __x,
const simd& __y)
5348 return simd::_S_make_mask(_Impl::_S_less_equal(__x._M_data, __y._M_data));
5351 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5352 operator>(
const simd& __x,
const simd& __y)
5353 {
return simd::_S_make_mask(_Impl::_S_less(__y._M_data, __x._M_data)); }
5355 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5356 operator>=(
const simd& __x,
const simd& __y)
5358 return simd::_S_make_mask(_Impl::_S_less_equal(__y._M_data, __x._M_data));
5362#ifdef __GXX_CONDITIONAL_IS_OVERLOADABLE__
5363 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5364 operator?:(
const mask_type& __k,
const simd& __where_true,
5365 const simd& __where_false)
5367 auto __ret = __where_false;
5368 _Impl::_S_masked_assign(__data(__k), __data(__ret), __data(__where_true));
5376 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
5377 simd(_PrivateInit,
const _MemberType& __init)
5378 : _M_data(__init) {}
5381 _GLIBCXX_SIMD_INTRINSIC
5382 simd(_BitsetInit, bitset<size()> __init) : _M_data()
5383 { where(mask_type(__bitset_init, __init), *
this) = ~*
this; }
5385 _GLIBCXX_SIMD_INTRINSIC
constexpr bool
5386 _M_is_constprop()
const
5388 if constexpr (__is_scalar_abi<_Abi>())
5389 return __builtin_constant_p(_M_data);
5391 return _M_data._M_is_constprop();
5395 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
static mask_type
5396 _S_make_mask(
typename mask_type::_MemberType __k)
5397 {
return {__private_init, __k}; }
5399 friend const auto& __data<value_type, abi_type>(
const simd&);
5400 friend auto& __data<value_type, abi_type>(simd&);
5401 alignas(_Traits::_S_simd_align) _MemberType _M_data;
5407template <
typename _Tp,
typename _Ap>
5408 _GLIBCXX_SIMD_INTRINSIC
constexpr const auto&
5409 __data(
const simd<_Tp, _Ap>& __x)
5410 {
return __x._M_data; }
5412template <
typename _Tp,
typename _Ap>
5413 _GLIBCXX_SIMD_INTRINSIC
constexpr auto&
5414 __data(simd<_Tp, _Ap>& __x)
5415 {
return __x._M_data; }
5418namespace __float_bitwise_operators {
5419template <
typename _Tp,
typename _Ap>
5420 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5421 operator^(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5423 return {__private_init,
5424 _Ap::_SimdImpl::_S_bit_xor(__data(__a), __data(__b))};
5427template <
typename _Tp,
typename _Ap>
5428 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5429 operator|(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5431 return {__private_init,
5432 _Ap::_SimdImpl::_S_bit_or(__data(__a), __data(__b))};
5435template <
typename _Tp,
typename _Ap>
5436 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5437 operator&(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5439 return {__private_init,
5440 _Ap::_SimdImpl::_S_bit_and(__data(__a), __data(__b))};
5443template <
typename _Tp,
typename _Ap>
5444 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
5445 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Ap>>
5446 operator~(
const simd<_Tp, _Ap>& __a)
5447 {
return {__private_init, _Ap::_SimdImpl::_S_complement(__data(__a))}; }
5452_GLIBCXX_SIMD_END_NAMESPACE
constexpr _If_is_unsigned_integer< _Tp, int > popcount(_Tp __x) noexcept
The number of bits set in x.
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.
constexpr bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.