Skip to content

Commit

Permalink
isqrt: assume that isqrt takes half as many bits
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoStra committed Sep 28, 2023
1 parent 77f9eae commit fcdfd5b
Showing 1 changed file with 7 additions and 0 deletions.
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

0 comments on commit fcdfd5b

Please sign in to comment.