Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/c++/11/experimental/bits/simd.h
$ cat -n /usr/include/c++/11/experimental/bits/simd.h 1 // Definition of the public simd interfaces -*- C++ -*- 2 3 // Copyright (C) 2020-2021 Free Software Foundation, Inc. 4 // 5 // This file is part of the GNU ISO C++ Library. This library is free 6 // software; you can redistribute it and/or modify it under the 7 // terms of the GNU General Public License as published by the 8 // Free Software Foundation; either version 3, or (at your option) 9 // any later version. 10 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 16 // Under Section 7 of GPL version 3, you are granted additional 17 // permissions described in the GCC Runtime Library Exception, version 18 // 3.1, as published by the Free Software Foundation. 19 20 // You should have received a copy of the GNU General Public License and 21 // a copy of the GCC Runtime Library Exception along with this program; 22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 //
. 24 25 #ifndef _GLIBCXX_EXPERIMENTAL_SIMD_H 26 #define _GLIBCXX_EXPERIMENTAL_SIMD_H 27 28 #if __cplusplus >= 201703L 29 30 #include "simd_detail.h" 31 #include "numeric_traits.h" 32 #include
33 #include
34 #ifdef _GLIBCXX_DEBUG_UB 35 #include
// for stderr 36 #endif 37 #include
38 #include
39 #include
40 #include
41 42 #if _GLIBCXX_SIMD_X86INTRIN 43 #include
44 #elif _GLIBCXX_SIMD_HAVE_NEON 45 #pragma GCC diagnostic push 46 // narrowing conversion of '__a' from 'uint64_t' {aka 'long long unsigned int'} to 47 // 'int64x1_t' {aka 'long long int'} [-Wnarrowing] 48 #pragma GCC diagnostic ignored "-Wnarrowing" 49 #include
50 #pragma GCC diagnostic pop 51 #endif 52 53 /** @ingroup ts_simd 54 * @{ 55 */ 56 /* There are several closely related types, with the following naming 57 * convention: 58 * _Tp: vectorizable (arithmetic) type (or any type) 59 * _TV: __vector_type_t<_Tp, _Np> 60 * _TW: _SimdWrapper<_Tp, _Np> 61 * _TI: __intrinsic_type_t<_Tp, _Np> 62 * _TVT: _VectorTraits<_TV> or _VectorTraits<_TW> 63 * If one additional type is needed use _U instead of _T. 64 * Otherwise use _T\d, _TV\d, _TW\d, TI\d, _TVT\d. 65 * 66 * More naming conventions: 67 * _Ap or _Abi: An ABI tag from the simd_abi namespace 68 * _Ip: often used for integer types with sizeof(_Ip) == sizeof(_Tp), 69 * _IV, _IW as for _TV, _TW 70 * _Np: number of elements (not bytes) 71 * _Bytes: number of bytes 72 * 73 * Variable names: 74 * __k: mask object (vector- or bitmask) 75 */ 76 _GLIBCXX_SIMD_BEGIN_NAMESPACE 77 78 #if !_GLIBCXX_SIMD_X86INTRIN 79 using __m128 [[__gnu__::__vector_size__(16)]] = float; 80 using __m128d [[__gnu__::__vector_size__(16)]] = double; 81 using __m128i [[__gnu__::__vector_size__(16)]] = long long; 82 using __m256 [[__gnu__::__vector_size__(32)]] = float; 83 using __m256d [[__gnu__::__vector_size__(32)]] = double; 84 using __m256i [[__gnu__::__vector_size__(32)]] = long long; 85 using __m512 [[__gnu__::__vector_size__(64)]] = float; 86 using __m512d [[__gnu__::__vector_size__(64)]] = double; 87 using __m512i [[__gnu__::__vector_size__(64)]] = long long; 88 #endif 89 90 namespace simd_abi { 91 // simd_abi forward declarations {{{ 92 // implementation details: 93 struct _Scalar; 94 95 template
96 struct _Fixed; 97 98 // There are two major ABIs that appear on different architectures. 99 // Both have non-boolean values packed into an N Byte register 100 // -> #elements = N / sizeof(T) 101 // Masks differ: 102 // 1. Use value vector registers for masks (all 0 or all 1) 103 // 2. Use bitmasks (mask registers) with one bit per value in the corresponding 104 // value vector 105 // 106 // Both can be partially used, masking off the rest when doing horizontal 107 // operations or operations that can trap (e.g. FP_INVALID or integer division 108 // by 0). This is encoded as the number of used bytes. 109 template
110 struct _VecBuiltin; 111 112 template
113 struct _VecBltnBtmsk; 114 115 template
116 using _VecN = _VecBuiltin
; 117 118 template
119 using _Sse = _VecBuiltin<_UsedBytes>; 120 121 template
122 using _Avx = _VecBuiltin<_UsedBytes>; 123 124 template
125 using _Avx512 = _VecBltnBtmsk<_UsedBytes>; 126 127 template
128 using _Neon = _VecBuiltin<_UsedBytes>; 129 130 // implementation-defined: 131 using __sse = _Sse<>; 132 using __avx = _Avx<>; 133 using __avx512 = _Avx512<>; 134 using __neon = _Neon<>; 135 using __neon128 = _Neon<16>; 136 using __neon64 = _Neon<8>; 137 138 // standard: 139 template
140 struct deduce; 141 142 template
143 using fixed_size = _Fixed<_Np>; 144 145 using scalar = _Scalar; 146 147 // }}} 148 } // namespace simd_abi 149 // forward declarations is_simd(_mask), simd(_mask), simd_size {{{ 150 template
151 struct is_simd; 152 153 template
154 struct is_simd_mask; 155 156 template
157 class simd; 158 159 template
160 class simd_mask; 161 162 template
163 struct simd_size; 164 165 // }}} 166 // load/store flags {{{ 167 struct element_aligned_tag 168 { 169 template
170 static constexpr size_t _S_alignment = alignof(_Up); 171 172 template
173 _GLIBCXX_SIMD_INTRINSIC static constexpr _Up* 174 _S_apply(_Up* __ptr) 175 { return __ptr; } 176 }; 177 178 struct vector_aligned_tag 179 { 180 template
181 static constexpr size_t _S_alignment 182 = std::__bit_ceil(sizeof(_Up) * _Tp::size()); 183 184 template
185 _GLIBCXX_SIMD_INTRINSIC static constexpr _Up* 186 _S_apply(_Up* __ptr) 187 { return static_cast<_Up*>(__builtin_assume_aligned(__ptr, _S_alignment<_Tp, _Up>)); } 188 }; 189 190 template
struct overaligned_tag 191 { 192 template
193 static constexpr size_t _S_alignment = _Np; 194 195 template
196 _GLIBCXX_SIMD_INTRINSIC static constexpr _Up* 197 _S_apply(_Up* __ptr) 198 { return static_cast<_Up*>(__builtin_assume_aligned(__ptr, _Np)); } 199 }; 200 201 inline constexpr element_aligned_tag element_aligned = {}; 202 203 inline constexpr vector_aligned_tag vector_aligned = {}; 204 205 template
206 inline constexpr overaligned_tag<_Np> overaligned = {}; 207 208 // }}} 209 template
210 using _SizeConstant = integral_constant
; 211 212 namespace __detail 213 { 214 struct _Minimum 215 { 216 template
217 _GLIBCXX_SIMD_INTRINSIC constexpr 218 _Tp 219 operator()(_Tp __a, _Tp __b) const 220 { 221 using std::min; 222 return min(__a, __b); 223 } 224 }; 225 226 struct _Maximum 227 { 228 template
229 _GLIBCXX_SIMD_INTRINSIC constexpr 230 _Tp 231 operator()(_Tp __a, _Tp __b) const 232 { 233 using std::max; 234 return max(__a, __b); 235 } 236 }; 237 } // namespace __detail 238 239 // unrolled/pack execution helpers 240 // __execute_n_times{{{ 241 template
242 _GLIBCXX_SIMD_INTRINSIC constexpr void 243 __execute_on_index_sequence(_Fp&& __f, index_sequence<_I...>) 244 { ((void)__f(_SizeConstant<_I>()), ...); } 245 246 template
247 _GLIBCXX_SIMD_INTRINSIC constexpr void 248 __execute_on_index_sequence(_Fp&&, index_sequence<>) 249 { } 250 251 template
252 _GLIBCXX_SIMD_INTRINSIC constexpr void 253 __execute_n_times(_Fp&& __f) 254 { 255 __execute_on_index_sequence(static_cast<_Fp&&>(__f), 256 make_index_sequence<_Np>{}); 257 } 258 259 // }}} 260 // __generate_from_n_evaluations{{{ 261 template
262 _GLIBCXX_SIMD_INTRINSIC constexpr _R 263 __execute_on_index_sequence_with_return(_Fp&& __f, index_sequence<_I...>) 264 { return _R{__f(_SizeConstant<_I>())...}; } 265 266 template
267 _GLIBCXX_SIMD_INTRINSIC constexpr _R 268 __generate_from_n_evaluations(_Fp&& __f) 269 { 270 return __execute_on_index_sequence_with_return<_R>( 271 static_cast<_Fp&&>(__f), make_index_sequence<_Np>{}); 272 } 273 274 // }}} 275 // __call_with_n_evaluations{{{ 276 template
277 _GLIBCXX_SIMD_INTRINSIC constexpr auto 278 __call_with_n_evaluations(index_sequence<_I...>, _F0&& __f0, _FArgs&& __fargs) 279 { return __f0(__fargs(_SizeConstant<_I>())...); } 280 281 template
282 _GLIBCXX_SIMD_INTRINSIC constexpr auto 283 __call_with_n_evaluations(_F0&& __f0, _FArgs&& __fargs) 284 { 285 return __call_with_n_evaluations(make_index_sequence<_Np>{}, 286 static_cast<_F0&&>(__f0), 287 static_cast<_FArgs&&>(__fargs)); 288 } 289 290 // }}} 291 // __call_with_subscripts{{{ 292 template
293 _GLIBCXX_SIMD_INTRINSIC constexpr auto 294 __call_with_subscripts(_Tp&& __x, index_sequence<_It...>, _Fp&& __fun) 295 { return __fun(__x[_First + _It]...); } 296 297 template
298 _GLIBCXX_SIMD_INTRINSIC constexpr auto 299 __call_with_subscripts(_Tp&& __x, _Fp&& __fun) 300 { 301 return __call_with_subscripts<_First>(static_cast<_Tp&&>(__x), 302 make_index_sequence<_Np>(), 303 static_cast<_Fp&&>(__fun)); 304 } 305 306 // }}} 307 308 // vvv ---- type traits ---- vvv 309 // integer type aliases{{{ 310 using _UChar = unsigned char; 311 using _SChar = signed char; 312 using _UShort = unsigned short; 313 using _UInt = unsigned int; 314 using _ULong = unsigned long; 315 using _ULLong = unsigned long long; 316 using _LLong = long long; 317 318 //}}} 319 // __first_of_pack{{{ 320 template
321 struct __first_of_pack 322 { using type = _T0; }; 323 324 template
325 using __first_of_pack_t = typename __first_of_pack<_Ts...>::type; 326 327 //}}} 328 // __value_type_or_identity_t {{{ 329 template
330 typename _Tp::value_type 331 __value_type_or_identity_impl(int); 332 333 template
334 _Tp 335 __value_type_or_identity_impl(float); 336 337 template
338 using __value_type_or_identity_t 339 = decltype(__value_type_or_identity_impl<_Tp>(int())); 340 341 // }}} 342 // __is_vectorizable {{{ 343 template
344 struct __is_vectorizable : public is_arithmetic<_Tp> {}; 345 346 template <> 347 struct __is_vectorizable
: public false_type {}; 348 349 template
350 inline constexpr bool __is_vectorizable_v = __is_vectorizable<_Tp>::value; 351 352 // Deduces to a vectorizable type 353 template
>> 354 using _Vectorizable = _Tp; 355 356 // }}} 357 // _LoadStorePtr / __is_possible_loadstore_conversion {{{ 358 template
359 struct __is_possible_loadstore_conversion 360 : conjunction<__is_vectorizable<_Ptr>, __is_vectorizable<_ValueType>> {}; 361 362 template <> 363 struct __is_possible_loadstore_conversion
: true_type {}; 364 365 // Deduces to a type allowed for load/store with the given value type. 366 template
::value>> 369 using _LoadStorePtr = _Ptr; 370 371 // }}} 372 // __is_bitmask{{{ 373 template
> 374 struct __is_bitmask : false_type {}; 375 376 template
377 inline constexpr bool __is_bitmask_v = __is_bitmask<_Tp>::value; 378 379 // the __mmaskXX case: 380 template
381 struct __is_bitmask<_Tp, 382 void_t
() = declval<_Tp>() & 1u)>> 383 : true_type {}; 384 385 // }}} 386 // __int_for_sizeof{{{ 387 #pragma GCC diagnostic push 388 #pragma GCC diagnostic ignored "-Wpedantic" 389 template
390 constexpr auto 391 __int_for_sizeof() 392 { 393 static_assert(_Bytes > 0); 394 if constexpr (_Bytes == sizeof(int)) 395 return int(); 396 #ifdef __clang__ 397 else if constexpr (_Bytes == sizeof(char)) 398 return char(); 399 #else 400 else if constexpr (_Bytes == sizeof(_SChar)) 401 return _SChar(); 402 #endif 403 else if constexpr (_Bytes == sizeof(short)) 404 return short(); 405 #ifndef __clang__ 406 else if constexpr (_Bytes == sizeof(long)) 407 return long(); 408 #endif 409 else if constexpr (_Bytes == sizeof(_LLong)) 410 return _LLong(); 411 #ifdef __SIZEOF_INT128__ 412 else if constexpr (_Bytes == sizeof(__int128)) 413 return __int128(); 414 #endif // __SIZEOF_INT128__ 415 else if constexpr (_Bytes % sizeof(int) == 0) 416 { 417 constexpr size_t _Np = _Bytes / sizeof(int); 418 struct _Ip 419 { 420 int _M_data[_Np]; 421 422 _GLIBCXX_SIMD_INTRINSIC constexpr _Ip 423 operator&(_Ip __rhs) const 424 { 425 return __generate_from_n_evaluations<_Np, _Ip>( 426 [&](auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { 427 return __rhs._M_data[__i] & _M_data[__i]; 428 }); 429 } 430 431 _GLIBCXX_SIMD_INTRINSIC constexpr _Ip 432 operator|(_Ip __rhs) const 433 { 434 return __generate_from_n_evaluations<_Np, _Ip>( 435 [&](auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { 436 return __rhs._M_data[__i] | _M_data[__i]; 437 }); 438 } 439 440 _GLIBCXX_SIMD_INTRINSIC constexpr _Ip 441 operator^(_Ip __rhs) const 442 { 443 return __generate_from_n_evaluations<_Np, _Ip>( 444 [&](auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { 445 return __rhs._M_data[__i] ^ _M_data[__i]; 446 }); 447 } 448 449 _GLIBCXX_SIMD_INTRINSIC constexpr _Ip 450 operator~() const 451 { 452 return __generate_from_n_evaluations<_Np, _Ip>( 453 [&](auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { return ~_M_data[__i]; }); 454 } 455 }; 456 return _Ip{}; 457 } 458 else 459 static_assert(_Bytes == 0, "this should be unreachable"); 460 } 461 #pragma GCC diagnostic pop 462 463 template
464 using __int_for_sizeof_t = decltype(__int_for_sizeof
()); 465 466 template
467 using __int_with_sizeof_t = decltype(__int_for_sizeof<_Np>()); 468 469 // }}} 470 // __is_fixed_size_abi{{{ 471 template
472 struct __is_fixed_size_abi : false_type {}; 473 474 template
475 struct __is_fixed_size_abi
> : true_type {}; 476 477 template
478 inline constexpr bool __is_fixed_size_abi_v = __is_fixed_size_abi<_Tp>::value; 479 480 // }}} 481 // constexpr feature detection{{{ 482 constexpr inline bool __have_mmx = _GLIBCXX_SIMD_HAVE_MMX; 483 constexpr inline bool __have_sse = _GLIBCXX_SIMD_HAVE_SSE; 484 constexpr inline bool __have_sse2 = _GLIBCXX_SIMD_HAVE_SSE2; 485 constexpr inline bool __have_sse3 = _GLIBCXX_SIMD_HAVE_SSE3; 486 constexpr inline bool __have_ssse3 = _GLIBCXX_SIMD_HAVE_SSSE3; 487 constexpr inline bool __have_sse4_1 = _GLIBCXX_SIMD_HAVE_SSE4_1; 488 constexpr inline bool __have_sse4_2 = _GLIBCXX_SIMD_HAVE_SSE4_2; 489 constexpr inline bool __have_xop = _GLIBCXX_SIMD_HAVE_XOP; 490 constexpr inline bool __have_avx = _GLIBCXX_SIMD_HAVE_AVX; 491 constexpr inline bool __have_avx2 = _GLIBCXX_SIMD_HAVE_AVX2; 492 constexpr inline bool __have_bmi = _GLIBCXX_SIMD_HAVE_BMI1; 493 constexpr inline bool __have_bmi2 = _GLIBCXX_SIMD_HAVE_BMI2; 494 constexpr inline bool __have_lzcnt = _GLIBCXX_SIMD_HAVE_LZCNT; 495 constexpr inline bool __have_sse4a = _GLIBCXX_SIMD_HAVE_SSE4A; 496 constexpr inline bool __have_fma = _GLIBCXX_SIMD_HAVE_FMA; 497 constexpr inline bool __have_fma4 = _GLIBCXX_SIMD_HAVE_FMA4; 498 constexpr inline bool __have_f16c = _GLIBCXX_SIMD_HAVE_F16C; 499 constexpr inline bool __have_popcnt = _GLIBCXX_SIMD_HAVE_POPCNT; 500 constexpr inline bool __have_avx512f = _GLIBCXX_SIMD_HAVE_AVX512F; 501 constexpr inline bool __have_avx512dq = _GLIBCXX_SIMD_HAVE_AVX512DQ; 502 constexpr inline bool __have_avx512vl = _GLIBCXX_SIMD_HAVE_AVX512VL; 503 constexpr inline bool __have_avx512bw = _GLIBCXX_SIMD_HAVE_AVX512BW; 504 constexpr inline bool __have_avx512dq_vl = __have_avx512dq && __have_avx512vl; 505 constexpr inline bool __have_avx512bw_vl = __have_avx512bw && __have_avx512vl; 506 507 constexpr inline bool __have_neon = _GLIBCXX_SIMD_HAVE_NEON; 508 constexpr inline bool __have_neon_a32 = _GLIBCXX_SIMD_HAVE_NEON_A32; 509 constexpr inline bool __have_neon_a64 = _GLIBCXX_SIMD_HAVE_NEON_A64; 510 constexpr inline bool __support_neon_float = 511 #if defined __GCC_IEC_559 512 __GCC_IEC_559 == 0; 513 #elif defined __FAST_MATH__ 514 true; 515 #else 516 false; 517 #endif 518 519 #ifdef _ARCH_PWR10 520 constexpr inline bool __have_power10vec = true; 521 #else 522 constexpr inline bool __have_power10vec = false; 523 #endif 524 #ifdef __POWER9_VECTOR__ 525 constexpr inline bool __have_power9vec = true; 526 #else 527 constexpr inline bool __have_power9vec = false; 528 #endif 529 #if defined __POWER8_VECTOR__ 530 constexpr inline bool __have_power8vec = true; 531 #else 532 constexpr inline bool __have_power8vec = __have_power9vec; 533 #endif 534 #if defined __VSX__ 535 constexpr inline bool __have_power_vsx = true; 536 #else 537 constexpr inline bool __have_power_vsx = __have_power8vec; 538 #endif 539 #if defined __ALTIVEC__ 540 constexpr inline bool __have_power_vmx = true; 541 #else 542 constexpr inline bool __have_power_vmx = __have_power_vsx; 543 #endif 544 545 // }}} 546 // __is_scalar_abi {{{ 547 template
548 constexpr bool 549 __is_scalar_abi() 550 { return is_same_v
; } 551 552 // }}} 553 // __abi_bytes_v {{{ 554 template
class _Abi, int _Bytes> 555 constexpr int 556 __abi_bytes_impl(_Abi<_Bytes>*) 557 { return _Bytes; } 558 559 template
560 constexpr int 561 __abi_bytes_impl(_Tp*) 562 { return -1; } 563 564 template
565 inline constexpr int __abi_bytes_v 566 = __abi_bytes_impl(static_cast<_Abi*>(nullptr)); 567 568 // }}} 569 // __is_builtin_bitmask_abi {{{ 570 template
571 constexpr bool 572 __is_builtin_bitmask_abi() 573 { return is_same_v
>, _Abi>; } 574 575 // }}} 576 // __is_sse_abi {{{ 577 template
578 constexpr bool 579 __is_sse_abi() 580 { 581 constexpr auto _Bytes = __abi_bytes_v<_Abi>; 582 return _Bytes <= 16 && is_same_v
, _Abi>; 583 } 584 585 // }}} 586 // __is_avx_abi {{{ 587 template
588 constexpr bool 589 __is_avx_abi() 590 { 591 constexpr auto _Bytes = __abi_bytes_v<_Abi>; 592 return _Bytes > 16 && _Bytes <= 32 593 && is_same_v
, _Abi>; 594 } 595 596 // }}} 597 // __is_avx512_abi {{{ 598 template
599 constexpr bool 600 __is_avx512_abi() 601 { 602 constexpr auto _Bytes = __abi_bytes_v<_Abi>; 603 return _Bytes <= 64 && is_same_v
, _Abi>; 604 } 605 606 // }}} 607 // __is_neon_abi {{{ 608 template
609 constexpr bool 610 __is_neon_abi() 611 { 612 constexpr auto _Bytes = __abi_bytes_v<_Abi>; 613 return _Bytes <= 16 && is_same_v
, _Abi>; 614 } 615 616 // }}} 617 // __make_dependent_t {{{ 618 template
619 struct __make_dependent 620 { using type = _Up; }; 621 622 template
623 using __make_dependent_t = typename __make_dependent<_Tp, _Up>::type; 624 625 // }}} 626 // ^^^ ---- type traits ---- ^^^ 627 628 // __invoke_ub{{{ 629 template
630 [[noreturn]] _GLIBCXX_SIMD_ALWAYS_INLINE void 631 __invoke_ub([[maybe_unused]] const char* __msg, [[maybe_unused]] const _Args&... __args) 632 { 633 #ifdef _GLIBCXX_DEBUG_UB 634 __builtin_fprintf(stderr, __msg, __args...); 635 __builtin_trap(); 636 #else 637 __builtin_unreachable(); 638 #endif 639 } 640 641 // }}} 642 // __assert_unreachable{{{ 643 template
644 struct __assert_unreachable 645 { static_assert(!is_same_v<_Tp, _Tp>, "this should be unreachable"); }; 646 647 // }}} 648 // __size_or_zero_v {{{ 649 template
::value> 650 constexpr size_t 651 __size_or_zero_dispatch(int) 652 { return _Np; } 653 654 template
655 constexpr size_t 656 __size_or_zero_dispatch(float) 657 { return 0; } 658 659 template
660 inline constexpr size_t __size_or_zero_v 661 = __size_or_zero_dispatch<_Tp, _Ap>(0); 662 663 // }}} 664 // __div_roundup {{{ 665 inline constexpr size_t 666 __div_roundup(size_t __a, size_t __b) 667 { return (__a + __b - 1) / __b; } 668 669 // }}} 670 // _ExactBool{{{ 671 class _ExactBool 672 { 673 const bool _M_data; 674 675 public: 676 _GLIBCXX_SIMD_INTRINSIC constexpr 677 _ExactBool(bool __b) : _M_data(__b) {} 678 679 _ExactBool(int) = delete; 680 681 _GLIBCXX_SIMD_INTRINSIC constexpr 682 operator bool() const 683 { return _M_data; } 684 }; 685 686 // }}} 687 // __may_alias{{{ 688 /**@internal 689 * Helper __may_alias<_Tp> that turns _Tp into the type to be used for an 690 * aliasing pointer. This adds the __may_alias attribute to _Tp (with compilers 691 * that support it). 692 */ 693 template
694 using __may_alias [[__gnu__::__may_alias__]] = _Tp; 695 696 // }}} 697 // _UnsupportedBase {{{ 698 // simd and simd_mask base for unsupported <_Tp, _Abi> 699 struct _UnsupportedBase 700 { 701 _UnsupportedBase() = delete; 702 _UnsupportedBase(const _UnsupportedBase&) = delete; 703 _UnsupportedBase& operator=(const _UnsupportedBase&) = delete; 704 ~_UnsupportedBase() = delete; 705 }; 706 707 // }}} 708 // _InvalidTraits {{{ 709 /** 710 * @internal 711 * Defines the implementation of __a given <_Tp, _Abi>. 712 * 713 * Implementations must ensure that only valid <_Tp, _Abi> instantiations are 714 * possible. Static assertions in the type definition do not suffice. It is 715 * important that SFINAE works. 716 */ 717 struct _InvalidTraits 718 { 719 using _IsValid = false_type; 720 using _SimdBase = _UnsupportedBase; 721 using _MaskBase = _UnsupportedBase; 722 723 static constexpr size_t _S_full_size = 0; 724 static constexpr bool _S_is_partial = false; 725 726 static constexpr size_t _S_simd_align = 1; 727 struct _SimdImpl; 728 struct _SimdMember {}; 729 struct _SimdCastType; 730 731 static constexpr size_t _S_mask_align = 1; 732 struct _MaskImpl; 733 struct _MaskMember {}; 734 struct _MaskCastType; 735 }; 736 737 // }}} 738 // _SimdTraits {{{ 739 template
> 740 struct _SimdTraits : _InvalidTraits {}; 741 742 // }}} 743 // __private_init, __bitset_init{{{ 744 /** 745 * @internal 746 * Tag used for private init constructor of simd and simd_mask 747 */ 748 inline constexpr struct _PrivateInit {} __private_init = {}; 749 750 inline constexpr struct _BitsetInit {} __bitset_init = {}; 751 752 // }}} 753 // __is_narrowing_conversion<_From, _To>{{{ 754 template
, 755 bool = is_arithmetic_v<_To>> 756 struct __is_narrowing_conversion; 757 758 // ignore "signed/unsigned mismatch" in the following trait. 759 // The implicit conversions will do the right thing here. 760 template
761 struct __is_narrowing_conversion<_From, _To, true, true> 762 : public __bool_constant<( 763 __digits_v<_From> > __digits_v<_To> 764 || __finite_max_v<_From> > __finite_max_v<_To> 765 || __finite_min_v<_From> < __finite_min_v<_To> 766 || (is_signed_v<_From> && is_unsigned_v<_To>))> {}; 767 768 template
769 struct __is_narrowing_conversion<_Tp, bool, true, true> 770 : public true_type {}; 771 772 template <> 773 struct __is_narrowing_conversion
774 : public false_type {}; 775 776 template
777 struct __is_narrowing_conversion<_Tp, _Tp, true, true> 778 : public false_type {}; 779 780 template
781 struct __is_narrowing_conversion<_From, _To, false, true> 782 : public negation
> {}; 783 784 // }}} 785 // __converts_to_higher_integer_rank{{{ 786 template
787 struct __converts_to_higher_integer_rank : public true_type {}; 788 789 // this may fail for char -> short if sizeof(char) == sizeof(short) 790 template
791 struct __converts_to_higher_integer_rank<_From, _To, false> 792 : public is_same
() + declval<_To>()), _To> {}; 793 794 // }}} 795 // __data(simd/simd_mask) {{{ 796 template
797 _GLIBCXX_SIMD_INTRINSIC constexpr const auto& 798 __data(const simd<_Tp, _Ap>& __x); 799 800 template
801 _GLIBCXX_SIMD_INTRINSIC constexpr auto& 802 __data(simd<_Tp, _Ap>& __x); 803 804 template
805 _GLIBCXX_SIMD_INTRINSIC constexpr const auto& 806 __data(const simd_mask<_Tp, _Ap>& __x); 807 808 template
809 _GLIBCXX_SIMD_INTRINSIC constexpr auto& 810 __data(simd_mask<_Tp, _Ap>& __x); 811 812 // }}} 813 // _SimdConverter {{{ 814 template
816 struct _SimdConverter; 817 818 template
819 struct _SimdConverter<_Tp, _Ap, _Tp, _Ap, void> 820 { 821 template
822 _GLIBCXX_SIMD_INTRINSIC const _Up& 823 operator()(const _Up& __x) 824 { return __x; } 825 }; 826 827 // }}} 828 // __to_value_type_or_member_type {{{ 829 template
830 _GLIBCXX_SIMD_INTRINSIC constexpr auto 831 __to_value_type_or_member_type(const _V& __x) -> decltype(__data(__x)) 832 { return __data(__x); } 833 834 template
835 _GLIBCXX_SIMD_INTRINSIC constexpr const typename _V::value_type& 836 __to_value_type_or_member_type(const typename _V::value_type& __x) 837 { return __x; } 838 839 // }}} 840 // __bool_storage_member_type{{{ 841 template
842 struct __bool_storage_member_type; 843 844 template
845 using __bool_storage_member_type_t = 846 typename __bool_storage_member_type<_Size>::type; 847 848 // }}} 849 // _SimdTuple {{{ 850 // why not tuple? 851 // 1. tuple gives no guarantee about the storage order, but I require 852 // storage 853 // equivalent to array<_Tp, _Np> 854 // 2. direct access to the element type (first template argument) 855 // 3. enforces equal element type, only different _Abi types are allowed 856 template
857 struct _SimdTuple; 858 859 //}}} 860 // __fixed_size_storage_t {{{ 861 template
862 struct __fixed_size_storage; 863 864 template
865 using __fixed_size_storage_t = typename __fixed_size_storage<_Tp, _Np>::type; 866 867 // }}} 868 // _SimdWrapper fwd decl{{{ 869 template
> 870 struct _SimdWrapper; 871 872 template
873 using _SimdWrapper8 = _SimdWrapper<_Tp, 8 / sizeof(_Tp)>; 874 template
875 using _SimdWrapper16 = _SimdWrapper<_Tp, 16 / sizeof(_Tp)>; 876 template
877 using _SimdWrapper32 = _SimdWrapper<_Tp, 32 / sizeof(_Tp)>; 878 template
879 using _SimdWrapper64 = _SimdWrapper<_Tp, 64 / sizeof(_Tp)>; 880 881 // }}} 882 // __is_simd_wrapper {{{ 883 template
884 struct __is_simd_wrapper : false_type {}; 885 886 template
887 struct __is_simd_wrapper<_SimdWrapper<_Tp, _Np>> : true_type {}; 888 889 template
890 inline constexpr bool __is_simd_wrapper_v = __is_simd_wrapper<_Tp>::value; 891 892 // }}} 893 // _BitOps {{{ 894 struct _BitOps 895 { 896 // _S_bit_iteration {{{ 897 template
898 static void 899 _S_bit_iteration(_Tp __mask, _Fp&& __f) 900 { 901 static_assert(sizeof(_ULLong) >= sizeof(_Tp)); 902 conditional_t
__k; 903 if constexpr (is_convertible_v<_Tp, decltype(__k)>) 904 __k = __mask; 905 else 906 __k = __mask.to_ullong(); 907 while(__k) 908 { 909 __f(std::__countr_zero(__k)); 910 __k &= (__k - 1); 911 } 912 } 913 914 //}}} 915 }; 916 917 //}}} 918 // __increment, __decrement {{{ 919 template
920 struct __increment 921 { constexpr _Tp operator()(_Tp __a) const { return ++__a; } }; 922 923 template <> 924 struct __increment
925 { 926 template
927 constexpr _Tp 928 operator()(_Tp __a) const 929 { return ++__a; } 930 }; 931 932 template
933 struct __decrement 934 { constexpr _Tp operator()(_Tp __a) const { return --__a; } }; 935 936 template <> 937 struct __decrement
938 { 939 template
940 constexpr _Tp 941 operator()(_Tp __a) const 942 { return --__a; } 943 }; 944 945 // }}} 946 // _ValuePreserving(OrInt) {{{ 947 template
, _To>>::value>> 950 using _ValuePreserving = _From; 951 952 template
, 954 typename = enable_if_t
, 956 disjunction< 957 is_same<_DecayedFrom, _To>, is_same<_DecayedFrom, int>, 958 conjunction
, is_unsigned<_To>>, 959 negation<__is_narrowing_conversion<_DecayedFrom, _To>>>>::value>> 960 using _ValuePreservingOrInt = _From; 961 962 // }}} 963 // __intrinsic_type {{{ 964 template
> 965 struct __intrinsic_type; 966 967 template
968 using __intrinsic_type_t = 969 typename __intrinsic_type<_Tp, _Size * sizeof(_Tp)>::type; 970 971 template
972 using __intrinsic_type2_t = typename __intrinsic_type<_Tp, 2>::type; 973 template
974 using __intrinsic_type4_t = typename __intrinsic_type<_Tp, 4>::type; 975 template
976 using __intrinsic_type8_t = typename __intrinsic_type<_Tp, 8>::type; 977 template
978 using __intrinsic_type16_t = typename __intrinsic_type<_Tp, 16>::type; 979 template
980 using __intrinsic_type32_t = typename __intrinsic_type<_Tp, 32>::type; 981 template
982 using __intrinsic_type64_t = typename __intrinsic_type<_Tp, 64>::type; 983 984 // }}} 985 // _BitMask {{{ 986 template
987 struct _BitMask; 988 989 template
990 struct __is_bitmask<_BitMask<_Np, _Sanitized>, void> : true_type {}; 991 992 template
993 using _SanitizedBitMask = _BitMask<_Np, true>; 994 995 template
996 struct _BitMask 997 { 998 static_assert(_Np > 0); 999 1000 static constexpr size_t _NBytes = __div_roundup(_Np, __CHAR_BIT__); 1001 1002 using _Tp = conditional_t<_Np == 1, bool, 1003 make_unsigned_t<__int_with_sizeof_t
>>; 1005 1006 static constexpr int _S_array_size = __div_roundup(_NBytes, sizeof(_Tp)); 1007 1008 _Tp _M_bits[_S_array_size]; 1009 1010 static constexpr int _S_unused_bits 1011 = _Np == 1 ? 0 : _S_array_size * sizeof(_Tp) * __CHAR_BIT__ - _Np; 1012 1013 static constexpr _Tp _S_bitmask = +_Tp(~_Tp()) >> _S_unused_bits; 1014 1015 constexpr _BitMask() noexcept = default; 1016 1017 constexpr _BitMask(unsigned long long __x) noexcept 1018 : _M_bits{static_cast<_Tp>(__x)} {} 1019 1020 _BitMask(bitset<_Np> __x) noexcept : _BitMask(__x.to_ullong()) {} 1021 1022 constexpr _BitMask(const _BitMask&) noexcept = default; 1023 1024 template
> 1026 constexpr _BitMask(const _BitMask<_Np, _RhsSanitized>& __rhs) noexcept 1027 : _BitMask(__rhs._M_sanitized()) {} 1028 1029 constexpr operator _SimdWrapper
() const noexcept 1030 { 1031 static_assert(_S_array_size == 1); 1032 return _M_bits[0]; 1033 } 1034 1035 // precondition: is sanitized 1036 constexpr _Tp 1037 _M_to_bits() const noexcept 1038 { 1039 static_assert(_S_array_size == 1); 1040 return _M_bits[0]; 1041 } 1042 1043 // precondition: is sanitized 1044 constexpr unsigned long long 1045 to_ullong() const noexcept 1046 { 1047 static_assert(_S_array_size == 1); 1048 return _M_bits[0]; 1049 } 1050 1051 // precondition: is sanitized 1052 constexpr unsigned long 1053 to_ulong() const noexcept 1054 { 1055 static_assert(_S_array_size == 1); 1056 return _M_bits[0]; 1057 } 1058 1059 constexpr bitset<_Np> 1060 _M_to_bitset() const noexcept 1061 { 1062 static_assert(_S_array_size == 1); 1063 return _M_bits[0]; 1064 } 1065 1066 constexpr decltype(auto) 1067 _M_sanitized() const noexcept 1068 { 1069 if constexpr (_Sanitized) 1070 return *this; 1071 else if constexpr (_Np == 1) 1072 return _SanitizedBitMask<_Np>(_M_bits[0]); 1073 else 1074 { 1075 _SanitizedBitMask<_Np> __r = {}; 1076 for (int __i = 0; __i < _S_array_size; ++__i) 1077 __r._M_bits[__i] = _M_bits[__i]; 1078 if constexpr (_S_unused_bits > 0) 1079 __r._M_bits[_S_array_size - 1] &= _S_bitmask; 1080 return __r; 1081 } 1082 } 1083 1084 template
1085 constexpr _BitMask<_Np + _Mp, _Sanitized> 1086 _M_prepend(_BitMask<_Mp, _LSanitized> __lsb) const noexcept 1087 { 1088 constexpr size_t _RN = _Np + _Mp; 1089 using _Rp = _BitMask<_RN, _Sanitized>; 1090 if constexpr (_Rp::_S_array_size == 1) 1091 { 1092 _Rp __r{{_M_bits[0]}}; 1093 __r._M_bits[0] <<= _Mp; 1094 __r._M_bits[0] |= __lsb._M_sanitized()._M_bits[0]; 1095 return __r; 1096 } 1097 else 1098 __assert_unreachable<_Rp>(); 1099 } 1100 1101 // Return a new _BitMask with size _NewSize while dropping _DropLsb least 1102 // significant bits. If the operation implicitly produces a sanitized bitmask, 1103 // the result type will have _Sanitized set. 1104 template
1105 constexpr auto 1106 _M_extract() const noexcept 1107 { 1108 static_assert(_Np > _DropLsb); 1109 static_assert(_DropLsb + _NewSize <= sizeof(_ULLong) * __CHAR_BIT__, 1110 "not implemented for bitmasks larger than one ullong"); 1111 if constexpr (_NewSize == 1) 1112 // must sanitize because the return _Tp is bool 1113 return _SanitizedBitMask<1>(_M_bits[0] & (_Tp(1) << _DropLsb)); 1114 else 1115 return _BitMask<_NewSize, 1116 ((_NewSize + _DropLsb == sizeof(_Tp) * __CHAR_BIT__ 1117 && _NewSize + _DropLsb <= _Np) 1118 || ((_Sanitized || _Np == sizeof(_Tp) * __CHAR_BIT__) 1119 && _NewSize + _DropLsb >= _Np))>(_M_bits[0] 1120 >> _DropLsb); 1121 } 1122 1123 // True if all bits are set. Implicitly sanitizes if _Sanitized == false. 1124 constexpr bool 1125 all() const noexcept 1126 { 1127 if constexpr (_Np == 1) 1128 return _M_bits[0]; 1129 else if constexpr (!_Sanitized) 1130 return _M_sanitized().all(); 1131 else 1132 { 1133 constexpr _Tp __allbits = ~_Tp(); 1134 for (int __i = 0; __i < _S_array_size - 1; ++__i) 1135 if (_M_bits[__i] != __allbits) 1136 return false; 1137 return _M_bits[_S_array_size - 1] == _S_bitmask; 1138 } 1139 } 1140 1141 // True if at least one bit is set. Implicitly sanitizes if _Sanitized == 1142 // false. 1143 constexpr bool 1144 any() const noexcept 1145 { 1146 if constexpr (_Np == 1) 1147 return _M_bits[0]; 1148 else if constexpr (!_Sanitized) 1149 return _M_sanitized().any(); 1150 else 1151 { 1152 for (int __i = 0; __i < _S_array_size - 1; ++__i) 1153 if (_M_bits[__i] != 0) 1154 return true; 1155 return _M_bits[_S_array_size - 1] != 0; 1156 } 1157 } 1158 1159 // True if no bit is set. Implicitly sanitizes if _Sanitized == false. 1160 constexpr bool 1161 none() const noexcept 1162 { 1163 if constexpr (_Np == 1) 1164 return !_M_bits[0]; 1165 else if constexpr (!_Sanitized) 1166 return _M_sanitized().none(); 1167 else 1168 { 1169 for (int __i = 0; __i < _S_array_size - 1; ++__i) 1170 if (_M_bits[__i] != 0) 1171 return false; 1172 return _M_bits[_S_array_size - 1] == 0; 1173 } 1174 } 1175 1176 // Returns the number of set bits. Implicitly sanitizes if _Sanitized == 1177 // false. 1178 constexpr int 1179 count() const noexcept 1180 { 1181 if constexpr (_Np == 1) 1182 return _M_bits[0]; 1183 else if constexpr (!_Sanitized) 1184 return _M_sanitized().none(); 1185 else 1186 { 1187 int __result = __builtin_popcountll(_M_bits[0]); 1188 for (int __i = 1; __i < _S_array_size; ++__i) 1189 __result += __builtin_popcountll(_M_bits[__i]); 1190 return __result; 1191 } 1192 } 1193 1194 // Returns the bit at offset __i as bool. 1195 constexpr bool 1196 operator[](size_t __i) const noexcept 1197 { 1198 if constexpr (_Np == 1) 1199 return _M_bits[0]; 1200 else if constexpr (_S_array_size == 1) 1201 return (_M_bits[0] >> __i) & 1; 1202 else 1203 { 1204 const size_t __j = __i / (sizeof(_Tp) * __CHAR_BIT__); 1205 const size_t __shift = __i % (sizeof(_Tp) * __CHAR_BIT__); 1206 return (_M_bits[__j] >> __shift) & 1; 1207 } 1208 } 1209 1210 template
1211 constexpr bool 1212 operator[](_SizeConstant<__i>) const noexcept 1213 { 1214 static_assert(__i < _Np); 1215 constexpr size_t __j = __i / (sizeof(_Tp) * __CHAR_BIT__); 1216 constexpr size_t __shift = __i % (sizeof(_Tp) * __CHAR_BIT__); 1217 return static_cast
(_M_bits[__j] & (_Tp(1) << __shift)); 1218 } 1219 1220 // Set the bit at offset __i to __x. 1221 constexpr void 1222 set(size_t __i, bool __x) noexcept 1223 { 1224 if constexpr (_Np == 1) 1225 _M_bits[0] = __x; 1226 else if constexpr (_S_array_size == 1) 1227 { 1228 _M_bits[0] &= ~_Tp(_Tp(1) << __i); 1229 _M_bits[0] |= _Tp(_Tp(__x) << __i); 1230 } 1231 else 1232 { 1233 const size_t __j = __i / (sizeof(_Tp) * __CHAR_BIT__); 1234 const size_t __shift = __i % (sizeof(_Tp) * __CHAR_BIT__); 1235 _M_bits[__j] &= ~_Tp(_Tp(1) << __shift); 1236 _M_bits[__j] |= _Tp(_Tp(__x) << __shift); 1237 } 1238 } 1239 1240 template
1241 constexpr void 1242 set(_SizeConstant<__i>, bool __x) noexcept 1243 { 1244 static_assert(__i < _Np); 1245 if constexpr (_Np == 1) 1246 _M_bits[0] = __x; 1247 else 1248 { 1249 constexpr size_t __j = __i / (sizeof(_Tp) * __CHAR_BIT__); 1250 constexpr size_t __shift = __i % (sizeof(_Tp) * __CHAR_BIT__); 1251 constexpr _Tp __mask = ~_Tp(_Tp(1) << __shift); 1252 _M_bits[__j] &= __mask; 1253 _M_bits[__j] |= _Tp(_Tp(__x) << __shift); 1254 } 1255 } 1256 1257 // Inverts all bits. Sanitized input leads to sanitized output. 1258 constexpr _BitMask 1259 operator~() const noexcept 1260 { 1261 if constexpr (_Np == 1) 1262 return !_M_bits[0]; 1263 else 1264 { 1265 _BitMask __result{}; 1266 for (int __i = 0; __i < _S_array_size - 1; ++__i) 1267 __result._M_bits[__i] = ~_M_bits[__i]; 1268 if constexpr (_Sanitized) 1269 __result._M_bits[_S_array_size - 1] 1270 = _M_bits[_S_array_size - 1] ^ _S_bitmask; 1271 else 1272 __result._M_bits[_S_array_size - 1] = ~_M_bits[_S_array_size - 1]; 1273 return __result; 1274 } 1275 } 1276 1277 constexpr _BitMask& 1278 operator^=(const _BitMask& __b) & noexcept 1279 { 1280 __execute_n_times<_S_array_size>( 1281 [&](auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { _M_bits[__i] ^= __b._M_bits[__i]; }); 1282 return *this; 1283 } 1284 1285 constexpr _BitMask& 1286 operator|=(const _BitMask& __b) & noexcept 1287 { 1288 __execute_n_times<_S_array_size>( 1289 [&](auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { _M_bits[__i] |= __b._M_bits[__i]; }); 1290 return *this; 1291 } 1292 1293 constexpr _BitMask& 1294 operator&=(const _BitMask& __b) & noexcept 1295 { 1296 __execute_n_times<_S_array_size>( 1297 [&](auto __i) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { _M_bits[__i] &= __b._M_bits[__i]; }); 1298 return *this; 1299 } 1300 1301 friend constexpr _BitMask 1302 operator^(const _BitMask& __a, const _BitMask& __b) noexcept 1303 { 1304 _BitMask __r = __a; 1305 __r ^= __b; 1306 return __r; 1307 } 1308 1309 friend constexpr _BitMask 1310 operator|(const _BitMask& __a, const _BitMask& __b) noexcept 1311 { 1312 _BitMask __r = __a; 1313 __r |= __b; 1314 return __r; 1315 } 1316 1317 friend constexpr _BitMask 1318 operator&(const _BitMask& __a, const _BitMask& __b) noexcept 1319 { 1320 _BitMask __r = __a; 1321 __r &= __b; 1322 return __r; 1323 } 1324 1325 _GLIBCXX_SIMD_INTRINSIC 1326 constexpr bool 1327 _M_is_constprop() const 1328 { 1329 if constexpr (_S_array_size == 0) 1330 return __builtin_constant_p(_M_bits[0]); 1331 else 1332 { 1333 for (int __i = 0; __i < _S_array_size; ++__i) 1334 if (!__builtin_constant_p(_M_bits[__i])) 1335 return false; 1336 return true; 1337 } 1338 } 1339 }; 1340 1341 // }}} 1342 1343 // vvv ---- builtin vector types [[gnu::vector_size(N)]] and operations ---- vvv 1344 // __min_vector_size {{{ 1345 template
1346 static inline constexpr int __min_vector_size = 2 * sizeof(_Tp); 1347 1348 #if _GLIBCXX_SIMD_HAVE_NEON 1349 template <> 1350 inline constexpr int __min_vector_size
= 8; 1351 #else 1352 template <> 1353 inline constexpr int __min_vector_size
= 16; 1354 #endif 1355 1356 // }}} 1357 // __vector_type {{{ 1358 template
1359 struct __vector_type_n {}; 1360 1361 // substition failure for 0-element case 1362 template
1363 struct __vector_type_n<_Tp, 0, void> {}; 1364 1365 // special case 1-element to be _Tp itself 1366 template
1367 struct __vector_type_n<_Tp, 1, enable_if_t<__is_vectorizable_v<_Tp>>> 1368 { using type = _Tp; }; 1369 1370 // else, use GNU-style builtin vector types 1371 template
1372 struct __vector_type_n<_Tp, _Np, enable_if_t<__is_vectorizable_v<_Tp> && _Np >= 2>> 1373 { 1374 static constexpr size_t _S_Np2 = std::__bit_ceil(_Np * sizeof(_Tp)); 1375 1376 static constexpr size_t _S_Bytes = 1377 #ifdef __i386__ 1378 // Using [[gnu::vector_size(8)]] would wreak havoc on the FPU because 1379 // those objects are passed via MMX registers and nothing ever calls EMMS. 1380 _S_Np2 == 8 ? 16 : 1381 #endif 1382 _S_Np2 < __min_vector_size<_Tp> ? __min_vector_size<_Tp> 1383 : _S_Np2; 1384 1385 using type [[__gnu__::__vector_size__(_S_Bytes)]] = _Tp; 1386 }; 1387 1388 template
1389 struct __vector_type; 1390 1391 template
1392 struct __vector_type<_Tp, _Bytes, 0> 1393 : __vector_type_n<_Tp, _Bytes / sizeof(_Tp)> {}; 1394 1395 template
1396 using __vector_type_t = typename __vector_type_n<_Tp, _Size>::type; 1397 1398 template
1399 using __vector_type2_t = typename __vector_type<_Tp, 2>::type; 1400 template
1401 using __vector_type4_t = typename __vector_type<_Tp, 4>::type; 1402 template
1403 using __vector_type8_t = typename __vector_type<_Tp, 8>::type; 1404 template
1405 using __vector_type16_t = typename __vector_type<_Tp, 16>::type; 1406 template
1407 using __vector_type32_t = typename __vector_type<_Tp, 32>::type; 1408 template
1409 using __vector_type64_t = typename __vector_type<_Tp, 64>::type; 1410 1411 // }}} 1412 // __is_vector_type {{{ 1413 template
> 1414 struct __is_vector_type : false_type {}; 1415 1416 template
1417 struct __is_vector_type< 1418 _Tp, void_t
()[0])>, sizeof(_Tp)>::type>> 1420 : is_same<_Tp, typename __vector_type< 1421 remove_reference_t
()[0])>, 1422 sizeof(_Tp)>::type> {}; 1423 1424 template
1425 inline constexpr bool __is_vector_type_v = __is_vector_type<_Tp>::value; 1426 1427 // }}} 1428 // __is_intrinsic_type {{{ 1429 #if _GLIBCXX_SIMD_HAVE_SSE_ABI 1430 template
1431 using __is_intrinsic_type = __is_vector_type<_Tp>; 1432 #else // not SSE (x86) 1433 template
> 1434 struct __is_intrinsic_type : false_type {}; 1435 1436 template
1437 struct __is_intrinsic_type< 1438 _Tp, void_t
()[0])>, sizeof(_Tp)>::type>> 1440 : is_same<_Tp, typename __intrinsic_type< 1441 remove_reference_t
()[0])>, 1442 sizeof(_Tp)>::type> {}; 1443 #endif 1444 1445 template
1446 inline constexpr bool __is_intrinsic_type_v = __is_intrinsic_type<_Tp>::value; 1447 1448 // }}} 1449 // _VectorTraits{{{ 1450 template
> 1451 struct _VectorTraitsImpl; 1452 1453 template
1454 struct _VectorTraitsImpl<_Tp, enable_if_t<__is_vector_type_v<_Tp> 1455 || __is_intrinsic_type_v<_Tp>>> 1456 { 1457 using type = _Tp; 1458 using value_type = remove_reference_t
()[0])>; 1459 static constexpr int _S_full_size = sizeof(_Tp) / sizeof(value_type); 1460 using _Wrapper = _SimdWrapper
; 1461 template
1462 static constexpr bool _S_is 1463 = is_same_v
&& _W == _S_full_size; 1464 }; 1465 1466 template
1467 struct _VectorTraitsImpl<_SimdWrapper<_Tp, _Np>, 1468 void_t<__vector_type_t<_Tp, _Np>>> 1469 { 1470 using type = __vector_type_t<_Tp, _Np>; 1471 using value_type = _Tp; 1472 static constexpr int _S_full_size = sizeof(type) / sizeof(value_type); 1473 using _Wrapper = _SimdWrapper<_Tp, _Np>; 1474 static constexpr bool _S_is_partial = (_Np == _S_full_size); 1475 static constexpr int _S_partial_width = _Np; 1476 template
1477 static constexpr bool _S_is 1478 = is_same_v
&& _W == _S_full_size; 1479 }; 1480 1481 template
::type> 1482 using _VectorTraits = _VectorTraitsImpl<_Tp>; 1483 1484 // }}} 1485 // __as_vector{{{ 1486 template
1487 _GLIBCXX_SIMD_INTRINSIC constexpr auto 1488 __as_vector(_V __x) 1489 { 1490 if constexpr (__is_vector_type_v<_V>) 1491 return __x; 1492 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value) 1493 return __data(__x)._M_data; 1494 else if constexpr (__is_vectorizable_v<_V>) 1495 return __vector_type_t<_V, 2>{__x}; 1496 else 1497 return __x._M_data; 1498 } 1499 1500 // }}} 1501 // __as_wrapper{{{ 1502 template
1503 _GLIBCXX_SIMD_INTRINSIC constexpr auto 1504 __as_wrapper(_V __x) 1505 { 1506 if constexpr (__is_vector_type_v<_V>) 1507 return _SimdWrapper
::value_type, 1508 (_Np > 0 ? _Np : _VectorTraits<_V>::_S_full_size)>(__x); 1509 else if constexpr (is_simd<_V>::value || is_simd_mask<_V>::value) 1510 { 1511 static_assert(_V::size() == _Np); 1512 return __data(__x); 1513 } 1514 else 1515 { 1516 static_assert(_V::_S_size == _Np); 1517 return __x; 1518 } 1519 } 1520 1521 // }}} 1522 // __intrin_bitcast{{{ 1523 template
1524 _GLIBCXX_SIMD_INTRINSIC constexpr _To 1525 __intrin_bitcast(_From __v) 1526 { 1527 static_assert((__is_vector_type_v<_From> || __is_intrinsic_type_v<_From>) 1528 && (__is_vector_type_v<_To> || __is_intrinsic_type_v<_To>)); 1529 if constexpr (sizeof(_To) == sizeof(_From)) 1530 return reinterpret_cast<_To>(__v); 1531 else if constexpr (sizeof(_From) > sizeof(_To)) 1532 if constexpr (sizeof(_To) >= 16) 1533 return reinterpret_cast
&>(__v); 1534 else 1535 { 1536 _To __r; 1537 __builtin_memcpy(&__r, &__v, sizeof(_To)); 1538 return __r; 1539 } 1540 #if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__ 1541 else if constexpr (__have_avx && sizeof(_From) == 16 && sizeof(_To) == 32) 1542 return reinterpret_cast<_To>(__builtin_ia32_ps256_ps( 1543 reinterpret_cast<__vector_type_t
>(__v))); 1544 else if constexpr (__have_avx512f && sizeof(_From) == 16 1545 && sizeof(_To) == 64) 1546 return reinterpret_cast<_To>(__builtin_ia32_ps512_ps( 1547 reinterpret_cast<__vector_type_t
>(__v))); 1548 else if constexpr (__have_avx512f && sizeof(_From) == 32 1549 && sizeof(_To) == 64) 1550 return reinterpret_cast<_To>(__builtin_ia32_ps512_256ps( 1551 reinterpret_cast<__vector_type_t
>(__v))); 1552 #endif // _GLIBCXX_SIMD_X86INTRIN 1553 else if constexpr (sizeof(__v) <= 8) 1554 return reinterpret_cast<_To>( 1555 __vector_type_t<__int_for_sizeof_t<_From>, sizeof(_To) / sizeof(_From)>{ 1556 reinterpret_cast<__int_for_sizeof_t<_From>>(__v)}); 1557 else 1558 { 1559 static_assert(sizeof(_To) > sizeof(_From)); 1560 _To __r = {}; 1561 __builtin_memcpy(&__r, &__v, sizeof(_From)); 1562 return __r; 1563 } 1564 } 1565 1566 // }}} 1567 // __vector_bitcast{{{ 1568 template
, 1570 size_t _Np = _NN == 0 ? sizeof(_From) / sizeof(_To) : _NN> 1571 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_To, _Np> 1572 __vector_bitcast(_From __x) 1573 { 1574 using _R = __vector_type_t<_To, _Np>; 1575 return __intrin_bitcast<_R>(__x); 1576 } 1577 1578 template
) / sizeof(_To) : _NN> 1581 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_To, _Np> 1582 __vector_bitcast(const _SimdWrapper<_Tp, _Nx>& __x) 1583 { 1584 static_assert(_Np > 1); 1585 return __intrin_bitcast<__vector_type_t<_To, _Np>>(__x._M_data); 1586 } 1587 1588 // }}} 1589 // __convert_x86 declarations {{{ 1590 #ifdef _GLIBCXX_SIMD_WORKAROUND_PR85048 1591 template
> 1592 _To __convert_x86(_Tp); 1593 1594 template
> 1595 _To __convert_x86(_Tp, _Tp); 1596 1597 template
> 1598 _To __convert_x86(_Tp, _Tp, _Tp, _Tp); 1599 1600 template
> 1601 _To __convert_x86(_Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp); 1602 1603 template
> 1604 _To __convert_x86(_Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, _Tp, 1605 _Tp, _Tp, _Tp, _Tp); 1606 #endif // _GLIBCXX_SIMD_WORKAROUND_PR85048 1607 1608 //}}} 1609 // __bit_cast {{{ 1610 template
1611 _GLIBCXX_SIMD_INTRINSIC constexpr _To 1612 __bit_cast(const _From __x) 1613 { 1614 // TODO: implement with / replace by __builtin_bit_cast ASAP 1615 static_assert(sizeof(_To) == sizeof(_From)); 1616 constexpr bool __to_is_vectorizable 1617 = is_arithmetic_v<_To> || is_enum_v<_To>; 1618 constexpr bool __from_is_vectorizable 1619 = is_arithmetic_v<_From> || is_enum_v<_From>; 1620 if constexpr (__is_vector_type_v<_To> && __is_vector_type_v<_From>) 1621 return reinterpret_cast<_To>(__x); 1622 else if constexpr (__is_vector_type_v<_To> && __from_is_vectorizable) 1623 { 1624 using _FV [[__gnu__::__vector_size__(sizeof(_From))]] = _From; 1625 return reinterpret_cast<_To>(_FV{__x}); 1626 } 1627 else if constexpr (__to_is_vectorizable && __from_is_vectorizable) 1628 { 1629 using _TV [[__gnu__::__vector_size__(sizeof(_To))]] = _To; 1630 using _FV [[__gnu__::__vector_size__(sizeof(_From))]] = _From; 1631 return reinterpret_cast<_TV>(_FV{__x})[0]; 1632 } 1633 else if constexpr (__to_is_vectorizable && __is_vector_type_v<_From>) 1634 { 1635 using _TV [[__gnu__::__vector_size__(sizeof(_To))]] = _To; 1636 return reinterpret_cast<_TV>(__x)[0]; 1637 } 1638 else 1639 { 1640 _To __r; 1641 __builtin_memcpy(reinterpret_cast
(&__r), 1642 reinterpret_cast
(&__x), sizeof(_To)); 1643 return __r; 1644 } 1645 } 1646 1647 // }}} 1648 // __to_intrin {{{ 1649 template
, 1650 typename _R = __intrinsic_type_t
> 1651 _GLIBCXX_SIMD_INTRINSIC constexpr _R 1652 __to_intrin(_Tp __x) 1653 { 1654 static_assert(sizeof(__x) <= sizeof(_R), 1655 "__to_intrin may never drop values off the end"); 1656 if constexpr (sizeof(__x) == sizeof(_R)) 1657 return reinterpret_cast<_R>(__as_vector(__x)); 1658 else 1659 { 1660 using _Up = __int_for_sizeof_t<_Tp>; 1661 return reinterpret_cast<_R>( 1662 __vector_type_t<_Up, sizeof(_R) / sizeof(_Up)>{__bit_cast<_Up>(__x)}); 1663 } 1664 } 1665 1666 // }}} 1667 // __make_vector{{{ 1668 template
1669 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp, sizeof...(_Args)> 1670 __make_vector(const _Args&... __args) 1671 { return __vector_type_t<_Tp, sizeof...(_Args)>{static_cast<_Tp>(__args)...}; } 1672 1673 // }}} 1674 // __vector_broadcast{{{ 1675 template
1676 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp, _Np> 1677 __vector_broadcast_impl(_Tp __x, index_sequence<_I...>) 1678 { return __vector_type_t<_Tp, _Np>{((void)_I, __x)...}; } 1679 1680 template
1681 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp, _Np> 1682 __vector_broadcast(_Tp __x) 1683 { return __vector_broadcast_impl<_Np, _Tp>(__x, make_index_sequence<_Np>()); } 1684 1685 // }}} 1686 // __generate_vector{{{ 1687 template
1688 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp, _Np> 1689 __generate_vector_impl(_Gp&& __gen, index_sequence<_I...>) 1690 { return __vector_type_t<_Tp, _Np>{ static_cast<_Tp>(__gen(_SizeConstant<_I>()))...}; } 1691 1692 template
, typename _Gp> 1693 _GLIBCXX_SIMD_INTRINSIC constexpr _V 1694 __generate_vector(_Gp&& __gen) 1695 { 1696 if constexpr (__is_vector_type_v<_V>) 1697 return __generate_vector_impl
( 1699 static_cast<_Gp&&>(__gen), make_index_sequence<_VVT::_S_full_size>()); 1700 else 1701 return __generate_vector_impl
( 1703 static_cast<_Gp&&>(__gen), 1704 make_index_sequence<_VVT::_S_partial_width>()); 1705 } 1706 1707 template
1708 _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp, _Np> 1709 __generate_vector(_Gp&& __gen) 1710 { 1711 return __generate_vector_impl<_Tp, _Np>(static_cast<_Gp&&>(__gen), 1712 make_index_sequence<_Np>()); 1713 } 1714 1715 // }}} 1716 // __xor{{{ 1717 template
1718 _GLIBCXX_SIMD_INTRINSIC constexpr _TW 1719 __xor(_TW __a, _TW __b) noexcept 1720 { 1721 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>) 1722 { 1723 using _Tp = typename conditional_t<__is_simd_wrapper_v<_TW>, _TW, 1724 _VectorTraitsImpl<_TW>>::value_type; 1725 if constexpr (is_floating_point_v<_Tp>) 1726 { 1727 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>; 1728 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a) 1729 ^ __vector_bitcast<_Ip>(__b)); 1730 } 1731 else if constexpr (__is_vector_type_v<_TW>) 1732 return __a ^ __b; 1733 else 1734 return __a._M_data ^ __b._M_data; 1735 } 1736 else 1737 return __a ^ __b; 1738 } 1739 1740 // }}} 1741 // __or{{{ 1742 template
1743 _GLIBCXX_SIMD_INTRINSIC constexpr _TW 1744 __or(_TW __a, _TW __b) noexcept 1745 { 1746 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>) 1747 { 1748 using _Tp = typename conditional_t<__is_simd_wrapper_v<_TW>, _TW, 1749 _VectorTraitsImpl<_TW>>::value_type; 1750 if constexpr (is_floating_point_v<_Tp>) 1751 { 1752 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>; 1753 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a) 1754 | __vector_bitcast<_Ip>(__b)); 1755 } 1756 else if constexpr (__is_vector_type_v<_TW>) 1757 return __a | __b; 1758 else 1759 return __a._M_data | __b._M_data; 1760 } 1761 else 1762 return __a | __b; 1763 } 1764 1765 // }}} 1766 // __and{{{ 1767 template
1768 _GLIBCXX_SIMD_INTRINSIC constexpr _TW 1769 __and(_TW __a, _TW __b) noexcept 1770 { 1771 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>) 1772 { 1773 using _Tp = typename conditional_t<__is_simd_wrapper_v<_TW>, _TW, 1774 _VectorTraitsImpl<_TW>>::value_type; 1775 if constexpr (is_floating_point_v<_Tp>) 1776 { 1777 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>; 1778 return __vector_bitcast<_Tp>(__vector_bitcast<_Ip>(__a) 1779 & __vector_bitcast<_Ip>(__b)); 1780 } 1781 else if constexpr (__is_vector_type_v<_TW>) 1782 return __a & __b; 1783 else 1784 return __a._M_data & __b._M_data; 1785 } 1786 else 1787 return __a & __b; 1788 } 1789 1790 // }}} 1791 // __andnot{{{ 1792 #if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__ 1793 static constexpr struct 1794 { 1795 _GLIBCXX_SIMD_INTRINSIC __v4sf 1796 operator()(__v4sf __a, __v4sf __b) const noexcept 1797 { return __builtin_ia32_andnps(__a, __b); } 1798 1799 _GLIBCXX_SIMD_INTRINSIC __v2df 1800 operator()(__v2df __a, __v2df __b) const noexcept 1801 { return __builtin_ia32_andnpd(__a, __b); } 1802 1803 _GLIBCXX_SIMD_INTRINSIC __v2di 1804 operator()(__v2di __a, __v2di __b) const noexcept 1805 { return __builtin_ia32_pandn128(__a, __b); } 1806 1807 _GLIBCXX_SIMD_INTRINSIC __v8sf 1808 operator()(__v8sf __a, __v8sf __b) const noexcept 1809 { return __builtin_ia32_andnps256(__a, __b); } 1810 1811 _GLIBCXX_SIMD_INTRINSIC __v4df 1812 operator()(__v4df __a, __v4df __b) const noexcept 1813 { return __builtin_ia32_andnpd256(__a, __b); } 1814 1815 _GLIBCXX_SIMD_INTRINSIC __v4di 1816 operator()(__v4di __a, __v4di __b) const noexcept 1817 { 1818 if constexpr (__have_avx2) 1819 return __builtin_ia32_andnotsi256(__a, __b); 1820 else 1821 return reinterpret_cast<__v4di>( 1822 __builtin_ia32_andnpd256(reinterpret_cast<__v4df>(__a), 1823 reinterpret_cast<__v4df>(__b))); 1824 } 1825 1826 _GLIBCXX_SIMD_INTRINSIC __v16sf 1827 operator()(__v16sf __a, __v16sf __b) const noexcept 1828 { 1829 if constexpr (__have_avx512dq) 1830 return _mm512_andnot_ps(__a, __b); 1831 else 1832 return reinterpret_cast<__v16sf>( 1833 _mm512_andnot_si512(reinterpret_cast<__v8di>(__a), 1834 reinterpret_cast<__v8di>(__b))); 1835 } 1836 1837 _GLIBCXX_SIMD_INTRINSIC __v8df 1838 operator()(__v8df __a, __v8df __b) const noexcept 1839 { 1840 if constexpr (__have_avx512dq) 1841 return _mm512_andnot_pd(__a, __b); 1842 else 1843 return reinterpret_cast<__v8df>( 1844 _mm512_andnot_si512(reinterpret_cast<__v8di>(__a), 1845 reinterpret_cast<__v8di>(__b))); 1846 } 1847 1848 _GLIBCXX_SIMD_INTRINSIC __v8di 1849 operator()(__v8di __a, __v8di __b) const noexcept 1850 { return _mm512_andnot_si512(__a, __b); } 1851 } _S_x86_andnot; 1852 #endif // _GLIBCXX_SIMD_X86INTRIN && !__clang__ 1853 1854 template
1855 _GLIBCXX_SIMD_INTRINSIC constexpr _TW 1856 __andnot(_TW __a, _TW __b) noexcept 1857 { 1858 if constexpr (__is_vector_type_v<_TW> || __is_simd_wrapper_v<_TW>) 1859 { 1860 using _TVT = conditional_t<__is_simd_wrapper_v<_TW>, _TW, 1861 _VectorTraitsImpl<_TW>>; 1862 using _Tp = typename _TVT::value_type; 1863 #if _GLIBCXX_SIMD_X86INTRIN && !defined __clang__ 1864 if constexpr (sizeof(_TW) >= 16) 1865 { 1866 const auto __ai = __to_intrin(__a); 1867 const auto __bi = __to_intrin(__b); 1868 if (!__builtin_is_constant_evaluated() 1869 && !(__builtin_constant_p(__ai) && __builtin_constant_p(__bi))) 1870 { 1871 const auto __r = _S_x86_andnot(__ai, __bi); 1872 if constexpr (is_convertible_v
) 1873 return __r; 1874 else 1875 return reinterpret_cast
(__r); 1876 } 1877 } 1878 #endif // _GLIBCXX_SIMD_X86INTRIN 1879 using _Ip = make_unsigned_t<__int_for_sizeof_t<_Tp>>; 1880 return __vector_bitcast<_Tp>(~__vector_bitcast<_Ip>(__a) 1881 & __vector_bitcast<_Ip>(__b)); 1882 } 1883 else 1884 return ~__a & __b; 1885 } 1886 1887 // }}} 1888 // __not{{{ 1889 template
> 1890 _GLIBCXX_SIMD_INTRINSIC constexpr _Tp 1891 __not(_Tp __a) noexcept 1892 { 1893 if constexpr (is_floating_point_v
) 1894 return reinterpret_cast
( 1895 ~__vector_bitcast
(__a)); 1896 else 1897 return ~__a; 1898 } 1899 1900 // }}} 1901 // __concat{{{ 1902 template
, 1903 typename _R = __vector_type_t
> 1904 constexpr _R 1905 __concat(_Tp a_, _Tp b_) 1906 { 1907 #ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_1 1908 using _W 1909 = conditional_t
, double, 1910 conditional_t<(sizeof(_Tp) >= 2 * sizeof(long long)), 1911 long long, typename _TVT::value_type>>; 1912 constexpr int input_width = sizeof(_Tp) / sizeof(_W); 1913 const auto __a = __vector_bitcast<_W>(a_); 1914 const auto __b = __vector_bitcast<_W>(b_); 1915 using _Up = __vector_type_t<_W, sizeof(_R) / sizeof(_W)>; 1916 #else 1917 constexpr int input_width = _TVT::_S_full_size; 1918 const _Tp& __a = a_; 1919 const _Tp& __b = b_; 1920 using _Up = _R; 1921 #endif 1922 if constexpr (input_width == 2) 1923 return reinterpret_cast<_R>(_Up{__a[0], __a[1], __b[0], __b[1]}); 1924 else if constexpr (input_width == 4) 1925 return reinterpret_cast<_R>( 1926 _Up{__a[0], __a[1], __a[2], __a[3], __b[0], __b[1], __b[2], __b[3]}); 1927 else if constexpr (input_width == 8) 1928 return reinterpret_cast<_R>( 1929 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6], __a[7], 1930 __b[0], __b[1], __b[2], __b[3], __b[4], __b[5], __b[6], __b[7]}); 1931 else if constexpr (input_width == 16) 1932 return reinterpret_cast<_R>( 1933 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6], 1934 __a[7], __a[8], __a[9], __a[10], __a[11], __a[12], __a[13], 1935 __a[14], __a[15], __b[0], __b[1], __b[2], __b[3], __b[4], 1936 __b[5], __b[6], __b[7], __b[8], __b[9], __b[10], __b[11], 1937 __b[12], __b[13], __b[14], __b[15]}); 1938 else if constexpr (input_width == 32) 1939 return reinterpret_cast<_R>( 1940 _Up{__a[0], __a[1], __a[2], __a[3], __a[4], __a[5], __a[6], 1941 __a[7], __a[8], __a[9], __a[10], __a[11], __a[12], __a[13], 1942 __a[14], __a[15], __a[16], __a[17], __a[18], __a[19], __a[20], 1943 __a[21], __a[22], __a[23], __a[24], __a[25], __a[26], __a[27], 1944 __a[28], __a[29], __a[30], __a[31], __b[0], __b[1], __b[2], 1945 __b[3], __b[4], __b[5], __b[6], __b[7], __b[8], __b[9], 1946 __b[10], __b[11], __b[12], __b[13], __b[14], __b[15], __b[16], 1947 __b[17], __b[18], __b[19], __b[20], __b[21], __b[22], __b[23], 1948 __b[24], __b[25], __b[26], __b[27], __b[28], __b[29], __b[30], 1949 __b[31]}); 1950 } 1951 1952 // }}} 1953 // __zero_extend {{{ 1954 template
> 1955 struct _ZeroExtendProxy 1956 { 1957 using value_type = typename _TVT::value_type; 1958 static constexpr size_t _Np = _TVT::_S_full_size; 1959 const _Tp __x; 1960 1961 template
, 1962 typename 1963 = enable_if_t
>> 1964 _GLIBCXX_SIMD_INTRINSIC operator _To() const 1965 { 1966 constexpr size_t _ToN = _ToVT::_S_full_size; 1967 if constexpr (_ToN == _Np) 1968 return __x; 1969 else if constexpr (_ToN == 2 * _Np) 1970 { 1971 #ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_3 1972 if constexpr (__have_avx && _TVT::template _S_is
) 1973 return __vector_bitcast
( 1974 _mm256_insertf128_ps(__m256(), __x, 0)); 1975 else if constexpr (__have_avx && _TVT::template _S_is
) 1976 return __vector_bitcast
( 1977 _mm256_insertf128_pd(__m256d(), __x, 0)); 1978 else if constexpr (__have_avx2 && _Np * sizeof(value_type) == 16) 1979 return __vector_bitcast
( 1980 _mm256_insertf128_si256(__m256i(), __to_intrin(__x), 0)); 1981 else if constexpr (__have_avx512f && _TVT::template _S_is
) 1982 { 1983 if constexpr (__have_avx512dq) 1984 return __vector_bitcast
( 1985 _mm512_insertf32x8(__m512(), __x, 0)); 1986 else 1987 return reinterpret_cast<__m512>( 1988 _mm512_insertf64x4(__m512d(), 1989 reinterpret_cast<__m256d>(__x), 0)); 1990 } 1991 else if constexpr (__have_avx512f 1992 && _TVT::template _S_is
) 1993 return __vector_bitcast
( 1994 _mm512_insertf64x4(__m512d(), __x, 0)); 1995 else if constexpr (__have_avx512f && _Np * sizeof(value_type) == 32) 1996 return __vector_bitcast
( 1997 _mm512_inserti64x4(__m512i(), __to_intrin(__x), 0)); 1998 #endif 1999 return __concat(__x, _Tp()); 2000 } 2001 else if constexpr (_ToN == 4 * _Np) 2002 { 2003 #ifdef _GLIBCXX_SIMD_WORKAROUND_XXX_3 2004 if constexpr (__have_avx512dq && _TVT::template _S_is
) 2005 { 2006 return __vector_bitcast
( 2007 _mm512_insertf64x2(__m512d(), __x, 0)); 2008 } 2009 else if constexpr (__have_avx512f 2010 && is_floating_point_v
) 2011 { 2012 return __vector_bitcast
( 2013 _mm512_insertf32x4(__m512(), reinterpret_cast<__m128>(__x), 2014 0)); 2015 } 2016 else if constexpr (__have_avx512f && _Np * sizeof(value_type) == 16) 2017 { 2018 return __vector_bitcast
( 2019 _mm512_inserti32x4(__m512i(), __to_intrin(__x), 0)); 2020 } 2021 #endif 2022 return __concat(__concat(__x, _Tp()), 2023 __vector_type_t