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

Simd<A> has the same layout and ABI as A #332

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joshlf
Copy link

@joshlf joshlf commented Sep 13, 2021

This will allow code to depend on Simd's layout. My specific use case is to emit impls of FromBytes and AsBytes for zerocopy so that other crates can safely transmute Simd instances.

@workingjubilee
Copy link
Member

workingjubilee commented Oct 3, 2021

This patch is incorrect.

Simd<A> is at risk of having different alignment (a property of layout) or being handled differently in parameter passing (a property of ABI). We can only promise that, on the stack, Simd<A> is safe to convert to A, but that doesn't change the alignment difference, so it is not safe to reverse that. It has also been a while since I have looked at how this crate handles masks, so I feel reluctant to promise anything regarding that.

@joshlf
Copy link
Author

joshlf commented Oct 3, 2021 via email

@workingjubilee
Copy link
Member

Hmm. This kind of thing is why #[repr(transparent)] needs to be specially marked: a struct with one field, versus a value with a type matching that field, may be passed and given different positions on the stack based on ABI details...

Can you elaborate a little more on the details of this use-case so I know exactly what sort of transformation, where, and when? I would like to know more exactly what I am promising. I looked at the crate but did not fully understand all the conversions you were offering.

@workingjubilee
Copy link
Member

By the time you read this message, the Simd<T, N> and Mask<T, N> types will hopefully be available in std::simd, with #![feature(portable_simd)]. We took a different route with that module: our Mask is an opaque type. By separating the concern of masks out, we are prepared to make stronger promises about the repr of Simd, as a result, such that Simd<T, N> should be equivalent to [T; N] with a more... variable alignment... the standard caveats re: parameter passing still apply, thus it is not "exactly equivalent in ABI", but in-memory it should be consistent, as far as we are aware. This is still technically what one might consider an "implementation detail" and thus subject to change, but we are... aspiring to this being the case.

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