Skip to content

Commit

Permalink
Replace Uint::overflowing_shr; with Uint::new_overflowing_shr
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-3milabs committed Jan 24, 2025
1 parent 6fdf08b commit a0afa4b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 31 deletions.
8 changes: 0 additions & 8 deletions benches/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,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();
}

Expand Down
23 changes: 0 additions & 23 deletions src/uint/shr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,6 @@ impl<const LIMBS: usize> Uint<LIMBS> {
///
/// Returns `None` if `shift >= Self::BITS`.
pub const fn overflowing_shr(&self, shift: u32) -> ConstCtOption<Self> {
// `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<Self> {
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)
Expand Down

0 comments on commit a0afa4b

Please sign in to comment.