~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to gmp3/mpn/generic/aorsmul_1.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* mpn_addmul_1, mpn_submul_1 -- multiply the S1_SIZE long limb vector
 
2
   pointed to by S1_PTR by S2_LIMB, add/subtract the S1_SIZE least
 
3
   significant limbs of the product to/from the limb vector pointed to by
 
4
   RES_PTR.  Return the most significant limb of the product, adjusted for
 
5
   carry-out from the addition.
 
6
 
 
7
Copyright 1992, 1993, 1994, 1996, 2000 Free Software Foundation, Inc.
 
8
 
 
9
This file is part of the GNU MP Library.
 
10
 
 
11
The GNU MP Library is free software; you can redistribute it and/or modify
 
12
it under the terms of the GNU Lesser General Public License as published by
 
13
the Free Software Foundation; either version 2.1 of the License, or (at your
 
14
option) any later version.
 
15
 
 
16
The GNU MP Library is distributed in the hope that it will be useful, but
 
17
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
18
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
19
License for more details.
 
20
 
 
21
You should have received a copy of the GNU Lesser General Public License
 
22
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
 
23
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
24
MA 02111-1307, USA. */
 
25
 
 
26
#include "gmp.h"
 
27
#include "gmp-impl.h"
 
28
#include "longlong.h"
 
29
 
 
30
 
 
31
#ifdef OPERATION_addmul_1
 
32
#define FUNCTION   mpn_addmul_1
 
33
#define VARIATION  prod_low = x + prod_low; cy_limb += (prod_low < x);
 
34
#endif
 
35
 
 
36
#ifdef OPERATION_submul_1
 
37
#define FUNCTION   mpn_submul_1
 
38
#define VARIATION  prod_low = x - prod_low; cy_limb += (prod_low > x);
 
39
#endif
 
40
 
 
41
#ifndef FUNCTION
 
42
Error, error, need OPERATION_addmul_1 or OPERATION_submul_1
 
43
#endif
 
44
 
 
45
 
 
46
mp_limb_t
 
47
FUNCTION (register mp_ptr res_ptr,
 
48
          register mp_srcptr s1_ptr,
 
49
          mp_size_t s1_size,
 
50
          register mp_limb_t s2_limb)
 
51
{
 
52
  register mp_limb_t cy_limb;
 
53
  register mp_size_t j;
 
54
  register mp_limb_t prod_high, prod_low;
 
55
  register mp_limb_t x;
 
56
 
 
57
  ASSERT (s1_size >= 1);
 
58
  ASSERT (MPN_SAME_OR_SEPARATE_P (res_ptr, s1_ptr, s1_size));
 
59
 
 
60
  /* The loop counter and index J goes from -SIZE to -1.  This way
 
61
     the loop becomes faster.  */
 
62
  j = -s1_size;
 
63
 
 
64
  /* Offset the base pointers to compensate for the negative indices.  */
 
65
  res_ptr -= j;
 
66
  s1_ptr -= j;
 
67
 
 
68
  cy_limb = 0;
 
69
  do
 
70
    {
 
71
      umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb);
 
72
 
 
73
      prod_low += cy_limb;
 
74
      cy_limb = (prod_low < cy_limb) + prod_high;
 
75
 
 
76
      x = res_ptr[j];
 
77
      VARIATION;
 
78
      res_ptr[j] = prod_low;
 
79
    }
 
80
  while (++j != 0);
 
81
 
 
82
  return cy_limb;
 
83
}