Skip to content

Implement swizzle_dyn_within_blocks, add tests#266

Merged
Shnatsel merged 6 commits into
linebender:mainfrom
Shnatsel:swizzle-within-blocks
Jul 5, 2026
Merged

Implement swizzle_dyn_within_blocks, add tests#266
Shnatsel merged 6 commits into
linebender:mainfrom
Shnatsel:swizzle-within-blocks

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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::simd swizzle_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 % len which should be faster than the branchy fallback in #265 and also more amenable to autovectorization on obscure platforms we don't have intrinsics for.

@Shnatsel Shnatsel requested a review from LaurenzV July 2, 2026 19:04
@Shnatsel Shnatsel enabled auto-merge July 2, 2026 19:28
@Shnatsel

Shnatsel commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

And just as I'm done placating Clippy, CI is stuck. Ugh.

@LaurenzV LaurenzV left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall!

Comment thread fearless_simd_gen/src/mk_simd_trait.rs Outdated
/// 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>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not just use Self::Bytes instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, you mean renaming it to Self::Bytes? I don't think this type exists right now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks again for the thorough review!

Comment thread fearless_simd_gen/src/ops.rs Outdated
Comment thread fearless_simd_tests/tests/harness/mod.rs Outdated
@Shnatsel Shnatsel added this pull request to the merge queue Jul 5, 2026
Merged via the queue into linebender:main with commit 5cccb41 Jul 5, 2026
22 checks passed
@Shnatsel Shnatsel deleted the swizzle-within-blocks branch July 5, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants