blob: 9a62982425285ca77899f6e861839ddf5a0dc01a [file] [log] [blame]
Gael Guennebaudcb71dc42009-01-07 22:20:03 +00001// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra. Eigen itself is part of the KDE project.
3//
4// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
5//
6// Eigen is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 3 of the License, or (at your option) any later version.
10//
11// Alternatively, you can redistribute it and/or
12// modify it under the terms of the GNU General Public License as
13// published by the Free Software Foundation; either version 2 of
14// the License, or (at your option) any later version.
15//
16// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public
22// License and a copy of the GNU General Public License along with
23// Eigen. If not, see <http://www.gnu.org/licenses/>.
24
25#include "main.h"
26#include <typeinfo>
27
28template<typename Dst, typename Src>
29bool test_assign(const Dst&, const Src&, int vectorization, int unrolling)
30{
31 return ei_assign_traits<Dst,Src>::Vectorization==vectorization
32 && ei_assign_traits<Dst,Src>::Unrolling==unrolling;
33}
34
35template<typename Xpr>
Gael Guennebaudc5245a32009-02-13 08:45:19 +000036bool test_redux(const Xpr&, int vectorization, int unrolling)
Gael Guennebaudcb71dc42009-01-07 22:20:03 +000037{
Gael Guennebaudc5245a32009-02-13 08:45:19 +000038 typedef ei_redux_traits<ei_scalar_sum_op<typename Xpr::Scalar>,Xpr> traits;
39 return traits::Vectorization==vectorization && traits::Unrolling==unrolling;
Gael Guennebaudcb71dc42009-01-07 22:20:03 +000040}
41
42void test_vectorization_logic()
43{
44
45#ifdef EIGEN_VECTORIZE
46
47 VERIFY(test_assign(Vector4f(),Vector4f(),
48 InnerVectorization,CompleteUnrolling));
49 VERIFY(test_assign(Vector4f(),Vector4f()+Vector4f(),
50 InnerVectorization,CompleteUnrolling));
51 VERIFY(test_assign(Vector4f(),Vector4f().cwise() * Vector4f(),
52 InnerVectorization,CompleteUnrolling));
53
54 VERIFY(test_assign(Matrix4f(),Matrix4f(),
55 InnerVectorization,CompleteUnrolling));
56 VERIFY(test_assign(Matrix4f(),Matrix4f()+Matrix4f(),
57 InnerVectorization,CompleteUnrolling));
58 VERIFY(test_assign(Matrix4f(),Matrix4f().cwise() * Matrix4f(),
59 InnerVectorization,CompleteUnrolling));
60
61 VERIFY(test_assign(Matrix<float,16,16>(),Matrix<float,16,16>()+Matrix<float,16,16>(),
62 InnerVectorization,InnerUnrolling));
63
64 VERIFY(test_assign(Matrix<float,16,16,DontAlign>(),Matrix<float,16,16>()+Matrix<float,16,16>(),
65 NoVectorization,InnerUnrolling));
66
67 VERIFY(test_assign(Matrix<float,6,2>(),Matrix<float,6,2>().cwise() / Matrix<float,6,2>(),
68 LinearVectorization,CompleteUnrolling));
69
70 VERIFY(test_assign(Matrix<float,17,17>(),Matrix<float,17,17>()+Matrix<float,17,17>(),
71 NoVectorization,InnerUnrolling));
72
73 VERIFY(test_assign(Matrix<float,4,4>(),Matrix<float,17,17>().block<4,4>(2,3)+Matrix<float,17,17>().block<4,4>(10,4),
74 NoVectorization,CompleteUnrolling));
75
76 VERIFY(test_assign(MatrixXf(10,10),MatrixXf(20,20).block(10,10,2,3),
77 SliceVectorization,NoUnrolling));
78
79
Gael Guennebaudc5245a32009-02-13 08:45:19 +000080 VERIFY(test_redux(VectorXf(10),
Gael Guennebaudcb71dc42009-01-07 22:20:03 +000081 LinearVectorization,NoUnrolling));
82
Gael Guennebaudc5245a32009-02-13 08:45:19 +000083 VERIFY(test_redux(Matrix<float,5,2>(),
Gael Guennebaudaf27fb72009-01-08 11:53:21 +000084 NoVectorization,CompleteUnrolling));
Gael Guennebaudc5245a32009-02-13 08:45:19 +000085
86 VERIFY(test_redux(Matrix<float,6,2>(),
Gael Guennebaudcb71dc42009-01-07 22:20:03 +000087 LinearVectorization,CompleteUnrolling));
88
Gael Guennebaudc5245a32009-02-13 08:45:19 +000089 VERIFY(test_redux(Matrix<float,16,16>(),
Gael Guennebaudcb71dc42009-01-07 22:20:03 +000090 LinearVectorization,NoUnrolling));
91
Gael Guennebaudc5245a32009-02-13 08:45:19 +000092 VERIFY(test_redux(Matrix<float,16,16>().block<4,4>(1,2),
Gael Guennebaudcb71dc42009-01-07 22:20:03 +000093 NoVectorization,CompleteUnrolling));
94
Gael Guennebaudc5245a32009-02-13 08:45:19 +000095 VERIFY(test_redux(Matrix<float,16,16>().block<8,1>(1,2),
Gael Guennebaudcb71dc42009-01-07 22:20:03 +000096 LinearVectorization,CompleteUnrolling));
97
Gael Guennebaudc5245a32009-02-13 08:45:19 +000098 VERIFY(test_redux(Matrix<double,7,3>(),
Gael Guennebaudcb71dc42009-01-07 22:20:03 +000099 NoVectorization,CompleteUnrolling));
100
101#endif // EIGEN_VECTORIZE
102
103}