From 57b7572e7503f72dfd829bf4392becd7f8c817d2 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 8 Jul 2010 09:33:06 +0200 Subject: [PATCH] rework 32bit version to match 64bit version --- src/simulator/high-precision-cairo.cc | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/simulator/high-precision-cairo.cc b/src/simulator/high-precision-cairo.cc index 766147ae7..57b1588fe 100644 --- a/src/simulator/high-precision-cairo.cc +++ b/src/simulator/high-precision-cairo.cc @@ -30,30 +30,23 @@ namespace ns3 { NS_LOG_COMPONENT_DEFINE ("HighPrecisionCairo"); -#define ABS_ARGS(sa,sb,ua,ub) \ - bool negResult, negA, negB; \ - /* take the sign of the operands */ \ +#define OUTPUT_SIGN(sa,sb,ua,ub) \ + ({bool negA, negB; \ negA = _cairo_int128_negative (sa); \ negB = _cairo_int128_negative (sb); \ - /* the result is negative only if one of the operand is negative */ \ - negResult = (negA && !negB) || (!negA && negB); \ - /* now take the absolute part to make sure that the resulting operands are positive */ \ ua = _cairo_int128_to_uint128 (sa); \ ub = _cairo_int128_to_uint128 (sb); \ ua = negA ? _cairo_uint128_negate (ua) : ua; \ - ub = negB ? _cairo_uint128_negate (ub) : ub - -#define SIGN_RESULT(result) \ - negResult ? _cairo_uint128_negate (result) : result - + ub = negB ? _cairo_uint128_negate (ub) : ub; \ + negResult = (negA && !negB) || (!negA && negB);}) void HighPrecision::Mul (HighPrecision const &o) { cairo_uint128_t a, b, result; - ABS_ARGS (m_value, o.m_value, a, b); + bool sign = OUTPUT_SIGN (m_value, o.m_value, a, b); result = Umul (a, b); - m_value = SIGN_RESULT (result); + m_value = sign ? _cairo_uint128_negate (result) : result; } @@ -93,9 +86,9 @@ void HighPrecision::Div (HighPrecision const &o) { cairo_uint128_t a, b, result; - ABS_ARGS(m_value, o.m_value, a, b); + bool sign = OUTPUT_SIGN (m_value, o.m_value, a, b); result = Udiv (a, b); - m_value = SIGN_RESULT (result); + m_value = sign ? _cairo_uint128_negate (result) : result; } cairo_uint128_t