-
Notifications
You must be signed in to change notification settings - Fork 82
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 copy_to_slice #331
Add copy_to_slice #331
Conversation
e449630
to
0fd7c8e
Compare
// Safety: | ||
// - We've checked the length is sufficient | ||
// - `T` and `Simd<T, N>` are Copy types. | ||
unsafe { slice.as_mut_ptr().cast::<Self>().write_unaligned(self) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the simd type has padding (e.g. for non-power-of-2 types where #319 isn't fixed yet)?
imho we should add an assert that the simd type and corresponding array type have the same size, otherwise write_unaligned
is permitted to overwrite after-the-end elements with undef
padding -- unsound. panicking is better than UB and the assert will never fire once #319 is fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, you might want an explicit Copy
bound since we might add Simd<&mut _, _>
support -- which isn't Copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point about the padding. I think I'll leave out the Copy
bound for because basically every one of Simd
's associated functions fail if the element isn't Copy
, that would probably need a much more significant overhaul.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda want the name to be something like copy_into
, but maybe that makes it too generic-sounding??? Otherwise seems cool though!
Closes #324