summaryrefslogtreecommitdiff
path: root/div.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2005-11-24 20:39:23 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2005-11-24 20:39:23 +0000
commit8b2442fa819b17a2240c5dd2baa7d45ef0d7616d (patch)
tree04a5bfd201ecf99ce782a5687385aed4afb0f56b /div.c
parentb128d9ca9406339234811030e68a79bfda650ce0 (diff)
downloadmpfr-8b2442fa819b17a2240c5dd2baa7d45ef0d7616d.tar.gz
fixed efficiency bug for small divisor (division had same cost than for
divisor of the same size than the result) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3963 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'div.c')
-rw-r--r--div.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/div.c b/div.c
index 81713ec7c..35f3bbca3 100644
--- a/div.c
+++ b/div.c
@@ -251,7 +251,7 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode)
sticky bits */
qsize = q0size + 1;
/* need to allocate memory for the quotient */
- qp = (mp_ptr) MPFR_TMP_ALLOC (qsize*sizeof(mp_limb_t));
+ qp = (mp_ptr) MPFR_TMP_ALLOC (qsize * sizeof(mp_limb_t));
}
else
{
@@ -261,7 +261,7 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode)
qqsize = qsize + qsize;
/* prepare the dividend */
- ap = (mp_ptr) MPFR_TMP_ALLOC (qqsize*sizeof(mp_limb_t));
+ ap = (mp_ptr) MPFR_TMP_ALLOC (qqsize * sizeof(mp_limb_t));
if (MPFR_LIKELY(qqsize > usize)) /* use the full dividend */
{
k = qqsize - usize; /* k > 0 */
@@ -298,19 +298,18 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode)
MPN_COPY(bp, vp, vsize);
}
sticky_v = sticky_v || mpn_cmpzero (vp, k);
+ k = 0;
}
- else /* vsize < qsize */
+ else /* vsize < qsize: small divisor case */
{
+ bp = vp;
k = qsize - vsize;
- bp = (mp_ptr) MPFR_TMP_ALLOC (qsize * sizeof(mp_limb_t));
- MPN_COPY(bp + k, vp, vsize);
- MPN_ZERO(bp, k);
}
/* we now can perform the division */
- qh = mpn_divrem (qp, 0, ap, qqsize, bp, qsize);
+ qh = mpn_divrem (qp, 0, ap + k, qqsize - k, bp, qsize - k);
/* warning: qh may be 1 if u1 == v1, but u < v */
-#ifdef DEBUG
+#ifdef DEBUG2
printf ("q="); mpn_print (qp, qsize);
printf ("r="); mpn_print (ap, qsize);
#endif
@@ -402,7 +401,7 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode)
mp_ptr sp;
int cmp_s_r;
- sp = (mp_ptr) MPFR_TMP_ALLOC (vsize*sizeof(mp_limb_t));
+ sp = (mp_ptr) MPFR_TMP_ALLOC (vsize * sizeof(mp_limb_t));
k = vsize - qsize;
/* sp <- {qp, qsize} * {vp, vsize-qsize} */
qp[0] ^= sticky3orig; /* restore original quotient */