1 // This file is part of Eigen, a lightweight C++ template library 2 // for linear algebra. 3 // 4 // Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com> 5 // 6 // This Source Code Form is subject to the terms of the Mozilla 7 // Public License v. 2.0. If a copy of the MPL was not distributed 8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 10 #ifndef CXX11_SRC_FIXEDPOINT_MATVECPRODUCT_H_ 11 #define CXX11_SRC_FIXEDPOINT_MATVECPRODUCT_H_ 12 13 namespace Eigen { 14 namespace internal { 15 16 // Mat-Vec product 17 // Both lhs and rhs are encoded as 8bit signed integers 18 template <typename Index, typename LhsMapper, bool ConjugateLhs, 19 typename RhsMapper, bool ConjugateRhs, int Version> 20 struct general_matrix_vector_product<Index, QInt8, LhsMapper, ColMajor, 21 ConjugateLhs, QInt8, RhsMapper, 22 ConjugateRhs, Version> { 23 EIGEN_DONT_INLINE static void run(Index rows, Index cols, 24 const LhsMapper& lhs, const RhsMapper& rhs, 25 QInt32* res, Index resIncr, QInt8 alpha); 26 }; 27 28 template <typename Index, typename LhsMapper, bool ConjugateLhs, 29 typename RhsMapper, bool ConjugateRhs, int Version> 30 EIGEN_DONT_INLINE void general_matrix_vector_product< 31 Index, QInt8, LhsMapper, ColMajor, ConjugateLhs, QInt8, RhsMapper, 32 ConjugateRhs, Version>::run(Index rows, Index cols, const LhsMapper& lhs, 33 const RhsMapper& rhs, QInt32* res, 34 Index resIncr, QInt8 alpha) { 35 eigen_assert(alpha.value == 1); 36 eigen_assert(resIncr == 1); 37 eigen_assert(rows > 0); 38 eigen_assert(cols > 0); 39 40 for (Index i = 0; i < rows; ++i) { 41 for (Index j = 0; j < cols; ++j) { 42 res[i] += lhs(i, j) * rhs(j, 0); 43 } 44 } 45 } 46 47 // Mat-Vec product 48 // Both lhs and rhs are encoded as 16bit signed integers 49 template <typename Index, typename LhsMapper, bool ConjugateLhs, 50 typename RhsMapper, bool ConjugateRhs, int Version> 51 struct general_matrix_vector_product<Index, QInt16, LhsMapper, ColMajor, 52 ConjugateLhs, QInt16, RhsMapper, 53 ConjugateRhs, Version> { 54 EIGEN_DONT_INLINE static void run(Index rows, Index cols, 55 const LhsMapper& lhs, const RhsMapper& rhs, 56 QInt32* res, Index resIncr, QInt16 alpha); 57 }; 58 59 template <typename Index, typename LhsMapper, bool ConjugateLhs, 60 typename RhsMapper, bool ConjugateRhs, int Version> 61 EIGEN_DONT_INLINE void general_matrix_vector_product< 62 Index, QInt16, LhsMapper, ColMajor, ConjugateLhs, QInt16, RhsMapper, 63 ConjugateRhs, Version>::run(Index rows, Index cols, const LhsMapper& lhs, 64 const RhsMapper& rhs, QInt32* res, 65 Index resIncr, QInt16 alpha) { 66 eigen_assert(alpha.value == 1); 67 eigen_assert(resIncr == 1); 68 eigen_assert(rows > 0); 69 eigen_assert(cols > 0); 70 71 for (Index i = 0; i < rows; ++i) { 72 for (Index j = 0; j < cols; ++j) { 73 res[i] += lhs(i, j) * rhs(j, 0); 74 } 75 } 76 } 77 78 // Mat-Vec product 79 // The lhs is encoded using 8bit signed integers, the rhs using 8bit unsigned 80 // integers 81 template <typename Index, typename LhsMapper, bool ConjugateLhs, 82 typename RhsMapper, bool ConjugateRhs, int Version> 83 struct general_matrix_vector_product<Index, QInt8, LhsMapper, ColMajor, 84 ConjugateLhs, QUInt8, RhsMapper, 85 ConjugateRhs, Version> { 86 EIGEN_DONT_INLINE static void run(Index rows, Index cols, 87 const LhsMapper& lhs, const RhsMapper& rhs, 88 QInt32* res, Index resIncr, QUInt8 alpha); 89 }; 90 91 template <typename Index, typename LhsMapper, bool ConjugateLhs, 92 typename RhsMapper, bool ConjugateRhs, int Version> 93 EIGEN_DONT_INLINE void general_matrix_vector_product< 94 Index, QInt8, LhsMapper, ColMajor, ConjugateLhs, QUInt8, RhsMapper, 95 ConjugateRhs, Version>::run(Index rows, Index cols, const LhsMapper& lhs, 96 const RhsMapper& rhs, QInt32* res, 97 Index resIncr, QUInt8 alpha) { 98 eigen_assert(alpha.value == 1); 99 eigen_assert(resIncr == 1); 100 eigen_assert(rows > 0); 101 eigen_assert(cols > 0); 102 103 for (Index i = 0; i < rows; ++i) { 104 for (Index j = 0; j < cols; ++j) { 105 res[i] += lhs(i, j) * rhs(j, 0); 106 } 107 } 108 } 109 110 // Mat-Vec product 111 // The lhs is encoded using bit unsigned integers, the rhs using 8bit signed 112 // integers 113 template <typename Index, typename LhsMapper, bool ConjugateLhs, 114 typename RhsMapper, bool ConjugateRhs, int Version> 115 struct general_matrix_vector_product<Index, QUInt8, LhsMapper, ColMajor, 116 ConjugateLhs, QInt8, RhsMapper, 117 ConjugateRhs, Version> { 118 EIGEN_DONT_INLINE static void run(Index rows, Index cols, 119 const LhsMapper& lhs, const RhsMapper& rhs, 120 QInt32* res, Index resIncr, QInt8 alpha); 121 }; 122 123 template <typename Index, typename LhsMapper, bool ConjugateLhs, 124 typename RhsMapper, bool ConjugateRhs, int Version> 125 EIGEN_DONT_INLINE void general_matrix_vector_product< 126 Index, QUInt8, LhsMapper, ColMajor, ConjugateLhs, QInt8, RhsMapper, 127 ConjugateRhs, Version>::run(Index rows, Index cols, const LhsMapper& lhs, 128 const RhsMapper& rhs, QInt32* res, 129 Index resIncr, QInt8 alpha) { 130 eigen_assert(alpha.value == 1); 131 eigen_assert(resIncr == 1); 132 eigen_assert(rows > 0); 133 eigen_assert(cols > 0); 134 135 for (Index i = 0; i < rows; ++i) { 136 for (Index j = 0; j < cols; ++j) { 137 res[i] += lhs(i, j) * rhs(j, 0); 138 } 139 } 140 } 141 142 } // namespace internal 143 } // namespace Eigen 144 145 #endif // CXX11_SRC_FIXEDPOINT_MATVECPRODUCT_H_ 146