Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSIMD for Rust #5841
Conversation
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
(otherwise great to see work on this!) |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
Ok @graydon, I will reimplement this using |
This comment has been minimized.
This comment has been minimized.
|
I discussed with sanxiyn on IRC. The following transcript shows the discussion: https://botbot.me/irc.mozilla.org/rust/msg/2799234/ General consensus points:
|
This comment has been minimized.
This comment has been minimized.
|
When I tried to implement an attribute approach, I encountered the problem that attributes are attached to AST nodes, not types. Nominal types ( |
This comment has been minimized.
This comment has been minimized.
|
Can you use a "tuple struct" like |
sanxiyn commentedApr 11, 2013
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.