Small improvements
This commit is contained in:
parent
e7be3c5378
commit
c5840be1cb
@ -379,11 +379,24 @@ macro_rules! uint_overflowing_mul_reg {
|
|||||||
($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let mut res = $name::from(0u64);
|
let mut res = $name::from(0u64);
|
||||||
let mut overflow = false;
|
let mut overflow = false;
|
||||||
for i in 0..(2 * $n_words) {
|
|
||||||
let v = overflowing!($self_expr.overflowing_mul_u32(($other >> (32 * i)).low_u32()), overflow);
|
let mut current = $other;
|
||||||
let res2 = overflowing!(v.overflowing_shl(32 * i as u32), overflow);
|
let mut current_shift = 0;
|
||||||
res = overflowing!(res.overflowing_add(res2), overflow);
|
let mut current_u32;
|
||||||
|
let mut i = 0;
|
||||||
|
|
||||||
|
while i < 2*$n_words {
|
||||||
|
current_u32 = current.low_u32();
|
||||||
|
|
||||||
|
let v = overflowing!($self_expr.overflowing_mul_u32(current_u32), overflow);
|
||||||
|
let v_shifted = overflowing!(v.overflowing_shl(current_shift), overflow);
|
||||||
|
res = overflowing!(res.overflowing_add(v_shifted), overflow);
|
||||||
|
|
||||||
|
current = current >> 32;
|
||||||
|
current_shift += 32;
|
||||||
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(res, overflow)
|
(res, overflow)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -973,6 +986,7 @@ macro_rules! construct_uint {
|
|||||||
let mut ret = [0u64; $n_words];
|
let mut ret = [0u64; $n_words];
|
||||||
let word_shift = shift / 64;
|
let word_shift = shift / 64;
|
||||||
let bit_shift = shift % 64;
|
let bit_shift = shift % 64;
|
||||||
|
|
||||||
for i in word_shift..$n_words {
|
for i in word_shift..$n_words {
|
||||||
// Shift
|
// Shift
|
||||||
ret[i - word_shift] += original[i] >> bit_shift;
|
ret[i - word_shift] += original[i] >> bit_shift;
|
||||||
@ -989,9 +1003,11 @@ macro_rules! construct_uint {
|
|||||||
fn cmp(&self, other: &$name) -> Ordering {
|
fn cmp(&self, other: &$name) -> Ordering {
|
||||||
let &$name(ref me) = self;
|
let &$name(ref me) = self;
|
||||||
let &$name(ref you) = other;
|
let &$name(ref you) = other;
|
||||||
for i in 0..$n_words {
|
let mut i = $n_words;
|
||||||
if me[$n_words - 1 - i] < you[$n_words - 1 - i] { return Ordering::Less; }
|
while i > 0 {
|
||||||
if me[$n_words - 1 - i] > you[$n_words - 1 - i] { return Ordering::Greater; }
|
i -= 1;
|
||||||
|
if me[i] < you[i] { return Ordering::Less; }
|
||||||
|
if me[i] > you[i] { return Ordering::Greater; }
|
||||||
}
|
}
|
||||||
Ordering::Equal
|
Ordering::Equal
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user