From 0794049d18708a3d258df42cd43f51ce03a9ae33 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 25 Feb 2016 02:05:59 +0300 Subject: [PATCH] fix naughty macros --- util/src/uint.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/util/src/uint.rs b/util/src/uint.rs index 38b4e4906..f27150199 100644 --- a/util/src/uint.rs +++ b/util/src/uint.rs @@ -53,6 +53,12 @@ macro_rules! impl_map_from { #[cfg(not(all(feature="dev", target_arch = "x86_64")))] macro_rules! uint_overflowing_add { + ($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ({ + uint_overflowing_add_reg!($name, $n_words, $self_expr, $other) + }) +} + +macro_rules! uint_overflowing_add_reg { ($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ({ let $name(ref me) = $self_expr; let $name(ref you) = $other; @@ -82,6 +88,7 @@ macro_rules! uint_overflowing_add { }) } + #[cfg(all(feature="dev", target_arch = "x86_64"))] macro_rules! uint_overflowing_add { (U256, $n_words: expr, $self_expr: expr, $other: expr) => ({ @@ -106,7 +113,7 @@ macro_rules! uint_overflowing_add { (U256(result), overflow != 0) }); ($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ( - overflowing_add_regular!($name, $n_words, $self_expr, $other) + uint_overflowing_add_reg!($name, $n_words, $self_expr, $other) ) } @@ -142,9 +149,11 @@ macro_rules! uint_overflowing_sub { } (U256(result), overflow != 0) }); - ($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ( - overflowing_add_regular!($name, $n_words, $self_expr, $other) - ) + ($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({ + let res = overflowing!((!$other).overflowing_add(From::from(1u64))); + let res = overflowing!($self_expr.overflowing_add(res)); + (res, $self_expr < $other) + }) } #[cfg(all(feature="dev", target_arch = "x86_64"))] @@ -241,12 +250,18 @@ macro_rules! uint_overflowing_mul { (U256(result), overflow > 0) }); ($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ( - overflowing_mul_regular!($name, $n_words, $self_expr, $other) + uint_overflowing_mul_reg!($name, $n_words, $self_expr, $other) ) } #[cfg(not(all(feature="dev", target_arch = "x86_64")))] macro_rules! uint_overflowing_mul { + ($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({ + uint_overflowing_mul_reg!($name, $n_words, $self_expr, $other) + }) +} + +macro_rules! uint_overflowing_mul_reg { ($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({ let mut res = $name::from(0u64); let mut overflow = false;