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