Line | Count | Source (jump to first uncovered line) |
1 | | /* mpn_preinv_mod_1 (up, un, d, dinv) -- Divide (UP,,UN) by the normalized D. |
2 | | DINV should be 2^(2*GMP_LIMB_BITS) / D - 2^GMP_LIMB_BITS. |
3 | | Return the single-limb remainder. |
4 | | |
5 | | Copyright 1991, 1993, 1994, 2000-2002, 2004, 2005 Free Software Foundation, |
6 | | 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 either: |
12 | | |
13 | | * the GNU Lesser General Public License as published by the Free |
14 | | Software Foundation; either version 3 of the License, or (at your |
15 | | option) any later version. |
16 | | |
17 | | or |
18 | | |
19 | | * the GNU General Public License as published by the Free Software |
20 | | Foundation; either version 2 of the License, or (at your option) any |
21 | | later version. |
22 | | |
23 | | or both in parallel, as here. |
24 | | |
25 | | The GNU MP Library is distributed in the hope that it will be useful, but |
26 | | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
27 | | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
28 | | for more details. |
29 | | |
30 | | You should have received copies of the GNU General Public License and the |
31 | | GNU Lesser General Public License along with the GNU MP Library. If not, |
32 | | see https://www.gnu.org/licenses/. */ |
33 | | |
34 | | #include "gmp-impl.h" |
35 | | #include "longlong.h" |
36 | | |
37 | | |
38 | | /* This function used to be documented, but is now considered obsolete. It |
39 | | continues to exist for binary compatibility, even when not required |
40 | | internally. */ |
41 | | |
42 | | mp_limb_t |
43 | | mpn_preinv_mod_1 (mp_srcptr up, mp_size_t un, mp_limb_t d, mp_limb_t dinv) |
44 | 0 | { |
45 | 0 | mp_size_t i; |
46 | 0 | mp_limb_t n0, r; |
47 | |
|
48 | 0 | ASSERT (un >= 1); |
49 | 0 | ASSERT (d & GMP_LIMB_HIGHBIT); |
50 | |
|
51 | 0 | r = up[un - 1]; |
52 | 0 | if (r >= d) |
53 | 0 | r -= d; |
54 | |
|
55 | 0 | for (i = un - 2; i >= 0; i--) |
56 | 0 | { |
57 | 0 | n0 = up[i]; |
58 | 0 | udiv_rnnd_preinv (r, r, n0, d, dinv); |
59 | 0 | } |
60 | 0 | return r; |
61 | 0 | } |