diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-12-28 12:24:13 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-12-28 12:24:13 +0000 |
commit | dbe96dbd1e833dc0e9c7cb6610f51ce70780f474 (patch) | |
tree | 5fa5549a6fed8722b313dd6ac23bf0f11b9941b9 | |
parent | f57831e545d7e98cd0e648a9ecedf710d7dd2654 (diff) | |
download | mpfr-dbe96dbd1e833dc0e9c7cb6610f51ce70780f474.tar.gz |
[src/sqr.c] use special code for 1 and 2 limbs
[mbench] added mpfr_sqr
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11098 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/mpfr-impl.h | 4 | ||||
-rw-r--r-- | src/mul.c | 14 | ||||
-rw-r--r-- | src/sqr.c | 9 | ||||
-rw-r--r-- | tools/mbench/mfv5-mpfr.cc | 8 |
4 files changed, 28 insertions, 7 deletions
diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h index 318fd1be2..0b9f2a9fa 100644 --- a/src/mpfr-impl.h +++ b/src/mpfr-impl.h @@ -2096,6 +2096,10 @@ __MPFR_DECLSPEC int mpfr_add1sp (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t); __MPFR_DECLSPEC int mpfr_sub1sp (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t); +__MPFR_DECLSPEC int mpfr_mul_1 (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t, + mpfr_prec_t); +__MPFR_DECLSPEC int mpfr_mul_2 (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t, + mpfr_prec_t); __MPFR_DECLSPEC int mpfr_can_round_raw (const mp_limb_t *, mp_size_t, int, mpfr_exp_t, mpfr_rnd_t, mpfr_rnd_t, mpfr_prec_t); @@ -205,9 +205,10 @@ mpfr_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) /* Multiply 2 mpfr_t */ -/* special code for prec(a) < GMP_NUMB_BITS and - prec(b), prec(c) <= GMP_NUMB_BITS */ -static int +/* Special code for prec(a) < GMP_NUMB_BITS and + prec(b), prec(c) <= GMP_NUMB_BITS. + We export it since it is called from mpfr_sqr too. */ +int mpfr_mul_1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode, mpfr_prec_t p) { @@ -301,9 +302,10 @@ mpfr_mul_1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode, } } -/* special code for GMP_NUMB_BITS < prec(a) < 2*GMP_NUMB_BITS and - GMP_NUMB_BITS < prec(b), prec(c) <= 2*GMP_NUMB_BITS */ -static int +/* Special code for GMP_NUMB_BITS < prec(a) < 2*GMP_NUMB_BITS and + GMP_NUMB_BITS < prec(b), prec(c) <= 2*GMP_NUMB_BITS. + It is exported since called from mpfr_sqr too. */ +int mpfr_mul_2 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode, mpfr_prec_t p) { @@ -53,9 +53,16 @@ mpfr_sqr (mpfr_ptr a, mpfr_srcptr b, mpfr_rnd_t rnd_mode) ( MPFR_ASSERTD(MPFR_IS_ZERO(b)), MPFR_SET_ZERO(a) ); MPFR_RET(0); } - ax = 2 * MPFR_GET_EXP (b); bq = MPFR_PREC(b); + if (MPFR_GET_PREC(a) < GMP_NUMB_BITS && bq <= GMP_NUMB_BITS) + return mpfr_mul_1 (a, b, b, rnd_mode, MPFR_GET_PREC(a)); + + if (GMP_NUMB_BITS < MPFR_GET_PREC(a) && MPFR_GET_PREC(a) < 2 * GMP_NUMB_BITS + && GMP_NUMB_BITS < bq && bq <= 2 * GMP_NUMB_BITS) + return mpfr_mul_2 (a, b, b, rnd_mode, MPFR_GET_PREC(a)); + + ax = 2 * MPFR_GET_EXP (b); MPFR_ASSERTN (2 * (mpfr_uprec_t) bq <= MPFR_PREC_MAX); bn = MPFR_LIMB_SIZE (b); /* number of limbs of b */ diff --git a/tools/mbench/mfv5-mpfr.cc b/tools/mbench/mfv5-mpfr.cc index 3d667429b..48496bae0 100644 --- a/tools/mbench/mfv5-mpfr.cc +++ b/tools/mbench/mfv5-mpfr.cc @@ -114,6 +114,13 @@ public: } }; +class mpfr_sqr_test { +public: + int func(mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t r) { + return mpfr_sqr (a,b,r); + } +}; + class mpfr_fma_test { public: int func(mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_srcptr d, mp_rnd_t r) { @@ -280,6 +287,7 @@ static mpfr_test4<mpfr_fmma_test> test12 ("mpfr_fmma"); #ifdef mpfr_fmms static mpfr_test4<mpfr_fmms_test> test13 ("mpfr_fmms"); #endif +static mpfr_test<mpfr_sqr_test> test14 ("mpfr_sqr"); static mpfr_test<mpfr_div_test> test4 ("mpfr_div"); static mpfr_test<mpfr_set_test> test5 ("mpfr_set"); |