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
I tried this code: (Playground). The random inputs are mostly just to keep the compiler fairly "honest" and block optimizing away the instructions it would use.
#![feature(repr_simd)]#![feature(platform_intrinsics)]use rand::random;#[derive(Debug)]#[repr(simd)]structf32x2(f32,f32);extern"platform-intrinsic"{fnsimd_shuffle2<T,U>(a:T,b:T,idx:[u32;2]) -> U;}fnmain(){let x = f32x2(rand::random(), rand::random());let y = f32x2(rand::random(), rand::random());let z:f32x2 = unsafe{simd_shuffle2(x, y,[0,2])};println!("Alignment is: {:?}", std::mem::align_of::<f32x2>());println!("Data is: {:?}", z);}
For best performance, the Streaming SIMD Extensions and Streaming SIMD Extensions 2 require their memory operands to be aligned to 16-byte boundaries.
Thus, I expected to see this happen:
Alignment is: 16
Data is: f32x2(0.12946808, 0.4856578)
Instead, this happened:
Alignment is: 8
Data is: f32x2(0.12946808, 0.4856578)
That does not appear to be the correct alignment to report for this type, unless I am misunderstanding something here.
I believe this is related to, but not exactly the same as, #27060. Apologies if this is a total duplicate, or if I am misunderstanding something here about what Rust means by "alignment", but after careful review with @calebzulawski, we started to arrive at the conclusion that something was off.
Here is the generated assembly, as you can see, it uses multiple SSE instructions, including movaps, an aligned load, but I haven't exhaustively analyzed it so I can't immediately tell if actual alignment requirements are being adhered to here and I am just spooked by the seemingly misleading information.
For note, here: having done some thought and research, it's not clear using a higher alignment is actually desired in practice. It may be the case that actually the desired alignment for vectors which do not precisely align to the machine's vector sizes is lower, around the element size (as if it were an array), possibly unless it uses a power of 2 element count (as it does here).
I tried this code: (Playground). The random inputs are mostly just to keep the compiler fairly "honest" and block optimizing away the instructions it would use.
Thus, I expected to see this happen:
Instead, this happened:
That does not appear to be the correct alignment to report for this type, unless I am misunderstanding something here.
Meta
rustc --version --verbose
:I believe this is related to, but not exactly the same as, #27060. Apologies if this is a total duplicate, or if I am misunderstanding something here about what Rust means by "alignment", but after careful review with @calebzulawski, we started to arrive at the conclusion that something was off.
Here is the generated assembly, as you can see, it uses multiple SSE instructions, including
movaps
, an aligned load, but I haven't exhaustively analyzed it so I can't immediately tell if actual alignment requirements are being adhered to here and I am just spooked by the seemingly misleading information.x86_64 Assembly
The text was updated successfully, but these errors were encountered: