-
Notifications
You must be signed in to change notification settings - Fork 281
Unify scalar, batch, and batch_bool in some places
#1205
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
base: master
Are you sure you want to change the base?
Conversation
- Add `batch_traits` that unifies traits for scalar, `batch`, and `batch_bool`. - Treat `batch_bool` as its own mask type. - `batch_cast` can now be used on `batch_bool` (because why not?) - Add casts for scalar types - Simplify `abs` implementation.
|
FWIW, the goal is to make it easier to write generic code that works on scalar and batch types. For instance, this enables something like: template <typename VecF, VecI, VecB>
VecF DoStuff(VecF fv, VecI iv, VecB cond) {
using F = typename batch_traits<VecF>::scalar_type;
auto cond_i = iv > 42;
return select(batch_cast<F>(cond_i) & cond, fv + batch_cast<F>(iv), 0.0));
}which can be used as Unifying template <typename Vec>
auto LoadSelect(bool *b, Vec x, Vec y) {
using VecB = typename batch_traits<Vec>::mask_type;
return select(VecB::load_unaligned(b), x, y);
}Tangentially related: I wonder if, in general, |
I like that!
I 'm not quite sure about this one. We currently have a conversion operator from |
|
True. Do you think it's better to allow implicit conversion between |
I'm not a big fan of this either :-/ |
|
I'll remove it from this PR; I think the other features are enough for what I want at the moment. The problem I'm trying to solve is that |
batch, and batch_bool in some places
|
Ok, |
| template <class A, class T, bool... Values> | ||
| XSIMD_INLINE batch_bool<T, A> select(batch_bool_constant<T, A, Values...> const&, batch_bool<T, A> const& true_br, batch_bool<T, A> const& false_br, requires_arch<common>) | ||
| { | ||
| return select<A>(batch_bool<T, A> { Values... }, true_br, false_br, A {}); |
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.
This seems sub-optimal in the case where we don't have access to a fast select, see https://godbolt.org/z/3GqaxTsbd
batch_traitsthat unifies traits for scalar,batch, andbatch_bool.batch_boolas its own mask type.select()forbatch_bool.absimplementation.