SourceForge Logo Tiny Vector Matrix library using Expression Templates Sourceforge Project Page

include/tvmet/loop/Gemtm.h

Go to the documentation of this file.
00001 /*
00002  * Tiny Vector Matrix Library
00003  * Dense Vector Matrix Libary of Tiny size using Expression Templates
00004  *
00005  * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * $Id: Gemtm.h,v 1.9 2007-06-23 15:58:59 opetzold Exp $
00022  */
00023 
00024 #ifndef TVMET_LOOP_GEMTM_H
00025 #define TVMET_LOOP_GEMTM_H
00026 
00027 namespace tvmet {
00028 
00029 namespace loop {
00030 
00031 
00058 template<std::size_t Rows1, std::size_t Cols1,
00059    std::size_t Cols2>
00060 class gemtm
00061 {
00062   gemtm(const gemtm&);
00063   gemtm& operator=(const gemtm&);
00064 
00065 private:
00066   enum {
00067     count   = Cols1,
00068     N     = (count+7)/8
00069   };
00070 
00071 public:
00072   gemtm() { }
00073 
00074 public:
00075   template<class E1, class E2>
00076   static inline
00077   typename PromoteTraits<
00078     typename E1::value_type,
00079     typename E2::value_type
00080     >::value_type
00081   prod(const E1& lhs, const E2& rhs, std::size_t i, std::size_t j) {
00082     typename PromoteTraits<
00083       typename E1::value_type,
00084       typename E2::value_type
00085     >::value_type         sum(0);
00086     std::size_t         k(0);
00087     std::size_t         n(N);
00088 
00089     // Duff's device
00090     switch(count % 8) {
00091     case 0: do { sum += lhs(k, i) * rhs(k, j); ++k;
00092     case 7:      sum += lhs(k, i) * rhs(k, j); ++k;
00093     case 6:      sum += lhs(k, i) * rhs(k, j); ++k;
00094     case 5:      sum += lhs(k, i) * rhs(k, j); ++k;
00095     case 4:      sum += lhs(k, i) * rhs(k, j); ++k;
00096     case 3:      sum += lhs(k, i) * rhs(k, j); ++k;
00097     case 2:      sum += lhs(k, i) * rhs(k, j); ++k;
00098     case 1:      sum += lhs(k, i) * rhs(k, j); ++k;
00099             } while(--n != 0);
00100     }
00101 
00102     return sum;
00103   }
00104 };
00105 
00106 
00107 } // namespace loop
00108 
00109 } // namespace tvmet
00110 
00111 #endif /* TVMET_LOOP_GEMTM_H */
00112 
00113 // Local Variables:
00114 // mode:C++
00115 // tab-width:8
00116 // End:

Author: