nussbaumer_mul.c revision 1.1.1.2 1 1.1 mrg /* mpn_nussbaumer_mul -- Multiply {ap,an} and {bp,bn} using
2 1.1 mrg Nussbaumer's negacyclic convolution.
3 1.1 mrg
4 1.1 mrg Contributed to the GNU project by Marco Bodrato.
5 1.1 mrg
6 1.1 mrg THE FUNCTION IN THIS FILE IS INTERNAL WITH A MUTABLE INTERFACE. IT IS ONLY
7 1.1 mrg SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST
8 1.1 mrg GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
9 1.1 mrg
10 1.1 mrg Copyright 2009 Free Software Foundation, Inc.
11 1.1 mrg
12 1.1 mrg This file is part of the GNU MP Library.
13 1.1 mrg
14 1.1 mrg The GNU MP Library is free software; you can redistribute it and/or modify
15 1.1.1.2 mrg it under the terms of either:
16 1.1.1.2 mrg
17 1.1.1.2 mrg * the GNU Lesser General Public License as published by the Free
18 1.1.1.2 mrg Software Foundation; either version 3 of the License, or (at your
19 1.1.1.2 mrg option) any later version.
20 1.1.1.2 mrg
21 1.1.1.2 mrg or
22 1.1.1.2 mrg
23 1.1.1.2 mrg * the GNU General Public License as published by the Free Software
24 1.1.1.2 mrg Foundation; either version 2 of the License, or (at your option) any
25 1.1.1.2 mrg later version.
26 1.1.1.2 mrg
27 1.1.1.2 mrg or both in parallel, as here.
28 1.1 mrg
29 1.1 mrg The GNU MP Library is distributed in the hope that it will be useful, but
30 1.1 mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
31 1.1.1.2 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
32 1.1.1.2 mrg for more details.
33 1.1 mrg
34 1.1.1.2 mrg You should have received copies of the GNU General Public License and the
35 1.1.1.2 mrg GNU Lesser General Public License along with the GNU MP Library. If not,
36 1.1.1.2 mrg see https://www.gnu.org/licenses/. */
37 1.1 mrg
38 1.1 mrg
39 1.1 mrg #include "gmp.h"
40 1.1 mrg #include "gmp-impl.h"
41 1.1 mrg
42 1.1 mrg /* Multiply {ap,an} by {bp,bn}, and put the result in {pp, an+bn} */
43 1.1 mrg void
44 1.1 mrg mpn_nussbaumer_mul (mp_ptr pp,
45 1.1 mrg mp_srcptr ap, mp_size_t an,
46 1.1 mrg mp_srcptr bp, mp_size_t bn)
47 1.1 mrg {
48 1.1 mrg mp_size_t rn;
49 1.1 mrg mp_ptr tp;
50 1.1 mrg TMP_DECL;
51 1.1 mrg
52 1.1 mrg ASSERT (an >= bn);
53 1.1 mrg ASSERT (bn > 0);
54 1.1 mrg
55 1.1 mrg TMP_MARK;
56 1.1 mrg
57 1.1 mrg if ((ap == bp) && (an == bn))
58 1.1 mrg {
59 1.1 mrg rn = mpn_sqrmod_bnm1_next_size (2*an);
60 1.1 mrg tp = TMP_ALLOC_LIMBS (mpn_sqrmod_bnm1_itch (rn, an));
61 1.1 mrg mpn_sqrmod_bnm1 (pp, rn, ap, an, tp);
62 1.1 mrg }
63 1.1 mrg else
64 1.1 mrg {
65 1.1 mrg rn = mpn_mulmod_bnm1_next_size (an + bn);
66 1.1 mrg tp = TMP_ALLOC_LIMBS (mpn_mulmod_bnm1_itch (rn, an, bn));
67 1.1 mrg mpn_mulmod_bnm1 (pp, rn, ap, an, bp, bn, tp);
68 1.1 mrg }
69 1.1 mrg
70 1.1 mrg TMP_FREE;
71 1.1 mrg }
72