beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpn / generic / toom_couple_handling.c
blob9e62bcba1c9605ac2fe12cc97d5afd8864070ba8
1 /* Helper function for high degree Toom-Cook algorithms.
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, 2010 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 either:
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.
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.
26 or both in parallel, as here.
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.
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/. */
38 #include "gmp.h"
39 #include "gmp-impl.h"
41 /* Gets {pp,n} and (sign?-1:1)*{np,n}. Computes at once:
42 {pp,n} <- ({pp,n}+{np,n})/2^{ps+1}
43 {pn,n} <- ({pp,n}-{np,n})/2^{ns+1}
44 Finally recompose them obtaining:
45 {pp,n+off} <- {pp,n}+{np,n}*2^{off*GMP_NUMB_BITS}
47 void
48 mpn_toom_couple_handling (mp_ptr pp, mp_size_t n, mp_ptr np,
49 int nsign, mp_size_t off, int ps, int ns)
51 if (nsign) {
52 #ifdef HAVE_NATIVE_mpn_rsh1sub_n
53 mpn_rsh1sub_n (np, pp, np, n);
54 #else
55 mpn_sub_n (np, pp, np, n);
56 mpn_rshift (np, np, n, 1);
57 #endif
58 } else {
59 #ifdef HAVE_NATIVE_mpn_rsh1add_n
60 mpn_rsh1add_n (np, pp, np, n);
61 #else
62 mpn_add_n (np, pp, np, n);
63 mpn_rshift (np, np, n, 1);
64 #endif
67 #ifdef HAVE_NATIVE_mpn_rsh1sub_n
68 if (ps == 1)
69 mpn_rsh1sub_n (pp, pp, np, n);
70 else
71 #endif
73 mpn_sub_n (pp, pp, np, n);
74 if (ps > 0)
75 mpn_rshift (pp, pp, n, ps);
77 if (ns > 0)
78 mpn_rshift (np, np, n, ns);
79 pp[n] = mpn_add_n (pp+off, pp+off, np, n-off);
80 ASSERT_NOCARRY (mpn_add_1(pp+n, np+n-off, off, pp[n]) );