nussbaumer_mul.c revision 1.1 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 mrg it under the terms of the GNU Lesser General Public License as published by
16 1.1 mrg the Free Software Foundation; either version 3 of the License, or (at your
17 1.1 mrg option) any later version.
18 1.1 mrg
19 1.1 mrg The GNU MP Library is distributed in the hope that it will be useful, but
20 1.1 mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 1.1 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
22 1.1 mrg License for more details.
23 1.1 mrg
24 1.1 mrg You should have received a copy of the GNU Lesser General Public License
25 1.1 mrg along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
26 1.1 mrg
27 1.1 mrg
28 1.1 mrg #include "gmp.h"
29 1.1 mrg #include "gmp-impl.h"
30 1.1 mrg
31 1.1 mrg /* Multiply {ap,an} by {bp,bn}, and put the result in {pp, an+bn} */
32 1.1 mrg void
33 1.1 mrg mpn_nussbaumer_mul (mp_ptr pp,
34 1.1 mrg mp_srcptr ap, mp_size_t an,
35 1.1 mrg mp_srcptr bp, mp_size_t bn)
36 1.1 mrg {
37 1.1 mrg mp_size_t rn;
38 1.1 mrg mp_ptr tp;
39 1.1 mrg TMP_DECL;
40 1.1 mrg
41 1.1 mrg ASSERT (an >= bn);
42 1.1 mrg ASSERT (bn > 0);
43 1.1 mrg
44 1.1 mrg TMP_MARK;
45 1.1 mrg
46 1.1 mrg if ((ap == bp) && (an == bn))
47 1.1 mrg {
48 1.1 mrg rn = mpn_sqrmod_bnm1_next_size (2*an);
49 1.1 mrg tp = TMP_ALLOC_LIMBS (mpn_sqrmod_bnm1_itch (rn, an));
50 1.1 mrg mpn_sqrmod_bnm1 (pp, rn, ap, an, tp);
51 1.1 mrg }
52 1.1 mrg else
53 1.1 mrg {
54 1.1 mrg rn = mpn_mulmod_bnm1_next_size (an + bn);
55 1.1 mrg tp = TMP_ALLOC_LIMBS (mpn_mulmod_bnm1_itch (rn, an, bn));
56 1.1 mrg mpn_mulmod_bnm1 (pp, rn, ap, an, bp, bn, tp);
57 1.1 mrg }
58 1.1 mrg
59 1.1 mrg TMP_FREE;
60 1.1 mrg }
61