Skip to content

128-bit integer division with remainder is not combined to a single operation #44545

Open
@henninglive

Description

@henninglive

Rustc fails to combine div() and mod() operations with u128 to a single division with remainder on x64. The following code compiles down to separate calls to __udivti3() and __umodti3() when we would prefer a single call to __udivmodti4().

#![feature(i128_type, i128, test)]
extern crate test;

#[inline(never)]
fn divmod_u128(a: u128, b: u128) -> (u128, u128) {
    (a / b, a % b)
}

fn main() {
    println!("{:?}", divmod_u128(std::u128::MAX, test::black_box(1000)));
}

Related to #39078.
Relevant in the Display implementation for i128 and u128.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions