[BACK]Return to mul_1.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpn / generic

Annotation of OpenXM_contrib/gmp/mpn/generic/mul_1.c, Revision 1.1.1.3

1.1.1.3 ! ohara       1: /* mpn_mul_1 -- Multiply a limb vector with a single limb and store the
        !             2:    product in a second limb vector.
1.1       maekawa     3:
1.1.1.3 ! ohara       4: Copyright 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002 Free Software
        !             5: Foundation, Inc.
1.1       maekawa     6:
                      7: This file is part of the GNU MP Library.
                      8:
                      9: The GNU MP Library is free software; you can redistribute it and/or modify
1.1.1.2   maekawa    10: it under the terms of the GNU Lesser General Public License as published by
                     11: the Free Software Foundation; either version 2.1 of the License, or (at your
1.1       maekawa    12: option) any later version.
                     13:
                     14: The GNU MP Library is distributed in the hope that it will be useful, but
                     15: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1.1.1.2   maekawa    16: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
1.1       maekawa    17: License for more details.
                     18:
1.1.1.2   maekawa    19: You should have received a copy of the GNU Lesser General Public License
1.1       maekawa    20: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
                     21: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     22: MA 02111-1307, USA. */
                     23:
                     24: #include "gmp.h"
                     25: #include "gmp-impl.h"
                     26: #include "longlong.h"
                     27:
1.1.1.3 ! ohara      28:
        !            29: #if GMP_NAIL_BITS == 0
        !            30:
1.1       maekawa    31: mp_limb_t
1.1.1.3 ! ohara      32: mpn_mul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
1.1       maekawa    33: {
1.1.1.3 ! ohara      34:   mp_limb_t ul, cl, hpl, lpl;
1.1       maekawa    35:
1.1.1.3 ! ohara      36:   ASSERT (n >= 1);
        !            37:   ASSERT (MPN_SAME_OR_INCR_P (rp, up, n));
        !            38:
        !            39:   cl = 0;
1.1       maekawa    40:   do
                     41:     {
1.1.1.3 ! ohara      42:       ul = *up++;
        !            43:       umul_ppmm (hpl, lpl, ul, vl);
        !            44:
        !            45:       lpl += cl;
        !            46:       cl = (lpl < cl) + hpl;
        !            47:
        !            48:       *rp++ = lpl;
        !            49:     }
        !            50:   while (--n != 0);
        !            51:
        !            52:   return cl;
        !            53: }
1.1       maekawa    54:
1.1.1.3 ! ohara      55: #endif
1.1       maekawa    56:
1.1.1.3 ! ohara      57: #if GMP_NAIL_BITS >= 1
        !            58:
        !            59: mp_limb_t
        !            60: mpn_mul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
        !            61: {
        !            62:   mp_limb_t shifted_vl, ul, lpl, hpl, prev_hpl, xw, cl, xl;
        !            63:
        !            64:   ASSERT (n >= 1);
        !            65:   ASSERT (MPN_SAME_OR_INCR_P (rp, up, n));
        !            66:   ASSERT_MPN (up, n);
        !            67:   ASSERT_LIMB (vl);
        !            68:
        !            69:   shifted_vl = vl << GMP_NAIL_BITS;
        !            70:   cl = 0;
        !            71:   prev_hpl = 0;
        !            72:   do
        !            73:     {
        !            74:       ul = *up++;
        !            75:
        !            76:       umul_ppmm (hpl, lpl, ul, shifted_vl);
        !            77:       lpl >>= GMP_NAIL_BITS;
        !            78:       xw = prev_hpl + lpl + cl;
        !            79:       cl = xw >> GMP_NUMB_BITS;
        !            80:       xl = xw & GMP_NUMB_MASK;
        !            81:       *rp++ = xl;
        !            82:       prev_hpl = hpl;
1.1       maekawa    83:     }
1.1.1.3 ! ohara      84:   while (--n != 0);
1.1       maekawa    85:
1.1.1.3 ! ohara      86:   return prev_hpl + cl;
1.1       maekawa    87: }
1.1.1.3 ! ohara      88:
        !            89: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>