From e967731486788bc04070076d1c4ee4542dacf32b Mon Sep 17 00:00:00 2001 From: William Hart Date: Thu, 11 Apr 2013 01:05:33 +0100 Subject: [PATCH] Move divrem fixup into macro. --- gmp-impl.h | 17 ++++++++++++----- mpn/generic/sb_div_qr.c | 10 +--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/gmp-impl.h b/gmp-impl.h index 8a5c90cb..3cebbff3 100644 --- a/gmp-impl.h +++ b/gmp-impl.h @@ -2778,19 +2778,26 @@ do { \ add_ssaaaa((q), __q2, (q), __q2, 0, __q3); \ } while (0) -#define mpir_divrem32_preinv2(q, r2, r3, a1, a2, a3, d1, d2, dinv) \ +#define mpir_divrem32_preinv2(q, r2, r3, a1, a2, a3, d11, d21, d1, d2, dinv) \ do { \ mp_limb_t __q2, __q3, __q4, __p1, __p2, __cy; \ umul_ppmm((q), __q2, (a1), (dinv)); \ add_ssaaaa((q), __q2, (q), __q2, (a1), (a2)); \ - umul_ppmm(__p1, __p2, (q), (d2)); \ + umul_ppmm(__p1, __p2, (q), (d21)); \ (r3) = (a3); \ - (r2) = (a2) - (q)*(d1); \ + (r2) = (a2) - (q)*(d11); \ sub_ddmmss((r2), (r3), (r2), (r3), __p1, __p2); \ - sub_ddmmss((r2), (r3), (r2), (r3), (d1), (d2)); \ + sub_ddmmss((r2), (r3), (r2), (r3), (d11), (d21)); \ (q)++; \ if ((r2) >= __q2) \ - { (q)--; add_ssaaaa((r2), (r3), (r2), (r3), (d1), (d2)); } \ + { (q)--; add_ssaaaa((r2), (r3), (r2), (r3), (d11), (d21)); } \ + add_333(__cy, (r2), (r3), 0, (r2), (r3), 0, 0, (q)); \ + while (UNLIKELY(__cy != 0 || (r2) >= (d1))) \ + { \ + if ((r2) == (d1) && (r3) < (d2) && __cy == 0) break; \ + sub_333(__cy, (r2), (r3), __cy, (r2), (r3), 0, (d1), (d2)); \ + (q)++; \ + } \ } while (0) /* Compute quotient the quotient and remainder for n / d. Requires d diff --git a/mpn/generic/sb_div_qr.c b/mpn/generic/sb_div_qr.c index 01eb277a..1c512fde 100644 --- a/mpn/generic/sb_div_qr.c +++ b/mpn/generic/sb_div_qr.c @@ -110,15 +110,7 @@ mpn_sb_div_qr (mp_ptr qp, } else { - mpir_divrem32_preinv2(q, n1, n0, n1, np[1], np[0], d11, d01, dinv); - - add_333(cy, n1, n0, 0, n1, n0, 0, 0, q); - while (UNLIKELY(cy != 0 || n1 >= d1)) - { - if (n1 == d1 && n0 < d0 && cy == 0) break; - sub_333(cy, n1, n0, cy, n1, n0, 0, d1, d0); - (q)++; - } + mpir_divrem32_preinv2(q, n1, n0, n1, np[1], np[0], d11, d01, d1, d0, dinv); cy2 = mpn_submul_1 (np - dn, dp, dn, q);