@@ -39,6 +39,8 @@ template <class _Tp, int _Np>
3939struct __simd_storage <_Tp, simd_abi::__vec_ext<_Np>> {
4040 _Tp __data __attribute__ ((__vector_size__(std::__bit_ceil((sizeof (_Tp) * _Np)))));
4141
42+ static constexpr bool __is_partial_v = (_Np < (sizeof (__data) / sizeof (_Tp)));
43+
4244 _LIBCPP_HIDE_FROM_ABI _Tp __get (size_t __idx) const noexcept {
4345 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (__idx < _Np, " Index is out of bounds" );
4446 return __data[__idx];
@@ -47,6 +49,17 @@ struct __simd_storage<_Tp, simd_abi::__vec_ext<_Np>> {
4749 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (__idx < _Np, " Index is out of bounds" );
4850 __data[__idx] = __v;
4951 }
52+
53+ _LIBCPP_HIDE_FROM_ABI __simd_storage __make_padding_nonzero () const noexcept {
54+ __simd_storage __result = *this ;
55+ if constexpr (__is_partial_v) {
56+ constexpr size_t __full_size = sizeof (__data) / sizeof (_Tp);
57+ for (size_t __i = _Np; __i < __full_size; ++__i) {
58+ __result.__data [__i] = _Tp (1 );
59+ }
60+ }
61+ return __result;
62+ }
5063};
5164
5265template <class _Tp , int _Np>
@@ -97,6 +110,60 @@ struct __simd_operations<_Tp, simd_abi::__vec_ext<_Np>> {
97110 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __bitwise_not (_SimdStorage __s) noexcept { return {~__s.__data }; }
98111
99112 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __unary_minus (_SimdStorage __s) noexcept { return {-__s.__data }; }
113+
114+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __plus (_SimdStorage __lhs, _SimdStorage __rhs) noexcept {
115+ return {__lhs.__data + __rhs.__data };
116+ }
117+
118+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __minus (_SimdStorage __lhs, _SimdStorage __rhs) noexcept {
119+ return {__lhs.__data - __rhs.__data };
120+ }
121+
122+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __multiplies (_SimdStorage __lhs, _SimdStorage __rhs) noexcept {
123+ return {__lhs.__data * __rhs.__data };
124+ }
125+
126+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __divides (_SimdStorage __lhs, _SimdStorage __rhs) noexcept {
127+ if constexpr (!_SimdStorage::__is_partial_v)
128+ return {__lhs.__data / __rhs.__data };
129+ else
130+ return {__lhs.__data / __rhs.__make_padding_nonzero ().__data };
131+ }
132+
133+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __modulus (_SimdStorage __lhs, _SimdStorage __rhs) noexcept {
134+ if constexpr (!_SimdStorage::__is_partial_v)
135+ return {__lhs.__data % __rhs.__data };
136+ else
137+ return {__lhs.__data % __rhs.__make_padding_nonzero ().__data };
138+ }
139+
140+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __bitwise_and (_SimdStorage __lhs, _SimdStorage __rhs) noexcept {
141+ return {__lhs.__data & __rhs.__data };
142+ }
143+
144+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __bitwise_or (_SimdStorage __lhs, _SimdStorage __rhs) noexcept {
145+ return {__lhs.__data | __rhs.__data };
146+ }
147+
148+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __bitwise_xor (_SimdStorage __lhs, _SimdStorage __rhs) noexcept {
149+ return {__lhs.__data ^ __rhs.__data };
150+ }
151+
152+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __shift_left (_SimdStorage __lhs, _SimdStorage __rhs) noexcept {
153+ return {__lhs.__data << __rhs.__data };
154+ }
155+
156+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __shift_right (_SimdStorage __lhs, _SimdStorage __rhs) noexcept {
157+ return {__lhs.__data >> __rhs.__data };
158+ }
159+
160+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __shift_left (_SimdStorage __lhs, int __rhs) noexcept {
161+ return {__lhs.__data << __rhs};
162+ }
163+
164+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __shift_right (_SimdStorage __lhs, int __rhs) noexcept {
165+ return {__lhs.__data >> __rhs};
166+ }
100167};
101168
102169template <class _Tp , int _Np>
0 commit comments