Coverage Report

Created: 2025-03-18 06:55

/src/gmp/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
0
{
48
0
  mp_limb_t di;
49
50
0
  if (BELOW_THRESHOLD (dn, DC_BDIV_Q_THRESHOLD))
51
0
    {
52
0
      MPN_COPY (tp, np, nn);
53
0
      binvert_limb (di, dp[0]);  di = -di;
54
0
      mpn_sbpi1_bdiv_q (qp, tp, nn, dp, dn, di);
55
0
    }
56
0
  else if (BELOW_THRESHOLD (dn, MU_BDIV_Q_THRESHOLD))
57
0
    {
58
0
      MPN_COPY (tp, np, nn);
59
0
      binvert_limb (di, dp[0]);  di = -di;
60
0
      mpn_dcpi1_bdiv_q (qp, tp, nn, dp, dn, di);
61
0
    }
62
0
  else
63
0
    {
64
0
      mpn_mu_bdiv_q (qp, np, nn, dp, dn, tp);
65
0
    }
66
0
  return;
67
0
}
68
69
mp_size_t
70
mpn_bdiv_q_itch (mp_size_t nn, mp_size_t dn)
71
0
{
72
0
  if (BELOW_THRESHOLD (dn, MU_BDIV_Q_THRESHOLD))
73
0
    return nn;
74
0
  else
75
0
    return mpn_mu_bdiv_q_itch (nn, dn);
76
0
}