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

include/tvmet/loop/Gemtv.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: Gemtv.h,v 1.7 2007-06-23 15:58:59 opetzold Exp $
00022  */
00023 
00024 #ifndef TVMET_LOOP_GEMTV_H
00025 #define TVMET_LOOP_GEMTV_H
00026 
00027 namespace tvmet {
00028 
00029 namespace loop {
00030 
00031 
00053 template<std::size_t Rows, std::size_t Cols>
00054 class gemtv
00055 {
00056   gemtv(const gemtv&);
00057   gemtv& operator=(const gemtv&);
00058 
00059 private:
00060   enum {
00061     count   = Rows,
00062     N     = (count+7)/8
00063   };
00064 
00065 public:
00066   gemtv() { }
00067 
00068 public:
00069   template<class E1, class E2>
00070   static inline
00071   typename PromoteTraits<
00072     typename E1::value_type,
00073     typename E2::value_type
00074     >::value_type
00075   prod(const E1& lhs, const E2& rhs, std::size_t i) {
00076     typename PromoteTraits<
00077       typename E1::value_type,
00078       typename E2::value_type
00079     >::value_type         sum(0);
00080     std::size_t         j(0);
00081     std::size_t         n(N);
00082 
00083     // Duff's device
00084     switch(count % 8) {
00085     case 0: do { sum += lhs(j, i) * rhs(j); ++j;
00086     case 7:      sum += lhs(j, i) * rhs(j); ++j;
00087     case 6:      sum += lhs(j, i) * rhs(j); ++j;
00088     case 5:      sum += lhs(j, i) * rhs(j); ++j;
00089     case 4:      sum += lhs(j, i) * rhs(j); ++j;
00090     case 3:      sum += lhs(j, i) * rhs(j); ++j;
00091     case 2:      sum += lhs(j, i) * rhs(j); ++j;
00092     case 1:      sum += lhs(j, i) * rhs(j); ++j;
00093             } while(--n != 0);
00094     }
00095 
00096     return sum;
00097   }
00098 };
00099 
00100 
00101 } // namespace loop
00102 
00103 } // namespace tvmet
00104 
00105 #endif /* TVMET_LOOP_GEMTV_H */
00106 
00107 // Local Variables:
00108 // mode:C++
00109 // tab-width:8
00110 // End:

Author: