1 /* mpn_toom_eval_pm2rexp -- Evaluate a polynomial in +2^-k and -2^-k
3 Contributed to the GNU project by Marco Bodrato
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.
9 Copyright 2009 Free Software Foundation, Inc.
11 This file is part of the GNU MP Library.
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.
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.
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/. */
30 #if HAVE_NATIVE_mpn_addlsh_n
31 #define DO_mpn_addlsh_n(dst,src,n,s,ws) mpn_addlsh_n(dst,dst,src,n,s)
34 DO_mpn_addlsh_n(mp_ptr dst, mp_srcptr src, mp_size_t n, unsigned int s, mp_ptr ws)
37 return mpn_addmul_1(dst,src,n,CNST_LIMB(1) <<(s));
40 __cy = mpn_lshift(ws,src,n,s);
41 return __cy + mpn_add_n(dst,dst,ws,n);
46 /* Evaluates a polynomial of degree k >= 3. */
48 mpn_toom_eval_pm2rexp (mp_ptr rp, mp_ptr rm,
49 unsigned int q, mp_srcptr ap, mp_size_t n, mp_size_t t,
50 unsigned int s, mp_ptr ws)
54 /* {ap,q*n+t} -> {rp,n+1} {rm,n+1} , with {ws, n+1}*/
56 ASSERT (s != 0); /* or _eval_pm1 should be used */
58 ASSERT (s*q < GMP_NUMB_BITS);
59 rp[n] = mpn_lshift(rp, ap, n, s*q);
60 ws[n] = mpn_lshift(ws, ap+n, n, s*(q-1));
62 ASSERT_NOCARRY(mpn_add(ws,ws,n+1,ap+n*q,t));
63 rp[n] += DO_mpn_addlsh_n(rp, ap+n*(q-1), n, s, rm);
65 ASSERT_NOCARRY(mpn_add(rp,rp,n+1,ap+n*q,t));
69 rp[n] += DO_mpn_addlsh_n(rp, ap+n*i, n, s*(q-i), rm);
71 ws[n] += DO_mpn_addlsh_n(ws, ap+n*i, n, s*(q-i), rm);
74 neg = (mpn_cmp (rp, ws, n + 1) < 0) ? ~0 : 0;
76 #if HAVE_NATIVE_mpn_add_n_sub_n
78 mpn_add_n_sub_n (rp, rm, ws, rp, n + 1);
80 mpn_add_n_sub_n (rp, rm, rp, ws, n + 1);
81 #else /* !HAVE_NATIVE_mpn_add_n_sub_n */
83 mpn_sub_n (rm, ws, rp, n + 1);
85 mpn_sub_n (rm, rp, ws, n + 1);
87 ASSERT_NOCARRY (mpn_add_n (rp, rp, ws, n + 1));
88 #endif /* !HAVE_NATIVE_mpn_add_n_sub_n */