Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore implementing SIMD types as arrays in the compiler #25

Closed
workingjubilee opened this issue Oct 6, 2020 · 9 comments
Closed

Explore implementing SIMD types as arrays in the compiler #25

workingjubilee opened this issue Oct 6, 2020 · 9 comments

Comments

@workingjubilee
Copy link
Member

workingjubilee commented Oct 6, 2020

Instantiating SIMD types as tuple literals becomes absolutely hand-cramping when those structs become wider than 2~8 elements, and even 8 is getting a bit tiresome. CTFE is now powerful enough to significantly sugar some fairly nuanced array creation, e.g.:

const ARRAY: [i8; 32] = {
  let mut arr = [-128; 32];
  arr[27] = -62
  arr[30] = -31;
  arr[31] = -15;
  arr
};

By providing, at the very least, conversions from the obvious arrays into SIMD types, we can make a lot of things easier on ourselves, so that this can just be used with some kind of method like i8x32::from_array(ARRAY).

Because arrays are a much more natural fit, I would honestly like to explore "what compiler changes would be required to let #[repr(simd)] accept arrays straight-out?" but that may quickly become too complicated, so for now it is just a (very) nice-to-have and std::simd conversions can still exist. On the other hand, it might be pretty easy, and that might simplify the overall API for us immensely, so I should at least check.

@calebzulawski
Copy link
Member

The vectors should already implement From for conversions to and from arrays. Do we want named methods as well?

@workingjubilee
Copy link
Member Author

Doh.
I got confused because I saw you talking about as_array methods.

@workingjubilee workingjubilee reopened this Oct 6, 2020
@workingjubilee workingjubilee changed the title Array -> SIMD Type conversions Explore implementing SIMD types as arrays in the compiler Oct 6, 2020
@workingjubilee
Copy link
Member Author

OK I mean... should we? 👀

Leaving this open actually since I still want to go check up on this in the compiler proper, but it makes sense to have the issue here since really it's an API concern.

@workingjubilee workingjubilee reopened this Oct 6, 2020
@Lokathor
Copy link
Contributor

Lokathor commented Oct 6, 2020

so, from_array can be a temporary method, with the advantage that it can be const fn while a From impl cannot yet. However, i think that just a From impl might be cleaner in the long term, if traits will be allowed to have const impls any time at all soon.

@bjorn3
Copy link
Member

bjorn3 commented Oct 6, 2020

I believe I once saw a PR to accept arrays in #[repr(simd)], but I can't find it anymore.

@workingjubilee
Copy link
Member Author

That's really cool to hear!
I think this was rust-lang/rust#63531 perhaps?

@workingjubilee
Copy link
Member Author

Inlining this relevant link from that conversation: rust-lang/rust#5841 👀

@workingjubilee
Copy link
Member Author

rust-lang/rust#78863 implemented this! Nice!

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

No branches or pull requests

4 participants