vorner / slipstream

Nudging the compiler to auto-vectorize things
Apache License 2.0
71 stars 4 forks source link

Conversion to and from arrays #9

Closed HadrienG2 closed 1 year ago

HadrienG2 commented 1 year ago

It would be very nice to be able to convert slipstream vectors to and from matching array types using standard From impls, as allowed by most other SIMD libraries I've played with.

vorner commented 1 year ago

Aren't these already supported?

https://docs.rs/slipstream/latest/slipstream/vector/struct.Vector.html#method.new https://docs.rs/slipstream/latest/slipstream/vector/struct.Vector.html#method.store

Or, maybe I don't understand what you need here. Can you elaborate?

HadrienG2 commented 1 year ago

I meant having impl<A, T, N> From<[T; N]> for Vector<A, T, N> and impl<A, T, N> From<Vector<A, T, N>> for [T; N].

They can indeed be implemented in terms of existing methods but...

  1. Due to orphan rules, I cannot do it myself, so I either need to roll a newtype or a differently named from(), both of which are undesirable.
  2. Since these two existing methods use slices as input an output, I would be relying on compiler optimizer stars to align properly for bound check elision, whereas an implementation inside of slipstream can just load or store the Vector::data array member at ~guaranteed zero cost.
vorner commented 1 year ago

Again, no objection to these existing (unless they conflict with something in the crate already ‒ I wonder why I didn't put them in in the first place; but maybe it was because the crate started before const generics existed). But no time to implement them (you see how long it takes me just to get around responding :-( ).