diff options
| author | Federico Stra <stra.federico@gmail.com> | 2023-09-28 13:59:19 +0200 |
|---|---|---|
| committer | Federico Stra <stra.federico@gmail.com> | 2023-09-28 14:05:10 +0200 |
| commit | fcdfd5b0b9efcf7797b0f1bf7e7ed47ff99de198 (patch) | |
| tree | 60814b918594017722c0e722a575f2214cbd220f | |
| parent | 77f9eae9956f6c7c23bdf81c2efdd47625382ea2 (diff) | |
| download | rust-fcdfd5b0b9efcf7797b0f1bf7e7ed47ff99de198.tar.gz rust-fcdfd5b0b9efcf7797b0f1bf7e7ed47ff99de198.zip | |
isqrt: `assume` that `isqrt` takes half as many bits
https://github.com/rust-lang/rust/issues/89273#issuecomment-970581089
| -rw-r--r-- | library/core/src/num/uint_macros.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 565fc1930ea..f2190efa4d3 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -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 } |
