xref: /dragonfly/contrib/gmp/mpn/generic/bdiv_dbm1c.c (revision 86d7f5d3)
1*86d7f5d3SJohn Marino /* mpn_bdiv_dbm1c -- divide an mpn number by a divisor of B-1, where B is the
2*86d7f5d3SJohn Marino    limb base.  The dbm1c moniker means "Divisor of B Minus 1 with Carry".
3*86d7f5d3SJohn Marino 
4*86d7f5d3SJohn Marino    THE FUNCTION IN THIS FILE IS INTERNAL WITH A MUTABLE INTERFACE.  IT IS ONLY
5*86d7f5d3SJohn Marino    SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
6*86d7f5d3SJohn Marino    GUARANTEED THAT IT'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
7*86d7f5d3SJohn Marino 
8*86d7f5d3SJohn Marino Copyright 2008, 2009 Free Software Foundation, Inc.
9*86d7f5d3SJohn Marino 
10*86d7f5d3SJohn Marino This file is part of the GNU MP Library.
11*86d7f5d3SJohn Marino 
12*86d7f5d3SJohn Marino The GNU MP Library is free software; you can redistribute it and/or modify
13*86d7f5d3SJohn Marino it under the terms of the GNU Lesser General Public License as published by
14*86d7f5d3SJohn Marino the Free Software Foundation; either version 3 of the License, or (at your
15*86d7f5d3SJohn Marino option) any later version.
16*86d7f5d3SJohn Marino 
17*86d7f5d3SJohn Marino The GNU MP Library is distributed in the hope that it will be useful, but
18*86d7f5d3SJohn Marino WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19*86d7f5d3SJohn Marino or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
20*86d7f5d3SJohn Marino License for more details.
21*86d7f5d3SJohn Marino 
22*86d7f5d3SJohn Marino You should have received a copy of the GNU Lesser General Public License
23*86d7f5d3SJohn Marino along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
24*86d7f5d3SJohn Marino 
25*86d7f5d3SJohn Marino #include "gmp.h"
26*86d7f5d3SJohn Marino #include "gmp-impl.h"
27*86d7f5d3SJohn Marino #include "longlong.h"
28*86d7f5d3SJohn Marino 
29*86d7f5d3SJohn Marino 
30*86d7f5d3SJohn Marino mp_limb_t
mpn_bdiv_dbm1c(mp_ptr qp,mp_srcptr ap,mp_size_t n,mp_limb_t bd,mp_limb_t h)31*86d7f5d3SJohn Marino mpn_bdiv_dbm1c (mp_ptr qp, mp_srcptr ap, mp_size_t n, mp_limb_t bd, mp_limb_t h)
32*86d7f5d3SJohn Marino {
33*86d7f5d3SJohn Marino   mp_limb_t a, p0, p1, cy;
34*86d7f5d3SJohn Marino   mp_size_t i;
35*86d7f5d3SJohn Marino 
36*86d7f5d3SJohn Marino   for (i = 0; i < n; i++)
37*86d7f5d3SJohn Marino     {
38*86d7f5d3SJohn Marino       a = ap[i];
39*86d7f5d3SJohn Marino       umul_ppmm (p1, p0, a, bd << GMP_NAIL_BITS);
40*86d7f5d3SJohn Marino       p0 >>= GMP_NAIL_BITS;
41*86d7f5d3SJohn Marino       cy = h < p0;
42*86d7f5d3SJohn Marino       h = (h - p0) & GMP_NUMB_MASK;
43*86d7f5d3SJohn Marino       qp[i] = h;
44*86d7f5d3SJohn Marino       h = h - p1 - cy;
45*86d7f5d3SJohn Marino     }
46*86d7f5d3SJohn Marino 
47*86d7f5d3SJohn Marino   return h;
48*86d7f5d3SJohn Marino }
49