Skip to content

Explore implementing SIMD types as arrays in the compiler #25

Closed
@workingjubilee

Description

@workingjubilee
Member

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

calebzulawski commented on Oct 6, 2020

@calebzulawski
Member

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

workingjubilee

workingjubilee commented on Oct 6, 2020

@workingjubilee
MemberAuthor

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

changed the title [-]Array -> SIMD Type conversions[/-] [+]Explore implementing SIMD types as arrays in the compiler[/+] on Oct 6, 2020
workingjubilee

workingjubilee commented on Oct 6, 2020

@workingjubilee
MemberAuthor

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

Lokathor commented on Oct 6, 2020

@Lokathor
Contributor

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

bjorn3 commented on Oct 6, 2020

@bjorn3
Member

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

workingjubilee

workingjubilee commented on Oct 6, 2020

@workingjubilee
MemberAuthor

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

workingjubilee

workingjubilee commented on Oct 6, 2020

@workingjubilee
MemberAuthor

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

workingjubilee

workingjubilee commented on Dec 4, 2020

@workingjubilee
MemberAuthor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @calebzulawski@Lokathor@bjorn3@workingjubilee

        Issue actions

          Explore implementing SIMD types as arrays in the compiler · Issue #25 · rust-lang/portable-simd