-
Notifications
You must be signed in to change notification settings - Fork 13.4k
SIMD for Rust #5841
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
SIMD for Rust #5841
Conversation
I'm ... generally uncomfortable with adding a new type for this. Feels like it ought to be possible with the existing type system. Will LLVM do the right thing if we just treat all small(ish) fixed-length vectors of appropriate types as the |
(otherwise great to see work on this!) |
As I understand, LLVM will scalarize vector types when SIMD is unavailable (see On the other hand, should operators be overloaded for all fixed-length vectors, or just small fixed-length vectors (of appropriate types)? I don't think it is desirable that |
Using an attribute is definitely possible (indeed, analogous to // In C
typedef float float4 __attribute__((ext_vector_type(4))); // As in C?
#[simd(4)]
type f32x4 = f32; // Or like this?
#[simd]
type f32x4 = [f32, ..4]; Using an attribute was useful in |
I also think it should be possible to vectorize struct, to form structures of arrays. I found Extending a C-like Language for Portable SIMD Programming (PPoPP 2012) interesting. |
Fascinating paper! I think it's beyond the scope of what we can get working in the 1.0 timeframe, honestly, but it is a promising looking extension to the language for ... some day. I think in the nearer term I'd prefer to approach this via a I don't think we have machinery to overload arithmetic on "all" fixed length vectors at the moment. I am not even sure if defining on any fixed length vectors will work well; I suspect the type system will try to borrow a slice and dispatch to an overload on It doesn't look like LLVM surfaces the entire repertoire of vector operations one might want to do in NEON or SSE; will we need to be putting bits of inline asm in the overloaded operators? |
Ok @graydon, I will reimplement this using |
I discussed with sanxiyn on IRC. The following transcript shows the discussion: https://botbot.me/irc.mozilla.org/rust/msg/2799234/ General consensus points:
|
When I tried to implement an attribute approach, I encountered the problem that attributes are attached to AST nodes, not types. Nominal types ( |
Can you use a "tuple struct" like |
Fix #3499.
This is a work in progress.
T ^ N
(temporary syntax) parses toast::ty_multi(@Ty, uint)
and converts toty::ty_multi(t, uint)
and lowers to LLVM SIMD vector type<n x t>
. Metadata support and reflection support are missing. There are minimal tests.Casting scalar to vector broadcasts, and element-wise vector arithmetics is implemented. There should be a way to load from vectors to SIMD vector (since terminology is confusing, let's call this "multi"), which needs design.
Some TODOs are OpenCL-style swizzling, type conversion, more SIMD operations (such as saturated arithmetics), etc.