25 #ifndef _GLIBCXX_EXPERIMENTAL_SIMD_PPC_H_
26 #define _GLIBCXX_EXPERIMENTAL_SIMD_PPC_H_
28 #if __cplusplus >= 201703L
31 #error "simd_ppc.h may only be included when AltiVec/VMX is available"
35 _GLIBCXX_SIMD_BEGIN_NAMESPACE
38 template <
typename _Abi,
typename>
39 struct _SimdImplPpc : _SimdImplBuiltin<_Abi>
41 using _Base = _SimdImplBuiltin<_Abi>;
49 template <
typename _Tp,
size_t _Np>
50 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
51 _S_bit_shift_left(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
53 __x = _Base::_S_bit_shift_left(__x, __y);
54 if constexpr (
sizeof(_Tp) <
sizeof(
int))
56 = (__y._M_data <
sizeof(_Tp) * __CHAR_BIT__) & __x._M_data;
60 template <
typename _Tp,
size_t _Np>
61 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
62 _S_bit_shift_left(_SimdWrapper<_Tp, _Np> __x,
int __y)
64 __x = _Base::_S_bit_shift_left(__x, __y);
65 if constexpr (
sizeof(_Tp) <
sizeof(
int))
67 if (__y >=
sizeof(_Tp) * __CHAR_BIT__)
75 template <
typename _Tp,
size_t _Np>
76 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
77 _S_bit_shift_right(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
79 if constexpr (
sizeof(_Tp) <
sizeof(
int))
81 constexpr
int __nbits =
sizeof(_Tp) * __CHAR_BIT__;
82 if constexpr (is_unsigned_v<_Tp>)
83 return (__y._M_data < __nbits)
84 & _Base::_S_bit_shift_right(__x, __y)._M_data;
87 _Base::_S_masked_assign(_SimdWrapper<_Tp, _Np>(__y._M_data
90 return _Base::_S_bit_shift_right(__x, __y);
94 return _Base::_S_bit_shift_right(__x, __y);
97 template <
typename _Tp,
size_t _Np>
98 _GLIBCXX_SIMD_INTRINSIC
static constexpr _SimdWrapper<_Tp, _Np>
99 _S_bit_shift_right(_SimdWrapper<_Tp, _Np> __x,
int __y)
101 if constexpr (
sizeof(_Tp) <
sizeof(
int))
103 constexpr
int __nbits =
sizeof(_Tp) * __CHAR_BIT__;
106 if constexpr (is_unsigned_v<_Tp>)
109 return _Base::_S_bit_shift_right(__x, __nbits - 1);
112 return _Base::_S_bit_shift_right(__x, __y);
120 template <
typename _Abi,
typename>
121 struct _MaskImplPpc : _MaskImplBuiltin<_Abi>
123 using _Base = _MaskImplBuiltin<_Abi>;
126 template <
typename _Tp>
127 _GLIBCXX_SIMD_INTRINSIC
static int _S_popcount(simd_mask<_Tp, _Abi> __k)
129 const auto __kv = __as_vector(__k);
130 if constexpr (__have_power10vec)
132 return vec_cntm(__to_intrin(__kv), 1);
134 else if constexpr (
sizeof(_Tp) >=
sizeof(
int))
136 using _Intrin = __intrinsic_type16_t<int>;
137 const int __sum = -vec_sums(__intrin_bitcast<_Intrin>(__kv), _Intrin())[3];
138 return __sum / (
sizeof(_Tp) /
sizeof(
int));
142 const auto __summed_to_int = vec_sum4s(__to_intrin(__kv), __intrinsic_type16_t<int>());
143 return -vec_sums(__summed_to_int, __intrinsic_type16_t<int>())[3];
152 _GLIBCXX_SIMD_END_NAMESPACE