From c100247b248caf44b901abfe645ad793ecb41a51 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)> Date: Thu, 11 Feb 2010 20:36:56 +0000 Subject: [PATCH] Added a test for inv_divappr_q_n and made it pass. --- mpn/generic/inv_divappr_q_n.c | 13 +++++++------ mpn/generic/tdiv_q.c | 2 +- tests/mpn/Makefile.am | 2 +- tests/mpn/Makefile.in | 24 ++++++++++++++++-------- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/mpn/generic/inv_divappr_q_n.c b/mpn/generic/inv_divappr_q_n.c index d93dccea..cfb4fdcd 100644 --- a/mpn/generic/inv_divappr_q_n.c +++ b/mpn/generic/inv_divappr_q_n.c @@ -21,6 +21,7 @@ MA 02110-1301, USA. */ #include #include "gmp-impl.h" +#include "longlong.h" /* Computes an approximate quotient of { np, 2*dn } by { dp, dn } which is @@ -31,7 +32,7 @@ mp_limb_t mpn_inv_divappr_q_n(mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t dn, mp_srcptr inv) { - mp_limb_t ret = 0; + mp_limb_t cy, lo, ret = 0; mp_ptr tp; TMP_DECL; @@ -43,9 +44,11 @@ mpn_inv_divappr_q_n(mp_ptr qp, mp_ptr np, mpn_sub_n(np + dn, np + dn, dp, dn); } - tp = TMP_ALLOC_LIMBS(2*dn); - mpn_mulhigh_n(tp, np + dn, inv, dn); - mpn_add_n(qp, tp + dn, dp, dn); + tp = TMP_ALLOC_LIMBS(2*dn + 1); + mpn_mul(tp, np + dn - 1, dn + 1, inv, dn); + add_ssaaaa(cy, lo, 0, np[dn - 1], 0, tp[dn]); + mpn_add_n(qp, tp + dn + 1, np + dn, dn); + ret += mpn_add_1(qp, qp, dn, cy + 1); /* Let X = B^dn + inv, D = { dp, dn }, N = { np, 2*dn }, then @@ -55,8 +58,6 @@ mpn_inv_divappr_q_n(mp_ptr qp, mp_ptr np, NX//B^{2*dn} <= N//D <= NX//B^{2*dn} + 1. */ - ret += mpn_add_1(qp, qp, dn, 1); - if (UNLIKELY(ret == 2)) { ret = 1; diff --git a/mpn/generic/tdiv_q.c b/mpn/generic/tdiv_q.c index c968a571..61ddb761 100644 --- a/mpn/generic/tdiv_q.c +++ b/mpn/generic/tdiv_q.c @@ -196,7 +196,7 @@ mpn_tdiv_q (mp_ptr qp, { mp_ptr inv = TMP_ALLOC_LIMBS(dn); mpn_invert(inv, dp, dn); - qh = mpn_inv_div_q (qp, np, nn, dp, dn, inv); + qh = mpn_inv_div_q (qp, new_np, nn, dp, dn, inv); } qp[nn - dn] = qh; } diff --git a/tests/mpn/Makefile.am b/tests/mpn/Makefile.am index 4cda1a71..e5ac627f 100644 --- a/tests/mpn/Makefile.am +++ b/tests/mpn/Makefile.am @@ -28,7 +28,7 @@ check_PROGRAMS = t-asmtype t-aors_1 t-divrem_1 t-fat t-get_d \ t-lorrshift1 t-divebyff t-addadd_n t-addsub_n t-subadd_n \ t-redc_basecase t-divebyBm1of t-mullowhigh t-mullow_basecase \ t-neg t-mulmod_2expp1 t-mulmod_2expm1 t-tdiv_q t-sb_divappr_q \ - t-dc_divappr_q_n t-invert + t-dc_divappr_q_n t-inv_divappr_q_n t-invert if ENABLE_STATIC if ENABLE_SHARED diff --git a/tests/mpn/Makefile.in b/tests/mpn/Makefile.in index 0fa0db4b..7227dee1 100644 --- a/tests/mpn/Makefile.in +++ b/tests/mpn/Makefile.in @@ -61,7 +61,7 @@ check_PROGRAMS = t-asmtype$(EXEEXT) t-aors_1$(EXEEXT) \ t-neg$(EXEEXT) t-mulmod_2expp1$(EXEEXT) \ t-mulmod_2expm1$(EXEEXT) t-tdiv_q$(EXEEXT) \ t-sb_divappr_q$(EXEEXT) t-dc_divappr_q_n$(EXEEXT) \ - t-invert$(EXEEXT) $(am__EXEEXT_1) + t-inv_divappr_q_n$(EXEEXT) t-invert$(EXEEXT) $(am__EXEEXT_1) @ENABLE_SHARED_TRUE@@ENABLE_STATIC_TRUE@am__append_1 = st_fat st_instrument subdir = tests/mpn DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in @@ -150,6 +150,11 @@ t_instrument_OBJECTS = t-instrument.$(OBJEXT) t_instrument_LDADD = $(LDADD) t_instrument_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ $(top_builddir)/libmpir.la +t_inv_divappr_q_n_SOURCES = t-inv_divappr_q_n.c +t_inv_divappr_q_n_OBJECTS = t-inv_divappr_q_n.$(OBJEXT) +t_inv_divappr_q_n_LDADD = $(LDADD) +t_inv_divappr_q_n_DEPENDENCIES = $(top_builddir)/tests/libtests.la \ + $(top_builddir)/libmpir.la t_invert_SOURCES = t-invert.c t_invert_OBJECTS = t-invert.$(OBJEXT) t_invert_LDADD = $(LDADD) @@ -245,17 +250,17 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ SOURCES = $(st_fat_SOURCES) $(st_instrument_SOURCES) t-addadd_n.c \ t-addsub_n.c t-aors_1.c t-asmtype.c t-dc_divappr_q_n.c \ t-divebyBm1of.c t-divebyff.c t-divrem_1.c t-fat.c t-get_d.c \ - t-instrument.c t-invert.c t-iord_u.c t-lorrshift1.c \ - t-mp_bases.c t-mullow_basecase.c t-mullowhigh.c t-mulmid.c \ - t-mulmod_2expm1.c t-mulmod_2expp1.c t-neg.c t-perfsqr.c \ - t-redc_basecase.c t-sb_divappr_q.c t-scan.c t-subadd_n.c \ - t-tdiv_q.c + t-instrument.c t-inv_divappr_q_n.c t-invert.c t-iord_u.c \ + t-lorrshift1.c t-mp_bases.c t-mullow_basecase.c t-mullowhigh.c \ + t-mulmid.c t-mulmod_2expm1.c t-mulmod_2expp1.c t-neg.c \ + t-perfsqr.c t-redc_basecase.c t-sb_divappr_q.c t-scan.c \ + t-subadd_n.c t-tdiv_q.c DIST_SOURCES = $(am__st_fat_SOURCES_DIST) \ $(am__st_instrument_SOURCES_DIST) t-addadd_n.c t-addsub_n.c \ t-aors_1.c t-asmtype.c t-dc_divappr_q_n.c t-divebyBm1of.c \ t-divebyff.c t-divrem_1.c t-fat.c t-get_d.c t-instrument.c \ - t-invert.c t-iord_u.c t-lorrshift1.c t-mp_bases.c \ - t-mullow_basecase.c t-mullowhigh.c t-mulmid.c \ + t-inv_divappr_q_n.c t-invert.c t-iord_u.c t-lorrshift1.c \ + t-mp_bases.c t-mullow_basecase.c t-mullowhigh.c t-mulmid.c \ t-mulmod_2expm1.c t-mulmod_2expp1.c t-neg.c t-perfsqr.c \ t-redc_basecase.c t-sb_divappr_q.c t-scan.c t-subadd_n.c \ t-tdiv_q.c @@ -500,6 +505,9 @@ t-get_d$(EXEEXT): $(t_get_d_OBJECTS) $(t_get_d_DEPENDENCIES) t-instrument$(EXEEXT): $(t_instrument_OBJECTS) $(t_instrument_DEPENDENCIES) @rm -f t-instrument$(EXEEXT) $(LINK) $(t_instrument_OBJECTS) $(t_instrument_LDADD) $(LIBS) +t-inv_divappr_q_n$(EXEEXT): $(t_inv_divappr_q_n_OBJECTS) $(t_inv_divappr_q_n_DEPENDENCIES) + @rm -f t-inv_divappr_q_n$(EXEEXT) + $(LINK) $(t_inv_divappr_q_n_OBJECTS) $(t_inv_divappr_q_n_LDADD) $(LIBS) t-invert$(EXEEXT): $(t_invert_OBJECTS) $(t_invert_DEPENDENCIES) @rm -f t-invert$(EXEEXT) $(LINK) $(t_invert_OBJECTS) $(t_invert_LDADD) $(LIBS)