dma: rework config parsing
[dragonfly.git] / contrib / gmp / mpn / generic / dc_div_q.c
blob276ae4fba6b5318412ac635d79da6fd3d032ea6f
1 /* mpn_dc_div_q -- divide-and-conquer division, returning exact quotient only.
3 Contributed to the GNU project by Torbjörn Granlund.
5 THE FUNCTIONS IN THIS FILE ARE INTERNAL WITH A MUTABLE INTERFACE. IT IS
6 ONLY SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS
7 ALMOST GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GMP
8 RELEASE.
10 Copyright 2006, 2007 Free Software Foundation, Inc.
12 This file is part of the GNU MP Library.
14 The GNU MP Library is free software; you can redistribute it and/or modify
15 it under the terms of the GNU Lesser General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or (at your
17 option) any later version.
19 The GNU MP Library is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
22 License for more details.
24 You should have received a copy of the GNU Lesser General Public License
25 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
27 #include "gmp.h"
28 #include "gmp-impl.h"
31 mp_limb_t
32 mpn_dc_div_q (mp_ptr qp, mp_ptr np, mp_size_t nn, mp_srcptr dp, mp_size_t dn)
34 mp_ptr tp, wp;
35 mp_limb_t qh;
36 mp_size_t qn;
37 TMP_DECL;
39 TMP_MARK;
41 tp = TMP_SALLOC_LIMBS (nn + 1);
42 MPN_COPY (tp + 1, np, nn);
43 tp[0] = 0;
45 qn = nn - dn;
46 wp = TMP_SALLOC_LIMBS (qn + 1);
48 qh = mpn_dc_divappr_q (wp, tp, nn + 1, dp, dn);
50 if (wp[0] == 0)
51 /* FIXME: Should multiply and subtract here, not recompute from scratch. */
52 qh = mpn_dc_div_qr (qp, np, nn, dp, dn);
53 else
54 MPN_COPY (qp, wp + 1, qn);
56 return qh;