Skip to content

Commit fcdfd5b

Browse files
committed
isqrt: assume that isqrt takes half as many bits
rust-lang#89273 (comment)
1 parent 77f9eae commit fcdfd5b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

library/core/src/num/uint_macros.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,13 @@ macro_rules! uint_impl {
20172017
one >>= 2;
20182018
}
20192019

2020+
// SAFETY: the result is positive and fits in an integer with half as many bits.
2021+
// Inform the optimizer about it.
2022+
unsafe {
2023+
intrinsics::assume(0 < res);
2024+
intrinsics::assume(res < 1 << (Self::BITS / 2));
2025+
}
2026+
20202027
res
20212028
}
20222029

0 commit comments

Comments
 (0)