Home | History | Annotate | Line # | Download | only in generic
nussbaumer_mul.c revision 1.1.1.3
      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 either:
     16 
     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.
     20 
     21 or
     22 
     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.
     26 
     27 or both in parallel, as here.
     28 
     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.
     33 
     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/.  */
     37 
     38 
     39 #include "gmp-impl.h"
     40 
     41 /* Multiply {ap,an} by {bp,bn}, and put the result in {pp, an+bn} */
     42 void
     43 mpn_nussbaumer_mul (mp_ptr pp,
     44 		    mp_srcptr ap, mp_size_t an,
     45 		    mp_srcptr bp, mp_size_t bn)
     46 {
     47   mp_size_t rn;
     48   mp_ptr tp;
     49   TMP_DECL;
     50 
     51   ASSERT (an >= bn);
     52   ASSERT (bn > 0);
     53 
     54   TMP_MARK;
     55 
     56   if ((ap == bp) && (an == bn))
     57     {
     58       rn = mpn_sqrmod_bnm1_next_size (2*an);
     59       tp = TMP_ALLOC_LIMBS (mpn_sqrmod_bnm1_itch (rn, an));
     60       mpn_sqrmod_bnm1 (pp, rn, ap, an, tp);
     61     }
     62   else
     63     {
     64       rn = mpn_mulmod_bnm1_next_size (an + bn);
     65       tp = TMP_ALLOC_LIMBS (mpn_mulmod_bnm1_itch (rn, an, bn));
     66       mpn_mulmod_bnm1 (pp, rn, ap, an, bp, bn, tp);
     67     }
     68 
     69   TMP_FREE;
     70 }
     71