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

Add as_array to SimdValue? #66

Open
RReverser opened this issue Feb 18, 2025 · 2 comments
Open

Add as_array to SimdValue? #66

RReverser opened this issue Feb 18, 2025 · 2 comments

Comments

@RReverser
Copy link

Often it would be convenient to be able to cast the entire SIMD value to an array reference instead of extracting lanes one by one, in a generic code over any SimdValue.

As far as I can tell, all implementations of SimdValue should be able to support this - AutoSimd<[T; N]> has array easily accessed via .0, primitives can be casted via std::slice::from_ref, num_complex::Complex has repr(C) compatible with [T; 2], std::simd-based implementation has its own as_array, and wide-based implementation has as_array_ref.

With that in mind, can we add as_array to SimdValue trait itself to make writing generic code easier?

@tilpner
Copy link

tilpner commented Feb 19, 2025

As far as I can tell, this already fails at trying to add as_array to the SimdValue trait, because the return type [Self::Element; Self::LANES] would require the rustc feature generic_const_exprs. And if you add an associated type and fill it in as an array via macro impls, you can't make use of the array in a generic context.

@RReverser
Copy link
Author

Oh, the name is misleading, I meant for it to just return slice. I should have called it as_slice.

Proper arrays would be nice too, but I agree not feasible at the moment.

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

2 participants