Skip to content

wrapping_{op} is not inlined in debug mode #82821

Closed
@Lokathor

Description

@Lokathor

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions