Skip to content

Commit

Permalink
Merge branch 'main' into bytes-perf
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich authored Oct 13, 2023
2 parents c5a3788 + 23fc40f commit 4a6074d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,15 @@ impl<const BITS: usize, const LIMBS: usize> Shl<Self> for Uint<BITS, LIMBS> {
type Output = Self;

#[inline(always)]
fn shl(self, rhs: Uint<BITS, LIMBS>) -> Self::Output {
fn shl(self, rhs: Self) -> Self::Output {
// This check shortcuts, and prevents panics on the `[0]` later
if BITS == 0 {
return self;
}
// Rationale: if BITS is larger than 2**64 - 1, it means we're running
// on a 128-bit platform with 2.3 exabytes of memory. In this case,
// the code produces incorrect output.
#[allow(clippy::cast_possible_truncation)]
self.wrapping_shl(rhs.as_limbs()[0] as usize)
}
}
Expand All @@ -568,7 +569,7 @@ impl<const BITS: usize, const LIMBS: usize> Shl<&Self> for Uint<BITS, LIMBS> {
type Output = Self;

#[inline(always)]
fn shl(self, rhs: &Uint<BITS, LIMBS>) -> Self::Output {
fn shl(self, rhs: &Self) -> Self::Output {
self << *rhs
}
}
Expand All @@ -577,14 +578,15 @@ impl<const BITS: usize, const LIMBS: usize> Shr<Self> for Uint<BITS, LIMBS> {
type Output = Self;

#[inline(always)]
fn shr(self, rhs: Uint<BITS, LIMBS>) -> Self::Output {
fn shr(self, rhs: Self) -> Self::Output {
// This check shortcuts, and prevents panics on the `[0]` later
if BITS == 0 {
return self;
}
// Rationale: if BITS is larger than 2**64 - 1, it means we're running
// on a 128-bit platform with 2.3 exabytes of memory. In this case,
// the code produces incorrect output.
#[allow(clippy::cast_possible_truncation)]
self.wrapping_shl(rhs.as_limbs()[0] as usize)
}
}
Expand All @@ -593,7 +595,7 @@ impl<const BITS: usize, const LIMBS: usize> Shr<&Self> for Uint<BITS, LIMBS> {
type Output = Self;

#[inline(always)]
fn shr(self, rhs: &Uint<BITS, LIMBS>) -> Self::Output {
fn shr(self, rhs: &Self) -> Self::Output {
self >> *rhs
}
}
Expand Down

0 comments on commit 4a6074d

Please sign in to comment.