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