Open Shnatsel opened 3 months ago
"Using experimental, unstable, nightly-only features to get less unsafe implementation." That sounds a bit contradictory. :smile:
I looked through std::simd
a while back and didn't find some useful functions that I use in my implementation for certain SIMD instructions. For example I didn't find how to implement something like vld4_u8
instruction from NEON. This instruction loads multiple 4-element structures from memory and writes the result to the four SIMD registers, with de-interleaving.
It's not like the portable SIMD implementation is incomplete, it's just that the API stability is not guaranteed yet. That's the same situation in which TryFrom
lingered for years. There's nothing unsafe about either of those APIs.
For example I didn't find how to implement something like vld4_u8 instruction from NEON.
Ah, yes, that could be a problem. There might be a pattern of several higher-level operations that the compiler will recognize and optimize down into a single instruction. Or there might not. Gotta play around with godbolt and see.
There might be a pattern of several higher-level operations
I'm afraid there will be different patterns for different architectures. And these patterns may be unstable and change from one version of Rust to another.
I may try to do what you want, but I can't promise I'll do it soon. Right now I want to add support for multi-threading.
That's fair! I don't expect it will fully replace the existing handwritten SIMD for every platform. More like, it will provide something in between no simd at all and platform-specific unsafe intrinsics.
Thank you for considering this request!
The
std::simd
module provides a safe, portable API for SIMD. Together with themultiversion
crate it allows for SIMD that works from a single source file on every platform, and entirely in safe code!The drawback is that it is nightly-only, and still technically unstable despite not having changed in quite some time. It would be great to add support for it and expose this as an opt-in feature, e.g.
nightly-portable-simd
. While the platform coverage of this crate is already outstanding, this would allow people on nightly channel to use an implementation with less unsafe code.