xref: /dflybsd-src/contrib/gmp/mpn/generic/toom_eval_dgr3_pm1.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /* mpn_toom_eval_dgr3_pm1 -- Evaluate a degree 3 polynomial in +1 and -1
286d7f5d3SJohn Marino 
386d7f5d3SJohn Marino    Contributed to the GNU project by Niels M�ller
486d7f5d3SJohn Marino 
586d7f5d3SJohn Marino    THE FUNCTION IN THIS FILE IS INTERNAL WITH A MUTABLE INTERFACE.  IT IS ONLY
686d7f5d3SJohn Marino    SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
786d7f5d3SJohn Marino    GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
886d7f5d3SJohn Marino 
986d7f5d3SJohn Marino Copyright 2009 Free Software Foundation, Inc.
1086d7f5d3SJohn Marino 
1186d7f5d3SJohn Marino This file is part of the GNU MP Library.
1286d7f5d3SJohn Marino 
1386d7f5d3SJohn Marino The GNU MP Library is free software; you can redistribute it and/or modify
1486d7f5d3SJohn Marino it under the terms of the GNU Lesser General Public License as published by
1586d7f5d3SJohn Marino the Free Software Foundation; either version 3 of the License, or (at your
1686d7f5d3SJohn Marino option) any later version.
1786d7f5d3SJohn Marino 
1886d7f5d3SJohn Marino The GNU MP Library is distributed in the hope that it will be useful, but
1986d7f5d3SJohn Marino WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
2086d7f5d3SJohn Marino or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
2186d7f5d3SJohn Marino License for more details.
2286d7f5d3SJohn Marino 
2386d7f5d3SJohn Marino You should have received a copy of the GNU Lesser General Public License
2486d7f5d3SJohn Marino along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
2586d7f5d3SJohn Marino 
2686d7f5d3SJohn Marino 
2786d7f5d3SJohn Marino #include "gmp.h"
2886d7f5d3SJohn Marino #include "gmp-impl.h"
2986d7f5d3SJohn Marino 
3086d7f5d3SJohn Marino int
mpn_toom_eval_dgr3_pm1(mp_ptr xp1,mp_ptr xm1,mp_srcptr xp,mp_size_t n,mp_size_t x3n,mp_ptr tp)3186d7f5d3SJohn Marino mpn_toom_eval_dgr3_pm1 (mp_ptr xp1, mp_ptr xm1,
3286d7f5d3SJohn Marino 			mp_srcptr xp, mp_size_t n, mp_size_t x3n, mp_ptr tp)
3386d7f5d3SJohn Marino {
3486d7f5d3SJohn Marino   int neg;
3586d7f5d3SJohn Marino 
3686d7f5d3SJohn Marino   ASSERT (x3n > 0);
3786d7f5d3SJohn Marino   ASSERT (x3n <= n);
3886d7f5d3SJohn Marino 
3986d7f5d3SJohn Marino   xp1[n] = mpn_add_n (xp1, xp, xp + 2*n, n);
4086d7f5d3SJohn Marino   tp[n] = mpn_add (tp, xp + n, n, xp + 3*n, x3n);
4186d7f5d3SJohn Marino 
4286d7f5d3SJohn Marino   neg = (mpn_cmp (xp1, tp, n + 1) < 0) ? ~0 : 0;
4386d7f5d3SJohn Marino 
4486d7f5d3SJohn Marino #if HAVE_NATIVE_mpn_add_n_sub_n
4586d7f5d3SJohn Marino   if (neg)
4686d7f5d3SJohn Marino     mpn_add_n_sub_n (xp1, xm1, tp, xp1, n + 1);
4786d7f5d3SJohn Marino   else
4886d7f5d3SJohn Marino     mpn_add_n_sub_n (xp1, xm1, xp1, tp, n + 1);
4986d7f5d3SJohn Marino #else
5086d7f5d3SJohn Marino   if (neg)
5186d7f5d3SJohn Marino     mpn_sub_n (xm1, tp, xp1, n + 1);
5286d7f5d3SJohn Marino   else
5386d7f5d3SJohn Marino     mpn_sub_n (xm1, xp1, tp, n + 1);
5486d7f5d3SJohn Marino 
5586d7f5d3SJohn Marino   mpn_add_n (xp1, xp1, tp, n + 1);
5686d7f5d3SJohn Marino #endif
5786d7f5d3SJohn Marino 
5886d7f5d3SJohn Marino   ASSERT (xp1[n] <= 3);
5986d7f5d3SJohn Marino   ASSERT (xm1[n] <= 1);
6086d7f5d3SJohn Marino 
6186d7f5d3SJohn Marino   return neg;
6286d7f5d3SJohn Marino }
63