Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78075 - in sandbox/e_float: boost/e_float libs/e_float/src/e_float/efx
From: e_float_at_[hidden]
Date: 2012-04-18 18:28:38


Author: christopher_kormanyos
Date: 2012-04-18 18:28:37 EDT (Wed, 18 Apr 2012)
New Revision: 78075
URL: http://svn.boost.org/trac/boost/changeset/78075

Log:
Removed the temporary storage from the multiplication routine.
Organized the class constants better.

Text files modified:
   sandbox/e_float/boost/e_float/e_float_efx.hpp | 2 +-
   sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp | 33 +++++++++++++++------------------
   2 files changed, 16 insertions(+), 19 deletions(-)

Modified: sandbox/e_float/boost/e_float/e_float_efx.hpp
==============================================================================
--- sandbox/e_float/boost/e_float/e_float_efx.hpp (original)
+++ sandbox/e_float/boost/e_float/e_float_efx.hpp 2012-04-18 18:28:37 EDT (Wed, 18 Apr 2012)
@@ -151,7 +151,7 @@
 
       INT32 cmp_data(const array_type& vd) const;
 
- static void mul_loop_uv (const UINT32* const u, const UINT32* const v, UINT32* const w, const INT32 p);
+ static UINT32 mul_loop_uv (UINT32* const u, const UINT32* const v, const INT32 p);
       static UINT32 mul_loop_n (UINT32* const u, UINT32 n, const INT32 p);
       static UINT32 div_loop_n (UINT32* const u, UINT32 n, const INT32 p);
       static void mul_loop_fft(UINT32* const u, const UINT32* const v, const INT32 p);

Modified: sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp (original)
+++ sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp 2012-04-18 18:28:37 EDT (Wed, 18 Apr 2012)
@@ -21,9 +21,7 @@
 
 #include <iomanip>
 #include <algorithm>
-#include <numeric>
 #include <cmath>
-#include <utility>
 
 #include <boost/e_float/e_float_functions.hpp>
 
@@ -381,7 +379,7 @@
   std::copy(temp, temp + (std::min)(i, static_cast<std::size_t>(ef_elem_number)), data.begin());
 }
 
-void efx::e_float::mul_loop_uv(const UINT32* const u, const UINT32* const v, UINT32* const w, const INT32 p)
+UINT32 efx::e_float::mul_loop_uv(UINT32* const u, const UINT32* const v, const INT32 p)
 {
   UINT64 carry = static_cast<UINT64>(0u);
 
@@ -391,14 +389,14 @@
 
     for(INT32 i = j; i >= static_cast<INT32>(0); i--)
     {
- sum += static_cast<UINT64>(u[i] * static_cast<UINT64>(v[j - i]));
+ sum += static_cast<UINT64>(u[j - i] * static_cast<UINT64>(v[i]));
     }
 
- w[j + 1] = static_cast<UINT32>(sum % static_cast<UINT32>(ef_elem_mask));
- carry = static_cast<UINT64>(sum / static_cast<UINT32>(ef_elem_mask));
+ u[j] = static_cast<UINT32>(sum % static_cast<UINT32>(ef_elem_mask));
+ carry = static_cast<UINT64>(sum / static_cast<UINT32>(ef_elem_mask));
   }
 
- w[0u] = static_cast<UINT32>(carry);
+ return static_cast<UINT32>(carry);
 }
 
 template<const bool is_forward = true,
@@ -703,6 +701,7 @@
   }
 
   // Do the add/sub operation.
+ // TBD: Eliminate the temporary storage array n_data.
 
   array_type::iterator p_u = data.begin();
   array_type::const_iterator p_v = v.data.begin();
@@ -942,21 +941,19 @@
 
   if(prec_mul < 1000)
   {
- std::tr1::array<UINT32, static_cast<std::size_t>(ef_elem_number + static_cast<INT32>(1))> w = {{ 0u }};
-
- mul_loop_uv(data.data(), v.data.data(), w.data(), prec_mul);
+ const UINT32 carry = mul_loop_uv(data.data(), v.data.data(), prec_mul);
 
- // Copy the multiplication data into the result.
- // Shift the result and adjust the exponent if necessary.
- if(w[static_cast<std::size_t>(0u)] != static_cast<UINT32>(0u))
+ // Handle a potential carry.
+ if(carry != static_cast<UINT32>(0u))
     {
       exp += static_cast<INT64>(ef_elem_digits10);
 
- std::copy(w.begin(), w.begin() + prec_mul, data.begin());
- }
- else
- {
- std::copy(w.begin() + 1u, w.begin() + (prec_mul + 1), data.begin());
+ // Shift the result of the multiplication one element to the right.
+ std::copy_backward(data.begin(),
+ data.begin() + static_cast<std::size_t>(prec_elem - static_cast<INT32>(1)),
+ data.begin() + static_cast<std::size_t>(prec_elem));
+
+ data.front() = static_cast<UINT32>(carry);
     }
   }
   else


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