[ci skip] flush

This commit is contained in:
Nikolay Volf 2016-02-25 19:58:09 +03:00
parent 2ee4a0c8c6
commit 600859ed04

View File

@ -165,7 +165,7 @@ macro_rules! uint_overflowing_mul {
let self_t: &[u64; 4] = unsafe { &mem::transmute($self_expr) }; let self_t: &[u64; 4] = unsafe { &mem::transmute($self_expr) };
let other_t: &[u64; 4] = unsafe { &mem::transmute($other) }; let other_t: &[u64; 4] = unsafe { &mem::transmute($other) };
let overflow: u8; let overflow: u64;
unsafe { unsafe {
asm!(" asm!("
mov $5, %rax mov $5, %rax
@ -227,20 +227,20 @@ macro_rules! uint_overflowing_mul {
mov $8, %rax mov $8, %rax
cmpq $$0, %rax cmpq $$0, %rax
sete %cl setne %cl
mov $7, %rax mov $7, %rax
cmpq $$0, %rax cmpq $$0, %rax
sete %dl setne %dl
or %dl, %cl or %dl, %cl
mov $3, %rax mov $3, %rax
cmpq $$0, %rax cmpq $$0, %rax
sete %dl setne %dl
mov $2, %rax mov $2, %rax
cmpq $$0, %rax cmpq $$0, %rax
sete %bl setne %bl
or %bl, %dl or %bl, %dl
and %dl, %cl and %dl, %cl
@ -253,7 +253,7 @@ macro_rules! uint_overflowing_mul {
: /* $5 */ "m"(self_t[0]), /* $6 */ "m"(self_t[1]), /* $7 */ "m"(self_t[2]), : /* $5 */ "m"(self_t[0]), /* $6 */ "m"(self_t[1]), /* $7 */ "m"(self_t[2]),
/* $8 */ "m"(self_t[3]), /* $9 */ "m"(other_t[0]), /* $10 */ "m"(other_t[1]), /* $8 */ "m"(self_t[3]), /* $9 */ "m"(other_t[0]), /* $10 */ "m"(other_t[1]),
/* $11 */ "m"(other_t[2]), /* $12 */ "m"(other_t[3]) /* $11 */ "m"(other_t[2]), /* $12 */ "m"(other_t[3])
: "rax", "rdx" : "rax", "rdx", "rbx"
: :
); );
@ -740,23 +740,8 @@ macro_rules! construct_uint {
type Output = $name; type Output = $name;
fn add(self, other: $name) -> $name { fn add(self, other: $name) -> $name {
let $name(ref me) = self; let (result, _) = self.overflowing_add(other);
let $name(ref you) = other; result
let mut ret = [0u64; $n_words];
let mut carry = [0u64; $n_words];
let mut b_carry = false;
for i in 0..$n_words {
if i < $n_words - 1 {
ret[i] = me[i].wrapping_add(you[i]);
if ret[i] < me[i] {
carry[i + 1] = 1;
b_carry = true;
}
} else {
ret[i] = me[i] + you[i];
}
}
if b_carry { $name(ret) + $name(carry) } else { $name(ret) }
} }
} }
@ -765,8 +750,7 @@ macro_rules! construct_uint {
#[inline] #[inline]
fn sub(self, other: $name) -> $name { fn sub(self, other: $name) -> $name {
let (result, overflow) = self.overflowing_sub(other); let (result, _) = self.overflowing_sub(other);
panic_on_overflow!(overflow);
result result
} }
} }
@ -775,15 +759,9 @@ macro_rules! construct_uint {
type Output = $name; type Output = $name;
fn mul(self, other: $name) -> $name { fn mul(self, other: $name) -> $name {
let mut res = $name::from(0u64); let (result, overflow) = self.overflowing_mul(other);
// TODO: be more efficient about this
for i in 0..(2 * $n_words) {
let v = self.mul_u32((other >> (32 * i)).low_u32());
let (r, overflow) = v.overflowing_shl(32 * i as u32);
panic_on_overflow!(overflow); panic_on_overflow!(overflow);
res = res + r; result
}
res
} }
} }