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<Normalized3by2Divisor<T, D>> for Normalized3by2Divisor<T, D>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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> StructuralEq for Normalized3by2Divisor<T, D>

source§

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

Auto Trait Implementations§

§

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

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.