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

pow: A dedicated function avoiding full-sized shift. #101

Open
github-actions bot opened this issue May 31, 2022 · 0 comments
Open

pow: A dedicated function avoiding full-sized shift. #101

github-actions bot opened this issue May 31, 2022 · 0 comments
Assignees
Labels
optimize Potential optimization opportunity tracker Issue tracked by bot

Comments

@github-actions
Copy link

On 2022-05-31 @recmo wrote in c1a0c34 “Merge pull request #97 from recmo/isqrt”:

A dedicated function avoiding full-sized shift.

        #[allow(clippy::cast_sign_loss)] // fract >= 0.
        let bits = (fract.exp2() * EXP2_63) as u64;
        // Note: If `fract` is zero this will result in `u64::MAX`.

        if shift >= 63 {
            // OPT: A dedicated function avoiding full-sized shift.
            Some(Self::try_from(bits).ok()?.checked_shl(shift - 63)?)
        } else {
            let shift = 63 - shift;
            // Divide `bits` by `2^shift`, rounding to nearest.
            let bits = (bits >> shift) + ((bits >> (shift - 1)) & 1);

From src/pow.rs:129

@github-actions github-actions bot added optimize Potential optimization opportunity tracker Issue tracked by bot labels May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimize Potential optimization opportunity tracker Issue tracked by bot
Projects
None yet
Development

No branches or pull requests

1 participant