I read in the documentation that LaneCount and SupportedLaneCount can be used to retrieve the maximum lane count supported by the current CPU and use it as the total SIMD lanes. I want to use them to set the chunk size portable, but when I tried, both of them were not found
I've tried importing the prelude, but the result is still the same. How do I actually use those?
It looks like the docs currently show the source for the 2026-01-19 nightly. However, Rust Playground uses a more recent nightly (2026-02-04, currently); presumably it's always the latest nightly.
You'd probably want to look through the source on the rust-lang/rust repo; here's a starting point: https://github.com/rust-lang/rust/blob/main/library/portable-simd/crates/core_simd/src/mod.rs
I'm looking through the source right now.
Edit: this is the PR that removed them: #151775
Edit: it looks like any N is valid for a lane count now...? Yeah, on Rust Playground, Simd<u8, 1000000> is a valid type (when it previously only allowed up to 64 lanes). That would explain why SupportedLaneCount (and LaneCount) are gone.
Further edit: Ah, that's probably because it now leads to post-monomorphization errors. And an ICE, apparently: Rust Playground (The actual limit is still 64 lanes, I think.)
1 Like
So is there currently no way to get the lane length supported by the current CPU?
My use case is like this
fn a<T, const N: usize>(input: &[T], target: T) -> bool
where T: SimdElement + PartialEq,
LaneCount<N>: SupportedLaneCount
{
let (chunks, remainder) = input.as_chunks::<N>();
The chunks will adapt to the lanes supported by the CPU and the data type. For instance, if there are 32 lanes and the data type is 1 byte (like u8), N will be 32. If the data type is 4 bytes (like i32), the lanes will be 8. If another computer supports larger lanes, it will automatically scale up instead of using 32 lanes setting without editing any code
Is there any other way to do this?
I think the intent of portable-simd seems to be that the SIMD operations work regardless of the CPU's supported lane length - keep in mind that SupportedLaneCount meant "this lane count is supported by portable-simd", not necessarily "by the CPU", so that wouldn't have helped you either.
I'm not sure what the performance of excessively-high lane counts is, it's outside my area of expertise. If it makes an impact, it looks like you'd need to use cfgs and runtime feature detection (see std::arch - Rust). I think it's still more ergonomic to choose a single N parameter based on architecture instead of using per-architecture SIMD intrinsics, though.
1 Like
Thank you! It is solved now
I use that macros + std::mem::size_of