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

« back to all changes in this revision

Viewing changes to gmp3/mpn/generic/pre_mod_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_preinv_mod_1 (dividend_ptr, dividend_size, divisor_limb,
 
2
                       divisor_limb_inverted) --
 
3
   Divide (DIVIDEND_PTR,,DIVIDEND_SIZE) by the normalized DIVISOR_LIMB.
 
4
   DIVISOR_LIMB_INVERTED should be 2^(2*BITS_PER_MP_LIMB) / DIVISOR_LIMB +
 
5
   - 2^BITS_PER_MP_LIMB.
 
6
   Return the single-limb remainder.
 
7
 
 
8
Copyright 1991, 1993, 1994, 2000, 2001 Free Software Foundation, Inc.
 
9
 
 
10
This file is part of the GNU MP Library.
 
11
 
 
12
The GNU MP Library is free software; you can redistribute it and/or modify
 
13
it under the terms of the GNU Lesser General Public License as published by
 
14
the Free Software Foundation; either version 2.1 of the License, or (at your
 
15
option) any later version.
 
16
 
 
17
The GNU MP Library is distributed in the hope that it will be useful, but
 
18
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
19
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
20
License for more details.
 
21
 
 
22
You should have received a copy of the GNU Lesser General Public License
 
23
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
 
24
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
25
MA 02111-1307, USA. */
 
26
 
 
27
#include "gmp.h"
 
28
#include "gmp-impl.h"
 
29
#include "longlong.h"
 
30
 
 
31
 
 
32
mp_limb_t
 
33
mpn_preinv_mod_1 (mp_srcptr dividend_ptr, mp_size_t dividend_size,
 
34
                  mp_limb_t divisor_limb, mp_limb_t divisor_limb_inverted)
 
35
{
 
36
  mp_size_t i;
 
37
  mp_limb_t n0, r;
 
38
  mp_limb_t dummy;
 
39
 
 
40
  ASSERT (dividend_size >= 1);
 
41
  ASSERT (divisor_limb & MP_LIMB_T_HIGHBIT);
 
42
 
 
43
  r = dividend_ptr[dividend_size-1];
 
44
  if (r >= divisor_limb)
 
45
    r -= divisor_limb;
 
46
 
 
47
  for (i = dividend_size - 2; i >= 0; i--)
 
48
    {
 
49
      n0 = dividend_ptr[i];
 
50
      udiv_qrnnd_preinv (dummy, r, r, n0, divisor_limb, divisor_limb_inverted);
 
51
    }
 
52
  return r;
 
53
}