#[allow(unused_macros)]
macro_rules! impl_normalization_shift {
(
$name:ident, // name of the normalization shift function
// boolean for if `$uX::leading_zeros` should be used (if an architecture does not have a
// hardware instruction for `usize::leading_zeros`, then this should be `true`)
$use_lz:ident,
$n:tt, $uX:ident, $iX:ident, $($unsigned_attr:meta),* ) => {
$(
#[$unsigned_attr]
)*
fn $name(duo: $uX, div: $uX, full_normalization: bool) -> usize {
let mut shl: usize;
if $use_lz {
shl = (div.leading_zeros() - duo.leading_zeros()) as usize;
if full_normalization {
if duo < (div << shl) {
shl -= 1;
}
}
} else {
let mut test = duo;
shl = 0usize;
let mut lvl = $n >> 1;
loop {
let tmp = test >> lvl;
if div <= tmp {
test = tmp;
shl += lvl;
}
lvl >>= 1;
if lvl == 0 {
break
}
}
}
shl
}
}
}