~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to src/gmp/mpn/generic/addmul_1.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2006-05-17 02:46:26 UTC
  • Revision ID: james.westby@ubuntu.com-20060517024626-lljr08ftv9g9vefl
Tags: upstream-0.9h-20060510
ImportĀ upstreamĀ versionĀ 0.9h-20060510

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* mpn_addmul_1 -- multiply the N long limb vector pointed to by UP by VL,
 
2
   add the N least significant limbs of the product to the limb vector
 
3
   pointed to by RP.  Return the most significant limb of the product,
 
4
   adjusted for carry-out from the addition.
 
5
 
 
6
Copyright 1992, 1993, 1994, 1996, 2000, 2002 Free Software Foundation, Inc.
 
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
 
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
 
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
 
17
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
18
License for more details.
 
19
 
 
20
You should have received a copy of the GNU Lesser General Public License
 
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
 
 
29
 
 
30
#if GMP_NAIL_BITS == 0
 
31
 
 
32
mp_limb_t
 
33
mpn_addmul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
 
34
{
 
35
  mp_limb_t ul, cl, hpl, lpl, rl;
 
36
 
 
37
  ASSERT (n >= 1);
 
38
  ASSERT (MPN_SAME_OR_SEPARATE_P (rp, up, n));
 
39
 
 
40
  cl = 0;
 
41
  do
 
42
    {
 
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
}
 
58
 
 
59
#endif
 
60
 
 
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_addmul_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 = prev_hpl + lpl + rl + cl;
 
88
      cl = xw >> GMP_NUMB_BITS;
 
89
      xl = xw & GMP_NUMB_MASK;
 
90
      *rp++ = xl;
 
91
      prev_hpl = hpl;
 
92
    }
 
93
  while (--n != 0);
 
94
 
 
95
  return prev_hpl + cl;
 
96
}
 
97
 
 
98
#endif