Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Lokathor opened this issue Mar 6, 2021 · 1 comment
Closed

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

Lokathor opened this issue Mar 6, 2021 · 1 comment

Comments

@Lokathor
Copy link
Contributor

Lokathor commented Mar 6, 2021

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

@nagisa
Copy link
Member

nagisa commented Mar 7, 2021

Duplicate of #75598

@nagisa nagisa marked this as a duplicate of #75598 Mar 7, 2021
@nagisa nagisa closed this as completed Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants