Implement swizzle_dyn_within_blocks, add tests#266
Conversation
|
And just as I'm done placating Clippy, CI is stuck. Ugh. |
| /// A 128-bit SIMD vector of the same scalar type. | ||
| type Block: SimdBase<S, Element = Self::Element>; | ||
| /// A same-width byte vector used to dynamically index bytes in this vector. | ||
| type Indices: SimdBase<S, Element = u8>; |
There was a problem hiding this comment.
Could we not just use Self::Bytes instead?
There was a problem hiding this comment.
To clarify, you mean renaming it to Self::Bytes? I don't think this type exists right now.
There was a problem hiding this comment.
SimdBase requires the type to implement the Bytes trait, which has the Bytes type that basically does the same as the Indices type you introduced, I think. But maybe it's still worth keeping them separately for semantic reasons.
There was a problem hiding this comment.
Ah! You are correct.
No, it's not worth keeping them separate. Even the scalable SIMD on SVE and RISC-V is only defined up to 2048 bytes in length, which is still fully addressable with u8 indices even for general swizzles.
There was a problem hiding this comment.
Done. Thanks again for the thorough review!
This addresses my criticism of #265
This maps to cheap hardware instructions on x86 and also maps really well to split+combine on blocks on NEON and WASM, so unlike #265 this can be implemented for all widths.
The API follows the
std::simdswizzle_dyn, which uses byte-level index vectors. This also makes the implementation really straightforward, since everything is treated as byte vectors internally, so it's implemented for all types too.The scalar fallback is branch-free thanks to
% lenwhich should be faster than the branchy fallback in #265 and also more amenable to autovectorization on obscure platforms we don't have intrinsics for.