unroll first iter of checked_ilog loop to save one multiplication · model-checking/verify-rust-std@ad38f9b

Skip to content

Navigation Menu

Sign in

Appearance settings

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Commit ad38f9b

committed

unroll first iter of checked_ilog loop to save one multiplication

1 parent 7a3093a commit ad38f9b

File tree

1 file changed

+

5

-

2

lines changed

1 file changed

+

5

-

2

lines changed

Lines changed: 5 additions & 2 deletions

Original file line numberDiff line numberDiff line change

@@ -1093,9 +1093,12 @@ macro_rules! uint_impl {

10931093

pub const fn checked_ilog(self, base: Self) -> Option<u32> {

10941094

if self <= 0 || base <= 1 {

10951095

None

1096+

} else if self < base {

1097+

Some(0)

10961098

} 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;

10991102
11001103

// Optimization for 128 bit wide integers.

11011104

if Self::BITS == 128 {

0 commit comments

Comments

 (0)