From 35e4f2920458caa1d263340ccc4a1bfe685d7813 Mon Sep 17 00:00:00 2001 From: Erik Takke Date: Fri, 24 Jan 2025 16:35:54 +0100 Subject: [PATCH] Replace `Uint::overflowing_shr`; with `Uint::new_overflowing_shr` --- benches/uint.rs | 8 -------- src/uint/shr.rs | 23 ----------------------- 2 files changed, 31 deletions(-) diff --git a/benches/uint.rs b/benches/uint.rs index 63543797..b7adc922 100644 --- a/benches/uint.rs +++ b/benches/uint.rs @@ -403,14 +403,6 @@ fn bench_shr(c: &mut Criterion) { ) }); - group.bench_function("new shr, U2048", |b| { - b.iter_batched( - || U2048::ONE, - |x| x.new_overflowing_shr(1024 + 10), - BatchSize::SmallInput, - ) - }); - group.finish(); } diff --git a/src/uint/shr.rs b/src/uint/shr.rs index 4b2e720f..f1576d35 100644 --- a/src/uint/shr.rs +++ b/src/uint/shr.rs @@ -25,29 +25,6 @@ impl Uint { /// /// Returns `None` if `shift >= Self::BITS`. pub const fn overflowing_shr(&self, shift: u32) -> ConstCtOption { - // `floor(log2(BITS - 1))` is the number of bits in the representation of `shift` - // (which lies in range `0 <= shift < BITS`). - let shift_bits = u32::BITS - (Self::BITS - 1).leading_zeros(); - let overflow = ConstChoice::from_u32_lt(shift, Self::BITS).not(); - let shift = shift % Self::BITS; - let mut result = *self; - let mut i = 0; - while i < shift_bits { - let bit = ConstChoice::from_u32_lsb((shift >> i) & 1); - result = Uint::select( - &result, - &result - .overflowing_shr_vartime(1 << i) - .expect("shift within range"), - bit, - ); - i += 1; - } - - ConstCtOption::new(Uint::select(&result, &Self::ZERO, overflow), overflow.not()) - } - - pub const fn new_overflowing_shr(&self, shift: u32) -> ConstCtOption { let (intra_limb_shift, limb_shift) = (shift % Limb::BITS, shift / Limb::BITS); self.intra_limb_carrying_shr_internal(intra_limb_shift).full_limb_shr(limb_shift) }