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>
impl Normalized2by1Divisor<u8>
Sourcepub const fn invert_word(divisor: u8) -> u8
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
Sourcepub const fn new(divisor: u8) -> Self
pub const fn new(divisor: u8) -> Self
Initialize from a given normalized divisor.
The divisor must have top bit of 1
Sourcepub const fn div_rem_1by1(&self, a: u8) -> (u8, u8)
pub const fn div_rem_1by1(&self, a: u8) -> (u8, u8)
Returns (a / divisor, a % divisor)
Sourcepub const fn div_rem_2by1(&self, a: u16) -> (u8, u8)
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>
impl Normalized2by1Divisor<u16>
Sourcepub const fn invert_word(divisor: u16) -> u16
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
Sourcepub const fn new(divisor: u16) -> Self
pub const fn new(divisor: u16) -> Self
Initialize from a given normalized divisor.
The divisor must have top bit of 1
Sourcepub const fn div_rem_1by1(&self, a: u16) -> (u16, u16)
pub const fn div_rem_1by1(&self, a: u16) -> (u16, u16)
Returns (a / divisor, a % divisor)
Sourcepub const fn div_rem_2by1(&self, a: u32) -> (u16, u16)
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>
impl Normalized2by1Divisor<u32>
Sourcepub const fn invert_word(divisor: u32) -> u32
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
Sourcepub const fn new(divisor: u32) -> Self
pub const fn new(divisor: u32) -> Self
Initialize from a given normalized divisor.
The divisor must have top bit of 1
Sourcepub const fn div_rem_1by1(&self, a: u32) -> (u32, u32)
pub const fn div_rem_1by1(&self, a: u32) -> (u32, u32)
Returns (a / divisor, a % divisor)
Sourcepub const fn div_rem_2by1(&self, a: u64) -> (u32, u32)
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>
impl Normalized2by1Divisor<u64>
Sourcepub const fn invert_word(divisor: u64) -> u64
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
Sourcepub const fn new(divisor: u64) -> Self
pub const fn new(divisor: u64) -> Self
Initialize from a given normalized divisor.
The divisor must have top bit of 1
Sourcepub const fn div_rem_1by1(&self, a: u64) -> (u64, u64)
pub const fn div_rem_1by1(&self, a: u64) -> (u64, u64)
Returns (a / divisor, a % divisor)
Sourcepub const fn div_rem_2by1(&self, a: u128) -> (u64, u64)
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>
impl Normalized2by1Divisor<usize>
Sourcepub const fn invert_word(divisor: usize) -> usize
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
Sourcepub const fn new(divisor: usize) -> Self
pub const fn new(divisor: usize) -> Self
Initialize from a given normalized divisor.
The divisor must have top bit of 1
Sourcepub const fn div_rem_1by1(&self, a: usize) -> (usize, usize)
pub const fn div_rem_1by1(&self, a: usize) -> (usize, usize)
Returns (a / divisor, a % divisor)
Sourcepub const fn div_rem_2by1(&self, a: u128) -> (usize, usize)
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>
impl<T: Clone> Clone for Normalized2by1Divisor<T>
Source§fn clone(&self) -> Normalized2by1Divisor<T>
fn clone(&self) -> Normalized2by1Divisor<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more