Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/int/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl<const LIMBS: usize> Int<LIMBS> {
}

/// Perform addition, raising the `overflow` flag on overflow.
#[inline]
#[must_use]
pub const fn overflowing_add(&self, rhs: &Self) -> (Self, Choice) {
// Step 1. add operands
Expand All @@ -32,6 +33,7 @@ impl<const LIMBS: usize> Int<LIMBS> {
}

/// Perform wrapping addition, discarding overflow.
#[inline]
#[must_use]
pub const fn wrapping_add(&self, rhs: &Self) -> Self {
Self(self.0.wrapping_add(&rhs.0))
Expand Down
2 changes: 2 additions & 0 deletions src/int/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl<const LIMBS: usize> Int<LIMBS> {
/// negated when converted from [`Uint`] to [`Int`].
///
/// Note: even if `negate` is truthy, the magnitude might be zero!
#[inline]
#[must_use]
pub const fn widening_mul<const RHS_LIMBS: usize>(
&self,
Expand Down Expand Up @@ -95,6 +96,7 @@ impl<const LIMBS: usize> Int<LIMBS> {

/// Multiply `self` by `rhs`, wrapping the result in case of overflow.
/// This is equivalent to `(self * rhs) % (Uint::<LIMBS>::MAX + 1)`.
#[inline]
#[must_use]
pub const fn wrapping_mul<const RHS_LIMBS: usize>(&self, rhs: &Int<RHS_LIMBS>) -> Self {
if RHS_LIMBS >= LIMBS {
Expand Down
1 change: 1 addition & 0 deletions src/int/shl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ impl<const LIMBS: usize> Int<LIMBS> {
///
/// # Panics
/// - if `shift >= Self::BITS`.
#[inline]
#[must_use]
#[track_caller]
pub const fn shl(&self, shift: u32) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions src/int/shr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl<const LIMBS: usize> Int<LIMBS> {
/// If the shift exceeds the precision, returns
/// - `0` when `self` is non-negative, and
/// - `-1` when `self` is negative.
#[inline]
#[must_use]
pub const fn wrapping_shr(&self, shift: u32) -> Self {
self.shr(u32_rem(shift, Self::BITS))
Expand All @@ -124,6 +125,7 @@ impl<const LIMBS: usize> Int<LIMBS> {
/// NOTE: this operation is variable time with respect to `shift` *ONLY*.
///
/// When used with a fixed `shift`, this function is constant-time with respect to `self`.
#[inline]
#[must_use]
#[allow(clippy::integer_division_remainder_used, reason = "needs triage")]
pub const fn wrapping_shr_vartime(&self, shift: u32) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions src/int/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{Checked, CheckedSub, Choice, CtOption, Int, Sub, SubAssign, Wrapping
impl<const LIMBS: usize> Int<LIMBS> {
/// Perform subtraction, returning the result along with a [`Choice`] which `is_true`
/// only if the operation underflowed.
#[inline]
#[must_use]
pub const fn underflowing_sub(&self, rhs: &Self) -> (Self, Choice) {
// Step 1. subtract operands
Expand All @@ -27,6 +28,7 @@ impl<const LIMBS: usize> Int<LIMBS> {

/// Perform wrapping subtraction, discarding underflow and wrapping around the boundary of the
/// type.
#[inline]
#[must_use]
pub const fn wrapping_sub(&self, rhs: &Self) -> Self {
self.underflowing_sub(rhs).0
Expand Down
2 changes: 2 additions & 0 deletions src/limb/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ impl Limb {
}

/// Compute "wide" multiplication, with a product twice the size of the input.
#[inline]
pub(crate) const fn widening_mul(self, rhs: Self) -> (Self, Self) {
let (lo, hi) = widening_mul(self.0, rhs.0);
(Limb(lo), Limb(hi))
}

/// Compute "wide" squaring, with a product twice the size of the input.
#[inline]
pub(crate) const fn widening_square(self) -> (Self, Self) {
let (lo, hi) = widening_mul(self.0, self.0);
(Limb(lo), Limb(hi))
Expand Down
3 changes: 3 additions & 0 deletions src/uint/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ impl<const LIMBS: usize> Uint<LIMBS> {
}

/// Perform wrapping addition, discarding overflow.
#[inline]
#[must_use]
pub const fn wrapping_add(&self, rhs: &Self) -> Self {
self.carrying_add(rhs, Limb::ZERO).0
}

/// Computes `self + rhs + carry`, returning the result along with the new carry.
#[inline]
pub(crate) const fn overflowing_add_limb(&self, mut carry: Limb) -> (Self, Limb) {
let mut limbs = [Limb::ZERO; LIMBS];
let mut i = 0;
Expand All @@ -56,6 +58,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
}

/// Computes `self + rhs`, discarding overflow.
#[inline]
pub(crate) const fn wrapping_add_limb(&self, rhs: Limb) -> Self {
self.overflowing_add_limb(rhs).0
}
Expand Down
4 changes: 4 additions & 0 deletions src/uint/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
}

/// Perform wrapping multiplication, discarding overflow.
#[inline]
#[must_use]
pub const fn wrapping_mul<const RHS_LIMBS: usize>(&self, rhs: &Uint<RHS_LIMBS>) -> Self {
karatsuba::wrapping_mul_fixed::<LIMBS>(self.as_uint_ref(), rhs.as_uint_ref()).0
Expand Down Expand Up @@ -83,6 +84,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
}

/// Perform multiplication by a Limb, returning the wrapped result and a Limb overflow.
#[inline]
pub(crate) const fn overflowing_mul_limb(&self, rhs: Limb) -> (Self, Limb) {
let mut ret = [Limb::ZERO; LIMBS];
let mut i = 0;
Expand All @@ -95,6 +97,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
}

/// Perform wrapping multiplication by a Limb, discarding overflow.
#[inline]
pub(crate) const fn wrapping_mul_limb(&self, rhs: Limb) -> Self {
self.overflowing_mul_limb(rhs).0
}
Expand Down Expand Up @@ -135,6 +138,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
}

/// Perform wrapping square, discarding overflow.
#[inline]
#[must_use]
pub const fn wrapping_square(&self) -> Uint<LIMBS> {
karatsuba::wrapping_square_fixed(self.as_uint_ref()).0
Expand Down
1 change: 1 addition & 0 deletions src/uint/shr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
///
/// # Panics
/// - if the shift exceeds the upper bound.
#[inline]
#[must_use]
#[track_caller]
pub(crate) const fn bounded_shr_by_limbs(&self, shift: u32, shift_upper_bound: u32) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions src/uint/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {

/// Perform wrapping subtraction, returning the truthy value as the second element of
/// the tuple if an underflow has occurred.
#[inline]
#[must_use]
pub(crate) const fn conditional_borrowing_sub(
&self,
Expand Down Expand Up @@ -61,6 +62,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {

/// Perform wrapping subtraction, discarding underflow and wrapping around
/// the boundary of the type.
#[inline]
#[must_use]
pub const fn wrapping_sub(&self, rhs: &Self) -> Self {
self.borrowing_sub(rhs, Limb::ZERO).0
Expand Down
Loading