unroll first iter of checked_ilog loop to save one multiplication · model-checking/verify-rust-std@ad38f9b (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Commit ad38f9b
unroll first iter of checked_ilog loop to save one multiplication
File tree
1 file changed
lines changed
1 file changed
lines changed
Lines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1093,9 +1093,12 @@ macro_rules! uint_impl { | ||
1093 | 1093 | pub const fn checked_ilog(self, base: Self) -> Option<u32> { |
1094 | 1094 | if self <= 0 | |
1095 | 1095 | None |
1096 | +} else if self < base { | |
1097 | +Some(0) | |
1096 | 1098 | } else { |
1097 | -let mut n = 0; | |
1098 | -let mut r = 1; | |
1099 | +// Since base >= self, n >= 1 | |
1100 | +let mut n = 1; | |
1101 | +let mut r = base; | |
1099 | 1102 | |
1100 | 1103 | // Optimization for 128 bit wide integers. |
1101 | 1104 | if Self::BITS == 128 { |