toom_eval_dgr3_pm2.c revision 1.1.1.2
1/* mpn_toom_eval_dgr3_pm2 -- Evaluate a degree 3 polynomial in +2 and -2 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 9Copyright 2009 Free Software Foundation, Inc. 10 11This file is part of the GNU MP Library. 12 13The GNU MP Library is free software; you can redistribute it and/or modify 14it under the terms of either: 15 16 * the GNU Lesser General Public License as published by the Free 17 Software Foundation; either version 3 of the License, or (at your 18 option) any later version. 19 20or 21 22 * the GNU General Public License as published by the Free Software 23 Foundation; either version 2 of the License, or (at your option) any 24 later version. 25 26or both in parallel, as here. 27 28The GNU MP Library is distributed in the hope that it will be useful, but 29WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 30or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 31for more details. 32 33You should have received copies of the GNU General Public License and the 34GNU Lesser General Public License along with the GNU MP Library. If not, 35see https://www.gnu.org/licenses/. */ 36 37 38#include "gmp.h" 39#include "gmp-impl.h" 40 41/* Needs n+1 limbs of temporary storage. */ 42int 43mpn_toom_eval_dgr3_pm2 (mp_ptr xp2, mp_ptr xm2, 44 mp_srcptr xp, mp_size_t n, mp_size_t x3n, mp_ptr tp) 45{ 46 mp_limb_t cy; 47 int neg; 48 49 ASSERT (x3n > 0); 50 ASSERT (x3n <= n); 51 52 /* (x0 + 4 * x2) +/- (2 x1 + 8 x_3) */ 53#if HAVE_NATIVE_mpn_addlsh_n || HAVE_NATIVE_mpn_addlsh2_n 54#if HAVE_NATIVE_mpn_addlsh2_n 55 xp2[n] = mpn_addlsh2_n (xp2, xp, xp + 2*n, n); 56 57 cy = mpn_addlsh2_n (tp, xp + n, xp + 3*n, x3n); 58#else /* HAVE_NATIVE_mpn_addlsh_n */ 59 xp2[n] = mpn_addlsh_n (xp2, xp, xp + 2*n, n, 2); 60 61 cy = mpn_addlsh_n (tp, xp + n, xp + 3*n, x3n, 2); 62#endif 63 if (x3n < n) 64 cy = mpn_add_1 (tp + x3n, xp + n + x3n, n - x3n, cy); 65 tp[n] = cy; 66#else 67 cy = mpn_lshift (tp, xp + 2*n, n, 2); 68 xp2[n] = cy + mpn_add_n (xp2, tp, xp, n); 69 70 tp[x3n] = mpn_lshift (tp, xp + 3*n, x3n, 2); 71 if (x3n < n) 72 tp[n] = mpn_add (tp, xp + n, n, tp, x3n + 1); 73 else 74 tp[n] += mpn_add_n (tp, xp + n, tp, n); 75#endif 76 mpn_lshift (tp, tp, n+1, 1); 77 78 neg = (mpn_cmp (xp2, tp, n + 1) < 0) ? ~0 : 0; 79 80#if HAVE_NATIVE_mpn_add_n_sub_n 81 if (neg) 82 mpn_add_n_sub_n (xp2, xm2, tp, xp2, n + 1); 83 else 84 mpn_add_n_sub_n (xp2, xm2, xp2, tp, n + 1); 85#else 86 if (neg) 87 mpn_sub_n (xm2, tp, xp2, n + 1); 88 else 89 mpn_sub_n (xm2, xp2, tp, n + 1); 90 91 mpn_add_n (xp2, xp2, tp, n + 1); 92#endif 93 94 ASSERT (xp2[n] < 15); 95 ASSERT (xm2[n] < 10); 96 97 return neg; 98} 99