Boost logo

Boost-Commit :

From: garcia_at_[hidden]
Date: 2007-08-26 15:40:26


Author: garcia
Date: 2007-08-26 15:40:25 EDT (Sun, 26 Aug 2007)
New Revision: 38974
URL: http://svn.boost.org/trac/boost/changeset/38974

Log:
Implemented an mpl::int_ based unrolling copy algorithm.
Changed subarrays to carry their own copy of extents, strides, and index bases
(in the hopes that this helps gcc track data dependencies)
implemented the copying of this data using the unrolling copy algorithm
because gcc does not seem to optimize for loops or std::copy very well.

Text files modified:
   branches/multi_array/boost/multi_array/algorithm.hpp | 22 ++++++++++++++++++++++
   branches/multi_array/boost/multi_array/subarray.hpp | 20 +++++++++++++-------
   2 files changed, 35 insertions(+), 7 deletions(-)

Modified: branches/multi_array/boost/multi_array/algorithm.hpp
==============================================================================
--- branches/multi_array/boost/multi_array/algorithm.hpp (original)
+++ branches/multi_array/boost/multi_array/algorithm.hpp 2007-08-26 15:40:25 EDT (Sun, 26 Aug 2007)
@@ -41,10 +41,12 @@
 
 
 #include "boost/iterator.hpp"
+#include "boost/mpl/int.hpp"
 
 namespace boost {
 namespace detail {
 namespace multi_array {
+ using ::boost::mpl::int_;
 //--------------------------------------------------
 // copy_n (not part of the C++ standard)
 #if 1
@@ -96,6 +98,26 @@
 }
 
 #endif // 1
+
+template <class InputIter, int N, class OutputIter>
+void unroll_copy_n(InputIter first, int_<N>,
+ OutputIter result) {
+ *result = *first;
+ unroll_copy_n(++first,int_<N-1>(),++result);
+}
+
+template <class InputIter,class OutputIter>
+void
+unroll_copy_n(InputIter first, int_<1>, OutputIter result) {
+ *result = *first;
+}
+
+template <class InputIter,class OutputIter>
+void
+unroll_copy_n(InputIter first, int_<0>, OutputIter result) {
+}
+
+
 } // namespace multi_array
 } // namespace detail
 } // namespace boost

Modified: branches/multi_array/boost/multi_array/subarray.hpp
==============================================================================
--- branches/multi_array/boost/multi_array/subarray.hpp (original)
+++ branches/multi_array/boost/multi_array/subarray.hpp 2007-08-26 15:40:25 EDT (Sun, 26 Aug 2007)
@@ -22,6 +22,7 @@
 #include "boost/multi_array/concept_checks.hpp"
 #include "boost/limits.hpp"
 #include "boost/type.hpp"
+#include "boost/multi_array/algorithm.hpp"
 #include <algorithm>
 #include <cstddef>
 #include <functional>
@@ -30,6 +31,7 @@
 namespace detail {
 namespace multi_array {
 
+ using ::boost::mpl::int_;
 //
 // const_sub_array
 // multi_array's proxy class to allow multiple overloads of
@@ -66,8 +68,10 @@
 
   template <typename OPtr>
   const_sub_array (const const_sub_array<T,NumDims,OPtr>& rhs) :
- base_(rhs.base_), extents_(rhs.extents_), strides_(rhs.strides_),
- index_base_(rhs.index_base_) {
+ base_(rhs.base_) {
+ unroll_copy_n(rhs.extents_,int_<NumDims>(),&extents_[0]);
+ unroll_copy_n(rhs.strides_,int_<NumDims>(),&strides_[0]);
+ unroll_copy_n(rhs.index_base_,int_<NumDims>(),&index_base_[0]);
   }
 
   // const_sub_array always returns const types, regardless of its own
@@ -183,14 +187,16 @@
                  const size_type* extents,
                  const index* strides,
                  const index* index_base) :
- base_(base), extents_(extents), strides_(strides),
- index_base_(index_base) {
+ base_(base) {
+ unroll_copy_n(extents,int_<NumDims>(),&extents_[0]);
+ unroll_copy_n(strides,int_<NumDims>(),&strides_[0]);
+ unroll_copy_n(index_base,int_<NumDims>(),&index_base_[0]);
   }
 
   TPtr base_;
- const size_type* extents_;
- const index* strides_;
- const index* index_base_;
+ size_type extents_[NumDims];
+ index strides_[NumDims];
+ index index_base_[NumDims];
 private:
   // const_sub_array cannot be assigned to (no deep copies!)
   const_sub_array& operator=(const const_sub_array&);


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