remove empty dir
[ghc-hetmet.git] / rts / gmp / mpn / generic / pre_mod_1.c
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 (C) 1991, 1993, 1994, 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 #ifndef UMUL_TIME
32 #define UMUL_TIME 1
33 #endif
34
35 #ifndef UDIV_TIME
36 #define UDIV_TIME UMUL_TIME
37 #endif
38
39 mp_limb_t
40 #if __STDC__
41 mpn_preinv_mod_1 (mp_srcptr dividend_ptr, mp_size_t dividend_size,
42                   mp_limb_t divisor_limb, mp_limb_t divisor_limb_inverted)
43 #else
44 mpn_preinv_mod_1 (dividend_ptr, dividend_size, divisor_limb, divisor_limb_inverted)
45      mp_srcptr dividend_ptr;
46      mp_size_t dividend_size;
47      mp_limb_t divisor_limb;
48      mp_limb_t divisor_limb_inverted;
49 #endif
50 {
51   mp_size_t i;
52   mp_limb_t n0, r;
53   int dummy;
54
55   i = dividend_size - 1;
56   r = dividend_ptr[i];
57
58   if (r >= divisor_limb)
59     r = 0;
60   else
61     i--;
62
63   for (; i >= 0; i--)
64     {
65       n0 = dividend_ptr[i];
66       udiv_qrnnd_preinv (dummy, r, r, n0, divisor_limb, divisor_limb_inverted);
67     }
68   return r;
69 }