25 #ifndef _GLIBCXX_EXPERIMENTAL_SIMD_ABIS_H_
26 #define _GLIBCXX_EXPERIMENTAL_SIMD_ABIS_H_
28 #if __cplusplus >= 201703L
34 _GLIBCXX_SIMD_BEGIN_NAMESPACE
36 template <
typename _V>
37 static inline _GLIBCXX_SIMD_USE_CONSTEXPR _V _S_allbits
38 =
reinterpret_cast<_V
>(~__vector_type_t<char,
sizeof(_V) /
sizeof(
char)>());
42 template <
typename _V,
typename = _VectorTraits<_V>>
43 static inline _GLIBCXX_SIMD_USE_CONSTEXPR _V _S_signmask
44 = __xor(_V() + 1, _V() - 1);
46 template <
typename _V,
typename = _VectorTraits<_V>>
47 static inline _GLIBCXX_SIMD_USE_CONSTEXPR _V _S_absmask
48 = __andnot(_S_signmask<_V>, _S_allbits<_V>);
53 template <
int... _Indices,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>,
54 typename = __detail::__odr_helper>
56 __vector_permute(_Tp __x)
58 static_assert(
sizeof...(_Indices) == _TVT::_S_full_size);
59 return __make_vector<typename _TVT::value_type>(
60 (_Indices == -1 ? 0 : __x[_Indices == -1 ? 0 : _Indices])...);
66 template <
int... _Indices,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>,
67 typename = __detail::__odr_helper>
69 __vector_shuffle(_Tp __x, _Tp __y)
71 return _Tp{(_Indices == -1 ? 0
72 : _Indices < _TVT::_S_full_size
74 : __y[_Indices - _TVT::_S_full_size])...};
79 template <
typename _Tp,
typename... _Args>
80 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper<_Tp,
sizeof...(_Args)>
81 __make_wrapper(
const _Args&... __args)
82 {
return __make_vector<_Tp>(__args...); }
86 template <
typename _Tp,
size_t _ToN = 0,
typename _Up,
size_t _M,
87 size_t _Np = _ToN != 0 ? _ToN :
sizeof(_Up) * _M /
sizeof(_Tp)>
88 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper<_Tp, _Np>
89 __wrapper_bitcast(_SimdWrapper<_Up, _M> __x)
91 static_assert(_Np > 1);
92 return __intrin_bitcast<__vector_type_t<_Tp, _Np>>(__x._M_data);
98 template <
unsigned __shift,
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
99 _GLIBCXX_SIMD_INTRINSIC _Tp
100 __shift_elements_right(_Tp __v)
102 [[maybe_unused]]
const auto __iv = __to_intrin(__v);
103 static_assert(__shift <=
sizeof(_Tp));
104 if constexpr (__shift == 0)
106 else if constexpr (__shift == sizeof(_Tp))
108 #if _GLIBCXX_SIMD_X86INTRIN
109 else if constexpr (__have_sse && __shift == 8
110 && _TVT::template _S_is<float, 4>)
111 return _mm_movehl_ps(__iv, __iv);
112 else if constexpr (__have_sse2 && __shift == 8
113 && _TVT::template _S_is<double, 2>)
114 return _mm_unpackhi_pd(__iv, __iv);
115 else if constexpr (__have_sse2 &&
sizeof(_Tp) == 16)
116 return reinterpret_cast<typename _TVT::type>(
117 _mm_srli_si128(reinterpret_cast<__m128i>(__iv), __shift));
118 else if constexpr (__shift == 16 && sizeof(_Tp) == 32)
128 return __zero_extend(__hi128(__v));
130 else if constexpr (__have_avx2 &&
sizeof(_Tp) == 32 && __shift < 16)
132 const auto __vll = __vector_bitcast<_LLong>(__v);
133 return reinterpret_cast<typename _TVT::type
>(
134 _mm256_alignr_epi8(_mm256_permute2x128_si256(__vll, __vll, 0x81),
137 else if constexpr (__have_avx &&
sizeof(_Tp) == 32 && __shift < 16)
139 const auto __vll = __vector_bitcast<_LLong>(__v);
140 return reinterpret_cast<typename _TVT::type
>(
141 __concat(_mm_alignr_epi8(__hi128(__vll), __lo128(__vll), __shift),
142 _mm_srli_si128(__hi128(__vll), __shift)));
144 else if constexpr (
sizeof(_Tp) == 32 && __shift > 16)
145 return __zero_extend(__shift_elements_right<__shift - 16>(__hi128(__v)));
146 else if constexpr (sizeof(_Tp) == 64 && __shift == 32)
147 return __zero_extend(__hi256(__v));
148 else if constexpr (__have_avx512f && sizeof(_Tp) == 64)
150 if constexpr (__shift >= 48)
151 return __zero_extend(
152 __shift_elements_right<__shift - 48>(__extract<3, 4>(__v)));
153 else if constexpr (__shift >= 32)
154 return __zero_extend(
155 __shift_elements_right<__shift - 32>(__hi256(__v)));
156 else if constexpr (__shift % 8 == 0)
157 return reinterpret_cast<typename _TVT::type>(
158 _mm512_alignr_epi64(__m512i(), __intrin_bitcast<__m512i>(__v),
160 else if constexpr (__shift % 4 == 0)
161 return reinterpret_cast<typename _TVT::type>(
162 _mm512_alignr_epi32(__m512i(), __intrin_bitcast<__m512i>(__v),
164 else if constexpr (__have_avx512bw && __shift < 16)
166 const auto __vll = __vector_bitcast<_LLong>(__v);
167 return reinterpret_cast<typename _TVT::type
>(
168 _mm512_alignr_epi8(_mm512_shuffle_i32x4(__vll, __vll, 0xf9),
171 else if constexpr (__have_avx512bw && __shift < 32)
173 const auto __vll = __vector_bitcast<_LLong>(__v);
174 return reinterpret_cast<typename _TVT::type
>(
175 _mm512_alignr_epi8(_mm512_shuffle_i32x4(__vll, __m512i(), 0xee),
176 _mm512_shuffle_i32x4(__vll, __vll, 0xf9),
180 __assert_unreachable<_Tp>();
189 constexpr
int __chunksize = __shift % 8 == 0 ? 8
190 : __shift % 4 == 0 ? 4
191 : __shift % 2 == 0 ? 2
193 auto __w = __vector_bitcast<__int_with_sizeof_t<__chunksize>>(__v);
194 using _Up = decltype(__w);
195 return __intrin_bitcast<_Tp>(
196 __call_with_n_evaluations<(
sizeof(_Tp) - __shift) / __chunksize>(
197 [](
auto... __chunks) {
return _Up{__chunks...}; },
198 [&](
auto __i) {
return __w[__shift / __chunksize + __i]; }));
204 template <
int _Index,
int _Total,
int _Combine,
typename _Tp,
size_t _Np>
205 _GLIBCXX_SIMD_INTRINSIC _GLIBCXX_CONST
206 _SimdWrapper<_Tp, _Np / _Total * _Combine>
207 __extract_part(
const _SimdWrapper<_Tp, _Np> __x)
209 if constexpr (_Index % 2 == 0 && _Total % 2 == 0 && _Combine % 2 == 0)
210 return __extract_part<_Index / 2, _Total / 2, _Combine / 2>(__x);
213 constexpr
size_t __values_per_part = _Np / _Total;
214 constexpr
size_t __values_to_skip = _Index * __values_per_part;
215 constexpr
size_t __return_size = __values_per_part * _Combine;
216 using _R = __vector_type_t<_Tp, __return_size>;
217 static_assert((_Index + _Combine) * __values_per_part *
sizeof(_Tp)
219 "out of bounds __extract_part");
226 if (__x._M_is_constprop())
227 return __generate_from_n_evaluations<__return_size, _R>(
228 [&](
auto __i) {
return __x[__values_to_skip + __i]; });
229 if constexpr (_Index == 0 && _Total == 1)
231 else if constexpr (_Index == 0)
232 return __intrin_bitcast<_R>(__as_vector(__x));
233 #if _GLIBCXX_SIMD_X86INTRIN
234 else if constexpr (
sizeof(__x) == 32
235 && __return_size *
sizeof(_Tp) <= 16)
237 constexpr
size_t __bytes_to_skip = __values_to_skip *
sizeof(_Tp);
238 if constexpr (__bytes_to_skip == 16)
239 return __vector_bitcast<_Tp, __return_size>(
240 __hi128(__as_vector(__x)));
242 return __vector_bitcast<_Tp, __return_size>(
243 _mm_alignr_epi8(__hi128(__vector_bitcast<_LLong>(__x)),
244 __lo128(__vector_bitcast<_LLong>(__x)),
248 else if constexpr (_Index > 0
249 && (__values_to_skip % __return_size != 0
251 && (__values_to_skip + __return_size) *
sizeof(_Tp)
253 &&
sizeof(__x) >= 16)
254 return __intrin_bitcast<_R>(
255 __shift_elements_right<__values_to_skip * sizeof(_Tp)>(
260 __builtin_memcpy(&__r,
261 reinterpret_cast<const char*
>(&__x)
262 +
sizeof(_Tp) * __values_to_skip,
263 __return_size *
sizeof(_Tp));
271 template <
int _Index,
int _Total,
int _Combine = 1,
size_t _Np>
272 _GLIBCXX_SIMD_INTRINSIC constexpr _SimdWrapper<bool, _Np / _Total * _Combine>
273 __extract_part(
const _SimdWrapper<bool, _Np> __x)
275 static_assert(_Combine == 1,
"_Combine != 1 not implemented");
276 static_assert(__have_avx512f && _Np == _Np);
277 static_assert(_Total >= 2 && _Index + _Combine <= _Total && _Index >= 0);
278 return __x._M_data >> (_Index * _Np / _Total);
285 template <
typename _To,
typename _From,
size_t... _I>
286 _GLIBCXX_SIMD_INTRINSIC constexpr _To
287 __vector_convert(_From __a, index_sequence<_I...>)
289 using _Tp =
typename _VectorTraits<_To>::value_type;
290 return _To{
static_cast<_Tp
>(__a[_I])...};
293 template <
typename _To,
typename _From,
size_t... _I>
294 _GLIBCXX_SIMD_INTRINSIC constexpr _To
295 __vector_convert(_From __a, _From __b, index_sequence<_I...>)
297 using _Tp =
typename _VectorTraits<_To>::value_type;
298 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...};
301 template <
typename _To,
typename _From,
size_t... _I>
302 _GLIBCXX_SIMD_INTRINSIC constexpr _To
303 __vector_convert(_From __a, _From __b, _From __c, index_sequence<_I...>)
305 using _Tp =
typename _VectorTraits<_To>::value_type;
306 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
307 static_cast<_Tp
>(__c[_I])...};
310 template <
typename _To,
typename _From,
size_t... _I>
311 _GLIBCXX_SIMD_INTRINSIC constexpr _To
312 __vector_convert(_From __a, _From __b, _From __c, _From __d,
313 index_sequence<_I...>)
315 using _Tp =
typename _VectorTraits<_To>::value_type;
316 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
317 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...};
320 template <
typename _To,
typename _From,
size_t... _I>
321 _GLIBCXX_SIMD_INTRINSIC constexpr _To
322 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
323 index_sequence<_I...>)
325 using _Tp =
typename _VectorTraits<_To>::value_type;
326 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
327 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
328 static_cast<_Tp
>(__e[_I])...};
331 template <
typename _To,
typename _From,
size_t... _I>
332 _GLIBCXX_SIMD_INTRINSIC constexpr _To
333 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
334 _From __f, index_sequence<_I...>)
336 using _Tp =
typename _VectorTraits<_To>::value_type;
337 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
338 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
339 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...};
342 template <
typename _To,
typename _From,
size_t... _I>
343 _GLIBCXX_SIMD_INTRINSIC constexpr _To
344 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
345 _From __f, _From __g, index_sequence<_I...>)
347 using _Tp =
typename _VectorTraits<_To>::value_type;
348 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
349 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
350 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...,
351 static_cast<_Tp
>(__g[_I])...};
354 template <
typename _To,
typename _From,
size_t... _I>
355 _GLIBCXX_SIMD_INTRINSIC constexpr _To
356 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
357 _From __f, _From __g, _From __h, index_sequence<_I...>)
359 using _Tp =
typename _VectorTraits<_To>::value_type;
360 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
361 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
362 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...,
363 static_cast<_Tp
>(__g[_I])...,
static_cast<_Tp
>(__h[_I])...};
366 template <
typename _To,
typename _From,
size_t... _I>
367 _GLIBCXX_SIMD_INTRINSIC constexpr _To
368 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
369 _From __f, _From __g, _From __h, _From __i,
370 index_sequence<_I...>)
372 using _Tp =
typename _VectorTraits<_To>::value_type;
373 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
374 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
375 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...,
376 static_cast<_Tp
>(__g[_I])...,
static_cast<_Tp
>(__h[_I])...,
377 static_cast<_Tp
>(__i[_I])...};
380 template <
typename _To,
typename _From,
size_t... _I>
381 _GLIBCXX_SIMD_INTRINSIC constexpr _To
382 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
383 _From __f, _From __g, _From __h, _From __i, _From __j,
384 index_sequence<_I...>)
386 using _Tp =
typename _VectorTraits<_To>::value_type;
387 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
388 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
389 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...,
390 static_cast<_Tp
>(__g[_I])...,
static_cast<_Tp
>(__h[_I])...,
391 static_cast<_Tp
>(__i[_I])...,
static_cast<_Tp
>(__j[_I])...};
394 template <
typename _To,
typename _From,
size_t... _I>
395 _GLIBCXX_SIMD_INTRINSIC constexpr _To
396 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
397 _From __f, _From __g, _From __h, _From __i, _From __j,
398 _From __k, index_sequence<_I...>)
400 using _Tp =
typename _VectorTraits<_To>::value_type;
401 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
402 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
403 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...,
404 static_cast<_Tp
>(__g[_I])...,
static_cast<_Tp
>(__h[_I])...,
405 static_cast<_Tp
>(__i[_I])...,
static_cast<_Tp
>(__j[_I])...,
406 static_cast<_Tp
>(__k[_I])...};
409 template <
typename _To,
typename _From,
size_t... _I>
410 _GLIBCXX_SIMD_INTRINSIC constexpr _To
411 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
412 _From __f, _From __g, _From __h, _From __i, _From __j,
413 _From __k, _From __l, index_sequence<_I...>)
415 using _Tp =
typename _VectorTraits<_To>::value_type;
416 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
417 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
418 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...,
419 static_cast<_Tp
>(__g[_I])...,
static_cast<_Tp
>(__h[_I])...,
420 static_cast<_Tp
>(__i[_I])...,
static_cast<_Tp
>(__j[_I])...,
421 static_cast<_Tp
>(__k[_I])...,
static_cast<_Tp
>(__l[_I])...};
424 template <
typename _To,
typename _From,
size_t... _I>
425 _GLIBCXX_SIMD_INTRINSIC constexpr _To
426 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
427 _From __f, _From __g, _From __h, _From __i, _From __j,
428 _From __k, _From __l, _From __m, index_sequence<_I...>)
430 using _Tp =
typename _VectorTraits<_To>::value_type;
431 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
432 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
433 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...,
434 static_cast<_Tp
>(__g[_I])...,
static_cast<_Tp
>(__h[_I])...,
435 static_cast<_Tp
>(__i[_I])...,
static_cast<_Tp
>(__j[_I])...,
436 static_cast<_Tp
>(__k[_I])...,
static_cast<_Tp
>(__l[_I])...,
437 static_cast<_Tp
>(__m[_I])...};
440 template <
typename _To,
typename _From,
size_t... _I>
441 _GLIBCXX_SIMD_INTRINSIC constexpr _To
442 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
443 _From __f, _From __g, _From __h, _From __i, _From __j,
444 _From __k, _From __l, _From __m, _From __n,
445 index_sequence<_I...>)
447 using _Tp =
typename _VectorTraits<_To>::value_type;
448 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
449 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
450 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...,
451 static_cast<_Tp
>(__g[_I])...,
static_cast<_Tp
>(__h[_I])...,
452 static_cast<_Tp
>(__i[_I])...,
static_cast<_Tp
>(__j[_I])...,
453 static_cast<_Tp
>(__k[_I])...,
static_cast<_Tp
>(__l[_I])...,
454 static_cast<_Tp
>(__m[_I])...,
static_cast<_Tp
>(__n[_I])...};
457 template <
typename _To,
typename _From,
size_t... _I>
458 _GLIBCXX_SIMD_INTRINSIC constexpr _To
459 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
460 _From __f, _From __g, _From __h, _From __i, _From __j,
461 _From __k, _From __l, _From __m, _From __n, _From __o,
462 index_sequence<_I...>)
464 using _Tp =
typename _VectorTraits<_To>::value_type;
465 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
466 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
467 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...,
468 static_cast<_Tp
>(__g[_I])...,
static_cast<_Tp
>(__h[_I])...,
469 static_cast<_Tp
>(__i[_I])...,
static_cast<_Tp
>(__j[_I])...,
470 static_cast<_Tp
>(__k[_I])...,
static_cast<_Tp
>(__l[_I])...,
471 static_cast<_Tp
>(__m[_I])...,
static_cast<_Tp
>(__n[_I])...,
472 static_cast<_Tp
>(__o[_I])...};
475 template <
typename _To,
typename _From,
size_t... _I>
476 _GLIBCXX_SIMD_INTRINSIC constexpr _To
477 __vector_convert(_From __a, _From __b, _From __c, _From __d, _From __e,
478 _From __f, _From __g, _From __h, _From __i, _From __j,
479 _From __k, _From __l, _From __m, _From __n, _From __o,
480 _From __p, index_sequence<_I...>)
482 using _Tp =
typename _VectorTraits<_To>::value_type;
483 return _To{
static_cast<_Tp
>(__a[_I])...,
static_cast<_Tp
>(__b[_I])...,
484 static_cast<_Tp
>(__c[_I])...,
static_cast<_Tp
>(__d[_I])...,
485 static_cast<_Tp
>(__e[_I])...,
static_cast<_Tp
>(__f[_I])...,
486 static_cast<_Tp
>(__g[_I])...,
static_cast<_Tp
>(__h[_I])...,
487 static_cast<_Tp
>(__i[_I])...,
static_cast<_Tp
>(__j[_I])...,
488 static_cast<_Tp
>(__k[_I])...,
static_cast<_Tp
>(__l[_I])...,
489 static_cast<_Tp
>(__m[_I])...,
static_cast<_Tp
>(__n[_I])...,
490 static_cast<_Tp
>(__o[_I])...,
static_cast<_Tp
>(__p[_I])...};
496 template <
typename _To,
typename... _From,
size_t _FromSize>
497 _GLIBCXX_SIMD_INTRINSIC constexpr _To
498 __vector_convert(_SimdWrapper<_From, _FromSize>... __xs)
500 #ifdef _GLIBCXX_SIMD_WORKAROUND_PR85048
501 using _From0 = __first_of_pack_t<_From...>;
502 using _FW = _SimdWrapper<_From0, _FromSize>;
503 if (!_FW::_S_is_partial && !(... && __xs._M_is_constprop()))
505 if constexpr ((
sizeof...(_From) & (
sizeof...(_From) - 1))
507 return __convert_x86<_To>(__as_vector(__xs)...);
509 return __vector_convert<_To>(__xs..., _FW{});
513 return __vector_convert<_To>(
514 __as_vector(__xs)...,
516 _VectorTraits<_To>::_S_full_size,
int(_FromSize))
522 template <
typename _To,
typename _From,
typename... _More>
523 _GLIBCXX_SIMD_INTRINSIC constexpr
auto
524 __convert(_From __v0, _More... __vs)
526 static_assert((
true && ... && is_same_v<_From, _More>) );
527 if constexpr (__is_vectorizable_v<_From>)
529 using _V =
typename _VectorTraits<_To>::type;
530 using _Tp =
typename _VectorTraits<_To>::value_type;
531 return _V{
static_cast<_Tp
>(__v0),
static_cast<_Tp
>(__vs)...};
533 else if constexpr (__is_vector_type_v<_From>)
534 return __convert<_To>(__as_wrapper(__v0), __as_wrapper(__vs)...);
537 constexpr
size_t __input_size = _From::_S_size * (1 +
sizeof...(_More));
538 if constexpr (__is_vectorizable_v<_To>)
539 return __convert<__vector_type_t<_To, __input_size>>(__v0, __vs...);
540 else if constexpr (!__is_vector_type_v<_To>)
541 return _To(__convert<typename _To::_BuiltinType>(__v0, __vs...));
545 sizeof...(_More) == 0
546 || _VectorTraits<_To>::_S_full_size >= __input_size,
547 "__convert(...) requires the input to fit into the output");
548 return __vector_convert<_To>(__v0, __vs...);
558 template <
typename _To,
563 typename _From,
typename _FromVT = _VectorTraits<_From>>
564 _GLIBCXX_SIMD_INTRINSIC
auto
565 __convert_all(_From __v)
567 if constexpr (is_arithmetic_v<_To> && _NParts != 1)
569 static_assert(_Offset < _FromVT::_S_full_size);
571 = _NParts == 0 ? _FromVT::_S_partial_width - _Offset : _NParts;
572 return __generate_from_n_evaluations<_Np, array<_To, _Np>>(
573 [&](
auto __i) {
return static_cast<_To
>(__v[__i + _Offset]); });
577 static_assert(__is_vector_type_v<_To>);
578 using _ToVT = _VectorTraits<_To>;
579 if constexpr (__is_vector_type_v<_From>)
580 return __convert_all<_To, _NParts>(__as_wrapper(__v));
581 else if constexpr (_NParts == 1)
583 static_assert(_Offset % _ToVT::_S_full_size == 0);
584 return array<_To, 1>{__vector_convert<_To>(
585 __extract_part<_Offset / _ToVT::_S_full_size,
586 __div_roundup(_FromVT::_S_partial_width,
587 _ToVT::_S_full_size)>(__v))};
589 #if _GLIBCXX_SIMD_X86INTRIN
590 else if constexpr (!__have_sse4_1 && _Offset == 0
591 && is_integral_v<typename _FromVT::value_type>
592 &&
sizeof(
typename _FromVT::value_type)
593 <
sizeof(
typename _ToVT::value_type)
594 && !(
sizeof(
typename _FromVT::value_type) == 4
595 && is_same_v<typename _ToVT::value_type, double>))
597 using _ToT =
typename _ToVT::value_type;
598 using _FromT =
typename _FromVT::value_type;
602 : (_FromVT::_S_partial_width / _ToVT::_S_full_size);
603 using _R = array<_To, _Np>;
608 [[maybe_unused]]
auto __adjust
610 auto __vv) -> _SimdWrapper<_FromT, decltype(__n)::value> {
611 return __vector_bitcast<_FromT, decltype(__n)::value>(__vv);
613 [[maybe_unused]]
const auto __vi = __to_intrin(__v);
614 auto&& __make_array = [](
auto __x0, [[maybe_unused]]
auto __x1) {
615 if constexpr (_Np == 1)
616 return _R{__intrin_bitcast<_To>(__x0)};
618 return _R{__intrin_bitcast<_To>(__x0),
619 __intrin_bitcast<_To>(__x1)};
622 if constexpr (_Np == 0)
624 else if constexpr (
sizeof(_FromT) == 1 &&
sizeof(_ToT) == 2)
626 static_assert(is_integral_v<_FromT>);
627 static_assert(is_integral_v<_ToT>);
628 if constexpr (is_unsigned_v<_FromT>)
629 return __make_array(_mm_unpacklo_epi8(__vi, __m128i()),
630 _mm_unpackhi_epi8(__vi, __m128i()));
633 _mm_srai_epi16(_mm_unpacklo_epi8(__vi, __vi), 8),
634 _mm_srai_epi16(_mm_unpackhi_epi8(__vi, __vi), 8));
636 else if constexpr (
sizeof(_FromT) == 2 &&
sizeof(_ToT) == 4)
638 static_assert(is_integral_v<_FromT>);
639 if constexpr (is_floating_point_v<_ToT>)
642 = __convert_all<__vector_type16_t<int>, _Np>(
643 __adjust(_SizeConstant<_Np * 4>(), __v));
644 return __generate_from_n_evaluations<_Np, _R>(
646 return __vector_convert<_To>(__as_wrapper(__ints[__i]));
649 else if constexpr (is_unsigned_v<_FromT>)
650 return __make_array(_mm_unpacklo_epi16(__vi, __m128i()),
651 _mm_unpackhi_epi16(__vi, __m128i()));
654 _mm_srai_epi32(_mm_unpacklo_epi16(__vi, __vi), 16),
655 _mm_srai_epi32(_mm_unpackhi_epi16(__vi, __vi), 16));
657 else if constexpr (
sizeof(_FromT) == 4 &&
sizeof(_ToT) == 8
658 && is_integral_v<_FromT> && is_integral_v<_ToT>)
660 if constexpr (is_unsigned_v<_FromT>)
661 return __make_array(_mm_unpacklo_epi32(__vi, __m128i()),
662 _mm_unpackhi_epi32(__vi, __m128i()));
665 _mm_unpacklo_epi32(__vi, _mm_srai_epi32(__vi, 31)),
666 _mm_unpackhi_epi32(__vi, _mm_srai_epi32(__vi, 31)));
668 else if constexpr (
sizeof(_FromT) == 4 &&
sizeof(_ToT) == 8
669 && is_integral_v<_FromT> && is_integral_v<_ToT>)
671 if constexpr (is_unsigned_v<_FromT>)
672 return __make_array(_mm_unpacklo_epi32(__vi, __m128i()),
673 _mm_unpackhi_epi32(__vi, __m128i()));
676 _mm_unpacklo_epi32(__vi, _mm_srai_epi32(__vi, 31)),
677 _mm_unpackhi_epi32(__vi, _mm_srai_epi32(__vi, 31)));
679 else if constexpr (
sizeof(_FromT) == 1 &&
sizeof(_ToT) >= 4
680 && is_signed_v<_FromT>)
682 const __m128i __vv[2] = {_mm_unpacklo_epi8(__vi, __vi),
683 _mm_unpackhi_epi8(__vi, __vi)};
684 const __vector_type_t<int, 4> __vvvv[4] = {
685 __vector_bitcast<int>(_mm_unpacklo_epi16(__vv[0], __vv[0])),
686 __vector_bitcast<int>(_mm_unpackhi_epi16(__vv[0], __vv[0])),
687 __vector_bitcast<int>(_mm_unpacklo_epi16(__vv[1], __vv[1])),
688 __vector_bitcast<int>(_mm_unpackhi_epi16(__vv[1], __vv[1]))};
689 if constexpr (
sizeof(_ToT) == 4)
690 return __generate_from_n_evaluations<_Np, _R>([&](auto __i) {
691 return __vector_convert<_To>(
692 _SimdWrapper<int, 4>(__vvvv[__i] >> 24));
694 else if constexpr (is_integral_v<_ToT>)
695 return __generate_from_n_evaluations<_Np, _R>([&](
auto __i) {
696 const auto __signbits = __to_intrin(__vvvv[__i / 2] >> 31);
697 const auto __sx32 = __to_intrin(__vvvv[__i / 2] >> 24);
698 return __vector_bitcast<_ToT>(
699 __i % 2 == 0 ? _mm_unpacklo_epi32(__sx32, __signbits)
700 : _mm_unpackhi_epi32(__sx32, __signbits));
703 return __generate_from_n_evaluations<_Np, _R>([&](
auto __i) {
704 const _SimdWrapper<int, 4> __int4 = __vvvv[__i / 2] >> 24;
705 return __vector_convert<_To>(
706 __i % 2 == 0 ? __int4
707 : _SimdWrapper<int, 4>(
708 _mm_unpackhi_epi64(__to_intrin(__int4),
709 __to_intrin(__int4))));
712 else if constexpr (
sizeof(_FromT) == 1 &&
sizeof(_ToT) == 4)
714 const auto __shorts = __convert_all<__vector_type16_t<
715 conditional_t<is_signed_v<_FromT>, short,
unsigned short>>>(
716 __adjust(_SizeConstant<(_Np + 1) / 2 * 8>(), __v));
717 return __generate_from_n_evaluations<_Np, _R>([&](
auto __i) {
718 return __convert_all<_To>(__shorts[__i / 2])[__i % 2];
721 else if constexpr (
sizeof(_FromT) == 2 &&
sizeof(_ToT) == 8
722 && is_signed_v<_FromT> && is_integral_v<_ToT>)
724 const __m128i __vv[2] = {_mm_unpacklo_epi16(__vi, __vi),
725 _mm_unpackhi_epi16(__vi, __vi)};
726 const __vector_type16_t<int> __vvvv[4]
727 = {__vector_bitcast<int>(
728 _mm_unpacklo_epi32(_mm_srai_epi32(__vv[0], 16),
729 _mm_srai_epi32(__vv[0], 31))),
730 __vector_bitcast<int>(
731 _mm_unpackhi_epi32(_mm_srai_epi32(__vv[0], 16),
732 _mm_srai_epi32(__vv[0], 31))),
733 __vector_bitcast<int>(
734 _mm_unpacklo_epi32(_mm_srai_epi32(__vv[1], 16),
735 _mm_srai_epi32(__vv[1], 31))),
736 __vector_bitcast<int>(
737 _mm_unpackhi_epi32(_mm_srai_epi32(__vv[1], 16),
738 _mm_srai_epi32(__vv[1], 31)))};
739 return __generate_from_n_evaluations<_Np, _R>([&](
auto __i) {
740 return __vector_bitcast<_ToT>(__vvvv[__i]);
743 else if constexpr (
sizeof(_FromT) <= 2 &&
sizeof(_ToT) == 8)
747 is_signed_v<_FromT> || is_floating_point_v<_ToT>, int,
749 __adjust(_SizeConstant<(_Np + 1) / 2 * 4>(), __v));
750 return __generate_from_n_evaluations<_Np, _R>([&](
auto __i) {
751 return __convert_all<_To>(__ints[__i / 2])[__i % 2];
755 __assert_unreachable<_To>();
758 else if constexpr ((_FromVT::_S_partial_width - _Offset)
759 > _ToVT::_S_full_size)
768 constexpr
size_t _NTotal
769 = (_FromVT::_S_partial_width - _Offset) / _ToVT::_S_full_size;
770 constexpr
size_t _Np = _NParts == 0 ? _NTotal : _NParts;
773 || (_Np == _NTotal + 1
774 && (_FromVT::_S_partial_width - _Offset) % _ToVT::_S_full_size
776 using _R = array<_To, _Np>;
777 if constexpr (_Np == 1)
778 return _R{__vector_convert<_To>(
779 __extract_part<_Offset, _FromVT::_S_partial_width,
780 _ToVT::_S_full_size>(__v))};
782 return __generate_from_n_evaluations<_Np, _R>([&](
783 auto __i) constexpr {
785 = __extract_part<__i * _ToVT::_S_full_size + _Offset,
786 _FromVT::_S_partial_width,
787 _ToVT::_S_full_size>(__v);
788 return __vector_convert<_To>(__part);
791 else if constexpr (_Offset == 0)
792 return array<_To, 1>{__vector_convert<_To>(__v)};
794 return array<_To, 1>{__vector_convert<_To>(
795 __extract_part<_Offset, _FromVT::_S_partial_width,
796 _FromVT::_S_partial_width - _Offset>(__v))};
803 template <
typename _Tp,
typename _Mp,
typename _Abi,
size_t _Np>
807 using _SimdImpl =
typename _Abi::_SimdImpl;
808 using _MaskImpl =
typename _Abi::_MaskImpl;
811 using _SimdMember = _SimdWrapper<_Tp, _Np>;
812 using _MaskMember = _SimdWrapper<_Mp, _Np>;
813 static constexpr
size_t _S_simd_align =
alignof(_SimdMember);
814 static constexpr
size_t _S_mask_align =
alignof(_MaskMember);
818 static constexpr
size_t _S_full_size = _SimdMember::_S_full_size;
819 static constexpr
bool _S_is_partial = _SimdMember::_S_is_partial;
825 _GLIBCXX_SIMD_ALWAYS_INLINE
826 explicit operator __intrinsic_type_t<_Tp, _Np>()
const
828 return __to_intrin(
static_cast<const simd<_Tp, _Abi>*
>(
this)->_M_data);
830 _GLIBCXX_SIMD_ALWAYS_INLINE
831 explicit operator __vector_type_t<_Tp, _Np>()
const
833 return static_cast<const simd<_Tp, _Abi>*
>(
this)->_M_data.__builtin();
839 _GLIBCXX_SIMD_ALWAYS_INLINE
840 explicit operator __intrinsic_type_t<_Tp, _Np>()
const
841 {
return __data(*
static_cast<const simd<_Tp, _Abi>*
>(
this)); }
845 is_same<__intrinsic_type_t<_Tp, _Np>, __vector_type_t<_Tp, _Np>>::value,
846 _SimdBase1, _SimdBase2>;
852 _GLIBCXX_SIMD_ALWAYS_INLINE
853 explicit operator __intrinsic_type_t<_Tp, _Np>()
const
855 return static_cast<const simd_mask<_Tp, _Abi>*
>(
this)
856 ->_M_data.__intrin();
858 _GLIBCXX_SIMD_ALWAYS_INLINE
859 explicit operator __vector_type_t<_Tp, _Np>()
const
861 return static_cast<const simd_mask<_Tp, _Abi>*
>(
this)->_M_data._M_data;
867 _GLIBCXX_SIMD_ALWAYS_INLINE
868 explicit operator __intrinsic_type_t<_Tp, _Np>()
const
869 {
return __data(*
static_cast<const simd_mask<_Tp, _Abi>*
>(
this)); }
873 is_same<__intrinsic_type_t<_Tp, _Np>, __vector_type_t<_Tp, _Np>>::value,
874 _MaskBase1, _MaskBase2>;
881 using _Up = __intrinsic_type_t<_Tp, _Np>;
885 _GLIBCXX_SIMD_ALWAYS_INLINE
886 _MaskCastType(_Up __x) : _M_data(__x) {}
887 _GLIBCXX_SIMD_ALWAYS_INLINE
888 operator _MaskMember()
const {
return _M_data; }
896 using _Ap = __intrinsic_type_t<_Tp, _Np>;
900 _GLIBCXX_SIMD_ALWAYS_INLINE
901 _SimdCastType1(_Ap __a) : _M_data(__vector_bitcast<_Tp>(__a)) {}
902 _GLIBCXX_SIMD_ALWAYS_INLINE
903 operator _SimdMember()
const {
return _M_data; }
908 using _Ap = __intrinsic_type_t<_Tp, _Np>;
909 using _Bp = __vector_type_t<_Tp, _Np>;
913 _GLIBCXX_SIMD_ALWAYS_INLINE
914 _SimdCastType2(_Ap __a) : _M_data(__vector_bitcast<_Tp>(__a)) {}
915 _GLIBCXX_SIMD_ALWAYS_INLINE
916 _SimdCastType2(_Bp __b) : _M_data(__b) {}
917 _GLIBCXX_SIMD_ALWAYS_INLINE
918 operator _SimdMember()
const {
return _M_data; }
922 is_same<__intrinsic_type_t<_Tp, _Np>, __vector_type_t<_Tp, _Np>>::value,
923 _SimdCastType1, _SimdCastType2>;
928 struct _CommonImplX86;
929 struct _CommonImplNeon;
930 struct _CommonImplBuiltin;
931 template <
typename _Abi,
typename = __detail::__odr_helper>
struct _SimdImplBuiltin;
932 template <
typename _Abi,
typename = __detail::__odr_helper>
struct _MaskImplBuiltin;
933 template <
typename _Abi,
typename = __detail::__odr_helper>
struct _SimdImplX86;
934 template <
typename _Abi,
typename = __detail::__odr_helper>
struct _MaskImplX86;
935 template <
typename _Abi,
typename = __detail::__odr_helper>
struct _SimdImplNeon;
936 template <
typename _Abi,
typename = __detail::__odr_helper>
struct _MaskImplNeon;
937 template <
typename _Abi,
typename = __detail::__odr_helper>
struct _SimdImplPpc;
938 template <
typename _Abi,
typename = __detail::__odr_helper>
struct _MaskImplPpc;
941 template <
int _UsedBytes>
942 struct simd_abi::_VecBuiltin
944 template <
typename _Tp>
945 static constexpr
size_t _S_size = _UsedBytes /
sizeof(_Tp);
948 struct _IsValidAbiTag : __bool_constant<(_UsedBytes > 1)> {};
950 template <
typename _Tp>
951 struct _IsValidSizeFor
952 : __bool_constant<(_UsedBytes / sizeof(_Tp) > 1
953 && _UsedBytes % sizeof(_Tp) == 0
954 && _UsedBytes <= __vectorized_sizeof<_Tp>()
955 && (!__have_avx512f || _UsedBytes <= 32))> {};
957 template <typename _Tp>
958 struct _IsValid : conjunction<_IsValidAbiTag, __is_vectorizable<_Tp>,
959 _IsValidSizeFor<_Tp>> {};
961 template <typename _Tp>
962 static constexpr bool _S_is_valid_v = _IsValid<_Tp>::value;
966 #if _GLIBCXX_SIMD_X86INTRIN
967 using _CommonImpl = _CommonImplX86;
968 using _SimdImpl = _SimdImplX86<_VecBuiltin<_UsedBytes>>;
969 using _MaskImpl = _MaskImplX86<_VecBuiltin<_UsedBytes>>;
970 #elif _GLIBCXX_SIMD_HAVE_NEON
971 using _CommonImpl = _CommonImplNeon;
972 using _SimdImpl = _SimdImplNeon<_VecBuiltin<_UsedBytes>>;
973 using _MaskImpl = _MaskImplNeon<_VecBuiltin<_UsedBytes>>;
975 using _CommonImpl = _CommonImplBuiltin;
977 using _SimdImpl = _SimdImplPpc<_VecBuiltin<_UsedBytes>>;
978 using _MaskImpl = _MaskImplPpc<_VecBuiltin<_UsedBytes>>;
980 using _SimdImpl = _SimdImplBuiltin<_VecBuiltin<_UsedBytes>>;
981 using _MaskImpl = _MaskImplBuiltin<_VecBuiltin<_UsedBytes>>;
987 template <typename _Tp>
988 using _MaskValueType = __int_for_sizeof_t<_Tp>;
990 template <typename _Tp>
992 = conditional_t<_S_is_valid_v<_Tp>,
993 _GnuTraits<_Tp, _MaskValueType<_Tp>,
994 _VecBuiltin<_UsedBytes>, _S_size<_Tp>>,
999 template <typename _Tp>
1000 static constexpr size_t _S_full_size = __traits<_Tp>::_S_full_size;
1002 template <typename _Tp>
1003 static constexpr bool _S_is_partial = __traits<_Tp>::_S_is_partial;
1007 template <typename _Tp>
1008 using _MaskMember = _SimdWrapper<_MaskValueType<_Tp>, _S_size<_Tp>>;
1010 template <typename _Tp>
1011 _GLIBCXX_SIMD_INTRINSIC static constexpr _MaskMember<_Tp>
1014 using _UV = typename _MaskMember<_Tp>::_BuiltinType;
1015 if constexpr (!_MaskMember<_Tp>::_S_is_partial)
1019 constexpr auto __size = _S_size<_Tp>;
1020 _GLIBCXX_SIMD_USE_CONSTEXPR auto __r = __generate_vector<_UV>(
1021 [](auto __i) constexpr { return __i < __size ? -1 : 0; });
1026 template <typename _Tp>
1027 _GLIBCXX_SIMD_INTRINSIC static constexpr __intrinsic_type_t<_Tp,
1029 _S_implicit_mask_intrin()
1032 __vector_bitcast<_Tp>(_S_implicit_mask<_Tp>()._M_data));
1035 template <typename _TW, typename _TVT = _VectorTraits<_TW>>
1036 _GLIBCXX_SIMD_INTRINSIC static constexpr _TW _S_masked(_TW __x)
1038 using _Tp = typename _TVT::value_type;
1039 if constexpr (!_MaskMember<_Tp>::_S_is_partial)
1042 return __and(__as_vector(__x),
1043 __vector_bitcast<_Tp>(_S_implicit_mask<_Tp>()));
1046 template <typename _TW, typename _TVT = _VectorTraits<_TW>>
1047 _GLIBCXX_SIMD_INTRINSIC static constexpr auto
1048 __make_padding_nonzero(_TW __x)
1050 using _Tp = typename _TVT::value_type;
1051 if constexpr (!_S_is_partial<_Tp>)
1055 _GLIBCXX_SIMD_USE_CONSTEXPR auto __implicit_mask
1056 = __vector_bitcast<_Tp>(_S_implicit_mask<_Tp>());
1057 if constexpr (is_integral_v<_Tp>)
1058 return __or(__x, ~__implicit_mask);
1061 _GLIBCXX_SIMD_USE_CONSTEXPR auto __one
1062 = __andnot(__implicit_mask,
1063 __vector_broadcast<_S_full_size<_Tp>>(_Tp(1)));
1067 return __or(__and(__x, __implicit_mask), __one);
1076 template <int _UsedBytes>
1077 struct simd_abi::_VecBltnBtmsk
1079 template <typename _Tp>
1080 static constexpr size_t _S_size = _UsedBytes / sizeof(_Tp);
1083 struct _IsValidAbiTag : __bool_constant<(_UsedBytes > 1)> {};
1085 template <typename _Tp>
1086 struct _IsValidSizeFor
1087 : __bool_constant<(_UsedBytes / sizeof(_Tp) > 1
1088 && _UsedBytes % sizeof(_Tp) == 0 && _UsedBytes <= 64
1089 && (_UsedBytes > 32 || __have_avx512vl))> {};
1093 template <
typename _Tp>
1096 _IsValidAbiTag, __bool_constant<__have_avx512f>,
1097 __bool_constant<__have_avx512bw || (sizeof(_Tp) >= 4)>,
1098 __bool_constant<(__vectorized_sizeof<_Tp>() > sizeof(_Tp))>,
1099 _IsValidSizeFor<_Tp>> {};
1101 template <
typename _Tp>
1102 static constexpr
bool _S_is_valid_v = _IsValid<_Tp>::value;
1106 #if _GLIBCXX_SIMD_X86INTRIN
1107 using _CommonImpl = _CommonImplX86;
1108 using _SimdImpl = _SimdImplX86<_VecBltnBtmsk<_UsedBytes>>;
1109 using _MaskImpl = _MaskImplX86<_VecBltnBtmsk<_UsedBytes>>;
1112 struct _MissingImpl;
1114 using _CommonImpl = _MissingImpl<_UsedBytes>;
1115 using _SimdImpl = _MissingImpl<_UsedBytes>;
1116 using _MaskImpl = _MissingImpl<_UsedBytes>;
1121 template <
typename _Tp>
1122 using _MaskMember = _SimdWrapper<bool, _S_size<_Tp>>;
1124 template <
typename _Tp>
1127 _GnuTraits<_Tp, bool, _VecBltnBtmsk<_UsedBytes>, _S_size<_Tp>>,
1132 template <
typename _Tp>
1133 static constexpr
size_t _S_full_size = __traits<_Tp>::_S_full_size;
1134 template <
typename _Tp>
1135 static constexpr
bool _S_is_partial = __traits<_Tp>::_S_is_partial;
1140 template <
typename _Tp>
1141 using _ImplicitMask = _SimdWrapper<bool, _S_size<_Tp>>;
1144 template <
size_t _Np>
1145 _GLIBCXX_SIMD_INTRINSIC
static constexpr __bool_storage_member_type_t<_Np>
1148 using _Tp = __bool_storage_member_type_t<_Np>;
1149 return _Np <
sizeof(_Tp) * __CHAR_BIT__ ? _Tp((1ULL << _Np) - 1) : ~_Tp();
1152 template <
typename _Tp>
1153 _GLIBCXX_SIMD_INTRINSIC
static constexpr _ImplicitMask<_Tp>
1155 {
return __implicit_mask_n<_S_size<_Tp>>(); }
1157 template <
typename _Tp>
1158 _GLIBCXX_SIMD_INTRINSIC
static constexpr __bool_storage_member_type_t<
1160 _S_implicit_mask_intrin()
1161 {
return __implicit_mask_n<_S_size<_Tp>>(); }
1163 template <
typename _Tp,
size_t _Np>
1164 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1165 _S_masked(_SimdWrapper<_Tp, _Np> __x)
1167 if constexpr (is_same_v<_Tp, bool>)
1168 if constexpr (_Np < 8 || (_Np & (_Np - 1)) != 0)
1169 return _MaskImpl::_S_bit_and(
1170 __x, _SimdWrapper<_Tp, _Np>(
1171 __bool_storage_member_type_t<_Np>((1ULL << _Np) - 1)));
1175 return _S_masked(__x._M_data);
1178 template <typename _TV>
1179 _GLIBCXX_SIMD_INTRINSIC static constexpr _TV
1182 using _Tp =
typename _VectorTraits<_TV>::value_type;
1184 !__is_bitmask_v<_TV>,
1185 "_VecBltnBtmsk::_S_masked cannot work on bitmasks, since it doesn't "
1186 "know the number of elements. Use _SimdWrapper<bool, N> instead.");
1187 if constexpr (_S_is_partial<_Tp>)
1189 constexpr
size_t _Np = _S_size<_Tp>;
1190 return __make_dependent_t<_TV, _CommonImpl>::_S_blend(
1191 _S_implicit_mask<_Tp>(), _SimdWrapper<_Tp, _Np>(),
1192 _SimdWrapper<_Tp, _Np>(__x));
1198 template <
typename _TV,
typename _TVT = _VectorTraits<_TV>>
1199 _GLIBCXX_SIMD_INTRINSIC
static constexpr
auto
1200 __make_padding_nonzero(_TV __x)
1202 using _Tp =
typename _TVT::value_type;
1203 if constexpr (!_S_is_partial<_Tp>)
1207 constexpr
size_t _Np = _S_size<_Tp>;
1208 if constexpr (is_integral_v<typename _TVT::value_type>)
1210 | __generate_vector<_Tp, _S_full_size<_Tp>>(
1211 [](
auto __i) -> _Tp {
1218 return __make_dependent_t<_TV, _CommonImpl>::_S_blend(
1219 _S_implicit_mask<_Tp>(),
1220 _SimdWrapper<_Tp, _Np>(
1221 __vector_broadcast<_S_full_size<_Tp>>(_Tp(1))),
1222 _SimdWrapper<_Tp, _Np>(__x))
1232 struct _CommonImplBuiltin
1239 template <
typename _From,
typename _To,
size_t _ToSize>
1240 static inline constexpr
bool __converts_via_decomposition_v
1241 =
sizeof(_From) !=
sizeof(_To);
1245 template <
typename _Tp,
size_t _Np,
size_t _Bytes = _Np * sizeof(_Tp)>
1246 _GLIBCXX_SIMD_INTRINSIC
static __vector_type_t<_Tp, _Np>
1247 _S_load(
const void* __p)
1249 static_assert(_Np > 1);
1250 static_assert(_Bytes %
sizeof(_Tp) == 0);
1251 using _Rp = __vector_type_t<_Tp, _Np>;
1252 if constexpr (
sizeof(_Rp) == _Bytes)
1255 __builtin_memcpy(&__r, __p, _Bytes);
1260 #ifdef _GLIBCXX_SIMD_WORKAROUND_PR90424
1264 conditional_t<_Bytes % 8 == 0, long long, int>,
1265 conditional_t<_Bytes % 2 == 0, short, signed char>>,
1266 conditional_t<(_Bytes < 8 || _Np % 2 == 1 || _Np == 2), _Tp,
1268 using _V = __vector_type_t<_Up, _Np *
sizeof(_Tp) /
sizeof(_Up)>;
1269 if constexpr (
sizeof(_V) !=
sizeof(_Rp))
1272 __builtin_memcpy(&__r, __p, _Bytes);
1281 static_assert(_Bytes <=
sizeof(_V));
1282 __builtin_memcpy(&__r, __p, _Bytes);
1283 return reinterpret_cast<_Rp
>(__r);
1290 template <
size_t _ReqBytes = 0,
typename _TV>
1291 _GLIBCXX_SIMD_INTRINSIC
static void _S_store(_TV __x,
void* __addr)
1293 constexpr
size_t _Bytes = _ReqBytes == 0 ?
sizeof(__x) : _ReqBytes;
1294 static_assert(
sizeof(__x) >= _Bytes);
1296 if constexpr (__is_vector_type_v<_TV>)
1298 using _Tp =
typename _VectorTraits<_TV>::value_type;
1299 constexpr
size_t _Np = _Bytes /
sizeof(_Tp);
1300 static_assert(_Np *
sizeof(_Tp) == _Bytes);
1302 #ifdef _GLIBCXX_SIMD_WORKAROUND_PR90424
1304 (is_integral_v<_Tp> || _Bytes < 4),
1305 conditional_t<(
sizeof(__x) >
sizeof(
long long)),
long long, _Tp>,
1307 const auto __v = __vector_bitcast<_Up>(__x);
1309 const __vector_type_t<_Tp, _Np> __v = __x;
1312 if constexpr ((_Bytes & (_Bytes - 1)) != 0)
1314 constexpr
size_t _MoreBytes = std::__bit_ceil(_Bytes);
1315 alignas(decltype(__v))
char __tmp[_MoreBytes];
1316 __builtin_memcpy(__tmp, &__v, _MoreBytes);
1317 __builtin_memcpy(__addr, __tmp, _Bytes);
1320 __builtin_memcpy(__addr, &__v, _Bytes);
1323 __builtin_memcpy(__addr, &__x, _Bytes);
1326 template <
typename _Tp,
size_t _Np>
1327 _GLIBCXX_SIMD_INTRINSIC
static void _S_store(_SimdWrapper<_Tp, _Np> __x,
1329 { _S_store<_Np * sizeof(_Tp)>(__x._M_data, __addr); }
1333 template <
size_t _Np,
bool _Sanitized>
1334 _GLIBCXX_SIMD_INTRINSIC
static constexpr
void
1335 _S_store_bool_array(_BitMask<_Np, _Sanitized> __x,
bool* __mem)
1337 if constexpr (_Np == 1)
1339 else if constexpr (_Np == 2)
1341 short __bool2 = (__x._M_to_bits() * 0x81) & 0x0101;
1342 _S_store<_Np>(__bool2, __mem);
1344 else if constexpr (_Np == 3)
1346 int __bool3 = (__x._M_to_bits() * 0x4081) & 0x010101;
1347 _S_store<_Np>(__bool3, __mem);
1351 __execute_n_times<__div_roundup(_Np, 4)>([&](
auto __i) {
1352 constexpr
int __offset = __i * 4;
1353 constexpr
int __remaining = _Np - __offset;
1354 if constexpr (__remaining > 4 && __remaining <= 7)
1356 const _ULLong __bool7
1357 = (__x.template _M_extract<__offset>()._M_to_bits()
1359 & 0x0101010101010101ULL;
1360 _S_store<__remaining>(__bool7, __mem + __offset);
1362 else if constexpr (__remaining >= 4)
1364 int __bits = __x.template _M_extract<__offset>()._M_to_bits();
1365 if constexpr (__remaining > 7)
1367 const
int __bool4 = (__bits * 0x204081) & 0x01010101;
1368 _S_store<4>(__bool4, __mem + __offset);
1376 template <typename _Tp,
size_t _Np>
1377 _GLIBCXX_SIMD_INTRINSIC static constexpr auto
1378 _S_blend(_SimdWrapper<__int_for_sizeof_t<_Tp>, _Np> __k,
1379 _SimdWrapper<_Tp, _Np> __at0, _SimdWrapper<_Tp, _Np> __at1)
1380 {
return __k._M_data ? __at1._M_data : __at0._M_data; }
1387 template <
typename _Abi,
typename>
1388 struct _SimdImplBuiltin
1391 template <
typename _Tp>
1392 static constexpr
size_t _S_max_store_size = 16;
1394 using abi_type = _Abi;
1396 template <
typename _Tp>
1397 using _TypeTag = _Tp*;
1399 template <
typename _Tp>
1400 using _SimdMember =
typename _Abi::template __traits<_Tp>::_SimdMember;
1402 template <
typename _Tp>
1403 using _MaskMember =
typename _Abi::template _MaskMember<_Tp>;
1405 template <
typename _Tp>
1406 static constexpr
size_t _S_size = _Abi::template _S_size<_Tp>;
1408 template <
typename _Tp>
1409 static constexpr
size_t _S_full_size = _Abi::template _S_full_size<_Tp>;
1411 using _CommonImpl =
typename _Abi::_CommonImpl;
1412 using _SuperImpl =
typename _Abi::_SimdImpl;
1413 using _MaskImpl =
typename _Abi::_MaskImpl;
1416 template <
typename _Tp,
size_t _Np>
1417 _GLIBCXX_SIMD_INTRINSIC
static simd<_Tp, _Abi>
1418 _M_make_simd(_SimdWrapper<_Tp, _Np> __x)
1419 {
return {__private_init, __x}; }
1421 template <
typename _Tp,
size_t _Np>
1422 _GLIBCXX_SIMD_INTRINSIC
static simd<_Tp, _Abi>
1423 _M_make_simd(__intrinsic_type_t<_Tp, _Np> __x)
1424 {
return {__private_init, __vector_bitcast<_Tp>(__x)}; }
1427 template <
typename _Tp>
1428 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdMember<_Tp>
1429 _S_broadcast(_Tp __x) noexcept
1430 {
return __vector_broadcast<_S_full_size<_Tp>>(__x); }
1433 template <
typename _Fp,
typename _Tp>
1434 inline static constexpr _SimdMember<_Tp> _S_generator(_Fp&& __gen,
1437 return __generate_vector<_Tp, _S_full_size<_Tp>>([&](
1438 auto __i) constexpr {
1439 if constexpr (__i < _S_size<_Tp>)
1447 template <
typename _Tp,
typename _Up>
1448 _GLIBCXX_SIMD_INTRINSIC
static _SimdMember<_Tp>
1449 _S_load(
const _Up* __mem, _TypeTag<_Tp>) noexcept
1451 constexpr
size_t _Np = _S_size<_Tp>;
1452 constexpr
size_t __max_load_size
1453 = (
sizeof(_Up) >= 4 && __have_avx512f) || __have_avx512bw ? 64
1454 : (is_floating_point_v<_Up> && __have_avx) || __have_avx2 ? 32
1456 constexpr
size_t __bytes_to_load =
sizeof(_Up) * _Np;
1457 if constexpr (
sizeof(_Up) > 8)
1458 return __generate_vector<_Tp, _SimdMember<_Tp>::_S_full_size>([&](
1459 auto __i) constexpr {
1460 return static_cast<_Tp
>(__i < _Np ? __mem[__i] : 0);
1462 else if constexpr (is_same_v<_Up, _Tp>)
1463 return _CommonImpl::template _S_load<_Tp, _S_full_size<_Tp>,
1464 _Np *
sizeof(_Tp)>(__mem);
1465 else if constexpr (__bytes_to_load <= __max_load_size)
1466 return __convert<_SimdMember<_Tp>>(
1467 _CommonImpl::template _S_load<_Up, _Np>(__mem));
1468 else if constexpr (__bytes_to_load % __max_load_size == 0)
1470 constexpr
size_t __n_loads = __bytes_to_load / __max_load_size;
1471 constexpr
size_t __elements_per_load = _Np / __n_loads;
1472 return __call_with_n_evaluations<__n_loads>(
1473 [](
auto... __uncvted) {
1474 return __convert<_SimdMember<_Tp>>(__uncvted...);
1477 return _CommonImpl::template _S_load<_Up, __elements_per_load>(
1478 __mem + __i * __elements_per_load);
1481 else if constexpr (__bytes_to_load % (__max_load_size / 2) == 0
1482 && __max_load_size > 16)
1484 constexpr
size_t __n_loads
1485 = __bytes_to_load / (__max_load_size / 2);
1486 constexpr
size_t __elements_per_load = _Np / __n_loads;
1487 return __call_with_n_evaluations<__n_loads>(
1488 [](
auto... __uncvted) {
1489 return __convert<_SimdMember<_Tp>>(__uncvted...);
1492 return _CommonImpl::template _S_load<_Up, __elements_per_load>(
1493 __mem + __i * __elements_per_load);
1497 return __call_with_subscripts(
1498 __mem, make_index_sequence<_Np>(), [](
auto... __args) {
1499 return __vector_type_t<_Tp, _S_full_size<_Tp>>{
1500 static_cast<_Tp
>(__args)...};
1505 template <
typename _Tp,
size_t _Np,
typename _Up>
1506 static inline _SimdWrapper<_Tp, _Np>
1507 _S_masked_load(_SimdWrapper<_Tp, _Np> __merge, _MaskMember<_Tp> __k,
1508 const _Up* __mem) noexcept
1510 _BitOps::_S_bit_iteration(_MaskImpl::_S_to_bits(__k), [&](
auto __i) {
1511 __merge._M_set(__i,
static_cast<_Tp
>(__mem[__i]));
1517 template <
typename _Tp,
typename _Up>
1518 _GLIBCXX_SIMD_INTRINSIC
static void
1519 _S_store(_SimdMember<_Tp> __v, _Up* __mem, _TypeTag<_Tp>) noexcept
1522 constexpr
size_t _Np = _S_size<_Tp>;
1523 constexpr
size_t __max_store_size
1524 = _SuperImpl::template _S_max_store_size<_Up>;
1525 if constexpr (
sizeof(_Up) > 8)
1526 __execute_n_times<_Np>([&](auto __i) constexpr {
1527 __mem[__i] = __v[__i];
1529 else if constexpr (is_same_v<_Up, _Tp>)
1530 _CommonImpl::_S_store(__v, __mem);
1531 else if constexpr (
sizeof(_Up) * _Np <= __max_store_size)
1532 _CommonImpl::_S_store(_SimdWrapper<_Up, _Np>(__convert<_Up>(__v)),
1536 constexpr
size_t __vsize = __max_store_size /
sizeof(_Up);
1538 constexpr
size_t __stores = __div_roundup(_Np, __vsize);
1539 constexpr
size_t __full_stores = _Np / __vsize;
1540 using _V = __vector_type_t<_Up, __vsize>;
1541 const array<_V, __stores> __converted
1542 = __convert_all<_V, __stores>(__v);
1543 __execute_n_times<__full_stores>([&](
auto __i) constexpr {
1544 _CommonImpl::_S_store(__converted[__i], __mem + __i * __vsize);
1546 if constexpr (__full_stores < __stores)
1547 _CommonImpl::template _S_store<(_Np - __full_stores * __vsize)
1549 __converted[__full_stores], __mem + __full_stores * __vsize);
1554 template <
typename _Tp,
size_t _Np>
1555 _GLIBCXX_SIMD_INTRINSIC
static void
1556 _S_masked_store_nocvt(_SimdWrapper<_Tp, _Np> __v, _Tp* __mem,
1557 _MaskMember<_Tp> __k)
1559 _BitOps::_S_bit_iteration(
1560 _MaskImpl::_S_to_bits(__k), [&](
auto __i) constexpr {
1561 __mem[__i] = __v[__i];
1566 template <
typename _TW,
typename _TVT = _VectorTraits<_TW>,
1567 typename _Tp =
typename _TVT::value_type,
typename _Up>
1569 _S_masked_store(
const _TW __v, _Up* __mem,
const _MaskMember<_Tp> __k)
1572 constexpr
size_t _TV_size = _S_size<_Tp>;
1573 [[maybe_unused]]
const auto __vi = __to_intrin(__v);
1574 constexpr
size_t __max_store_size
1575 = _SuperImpl::template _S_max_store_size<_Up>;
1579 _Up> || (is_integral_v<_Tp> && is_integral_v<_Up> &&
sizeof(_Tp) ==
sizeof(_Up)))
1582 const _MaskMember<_Up> __kk = [&]() {
1583 if constexpr (__is_bitmask_v<decltype(__k)>)
1584 return _MaskMember<_Up>(__k._M_data);
1586 return __wrapper_bitcast<__int_for_sizeof_t<_Up>>(__k);
1588 _SuperImpl::_S_masked_store_nocvt(__wrapper_bitcast<_Up>(__v),
1591 else if constexpr (__vectorized_sizeof<_Up>() > sizeof(_Up)
1593 template __converts_via_decomposition_v<
1594 _Tp, _Up, __max_store_size>)
1598 constexpr
size_t _UW_size
1599 =
std::min(_TV_size, __max_store_size /
sizeof(_Up));
1600 static_assert(_UW_size <= _TV_size);
1601 using _UW = _SimdWrapper<_Up, _UW_size>;
1602 using _UV = __vector_type_t<_Up, _UW_size>;
1603 using _UAbi = simd_abi::deduce_t<_Up, _UW_size>;
1604 if constexpr (_UW_size == _TV_size)
1606 const _UW __converted = __convert<_UW>(__v);
1607 _SuperImpl::_S_masked_store_nocvt(
1609 _UAbi::_MaskImpl::template _S_convert<
1610 __int_for_sizeof_t<_Up>>(__k));
1614 static_assert(_UW_size *
sizeof(_Up) == __max_store_size);
1615 constexpr
size_t _NFullStores = _TV_size / _UW_size;
1616 constexpr
size_t _NAllStores
1617 = __div_roundup(_TV_size, _UW_size);
1618 constexpr
size_t _NParts = _S_full_size<_Tp> / _UW_size;
1619 const array<_UV, _NAllStores> __converted
1620 = __convert_all<_UV, _NAllStores>(__v);
1621 __execute_n_times<_NFullStores>([&](
auto __i) {
1622 _SuperImpl::_S_masked_store_nocvt(
1623 _UW(__converted[__i]), __mem + __i * _UW_size,
1624 _UAbi::_MaskImpl::template _S_convert<
1625 __int_for_sizeof_t<_Up>>(
1626 __extract_part<__i, _NParts>(__k.__as_full_vector())));
1628 if constexpr (_NAllStores
1630 _SuperImpl::_S_masked_store_nocvt(
1631 _UW(__converted[_NFullStores]),
1632 __mem + _NFullStores * _UW_size,
1633 _UAbi::_MaskImpl::template _S_convert<
1634 __int_for_sizeof_t<_Up>>(
1635 __extract_part<_NFullStores, _NParts>(
1636 __k.__as_full_vector())));
1640 _BitOps::_S_bit_iteration(
1641 _MaskImpl::_S_to_bits(__k), [&](
auto __i) constexpr {
1642 __mem[__i] =
static_cast<_Up
>(__v[__i]);
1647 template <
typename _Tp,
size_t _Np>
1648 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1649 _S_complement(_SimdWrapper<_Tp, _Np> __x) noexcept
1651 if constexpr (is_floating_point_v<_Tp>)
1652 return __vector_bitcast<_Tp>(~__vector_bitcast<__int_for_sizeof_t<_Tp>>(__x));
1654 return ~__x._M_data;
1658 template <
typename _Tp,
size_t _Np>
1659 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1660 _S_unary_minus(_SimdWrapper<_Tp, _Np> __x) noexcept
1664 return -__x._M_data;
1668 template <
typename _Tp,
size_t _Np>
1669 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1670 _S_plus(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1671 {
return __x._M_data + __y._M_data; }
1673 template <
typename _Tp,
size_t _Np>
1674 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1675 _S_minus(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1676 {
return __x._M_data - __y._M_data; }
1678 template <
typename _Tp,
size_t _Np>
1679 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1680 _S_multiplies(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1681 {
return __x._M_data * __y._M_data; }
1683 template <
typename _Tp,
size_t _Np>
1684 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1685 _S_divides(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1689 if constexpr (!_Abi::template _S_is_partial<_Tp>)
1690 return __x._M_data / __y._M_data;
1692 return __x._M_data / _Abi::__make_padding_nonzero(__y._M_data);
1695 template <
typename _Tp,
size_t _Np>
1696 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1697 _S_modulus(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1699 if constexpr (!_Abi::template _S_is_partial<_Tp>)
1700 return __x._M_data % __y._M_data;
1702 return __as_vector(__x)
1703 % _Abi::__make_padding_nonzero(__as_vector(__y));
1706 template <
typename _Tp,
size_t _Np>
1707 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1708 _S_bit_and(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1709 {
return __and(__x, __y); }
1711 template <
typename _Tp,
size_t _Np>
1712 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1713 _S_bit_or(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1714 {
return __or(__x, __y); }
1716 template <
typename _Tp,
size_t _Np>
1717 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1718 _S_bit_xor(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1719 {
return __xor(__x, __y); }
1721 template <
typename _Tp,
size_t _Np>
1722 _GLIBCXX_SIMD_INTRINSIC
static _SimdWrapper<_Tp, _Np>
1723 _S_bit_shift_left(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1724 {
return __x._M_data << __y._M_data; }
1726 template <
typename _Tp,
size_t _Np>
1727 _GLIBCXX_SIMD_INTRINSIC
static _SimdWrapper<_Tp, _Np>
1728 _S_bit_shift_right(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1729 {
return __x._M_data >> __y._M_data; }
1731 template <
typename _Tp,
size_t _Np>
1732 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1733 _S_bit_shift_left(_SimdWrapper<_Tp, _Np> __x,
int __y)
1734 {
return __x._M_data << __y; }
1736 template <
typename _Tp,
size_t _Np>
1737 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
1738 _S_bit_shift_right(_SimdWrapper<_Tp, _Np> __x,
int __y)
1739 {
return __x._M_data >> __y; }
1743 template <
typename _Tp,
size_t _Np>
1744 _GLIBCXX_SIMD_INTRINSIC
static constexpr _MaskMember<_Tp>
1745 _S_equal_to(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1746 {
return __x._M_data == __y._M_data; }
1749 template <
typename _Tp,
size_t _Np>
1750 _GLIBCXX_SIMD_INTRINSIC
static constexpr _MaskMember<_Tp>
1751 _S_not_equal_to(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1752 {
return __x._M_data != __y._M_data; }
1755 template <
typename _Tp,
size_t _Np>
1756 _GLIBCXX_SIMD_INTRINSIC
static constexpr _MaskMember<_Tp>
1757 _S_less(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1758 {
return __x._M_data < __y._M_data; }
1761 template <
typename _Tp,
size_t _Np>
1762 _GLIBCXX_SIMD_INTRINSIC
static constexpr _MaskMember<_Tp>
1763 _S_less_equal(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
1764 {
return __x._M_data <= __y._M_data; }
1767 template <
typename _Tp,
size_t _Np>
1768 _GLIBCXX_SIMD_INTRINSIC
static constexpr _MaskMember<_Tp>
1769 _S_negate(_SimdWrapper<_Tp, _Np> __x) noexcept
1770 {
return !__x._M_data; }
1773 template <
typename _Tp,
size_t _Np>
1774 _GLIBCXX_SIMD_NORMAL_MATH _GLIBCXX_SIMD_INTRINSIC
static constexpr
1775 _SimdWrapper<_Tp, _Np>
1776 _S_min(_SimdWrapper<_Tp, _Np> __a, _SimdWrapper<_Tp, _Np> __b)
1777 {
return __a._M_data < __b._M_data ? __a._M_data : __b._M_data; }
1779 template <
typename _Tp,
size_t _Np>
1780 _GLIBCXX_SIMD_NORMAL_MATH _GLIBCXX_SIMD_INTRINSIC
static constexpr
1781 _SimdWrapper<_Tp, _Np>
1782 _S_max(_SimdWrapper<_Tp, _Np> __a, _SimdWrapper<_Tp, _Np> __b)
1783 {
return __a._M_data > __b._M_data ? __a._M_data : __b._M_data; }
1785 template <
typename _Tp,
size_t _Np>
1786 _GLIBCXX_SIMD_NORMAL_MATH _GLIBCXX_SIMD_INTRINSIC
static constexpr
1787 pair<_SimdWrapper<_Tp, _Np>, _SimdWrapper<_Tp, _Np>>
1788 _S_minmax(_SimdWrapper<_Tp, _Np> __a, _SimdWrapper<_Tp, _Np> __b)
1790 return {__a._M_data < __b._M_data ? __a._M_data : __b._M_data,
1791 __a._M_data < __b._M_data ? __b._M_data : __a._M_data};
1795 template <
size_t _Np,
size_t... _Is,
size_t... _Zeros,
typename _Tp,
1796 typename _BinaryOperation>
1797 _GLIBCXX_SIMD_INTRINSIC
static _Tp
1798 _S_reduce_partial(index_sequence<_Is...>, index_sequence<_Zeros...>,
1799 simd<_Tp, _Abi> __x, _BinaryOperation&& __binary_op)
1801 using _V = __vector_type_t<_Tp, _Np / 2>;
1802 static_assert(
sizeof(_V) <=
sizeof(__x));
1805 using _FullSimd = __deduced_simd<_Tp, _VectorTraits<_V>::_S_full_size>;
1806 using _HalfSimd = __deduced_simd<_Tp, _Np / 2>;
1807 const auto __xx = __as_vector(__x);
1808 return _HalfSimd::abi_type::_SimdImpl::_S_reduce(
1809 static_cast<_HalfSimd
>(__as_vector(__binary_op(
1810 static_cast<_FullSimd
>(__intrin_bitcast<_V>(__xx)),
1811 static_cast<_FullSimd
>(__intrin_bitcast<_V>(
1812 __vector_permute<(_Np / 2 + _Is)..., (
int(_Zeros * 0) - 1)...>(
1817 template <
typename _Tp,
typename _BinaryOperation>
1818 _GLIBCXX_SIMD_INTRINSIC
static constexpr _Tp
1819 _S_reduce(simd<_Tp, _Abi> __x, _BinaryOperation&& __binary_op)
1821 constexpr
size_t _Np = simd_size_v<_Tp, _Abi>;
1822 if constexpr (_Np == 1)
1824 else if constexpr (_Np == 2)
1825 return __binary_op(simd<_Tp, simd_abi::scalar>(__x[0]),
1826 simd<_Tp, simd_abi::scalar>(__x[1]))[0];
1827 else if constexpr (_Abi::template _S_is_partial<_Tp>)
1829 [[maybe_unused]] constexpr
auto __full_size
1830 = _Abi::template _S_full_size<_Tp>;
1831 if constexpr (_Np == 3)
1833 __binary_op(simd<_Tp, simd_abi::scalar>(__x[0]),
1834 simd<_Tp, simd_abi::scalar>(__x[1])),
1835 simd<_Tp, simd_abi::scalar>(__x[2]))[0];
1836 else if constexpr (is_same_v<__remove_cvref_t<_BinaryOperation>,
1839 using _Ap = simd_abi::deduce_t<_Tp, __full_size>;
1840 return _Ap::_SimdImpl::_S_reduce(
1841 simd<_Tp, _Ap>(__private_init,
1842 _Abi::_S_masked(__as_vector(__x))),
1845 else if constexpr (is_same_v<__remove_cvref_t<_BinaryOperation>,
1848 using _Ap = simd_abi::deduce_t<_Tp, __full_size>;
1849 using _TW = _SimdWrapper<_Tp, __full_size>;
1850 _GLIBCXX_SIMD_USE_CONSTEXPR
auto __implicit_mask_full
1851 = _Abi::template _S_implicit_mask<_Tp>().__as_full_vector();
1852 _GLIBCXX_SIMD_USE_CONSTEXPR _TW __one
1853 = __vector_broadcast<__full_size>(_Tp(1));
1854 const _TW __x_full = __data(__x).__as_full_vector();
1855 const _TW __x_padded_with_ones
1856 = _Ap::_CommonImpl::_S_blend(__implicit_mask_full, __one,
1858 return _Ap::_SimdImpl::_S_reduce(
1859 simd<_Tp, _Ap>(__private_init, __x_padded_with_ones),
1862 else if constexpr (_Np & 1)
1864 using _Ap = simd_abi::deduce_t<_Tp, _Np - 1>;
1866 simd<_Tp, simd_abi::scalar>(_Ap::_SimdImpl::_S_reduce(
1868 __intrin_bitcast<__vector_type_t<_Tp, _Np - 1>>(
1871 simd<_Tp, simd_abi::scalar>(__x[_Np - 1]))[0];
1874 return _S_reduce_partial<_Np>(
1875 make_index_sequence<_Np / 2>(),
1876 make_index_sequence<__full_size - _Np / 2>(), __x, __binary_op);
1878 else if constexpr (
sizeof(__x) == 16)
1880 if constexpr (_Np == 16)
1882 const auto __y = __data(__x);
1884 _M_make_simd<_Tp, _Np>(
1885 __vector_permute<0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
1887 _M_make_simd<_Tp, _Np>(
1888 __vector_permute<8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
1889 14, 14, 15, 15>(__y)));
1891 if constexpr (_Np >= 8)
1893 const auto __y = __vector_bitcast<short>(__data(__x));
1895 _M_make_simd<_Tp, _Np>(__vector_bitcast<_Tp>(
1896 __vector_permute<0, 0, 1, 1, 2, 2, 3, 3>(__y))),
1897 _M_make_simd<_Tp, _Np>(__vector_bitcast<_Tp>(
1898 __vector_permute<4, 4, 5, 5, 6, 6, 7, 7>(__y))));
1900 if constexpr (_Np >= 4)
1902 using _Up = conditional_t<is_floating_point_v<_Tp>, float,
int>;
1903 const auto __y = __vector_bitcast<_Up>(__data(__x));
1904 __x = __binary_op(__x,
1905 _M_make_simd<_Tp, _Np>(__vector_bitcast<_Tp>(
1906 __vector_permute<3, 2, 1, 0>(__y))));
1908 using _Up = conditional_t<is_floating_point_v<_Tp>, double, _LLong>;
1909 const auto __y = __vector_bitcast<_Up>(__data(__x));
1910 __x = __binary_op(__x, _M_make_simd<_Tp, _Np>(__vector_bitcast<_Tp>(
1911 __vector_permute<1, 1>(__y))));
1916 static_assert(
sizeof(__x) > __min_vector_size<_Tp>);
1917 static_assert((_Np & (_Np - 1)) == 0);
1918 using _Ap = simd_abi::deduce_t<_Tp, _Np / 2>;
1919 using _V = simd<_Tp, _Ap>;
1920 return _Ap::_SimdImpl::_S_reduce(
1921 __binary_op(_V(__private_init, __extract<0, 2>(__as_vector(__x))),
1923 __extract<1, 2>(__as_vector(__x)))),
1924 static_cast<_BinaryOperation&&
>(__binary_op));
1930 #define _GLIBCXX_SIMD_MATH_FALLBACK(__name) \
1931 template <typename _Tp, typename... _More> \
1932 static _Tp _S_##__name(const _Tp& __x, const _More&... __more) \
1934 return __generate_vector<_Tp>( \
1935 [&](auto __i) { return __name(__x[__i], __more[__i]...); }); \
1938 #define _GLIBCXX_SIMD_MATH_FALLBACK_MASKRET(__name) \
1939 template <typename _Tp, typename... _More> \
1940 static typename _Tp::mask_type _S_##__name(const _Tp& __x, \
1941 const _More&... __more) \
1943 return __generate_vector<_Tp>( \
1944 [&](auto __i) { return __name(__x[__i], __more[__i]...); }); \
1947 #define _GLIBCXX_SIMD_MATH_FALLBACK_FIXEDRET(_RetTp, __name) \
1948 template <typename _Tp, typename... _More> \
1949 static auto _S_##__name(const _Tp& __x, const _More&... __more) \
1951 return __fixed_size_storage_t<_RetTp, \
1952 _VectorTraits<_Tp>::_S_partial_width>:: \
1953 _S_generate([&](auto __meta) constexpr { \
1954 return __meta._S_generator( \
1956 return __name(__x[__meta._S_offset + __i], \
1957 __more[__meta._S_offset + __i]...); \
1959 static_cast<_RetTp*>(nullptr)); \
1963 _GLIBCXX_SIMD_MATH_FALLBACK(
acos)
1964 _GLIBCXX_SIMD_MATH_FALLBACK(
asin)
1965 _GLIBCXX_SIMD_MATH_FALLBACK(
atan)
1966 _GLIBCXX_SIMD_MATH_FALLBACK(atan2)
1967 _GLIBCXX_SIMD_MATH_FALLBACK(
cos)
1968 _GLIBCXX_SIMD_MATH_FALLBACK(
sin)
1969 _GLIBCXX_SIMD_MATH_FALLBACK(
tan)
1970 _GLIBCXX_SIMD_MATH_FALLBACK(
acosh)
1971 _GLIBCXX_SIMD_MATH_FALLBACK(
asinh)
1972 _GLIBCXX_SIMD_MATH_FALLBACK(
atanh)
1973 _GLIBCXX_SIMD_MATH_FALLBACK(
cosh)
1974 _GLIBCXX_SIMD_MATH_FALLBACK(
sinh)
1975 _GLIBCXX_SIMD_MATH_FALLBACK(
tanh)
1976 _GLIBCXX_SIMD_MATH_FALLBACK(
exp)
1977 _GLIBCXX_SIMD_MATH_FALLBACK(exp2)
1978 _GLIBCXX_SIMD_MATH_FALLBACK(expm1)
1979 _GLIBCXX_SIMD_MATH_FALLBACK(ldexp)
1980 _GLIBCXX_SIMD_MATH_FALLBACK_FIXEDRET(
int, ilogb)
1981 _GLIBCXX_SIMD_MATH_FALLBACK(
log)
1982 _GLIBCXX_SIMD_MATH_FALLBACK(
log10)
1983 _GLIBCXX_SIMD_MATH_FALLBACK(log1p)
1984 _GLIBCXX_SIMD_MATH_FALLBACK(log2)
1985 _GLIBCXX_SIMD_MATH_FALLBACK(logb)
1988 _GLIBCXX_SIMD_MATH_FALLBACK(scalbn)
1989 _GLIBCXX_SIMD_MATH_FALLBACK(scalbln)
1990 _GLIBCXX_SIMD_MATH_FALLBACK(cbrt)
1991 _GLIBCXX_SIMD_MATH_FALLBACK(
fabs)
1992 _GLIBCXX_SIMD_MATH_FALLBACK(
pow)
1993 _GLIBCXX_SIMD_MATH_FALLBACK(
sqrt)
1994 _GLIBCXX_SIMD_MATH_FALLBACK(erf)
1995 _GLIBCXX_SIMD_MATH_FALLBACK(erfc)
1996 _GLIBCXX_SIMD_MATH_FALLBACK(lgamma)
1997 _GLIBCXX_SIMD_MATH_FALLBACK(tgamma)
1999 _GLIBCXX_SIMD_MATH_FALLBACK_FIXEDRET(
long, lrint)
2000 _GLIBCXX_SIMD_MATH_FALLBACK_FIXEDRET(
long long, llrint)
2002 _GLIBCXX_SIMD_MATH_FALLBACK_FIXEDRET(
long, lround)
2003 _GLIBCXX_SIMD_MATH_FALLBACK_FIXEDRET(
long long, llround)
2005 _GLIBCXX_SIMD_MATH_FALLBACK(fmod)
2006 _GLIBCXX_SIMD_MATH_FALLBACK(remainder)
2008 template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2010 _S_remquo(
const _Tp __x,
const _Tp __y,
2011 __fixed_size_storage_t<int, _TVT::_S_partial_width>* __z)
2013 return __generate_vector<_Tp>([&](
auto __i) {
2015 auto __r = remquo(__x[__i], __y[__i], &__tmp);
2016 __z->_M_set(__i, __tmp);
2022 _GLIBCXX_SIMD_MATH_FALLBACK(nextafter)
2023 _GLIBCXX_SIMD_MATH_FALLBACK(fdim)
2024 _GLIBCXX_SIMD_MATH_FALLBACK(fmax)
2025 _GLIBCXX_SIMD_MATH_FALLBACK(fmin)
2026 _GLIBCXX_SIMD_MATH_FALLBACK(fma)
2028 template <
typename _Tp,
size_t _Np>
2029 static constexpr _MaskMember<_Tp>
2030 _S_isgreater(_SimdWrapper<_Tp, _Np> __x,
2031 _SimdWrapper<_Tp, _Np> __y) noexcept
2033 using _Ip = __int_for_sizeof_t<_Tp>;
2034 const auto __xn = __vector_bitcast<_Ip>(__x);
2035 const auto __yn = __vector_bitcast<_Ip>(__y);
2036 const auto __xp = __xn < 0 ? -(__xn & __finite_max_v<_Ip>) : __xn;
2037 const auto __yp = __yn < 0 ? -(__yn & __finite_max_v<_Ip>) : __yn;
2038 return __andnot(_SuperImpl::_S_isunordered(__x, __y)._M_data,
2042 template <
typename _Tp,
size_t _Np>
2043 static constexpr _MaskMember<_Tp>
2044 _S_isgreaterequal(_SimdWrapper<_Tp, _Np> __x,
2045 _SimdWrapper<_Tp, _Np> __y) noexcept
2047 using _Ip = __int_for_sizeof_t<_Tp>;
2048 const auto __xn = __vector_bitcast<_Ip>(__x);
2049 const auto __yn = __vector_bitcast<_Ip>(__y);
2050 const auto __xp = __xn < 0 ? -(__xn & __finite_max_v<_Ip>) : __xn;
2051 const auto __yp = __yn < 0 ? -(__yn & __finite_max_v<_Ip>) : __yn;
2052 return __andnot(_SuperImpl::_S_isunordered(__x, __y)._M_data,
2056 template <
typename _Tp,
size_t _Np>
2057 static constexpr _MaskMember<_Tp>
2058 _S_isless(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y) noexcept
2060 using _Ip = __int_for_sizeof_t<_Tp>;
2061 const auto __xn = __vector_bitcast<_Ip>(__x);
2062 const auto __yn = __vector_bitcast<_Ip>(__y);
2063 const auto __xp = __xn < 0 ? -(__xn & __finite_max_v<_Ip>) : __xn;
2064 const auto __yp = __yn < 0 ? -(__yn & __finite_max_v<_Ip>) : __yn;
2065 return __andnot(_SuperImpl::_S_isunordered(__x, __y)._M_data,
2069 template <
typename _Tp,
size_t _Np>
2070 static constexpr _MaskMember<_Tp>
2071 _S_islessequal(_SimdWrapper<_Tp, _Np> __x,
2072 _SimdWrapper<_Tp, _Np> __y) noexcept
2074 using _Ip = __int_for_sizeof_t<_Tp>;
2075 const auto __xn = __vector_bitcast<_Ip>(__x);
2076 const auto __yn = __vector_bitcast<_Ip>(__y);
2077 const auto __xp = __xn < 0 ? -(__xn & __finite_max_v<_Ip>) : __xn;
2078 const auto __yp = __yn < 0 ? -(__yn & __finite_max_v<_Ip>) : __yn;
2079 return __andnot(_SuperImpl::_S_isunordered(__x, __y)._M_data,
2083 template <
typename _Tp,
size_t _Np>
2084 static constexpr _MaskMember<_Tp>
2085 _S_islessgreater(_SimdWrapper<_Tp, _Np> __x,
2086 _SimdWrapper<_Tp, _Np> __y) noexcept
2088 return __andnot(_SuperImpl::_S_isunordered(__x, __y),
2089 _SuperImpl::_S_not_equal_to(__x, __y));
2092 #undef _GLIBCXX_SIMD_MATH_FALLBACK
2093 #undef _GLIBCXX_SIMD_MATH_FALLBACK_MASKRET
2094 #undef _GLIBCXX_SIMD_MATH_FALLBACK_FIXEDRET
2096 template <
typename _Tp,
size_t _Np>
2097 _GLIBCXX_SIMD_INTRINSIC
static _SimdWrapper<_Tp, _Np>
2098 _S_abs(_SimdWrapper<_Tp, _Np> __x) noexcept
2104 if constexpr (is_floating_point_v<_Tp>)
2109 return __and(_S_absmask<__vector_type_t<_Tp, _Np>>, __x._M_data);
2111 return __x._M_data < 0 ? -__x._M_data : __x._M_data;
2119 template <
typename _TV,
typename _UV>
2120 _GLIBCXX_SIMD_INTRINSIC
static constexpr _TV _S_plus_minus(_TV __x,
2123 #if defined __i386__ && !defined __SSE_MATH__
2124 if constexpr (
sizeof(__x) == 8)
2126 static_assert(is_same_v<_TV, __vector_type_t<float, 2>>);
2127 const auto __x4 = __vector_bitcast<float, 4>(__x);
2128 if constexpr (is_same_v<_TV, _UV>)
2129 return __vector_bitcast<float, 2>(
2130 _S_plus_minus(__x4, __vector_bitcast<float, 4>(__y)));
2132 return __vector_bitcast<float, 2>(_S_plus_minus(__x4, __y));
2135 #if !defined __clang__ && __GCC_IEC_559 == 0
2136 if (__builtin_is_constant_evaluated()
2137 || (__builtin_constant_p(__x) && __builtin_constant_p(__y)))
2138 return (__x + __y) - __y;
2142 if constexpr(__have_sse)
2144 if constexpr (
sizeof(__x) >= 16)
2145 asm("" : "+x"(__x));
2146 else if constexpr (is_same_v<__vector_type_t<
float, 2>, _TV>)
2147 asm("" : "+x"(__x[0]), "+x"(__x[1]));
2149 __assert_unreachable<_TV>();
2151 else if constexpr(__have_neon)
2152 asm("" : "+w"(__x));
2153 else if constexpr (__have_power_vmx)
2155 if constexpr (is_same_v<__vector_type_t<float, 2>, _TV>)
2156 asm("" : "+fgr"(__x[0]), "+fgr"(__x[1]));
2158 asm("" : "+v"(__x));
2161 asm("" : "+g"(__x));
2165 return (__x + __y) - __y;
2171 template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2172 _GLIBCXX_SIMD_INTRINSIC
static _Tp _S_nearbyint(_Tp __x_) noexcept
2174 using value_type =
typename _TVT::value_type;
2175 using _V =
typename _TVT::type;
2176 const _V __x = __x_;
2177 const _V __absx = __and(__x, _S_absmask<_V>);
2178 static_assert(__CHAR_BIT__ *
sizeof(1ull) >= __digits_v<value_type>);
2179 _GLIBCXX_SIMD_USE_CONSTEXPR _V __shifter_abs
2180 = _V() + (1ull << (__digits_v<value_type> - 1));
2181 const _V __shifter = __or(__and(_S_signmask<_V>, __x), __shifter_abs);
2182 const _V __shifted = _S_plus_minus(__x, __shifter);
2183 return __absx < __shifter_abs ? __shifted : __x;
2187 template <
typename _Tp,
typename _TVT = _VectorTraits<_Tp>>
2188 _GLIBCXX_SIMD_INTRINSIC
static _Tp _S_rint(_Tp __x) noexcept
2190 return _SuperImpl::_S_nearbyint(__x);
2194 template <
typename _Tp,
size_t _Np>
2195 _GLIBCXX_SIMD_INTRINSIC
static _SimdWrapper<_Tp, _Np>
2196 _S_trunc(_SimdWrapper<_Tp, _Np> __x)
2198 using _V = __vector_type_t<_Tp, _Np>;
2199 const _V __absx = __and(__x._M_data, _S_absmask<_V>);
2200 static_assert(__CHAR_BIT__ *
sizeof(1ull) >= __digits_v<_Tp>);
2201 constexpr _Tp __shifter = 1ull << (__digits_v<_Tp> - 1);
2202 _V __truncated = _S_plus_minus(__absx, __shifter);
2203 __truncated -= __truncated > __absx ? _V() + 1 : _V();
2204 return __absx < __shifter ? __or(__xor(__absx, __x._M_data), __truncated)
2209 template <
typename _Tp,
size_t _Np>
2210 _GLIBCXX_SIMD_INTRINSIC
static _SimdWrapper<_Tp, _Np>
2211 _S_round(_SimdWrapper<_Tp, _Np> __x)
2213 const auto __abs_x = _SuperImpl::_S_abs(__x);
2214 const auto __t_abs = _SuperImpl::_S_trunc(__abs_x)._M_data;
2216 = __t_abs + (__abs_x._M_data - __t_abs >= _Tp(.5) ? _Tp(1) : 0);
2217 return __or(__xor(__abs_x._M_data, __x._M_data), __r_abs);
2221 template <
typename _Tp,
size_t _Np>
2222 _GLIBCXX_SIMD_INTRINSIC
static _SimdWrapper<_Tp, _Np>
2223 _S_floor(_SimdWrapper<_Tp, _Np> __x)
2225 const auto __y = _SuperImpl::_S_trunc(__x)._M_data;
2226 const auto __negative_input
2227 = __vector_bitcast<_Tp>(__x._M_data < __vector_broadcast<_Np, _Tp>(0));
2229 = __andnot(__vector_bitcast<_Tp>(__y == __x._M_data), __negative_input);
2230 return __or(__andnot(__mask, __y),
2231 __and(__mask, __y - __vector_broadcast<_Np, _Tp>(1)));
2235 template <
typename _Tp,
size_t _Np>
2236 _GLIBCXX_SIMD_INTRINSIC
static _SimdWrapper<_Tp, _Np>
2237 _S_ceil(_SimdWrapper<_Tp, _Np> __x)
2239 const auto __y = _SuperImpl::_S_trunc(__x)._M_data;
2240 const auto __negative_input
2241 = __vector_bitcast<_Tp>(__x._M_data < __vector_broadcast<_Np, _Tp>(0));
2242 const auto __inv_mask
2243 = __or(__vector_bitcast<_Tp>(__y == __x._M_data), __negative_input);
2244 return __or(__and(__inv_mask, __y),
2245 __andnot(__inv_mask, __y + __vector_broadcast<_Np, _Tp>(1)));
2249 template <
typename _Tp,
size_t _Np>
2250 _GLIBCXX_SIMD_INTRINSIC
static _MaskMember<_Tp>
2251 _S_isnan([[maybe_unused]] _SimdWrapper<_Tp, _Np> __x)
2253 #if __FINITE_MATH_ONLY__
2255 #elif !defined __SUPPORT_SNAN__
2256 return ~(__x._M_data == __x._M_data);
2257 #elif defined __STDC_IEC_559__
2258 using _Ip = __int_for_sizeof_t<_Tp>;
2259 const auto __absn = __vector_bitcast<_Ip>(_SuperImpl::_S_abs(__x));
2261 = __vector_bitcast<_Ip>(__vector_broadcast<_Np>(__infinity_v<_Tp>));
2262 return __infn < __absn;
2264 #error "Not implemented: how to support SNaN but non-IEC559 floating-point?"
2269 template <
typename _Tp,
size_t _Np>
2270 _GLIBCXX_SIMD_INTRINSIC
static _MaskMember<_Tp>
2271 _S_isfinite([[maybe_unused]] _SimdWrapper<_Tp, _Np> __x)
2273 #if __FINITE_MATH_ONLY__
2274 using _UV =
typename _MaskMember<_Tp>::_BuiltinType;
2275 _GLIBCXX_SIMD_USE_CONSTEXPR _UV __alltrue = ~_UV();
2279 using _Ip = __int_for_sizeof_t<_Tp>;
2280 const auto __absn = __vector_bitcast<_Ip>(_SuperImpl::_S_abs(__x));
2282 = __vector_bitcast<_Ip>(__vector_broadcast<_Np>(__finite_max_v<_Tp>));
2283 return __absn <= __maxn;
2288 template <
typename _Tp,
size_t _Np>
2289 _GLIBCXX_SIMD_INTRINSIC
static _MaskMember<_Tp>
2290 _S_isunordered(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
2292 return __or(_S_isnan(__x), _S_isnan(__y));
2296 template <
typename _Tp,
size_t _Np>
2297 _GLIBCXX_SIMD_INTRINSIC
static _MaskMember<_Tp>
2298 _S_signbit(_SimdWrapper<_Tp, _Np> __x)
2300 using _Ip = __int_for_sizeof_t<_Tp>;
2301 return __vector_bitcast<_Ip>(__x) < 0;
2308 template <
typename _Tp,
size_t _Np>
2309 _GLIBCXX_SIMD_INTRINSIC
static _MaskMember<_Tp>
2310 _S_isinf([[maybe_unused]] _SimdWrapper<_Tp, _Np> __x)
2312 #if __FINITE_MATH_ONLY__
2315 return _SuperImpl::template _S_equal_to<_Tp, _Np>(_SuperImpl::_S_abs(__x),
2316 __vector_broadcast<_Np>(
2317 __infinity_v<_Tp>));
2332 template <
typename _Tp,
size_t _Np>
2333 _GLIBCXX_SIMD_INTRINSIC
static _MaskMember<_Tp>
2334 _S_isnormal(_SimdWrapper<_Tp, _Np> __x)
2336 using _Ip = __int_for_sizeof_t<_Tp>;
2337 const auto __absn = __vector_bitcast<_Ip>(_SuperImpl::_S_abs(__x));
2339 = __vector_bitcast<_Ip>(__vector_broadcast<_Np>(__norm_min_v<_Tp>));
2340 #if __FINITE_MATH_ONLY__
2341 return __absn >= __minn;
2344 = __vector_bitcast<_Ip>(__vector_broadcast<_Np>(__finite_max_v<_Tp>));
2345 return __minn <= __absn && __absn <= __maxn;
2350 template <
typename _Tp,
size_t _Np>
2351 _GLIBCXX_SIMD_INTRINSIC
static __fixed_size_storage_t<int, _Np>
2352 _S_fpclassify(_SimdWrapper<_Tp, _Np> __x)
2354 using _I = __int_for_sizeof_t<_Tp>;
2356 = __vector_bitcast<_I>(__to_intrin(_SuperImpl::_S_abs(__x)));
2357 constexpr
size_t _NI =
sizeof(__xn) /
sizeof(_I);
2358 _GLIBCXX_SIMD_USE_CONSTEXPR
auto __minn
2359 = __vector_bitcast<_I>(__vector_broadcast<_NI>(__norm_min_v<_Tp>));
2360 _GLIBCXX_SIMD_USE_CONSTEXPR
auto __infn
2361 = __vector_bitcast<_I>(__vector_broadcast<_NI>(__infinity_v<_Tp>));
2363 _GLIBCXX_SIMD_USE_CONSTEXPR
auto __fp_normal
2364 = __vector_broadcast<_NI, _I>(FP_NORMAL);
2365 #if !__FINITE_MATH_ONLY__
2366 _GLIBCXX_SIMD_USE_CONSTEXPR
auto __fp_nan
2367 = __vector_broadcast<_NI, _I>(FP_NAN);
2368 _GLIBCXX_SIMD_USE_CONSTEXPR
auto __fp_infinite
2369 = __vector_broadcast<_NI, _I>(FP_INFINITE);
2371 #ifndef __FAST_MATH__
2372 _GLIBCXX_SIMD_USE_CONSTEXPR
auto __fp_subnormal
2373 = __vector_broadcast<_NI, _I>(FP_SUBNORMAL);
2375 _GLIBCXX_SIMD_USE_CONSTEXPR
auto __fp_zero
2376 = __vector_broadcast<_NI, _I>(FP_ZERO);
2378 __vector_type_t<_I, _NI>
2379 __tmp = __xn < __minn
2380 #ifdef __FAST_MATH__
2383 ? (__xn == 0 ? __fp_zero : __fp_subnormal)
2385 #
if __FINITE_MATH_ONLY__
2388 : (__xn < __infn ? __fp_normal
2389 : (__xn == __infn ? __fp_infinite : __fp_nan));
2392 if constexpr (
sizeof(_I) ==
sizeof(
int))
2394 using _FixedInt = __fixed_size_storage_t<int, _Np>;
2395 const auto __as_int = __vector_bitcast<int, _Np>(__tmp);
2396 if constexpr (_FixedInt::_S_tuple_size == 1)
2398 else if constexpr (_FixedInt::_S_tuple_size == 2
2400 typename _FixedInt::_SecondType::_FirstAbi,
2402 return {__extract<0, 2>(__as_int), __as_int[_Np - 1]};
2403 else if constexpr (_FixedInt::_S_tuple_size == 2)
2404 return {__extract<0, 2>(__as_int),
2405 __auto_bitcast(__extract<1, 2>(__as_int))};
2407 __assert_unreachable<_Tp>();
2409 else if constexpr (_Np == 2 &&
sizeof(_I) == 8
2410 && __fixed_size_storage_t<int, _Np>::_S_tuple_size == 2)
2412 const auto __aslong = __vector_bitcast<_LLong>(__tmp);
2413 return {int(__aslong[0]), {int(__aslong[1])}};
2415 #if _GLIBCXX_SIMD_X86INTRIN
2416 else if constexpr (
sizeof(_Tp) == 8 &&
sizeof(__tmp) == 32
2417 && __fixed_size_storage_t<int, _Np>::_S_tuple_size == 1)
2418 return {_mm_packs_epi32(__to_intrin(__lo128(__tmp)),
2419 __to_intrin(__hi128(__tmp)))};
2420 else if constexpr (
sizeof(_Tp) == 8 &&
sizeof(__tmp) == 64
2421 && __fixed_size_storage_t<int, _Np>::_S_tuple_size == 1)
2422 return {_mm512_cvtepi64_epi32(__to_intrin(__tmp))};
2424 else if constexpr (__fixed_size_storage_t<int, _Np>::_S_tuple_size == 1)
2425 return {__call_with_subscripts<_Np>(__vector_bitcast<_LLong>(__tmp),
2427 return __make_wrapper<int>(__l...);
2430 __assert_unreachable<_Tp>();
2434 template <
typename _Tp,
size_t _Np>
2435 _GLIBCXX_SIMD_INTRINSIC
static void
2436 _S_increment(_SimdWrapper<_Tp, _Np>& __x)
2437 { __x = __x._M_data + 1; }
2439 template <
typename _Tp,
size_t _Np>
2440 _GLIBCXX_SIMD_INTRINSIC
static void
2441 _S_decrement(_SimdWrapper<_Tp, _Np>& __x)
2442 { __x = __x._M_data - 1; }
2445 template <
typename _Tp,
size_t _Np,
typename _Up>
2446 _GLIBCXX_SIMD_INTRINSIC constexpr
static void
2447 _S_set(_SimdWrapper<_Tp, _Np>& __v,
int __i, _Up&& __x) noexcept
2448 { __v._M_set(__i,
static_cast<_Up&&
>(__x)); }
2451 template <
typename _Tp,
typename _K,
size_t _Np>
2452 _GLIBCXX_SIMD_INTRINSIC
static void
2453 _S_masked_assign(_SimdWrapper<_K, _Np> __k, _SimdWrapper<_Tp, _Np>& __lhs,
2454 __type_identity_t<_SimdWrapper<_Tp, _Np>> __rhs)
2456 if (__k._M_is_constprop_none_of())
2458 else if (__k._M_is_constprop_all_of())
2461 __lhs = _CommonImpl::_S_blend(__k, __lhs, __rhs);
2464 template <
typename _Tp,
typename _K,
size_t _Np>
2465 _GLIBCXX_SIMD_INTRINSIC
static void
2466 _S_masked_assign(_SimdWrapper<_K, _Np> __k, _SimdWrapper<_Tp, _Np>& __lhs,
2467 __type_identity_t<_Tp> __rhs)
2469 if (__k._M_is_constprop_none_of())
2471 else if (__k._M_is_constprop_all_of())
2472 __lhs = __vector_broadcast<_Np>(__rhs);
2473 else if (__builtin_constant_p(__rhs) && __rhs == 0)
2475 if constexpr (!is_same_v<bool, _K>)
2479 = __andnot(__vector_bitcast<_Tp>(__k), __lhs._M_data);
2483 = _CommonImpl::_S_blend(__k, __lhs, _SimdWrapper<_Tp, _Np>());
2486 __lhs = _CommonImpl::_S_blend(__k, __lhs,
2487 _SimdWrapper<_Tp, _Np>(
2488 __vector_broadcast<_Np>(__rhs)));
2492 template <
typename _Op,
typename _Tp,
typename _K,
size_t _Np>
2493 _GLIBCXX_SIMD_INTRINSIC
static void
2494 _S_masked_cassign(
const _SimdWrapper<_K, _Np> __k,
2495 _SimdWrapper<_Tp, _Np>& __lhs,
2496 const __type_identity_t<_SimdWrapper<_Tp, _Np>> __rhs,
2499 if (__k._M_is_constprop_none_of())
2501 else if (__k._M_is_constprop_all_of())
2502 __lhs = __op(_SuperImpl{}, __lhs, __rhs);
2504 __lhs = _CommonImpl::_S_blend(__k, __lhs,
2505 __op(_SuperImpl{}, __lhs, __rhs));
2508 template <
typename _Op,
typename _Tp,
typename _K,
size_t _Np>
2509 _GLIBCXX_SIMD_INTRINSIC
static void
2510 _S_masked_cassign(
const _SimdWrapper<_K, _Np> __k,
2511 _SimdWrapper<_Tp, _Np>& __lhs,
2512 const __type_identity_t<_Tp> __rhs, _Op __op)
2513 { _S_masked_cassign(__k, __lhs, __vector_broadcast<_Np>(__rhs), __op); }
2516 template <
template <
typename>
class _Op,
typename _Tp,
typename _K,
2518 _GLIBCXX_SIMD_INTRINSIC
static _SimdWrapper<_Tp, _Np>
2519 _S_masked_unary(
const _SimdWrapper<_K, _Np> __k,
2520 const _SimdWrapper<_Tp, _Np> __v)
2522 if (__k._M_is_constprop_none_of())
2524 auto __vv = _M_make_simd(__v);
2525 _Op<decltype(__vv)> __op;
2526 if (__k._M_is_constprop_all_of())
2527 return __data(__op(__vv));
2529 return _CommonImpl::_S_blend(__k, __v, __data(__op(__vv)));
2536 struct _MaskImplBuiltinMixin
2538 template <
typename _Tp>
2539 using _TypeTag = _Tp*;
2542 template <
typename _Up,
size_t _ToN = 1>
2543 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Up, _ToN>
2544 _S_to_maskvector(
bool __x)
2546 static_assert(is_same_v<_Up, __int_for_sizeof_t<_Up>>);
2547 return __x ? __vector_type_t<_Up, _ToN>{~_Up()}
2548 : __vector_type_t<_Up, _ToN>{};
2551 template <
typename _Up,
size_t _UpN = 0,
size_t _Np,
bool _Sanitized,
2552 size_t _ToN = _UpN == 0 ? _Np : _UpN>
2553 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Up, _ToN>
2554 _S_to_maskvector(_BitMask<_Np, _Sanitized> __x)
2556 static_assert(is_same_v<_Up, __int_for_sizeof_t<_Up>>);
2557 return __generate_vector<__vector_type_t<_Up, _ToN>>([&](
2558 auto __i) constexpr {
2559 if constexpr (__i < _Np)
2560 return __x[__i] ? ~_Up() : _Up();
2566 template <
typename _Up,
size_t _UpN = 0,
typename _Tp,
size_t _Np,
2567 size_t _ToN = _UpN == 0 ? _Np : _UpN>
2568 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Up, _ToN>
2569 _S_to_maskvector(_SimdWrapper<_Tp, _Np> __x)
2571 static_assert(is_same_v<_Up, __int_for_sizeof_t<_Up>>);
2572 using _TW = _SimdWrapper<_Tp, _Np>;
2573 using _UW = _SimdWrapper<_Up, _ToN>;
2574 if constexpr (
sizeof(_Up) ==
sizeof(_Tp) &&
sizeof(_TW) ==
sizeof(_UW))
2575 return __wrapper_bitcast<_Up, _ToN>(__x);
2576 else if constexpr (is_same_v<_Tp, bool>)
2577 return _S_to_maskvector<_Up, _ToN>(_BitMask<_Np>(__x._M_data));
2604 return __generate_vector<__vector_type_t<_Up, _ToN>>([&](
2605 auto __i) constexpr {
2606 if constexpr (__i < _Np)
2607 return _Up(__x[__i.value]);
2617 template <
typename _Tp,
size_t _Np>
2618 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SanitizedBitMask<_Np>
2619 _S_to_bits(_SimdWrapper<_Tp, _Np> __x)
2621 static_assert(!is_same_v<_Tp, bool>);
2622 static_assert(_Np <= __CHAR_BIT__ *
sizeof(_ULLong));
2623 using _Up = make_unsigned_t<__int_for_sizeof_t<_Tp>>;
2625 = __vector_bitcast<_Up>(__x) >> (
sizeof(_Up) * __CHAR_BIT__ - 1);
2627 __execute_n_times<_Np>(
2628 [&](
auto __i) { __r |= _ULLong(__bools[__i.value]) << __i; });
2636 template <
typename _Abi,
typename>
2637 struct _MaskImplBuiltin : _MaskImplBuiltinMixin
2639 using _MaskImplBuiltinMixin::_S_to_bits;
2640 using _MaskImplBuiltinMixin::_S_to_maskvector;
2643 template <
typename _Tp>
2644 using _SimdMember =
typename _Abi::template __traits<_Tp>::_SimdMember;
2646 template <
typename _Tp>
2647 using _MaskMember =
typename _Abi::template _MaskMember<_Tp>;
2649 using _SuperImpl =
typename _Abi::_MaskImpl;
2650 using _CommonImpl =
typename _Abi::_CommonImpl;
2652 template <
typename _Tp>
2653 static constexpr
size_t _S_size = simd_size_v<_Tp, _Abi>;
2657 template <
typename _Tp>
2658 _GLIBCXX_SIMD_INTRINSIC
static constexpr _MaskMember<_Tp>
2659 _S_broadcast(
bool __x)
2661 return __x ? _Abi::template _S_implicit_mask<_Tp>()
2662 : _MaskMember<_Tp>();
2667 template <
typename _Tp>
2668 _GLIBCXX_SIMD_INTRINSIC
static constexpr _MaskMember<_Tp>
2669 _S_load(
const bool* __mem)
2671 using _I = __int_for_sizeof_t<_Tp>;
2672 if constexpr (
sizeof(_Tp) ==
sizeof(
bool))
2675 = _CommonImpl::template _S_load<_I, _S_size<_Tp>>(__mem);
2680 return __generate_vector<_I, _S_size<_Tp>>([&](
auto __i) constexpr {
2681 return __mem[__i] ? ~_I() : _I();
2687 template <
typename _Tp,
size_t _Np,
bool _Sanitized>
2688 _GLIBCXX_SIMD_INTRINSIC
static constexpr
auto
2689 _S_convert(_BitMask<_Np, _Sanitized> __x)
2691 if constexpr (__is_builtin_bitmask_abi<_Abi>())
2692 return _SimdWrapper<
bool, simd_size_v<_Tp, _Abi>>(__x._M_to_bits());
2694 return _SuperImpl::template _S_to_maskvector<__int_for_sizeof_t<_Tp>,
2696 __x._M_sanitized());
2699 template <typename _Tp,
size_t _Np>
2700 _GLIBCXX_SIMD_INTRINSIC static constexpr auto
2701 _S_convert(_SimdWrapper<
bool, _Np> __x)
2703 if constexpr (__is_builtin_bitmask_abi<_Abi>())
2704 return _SimdWrapper<
bool, simd_size_v<_Tp, _Abi>>(__x._M_data);
2706 return _SuperImpl::template _S_to_maskvector<__int_for_sizeof_t<_Tp>,
2708 _BitMask<_Np>(__x._M_data)._M_sanitized());
2711 template <typename _Tp, typename _Up,
size_t _Np>
2712 _GLIBCXX_SIMD_INTRINSIC static constexpr auto
2713 _S_convert(_SimdWrapper<_Up, _Np> __x)
2715 if constexpr (__is_builtin_bitmask_abi<_Abi>())
2716 return _SimdWrapper<
bool, simd_size_v<_Tp, _Abi>>(
2717 _SuperImpl::_S_to_bits(__x));
2719 return _SuperImpl::template _S_to_maskvector<__int_for_sizeof_t<_Tp>,
2723 template <typename _Tp, typename _Up, typename _UAbi>
2724 _GLIBCXX_SIMD_INTRINSIC static constexpr auto
2725 _S_convert(simd_mask<_Up, _UAbi> __x)
2727 if constexpr (__is_builtin_bitmask_abi<_Abi>())
2729 using _R = _SimdWrapper<bool, simd_size_v<_Tp, _Abi>>;
2730 if constexpr (__is_builtin_bitmask_abi<_UAbi>())
2731 return _R(__data(__x));
2732 else if constexpr (__is_scalar_abi<_UAbi>())
2733 return _R(__data(__x));
2734 else if constexpr (__is_fixed_size_abi_v<_UAbi>)
2735 return _R(__data(__x)._M_to_bits());
2737 return _R(_UAbi::_MaskImpl::_S_to_bits(__data(__x))._M_to_bits());
2740 return _SuperImpl::template _S_to_maskvector<__int_for_sizeof_t<_Tp>,
2747 template <typename _Tp,
size_t _Np>
2748 static inline _SimdWrapper<_Tp, _Np>
2749 _S_masked_load(_SimdWrapper<_Tp, _Np> __merge,
2750 _SimdWrapper<_Tp, _Np> __mask, const
bool* __mem) noexcept
2753 auto __tmp = __wrapper_bitcast<__int_for_sizeof_t<_Tp>>(__merge);
2754 _BitOps::_S_bit_iteration(_SuperImpl::_S_to_bits(__mask),
2756 __tmp._M_set(__i, -__mem[__i]);
2758 __merge = __wrapper_bitcast<_Tp>(__tmp);
2763 template <
typename _Tp,
size_t _Np>
2764 _GLIBCXX_SIMD_INTRINSIC
static void _S_store(_SimdWrapper<_Tp, _Np> __v,
2765 bool* __mem) noexcept
2767 __execute_n_times<_Np>([&](
auto __i) constexpr {
2768 __mem[__i] = __v[__i];
2773 template <
typename _Tp,
size_t _Np>
2775 _S_masked_store(
const _SimdWrapper<_Tp, _Np> __v,
bool* __mem,
2776 const _SimdWrapper<_Tp, _Np> __k) noexcept
2778 _BitOps::_S_bit_iteration(
2779 _SuperImpl::_S_to_bits(__k), [&](
auto __i) constexpr {
2780 __mem[__i] = __v[__i];
2785 template <
size_t _Np,
typename _Tp>
2786 _GLIBCXX_SIMD_INTRINSIC
static _MaskMember<_Tp>
2787 _S_from_bitmask(_SanitizedBitMask<_Np> __bits, _TypeTag<_Tp>)
2789 return _SuperImpl::template _S_to_maskvector<_Tp, _S_size<_Tp>>(__bits);
2793 template <
typename _Tp,
size_t _Np>
2794 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
2795 _S_logical_and(
const _SimdWrapper<_Tp, _Np>& __x,
2796 const _SimdWrapper<_Tp, _Np>& __y)
2797 {
return __and(__x._M_data, __y._M_data); }
2799 template <
typename _Tp,
size_t _Np>
2800 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
2801 _S_logical_or(
const _SimdWrapper<_Tp, _Np>& __x,
2802 const _SimdWrapper<_Tp, _Np>& __y)
2803 {
return __or(__x._M_data, __y._M_data); }
2805 template <
typename _Tp,
size_t _Np>
2806 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
2807 _S_bit_not(
const _SimdWrapper<_Tp, _Np>& __x)
2809 if constexpr (_Abi::template _S_is_partial<_Tp>)
2810 return __andnot(__x, __wrapper_bitcast<_Tp>(
2811 _Abi::template _S_implicit_mask<_Tp>()));
2813 return __not(__x._M_data);
2816 template <
typename _Tp,
size_t _Np>
2817 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
2818 _S_bit_and(
const _SimdWrapper<_Tp, _Np>& __x,
2819 const _SimdWrapper<_Tp, _Np>& __y)
2820 {
return __and(__x._M_data, __y._M_data); }
2822 template <
typename _Tp,
size_t _Np>
2823 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
2824 _S_bit_or(
const _SimdWrapper<_Tp, _Np>& __x,
2825 const _SimdWrapper<_Tp, _Np>& __y)
2826 {
return __or(__x._M_data, __y._M_data); }
2828 template <
typename _Tp,
size_t _Np>
2829 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
2830 _S_bit_xor(
const _SimdWrapper<_Tp, _Np>& __x,
2831 const _SimdWrapper<_Tp, _Np>& __y)
2832 {
return __xor(__x._M_data, __y._M_data); }
2835 template <
typename _Tp,
size_t _Np>
2836 static constexpr
void _S_set(_SimdWrapper<_Tp, _Np>& __k,
int __i,
2839 if constexpr (is_same_v<_Tp, bool>)
2840 __k._M_set(__i, __x);
2843 static_assert(is_same_v<_Tp, __int_for_sizeof_t<_Tp>>);
2844 if (__builtin_is_constant_evaluated())
2846 __k = __generate_from_n_evaluations<_Np,
2847 __vector_type_t<_Tp, _Np>>(
2856 __k._M_data[__i] = -__x;
2861 template <
typename _Tp,
size_t _Np>
2862 _GLIBCXX_SIMD_INTRINSIC
static void
2863 _S_masked_assign(_SimdWrapper<_Tp, _Np> __k,
2864 _SimdWrapper<_Tp, _Np>& __lhs,
2865 __type_identity_t<_SimdWrapper<_Tp, _Np>> __rhs)
2866 { __lhs = _CommonImpl::_S_blend(__k, __lhs, __rhs); }
2868 template <
typename _Tp,
size_t _Np>
2869 _GLIBCXX_SIMD_INTRINSIC
static void
2870 _S_masked_assign(_SimdWrapper<_Tp, _Np> __k,
2871 _SimdWrapper<_Tp, _Np>& __lhs,
bool __rhs)
2873 if (__builtin_constant_p(__rhs))
2876 __lhs = __andnot(__k, __lhs);
2878 __lhs = __or(__k, __lhs);
2881 __lhs = _CommonImpl::_S_blend(__k, __lhs,
2882 __data(simd_mask<_Tp, _Abi>(__rhs)));
2887 template <
typename _Tp>
2888 _GLIBCXX_SIMD_INTRINSIC
static bool
2889 _S_all_of(simd_mask<_Tp, _Abi> __k)
2891 return __call_with_subscripts(
2893 [](
const auto... __ent) constexpr {
return (... && !(__ent == 0)); });
2898 template <
typename _Tp>
2899 _GLIBCXX_SIMD_INTRINSIC
static bool
2900 _S_any_of(simd_mask<_Tp, _Abi> __k)
2902 return __call_with_subscripts(
2904 [](
const auto... __ent) constexpr {
return (... || !(__ent == 0)); });
2909 template <
typename _Tp>
2910 _GLIBCXX_SIMD_INTRINSIC
static bool
2911 _S_none_of(simd_mask<_Tp, _Abi> __k)
2913 return __call_with_subscripts(
2915 [](
const auto... __ent) constexpr {
return (... && (__ent == 0)); });
2920 template <
typename _Tp>
2921 _GLIBCXX_SIMD_INTRINSIC
static bool
2922 _S_some_of(simd_mask<_Tp, _Abi> __k)
2924 const int __n_true = _SuperImpl::_S_popcount(__k);
2925 return __n_true > 0 && __n_true < int(_S_size<_Tp>);
2930 template <
typename _Tp>
2931 _GLIBCXX_SIMD_INTRINSIC
static int
2932 _S_popcount(simd_mask<_Tp, _Abi> __k)
2934 using _I = __int_for_sizeof_t<_Tp>;
2935 if constexpr (is_default_constructible_v<simd<_I, _Abi>>)
2937 simd<_I, _Abi>(__private_init, __wrapper_bitcast<_I>(__data(__k))));
2939 return -
reduce(__bit_cast<rebind_simd_t<_I, simd<_Tp, _Abi>>>(
2940 simd<_Tp, _Abi>(__private_init, __data(__k))));
2945 template <typename _Tp>
2946 _GLIBCXX_SIMD_INTRINSIC static
int
2947 _S_find_first_set(simd_mask<_Tp, _Abi> __k)
2949 return std::__countr_zero(
2950 _SuperImpl::_S_to_bits(__data(__k))._M_to_bits());
2955 template <
typename _Tp>
2956 _GLIBCXX_SIMD_INTRINSIC
static int
2957 _S_find_last_set(simd_mask<_Tp, _Abi> __k)
2959 return std::__bit_width(
2960 _SuperImpl::_S_to_bits(__data(__k))._M_to_bits()) - 1;
2967 _GLIBCXX_SIMD_END_NAMESPACE
complex< _Tp > log10(const complex< _Tp > &)
Return complex base 10 logarithm of z.
complex< _Tp > sin(const complex< _Tp > &)
Return complex sine of z.
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
complex< _Tp > cosh(const complex< _Tp > &)
Return complex hyperbolic cosine of z.
complex< _Tp > tanh(const complex< _Tp > &)
Return complex hyperbolic tangent of z.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
complex< _Tp > sinh(const complex< _Tp > &)
Return complex hyperbolic sine of z.
complex< _Tp > cos(const complex< _Tp > &)
Return complex cosine of z.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
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.
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.
_Tp fabs(const std::complex< _Tp > &)
fabs(__z) [8.1.8].
std::complex< _Tp > asinh(const std::complex< _Tp > &)
asinh(__z) [8.1.6].
std::complex< _Tp > atan(const std::complex< _Tp > &)
atan(__z) [8.1.4].
make_integer_sequence< size_t, _Num > make_index_sequence
Alias template make_index_sequence.
std::complex< _Tp > atanh(const std::complex< _Tp > &)
atanh(__z) [8.1.7].
std::complex< _Tp > acosh(const std::complex< _Tp > &)
acosh(__z) [8.1.5].
std::complex< _Tp > acos(const std::complex< _Tp > &)
acos(__z) [8.1.2].
std::complex< _Tp > asin(const std::complex< _Tp > &)
asin(__z) [8.1.3].