pub struct Normalized2by1Divisor<T> { /* private fields */ }
Expand description

Divide a DoubleWord by a prearranged divisor.

Assumes quotient fits in a Word.

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

Implementations§

source§

impl Normalized2by1Divisor<u8>

source

pub const fn invert_word(divisor: u8) -> u8

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

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

source

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

Initialize from a given normalized divisor.

The divisor must have top bit of 1

source

pub const fn div_rem_1by1(&self, a: u8) -> (u8, u8)

Returns (a / divisor, a % divisor)

source

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

Returns (a / divisor, a % divisor) The result must fit in a single word.

source§

impl Normalized2by1Divisor<u16>

source

pub const fn invert_word(divisor: u16) -> u16

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

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

source

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

Initialize from a given normalized divisor.

The divisor must have top bit of 1

source

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

Returns (a / divisor, a % divisor)

source

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

Returns (a / divisor, a % divisor) The result must fit in a single word.

source§

impl Normalized2by1Divisor<u32>

source

pub const fn invert_word(divisor: u32) -> u32

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

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

source

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

Initialize from a given normalized divisor.

The divisor must have top bit of 1

source

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

Returns (a / divisor, a % divisor)

source

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

Returns (a / divisor, a % divisor) The result must fit in a single word.

source§

impl Normalized2by1Divisor<u64>

source

pub const fn invert_word(divisor: u64) -> u64

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

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

source

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

Initialize from a given normalized divisor.

The divisor must have top bit of 1

source

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

Returns (a / divisor, a % divisor)

source

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

Returns (a / divisor, a % divisor) The result must fit in a single word.

source§

impl Normalized2by1Divisor<usize>

source

pub const fn invert_word(divisor: usize) -> usize

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

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

source

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

Initialize from a given normalized divisor.

The divisor must have top bit of 1

source

pub const fn div_rem_1by1(&self, a: usize) -> (usize, usize)

Returns (a / divisor, a % divisor)

source

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

Returns (a / divisor, a % divisor) The result must fit in a single word.

Trait Implementations§

source§

impl<T: Clone> Clone for Normalized2by1Divisor<T>

source§

fn clone(&self) -> Normalized2by1Divisor<T>

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> Debug for Normalized2by1Divisor<T>

source§

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

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

impl<T: PartialEq> PartialEq<Normalized2by1Divisor<T>> for Normalized2by1Divisor<T>

source§

fn eq(&self, other: &Normalized2by1Divisor<T>) -> 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> Copy for Normalized2by1Divisor<T>

source§

impl<T: Eq> Eq for Normalized2by1Divisor<T>

source§

impl<T> StructuralEq for Normalized2by1Divisor<T>

source§

impl<T> StructuralPartialEq for Normalized2by1Divisor<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Normalized2by1Divisor<T>where T: RefUnwindSafe,

§

impl<T> Send for Normalized2by1Divisor<T>where T: Send,

§

impl<T> Sync for Normalized2by1Divisor<T>where T: Sync,

§

impl<T> Unpin for Normalized2by1Divisor<T>where T: Unpin,

§

impl<T> UnwindSafe for Normalized2by1Divisor<T>where 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.