/src/gmp/mpn/toom_eval_dgr3_pm2.c
Line  | Count  | Source (jump to first uncovered line)  | 
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  |  |  | 
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 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  |  |  | 
20  |  | or  | 
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  |  |  | 
26  |  | or both in parallel, as here.  | 
27  |  |  | 
28  |  | The GNU MP Library is distributed in the hope that it will be useful, but  | 
29  |  | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  | 
30  |  | or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License  | 
31  |  | for more details.  | 
32  |  |  | 
33  |  | You should have received copies of the GNU General Public License and the  | 
34  |  | GNU Lesser General Public License along with the GNU MP Library.  If not,  | 
35  |  | see https://www.gnu.org/licenses/.  */  | 
36  |  |  | 
37  |  |  | 
38  |  | #include "gmp-impl.h"  | 
39  |  |  | 
40  |  | /* Needs n+1 limbs of temporary storage. */  | 
41  |  | int  | 
42  |  | mpn_toom_eval_dgr3_pm2 (mp_ptr xp2, mp_ptr xm2,  | 
43  |  |       mp_srcptr xp, mp_size_t n, mp_size_t x3n, mp_ptr tp)  | 
44  | 0  | { | 
45  | 0  |   mp_limb_t cy;  | 
46  | 0  |   int neg;  | 
47  |  | 
  | 
48  | 0  |   ASSERT (x3n > 0);  | 
49  | 0  |   ASSERT (x3n <= n);  | 
50  |  |  | 
51  |  |   /* (x0 + 4 * x2) +/- (2 x1 + 8 x_3) */  | 
52  | 0  | #if HAVE_NATIVE_mpn_addlsh_n || HAVE_NATIVE_mpn_addlsh2_n  | 
53  | 0  | #if HAVE_NATIVE_mpn_addlsh2_n  | 
54  | 0  |   xp2[n] = mpn_addlsh2_n (xp2, xp, xp + 2*n, n);  | 
55  |  | 
  | 
56  | 0  |   cy = mpn_addlsh2_n (tp, xp + n, xp + 3*n, x3n);  | 
57  |  | #else /* HAVE_NATIVE_mpn_addlsh_n */  | 
58  |  |   xp2[n] = mpn_addlsh_n (xp2, xp, xp + 2*n, n, 2);  | 
59  |  |  | 
60  |  |   cy = mpn_addlsh_n (tp, xp + n, xp + 3*n, x3n, 2);  | 
61  |  | #endif  | 
62  | 0  |   if (x3n < n)  | 
63  | 0  |     cy = mpn_add_1 (tp + x3n, xp + n + x3n, n - x3n, cy);  | 
64  | 0  |   tp[n] = cy;  | 
65  |  | #else  | 
66  |  |   cy = mpn_lshift (tp, xp + 2*n, n, 2);  | 
67  |  |   xp2[n] = cy + mpn_add_n (xp2, tp, xp, n);  | 
68  |  |  | 
69  |  |   tp[x3n] = mpn_lshift (tp, xp + 3*n, x3n, 2);  | 
70  |  |   if (x3n < n)  | 
71  |  |     tp[n] = mpn_add (tp, xp + n, n, tp, x3n + 1);  | 
72  |  |   else  | 
73  |  |     tp[n] += mpn_add_n (tp, xp + n, tp, n);  | 
74  |  | #endif  | 
75  | 0  |   mpn_lshift (tp, tp, n+1, 1);  | 
76  |  | 
  | 
77  | 0  |   neg = (mpn_cmp (xp2, tp, n + 1) < 0) ? ~0 : 0;  | 
78  |  | 
  | 
79  |  | #if HAVE_NATIVE_mpn_add_n_sub_n  | 
80  |  |   if (neg)  | 
81  |  |     mpn_add_n_sub_n (xp2, xm2, tp, xp2, n + 1);  | 
82  |  |   else  | 
83  |  |     mpn_add_n_sub_n (xp2, xm2, xp2, tp, n + 1);  | 
84  |  | #else  | 
85  | 0  |   if (neg)  | 
86  | 0  |     mpn_sub_n (xm2, tp, xp2, n + 1);  | 
87  | 0  |   else  | 
88  | 0  |     mpn_sub_n (xm2, xp2, tp, n + 1);  | 
89  |  | 
  | 
90  | 0  |   mpn_add_n (xp2, xp2, tp, n + 1);  | 
91  | 0  | #endif  | 
92  |  | 
  | 
93  | 0  |   ASSERT (xp2[n] < 15);  | 
94  | 0  |   ASSERT (xm2[n] < 10);  | 
95  |  | 
  | 
96  | 0  |   return neg;  | 
97  | 0  | }  |