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

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

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

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