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 copy_to_slice #331

Merged
merged 2 commits into from
Mar 11, 2023
Merged

Add copy_to_slice #331

merged 2 commits into from
Mar 11, 2023

Conversation

calebzulawski
Copy link
Member

Closes #324

// 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) }
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@workingjubilee workingjubilee left a 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!

@calebzulawski calebzulawski merged commit 8dcb4d5 into master Mar 11, 2023
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.

explicit simd store -- opposite of Simd::from_slice
3 participants