You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some C compilers (clang and gcc at least) define unaligned vector types. Vectors are often read from unaligned locations, and then using and dereferencing a pointer to the normal vector types would be UB. Hence these types:
I think the first option runs into arrays technically not being FFI-safe. Option 2 is kind of cumbersome, so I'd like to explore option 3 using packed. The packed option can be a little weird, but I don't think that matters here. The whole purpose of this type is just to load the value, and then it'll likely just get transmuted to a proper vector type.
I can open this as an ACP if that is the proper route.
I checked with Jubilee and packed getting ignored is deliberate. So in effect I guess it's not possible today to have a type that is passed like a vector, but loaded/stored with an alignment of 1.
Activity
bjorn3 commentedon Jun 27, 2025
Does
#[repr(simd, packed(1))] struct __m128d_u([f64; 2])work? And is that compatible with the calling convention that Clang and GCC use?folkertdev commentedon Jun 27, 2025
Not sure, how would I test that?
I know that the plan is to eventually remove
repr(simd), that's why I left it out above.folkertdev commentedon Jun 29, 2025
based on
https://godbolt.org/z/W4Y1rrfc4
It does not, In fact, it looks like
packedhas no effect whatsoever and the load is still aligned to 16:The equivalent clang code does use an alignment of 1: https://godbolt.org/z/6MzTP3c6e
sayantn commentedon Jun 29, 2025
afaik currently
repr(simd)doesn't interact at all with otherreprs, includingpackedandalign. This might need some modifications in rustcfolkertdev commentedon Jun 29, 2025
I checked with Jubilee and
packedgetting ignored is deliberate. So in effect I guess it's not possible today to have a type that is passed like a vector, but loaded/stored with an alignment of 1.