Coverage Report

Created: 2024-11-25 06:27

/src/gmp/mpn/bdiv_dbm1c.c
Line
Count
Source
1
/* mpn_bdiv_dbm1c -- divide an mpn number by a divisor of B-1, where B is the
2
   limb base.  The dbm1c moniker means "Divisor of B Minus 1 with Carry".
3
4
   THE FUNCTION IN THIS FILE IS INTERNAL WITH A MUTABLE INTERFACE.  IT IS ONLY
5
   SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
6
   GUARANTEED THAT IT'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
7
8
Copyright 2008, 2009 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 either:
14
15
  * the GNU Lesser General Public License as published by the Free
16
    Software Foundation; either version 3 of the License, or (at your
17
    option) any later version.
18
19
or
20
21
  * the GNU General Public License as published by the Free Software
22
    Foundation; either version 2 of the License, or (at your option) any
23
    later version.
24
25
or both in parallel, as here.
26
27
The GNU MP Library is distributed in the hope that it will be useful, but
28
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
29
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
30
for more details.
31
32
You should have received copies of the GNU General Public License and the
33
GNU Lesser General Public License along with the GNU MP Library.  If not,
34
see https://www.gnu.org/licenses/.  */
35
36
#include "gmp-impl.h"
37
#include "longlong.h"
38
39
40
mp_limb_t
41
mpn_bdiv_dbm1c (mp_ptr qp, mp_srcptr ap, mp_size_t n, mp_limb_t bd, mp_limb_t h)
42
57.2k
{
43
57.2k
  mp_limb_t a, p0, p1, cy;
44
57.2k
  mp_size_t i;
45
46
5.03M
  for (i = 0; i < n; i++)
47
4.97M
    {
48
4.97M
      a = ap[i];
49
4.97M
      umul_ppmm (p1, p0, a, bd << GMP_NAIL_BITS);
50
4.97M
      p0 >>= GMP_NAIL_BITS;
51
4.97M
      cy = h < p0;
52
4.97M
      h = (h - p0) & GMP_NUMB_MASK;
53
4.97M
      qp[i] = h;
54
4.97M
      h = h - p1 - cy;
55
4.97M
    }
56
57
57.2k
  return h;
58
57.2k
}