num_modular

Struct Normalized3by2Divisor

Source
pub struct Normalized3by2Divisor<T, D> { /* private fields */ }
Expand description

Divide a 3-Word by a prearranged DoubleWord divisor.

Assumes quotient fits in a Word.

Möller, Granlund, “Improved division by invariant integers” Algorithm 5.

Implementations§

Source§

impl Normalized3by2Divisor<u8, u16>

Source

pub const fn invert_double_word(divisor: u16) -> u8

Calculate the inverse m > 0 of a normalized divisor (fit in a DoubleWord), such that

(m + B) * divisor = B^3 - k for some 1 <= k <= divisor

Möller, Granlund, “Improved division by invariant integers”, Algorithm 6.

Source

pub const fn new(divisor: u16) -> Self

Initialize from a given normalized divisor.

divisor must have top bit of 1

Source

pub const fn div_rem_2by2(&self, a: u16) -> (u16, u16)

Source

pub const fn div_rem_3by2(&self, a_lo: u8, a_hi: u16) -> (u8, u16)

The input a is arranged as (lo, mi & hi) The output is (a / divisor, a % divisor)

Source

pub const fn div_rem_4by2(&self, a_lo: u16, a_hi: u16) -> (u16, u16)

Divdide a 4-word number with double word divisor

The output is (a / divisor, a % divisor)

Source§

impl Normalized3by2Divisor<u16, u32>

Source

pub const fn invert_double_word(divisor: u32) -> u16

Calculate the inverse m > 0 of a normalized divisor (fit in a DoubleWord), such that

(m + B) * divisor = B^3 - k for some 1 <= k <= divisor

Möller, Granlund, “Improved division by invariant integers”, Algorithm 6.

Source

pub const fn new(divisor: u32) -> Self

Initialize from a given normalized divisor.

divisor must have top bit of 1

Source

pub const fn div_rem_2by2(&self, a: u32) -> (u32, u32)

Source

pub const fn div_rem_3by2(&self, a_lo: u16, a_hi: u32) -> (u16, u32)

The input a is arranged as (lo, mi & hi) The output is (a / divisor, a % divisor)

Source

pub const fn div_rem_4by2(&self, a_lo: u32, a_hi: u32) -> (u32, u32)

Divdide a 4-word number with double word divisor

The output is (a / divisor, a % divisor)

Source§

impl Normalized3by2Divisor<u32, u64>

Source

pub const fn invert_double_word(divisor: u64) -> u32

Calculate the inverse m > 0 of a normalized divisor (fit in a DoubleWord), such that

(m + B) * divisor = B^3 - k for some 1 <= k <= divisor

Möller, Granlund, “Improved division by invariant integers”, Algorithm 6.

Source

pub const fn new(divisor: u64) -> Self

Initialize from a given normalized divisor.

divisor must have top bit of 1

Source

pub const fn div_rem_2by2(&self, a: u64) -> (u64, u64)

Source

pub const fn div_rem_3by2(&self, a_lo: u32, a_hi: u64) -> (u32, u64)

The input a is arranged as (lo, mi & hi) The output is (a / divisor, a % divisor)

Source

pub const fn div_rem_4by2(&self, a_lo: u64, a_hi: u64) -> (u64, u64)

Divdide a 4-word number with double word divisor

The output is (a / divisor, a % divisor)

Source§

impl Normalized3by2Divisor<u64, u128>

Source

pub const fn invert_double_word(divisor: u128) -> u64

Calculate the inverse m > 0 of a normalized divisor (fit in a DoubleWord), such that

(m + B) * divisor = B^3 - k for some 1 <= k <= divisor

Möller, Granlund, “Improved division by invariant integers”, Algorithm 6.

Source

pub const fn new(divisor: u128) -> Self

Initialize from a given normalized divisor.

divisor must have top bit of 1

Source

pub const fn div_rem_2by2(&self, a: u128) -> (u128, u128)

Source

pub const fn div_rem_3by2(&self, a_lo: u64, a_hi: u128) -> (u64, u128)

The input a is arranged as (lo, mi & hi) The output is (a / divisor, a % divisor)

Source

pub const fn div_rem_4by2(&self, a_lo: u128, a_hi: u128) -> (u128, u128)

Divdide a 4-word number with double word divisor

The output is (a / divisor, a % divisor)

Source§

impl Normalized3by2Divisor<usize, u128>

Source

pub const fn invert_double_word(divisor: u128) -> usize

Calculate the inverse m > 0 of a normalized divisor (fit in a DoubleWord), such that

(m + B) * divisor = B^3 - k for some 1 <= k <= divisor

Möller, Granlund, “Improved division by invariant integers”, Algorithm 6.

Source

pub const fn new(divisor: u128) -> Self

Initialize from a given normalized divisor.

divisor must have top bit of 1

Source

pub const fn div_rem_2by2(&self, a: u128) -> (u128, u128)

Source

pub const fn div_rem_3by2(&self, a_lo: usize, a_hi: u128) -> (usize, u128)

The input a is arranged as (lo, mi & hi) The output is (a / divisor, a % divisor)

Source

pub const fn div_rem_4by2(&self, a_lo: u128, a_hi: u128) -> (u128, u128)

Divdide a 4-word number with double word divisor

The output is (a / divisor, a % divisor)

Trait Implementations§

Source§

impl<T: Clone, D: Clone> Clone for Normalized3by2Divisor<T, D>

Source§

fn clone(&self) -> Normalized3by2Divisor<T, D>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, D: Debug> Debug for Normalized3by2Divisor<T, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq, D: PartialEq> PartialEq for Normalized3by2Divisor<T, D>

Source§

fn eq(&self, other: &Normalized3by2Divisor<T, D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Copy, D: Copy> Copy for Normalized3by2Divisor<T, D>

Source§

impl<T: Eq, D: Eq> Eq for Normalized3by2Divisor<T, D>

Source§

impl<T, D> StructuralPartialEq for Normalized3by2Divisor<T, D>

Auto Trait Implementations§

§

impl<T, D> Freeze for Normalized3by2Divisor<T, D>
where D: Freeze, T: Freeze,

§

impl<T, D> RefUnwindSafe for Normalized3by2Divisor<T, D>

§

impl<T, D> Send for Normalized3by2Divisor<T, D>
where D: Send, T: Send,

§

impl<T, D> Sync for Normalized3by2Divisor<T, D>
where D: Sync, T: Sync,

§

impl<T, D> Unpin for Normalized3by2Divisor<T, D>
where D: Unpin, T: Unpin,

§

impl<T, D> UnwindSafe for Normalized3by2Divisor<T, D>
where D: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.