1 /* mpn_toom_eval_dgr3_pm1 -- Evaluate a degree 3 polynomial in +1 and -1 2 3 Contributed to the GNU project by Niels M�ller 4 5 THE FUNCTION IN THIS FILE IS INTERNAL WITH A MUTABLE INTERFACE. IT IS ONLY 6 SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST 7 GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE. 8 9 Copyright 2009 Free Software Foundation, Inc. 10 11 This file is part of the GNU MP Library. 12 13 The GNU MP Library is free software; you can redistribute it and/or modify 14 it under the terms of the GNU Lesser General Public License as published by 15 the Free Software Foundation; either version 3 of the License, or (at your 16 option) any later version. 17 18 The GNU MP Library is distributed in the hope that it will be useful, but 19 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 21 License for more details. 22 23 You should have received a copy of the GNU Lesser General Public License 24 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ 25 26 27 #include "gmp.h" 28 #include "gmp-impl.h" 29 30 int 31 mpn_toom_eval_dgr3_pm1 (mp_ptr xp1, mp_ptr xm1, 32 mp_srcptr xp, mp_size_t n, mp_size_t x3n, mp_ptr tp) 33 { 34 int neg; 35 36 ASSERT (x3n > 0); 37 ASSERT (x3n <= n); 38 39 xp1[n] = mpn_add_n (xp1, xp, xp + 2*n, n); 40 tp[n] = mpn_add (tp, xp + n, n, xp + 3*n, x3n); 41 42 neg = (mpn_cmp (xp1, tp, n + 1) < 0) ? ~0 : 0; 43 44 #if HAVE_NATIVE_mpn_add_n_sub_n 45 if (neg) 46 mpn_add_n_sub_n (xp1, xm1, tp, xp1, n + 1); 47 else 48 mpn_add_n_sub_n (xp1, xm1, xp1, tp, n + 1); 49 #else 50 if (neg) 51 mpn_sub_n (xm1, tp, xp1, n + 1); 52 else 53 mpn_sub_n (xm1, xp1, tp, n + 1); 54 55 mpn_add_n (xp1, xp1, tp, n + 1); 56 #endif 57 58 ASSERT (xp1[n] <= 3); 59 ASSERT (xm1[n] <= 1); 60 61 return neg; 62 } 63