Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85449 - trunk/boost/multiprecision
From: john_at_[hidden]
Date: 2013-08-24 13:21:28


Author: johnmaddock
Date: 2013-08-24 13:21:28 EDT (Sat, 24 Aug 2013)
New Revision: 85449
URL: http://svn.boost.org/trac/boost/changeset/85449

Log:
Optimise squaring to use mpfr_sqr and mpfi_sqr.

Text files modified:
   trunk/boost/multiprecision/mpfi.hpp | 10 ++++++++--
   trunk/boost/multiprecision/mpfr.hpp | 10 ++++++++--
   2 files changed, 16 insertions(+), 4 deletions(-)

Modified: trunk/boost/multiprecision/mpfi.hpp
==============================================================================
--- trunk/boost/multiprecision/mpfi.hpp Sat Aug 24 13:13:18 2013 (r85448)
+++ trunk/boost/multiprecision/mpfi.hpp 2013-08-24 13:21:28 EDT (Sat, 24 Aug 2013) (r85449)
@@ -477,7 +477,10 @@
 template <unsigned D1, unsigned D2>
 inline void eval_multiply(mpfi_float_backend<D1>& result, const mpfi_float_backend<D2>& o)
 {
- mpfi_mul(result.data(), result.data(), o.data());
+ if(&result == &o)
+ mpfi_sqr(result.data(), o.data());
+ else
+ mpfi_mul(result.data(), result.data(), o.data());
 }
 template <unsigned D1, unsigned D2>
 inline void eval_divide(mpfi_float_backend<D1>& result, const mpfi_float_backend<D2>& o)
@@ -609,7 +612,10 @@
 template <unsigned D1, unsigned D2, unsigned D3>
 inline void eval_multiply(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, const mpfi_float_backend<D3>& y)
 {
- mpfi_mul(a.data(), x.data(), y.data());
+ if(&x == &y)
+ mpfi_sqr(a.data(), x.data());
+ else
+ mpfi_mul(a.data(), x.data(), y.data());
 }
 template <unsigned D1, unsigned D2>
 inline void eval_multiply(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, unsigned long y)

Modified: trunk/boost/multiprecision/mpfr.hpp
==============================================================================
--- trunk/boost/multiprecision/mpfr.hpp Sat Aug 24 13:13:18 2013 (r85448)
+++ trunk/boost/multiprecision/mpfr.hpp 2013-08-24 13:21:28 EDT (Sat, 24 Aug 2013) (r85449)
@@ -952,7 +952,10 @@
 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
 inline void eval_multiply(mpfr_float_backend<D1, A1>& result, const mpfr_float_backend<D2, A2>& o)
 {
- mpfr_mul(result.data(), result.data(), o.data(), GMP_RNDN);
+ if(&o == &result)
+ mpfr_sqr(result.data(), o.data(), GMP_RNDN);
+ else
+ mpfr_mul(result.data(), result.data(), o.data(), GMP_RNDN);
 }
 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
 inline void eval_divide(mpfr_float_backend<D1, A1>& result, const mpfr_float_backend<D2, A2>& o)
@@ -1084,7 +1087,10 @@
 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2, unsigned D3>
 inline void eval_multiply(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, const mpfr_float_backend<D3>& y)
 {
- mpfr_mul(a.data(), x.data(), y.data(), GMP_RNDN);
+ if(&x == &y)
+ mpfr_sqr(a.data(), x.data(), GMP_RNDN);
+ else
+ mpfr_mul(a.data(), x.data(), y.data(), GMP_RNDN);
 }
 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
 inline void eval_multiply(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, unsigned long y)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk