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
44 #include <x86intrin.h>
45 #elif _GLIBCXX_SIMD_HAVE_NEON
72 _GLIBCXX_SIMD_BEGIN_NAMESPACE
74 #if !_GLIBCXX_SIMD_X86INTRIN
75 using __m128 [[__gnu__::__vector_size__(16)]] = float;
76 using __m128d [[__gnu__::__vector_size__(16)]] = double;
77 using __m128i [[__gnu__::__vector_size__(16)]] =
long long;
78 using __m256 [[__gnu__::__vector_size__(32)]] = float;
79 using __m256d [[__gnu__::__vector_size__(32)]] = double;
80 using __m256i [[__gnu__::__vector_size__(32)]] =
long long;
81 using __m512 [[__gnu__::__vector_size__(64)]] = float;
82 using __m512d [[__gnu__::__vector_size__(64)]] = double;
83 using __m512i [[__gnu__::__vector_size__(64)]] =
long long;
105 template <
int _UsedBytes>
108 template <
int _UsedBytes>
109 struct _VecBltnBtmsk;
111 template <
typename _Tp,
int _Np>
112 using _VecN = _VecBuiltin<
sizeof(_Tp) * _Np>;
114 template <
int _UsedBytes = 16>
115 using _Sse = _VecBuiltin<_UsedBytes>;
117 template <
int _UsedBytes = 32>
118 using _Avx = _VecBuiltin<_UsedBytes>;
120 template <
int _UsedBytes = 64>
121 using _Avx512 = _VecBltnBtmsk<_UsedBytes>;
123 template <
int _UsedBytes = 16>
124 using _Neon = _VecBuiltin<_UsedBytes>;
127 using __sse = _Sse<>;
128 using __avx = _Avx<>;
129 using __avx512 = _Avx512<>;
130 using __neon = _Neon<>;
131 using __neon128 = _Neon<16>;
132 using __neon64 = _Neon<8>;
135 template <
typename _Tp,
size_t _Np,
typename...>
139 using fixed_size = _Fixed<_Np>;
141 using scalar = _Scalar;
146 template <
typename _Tp>
149 template <
typename _Tp>
152 template <
typename _Tp,
typename _Abi>
155 template <
typename _Tp,
typename _Abi>
158 template <
typename _Tp,
typename _Abi>
163 struct 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*
174 struct 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>));
189 template <
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)); }
200 inline constexpr element_aligned_tag element_aligned = {};
202 inline constexpr vector_aligned_tag vector_aligned = {};
204 template <
size_t _Np>
205 inline constexpr overaligned_tag<_Np> overaligned = {};
208 template <
size_t _Xp>
209 using _SizeConstant = integral_constant<size_t, _Xp>;
211 constexpr
inline bool __have_mmx = _GLIBCXX_SIMD_HAVE_MMX;
212 constexpr
inline bool __have_sse = _GLIBCXX_SIMD_HAVE_SSE;
213 constexpr
inline bool __have_sse2 = _GLIBCXX_SIMD_HAVE_SSE2;
214 constexpr
inline bool __have_sse3 = _GLIBCXX_SIMD_HAVE_SSE3;
215 constexpr
inline bool __have_ssse3 = _GLIBCXX_SIMD_HAVE_SSSE3;
216 constexpr
inline bool __have_sse4_1 = _GLIBCXX_SIMD_HAVE_SSE4_1;
217 constexpr
inline bool __have_sse4_2 = _GLIBCXX_SIMD_HAVE_SSE4_2;
218 constexpr
inline bool __have_xop = _GLIBCXX_SIMD_HAVE_XOP;
219 constexpr
inline bool __have_avx = _GLIBCXX_SIMD_HAVE_AVX;
220 constexpr
inline bool __have_avx2 = _GLIBCXX_SIMD_HAVE_AVX2;
221 constexpr
inline bool __have_bmi = _GLIBCXX_SIMD_HAVE_BMI1;
222 constexpr
inline bool __have_bmi2 = _GLIBCXX_SIMD_HAVE_BMI2;
223 constexpr
inline bool __have_lzcnt = _GLIBCXX_SIMD_HAVE_LZCNT;
224 constexpr
inline bool __have_sse4a = _GLIBCXX_SIMD_HAVE_SSE4A;
225 constexpr
inline bool __have_fma = _GLIBCXX_SIMD_HAVE_FMA;
226 constexpr
inline bool __have_fma4 = _GLIBCXX_SIMD_HAVE_FMA4;
227 constexpr
inline bool __have_f16c = _GLIBCXX_SIMD_HAVE_F16C;
228 constexpr
inline bool __have_popcnt = _GLIBCXX_SIMD_HAVE_POPCNT;
229 constexpr
inline bool __have_avx512f = _GLIBCXX_SIMD_HAVE_AVX512F;
230 constexpr
inline bool __have_avx512dq = _GLIBCXX_SIMD_HAVE_AVX512DQ;
231 constexpr
inline bool __have_avx512vl = _GLIBCXX_SIMD_HAVE_AVX512VL;
232 constexpr
inline bool __have_avx512bw = _GLIBCXX_SIMD_HAVE_AVX512BW;
233 constexpr
inline bool __have_avx512dq_vl = __have_avx512dq && __have_avx512vl;
234 constexpr
inline bool __have_avx512bw_vl = __have_avx512bw && __have_avx512vl;
235 constexpr
inline bool __have_avx512bitalg = _GLIBCXX_SIMD_HAVE_AVX512BITALG;
236 constexpr
inline bool __have_avx512vbmi2 = _GLIBCXX_SIMD_HAVE_AVX512VBMI2;
237 constexpr
inline bool __have_avx512vbmi = _GLIBCXX_SIMD_HAVE_AVX512VBMI;
238 constexpr
inline bool __have_avx512ifma = _GLIBCXX_SIMD_HAVE_AVX512IFMA;
239 constexpr
inline bool __have_avx512cd = _GLIBCXX_SIMD_HAVE_AVX512CD;
240 constexpr
inline bool __have_avx512vnni = _GLIBCXX_SIMD_HAVE_AVX512VNNI;
241 constexpr
inline bool __have_avx512vpopcntdq = _GLIBCXX_SIMD_HAVE_AVX512VPOPCNTDQ;
242 constexpr
inline bool __have_avx512vp2intersect = _GLIBCXX_SIMD_HAVE_AVX512VP2INTERSECT;
244 constexpr
inline bool __have_neon = _GLIBCXX_SIMD_HAVE_NEON;
245 constexpr
inline bool __have_neon_a32 = _GLIBCXX_SIMD_HAVE_NEON_A32;
246 constexpr
inline bool __have_neon_a64 = _GLIBCXX_SIMD_HAVE_NEON_A64;
247 constexpr
inline bool __support_neon_float =
248 #if defined __GCC_IEC_559
250 #elif defined __FAST_MATH__
257 constexpr
inline bool __have_power10vec =
true;
259 constexpr
inline bool __have_power10vec =
false;
261 #ifdef __POWER9_VECTOR__
262 constexpr
inline bool __have_power9vec =
true;
264 constexpr
inline bool __have_power9vec =
false;
266 #if defined __POWER8_VECTOR__
267 constexpr
inline bool __have_power8vec =
true;
269 constexpr
inline bool __have_power8vec = __have_power9vec;
272 constexpr
inline bool __have_power_vsx =
true;
274 constexpr
inline bool __have_power_vsx = __have_power8vec;
276 #if defined __ALTIVEC__
277 constexpr
inline bool __have_power_vmx =
true;
279 constexpr
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);
424 template <
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>()), ...); }
430 template <
typename _Fp>
431 _GLIBCXX_SIMD_INTRINSIC constexpr
void
432 __execute_on_index_sequence(_Fp&&, index_sequence<>)
435 template <
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>{});
445 template <
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>())...}; }
451 template <
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>{});
461 template <
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>())...); }
467 template <
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));
478 template <
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]...); }
484 template <
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));
497 using _UChar =
unsigned char;
498 using _SChar =
signed char;
499 using _UShort =
unsigned short;
500 using _UInt =
unsigned int;
501 using _ULong =
unsigned long;
502 using _ULLong =
unsigned long long;
503 using _LLong =
long long;
507 template <
typename _T0,
typename...>
508 struct __first_of_pack
509 {
using type = _T0; };
511 template <
typename... _Ts>
512 using __first_of_pack_t =
typename __first_of_pack<_Ts...>::type;
516 template <
typename _Tp>
517 typename _Tp::value_type
518 __value_type_or_identity_impl(
int);
520 template <
typename _Tp>
522 __value_type_or_identity_impl(
float);
524 template <
typename _Tp>
525 using __value_type_or_identity_t
526 = decltype(__value_type_or_identity_impl<_Tp>(
int()));
530 template <
typename _Tp>
531 struct __is_vectorizable :
public is_arithmetic<_Tp> {};
534 struct __is_vectorizable<bool> :
public false_type {};
536 template <
typename _Tp>
537 inline constexpr
bool __is_vectorizable_v = __is_vectorizable<_Tp>::value;
540 template <
typename _Tp,
typename = enable_if_t<__is_vectorizable_v<_Tp>>>
541 using _Vectorizable = _Tp;
545 template <
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 {};
553 template <
typename _Ptr,
typename _ValueType,
555 __is_possible_loadstore_conversion<_Ptr, _ValueType>::value>>
556 using _LoadStorePtr = _Ptr;
560 template <
typename _Tp,
typename =
void_t<>>
563 template <
typename _Tp>
564 inline constexpr
bool __is_bitmask_v = __is_bitmask<_Tp>::value;
567 template <
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"
576 template <
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) {
return __rhs._M_data[__i] & _M_data[__i]; });
615 _GLIBCXX_SIMD_INTRINSIC constexpr _Ip
618 return __generate_from_n_evaluations<_Np, _Ip>(
619 [&](
auto __i) {
return __rhs._M_data[__i] | _M_data[__i]; });
622 _GLIBCXX_SIMD_INTRINSIC constexpr _Ip
625 return __generate_from_n_evaluations<_Np, _Ip>(
626 [&](
auto __i) {
return __rhs._M_data[__i] ^ _M_data[__i]; });
629 _GLIBCXX_SIMD_INTRINSIC constexpr _Ip
632 return __generate_from_n_evaluations<_Np, _Ip>(
633 [&](
auto __i) {
return ~_M_data[__i]; });
639 static_assert(_Bytes != _Bytes,
"this should be unreachable");
641 #pragma GCC diagnostic pop
643 template <
typename _Tp>
644 using __int_for_sizeof_t = decltype(__int_for_sizeof<
sizeof(_Tp)>());
646 template <
size_t _Np>
647 using __int_with_sizeof_t = decltype(__int_for_sizeof<_Np>());
651 template <
typename _Tp>
655 struct __is_fixed_size_abi<simd_abi::fixed_size<_Np>> :
true_type {};
657 template <
typename _Tp>
658 inline constexpr
bool __is_fixed_size_abi_v = __is_fixed_size_abi<_Tp>::value;
662 template <
typename _Abi>
665 {
return is_same_v<simd_abi::scalar, _Abi>; }
669 template <
template <
int>
class _Abi,
int _Bytes>
671 __abi_bytes_impl(_Abi<_Bytes>*)
674 template <
typename _Tp>
676 __abi_bytes_impl(_Tp*)
679 template <
typename _Abi>
680 inline constexpr
int __abi_bytes_v
681 = __abi_bytes_impl(
static_cast<_Abi*
>(
nullptr));
685 template <
typename _Abi>
687 __is_builtin_bitmask_abi()
688 {
return is_same_v<simd_abi::_VecBltnBtmsk<__abi_bytes_v<_Abi>>, _Abi>; }
692 template <
typename _Abi>
696 constexpr
auto _Bytes = __abi_bytes_v<_Abi>;
697 return _Bytes <= 16 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
702 template <
typename _Abi>
706 constexpr
auto _Bytes = __abi_bytes_v<_Abi>;
707 return _Bytes > 16 && _Bytes <= 32
708 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
713 template <
typename _Abi>
717 constexpr
auto _Bytes = __abi_bytes_v<_Abi>;
718 return _Bytes <= 64 && is_same_v<simd_abi::_Avx512<_Bytes>, _Abi>;
723 template <
typename _Abi>
727 constexpr
auto _Bytes = __abi_bytes_v<_Abi>;
728 return _Bytes <= 16 && is_same_v<simd_abi::_VecBuiltin<_Bytes>, _Abi>;
733 template <
typename,
typename _Up>
734 struct __make_dependent
735 {
using type = _Up; };
737 template <
typename _Tp,
typename _Up>
738 using __make_dependent_t =
typename __make_dependent<_Tp, _Up>::type;
744 template <
typename... _Args>
745 [[noreturn]] _GLIBCXX_SIMD_ALWAYS_INLINE
void
746 __invoke_ub([[maybe_unused]]
const char* __msg,
747 [[maybe_unused]]
const _Args&... __args)
749 #ifdef _GLIBCXX_DEBUG_UB
750 __builtin_fprintf(stderr, __msg, __args...);
753 __builtin_unreachable();
759 template <
typename _Tp>
760 struct __assert_unreachable
761 { static_assert(!is_same_v<_Tp, _Tp>,
"this should be unreachable"); };
765 template <typename _Tp, typename _Ap, size_t _Np = simd_size<_Tp, _Ap>::value>
767 __size_or_zero_dispatch(
int)
770 template <
typename _Tp,
typename _Ap>
772 __size_or_zero_dispatch(
float)
775 template <
typename _Tp,
typename _Ap>
776 inline constexpr
size_t __size_or_zero_v
777 = __size_or_zero_dispatch<_Tp, _Ap>(0);
781 inline constexpr
size_t
782 __div_roundup(
size_t __a,
size_t __b)
783 {
return (__a + __b - 1) / __b; }
792 _GLIBCXX_SIMD_INTRINSIC constexpr _ExactBool(
bool __b) : _M_data(__b) {}
794 _ExactBool(
int) =
delete;
796 _GLIBCXX_SIMD_INTRINSIC constexpr
operator bool()
const {
return _M_data; }
806 template <
typename _Tp>
807 using __may_alias [[__gnu__::__may_alias__]] = _Tp;
812 struct _UnsupportedBase
814 _UnsupportedBase() =
delete;
815 _UnsupportedBase(
const _UnsupportedBase&) =
delete;
816 _UnsupportedBase& operator=(
const _UnsupportedBase&) =
delete;
817 ~_UnsupportedBase() =
delete;
830 struct _InvalidTraits
833 using _SimdBase = _UnsupportedBase;
834 using _MaskBase = _UnsupportedBase;
836 static constexpr
size_t _S_full_size = 0;
837 static constexpr
bool _S_is_partial =
false;
839 static constexpr
size_t _S_simd_align = 1;
841 struct _SimdMember {};
842 struct _SimdCastType;
844 static constexpr
size_t _S_mask_align = 1;
846 struct _MaskMember {};
847 struct _MaskCastType;
852 template <
typename _Tp,
typename _Abi,
typename =
void_t<>>
853 struct _SimdTraits : _InvalidTraits {};
861 inline constexpr
struct _PrivateInit {} __private_init = {};
863 inline constexpr
struct _BitsetInit {} __bitset_init = {};
867 template <
typename _From,
typename _To,
bool = is_arithmetic_v<_From>,
868 bool = is_arithmetic_v<_To>>
869 struct __is_narrowing_conversion;
873 template <
typename _From,
typename _To>
874 struct __is_narrowing_conversion<_From, _To, true, true>
875 :
public __bool_constant<(
876 __digits_v<_From> > __digits_v<_To>
877 || __finite_max_v<_From> > __finite_max_v<_To>
878 || __finite_min_v<_From> < __finite_min_v<_To>
879 || (is_signed_v<_From> && is_unsigned_v<_To>))> {};
881 template <
typename _Tp>
882 struct __is_narrowing_conversion<_Tp, bool, true, true>
886 struct __is_narrowing_conversion<bool, bool, true, true>
889 template <
typename _Tp>
890 struct __is_narrowing_conversion<_Tp, _Tp, true, true>
893 template <
typename _From,
typename _To>
894 struct __is_narrowing_conversion<_From, _To, false, true>
895 :
public negation<is_convertible<_From, _To>> {};
899 template <
typename _From,
typename _To,
bool = (sizeof(_From) < sizeof(_To))>
900 struct __converts_to_higher_
integer_rank : public true_type {};
903 template <
typename _From,
typename _To>
904 struct __converts_to_higher_integer_rank<_From, _To, false>
905 :
public is_same<decltype(declval<_From>() + declval<_To>()), _To> {};
909 template <
typename _Tp,
typename _Ap>
910 _GLIBCXX_SIMD_INTRINSIC constexpr
const auto&
911 __data(
const simd<_Tp, _Ap>& __x);
913 template <
typename _Tp,
typename _Ap>
914 _GLIBCXX_SIMD_INTRINSIC constexpr
auto&
915 __data(simd<_Tp, _Ap>& __x);
917 template <
typename _Tp,
typename _Ap>
918 _GLIBCXX_SIMD_INTRINSIC constexpr
const auto&
919 __data(
const simd_mask<_Tp, _Ap>& __x);
921 template <
typename _Tp,
typename _Ap>
922 _GLIBCXX_SIMD_INTRINSIC constexpr
auto&
923 __data(simd_mask<_Tp, _Ap>& __x);
927 template <
typename _FromT,
typename _FromA,
typename _ToT,
typename _ToA,
929 struct _SimdConverter;
931 template <
typename _Tp,
typename _Ap>
932 struct _SimdConverter<_Tp, _Ap, _Tp, _Ap, void>
934 template <
typename _Up>
935 _GLIBCXX_SIMD_INTRINSIC
const _Up&
936 operator()(
const _Up& __x)
942 template <
typename _V>
943 _GLIBCXX_SIMD_INTRINSIC constexpr
auto
944 __to_value_type_or_member_type(
const _V& __x) -> decltype(__data(__x))
945 {
return __data(__x); }
947 template <
typename _V>
948 _GLIBCXX_SIMD_INTRINSIC constexpr
const typename _V::value_type&
949 __to_value_type_or_member_type(
const typename _V::value_type& __x)
954 template <
size_t _Size>
955 struct __bool_storage_member_type;
957 template <
size_t _Size>
958 using __bool_storage_member_type_t =
959 typename __bool_storage_member_type<_Size>::type;
969 template <
typename _Tp,
typename... _Abis>
974 template <
typename _Tp,
int _Np>
975 struct __fixed_size_storage;
977 template <
typename _Tp,
int _Np>
978 using __fixed_size_storage_t =
typename __fixed_size_storage<_Tp, _Np>::type;
982 template <
typename _Tp,
size_t _Size,
typename =
void_t<>>
985 template <
typename _Tp>
986 using _SimdWrapper8 = _SimdWrapper<_Tp, 8 /
sizeof(_Tp)>;
987 template <
typename _Tp>
988 using _SimdWrapper16 = _SimdWrapper<_Tp, 16 /
sizeof(_Tp)>;
989 template <
typename _Tp>
990 using _SimdWrapper32 = _SimdWrapper<_Tp, 32 /
sizeof(_Tp)>;
991 template <
typename _Tp>
992 using _SimdWrapper64 = _SimdWrapper<_Tp, 64 /
sizeof(_Tp)>;
996 template <
typename _Tp>
999 template <
typename _Tp,
size_t _Np>
1000 struct __is_simd_wrapper<_SimdWrapper<_Tp, _Np>> :
true_type {};
1002 template <
typename _Tp>
1003 inline constexpr
bool __is_simd_wrapper_v = __is_simd_wrapper<_Tp>::value;
1010 template <
typename _Tp,
typename _Fp>
1012 _S_bit_iteration(_Tp __mask, _Fp&& __f)
1014 static_assert(
sizeof(_ULLong) >=
sizeof(_Tp));
1015 conditional_t<
sizeof(_Tp) <=
sizeof(_UInt), _UInt, _ULLong> __k;
1016 if constexpr (is_convertible_v<_Tp, decltype(__k)>)
1019 __k = __mask.to_ullong();
1022 __f(std::__countr_zero(__k));
1032 template <
typename _Tp =
void>
1034 { constexpr _Tp operator()(_Tp __a)
const {
return ++__a; } };
1037 struct __increment<void>
1039 template <
typename _Tp>
1041 operator()(_Tp __a)
const
1045 template <
typename _Tp =
void>
1047 { constexpr _Tp operator()(_Tp __a)
const {
return --__a; } };
1050 struct __decrement<void>
1052 template <
typename _Tp>
1054 operator()(_Tp __a)
const
1060 template <
typename _From,
typename _To,
1062 __is_narrowing_conversion<__remove_cvref_t<_From>, _To>>::value>>
1063 using _ValuePreserving = _From;
1065 template <
typename _From,
typename _To,
1066 typename _DecayedFrom = __remove_cvref_t<_From>,
1068 is_convertible<_From, _To>,
1070 is_same<_DecayedFrom, _To>, is_same<_DecayedFrom, int>,
1071 conjunction<is_same<_DecayedFrom, _UInt>, is_unsigned<_To>>,
1072 negation<__is_narrowing_conversion<_DecayedFrom, _To>>>>::value>>
1073 using _ValuePreservingOrInt = _From;
1077 template <
typename _Tp,
size_t _Bytes,
typename =
void_t<>>
1078 struct __intrinsic_type;
1080 template <
typename _Tp,
size_t _Size>
1081 using __intrinsic_type_t =
1082 typename __intrinsic_type<_Tp, _Size *
sizeof(_Tp)>::type;
1084 template <
typename _Tp>
1085 using __intrinsic_type2_t =
typename __intrinsic_type<_Tp, 2>::type;
1086 template <
typename _Tp>
1087 using __intrinsic_type4_t =
typename __intrinsic_type<_Tp, 4>::type;
1088 template <
typename _Tp>
1089 using __intrinsic_type8_t =
typename __intrinsic_type<_Tp, 8>::type;
1090 template <
typename _Tp>
1091 using __intrinsic_type16_t =
typename __intrinsic_type<_Tp, 16>::type;
1092 template <
typename _Tp>
1093 using __intrinsic_type32_t =
typename __intrinsic_type<_Tp, 32>::type;
1094 template <
typename _Tp>
1095 using __intrinsic_type64_t =
typename __intrinsic_type<_Tp, 64>::type;
1099 template <
size_t _Np,
bool _Sanitized = false>
1102 template <
size_t _Np,
bool _Sanitized>
1103 struct __is_bitmask<_BitMask<_Np, _Sanitized>, void> :
true_type {};
1105 template <
size_t _Np>
1106 using _SanitizedBitMask = _BitMask<_Np, true>;
1108 template <
size_t _Np,
bool _Sanitized>
1111 static_assert(_Np > 0);
1113 static constexpr
size_t _NBytes = __div_roundup(_Np, __CHAR_BIT__);
1117 sizeof(_ULLong), std::__bit_ceil(_NBytes))>>>;
1119 static constexpr
int _S_array_size = __div_roundup(_NBytes,
sizeof(_Tp));
1121 _Tp _M_bits[_S_array_size];
1123 static constexpr
int _S_unused_bits
1124 = _Np == 1 ? 0 : _S_array_size *
sizeof(_Tp) * __CHAR_BIT__ - _Np;
1126 static constexpr _Tp _S_bitmask = +_Tp(~_Tp()) >> _S_unused_bits;
1128 constexpr _BitMask() noexcept = default;
1130 constexpr _BitMask(
unsigned long long __x) noexcept
1131 : _M_bits{
static_cast<_Tp
>(__x)} {}
1133 _BitMask(bitset<_Np> __x) noexcept : _BitMask(__x.to_ullong()) {}
1135 constexpr _BitMask(
const _BitMask&) noexcept =
default;
1137 template <
bool _RhsSanitized,
typename =
enable_if_t<_RhsSanitized ==
false
1138 && _Sanitized ==
true>>
1139 constexpr _BitMask(
const _BitMask<_Np, _RhsSanitized>& __rhs) noexcept
1140 : _BitMask(__rhs._M_sanitized()) {}
1142 constexpr
operator _SimdWrapper<bool, _Np>() const noexcept
1144 static_assert(_S_array_size == 1);
1150 _M_to_bits() const noexcept
1152 static_assert(_S_array_size == 1);
1157 constexpr
unsigned long long
1158 to_ullong() const noexcept
1160 static_assert(_S_array_size == 1);
1165 constexpr
unsigned long
1166 to_ulong() const noexcept
1168 static_assert(_S_array_size == 1);
1172 constexpr bitset<_Np>
1173 _M_to_bitset() const noexcept
1175 static_assert(_S_array_size == 1);
1179 constexpr decltype(
auto)
1180 _M_sanitized() const noexcept
1182 if constexpr (_Sanitized)
1184 else if constexpr (_Np == 1)
1185 return _SanitizedBitMask<_Np>(_M_bits[0]);
1188 _SanitizedBitMask<_Np> __r = {};
1189 for (
int __i = 0; __i < _S_array_size; ++__i)
1190 __r._M_bits[__i] = _M_bits[__i];
1191 if constexpr (_S_unused_bits > 0)
1192 __r._M_bits[_S_array_size - 1] &= _S_bitmask;
1197 template <
size_t _Mp,
bool _LSanitized>
1198 constexpr _BitMask<_Np + _Mp, _Sanitized>
1199 _M_prepend(_BitMask<_Mp, _LSanitized> __lsb)
const noexcept
1201 constexpr
size_t _RN = _Np + _Mp;
1202 using _Rp = _BitMask<_RN, _Sanitized>;
1203 if constexpr (_Rp::_S_array_size == 1)
1205 _Rp __r{{_M_bits[0]}};
1206 __r._M_bits[0] <<= _Mp;
1207 __r._M_bits[0] |= __lsb._M_sanitized()._M_bits[0];
1211 __assert_unreachable<_Rp>();
1217 template <
size_t _DropLsb,
size_t _NewSize = _Np - _DropLsb>
1219 _M_extract() const noexcept
1221 static_assert(_Np > _DropLsb);
1222 static_assert(_DropLsb + _NewSize <=
sizeof(_ULLong) * __CHAR_BIT__,
1223 "not implemented for bitmasks larger than one ullong");
1224 if constexpr (_NewSize == 1)
1226 return _SanitizedBitMask<1>(_M_bits[0] & (_Tp(1) << _DropLsb));
1228 return _BitMask<_NewSize,
1229 ((_NewSize + _DropLsb == sizeof(_Tp) * __CHAR_BIT__
1230 && _NewSize + _DropLsb <= _Np)
1231 || ((_Sanitized || _Np == sizeof(_Tp) * __CHAR_BIT__)
1232 && _NewSize + _DropLsb >= _Np))>(_M_bits[0]
1238 all() const noexcept
1240 if constexpr (_Np == 1)
1242 else if constexpr (!_Sanitized)
1243 return _M_sanitized().all();
1246 constexpr _Tp __allbits = ~_Tp();
1247 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1248 if (_M_bits[__i] != __allbits)
1250 return _M_bits[_S_array_size - 1] == _S_bitmask;
1257 any() const noexcept
1259 if constexpr (_Np == 1)
1261 else if constexpr (!_Sanitized)
1262 return _M_sanitized().any();
1265 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1266 if (_M_bits[__i] != 0)
1268 return _M_bits[_S_array_size - 1] != 0;
1274 none() const noexcept
1276 if constexpr (_Np == 1)
1278 else if constexpr (!_Sanitized)
1279 return _M_sanitized().none();
1282 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1283 if (_M_bits[__i] != 0)
1285 return _M_bits[_S_array_size - 1] == 0;
1292 count() const noexcept
1294 if constexpr (_Np == 1)
1296 else if constexpr (!_Sanitized)
1297 return _M_sanitized().none();
1300 int __result = __builtin_popcountll(_M_bits[0]);
1301 for (
int __i = 1; __i < _S_array_size; ++__i)
1302 __result += __builtin_popcountll(_M_bits[__i]);
1309 operator[](
size_t __i)
const noexcept
1311 if constexpr (_Np == 1)
1313 else if constexpr (_S_array_size == 1)
1314 return (_M_bits[0] >> __i) & 1;
1317 const size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1318 const size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1319 return (_M_bits[__j] >> __shift) & 1;
1323 template <
size_t __i>
1325 operator[](_SizeConstant<__i>)
const noexcept
1327 static_assert(__i < _Np);
1328 constexpr
size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1329 constexpr
size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1330 return static_cast<bool>(_M_bits[__j] & (_Tp(1) << __shift));
1335 set(
size_t __i,
bool __x) noexcept
1337 if constexpr (_Np == 1)
1339 else if constexpr (_S_array_size == 1)
1341 _M_bits[0] &= ~_Tp(_Tp(1) << __i);
1342 _M_bits[0] |= _Tp(_Tp(__x) << __i);
1346 const size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1347 const size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1348 _M_bits[__j] &= ~_Tp(_Tp(1) << __shift);
1349 _M_bits[__j] |= _Tp(_Tp(__x) << __shift);
1353 template <
size_t __i>
1355 set(_SizeConstant<__i>,
bool __x) noexcept
1357 static_assert(__i < _Np);
1358 if constexpr (_Np == 1)
1362 constexpr
size_t __j = __i / (
sizeof(_Tp) * __CHAR_BIT__);
1363 constexpr
size_t __shift = __i % (
sizeof(_Tp) * __CHAR_BIT__);
1364 constexpr _Tp __mask = ~_Tp(_Tp(1) << __shift);
1365 _M_bits[__j] &= __mask;
1366 _M_bits[__j] |= _Tp(_Tp(__x) << __shift);
1372 operator~() const noexcept
1374 if constexpr (_Np == 1)
1378 _BitMask __result{};
1379 for (
int __i = 0; __i < _S_array_size - 1; ++__i)
1380 __result._M_bits[__i] = ~_M_bits[__i];
1381 if constexpr (_Sanitized)
1382 __result._M_bits[_S_array_size - 1]
1383 = _M_bits[_S_array_size - 1] ^ _S_bitmask;
1385 __result._M_bits[_S_array_size - 1] = ~_M_bits[_S_array_size - 1];
1391 operator^=(
const _BitMask& __b) & noexcept
1393 __execute_n_times<_S_array_size>(
1394 [&](
auto __i) { _M_bits[__i] ^= __b._M_bits[__i]; });
1399 operator|=(
const _BitMask& __b) & noexcept
1401 __execute_n_times<_S_array_size>(
1402 [&](
auto __i) { _M_bits[__i] |= __b._M_bits[__i]; });
1407 operator&=(
const _BitMask& __b) & noexcept
1409 __execute_n_times<_S_array_size>(
1410 [&](
auto __i) { _M_bits[__i] &= __b._M_bits[__i]; });
1414 friend constexpr _BitMask
1415 operator^(
const _BitMask& __a,
const _BitMask& __b) noexcept
1422 friend constexpr _BitMask
1423 operator|(
const _BitMask& __a,
const _BitMask& __b) noexcept
1430 friend constexpr _BitMask
1431 operator&(
const _BitMask& __a,
const _BitMask& __b) noexcept
1438 _GLIBCXX_SIMD_INTRINSIC
1440 _M_is_constprop()
const
1442 if constexpr (_S_array_size == 0)
1443 return __builtin_constant_p(_M_bits[0]);
1446 for (
int __i = 0; __i < _S_array_size; ++__i)
1447 if (!__builtin_constant_p(_M_bits[__i]))
1458 template <
typename _Tp =
void>
1459 static inline constexpr
int __min_vector_size = 2 *
sizeof(_Tp);
1461 #if _GLIBCXX_SIMD_HAVE_NEON
1463 inline constexpr
int __min_vector_size<void> = 8;
1466 inline constexpr
int __min_vector_size<void> = 16;
1471 template <
typename _Tp,
size_t _Np,
typename =
void>
1472 struct __vector_type_n {};
1475 template <
typename _Tp>
1476 struct __vector_type_n<_Tp, 0, void> {};
1479 template <
typename _Tp>
1480 struct __vector_type_n<_Tp, 1,
enable_if_t<__is_vectorizable_v<_Tp>>>
1481 {
using type = _Tp; };
1484 template <
typename _Tp,
size_t _Np>
1485 struct __vector_type_n<_Tp, _Np,
1486 enable_if_t<__is_vectorizable_v<_Tp> && _Np >= 2>>
1488 static constexpr
size_t _S_Np2 = std::__bit_ceil(_Np *
sizeof(_Tp));
1490 static constexpr
size_t _S_Bytes =
1496 _S_Np2 < __min_vector_size<_Tp> ? __min_vector_size<_Tp>
1499 using type [[__gnu__::__vector_size__(_S_Bytes)]] = _Tp;
1502 template <
typename _Tp,
size_t _Bytes,
size_t = _Bytes % sizeof(_Tp)>
1503 struct __vector_type;
1505 template <
typename _Tp,
size_t _Bytes>
1506 struct __vector_type<_Tp, _Bytes, 0>
1507 : __vector_type_n<_Tp, _Bytes / sizeof(_Tp)> {};
1509 template <
typename _Tp,
size_t _Size>
1510 using __vector_type_t =
typename __vector_type_n<_Tp, _Size>::type;
1512 template <
typename _Tp>
1513 using __vector_type2_t =
typename __vector_type<_Tp, 2>::type;
1514 template <
typename _Tp>
1515 using __vector_type4_t =
typename __vector_type<_Tp, 4>::type;
1516 template <
typename _Tp>
1517 using __vector_type8_t =
typename __vector_type<_Tp, 8>::type;
1518 template <
typename _Tp>
1519 using __vector_type16_t =
typename __vector_type<_Tp, 16>::type;
1520 template <
typename _Tp>
1521 using __vector_type32_t =
typename __vector_type<_Tp, 32>::type;
1522 template <
typename _Tp>
1523 using __vector_type64_t =
typename __vector_type<_Tp, 64>::type;
1527 template <
typename _Tp,
typename =
void_t<>>
1530 template <
typename _Tp>
1531 struct __is_vector_type<
1532 _Tp,
void_t<typename __vector_type<
1534 : is_same<_Tp, typename __vector_type<
1535 remove_reference_t<decltype(declval<_Tp>()[0])>,
1536 sizeof(_Tp)>::type> {};
1538 template <
typename _Tp>
1539 inline constexpr
bool __is_vector_type_v = __is_vector_type<_Tp>::value;
1543 #if _GLIBCXX_SIMD_HAVE_SSE_ABI
1544 template <
typename _Tp>
1545 using __is_intrinsic_type = __is_vector_type<_Tp>;
1547 template <
typename _Tp,
typename =
void_t<>>
1550 template <
typename _Tp>
1551 struct __is_intrinsic_type<
1552 _Tp,
void_t<typename __intrinsic_type<
1554 : is_same<_Tp, typename __intrinsic_type<
1555 remove_reference_t<decltype(declval<_Tp>()[0])>,
1556 sizeof(_Tp)>::type> {};
1559 template <
typename _Tp>
1560 inline constexpr
bool __is_intrinsic_type_v = __is_intrinsic_type<_Tp>::value;
1564 template <
typename _Tp,
typename =
void_t<>>
1565 struct _VectorTraitsImpl;
1567 template <
typename _Tp>
1568 struct _VectorTraitsImpl<_Tp,
enable_if_t<__is_vector_type_v<_Tp>
1569 || __is_intrinsic_type_v<_Tp>>>
1572 using value_type = remove_reference_t<decltype(declval<_Tp>()[0])>;
1573 static constexpr
int _S_full_size =
sizeof(_Tp) /
sizeof(value_type);
1574 using _Wrapper = _SimdWrapper<value_type, _S_full_size>;
1575 template <
typename _Up,
int _W = _S_full_size>
1576 static constexpr
bool _S_is
1577 = is_same_v<value_type, _Up> && _W == _S_full_size;
1580 template <
typename _Tp,
size_t _Np>
1581 struct _VectorTraitsImpl<_SimdWrapper<_Tp, _Np>,
1582 void_t<__vector_type_t<_Tp, _Np>>>
1584 using type = __vector_type_t<_Tp, _Np>;
1585 using value_type = _Tp;
1586 static constexpr
int _S_full_size =
sizeof(type) /
sizeof(value_type);
1587 using _Wrapper = _SimdWrapper<_Tp, _Np>;
1588 static constexpr
bool _S_is_partial = (_Np == _S_full_size);
1589 static constexpr
int _S_partial_width = _Np;
1590 template <
typename _Up,
int _W = _S_full_size>
1591 static constexpr
bool _S_is
1592 = is_same_v<value_type, _Up>&& _W == _S_full_size;
1595 template <typename _Tp, typename = typename _VectorTraitsImpl<_Tp>::type>
1596 using _VectorTraits = _VectorTraitsImpl<_Tp>;
1600 template <
typename _V>
1601 _GLIBCXX_SIMD_INTRINSIC constexpr
auto
1604 if constexpr (__is_vector_type_v<_V>)
1606 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value)
1607 return __data(__x)._M_data;
1608 else if constexpr (__is_vectorizable_v<_V>)
1609 return __vector_type_t<_V, 2>{__x};
1616 template <
size_t _Np = 0,
typename _V>
1617 _GLIBCXX_SIMD_INTRINSIC constexpr
auto
1618 __as_wrapper(_V __x)
1620 if constexpr (__is_vector_type_v<_V>)
1621 return _SimdWrapper<typename _VectorTraits<_V>::value_type,
1622 (_Np > 0 ? _Np : _VectorTraits<_V>::_S_full_size)>(__x);
1623 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value)
1625 static_assert(_V::size() == _Np);
1630 static_assert(_V::_S_size == _Np);
1637 template <
typename _To,
typename _From>
1638 _GLIBCXX_SIMD_INTRINSIC constexpr _To
1639 __intrin_bitcast(_From __v)
1641 static_assert((__is_vector_type_v<_From> || __is_intrinsic_type_v<_From>)
1642 && (__is_vector_type_v<_To> || __is_intrinsic_type_v<_To>));
1643 if constexpr (
sizeof(_To) ==
sizeof(_From))
1644 return reinterpret_cast<_To
>(__v);
1645 else if constexpr (
sizeof(_From) >
sizeof(_To))
1646 if constexpr (
sizeof(_To) >= 16)
1647 return reinterpret_cast<const __may_alias<_To>&>(__v);
1651 __builtin_memcpy(&__r, &__v,
sizeof(_To));
1654 #if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1655 else if constexpr (__have_avx &&
sizeof(_From) == 16 &&
sizeof(_To) == 32)
1656 return reinterpret_cast<_To>(__builtin_ia32_ps256_ps(
1657 reinterpret_cast<__vector_type_t<
float, 4>>(__v)));
1658 else if constexpr (__have_avx512f && sizeof(_From) == 16
1659 && sizeof(_To) == 64)
1660 return reinterpret_cast<_To>(__builtin_ia32_ps512_ps(
1661 reinterpret_cast<__vector_type_t<
float, 4>>(__v)));
1662 else if constexpr (__have_avx512f && sizeof(_From) == 32
1663 && sizeof(_To) == 64)
1664 return reinterpret_cast<_To>(__builtin_ia32_ps512_256ps(
1665 reinterpret_cast<__vector_type_t<
float, 8>>(__v)));
1667 else if constexpr (
sizeof(__v) <= 8)
1668 return reinterpret_cast<_To>(
1669 __vector_type_t<__int_for_sizeof_t<_From>, sizeof(_To) / sizeof(_From)>{
1670 reinterpret_cast<__int_for_sizeof_t<_From>
>(__v)});
1673 static_assert(
sizeof(_To) >
sizeof(_From));
1675 __builtin_memcpy(&__r, &__v,
sizeof(_From));
1682 template <
typename _To,
size_t _NN = 0,
typename _From,
1683 typename _FromVT = _VectorTraits<_From>,
1684 size_t _Np = _NN == 0 ?
sizeof(_From) /
sizeof(_To) : _NN>
1685 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_To, _Np>
1686 __vector_bitcast(_From __x)
1688 using _R = __vector_type_t<_To, _Np>;
1689 return __intrin_bitcast<_R>(__x);
1692 template <
typename _To,
size_t _NN = 0,
typename _Tp,
size_t _Nx,
1694 = _NN == 0 ?
sizeof(_SimdWrapper<_Tp, _Nx>) /
sizeof(_To) : _NN>
1695 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_To, _Np>
1696 __vector_bitcast(
const _SimdWrapper<_Tp, _Nx>& __x)
1698 static_assert(_Np > 1);
1699 return __intrin_bitcast<__vector_type_t<_To, _Np>>(__x._M_data);
1704 #ifdef _GLIBCXX_SIMD_WORKAROUND_PR85048
1705 template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1706 _To __convert_x86(_Tp);
1708 template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1709 _To __convert_x86(_Tp, _Tp);
1711 template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1712 _To __convert_x86(_Tp, _Tp, _Tp, _Tp);
1714 template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1715 _To __convert_x86(_Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp);
1717 template <
typename _To,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
1718 _To __convert_x86(_Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp,
1719 _Tp, _Tp, _Tp, _Tp);
1724 template <
typename _To,
typename _From>
1725 _GLIBCXX_SIMD_INTRINSIC constexpr _To
1726 __bit_cast(
const _From __x)
1728 #if __has_builtin(__builtin_bit_cast)
1729 return __builtin_bit_cast(_To, __x);
1731 static_assert(
sizeof(_To) ==
sizeof(_From));
1732 constexpr
bool __to_is_vectorizable
1733 = is_arithmetic_v<_To> || is_enum_v<_To>;
1734 constexpr
bool __from_is_vectorizable
1735 = is_arithmetic_v<_From> || is_enum_v<_From>;
1736 if constexpr (__is_vector_type_v<_To> && __is_vector_type_v<_From>)
1737 return reinterpret_cast<_To
>(__x);
1738 else if constexpr (__is_vector_type_v<_To> && __from_is_vectorizable)
1740 using _FV [[gnu::vector_size(
sizeof(_From))]] = _From;
1741 return reinterpret_cast<_To
>(_FV{__x});
1743 else if constexpr (__to_is_vectorizable && __from_is_vectorizable)
1745 using _TV [[gnu::vector_size(
sizeof(_To))]] = _To;
1746 using _FV [[gnu::vector_size(
sizeof(_From))]] = _From;
1747 return reinterpret_cast<_TV
>(_FV{__x})[0];
1749 else if constexpr (__to_is_vectorizable && __is_vector_type_v<_From>)
1751 using _TV [[gnu::vector_size(
sizeof(_To))]] = _To;
1752 return reinterpret_cast<_TV
>(__x)[0];
1757 __builtin_memcpy(
reinterpret_cast<char*
>(&__r),
1758 reinterpret_cast<const char*
>(&__x),
sizeof(_To));
1766 template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>,
1768 = __
intrinsic_type_t<
typename _TVT::value_type, _TVT::_S_full_size>>
1769 _GLIBCXX_SIMD_INTRINSIC constexpr _R
1770 __to_intrin(_Tp __x)
1772 static_assert(
sizeof(__x) <=
sizeof(_R),
1773 "__to_intrin may never drop values off the end");
1774 if constexpr (
sizeof(__x) ==
sizeof(_R))
1775 return reinterpret_cast<_R
>(__as_vector(__x));
1778 using _Up = __int_for_sizeof_t<_Tp>;
1779 return reinterpret_cast<_R
>(
1780 __vector_type_t<_Up,
sizeof(_R) /
sizeof(_Up)>{__bit_cast<_Up>(__x)});
1786 template <
typename _Tp,
typename... _Args>
1787 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp,
sizeof...(_Args)>
1788 __make_vector(
const _Args&... __args)
1790 return __vector_type_t<_Tp,
sizeof...(_Args)>{
static_cast<_Tp
>(__args)...};
1795 template <
size_t _Np,
typename _Tp>
1796 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp, _Np>
1797 __vector_broadcast(_Tp __x)
1799 return __call_with_n_evaluations<_Np>(
1800 [](
auto... __xx) {
return __vector_type_t<_Tp, _Np>{__xx...}; },
1801 [&__x](int) {
return __x; });
1806 template <
typename _Tp,
size_t _Np,
typename _Gp,
size_t... _I>
1807 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp, _Np>
1808 __generate_vector_impl(_Gp&& __gen, index_sequence<_I...>)
1810 return __vector_type_t<_Tp, _Np>{
1811 static_cast<_Tp
>(__gen(_SizeConstant<_I>()))...};
1814 template <
typename _V,
typename _VVT = _VectorTraits<_V>,
typename _Gp>
1815 _GLIBCXX_SIMD_INTRINSIC constexpr _V
1816 __generate_vector(_Gp&& __gen)
1818 if constexpr (__is_vector_type_v<_V>)
1819 return __generate_vector_impl<
typename _VVT::value_type,
1820 _VVT::_S_full_size>(
1821 static_cast<_Gp&&
>(__gen), make_index_sequence<_VVT::_S_full_size>());
1823 return __generate_vector_impl<
typename _VVT::value_type,
1824 _VVT::_S_partial_width>(
1825 static_cast<_Gp&&
>(__gen),
1826 make_index_sequence<_VVT::_S_partial_width>());
1829 template <
typename _Tp,
size_t _Np,
typename _Gp>
1830 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp, _Np>
1831 __generate_vector(_Gp&& __gen)
1833 return __generate_vector_impl<_Tp, _Np>(
static_cast<_Gp&&
>(__gen),
1834 make_index_sequence<_Np>());
1839 template <
typename _TW>
1840 _GLIBCXX_SIMD_INTRINSIC constexpr _TW
1841 __xor(_TW __a, _TW __b) noexcept
1843 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1845 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1846 _VectorTraitsImpl<_TW>>::value_type;
1847 if constexpr (is_floating_point_v<_Tp>)
1849 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1850 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1851 ^ __vector_bitcast<_Ip>(__b));
1853 else if constexpr (__is_vector_type_v<_TW>)
1856 return __a._M_data ^ __b._M_data;
1864 template <
typename _TW>
1865 _GLIBCXX_SIMD_INTRINSIC constexpr _TW
1866 __or(_TW __a, _TW __b) noexcept
1868 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1870 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1871 _VectorTraitsImpl<_TW>>::value_type;
1872 if constexpr (is_floating_point_v<_Tp>)
1874 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1875 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1876 | __vector_bitcast<_Ip>(__b));
1878 else if constexpr (__is_vector_type_v<_TW>)
1881 return __a._M_data | __b._M_data;
1889 template <
typename _TW>
1890 _GLIBCXX_SIMD_INTRINSIC constexpr _TW
1891 __and(_TW __a, _TW __b) noexcept
1893 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1895 using _Tp =
typename conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1896 _VectorTraitsImpl<_TW>>::value_type;
1897 if constexpr (is_floating_point_v<_Tp>)
1899 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
1900 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a)
1901 & __vector_bitcast<_Ip>(__b));
1903 else if constexpr (__is_vector_type_v<_TW>)
1906 return __a._M_data & __b._M_data;
1914 #if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1915 static constexpr
struct
1917 _GLIBCXX_SIMD_INTRINSIC __v4sf
1918 operator()(__v4sf __a, __v4sf __b)
const noexcept
1919 {
return __builtin_ia32_andnps(__a, __b); }
1921 _GLIBCXX_SIMD_INTRINSIC __v2df
1922 operator()(__v2df __a, __v2df __b)
const noexcept
1923 {
return __builtin_ia32_andnpd(__a, __b); }
1925 _GLIBCXX_SIMD_INTRINSIC __v2di
1926 operator()(__v2di __a, __v2di __b)
const noexcept
1927 {
return __builtin_ia32_pandn128(__a, __b); }
1929 _GLIBCXX_SIMD_INTRINSIC __v8sf
1930 operator()(__v8sf __a, __v8sf __b)
const noexcept
1931 {
return __builtin_ia32_andnps256(__a, __b); }
1933 _GLIBCXX_SIMD_INTRINSIC __v4df
1934 operator()(__v4df __a, __v4df __b)
const noexcept
1935 {
return __builtin_ia32_andnpd256(__a, __b); }
1937 _GLIBCXX_SIMD_INTRINSIC __v4di
1938 operator()(__v4di __a, __v4di __b)
const noexcept
1940 if constexpr (__have_avx2)
1941 return __builtin_ia32_andnotsi256(__a, __b);
1943 return reinterpret_cast<__v4di
>(
1944 __builtin_ia32_andnpd256(
reinterpret_cast<__v4df
>(__a),
1945 reinterpret_cast<__v4df
>(__b)));
1948 _GLIBCXX_SIMD_INTRINSIC __v16sf
1949 operator()(__v16sf __a, __v16sf __b)
const noexcept
1951 if constexpr (__have_avx512dq)
1952 return _mm512_andnot_ps(__a, __b);
1954 return reinterpret_cast<__v16sf
>(
1955 _mm512_andnot_si512(
reinterpret_cast<__v8di
>(__a),
1956 reinterpret_cast<__v8di
>(__b)));
1959 _GLIBCXX_SIMD_INTRINSIC __v8df
1960 operator()(__v8df __a, __v8df __b)
const noexcept
1962 if constexpr (__have_avx512dq)
1963 return _mm512_andnot_pd(__a, __b);
1965 return reinterpret_cast<__v8df
>(
1966 _mm512_andnot_si512(
reinterpret_cast<__v8di
>(__a),
1967 reinterpret_cast<__v8di
>(__b)));
1970 _GLIBCXX_SIMD_INTRINSIC __v8di
1971 operator()(__v8di __a, __v8di __b)
const noexcept
1972 {
return _mm512_andnot_si512(__a, __b); }
1976 template <
typename _TW>
1977 _GLIBCXX_SIMD_INTRINSIC constexpr _TW
1978 __andnot(_TW __a, _TW __b) noexcept
1980 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>)
1982 using _TVT = conditional_t<__is_simd_wrapper_v<_TW>, _TW,
1983 _VectorTraitsImpl<_TW>>;
1984 using _Tp =
typename _TVT::value_type;
1985 #if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__
1986 if constexpr (
sizeof(_TW) >= 16)
1988 const auto __ai = __to_intrin(__a);
1989 const auto __bi = __to_intrin(__b);
1990 if (!__builtin_is_constant_evaluated()
1991 && !(__builtin_constant_p(__ai) && __builtin_constant_p(__bi)))
1993 const auto __r = _S_x86_andnot(__ai, __bi);
1994 if constexpr (is_convertible_v<decltype(__r), _TW>)
1997 return reinterpret_cast<typename _TVT::type>(__r);
2001 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
2002 return __vector_bitcast<_Tp>(~__vector_bitcast<_Ip>(__a)
2003 & __vector_bitcast<_Ip>(__b));
2011 template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2012 _GLIBCXX_SIMD_INTRINSIC constexpr _Tp
2013 __not(_Tp __a) noexcept
2015 if constexpr (is_floating_point_v<typename _TVT::value_type>)
2016 return reinterpret_cast<typename _TVT::type
>(
2017 ~__vector_bitcast<unsigned>(__a));
2024 template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>,
2025 typename _R = __vector_type_t<
typename _TVT::value_type,
2026 _TVT::_S_full_size * 2>>
2028 __concat(_Tp a_, _Tp b_)
2030 #ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_1
2032 = conditional_t<is_floating_point_v<typename _TVT::value_type>, double,
2034 long long,
typename _TVT::value_type>>;
2035 constexpr
int input_width =
sizeof(_Tp) /
sizeof(_W);
2036 const auto __a = __vector_bitcast<_W>(a_);
2037 const auto __b = __vector_bitcast<_W>(b_);
2038 using _Up = __vector_type_t<_W,
sizeof(_R) /
sizeof(_W)>;
2040 constexpr
int input_width = _TVT::_S_full_size;
2041 const _Tp& __a = a_;
2042 const _Tp& __b = b_;
2045 if constexpr (input_width == 2)
2046 return reinterpret_cast<_R>(_Up{__a[0], __a[1], __b[0], __b[1]});
2047 else if constexpr (input_width == 4)
2048 return reinterpret_cast<_R>(
2049 _Up{__a[0], __a[1], __a[2], __a[3], __b[0], __b[1], __b[2], __b[3]});
2050 else if constexpr (input_width == 8)
2051 return reinterpret_cast<_R>(
2052 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6], __a[7],
2053 __b[0], __b[1], __b[2], __b[3], __b[4], __b[5], __b[6], __b[7]});
2054 else if constexpr (input_width == 16)
2055 return reinterpret_cast<_R>(
2056 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6],
2057 __a[7], __a[8], __a[9], __a[10], __a[11], __a[12], __a[13],
2058 __a[14], __a[15], __b[0], __b[1], __b[2], __b[3], __b[4],
2059 __b[5], __b[6], __b[7], __b[8], __b[9], __b[10], __b[11],
2060 __b[12], __b[13], __b[14], __b[15]});
2061 else if constexpr (input_width == 32)
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], __a[16], __a[17], __a[18], __a[19], __a[20],
2066 __a[21], __a[22], __a[23], __a[24], __a[25], __a[26], __a[27],
2067 __a[28], __a[29], __a[30], __a[31], __b[0], __b[1], __b[2],
2068 __b[3], __b[4], __b[5], __b[6], __b[7], __b[8], __b[9],
2069 __b[10], __b[11], __b[12], __b[13], __b[14], __b[15], __b[16],
2070 __b[17], __b[18], __b[19], __b[20], __b[21], __b[22], __b[23],
2071 __b[24], __b[25], __b[26], __b[27], __b[28], __b[29], __b[30],
2077 template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2078 struct _ZeroExtendProxy
2080 using value_type =
typename _TVT::value_type;
2081 static constexpr
size_t _Np = _TVT::_S_full_size;
2084 template <
typename _To,
typename _ToVT = _VectorTraits<_To>,
2086 = enable_if_t<is_same_v<
typename _ToVT::value_type, value_type>>>
2087 _GLIBCXX_SIMD_INTRINSIC
operator _To()
const
2089 constexpr
size_t _ToN = _ToVT::_S_full_size;
2090 if constexpr (_ToN == _Np)
2092 else if constexpr (_ToN == 2 * _Np)
2094 #ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_3
2095 if constexpr (__have_avx && _TVT::template _S_is<float, 4>)
2096 return __vector_bitcast<value_type>(
2097 _mm256_insertf128_ps(__m256(), __x, 0));
2098 else if constexpr (__have_avx && _TVT::template _S_is<double, 2>)
2099 return __vector_bitcast<value_type>(
2100 _mm256_insertf128_pd(__m256d(), __x, 0));
2101 else if constexpr (__have_avx2 && _Np *
sizeof(value_type) == 16)
2102 return __vector_bitcast<value_type>(
2103 _mm256_insertf128_si256(__m256i(), __to_intrin(__x), 0));
2104 else if constexpr (__have_avx512f && _TVT::template _S_is<
float, 8>)
2106 if constexpr (__have_avx512dq)
2107 return __vector_bitcast<value_type>(
2108 _mm512_insertf32x8(__m512(), __x, 0));
2110 return reinterpret_cast<__m512
>(
2111 _mm512_insertf64x4(__m512d(),
2112 reinterpret_cast<__m256d
>(__x), 0));
2114 else if constexpr (__have_avx512f
2115 && _TVT::template _S_is<double, 4>)
2116 return __vector_bitcast<value_type>(
2117 _mm512_insertf64x4(__m512d(), __x, 0));
2118 else if constexpr (__have_avx512f && _Np *
sizeof(value_type) == 32)
2119 return __vector_bitcast<value_type>(
2120 _mm512_inserti64x4(__m512i(), __to_intrin(__x), 0));
2122 return __concat(__x, _Tp());
2124 else if constexpr (_ToN == 4 * _Np)
2126 #ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_3
2127 if constexpr (__have_avx512dq && _TVT::template _S_is<double, 2>)
2129 return __vector_bitcast<value_type>(
2130 _mm512_insertf64x2(__m512d(), __x, 0));
2132 else if constexpr (__have_avx512f
2133 && is_floating_point_v<value_type>)
2135 return __vector_bitcast<value_type>(
2136 _mm512_insertf32x4(__m512(),
reinterpret_cast<__m128
>(__x),
2139 else if constexpr (__have_avx512f && _Np *
sizeof(value_type) == 16)
2141 return __vector_bitcast<value_type>(
2142 _mm512_inserti32x4(__m512i(), __to_intrin(__x), 0));
2145 return __concat(__concat(__x, _Tp()),
2146 __vector_type_t<value_type, _Np * 2>());
2148 else if constexpr (_ToN == 8 * _Np)
2149 return __concat(
operator __vector_type_t<value_type, _Np * 4>(),
2150 __vector_type_t<value_type, _Np * 4>());
2151 else if constexpr (_ToN == 16 * _Np)
2152 return __concat(
operator __vector_type_t<value_type, _Np * 8>(),
2153 __vector_type_t<value_type, _Np * 8>());
2155 __assert_unreachable<_Tp>();
2159 template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2160 _GLIBCXX_SIMD_INTRINSIC _ZeroExtendProxy<_Tp, _TVT>
2161 __zero_extend(_Tp __x)
2166 template <
int _Offset,
2169 typename _TVT = _VectorTraits<_Tp>,
2170 typename _R = __vector_type_t<
typename _TVT::value_type,
2171 _TVT::_S_full_size / _SplitBy>>
2172 _GLIBCXX_SIMD_INTRINSIC constexpr _R
2175 using value_type =
typename _TVT::value_type;
2176 #if _GLIBCXX_SIMD_X86INTRIN
2177 if constexpr (
sizeof(_Tp) == 64 && _SplitBy == 4 && _Offset > 0)
2179 if constexpr (__have_avx512dq && is_same_v<double, value_type>)
2180 return _mm512_extractf64x2_pd(__to_intrin(__in), _Offset);
2181 else if constexpr (is_floating_point_v<value_type>)
2182 return __vector_bitcast<value_type>(
2183 _mm512_extractf32x4_ps(__intrin_bitcast<__m512>(__in), _Offset));
2185 return reinterpret_cast<_R
>(
2186 _mm512_extracti32x4_epi32(__intrin_bitcast<__m512i>(__in),
2192 #ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_1
2194 is_floating_point_v<value_type>, double,
2196 static_assert(
sizeof(_R) %
sizeof(_W) == 0);
2197 constexpr
int __return_width =
sizeof(_R) /
sizeof(_W);
2198 using _Up = __vector_type_t<_W, __return_width>;
2199 const auto __x = __vector_bitcast<_W>(__in);
2201 constexpr
int __return_width = _TVT::_S_full_size / _SplitBy;
2203 const __vector_type_t<value_type, _TVT::_S_full_size>& __x
2206 constexpr
int _O = _Offset * __return_width;
2207 return __call_with_subscripts<__return_width, _O>(
2208 __x, [](
auto... __entries) {
2209 return reinterpret_cast<_R
>(_Up{__entries...});
2216 template <
typename _Tp,
2218 = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2219 _GLIBCXX_SIMD_INTRINSIC constexpr _R
2223 __builtin_memcpy(&__r, &__x, 8);
2227 template <
typename _Tp,
2229 = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2230 _GLIBCXX_SIMD_INTRINSIC constexpr _R
2233 static_assert(
sizeof(_Tp) == 16,
"use __hi64z if you meant it");
2235 __builtin_memcpy(&__r,
reinterpret_cast<const char*
>(&__x) + 8, 8);
2239 template <
typename _Tp,
2241 = __vector_type8_t<typename _VectorTraits<_Tp>::value_type>>
2242 _GLIBCXX_SIMD_INTRINSIC constexpr _R
2243 __hi64z([[maybe_unused]] _Tp __x)
2246 if constexpr (
sizeof(_Tp) == 16)
2247 __builtin_memcpy(&__r, reinterpret_cast<const
char*>(&__x) + 8, 8);
2253 template <typename _Tp>
2254 _GLIBCXX_SIMD_INTRINSIC constexpr auto
2256 {
return __extract<0,
sizeof(_Tp) / 16>(__x); }
2258 template <
typename _Tp>
2259 _GLIBCXX_SIMD_INTRINSIC constexpr
auto
2262 static_assert(
sizeof(__x) == 32);
2263 return __extract<1, 2>(__x);
2268 template <
typename _Tp>
2269 _GLIBCXX_SIMD_INTRINSIC constexpr
auto
2272 static_assert(
sizeof(__x) == 64);
2273 return __extract<0, 2>(__x);
2276 template <
typename _Tp>
2277 _GLIBCXX_SIMD_INTRINSIC constexpr
auto
2280 static_assert(
sizeof(__x) == 64);
2281 return __extract<1, 2>(__x);
2286 template <
typename _Tp>
2289 static_assert(__is_vector_type_v<_Tp>);
2293 template <
typename _Up,
typename _UVT = _VectorTraits<_Up>>
2294 _GLIBCXX_SIMD_INTRINSIC constexpr
operator _Up()
const
2295 {
return __intrin_bitcast<typename _UVT::type>(__x); }
2298 template <
typename _Tp>
2299 _GLIBCXX_SIMD_INTRINSIC constexpr _AutoCast<_Tp>
2300 __auto_bitcast(
const _Tp& __x)
2303 template <
typename _Tp,
size_t _Np>
2304 _GLIBCXX_SIMD_INTRINSIC constexpr
2305 _AutoCast<typename _SimdWrapper<_Tp, _Np>::_BuiltinType>
2306 __auto_bitcast(
const _SimdWrapper<_Tp, _Np>& __x)
2307 {
return {__x._M_data}; }
2312 #if _GLIBCXX_SIMD_HAVE_SSE_ABI
2314 #if _GLIBCXX_SIMD_HAVE_AVX512F && _GLIBCXX_SIMD_X86INTRIN
2315 template <
size_t _Size>
2316 struct __bool_storage_member_type
2318 static_assert((_Size & (_Size - 1)) != 0,
2319 "This trait may only be used for non-power-of-2 sizes. "
2320 "Power-of-2 sizes must be specialized.");
2322 typename __bool_storage_member_type<std::__bit_ceil(_Size)>::type;
2326 struct __bool_storage_member_type<1> {
using type = bool; };
2329 struct __bool_storage_member_type<2> {
using type = __mmask8; };
2332 struct __bool_storage_member_type<4> {
using type = __mmask8; };
2335 struct __bool_storage_member_type<8> {
using type = __mmask8; };
2338 struct __bool_storage_member_type<16> {
using type = __mmask16; };
2341 struct __bool_storage_member_type<32> {
using type = __mmask32; };
2344 struct __bool_storage_member_type<64> {
using type = __mmask64; };
2350 #if _GLIBCXX_SIMD_HAVE_SSE
2351 template <
typename _Tp,
size_t _Bytes>
2352 struct __intrinsic_type<_Tp, _Bytes,
2353 enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 64>>
2355 static_assert(!is_same_v<_Tp, long double>,
2356 "no __intrinsic_type support for long double on x86");
2358 static constexpr
size_t _S_VBytes = _Bytes <= 16 ? 16
2362 using type [[__gnu__::__vector_size__(_S_VBytes)]]
2363 = conditional_t<is_integral_v<_Tp>,
long long int, _Tp>;
2370 #if _GLIBCXX_SIMD_HAVE_NEON
2372 struct __intrinsic_type<float, 8, void>
2373 {
using type = float32x2_t; };
2376 struct __intrinsic_type<float, 16, void>
2377 {
using type = float32x4_t; };
2379 #if _GLIBCXX_SIMD_HAVE_NEON_A64
2381 struct __intrinsic_type<double, 8, void>
2382 {
using type = float64x1_t; };
2385 struct __intrinsic_type<double, 16, void>
2386 {
using type = float64x2_t; };
2389 #define _GLIBCXX_SIMD_ARM_INTRIN(_Bits, _Np) \
2391 struct __intrinsic_type<__int_with_sizeof_t<_Bits / 8>, \
2392 _Np * _Bits / 8, void> \
2393 { using type = int##_Bits##x##_Np##_t; }; \
2395 struct __intrinsic_type<make_unsigned_t<__int_with_sizeof_t<_Bits / 8>>, \
2396 _Np * _Bits / 8, void> \
2397 { using type = uint##_Bits##x##_Np##_t; }
2398 _GLIBCXX_SIMD_ARM_INTRIN(8, 8);
2399 _GLIBCXX_SIMD_ARM_INTRIN(8, 16);
2400 _GLIBCXX_SIMD_ARM_INTRIN(16, 4);
2401 _GLIBCXX_SIMD_ARM_INTRIN(16, 8);
2402 _GLIBCXX_SIMD_ARM_INTRIN(32, 2);
2403 _GLIBCXX_SIMD_ARM_INTRIN(32, 4);
2404 _GLIBCXX_SIMD_ARM_INTRIN(64, 1);
2405 _GLIBCXX_SIMD_ARM_INTRIN(64, 2);
2406 #undef _GLIBCXX_SIMD_ARM_INTRIN
2408 template <
typename _Tp,
size_t _Bytes>
2409 struct __intrinsic_type<_Tp, _Bytes,
2410 enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 16>>
2412 static constexpr
int _SVecBytes = _Bytes <= 8 ? 8 : 16;
2413 using _Ip = __int_for_sizeof_t<_Tp>;
2415 is_floating_point_v<_Tp>, _Tp,
2416 conditional_t<is_unsigned_v<_Tp>, make_unsigned_t<_Ip>, _Ip>>;
2417 static_assert(!is_same_v<_Tp, _Up> || _SVecBytes != _Bytes,
2418 "should use explicit specialization above");
2419 using type =
typename __intrinsic_type<_Up, _SVecBytes>::type;
2426 template <
typename _Tp>
2427 struct __intrinsic_type_impl;
2429 #define _GLIBCXX_SIMD_PPC_INTRIN(_Tp) \
2431 struct __intrinsic_type_impl<_Tp> { using type = __vector _Tp; }
2432 _GLIBCXX_SIMD_PPC_INTRIN(
float);
2434 _GLIBCXX_SIMD_PPC_INTRIN(
double);
2436 _GLIBCXX_SIMD_PPC_INTRIN(
signed char);
2437 _GLIBCXX_SIMD_PPC_INTRIN(
unsigned char);
2438 _GLIBCXX_SIMD_PPC_INTRIN(
signed short);
2439 _GLIBCXX_SIMD_PPC_INTRIN(
unsigned short);
2440 _GLIBCXX_SIMD_PPC_INTRIN(
signed int);
2441 _GLIBCXX_SIMD_PPC_INTRIN(
unsigned int);
2442 #if defined __VSX__ || __SIZEOF_LONG__ == 4
2443 _GLIBCXX_SIMD_PPC_INTRIN(
signed long);
2444 _GLIBCXX_SIMD_PPC_INTRIN(
unsigned long);
2447 _GLIBCXX_SIMD_PPC_INTRIN(
signed long long);
2448 _GLIBCXX_SIMD_PPC_INTRIN(
unsigned long long);
2450 #undef _GLIBCXX_SIMD_PPC_INTRIN
2452 template <
typename _Tp,
size_t _Bytes>
2453 struct __intrinsic_type<_Tp, _Bytes,
2454 enable_if_t<__is_vectorizable_v<_Tp> && _Bytes <= 16>>
2456 static constexpr
bool _S_is_ldouble = is_same_v<_Tp, long double>;
2458 static_assert(!(_S_is_ldouble &&
sizeof(
long double) >
sizeof(
double)),
2459 "no __intrinsic_type support for 128-bit floating point on PowerPC");
2461 static_assert(!(is_same_v<_Tp, double>
2462 || (_S_is_ldouble &&
sizeof(
long double) ==
sizeof(
double))),
2463 "no __intrinsic_type support for 64-bit floating point on PowerPC w/o VSX");
2466 typename __intrinsic_type_impl<
2467 conditional_t<is_floating_point_v<_Tp>,
2468 conditional_t<_S_is_ldouble, double, _Tp>,
2469 __int_for_sizeof_t<_Tp>>>::type;
2475 template <
size_t _W
idth>
2476 struct _SimdWrapper<bool, _Width,
2477 void_t<typename __bool_storage_member_type<_Width>::type>>
2479 using _BuiltinType =
typename __bool_storage_member_type<_Width>::type;
2480 using value_type = bool;
2482 static constexpr
size_t _S_full_size =
sizeof(_BuiltinType) * __CHAR_BIT__;
2484 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper<bool, _S_full_size>
2485 __as_full_vector()
const {
return _M_data; }
2487 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper() =
default;
2488 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper(_BuiltinType __k)
2491 _GLIBCXX_SIMD_INTRINSIC
operator const _BuiltinType&()
const
2494 _GLIBCXX_SIMD_INTRINSIC
operator _BuiltinType&()
2497 _GLIBCXX_SIMD_INTRINSIC _BuiltinType __intrin()
const
2500 _GLIBCXX_SIMD_INTRINSIC constexpr value_type operator[](
size_t __i)
const
2501 {
return _M_data & (_BuiltinType(1) << __i); }
2503 template <
size_t __i>
2504 _GLIBCXX_SIMD_INTRINSIC constexpr value_type
2505 operator[](_SizeConstant<__i>)
const
2506 {
return _M_data & (_BuiltinType(1) << __i); }
2508 _GLIBCXX_SIMD_INTRINSIC constexpr
void _M_set(
size_t __i, value_type __x)
2511 _M_data |= (_BuiltinType(1) << __i);
2513 _M_data &= ~(_BuiltinType(1) << __i);
2516 _GLIBCXX_SIMD_INTRINSIC
2517 constexpr
bool _M_is_constprop()
const
2518 {
return __builtin_constant_p(_M_data); }
2520 _GLIBCXX_SIMD_INTRINSIC constexpr
bool _M_is_constprop_none_of()
const
2522 if (__builtin_constant_p(_M_data))
2524 constexpr
int __nbits =
sizeof(_BuiltinType) * __CHAR_BIT__;
2525 constexpr _BuiltinType __active_mask
2526 = ~_BuiltinType() >> (__nbits - _Width);
2527 return (_M_data & __active_mask) == 0;
2532 _GLIBCXX_SIMD_INTRINSIC constexpr
bool _M_is_constprop_all_of()
const
2534 if (__builtin_constant_p(_M_data))
2536 constexpr
int __nbits =
sizeof(_BuiltinType) * __CHAR_BIT__;
2537 constexpr _BuiltinType __active_mask
2538 = ~_BuiltinType() >> (__nbits - _Width);
2539 return (_M_data & __active_mask) == __active_mask;
2544 _BuiltinType _M_data;
2548 template <
bool _MustZeroInitPadding,
typename _BuiltinType>
2549 struct _SimdWrapperBase;
2551 template <
typename _BuiltinType>
2552 struct _SimdWrapperBase<false, _BuiltinType>
2554 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapperBase() =
default;
2555 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapperBase(_BuiltinType __init)
2559 _BuiltinType _M_data;
2562 template <
typename _BuiltinType>
2563 struct _SimdWrapperBase<true, _BuiltinType>
2566 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapperBase() : _M_data() {}
2567 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapperBase(_BuiltinType __init)
2571 _BuiltinType _M_data;
2576 template <
typename _Tp,
size_t _W
idth>
2577 struct _SimdWrapper<
2579 void_t<__vector_type_t<_Tp, _Width>, __intrinsic_type_t<_Tp, _Width>>>
2580 : _SimdWrapperBase<__has_iec559_behavior<__signaling_NaN, _Tp>::value
2581 && sizeof(_Tp) * _Width
2582 == sizeof(__vector_type_t<_Tp, _Width>),
2583 __vector_type_t<_Tp, _Width>>
2586 = _SimdWrapperBase<__has_iec559_behavior<__signaling_NaN, _Tp>::value
2587 &&
sizeof(_Tp) * _Width
2588 ==
sizeof(__vector_type_t<_Tp, _Width>),
2589 __vector_type_t<_Tp, _Width>>;
2591 static_assert(__is_vectorizable_v<_Tp>);
2592 static_assert(_Width >= 2);
2594 using _BuiltinType = __vector_type_t<_Tp, _Width>;
2595 using value_type = _Tp;
2597 static inline constexpr
size_t _S_full_size
2598 =
sizeof(_BuiltinType) /
sizeof(value_type);
2599 static inline constexpr
int _S_size = _Width;
2600 static inline constexpr
bool _S_is_partial = _S_full_size != _S_size;
2602 using _Base::_M_data;
2604 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper<_Tp, _S_full_size>
2605 __as_full_vector()
const
2608 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper(initializer_list<_Tp> __init)
2609 : _Base(__generate_from_n_evaluations<_Width, _BuiltinType>(
2610 [&](auto __i) {
return __init.begin()[__i.value]; })) {}
2612 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper() =
default;
2613 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper(
const _SimdWrapper&)
2615 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper(_SimdWrapper&&) =
default;
2617 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper&
2618 operator=(
const _SimdWrapper&) =
default;
2619 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper&
2620 operator=(_SimdWrapper&&) =
default;
2622 template <
typename _V,
typename =
enable_if_t<disjunction_v<
2623 is_same<_V, __vector_type_t<_Tp, _Width>>,
2624 is_same<_V, __intrinsic_type_t<_Tp, _Width>>>>>
2625 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper(_V __x)
2627 : _Base(__vector_bitcast<_Tp, _Width>(__x)) {}
2629 template <
typename... _As,
2630 typename =
enable_if_t<((is_same_v<simd_abi::scalar, _As> && ...)
2631 &&
sizeof...(_As) <= _Width)>>
2632 _GLIBCXX_SIMD_INTRINSIC constexpr
2633 operator _SimdTuple<_Tp, _As...>()
const
2635 const auto& dd = _M_data;
2636 return __generate_from_n_evaluations<
sizeof...(_As),
2637 _SimdTuple<_Tp, _As...>>([&](
2638 auto __i) constexpr {
return dd[int(__i)]; });
2641 _GLIBCXX_SIMD_INTRINSIC constexpr
operator const _BuiltinType&()
const
2644 _GLIBCXX_SIMD_INTRINSIC constexpr
operator _BuiltinType&()
2647 _GLIBCXX_SIMD_INTRINSIC constexpr _Tp operator[](
size_t __i)
const
2648 {
return _M_data[__i]; }
2650 template <
size_t __i>
2651 _GLIBCXX_SIMD_INTRINSIC constexpr _Tp operator[](_SizeConstant<__i>)
const
2652 {
return _M_data[__i]; }
2654 _GLIBCXX_SIMD_INTRINSIC constexpr
void _M_set(
size_t __i, _Tp __x)
2655 { _M_data[__i] = __x; }
2657 _GLIBCXX_SIMD_INTRINSIC
2658 constexpr
bool _M_is_constprop()
const
2659 {
return __builtin_constant_p(_M_data); }
2661 _GLIBCXX_SIMD_INTRINSIC constexpr
bool _M_is_constprop_none_of()
const
2663 if (__builtin_constant_p(_M_data))
2666 if constexpr (is_floating_point_v<_Tp>)
2668 using _Ip = __int_for_sizeof_t<_Tp>;
2669 const auto __intdata = __vector_bitcast<_Ip>(_M_data);
2670 __execute_n_times<_Width>(
2671 [&](
auto __i) { __r &= __intdata[__i.value] == _Ip(); });
2674 __execute_n_times<_Width>(
2675 [&](
auto __i) { __r &= _M_data[__i.value] == _Tp(); });
2681 _GLIBCXX_SIMD_INTRINSIC constexpr
bool _M_is_constprop_all_of()
const
2683 if (__builtin_constant_p(_M_data))
2686 if constexpr (is_floating_point_v<_Tp>)
2688 using _Ip = __int_for_sizeof_t<_Tp>;
2689 const auto __intdata = __vector_bitcast<_Ip>(_M_data);
2690 __execute_n_times<_Width>(
2691 [&](
auto __i) { __r &= __intdata[__i.value] == ~_Ip(); });
2694 __execute_n_times<_Width>(
2695 [&](
auto __i) { __r &= _M_data[__i.value] == ~_Tp(); });
2705 template <
typename _Tp>
2707 __vectorized_sizeof()
2709 if constexpr (!__is_vectorizable_v<_Tp>)
2712 if constexpr (
sizeof(_Tp) <= 8)
2715 if constexpr (__have_avx512bw)
2717 if constexpr (__have_avx512f &&
sizeof(_Tp) >= 4)
2719 if constexpr (__have_avx2)
2721 if constexpr (__have_avx && is_floating_point_v<_Tp>)
2723 if constexpr (__have_sse2)
2725 if constexpr (__have_sse && is_same_v<_Tp,
float>)
2735 if constexpr (__have_power8vec
2736 || (__have_power_vmx && (sizeof(_Tp) < 8))
2737 || (__have_power_vsx && is_floating_point_v<_Tp>) )
2741 if constexpr (__have_neon_a64
2742 || (__have_neon_a32 && !is_same_v<_Tp,
double>) )
2744 if constexpr (__have_neon
2749 && (__support_neon_float || !is_floating_point_v<_Tp>))
2757 namespace simd_abi {
2759 template <
typename _Tp>
2760 inline constexpr
int max_fixed_size
2761 = (__have_avx512bw &&
sizeof(_Tp) == 1) ? 64 : 32;
2764 #if defined __x86_64__ || defined __aarch64__
2765 template <
typename _Tp>
2766 using compatible =
conditional_t<(
sizeof(_Tp) <= 8), _VecBuiltin<16>, scalar>;
2767 #elif defined __ARM_NEON
2770 template <
typename _Tp>
2773 && (__support_neon_float || !is_floating_point_v<_Tp>)),
2774 _VecBuiltin<16>, scalar>;
2777 using compatible = scalar;
2782 template <
typename _Tp>
2784 __determine_native_abi()
2786 constexpr
size_t __bytes = __vectorized_sizeof<_Tp>();
2787 if constexpr (__bytes ==
sizeof(_Tp))
2788 return static_cast<scalar*
>(
nullptr);
2789 else if constexpr (__have_avx512vl || (__have_avx512f && __bytes == 64))
2790 return static_cast<_VecBltnBtmsk<__bytes>*>(
nullptr);
2792 return static_cast<_VecBuiltin<__bytes>*>(
nullptr);
2795 template <typename _Tp, typename =
enable_if_t<__is_vectorizable_v<_Tp>>>
2800 #if defined _GLIBCXX_SIMD_DEFAULT_ABI
2801 template <
typename _Tp>
2802 using __default_abi = _GLIBCXX_SIMD_DEFAULT_ABI<_Tp>;
2804 template <
typename _Tp>
2805 using __default_abi = compatible<_Tp>;
2813 template <
typename _Tp,
typename =
void_t<>>
2816 template <
typename _Tp>
2817 struct is_abi_tag<_Tp,
void_t<typename _Tp::_IsValidAbiTag>>
2818 :
public _Tp::_IsValidAbiTag {};
2820 template <
typename _Tp>
2821 inline constexpr
bool is_abi_tag_v = is_abi_tag<_Tp>::value;
2824 template <
typename _Tp>
2827 template <
typename _Tp>
2828 inline constexpr
bool is_simd_v = is_simd<_Tp>::value;
2830 template <
typename _Tp>
2833 template <
typename _Tp>
2834 inline constexpr
bool is_simd_mask_v = is_simd_mask<_Tp>::value;
2837 template <
typename _Tp,
typename _Abi,
typename =
void>
2838 struct __simd_size_impl {};
2840 template <
typename _Tp,
typename _Abi>
2841 struct __simd_size_impl<
2843 enable_if_t<conjunction_v<__is_vectorizable<_Tp>, is_abi_tag<_Abi>>>>
2844 : _SizeConstant<_Abi::template _S_size<_Tp>> {};
2846 template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2847 struct simd_size : __simd_size_impl<_Tp, _Abi> {};
2849 template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2850 inline constexpr
size_t simd_size_v = simd_size<_Tp, _Abi>::value;
2853 template <
typename _Tp,
size_t _Np,
typename =
void>
2854 struct __deduce_impl;
2856 namespace simd_abi {
2865 template <
typename _Tp,
size_t _Np,
typename...>
2868 template <
typename _Tp,
size_t _Np,
typename... _Abis>
2869 using deduce_t =
typename deduce<_Tp, _Np, _Abis...>::type;
2874 template <
typename _Tp,
typename _V,
typename =
void>
2877 template <
typename _Tp,
typename _Up,
typename _Abi>
2879 _Tp, simd<_Up, _Abi>,
2880 void_t<simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>>
2883 = simd<_Tp, simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>;
2886 template <
typename _Tp,
typename _Up,
typename _Abi>
2888 _Tp, simd_mask<_Up, _Abi>,
2889 void_t<simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>>
2892 = simd_mask<_Tp, simd_abi::deduce_t<_Tp, simd_size_v<_Up, _Abi>, _Abi>>;
2895 template <
typename _Tp,
typename _V>
2896 using rebind_simd_t =
typename rebind_simd<_Tp, _V>::type;
2899 template <
int _Np,
typename _V,
typename =
void>
2902 template <
int _Np,
typename _Tp,
typename _Abi>
2903 struct resize_simd<_Np, simd<_Tp, _Abi>,
2904 void_t<simd_abi::deduce_t<_Tp, _Np, _Abi>>>
2905 {
using type = simd<_Tp, simd_abi::deduce_t<_Tp, _Np, _Abi>>; };
2907 template <
int _Np,
typename _Tp,
typename _Abi>
2908 struct resize_simd<_Np, simd_mask<_Tp, _Abi>,
2909 void_t<simd_abi::deduce_t<_Tp, _Np, _Abi>>>
2910 {
using type = simd_mask<_Tp, simd_abi::deduce_t<_Tp, _Np, _Abi>>; };
2912 template <
int _Np,
typename _V>
2913 using resize_simd_t =
typename resize_simd<_Np, _V>::type;
2917 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
2918 struct memory_alignment
2919 :
public _SizeConstant<vector_aligned_tag::_S_alignment<_Tp, _Up>> {};
2921 template <
typename _Tp,
typename _Up =
typename _Tp::value_type>
2922 inline constexpr
size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value;
2925 template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2928 template <
typename _Tp,
typename _Abi>
2929 struct is_simd<simd<_Tp, _Abi>> :
public true_type {};
2931 template <
typename _Tp>
2932 using native_simd = simd<_Tp, simd_abi::native<_Tp>>;
2934 template <
typename _Tp,
int _Np>
2935 using fixed_size_simd = simd<_Tp, simd_abi::fixed_size<_Np>>;
2937 template <
typename _Tp,
size_t _Np>
2938 using __deduced_simd = simd<_Tp, simd_abi::deduce_t<_Tp, _Np>>;
2941 template <
typename _Tp,
typename _Abi = simd_abi::__default_abi<_Tp>>
2944 template <
typename _Tp,
typename _Abi>
2945 struct is_simd_mask<simd_mask<_Tp, _Abi>> :
public true_type {};
2947 template <
typename _Tp>
2948 using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>;
2950 template <
typename _Tp,
int _Np>
2951 using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>;
2953 template <
typename _Tp,
size_t _Np>
2954 using __deduced_simd_mask = simd_mask<_Tp, simd_abi::deduce_t<_Tp, _Np>>;
2958 template <
typename _Tp,
typename _Up,
typename _Ap,
bool = is_simd_v<_Tp>,
2960 struct __static_simd_cast_return_type;
2962 template <
typename _Tp,
typename _A0,
typename _Up,
typename _Ap>
2963 struct __static_simd_cast_return_type<simd_mask<_Tp, _A0>, _Up, _Ap, false,
2965 : __static_simd_cast_return_type<simd<_Tp, _A0>, _Up, _Ap> {};
2967 template <
typename _Tp,
typename _Up,
typename _Ap>
2968 struct __static_simd_cast_return_type<
2969 _Tp, _Up, _Ap, true,
enable_if_t<_Tp::size() == simd_size_v<_Up, _Ap>>>
2970 {
using type = _Tp; };
2972 template <
typename _Tp,
typename _Ap>
2973 struct __static_simd_cast_return_type<_Tp, _Tp, _Ap, false,
2974 #ifdef _GLIBCXX_SIMD_FIX_P2TS_ISSUE66
2980 {
using type = simd<_Tp, _Ap>; };
2982 template <
typename _Tp,
typename =
void>
2983 struct __safe_make_signed {
using type = _Tp;};
2985 template <
typename _Tp>
2986 struct __safe_make_signed<_Tp,
enable_if_t<is_integral_v<_Tp>>>
2989 using type = make_signed_t<make_unsigned_t<_Tp>>;
2992 template <
typename _Tp>
2993 using safe_make_signed_t =
typename __safe_make_signed<_Tp>::type;
2995 template <
typename _Tp,
typename _Up,
typename _Ap>
2996 struct __static_simd_cast_return_type<_Tp, _Up, _Ap, false,
2997 #ifdef _GLIBCXX_SIMD_FIX_P2TS_ISSUE66
3005 (is_integral_v<_Up> && is_integral_v<_Tp> &&
3006 #ifndef _GLIBCXX_SIMD_FIX_P2TS_ISSUE65
3007 is_signed_v<_Up> != is_signed_v<_Tp> &&
3009 is_same_v<safe_make_signed_t<_Up>, safe_make_signed_t<_Tp>>),
3010 simd<_Tp, _Ap>, fixed_size_simd<_Tp, simd_size_v<_Up, _Ap>>>;
3013 template <
typename _Tp,
typename _Up,
typename _Ap,
3015 =
typename __static_simd_cast_return_type<_Tp, _Up, _Ap>::type>
3016 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _R
3017 static_simd_cast(
const simd<_Up, _Ap>& __x)
3019 if constexpr (is_same<_R, simd<_Up, _Ap>>::value)
3023 _SimdConverter<_Up, _Ap, typename _R::value_type, typename _R::abi_type>
3025 return _R(__private_init, __c(__data(__x)));
3029 namespace __proposed {
3030 template <
typename _Tp,
typename _Up,
typename _Ap,
3032 =
typename __static_simd_cast_return_type<_Tp, _Up, _Ap>::type>
3033 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
typename _R::mask_type
3034 static_simd_cast(
const simd_mask<_Up, _Ap>& __x)
3036 using _RM =
typename _R::mask_type;
3037 return {__private_init, _RM::abi_type::_MaskImpl::template _S_convert<
3038 typename _RM::simd_type::value_type>(__x)};
3041 template <
typename _To,
typename _Up,
typename _Abi>
3042 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3044 simd_bit_cast(
const simd<_Up, _Abi>& __x)
3046 using _Tp =
typename _To::value_type;
3047 using _ToMember =
typename _SimdTraits<_Tp, typename _To::abi_type>::_SimdMember;
3048 using _From = simd<_Up, _Abi>;
3049 using _FromMember =
typename _SimdTraits<_Up, _Abi>::_SimdMember;
3051 static_assert(
sizeof(_To) ==
sizeof(_From));
3052 static_assert(is_trivially_copyable_v<_Tp> && is_trivially_copyable_v<_Up>);
3053 static_assert(is_trivially_copyable_v<_ToMember> && is_trivially_copyable_v<_FromMember>);
3054 #if __has_builtin(__builtin_bit_cast)
3055 return {__private_init, __builtin_bit_cast(_ToMember, __data(__x))};
3057 return {__private_init, __bit_cast<_ToMember>(__data(__x))};
3061 template <
typename _To,
typename _Up,
typename _Abi>
3062 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3064 simd_bit_cast(
const simd_mask<_Up, _Abi>& __x)
3066 using _From = simd_mask<_Up, _Abi>;
3067 static_assert(
sizeof(_To) ==
sizeof(_From));
3068 static_assert(is_trivially_copyable_v<_From>);
3071 if constexpr (is_simd_v<_To>)
3073 using _Tp =
typename _To::value_type;
3074 using _ToMember =
typename _SimdTraits<_Tp, typename _To::abi_type>::_SimdMember;
3075 static_assert(is_trivially_copyable_v<_ToMember>);
3076 #if __has_builtin(__builtin_bit_cast)
3077 return {__private_init, __builtin_bit_cast(_ToMember, __x)};
3079 return {__private_init, __bit_cast<_ToMember>(__x)};
3084 static_assert(is_trivially_copyable_v<_To>);
3085 #if __has_builtin(__builtin_bit_cast)
3086 return __builtin_bit_cast(_To, __x);
3088 return __bit_cast<_To>(__x);
3095 template <
typename _Tp,
typename _Up,
typename _Ap,
3096 typename _To = __value_type_or_identity_t<_Tp>>
3097 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
auto
3098 simd_cast(
const simd<_ValuePreserving<_Up, _To>, _Ap>& __x)
3099 -> decltype(static_simd_cast<_Tp>(__x))
3100 {
return static_simd_cast<_Tp>(__x); }
3102 namespace __proposed {
3103 template <
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_mask<_ValuePreserving<_Up, _To>, _Ap>& __x)
3107 -> decltype(static_simd_cast<_Tp>(__x))
3108 {
return static_simd_cast<_Tp>(__x); }
3113 namespace __proposed {
3140 template <
typename _Tp,
typename _Up,
typename _Ap>
3141 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
enable_if_t<
3142 conjunction_v<is_simd<_Tp>, is_same<typename _Tp::value_type, _Up>>, _Tp>
3143 resizing_simd_cast(
const simd<_Up, _Ap>& __x)
3145 if constexpr (is_same_v<typename _Tp::abi_type, _Ap>)
3147 else if constexpr (simd_size_v<_Up, _Ap> == 1)
3153 else if constexpr (_Tp::size() == 1)
3155 else if constexpr (sizeof(_Tp) == sizeof(__x)
3156 && !__is_fixed_size_abi_v<_Ap>)
3157 return {__private_init,
3158 __vector_bitcast<typename _Tp::value_type, _Tp::size()>(
3159 _Ap::_S_masked(__data(__x))._M_data)};
3163 __builtin_memcpy(&__data(__r), &__data(__x),
3165 *
std::min(_Tp::size(), simd_size_v<_Up, _Ap>));
3170 template <
typename _Tp,
typename _Up,
typename _Ap>
3171 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3172 enable_if_t<is_simd_mask_v<_Tp>, _Tp>
3173 resizing_simd_cast(
const simd_mask<_Up, _Ap>& __x)
3175 return {__private_init, _Tp::abi_type::_MaskImpl::template _S_convert<
3176 typename _Tp::simd_type::value_type>(__x)};
3182 template <
typename _Tp,
int _Np>
3183 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd<_Tp, _Np>
3184 to_fixed_size(
const fixed_size_simd<_Tp, _Np>& __x)
3187 template <
typename _Tp,
int _Np>
3188 _GLIBCXX_SIMD_INTRINSIC fixed_size_simd_mask<_Tp, _Np>
3189 to_fixed_size(
const fixed_size_simd_mask<_Tp, _Np>& __x)
3192 template <
typename _Tp,
typename _Ap>
3193 _GLIBCXX_SIMD_INTRINSIC
auto
3194 to_fixed_size(
const simd<_Tp, _Ap>& __x)
3196 return simd<_Tp, simd_abi::fixed_size<simd_size_v<_Tp, _Ap>>>([&__x](
3197 auto __i) constexpr {
return __x[__i]; });
3200 template <
typename _Tp,
typename _Ap>
3201 _GLIBCXX_SIMD_INTRINSIC
auto
3202 to_fixed_size(
const simd_mask<_Tp, _Ap>& __x)
3204 constexpr
int _Np = simd_mask<_Tp, _Ap>::size();
3205 fixed_size_simd_mask<_Tp, _Np> __r;
3206 __execute_n_times<_Np>([&](
auto __i) constexpr { __r[__i] = __x[__i]; });
3211 template <
typename _Tp,
int _Np>
3212 _GLIBCXX_SIMD_INTRINSIC
3213 enable_if_t<(_Np == native_simd<_Tp>::size()), native_simd<_Tp>>
3214 to_native(
const fixed_size_simd<_Tp, _Np>& __x)
3216 alignas(memory_alignment_v<native_simd<_Tp>>) _Tp __mem[_Np];
3217 __x.copy_to(__mem, vector_aligned);
3218 return {__mem, vector_aligned};
3221 template <
typename _Tp,
size_t _Np>
3222 _GLIBCXX_SIMD_INTRINSIC
3223 enable_if_t<(_Np == native_simd_mask<_Tp>::size()), native_simd_mask<_Tp>>
3224 to_native(
const fixed_size_simd_mask<_Tp, _Np>& __x)
3226 return native_simd_mask<_Tp>([&](
auto __i) constexpr {
return __x[__i]; });
3230 template <
typename _Tp,
size_t _Np>
3231 _GLIBCXX_SIMD_INTRINSIC
enable_if_t<(_Np == simd<_Tp>::size()), simd<_Tp>>
3232 to_compatible(
const simd<_Tp, simd_abi::fixed_size<_Np>>& __x)
3234 alignas(memory_alignment_v<simd<_Tp>>) _Tp __mem[_Np];
3235 __x.copy_to(__mem, vector_aligned);
3236 return {__mem, vector_aligned};
3239 template <
typename _Tp,
size_t _Np>
3240 _GLIBCXX_SIMD_INTRINSIC
3241 enable_if_t<(_Np == simd_mask<_Tp>::size()), simd_mask<_Tp>>
3242 to_compatible(
const simd_mask<_Tp, simd_abi::fixed_size<_Np>>& __x)
3243 {
return simd_mask<_Tp>([&](
auto __i) constexpr {
return __x[__i]; }); }
3249 template <
typename _M,
typename _Tp>
3250 class const_where_expression
3253 static_assert(is_same_v<_V, __remove_cvref_t<_Tp>>);
3255 struct _Wrapper {
using value_type = _V; };
3258 using _Impl =
typename _V::_Impl;
3261 typename conditional_t<is_arithmetic_v<_V>, _Wrapper, _V>::value_type;
3263 _GLIBCXX_SIMD_INTRINSIC
friend const _M&
3264 __get_mask(
const const_where_expression& __x)
3265 {
return __x._M_k; }
3267 _GLIBCXX_SIMD_INTRINSIC
friend const _Tp&
3268 __get_lvalue(
const const_where_expression& __x)
3269 {
return __x._M_value; }
3275 const_where_expression(
const const_where_expression&) =
delete;
3276 const_where_expression& operator=(
const const_where_expression&) =
delete;
3278 _GLIBCXX_SIMD_INTRINSIC const_where_expression(
const _M& __kk,
const _Tp& dd)
3279 : _M_k(__kk), _M_value(const_cast<_Tp&>(dd)) {}
3281 _GLIBCXX_SIMD_INTRINSIC _V
3284 return {__private_init,
3285 _Impl::template _S_masked_unary<negate>(__data(_M_k),
3289 template <
typename _Up,
typename _Flags>
3290 [[nodiscard]] _GLIBCXX_SIMD_INTRINSIC _V
3291 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _Flags)
const&&
3293 return {__private_init,
3294 _Impl::_S_masked_load(__data(_M_value), __data(_M_k),
3295 _Flags::template _S_apply<_V>(__mem))};
3298 template <
typename _Up,
typename _Flags>
3299 _GLIBCXX_SIMD_INTRINSIC
void
3300 copy_to(_LoadStorePtr<_Up, value_type>* __mem, _Flags)
const&&
3302 _Impl::_S_masked_store(__data(_M_value),
3303 _Flags::template _S_apply<_V>(__mem),
3309 template <
typename _Tp>
3310 class const_where_expression<bool, _Tp>
3315 static_assert(is_same_v<_V, __remove_cvref_t<_Tp>>);
3317 struct _Wrapper {
using value_type = _V; };
3321 typename conditional_t<is_arithmetic_v<_V>, _Wrapper, _V>::value_type;
3323 _GLIBCXX_SIMD_INTRINSIC
friend const _M&
3324 __get_mask(
const const_where_expression& __x)
3325 {
return __x._M_k; }
3327 _GLIBCXX_SIMD_INTRINSIC
friend const _Tp&
3328 __get_lvalue(
const const_where_expression& __x)
3329 {
return __x._M_value; }
3335 const_where_expression(
const const_where_expression&) =
delete;
3336 const_where_expression& operator=(
const const_where_expression&) =
delete;
3338 _GLIBCXX_SIMD_INTRINSIC const_where_expression(
const bool __kk,
const _Tp& dd)
3339 : _M_k(__kk), _M_value(const_cast<_Tp&>(dd)) {}
3341 _GLIBCXX_SIMD_INTRINSIC _V
operator-() const&&
3342 {
return _M_k ? -_M_value : _M_value; }
3344 template <
typename _Up,
typename _Flags>
3345 [[nodiscard]] _GLIBCXX_SIMD_INTRINSIC _V
3346 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _Flags)
const&&
3347 {
return _M_k ?
static_cast<_V
>(__mem[0]) : _M_value; }
3349 template <
typename _Up,
typename _Flags>
3350 _GLIBCXX_SIMD_INTRINSIC
void
3351 copy_to(_LoadStorePtr<_Up, value_type>* __mem, _Flags)
const&&
3354 __mem[0] = _M_value;
3359 template <
typename _M,
typename _Tp>
3360 class where_expression :
public const_where_expression<_M, _Tp>
3362 using _Impl =
typename const_where_expression<_M, _Tp>::_Impl;
3364 static_assert(!is_const<_Tp>::value,
3365 "where_expression may only be instantiated with __a non-const "
3368 using typename const_where_expression<_M, _Tp>::value_type;
3369 using const_where_expression<_M, _Tp>::_M_k;
3370 using const_where_expression<_M, _Tp>::_M_value;
3373 is_same<typename _M::abi_type, typename _Tp::abi_type>::value,
"");
3374 static_assert(_M::size() == _Tp::size(),
"");
3376 _GLIBCXX_SIMD_INTRINSIC
friend _Tp& __get_lvalue(where_expression& __x)
3377 {
return __x._M_value; }
3380 where_expression(
const where_expression&) =
delete;
3381 where_expression& operator=(
const where_expression&) =
delete;
3383 _GLIBCXX_SIMD_INTRINSIC where_expression(
const _M& __kk, _Tp& dd)
3384 : const_where_expression<_M, _Tp>(__kk, dd) {}
3386 template <
typename _Up>
3387 _GLIBCXX_SIMD_INTRINSIC
void operator=(_Up&& __x) &&
3389 _Impl::_S_masked_assign(__data(_M_k), __data(_M_value),
3390 __to_value_type_or_member_type<_Tp>(
3391 static_cast<_Up&&
>(__x)));
3394 #define _GLIBCXX_SIMD_OP_(__op, __name) \
3395 template <typename _Up> \
3396 _GLIBCXX_SIMD_INTRINSIC void operator __op##=(_Up&& __x)&& \
3398 _Impl::template _S_masked_cassign( \
3399 __data(_M_k), __data(_M_value), \
3400 __to_value_type_or_member_type<_Tp>(static_cast<_Up&&>(__x)), \
3401 [](auto __impl, auto __lhs, auto __rhs) constexpr { \
3402 return __impl.__name(__lhs, __rhs); \
3406 _GLIBCXX_SIMD_OP_(+, _S_plus);
3407 _GLIBCXX_SIMD_OP_(-, _S_minus);
3408 _GLIBCXX_SIMD_OP_(*, _S_multiplies);
3409 _GLIBCXX_SIMD_OP_(/, _S_divides);
3410 _GLIBCXX_SIMD_OP_(%, _S_modulus);
3411 _GLIBCXX_SIMD_OP_(&, _S_bit_and);
3412 _GLIBCXX_SIMD_OP_(|, _S_bit_or);
3413 _GLIBCXX_SIMD_OP_(^, _S_bit_xor);
3414 _GLIBCXX_SIMD_OP_(<<, _S_shift_left);
3415 _GLIBCXX_SIMD_OP_(>>, _S_shift_right);
3416 #undef _GLIBCXX_SIMD_OP_
3418 _GLIBCXX_SIMD_INTRINSIC
void operator++() &&
3421 = _Impl::template _S_masked_unary<__increment>(__data(_M_k),
3425 _GLIBCXX_SIMD_INTRINSIC
void operator++(
int) &&
3428 = _Impl::template _S_masked_unary<__increment>(__data(_M_k),
3432 _GLIBCXX_SIMD_INTRINSIC
void operator--() &&
3435 = _Impl::template _S_masked_unary<__decrement>(__data(_M_k),
3439 _GLIBCXX_SIMD_INTRINSIC
void operator--(
int) &&
3442 = _Impl::template _S_masked_unary<__decrement>(__data(_M_k),
3447 template <
typename _Up,
typename _Flags>
3448 _GLIBCXX_SIMD_INTRINSIC
void
3449 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _Flags) &&
3452 = _Impl::_S_masked_load(__data(_M_value), __data(_M_k),
3453 _Flags::template _S_apply<_Tp>(__mem));
3458 template <
typename _Tp>
3459 class where_expression<bool, _Tp> :
public const_where_expression<bool, _Tp>
3462 using typename const_where_expression<_M, _Tp>::value_type;
3463 using const_where_expression<_M, _Tp>::_M_k;
3464 using const_where_expression<_M, _Tp>::_M_value;
3467 where_expression(
const where_expression&) =
delete;
3468 where_expression& operator=(
const where_expression&) =
delete;
3470 _GLIBCXX_SIMD_INTRINSIC where_expression(
const _M& __kk, _Tp& dd)
3471 : const_where_expression<_M, _Tp>(__kk, dd) {}
3473 #define _GLIBCXX_SIMD_OP_(__op) \
3474 template <typename _Up> \
3475 _GLIBCXX_SIMD_INTRINSIC void operator __op(_Up&& __x)&& \
3476 { if (_M_k) _M_value __op static_cast<_Up&&>(__x); }
3478 _GLIBCXX_SIMD_OP_(=)
3479 _GLIBCXX_SIMD_OP_(+=)
3480 _GLIBCXX_SIMD_OP_(-=)
3481 _GLIBCXX_SIMD_OP_(*=)
3482 _GLIBCXX_SIMD_OP_(/=)
3483 _GLIBCXX_SIMD_OP_(%=)
3484 _GLIBCXX_SIMD_OP_(&=)
3485 _GLIBCXX_SIMD_OP_(|=)
3486 _GLIBCXX_SIMD_OP_(^=)
3487 _GLIBCXX_SIMD_OP_(<<=)
3488 _GLIBCXX_SIMD_OP_(>>=)
3489 #undef _GLIBCXX_SIMD_OP_
3491 _GLIBCXX_SIMD_INTRINSIC
void operator++() &&
3492 {
if (_M_k) ++_M_value; }
3494 _GLIBCXX_SIMD_INTRINSIC
void operator++(
int) &&
3495 {
if (_M_k) ++_M_value; }
3497 _GLIBCXX_SIMD_INTRINSIC
void operator--() &&
3498 {
if (_M_k) --_M_value; }
3500 _GLIBCXX_SIMD_INTRINSIC
void operator--(
int) &&
3501 {
if (_M_k) --_M_value; }
3504 template <
typename _Up,
typename _Flags>
3505 _GLIBCXX_SIMD_INTRINSIC
void
3506 copy_from(
const _LoadStorePtr<_Up, value_type>* __mem, _Flags) &&
3507 {
if (_M_k) _M_value = __mem[0]; }
3511 template <
typename _Tp,
typename _Ap>
3512 _GLIBCXX_SIMD_INTRINSIC where_expression<simd_mask<_Tp, _Ap>, simd<_Tp, _Ap>>
3513 where(
const typename simd<_Tp, _Ap>::mask_type& __k, simd<_Tp, _Ap>& __value)
3514 {
return {__k, __value}; }
3516 template <
typename _Tp,
typename _Ap>
3517 _GLIBCXX_SIMD_INTRINSIC
3518 const_where_expression<simd_mask<_Tp, _Ap>, simd<_Tp, _Ap>>
3519 where(
const typename simd<_Tp, _Ap>::mask_type& __k,
3520 const simd<_Tp, _Ap>& __value)
3521 {
return {__k, __value}; }
3523 template <
typename _Tp,
typename _Ap>
3524 _GLIBCXX_SIMD_INTRINSIC
3525 where_expression<simd_mask<_Tp, _Ap>, simd_mask<_Tp, _Ap>>
3527 simd_mask<_Tp, _Ap>& __value)
3528 {
return {__k, __value}; }
3530 template <
typename _Tp,
typename _Ap>
3531 _GLIBCXX_SIMD_INTRINSIC
3532 const_where_expression<simd_mask<_Tp, _Ap>, simd_mask<_Tp, _Ap>>
3534 const simd_mask<_Tp, _Ap>& __value)
3535 {
return {__k, __value}; }
3537 template <
typename _Tp>
3538 _GLIBCXX_SIMD_INTRINSIC where_expression<bool, _Tp>
3539 where(_ExactBool __k, _Tp& __value)
3540 {
return {__k, __value}; }
3542 template <
typename _Tp>
3543 _GLIBCXX_SIMD_INTRINSIC const_where_expression<bool, _Tp>
3544 where(_ExactBool __k,
const _Tp& __value)
3545 {
return {__k, __value}; }
3547 template <
typename _Tp,
typename _Ap>
3548 void where(
bool __k, simd<_Tp, _Ap>& __value) =
delete;
3550 template <
typename _Tp,
typename _Ap>
3551 void where(
bool __k,
const simd<_Tp, _Ap>& __value) =
delete;
3554 namespace __proposed {
3555 template <
size_t _Np>
3558 const bitset<_Np> __bits;
3561 where_range(bitset<_Np> __b) : __bits(__b) {}
3568 _GLIBCXX_SIMD_INTRINSIC
void __next_bit()
3569 { __bit = __builtin_ctzl(__mask); }
3571 _GLIBCXX_SIMD_INTRINSIC
void __reset_lsb()
3574 __mask &= (__mask - 1);
3579 iterator(decltype(__mask) __m) : __mask(__m) { __next_bit(); }
3580 iterator(
const iterator&) =
default;
3581 iterator(iterator&&) =
default;
3583 _GLIBCXX_SIMD_ALWAYS_INLINE
size_t operator->()
const
3586 _GLIBCXX_SIMD_ALWAYS_INLINE
size_t operator*()
const
3589 _GLIBCXX_SIMD_ALWAYS_INLINE iterator& operator++()
3596 _GLIBCXX_SIMD_ALWAYS_INLINE iterator operator++(
int)
3598 iterator __tmp = *
this;
3604 _GLIBCXX_SIMD_ALWAYS_INLINE
bool operator==(
const iterator& __rhs)
const
3605 {
return __mask == __rhs.__mask; }
3607 _GLIBCXX_SIMD_ALWAYS_INLINE
bool operator!=(
const iterator& __rhs)
const
3608 {
return __mask != __rhs.__mask; }
3611 iterator begin()
const
3612 {
return __bits.to_ullong(); }
3614 iterator end()
const
3618 template <
typename _Tp,
typename _Ap>
3619 where_range<simd_size_v<_Tp, _Ap>>
3620 where(
const simd_mask<_Tp, _Ap>& __k)
3621 {
return __k.__to_bitset(); }
3627 template <
typename _Tp,
typename _Abi,
typename _BinaryOperation = plus<>>
3628 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3629 reduce(
const simd<_Tp, _Abi>& __v,
3630 _BinaryOperation __binary_op = _BinaryOperation())
3631 {
return _Abi::_SimdImpl::_S_reduce(__v, __binary_op); }
3633 template <
typename _M,
typename _V,
typename _BinaryOperation = plus<>>
3634 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3635 reduce(
const const_where_expression<_M, _V>& __x,
3636 typename _V::value_type __identity_element,
3637 _BinaryOperation __binary_op)
3639 if (__builtin_expect(none_of(__get_mask(__x)),
false))
3640 return __identity_element;
3642 _V __tmp = __identity_element;
3643 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3644 __data(__get_lvalue(__x)));
3645 return reduce(__tmp, __binary_op);
3648 template <
typename _M,
typename _V>
3649 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3650 reduce(
const const_where_expression<_M, _V>& __x, plus<> __binary_op = {})
3651 {
return reduce(__x, 0, __binary_op); }
3653 template <
typename _M,
typename _V>
3654 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3655 reduce(
const const_where_expression<_M, _V>& __x, multiplies<> __binary_op)
3656 {
return reduce(__x, 1, __binary_op); }
3658 template <
typename _M,
typename _V>
3659 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3660 reduce(
const const_where_expression<_M, _V>& __x, bit_and<> __binary_op)
3661 {
return reduce(__x, ~
typename _V::value_type(), __binary_op); }
3663 template <
typename _M,
typename _V>
3664 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3665 reduce(
const const_where_expression<_M, _V>& __x, bit_or<> __binary_op)
3666 {
return reduce(__x, 0, __binary_op); }
3668 template <
typename _M,
typename _V>
3669 _GLIBCXX_SIMD_INTRINSIC
typename _V::value_type
3670 reduce(
const const_where_expression<_M, _V>& __x, bit_xor<> __binary_op)
3671 {
return reduce(__x, 0, __binary_op); }
3673 template <
typename _Tp,
typename _Abi>
3674 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3675 hmin(
const simd<_Tp, _Abi>& __v) noexcept
3677 return _Abi::_SimdImpl::_S_reduce(__v, __detail::_Minimum());
3680 template <
typename _Tp,
typename _Abi>
3681 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR _Tp
3682 hmax(
const simd<_Tp, _Abi>& __v) noexcept
3684 return _Abi::_SimdImpl::_S_reduce(__v, __detail::_Maximum());
3687 template <
typename _M,
typename _V>
3688 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3689 typename _V::value_type
3690 hmin(
const const_where_expression<_M, _V>& __x) noexcept
3692 using _Tp =
typename _V::value_type;
3693 constexpr _Tp __id_elem =
3694 #ifdef __FINITE_MATH_ONLY__
3695 __finite_max_v<_Tp>;
3697 __value_or<__infinity, _Tp>(__finite_max_v<_Tp>);
3699 _V __tmp = __id_elem;
3700 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3701 __data(__get_lvalue(__x)));
3702 return _V::abi_type::_SimdImpl::_S_reduce(__tmp, __detail::_Minimum());
3705 template <
typename _M,
typename _V>
3706 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3707 typename _V::value_type
3708 hmax(
const const_where_expression<_M, _V>& __x) noexcept
3710 using _Tp =
typename _V::value_type;
3711 constexpr _Tp __id_elem =
3712 #ifdef __FINITE_MATH_ONLY__
3713 __finite_min_v<_Tp>;
3716 if constexpr (__value_exists_v<__infinity, _Tp>)
3717 return -__infinity_v<_Tp>;
3719 return __finite_min_v<_Tp>;
3722 _V __tmp = __id_elem;
3723 _V::_Impl::_S_masked_assign(__data(__get_mask(__x)), __data(__tmp),
3724 __data(__get_lvalue(__x)));
3725 return _V::abi_type::_SimdImpl::_S_reduce(__tmp, __detail::_Maximum());
3730 template <
typename _Tp,
typename _Ap>
3731 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3732 min(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3733 {
return {__private_init, _Ap::_SimdImpl::_S_min(__data(__a), __data(__b))}; }
3735 template <
typename _Tp,
typename _Ap>
3736 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3737 max(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3738 {
return {__private_init, _Ap::_SimdImpl::_S_max(__data(__a), __data(__b))}; }
3740 template <
typename _Tp,
typename _Ap>
3741 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
3742 pair<simd<_Tp, _Ap>, simd<_Tp, _Ap>>
3743 minmax(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
3745 const auto pair_of_members
3746 = _Ap::_SimdImpl::_S_minmax(__data(__a), __data(__b));
3747 return {simd<_Tp, _Ap>(__private_init, pair_of_members.first),
3748 simd<_Tp, _Ap>(__private_init, pair_of_members.second)};
3751 template <
typename _Tp,
typename _Ap>
3752 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
3753 clamp(
const simd<_Tp, _Ap>& __v,
const simd<_Tp, _Ap>& __lo,
3754 const simd<_Tp, _Ap>& __hi)
3756 using _Impl =
typename _Ap::_SimdImpl;
3757 return {__private_init,
3758 _Impl::_S_min(__data(__hi),
3759 _Impl::_S_max(__data(__lo), __data(__v)))};
3764 template <
size_t... _Sizes,
typename _Tp,
typename _Ap,
3765 typename =
enable_if_t<((_Sizes + ...) == simd<_Tp, _Ap>::size())>>
3766 inline tuple<simd<_Tp, simd_abi::deduce_t<_Tp, _Sizes>>...>
3767 split(
const simd<_Tp, _Ap>&);
3770 template <
int _Index,
int _Total,
int _Combine = 1,
typename _Tp,
size_t _Np>
3771 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_CONST
3772 _SimdWrapper<_Tp, _Np / _Total * _Combine>
3773 __extract_part(
const _SimdWrapper<_Tp, _Np> __x);
3775 template <
int Index,
int Parts,
int _Combine = 1,
typename _Tp,
typename _A0,
3777 _GLIBCXX_SIMD_INTRINSIC
auto
3778 __extract_part(
const _SimdTuple<_Tp, _A0, _As...>& __x);
3782 template <
size_t _V0,
size_t... _Values>
3785 template <
size_t _I>
3786 static constexpr
size_t _S_at(_SizeConstant<_I> = {})
3788 if constexpr (_I == 0)
3791 return _SizeList<_Values...>::template _S_at<_I - 1>();
3794 template <
size_t _I>
3795 static constexpr auto _S_before(_SizeConstant<_I> = {})
3797 if constexpr (_I == 0)
3798 return _SizeConstant<0>();
3800 return _SizeConstant<
3801 _V0 + _SizeList<_Values...>::template _S_before<_I - 1>()>();
3804 template <
size_t _Np>
3805 static constexpr auto _S_pop_front(_SizeConstant<_Np> = {})
3807 if constexpr (_Np == 0)
3810 return _SizeList<_Values...>::template _S_pop_front<_Np - 1>();
3816 template <typename _Tp,
size_t _Np>
3817 _GLIBCXX_SIMD_INTRINSIC _SimdWrapper<_Tp, _Np / 2>
3818 __extract_center(_SimdWrapper<_Tp, _Np> __x)
3820 static_assert(_Np >= 4);
3821 static_assert(_Np % 4 == 0);
3822 #if _GLIBCXX_SIMD_X86INTRIN
3823 if constexpr (__have_avx512f &&
sizeof(_Tp) * _Np == 64)
3825 const auto __intrin = __to_intrin(__x);
3826 if constexpr (is_integral_v<_Tp>)
3827 return __vector_bitcast<_Tp>(_mm512_castsi512_si256(
3828 _mm512_shuffle_i32x4(__intrin, __intrin,
3829 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
3830 else if constexpr (
sizeof(_Tp) == 4)
3831 return __vector_bitcast<_Tp>(_mm512_castps512_ps256(
3832 _mm512_shuffle_f32x4(__intrin, __intrin,
3833 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
3834 else if constexpr (sizeof(_Tp) == 8)
3835 return __vector_bitcast<_Tp>(_mm512_castpd512_pd256(
3836 _mm512_shuffle_f64x2(__intrin, __intrin,
3837 1 + 2 * 0x4 + 2 * 0x10 + 3 * 0x40)));
3839 __assert_unreachable<_Tp>();
3841 else if constexpr (sizeof(_Tp) * _Np == 32 && is_floating_point_v<_Tp>)
3842 return __vector_bitcast<_Tp>(
3843 _mm_shuffle_pd(__lo128(__vector_bitcast<
double>(__x)),
3844 __hi128(__vector_bitcast<
double>(__x)), 1));
3845 else if constexpr (sizeof(__x) == 32 && sizeof(_Tp) * _Np <= 32)
3846 return __vector_bitcast<_Tp>(
3847 _mm_alignr_epi8(__hi128(__vector_bitcast<_LLong>(__x)),
3848 __lo128(__vector_bitcast<_LLong>(__x)),
3849 sizeof(_Tp) * _Np / 4));
3853 __vector_type_t<_Tp, _Np / 2> __r;
3854 __builtin_memcpy(&__r,
3855 reinterpret_cast<const char*
>(&__x)
3856 +
sizeof(_Tp) * _Np / 4,
3857 sizeof(_Tp) * _Np / 2);
3862 template <
typename _Tp,
typename _A0,
typename... _As>
3863 _GLIBCXX_SIMD_INTRINSIC
3864 _SimdWrapper<_Tp, _SimdTuple<_Tp, _A0, _As...>::_S_size() / 2>
3865 __extract_center(
const _SimdTuple<_Tp, _A0, _As...>& __x)
3867 if constexpr (
sizeof...(_As) == 0)
3868 return __extract_center(__x.first);
3870 return __extract_part<1, 4, 2>(__x);
3875 template <
size_t... _Sizes, typename _Tp, typename... _As>
3877 __split_wrapper(_SizeList<_Sizes...>, const _SimdTuple<_Tp, _As...>& __x)
3879 return split<_Sizes...>(
3880 fixed_size_simd<_Tp, _SimdTuple<_Tp, _As...>::_S_size()>(__private_init,
3887 template <
typename _V,
typename _Ap,
3888 size_t Parts = simd_size_v<typename _V::value_type, _Ap> / _V::size()>
3889 enable_if_t<simd_size_v<typename _V::value_type, _Ap> == Parts * _V::size()
3890 && is_simd_v<_V>, array<_V, Parts>>
3891 split(
const simd<typename _V::value_type, _Ap>& __x)
3893 using _Tp =
typename _V::value_type;
3894 if constexpr (Parts == 1)
3896 return {simd_cast<_V>(__x)};
3898 else if (__x._M_is_constprop())
3900 return __generate_from_n_evaluations<Parts, array<_V, Parts>>([&](
3901 auto __i) constexpr {
3902 return _V([&](
auto __j) constexpr {
3903 return __x[__i * _V::size() + __j];
3908 __is_fixed_size_abi_v<_Ap>
3909 && (is_same_v<typename _V::abi_type, simd_abi::scalar>
3910 || (__is_fixed_size_abi_v<typename _V::abi_type>
3911 &&
sizeof(_V) ==
sizeof(_Tp) * _V::size()
3915 #ifdef _GLIBCXX_SIMD_USE_ALIASING_LOADS
3916 const __may_alias<_Tp>*
const __element_ptr
3917 =
reinterpret_cast<const __may_alias<_Tp>*
>(&__data(__x));
3918 return __generate_from_n_evaluations<Parts, array<_V, Parts>>([&](
3919 auto __i) constexpr {
3920 return _V(__element_ptr + __i * _V::size(), vector_aligned);
3923 const auto& __xx = __data(__x);
3924 return __generate_from_n_evaluations<Parts, array<_V, Parts>>([&](
3925 auto __i) constexpr {
3926 [[maybe_unused]] constexpr
size_t __offset
3927 = decltype(__i)::value * _V::size();
3928 return _V([&](
auto __j) constexpr {
3929 constexpr _SizeConstant<__j + __offset> __k;
3935 else if constexpr (is_same_v<typename _V::abi_type, simd_abi::scalar>)
3938 return __generate_from_n_evaluations<Parts, array<_V, Parts>>([&](
3939 auto __i) constexpr {
return __x[__i]; });
3943 return __generate_from_n_evaluations<Parts, array<_V, Parts>>([&](
3944 auto __i) constexpr {
3945 if constexpr (__is_fixed_size_abi_v<typename _V::abi_type>)
3946 return _V([&](
auto __j) constexpr {
3947 return __x[__i * _V::size() + __j];
3950 return _V(__private_init,
3951 __extract_part<decltype(__i)::value, Parts>(__data(__x)));
3958 template <
typename _V,
typename _Ap,
3960 = simd_size_v<typename _V::simd_type::value_type, _Ap> / _V::size()>
3961 enable_if_t<is_simd_mask_v<_V> && simd_size_v<
typename
3962 _V::simd_type::value_type, _Ap> == _Parts * _V::size(), array<_V, _Parts>>
3963 split(
const simd_mask<typename _V::simd_type::value_type, _Ap>& __x)
3965 if constexpr (is_same_v<_Ap, typename _V::abi_type>)
3967 else if constexpr (_Parts == 1)
3968 return {__proposed::static_simd_cast<_V>(__x)};
3969 else if constexpr (_Parts == 2 && __is_sse_abi<typename _V::abi_type>()
3970 && __is_avx_abi<_Ap>())
3971 return {_V(__private_init, __lo128(__data(__x))),
3972 _V(__private_init, __hi128(__data(__x)))};
3973 else if constexpr (_V::size() <= __CHAR_BIT__ *
sizeof(_ULLong))
3975 const bitset __bits = __x.__to_bitset();
3976 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>([&](
3977 auto __i) constexpr {
3978 constexpr
size_t __offset = __i * _V::size();
3979 return _V(__bitset_init, (__bits >> __offset).to_ullong());
3984 return __generate_from_n_evaluations<_Parts, array<_V, _Parts>>([&](
3985 auto __i) constexpr {
3986 constexpr
size_t __offset = __i * _V::size();
3988 __private_init, [&](
auto __j) constexpr {
3989 return __x[__j + __offset];
3997 template <
size_t... _Sizes,
typename _Tp,
typename _Ap,
typename>
3998 _GLIBCXX_SIMD_ALWAYS_INLINE
3999 tuple<simd<_Tp, simd_abi::deduce_t<_Tp, _Sizes>>...>
4000 split(
const simd<_Tp, _Ap>& __x)
4002 using _SL = _SizeList<_Sizes...>;
4003 using _Tuple = tuple<__deduced_simd<_Tp, _Sizes>...>;
4004 constexpr
size_t _Np = simd_size_v<_Tp, _Ap>;
4005 constexpr
size_t _N0 = _SL::template _S_at<0>();
4006 using _V = __deduced_simd<_Tp, _N0>;
4008 if (__x._M_is_constprop())
4009 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>([&](
4010 auto __i) constexpr {
4011 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4012 constexpr
size_t __offset = _SL::_S_before(__i);
4013 return _Vi([&](
auto __j) constexpr {
return __x[__offset + __j]; });
4015 else if constexpr (_Np == _N0)
4017 static_assert(
sizeof...(_Sizes) == 1);
4018 return {simd_cast<_V>(__x)};
4021 (__is_fixed_size_abi_v<
4022 _Ap> && __fixed_size_storage_t<_Tp, _Np>::_S_first_size == _N0)
4025 !__is_fixed_size_abi_v<typename _V::abi_type>,
4026 "How can <_Tp, _Np> be __a single _SimdTuple entry but __a "
4031 return tuple_cat(make_tuple(_V(__private_init, __data(__x).first)),
4032 __split_wrapper(_SL::template _S_pop_front<1>(),
4033 __data(__x).second));
4035 else if constexpr ((!is_same_v<simd_abi::scalar,
4036 simd_abi::deduce_t<_Tp, _Sizes>> && ...)
4037 && (!__is_fixed_size_abi_v<
4038 simd_abi::deduce_t<_Tp, _Sizes>> && ...))
4040 if constexpr (((_Sizes * 2 == _Np) && ...))
4041 return {{__private_init, __extract_part<0, 2>(__data(__x))},
4042 {__private_init, __extract_part<1, 2>(__data(__x))}};
4043 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4044 _SizeList<_Np / 3, _Np / 3, _Np / 3>>)
4045 return {{__private_init, __extract_part<0, 3>(__data(__x))},
4046 {__private_init, __extract_part<1, 3>(__data(__x))},
4047 {__private_init, __extract_part<2, 3>(__data(__x))}};
4048 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4049 _SizeList<2 * _Np / 3, _Np / 3>>)
4050 return {{__private_init, __extract_part<0, 3, 2>(__data(__x))},
4051 {__private_init, __extract_part<2, 3>(__data(__x))}};
4052 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4053 _SizeList<_Np / 3, 2 * _Np / 3>>)
4054 return {{__private_init, __extract_part<0, 3>(__data(__x))},
4055 {__private_init, __extract_part<1, 3, 2>(__data(__x))}};
4056 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4057 _SizeList<_Np / 2, _Np / 4, _Np / 4>>)
4058 return {{__private_init, __extract_part<0, 2>(__data(__x))},
4059 {__private_init, __extract_part<2, 4>(__data(__x))},
4060 {__private_init, __extract_part<3, 4>(__data(__x))}};
4061 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4062 _SizeList<_Np / 4, _Np / 4, _Np / 2>>)
4063 return {{__private_init, __extract_part<0, 4>(__data(__x))},
4064 {__private_init, __extract_part<1, 4>(__data(__x))},
4065 {__private_init, __extract_part<1, 2>(__data(__x))}};
4066 else if constexpr (is_same_v<_SizeList<_Sizes...>,
4067 _SizeList<_Np / 4, _Np / 2, _Np / 4>>)
4068 return {{__private_init, __extract_part<0, 4>(__data(__x))},
4069 {__private_init, __extract_center(__data(__x))},
4070 {__private_init, __extract_part<3, 4>(__data(__x))}};
4071 else if constexpr (((_Sizes * 4 == _Np) && ...))
4072 return {{__private_init, __extract_part<0, 4>(__data(__x))},
4073 {__private_init, __extract_part<1, 4>(__data(__x))},
4074 {__private_init, __extract_part<2, 4>(__data(__x))},
4075 {__private_init, __extract_part<3, 4>(__data(__x))}};
4078 #ifdef _GLIBCXX_SIMD_USE_ALIASING_LOADS
4079 const __may_alias<_Tp>*
const __element_ptr
4080 =
reinterpret_cast<const __may_alias<_Tp>*
>(&__x);
4081 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>([&](
4082 auto __i) constexpr {
4083 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4084 constexpr
size_t __offset = _SL::_S_before(__i);
4085 constexpr
size_t __base_align =
alignof(simd<_Tp, _Ap>);
4086 constexpr
size_t __a
4087 = __base_align - ((__offset *
sizeof(_Tp)) % __base_align);
4088 constexpr
size_t __b = ((__a - 1) & __a) ^ __a;
4089 constexpr
size_t __alignment = __b == 0 ? __a : __b;
4090 return _Vi(__element_ptr + __offset, overaligned<__alignment>);
4093 return __generate_from_n_evaluations<
sizeof...(_Sizes), _Tuple>([&](
4094 auto __i) constexpr {
4095 using _Vi = __deduced_simd<_Tp, _SL::_S_at(__i)>;
4096 const auto& __xx = __data(__x);
4097 using _Offset = decltype(_SL::_S_before(__i));
4098 return _Vi([&](
auto __j) constexpr {
4099 constexpr _SizeConstant<_Offset::value + __j> __k;
4109 template <
size_t _I,
typename _Tp,
typename _Ap,
typename... _As>
4110 _GLIBCXX_SIMD_INTRINSIC constexpr _Tp
4111 __subscript_in_pack(
const simd<_Tp, _Ap>& __x,
const simd<_Tp, _As>&... __xs)
4113 if constexpr (_I < simd_size_v<_Tp, _Ap>)
4116 return __subscript_in_pack<_I - simd_size_v<_Tp, _Ap>>(__xs...);
4121 template <
typename _Tp,
typename _A0,
typename... _As>
4122 _GLIBCXX_SIMD_INTRINSIC
void
4123 __store_pack_of_simd(
char* __mem,
const simd<_Tp, _A0>& __x0,
4124 const simd<_Tp, _As>&... __xs)
4126 constexpr
size_t __n_bytes =
sizeof(_Tp) * simd_size_v<_Tp, _A0>;
4127 __builtin_memcpy(__mem, &__data(__x0), __n_bytes);
4128 if constexpr (
sizeof...(__xs) > 0)
4129 __store_pack_of_simd(__mem + __n_bytes, __xs...);
4134 template <typename _Tp, typename... _As, typename = __detail::__odr_helper>
4135 inline _GLIBCXX_SIMD_CONSTEXPR
4136 simd<_Tp, simd_abi::deduce_t<_Tp, (simd_size_v<_Tp, _As> + ...)>>
4137 concat(const simd<_Tp, _As>&... __xs)
4139 using _Rp = __deduced_simd<_Tp, (simd_size_v<_Tp, _As> + ...)>;
4140 if constexpr (
sizeof...(__xs) == 1)
4141 return simd_cast<_Rp>(__xs...);
4142 else if ((... && __xs._M_is_constprop()))
4144 simd_abi::deduce_t<_Tp, (simd_size_v<_Tp, _As> + ...)>>([&](
4145 auto __i) constexpr {
return __subscript_in_pack<__i>(__xs...); });
4149 __store_pack_of_simd(
reinterpret_cast<char*
>(&__data(__r)), __xs...);
4156 template <
typename _Tp,
typename _Abi,
size_t _Np>
4157 _GLIBCXX_SIMD_ALWAYS_INLINE
4158 _GLIBCXX_SIMD_CONSTEXPR __deduced_simd<_Tp, simd_size_v<_Tp, _Abi> * _Np>
4159 concat(
const array<simd<_Tp, _Abi>, _Np>& __x)
4161 return __call_with_subscripts<_Np>(__x, [](
const auto&... __xs) {
4162 return concat(__xs...);
4170 template <
typename _Up,
typename _Accessor = _Up,
4171 typename _ValueType =
typename _Up::value_type>
4172 class _SmartReference
4178 _GLIBCXX_SIMD_INTRINSIC constexpr _ValueType _M_read() const noexcept
4180 if constexpr (is_arithmetic_v<_Up>)
4183 return _M_obj[_M_index];
4186 template <
typename _Tp>
4187 _GLIBCXX_SIMD_INTRINSIC constexpr
void _M_write(_Tp&& __x)
const
4188 { _Accessor::_S_set(_M_obj, _M_index,
static_cast<_Tp&&
>(__x)); }
4191 _GLIBCXX_SIMD_INTRINSIC constexpr
4192 _SmartReference(_Up& __o,
int __i) noexcept
4193 : _M_index(__i), _M_obj(__o) {}
4195 using value_type = _ValueType;
4197 _GLIBCXX_SIMD_INTRINSIC _SmartReference(
const _SmartReference&) =
delete;
4199 _GLIBCXX_SIMD_INTRINSIC constexpr
operator value_type() const noexcept
4200 {
return _M_read(); }
4202 template <
typename _Tp,
4204 = _ValuePreservingOrInt<__remove_cvref_t<_Tp>, value_type>>
4205 _GLIBCXX_SIMD_INTRINSIC constexpr _SmartReference operator=(_Tp&& __x) &&
4207 _M_write(
static_cast<_Tp&&
>(__x));
4208 return {_M_obj, _M_index};
4211 #define _GLIBCXX_SIMD_OP_(__op) \
4212 template <typename _Tp, \
4214 = decltype(declval<value_type>() __op declval<_Tp>()), \
4215 typename = _ValuePreservingOrInt<__remove_cvref_t<_Tp>, _TT>, \
4216 typename = _ValuePreservingOrInt<_TT, value_type>> \
4217 _GLIBCXX_SIMD_INTRINSIC constexpr _SmartReference \
4218 operator __op##=(_Tp&& __x) && \
4220 const value_type& __lhs = _M_read(); \
4221 _M_write(__lhs __op __x); \
4222 return {_M_obj, _M_index}; \
4224 _GLIBCXX_SIMD_ALL_ARITHMETICS(_GLIBCXX_SIMD_OP_);
4225 _GLIBCXX_SIMD_ALL_SHIFTS(_GLIBCXX_SIMD_OP_);
4226 _GLIBCXX_SIMD_ALL_BINARY(_GLIBCXX_SIMD_OP_);
4227 #undef _GLIBCXX_SIMD_OP_
4229 template <
typename _Tp = void,
4231 = decltype(++
declval<conditional_t<true, value_type, _Tp>&>())>
4232 _GLIBCXX_SIMD_INTRINSIC constexpr _SmartReference operator++() &&
4234 value_type __x = _M_read();
4236 return {_M_obj, _M_index};
4239 template <
typename _Tp = void,
4241 = decltype(
declval<conditional_t<true, value_type, _Tp>&>()++)>
4242 _GLIBCXX_SIMD_INTRINSIC constexpr value_type operator++(
int) &&
4244 const value_type __r = _M_read();
4245 value_type __x = __r;
4250 template <
typename _Tp = void,
4252 = decltype(--
declval<conditional_t<true, value_type, _Tp>&>())>
4253 _GLIBCXX_SIMD_INTRINSIC constexpr _SmartReference operator--() &&
4255 value_type __x = _M_read();
4257 return {_M_obj, _M_index};
4260 template <
typename _Tp = void,
4262 = decltype(
declval<conditional_t<true, value_type, _Tp>&>()--)>
4263 _GLIBCXX_SIMD_INTRINSIC constexpr value_type operator--(
int) &&
4265 const value_type __r = _M_read();
4266 value_type __x = __r;
4271 _GLIBCXX_SIMD_INTRINSIC
friend void
4272 swap(_SmartReference&& __a, _SmartReference&& __b) noexcept(
4274 is_nothrow_constructible<value_type, _SmartReference&&>,
4275 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4277 value_type __tmp =
static_cast<_SmartReference&&
>(__a);
4278 static_cast<_SmartReference&&
>(__a) =
static_cast<value_type
>(__b);
4279 static_cast<_SmartReference&&
>(__b) =
std::move(__tmp);
4282 _GLIBCXX_SIMD_INTRINSIC
friend void
4283 swap(value_type& __a, _SmartReference&& __b) noexcept(
4285 is_nothrow_constructible<value_type, value_type&&>,
4286 is_nothrow_assignable<value_type&, value_type&&>,
4287 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4290 __a =
static_cast<value_type
>(__b);
4291 static_cast<_SmartReference&&
>(__b) =
std::move(__tmp);
4294 _GLIBCXX_SIMD_INTRINSIC
friend void
4295 swap(_SmartReference&& __a, value_type& __b) noexcept(
4297 is_nothrow_constructible<value_type, _SmartReference&&>,
4298 is_nothrow_assignable<value_type&, value_type&&>,
4299 is_nothrow_assignable<_SmartReference&&, value_type&&>>::value)
4301 value_type __tmp(__a);
4302 static_cast<_SmartReference&&
>(__a) =
std::move(__b);
4309 template <
int _Bytes>
4310 struct __scalar_abi_wrapper
4312 template <
typename _Tp>
static constexpr
size_t _S_full_size = 1;
4313 template <
typename _Tp>
static constexpr
size_t _S_size = 1;
4314 template <
typename _Tp>
static constexpr
size_t _S_is_partial =
false;
4316 template <
typename _Tp,
typename _Abi = simd_abi::scalar>
4317 static constexpr
bool _S_is_valid_v
4318 = _Abi::template _IsValid<_Tp>::value &&
sizeof(_Tp) == _Bytes;
4323 template <
typename _Tp>
4324 struct __decay_abi {
using type = _Tp; };
4326 template <
int _Bytes>
4327 struct __decay_abi<__scalar_abi_wrapper<_Bytes>>
4328 {
using type = simd_abi::scalar; };
4336 template <
template <
int>
class _Abi,
int _Bytes,
typename _Tp>
4337 struct __find_next_valid_abi
4339 static constexpr
auto _S_choose()
4341 constexpr
int _NextBytes = std::__bit_ceil(_Bytes) / 2;
4342 using _NextAbi = _Abi<_NextBytes>;
4343 if constexpr (_NextBytes <
sizeof(_Tp) * 2)
4344 return _Abi<_Bytes>();
4345 else if constexpr (_NextAbi::template _S_is_partial<_Tp> ==
false
4346 && _NextAbi::template _S_is_valid_v<_Tp>)
4349 return __find_next_valid_abi<_Abi, _NextBytes, _Tp>::_S_choose();
4352 using type = decltype(_S_choose());
4355 template <
int _Bytes,
typename _Tp>
4356 struct __find_next_valid_abi<__scalar_abi_wrapper, _Bytes, _Tp>
4357 {
using type = simd_abi::scalar; };
4360 template <
template <
int>
class...>
4363 template <
typename,
int>
static constexpr
bool _S_has_valid_abi =
false;
4364 template <
typename,
int>
using _FirstValidAbi = void;
4365 template <
typename,
int>
using _BestAbi = void;
4368 template <
template <
int>
class _A0,
template <
int>
class... _Rest>
4369 struct _AbiList<_A0, _Rest...>
4371 template <
typename _Tp,
int _Np>
4372 static constexpr
bool _S_has_valid_abi
4373 = _A0<
sizeof(_Tp) * _Np>::
template _S_is_valid_v<
4374 _Tp> || _AbiList<_Rest...>::template _S_has_valid_abi<_Tp, _Np>;
4376 template <
typename _Tp,
int _Np>
4378 _A0<
sizeof(_Tp) * _Np>::
template _S_is_valid_v<_Tp>,
4379 typename __decay_abi<_A0<
sizeof(_Tp) * _Np>>::type,
4380 typename _AbiList<_Rest...>::template _FirstValidAbi<_Tp, _Np>>;
4382 template <
typename _Tp,
int _Np>
4383 static constexpr
auto _S_determine_best_abi()
4385 static_assert(_Np >= 1);
4386 constexpr
int _Bytes =
sizeof(_Tp) * _Np;
4387 if constexpr (_Np == 1)
4388 return __make_dependent_t<_Tp, simd_abi::scalar>{};
4391 constexpr
int __fullsize = _A0<_Bytes>::template _S_full_size<_Tp>;
4396 if constexpr (_A0<_Bytes>::template _S_is_valid_v<
4397 _Tp> && __fullsize / 2 < _Np)
4398 return typename __decay_abi<_A0<_Bytes>>::type{};
4402 typename __find_next_valid_abi<_A0, _Bytes, _Tp>::type;
4403 if constexpr (_Bp::template _S_is_valid_v<
4404 _Tp> && _Bp::template _S_size<_Tp> <= _Np)
4408 typename _AbiList<_Rest...>::template _BestAbi<_Tp, _Np>{};
4413 template <
typename _Tp,
int _Np>
4414 using _BestAbi = decltype(_S_determine_best_abi<_Tp, _Np>());
4422 using _AllNativeAbis = _AbiList<simd_abi::_VecBltnBtmsk, simd_abi::_VecBuiltin,
4423 __scalar_abi_wrapper>;
4426 template <
typename _Tp,
typename _Abi>
4427 struct _SimdTraits<_Tp, _Abi,
void_t<typename _Abi::template _IsValid<_Tp>>>
4428 : _Abi::template __traits<_Tp> {};
4432 template <
typename _Tp,
size_t _Np>
4433 struct __deduce_impl<
4434 _Tp, _Np,
enable_if_t<_AllNativeAbis::template _S_has_valid_abi<_Tp, _Np>>>
4435 {
using type = _AllNativeAbis::_FirstValidAbi<_Tp, _Np>; };
4438 template <
typename _Tp,
size_t _Np,
typename =
void>
4439 struct __deduce_fixed_size_fallback {};
4441 template <
typename _Tp,
size_t _Np>
4442 struct __deduce_fixed_size_fallback<_Tp, _Np,
4443 enable_if_t<simd_abi::fixed_size<_Np>::template _S_is_valid_v<_Tp>>>
4444 {
using type = simd_abi::fixed_size<_Np>; };
4446 template <
typename _Tp,
size_t _Np,
typename>
4447 struct __deduce_impl :
public __deduce_fixed_size_fallback<_Tp, _Np> {};
4453 template <
typename _Tp,
typename _Abi>
4454 class simd_mask :
public _SimdTraits<_Tp, _Abi>::_MaskBase
4457 using _Traits = _SimdTraits<_Tp, _Abi>;
4458 using _MemberType =
typename _Traits::_MaskMember;
4464 using _Ip = __int_for_sizeof_t<_Tp>;
4465 static constexpr _Ip* _S_type_tag =
nullptr;
4467 friend typename _Traits::_MaskBase;
4468 friend class simd<_Tp, _Abi>;
4469 friend typename _Traits::_SimdImpl;
4472 using _Impl =
typename _Traits::_MaskImpl;
4477 using value_type = bool;
4478 using reference = _SmartReference<_MemberType, _Impl, value_type>;
4479 using simd_type = simd<_Tp, _Abi>;
4480 using abi_type = _Abi;
4483 static constexpr
size_t size()
4484 {
return __size_or_zero_v<_Tp, _Abi>; }
4488 simd_mask() =
default;
4489 simd_mask(
const simd_mask&) =
default;
4490 simd_mask(simd_mask&&) =
default;
4491 simd_mask& operator=(
const simd_mask&) =
default;
4492 simd_mask& operator=(simd_mask&&) =
default;
4496 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit
4497 simd_mask(
typename _Traits::_MaskCastType __init)
4498 : _M_data{__init} {}
4507 _GLIBCXX_SIMD_ALWAYS_INLINE
static simd_mask
4508 __from_bitset(bitset<size()> bs)
4509 {
return {__bitset_init, bs}; }
4511 _GLIBCXX_SIMD_ALWAYS_INLINE bitset<size()>
4513 {
return _Impl::_S_to_bits(_M_data)._M_to_bitset(); }
4517 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
4518 simd_mask(value_type __x)
4519 : _M_data(_Impl::template _S_broadcast<_Ip>(__x)) {}
4523 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4525 template <
typename _Up,
typename _A2,
4526 typename = enable_if_t<simd_size_v<_Up, _A2> == size()>>
4527 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit(
sizeof(_MemberType)
4528 !=
sizeof(
typename _SimdTraits<_Up, _A2>::_MaskMember))
4529 simd_mask(
const simd_mask<_Up, _A2>& __x)
4530 : simd_mask(__proposed::static_simd_cast<simd_mask>(__x)) {}
4533 template <
typename _Up,
typename =
enable_if_t<conjunction<
4534 is_same<abi_type, simd_abi::fixed_size<size()>>,
4535 is_same<_Up, _Up>>::value>>
4536 _GLIBCXX_SIMD_ALWAYS_INLINE
4537 simd_mask(
const simd_mask<_Up, simd_abi::fixed_size<size()>>& __x)
4538 : _M_data(_Impl::_S_from_bitmask(__data(__x), _S_type_tag)) {}
4543 template <
typename _Flags>
4544 _GLIBCXX_SIMD_ALWAYS_INLINE
4545 simd_mask(
const value_type* __mem, _Flags)
4546 : _M_data(_Impl::template _S_load<_Ip>(
4547 _Flags::template _S_apply<simd_mask>(__mem))) {}
4549 template <
typename _Flags>
4550 _GLIBCXX_SIMD_ALWAYS_INLINE
4551 simd_mask(
const value_type* __mem, simd_mask __k, _Flags)
4555 = _Impl::_S_masked_load(_M_data, __k._M_data,
4556 _Flags::template _S_apply<simd_mask>(__mem));
4561 template <
typename _Flags>
4562 _GLIBCXX_SIMD_ALWAYS_INLINE
void
4563 copy_from(
const value_type* __mem, _Flags)
4565 _M_data = _Impl::template _S_load<_Ip>(
4566 _Flags::template _S_apply<simd_mask>(__mem));
4571 template <
typename _Flags>
4572 _GLIBCXX_SIMD_ALWAYS_INLINE
void
4573 copy_to(value_type* __mem, _Flags)
const
4574 { _Impl::_S_store(_M_data, _Flags::template _S_apply<simd_mask>(__mem)); }
4578 _GLIBCXX_SIMD_ALWAYS_INLINE reference
4579 operator[](
size_t __i)
4582 __invoke_ub(
"Subscript %d is out of range [0, %d]", __i, size() - 1);
4583 return {_M_data, int(__i)};
4586 _GLIBCXX_SIMD_ALWAYS_INLINE value_type
4587 operator[](
size_t __i)
const
4590 __invoke_ub(
"Subscript %d is out of range [0, %d]", __i, size() - 1);
4591 if constexpr (__is_scalar_abi<_Abi>())
4594 return static_cast<
bool>(_M_data[__i]);
4599 _GLIBCXX_SIMD_ALWAYS_INLINE simd_mask
4601 {
return {__private_init, _Impl::_S_bit_not(_M_data)}; }
4605 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4607 template <
typename _Up,
typename _A2,
4609 = enable_if_t<is_convertible_v<simd_mask<_Up, _A2>, simd_mask>>>
4610 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4611 operator&&(
const simd_mask& __x,
const simd_mask<_Up, _A2>& __y)
4613 return {__private_init,
4614 _Impl::_S_logical_and(__x._M_data, simd_mask(__y)._M_data)};
4617 template <
typename _Up,
typename _A2,
4619 = enable_if_t<is_convertible_v<simd_mask<_Up, _A2>, simd_mask>>>
4620 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4621 operator||(
const simd_mask& __x,
const simd_mask<_Up, _A2>& __y)
4623 return {__private_init,
4624 _Impl::_S_logical_or(__x._M_data, simd_mask(__y)._M_data)};
4628 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4629 operator&&(
const simd_mask& __x,
const simd_mask& __y)
4631 return {__private_init, _Impl::_S_logical_and(__x._M_data, __y._M_data)};
4634 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4635 operator||(
const simd_mask& __x,
const simd_mask& __y)
4637 return {__private_init, _Impl::_S_logical_or(__x._M_data, __y._M_data)};
4640 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4641 operator&(
const simd_mask& __x,
const simd_mask& __y)
4642 {
return {__private_init, _Impl::_S_bit_and(__x._M_data, __y._M_data)}; }
4644 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4645 operator|(
const simd_mask& __x,
const simd_mask& __y)
4646 {
return {__private_init, _Impl::_S_bit_or(__x._M_data, __y._M_data)}; }
4648 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask
4649 operator^(
const simd_mask& __x,
const simd_mask& __y)
4650 {
return {__private_init, _Impl::_S_bit_xor(__x._M_data, __y._M_data)}; }
4652 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask&
4653 operator&=(simd_mask& __x,
const simd_mask& __y)
4655 __x._M_data = _Impl::_S_bit_and(__x._M_data, __y._M_data);
4659 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask&
4660 operator|=(simd_mask& __x,
const simd_mask& __y)
4662 __x._M_data = _Impl::_S_bit_or(__x._M_data, __y._M_data);
4666 _GLIBCXX_SIMD_ALWAYS_INLINE
friend simd_mask&
4667 operator^=(simd_mask& __x,
const simd_mask& __y)
4669 __x._M_data = _Impl::_S_bit_xor(__x._M_data, __y._M_data);
4675 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4676 operator==(
const simd_mask& __x,
const simd_mask& __y)
4677 {
return !operator!=(__x, __y); }
4679 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4680 operator!=(
const simd_mask& __x,
const simd_mask& __y)
4681 {
return {__private_init, _Impl::_S_bit_xor(__x._M_data, __y._M_data)}; }
4685 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
4686 simd_mask(_PrivateInit,
typename _Traits::_MaskMember __init)
4687 : _M_data(__init) {}
4691 template <typename _Fp, typename = decltype(bool(declval<_Fp>()(size_t())))>
4692 _GLIBCXX_SIMD_INTRINSIC constexpr
4693 simd_mask(_PrivateInit, _Fp&& __gen)
4696 __execute_n_times<size()>([&](
auto __i) constexpr {
4697 _Impl::_S_set(_M_data, __i, __gen(__i));
4703 _GLIBCXX_SIMD_INTRINSIC simd_mask(_BitsetInit, bitset<size()> __init)
4705 _Impl::_S_from_bitmask(_SanitizedBitMask<size()>(__init), _S_type_tag))
4716 template <
typename _Up,
typename _A2,
4718 = enable_if_t<simd_size_v<_Up, _A2> == simd_size_v<_Tp, _Abi>>>
4719 _GLIBCXX_SIMD_ALWAYS_INLINE
4720 operator simd_mask<_Up, _A2>() &&
4722 using namespace std::experimental::__proposed;
4723 return static_simd_cast<simd_mask<_Up, _A2>>(_M_data);
4726 const simd_mask<_Tp, _Abi>& _M_data;
4729 _GLIBCXX_SIMD_INTRINSIC _CvtProxy
4735 #ifdef __GXX_CONDITIONAL_IS_OVERLOADABLE__
4736 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4737 operator?:(
const simd_mask& __k,
const simd_mask& __where_true,
4738 const simd_mask& __where_false)
4740 auto __ret = __where_false;
4741 _Impl::_S_masked_assign(__k._M_data, __ret._M_data, __where_true._M_data);
4745 template <
typename _U1,
typename _U2,
4746 typename _Rp = simd<common_type_t<_U1, _U2>, _Abi>,
4748 is_convertible<_U1, _Rp>, is_convertible<_U2, _Rp>,
4749 is_convertible<simd_mask, typename _Rp::mask_type>>>>
4750 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend _Rp
4751 operator?:(
const simd_mask& __k,
const _U1& __where_true,
4752 const _U2& __where_false)
4754 _Rp __ret = __where_false;
4755 _Rp::_Impl::_S_masked_assign(
4756 __data(
static_cast<typename _Rp::mask_type
>(__k)), __data(__ret),
4757 __data(
static_cast<_Rp
>(__where_true)));
4761 #ifdef _GLIBCXX_SIMD_ENABLE_IMPLICIT_MASK_CAST
4762 template <
typename _Kp,
typename _Ak,
typename _Up,
typename _Au,
4764 conjunction_v<is_convertible<simd_mask<_Kp, _Ak>, simd_mask>,
4765 is_convertible<simd_mask<_Up, _Au>, simd_mask>>>>
4766 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd_mask
4767 operator?:(
const simd_mask<_Kp, _Ak>& __k,
const simd_mask& __where_true,
4768 const simd_mask<_Up, _Au>& __where_false)
4770 simd_mask __ret = __where_false;
4771 _Impl::_S_masked_assign(simd_mask(__k)._M_data, __ret._M_data,
4772 __where_true._M_data);
4780 _GLIBCXX_SIMD_INTRINSIC constexpr
bool
4781 _M_is_constprop()
const
4783 if constexpr (__is_scalar_abi<_Abi>())
4784 return __builtin_constant_p(_M_data);
4786 return _M_data._M_is_constprop();
4792 friend const auto& __data<_Tp, abi_type>(const simd_mask&);
4793 friend auto& __data<_Tp, abi_type>(simd_mask&);
4794 alignas(_Traits::_S_mask_align) _MemberType _M_data;
4801 template <typename _Tp, typename _Ap>
4802 _GLIBCXX_SIMD_INTRINSIC constexpr const auto&
4803 __data(const simd_mask<_Tp, _Ap>& __x)
4804 {
return __x._M_data; }
4806 template <
typename _Tp,
typename _Ap>
4807 _GLIBCXX_SIMD_INTRINSIC constexpr
auto&
4808 __data(simd_mask<_Tp, _Ap>& __x)
4809 {
return __x._M_data; }
4815 template <
typename _Tp,
typename _Abi>
4816 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4817 all_of(
const simd_mask<_Tp, _Abi>& __k) noexcept
4819 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4821 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
4827 return _Abi::_MaskImpl::_S_all_of(__k);
4830 template <
typename _Tp,
typename _Abi>
4831 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4832 any_of(
const simd_mask<_Tp, _Abi>& __k) noexcept
4834 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4836 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
4842 return _Abi::_MaskImpl::_S_any_of(__k);
4845 template <
typename _Tp,
typename _Abi>
4846 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4847 none_of(
const simd_mask<_Tp, _Abi>& __k) noexcept
4849 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4851 for (
size_t __i = 0; __i < simd_size_v<_Tp, _Abi>; ++__i)
4857 return _Abi::_MaskImpl::_S_none_of(__k);
4860 template <
typename _Tp,
typename _Abi>
4861 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4862 some_of(
const simd_mask<_Tp, _Abi>& __k) noexcept
4864 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4866 for (
size_t __i = 1; __i < simd_size_v<_Tp, _Abi>; ++__i)
4867 if (__k[__i] != __k[__i - 1])
4872 return _Abi::_MaskImpl::_S_some_of(__k);
4875 template <
typename _Tp,
typename _Abi>
4876 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4877 popcount(
const simd_mask<_Tp, _Abi>& __k) noexcept
4879 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4881 const int __r = __call_with_subscripts<simd_size_v<_Tp, _Abi>>(
4882 __k, [](
auto... __elements) {
return ((__elements != 0) + ...); });
4883 if (__builtin_is_constant_evaluated() || __builtin_constant_p(__r))
4886 return _Abi::_MaskImpl::_S_popcount(__k);
4889 template <
typename _Tp,
typename _Abi>
4890 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4891 find_first_set(
const simd_mask<_Tp, _Abi>& __k)
4893 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4895 constexpr
size_t _Np = simd_size_v<_Tp, _Abi>;
4896 const size_t _Idx = __call_with_n_evaluations<_Np>(
4897 [](
auto... __indexes) {
return std::min({__indexes...}); },
4898 [&](
auto __i) {
return __k[__i] ? +__i : _Np; });
4900 __invoke_ub(
"find_first_set(empty mask) is UB");
4901 if (__builtin_constant_p(_Idx))
4904 return _Abi::_MaskImpl::_S_find_first_set(__k);
4907 template <
typename _Tp,
typename _Abi>
4908 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4909 find_last_set(
const simd_mask<_Tp, _Abi>& __k)
4911 if (__builtin_is_constant_evaluated() || __k._M_is_constprop())
4913 constexpr
size_t _Np = simd_size_v<_Tp, _Abi>;
4914 const int _Idx = __call_with_n_evaluations<_Np>(
4915 [](
auto... __indexes) {
return std::max({__indexes...}); },
4916 [&](
auto __i) {
return __k[__i] ? int(__i) : -1; });
4918 __invoke_ub(
"find_first_set(empty mask) is UB");
4919 if (__builtin_constant_p(_Idx))
4922 return _Abi::_MaskImpl::_S_find_last_set(__k);
4925 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4926 all_of(_ExactBool __x) noexcept
4929 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4930 any_of(_ExactBool __x) noexcept
4933 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4934 none_of(_ExactBool __x) noexcept
4937 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
bool
4938 some_of(_ExactBool) noexcept
4941 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4945 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4946 find_first_set(_ExactBool)
4949 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
int
4950 find_last_set(_ExactBool)
4957 template <
typename _V,
typename _Tp,
typename _Abi,
bool>
4958 class _SimdIntOperators {};
4960 template <
typename _V,
typename _Tp,
typename _Abi>
4961 class _SimdIntOperators<_V, _Tp, _Abi, true>
4963 using _Impl =
typename _SimdTraits<_Tp, _Abi>::_SimdImpl;
4965 _GLIBCXX_SIMD_INTRINSIC
const _V& __derived()
const
4966 {
return *
static_cast<const _V*
>(
this); }
4968 template <
typename _Up>
4969 _GLIBCXX_SIMD_INTRINSIC
static _GLIBCXX_SIMD_CONSTEXPR _V
4970 _S_make_derived(_Up&& __d)
4971 {
return {__private_init,
static_cast<_Up&&
>(__d)}; }
4974 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
4976 operator%=(_V& __lhs,
const _V& __x)
4977 {
return __lhs = __lhs % __x; }
4979 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
4981 operator&=(_V& __lhs,
const _V& __x)
4982 {
return __lhs = __lhs & __x; }
4984 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
4986 operator|=(_V& __lhs,
const _V& __x)
4987 {
return __lhs = __lhs | __x; }
4989 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
4991 operator^=(_V& __lhs,
const _V& __x)
4992 {
return __lhs = __lhs ^ __x; }
4994 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
4996 operator<<=(_V& __lhs,
const _V& __x)
4997 {
return __lhs = __lhs << __x; }
4999 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5001 operator>>=(_V& __lhs,
const _V& __x)
5002 {
return __lhs = __lhs >> __x; }
5004 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5006 operator<<=(_V& __lhs,
int __x)
5007 {
return __lhs = __lhs << __x; }
5009 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5011 operator>>=(_V& __lhs,
int __x)
5012 {
return __lhs = __lhs >> __x; }
5014 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5016 operator%(
const _V& __x,
const _V& __y)
5018 return _SimdIntOperators::_S_make_derived(
5019 _Impl::_S_modulus(__data(__x), __data(__y)));
5022 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5026 return _SimdIntOperators::_S_make_derived(
5027 _Impl::_S_bit_and(__data(__x), __data(__y)));
5030 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5034 return _SimdIntOperators::_S_make_derived(
5035 _Impl::_S_bit_or(__data(__x), __data(__y)));
5038 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5042 return _SimdIntOperators::_S_make_derived(
5043 _Impl::_S_bit_xor(__data(__x), __data(__y)));
5046 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5050 return _SimdIntOperators::_S_make_derived(
5051 _Impl::_S_bit_shift_left(__data(__x), __data(__y)));
5054 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5058 return _SimdIntOperators::_S_make_derived(
5059 _Impl::_S_bit_shift_right(__data(__x), __data(__y)));
5062 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5067 __invoke_ub(
"The behavior is undefined if the right operand of a "
5068 "shift operation is negative. [expr.shift]\nA shift by "
5071 if (
size_t(__y) >=
sizeof(declval<_Tp>() << __y) * __CHAR_BIT__)
5073 "The behavior is undefined if the right operand of a "
5074 "shift operation is greater than or equal to the width of the "
5075 "promoted left operand. [expr.shift]\nA shift by %d was requested",
5077 return _SimdIntOperators::_S_make_derived(
5078 _Impl::_S_bit_shift_left(__data(__x), __y));
5081 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend
5087 "The behavior is undefined if the right operand of a shift "
5088 "operation is negative. [expr.shift]\nA shift by %d was requested",
5090 if (
size_t(__y) >=
sizeof(declval<_Tp>() << __y) * __CHAR_BIT__)
5092 "The behavior is undefined if the right operand of a shift "
5093 "operation is greater than or equal to the width of the promoted "
5094 "left operand. [expr.shift]\nA shift by %d was requested",
5096 return _SimdIntOperators::_S_make_derived(
5097 _Impl::_S_bit_shift_right(__data(__x), __y));
5101 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5104 {
return {__private_init, _Impl::_S_complement(__derived()._M_data)}; }
5111 template <
typename _Tp,
typename _Abi>
5112 class simd :
public _SimdIntOperators<
5113 simd<_Tp, _Abi>, _Tp, _Abi,
5114 conjunction<is_integral<_Tp>,
5115 typename _SimdTraits<_Tp, _Abi>::_IsValid>::value>,
5116 public _SimdTraits<_Tp, _Abi>::_SimdBase
5118 using _Traits = _SimdTraits<_Tp, _Abi>;
5119 using _MemberType =
typename _Traits::_SimdMember;
5120 using _CastType =
typename _Traits::_SimdCastType;
5121 static constexpr _Tp* _S_type_tag =
nullptr;
5122 friend typename _Traits::_SimdBase;
5125 using _Impl =
typename _Traits::_SimdImpl;
5127 friend _SimdIntOperators<simd, _Tp, _Abi, true>;
5129 using value_type = _Tp;
5130 using reference = _SmartReference<_MemberType, _Impl, value_type>;
5131 using mask_type = simd_mask<_Tp, _Abi>;
5132 using abi_type = _Abi;
5134 static constexpr
size_t size()
5135 {
return __size_or_zero_v<_Tp, _Abi>; }
5137 _GLIBCXX_SIMD_CONSTEXPR simd() =
default;
5138 _GLIBCXX_SIMD_CONSTEXPR simd(
const simd&) =
default;
5139 _GLIBCXX_SIMD_CONSTEXPR simd(simd&&) noexcept = default;
5140 _GLIBCXX_SIMD_CONSTEXPR simd& operator=(const simd&) = default;
5141 _GLIBCXX_SIMD_CONSTEXPR simd& operator=(simd&&) noexcept = default;
5144 template <typename _Up,
5145 typename =
enable_if_t<!is_same_v<__remove_cvref_t<_Up>,
bool>>>
5146 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5147 simd(_ValuePreservingOrInt<_Up, value_type>&& __x)
5149 _Impl::_S_broadcast(static_cast<value_type>(static_cast<_Up&&>(__x))))
5154 template <
typename _Up>
5155 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
5156 simd(
const simd<_Up, simd_abi::fixed_size<size()>>& __x,
5159 is_same<simd_abi::fixed_size<size()>, abi_type>,
5160 negation<__is_narrowing_conversion<_Up, value_type>>,
5161 __converts_to_higher_integer_rank<_Up, value_type>>::value,
5163 : simd{static_cast<array<_Up, size()>>(__x).data(), vector_aligned} {}
5166 #ifdef _GLIBCXX_SIMD_ENABLE_STATIC_CAST
5167 template <
typename _Up,
typename _A2,
5168 typename = decltype(static_simd_cast<simd>(
5169 declval<
const simd<_Up, _A2>&>()))>
5170 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5171 simd(
const simd<_Up, _A2>& __x)
5172 : simd(static_simd_cast<simd>(__x)) {}
5176 template <
typename _Fp>
5177 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5178 simd(_Fp&& __gen, _ValuePreservingOrInt<decltype(declval<_Fp>()(
5179 declval<_SizeConstant<0>&>())),
5180 value_type>* =
nullptr)
5181 : _M_data(_Impl::_S_generator(static_cast<_Fp&&>(__gen), _S_type_tag)) {}
5184 template <
typename _Up,
typename _Flags>
5185 _GLIBCXX_SIMD_ALWAYS_INLINE
5186 simd(
const _Up* __mem, _Flags)
5188 _Impl::_S_load(_Flags::template _S_apply<simd>(__mem), _S_type_tag))
5192 template <
typename _Up,
typename _Flags>
5193 _GLIBCXX_SIMD_ALWAYS_INLINE
void
5194 copy_from(
const _Vectorizable<_Up>* __mem, _Flags)
5196 _M_data =
static_cast<decltype(_M_data)
>(
5197 _Impl::_S_load(_Flags::template _S_apply<simd>(__mem), _S_type_tag));
5201 template <
typename _Up,
typename _Flags>
5202 _GLIBCXX_SIMD_ALWAYS_INLINE
void
5203 copy_to(_Vectorizable<_Up>* __mem, _Flags)
const
5205 _Impl::_S_store(_M_data, _Flags::template _S_apply<simd>(__mem),
5210 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR reference
5211 operator[](
size_t __i)
5212 {
return {_M_data, int(__i)}; }
5214 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR value_type
5215 operator[]([[maybe_unused]]
size_t __i)
const
5217 if constexpr (__is_scalar_abi<_Abi>())
5219 _GLIBCXX_DEBUG_ASSERT(__i == 0);
5223 return _M_data[__i];
5227 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd&
5230 _Impl::_S_increment(_M_data);
5234 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5238 _Impl::_S_increment(_M_data);
5242 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd&
5245 _Impl::_S_decrement(_M_data);
5249 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5253 _Impl::_S_decrement(_M_data);
5258 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR mask_type
5260 {
return {__private_init, _Impl::_S_negate(_M_data)}; }
5262 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5266 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR simd
5268 {
return {__private_init, _Impl::_S_unary_minus(_M_data)}; }
5271 _GLIBCXX_SIMD_ALWAYS_INLINE
explicit _GLIBCXX_SIMD_CONSTEXPR
5272 simd(_CastType __init) : _M_data(__init) {}
5275 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5276 operator+=(simd& __lhs,
const simd& __x)
5277 {
return __lhs = __lhs + __x; }
5279 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5280 operator-=(simd& __lhs,
const simd& __x)
5281 {
return __lhs = __lhs - __x; }
5283 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5284 operator*=(simd& __lhs,
const simd& __x)
5285 {
return __lhs = __lhs * __x; }
5287 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd&
5288 operator/=(simd& __lhs,
const simd& __x)
5289 {
return __lhs = __lhs / __x; }
5292 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5293 operator+(
const simd& __x,
const simd& __y)
5294 {
return {__private_init, _Impl::_S_plus(__x._M_data, __y._M_data)}; }
5296 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5297 operator-(
const simd& __x,
const simd& __y)
5298 {
return {__private_init, _Impl::_S_minus(__x._M_data, __y._M_data)}; }
5300 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5301 operator*(
const simd& __x,
const simd& __y)
5302 {
return {__private_init, _Impl::_S_multiplies(__x._M_data, __y._M_data)}; }
5304 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5305 operator/(
const simd& __x,
const simd& __y)
5306 {
return {__private_init, _Impl::_S_divides(__x._M_data, __y._M_data)}; }
5309 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5310 operator==(
const simd& __x,
const simd& __y)
5311 {
return simd::_S_make_mask(_Impl::_S_equal_to(__x._M_data, __y._M_data)); }
5313 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5314 operator!=(
const simd& __x,
const simd& __y)
5316 return simd::_S_make_mask(
5317 _Impl::_S_not_equal_to(__x._M_data, __y._M_data));
5320 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5321 operator<(
const simd& __x,
const simd& __y)
5322 {
return simd::_S_make_mask(_Impl::_S_less(__x._M_data, __y._M_data)); }
5324 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend mask_type
5325 operator<=(
const simd& __x,
const simd& __y)
5327 return simd::_S_make_mask(_Impl::_S_less_equal(__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_less(__y._M_data, __x._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(_Impl::_S_less_equal(__y._M_data, __x._M_data));
5341 #ifdef __GXX_CONDITIONAL_IS_OVERLOADABLE__
5342 _GLIBCXX_SIMD_ALWAYS_INLINE _GLIBCXX_SIMD_CONSTEXPR
friend simd
5343 operator?:(
const mask_type& __k,
const simd& __where_true,
5344 const simd& __where_false)
5346 auto __ret = __where_false;
5347 _Impl::_S_masked_assign(__data(__k), __data(__ret), __data(__where_true));
5355 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
5356 simd(_PrivateInit,
const _MemberType& __init)
5357 : _M_data(__init) {}
5360 _GLIBCXX_SIMD_INTRINSIC
5361 simd(_BitsetInit, bitset<size()> __init) : _M_data()
5362 { where(mask_type(__bitset_init, __init), *
this) = ~*
this; }
5364 _GLIBCXX_SIMD_INTRINSIC constexpr
bool
5365 _M_is_constprop()
const
5367 if constexpr (__is_scalar_abi<_Abi>())
5368 return __builtin_constant_p(_M_data);
5370 return _M_data._M_is_constprop();
5374 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR static mask_type
5375 _S_make_mask(typename mask_type::_MemberType __k)
5376 {
return {__private_init, __k}; }
5378 friend const auto& __data<value_type, abi_type>(
const simd&);
5379 friend auto& __data<value_type, abi_type>(simd&);
5380 alignas(_Traits::_S_simd_align) _MemberType _M_data;
5386 template <
typename _Tp,
typename _Ap>
5387 _GLIBCXX_SIMD_INTRINSIC constexpr
const auto&
5388 __data(
const simd<_Tp, _Ap>& __x)
5389 {
return __x._M_data; }
5391 template <
typename _Tp,
typename _Ap>
5392 _GLIBCXX_SIMD_INTRINSIC constexpr
auto&
5393 __data(simd<_Tp, _Ap>& __x)
5394 {
return __x._M_data; }
5397 namespace __float_bitwise_operators {
5398 template <
typename _Tp,
typename _Ap>
5399 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5400 operator^(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5402 return {__private_init,
5403 _Ap::_SimdImpl::_S_bit_xor(__data(__a), __data(__b))};
5406 template <
typename _Tp,
typename _Ap>
5407 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5408 operator|(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5410 return {__private_init,
5411 _Ap::_SimdImpl::_S_bit_or(__data(__a), __data(__b))};
5414 template <
typename _Tp,
typename _Ap>
5415 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR simd<_Tp, _Ap>
5416 operator&(
const simd<_Tp, _Ap>& __a,
const simd<_Tp, _Ap>& __b)
5418 return {__private_init,
5419 _Ap::_SimdImpl::_S_bit_and(__data(__a), __data(__b))};
5422 template <
typename _Tp,
typename _Ap>
5423 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_SIMD_CONSTEXPR
5424 enable_if_t<is_floating_point_v<_Tp>, simd<_Tp, _Ap>>
5425 operator~(
const simd<_Tp, _Ap>& __a)
5426 {
return {__private_init, _Ap::_SimdImpl::_S_complement(__data(__a))}; }
5431 _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 divided by 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.
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.
typename remove_pointer< _Tp >::type remove_pointer_t
Alias template for remove_pointer.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
typename remove_const< _Tp >::type remove_const_t
Alias template for remove_const.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr auto tuple_cat(_Tpls &&... __tpls) -> typename __tuple_cat_result< _Tpls... >::__type
tuple_cat
auto declval() noexcept -> decltype(__declval< _Tp >(0))
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
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.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.