Skip to content

Add interleave method#206

Merged
LaurenzV merged 15 commits intolinebender:mainfrom
Shnatsel:interleave
Apr 18, 2026
Merged

Add interleave method#206
LaurenzV merged 15 commits intolinebender:mainfrom
Shnatsel:interleave

Conversation

@Shnatsel
Copy link
Copy Markdown
Contributor

@Shnatsel Shnatsel commented Apr 12, 2026

Adds a new method with API matching std::simd's interleave method.

The primary motivation is performance: on AVX2, zip_low followed by zip_high requires 6 instructions, while a combined interleave function only needs 4 instructions. (With AVX-512 we'd be able to to do it in 2 instructions on 256-bit vectors, but that's not supported by fearless_simd yet and #201 seems stalled).

This also improves API compatibility with std::simd as a nice bonus.

AI use disclosure: this work was assisted by Claude Opus 4.5 for the initial commit and 4.6 for the rest. I have manually reviewed the code and take full responsibility for it.

@LaurenzV LaurenzV self-requested a review April 13, 2026 04:44
@Shnatsel
Copy link
Copy Markdown
Contributor Author

I'm seeing non-trivial improvements from this, up to 8% end-to-end for my FFT implementation, so I'd really appreciate this getting reviewed and published as a point release.

@LaurenzV
Copy link
Copy Markdown
Collaborator

Haven't forgotten about this, just haven't gotten to it yet. Will try to do soon, if no one else gets to it before me.

@LaurenzV LaurenzV changed the title Add interleave() matching std::simd API, faster than zip_low/zip_high on AVX2 Add interleave method Apr 18, 2026
Comment on lines +844 to +857
pub(crate) fn handle_deinterleave(
&self,
method_sig: TokenStream,
vec_ty: &VecType,
) -> TokenStream {
let unzip_low = generic_op_name("unzip_low", vec_ty);
let unzip_high = generic_op_name("unzip_high", vec_ty);
quote! {
#method_sig {
(self.#unzip_low(a, b), self.#unzip_high(a, b))
}
}
}

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.

WHy canw e not apply the same optimization for deinterleave?

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.

That's an oversight on my part. I was focused on interleaving, since that's the hot path in my code, and forgot to optimize deinterleave. I'll do so shortly.

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.

It's not big deal, I was just wondering.

Copy link
Copy Markdown
Collaborator

@LaurenzV LaurenzV left a comment

Choose a reason for hiding this comment

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

Seems fine to me, since no one else has commented I presume no one has any objections. Thanks!

@LaurenzV LaurenzV added this pull request to the merge queue Apr 18, 2026
Merged via the queue into linebender:main with commit 8fcafea Apr 18, 2026
22 checks passed
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