Coverage Report

Created: 2024-06-28 06:19

/src/gmp-6.2.1/mpn/bdiv_q.c
Line
Count
Source (jump to first uncovered line)
1
/* mpn_bdiv_q -- Hensel division with precomputed inverse, returning quotient.
2
3
   Contributed to the GNU project by Torbjorn Granlund.
4
5
   THE FUNCTIONS IN THIS FILE ARE INTERNAL WITH MUTABLE INTERFACES.  IT IS ONLY
6
   SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
7
   GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GMP RELEASE.
8
9
Copyright 2006, 2007, 2009 Free Software Foundation, Inc.
10
11
This file is part of the GNU MP Library.
12
13
The GNU MP Library is free software; you can redistribute it and/or modify
14
it under the terms of either:
15
16
  * the GNU Lesser General Public License as published by the Free
17
    Software Foundation; either version 3 of the License, or (at your
18
    option) any later version.
19
20
or
21
22
  * the GNU General Public License as published by the Free Software
23
    Foundation; either version 2 of the License, or (at your option) any
24
    later version.
25
26
or both in parallel, as here.
27
28
The GNU MP Library is distributed in the hope that it will be useful, but
29
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
30
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
31
for more details.
32
33
You should have received copies of the GNU General Public License and the
34
GNU Lesser General Public License along with the GNU MP Library.  If not,
35
see https://www.gnu.org/licenses/.  */
36
37
#include "gmp-impl.h"
38
39
40
/* Computes Q = N / D mod B^n. */
41
42
void
43
mpn_bdiv_q (mp_ptr qp,
44
      mp_srcptr np, mp_size_t nn,
45
      mp_srcptr dp, mp_size_t dn,
46
      mp_ptr tp)
47
1.29k
{
48
1.29k
  mp_limb_t di;
49
50
1.29k
  if (BELOW_THRESHOLD (dn, DC_BDIV_Q_THRESHOLD))
51
975
    {
52
975
      MPN_COPY (tp, np, nn);
53
975
      binvert_limb (di, dp[0]);  di = -di;
54
975
      mpn_sbpi1_bdiv_q (qp, tp, nn, dp, dn, di);
55
975
    }
56
322
  else if (BELOW_THRESHOLD (dn, MU_BDIV_Q_THRESHOLD))
57
322
    {
58
322
      MPN_COPY (tp, np, nn);
59
322
      binvert_limb (di, dp[0]);  di = -di;
60
322
      mpn_dcpi1_bdiv_q (qp, tp, nn, dp, dn, di);
61
322
    }
62
0
  else
63
0
    {
64
0
      mpn_mu_bdiv_q (qp, np, nn, dp, dn, tp);
65
0
    }
66
1.29k
  return;
67
1.29k
}
68
69
mp_size_t
70
mpn_bdiv_q_itch (mp_size_t nn, mp_size_t dn)
71
1.29k
{
72
1.29k
  if (BELOW_THRESHOLD (dn, MU_BDIV_Q_THRESHOLD))
73
1.29k
    return nn;
74
0
  else
75
0
    return mpn_mu_bdiv_q_itch (nn, dn);
76
1.29k
}