Skip to content

Make conversion to/from arrays generic - #286

Closed
Shnatsel wants to merge 3 commits into
linebender:mainfrom
Shnatsel:avoid-useless-codegen-for-arrays
Closed

Make conversion to/from arrays generic#286
Shnatsel wants to merge 3 commits into
linebender:mainfrom
Shnatsel:avoid-useless-codegen-for-arrays

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Move conversion to/from array into a separate trait, SimdArray. Unifies conversion handling between vectors and masks. SimdArrayRef with in-place conversions to references is added as an extension for vectors only (not masks).

In most cases store_array no longer needs the length to be explicitly qualified; in the few places where it is needed, it can be done through the usual turbofish synatx, same as From and TryFrom.

This improves generic programming:

  • Generic code can now convert to/from arrays
  • Native-width types such as S::f32s can now be converted to/from arrays

Despite N now living in SimdArray, it is still accessible through SimdBase through supertrait relationship.

Pairs well with #285 which makes arrays more useful in general. Also conflicts with it, but c'est la vie, I'll resolve conflicts in one when the other lands.

This also drops 204 code-generated wrappers around various safe transmute functions, reducing the size of the generated code.

Shnatsel added 3 commits July 27, 2026 14:13
…Move array element and other metadata from SimdBase to SimdArray. This unifies conversion to/from arrays between SIMD vectors and masks.
@LaurenzV

Copy link
Copy Markdown
Collaborator

Looks nice in principle, but we should benchmark to make sure it doesn't cause regressions. It has happened before that changing how arrays are loaded/stored resulted in differences.

@Shnatsel

Copy link
Copy Markdown
Contributor Author

I tried converting Vello to this and ended up disliking how this ends up getting used in practice.

Being able to load and store masks and vectors without knowing which one it is just isn't very useful, but it makes the docs harder to navigate and requires changes to the existing user code in some cases (<Self as SimdBase<_>>::from_slice(simd, slice) now needs to be rewritten as <Self as SimdArray<_>>::from_slice(simd, slice), extra trait to import if not using the prelude).

I think the upsides of this can be achieved without requiring code changes from users, and without complicating and fragmenting the trait hierarchy. I'll experiment with that.

@Shnatsel
Shnatsel marked this pull request as draft July 28, 2026 22:48
@Shnatsel

Copy link
Copy Markdown
Contributor Author

Closing in favor of #292

@Shnatsel Shnatsel closed this Jul 29, 2026
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

Successfully merging this pull request may close these issues.

2 participants