xref: /dflybsd-src/contrib/gmp/mpn/generic/nussbaumer_mul.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /* mpn_nussbaumer_mul -- Multiply {ap,an} and {bp,bn} using
286d7f5d3SJohn Marino    Nussbaumer's negacyclic convolution.
386d7f5d3SJohn Marino 
486d7f5d3SJohn Marino    Contributed to the GNU project by Marco Bodrato.
586d7f5d3SJohn Marino 
686d7f5d3SJohn Marino    THE FUNCTION IN THIS FILE IS INTERNAL WITH A MUTABLE INTERFACE.  IT IS ONLY
786d7f5d3SJohn Marino    SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
886d7f5d3SJohn Marino    GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
986d7f5d3SJohn Marino 
1086d7f5d3SJohn Marino Copyright 2009 Free Software Foundation, Inc.
1186d7f5d3SJohn Marino 
1286d7f5d3SJohn Marino This file is part of the GNU MP Library.
1386d7f5d3SJohn Marino 
1486d7f5d3SJohn Marino The GNU MP Library is free software; you can redistribute it and/or modify
1586d7f5d3SJohn Marino it under the terms of the GNU Lesser General Public License as published by
1686d7f5d3SJohn Marino the Free Software Foundation; either version 3 of the License, or (at your
1786d7f5d3SJohn Marino option) any later version.
1886d7f5d3SJohn Marino 
1986d7f5d3SJohn Marino The GNU MP Library is distributed in the hope that it will be useful, but
2086d7f5d3SJohn Marino WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
2186d7f5d3SJohn Marino or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
2286d7f5d3SJohn Marino License for more details.
2386d7f5d3SJohn Marino 
2486d7f5d3SJohn Marino You should have received a copy of the GNU Lesser General Public License
2586d7f5d3SJohn Marino along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
2686d7f5d3SJohn Marino 
2786d7f5d3SJohn Marino 
2886d7f5d3SJohn Marino #include "gmp.h"
2986d7f5d3SJohn Marino #include "gmp-impl.h"
3086d7f5d3SJohn Marino 
3186d7f5d3SJohn Marino /* Multiply {ap,an} by {bp,bn}, and put the result in {pp, an+bn} */
3286d7f5d3SJohn Marino void
mpn_nussbaumer_mul(mp_ptr pp,mp_srcptr ap,mp_size_t an,mp_srcptr bp,mp_size_t bn)3386d7f5d3SJohn Marino mpn_nussbaumer_mul (mp_ptr pp,
3486d7f5d3SJohn Marino 		    mp_srcptr ap, mp_size_t an,
3586d7f5d3SJohn Marino 		    mp_srcptr bp, mp_size_t bn)
3686d7f5d3SJohn Marino {
3786d7f5d3SJohn Marino   mp_size_t rn;
3886d7f5d3SJohn Marino   mp_ptr tp;
3986d7f5d3SJohn Marino   TMP_DECL;
4086d7f5d3SJohn Marino 
4186d7f5d3SJohn Marino   ASSERT (an >= bn);
4286d7f5d3SJohn Marino   ASSERT (bn > 0);
4386d7f5d3SJohn Marino 
4486d7f5d3SJohn Marino   TMP_MARK;
4586d7f5d3SJohn Marino 
4686d7f5d3SJohn Marino   if ((ap == bp) && (an == bn))
4786d7f5d3SJohn Marino     {
4886d7f5d3SJohn Marino       rn = mpn_sqrmod_bnm1_next_size (2*an);
4986d7f5d3SJohn Marino       tp = TMP_ALLOC_LIMBS (mpn_sqrmod_bnm1_itch (rn, an));
5086d7f5d3SJohn Marino       mpn_sqrmod_bnm1 (pp, rn, ap, an, tp);
5186d7f5d3SJohn Marino     }
5286d7f5d3SJohn Marino   else
5386d7f5d3SJohn Marino     {
5486d7f5d3SJohn Marino       rn = mpn_mulmod_bnm1_next_size (an + bn);
5586d7f5d3SJohn Marino       tp = TMP_ALLOC_LIMBS (mpn_mulmod_bnm1_itch (rn, an, bn));
5686d7f5d3SJohn Marino       mpn_mulmod_bnm1 (pp, rn, ap, an, bp, bn, tp);
5786d7f5d3SJohn Marino     }
5886d7f5d3SJohn Marino 
5986d7f5d3SJohn Marino   TMP_FREE;
6086d7f5d3SJohn Marino }
61