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

Add "integer square root" method to integer primitive types #116176

Merged
merged 10 commits into from
Sep 29, 2023
Prev Previous commit
Next Next commit
isqrt: assume that isqrt takes half as many bits
  • Loading branch information
FedericoStra committed Sep 28, 2023
commit fcdfd5b0b9efcf7797b0f1bf7e7ed47ff99de198
7 changes: 7 additions & 0 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,13 @@ macro_rules! uint_impl {
one >>= 2;
}

// SAFETY: the result is positive and fits in an integer with half as many bits.
// Inform the optimizer about it.
unsafe {
intrinsics::assume(0 < res);
intrinsics::assume(res < 1 << (Self::BITS / 2));
}

res
}

Expand Down
Loading