2012-03-10 04:38:09 -05:00
|
|
|
/* Copyright 2012 The Code cavern
|
2008-06-25 03:33:36 -04:00
|
|
|
|
2012-03-10 04:38:09 -05:00
|
|
|
This file is part of the MPIR Library.
|
2008-06-25 03:33:36 -04:00
|
|
|
|
2012-03-10 04:38:09 -05:00
|
|
|
The MPIR Library is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
|
|
|
by the Free Software Foundation; either version 2.1 of the License, or (at
|
|
|
|
your option) any later version.
|
2008-06-25 03:33:36 -04:00
|
|
|
|
2012-03-10 04:38:09 -05:00
|
|
|
The MPIR Library is distributed in the hope that it will be useful, but
|
2008-06-25 03:33:36 -04:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2012-03-10 04:38:09 -05:00
|
|
|
along with the MPIR Library; see the file COPYING.LIB. If not, write
|
|
|
|
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
*/
|
2008-06-25 03:33:36 -04:00
|
|
|
|
2009-02-12 05:24:24 -05:00
|
|
|
#include "mpir.h"
|
2008-06-25 03:33:36 -04:00
|
|
|
#include "gmp-impl.h"
|
|
|
|
|
2014-02-14 18:25:39 -05:00
|
|
|
mp_limb_t mpn_sumdiff_n(mp_ptr s, mp_ptr d, mp_srcptr x, mp_srcptr y, mp_size_t n)
|
|
|
|
{
|
|
|
|
mp_limb_t ret;
|
|
|
|
mp_ptr t;
|
|
|
|
|
|
|
|
ASSERT_MPN(x, n);
|
|
|
|
ASSERT_MPN(y, n);
|
|
|
|
ASSERT(MPN_SAME_OR_SEPARATE_P(s, x, n));
|
|
|
|
ASSERT(MPN_SAME_OR_SEPARATE_P(s, y, n));
|
|
|
|
ASSERT(MPN_SAME_OR_SEPARATE_P(d, x, n));
|
|
|
|
ASSERT(MPN_SAME_OR_SEPARATE_P(d, y, n));
|
|
|
|
ASSERT(!MPN_OVERLAP_P(s, n, d, n));
|
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((s == x && d == y) || (s == y && d == x))
|
|
|
|
{
|
|
|
|
t = __GMP_ALLOCATE_FUNC_LIMBS(n);
|
|
|
|
|
|
|
|
ret = mpn_sub_n(t, x, y, n);
|
|
|
|
ret += 2*mpn_add_n(s, x, y, n);
|
|
|
|
MPN_COPY(d, t, n);
|
|
|
|
|
|
|
|
__GMP_FREE_FUNC_LIMBS(t, n);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s == x || s == y)
|
|
|
|
{
|
|
|
|
ret = mpn_sub_n(d, x, y, n);
|
|
|
|
ret += 2*mpn_add_n(s, x, y, n);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 2*mpn_add_n(s, x, y, n);
|
|
|
|
ret += mpn_sub_n(d, x, y, n);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|