Closed
Description
The wrapping operations for numbers, such as wrapping_mul
for u32 or i32, are marked #[inline]
instead of #[inline(always)]
. This gives them bad performance in debug builds.
#[inline(always)]
pub fn a(x: u32, y: u32) -> u32 {
x.wrapping_mul(y)
}
pub fn b(x: u32, y: u32) -> u32 {
a(x.wrapping_add(3), y.wrapping_add(2))
}
Output:
example::b:
sub rsp, 24
mov eax, 3
mov dword ptr [rsp + 20], esi
mov esi, eax
call core::num::<impl u32>::wrapping_add
mov dword ptr [rsp + 16], eax
mov edi, dword ptr [rsp + 20]
mov esi, 2
call core::num::<impl u32>::wrapping_add
mov dword ptr [rsp + 12], eax
mov edi, dword ptr [rsp + 16]
mov esi, dword ptr [rsp + 12]
call core::num::<impl u32>::wrapping_mul
mov dword ptr [rsp + 8], eax
mov eax, dword ptr [rsp + 8]
add rsp, 24
ret
1.50.0: https://rust.godbolt.org/z/b6T1eM
Nightly: https://rust.godbolt.org/z/6oMebd
Metadata
Metadata
Assignees
Labels
No labels