Skip to content
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

Fix mod_inv termination for the last iteration #103378

Merged
merged 1 commit into from
Nov 19, 2022

Commits on Oct 22, 2022

  1. Fix mod_inv termination for the last iteration

    On usize=u64 platforms, the 4th iteration would overflow the `mod_gate`
    back to 0. Similarly for usize=u32 platforms, the 3rd iteration would
    overflow much the same way.
    
    I tested various approaches to resolving this, including approaches with
    `saturating_mul` and `widening_mul` to a double usize. Turns out LLVM
    likes `mul_with_overflow` the best. In fact now, that LLVM can see the
    iteration count is limited, it will happily unroll the loop into a nice
    linear sequence.
    
    You will also notice that the code around the loop got simplified
    somewhat. Now that LLVM is handling the loop nicely, there isn’t any
    more reasons to manually unroll the first iteration out of the loop
    (though looking at the code today I’m not sure all that complexity was
    necessary in the first place).
    
    Fixes rust-lang#103361
    nagisa committed Oct 22, 2022
    Configuration menu
    Copy the full SHA
    a3c3f72 View commit details
    Browse the repository at this point in the history