beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpn / generic / nussbaumer_mul.c
blobd2bf19ad56a166ec5e4786767e82d1baf6d69471
1 /* mpn_nussbaumer_mul -- Multiply {ap,an} and {bp,bn} using
2 Nussbaumer's negacyclic convolution.
4 Contributed to the GNU project by Marco Bodrato.
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.
10 Copyright 2009 Free Software Foundation, Inc.
12 This file is part of the GNU MP Library.
14 The GNU MP Library is free software; you can redistribute it and/or modify
15 it under the terms of either:
17 * the GNU Lesser General Public License as published by the Free
18 Software Foundation; either version 3 of the License, or (at your
19 option) any later version.
23 * the GNU General Public License as published by the Free Software
24 Foundation; either version 2 of the License, or (at your option) any
25 later version.
27 or both in parallel, as here.
29 The GNU MP Library is distributed in the hope that it will be useful, but
30 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
31 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
32 for more details.
34 You should have received copies of the GNU General Public License and the
35 GNU Lesser General Public License along with the GNU MP Library. If not,
36 see https://www.gnu.org/licenses/. */
39 #include "gmp.h"
40 #include "gmp-impl.h"
42 /* Multiply {ap,an} by {bp,bn}, and put the result in {pp, an+bn} */
43 void
44 mpn_nussbaumer_mul (mp_ptr pp,
45 mp_srcptr ap, mp_size_t an,
46 mp_srcptr bp, mp_size_t bn)
48 mp_size_t rn;
49 mp_ptr tp;
50 TMP_DECL;
52 ASSERT (an >= bn);
53 ASSERT (bn > 0);
55 TMP_MARK;
57 if ((ap == bp) && (an == bn))
59 rn = mpn_sqrmod_bnm1_next_size (2*an);
60 tp = TMP_ALLOC_LIMBS (mpn_sqrmod_bnm1_itch (rn, an));
61 mpn_sqrmod_bnm1 (pp, rn, ap, an, tp);
63 else
65 rn = mpn_mulmod_bnm1_next_size (an + bn);
66 tp = TMP_ALLOC_LIMBS (mpn_mulmod_bnm1_itch (rn, an, bn));
67 mpn_mulmod_bnm1 (pp, rn, ap, an, bp, bn, tp);
70 TMP_FREE;