-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add gather/scatter methods for simd #27
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,6 +395,15 @@ template <typename _Tp, typename _Abi0, typename... _Abis> | |
return second.template _M_simd_at<_Np - 1>(); | ||
} | ||
|
||
template <size_t _Offset> | ||
_GLIBCXX_SIMD_INTRINSIC constexpr auto _M_tuple_at() const | ||
{ | ||
if constexpr (_Offset == 0) | ||
return first; | ||
else | ||
return second.template _M_tuple_at<_Offset - simd_size_v<_Tp, _Abi0>>(); | ||
} | ||
|
||
Comment on lines
+398
to
+406
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the name I expected it to do the same as |
||
template <size_t _Offset = 0, typename _Fp> | ||
_GLIBCXX_SIMD_INTRINSIC static constexpr _SimdTuple | ||
_S_generate(_Fp&& __gen, _SizeConstant<_Offset> = {}) | ||
|
@@ -1331,6 +1340,56 @@ template <int _Np> | |
}); | ||
} | ||
|
||
// _S_gather {{{2 | ||
template <typename _Tp, typename _Up> | ||
static inline _SimdMember<_Tp> | ||
_S_gather(const _Up* __mem, const __int_for_sizeof_t<_Up>* __idx, | ||
_TypeTag<_Tp>) noexcept | ||
{ | ||
return _SimdMember<_Tp>::_S_generate([&](auto __meta) { | ||
return __meta._S_gather(__mem, &__idx[__meta._S_offset], | ||
_TypeTag<_Tp>()); | ||
}); | ||
} | ||
|
||
// _S_gather {{{2 | ||
template <typename _Tp, typename _Up> | ||
static inline _SimdMember<_Tp> | ||
_S_gather(const _Up* __mem, const _SimdMember<_Tp>& __idx, | ||
_TypeTag<_Tp>) noexcept | ||
{ | ||
return _SimdMember<_Tp>::_S_generate([&](auto __meta) { | ||
return __meta._S_gather( | ||
__mem, __idx.template _M_tuple_at<__meta._S_offset>(), | ||
_TypeTag<_Tp>()); | ||
}); | ||
} | ||
Comment on lines
+1356
to
+1366
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you intend the types like this? I.e. the |
||
|
||
// _S_scatter {{{2 | ||
template <typename _Tp, typename _Up> | ||
static inline void | ||
_S_scatter(const _SimdMember<_Tp>& __v, _Up* __mem, | ||
const __int_for_sizeof_t<_Up>* __idx, _TypeTag<_Tp>) noexcept | ||
{ | ||
__for_each(__v, [&](auto __meta, auto __native) { | ||
__meta._S_scatter(__native, __mem, &__idx[__meta._S_offset], | ||
_TypeTag<_Tp>()); | ||
}); | ||
} | ||
|
||
// _S_scatter {{{2 | ||
template <typename _Tp, typename _Up> | ||
static inline void | ||
_S_scatter(const _SimdMember<_Tp>& __v, _Up* __mem, | ||
const _SimdMember<_Tp>& __idx, _TypeTag<_Tp>) noexcept | ||
Comment on lines
+1383
to
+1384
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same type question as above. Did you want different types for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I try to support different types in the following manner, but it seems that is not best way after reading our comments. |
||
{ | ||
__for_each(__v, __idx, | ||
[&](auto __meta, auto __v_tuple, auto __idx_tuple) { | ||
__meta._S_scatter(__v_tuple, __mem, __idx_tuple, | ||
_TypeTag<_Tp>()); | ||
}); | ||
} | ||
|
||
// _S_load {{{2 | ||
template <typename _Tp, typename _Up> | ||
static inline _SimdMember<_Tp> _S_load(const _Up* __mem, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simd
. Turning an array into simd isn't too hard. And the expectation for gather & scatter is that indexes are computed viasimd
objects._Flags
parameter is unnecessary. I'd drop it.constexpr
scale parameter has been useful in Vc 1. I'm not sure whether we want it as public API at some point, though.I also just implemented a complete
_S_gather
implementation for_SimdImplX86
(AVX512 and AVX2) and fallback in_SimdImplBuiltin
. I didn't implement anything else, because I only use it internally to implement a lookup table for mystd::exp(simd)
implementation. It's not pushed anywhere yet. But I'm closing in on getting the patch ready.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you have implemented _S_gather, will I work based on your implementation be better?