Description
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.
Activity
calebzulawski commentedon Oct 6, 2020
The vectors should already implement From for conversions to and from arrays. Do we want named methods as well?
workingjubilee commentedon Oct 6, 2020
Doh.
I got confused because I saw you talking about
as_array
methods.[-]Array -> SIMD Type conversions[/-][+]Explore implementing SIMD types as arrays in the compiler[/+]workingjubilee commentedon Oct 6, 2020
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.
Lokathor commentedon 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 commentedon Oct 6, 2020
I believe I once saw a PR to accept arrays in
#[repr(simd)]
, but I can't find it anymore.workingjubilee commentedon Oct 6, 2020
That's really cool to hear!
I think this was rust-lang/rust#63531 perhaps?
Lokathor commentedon Oct 6, 2020
See also, https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Why.20is.20repr(simd).20only.20allowed.20on.20tuple.20structs.3F
workingjubilee commentedon Oct 6, 2020
Inlining this relevant link from that conversation: rust-lang/rust#5841 👀
workingjubilee commentedon Dec 4, 2020
rust-lang/rust#78863 implemented this! Nice!