View all comments
I tried this code:
#[derive(Clone, Copy, PartialEq)]
pub struct Foo {
pub x: u16,
pub y: u16,
}
#[no_mangle]
fn eq(a: &Foo, b: &Foo) -> bool {
a == b
}
I expected to see this happen: a and b are loaded into a single register each and then the registers are compared against each other.
Instead, this happened:
For -Copt-level=2:
eq:
movzx eax, word ptr [rdi]
movzx ecx, word ptr [rdi + 2]
xor ax, word ptr [rsi]
movzx edx, word ptr [rsi + 2]
xor edx, ecx
or dx, ax
sete al
ret
For -Copt-level=3:
eq:
movd xmm0, dword ptr [rdi]
movd xmm1, dword ptr [rsi]
pcmpeqw xmm1, xmm0
pshuflw xmm0, xmm1, 80
pshufd xmm0, xmm0, 80
movmskpd eax, xmm0
cmp eax, 3
sete al
ret
Meta
rustc --version --verbose:
Both 1.86 and nightly.
View all comments
I tried this code:
I expected to see this happen:
aandbare loaded into a single register each and then the registers are compared against each other.Instead, this happened:
For
-Copt-level=2:For
-Copt-level=3:Meta
rustc --version --verbose:Both 1.86 and nightly.